title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Cannot run matplotlib and pyqt4 at the same time | 38,214,737 | <p>I am running some code using PyQt4, and I would like to plot a figure using its data. But when I try to do that, it will report </p>
<pre><code>QPixmap: Must construct a QGuiApplication before a QPixmap
</code></pre>
<p>Below is the code:</p>
<pre><code>from PyQt4 import QtCore
import sys
import matplotlib.pyplot... | 0 | 2016-07-06T00:16:03Z | 38,217,242 | <p>The complaint by PyQt is that you are not running a Gui EventLoop. <code>app.exec_()</code> sure starts an event loop, but that depends on what <code>app</code> is. In your case its <code>QCoreApplication</code> object. How do you expect it to start a Gui EventLoop? It's like buying a saucepan and expecting it to co... | 1 | 2016-07-06T06:04:21Z | [
"python",
"matplotlib",
"pyqt4"
] |
base64 encodebytes v b64encode v encodestring | 38,214,765 | <p>What is difference and why/when would I want to use
<code>base64.b64encode</code> vs. <code>base64.encodestring</code> vs. <code>base64.encodebytes</code>?</p>
<p>From what I can tell they all basically do the same thing except that <code>base64.encodebytes</code> is no longer <a href="https://docs.python.org/3.1/l... | 0 | 2016-07-06T00:21:26Z | 38,214,838 | <p>For Python 3, <code>encodestring</code> is the same as <code>encodebytes</code> except that <code>encodestring</code> is deprecated. In Python 2, <code>encodebytes</code> does not exist.</p>
<p><code>b64encode</code> does a straight encoding, with the option of using alternate characters in the base64 alphabet in p... | 1 | 2016-07-06T00:34:37Z | [
"python",
"base64"
] |
Maximum sum in a non-binary tree in Python | 38,214,776 | <p>I have a non-binary tree and each node of that tree has a value. I would like to get the maximum sum available.
For example:</p>
<pre><code> 10
9 8 7
1 2 5 5 15
</code></pre>
<p>The return would be 10+7+15=32
I know how to do this if the tree was binary, but what if th... | 0 | 2016-07-06T00:24:07Z | 38,214,896 | <p>Here's one approach:</p>
<pre><code>class Node:
def __init__(self, value):
self.value = value
self.children = []
def max_sum(root):
if len(root.children) == 0:
return root.value
sums = []
for child in root.children:
sums.append(root.value + max_sum(child))
ret... | 0 | 2016-07-06T00:45:25Z | [
"python",
"recursion",
"tree"
] |
Maximum sum in a non-binary tree in Python | 38,214,776 | <p>I have a non-binary tree and each node of that tree has a value. I would like to get the maximum sum available.
For example:</p>
<pre><code> 10
9 8 7
1 2 5 5 15
</code></pre>
<p>The return would be 10+7+15=32
I know how to do this if the tree was binary, but what if th... | 0 | 2016-07-06T00:24:07Z | 38,214,898 | <p>Assuming each node has a <code>value</code> attribute and a <code>children</code> attribute which is either a list of child nodes, an empty list, or None:</p>
<pre><code>def tree_sum(node):
if node.children:
child_sums = []
for child in node.children:
child_sums.append(tree_sum(child... | 3 | 2016-07-06T00:45:47Z | [
"python",
"recursion",
"tree"
] |
Python sentiment classification | 38,214,855 | <p>Hi i am trying to classify certain text file by using sentiment classifier package.The following program works fine for a single sentence i.e.,</p>
<pre><code>from senti_classifier import senti_classifier
sentences = ['i love u']
pos_score, neg_score = senti_classifier.polarity_scores(sentences)
print pos_score, ne... | 1 | 2016-07-06T00:38:15Z | 38,214,884 | <p><a href="https://github.com/kevincobain2000/sentiment_classifier/blob/master/src/senti_classifier/senti_classifier.py#L207" rel="nofollow"><code>senti_classifier.polarity_scores()</code> function</a> expects a <em>list of strings</em> as an argument, but you are passing a single string. Put it into the list:</p>
<p... | 1 | 2016-07-06T00:42:26Z | [
"python",
"nltk",
"sentiment-analysis"
] |
Python doesn't create file if not existing | 38,214,952 | <p>I cannot figure out how to create file that does not exist. I tried following, yet I get error that file does not exist.</p>
<p>Please guide.</p>
<pre><code>f=open('c:\Lets_Create_Malware\output.txt', 'r+')
f=open('c:\Lets_Create_Malware\output.txt', 'w+')
f=open('c:\Lets_Create_Malware\output.txt', 'a+')
f=ope... | 0 | 2016-07-06T00:52:12Z | 38,214,964 | <p>Use a double backslash:</p>
<pre><code>f=open('c:\\Lets_Create_Malware\\output.txt', 'w+')
</code></pre>
<p>From the <a href="https://docs.python.org/3.6/reference/lexical_analysis.html#string-and-bytes-literals" rel="nofollow">docs</a>:</p>
<blockquote>
<p>The backslash (<code>\</code>) character is used to es... | 1 | 2016-07-06T00:54:47Z | [
"python",
"file",
"read-write"
] |
Python doesn't create file if not existing | 38,214,952 | <p>I cannot figure out how to create file that does not exist. I tried following, yet I get error that file does not exist.</p>
<p>Please guide.</p>
<pre><code>f=open('c:\Lets_Create_Malware\output.txt', 'r+')
f=open('c:\Lets_Create_Malware\output.txt', 'w+')
f=open('c:\Lets_Create_Malware\output.txt', 'a+')
f=ope... | 0 | 2016-07-06T00:52:12Z | 38,215,090 | <p>Given the exact paths you've specificed, at least some of your examples ought to have worked (unless the <code>c:\Lets_Create_Malware</code> path doesn't exist, which would add to the confusion by causing all of your test cases to fail).</p>
<p>Backslashes aren't a problem here given your examples because the chara... | 1 | 2016-07-06T01:15:27Z | [
"python",
"file",
"read-write"
] |
Create dataframes from unique value pairs by filtering across multiple columns | 38,215,009 | <p>I want to filter values across multiple columns creating dataframes for the unique value combinations. Any help would be appreciated.</p>
<p>Here is my code that is failing (given dataframe df):</p>
<pre><code>dd = defaultdict(dict) #create blank default dictionary
values_col1 = df.col1.unique() #get the unique... | 0 | 2016-07-06T01:02:32Z | 38,229,347 | <p>Use pandas <code>groupby</code> functionality to extract the unique indices and the corresponding rows of your dataframe.</p>
<pre><code>import pandas as pd
from collections import defaultdict
df = pd.DataFrame({'col1': ['A']*4 + ['B']*4,
'col2': [0,1]*4,
'col3': np.arange(8),... | 2 | 2016-07-06T16:45:44Z | [
"python",
"pandas",
"dataframe"
] |
PyCharm and f-strings | 38,215,059 | <p>I am using the latest stable PyCharm 2016.1.4 and Python 3.6a1. Whenever I use the "f-strings" (<a href="https://www.python.org/dev/peps/pep-0498/" rel="nofollow">PEP-498</a>) PyCharm is complaining about <code>f</code> being an <em>unresolved reference</em>:</p>
<p><a href="http://m.stack.imgur.com/8Yntam.png" rel... | 3 | 2016-07-06T01:10:08Z | 38,215,091 | <p>The Literal String Interpolation is <em>not yet supported</em>, but the feature request is already in place:</p>
<ul>
<li><a href="https://youtrack.jetbrains.com/issue/PY-18972" rel="nofollow">PY-18972 implement support for PEP 498 (f-strings)</a></li>
</ul>
<p>Since, PyCharm is known to be good at tracking and su... | 4 | 2016-07-06T01:15:40Z | [
"python",
"python-3.x",
"pycharm",
"string-formatting",
"python-3.6"
] |
Vectorizing a very simple pandas lambda function in apply | 38,215,071 | <p>pandas <code>apply/map</code> is my nemesis and even on small datasets can be agonizingly slow. Below is a very simple example where there is nearly a 3 order of magnitude difference in speed. Below I create a <code>Series</code> with 1 million values and simply want to map values greater than .5 to 'Yes' and those ... | 0 | 2016-07-06T01:12:39Z | 38,215,101 | <p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow"><code>np.where(cond, A, B)</code></a> is the vectorized equivalent of <code>A if cond else B</code>:</p>
<pre><code>import numpy as np
import pandas as pd
ser = pd.Series(np.random.rand(1000000))
mask = ser > 0.5
result... | 4 | 2016-07-06T01:16:50Z | [
"python",
"pandas",
"vectorization",
"apply"
] |
DLL load failed: The specified module could not be found for pygpu/libgpuarray | 38,215,120 | <p>I'm using libgpuarray (openCL) but can't seem to get the GPU working with Theano in anaconda 2. When I try to run the <a href="http://deeplearning.net/software/theano/tutorial/using_gpu.html" rel="nofollow">test</a> I get:</p>
<blockquote>
<p>ERROR (theano.gpuarray): pygpu was configured but could not be
import... | 0 | 2016-07-06T01:18:54Z | 38,766,366 | <p>I solved this problem by copying <code>gpuarray.dll</code> generated in your build dir into C:\Windows\System32. </p>
| 0 | 2016-08-04T11:41:41Z | [
"python",
"opencl",
"gpu",
"anaconda",
"theano"
] |
Use logging.DEBUG in PyCharm debug run | 38,215,212 | <p>What is a good way to set the logging level for a module in pycharm so that debugging statements will print during a debug session? I am using the native python logging module in python 2.7.</p>
| 0 | 2016-07-06T01:35:31Z | 38,215,383 | <p>Python logging level can be set inside the Python module, not outside from PyCharm. Your Python application must adjust its own logging level.</p>
<ul>
<li><p>Call <code>logging.getLogger()</code> to get the root logger (topmost in logging hierarchy)</p></li>
<li><p>Set environment variable in your run configuratio... | 1 | 2016-07-06T02:02:26Z | [
"python",
"logging",
"pycharm"
] |
plane fitting with normalized coefficients | 38,215,223 | <p>I am Trying to fit 3d-points to a plane in 2.5d/3d using <strong>scipy.optimize.leastsq</strong>.</p>
<p>I am trying to minimize the function: a<em>x + b</em>y + c - z </p>
<p>When I add noise to the planes I'm generating, I am starting to get different results for (a,b,c), while the linear relationship between a ... | 1 | 2016-07-06T01:37:51Z | 38,221,692 | <p>Here's one way:
Given N X,Y,Z values you want to find a,b,c,d to minimise </p>
<pre><code>Q = Sum{ i | square( (a,b,c)*(X[i], Y[i], Z[i])' - d)}
</code></pre>
<p>whatever value you choose for (a,b,c) the value of d that minimises this will be </p>
<pre><code>d = Sum{ i | (a,b,c)*(X[i], Y[i], Z[i])' }/N
= (a,b,... | 1 | 2016-07-06T10:22:25Z | [
"python",
"numpy",
"scipy",
"least-squares"
] |
How to parse python functions from strings, with any input variable name? | 38,215,227 | <p>My app allows the user to specify simple python expressions to use as functions of a given variable. For example, the user could write <code>'x**2 + 2*x + 4'</code> and my app would parse that into a function of <code>x</code>, equivalent to <code>lambda x: x**2 + 2*x + 4</code>. I already know how to do this with:<... | 0 | 2016-07-06T01:38:39Z | 38,215,353 | <p>Use the <a href="http://docs.sympy.org/dev/modules/utilities/lambdify.html" rel="nofollow">lambdify module from Sympy</a>, <a href="http://docs.sympy.org/latest/index.html" rel="nofollow">full docs here</a></p>
<p>The package has several possible ways of addressing this problem, since it support full symbolic compu... | 1 | 2016-07-06T01:57:47Z | [
"python",
"parsing",
"user-defined-functions"
] |
Print top view of a Binary Tree | 38,215,320 | <p>I am trying to print the top view of a binary tree. My code in python is as follows:</p>
<pre><code>class Node(object):
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def top_view(root, m, hd):
if root is None:
return
if hd not in m:
... | 0 | 2016-07-06T01:53:00Z | 38,215,413 | <p>You're traversing the tree in depth-first order. I.e. you are calling top_view(root.left, m, -1), which will recursively search the entire left side of the tree. So by the time you call top_view(root.right, m, 1), you've already set m[1] with node 5, and you don't end up putting node 3 in.</p>
<p>I think there ar... | 2 | 2016-07-06T02:07:53Z | [
"python",
"binary-tree"
] |
Print top view of a Binary Tree | 38,215,320 | <p>I am trying to print the top view of a binary tree. My code in python is as follows:</p>
<pre><code>class Node(object):
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def top_view(root, m, hd):
if root is None:
return
if hd not in m:
... | 0 | 2016-07-06T01:53:00Z | 38,215,559 | <p>in your code, lower level nodes are collecting fast than the higher level nodes,since your code is dfs.<br>
add one more parameter(level) could solve it.</p>
<pre><code>class Node(object):
def __init__(self, data):
self.data = data
self.left = None
self.right = None
def top_view(root, m... | 1 | 2016-07-06T02:32:00Z | [
"python",
"binary-tree"
] |
webapp2 http error 500 | 38,215,362 | <p>I try to run a code snippet in goold app engine and find a weird problem. When I run the code snippet below, it report error:</p>
<blockquote>
<p>localhost is currently unable to handle this request.HTTP ERROR 500</p>
</blockquote>
<pre><code> import webapp2
import cgi
form="""
<!DOCTYPE html>
<html&g... | 1 | 2016-07-06T01:59:20Z | 38,261,432 | <p>First remove the space from first line.</p>
<p>Then display the "text" which you get from the user.</p>
<pre><code>text = self.request.get('text')
self.response.out.write(text)
</code></pre>
| 1 | 2016-07-08T07:45:21Z | [
"python",
"html"
] |
How to make pandas#read_csv raise exception when some columns missed | 38,215,417 | <p>As following, the last line of <code>text</code> has a missed column. I want <code>read_csv</code> raise an exception rather than return a <code>DataFrame</code> with <code>NaN</code> value. Is this possible?</p>
<p>A row with missed column if <code>len(row.split(sep)) < len(columns)</code>.</p>
<pre><code>In ... | 0 | 2016-07-06T02:08:11Z | 38,215,553 | <p>It doesn't look like there's an easy way to get the <code>read_csv</code> function to do what you're asking, according to the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html" rel="nofollow">docs</a>.</p>
<p>However, you can use <code>df.isnull().values.any()</code>. That statemen... | 1 | 2016-07-06T02:31:00Z | [
"python",
"pandas"
] |
Interpretation of .join() | 38,215,423 | <p>Original code:</p>
<pre><code>board = []
for x in range(5):
board.append("O" * 5)
print(board)
</code></pre>
<p>Why does the code print each index in its own row when you add this to the code above?</p>
<pre><code>board = []
for x in range(5):
board.append("O" * 5)
def print_board(board):
for row i... | 2 | 2016-07-06T02:09:07Z | 38,215,512 | <p>Since you're doing print in a for loop,
everytime the loop is iterating through the row,
it's doing a new print statement on the next line. </p>
<p>Think of it this way.</p>
<pre><code>for i in range(5):
print (i)
</code></pre>
<p>makes </p>
<pre><code>0
1
2
3
4
</code></pre>
| 1 | 2016-07-06T02:23:00Z | [
"python",
"python-3.x"
] |
Errors with python even though I included libraries | 38,215,425 | <p>I have Python code based on <a href="https://www.youtube.com/watch?v=5xy9w9-hzrs" rel="nofollow">YouTube video</a> </p>
<p>When I enter Ctrl-E to exit, I get error <code>Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pyHook\HookManager.py", line 351, in KeyboardSwitch
return func(event... | 1 | 2016-07-06T02:09:19Z | 38,215,450 | <p>To use an imported module in python you must call the method from the module as <code>module.method</code> so you should have <code>sys.exit(1)</code> not <code>_exit(1)</code>.</p>
| 2 | 2016-07-06T02:12:19Z | [
"python",
"file",
"exit",
"read-write"
] |
Python/Pygame button push for sound | 38,215,437 | <p>I am very new to programming. I am building a project: when i push my doorbell button, a picture sends my phone (with <code>twilio</code> and <code>Imgur</code>) and I also want a doorbell sound to go off when the same button is pushed. the coding i have for the initial part is working, and the picture is sending to... | 1 | 2016-07-06T02:10:19Z | 38,217,444 | <p><code>mixer.music.load()</code> returns <code>None</code> no matter what the input is (see the Docs <a href="http://www.pygame.org/docs/ref/music.html#pygame.mixer.music.load" rel="nofollow">here</a>). That means that <code>sndA</code> also gets <code>None</code>. </p>
<p>But the <code>pygame.mixer.music.play()</co... | 2 | 2016-07-06T06:23:36Z | [
"python",
"audio",
"raspberry-pi",
"pygame"
] |
Python/Pygame button push for sound | 38,215,437 | <p>I am very new to programming. I am building a project: when i push my doorbell button, a picture sends my phone (with <code>twilio</code> and <code>Imgur</code>) and I also want a doorbell sound to go off when the same button is pushed. the coding i have for the initial part is working, and the picture is sending to... | 1 | 2016-07-06T02:10:19Z | 38,223,741 | <p>Try using the Sound object from the mixer instead of the music function.</p>
<pre><code>doorbell = pygame.mixer.Sound(filename)
doorbell.play()
</code></pre>
<p>Check out this link:
<a href="http://www.pygame.org/docs/ref/mixer.html#pygame.mixer.Sound" rel="nofollow">Pygame Sound object</a></p>
<p>As for combini... | 1 | 2016-07-06T12:13:20Z | [
"python",
"audio",
"raspberry-pi",
"pygame"
] |
while loops and possible if statements | 38,215,445 | <p>I need to write a function that will list n amount of numbers that are divisible by m. So if I list the function divisibility(10,2) it will list the first 10 numbers divisible by 2. This is in Python 3. Any basic structures that I can manipulate would be helpful. Brand new programmer, so all insight will much apprec... | -2 | 2016-07-06T02:11:49Z | 38,215,458 | <p>Divisible just means âa multiple ofâ</p>
<pre><code>divisible_by = 2
number_of_numbers_you_want = 10
for i in range(number_of_numbers_you_want):
print(i*divisible_by)
</code></pre>
| 0 | 2016-07-06T02:13:56Z | [
"python"
] |
while loops and possible if statements | 38,215,445 | <p>I need to write a function that will list n amount of numbers that are divisible by m. So if I list the function divisibility(10,2) it will list the first 10 numbers divisible by 2. This is in Python 3. Any basic structures that I can manipulate would be helpful. Brand new programmer, so all insight will much apprec... | -2 | 2016-07-06T02:11:49Z | 38,215,514 | <p>Another way of saying "divisible by" is "multiple of". To put if simply, you have to write a program to output the first 10 multiples of 2. You can use range() function for this.</p>
<p>The range function can take 3 inputs. range(x, y, z)<br>
x is starting index (inclusive)<br>
y is ending index (exclusive)<br>
z i... | 0 | 2016-07-06T02:23:14Z | [
"python"
] |
Combining browser app and desktop app | 38,215,515 | <p>I am developing an application using Python + SQLite. The application is very basic - it will take user input through GUI and retrieve data based on the button clicks. There is no requirement for web technology.</p>
<p>I plan to use Tkinter for developing the GUI. This works fine for taking user input. However the ... | 0 | 2016-07-06T02:23:26Z | 38,215,552 | <p>It certainly is possible to use the combination of browser app and desktop app together. However, to me it seems like the work would be more complicated than necessary. </p>
<p>How about making a simple server with python and just solely sticking with the web app? You can just use simplehttpserver and not have to d... | 2 | 2016-07-06T02:30:44Z | [
"python",
"user-interface",
"tkinter"
] |
Counting/assigning group order to observations within groups for multilevel groups? | 38,215,544 | <p>I'm working on a time-series analysis I have a dataset that contains at least two indexing variables (in this case ID and Year). After sorting by ID and Year:</p>
<pre><code>ID Year Grade
1 1990 B
1 1991 B
1 1991 A
2 2001 B
2 2001 C
2 2001 C
2 2003 A
</code></pre>
<p>I would like to group by... | 1 | 2016-07-06T02:29:35Z | 38,215,545 | <p>I found a round about way to go about this. First sort your level variables</p>
<pre><code>full_data = full_data.sort_values(by=['ID','Year'],ascending = [True, True])
</code></pre>
<p>create a binary variable that indicates the first observation in each 2 level group</p>
<pre><code>full_data['temp'] = (full_data... | 2 | 2016-07-06T02:29:35Z | [
"python",
"pandas",
"group-by",
"time-series"
] |
How to reopen window | 38,215,579 | <p>The following code should close the current file and open it again. Instead, it keeps opening only new windows. </p>
<p>Does anybody have a hint for keeping the old window closed? </p>
<pre><code>import sys
from PyQt4 import QtGui, QtCore
import subprocess
class Example(QtGui.QWidget):
def __init__(self):
... | 0 | 2016-07-06T02:35:34Z | 38,230,103 | <p>You seem to have put <code>self.close()</code> in the wrong place. Also, you should not use <code>subprocess.call</code>, as it will block until the command completes. It's better to use <code>QProcess</code> instead:</p>
<pre><code> def run(self, path):
QtCore.QProcess.startDetached('python', [path])
... | 1 | 2016-07-06T17:27:30Z | [
"python",
"pyqt",
"pyqt4"
] |
two-dimensional python dict with shared memory | 38,215,604 | <p>I need to load data from a csv file or an excel sheet (with rows and columns) into a two-dimensional python dict. For example, if the data in an excel sheet looks like this:</p>
<pre><code> name age gender location
1 Jim 18 male China
2 Ross 18 male China
3 Cara 19 female Japan
4 Ted ... | 0 | 2016-07-06T02:39:43Z | 38,217,061 | <p>I guess you are asking about a data compression solution, which should then consider both memory sizes and use of references. The smallest memory footprint typically belongs to an integer which should be at least as small as a memory reference, so I would try to map everything to integers unless it is too inconvenie... | 1 | 2016-07-06T05:49:11Z | [
"python",
"dictionary",
"python-extensions"
] |
number pyramid using while loop for python | 38,215,624 | <p>I'm supposed to have an output that looks like this:</p>
<pre><code> 1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
</code></pre>
<p>I am using this code:</p>
<pre><code> outer = 1
while outer <=6:
inner = 1
while inner <= outer:
print(inner, end=" ")
inn... | 1 | 2016-07-06T02:43:08Z | 38,215,695 | <p>use <code>string.join()</code>.</p>
<pre><code>def triangle(levels):
for i in range(1,levels + 1):
print(' '*2*(levels - i) + ' '.join(str(j + 1) for j in reversed(range(i))))
triangle(6)
</code></pre>
<p>makes</p>
<pre><code> 1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
</cod... | 0 | 2016-07-06T02:53:07Z | [
"python",
"while-loop",
"nested"
] |
number pyramid using while loop for python | 38,215,624 | <p>I'm supposed to have an output that looks like this:</p>
<pre><code> 1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
</code></pre>
<p>I am using this code:</p>
<pre><code> outer = 1
while outer <=6:
inner = 1
while inner <= outer:
print(inner, end=" ")
inn... | 1 | 2016-07-06T02:43:08Z | 38,215,830 | <p>Looking your code, there were only 2 issues:
1. You were printing in increasing order. So if you subtract the outer from inner, it would print the numbers in decreasing order
2. The padding varies from one line to the next, so add the padding in the outer loop. This is how your code would look with the 2 revisions:<... | 0 | 2016-07-06T03:13:08Z | [
"python",
"while-loop",
"nested"
] |
number pyramid using while loop for python | 38,215,624 | <p>I'm supposed to have an output that looks like this:</p>
<pre><code> 1
2 1
3 2 1
4 3 2 1
5 4 3 2 1
6 5 4 3 2 1
</code></pre>
<p>I am using this code:</p>
<pre><code> outer = 1
while outer <=6:
inner = 1
while inner <= outer:
print(inner, end=" ")
inn... | 1 | 2016-07-06T02:43:08Z | 38,215,876 | <p>Another <code>while</code> solution:</p>
<pre><code>outer = 1
while outer <= 6:
inner = outer
pos = 6 # create a position variable and start from 6 since you are printing backward
while pos >= 1:
if pos > inner: # print white space if pos is larger than the diagonal
... | 0 | 2016-07-06T03:19:14Z | [
"python",
"while-loop",
"nested"
] |
why am I not being redirected in the browser after Mailchimp API oauth2 initial request is sent? | 38,215,657 | <p>I am trying to set up Oauth2 with the Mailchimp API. So far things seem to be working correctly except that after having the user login at Mailchimp, the browser doesn't redirect back to my redirect_uri. It just stays on the Mailchimp login page. </p>
<p>For the code: </p>
<p>I redirect the user to the authorize u... | 0 | 2016-07-06T02:48:30Z | 38,216,891 | <p>Your email_host, user, password and port match with your mail-chimp credentials? second thing you need to check mail-chimp api log for status. you will get some glimpse from there. </p>
| 0 | 2016-07-06T05:31:57Z | [
"python",
"django",
"redirect",
"oauth-2.0",
"mailchimp"
] |
Why FreqDist comparisons in NLTK are not symmetric? i.e. '>' and '<' behave differently | 38,215,686 | <pre><code>nltk.FreqDist('abc') > nltk.FreqDist('abd')
</code></pre>
<p>returns <code>True</code></p>
<p>and</p>
<pre><code>nltk.FreqDist('abd') < nltk.FreqDist('abc')
</code></pre>
<p>returns <code>False</code></p>
<p>What's the reason behind this? It seems a bit weird to me.</p>
| 2 | 2016-07-06T02:51:30Z | 38,231,458 | <p>I looked at the comparison methods of the <code>FreqDist</code> class and found that they are all based on one method: <code>__le__</code>. Just to illustrate what that means, given this setup:</p>
<pre><code>>>> abc = nltk.FreqDist('abc')
>>> abd = nltk.FreqDist('abd')
</code></pre>
<p>These two... | 1 | 2016-07-06T18:40:57Z | [
"python",
"nltk"
] |
Docker cannot build because can't find matching distribution of a requirement | 38,215,720 | <p>I'm having difficulty getting my app on Docker. Currently I'm trying to build build it, but am running in to an error I can't figure out how to solve.</p>
<p>When I ran <code>docker-compose build</code>, it was pulling and downloading, but when it tried to collect <code>json</code>, it gave the error:</p>
<pre><c... | 0 | 2016-07-06T02:56:42Z | 38,215,869 | <p><code>json</code> has been added to Python since Python 2.6, you need to remove it from the requirements file.</p>
<p>You also have things like <code>math</code> and <code>itertools</code> that are part of Python in your requirements file.</p>
<p>The requirements file is for packages that your application needs wh... | 2 | 2016-07-06T03:18:22Z | [
"python",
"json",
"docker"
] |
Variable is not defined: but I think it is | 38,215,837 | <p>I'm new to coding, especially in python. I started learning python using codeacademy about 1 day ago and I have progressed quickly. After reaching the end of the battleship unit, it challenged me to challenge myself by seeing what I can do. So, I set out to make the game two-player. However, after finishing the prog... | 0 | 2016-07-06T03:14:06Z | 38,215,895 | <p>Your problem is that the variable <code>ship_col2</code> is defined within a function. That means that it only exists until that function is done running, and then it is deleted. In order to make it available outside that function and in other functions, you must declare it as a global variable, which you can do by ... | 0 | 2016-07-06T03:22:20Z | [
"python",
"variables"
] |
I want to keep order of OrderedDict with ujson | 38,215,872 | <p>My function's return value type is <code>OrderedDict</code>,</p>
<p>and now I want to write this on the file:</p>
<p>Here's my code:</p>
<pre><code>mainDict = OrderedDict([('a',1),('b',2),('c',3),('d',[4,5,6])])
with open(outFileName, 'w', encoding='utf-8') as outFile :
outFile.write(ujson.dumps(mainDict, inde... | 1 | 2016-07-06T03:18:38Z | 38,216,409 | <p>Use like this</p>
<pre><code>mainDict = OrderedDict([('a',1),('b',2),('c',3),('d',[4,5,6])])
with open(outFileName, 'w', encoding='utf-8') as outFile :
outFile.write(ujson.dumps(mainDict, indent=4, sort_keys=False))
</code></pre>
| 0 | 2016-07-06T04:38:09Z | [
"python",
"ordereddictionary",
"ujson"
] |
I want to keep order of OrderedDict with ujson | 38,215,872 | <p>My function's return value type is <code>OrderedDict</code>,</p>
<p>and now I want to write this on the file:</p>
<p>Here's my code:</p>
<pre><code>mainDict = OrderedDict([('a',1),('b',2),('c',3),('d',[4,5,6])])
with open(outFileName, 'w', encoding='utf-8') as outFile :
outFile.write(ujson.dumps(mainDict, inde... | 1 | 2016-07-06T03:18:38Z | 38,216,473 | <p>Yes, it seems like <code>ujson</code> dumps the dictionary as an unordered dictionary by default, unlike the built-in <code>json</code> package. Set the <code>sort_keys</code> argument to <code>true</code> to dump the data as an ordered dictionary.</p>
<p>Here's my the sample code:</p>
<pre><code>import ujson
impo... | -2 | 2016-07-06T04:48:34Z | [
"python",
"ordereddictionary",
"ujson"
] |
I want to keep order of OrderedDict with ujson | 38,215,872 | <p>My function's return value type is <code>OrderedDict</code>,</p>
<p>and now I want to write this on the file:</p>
<p>Here's my code:</p>
<pre><code>mainDict = OrderedDict([('a',1),('b',2),('c',3),('d',[4,5,6])])
with open(outFileName, 'w', encoding='utf-8') as outFile :
outFile.write(ujson.dumps(mainDict, inde... | 1 | 2016-07-06T03:18:38Z | 38,265,539 | <h2>Use <code>sort_keys</code> parameter of <code>ujson.dumps</code></h2>
<p>Behaviour of <code>ujson</code> is the following:</p>
<ul>
<li><code>sort_keys=None</code> (default if omitted) - dump dict keys in implementation-defined order, which may be different every launch (but it's fast)</li>
<li><code>sort_keys=Tr... | 1 | 2016-07-08T11:29:49Z | [
"python",
"ordereddictionary",
"ujson"
] |
TypeError: Required argument 'object' (pos 1) not found | 38,215,975 | <p>I am a beginner and facing an error in my code:</p>
<p>This error was resolved:</p>
<pre><code>Traceback (most recent call last):
File "/Users/ankitchaudhari/PycharmProjects/Learn/datascience/gg.py", line 26, in <module>
label = kmeans(data, k)
File "/Users/ankitchaudhari/PycharmProjects/Learn/datasc... | 0 | 2016-07-06T03:35:11Z | 38,216,045 | <p>In your 'for' loop, the second parameter should be 'i' not 'k':</p>
<pre><code>label = kmeans(data, i)
</code></pre>
| 0 | 2016-07-06T03:47:47Z | [
"python"
] |
Python Regular Expression Groups | 38,216,055 | <p>Why does this regex print <code>('c',)</code> and <code>()</code>?
I thought <code>"([abc])+" === "([abc])([abc])([abc])..."</code></p>
<pre><code>>>> import re
>>> m = re.match("([abc])+", "abc")
>>> print m.groups()
('c',)
>>> m.groups(0)
('c',)
>>> m = re.match("[abc]... | 1 | 2016-07-06T03:48:58Z | 38,216,105 | <p>When you put plus after the parenthesis you are matching one character at a time, many times. So it matches a then b then c, each time overwriting the previous. Move the + inside ([abc]+) to match one or more.</p>
| 0 | 2016-07-06T03:56:17Z | [
"python",
"regex",
"python-2.7"
] |
Python Regular Expression Groups | 38,216,055 | <p>Why does this regex print <code>('c',)</code> and <code>()</code>?
I thought <code>"([abc])+" === "([abc])([abc])([abc])..."</code></p>
<pre><code>>>> import re
>>> m = re.match("([abc])+", "abc")
>>> print m.groups()
('c',)
>>> m.groups(0)
('c',)
>>> m = re.match("[abc]... | 1 | 2016-07-06T03:48:58Z | 38,216,111 | <p>From documentation about <strong><a href="https://docs.python.org/2/library/re.html#re.MatchObject.groups" rel="nofollow">groups</a></strong></p>
<blockquote>
<p>Return a tuple containing all the subgroups of the match, from 1 up to however many groups are in the pattern. The default argument is used for groups t... | 1 | 2016-07-06T03:57:16Z | [
"python",
"regex",
"python-2.7"
] |
Python nested dictionary assignment not working | 38,216,065 | <p>The code in question is <a href="https://github.com/IamCarbonMan/PoGoMsgBot/blob/master/bot.py" rel="nofollow">here on Github</a>. Basically, everything is working except the <a href="https://github.com/IamCarbonMan/PoGoMsgBot/blob/master/bot.py#L35" rel="nofollow">addClient( )</a> function, which takes a SRE_Match ... | -3 | 2016-07-06T03:51:01Z | 38,216,185 | <p>Okay, the answer should have been obvious. As TesselatingHeckler suggested, the error pops up when <code>info</code> is not true, and can be fixed like:</p>
<pre><code>def addClient(client, info,medium):
if info:
info = info.group(0).split(' ')
if medium == 'text':
db['clients']['text'][client] = {'... | 0 | 2016-07-06T04:07:53Z | [
"python",
"dictionary"
] |
Python: How to write this python one-liner in 'readable' way? | 38,216,099 | <p>I have started to learn Python. I very confused with one-liner used in this code (5th line in the below code).</p>
<p>Can someone please explain to me how this one liner is working? May be re-write in verbose way?</p>
<pre><code>multiset = [2, 2, 3, 3, 4, 5, 6, 7, 8, 10]
x = [0]
deltaSet = set(multiset)
for candi... | 1 | 2016-07-06T03:55:24Z | 38,216,161 | <p>I believe the line you are looking at is:</p>
<pre><code>sum([(abs(candidate-member) in multiset) for member in x])
</code></pre>
<p>First, there are far too many parenthesis there. Lets get rid of the stuff we don't need:</p>
<pre><code>sum(abs(candidate-member) in multiset for member in x)
</code></pre>
<p>Ph... | 7 | 2016-07-06T04:04:57Z | [
"python"
] |
How to set width and input limit of NumberInput widget for IntegerField in a Django form | 38,216,135 | <p>I'm looking for a way to change the width of the input box in a Django form.</p>
<p>The model code for a parameter looks like this:</p>
<pre><code>my_integer = models.IntegerField('Window', default=50)
</code></pre>
<p>and putting it into a form, the HTML code that is generated is this:</p>
<pre><code><input ... | 0 | 2016-07-06T04:02:00Z | 38,218,670 | <p>The arrow controls are a part of the <code>NumberInput</code> widget, so you'll have to use that. Unfortunately, in current HTML, there is no support for the <code>size</code> and <code>maxlength</code> attributes for the number input field <code><input type="number"></code>.</p>
<p>The width of the field is... | 0 | 2016-07-06T07:42:22Z | [
"python",
"html",
"css",
"django"
] |
LoginRequiredMixin, How to get and use the redirect_field_name? | 38,216,165 | <p>I don't know whether this is the correct way to use this, if not, please let me know:</p>
<p>I have a view protected with the mixin like this:</p>
<pre><code>class ControlPanel_vw(LoginRequiredMixin, DetailView):
template_name = 'controlPanel.html'
login_url = '/login/'
redirect_field_name = 'next'
</c... | 0 | 2016-07-06T04:05:14Z | 38,216,482 | <p><code>form_valid()</code> is called from the <code>FormView</code>s <code>post()</code> method, which it runs only when there is POSTed form data. </p>
<p>You are saving <code>self.next</code> in the <code>get()</code> method which will not be called when there is a POST request - hence the value is not set when yo... | 0 | 2016-07-06T04:49:57Z | [
"python",
"django"
] |
LoginRequiredMixin, How to get and use the redirect_field_name? | 38,216,165 | <p>I don't know whether this is the correct way to use this, if not, please let me know:</p>
<p>I have a view protected with the mixin like this:</p>
<pre><code>class ControlPanel_vw(LoginRequiredMixin, DetailView):
template_name = 'controlPanel.html'
login_url = '/login/'
redirect_field_name = 'next'
</c... | 0 | 2016-07-06T04:05:14Z | 38,254,485 | <p>I removed the <code>get</code> method and added the <code>get_context_data</code> instead:</p>
<pre><code>def get_context_data(self, **kwargs):
context = super(Login_vw, self).get_context_data(**kwargs)
context['next'] = self.request.GET.get('next')
return context
</code></pre>
<p>and then ... | 0 | 2016-07-07T20:14:31Z | [
"python",
"django"
] |
Force QTimer() timeout in PySide | 38,216,182 | <p>I have a pySide application which uses QTimer to refresh its status once a minute. In some cases I need to force an immediate update, and then restart the timer</p>
<pre><code>self.timer = QTimer()
self.timer.timeout.connect(self._update_status)
self.timer.start(60 * 1000)
</code></pre>
<p>Is there any way to for... | 1 | 2016-07-06T04:07:10Z | 38,229,501 | <p>The cleanest solution seems to be simply this:</p>
<pre><code> self.timer.start() # restart the timer
self.timer.timeout.emit() # force an immediate update
</code></pre>
<p>It is also possible to force an immediate update by calling <code>setInterval(1)</code>, but this has the disadvantage that you... | 1 | 2016-07-06T16:54:29Z | [
"python",
"pyqt",
"pyside"
] |
Using the subprocess module in python to run a lua script with command line inputs | 38,216,223 | <p>I have a Lua script with command line inputs that I would like to run in Python (2.7) and read the output. For example the code I would run in terminal (Ubuntu 14.xx) looks like:</p>
<pre><code>lua sample.lua -arg1 helloworld -arg2 "helloworld"
</code></pre>
<p>How do I run a Lua script with command line inputs in... | 1 | 2016-07-06T04:13:17Z | 38,216,249 | <p>try this:</p>
<pre><code>import subprocess
print subprocess.check_output('lua sample.lua -arg1 helloworld -arg2 "helloworld"', shell=True)
</code></pre>
| 1 | 2016-07-06T04:16:57Z | [
"python",
"python-2.7",
"command-line",
"lua",
"subprocess"
] |
Using the subprocess module in python to run a lua script with command line inputs | 38,216,223 | <p>I have a Lua script with command line inputs that I would like to run in Python (2.7) and read the output. For example the code I would run in terminal (Ubuntu 14.xx) looks like:</p>
<pre><code>lua sample.lua -arg1 helloworld -arg2 "helloworld"
</code></pre>
<p>How do I run a Lua script with command line inputs in... | 1 | 2016-07-06T04:13:17Z | 38,216,265 | <p>If you aren't sure, you can generally pass the verbatim string that works in the shell and split it with <code>shlex.split</code>:</p>
<pre><code>import shlex
subprocess.check_output(shlex.split('lua sample.lua -arg1 helloworld -arg2 "helloworld"'))
</code></pre>
<p>However, you <em>usually</em> don't need to do t... | 2 | 2016-07-06T04:18:41Z | [
"python",
"python-2.7",
"command-line",
"lua",
"subprocess"
] |
How to perform join for each of the value in array in rethinkdb | 38,216,355 | <p>I am working on a web platform that serves media content. I am adding 'follow' feature similar to twitter in the platform. Each user must get update from someone they follow in my platform.</p>
<p>I am confused on how to design the database for the 'follow' feature. This is what i tried.</p>
<p>User table containi... | 0 | 2016-07-06T04:30:57Z | 38,216,466 | <p>You probably want something like this:</p>
<pre><code>r.table('user').get(USER_ID)('follow').eqJoin(function(row) { return row; }, r.table('post'), {index: 'user_id'})
</code></pre>
| 1 | 2016-07-06T04:46:56Z | [
"python",
"join",
"rethinkdb"
] |
I'm really stuck with Python selenium module | 38,216,394 | <p>I was making a simple program which enables me to fill out the login form and send email to someone.. and while i'm on it, it just don't go more and stopped at opening some link.</p>
<pre><code># Practice Program!
import requests, os, bs4, webbrowser
from selenium import webdriver
url = 'http://google.com'
res =... | 1 | 2016-07-06T04:35:54Z | 38,216,698 | <p><code>Paasword</code> field is getting visible when you submit the <code>Email</code> so you need to implement <code>WebDriverWait</code> to wait until <code>password</code> field visible as below :-</p>
<pre><code>from selenium.webdriver.support import expected_conditions as EC
-------------
wait = WebDriverWait... | 1 | 2016-07-06T05:12:56Z | [
"python",
"selenium"
] |
I'm really stuck with Python selenium module | 38,216,394 | <p>I was making a simple program which enables me to fill out the login form and send email to someone.. and while i'm on it, it just don't go more and stopped at opening some link.</p>
<pre><code># Practice Program!
import requests, os, bs4, webbrowser
from selenium import webdriver
url = 'http://google.com'
res =... | 1 | 2016-07-06T04:35:54Z | 38,219,333 | <p>Actually your error message says:.NoSuchElementException: Message: Unable to locate element</p>
<p>And I see there is a next button on the google login page, right below the Email input box.</p>
<p>So you may click the next button to find the password input box</p>
| 0 | 2016-07-06T08:20:49Z | [
"python",
"selenium"
] |
Multiprocessing/threading on a function | 38,216,404 | <p>Right now my function is using 25% of my cpu, and I have 4 cores, so I'm guessing it's maxing out 1 core? </p>
<p>Anyway.. I need a way to run my function on 4 threads/processes to utilize all of my CPU, I have looked on stackoverflow how to do this already but they are all for functions that require arguments..min... | 0 | 2016-07-06T04:37:10Z | 38,216,604 | <p>Figured it out..</p>
<pre><code>if __name__ == '__main__':
jobs = []
for i in range(4):
p = multiprocessing.Process(target=loop)
jobs.append(p)
p.start()
</code></pre>
| 0 | 2016-07-06T05:02:17Z | [
"python",
"multithreading"
] |
How to find number is between some specified range in python? | 38,216,459 | <p>I want to find the number which is input for the Python function. The input value is not fixed; it may be in thousands, lacks or cores.</p>
<p>I'm using Python 2.7.</p>
<p>Example:</p>
<pre><code>def check(number):
if(10000 <= number <= 50000):
print "Number is between 10000 & 50000"
if(50... | 0 | 2016-07-06T04:46:23Z | 38,216,762 | <p>Your <code>num</code> is a string, and you're comparing it with integers. In Python 2 it is legal to compare a string with an integer, but the result will not be useful (in Python 3 it is an error) . </p>
<p>You need to call <code>check(int(num))</code> for the comparisons to work as intended. </p>
| 1 | 2016-07-06T05:18:53Z | [
"python",
"python-2.7",
"range"
] |
How to find number is between some specified range in python? | 38,216,459 | <p>I want to find the number which is input for the Python function. The input value is not fixed; it may be in thousands, lacks or cores.</p>
<p>I'm using Python 2.7.</p>
<p>Example:</p>
<pre><code>def check(number):
if(10000 <= number <= 50000):
print "Number is between 10000 & 50000"
if(50... | 0 | 2016-07-06T04:46:23Z | 38,216,813 | <p>You have to check <code>int(num)</code> instead of just <code>num</code>, because you need to compare <code>integer vs integer</code><br>
Also seems there is a typo error in your third condition </p>
<pre><code> if(100000 <= number <= 500000):
print "Number is between 100000 & 500000
</code></pre... | 0 | 2016-07-06T05:22:55Z | [
"python",
"python-2.7",
"range"
] |
Most intuitive way to parse several thousand different log types (with Python)? | 38,216,475 | <p>I'm interning at a small company this summer and have been tasked with parsing log files from a kinesis stream. This has an extremely high throughput, so I've been learning how to do 'real-time' parsing, for lack of a better term, so as to avoid bloating memory and incurring extra costs in lambda.</p>
<p>I went int... | 4 | 2016-07-06T04:49:14Z | 38,216,935 | <p>Assuming </p>
<ol>
<li>high frequency input</li>
<li>line delimited text</li>
<li>log schema of unknown semantics
<ol>
<li>dominated by some </li>
<li>long tail of rare "others"</li>
</ol></li>
</ol>
<p>I did in the past in python generator based processing in stages, which nicely scales. It does not automaticall... | 1 | 2016-07-06T05:36:11Z | [
"python",
"regex",
"parsing",
"bigdata",
"aws-lambda"
] |
Most intuitive way to parse several thousand different log types (with Python)? | 38,216,475 | <p>I'm interning at a small company this summer and have been tasked with parsing log files from a kinesis stream. This has an extremely high throughput, so I've been learning how to do 'real-time' parsing, for lack of a better term, so as to avoid bloating memory and incurring extra costs in lambda.</p>
<p>I went int... | 4 | 2016-07-06T04:49:14Z | 38,217,099 | <p>I can give you an answer only the following way:<br>
Multi-tool that can do everything is not the solution, it's almost not possible to write a tool that can parse any logs, and provide to you a right info on a fly for any types of logs. <strong>You have to maintain/support what you did.</strong></p>
<h1>TO DO PLAN... | 1 | 2016-07-06T05:52:18Z | [
"python",
"regex",
"parsing",
"bigdata",
"aws-lambda"
] |
Is RIDE 1.5.2.1 possible to work with Collection 3.0? | 38,216,690 | <p>I am using RIDE 1.5.2.1 running on Python 2.7.11 but found some features from Collections 3.0 are not existing.
Can I upgrade upgrade Ride but still use Python 2.7? Or there is a way to only upgrade the collections library?
Thanks.</p>
| 0 | 2016-07-06T05:11:36Z | 38,220,509 | <p>As the collections library is a builtin library, you will need to upgrade to Robot Framework 3.0 to get those non-existing changes, you won't be able to get it individually. It should work with Python 2.7 without issue.</p>
| 1 | 2016-07-06T09:24:10Z | [
"python",
"robotframework"
] |
What will be the benefits of type hinting in Python? | 38,216,974 | <p>I was reading through the <a href="https://www.python.org/dev/peps/pep-0484/#abstract">PEP 484 -- Type Hints</a></p>
<p>when it is implemented, the function specifies the type of arguments it accept and return.</p>
<pre><code>def greeting(name: str) -> str:
return 'Hello ' + name
</code></pre>
<p>My questi... | 7 | 2016-07-06T05:41:09Z | 38,217,169 | <p>Type hinting can help with:</p>
<ol>
<li>Data validation and quality of code (you can do it with assert too).</li>
<li>Speed of code if code with be compiled since some assumption can be taken and better memory management.</li>
<li>Documentation code and readability.</li>
</ol>
<p>I general lack of type hinting is... | 4 | 2016-07-06T05:58:26Z | [
"python",
"types",
"pep"
] |
What will be the benefits of type hinting in Python? | 38,216,974 | <p>I was reading through the <a href="https://www.python.org/dev/peps/pep-0484/#abstract">PEP 484 -- Type Hints</a></p>
<p>when it is implemented, the function specifies the type of arguments it accept and return.</p>
<pre><code>def greeting(name: str) -> str:
return 'Hello ' + name
</code></pre>
<p>My questi... | 7 | 2016-07-06T05:41:09Z | 38,217,786 | <p>Take an example of the typed function,</p>
<pre><code>def add1(x: int, y: int) -> int:
return x + y
</code></pre>
<p>and a general function.</p>
<pre><code>def add2(x,y):
return x + y
</code></pre>
<p>Type checking with mypy on <code>add1</code></p>
<pre><code>add1("foo", "bar")
</code></pre>
<p>wou... | 3 | 2016-07-06T06:48:50Z | [
"python",
"types",
"pep"
] |
interdependent widgets in bokeh | 38,217,071 | <p>In <code>bokeh</code>, I would like to adjust the possible options in one <code>Select</code> widget depending on the chosen value in another <code>Select</code> widget. My minimally not-working example looks like this:</p>
<pre><code>from bokeh.io import output_notebook, show
from bokeh.layouts import column
from... | 0 | 2016-07-06T05:49:39Z | 38,235,174 | <p>Inspired by Bryan's (bigreddot's) comment I successfully tried this. It can be served with <code>bokeh serve main.py</code></p>
<pre><code>'''
with inspiration from
https://github.com/bokeh/bokeh/blob/master/examples/app/stocks/main.py
'''
from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.mod... | 1 | 2016-07-06T23:02:13Z | [
"python",
"widget",
"bokeh"
] |
multi-threading in Python with pulp | 38,217,097 | <p>I have a function which accepts a list R. In this function, I have defined an optimization problem using "pulp", This is my function:</p>
<pre><code>import pulp
from multiprocessing.dummy import Pool as ThreadPool
def optimize(R):
variables = ["x1","x2","x3","x4"]
costs = {"x1":R[0], "x2":R[1], "x3":R[2]... | 0 | 2016-07-06T05:51:52Z | 38,232,601 | <p>I have seen that class <a href="https://pythonhosted.org/PuLP/solvers.html" rel="nofollow"><code>pulp.solvers.COIN_CMD</code></a> has a <code>threads</code> argument, although the documentation is quite laconic. Taking a look at the code source, it seems to be indeed a way to provide threads to the solver.</p>
<p>I... | 1 | 2016-07-06T19:50:45Z | [
"python",
"multithreading"
] |
Python pandas transpose data issue | 38,217,156 | <p>I am having trouble figuring out how to properly transpose data in a DataFrame in order to calculate differences between actuals and targets. Doing something like: <br> <code>df['difference'] = df['Revenue'] - df['Target']</code>, <br> is straightforward so this is more a question of desired output formatting.</p>
... | 1 | 2016-07-06T05:57:14Z | 38,218,638 | <h3>Setup</h3>
<pre><code>df = pd.DataFrame([
['2016-06-01', 15000, 10000, 1000, 900, 100, 50, 'US'],
['2016-06-01', 16000, 12000, 1500, 1200, 150, 100, 'UK']
], columns=['Date', 'Revenue', 'Target', 'Users', 'Target', 'New Users', 'Target', 'Source'])
df
</code></pre>
<p><a href="http://i.stack.i... | 1 | 2016-07-06T07:40:41Z | [
"python",
"pandas"
] |
selenium.click() - block redirect | 38,217,292 | <p>I want to figure out (in a general way) the target url of a clickable element without being redirected by the browser. Is this possible in Selenium?</p>
<p>Note, the clickable element generates the target url in a Javascript function. Hence, grabbing the href attribute of the element is not the solution for me.</p>... | 0 | 2016-07-06T06:09:55Z | 38,219,898 | <p>If you just want to get <code>URL</code> that generated by clicking on provided <code><a></code> element you don't need to use <code>Selenium</code> at all. You can just use the same algorithm in <code>Python</code> to get required <code>URL</code> value:</p>
<pre><code>import random
random_page = random.rand... | 0 | 2016-07-06T08:53:23Z | [
"python",
"selenium",
"redirect",
"onclick"
] |
Dronekit python goto_position_target_local_ned() | 38,217,297 | <p>Running dronekit-python with ArduCopter as SITL was successful.(APM:Copter V3.4-dev)</p>
<p>Then,I run the same code on the real copter(APM:Copter V3.2.1) is not work.
The code is from dronekit's example.
Any ideas or pointers are appreciated.</p>
| 0 | 2016-07-06T06:10:23Z | 38,236,476 | <p>Try flying with APM:Copter 3.3</p>
| 0 | 2016-07-07T01:48:07Z | [
"python",
"dronekit"
] |
How to auto format numbers in form field django when user input value | 38,217,338 | <p>I have a Decimal field in form.py like this:
`</p>
<pre><code>quantity = forms.DecimalField(required=True, widget=forms.NumberInput(
attrs={'class': 'form-control item-quantity', 'style': 'text-align: right'}),
error_messages={'required': 'This field is required.'}, localize=True)
</code></pre>
<p>In html... | -1 | 2016-07-06T06:13:55Z | 38,217,583 | <pre><code>total=100000
print ("Total cost is: ${:,.2f}".format(total)
</code></pre>
<blockquote>
<p>first of all you convert your o/p in string then after store in database try it....</p>
</blockquote>
<p>lol.. sorry for my bad english :)</p>
| 0 | 2016-07-06T06:34:04Z | [
"python",
"django"
] |
How to auto format numbers in form field django when user input value | 38,217,338 | <p>I have a Decimal field in form.py like this:
`</p>
<pre><code>quantity = forms.DecimalField(required=True, widget=forms.NumberInput(
attrs={'class': 'form-control item-quantity', 'style': 'text-align: right'}),
error_messages={'required': 'This field is required.'}, localize=True)
</code></pre>
<p>In html... | -1 | 2016-07-06T06:13:55Z | 38,217,608 | <p>I'm not sure if I understand your requirements correctly, but I think I have the gist of it:</p>
<ol>
<li>User can enter data in a form (numerical) which will be saved to the database as an integer</li>
<li>When the data is next presented to the user (for editing?) it will be formatted with commas (1,000 | 100,000 ... | 0 | 2016-07-06T06:35:39Z | [
"python",
"django"
] |
How to auto format numbers in form field django when user input value | 38,217,338 | <p>I have a Decimal field in form.py like this:
`</p>
<pre><code>quantity = forms.DecimalField(required=True, widget=forms.NumberInput(
attrs={'class': 'form-control item-quantity', 'style': 'text-align: right'}),
error_messages={'required': 'This field is required.'}, localize=True)
</code></pre>
<p>In html... | -1 | 2016-07-06T06:13:55Z | 38,217,651 | <p>In addition to above format localization comment, in the template you can formatting numbers as follows.</p>
<pre><code><!DOCTYPE html>
{% load humanize %}
{% for post in posts %}
Views : {{ post.views|intcomma }}
{% endfor %}
</code></pre>
| 0 | 2016-07-06T06:38:56Z | [
"python",
"django"
] |
How to put a variable inside of a variable in python | 38,217,399 | <p>I want to use a do something like:</p>
<pre><code>i = 3
stored_number_i
</code></pre>
<p>Where <code>i</code> is 3</p>
<p>Is there a way to do this, or is it impossible? Is there at least a decent alternative?</p>
| -3 | 2016-07-06T06:20:17Z | 38,217,479 | <p>There is no inbuilt way to do this. You may find it useful to create your own datatype; namely a class.</p>
<p>That way, you can design the way data is stored in your "variable".</p>
| 0 | 2016-07-06T06:26:15Z | [
"python"
] |
How to put a variable inside of a variable in python | 38,217,399 | <p>I want to use a do something like:</p>
<pre><code>i = 3
stored_number_i
</code></pre>
<p>Where <code>i</code> is 3</p>
<p>Is there a way to do this, or is it impossible? Is there at least a decent alternative?</p>
| -3 | 2016-07-06T06:20:17Z | 38,217,511 | <p>Make a dummy class via</p>
<pre><code>class dummy():
pass
</code></pre>
<p>Then you can do <code>a=dummy()</code> to create your new object.</p>
<p>To set attributes you can either do <code>a.blarg=4</code> or <code>setattr(a,'blarg',4)</code>
This then gives you the possibility of doing something like you desc... | 0 | 2016-07-06T06:28:34Z | [
"python"
] |
How to put a variable inside of a variable in python | 38,217,399 | <p>I want to use a do something like:</p>
<pre><code>i = 3
stored_number_i
</code></pre>
<p>Where <code>i</code> is 3</p>
<p>Is there a way to do this, or is it impossible? Is there at least a decent alternative?</p>
| -3 | 2016-07-06T06:20:17Z | 38,218,021 | <p>If you really want to, you can do so in two ways:</p>
<ul>
<li><p>You can directly modify the <code>globals</code> dictionary, which holds all global variables of a module:</p>
<pre><code>globals()['stored_number_%s' % i] = "content of my programmatically created variable"
</code></pre></li>
<li><p>You can <code>e... | 0 | 2016-07-06T07:03:17Z | [
"python"
] |
How to put a variable inside of a variable in python | 38,217,399 | <p>I want to use a do something like:</p>
<pre><code>i = 3
stored_number_i
</code></pre>
<p>Where <code>i</code> is 3</p>
<p>Is there a way to do this, or is it impossible? Is there at least a decent alternative?</p>
| -3 | 2016-07-06T06:20:17Z | 38,219,618 | <p>Sounds like you are looking for a <code>dict</code>.</p>
<pre><code>stored_number = {23: 1, 1: 17, 3: 42}
print(stored_number[i])
</code></pre>
<p>prints <code>42</code> when <code>i</code> is 3.</p>
| 1 | 2016-07-06T08:38:17Z | [
"python"
] |
conditional add statement in SQLAlchemy | 38,217,405 | <p>Suppose I want to upload several SQL records, to a table that may not be populated yet. If there is a record with a primary key("ID") that already exists, either in the table or in the records to be committed to a table, I want to replace the existing record with the new record.
I'm using mssql, SQL server 2008.</... | 0 | 2016-07-06T06:20:38Z | 38,217,850 | <p>No. There is a much better pattern for doing this. Do a query first to see if the record already exists, and then proceed accordingly. </p>
<p>Using your syntax, it would be something like the following:</p>
<pre><code>result = session.query().filter(Class.ID == record.ID).first()
# If record does not exist i... | 0 | 2016-07-06T06:52:46Z | [
"python",
"sql-server",
"sql-server-2008",
"sqlalchemy"
] |
conditional add statement in SQLAlchemy | 38,217,405 | <p>Suppose I want to upload several SQL records, to a table that may not be populated yet. If there is a record with a primary key("ID") that already exists, either in the table or in the records to be committed to a table, I want to replace the existing record with the new record.
I'm using mssql, SQL server 2008.</... | 0 | 2016-07-06T06:20:38Z | 38,218,614 | <p>In general unless using statements that guarantee atomicity, you'll always have to account for race conditions that might arise from multiple actors trying to either insert or update (don't forget delete). Even the <a href="https://msdn.microsoft.com/en-us/library/bb510625.aspx" rel="nofollow">MERGE statement</a>, t... | 2 | 2016-07-06T07:39:36Z | [
"python",
"sql-server",
"sql-server-2008",
"sqlalchemy"
] |
Python multiprocessing slower than single thread | 38,217,449 | <p>I have been playing around with multiprocessing problem and notice my algorithm is slower when I parallelizes it than when it is single thread.</p>
<p>In my code I don't share memory.
And I'm pretty sure my algorithm (see code), which is just nested loops is CPU bound. </p>
<p>However, no matter what I do. The par... | 1 | 2016-07-06T06:24:00Z | 38,217,733 | <p>You are using <em>multithreading</em>, not <em>multiprocessing</em>. While many languages allow threads to run in parallel, python does not. A thread is just a separate state of control, i.e. it holds it own stack, current function, etc. The python interpreter just switches between executing each stack every now and... | 6 | 2016-07-06T06:44:42Z | [
"python",
"multithreading"
] |
Getting the row and column numbers that meets multiple conditions in Pandas | 38,217,462 | <p>I am trying to get the <code>row</code> and <code>column</code> number, which meets three conditions in Pandas DataFrame.</p>
<p>I have a DataFrame of <code>0</code>, <code>1</code>, <code>-1</code> (bigger than <code>1850</code>); when I try to get the <code>row</code> and <code>column</code> it takes forever to g... | 0 | 2016-07-06T06:25:07Z | 38,217,580 | <p>You are right <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html" rel="nofollow"><code>np.where</code></a> would be one way to do it. Here's an implementation with it -</p>
<pre><code># Extract the values from c into an array for ease in further processing
c_arr = c.values
# Use np.wher... | 1 | 2016-07-06T06:33:44Z | [
"python",
"numpy",
"pandas"
] |
How to open a csv file for reading purpose using mmap in python? | 38,217,514 | <p>I want to open csv file for reading purpose. But I'm facing some exceptions regarding to that.</p>
<p>I'm using Python 2.7.</p>
<p><strong>main.python-</strong> </p>
<pre><code>if __name__ == "__main__":
f = open('input.csv','r+b')
m = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)
reader = csv.DictReade... | 1 | 2016-07-06T06:28:43Z | 38,217,790 | <p>if you just want to read data with specific columnes from csv file, just try:</p>
<pre><code>import csv
with open('input.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print row['time']
</code></pre>
| 0 | 2016-07-06T06:49:07Z | [
"python",
"csv"
] |
How to open a csv file for reading purpose using mmap in python? | 38,217,514 | <p>I want to open csv file for reading purpose. But I'm facing some exceptions regarding to that.</p>
<p>I'm using Python 2.7.</p>
<p><strong>main.python-</strong> </p>
<pre><code>if __name__ == "__main__":
f = open('input.csv','r+b')
m = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)
reader = csv.DictReade... | 1 | 2016-07-06T06:28:43Z | 38,218,133 | <p>When open a file with the flag <code>b</code> like this:</p>
<pre><code>f = open('input.csv','r+b')
</code></pre>
<p><strong>You read the file as bytes</strong> and not as string.<br></p>
<p>So, try to change the flags to <code>r</code>:</p>
<pre><code>f = open('input.csv','r')
</code></pre>
| 0 | 2016-07-06T07:09:52Z | [
"python",
"csv"
] |
How to open a csv file for reading purpose using mmap in python? | 38,217,514 | <p>I want to open csv file for reading purpose. But I'm facing some exceptions regarding to that.</p>
<p>I'm using Python 2.7.</p>
<p><strong>main.python-</strong> </p>
<pre><code>if __name__ == "__main__":
f = open('input.csv','r+b')
m = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)
reader = csv.DictReade... | 1 | 2016-07-06T06:28:43Z | 38,444,022 | <p>I know you asked this a while ago, but I actually created a module for myself that does this, because I do a lot of work with large CSV files, and sometimes I need to convert them into dictionaries, based on a key. Below is the code I've been using. Please feel free to modify as needed.</p>
<pre><code>def MmapCsv... | 0 | 2016-07-18T18:51:05Z | [
"python",
"csv"
] |
the different between pyenv, virtualenv, anaconda in python | 38,217,545 | <p>I am a ruby programmer trying to learn python. I am pretty family with pyenv since it is like a copy and paste from rbenv. Pyenv helps allow to have more than one version of python in a system and also to isolate the python without touching sensitive part of system.</p>
<p>I suppose every python installation come w... | 5 | 2016-07-06T06:31:10Z | 39,928,067 | <p><em>Edit: It's worth mentioning <code>pip</code> here as well, as <code>conda</code> and <code>pip</code> have similarities and differences that are relevant to this topic</em>.</p>
<p><strong>pip: the Python Package Manager.</strong></p>
<ul>
<li>You might think of <code>pip</code> as the python equivalent of the... | 2 | 2016-10-08T02:22:57Z | [
"python",
"pip",
"virtualenv",
"pyenv"
] |
My if/else doesn't work correct | 38,217,562 | <p>I was trying to solve a king move(chess) task. I found out that king can move only if it's coordinates <code>-1 <= x1-x2 and y1-y2 <= 1</code>.
My code is:</p>
<pre><code>x1 = int(input()) #cuurent x-position
y1 = int(input()) #current y-position
x2 = int(input()) #estim... | -1 | 2016-07-06T06:32:34Z | 38,217,619 | <p>A king can move if the <strong>absolute difference</strong> between the co-ordinates is less than or equal to 1. </p>
<p>So, write:</p>
<pre><code>if abs(x1-x2) <= 1 and abs(y1-y2) <= 1: #king can move to the x2-y2 from x1-y1
print('YES')
else: #king can't move to the x2-y2 from... | 4 | 2016-07-06T06:36:15Z | [
"python",
"if-statement",
"comparison",
"chess"
] |
Python 3.5.1 - Assign variables to all Files (Filetype: .jpg) inside target folder | 38,217,688 | <p>I am fairly new to Python and have a difficult Problem to solve:</p>
<p>Here is what I am trying to do --></p>
<ol>
<li>I have a Folder (path known) with 1 - x picture files (.jpg) in it, whereas x can be as high as 1000</li>
<li>These picture files should be stiched together (one on top of the other)</li>
<li>To ... | 2 | 2016-07-06T06:40:59Z | 38,217,861 | <p>Why not use a container such as a <code>list</code>?</p>
<pre><code>images = [Image.open(img_name) for img_name in os.listdir(my_folder) if img_name.endswith('.jpg')
def merge_images(list_images):
result_width = max(img.size[0] for img in images)
result_height = sum(img.size[1] for img in images)
result... | 1 | 2016-07-06T06:53:20Z | [
"python",
"python-2.7",
"python-3.x"
] |
Python 3.5.1 - Assign variables to all Files (Filetype: .jpg) inside target folder | 38,217,688 | <p>I am fairly new to Python and have a difficult Problem to solve:</p>
<p>Here is what I am trying to do --></p>
<ol>
<li>I have a Folder (path known) with 1 - x picture files (.jpg) in it, whereas x can be as high as 1000</li>
<li>These picture files should be stiched together (one on top of the other)</li>
<li>To ... | 2 | 2016-07-06T06:40:59Z | 38,217,874 | <p>If you start with a 0x0 image, you can stack further images onto it like this:</p>
<pre><code>stacked_img = Image.new('RGB', (0, 0))
for filename in glob.glob('*.jpg'):
stacked_img = merge_images(stacked_img, Image.open(filename))
stacked_img.save('stacked.jpg')
</code></pre>
<p>You might also like to change... | 3 | 2016-07-06T06:54:04Z | [
"python",
"python-2.7",
"python-3.x"
] |
Python 3.5.1 - Assign variables to all Files (Filetype: .jpg) inside target folder | 38,217,688 | <p>I am fairly new to Python and have a difficult Problem to solve:</p>
<p>Here is what I am trying to do --></p>
<ol>
<li>I have a Folder (path known) with 1 - x picture files (.jpg) in it, whereas x can be as high as 1000</li>
<li>These picture files should be stiched together (one on top of the other)</li>
<li>To ... | 2 | 2016-07-06T06:40:59Z | 38,219,129 | <p>this is my code in which I implemented your approach. As a result, I am getting an image where 2 of the 4 images are displayed and the rest of the image is black. In the source directory I have 4 images (img1.jpg - img4.jpg)</p>
<pre><code>from PIL import Image
import glob
stacked_img = Image.new('RGB', (0,0))
d... | 0 | 2016-07-06T08:08:46Z | [
"python",
"python-2.7",
"python-3.x"
] |
get all elements in a loop through xpath | 38,217,855 | <p>I am currently learning selenium using python</p>
<p>html is:</p>
<pre><code><ol class="item-section">
<li>
<div class="abc xyz">
<div class="foo qwe">
<a href="/watch123"></a>
</div>
</div>
</li>
<li&g... | 0 | 2016-07-06T06:52:58Z | 38,218,694 | <p>You can get the list of elements using</p>
<pre><code>driver.find_elements_by_xpath("//div[@class='foo qwe']/a")
or
from selenium.webdriver.common.by import By
inputs = driver.find_elements(By.XPATH, "//div[@class='foo qwe']/a")
</code></pre>
| 0 | 2016-07-06T07:43:17Z | [
"python",
"selenium",
"xpath"
] |
why post request has different result? | 38,217,958 | <p>I have use curl in linux to post data to asana and its work fine.</p>
<pre><code>curl -H "Authorization: Bearer <mytoken>" https://app.asana.com/api/1.0/tasks/101/stories -d "text=hello world"
</code></pre>
<p>but if I use requests library for python the result is 400</p>
<pre><code>response = requests.post... | 0 | 2016-07-06T06:59:12Z | 38,218,006 | <p>You need to add the same "Authorization: Bearer" token header to your request in python. Similar to this answer:</p>
<p><a href="http://stackoverflow.com/a/29931730/6080374">http://stackoverflow.com/a/29931730/6080374</a></p>
| 0 | 2016-07-06T07:02:41Z | [
"python",
"curl",
"python-requests",
"asana-api"
] |
why post request has different result? | 38,217,958 | <p>I have use curl in linux to post data to asana and its work fine.</p>
<pre><code>curl -H "Authorization: Bearer <mytoken>" https://app.asana.com/api/1.0/tasks/101/stories -d "text=hello world"
</code></pre>
<p>but if I use requests library for python the result is 400</p>
<pre><code>response = requests.post... | 0 | 2016-07-06T06:59:12Z | 38,218,127 | <p>The <code>auth</code> argument to <code>requests</code> methods produces a <code>Authorization: Basic</code> header, not a <code>Authorization: Bearer</code> header.</p>
<p>Set a <code>headers</code> dictionary with a manually created <code>Authorization</code> header instead. POST data (the <code>-d</code> command... | 0 | 2016-07-06T07:09:43Z | [
"python",
"curl",
"python-requests",
"asana-api"
] |
Need to ask user if they want to repeat with for loop (Python) | 38,218,015 | <pre><code>myList = []
numbers = int(input("How many numbers would you like to enter? "))
for numbers in range(1,numbers + 1):
x = int(input("Please enter number %i: " %(numbers)))
myList.append(x)
b = sum(x for x in myList if x < 0)
for x in myList:
print("Sum of negatives = %r" %(b))
break
c = su... | 0 | 2016-07-06T07:03:05Z | 38,218,111 | <p>You can try something like this:</p>
<p>Keep a variable which asks the users if they want to play the game or not and in the end ask them again.</p>
<pre><code>k = input("Do you want to play the game? Press y/n")
while k == 'y':
myList = []
numbers = int(input("How many numbers would you like to enter? ")... | 0 | 2016-07-06T07:08:43Z | [
"python"
] |
Need to ask user if they want to repeat with for loop (Python) | 38,218,015 | <pre><code>myList = []
numbers = int(input("How many numbers would you like to enter? "))
for numbers in range(1,numbers + 1):
x = int(input("Please enter number %i: " %(numbers)))
myList.append(x)
b = sum(x for x in myList if x < 0)
for x in myList:
print("Sum of negatives = %r" %(b))
break
c = su... | 0 | 2016-07-06T07:03:05Z | 38,218,354 | <p>You're exiting the loop when you hit break, so that won't work either. </p>
<p>Use a while loop, and think of the problem in another way: Assume the user will enter more input, and ask if he/she wants to quit.</p>
<p>I think this is what you're looking for (assuming you're using Python 3):</p>
<pre><code>myList... | 0 | 2016-07-06T07:24:25Z | [
"python"
] |
Pivoting Dataframe with Pandas | 38,218,063 | <p>I have the below table taken online through <code>pandas.read_html</code> </p>
<pre><code> Column0 Column1 Column2 Column3
0 Entry_1 0.685 Record_1 0.69-S$ 0.685
1 Entry_2 0.036 Record_2 0.685
2 Entry_3 05/Jul/2016 Record_3 0.72-S$ 0.4
3 Entry_4 ... | 0 | 2016-07-06T07:05:45Z | 38,218,427 | <p>I suggest you use the method <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pivot.html" rel="nofollow">DataFrame.pivot</a> as the following example:</p>
<pre><code>import pandas as pd
import numpy as np
import pandas.util.testing as tm; tm.N = 3
def unpivot(frame):
N, K = frame.... | 0 | 2016-07-06T07:28:56Z | [
"python",
"numpy",
"pandas"
] |
Pivoting Dataframe with Pandas | 38,218,063 | <p>I have the below table taken online through <code>pandas.read_html</code> </p>
<pre><code> Column0 Column1 Column2 Column3
0 Entry_1 0.685 Record_1 0.69-S$ 0.685
1 Entry_2 0.036 Record_2 0.685
2 Entry_3 05/Jul/2016 Record_3 0.72-S$ 0.4
3 Entry_4 ... | 0 | 2016-07-06T07:05:45Z | 38,223,873 | <p>You can use <code>lreshape</code> for create new columns, then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> from <code>Col</code>, transpose by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.... | 1 | 2016-07-06T12:21:12Z | [
"python",
"numpy",
"pandas"
] |
Pivoting Dataframe with Pandas | 38,218,063 | <p>I have the below table taken online through <code>pandas.read_html</code> </p>
<pre><code> Column0 Column1 Column2 Column3
0 Entry_1 0.685 Record_1 0.69-S$ 0.685
1 Entry_2 0.036 Record_2 0.685
2 Entry_3 05/Jul/2016 Record_3 0.72-S$ 0.4
3 Entry_4 ... | 0 | 2016-07-06T07:05:45Z | 38,223,968 | <p>This is probably the easiest way to solve this problem. The easiest way I could come up with anyway.</p>
<pre><code>Column0 Column1 Column2 Column3
0 Entry_1 0.685 Record_1 0.69-S$ 0.685
1 Entry_2 0.036 Record_2 0.685
2 Entry_3 05/Jul/2016 Record_3 0.72-S$ 0.4
3 Entr... | 1 | 2016-07-06T12:26:33Z | [
"python",
"numpy",
"pandas"
] |
Different Import statements for different classes in same .py file? | 38,218,091 | <p>In Python, I have seen that the practice of multiple classes in the same <code>module</code> or <code>.py file</code> is prevalent. But if the different classes use entirely different packages, is it possible to selectively specify import statements for the classes?</p>
<p>Is the following(or some variation) possib... | 0 | 2016-07-06T07:07:44Z | 38,218,510 | <p>This is perfectly possible:</p>
<pre><code>import collections
class Foobar(collections.OrderedDict):
pass
import weakref
class Barfoo(weakref.WeakKeyDictionary):
pass
</code></pre>
<p>For readability, you <a href="https://www.python.org/dev/peps/pep-0008/#imports" rel="nofollow">should</a> have your <code>imp... | 1 | 2016-07-06T07:33:53Z | [
"python",
"import"
] |
How to save changed fields with ModelForm? | 38,218,113 | <p>I want to save changed values of ModelForm to database. I'm having problems even I follow this documentation if I'm right that it can be possible with initial values: <a href="https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#providing-initial-values" rel="nofollow">Documentation- providing initial valu... | 0 | 2016-07-06T07:08:44Z | 38,221,041 | <p>The <code>initial</code> argument and the <code>instance</code> argument in your call to <code>SettingsForm()</code> serve the exact same purpose, because you are using the fields of the <code>instance</code> individually in each field of <code>initial</code>.</p>
<p>The save() method is not working because you nee... | 1 | 2016-07-06T09:49:21Z | [
"python",
"django",
"django-models",
"django-forms"
] |
Pip uninstall Scrapy with all its dependencies | 38,218,132 | <p>I had installed Scrapy with <code>pip install scrapy</code>. It also install all its requirement packages <code>Installing collected packages: zope.interface, Twisted, six, cssselect, w3lib, parsel, pycparser, cffi, pyasn1, idna, cryptography, pyOpenSSL, attrs, pyasn1-modules, service-identity, queuelib, PyDispatche... | -1 | 2016-07-06T07:09:50Z | 38,218,276 | <p><code>pip uninstall</code> currently doesn't support removing the dependencies. You can manually go to the folder where scrapy is installed and delete it. For example: <code>/usr/local/lib/python2.7/dist-packages/scrapy</code>. </p>
<p>For example if it is at <code>'/PATH/TO/SCRAPY'</code>, run this command on the ... | 1 | 2016-07-06T07:19:13Z | [
"python",
"python-3.x",
"pip"
] |
Pip uninstall Scrapy with all its dependencies | 38,218,132 | <p>I had installed Scrapy with <code>pip install scrapy</code>. It also install all its requirement packages <code>Installing collected packages: zope.interface, Twisted, six, cssselect, w3lib, parsel, pycparser, cffi, pyasn1, idna, cryptography, pyOpenSSL, attrs, pyasn1-modules, service-identity, queuelib, PyDispatche... | -1 | 2016-07-06T07:09:50Z | 38,218,628 | <p>It is a bit contrived but you can use something like this</p>
<pre><code>for p in `pip show scrapy | grep 'Requires:' | tr ',' ' ' | cut -d " " -f2-`;
do
pip uninstall $p;
done;
</code></pre>
| 0 | 2016-07-06T07:40:13Z | [
"python",
"python-3.x",
"pip"
] |
snapshot.wait_until_completed doesn't show progress nor when it has completed | 38,218,141 | <p>I have a small function which is responsible for creating the snapshots , it works fine; but i want to get the progress as well , but the following function doesn't help me:</p>
<pre><code>def call_creater():
regions = ['eu-central-1']
for region in regions:
ec2 = boto3.resource('ec2', region, aws_a... | 0 | 2016-07-06T07:10:22Z | 38,218,486 | <p><a href="http://boto3.readthedocs.io/en/latest/reference/services/ec2.html#EC2.Snapshot.wait_until_completed" rel="nofollow"><code>wait_until_completed</code> should wait for a maximum of about 10 minutes</a>, which is nowhere near enough for a big snapshot, and <a href="https://github.com/boto/boto3/issues/705" rel... | 1 | 2016-07-06T07:32:38Z | [
"python",
"boto3"
] |
Hive Data to Pandas Data frame | 38,218,200 | <p>Newbie to Python.</p>
<p>How can i save the data from hive to Pandas data frame.</p>
<p>With pyhs2.connect(host, port=20000,authMechanism="PLAIN",user,password,
database) as conn:
With conn.cursor() as cur:
#Show databases
print cur.getDatabases()</p>
<pre><code> #Execute que... | -1 | 2016-07-06T07:14:40Z | 38,237,979 | <p>As I had fetched data before and was trying to fetch again, so was getting empty Data Frame. </p>
<pre><code>cur.execute(query)
val=cur.fetchall()
columnNames = [a['columnName'] for a in cur.getSchema()]
df=pd.DataFrame(data=val,columns=columnNames)
#print df
return df
</code></pre>
| 0 | 2016-07-07T05:18:35Z | [
"python",
"python-2.7",
"hadoop",
"pandas",
"hive"
] |
Tensorflow: ImportError for graph_util from tensorflow.python.framework | 38,218,274 | <p>I am trying to go through the <a href="https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/index.html" rel="nofollow">TensorFlow for Poets Codelab</a> on OS X El Capitan, Python 2.7 (via HomeBrew), and TensorFlow 0.9.0. Instead of using Docker as instructed, I installed TensorFlow with pip and I clo... | 0 | 2016-07-06T07:19:03Z | 38,263,841 | <p>Since this was the number 1 google result for me when I searched for this problem, I'll suggest a workaround which works (until tensorflow/examples get updated):</p>
<p>In <code>examples/image_retraining/retrain.py</code></p>
<pre><code>CHANGE
from `tensorflow.python.framework import graph_util`
TO
from `tensorflo... | 1 | 2016-07-08T09:59:45Z | [
"python",
"tensorflow"
] |
Create multiple texts files from data in an original text file | 38,218,395 | <p>I have an original text file with 100 rows and 40 columns of data.
I would like to write an individual text file for each data row of the original text file.</p>
<p>I can only work out how to do it the long way:</p>
<pre><code>Data = loadtxt('Data.txt')
Row1 = Data[0,:]
np.savetxt('Row1.txt', [Row1])
Row2 = Da... | 1 | 2016-07-06T07:27:30Z | 38,218,601 | <p>You're on the right track. This should give you files with names corresponding to each line number:</p>
<pre><code>counter = 0
with open("sampleInput.txt",'rU') as f:
for i in f:
newFileName = 'newFile_'+str(counter)
outFile = open(newFileName,'w')
outFile.write(i)
outFile.clos... | 0 | 2016-07-06T07:39:09Z | [
"python",
"python-2.7",
"numpy",
"text"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.