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 |
|---|---|---|---|---|---|---|---|---|---|
App engine PHP modules not working | 38,716,279 | <p>I read the docs about GAE's modules. This <a href="https://github.com/GoogleCloudPlatform/appengine-modules-helloworld-python" rel="nofollow">sample application</a> shows how to use modules in a GAE app. I have modified the code little bit to use both <a href="http://stackoverflow.com/a/21588987/3297613">php and pyt... | 0 | 2016-08-02T09:11:33Z | 38,734,406 | <p>I have ran your code without a problem.</p>
<p><a href="http://i.stack.imgur.com/elHfS.png" rel="nofollow"><img src="http://i.stack.imgur.com/elHfS.png" alt="php module"></a>
<a href="http://i.stack.imgur.com/JJtyD.png" rel="nofollow"><img src="http://i.stack.imgur.com/JJtyD.png" alt="python module"></a></p>
<pre>... | 1 | 2016-08-03T04:26:24Z | [
"php",
"python",
"google-app-engine"
] |
capture response data into an array using python | 38,716,359 | <p>Capture response data into an array using python:</p>
<p>When I read an url using urlib2 I get the below response in the console using print resp</p>
<pre><code>code : resp = urllib2.urlopen(memberProfileInfo).read()
Console display
OCODE: 11
UCODE: XXX
GID: XXXXXX
GDISP: XXXXX
\# rc=0, count=1, message=Success
... | 0 | 2016-08-02T09:15:16Z | 38,720,092 | <pre><code>I did this and it worked:
Code as below:
profdata = []
resp = urllib2.urlopen(memberProfileInfo).read()
profdata = resp.split('\n')
return profdata
However now in the excel I get all the response appended:
OCODE: 11 UCODE: XXX GID: XXXXXX GDISP: XXXXX \# rc=0, count=1, message=Success
Can we use regex and ... | 0 | 2016-08-02T12:12:02Z | [
"python",
"python-2.7"
] |
Python tkinter entry prompt | 38,716,453 | <p>I want to prompt a string of letters one for each time to ask user to click and the game will continue only when user press the correct key.</p>
<p>I am having trouble with the key pressing part. I want to get the text on the button and test if it matches with the prompted letter, if it matches the entry widget wil... | 1 | 2016-08-02T09:19:15Z | 38,720,653 | <p>You can resolve your problem by <a href="http://effbot.org/tkinterbook/tkinter-events-and-bindings.htm" rel="nofollow"><code>binding</code></a> the same event to each button you created.</p>
<p>Hence, in your callback you will need to identify the button which is clicked (which thing your actual code does not do) i... | 2 | 2016-08-02T12:38:39Z | [
"python",
"python-3.x",
"tkinter"
] |
PYTHON prime numbers function | 38,716,517 | <p>I am new to programming and I face an issue while trying to write a program in finding out prime number. Here is my code:</p>
<pre><code>def is_prime(x):
if x < 2:
return False
elif x == 2:
return True
else:
for n in range (2,x-1):
if x % n == 0:
re... | 0 | 2016-08-02T09:22:07Z | 38,716,556 | <p><code>range()</code> has an <a href="https://docs.python.org/3.4/library/stdtypes.html#range" rel="nofollow">exclusive upper bound</a>, so it's trying to get the range between 2 and 2 (3 - 1), which is no elements. Since you can't iterate over nothing, the for loop never runs, so <code>None</code> is returned (this ... | 3 | 2016-08-02T09:24:12Z | [
"python",
"if-statement",
"for-loop",
"primes",
"prime-factoring"
] |
PYTHON prime numbers function | 38,716,517 | <p>I am new to programming and I face an issue while trying to write a program in finding out prime number. Here is my code:</p>
<pre><code>def is_prime(x):
if x < 2:
return False
elif x == 2:
return True
else:
for n in range (2,x-1):
if x % n == 0:
re... | 0 | 2016-08-02T09:22:07Z | 38,716,812 | <pre><code>def is_prime(x):
if x < 2:
return False
elif x == 2:
return True
else:
for n in range (2,x): # range function will iterate till x-1
if x % n == 0:
return False
# return true only at the end after making sure it is not divisible by any... | 0 | 2016-08-02T09:35:50Z | [
"python",
"if-statement",
"for-loop",
"primes",
"prime-factoring"
] |
Python Session 10054 Connection Aborted Error | 38,716,539 | <p>I wrote a web scraper using requests module. I open up a session and send subsequent requests using this session. It has 2 phases.</p>
<p>1) Scrape page by page and collect id's in an array.
2) Get details about each id in the array using requests to an ajax server on the same host.</p>
<p>The scraper works fine o... | 0 | 2016-08-02T09:23:12Z | 39,290,736 | <p>I still don't know why this problem occurs only in Windows. However, retrying decorator seems to have fixed the problem of socket error. The reason why the script hangs was due to the server not responding to a request. By default requests mode waits forever for a response. By adding a timeout value requests throws ... | 0 | 2016-09-02T10:58:18Z | [
"python",
"windows",
"session",
"web-scraping",
"python-requests"
] |
Unable to run TensorFlow on Spark | 38,716,584 | <p>I am trying to make TensorFlow work on my Spark cluster in order to make it run in parallel.
As a start, I tried to use this <a href="https://gist.github.com/tnachen/e004539cdd38e5941d0cb712d0ad3b91" rel="nofollow">demo</a> as-is.</p>
<p>The demo works great without Spark, but when using Spark, I get the following ... | 2 | 2016-08-02T09:25:45Z | 38,723,690 | <p>I finally realised that the root-cause is the six module itself - it has some compatibility issues with spark, and whenever it is loaded there are problems.</p>
<p>Therefore, to solve the issue I searched for all the usages of the <strong><em>six</em></strong> package in the demo, and replaced them with an equivale... | 4 | 2016-08-02T14:47:12Z | [
"python",
"apache-spark",
"tensorflow",
"pyspark"
] |
using pandas.read_csv to read certain columns | 38,716,643 | <p>I have a .csv file with three columns and many rows. I am trying to use pandas to read only the third column.</p>
<p>right now I have:</p>
<pre><code>import pandas as pd
pd.read_csv(r"C:\test.csv",usecols=(3))
</code></pre>
| 1 | 2016-08-02T09:28:32Z | 38,716,698 | <p>column indexing is zero based, pass <code>2</code> to read the third column:</p>
<pre><code>pd.read_csv(r"C:\test.csv",usecols=[2])
</code></pre>
| 2 | 2016-08-02T09:30:51Z | [
"python",
"csv",
"pandas"
] |
gloabl name cx not defined | 38,716,862 | <p>I wanna call an Oracle function returning an objectby using cx_Oracle`s cursor.callfunc(). But this is not working</p>
<p>Here you can see my code:</p>
<pre><code>import cx_Oracle
import json
import web
urls = (
"/", "index",
"/grid", "grid",
)
app = web.application(urls, globals(),web.profiler )
web.config.debug... | 0 | 2016-08-02T09:38:22Z | 38,717,006 | <p>Simple typo. In the line</p>
<pre><code>cursor.callfunc("SDO2GEOJSON", cx.Oracle.OBJECT, [obj])
</code></pre>
<p>You should use <code>cx_Oracle.OBJECT</code></p>
| 1 | 2016-08-02T09:45:05Z | [
"python",
"web.py",
"cx-oracle"
] |
Python thread scope | 38,716,886 | <p>Both codes seem to have similar performance. How does the scope work in this case? Is any of them better than the other? Is there a better way to achieve the same behavior?</p>
<p>code 1:</p>
<pre><code>class ex:
b = 6
def foo(self, a):
def fooHandler(a):
while True:
print a
time.slee... | 3 | 2016-08-02T09:39:40Z | 38,718,152 | <p>This has nothing to do with threading, it's just a matter of using a value from nested scope vs. passing it explicitly as an argument and using it from local scope.</p>
<p>It doesn't particularly matter which approach you use in this case; you're using the same value in either case. Looking it up in nested scope is... | 0 | 2016-08-02T10:37:48Z | [
"python",
"multithreading",
"scope"
] |
Python thread scope | 38,716,886 | <p>Both codes seem to have similar performance. How does the scope work in this case? Is any of them better than the other? Is there a better way to achieve the same behavior?</p>
<p>code 1:</p>
<pre><code>class ex:
b = 6
def foo(self, a):
def fooHandler(a):
while True:
print a
time.slee... | 3 | 2016-08-02T09:39:40Z | 38,719,721 | <p>Well, there <strong>is</strong> a difference in the generated code (at least when using CPython 2.7.12):</p>
<pre><code>def runThread(a):
def threadFunc():
while True:
print a
time.sleep(1)
t = threading.Thread(target=threadFunc)
t.start()
</code></pre>
<p>Will issue a ... | 1 | 2016-08-02T11:52:57Z | [
"python",
"multithreading",
"scope"
] |
Python Json Config 'Extended Interpolation' | 38,716,890 | <p>I am currently using the Python library configparser:</p>
<pre><code>from configparser import ConfigParser, ExtendedInterpolation
</code></pre>
<p>I find the ExtendedInterpolation very useful because it avoids the risk of having to reenter constants in multiple places.</p>
<p>I now have a requirement to use a Jso... | 2 | 2016-08-02T09:39:52Z | 38,843,138 | <p>Try to use <code>string.Template</code>. But I'm not sure whether it's your need. There is one package can do this may be. Bellow is what i should do. </p>
<p><code>config.json</code></p>
<pre><code>{
"home_dir": "/home/joey",
"class_path": "/user/local/bin",
"dir_one": "${home_dir}/dir_one",
"dir... | 0 | 2016-08-09T06:00:53Z | [
"python",
"json",
"configparser"
] |
ImportError: DLL load failed: Le module spécifié est introuvable | 38,716,945 | <p>I use Python 3.5.2 32-bit on Windows 64-bit. I get this error when I execute the project which uses Scipy, Pandas and Numpy:</p>
<pre><code>Traceback (most recent call last):
import scipy.stats as stat
File "C:\Users\Mohammed\AppData\Local\Programs\Python\Python35-32\lib\site- packages\scipy\stats\__init_... | 0 | 2016-08-02T09:42:14Z | 39,146,632 | <p>Open the most concerned .pyd file with <a href="http://www.dependencywalker.com/" rel="nofollow">dependency walker</a> (the file should be somewhere in <em>Python35-32\lib\site-packages\scipy\special\</em> ) to find which dll is missing and where it is expected to be.</p>
| 0 | 2016-08-25T13:26:14Z | [
"python",
"pandas",
"numpy",
"scipy"
] |
Python: how to access a class's attribute from a module | 38,717,058 | <p>I have a main file, which contains mainly the GUI(Tkinter code). A window which has <code>Label</code>, a <code>Text</code> area where text gets updated on users action and a <code>Button</code>.</p>
<pre><code># ~/main.py
import Tkinter
import buttonevent
from itertools import cycle
msglist = ['main_msg1\n', 'mai... | 1 | 2016-08-02T09:47:27Z | 38,717,417 | <p>You can achieve what you want by giving a reference of the Root instance as a parameter to your functions:</p>
<p>Instead of assigning to the Root class:</p>
<pre><code>Root.status = Tkinter.StringVar()
</code></pre>
<p>Assign it to the Root instance:</p>
<pre><code>self.status = Tkinter.StringVar()
</code></pre... | 1 | 2016-08-02T10:03:32Z | [
"python",
"tkinter",
"attributeerror"
] |
Python: how to access a class's attribute from a module | 38,717,058 | <p>I have a main file, which contains mainly the GUI(Tkinter code). A window which has <code>Label</code>, a <code>Text</code> area where text gets updated on users action and a <code>Button</code>.</p>
<pre><code># ~/main.py
import Tkinter
import buttonevent
from itertools import cycle
msglist = ['main_msg1\n', 'mai... | 1 | 2016-08-02T09:47:27Z | 38,718,635 | <p>All "Root." changed as "self."
main.py</p>
<pre><code># ~/main.py
import Tkinter
import buttonevent
from itertools import cycle
curwin=None
msglist = ['main_msg1\n', 'main_msg2\n', 'main_msg3\n', 'main_msg4\n']
class Root(object):
def __init__(self, master):
self.msglist = cycle(msglist)
self.m... | 1 | 2016-08-02T11:02:14Z | [
"python",
"tkinter",
"attributeerror"
] |
Loop through file and execute an api request | 38,717,207 | <p>I'm trying to write a web service in Python (fairly new to it). I have acces to an API that wants an url in a specific format:</p>
<pre><code>http://api.company-x.com/api/publickey/string/0/json
</code></pre>
<p>It is not a problem to perform a GET-request one by one but I would like to do it in a batch. So I have... | 0 | 2016-08-02T09:53:54Z | 38,717,675 | <p>First open the file that has the strings,</p>
<pre><code>import requests
with open(filename) as file:
data = file.read()
split_data = data.split(',')
</code></pre>
<p>Then iterate through the list,</p>
<pre><code>for string in split_data:
r = requests.get(string)
(...your code...)
</code></pre>
<p>I... | 0 | 2016-08-02T10:15:38Z | [
"python",
"api",
"loops",
"batch-file",
"for-loop"
] |
Loop through file and execute an api request | 38,717,207 | <p>I'm trying to write a web service in Python (fairly new to it). I have acces to an API that wants an url in a specific format:</p>
<pre><code>http://api.company-x.com/api/publickey/string/0/json
</code></pre>
<p>It is not a problem to perform a GET-request one by one but I would like to do it in a batch. So I have... | 0 | 2016-08-02T09:53:54Z | 38,763,885 | <p>I've played around some more and this is what I wanted:</p>
<pre><code>#requests to talk easily with API's
import requests
#to use strip to remove spaces in textfiles.
import sys
#two variables to squeeze a string between these two so it will become a full uri
part1 = 'http://api.companyx.com/api/productkey/'
par... | 0 | 2016-08-04T09:43:31Z | [
"python",
"api",
"loops",
"batch-file",
"for-loop"
] |
Get attributes from module imported with star | 38,717,337 | <p>A python script needs a per-user configuration to override (redefine) "default" assignments (e.g. <code>path = "local/path/"</code>) which could by done by importing a custom module's attributes with <code>from custom_settings import *</code>. I would like to output the ones that are being changed by the custom mod... | -1 | 2016-08-02T09:59:45Z | 38,717,890 | <p>This may not be the neatest solution, and it seems painfully redundant, but you could always simply:</p>
<pre><code>from custom_settings import *
import custom_settings
overridden = ", ".join(a for a in dir(custom_settings) if not a.startswith("__"))
</code></pre>
| 0 | 2016-08-02T10:26:22Z | [
"python",
"python-3.x",
"python-3.5"
] |
regex for markdown validator | 38,717,564 | <p>I've been developing a Telegram bot with CMS with Markdown support. The tags supported are</p>
<pre><code>*bold text*
_italic text_
`inline fixed-width code`
```text
pre-formatted fixed-width code block
```
</code></pre>
<p>the problem is when there is, say, an opening <code>*</code> tag and no closing <code>*</co... | 1 | 2016-08-02T10:10:27Z | 38,717,900 | <p>To check if the line starts and ends with '*' try regex pattern</p>
<pre><code>> ^\*.*\*$
</code></pre>
| 0 | 2016-08-02T10:26:49Z | [
"python",
"regex",
"markdown"
] |
regex for markdown validator | 38,717,564 | <p>I've been developing a Telegram bot with CMS with Markdown support. The tags supported are</p>
<pre><code>*bold text*
_italic text_
`inline fixed-width code`
```text
pre-formatted fixed-width code block
```
</code></pre>
<p>the problem is when there is, say, an opening <code>*</code> tag and no closing <code>*</co... | 1 | 2016-08-02T10:10:27Z | 38,718,913 | <p>This approach might suit your needs:</p>
<pre><code>import re
teststring="*hello*?Q@*()@(UE) World?@(EI)@EN *"
results=re.findall("^[*].*[*]$",teststring)
if not len(results)==1:
raise Exception
</code></pre>
<p>It assumes that a line starts with * and ends with *.
The _ and ' cases would follow a similar appr... | 0 | 2016-08-02T11:15:10Z | [
"python",
"regex",
"markdown"
] |
python rfc3161 verification failed but openssl verification is ok | 38,717,609 | <p>I am trying to get my content timestamped so I know when it was changed. First I used a shell script but I want to implement it in my python program. the shell script works fine for now but I can't get the python version to work for me.
This is the <strong>working</strong> shell version</p>
<pre><code>in_file='test... | 0 | 2016-08-02T10:12:28Z | 38,784,069 | <p>The problem lies in the library <a href="https://pypi.python.org/pypi/rfc3161" rel="nofollow">rfc3161</a> that I used. It seems like the author does not include check for TSA authority certificate so I had to make a change to the library.</p>
<p>The changed code is in <code>api.py</code> in <code>check_timestamp</c... | 0 | 2016-08-05T07:57:15Z | [
"python",
"shell",
"ssl",
"trusted-timestamp"
] |
python rfc3161 verification failed but openssl verification is ok | 38,717,609 | <p>I am trying to get my content timestamped so I know when it was changed. First I used a shell script but I want to implement it in my python program. the shell script works fine for now but I can't get the python version to work for me.
This is the <strong>working</strong> shell version</p>
<pre><code>in_file='test... | 0 | 2016-08-02T10:12:28Z | 38,809,586 | <p>python-rfc3161's author here. If bad signature is returned, it means that the certificate your declared for TSA is not the one that is really used for signing.</p>
<p>The patch provided by melanholly does not seem right to me, you should never use certificate bundled with a signature to check if you cannot verify i... | 0 | 2016-08-06T23:26:49Z | [
"python",
"shell",
"ssl",
"trusted-timestamp"
] |
Python:Input images in a list with a for loop | 38,717,651 | <p>Is there a way to fill a list with Images through a for loop and if so how do I do that?If there is no way just show me a way to add variables through a for loop in a list and I'll take it from there</p>
| -1 | 2016-08-02T10:14:15Z | 38,717,715 | <p>Adding items to a list is straightforward</p>
<pre><code>>>> l = []
>>> for i in range(10):
... l.append(i)
...
>>> l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
</code></pre>
| 0 | 2016-08-02T10:18:01Z | [
"python",
"list",
"for-loop",
"image-processing"
] |
Make Matlab print the complex unit as "j" instead of "i" | 38,717,710 | <p>I want to print complex data to a text-file using Matlab. Afterwards I want to read the data using Python (via the open() function for example). However, Matlab prints the complex numbers like</p>
<blockquote>
<p>1+1i</p>
</blockquote>
<p>but Python would like it in the form</p>
<blockquote>
<p>1+1j</p>
</blo... | 0 | 2016-08-02T10:17:45Z | 38,718,685 | <p>As you're writing to a text-file, while not just do the conversion there?</p>
<p>Something like</p>
<pre><code>>> a=1+2i
a =
1.0000 + 2.0000i
>> sprintf('%f+%fj',real(a), imag(a))
ans =
1.000000+2.000000j
</code></pre>
<p>You can of course replace <code>sprintf</code> with <code>fprintf</code>.</p>... | 2 | 2016-08-02T11:04:17Z | [
"python",
"matlab",
"complex-numbers"
] |
Make Matlab print the complex unit as "j" instead of "i" | 38,717,710 | <p>I want to print complex data to a text-file using Matlab. Afterwards I want to read the data using Python (via the open() function for example). However, Matlab prints the complex numbers like</p>
<blockquote>
<p>1+1i</p>
</blockquote>
<p>but Python would like it in the form</p>
<blockquote>
<p>1+1j</p>
</blo... | 0 | 2016-08-02T10:17:45Z | 38,722,971 | <p>Could you use a regex replacement? Perhaps the one in MATLAB?</p>
<pre><code>newStr=regexprep(str,'([\d.]+\s*[+\-]\s*[\d.]+)i','$1j');
</code></pre>
| 0 | 2016-08-02T14:17:06Z | [
"python",
"matlab",
"complex-numbers"
] |
Raspberry Pi as iBeacon reciever | 38,718,022 | <p>I have to make a iBeacon reciever for my Raspberry Pi and I have tried to follow this guide: <a href="http://www.switchdoc.com/2014/08/ibeacon-raspberry-pi-scanner-python/" rel="nofollow">http://www.switchdoc.com/2014/08/ibeacon-raspberry-pi-scanner-python/</a></p>
<p>The problem is that when I try the command: sud... | 0 | 2016-08-02T10:32:38Z | 38,718,648 | <p>If you followed the instructions exactly then <code>testblescan.py</code> should be in the <code>blescanner</code> sub-directory of your home directory. Try</p>
<pre><code>cd ~/blescanner
</code></pre>
<p>before you attempt to run the program. Then the Python interpreter should be able to find it.</p>
<p>If for s... | 0 | 2016-08-02T11:02:52Z | [
"python",
"linux",
"bluetooth",
"ibeacon"
] |
Python matplot3d - plot two sets of data on the same 3D plot | 38,718,082 | <p>I`m trying to plot 2 sets of data on a single 3D plot.
What I expect to see is these two images on the same plot:
<a href="http://i.stack.imgur.com/YdSIP.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/YdSIP.jpg" alt="enter image description here"></a></p>
<p>The plot I am looking for is this: <a href="http:... | 0 | 2016-08-02T10:34:57Z | 38,748,271 | <p>Note, that in the example code both the figures are present, you can see it by changing the code in the following way <code>Poly3DCollection([self.cords],alpha=0.5)</code>. It's just that the <code>add_collection3d</code> draws one over the other, so you don't see both.</p>
<p>I didn't find a way to beat it, but yo... | 0 | 2016-08-03T15:48:42Z | [
"python",
"matplotlib",
"plot"
] |
In DjangoRestFramework(DRF), name 'request' is not defined | 38,718,098 | <p>I'm making api that gets 'android or iphone' user's coordinates, and depend on that coordinates, makes 'post_list'(It means just post_list literally).</p>
<p>Using DRF i made my queryset(this queryset is for making 'post_list') like this</p>
<p><strong>views.py</strong></p>
<pre><code>from django.shortcuts import... | 1 | 2016-08-02T10:35:30Z | 38,718,164 | <pre><code>lat = request.POST.get('user_lat', '13')
lon = request.POST.get('user_lon', '15')
</code></pre>
<p>should be:</p>
<pre><code>lat = self.request.POST.get('user_lat', '13')
lon = self.request.POST.get('user_lon', '15')
</code></pre>
| 2 | 2016-08-02T10:38:38Z | [
"python",
"django",
"django-rest-framework"
] |
Construct image from 4D list | 38,718,234 | <p>I have a list of size <code>(10,10,3,64)</code></p>
<p>This represents a list of 64 images of size <code>10x10x3</code></p>
<p>I want to create 1 image of size <code>80x80x3</code>, where each image is side by side. I am not sure exactly how to merge these axes to make sure that the image integrity holds.</p>
<p>... | 2 | 2016-08-02T10:42:01Z | 38,718,296 | <p>IIUC one way to solve it would be with reshaping and permuting dimensions.</p>
<p>1) Reshape to split the last dimension into two dimensions.</p>
<p>2) Transpose to bring the last two split dims come next to the first two dims).</p>
<p>3) Finally reshape again to merge the first two dims and next two dims into on... | 3 | 2016-08-02T10:45:13Z | [
"python",
"list",
"python-2.7",
"numpy"
] |
Construct image from 4D list | 38,718,234 | <p>I have a list of size <code>(10,10,3,64)</code></p>
<p>This represents a list of 64 images of size <code>10x10x3</code></p>
<p>I want to create 1 image of size <code>80x80x3</code>, where each image is side by side. I am not sure exactly how to merge these axes to make sure that the image integrity holds.</p>
<p>... | 2 | 2016-08-02T10:42:01Z | 38,719,525 | <p>You could try this through <code>np.concatenate</code> and nested list comprehensions, e.g.:
</p>
<pre><code>arr = np.array(mylist)
arr2 = np.concatenate([ np.concatenate([arr[...,i + 8*j] for i in np.arange(8)],axis=0) for j in np.arange(8)],axis=1 )
print(arr2.shape)
</code></pre>
<p>gives</p>
<pre><code>(80,... | 1 | 2016-08-02T11:44:03Z | [
"python",
"list",
"python-2.7",
"numpy"
] |
Comparing values of two dictionaries | 38,718,339 | <p>I have two dictionaries as follows:</p>
<pre><code>a = {1:2, 3:4, 5:6}
b = {1:5, 3:6, 7:1}
</code></pre>
<p>For every key in <code>a</code>, I want to check if the key exists in <code>b</code>, if so, I want to print the value of both keys, if it does not, I print <code>0</code> as the value of the key in <code>b<... | 1 | 2016-08-02T10:47:13Z | 38,718,418 | <p>Use dict <code>b</code>'s <code>get</code> method, supplying a default value for use when the key isn't found.</p>
<pre><code>for key in a:
print key, a[key], b.get(key, '0')
</code></pre>
| 0 | 2016-08-02T10:51:16Z | [
"python",
"dictionary"
] |
Comparing values of two dictionaries | 38,718,339 | <p>I have two dictionaries as follows:</p>
<pre><code>a = {1:2, 3:4, 5:6}
b = {1:5, 3:6, 7:1}
</code></pre>
<p>For every key in <code>a</code>, I want to check if the key exists in <code>b</code>, if so, I want to print the value of both keys, if it does not, I print <code>0</code> as the value of the key in <code>b<... | 1 | 2016-08-02T10:47:13Z | 38,718,420 | <p>If I understand correctly, you want to iterate through all keys from either dictionary, and print their values from the two dictionaries, using <code>'0'</code> if the key is missing from that dictionary. Something like this:</p>
<pre><code>for key in set(a)|set(b):
print key, a.get(key, '0'), b.get(key, '0')
<... | 2 | 2016-08-02T10:51:31Z | [
"python",
"dictionary"
] |
Comparing values of two dictionaries | 38,718,339 | <p>I have two dictionaries as follows:</p>
<pre><code>a = {1:2, 3:4, 5:6}
b = {1:5, 3:6, 7:1}
</code></pre>
<p>For every key in <code>a</code>, I want to check if the key exists in <code>b</code>, if so, I want to print the value of both keys, if it does not, I print <code>0</code> as the value of the key in <code>b<... | 1 | 2016-08-02T10:47:13Z | 38,718,430 | <pre><code>for key in set(a.keys()) | set(b.keys()):
print key, a.get(key, 0), b.get(key,0)
</code></pre>
<p><code>|</code> means union in a set context. You can also convert the resulting set into a list and sort it before iterating.</p>
| 2 | 2016-08-02T10:51:52Z | [
"python",
"dictionary"
] |
For getting describe attributes checks in aws | 38,718,363 | <p>Here I am trying to get AWS limit check ids from <code>AWSLIMITCHECKER</code> module and from that I need to check <code>categorywise</code>.</p>
<p>This is my sample code:</p>
<pre><code>from awslimitchecker.checker import AwsLimitChecker
from awslimitchecker.trustedadvisor import TrustedAdvisor
#from awslimitche... | -1 | 2016-08-02T10:48:19Z | 38,742,021 | <pre><code> Hi i have resolved this,but when i getting check ids it shows the following
</code></pre>
<p>error:</p>
<pre><code> mycode:
d = TrustedAdvisor(services,
region='myregion',
account_id='none',
account_role='none'
)
e = d... | 0 | 2016-08-03T11:15:41Z | [
"python",
"amazon-web-services",
"aws-lib"
] |
py.test in Jenkins: No tests found in slack. Where I'm wrong? | 38,718,364 | <p>I keep receiving an error when run Build. py.tests in jenkins:</p>
<p>jenkins execute shell:</p>
<pre><code>#!/bin/sh
py.test tests || true
</code></pre>
<p>it starts. and after it finished I see next log:</p>
<pre><code> Started by user manny
Building in workspace /var/lib/jenkins/workspace/web-services tests... | 0 | 2016-08-02T10:48:20Z | 38,718,525 | <p>Run the same test manually (outside of Jenkins) and check the error there.
Could be a problem is test collection, or just a test failure itself.</p>
<p>Also: please post full logs so we can better check what is going on</p>
| 0 | 2016-08-02T10:56:45Z | [
"python",
"jenkins",
"slack"
] |
py.test in Jenkins: No tests found in slack. Where I'm wrong? | 38,718,364 | <p>I keep receiving an error when run Build. py.tests in jenkins:</p>
<p>jenkins execute shell:</p>
<pre><code>#!/bin/sh
py.test tests || true
</code></pre>
<p>it starts. and after it finished I see next log:</p>
<pre><code> Started by user manny
Building in workspace /var/lib/jenkins/workspace/web-services tests... | 0 | 2016-08-02T10:48:20Z | 38,718,568 | <p>Jenkins marks the build success/failed depending on the exit code. 0 is success, else failed.</p>
<p>Exitcode of Py.Test is 0 when there are no errors. When there are 1 or more errors, not 0 (maybe 1, no idea exactly).</p>
<p>Solution:</p>
<ul>
<li>Wrap your call into a seperate shellscript and ignore the exitcod... | 1 | 2016-08-02T10:59:01Z | [
"python",
"jenkins",
"slack"
] |
py.test in Jenkins: No tests found in slack. Where I'm wrong? | 38,718,364 | <p>I keep receiving an error when run Build. py.tests in jenkins:</p>
<p>jenkins execute shell:</p>
<pre><code>#!/bin/sh
py.test tests || true
</code></pre>
<p>it starts. and after it finished I see next log:</p>
<pre><code> Started by user manny
Building in workspace /var/lib/jenkins/workspace/web-services tests... | 0 | 2016-08-02T10:48:20Z | 38,718,920 | <p>From the log, we can see that the python script has failed</p>
<p><strong><code>collected 99 items / 4 errors</code></strong></p>
<p>And from Jenkins point of view, if any error is encountered, it will give failure as Jenkins uses <code>/bin/sh -xe</code> by default.</p>
<p>So by adding the <code>#!/bin/sh</code... | 0 | 2016-08-02T11:15:31Z | [
"python",
"jenkins",
"slack"
] |
State of Response object 'dead' while using livy with python | 38,718,448 | <p>I am trying to use livy, it is my first time with a REST api as well. Following the <a href="https://github.com/cloudera/livy" rel="nofollow">tutorial</a>, when I type</p>
<p><code>r = requests.post(statements_url, data=json.dumps(data), headers=headers)</code> </p>
<p>and then</p>
<p><code>r.json()</code></p>
<... | 0 | 2016-08-02T10:52:51Z | 38,720,983 | <p>After several attempts, I realized that I am running spark with scala 2.11, and Livy only supports Scala 2.10.</p>
| 0 | 2016-08-02T12:52:41Z | [
"python",
"rest",
"cloudera",
"hue"
] |
Django Rest Framework owner permissions | 38,718,454 | <p>I use Django Rest Framework and in my one of my viewsets class I have <strong>partial_update</strong> method (PATCH) for update my user profile. I want to create a permission for one user can update <strong><em>only his profile</em></strong>.</p>
<pre><code>class ProfileViewSet(viewsets.ModelViewSet):
"""
API endpo... | 1 | 2016-08-02T10:53:15Z | 38,718,896 | <p>You can add a custom permission that checks whether it's his own profile. Something like this.</p>
<pre><code># permissions.py
from rest_framework import permissions
class OwnProfilePermission(permissions.BasePermission):
"""
Object-level permission to only allow updating his own profile
"""
def ha... | 0 | 2016-08-02T11:14:09Z | [
"python",
"django",
"api",
"permissions",
"django-rest-framework"
] |
Django Rest Framework owner permissions | 38,718,454 | <p>I use Django Rest Framework and in my one of my viewsets class I have <strong>partial_update</strong> method (PATCH) for update my user profile. I want to create a permission for one user can update <strong><em>only his profile</em></strong>.</p>
<pre><code>class ProfileViewSet(viewsets.ModelViewSet):
"""
API endpo... | 1 | 2016-08-02T10:53:15Z | 38,718,998 | <p>IsOwnerOrReject is permission class that match the user to current login user otherwise it rejects.</p>
<p>In your case you have to define custom permission class. Which check user is login for other profile what ever permission you want to apply. You can do it like this:</p>
<pre><code>class IsUpdateProfile(permi... | 1 | 2016-08-02T11:19:28Z | [
"python",
"django",
"api",
"permissions",
"django-rest-framework"
] |
What's convention for naming a class or method as "class" in Python? | 38,718,484 | <p>Let's say I have a class in Python like this:</p>
<pre><code>class Student:
def __init__(self, classs):
self.classs = classs
</code></pre>
<p>Now, what's convention for naming a parameter (and class property) <code>classs</code>? I saw <code>classs</code> as well as <code>klass</code> and I'm wondering... | 1 | 2016-08-02T10:55:03Z | 38,718,532 | <p>There isn't really a convention. I've seen - and probably used - <code>klass</code>, <code>_class</code>, and <code>cls</code>.</p>
| 1 | 2016-08-02T10:57:00Z | [
"python",
"naming-conventions",
"pep8"
] |
What's convention for naming a class or method as "class" in Python? | 38,718,484 | <p>Let's say I have a class in Python like this:</p>
<pre><code>class Student:
def __init__(self, classs):
self.classs = classs
</code></pre>
<p>Now, what's convention for naming a parameter (and class property) <code>classs</code>? I saw <code>classs</code> as well as <code>klass</code> and I'm wondering... | 1 | 2016-08-02T10:55:03Z | 38,718,583 | <p>PEP 8 advises to use a trailing underscore in that case: <code>class_</code>.</p>
<p>See <a href="https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles" rel="nofollow">https://www.python.org/dev/peps/pep-0008/#descriptive-naming-styles</a> for details:</p>
<blockquote>
<p>single_trailing_underscore... | 4 | 2016-08-02T10:59:56Z | [
"python",
"naming-conventions",
"pep8"
] |
Python twice opens a file if uses subprocess.Popen for run another script | 38,718,558 | <p>I have script test1.py (For example)</p>
<pre><code>import test2
def main():
f = open("File.txt")
test2.run()
while True:
pass
if __name__ == '__main__':
main()
</code></pre>
<p>And test2.py</p>
<pre><code>import subprocess, sys, os
def run():
# Self run
subprocess.Popen(['C:\... | 1 | 2016-08-02T10:58:37Z | 38,718,834 | <p>The child process inherits a file handle for compatibility with the Unix model (see <a href="https://www.python.org/dev/peps/pep-0446/#rationale" rel="nofollow">PEP 446</a> for more explanation). After the subprocess call, both the original and the new script should have access to the file; on Windows that means two... | 1 | 2016-08-02T11:11:12Z | [
"python",
"subprocess",
"popen"
] |
Python twice opens a file if uses subprocess.Popen for run another script | 38,718,558 | <p>I have script test1.py (For example)</p>
<pre><code>import test2
def main():
f = open("File.txt")
test2.run()
while True:
pass
if __name__ == '__main__':
main()
</code></pre>
<p>And test2.py</p>
<pre><code>import subprocess, sys, os
def run():
# Self run
subprocess.Popen(['C:\... | 1 | 2016-08-02T10:58:37Z | 38,718,921 | <p>By the time you call <code>test2</code> your <code>test1</code> program has already opened the file. Therefore, when you create a subprocess that child process inherits any open files - including <code>File.txt</code>.</p>
<p>See the <a href="https://docs.python.org/2/library/subprocess.html#popen-constructor" rel=... | 1 | 2016-08-02T11:15:32Z | [
"python",
"subprocess",
"popen"
] |
Python text parsing and saving as html | 38,718,622 | <p>I've been playing around with Python trying to write a script to scan a directory for specific files, finding certain keywords and saving the lines where these keywords appear into a new file. I came up with this;</p>
<pre><code>import sys, os, glob
for filename in glob.glob("./*.LOG"):
with open(filename) as log... | 0 | 2016-08-02T11:01:34Z | 38,719,058 | <p>It's a matter of indenting the lines to the right level. The HTML footer must be printed at the indentation level of the header lines, not indented within the loop. Try this:</p>
<pre><code>import sys, os, glob
import cgi
for filename in glob.glob("./*.LOG"):
name = os.path.splitext(filename)[0]
with open... | 1 | 2016-08-02T11:22:05Z | [
"python",
"html",
"loops"
] |
Python - How to loop through lines of multiple files | 38,718,714 | <p>I have 2 files: <code>"a.txt"</code> and <code>"b.txt"</code> where I want to match lines between them. The files contain the following:</p>
<pre><code>1
2
3
4
5
6
7
8
9
10
</code></pre>
<p>To match the lines, I'm doing the following</p>
<pre><code> a = open("a.txt","r")
b = open("b.txt","r")
for al i... | 0 | 2016-08-02T11:05:51Z | 38,718,780 | <p>You can fetch <code>b</code> to a list of lines with <code>readlines()</code>, and then you can iterate over it again and again:</p>
<pre><code>a = open("a.txt","r")
b = open("b.txt","r").readlines()
for al in a:
al = al.split()
val_a = al[0]
for bl in b:
bl = bl.split()
val_b = bl[0]
... | 3 | 2016-08-02T11:08:53Z | [
"python",
"file"
] |
Python - How to loop through lines of multiple files | 38,718,714 | <p>I have 2 files: <code>"a.txt"</code> and <code>"b.txt"</code> where I want to match lines between them. The files contain the following:</p>
<pre><code>1
2
3
4
5
6
7
8
9
10
</code></pre>
<p>To match the lines, I'm doing the following</p>
<pre><code> a = open("a.txt","r")
b = open("b.txt","r")
for al i... | 0 | 2016-08-02T11:05:51Z | 38,718,793 | <p>Convert b as a list else first iteration through b will consume the file.</p>
<pre><code> blist= list(b)
</code></pre>
<p>Then the inner loop</p>
<pre><code>For bl in blist:
...
</code></pre>
| 0 | 2016-08-02T11:09:16Z | [
"python",
"file"
] |
Python - How to loop through lines of multiple files | 38,718,714 | <p>I have 2 files: <code>"a.txt"</code> and <code>"b.txt"</code> where I want to match lines between them. The files contain the following:</p>
<pre><code>1
2
3
4
5
6
7
8
9
10
</code></pre>
<p>To match the lines, I'm doing the following</p>
<pre><code> a = open("a.txt","r")
b = open("b.txt","r")
for al i... | 0 | 2016-08-02T11:05:51Z | 38,718,816 | <p>You need to reset the file pointer to the start of the file for <code>b.txt</code> each time you attempt to loop through it, otherwise you've reached the end.</p>
<p>The easiest way to do this is with <code>file.seek(0)</code> as shown below:</p>
<pre><code>a = open("a.txt","r")
b = open("b.txt","r")
for al in a:... | 4 | 2016-08-02T11:10:33Z | [
"python",
"file"
] |
Python - How to loop through lines of multiple files | 38,718,714 | <p>I have 2 files: <code>"a.txt"</code> and <code>"b.txt"</code> where I want to match lines between them. The files contain the following:</p>
<pre><code>1
2
3
4
5
6
7
8
9
10
</code></pre>
<p>To match the lines, I'm doing the following</p>
<pre><code> a = open("a.txt","r")
b = open("b.txt","r")
for al i... | 0 | 2016-08-02T11:05:51Z | 38,718,893 | <p>try this :</p>
<pre><code>a = open("a.txt","r")
b = open("b.txt","r")
for i,j in zip(a,b):
print (i.split())[0]
print (j.split())[0]
</code></pre>
| 0 | 2016-08-02T11:14:00Z | [
"python",
"file"
] |
pandas time-series data preprocessing | 38,718,774 | <p>I have dataframe look likes this :</p>
<pre><code>> dt
text timestamp
0 a 2016-06-13 18:00
1 b 2016-06-20 14:08
2 c 2016-07-01 07:41
3 d 2016-07-11 19:07
4 e 2016-08-01 16:00
</code></pre>
<p>And I want to summarise every month's data like:</p>
<pre><code>> dt_month
count timest... | 2 | 2016-08-02T11:08:33Z | 38,718,832 | <p>You can groupby by <code>timestamp</code> column converted <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.to_period.html" rel="nofollow"><code>to_period</code></a> and aggregate <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.size.html" rel=... | 0 | 2016-08-02T11:11:08Z | [
"python",
"pandas",
"dataframe",
"time-series",
"visualization"
] |
Python Decorators - <Classname> object has no attribute '__name__' | 38,719,002 | <p>I have a tornado method like below and I tried to decorate method to cache stuff. I have the following setup</p>
<pre><code>def request_cacher(x):
def wrapper(funca):
@functools.wraps(funca)
@asynchronous
@coroutine
def wrapped_f(self, *args, **kwargs):
pass
... | 0 | 2016-08-02T11:19:39Z | 38,720,698 | <p>i think this might work for you,</p>
<pre><code>import tornado.ioloop
import tornado.web
from tornado.gen import coroutine
from functools import wraps
cache = {}
class cached(object):
def __init__ (self, rule, *args, **kwargs):
self.args = args
self.kwargs = kwargs
self.rule = rule
... | 1 | 2016-08-02T12:40:55Z | [
"python",
"tornado",
"decorator",
"python-decorators",
"functools"
] |
Python Decorators - <Classname> object has no attribute '__name__' | 38,719,002 | <p>I have a tornado method like below and I tried to decorate method to cache stuff. I have the following setup</p>
<pre><code>def request_cacher(x):
def wrapper(funca):
@functools.wraps(funca)
@asynchronous
@coroutine
def wrapped_f(self, *args, **kwargs):
pass
... | 0 | 2016-08-02T11:19:39Z | 38,720,779 | <p>Your code throws from <code>functools.wraps(funca)</code>, so <code>funca</code> must be a <code>PhotoListHandler</code> instance instead of a wrapped <code>get</code> method as you intend. I believe this means that the next decorator down the stack, <code>auth_required</code>, is written incorrectly: <code>auth_req... | 0 | 2016-08-02T12:44:59Z | [
"python",
"tornado",
"decorator",
"python-decorators",
"functools"
] |
Python Decorators - <Classname> object has no attribute '__name__' | 38,719,002 | <p>I have a tornado method like below and I tried to decorate method to cache stuff. I have the following setup</p>
<pre><code>def request_cacher(x):
def wrapper(funca):
@functools.wraps(funca)
@asynchronous
@coroutine
def wrapped_f(self, *args, **kwargs):
pass
... | 0 | 2016-08-02T11:19:39Z | 38,721,615 | <p>The issue is that you defined your <code>request_cacher</code> decorator as a decorator with arguments but you forgot to pass the argument!</p>
<p>Consider this code:</p>
<pre><code>import functools
def my_decorator_with_argument(useless_and_wrong):
def wrapper(func):
@functools.wraps(func)
d... | 2 | 2016-08-02T13:20:05Z | [
"python",
"tornado",
"decorator",
"python-decorators",
"functools"
] |
select special elements in a list and compute conditional probabilities | 38,719,138 | <p>I need to compute the probability of a bigram given the existence of its corresponding unigrams in a list. The desired outcome is, for instance, in the following list, <code>'pretty girl', 'pretty', 'girl'</code> all exist. The probability is therefore, by using the values in list <code>P</code>, <code>(0.0017) % (0... | 0 | 2016-08-02T11:25:24Z | 38,720,714 | <p>This works</p>
<pre><code>S = ['girl', 'pretty', 'pretty girl', 'our', 'our world', 'wide', 'world', 'yes', 'yike', 'yummy']
P = [0.003, 0.002, 0.0017, 0.003, 0.006, 0.004, 0.002, 0.012, 0.006, 0.003]
for i in range(len(S)):
s_split = S[i].split()
s_split_len = len(S[i].split())
if s_split_len == 2:
... | 0 | 2016-08-02T12:41:42Z | [
"python",
"string",
"loops",
"probability"
] |
Pyqt two buttons connect to method to set text in label | 38,719,142 | <p>I have two buttons and I would like to connect it to label to see text.</p>
<p>In __init__method i have:</p>
<pre><code>self.pushButton.clicked.connect(self.labeltext)
self.pushButton_2.clicked.connect(self.labeltext)
def labeltext(self):
if self.pushButton.clicked:
self.label.setText('A')
elif se... | 1 | 2016-08-02T11:25:53Z | 38,719,618 | <p>If you use functools.partial, you can replace the connection lines as below. Also you can simplify labeltext function by adding a string parameter which is passed when the button is pushed.</p>
<pre><code>def labeltext(self, text):
self.label.setText(text)
self.pushButton.clicked.connect(partial(self.labeltext... | 1 | 2016-08-02T11:48:23Z | [
"python",
"pyqt5"
] |
Pyqt two buttons connect to method to set text in label | 38,719,142 | <p>I have two buttons and I would like to connect it to label to see text.</p>
<p>In __init__method i have:</p>
<pre><code>self.pushButton.clicked.connect(self.labeltext)
self.pushButton_2.clicked.connect(self.labeltext)
def labeltext(self):
if self.pushButton.clicked:
self.label.setText('A')
elif se... | 1 | 2016-08-02T11:25:53Z | 38,719,844 | <p>You can accomplish this by using <a href="https://docs.python.org/2/library/functools.html#functools.partial" rel="nofollow"><code>partial</code></a>.</p>
<p>Using <code>partial</code>, you will pass the text you want displayed in your <code>.connect()</code>.</p>
<pre><code>qbtn1.clicked.connect(partial(self.labe... | 1 | 2016-08-02T11:59:27Z | [
"python",
"pyqt5"
] |
Pyqt two buttons connect to method to set text in label | 38,719,142 | <p>I have two buttons and I would like to connect it to label to see text.</p>
<p>In __init__method i have:</p>
<pre><code>self.pushButton.clicked.connect(self.labeltext)
self.pushButton_2.clicked.connect(self.labeltext)
def labeltext(self):
if self.pushButton.clicked:
self.label.setText('A')
elif se... | 1 | 2016-08-02T11:25:53Z | 38,725,276 | <p>You can use the <a href="http://doc.qt.io/qt-5/qobject.html#sender" rel="nofollow">sender()</a> method for this:</p>
<pre><code>def labeltext(self):
sender = self.sender()
if sender is self.pushButton:
self.label.setText('A')
elif sender is self.pushButton_2:
self.label.setText('B')
</co... | 1 | 2016-08-02T15:55:54Z | [
"python",
"pyqt5"
] |
Pandas: how to edit values in a column of a .csv file? | 38,719,184 | <p>I have a .csv file which looks as follows:<a href="http://i.stack.imgur.com/buFdW.png" rel="nofollow">link</a></p>
<p>I want to open this file using pandas and edit the column <strong>Coordinate</strong> by adding a constant value of 756 to each value in it. Finally, I want the changes to be reflected in the .csv f... | 0 | 2016-08-02T11:27:51Z | 38,719,493 | <p>Define path where csv file is located </p>
<pre><code>Location = r'C:\\'
df = pd.read_csv(Location,header=None)
df["Coorinate"].values +756
</code></pre>
<p>Do not forget to import pandas package</p>
<pre><code>import pandas as pd
</code></pre>
| 0 | 2016-08-02T11:42:22Z | [
"python",
"pandas"
] |
Pandas: how to edit values in a column of a .csv file? | 38,719,184 | <p>I have a .csv file which looks as follows:<a href="http://i.stack.imgur.com/buFdW.png" rel="nofollow">link</a></p>
<p>I want to open this file using pandas and edit the column <strong>Coordinate</strong> by adding a constant value of 756 to each value in it. Finally, I want the changes to be reflected in the .csv f... | 0 | 2016-08-02T11:27:51Z | 38,719,555 | <p>you can also type:</p>
<pre><code>df["Coordinate"] = df["Coordinate"] + 756
</code></pre>
| 0 | 2016-08-02T11:45:21Z | [
"python",
"pandas"
] |
Pandas: how to edit values in a column of a .csv file? | 38,719,184 | <p>I have a .csv file which looks as follows:<a href="http://i.stack.imgur.com/buFdW.png" rel="nofollow">link</a></p>
<p>I want to open this file using pandas and edit the column <strong>Coordinate</strong> by adding a constant value of 756 to each value in it. Finally, I want the changes to be reflected in the .csv f... | 0 | 2016-08-02T11:27:51Z | 38,719,709 | <p>@EdChum: Thanks for your comment. It kind of fired me up. I was unnecessarily complicating things for myself. Following is what I did:</p>
<pre><code>df = pd.read_csv('C:/TestBook1.csv')
df = df[['Coordinate','Speed']]
df['Coordinate']+=756
df.to_csv('C:/TestBook1.csv')
</code></pre>
<p>Initially I was loading al... | 0 | 2016-08-02T11:52:33Z | [
"python",
"pandas"
] |
AttributeError: 'Window' object has no attribute 'q' | 38,719,276 | <p>I'm trying to append a simple string to a list in and object. But I'm guessing the self keyword is interfereing with the pyqt window? </p>
<p>How can I work around this?</p>
<pre><code>class Window(qt.QMainWindow):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
self.Creat... | 0 | 2016-08-02T11:32:22Z | 38,722,931 | <p>You are trying to fetch the member <strong>q</strong> before it is initialized. Call Qfetch.DataFetch() before self.CreateWidgets().</p>
<p>This code for the constructor should work:</p>
<pre><code>class Window(qt.QMainWindow):
def __init__(self, parent=None):
super(Window, self).__init__(parent)
... | 4 | 2016-08-02T14:15:10Z | [
"python",
"pyqt"
] |
Not able to take screenshot of alert box in selenium using python | 38,719,337 | <p>I am new to selenium i want to take the screenshot of alert box whenever the alert is popped.
The code i have written is as below:</p>
<pre><code>import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoAlertPresentException
import time
... | 1 | 2016-08-02T11:35:29Z | 38,719,648 | <p>You can not take <code>screenshot</code> with the <code>alert</code> box, you need to handle <code>alert</code> first means <code>accept</code> or <code>dismiss</code> then go to take screenshot because when selenium goes to take screenshot with alert present, it always throws the <code>UnexpectedAlertPresentExcepti... | 0 | 2016-08-02T11:49:33Z | [
"python",
"selenium"
] |
ImportError: No module named 'pkg_resources.extern.six.moves'; 'pkg_resources.extern.six' is not a package | 38,719,356 | <p>I can not import pkg_resources. Whenever I tried it shows</p>
<pre><code>Python 3.5.2 (default, Jun 28 2016, 08:46:01)
[GCC 6.1.1 20160602] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
Traceback (most recent call last):
File "<stdin>", ... | 1 | 2016-08-02T11:36:21Z | 38,779,433 | <p>Well, there is no <code>six</code> package there. <code>six</code> is just a name defined in</p>
<pre><code>/usr/lib/python3.5/site-packages/pkg_resources/extern/__init__.py
</code></pre>
<p>To be exact, it looks as follows:</p>
<pre><code>names = 'packaging', 'pyparsing', 'six'
VendorImporter(__name__, names).i... | 1 | 2016-08-05T00:34:15Z | [
"python",
"python-3.x",
"setuptools",
"archlinux"
] |
Scrapy yields only the last element | 38,719,489 | <p>I am scraping some courses/lessons with the help of <code>scrapy</code>, however it seems to yield only ever the <strong>last</strong> element of a list.<br>
Here's the code in question:</p>
<pre><code>def parse_course_list(self, response):
""" Scrape list of lessons for each course """
lessons = response.c... | 1 | 2016-08-02T11:42:14Z | 38,720,951 | <p>Ah... The classic pointer problem!</p>
<p>I'm not sure on why this happens besides that the requests you're yielding carry items with the same address on the stack.</p>
<p>Here is how you can solve it:</p>
<pre><code>def parse_course_list(self, response):
lessons = response.css('ul.lessons-list a')
itemTo... | 2 | 2016-08-02T12:51:21Z | [
"python",
"scrapy",
"scrapy-spider"
] |
wxFormBuilder and frame subclasses | 38,719,521 | <p>I have been trying to work with wxFrameBuilder to create subclasses of frames so I can call a subclass that inherits a lot of the main frame but overwrites part of the frame by replacing a panel.
Here is the wxFormBuilder generated test code.</p>
<pre><code> class MainMenu ( wx.Frame ):
def __init__( self, ... | 1 | 2016-08-02T11:43:54Z | 38,726,921 | <p><code>MainMenu.__init__</code> is defined like this:</p>
<pre><code>def __init__( self, parent ):
</code></pre>
<p>But you are calling it like this: </p>
<pre><code>MainMenu.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString,
pos = wx.DefaultPosition, size = wx.Size( 500,300 ),
... | 1 | 2016-08-02T17:26:47Z | [
"python",
"python-2.7",
"wxpython",
"wx",
"wxformbuilder"
] |
Use x if z equals true else use z | 38,719,534 | <p>I need forLoop1 to use <code>y</code> if <code>z</code> equals 1 else use <code>x</code> and same for forLoop2 but reversed</p>
<p>my code:</p>
<pre><code>for z in range(3):
count=[0]*plys
for y in range(len(game)): #forLoop1
for x in range(len(game[y])): #forLoop2
for i in range(plys):... | 0 | 2016-08-02T11:44:33Z | 38,719,799 | <p>The <code>... if ... else ...</code> conditional expression produces an <em>expression</em>, you can't use it to man-handle the <code>for</code> loop index variable names like that.</p>
<p>But you <em>can</em> do this:</p>
<pre><code>for z in range(3):
count=[0]*plys
for k1 in range(len(game)): #forLoop1
... | 1 | 2016-08-02T11:57:07Z | [
"python",
"python-3.x"
] |
How to set current user to be an attribute of the ModelForm? | 38,719,567 | <p>I have a form which creates a <code>Reservation</code> object. This object has a <code>customer = models.ForeignKey(User)</code> - which is a required attribute. </p>
<p>What to do to be able to create object using <code>ReservationCreationForm().save()</code>?</p>
<p>I've tried to overwrite save method:</p>
<pre... | 0 | 2016-08-02T11:45:44Z | 38,719,722 | <p>Your are not calling the <code>.save</code> method correctly. <code>super</code> accepts a second argument which is the object instance.</p>
<pre><code>super(ReservationCreationForm, self).save(*args, **kwargs)
</code></pre>
<p>UPDATE</p>
<p>You are not setting <code>customer</code> to a <code>reservation instanc... | 1 | 2016-08-02T11:52:58Z | [
"python",
"django",
"django-forms"
] |
Get an error when installing virtualenv for flask | 38,719,628 | <p>I am learning to use flask for python web framework, however, when I try to <code>sudo easy_install virtualenv</code>, I get an error:</p>
<pre><code>[Errno 97] Address family not supported by protocol
</code></pre>
<p>how to solve this? My linux is CentOS release 4.3 (Final) and python version is 2.7.3</p>
| 0 | 2016-08-02T11:48:44Z | 38,720,003 | <p>You can install it from source package...</p>
<pre><code>$ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-X.X.tar.gz
$ tar xvfz virtualenv-X.X.tar.gz
$ cd virtualenv-X.X
$ [sudo] python setup.py install
</code></pre>
| 1 | 2016-08-02T12:07:10Z | [
"python"
] |
Can't get BeautifulSoup to recognize columns correctly (Python, xml (Excel web) html file) | 38,719,764 | <p>I'm working with a number of files of this format (eliminated styling html):</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><html xmlns:x="urn:schemas-microsoft-c... | 0 | 2016-08-02T11:55:09Z | 38,721,383 | <p>If I understood well this is what you wanted to extract:</p>
<p><a href="http://i.stack.imgur.com/qv7La.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/qv7La.jpg" alt="enter image description here"></a></p>
<p>You should be able to get it with the following code:</p>
<pre><code>def read_xls(file):
f = ... | -1 | 2016-08-02T13:10:34Z | [
"python",
"parsing",
"xml-parsing",
"beautifulsoup",
"html-parsing"
] |
Not able to install scapy module in python | 38,720,118 | <p>I am using python version 2.7 and Pycharm IDE , I installed scapy module via pycharm UI (file --- default setting -- added scapy)</p>
<pre><code>from scapy.all import DNS
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/apple/Library/Python/2.7/lib/python/site-pa... | -1 | 2016-08-02T12:13:06Z | 38,722,379 | <p>You have to install <code>libdnet</code></p>
<pre><code>$ wget http://libdnet.googlecode.com/files/libdnet-1.12.tgz
$ tar xfz libdnet-1.12.tgz
$ ./configure
$ make
$ sudo make install
$ cd python
$ python2.5 setup.py install
</code></pre>
<p>For 64 bit....</p>
<pre><code>$ CFLAGS='-arch i386 -arch x86_64' ./confi... | 0 | 2016-08-02T13:51:05Z | [
"python",
"django",
"python-2.7",
"python-3.x",
"module"
] |
one if statement with unknown number of conditions python | 38,720,150 | <p>I have a list of list that contains all the conditions that the if statement has to satisfy, but the problem is that the number of conditions stored into the list of list is unknown. For e.g., the list of list is like this:</p>
<pre><code>my_list: [["A", "0"], ["B", "1"], ["C", "2"]]
</code></pre>
<p>so the if sho... | 2 | 2016-08-02T12:14:27Z | 38,720,186 | <p>You can use a <a href="https://www.python.org/dev/peps/pep-0289/"><em>generator expression</em></a> within <a href="https://docs.python.org/3.5/library/functions.html#all"><code>all()</code></a>:</p>
<pre><code>if all(i == j for i, j in my_list): # use int(j) if 'j' is string and 'i' is integer.
# do something
... | 5 | 2016-08-02T12:16:20Z | [
"python",
"if-statement"
] |
one if statement with unknown number of conditions python | 38,720,150 | <p>I have a list of list that contains all the conditions that the if statement has to satisfy, but the problem is that the number of conditions stored into the list of list is unknown. For e.g., the list of list is like this:</p>
<pre><code>my_list: [["A", "0"], ["B", "1"], ["C", "2"]]
</code></pre>
<p>so the if sho... | 2 | 2016-08-02T12:14:27Z | 38,720,291 | <p>I think @Kasramwd provides the most pythonic solution, but an alternative makes use of Python's <a href="http://python-notes.curiousefficiency.org/en/latest/python_concepts/break_else.html" rel="nofollow"><code>else</code> clause on a <code>for</code> loop</a>.</p>
<pre><code>for item in my_list:
if item[0] != ... | 1 | 2016-08-02T12:21:26Z | [
"python",
"if-statement"
] |
Pandas - Datetime Manipulations Not Using Apply or Map | 38,720,173 | <p>You can convert pandas' datetime objects pretty easily using apply() on a column, but the issue I'm running into is that it is really slow. </p>
<p>I'm trying to develop another solution, but I keep running into a performance wall.</p>
<p>My current solution is:</p>
<pre><code>def modify_date2(x):
"""
ap... | 0 | 2016-08-02T12:15:43Z | 38,720,324 | <p>IIUC you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.strftime.html" rel="nofollow"><code>dt.strftime</code></a>, dtype of <code>columnname</code> is <code>datetime</code>:</p>
<pre><code>print (df)
text columnname
0 a 2016-06-13 18:00:00
1 b ... | 1 | 2016-08-02T12:22:44Z | [
"python",
"datetime",
"pandas"
] |
Python: String clustering with scikit-learn's dbscan, using Levenshtein distance as metric: | 38,720,283 | <p>I have been trying to cluster multiple datasets of URLs (around 1 million each), to find the original and the typos of each URL. I decided to use the levenshtein distance as a similarity metric, along with dbscan as the clustering algorithm as k-means algorithms won't work because I do not know the number of cluster... | 2 | 2016-08-02T12:20:55Z | 38,729,114 | <p>Try ELKI instead of sklearn.</p>
<p>It is the only tool I know that allows index accelerated DBSCAN with <em>any</em> metric.</p>
<p>It includes Levenshtein distance. You need to add an index to your database with <code>-db.index</code>. I always use the cover tree index (you need to choose the same distance for t... | 1 | 2016-08-02T19:38:51Z | [
"python",
"machine-learning",
"scikit-learn",
"cluster-analysis",
"levenshtein-distance"
] |
"ValueError: need more than 0 values to unpack" | 38,720,472 | <p>I have looked at the questions on here and none of them seem to help my cause. Essentially what I am doing is calling <code>getAllOpenChoices</code> to try and return a the value of the Radio button so when one is selected it saves.</p>
<p><strong>forms.py</strong></p>
<pre><code>def getAllOpenChoices():
listO... | 1 | 2016-08-02T12:29:39Z | 38,720,696 | <p>The choices should be a list of 2-tuples, like your initial value <code>listOpenChoice</code></p>
<pre><code>listOpenChoice = [('All', 'All'), ('No One', 'No One'), ('Test','Test')]`
</code></pre>
<p>If you extend that list, you should only add 2-tuples. For example:</p>
<pre><code>listOpenChoice.append(('new', '... | 1 | 2016-08-02T12:40:54Z | [
"python",
"django"
] |
Opening and reading several files in different directories | 38,720,527 | <p>I have a huge list of directories. With <code>/home</code> as my current directory, the highest level is the year. There are seven years: 2010, 2011, 2012, 2013, 2014, 2015 and 2016.</p>
<p>Then there are subdirectories for each month, so for instance <code>/home/2010/01</code>. There are, of course, twelve months,... | 0 | 2016-08-02T12:32:26Z | 38,720,681 | <p>You are opening the simple file name, but in nested folders it will not be found. Join it with the root:</p>
<pre><code>import os
for root, dirs, files in os.walk("/home"):
for name in files:
f = open(os.path.join(root, name), 'r')
f.close
</code></pre>
| 1 | 2016-08-02T12:40:09Z | [
"python",
"directory",
"os.walk"
] |
Django directing users after login | 38,720,569 | <p>I've got problems login people with my django app, and I don't think I quite understand how login currently works. Here's my user class, that extends Django's user with some extra fields. The extra fields indicate the type of the user, which I'll just call A, B and C.</p>
<pre><code>class MyUser(models.Model):
... | 0 | 2016-08-02T12:34:14Z | 38,721,290 | <p>The <code>get</code> <code>QuerySet</code> method raises an <code>DoesNotExist</code> exception if there is no matching entry. The line <code>myuser = MyUser.objects.get(user=user)</code> needs changing.</p>
<h3>try/except</h3>
<pre><code>try:
myuser = MyUser.objects.get(user=user)
except MyUser.DoesNotExist:
... | 0 | 2016-08-02T13:06:27Z | [
"python",
"django"
] |
Python's OS module to write to file giving "TypeError" | 38,720,688 | <p>Here is my script:</p>
<pre><code>import random
import os
i = 0
file = os.open("numbers.txt", "w")
while i < 5000:
ranNumb = str(random.randint(1,500))
file.write(ranNumb,",")
</code></pre>
<p>The end goal is simply a text file with 5000 randomly generated numbers in it that I would like to use in subs... | 0 | 2016-08-02T12:40:29Z | 38,720,741 | <p>If you want to use <a href="https://docs.python.org/2/library/os.html#os.open" rel="nofollow">os.open</a> you have to use <a href="https://docs.python.org/2/library/os.html#open-constants" rel="nofollow">os flags</a> to identify mode in which you are going to open file:</p>
<pre><code>file = os.open("numbers.txt", ... | 2 | 2016-08-02T12:43:12Z | [
"python",
"typeerror"
] |
Python's OS module to write to file giving "TypeError" | 38,720,688 | <p>Here is my script:</p>
<pre><code>import random
import os
i = 0
file = os.open("numbers.txt", "w")
while i < 5000:
ranNumb = str(random.randint(1,500))
file.write(ranNumb,",")
</code></pre>
<p>The end goal is simply a text file with 5000 randomly generated numbers in it that I would like to use in subs... | 0 | 2016-08-02T12:40:29Z | 38,720,749 | <p>From the <a href="https://docs.python.org/3/library/os.html" rel="nofollow">documentation</a> you linked:</p>
<blockquote>
<p>If you just want to read or write a file see <a href="https://docs.python.org/3/library/functions.html#open" rel="nofollow">open()</a>.</p>
</blockquote>
<p>As I said in the comment, chan... | 0 | 2016-08-02T12:43:37Z | [
"python",
"typeerror"
] |
Python's OS module to write to file giving "TypeError" | 38,720,688 | <p>Here is my script:</p>
<pre><code>import random
import os
i = 0
file = os.open("numbers.txt", "w")
while i < 5000:
ranNumb = str(random.randint(1,500))
file.write(ranNumb,",")
</code></pre>
<p>The end goal is simply a text file with 5000 randomly generated numbers in it that I would like to use in subs... | 0 | 2016-08-02T12:40:29Z | 38,720,766 | <p>Citing after Python docs available <a href="https://docs.python.org/2/library/os.html#os.open" rel="nofollow">here</a></p>
<blockquote>
<p>This function is intended for low-level I/O. For normal usage, use the built-in function open(), which returns a âfile objectâ with read() and write() methods (and many mo... | 0 | 2016-08-02T12:44:28Z | [
"python",
"typeerror"
] |
Setting boolean values in pandas dataframe (by date) based on column header membership in other dataframe (by date) | 38,720,745 | <p>I have two pandas dataframes (X and Y) and am trying to populate a third (Z) with boolean values based on interrelationships between the axes of X and the columns/constituents of Y. I could only manage to do this via nested loops and the code works on my toy example but is too slow for my actual data set.</p>
<pre... | 1 | 2016-08-02T12:43:27Z | 38,721,441 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.stack.html" rel="nofollow"><code>stack</code></a> method, where values of DataFrame are converted to columns and columns to values of DataFrames. Last test <code>NaN</code> by <a href="http://pandas.pydata.org/pandas-docs/sta... | 1 | 2016-08-02T13:13:29Z | [
"python",
"pandas",
"boolean",
"intersection"
] |
change a range of colors to white in python | 38,720,810 | <p>I use following code to change specific colors (grays) to white in photos. But the code is too slow. any suggestion or alternative is welcomed.</p>
<pre><code>import os
import numpy as np
from PIL import Image
for j in range(1,160):
im = Image.open(str(j)+'.jpg')
data = np.array(im)
for i in (range(205,... | 0 | 2016-08-02T12:45:55Z | 38,721,027 | <p>This way of image processing is slow because it is single threaded, and straightforward. Try splitting it into multiple equal parts, and running them at the same time for a major speedup (try to split the job with function and check the results: more of smaller chunks vs lesser number of larger ones).
For greater im... | 0 | 2016-08-02T12:54:45Z | [
"python",
"image-processing"
] |
change a range of colors to white in python | 38,720,810 | <p>I use following code to change specific colors (grays) to white in photos. But the code is too slow. any suggestion or alternative is welcomed.</p>
<pre><code>import os
import numpy as np
from PIL import Image
for j in range(1,160):
im = Image.open(str(j)+'.jpg')
data = np.array(im)
for i in (range(205,... | 0 | 2016-08-02T12:45:55Z | 38,721,161 | <p>You are searching for all the values in the image were all thae values of all channels are the same. Therefore first create a mask for all the pixels that are equal for all three channels and than from them only leave the ones that are in your range.
Try the following code:</p>
<pre><code>import os
import numpy as ... | 0 | 2016-08-02T13:00:14Z | [
"python",
"image-processing"
] |
change a range of colors to white in python | 38,720,810 | <p>I use following code to change specific colors (grays) to white in photos. But the code is too slow. any suggestion or alternative is welcomed.</p>
<pre><code>import os
import numpy as np
from PIL import Image
for j in range(1,160):
im = Image.open(str(j)+'.jpg')
data = np.array(im)
for i in (range(205,... | 0 | 2016-08-02T12:45:55Z | 38,743,233 | <p>I think you are missing an indent at the end, you're saving each output image 50 times. I changed your code to be:</p>
<pre><code>import os
import numpy as np
from PIL import Image
for j in range(1, 10):
filename = str(j) + '.jpg'
print 'processing', filename, '...'
im = Image.open(filename)
data ... | 0 | 2016-08-03T12:07:50Z | [
"python",
"image-processing"
] |
Python pandas plot scatter datetime error | 38,720,851 | <p>I want a scatter plot where x-axis is a <code>datetime</code>, y-axis is an <code>int</code>. And I have only a few of datapoints that are discrete and not continuous, so I don't want to connect datapoints.</p>
<p>My DataFrame is:</p>
<pre><code>df = pd.DataFrame({'datetime':[dt.datetime(2016,1,1,0,0,0), dt.dateti... | 0 | 2016-08-02T12:47:36Z | 38,723,651 | <p><em>Scatter plot can be drawn by using the DataFrame.plot.scatter() method. Scatter plot requires <strong>numeric</strong> columns for x and y axis. These
can be specified by x and y keywords each.</em></p>
<p>Alternative Approach:</p>
<pre><code>In [71]: df['day'] = df['datetime'].dt.day
In [72]: df.plot.scatte... | 1 | 2016-08-02T14:45:21Z | [
"python",
"pandas",
"plot",
"scatter-plot"
] |
How to unpack deep nested iterable structure | 38,720,918 | <p>Say for example I have a structure that contains many sub-elements some of which are structures:</p>
<pre><code>v = [1, 2, 3, [4, (5, 6)]]
</code></pre>
<p>How can I unpack these into a series of names that contain only the contents of the structures and not a structure?</p>
<p>Trying <code>a, b, c, d, e, f = v</... | 4 | 2016-08-02T12:50:13Z | 38,720,943 | <p>Assignments are defined recursively, you need to <em><a href="https://docs.python.org/3/reference/simple_stmts.html#assignment-statements" rel="nofollow">use parentheses <code>()</code> and/or square brackets <code>[]</code> to enclose target names</a></em> and match the nested structure of your iterable. In your ca... | 10 | 2016-08-02T12:51:02Z | [
"python",
"python-3.x",
"iterable",
"iterable-unpacking"
] |
How to unpack deep nested iterable structure | 38,720,918 | <p>Say for example I have a structure that contains many sub-elements some of which are structures:</p>
<pre><code>v = [1, 2, 3, [4, (5, 6)]]
</code></pre>
<p>How can I unpack these into a series of names that contain only the contents of the structures and not a structure?</p>
<p>Trying <code>a, b, c, d, e, f = v</... | 4 | 2016-08-02T12:50:13Z | 38,722,308 | <p>Another option you might consider is to flatten the structure and then assign it.</p>
<pre><code>def flatten(container):
for i in container:
if isinstance(i, (list,tuple)):
for j in flatten(i):
yield j
else:
yield i
</code></pre>
<p>Then </p>
<pre><code>... | 3 | 2016-08-02T13:47:55Z | [
"python",
"python-3.x",
"iterable",
"iterable-unpacking"
] |
Python: Is it better to pass in a mutable object as a parameter or have the method create one locally and return it? | 38,721,013 | <p>I have a relatively straightforward question but couldn't really find the answer online. I know in C++, if you are trying to create a large object (say a huge vector of strings) you would avoid doing:</p>
<pre><code>int main() {
vector<string> v = foo()
}
vector<string> foo() {
vector<string... | 0 | 2016-08-02T12:54:09Z | 38,721,225 | <p>Python's data model is very different from C++'s.</p>
<p>In Python, new objects are created on the heap and bound to variables that exist in namespaces (function calls, classes, instances and varaious other parts of the language implement namespaces).</p>
<p>In C++, without proper care you can create an object in ... | 1 | 2016-08-02T13:03:14Z | [
"python",
"performance"
] |
Fetch certain parts of sympy solution | 38,721,014 | <p>I have a huge symbolic sympy expression on the form</p>
<pre><code>expression = factor * (f1*a + f2*b + f3*c + f4*d + f5*e)
</code></pre>
<p>where all of the factors a through e all consists of several terms. I.e: </p>
<pre><code>a = exp(2x) + exp(3x) + sin(Ix).
</code></pre>
<p>I want to create en array on the... | 1 | 2016-08-02T12:54:11Z | 38,721,394 | <p>Here's a simple example you can extrapolate for more terms</p>
<pre><code>import sympy as sp
x = sp.var('x')
f1, f2 = sp.symbols('f1:3')
factor = sp.symbols('factor')
a = x**2 + sp.sin(x) + sp.exp(sp.I * x)
b = sp.log(x)/(x+1)**2
# example expression:
expression = (factor * (f1 * a + f2 * b)).expand()
print(expr... | 1 | 2016-08-02T13:10:59Z | [
"python",
"arrays",
"math",
"sympy",
"factors"
] |
AWS S3 Data Protection Using Client-Side Encryption | 38,721,026 | <p>I need to use AWS S3 feature - <a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingClientSideEncryption.html" rel="nofollow">Protecting Data Using Client-Side Encryption</a></p>
<p>According to AWS documentation the following AWS SDKs support client-side encryption:</p>
<pre><code>AWS SDK for Java
AWS SDK... | 1 | 2016-08-02T12:54:37Z | 38,721,409 | <p>Client-side encryption means that you are encrypting the file prior to uploading it to S3. You can accomplish that using any programming language along with any encryption tool. For that matter, you could just use a tool like gpg and the AWS CLI to encrypt and upload files to S3. You manage the encryption keys on yo... | 2 | 2016-08-02T13:11:45Z | [
"python",
"amazon-web-services",
"amazon-s3"
] |
Why does this Python code give Runtime Error(NZEC)? | 38,721,038 | <p>I already read the other questions and answers but couldn't implement any of the solutions to my code. I'm still clueless about the reason why this code gives a runtime error.</p>
<p>I'm trying to submit the code on CodeChef, yet it gives the Runtime Error(NZEC), although the code runs flawlessly on my console for ... | 0 | 2016-08-02T12:55:00Z | 38,721,250 | <p>The problem description says that the input is constrained to be < 10^4. That's 10,000! Your code will need to make 10,000/4 = 2500 recursive calls to GetSquares, that's a lot! In fact, it's so much that it's going to give you, fittingly, this error:</p>
<pre><code>RuntimeError: maximum recursion depth exceeded
... | 3 | 2016-08-02T13:04:39Z | [
"python",
"python-3.x"
] |
Why does this Python code give Runtime Error(NZEC)? | 38,721,038 | <p>I already read the other questions and answers but couldn't implement any of the solutions to my code. I'm still clueless about the reason why this code gives a runtime error.</p>
<p>I'm trying to submit the code on CodeChef, yet it gives the Runtime Error(NZEC), although the code runs flawlessly on my console for ... | 0 | 2016-08-02T12:55:00Z | 38,721,773 | <p>The question puts a constraint on the value of '<strong>B</strong>' which is 10000 at max, which means there are a lot of recursive calls and giving a runtime error. Try solving using iteration.</p>
| 0 | 2016-08-02T13:26:09Z | [
"python",
"python-3.x"
] |
Python pandas plot more columns but shows only one legend | 38,721,080 | <p>I want to plot two columns on the same x-axis & y-axis. But <code>pandas-plot</code> only displays the second column's legend (so no dots for the first column). Of course both labels (name of columns) are displayed in the legend box.</p>
<p>My DataFrame is:</p>
<pre><code>df = pd.DataFrame({'datetime':[dt.date... | 0 | 2016-08-02T12:56:36Z | 38,771,349 | <p>You should try recalling the legend after you call the second plot:</p>
<pre><code>ax.legend()
</code></pre>
<p>this is what I get:</p>
<p><a href="http://i.stack.imgur.com/HmFdo.png" rel="nofollow"><img src="http://i.stack.imgur.com/HmFdo.png" alt="enter image description here"></a></p>
| 1 | 2016-08-04T15:19:53Z | [
"python",
"pandas",
"plot",
"legend"
] |
first and last bars on matplotlib histogram appear moved | 38,721,086 | <p>I'm trying to create a histogram using these values:</p>
<pre><code>[1, 1, 1, 2, 2, 1, 1, 1, 1, 5, 2, 1, 1, 2, 2, 1, 1, 4, 1, 1, 2, 1, 1, 2]
</code></pre>
<p>The code I'm using is this</p>
<pre><code>plt.hist(values, histtype='bar', color='green', alpha=0.5)
plt.title(library_name, fontsize=12)
plt.xlabel(xlabel)... | 1 | 2016-08-02T12:56:53Z | 38,721,373 | <p>To get centre-aligned bins instead of left-aligned, use <code>plt.hist(data, bins=np.arange(50)-0.5)</code></p>
<p>Example code:</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
values = [1, 1, 1, 2, 2, 1, 1, 1, 1, 5, 2, 1, 1, 2, 2,5,3,2,5, 1, 1, 4, 1, 1, 2, 1, 1,7,8,9,9,3,8,6, 2]
offset = 0.5
... | 1 | 2016-08-02T13:10:15Z | [
"python",
"matplotlib",
"histogram"
] |
first and last bars on matplotlib histogram appear moved | 38,721,086 | <p>I'm trying to create a histogram using these values:</p>
<pre><code>[1, 1, 1, 2, 2, 1, 1, 1, 1, 5, 2, 1, 1, 2, 2, 1, 1, 4, 1, 1, 2, 1, 1, 2]
</code></pre>
<p>The code I'm using is this</p>
<pre><code>plt.hist(values, histtype='bar', color='green', alpha=0.5)
plt.title(library_name, fontsize=12)
plt.xlabel(xlabel)... | 1 | 2016-08-02T12:56:53Z | 38,739,635 | <p>As an aside, you can use [<strong>DISCLAIMER: I wrote it</strong>] the "physt" library which has a couple of binning options including one suitable for integers - see <a href="https://github.com/janpipek/physt" rel="nofollow">https://github.com/janpipek/physt</a>, and particularly for your case <a href="http://nbvie... | 0 | 2016-08-03T09:28:18Z | [
"python",
"matplotlib",
"histogram"
] |
Split timestamp column into two seperate date and time columns with python | 38,721,087 | <p>I have a dataset called "df_no_missing". </p>
<pre><code>df_no_missing.head()
</code></pre>
<blockquote>
<pre><code>TIMESTAMP object
P_ACT_KW float64
PERIODE_TARIF object
P_SOUSCR float64
SITE object
TARIF object
depassement float64
dtype: object
</code></p... | -3 | 2016-08-02T12:56:53Z | 38,721,175 | <p>IIUC you want:</p>
<pre><code>df_no_missing['TIMESTAMP'] = pd.to_datetime(df_no_missin['TIMESTAMP'], '%d/%m/%y %H:%M')
</code></pre>
<p>then you can do <code>.dt.time</code> and <code>dt.date</code> after the conversion</p>
<p>Also you need to post what the datetime strings look like</p>
<p><strong>EDIT</strong>... | 0 | 2016-08-02T13:00:50Z | [
"python",
"pandas",
"time",
"timestamp"
] |
Split timestamp column into two seperate date and time columns with python | 38,721,087 | <p>I have a dataset called "df_no_missing". </p>
<pre><code>df_no_missing.head()
</code></pre>
<blockquote>
<pre><code>TIMESTAMP object
P_ACT_KW float64
PERIODE_TARIF object
P_SOUSCR float64
SITE object
TARIF object
depassement float64
dtype: object
</code></p... | -3 | 2016-08-02T12:56:53Z | 38,722,360 | <p>If you define</p>
<pre><code>dt = datetime.strptime(TIMESTAMP, '%d/%m/%y %H:%M')
</code></pre>
<p>Then the value of <code>TIMESTAMP</code> has to be like</p>
<pre><code>TIMESTAMP = '03/08/16 16:49'
</code></pre>
<p>If the format is defined as</p>
<pre><code>dt = datetime.strptime(TIMESTAMP, '%d/%m/%Y %H:%M')
</... | 0 | 2016-08-02T13:50:13Z | [
"python",
"pandas",
"time",
"timestamp"
] |
sqlalchemy select by filter | 38,721,092 | <p>app.py:</p>
<pre><code>from flask import Flask, render_template
from itertools import groupby
from flask import request
import MySQLdb
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine
from sqlalchemy.orm i... | 0 | 2016-08-02T12:57:14Z | 38,722,434 | <p>You are making two queries and that's probably why you aren't getting the desired result.</p>
<p><code>pUser.query</code> creates a <a href="http://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query" rel="nofollow"><code>Query</code></a> object. On that you're able to call stuff like <code>sele... | 0 | 2016-08-02T13:53:24Z | [
"python",
"sqlalchemy"
] |
Execute function with variable from imported file | 38,721,132 | <p>I'm trying to execute function with value from other file as variable.</p>
<p>one file (let's assume text.py) containing:</p>
<pre><code>VAR="abc"
</code></pre>
<p>In main file:</p>
<pre><code>variable1 -> that variable contain value "VAR"
import text
</code></pre>
<p>Execute function:</p>
<pre><code>exampl... | 0 | 2016-08-02T12:58:49Z | 38,721,329 | <p>You cannot do <code>text.variable1</code> because <code>variable1</code> resides in your main file.</p>
<p>You can either use the value from the imported file:</p>
<pre><code>import text
example_function(connect=text.VAR)
</code></pre>
<p>Or use the value in <code>variable1</code>:</p>
<pre><code>example_functio... | 1 | 2016-08-02T13:08:20Z | [
"python",
"import"
] |
Does Spark Dataframe have an equivalent option of Panda's merge indicator? | 38,721,194 | <p>The python Pandas library contains the following function :</p>
<pre><code>DataFrame.merge(right, how='inner', on=None, left_on=None, right_on=None, left_index=False,
right_index=False, sort=False, suffixes=('_x', '_y'), copy=True,
indicator=False)
</code></pre>
<p>The indicator fie... | 1 | 2016-08-02T13:01:45Z | 38,731,256 | <p>Try this:</p>
<pre><code>>>> from pyspark.sql.functions import *
>>> sdf1 = sqlContext.createDataFrame(df1)
>>> sdf2 = sqlContext.createDataFrame(df2)
>>> sdf = sdf1.join(sdf2, sdf1["col1"] == sdf2["col1"], "outer")
>>> sdf.withColumn("_merge", when(sdf1["col1"].isNull()... | 2 | 2016-08-02T22:07:48Z | [
"python",
"pandas",
"pyspark",
"spark-dataframe"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.