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 |
|---|---|---|---|---|---|---|---|---|---|
Categorical values on the x-axis with xlsxwriter | 39,499,563 | <p>I have a plot that needs names as the values for the x-axis. I imagine this is accomplished via the set_x_axis function for chart objects but can't find the proper key in the documentation (<a href="http://xlsxwriter.readthedocs.io/chart.html#set_x_axis" rel="nofollow">http://xlsxwriter.readthedocs.io/chart.html#set... | 1 | 2016-09-14T20:59:33Z | 39,505,730 | <p>Just set the series categories to point to the strings, or numbers, or dates that you wish to plot.</p>
<p>For example:</p>
<pre><code>import xlsxwriter
workbook = xlsxwriter.Workbook('chart.xlsx')
worksheet = workbook.add_worksheet()
# Add a column chart.
chart = workbook.add_chart({'type': 'column'})
# Write ... | 1 | 2016-09-15T07:52:32Z | [
"python",
"xlsxwriter"
] |
Making swarmplot points bigger | 39,499,576 | <p>I would like to make the data points on my swarmplot larger. The code I have is:</p>
<pre><code>sns.swarmplot(x="Heart", y="FirstPersonPronouns", hue="Speech", data=df)
sns.set_context("notebook", font_scale=1.8)
</code></pre>
<p>I have tried scatter_kws but get </p>
<pre><code>Attribute error: unknown property s... | 0 | 2016-09-14T21:00:36Z | 39,500,752 | <p>From the swarmplot docstring:</p>
<pre><code>Signature: seaborn.swarmplot(x=None, y=None, hue=None, data=None,
order=None, hue_order=None, split=False, orient=None, color=None,
palette=None, size=5, edgecolor='gray', linewidth=0, ax=None,
**kwargs)
Docstring: Draw a categorical scatterplot with non-overlapping poi... | 2 | 2016-09-14T22:44:45Z | [
"python",
"seaborn"
] |
"Compiling" Python to run on another machine | 39,499,599 | <p>I have created a simple-medium complexity script written in Python using Pycharm on my laptop and I wish to run this on my Raspberry Pi using Crontab. All of my past programming experience has been with C++ and C# in Windows and so I would normally just do a build of the project and it all gets compiled and linked i... | 0 | 2016-09-14T21:02:50Z | 39,499,638 | <p>Python does not need to compile as it is an interpretive language. You will be fine running it on another machine as long as you aren't making system calls. System calls will only become a problem if you are trying to do things like use windows commands on a linux machine.</p>
<p>Just copy those two files over to t... | 0 | 2016-09-14T21:06:26Z | [
"python",
"cron",
"pycharm"
] |
"Compiling" Python to run on another machine | 39,499,599 | <p>I have created a simple-medium complexity script written in Python using Pycharm on my laptop and I wish to run this on my Raspberry Pi using Crontab. All of my past programming experience has been with C++ and C# in Windows and so I would normally just do a build of the project and it all gets compiled and linked i... | 0 | 2016-09-14T21:02:50Z | 39,499,644 | <p>Use PyInstaller. In the terminal, to create a stand alone exe just use a command like this:</p>
<pre><code>pyinstaller -F myscript.py
</code></pre>
| 0 | 2016-09-14T21:06:51Z | [
"python",
"cron",
"pycharm"
] |
"Compiling" Python to run on another machine | 39,499,599 | <p>I have created a simple-medium complexity script written in Python using Pycharm on my laptop and I wish to run this on my Raspberry Pi using Crontab. All of my past programming experience has been with C++ and C# in Windows and so I would normally just do a build of the project and it all gets compiled and linked i... | 0 | 2016-09-14T21:02:50Z | 39,499,656 | <p>You can "compile" python files to <code>.pyc</code> but you would still need the python interpreter on the RaspPi to run them.</p>
<p>On a PC that does not have Python, you can create a standalone executable using <code>py2exe</code>, but the executable must then run on Windows.</p>
<p>You have to install a python... | 0 | 2016-09-14T21:07:35Z | [
"python",
"cron",
"pycharm"
] |
"Compiling" Python to run on another machine | 39,499,599 | <p>I have created a simple-medium complexity script written in Python using Pycharm on my laptop and I wish to run this on my Raspberry Pi using Crontab. All of my past programming experience has been with C++ and C# in Windows and so I would normally just do a build of the project and it all gets compiled and linked i... | 0 | 2016-09-14T21:02:50Z | 39,499,690 | <p>As the other answers have said, you can just run your code on the Pi, because Python code is interpreted and not complied.</p>
<p>That being said, you will need to install any python packages, like the ImgurClient beforehand. If you did this with PyCharm on you PC, you will likely have to use <a href="http://www.py... | 0 | 2016-09-14T21:10:19Z | [
"python",
"cron",
"pycharm"
] |
"Compiling" Python to run on another machine | 39,499,599 | <p>I have created a simple-medium complexity script written in Python using Pycharm on my laptop and I wish to run this on my Raspberry Pi using Crontab. All of my past programming experience has been with C++ and C# in Windows and so I would normally just do a build of the project and it all gets compiled and linked i... | 0 | 2016-09-14T21:02:50Z | 39,499,735 | <p>I don't know if you are gonna be able to run the python script in your other environment, specially if the script uses external libraries (.whl) that you normally install with pip.</p>
<p>A good option to run the script on a clean environment is to use virtualenv:</p>
<p><a href="https://virtualenv.pypa.io/en/stab... | 0 | 2016-09-14T21:14:47Z | [
"python",
"cron",
"pycharm"
] |
"Compiling" Python to run on another machine | 39,499,599 | <p>I have created a simple-medium complexity script written in Python using Pycharm on my laptop and I wish to run this on my Raspberry Pi using Crontab. All of my past programming experience has been with C++ and C# in Windows and so I would normally just do a build of the project and it all gets compiled and linked i... | 0 | 2016-09-14T21:02:50Z | 39,499,743 | <p>If you have Python installed on your Raspberry Pi, then from the shell, you just need to run:</p>
<pre><code># This installs pip (Python installer) as well as the requests library
sudo apt-get install python-pip
</code></pre>
<p>Once that is installed, run:</p>
<pre><code># To install the ImgurClient
pip install ... | 1 | 2016-09-14T21:15:13Z | [
"python",
"cron",
"pycharm"
] |
Python: how to get text from html file | 39,499,693 | <p>I have a folder with some <code>html-file</code> with</p>
<pre><code>import os
indir = 'html/'
for root, dirs, filenames in os.walk(indir):
for f in filenames:
page = open(f)
</code></pre>
<p>But it returns me <code>IOError: [Errno 2] No such file or directory: '0out.html'.</code></p>
<p>But there are... | -1 | 2016-09-14T21:11:01Z | 39,499,713 | <p>You need to prepend the path to the file.</p>
<pre><code>import os
indir = 'html/'
for root, dirs, filenames in os.walk(indir):
for f in filenames:
page = open(os.path.join(indir ,f)) # <-- note the added path
</code></pre>
<p>Without it, you are trying to open a file named <code>0out.html</code> wh... | 0 | 2016-09-14T21:12:35Z | [
"python",
"html"
] |
Override ipython exit function - or add hooks in to it | 39,499,748 | <p>In my project <a href="http://github.com/rochacbruno/manage" rel="nofollow">manage</a>, I am embedding iPython with:</p>
<pre><code>from IPython import start_ipython
from traitlets.config import Config
c = Config()
c.TerminalInteractiveShell.banner2 = "Welcome to my shell"
c.InteractiveShellApp.extensions = ['autor... | 2 | 2016-09-14T21:16:03Z | 39,499,913 | <p>Googling <a href="https://www.google.com/search?q=ipython%20exit%20hook" rel="nofollow">IPython exit hook</a> turns up <a href="http://ipython.readthedocs.io/en/stable/api/generated/IPython.core.hooks.html?highlight=core.hooks#module-IPython.core.hooks" rel="nofollow"><code>IPython.core.hooks</code></a>. From that d... | 2 | 2016-09-14T21:29:02Z | [
"python",
"shell",
"ipython"
] |
Override ipython exit function - or add hooks in to it | 39,499,748 | <p>In my project <a href="http://github.com/rochacbruno/manage" rel="nofollow">manage</a>, I am embedding iPython with:</p>
<pre><code>from IPython import start_ipython
from traitlets.config import Config
c = Config()
c.TerminalInteractiveShell.banner2 = "Welcome to my shell"
c.InteractiveShellApp.extensions = ['autor... | 2 | 2016-09-14T21:16:03Z | 39,502,890 | <p>First thanks to @user2357112, I learned how to create an extension and register a hook, but I figured out that <code>shutdown_hook</code>is deprecated.</p>
<p>The right way is simply.</p>
<pre><code>import atexit
def teardown_my_shell():
# things I want to happen when iPython exits
atexit.register(teardown_m... | 2 | 2016-09-15T03:58:37Z | [
"python",
"shell",
"ipython"
] |
Missing .DLL files Anaconda 4.1.1 32-bit | 39,499,756 | <p>I've installed <strong>Anaconda 4.1.1 32-bit</strong> on our <strong>Windows 2003 Server</strong>. </p>
<p>When I try to run a program through the command prompt it gives me the following error message:</p>
<pre><code>..\python.exe is not a valid Win32 application
</code></pre>
<p>After searching around for a bit... | 0 | 2016-09-14T21:16:45Z | 39,499,894 | <p>Those .dll files appear to have been removed by IE8. You should be able to restore them by installing Visual C++ 2005 SP1</p>
<pre><code>https://www.microsoft.com/en-au/download/details.aspx?id=26347
</code></pre>
<p>Attributed from:</p>
<p><a href="http://stackoverflow.com/a/23484851/3006366">http://stackoverflo... | 0 | 2016-09-14T21:27:10Z | [
"python",
"dll",
"anaconda",
"windows-2003-webserver"
] |
django attribute error : object has no attribute 'get_bound_field' | 39,499,798 | <p>Apparently a form being loaded on my template is requiring a field that isn't being passed to it. </p>
<p>Can anyone tell me what is causing this error?</p>
<p>Error occurs during template rendering</p>
<pre><code>In template C:\django\projectname\static\templates\link_list.html, error at line 114
'UserProfile' o... | 1 | 2016-09-14T21:20:06Z | 39,500,348 | <p>In your form you're getting a UserProfile object and then assigning it as a field. But it's not a field, it's a model object.</p>
<p>I don't know what you're trying to do there, but don't assign that object to the fields dict.</p>
| 1 | 2016-09-14T22:04:06Z | [
"python",
"django",
"models"
] |
Ansible tower-cli on Windows 10 - tower-cli' is not recognized as an internal or external command | 39,499,819 | <p>From this link: <a href="https://github.com/ansible/tower-cli/" rel="nofollow">https://github.com/ansible/tower-cli/</a>, you install tower-cli with pip install ansible-tower-cli but when you go to run a command like: <code>tower-cli config host www.myWebsite.com</code>, </p>
<p>You get this error: <code>tower-cli'... | 0 | 2016-09-14T21:21:42Z | 39,579,619 | <p>If you run the command python in your windows shell and get that error, 'python' is not recognized as an internal or external command, operable program or bathc file, then do this: </p>
<p><em>Replace <strong>python</strong> with <strong>py</em></strong>, so type <code>py</code> in the command prompt and it'll work... | 0 | 2016-09-19T18:14:58Z | [
"python",
"pip",
"ansible",
"ansible-playbook",
"ansible-tower"
] |
Why declare a list twice in __init__? | 39,499,823 | <p>I'm reading through the Python Docs, and, under <a href="https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes" rel="nofollow">Section 8.4.1</a>,
I found the following <code>__init__</code> definition (abbreviated):</p>
<pre><code>class ListBasedSet(collections.abc.Set):
''' A... | 0 | 2016-09-14T21:21:51Z | 39,500,256 | <p>I'd call this a case of premature optimization; you don't save <em>that much</em> by eliminating the dot, especially for large input iterables; here's some timings:</p>
<p>Eliminating the dot:</p>
<pre><code>%timeit ListBasedSet(range(3))
The slowest run took 4.06 times longer than the fastest. This could mean tha... | 0 | 2016-09-14T21:55:32Z | [
"python",
"python-3.x",
"documentation",
"reentrancy"
] |
celery task unable to import ImportError of a module from inside the project | 39,499,893 | <p>I would like to note that the following error only occurs when ran through a celery worker.
with the following command in the terminal:</p>
<pre><code>celery -A MarketPlaceTasks worker --loglevel=info
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/celery/app/trace.py", line 218, in tra... | 1 | 2016-09-14T21:27:09Z | 39,500,575 | <p>Well it seems like some sort of work around but following the advice in this answer:
<a href="http://stackoverflow.com/questions/4655526/how-to-accomplish-relative-import-in-python/4656228#4656228">How to accomplish relative import in python</a></p>
<p>I moved most of the project inside a "main" module containing a... | 0 | 2016-09-14T22:26:01Z | [
"python",
"python-2.7",
"enums",
"celery",
"celery-task"
] |
Is there a standard way to tell py.test to run against specific code? | 39,499,937 | <p>I'm trying to run a Python project's unit tests using py.test. Until recently I've used nose and it ran the tests against my local source code instead of the installed package, but py.test seems to want to run against the installed package, meaning I have to run <code>python setup.py install</code> before every tes... | 0 | 2016-09-14T21:30:39Z | 39,519,231 | <p>My first mistake was setting up my project using <code>python setup.py install</code> instead of <code>python setup.py develop</code>. Pytest expects you to use the latter, which seems like good practice anyway.</p>
<p>If it's necessary to run against local code when the same code is installed, there does seem to ... | 0 | 2016-09-15T19:48:30Z | [
"python",
"python-2.7",
"unit-testing",
"testing",
"py.test"
] |
Terminating a subprocess with KeyboardInterrupt | 39,499,959 | <p>I'm using Python to call a C++ program using the subprocess module. Since the program takes some time to run, I'd like to be able to terminate it using Ctrl+C. I've seen a few questions regarding this on StackOverflow but none of the solutions seem to work for me.</p>
<p>What I would like is for the subprocess to b... | 0 | 2016-09-14T21:32:31Z | 39,500,096 | <p>My ugly but successfull attempt on Windows:</p>
<pre><code>import subprocess
import threading
import time
binary_path = 'notepad'
args = 'foo.txt' # arbitrary
proc = None
done = False
def s():
call_str = '{} {}'.format(binary_path, args)
global done
global proc
proc = subprocess.Popen(call_str,s... | 1 | 2016-09-14T21:44:09Z | [
"python",
"windows",
"subprocess",
"interrupt",
"terminate"
] |
Terminating a subprocess with KeyboardInterrupt | 39,499,959 | <p>I'm using Python to call a C++ program using the subprocess module. Since the program takes some time to run, I'd like to be able to terminate it using Ctrl+C. I've seen a few questions regarding this on StackOverflow but none of the solutions seem to work for me.</p>
<p>What I would like is for the subprocess to b... | 0 | 2016-09-14T21:32:31Z | 39,503,654 | <p>I figured out a way to do this, similar to Jean-Francois's answer with the loop but without the multiple threads. The key is to use Popen.poll() to determine if the subprocess has finished (will return None if still running). </p>
<pre><code>import subprocess
import time
binary_path = '/path/to/binary'
args = 'arg... | 2 | 2016-09-15T05:24:16Z | [
"python",
"windows",
"subprocess",
"interrupt",
"terminate"
] |
How to find element with specific parent? | 39,499,976 | <p>I have some HTML like:</p>
<pre><code><div class='cl1'>
<div class='cl2'>text_1</div>
<div class='cl3'>
<div class='cl2'>text_2</div>
</div>
</div>
</code></pre>
<p>I need to find any items of cl2 class that have cl1 as parent, so i need to get <s... | 2 | 2016-09-14T21:33:54Z | 39,500,233 | <p>One possible solution would be:</p>
<pre><code>from bs4 import BeautifulSoup
data = """
<div class='cl1'>
<div class='cl2'>text_1</div>
<div class='cl3'>
<div class='cl2'>text_2</div>
</div>
</div>
"""
soup = BeautifulSoup(data)
divs = [div
... | 0 | 2016-09-14T21:53:49Z | [
"python",
"css-selectors",
"beautifulsoup",
"robobrowser"
] |
How to find element with specific parent? | 39,499,976 | <p>I have some HTML like:</p>
<pre><code><div class='cl1'>
<div class='cl2'>text_1</div>
<div class='cl3'>
<div class='cl2'>text_2</div>
</div>
</div>
</code></pre>
<p>I need to find any items of cl2 class that have cl1 as parent, so i need to get <s... | 2 | 2016-09-14T21:33:54Z | 39,501,209 | <p>You selector is on the right track, you just need to space out the classes i.e <code>div.cl1>div.cl2</code> should be <code>div.cl1 > div.cl2</code>:</p>
<pre><code>In [5]: from bs4 import BeautifulSoup
In [6]: html = """<div class='cl1'>
<div class='cl2'>text_1</div>
<div class=... | 1 | 2016-09-14T23:42:22Z | [
"python",
"css-selectors",
"beautifulsoup",
"robobrowser"
] |
Python joke or chat error | 39,500,093 | <p>when i run this, if i type chat it runs the punchline from the joke above how do i fix this?
<a href="http://i.stack.imgur.com/1oXAp.png" rel="nofollow">enter image description here</a></p>
<pre><code>print ("whats your name?")
firstname = input()
print ("hello,", firstname)
print ("what's your surname?")
surname =... | -3 | 2016-09-14T21:43:53Z | 39,500,143 | <p>Your spacing / indentation is off:</p>
<pre><code>if question == "joke":
print("what do you call a deer with no heart?")
idk = input()
print ("Dead!!! LOL!!!!")
</code></pre>
<p>In your code should be:</p>
<pre><code>if question == "joke":
print("what do you call a deer with no heart?")
idk = input()
print ("... | 1 | 2016-09-14T21:47:33Z | [
"python"
] |
Python joke or chat error | 39,500,093 | <p>when i run this, if i type chat it runs the punchline from the joke above how do i fix this?
<a href="http://i.stack.imgur.com/1oXAp.png" rel="nofollow">enter image description here</a></p>
<pre><code>print ("whats your name?")
firstname = input()
print ("hello,", firstname)
print ("what's your surname?")
surname =... | -3 | 2016-09-14T21:43:53Z | 39,500,152 | <p>In the absence of proper indentation, Python is assuming that the lines</p>
<pre><code>idk = input()
print ("Dead!!! LOL!!!!")
</code></pre>
<p>are outside the <code>if</code> statement. Indent them like you did for the <code>print</code> statement for the punchline.</p>
| 1 | 2016-09-14T21:48:19Z | [
"python"
] |
Swap every Nth element of two lists | 39,500,214 | <p>I have two lists as:</p>
<pre><code>l1 = [1, 2, 3, 4, 5, 6]
l2 = ['a', 'b', 'c', 'd', 'e', 'f']
</code></pre>
<p>I need to swap every <code>N</code>th element of these lists. For example if <code>N=3</code>, desired result is:</p>
<pre><code>l1 = [1, 2, 'c', 4, 5, 'f']
l2 = ['a', 'b', 3, 'd', 'e', 6]
</code></pre... | -2 | 2016-09-14T21:52:21Z | 39,500,221 | <p>We can achieve that via <code>list slicing</code> as:</p>
<pre><code>>>> l1[2::3], l2[2::3] = l2[2::3], l1[2::3]
>>> l1, l2
([1, 2, 'c', 4, 5, 'f'], ['a', 'b', 3, 'd', 'e', 6])
</code></pre>
| 1 | 2016-09-14T21:53:05Z | [
"python",
"list",
"swap"
] |
numpy binning: how to get array indexes satisfying a predicate | 39,500,218 | <p>I have a vector <code>g</code> of values of length 1024 and a smaller vector <code>f</code> of size 32 defining bin boundaries. <code>v</code> and <code>f</code> are sorted in ascending order. I want to return an array of vectors i.e <code>[v_1,v_2,v_3,...]</code> of length <code>len(f)</code> such that each vector ... | 0 | 2016-09-14T21:52:43Z | 39,500,568 | <p>first things first:</p>
<pre><code>import numpy as np
</code></pre>
<p>let's say you have your data <code>g</code>:</p>
<pre><code>g = sorted((1e3 * np.random.random(1024)).astype(int))
</code></pre>
<p>and your bins <code>f</code>:</p>
<pre><code>f = sorted((1e3 * np.random.random(32)).astype(int))
</code></pr... | 0 | 2016-09-14T22:25:13Z | [
"python",
"numpy"
] |
numpy binning: how to get array indexes satisfying a predicate | 39,500,218 | <p>I have a vector <code>g</code> of values of length 1024 and a smaller vector <code>f</code> of size 32 defining bin boundaries. <code>v</code> and <code>f</code> are sorted in ascending order. I want to return an array of vectors i.e <code>[v_1,v_2,v_3,...]</code> of length <code>len(f)</code> such that each vector ... | 0 | 2016-09-14T21:52:43Z | 39,502,590 | <p>You can use <code>searchsorted</code> to find the sorted positions of <code>f</code> in <code>g</code>. These give the lower and upper bounds of the ranges that you want:</p>
<p>For example,</p>
<pre><code>In [42]: g
Out[42]:
array([ 1, 11, 19, 20, 21, 32, 36, 41, 47, 53, 54, 55, 65, 66, 69, 74, 76,
87, 8... | 1 | 2016-09-15T03:14:44Z | [
"python",
"numpy"
] |
Pandas: how to get the unique values of a column that contains a list of values? | 39,500,258 | <p>Consider the following dataframe</p>
<pre><code>df = pd.DataFrame({'name' : [['one two','three four'], ['one'],[], [],['one two'],['three']],
'col' : ['A','B','A','B','A','B']})
df.sort_values(by='col',inplace=True)
df
Out[62]:
col name
0 A [one two, three four]
2 ... | 3 | 2016-09-14T21:55:34Z | 39,500,391 | <p>Try:</p>
<pre><code>uniq_df = df.groupby('col')['name'].apply(lambda x: list(set(reduce(lambda y,z: y+z,x)))).reset_index()
uniq_df.columns = ['col','uniq_list']
pd.merge(df,uniq_df, on='col', how='left')
</code></pre>
<p>Desired output:</p>
<pre><code> col name uniq_list
0 A [o... | 2 | 2016-09-14T22:08:02Z | [
"python",
"pandas"
] |
Pandas: how to get the unique values of a column that contains a list of values? | 39,500,258 | <p>Consider the following dataframe</p>
<pre><code>df = pd.DataFrame({'name' : [['one two','three four'], ['one'],[], [],['one two'],['three']],
'col' : ['A','B','A','B','A','B']})
df.sort_values(by='col',inplace=True)
df
Out[62]:
col name
0 A [one two, three four]
2 ... | 3 | 2016-09-14T21:55:34Z | 39,500,774 | <p>Here is the solution </p>
<pre><code>df['unique_list'] = df.col.map(df.groupby('col')['name'].sum().apply(np.unique))
df
</code></pre>
<p><a href="http://i.stack.imgur.com/S8IdI.png" rel="nofollow"><img src="http://i.stack.imgur.com/S8IdI.png" alt="enter image description here"></a></p>
| 3 | 2016-09-14T22:47:11Z | [
"python",
"pandas"
] |
Manually add legend Items Python matplotlib | 39,500,265 | <p>I am using matlibplot and I would like to manually add items to the legend that are a color and a label. I am adding data to to the plot to specifying there would lead to a lot of duplicates.</p>
<p>My thought was to do:</p>
<pre><code> ax2.legend(self.labels,colorList[:len(self.labels)])
plt.legend()
</cod... | 0 | 2016-09-14T21:55:58Z | 39,500,357 | <p>Have you checked the <a href="http://matplotlib.org/users/legend_guide.html" rel="nofollow">Legend Guide</a>?</p>
<p>For practicality, I quote the example from the <a href="http://matplotlib.org/users/legend_guide.html#creating-artists-specifically-for-adding-to-the-legend-aka-proxy-artists" rel="nofollow">guide</a... | 2 | 2016-09-14T22:05:15Z | [
"python",
"matplotlib"
] |
Behavior of ndarray.data for views in numpy | 39,500,356 | <p>I am trying to understand the meaning of <code>ndarray.data</code> field in numpy (see <a href="http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html#memory-layout" rel="nofollow">memory layout</a> section of the reference page on N-dimensional arrays), especially for views into arrays. To quote the document... | 1 | 2016-09-14T22:05:12Z | 39,500,532 | <p><code><memory at 0x000000F2F5150348></code> is a <code>memoryview</code> object located at address <code>0x000000F2F5150348</code>; the buffer it provides access to is located somewhere else.</p>
<p>Memoryviews provide a number of operations described in the <a href="https://docs.python.org/3/library/stdtypes... | 3 | 2016-09-14T22:20:53Z | [
"python",
"python-3.x",
"numpy"
] |
Behavior of ndarray.data for views in numpy | 39,500,356 | <p>I am trying to understand the meaning of <code>ndarray.data</code> field in numpy (see <a href="http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html#memory-layout" rel="nofollow">memory layout</a> section of the reference page on N-dimensional arrays), especially for views into arrays. To quote the document... | 1 | 2016-09-14T22:05:12Z | 39,500,603 | <p>Generally the number displayed by <code>x.data</code> isn't meant to be used by you. <code>x.data</code> is the buffer, which can be used in other contexts that expect a buffer.</p>
<pre><code>np.frombuffer(x.data,dtype=float)
</code></pre>
<p>replicates your <code>x</code>. </p>
<pre><code>np.frombuffer(x[3:].d... | 2 | 2016-09-14T22:28:54Z | [
"python",
"python-3.x",
"numpy"
] |
How to get a vertex list of differences between two graphs in igraph | 39,500,358 | <p>I'm trying to get a list of vertex that are present or missing from a graph 1 against another graph 2. I'm wondering if there any helper method in igraph to do it or if would be necessary to build a own. Thank you.</p>
| 1 | 2016-09-14T22:05:24Z | 39,500,735 | <p>I don't think there's a builtin method within graph that does what you want. However, it is straightforward to make your own.</p>
<p>I'm going to make the reasonable assumption here that the unique identifier of a vertex is the 'name' property that igraph encourages users to use. Essentially, you make two sets of t... | 0 | 2016-09-14T22:42:40Z | [
"python",
"igraph"
] |
Reducing database operation time Django/ Mysql | 39,500,404 | <p>So, the thing is I am having a moderately large list of emails ~ 250,000 entries.</p>
<p>I have another table containing list of invalid emails ~ 50,000 which i need to remove (mark inactive) from 1st table. For that I have ran a simple django function which is taking 3-4 seconds in each loop. The code is:</p>
<pr... | 0 | 2016-09-14T22:09:20Z | 39,501,863 | <p>There are a couple optimisations you might want to take a look at. Instead of looping over a get for each object try getting a values list:</p>
<p><code>queryset = Invalid.objects.filter(id__range=(9,40000))
queryset_list = queryset.values_list('email' flat=True)</code></p>
<p><a href="https://docs.djangoproject.c... | 1 | 2016-09-15T01:17:49Z | [
"python",
"mysql",
"django",
"database"
] |
Reducing database operation time Django/ Mysql | 39,500,404 | <p>So, the thing is I am having a moderately large list of emails ~ 250,000 entries.</p>
<p>I have another table containing list of invalid emails ~ 50,000 which i need to remove (mark inactive) from 1st table. For that I have ran a simple django function which is taking 3-4 seconds in each loop. The code is:</p>
<pr... | 0 | 2016-09-14T22:09:20Z | 39,502,431 | <p>Untested:</p>
<pre><code>IndiList.objects.filter(email__in=Invalid.objects.only('email').all()).update(active=False)
</code></pre>
<p>I am not sure if Django is smart enough to build a subquery from that, if not, then this should do:</p>
<pre><code>IndiList.objects.filter(email__in=Invalid.objects.all().values_li... | 1 | 2016-09-15T02:50:27Z | [
"python",
"mysql",
"django",
"database"
] |
Reducing database operation time Django/ Mysql | 39,500,404 | <p>So, the thing is I am having a moderately large list of emails ~ 250,000 entries.</p>
<p>I have another table containing list of invalid emails ~ 50,000 which i need to remove (mark inactive) from 1st table. For that I have ran a simple django function which is taking 3-4 seconds in each loop. The code is:</p>
<pr... | 0 | 2016-09-14T22:09:20Z | 39,507,823 | <p>After a few iterations, i used this function which was more than <strong>1000 times faster.</strong></p>
<pre><code>def clean_list3():
pp = Invalid.objects.filter(id__gte=9)
listd = [oo.email.strip() for oo in pp]
for e in IndiList.objects.all():
if e.email.strip() in listd:
e.active... | 0 | 2016-09-15T09:41:02Z | [
"python",
"mysql",
"django",
"database"
] |
Report number of assertions in pyTest | 39,500,416 | <p>I am using <code>pytest</code> for writing some tests at integration level. I would like to be able to also report the number of assertions done on each test case. By default, <code>pytest</code> will only report the number of test cases which have passed and failed.</p>
| 0 | 2016-09-14T22:10:35Z | 39,559,306 | <p>On assertion further execution of test is aborted. So there will always be 1 assertion per test.</p>
<p>To achieve what you want you will have to write your own wrapper over assertion to keep track. At the end of the test check if count is >0 then raise assertion.
The count can be reset to zero either the <code>set... | 0 | 2016-09-18T15:24:12Z | [
"python",
"integration-testing",
"py.test"
] |
Opening Pycharm from terminal with the current path | 39,500,438 | <p>If you give in the command "atom ." in the terminal, the Atom editor opens the current folder and I am ready to code.</p>
<p>I am trying to achieve the same with Pycharm using Ubuntu: get the current directory and open it with Pycharm as a project.</p>
<p>Is there way to achieve this by setting a bash alias?</p>
| 1 | 2016-09-14T22:12:25Z | 39,500,482 | <p>This works for me:</p>
<pre><code>alias atom_pycharm='~/pycharm/bin/pycharm.sh .'
</code></pre>
<p>Maybe you installed it to a different path, though - <code>locate</code> your <code>pycharm.sh</code> file and modify accordingly. </p>
<p>You have the usual bash tricks: if you want to run in the background, appen... | 0 | 2016-09-14T22:17:24Z | [
"python",
"bash",
"command-line",
"pycharm"
] |
Opening Pycharm from terminal with the current path | 39,500,438 | <p>If you give in the command "atom ." in the terminal, the Atom editor opens the current folder and I am ready to code.</p>
<p>I am trying to achieve the same with Pycharm using Ubuntu: get the current directory and open it with Pycharm as a project.</p>
<p>Is there way to achieve this by setting a bash alias?</p>
| 1 | 2016-09-14T22:12:25Z | 39,500,506 | <p>PyCharm can be launched using the <code>charm</code> command line tool (which can be installed while getting started with PyCharm the first time).</p>
<p><code>charm .</code></p>
| 3 | 2016-09-14T22:18:27Z | [
"python",
"bash",
"command-line",
"pycharm"
] |
How to access grand childs of a node using XPath in Python Selenium? | 39,500,465 | <p>I am preparing a web-scrapping script which supposed to find list of attorneys in an area through a business directory web-site. I use chrome driver to fill out search keywords and the area values. </p>
<p>Since some of the hits don't have phone number, I would like to iterate through list of DIVs corresponding to ... | 0 | 2016-09-14T22:15:25Z | 39,500,996 | <p>Actually <code>find_elements()</code> returns either list of <a href="http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.remote.webelement" rel="nofollow"><code>WebElement</code></a> or empty list. You're storing this result into a list variable name <code>elem</code>.</p>
<blockquote>
<p>At... | 1 | 2016-09-14T23:13:36Z | [
"python",
"selenium",
"xpath",
"web-scraping"
] |
Django Migration Process for Elasticbeanstalk / Multiple Databases | 39,500,513 | <p>I am developing a small web application using Django and Elasticbeanstalk.
I created a EB application with two environments (staging and production), created a RDS instance and assigned it to my EB environments. </p>
<p>For development I use a local database, because deploying to AWS takes quite some time.</p>
<p>... | 1 | 2016-09-14T22:18:49Z | 39,500,763 | <p>Seems that you might have deleted the table or migrations at some point of time.</p>
<p>When you run makemigrations, django create migratins and when you run migrate, it creates database whichever is specified in settings file.</p>
<p>One thing is if you keep on creating migrations and do not run it in a particula... | 1 | 2016-09-14T22:45:44Z | [
"python",
"django",
"amazon-web-services",
"elastic-beanstalk",
"django-migrations"
] |
Name "userInput" cannot be defined | 39,500,567 | <p>i'm practicing some Python and i'm having some trouble trying to compare userInput would selected word in a hangman game. </p>
<pre><code># User guess input (single char)
# Exception handling to limit input to letters between a-z
while True:
userInput = str(input('Please guess a letter:'))
if len(userInput)... | 1 | 2016-09-14T22:25:09Z | 39,501,373 | <blockquote>
<p>set userInput = None above while loop</p>
</blockquote>
<p>This was the solution, thank you everyone!</p>
| 1 | 2016-09-15T00:04:23Z | [
"python",
"python-3.x"
] |
Sparse matrix slicing using list of int | 39,500,649 | <p>I'm writing a machine learning algorithm on huge & sparse data (my matrix is of shape (347, 5 416 812 801) but very sparse, only 0.13% of the data is non zero. </p>
<p>My sparse matrix's size is 105 000 bytes (<1Mbytes) and is of <code>csr</code> type.</p>
<p>I'm trying to separate train/test sets by choos... | 1 | 2016-09-14T22:33:52Z | 39,500,986 | <p>I think I've recreated the <code>csr</code> row indexing with:</p>
<pre><code>def extractor(indices, N):
indptr=np.arange(len(indices)+1)
data=np.ones(len(indices))
shape=(len(indices),N)
return sparse.csr_matrix((data,indices,indptr), shape=shape)
</code></pre>
<p>Testing on a <code>csr</code> I had h... | 1 | 2016-09-14T23:12:00Z | [
"python",
"scipy",
"segmentation-fault",
"sparse-matrix"
] |
I'm having trouble trying to read the numbers (0 - 10) into a list in Python 3 using CSV file and in a column format. | 39,500,668 | <p>I first wrote the numbers in a column into a CSV file but having trouble with the reading part. I want to make into one list and make sure that the numbers are converted into ints</p>
<pre><code>f = open('numbers.csv', 'r')
with f:
reader = csv.reader(f)
for column in reader:
print(column)
</code></... | 0 | 2016-09-14T22:35:47Z | 39,500,704 | <pre><code>numlist = list()
f = open('numbers.csv', 'r')
with f:
reader = csv.reader(f)
for column in reader:
numlist.append( int(column[0]) )
print( numlist )
</code></pre>
| 0 | 2016-09-14T22:39:05Z | [
"python",
"numbers"
] |
I'm having trouble trying to read the numbers (0 - 10) into a list in Python 3 using CSV file and in a column format. | 39,500,668 | <p>I first wrote the numbers in a column into a CSV file but having trouble with the reading part. I want to make into one list and make sure that the numbers are converted into ints</p>
<pre><code>f = open('numbers.csv', 'r')
with f:
reader = csv.reader(f)
for column in reader:
print(column)
</code></... | 0 | 2016-09-14T22:35:47Z | 39,500,864 | <p>You just need to iterate over each <code>row</code> in your <code>file</code>, cast the first <code>column</code> to <code>int</code> using <code>int()</code> and then add to a <code>list</code>. Here is compact version:</p>
<pre><code>with open('numbers.csv', 'r') as numbers_file:
reader = csv.reader(numbers_f... | 0 | 2016-09-14T22:58:37Z | [
"python",
"numbers"
] |
Reduce dictionary of deque to single boolean | 39,500,827 | <p>I want d to evaluate to <code>True</code> iff all values in <code>d</code> are empty</p>
<pre><code>from collections import deque
d = {'a': deque([1,2,3]), 'b': deque([1,2,3]), 'c': deque([1,2,3])}
</code></pre>
<p>I've tried <code>reduce</code> but I'm clearly missing something important. </p>
<p>Thanks in adva... | 1 | 2016-09-14T22:54:59Z | 39,504,138 | <p>As Peter Wood kindly pointed out, <code>not any(d.values())</code> does the trick nicely. </p>
| 1 | 2016-09-15T06:10:40Z | [
"python",
"python-2.7"
] |
Find the indicies of common tuples in two list of tuples without loop in Python | 39,500,876 | <p>How can one find the indexes of the common tuples in two list of tuples?</p>
<pre><code>tuplelist1 = [("a","b"), ("c","d"), ("e","f"), ("g","h")]
tuplelist2 = [("c","d"),("e","f")]
</code></pre>
<p>So the indices in tuplelist1 that are common with tupplelist2 are indices 1 and 2.</p>
<p>Is there a way to figure t... | -1 | 2016-09-14T22:59:37Z | 39,500,933 | <p>With a list comprehension, you could do</p>
<pre><code>indices_of_shared = [index for (index, pair) in enumerate(tuplelist1) if pair in tuplelist2]
</code></pre>
| 2 | 2016-09-14T23:04:56Z | [
"python",
"list",
"indexing",
"tuples",
"indices"
] |
Spell Checking a column in Python/Pandas/PyEnchant | 39,500,899 | <p>I'm trying to use Pyenchant to spell check each entry in a column called pets in a pandas dataframe called house.</p>
<pre><code>import enchant
dict = enchant.Dict("en_US")
for pets in house:
[pets] = dict.suggest([pets])[0]
</code></pre>
<p>When I run this code, I get an error about not passing bytestrings ... | 0 | 2016-09-14T23:02:07Z | 39,502,018 | <p>If your dataframe contains bytestrings, you will need to decode them before you pass them to <code>enchant</code>; you can do this with <code>.str.decode('utf-8')</code>. Then to apply your function, the cleanest way to approach this type of situation is usually to use <code>map</code> across your Series rather than... | 0 | 2016-09-15T01:43:58Z | [
"python",
"pandas",
"pyenchant"
] |
Initializing many objects in an elegant way | 39,500,940 | <p>I'm looking for a elegant way to initialize many objects.</p>
<p>Let's say that I have a <code>Utils</code> module, which has an interface to SVN, Git, Make and other stuff.</p>
<p>Currently, I'm doing it like this:</p>
<pre><code>from Utils.Config import Config, Properties
from Utils.Utils import PrettyPrint, SV... | 3 | 2016-09-14T23:05:58Z | 39,501,272 | <p>I wouldn't create a class and place it as a base, <em>that seems like overkill, too bulky of an approach</em>.</p>
<p>Instead, you could create an auxiliary, helper, function that takes <code>self</code> and <code>setattr</code> on it. An example of this with a couple of objects from <a href="https://docs.python.or... | 3 | 2016-09-14T23:49:44Z | [
"python",
"python-3.x"
] |
Scrapy response have backslashes into element attributes | 39,501,019 | <p>I run the following code in a Scrapy Shell, to scrape data using a POST request:</p>
<pre><code>url = 'http://www.ldg.co.uk/wp-admin/admin-ajax.php'
data = {'action': 'wpp_property_overview_pagination',
'wpp_ajax_query[show_children]': 'true',
'wpp_ajax_query[disable_wrapper]': 'true',
'wpp... | 1 | 2016-09-14T23:16:03Z | 39,501,745 | <p>There is a very simple solution, you get <a href="http://www.w3schools.com/json/" rel="nofollow"><em>json</em></a> back <em>not html</em>:</p>
<pre><code>url = 'http://www.ldg.co.uk/wp-admin/admin-ajax.php'
data = {'action': 'wpp_property_overview_pagination',
'wpp_ajax_query[show_children]': 'true',
... | 1 | 2016-09-15T00:59:18Z | [
"python",
"python-2.7",
"xpath",
"web-scraping",
"scrapy"
] |
Regex interpretaion in Django tutorial | 39,501,066 | <p>despite being familiar with the basics of regex, the tutorial for <a href="https://docs.djangoproject.com/en/1.10/intro/tutorial03/#writing-more-views" rel="nofollow">Django 1.10</a> does not go into much detail about how some regex generates dynamic links.
I am looking at this specific snippet under the polls/urls... | 1 | 2016-09-14T23:21:50Z | 39,501,099 | <p>The <code>(?P<<em>name</em>><em>...</em>)</code> means that this regex has a <em>named capture group</em>, unlike the <code>(...)</code> syntax, which is a numbered capture group. Django takes the named parameters and passes them to your view.</p>
| 0 | 2016-09-14T23:28:20Z | [
"python",
"regex",
"django"
] |
Regex interpretaion in Django tutorial | 39,501,066 | <p>despite being familiar with the basics of regex, the tutorial for <a href="https://docs.djangoproject.com/en/1.10/intro/tutorial03/#writing-more-views" rel="nofollow">Django 1.10</a> does not go into much detail about how some regex generates dynamic links.
I am looking at this specific snippet under the polls/urls... | 1 | 2016-09-14T23:21:50Z | 39,501,107 | <p><strong><code>^(?P<question_id>[0-9]+)/$</code></strong></p>
<pre><code>^ assert position at start of the string
(?P<question_id>[0-9]+) Named capturing group "question_id"
[0-9]+ match a single character present in the list below:
Quantifier: + Between one and unlimited times, as many time... | 0 | 2016-09-14T23:29:19Z | [
"python",
"regex",
"django"
] |
Regex interpretaion in Django tutorial | 39,501,066 | <p>despite being familiar with the basics of regex, the tutorial for <a href="https://docs.djangoproject.com/en/1.10/intro/tutorial03/#writing-more-views" rel="nofollow">Django 1.10</a> does not go into much detail about how some regex generates dynamic links.
I am looking at this specific snippet under the polls/urls... | 1 | 2016-09-14T23:21:50Z | 39,501,151 | <p>The <code>(?P<question_id>.*)</code> Says everything captured by the regex inside the parenthesis will be in a named group called question_id. It can be directly addressed. So the regex doesn't know it is a foreign key or anything of the sort, just that there is a group named <code>question_id</code>. The ... | 2 | 2016-09-14T23:34:04Z | [
"python",
"regex",
"django"
] |
Regex interpretaion in Django tutorial | 39,501,066 | <p>despite being familiar with the basics of regex, the tutorial for <a href="https://docs.djangoproject.com/en/1.10/intro/tutorial03/#writing-more-views" rel="nofollow">Django 1.10</a> does not go into much detail about how some regex generates dynamic links.
I am looking at this specific snippet under the polls/urls... | 1 | 2016-09-14T23:21:50Z | 39,501,219 | <p>It captures [0-9]+ under the name question_id. Then it passes the captured number to the view function as a parameter. You can try it with re functions. It is not Django specific.</p>
<pre><code>>>> import re
>>> re.match(r'^(?P<question_id>[0-9]+)/$', '122/').groupdict()
{'question_id': '12... | 0 | 2016-09-14T23:43:40Z | [
"python",
"regex",
"django"
] |
ImportError: No module named downsample | 39,501,152 | <p>I am using Theano. The OS is Ubuntu. The Theano is UPTODATE. I am wondering why I am getting by <code>from theano.tensor.signal.downsample import max_pool_2d</code> command.</p>
<p><code>ImportError: No module named downsample</code>.</p>
| 2 | 2016-09-14T23:34:17Z | 39,501,251 | <p>The <code>downsample</code> module has been moved to <code>pool</code>, so try declaring it as:</p>
<pre><code>from theano.tensor.signal.pool import pool_2d
</code></pre>
<p>After changing delete your theano cache with the command:</p>
<pre><code>theano-cache purge
</code></pre>
| 1 | 2016-09-14T23:47:05Z | [
"python",
"module",
"theano"
] |
Python Project Euler digit fifth powers | 39,501,154 | <p><a href="https://projecteuler.net/problem=30" rel="nofollow">Here is the problem</a>:</p>
<blockquote>
<p>Surprisingly there are only three numbers that can be written as the
sum of fourth powers of their digits:</p>
<p>1634 = 1^4 + 6^4 + 3^4 + 4^4<br>
8208 = 8^4 + 2^4 + 0^4 + 8^4<br>
9474 = 9^4 ... | 0 | 2016-09-14T23:35:16Z | 39,501,262 | <p>The problem in your code is you forgot to reset the <code>digit_sum</code> when you got an answer.
Put <code>digit_sum = 0</code> before <code>j = list(str(i))</code>. You also start with <code>i = 0</code>. I suggest to start with <code>i = 10</code> since the first 2 digit number is 10.</p>
<p>use this:</p>
<pre... | 0 | 2016-09-14T23:48:23Z | [
"python",
"loops",
"sum",
"project",
"digit"
] |
Python Project Euler digit fifth powers | 39,501,154 | <p><a href="https://projecteuler.net/problem=30" rel="nofollow">Here is the problem</a>:</p>
<blockquote>
<p>Surprisingly there are only three numbers that can be written as the
sum of fourth powers of their digits:</p>
<p>1634 = 1^4 + 6^4 + 3^4 + 4^4<br>
8208 = 8^4 + 2^4 + 0^4 + 8^4<br>
9474 = 9^4 ... | 0 | 2016-09-14T23:35:16Z | 39,501,312 | <p>4150 is also in solutions. The digit_sum is not set to 0 before 4151 step. You should set digit_sum = 0 in each step.</p>
<pre><code>summ = 0
digit_sum = 0
i = 0
while i < 1000000:
digit_sum = 0 # should be set in each step
j = list(str(i))
for x in j:
digit = int(x) ** 5
digit_sum += d... | 0 | 2016-09-14T23:55:50Z | [
"python",
"loops",
"sum",
"project",
"digit"
] |
Python Project Euler digit fifth powers | 39,501,154 | <p><a href="https://projecteuler.net/problem=30" rel="nofollow">Here is the problem</a>:</p>
<blockquote>
<p>Surprisingly there are only three numbers that can be written as the
sum of fourth powers of their digits:</p>
<p>1634 = 1^4 + 6^4 + 3^4 + 4^4<br>
8208 = 8^4 + 2^4 + 0^4 + 8^4<br>
9474 = 9^4 ... | 0 | 2016-09-14T23:35:16Z | 39,501,315 | <p>The answer to your question is that you don't reset <code>digit_sum</code> every time, only when <code>digit_sum != i</code>. If you remove the <code>else</code> statement, it should work correctly.</p>
<pre><code>if digit_sum == i:
summ += i
print(i)
digit_sum = 0
i += 1
</code></pre>
| -1 | 2016-09-14T23:55:57Z | [
"python",
"loops",
"sum",
"project",
"digit"
] |
Efficient Python Pandas Stock Beta Calculation on Many Dataframes | 39,501,277 | <p>I have many (4000+) CSVs of stock data (Date, Open, High, Low, Close) which I import into individual Pandas dataframes to perform analysis. I am new to python and want to calculate a rolling 12month beta for each stock, I found a post to calculate rolling beta (<a href="http://stackoverflow.com/questions/34802972/p... | 4 | 2016-09-14T23:50:04Z | 39,503,417 | <p><strong><em>Generate Random Stock Data</em></strong><br>
20 Years of Monthly Data for 4,000 Stocks</p>
<pre><code>dates = pd.date_range('1995-12-31', periods=480, freq='M', name='Date')
stoks = pd.Index(['s{:04d}'.format(i) for i in range(4000)])
df = pd.DataFrame(np.random.rand(480, 4000), dates, stoks)
</code></p... | 3 | 2016-09-15T04:59:23Z | [
"python",
"algorithm",
"performance",
"pandas"
] |
Efficient Python Pandas Stock Beta Calculation on Many Dataframes | 39,501,277 | <p>I have many (4000+) CSVs of stock data (Date, Open, High, Low, Close) which I import into individual Pandas dataframes to perform analysis. I am new to python and want to calculate a rolling 12month beta for each stock, I found a post to calculate rolling beta (<a href="http://stackoverflow.com/questions/34802972/p... | 4 | 2016-09-14T23:50:04Z | 39,565,919 | <p>Using a generator to improve memory efficiency</p>
<p><strong><em>Simulated data</em></strong> </p>
<pre><code>m, n = 480, 10000
dates = pd.date_range('1995-12-31', periods=m, freq='M', name='Date')
stocks = pd.Index(['s{:04d}'.format(i) for i in range(n)])
df = pd.DataFrame(np.random.rand(m, n), dates, stocks)
m... | 0 | 2016-09-19T05:26:03Z | [
"python",
"algorithm",
"performance",
"pandas"
] |
How to convert lat/lon points in pandas and see whether they fall in some boundary polygons? | 39,501,303 | <p>I have a Pandas dataframe <code>df</code> like this:</p>
<pre><code> id lat lon
jhg 2.7 3.5
ytr 3.1 3.5
...
</code></pre>
<p>I also have a Geopandas dataframe <code>poly</code> with some polygons. Now, I would like to only plot the points in <code>df</code> that are <em>inside</em> some polygon. So I sho... | 4 | 2016-09-14T23:54:35Z | 39,501,858 | <p>Your starting point:</p>
<pre><code>import pandas as pd
from shapely.geometry import box
import matplotlib.pyplot as plt
from matplotlib.collections import PatchCollection
from matplotlib.patches import Polygon
from shapely.geometry import Point
import seaborn as sns
import numpy as np
# some pretend data
data = ... | 1 | 2016-09-15T01:16:55Z | [
"python",
"pandas",
"matplotlib",
"geopandas"
] |
How do I sum the rows of my dataframe so it only sums values based on the month, day, or year. Then form a report with all the results | 39,501,354 | <p>I am analyzing stock data from yahoo finance, I currently have my DataFrame = Df
filtered to show only the days for the month of march, since 1991. I want to be able to find out what the monthly returns are for march by year. Or any other combination of months i.e. what is the returns from January to March since 199... | 2 | 2016-09-15T00:00:44Z | 39,501,542 | <p>As in the comments, you can find monthly totals using groupby:</p>
<pre><code>#change the previous last line of code to this
df=df[['Date','year','month','Close%pd']][(df.month == 3)]
#make a new dataframe
new_df = df.groupby(['year','month']).sum()
</code></pre>
<p>An alternative method would be to use the <code... | 1 | 2016-09-15T00:29:09Z | [
"python",
"pandas",
"dataframe",
"report",
"filtering"
] |
How to call a method from a class with inheritence on an object of the base class? | 39,501,400 | <p>I have two classes. One inherits the other:</p>
<pre><code>class A(object):
def __init__(self):
self.attribute = 1
class B(A):
def get_attribute(self):
return self.attribute
</code></pre>
<p>I would like to be able to call methods from B on objects of type A. I cannot edit class A (it is a... | -1 | 2016-09-15T00:09:34Z | 39,501,775 | <p>While it is discouraged to do you can use any method like a function. In your case it would be</p>
<pre><code>B.get_attribute(a)
</code></pre>
<p>Of cause the method has to be compatible with the type of <code>a</code>.</p>
| 0 | 2016-09-15T01:04:04Z | [
"python",
"python-2.7"
] |
SQL Query output formatting URL in python | 39,501,424 | <p>I am new to python. I am writing a script which queries the database for a URL string. Below is my snippet.</p>
<pre><code>db.execute('select sitevideobaseurl,videositestring '
'from site, video '
'where siteID =1 and site.SiteID=video.VideoSiteID limit 1')
result = db.fetchall()
for row in res... | 0 | 2016-09-15T00:11:54Z | 39,501,465 | <p>Use <a href="https://docs.python.org/2/library/stdtypes.html#str.format" rel="nofollow"><code>str.format</code></a>.</p>
<pre><code>db.execute('select sitevideobaseurl,videositestring '
'from site, video '
'where siteID =1 and site.SiteID=video.VideoSiteID limit 1')
result = db.fetchall()
for r... | 0 | 2016-09-15T00:17:59Z | [
"python",
"sql",
"url",
"formatting"
] |
SQL Query output formatting URL in python | 39,501,424 | <p>I am new to python. I am writing a script which queries the database for a URL string. Below is my snippet.</p>
<pre><code>db.execute('select sitevideobaseurl,videositestring '
'from site, video '
'where siteID =1 and site.SiteID=video.VideoSiteID limit 1')
result = db.fetchall()
for row in res... | 0 | 2016-09-15T00:11:54Z | 39,501,518 | <p>You can use a "replace" command in either Sql or Python.</p>
<pre><code>str_url = str_url.replace('[','')
str_url = str_url.replace(']','')
str_url = str_url.replace('?','')
</code></pre>
<p>Something like this in Python which is the easier of the two to do.</p>
<p>Repeat for as many characters as you want to cho... | 0 | 2016-09-15T00:26:49Z | [
"python",
"sql",
"url",
"formatting"
] |
Python 3.5.2 Roman Numeral Quiz | 39,501,452 | <p>So I am doing this assignment for school. I have to create a quiz like game that will prompt a user to add roman numerals together and input their answer. It will then check the user's answer with the correct answer and tell the user if they got it right or wrong.</p>
<p>So far I have this:</p>
<pre><code>class Ro... | 1 | 2016-09-15T00:16:53Z | 39,501,473 | <p>Your error says</p>
<pre><code>local variable 'r_integer' referenced before assignment
</code></pre>
<p>This means you tried to use a variable before you defined it. Define <code>r_integer</code> to 0 (or some other number) before the <code>while</code> loop and your problem should be fixed.</p>
| 0 | 2016-09-15T00:19:24Z | [
"python",
"roman-numerals"
] |
Python 3.5.2 Roman Numeral Quiz | 39,501,452 | <p>So I am doing this assignment for school. I have to create a quiz like game that will prompt a user to add roman numerals together and input their answer. It will then check the user's answer with the correct answer and tell the user if they got it right or wrong.</p>
<p>So far I have this:</p>
<pre><code>class Ro... | 1 | 2016-09-15T00:16:53Z | 39,501,497 | <p>You need to initialize <code>r_integer</code> before the <code>while</code> loop. Added to your code below the ##### comment </p>
<pre><code> #Add if the number is greater than the one that follows, otherwise
#subtract r_integer = 0
#Stands for roman integer or the integer equivalent of the roman string
... | 0 | 2016-09-15T00:23:38Z | [
"python",
"roman-numerals"
] |
Python 3.5.2 Roman Numeral Quiz | 39,501,452 | <p>So I am doing this assignment for school. I have to create a quiz like game that will prompt a user to add roman numerals together and input their answer. It will then check the user's answer with the correct answer and tell the user if they got it right or wrong.</p>
<p>So far I have this:</p>
<pre><code>class Ro... | 1 | 2016-09-15T00:16:53Z | 39,501,773 | <p>You aren't using the integer defined for self. Try adding a declaration after </p>
<pre><code> r_string = r_string.upper()
</code></pre>
<p>Add </p>
<pre><code>r_integer = self.__integer
</code></pre>
<p>That way you have a local copy to work with. </p>
<p>However you do need to overload the integer method whic... | 0 | 2016-09-15T01:03:38Z | [
"python",
"roman-numerals"
] |
(Python) Stop thread with raw input? | 39,501,529 | <p><strong>EDIT 9/15/16:</strong> In my original code (still posted below) I tried to use <code>.join()</code> with a function, which is a silly mistake because it can only be used with a thread object. I am trying to
(1) continuously run a thread that gets data and saves it to a file
(2) have a second thread, or inc... | 2 | 2016-09-15T00:27:58Z | 39,501,789 | <p>This is not possible. The thread function has to finish. You can't join it from the outside.</p>
| 0 | 2016-09-15T01:05:52Z | [
"python",
"multithreading"
] |
(Python) Stop thread with raw input? | 39,501,529 | <p><strong>EDIT 9/15/16:</strong> In my original code (still posted below) I tried to use <code>.join()</code> with a function, which is a silly mistake because it can only be used with a thread object. I am trying to
(1) continuously run a thread that gets data and saves it to a file
(2) have a second thread, or inc... | 2 | 2016-09-15T00:27:58Z | 39,501,792 | <p>You're looking for something like this:</p>
<pre><code>from threading import Thread
from time import sleep
# "volatile" global shared by threads
active = True
def get_data():
while active:
print "working!"
sleep(3)
def wait_on_user():
global active
raw_input("press enter to stop")
... | 0 | 2016-09-15T01:06:33Z | [
"python",
"multithreading"
] |
(Python) Stop thread with raw input? | 39,501,529 | <p><strong>EDIT 9/15/16:</strong> In my original code (still posted below) I tried to use <code>.join()</code> with a function, which is a silly mistake because it can only be used with a thread object. I am trying to
(1) continuously run a thread that gets data and saves it to a file
(2) have a second thread, or inc... | 2 | 2016-09-15T00:27:58Z | 39,502,488 | <p>The error you see is a result of calling join on the function. You need to call <code>join</code> on the <code>thread</code> object. You don't capture a reference to the thread so you have no way to call <code>join</code> anyway. You should <code>join</code> like so.</p>
<pre><code>th1 = thread.start_new_thread( mo... | 0 | 2016-09-15T02:59:14Z | [
"python",
"multithreading"
] |
Use enumerate to find indices of all words with letter 'x' | 39,501,531 | <p>How use enumerate to help find the indices of all words containing 'x' </p>
<p>Thank you</p>
<pre><code>wordsFile = open("words.txt", 'r')
words = wordsFile.read()
wordsFile.close()
wordList = words.split()
indices=[]
for (index, value) in enumerate(wordList):
if value == 'x':
print("These locations contain... | -1 | 2016-09-15T00:28:03Z | 39,501,599 | <p>Your code is almost complete:</p>
<pre><code>for (index, value) in enumerate(wordList):
if 'x' in value:
indices.append(index)
</code></pre>
<p>This checks, for every single word, if there is an <code>x</code> in it. If so, it adds the index to <code>indices</code>.</p>
| 1 | 2016-09-15T00:37:15Z | [
"python",
"python-3.x"
] |
Add values to bottom of DataFrame automatically with Pandas | 39,501,554 | <p>I'm initializing a DataFrame:</p>
<pre><code>columns = ['Thing','Time']
df_new = pd.DataFrame(columns=columns)
</code></pre>
<p>and then writing values to it like this:</p>
<pre><code>for t in df.Thing.unique():
df_temp = df[df['Thing'] == t] #filtering the df
df_new.loc[counter,'Thing'] = t #writing the... | 2 | 2016-09-15T00:30:44Z | 39,502,967 | <p>If I'm interpreting this correctly, I think this can be done in one line:</p>
<pre><code>newDf = df.groupby('Thing')['delta'].sum().reset_index()
</code></pre>
<p>By grouping by 'Thing', you have the various "t-filters" from your for-loop. We then apply a <code>sum()</code> to 'delta', but only within the various ... | 3 | 2016-09-15T04:08:22Z | [
"python",
"pandas"
] |
UnboundLocalError: Says variable isn't defined before being used | 39,501,627 | <p>when i run my game function i get this error:</p>
<pre><code> Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "hog.py", line 162, in play
if is_swap(score0,score1)== True and who == 0:
File "hog.py", line 121, in is_swap
elif swap1 == score0:
UnboundLocalErro... | -1 | 2016-09-15T00:41:48Z | 39,501,733 | <p>None of the branches of your <code>if</code>/<code>elif</code> logic handle the situation where <code>score1</code> is exactly 100. This leaves <code>swap1</code> undefined, leading to the error you've described.</p>
<p>To avoid this, make sure your different conditions cover all branches. Often this is easiest if ... | 1 | 2016-09-15T00:57:29Z | [
"python"
] |
'int' object has no attribute '__getitem__' on a non-integer object | 39,501,670 | <p>In looking at other answers to this issue I found that the object was usually an integer so i constructed a simple example showing it is not and integer (or so I think), <strong>this code:</strong></p>
<pre><code>import numpy as np
a=np.arange(2,10)
print '1: ', a
print '2: ', a.size
print '3: ', a[3:] #this shows ... | -2 | 2016-09-15T00:48:38Z | 39,501,716 | <p>If you want the size of <code>a[3:]</code> then try:</p>
<pre><code>>>> a[3:].size
5
</code></pre>
<p>By writing <code>a.size[3:]</code> what you are trying to do is <code>index</code> over an <code>integer</code> as <code>a.size</code> is an <code>integer</code>.</p>
| 2 | 2016-09-15T00:54:21Z | [
"python"
] |
Is subclassing from object the same as defining type as metaclass? | 39,501,774 | <p>This is an old-style class:</p>
<pre><code>class OldStyle:
pass
</code></pre>
<p>This is a new-style class:</p>
<pre><code>class NewStyle(object):
pass
</code></pre>
<p>This is also a new-style class:</p>
<pre><code>class NewStyle2:
__metaclass__ = type
</code></pre>
<p>Is there any difference what... | 5 | 2016-09-15T01:03:51Z | 39,987,578 | <p>Pretty much yes, there's no difference between <code>NewStyle</code> and <code>NewStyle2</code>. Both are of type <code>type</code> while <code>OldStyle</code> of type <code>classobj</code>.</p>
<p>If you subclass from object, the <a href="https://hg.python.org/cpython/file/2.7/Python/ceval.c#l4949" rel="nofollow">... | 2 | 2016-10-11T22:10:15Z | [
"python",
"python-2.7",
"python-internals",
"new-style-class"
] |
Python multiprocessing silent failure with class | 39,501,785 | <p>the following does not work using python 2.7.9, but also does not throw any error or exception. is there a bug, or can multiprocessing not be used in a class?</p>
<pre><code>from multiprocessing import Pool
def testNonClass(arg):
print "running %s" % arg
return arg
def nonClassCallback(result):
print ... | 1 | 2016-09-15T01:05:14Z | 39,501,851 | <p>I'm pretty sure it can be used in a class, but you need to protect the call to <code>Foo</code> inside of a clause like:</p>
<p><code>if name == "__main__":</code></p>
<p>so that it only gets called in the main thread. You may also have to alter the <code>__init__</code> function of the class so that it accepts a ... | 0 | 2016-09-15T01:16:24Z | [
"python",
"class",
"multiprocessing"
] |
Python multiprocessing silent failure with class | 39,501,785 | <p>the following does not work using python 2.7.9, but also does not throw any error or exception. is there a bug, or can multiprocessing not be used in a class?</p>
<pre><code>from multiprocessing import Pool
def testNonClass(arg):
print "running %s" % arg
return arg
def nonClassCallback(result):
print ... | 1 | 2016-09-15T01:05:14Z | 39,501,991 | <p>Processes don't share state or memory by default, each process is an independent program. You need to either 1) use threading 2) use <a href="https://docs.python.org/2/library/multiprocessing.html#sharing-state-between-processes" rel="nofollow">specific types capable of sharing state</a> or 3) design your program to... | 1 | 2016-09-15T01:40:24Z | [
"python",
"class",
"multiprocessing"
] |
why is 2 printed as a prime when if statement says it should not be | 39,501,839 | <p>i know 2 is a prime number (btw), but when this code is ran it doesn't match the if statement condition <code>if n % x == 0</code>. but <code>2 % 2 == 0</code> so it should be a equal </p>
<pre><code>for n in range(2, 10):
for x in range(2, n):
if n % x == 0:
print(n, 'equals', x, '*', n//... | 0 | 2016-09-15T01:14:47Z | 39,501,909 | <p>From the Python documentation of <a href="https://docs.python.org/3/library/stdtypes.html#typesseq-range" rel="nofollow"><code>range()</code></a></p>
<blockquote>
<p>For a positive <em>step</em>, the contents of a range <code>r</code> are determined by the formula <code>r[i] = start + step*i</code> where <code>i ... | 5 | 2016-09-15T01:25:03Z | [
"python",
"python-3.x"
] |
Create a Ansible dictionary which keeps order | 39,501,901 | <p>How could I create dictionary with order?</p>
<p>I have dictionary as </p>
<pre><code>vars:
myDict:
Bob: 30
Alice: 20
</code></pre>
<p>How could I keep <code>"Bob"</code> in front of <code>"Alice"</code>? Ansible orders this map for me based on key letters</p>
| 0 | 2016-09-15T01:23:59Z | 39,504,343 | <p>There is no way to do this. Please, search for "python dict order".</p>
<p>You can only replace your original dict with a list:</p>
<pre><code>myListofDict:
- key: Bob
value: 30
- key: Alice
value: 20
</code></pre>
| 0 | 2016-09-15T06:27:21Z | [
"python",
"ansible"
] |
How to automatically input using python Popen and return control to command line | 39,501,950 | <p>I have a question regarding subprocess.Popen .I'm calling a shell script and provide fewinputs. After few inputs ,I want user running the python script to input.</p>
<p>Is it possible to transfer control from Popen process to command line.</p>
<p>I've added sample scripts</p>
<p>sample.sh</p>
<pre><code>echo "hi... | 0 | 2016-09-15T01:33:04Z | 39,519,093 | <p>As soon as your last <code>write</code> is executed in your python script, it will exit, and the child shell script will be terminated with it. You request seems to indicate that you would want your child shell script to keep running and keep getting input from the user. If that's the case, then <code>subprocess</co... | 1 | 2016-09-15T19:40:03Z | [
"python",
"shell",
"command-line"
] |
Comparing dates in template Django | 39,501,953 | <p>I have two dates in a template that I need to compare in an if statement.</p>
<p>Date1 is from the created field of a data element {{ endjob.created|date:"Y-m-d" }} that is displayed as 2016-09-12</p>
<p>Date2 if from an array {{ pay_period.periods.0.0 }} that is displayed as 2016-09-04</p>
<p>Therefore I am tryi... | 0 | 2016-09-15T01:33:54Z | 39,502,426 | <p>You are probably comparing two different data types which is why you are not getting anything. By doing <code>endjob.created|date:"Y-m-d"</code>,you are converting <code>endjob.created</code> to a string. Yes, <code>{{ pay_period.periods.0.0 }}</code> is displayed as the string '2016-09-04'. That is what the <code>{... | 0 | 2016-09-15T02:49:50Z | [
"python",
"django"
] |
python making a live output of cpu usage | 39,501,982 | <p>So I would like to make a python program that displays the computers cpu usage in real time. So far I am using the psutil module to find cpu usage but I'm not sure how to represent the output visualy.</p>
<pre><code>import psutil
x=(2)
while x>0:
cpu = psutil.cpu_percent(interval=1, percpu=False)
print(c... | -1 | 2016-09-15T01:38:29Z | 39,502,386 | <p>tkinter is a simple gui package that comes bundled with python. You could use that.</p>
<p>Or you could <code>sys.stdout.write</code> to print the result without a <code>\n</code> every second or so, with <code>\r</code> at the beginning to bring the character cursor to the beginning of the line. This would make a... | 0 | 2016-09-15T02:42:04Z | [
"python",
"psutil"
] |
How to create a new numpy array from a calculation of elements within an existing numpyarray | 39,502,021 | <p>I'm a Python and Numpy newbie...and I'm stuck. I'm trying to create a new numpy array from the log returns of elements in an existing numpy array (i.e. new array = old array(with ln(x/x-1)). I was not using Pandas dataframe because I plan to incorporate the correlations of the returns (i.e. "new array) into a lar... | 0 | 2016-09-15T01:44:23Z | 39,502,040 | <p>Numpy as <code>log</code> function, you can apply it directly to an array. The return value will be a new array of the same shape. Keep in mind that the input should be an array of positive values with <code>dtype == float</code>.</p>
<pre><code>import numpy
old_array = numpy.random.random(5.) * 10.
new_array = nu... | 1 | 2016-09-15T01:46:56Z | [
"python",
"arrays",
"numpy"
] |
While statment loop in python | 39,502,051 | <p>I am learning python, and I am stuck in an infinite while loop in the following code.</p>
<pre><code>A = input("Hello what is your name? ")
D = input("What is today's date? ")
B = input("Did you have a good day [y/N]")
while B != "y" or B != "Y" or B != "N" or B != "n":
B = input("Did you have a good day [y/N]"... | 0 | 2016-09-15T01:47:57Z | 39,502,086 | <p>The issue is that you are doing <code>while B != "y" or B != "Y" or B != "N" or B != "n":</code></p>
<p>With <code>or</code> it returns true if either of its options are true. So if B="N"
<code>b!="N" or b!=n"</code> is true because b still isn't "n"</p>
<p>You can solve this by replacing all the <code>or</code>s ... | 0 | 2016-09-15T01:54:20Z | [
"python",
"while-loop"
] |
While statment loop in python | 39,502,051 | <p>I am learning python, and I am stuck in an infinite while loop in the following code.</p>
<pre><code>A = input("Hello what is your name? ")
D = input("What is today's date? ")
B = input("Did you have a good day [y/N]")
while B != "y" or B != "Y" or B != "N" or B != "n":
B = input("Did you have a good day [y/N]"... | 0 | 2016-09-15T01:47:57Z | 39,502,093 | <p>The problem is here:</p>
<pre><code>while B != "y" or B != "Y" or B != "N" or B != "n":
</code></pre>
<p><code>B</code> is <em>always</em> not equal to one of those. If it's "y" it is not equal to the other three, and so on. And since you are using <code>or</code> to combine these conditions, the loop continues if... | 2 | 2016-09-15T01:55:41Z | [
"python",
"while-loop"
] |
While statment loop in python | 39,502,051 | <p>I am learning python, and I am stuck in an infinite while loop in the following code.</p>
<pre><code>A = input("Hello what is your name? ")
D = input("What is today's date? ")
B = input("Did you have a good day [y/N]")
while B != "y" or B != "Y" or B != "N" or B != "n":
B = input("Did you have a good day [y/N]"... | 0 | 2016-09-15T01:47:57Z | 39,502,095 | <p>This line</p>
<pre><code>elif B == "N" or "n":
</code></pre>
<p>Should be</p>
<pre><code>elif B == "N" or B == "n":
</code></pre>
<p>You should use condition, simply <code>"n"</code> (non empty string) means <code>true</code></p>
| 0 | 2016-09-15T01:55:49Z | [
"python",
"while-loop"
] |
While statment loop in python | 39,502,051 | <p>I am learning python, and I am stuck in an infinite while loop in the following code.</p>
<pre><code>A = input("Hello what is your name? ")
D = input("What is today's date? ")
B = input("Did you have a good day [y/N]")
while B != "y" or B != "Y" or B != "N" or B != "n":
B = input("Did you have a good day [y/N]"... | 0 | 2016-09-15T01:47:57Z | 39,502,099 | <p>Lets use a simplified version of your while loop.</p>
<pre><code>while B != "Y" or B != "y":
# ...
</code></pre>
<p>There is no way that this will ever evaluate to <code>False</code>.</p>
<p>If B was set to <code>Y</code> then <code>B != "Y"</code> would be <code>False</code>, but <code>B != "y"</code> would ... | 1 | 2016-09-15T01:56:12Z | [
"python",
"while-loop"
] |
While statment loop in python | 39,502,051 | <p>I am learning python, and I am stuck in an infinite while loop in the following code.</p>
<pre><code>A = input("Hello what is your name? ")
D = input("What is today's date? ")
B = input("Did you have a good day [y/N]")
while B != "y" or B != "Y" or B != "N" or B != "n":
B = input("Did you have a good day [y/N]"... | 0 | 2016-09-15T01:47:57Z | 39,502,176 | <p>This is the simplest solution!</p>
<pre><code>while B not in "YNyn":
</code></pre>
| 0 | 2016-09-15T02:06:36Z | [
"python",
"while-loop"
] |
pypyodbc execute delete query error "Function sequence error" | 39,502,054 | <p>I was able to execute the delete SQL query in Python with pypyodbc as below</p>
<pre><code>cur.execute("delete from table_a where a ='a';").commit()
</code></pre>
<p>However, I failed to run the delete SQL with a subquery</p>
<pre><code>cur.execute("delete from table_a where a in ( select a from table_b );").comm... | 0 | 2016-09-15T01:48:16Z | 39,520,923 | <p>The cause of this issue is pypyodbc not work with the delete command that actually delete nothing.</p>
<p>If I run "delete from table_a where a ='a';" twice, first time it will success and second time return error.</p>
<p>To run delete command with subquery, I need to check whether subquery really have records.</p... | 0 | 2016-09-15T21:54:53Z | [
"python",
"sql",
"vertica",
"pypyodbc"
] |
in Python, is there a way to break a wrapping, centered text prhase so that there is not a single word left hanging under a long string? | 39,502,057 | <p>in Python, is there a way to break a wrapping, centered text prhase so that there is not a single word left hanging under a long string?</p>
<p>Example, assuming this is centered:</p>
<p>**West Dakota Department of Fish and </p>
<pre><code> Game**
</code></pre>
<p>The word "Game" is short, and the string ... | 0 | 2016-09-15T01:49:01Z | 39,502,185 | <p>a couple of things, you could get fancy and parse the length of the longest sub-string as well rather than specifying the format width (eg. ^20) in the centering portion of the expression</p>
<pre><code>>>> import textwrap
>>> a = "West Dakota Department of Fish and Game"
>>> wdth = int(l... | 0 | 2016-09-15T02:07:55Z | [
"python"
] |
Use strings in a list as variable names in Python | 39,502,079 | <p>I have a list of string elements like <code>user_contract = ['ZNZ6','TNZ6','ZBZ6']</code></p>
<p>I have a data set which has nested list structure like <code>data = [[1,2,3],[4,5,6],[7,8,9]]</code></p>
<p>I want to assign each of the <code>user_contract</code> strings as variable names for each of the <code>data</... | 0 | 2016-09-15T01:52:47Z | 39,502,114 | <p>Please try if this code can help you. </p>
<pre><code>user_contract = ['ZNZ6','TNZ6','ZBZ6']
data = [[1,2,3],[4,5,6],[7,8,9]]
dictionary = dict(zip(user_contract, data))
print(dictionary)
</code></pre>
<p>It creates a dictionary from the two lists and prints it:</p>
<pre><code>python3 pyprog.py
{'ZBZ6': [7, 8, 9... | 0 | 2016-09-15T01:59:02Z | [
"python",
"list"
] |
Use strings in a list as variable names in Python | 39,502,079 | <p>I have a list of string elements like <code>user_contract = ['ZNZ6','TNZ6','ZBZ6']</code></p>
<p>I have a data set which has nested list structure like <code>data = [[1,2,3],[4,5,6],[7,8,9]]</code></p>
<p>I want to assign each of the <code>user_contract</code> strings as variable names for each of the <code>data</... | 0 | 2016-09-15T01:52:47Z | 39,502,116 | <p>You can use a dictionary comprehension to assign the values:</p>
<pre><code>myvars = {user_contract[i]: data[i] for i in len(user_contract}
</code></pre>
<p>Then you can access the values like so</p>
<pre><code>myvars['TNZ6']
> [1, 2, 3]
</code></pre>
| 0 | 2016-09-15T01:59:17Z | [
"python",
"list"
] |
Use strings in a list as variable names in Python | 39,502,079 | <p>I have a list of string elements like <code>user_contract = ['ZNZ6','TNZ6','ZBZ6']</code></p>
<p>I have a data set which has nested list structure like <code>data = [[1,2,3],[4,5,6],[7,8,9]]</code></p>
<p>I want to assign each of the <code>user_contract</code> strings as variable names for each of the <code>data</... | 0 | 2016-09-15T01:52:47Z | 39,502,764 | <p>You can use <code>exec</code> to evaluate expressions and assign to variables dynamically:</p>
<pre><code>>>> names = ','.join(user_contract)
>>> exec('{:s} = {:s}'.format(names, str(data)))
</code></pre>
| 0 | 2016-09-15T03:39:17Z | [
"python",
"list"
] |
Gmail API messages.modify 40x slower than IMAP? | 39,502,142 | <p>I'm creating an app to move messages around in a user's inbox. Currently I'm using the Gmail API to do so, but I've noticed that making requests to the API is markedly slower than using IMAP. </p>
<p>The method is straightforward: I'm sending a batch of modify requests to change the labels on a group of emails in o... | 1 | 2016-09-15T02:02:31Z | 39,519,295 | <p>Reading through the GMail API you seem to be doing it "right". I'm going to guess that because GMail is itself a mail client the GMail API is targeted at writing toy mail clients while IMAP is better designed for the efficient bulk work of a fully functional mail client.</p>
<p>If you're moving <em>every</em> messa... | 0 | 2016-09-15T19:52:22Z | [
"python",
"imap",
"gmail-api"
] |
Python Turtle - Is it possible to prevent the crash at the end | 39,502,170 | <p>this is my code. I am using the turtle module to just write some text on the screen for a project for school. But whenever I do this, the program crashes/stops responding and I was wondering if it is possible to prevent this from happening.</p>
<pre><code>import turtle
screen = turtle.Screen()
screen.screensize(50... | 0 | 2016-09-15T02:06:00Z | 39,502,226 | <p>Your code hasn't crashed, it just ran out of code to process. The code that is there is working fine and as expected.</p>
<p>To see what I mean add:</p>
<pre><code>print("END") #Python 3
print "END" #Python 2
</code></pre>
<p>to the end of your code. You will see the console prints the word "END" after your text... | 2 | 2016-09-15T02:14:03Z | [
"python",
"python-2.7"
] |
Make executable symbolic link in Python? | 39,502,197 | <p>I have a file called <code>client.py</code>. I created a symbolic link called <code>incro</code> using </p>
<pre><code>ln -s client.py incro
</code></pre>
<p>How do I make this script executable and move it to my bin (I'm on Linux using Ubuntu, with a bash terminal), under the name of <code>incro</code>? So that I... | 0 | 2016-09-15T02:09:13Z | 39,502,237 | <p>In Linux to make a file executable you will need to set the file with the following command:</p>
<pre><code>chmod +x [filename]
</code></pre>
<p>This will make the file executable to root, user, and group owners.</p>
<p>To make the file executable from any directory you will need to make sure that the directory i... | 1 | 2016-09-15T02:16:14Z | [
"python",
"bash",
"bin"
] |
Make executable symbolic link in Python? | 39,502,197 | <p>I have a file called <code>client.py</code>. I created a symbolic link called <code>incro</code> using </p>
<pre><code>ln -s client.py incro
</code></pre>
<p>How do I make this script executable and move it to my bin (I'm on Linux using Ubuntu, with a bash terminal), under the name of <code>incro</code>? So that I... | 0 | 2016-09-15T02:09:13Z | 39,502,262 | <p>Put the link in your <code>bin</code> directory, not the current directory:</p>
<pre><code>ln -s $PWD/client.py ~/bin/incro
</code></pre>
<p>You should also have <code>~/bin</code> in your <code>$PATH</code> so that you can run programs that are in there.</p>
<p>And if the script isn't already executable, add tha... | 1 | 2016-09-15T02:20:38Z | [
"python",
"bash",
"bin"
] |
Make executable symbolic link in Python? | 39,502,197 | <p>I have a file called <code>client.py</code>. I created a symbolic link called <code>incro</code> using </p>
<pre><code>ln -s client.py incro
</code></pre>
<p>How do I make this script executable and move it to my bin (I'm on Linux using Ubuntu, with a bash terminal), under the name of <code>incro</code>? So that I... | 0 | 2016-09-15T02:09:13Z | 39,513,585 | <p>By default symbolic links follow file permissions so you don't make symbolic link executable, but simply make your client.py file executable.</p>
<p>Command:</p>
<pre><code>ln -s client.py incro
</code></pre>
<p>Creates relative symbolic link so you can't simply copy or move it to other directory.
To make link mo... | 1 | 2016-09-15T14:22:51Z | [
"python",
"bash",
"bin"
] |
lambda python function with external library psycopg2 - No module named psycopg2 | 39,502,265 | <p>Error Message - No module named psycopg2<br>
File used in zip - <a href="https://github.com/jkehler/awslambda-psycopg2" rel="nofollow">https://github.com/jkehler/awslambda-psycopg2</a> <br>
Code Snippet -<br></p>
<pre><code> #!/usr/bin/python
import psycopg2
import sys
import pprint
import datetime
def lambda_h... | 1 | 2016-09-15T02:21:19Z | 39,502,387 | <p>psycopg2 is a compiled module. Copying the Windows version won't work because Lambda runs on top of Amazon Linux. According to <a href="https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/" rel="nofollow">the docs</a> it is possible to run native executables and libraries on lambda, but you'll nee... | 1 | 2016-09-15T02:42:17Z | [
"python",
"python-2.7",
"lambda",
"aws-lambda",
"amazon-lambda"
] |
Regular expression to replace all occurrences of U.S | 39,502,301 | <p>I'm trying to write a regular expression to replace all occurrences of U.S. . Here's what I thought would work.</p>
<pre><code>string = re.sub(r'\bU.S.\b', 'U S ', string)
</code></pre>
<p>When I run this it only finds the first occurrence. Why is this and how can I resolve this issue. Thanks </p>
| 0 | 2016-09-15T02:27:37Z | 39,502,369 | <p>The problem is that <code>.</code> has special meaning in regular expressions (it matches any character), so it needs to be escaped.</p>
<pre><code>string = re.sub(r'\bU\.S\.', 'U S ', string)
</code></pre>
<p>Also, you shouldn't use <code>\b</code> after <code>.</code>. <code>\b</code> matches between a word and ... | 2 | 2016-09-15T02:38:23Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.