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
How to add a dot in python numpy ndarray - data type issue
39,083,473
<p>I have a NumPy <code>ndarray</code> that looks like:</p> <pre><code>[[ 0 0 0 1 0] [ 0 0 0 0 1]] </code></pre> <p>but I would like to process it to the following form:</p> <pre><code>[[ 0. 0. 0. 1. 0.] [ 0. 0. 0. 0. 1.]] </code></pre> <p>How would I achieve this?</p>
0
2016-08-22T15:31:34Z
39,083,556
<p>It looks to me like you have an array of some integer type. You probably want to convert to an array of float:</p> <pre><code>array_float = array_int.astype(float) </code></pre> <p>e.g.:</p> <pre><code>&gt;&gt;&gt; ones_i = np.ones(10, dtype=int) &gt;&gt;&gt; print ones_i [1 1 1 1 1 1 1 1 1 1] &gt;&gt;&gt; ones_...
1
2016-08-22T15:35:52Z
[ "python", "arrays" ]
Force numbers in list to two decimal places
39,083,510
<p>I have a list of numerical data read from a GIS file (.shp):</p> <p><code>dataList = [4.98, 5.09, 5.23, 5.35, 5.4, 5.59, ...]</code></p> <p>I'm looking for a method that forces numbers in this list to display to two decimal places, with output like this:</p> <p><code>dataList = [4.98, 5.09, 5.23, 5.35, 5.40, 5.59...
1
2016-08-22T15:33:52Z
39,083,605
<p>Iterate through your datalist and convert each value to the formatted string:</p> <pre><code>new_datalist = ["{:.2f}".format(value) for value in dataList] </code></pre>
2
2016-08-22T15:38:40Z
[ "python", "list", "formatting", "decimal" ]
Force numbers in list to two decimal places
39,083,510
<p>I have a list of numerical data read from a GIS file (.shp):</p> <p><code>dataList = [4.98, 5.09, 5.23, 5.35, 5.4, 5.59, ...]</code></p> <p>I'm looking for a method that forces numbers in this list to display to two decimal places, with output like this:</p> <p><code>dataList = [4.98, 5.09, 5.23, 5.35, 5.40, 5.59...
1
2016-08-22T15:33:52Z
39,083,707
<p>Most Pythonic way to achieve this is using <code>map()</code> and <code>lambda</code> functions. </p> <pre><code>map(lambda x: "{:.2f}".format(x), dataList) </code></pre>
1
2016-08-22T15:44:19Z
[ "python", "list", "formatting", "decimal" ]
Sorting email in descending order
39,083,524
<p>In reference to my previous question (Solved): <a href="http://stackoverflow.com/questions/38921933/only-show-certain-number-of-emails-in-imaplib?noredirect=1#comment65309180_38921933">Only show certain number of emails in imaplib</a></p> <p>So now I can show certain number of emails in my inbox but the problem I'm...
-1
2016-08-22T15:34:25Z
39,083,617
<p>I would like to thank Max for this solution, now my email is sorted to the most recent</p> <pre><code>ids = data[0] id_list = ids.split() #[0:10] will only output 10 emails for num in id_list[10::-1]: rv, data = M.fetch(num, '(RFC822)') msg = email.message_from_string(data[0][1]) subj = msg['Subject']...
0
2016-08-22T15:39:39Z
[ "python", "sorting", "imaplib" ]
Match all occurences of string using re.findall
39,083,539
<p>I have a string</p> <p><code>a = "123 some_string ABC 456 some_string DEF 789 some_string GHI"</code></p> <pre><code>print re.findall("(\d\d\d).*([A-Z]+)", a) </code></pre> <p><strong>o/p</strong> : <code>[('123', 'I')]</code> </p> <p><strong>Expected o/p</strong> : <code>[('123', 'ABC'), ('456', 'DEF'), ('789',...
1
2016-08-22T15:34:57Z
39,083,732
<p>Converting my comment to an answer:</p> <p>You are using greedy <code>.*</code> that is matching first 3 digit number to very last text starting with upper case alphabet.</p> <p>You should make it non-greedy (lazy):</p> <pre><code>(\d{3}).*?([A-Z]+) </code></pre> <p><a href="https://regex101.com/r/oL1lR1/1" rel=...
2
2016-08-22T15:45:53Z
[ "python", "regex" ]
Match all occurences of string using re.findall
39,083,539
<p>I have a string</p> <p><code>a = "123 some_string ABC 456 some_string DEF 789 some_string GHI"</code></p> <pre><code>print re.findall("(\d\d\d).*([A-Z]+)", a) </code></pre> <p><strong>o/p</strong> : <code>[('123', 'I')]</code> </p> <p><strong>Expected o/p</strong> : <code>[('123', 'ABC'), ('456', 'DEF'), ('789',...
1
2016-08-22T15:34:57Z
39,084,127
<p>While anubhava's expression works, consider using the principle of contrast (108 steps compared to 30 steps - a reduction by more than 70%!):</p> <pre><code>(\d{3})[^A-Z]*([A-Z]+) </code></pre> <p>See the <a href="https://regex101.com/r/oL1lR1/2" rel="nofollow"><strong>hijacked demo on regex101.com</strong></a>.<b...
3
2016-08-22T16:08:12Z
[ "python", "regex" ]
Merge 2 images onto new image: can someone explain this code?
39,083,540
<p>I'm trying to write a code to merge 2 photos side by side onto a new image, and I found this script online--however, I have no idea how it works. Where do I input the image files that I want to merge? Can someone please explain this code to me? Thanks!!</p> <pre><code>from PIL import Image import sys if not len...
0
2016-08-22T15:34:57Z
39,083,704
<p>It is very easy. You open the images with names provided in sys.argv (arguments to the program):</p> <pre><code>images = map(Image.open, sys.argv[1:-1]) </code></pre> <p>You calculate the new width (sum of all width for opened images, which is i.size[0])</p> <pre><code>w = sum(i.size[0] for i in images) </code></...
-1
2016-08-22T15:44:16Z
[ "python", "image" ]
python file read "int too large to convert to c long"
39,083,644
<p>On my (presumably 64-bit Windows, 64-bit 2.7 python) installation, the file read function is using a 4 byte c_long (signed long). I tested the base python file read function and I can't pass in an offset of more than the max signed long integer value (2,147,483,647). Not sure if this is due to a problem with my pyth...
2
2016-08-22T15:41:32Z
39,083,963
<p>This is happening because the function you are calling is layered on top of a C function that requires a 32-bit offset value. Python integers are not limited to this range, but C functions are.</p> <p>Also note that the read would specify a read of up to 2GB if you ever managed that. Are you prepared to handle a 2G...
1
2016-08-22T15:58:37Z
[ "python", "python-2.7", "long-integer" ]
illegal instruction (core dumped) message when displaying generated image using numpy and matplotlib
39,083,742
<p>When running the following code segment, the last two lines of code <code>plt.imshow(X[0,:,:]) plt.show()</code> keep generating the error message of <code>Illegal instruction (core dumped)</code> The X shape is <code>(1, 572, 572)</code>. May I know what can be the reason of this?</p> <pre><code>import os impo...
0
2016-08-22T15:46:17Z
39,083,859
<p>Works fine for me. Try upgrading and/or reinstalling your libraries and/or Python. </p> <p>If it still fails, consider using <code>gdb</code> to get a stack trace (hint: <code>gdb /path/to/your/python</code>). Then submit a <a href="http://matplotlib.org/faq/troubleshooting_faq.html" rel="nofollow">bug report</a...
0
2016-08-22T15:53:21Z
[ "python", "numpy", "image-processing", "matplotlib", "scipy" ]
Python give number of args to an imported function
39,083,767
<p>I'm trying to give an argument to an imported function.<br> I have <code>base.py</code>:</p> <pre><code>import sc1 #import sc1.py from threading import Thread Thread(target=sc1.main,args="John").start() </code></pre> <p>And a function in <code>sc1.py</code>:</p> <pre><code>def main(name): print "Hello ",name...
2
2016-08-22T15:48:01Z
39,083,786
<p>You want to pass a tuple of args:</p> <pre><code>Thread(target=sc1.main,args=("John",)).start() </code></pre> <p>In your case, since <code>str</code> are iterable, the <code>Thread</code> is trying to unpack <code>"J" "o", "h", "n"</code> as the arguments rather than passing the entire thing as an atomic unit.</p>...
4
2016-08-22T15:49:24Z
[ "python", "function", "arguments" ]
Python give number of args to an imported function
39,083,767
<p>I'm trying to give an argument to an imported function.<br> I have <code>base.py</code>:</p> <pre><code>import sc1 #import sc1.py from threading import Thread Thread(target=sc1.main,args="John").start() </code></pre> <p>And a function in <code>sc1.py</code>:</p> <pre><code>def main(name): print "Hello ",name...
2
2016-08-22T15:48:01Z
39,083,854
<p>Call the <code>Thread</code> as:</p> <pre><code>Thread(target=sc1.main,args=["John"]).start() </code></pre> <p><strong>Explaination:</strong></p> <p>It is throwing error in your case because <code>args</code> is expected to be of <code>list</code> or <code>tuple</code> type. And when your are passing <code>"John"...
2
2016-08-22T15:53:10Z
[ "python", "function", "arguments" ]
Newbie inquiry about NameError
39,083,806
<p>Total Newbie question for which I have searched the site. I am running a really simple program in Chapter 2 of Automate the Boring Stuff and I keep getting a NameError. The first line is </p> <p><code>if name == 'Alice':</code></p> <p>And it results in </p> <pre><code>NameError: name 'name' is not defined <...
-4
2016-08-22T15:50:32Z
39,083,921
<p>In the <a href="https://automatetheboringstuff.com/chapter2/" rel="nofollow">book</a> you missed this comment above the code: "<em>(Pretend name was assigned some value earlier.)</em>". So you need to do that. For example (assuming Python 3):</p> <pre><code>name = input("Please enter your name: ") if name == 'Al...
2
2016-08-22T15:56:41Z
[ "python", "nameerror" ]
Django relation error when running make migrations
39,083,865
<p>Hey I am attempting to initialize a new database, but I am running into some issues setting up the migrations. The error I am getting appears to stem from setting up my forms. In a form I am using, I am creating a choice field as so:</p> <pre><code>from django import forms from ..custom_admin import widgets, choice...
0
2016-08-22T15:54:05Z
39,084,645
<p>You cannot execute queries during the initialization of the app registry. Your <code>choices.py</code> file is indirectly imported during this time, resulting in the error. To fix this issue, you can pass a callable to <code>choices</code>:</p> <pre><code>def get_provinces(): province_choices = [] for provi...
2
2016-08-22T16:40:15Z
[ "python", "django", "django-forms", "django-admin", "django-migrations" ]
Python can't load modules from a large zipfile
39,083,913
<p>I've been packing up a script and some resources into a executable zipfile using the technique in (for example) <a href="http://blog.ablepear.com/2012/10/bundling-python-files-into-stand-alone.html" rel="nofollow">this blog post</a></p> <p>The process suddenly stopped working, and I think it has to do with the zip6...
0
2016-08-22T15:56:12Z
39,107,193
<p>Digging into the python source code, in zipimport.c, we can see that indeed it looks for the <code>end-of-central-directory</code> block in the last 22 bytes of the file. It does not retract the search from there if it doesn't find a valid end-of-central-directory (and I guess that makes it not a compliant zip parse...
0
2016-08-23T17:16:13Z
[ "python" ]
Could not find a version that satisfies the requirement easy_install (from versions: )
39,083,949
<blockquote> <p>Python 2.7.12</p> <p>pip 8.1.2</p> <p>ubuntu-16.04</p> </blockquote> <p>I'm trying to install <code>pycurl</code> using:</p> <pre><code>pip install pycurl </code></pre> <p>this is what I get,</p> <blockquote> <p>Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-...
0
2016-08-22T15:57:50Z
39,084,081
<p>The issue here is that you are attempting to upgrade the <code>setuptools</code> that came installed in your system Python, which requires changes to areas of the file system a "normal" user won't have (it requires root privileges).</p> <p>Prefixing the command with <code>sudo</code> might help, but you should ask ...
0
2016-08-22T16:05:19Z
[ "python", "python-2.7", "pip", "easy-install", "pycurl" ]
Could not find a version that satisfies the requirement easy_install (from versions: )
39,083,949
<blockquote> <p>Python 2.7.12</p> <p>pip 8.1.2</p> <p>ubuntu-16.04</p> </blockquote> <p>I'm trying to install <code>pycurl</code> using:</p> <pre><code>pip install pycurl </code></pre> <p>this is what I get,</p> <blockquote> <p>Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-...
0
2016-08-22T15:57:50Z
39,899,596
<pre><code>sudo apt-get install python-pycurl </code></pre> <p>this solved the problem.</p>
0
2016-10-06T15:08:12Z
[ "python", "python-2.7", "pip", "easy-install", "pycurl" ]
Selenium wait for element to be clickable python
39,083,974
<p>All, I'm needing a little assistance with Selenium waits. I can't seem to figure out how to wait for an element to be ready.</p> <p>The element that I am needing to wait I can locate and click using my script via the code below...</p> <pre><code>CreateJob = driver.find_element_by_xpath(".//*[@id='line']/div[1]/a")...
1
2016-08-22T15:59:16Z
39,084,035
<p>If you are in Java try below WebDriverWait syntax - </p> <pre><code>new WebDriverWait(driver,10,100).until(ExpectedConditions.visibilityOf(CreateJob)); </code></pre> <p>Waits for 10ses and polls every 100 msec for the CreateJob element to be visible. Can use <code>ExpectedConditions.elementToBeClickable(CreateJob)...
0
2016-08-22T16:03:03Z
[ "python", "selenium" ]
Selenium wait for element to be clickable python
39,083,974
<p>All, I'm needing a little assistance with Selenium waits. I can't seem to figure out how to wait for an element to be ready.</p> <p>The element that I am needing to wait I can locate and click using my script via the code below...</p> <pre><code>CreateJob = driver.find_element_by_xpath(".//*[@id='line']/div[1]/a")...
1
2016-08-22T15:59:16Z
39,084,357
<p>Here is a link to the 'waiting' section of the Python Selenium docs: <a href="http://selenium-python.readthedocs.io/waits.html#explicit-waits" rel="nofollow">http://selenium-python.readthedocs.io/waits.html#explicit-waits</a></p> <p>You wait should look like this:</p> <pre><code>element = WebDriverWait(driver, 10)...
2
2016-08-22T16:21:35Z
[ "python", "selenium" ]
Selenium wait for element to be clickable python
39,083,974
<p>All, I'm needing a little assistance with Selenium waits. I can't seem to figure out how to wait for an element to be ready.</p> <p>The element that I am needing to wait I can locate and click using my script via the code below...</p> <pre><code>CreateJob = driver.find_element_by_xpath(".//*[@id='line']/div[1]/a")...
1
2016-08-22T15:59:16Z
39,091,572
<p>I find this to be the easiest: </p> <pre><code>driver.implicitly_wait(10) </code></pre> <p>Where it waits for up to 10 seconds before the script might crash if expected conditions aren't met. I think it's better than always checking for the visibility of, the clickability of, or whatever it is about the element. ...
0
2016-08-23T02:50:45Z
[ "python", "selenium" ]
Django SMTP library generates wrong smtp auth plain authentication string
39,083,998
<p>I encounter a strange, reproducible issue on different setups (localhost, production systems) with Django's smtp library:</p> <p>the auth plain authentication string is totally off the mark. This is what the python console returns: <code> sys.version_info sys.version_info(major=3, minor=5, micro=0, releaselevel='fi...
0
2016-08-22T16:01:10Z
39,099,854
<p>aldryn-emailsettings is being deprecated and it does not support python3 yet. Use a recent version of aldryn-django (1.8.15.2 or 1.9.8.2 and higher) and set the email connection as an <code>EMAIL_URL</code> environment variable instead. See <a href="https://pypi.python.org/pypi/dj-email-url/" rel="nofollow">https://...
0
2016-08-23T11:25:07Z
[ "python", "django", "smtp" ]
Changed behaviour of ImageEnhance.Brightness in Pillow
39,084,077
<p>I'm trying to paste image B over image A with half opacity (i.e. pasted image is half transparent). </p> <p>In version 2.1.0 of pillow the following code worked, in version 3.3.1 it no longer works:</p> <blockquote> <pre><code>A = Image.open('A.png') B = Image.open('B.png') enhancer = ImageEnhance.Brightness(B) m...
0
2016-08-22T16:05:11Z
39,086,273
<p>Pillow is correct, changing the brightness of a pixel <em>should not</em> change its transparency. Obviously there was a bug in PIL.</p> <p>What you really want is to split the alpha from image B and turn <em>that</em> into a mask. Using the technique from <a href="http://stackoverflow.com/a/1963146/5987">this answ...
1
2016-08-22T18:23:35Z
[ "python", "image", "pillow", "brightness" ]
Receive and process a SOAP message
39,084,131
<p>Got a service provider (Safaricom) that has decided to use SOAP to send mobile money payment notifications to businesses. When the mobile user pays (either through USSD or via a web interface) the mobile money service will send a SOAP message that we are supposed to consume.</p> <pre><code>&lt;soapenv:Envelope xmln...
0
2016-08-22T16:08:31Z
39,266,508
<p>I hope it's not late for an answer: For the C2B transactions there is a project on github <a href="https://github.com/kn9ts/project-mulla" rel="nofollow">https://github.com/kn9ts/project-mulla</a> it takes the request from the checkout in POST form, converts it to a SOAP request, send it to safaricom, receives the r...
0
2016-09-01T08:32:28Z
[ "python", "soap", "python-3.4", "bottle", "suds" ]
How to write proper decorator to alter classes
39,084,190
<p>I know I can use closure and inheritance to create a decorator that alter classes.</p> <pre><code>def wrapper(cls, *args, **kwargs): class Wrapped(cls): """Modify your class here.""" return Wrapped </code></pre> <p>But if I need to test my new classes to know if they inherit <code>Wrapped</code> o...
0
2016-08-22T16:11:11Z
39,084,282
<p>It sounds like you want to check whether a class has been wrapped by this particular decorator. The most efficacious method to do so may simply be to add a field to that effect, to wit:</p> <pre><code>def wrapper(cls, *args, **kwargs): class Wrapped(cls): """Modify your class here.""" Wrapped._is_w...
2
2016-08-22T16:17:17Z
[ "python", "python-decorators" ]
How to write proper decorator to alter classes
39,084,190
<p>I know I can use closure and inheritance to create a decorator that alter classes.</p> <pre><code>def wrapper(cls, *args, **kwargs): class Wrapped(cls): """Modify your class here.""" return Wrapped </code></pre> <p>But if I need to test my new classes to know if they inherit <code>Wrapped</code> o...
0
2016-08-22T16:11:11Z
39,084,314
<p>You could inherit from two classes, a base class and <code>cls</code>:</p> <pre><code>class WrapperBase: pass def wrapper(cls, *args, **kwargs): class Wrapped(cls, WrapperBase): """Modify your class here.""" return Wrapped </code></pre> <p>Now all instances of generated classes test <code>Tru...
1
2016-08-22T16:19:07Z
[ "python", "python-decorators" ]
Finding distance between two gps points in Python
39,084,244
<p>I have the method below (haversine) that returns the distance between two gps points. Table below is my dataframe.</p> <p>When I apply the function on the dataframe using, I get the error "cannot convert the series to ". Not sure whether i am missing something. Any help would be appreciated.</p> <pre><code> distdf...
0
2016-08-22T16:15:00Z
39,084,283
<p>Try: </p> <pre><code>distdf1.apply(lambda x: haversine(x['SLongitude'], x['SLatitude'], x['ClosestLong'], x['ClosestLat']), axis=1) </code></pre>
0
2016-08-22T16:17:18Z
[ "python", "pandas", "dataframe" ]
Logging in an already-registered user in Django
39,084,249
<p>I have made the registration part of the login system, but I am unable to make a registered user login. How can I do this?</p> <p>Here's my code:</p> <h3>Views.py</h3> <pre><code>from django.shortcuts import render, redirect from django.contrib.auth import authenticate, login from django.views.generic import View...
-1
2016-08-22T16:15:06Z
39,084,382
<p>You need to use <code>authenticate()</code> and <code>login()</code> after create your user. </p> <p>Also, use <code>HttpResponseRedirect</code> to redirect user to your landing page, I think, you don't need to create a "success.html".</p> <pre><code> if form.is_valid(): user = form.save(commit...
1
2016-08-22T16:22:47Z
[ "python", "django", "forms", "authentication" ]
SPSS Python Custom Extension Command Debugging
39,084,265
<p>I have created a Custom Extension Command in Python. I installed it, but as expected I am getting errors (quote from SPSS log output - the only way I know for debugging Python programs in SPSS):</p> <pre><code>Extension command TEST_EXTENSION could not be loaded. The module or a module that it requires may be mis...
1
2016-08-22T16:16:02Z
39,102,672
<p>@horace</p> <p>You set the environment variable on Windows via the Control Panel > System > Advanced system settings > Environment Variables. The exact wording varies with different Windows versions. I usually choose System variables, although either will usually work. You need to restart Statistics after that. ...
1
2016-08-23T13:31:18Z
[ "python", "debugging", "spss" ]
Find the index of first same group based on value in a dictionary
39,084,289
<p>I have a dictionary, which shows one individual's trip, where blank list means walk and list with content means the tube he/she took. I want to find out his/her first tube journey which are indexed as '2,3'.</p> <pre><code>specific_path_legs={0: [], 1: [], 2: ['Jubilee'], 3: ['Jubilee'], 4: [], 5: [], 6: ['Me...
0
2016-08-22T16:17:32Z
39,084,378
<pre><code># Sort dictionary based on keys import collections specific_path_legs = collections.OrderedDict(sorted(specific_path_legs.items())) # Store your info in another dict path_legs_dict = {} for key, value in specific_path_legs.items(): if value and value[0] not in path_legs_dict: path_legs_dict[valu...
0
2016-08-22T16:22:37Z
[ "python", "dictionary", "indexing", "key", "value" ]
Find the index of first same group based on value in a dictionary
39,084,289
<p>I have a dictionary, which shows one individual's trip, where blank list means walk and list with content means the tube he/she took. I want to find out his/her first tube journey which are indexed as '2,3'.</p> <pre><code>specific_path_legs={0: [], 1: [], 2: ['Jubilee'], 3: ['Jubilee'], 4: [], 5: [], 6: ['Me...
0
2016-08-22T16:17:32Z
39,085,733
<p>Since the keys are incremental starting from 0 just go until you find a non empty value:</p> <pre><code>for i in range(len(specific_path_legs)): if specific_path_legs[i]: print(i, specific_path_legs[i]) break </code></pre> <p>Which would give you:</p> <pre><code>(2, ['Jubilee']) </code></pre> ...
0
2016-08-22T17:49:26Z
[ "python", "dictionary", "indexing", "key", "value" ]
pyqt4 Setting QDateEdit value in Linux
39,084,290
<p>I am copying a date value from a table to a QDateEdit in a dialog prior to launching the dialog. When I do this, the date format changes from "yyyy-MM-dd" to "dd/MM/yy" in the dialog. This happens in Linux not in OSx. My Code:</p> <pre><code>class BuildRecordEditorDialog(QDialog, Ui_brePartEditDialog): def __in...
0
2016-08-22T16:17:43Z
39,240,067
<p>No answers forthcoming so I did a work around. I converted the dates returned from the dialog from the bad format to the one I wanted and then processed them. User sees a different format but enters data with a date picker so all-in-all it will do.</p>
0
2016-08-31T02:59:09Z
[ "python", "linux", "pyqt4" ]
List item template Django
39,084,313
<p>I'm dealing creating a template on Django to show a list of items with 2 buttons that make actions.</p> <p>My form class it's:</p> <pre><code>class AppsForm(forms.Form): def __init__(self, *args, **kwargs): policiesList = kwargs.pop('policiesList', None) applicationList = kwargs.pop('applicatio...
0
2016-08-22T16:19:05Z
39,084,935
<p>You just need to change the code a bit is all:</p> <pre><code>{% for field in form %} { field.label }}: {{ field}} &lt;input type="submit" class="btn btn-default btn-success" name="deployButton" value="Deploy"/&gt; &lt;input type="submit" class="btn btn-default btn-danger" name="undeployButton" value="U...
1
2016-08-22T16:57:36Z
[ "python", "django", "forms", "list" ]
Unable to import multithreaded Python module.
39,084,341
<p>This is the multithreaded code I'm trying to import as a module. It works fine when I run it as a stand alone file. It simply just prints out a list of numbers. All I change is which main() is commented out. I think that the problem might be that the imported code is calling itself as a module after the reader file ...
1
2016-08-22T16:20:50Z
39,115,666
<p>You're violating a significant Windows-specific constraint called out <a href="https://docs.python.org/2/library/multiprocessing.html#windows" rel="nofollow">here</a>:</p> <blockquote> <p>Make sure that the main module can be safely imported by a new Python interpreter without causing unintended side effects (suc...
0
2016-08-24T06:14:42Z
[ "python", "multithreading", "import", "module", "multiprocessing" ]
How can I trigger an IncompleteRead (on purpose) in a Python web application?
39,084,348
<p>I've got some Python code that makes requests using the <a href="http://docs.python-requests.org/en/master/" rel="nofollow">requests</a> library and occasionally experiences an <code>IncompleteRead</code> error. I'm trying to update this code to handle this error more gracefully and would like to test that it works,...
1
2016-08-22T16:21:09Z
39,084,614
<p>When testing code that relies on external behavior (such as server responses, system sensors, etc) the usual approach is to fake the external factors instead of working to produce them.</p> <p>Create a test version of the function or class you're using to make HTTP requests. If you're using <code>requests</code> <e...
1
2016-08-22T16:37:47Z
[ "python", "python-requests" ]
How can I trigger an IncompleteRead (on purpose) in a Python web application?
39,084,348
<p>I've got some Python code that makes requests using the <a href="http://docs.python-requests.org/en/master/" rel="nofollow">requests</a> library and occasionally experiences an <code>IncompleteRead</code> error. I'm trying to update this code to handle this error more gracefully and would like to test that it works,...
1
2016-08-22T16:21:09Z
39,086,666
<p><em>Adding a second answer, more to the point this time. I took a dive into some source code, and found information that may help</em></p> <p>The <code>IncompleteRead</code> exception bubbles up from <code>httplib</code>, part of the python standard library. Most likely, it comes from <a href="https://github.com/py...
1
2016-08-22T18:46:48Z
[ "python", "python-requests" ]
Google Prediction API with Google App Engine
39,084,362
<p>I'm following this example, and at the bottom it has some code <a href="https://cloud.google.com/prediction/docs/developer-guide" rel="nofollow">https://cloud.google.com/prediction/docs/developer-guide</a></p> <p>I'm using Flask instead of webapp2 and my code looks like this:</p> <pre><code># [START app] import lo...
1
2016-08-22T16:21:55Z
39,084,712
<p><strong>You are missing a colon on line 24, where the little carrot is pointing to in the stack trace:</strong></p> <pre><code> File "/Users/morganallen/Desktop/project/flask_app_engine/main.py", line 24 result = service.hostedmodels().predict(project='linear-yen-140912', hostedModelName='language-identifier', bod...
2
2016-08-22T16:43:40Z
[ "python", "google-app-engine" ]
Stitched image not well aligned, hence leading to duplication
39,084,392
<p>As shown in the image below, one image is not well aligned with another, which is causing duplication of vessels. How do I get rid of the duplication?</p> <p><img src="http://i.stack.imgur.com/EwlLA.jpg" alt="enter image description here"></p> <p>Th way I'm currently going about stitching is, I first find the keyp...
0
2016-08-22T16:23:50Z
39,087,094
<p>homography isnt perfect for non-planar scene or non-pure-rotation-camera, so there will always be errors SOMEWHERE in the aligned images. </p> <p>Imho best to do (if you have to use homographies) is to distribute the errors over the whole image by making sure that the points used to compute the homography are distr...
1
2016-08-22T19:13:14Z
[ "python", "opencv", "image-processing", "computer-vision" ]
How to deal with a child thread that hangs?
39,084,395
<p>I have a process to extract data from an API that uses multiple threads that is hanging.</p> <ul> <li>The main thread launches the child threads and waits until N numbers of API calls have been made and all child threads have ended to finish;</li> <li>1 child thread populates a queue with calls that need to be made...
0
2016-08-22T16:23:56Z
39,085,490
<p>When a thread is created, you can control whether it will be automatically terminated when the main thread quits by explicitly setting its <code>daemon</code> attribute before calling its <code>start()</code> method. See the <a href="https://docs.python.org/2/library/threading.html#threading.Thread.daemon" rel="nofo...
0
2016-08-22T17:32:50Z
[ "python", "multithreading", "api", "design-patterns" ]
tkinter.Listbox scrolbar yview
39,084,403
<p>I again encounter some problems in writing Python and would like to seek my help. I continue to build my Listbox widget but cannot setup a scrollbar. I can put the Scrollbar in the right position, however, the up and down just don't work out and pop up an error saying "Object() takes no parameter". Could anyone advi...
1
2016-08-22T16:24:23Z
39,086,030
<p>first of all you don't need both <code>import tkinter</code> and <code>from tkinter import *</code></p> <ul> <li>Using <code>import</code> means you need <code>tkinter.'function'</code> to call a function from tkinter </li> <li>Using <code>from</code> means you can call the function as if it were in your program ...
1
2016-08-22T18:07:08Z
[ "python", "tkinter", "listbox", "python-3.5" ]
Reading a text file and assigning the values
39,084,411
<p>I have a text file with 5 columns:</p> <pre class="lang-none prettyprint-override"><code>StudentID UserID FirstName LastName NickName 0122334 7727263 John Smith Johnny 8273263 8349734 timmer Jansen tim </code></pre> <p>I am trying to read this file in python and assig...
1
2016-08-22T16:24:48Z
39,084,456
<pre><code>f = open(textfile, 'r') for line in f: student_id, user_id, first_name, last_name, nick_name = line.split(' ') StudentId.append(student_id) UserId.append(user_id) .... f.close() </code></pre> <p>That is very weird way to write anything though. Much better way is to create class Student that will know th...
1
2016-08-22T16:27:45Z
[ "python", "python-2.7" ]
Reading a text file and assigning the values
39,084,411
<p>I have a text file with 5 columns:</p> <pre class="lang-none prettyprint-override"><code>StudentID UserID FirstName LastName NickName 0122334 7727263 John Smith Johnny 8273263 8349734 timmer Jansen tim </code></pre> <p>I am trying to read this file in python and assig...
1
2016-08-22T16:24:48Z
39,084,490
<pre><code>with open(textfile,'r') as f: for line in f.readlines(): student_id ,user_id, first_name, last_name, nick_name = line.split() StudentID.append(student_id) UserID.append(user_id) FirstName.append(first_name) LastName.append(last_name) NickName.append(nick_...
1
2016-08-22T16:29:59Z
[ "python", "python-2.7" ]
Reading a text file and assigning the values
39,084,411
<p>I have a text file with 5 columns:</p> <pre class="lang-none prettyprint-override"><code>StudentID UserID FirstName LastName NickName 0122334 7727263 John Smith Johnny 8273263 8349734 timmer Jansen tim </code></pre> <p>I am trying to read this file in python and assig...
1
2016-08-22T16:24:48Z
39,084,949
<p>You can extract all of them at once:</p> <pre><code>with open(textfile,'r') as f: columns = [line.split() for line in f.readlines()] </code></pre> <p>And then create each list from <code>columns</code>:</p> <pre><code>StudentID, UserID, firstNAme, LastNAme, NickName = map(list, zip(*columns)) </code></pre> <...
3
2016-08-22T16:58:12Z
[ "python", "python-2.7" ]
How do I setup logging when using aiohttp and aiopg with Gunicorn?
39,084,433
<p><code>aiohttp</code> is great, but setting up logging has been a nightmare, both locally and in production, when using <code>Gunicorn</code>.</p> <p>Most of the examples and documentation I find for setting up logging are for running in native server mode, where you use <code>make_handler()</code></p> <p>As recomm...
1
2016-08-22T16:26:08Z
39,107,800
<p>Documentation <strong>don't recommend</strong> to use Gunicorn for deployment but have instructions for under running Gunicorn. </p> <p>Perhaps it should be upgraded to passing correct format for access logger.</p> <p>From my perspective the easiest way to run aiohttp server is just running it (by using <code>web....
1
2016-08-23T17:53:52Z
[ "python", "psycopg2", "gunicorn", "aiohttp" ]
Spark: how to get cluster's points (KMeans)
39,084,519
<p>I'm trying to retrieve the data points belonging to a specific cluster in Spark. In the following piece of code, the data is made up but I actually obtain the predicted clustered.</p> <p>Here is the code I have so far:</p> <pre><code>import numpy as np # Example data flight_routes = np.array([[1,3,2,0], ...
0
2016-08-22T16:31:25Z
39,089,300
<p>If you both record and prediction (and not willing to switch to Spark ML) you can <code>zip</code> RDDs:</p> <pre><code>predictions_and_values = model.predict(test).zip(test) </code></pre> <p>and filter afterwards: </p> <pre><code>predictions_and_values.filter(lambda x: x[1] == 100) </code></pre>
0
2016-08-22T21:53:04Z
[ "python", "apache-spark", "k-means" ]
how to use spark with python or jupyter notebook
39,084,520
<p>I am trying to work with 12GB of data in python for which I desperately need to use Spark , but I guess I'm too stupid to use command line by myself or by using internet and that is why I guess I have to turn to SO , </p> <p>So by far I have downloaded the spark and unzipped the tar file or whatever that is ( sorry...
1
2016-08-22T16:31:28Z
39,084,592
<p>When you unzip the file, a directory is created.</p> <ol> <li>Open a terminal.</li> <li>Navigate to that directory with <code>cd</code>.</li> <li>Do an <code>ls</code>. You will see its contents. <code>bin</code> must be placed somewhere.</li> <li>Execute <code>bin/pyspark</code> or maybe <code>./bin/pyspark</code>...
2
2016-08-22T16:36:21Z
[ "python", "windows", "apache-spark", "pyspark", "distributed-computing" ]
how to use spark with python or jupyter notebook
39,084,520
<p>I am trying to work with 12GB of data in python for which I desperately need to use Spark , but I guess I'm too stupid to use command line by myself or by using internet and that is why I guess I have to turn to SO , </p> <p>So by far I have downloaded the spark and unzipped the tar file or whatever that is ( sorry...
1
2016-08-22T16:31:28Z
39,091,446
<p>If you are more familiar with jupyter notebook, you can install <a href="https://toree.incubator.apache.org/documentation/user/quick-start" rel="nofollow">Apache Toree</a> which integrates pyspark,scala,sql and SparkR kernels with Spark.</p> <p>for installing toree</p> <pre><code>pip install toree jupyter toree i...
1
2016-08-23T02:34:40Z
[ "python", "windows", "apache-spark", "pyspark", "distributed-computing" ]
Convert pandas DataFrame to dict where each value is a list of values of multiple columns
39,084,521
<p>Let's say I have the DataFrame</p> <pre><code>filename size inverse similarity 123.txt 1 2 34 323.txt 3 1 44 222.txt 4 1 43 </code></pre> <p>I want to create a dictionary in the form</p> <pre><code>{'123.txt': [1, 2, 34], '323.txt': [3, 1, 44], '222.txt': [4, 1, 43]} </code></pre> ...
1
2016-08-22T16:31:35Z
39,084,631
<p>Set <code>'filename'</code> as the index, take the transpose, then use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_dict.html" rel="nofollow"><code>to_dict</code></a> with <code>orient='list'</code>:</p> <pre><code>my_dict = df.set_index('filename').T.to_dict(orient='list') </c...
3
2016-08-22T16:39:26Z
[ "python", "pandas", "dataframe" ]
Convert pandas DataFrame to dict where each value is a list of values of multiple columns
39,084,521
<p>Let's say I have the DataFrame</p> <pre><code>filename size inverse similarity 123.txt 1 2 34 323.txt 3 1 44 222.txt 4 1 43 </code></pre> <p>I want to create a dictionary in the form</p> <pre><code>{'123.txt': [1, 2, 34], '323.txt': [3, 1, 44], '222.txt': [4, 1, 43]} </code></pre> ...
1
2016-08-22T16:31:35Z
39,084,636
<p>Here's an approach with dict comprehension:</p> <pre><code>{k: v for k, v in zip(df['filename'], df.set_index('filename').values.tolist())} Out: {'123.txt': [1, 2, 34], '222.txt': [4, 1, 43], '323.txt': [3, 1, 44]} </code></pre>
3
2016-08-22T16:39:45Z
[ "python", "pandas", "dataframe" ]
Access queryset values while setting up modelform
39,084,611
<p>Is it possible to access a value from the queryset that was used to create the form class. For example I have the following view:</p> <pre><code>class MyView(View): position = Position() form_class = PortfolioForm PositionModelFormSet = modelformset_factory(Position, ...
0
2016-08-22T16:37:39Z
39,090,101
<p>With a ModelForm, form.instance already works. </p> <p>In the form: self.instance</p> <p>In the view: formset.form.instance</p>
1
2016-08-22T23:13:52Z
[ "python", "django", "django-forms" ]
Using a list of lists as a lookup table and updating a value in new list of lists
39,084,661
<p>I have an application that creates a list of lists. The second element in the list needs to be assigned using lookup list which also consists of a list of lists. </p> <p>I have used the "all" method to match the values in the list. If the list value exists in the lookup list, it should update the second position el...
3
2016-08-22T16:40:52Z
39,084,713
<p>You can't do what you want with <code>all()</code>, because <code>elem</code> is not a local variable outside of the generator expression.</p> <p>Instead of using a list, use a <em>dictionary</em> to store the <code>lookupList</code>:</p> <pre><code>lookupDict = dict(lookupList) </code></pre> <p>and looking up ma...
3
2016-08-22T16:43:41Z
[ "python", "list" ]
Using a list of lists as a lookup table and updating a value in new list of lists
39,084,661
<p>I have an application that creates a list of lists. The second element in the list needs to be assigned using lookup list which also consists of a list of lists. </p> <p>I have used the "all" method to match the values in the list. If the list value exists in the lookup list, it should update the second position el...
3
2016-08-22T16:40:52Z
39,084,879
<p>you should use dictionaries instead, like this:</p> <pre><code>lookupList = newData = {} old_lookupList = [['Garry','34'],['Simon', '24'] ,['Louise','13'] ] old_newData = [['Louise','xxx'],['Garry', 'xxx'] ,['Simon','xxx'] ] #convert into dictionary for e in old_newData: newData[e[0]] = e[1] for e in old_lookupL...
0
2016-08-22T16:54:17Z
[ "python", "list" ]
dictionary from JSON to CSV
39,084,687
<p>I have a JSON file containing a dictionary with many key-value pairs. I want to write it to a single CSV. One way to do this is simply to iterate through each key:</p> <pre><code>csvwriter.writerow([f["dict"]["key1"], f["dict"]["key2"], f["dict"]["key3"], ... ]) </code></pre> <p>This would be v...
1
2016-08-22T16:41:59Z
39,084,751
<p>You probably want to use a <a href="https://docs.python.org/2/library/csv.html#csv.DictWriter" rel="nofollow"><code>csv.DictWriter</code></a></p> <p>The example in the official documentation is pretty straight-forward:</p> <pre><code>import csv with open('names.csv', 'w') as csvfile: fieldnames = ['first_name...
3
2016-08-22T16:46:17Z
[ "python", "json", "csv", "dictionary" ]
dictionary from JSON to CSV
39,084,687
<p>I have a JSON file containing a dictionary with many key-value pairs. I want to write it to a single CSV. One way to do this is simply to iterate through each key:</p> <pre><code>csvwriter.writerow([f["dict"]["key1"], f["dict"]["key2"], f["dict"]["key3"], ... ]) </code></pre> <p>This would be v...
1
2016-08-22T16:41:59Z
39,084,762
<p><a href="http://pandas.pydata.org/pandas-docs/stable/index.html" rel="nofollow">Pandas</a> is good for this kind of thing. </p> <p>I would read the JSON file into a pandas dataframe (<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_json.html" rel="nofollow">link</a>). Then write it as a CS...
1
2016-08-22T16:47:37Z
[ "python", "json", "csv", "dictionary" ]
dictionary from JSON to CSV
39,084,687
<p>I have a JSON file containing a dictionary with many key-value pairs. I want to write it to a single CSV. One way to do this is simply to iterate through each key:</p> <pre><code>csvwriter.writerow([f["dict"]["key1"], f["dict"]["key2"], f["dict"]["key3"], ... ]) </code></pre> <p>This would be v...
1
2016-08-22T16:41:59Z
39,084,796
<p>Equivalent to your code: </p> <pre><code>csvwriter.writerow(f["dict"].values()) </code></pre> <p><strong>Note:</strong> For this, your dictionary should be of <code>collections.OrderedDict</code> because Python's default dictionaries are not ordered. Hence, you'll end up with different order in each row.</p> <p><...
1
2016-08-22T16:49:54Z
[ "python", "json", "csv", "dictionary" ]
dictionary from JSON to CSV
39,084,687
<p>I have a JSON file containing a dictionary with many key-value pairs. I want to write it to a single CSV. One way to do this is simply to iterate through each key:</p> <pre><code>csvwriter.writerow([f["dict"]["key1"], f["dict"]["key2"], f["dict"]["key3"], ... ]) </code></pre> <p>This would be v...
1
2016-08-22T16:41:59Z
39,088,528
<p>It's not necessary to use <code>csv.DictWriter</code>. The following, which works in both Python 2 and 3, shows how to create a CSV file that will automatically have the key/value pairs in the same order as they appear in the JSON file (instead of requiring a manually defined <code>fieldnames</code> list):</p> <pre...
0
2016-08-22T20:51:05Z
[ "python", "json", "csv", "dictionary" ]
Facing 401 Error while streaming tweets using python
39,084,694
<p>The below image shows the code and error message .</p> <p>I have pasted the code below </p> <p>Code:</p> <pre><code>from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming import StreamListener #consumer key, consumer secret, access token, access secret. ckey="" csecret="" atoken="" asec...
0
2016-08-22T16:42:31Z
39,085,367
<p>I haven't used this software but I believe the problem is that you haven't supplied a consumer key and consumer secret. This being the case you could refer to,</p> <p><a href="http://support.yapsody.com/hc/en-us/articles/203068116-How-do-I-get-a-Twitter-Consumer-Key-and-Consumer-Secret-key-" rel="nofollow">Getting ...
0
2016-08-22T17:25:12Z
[ "python", "twitter", "tweepy" ]
Django - create custom tag to acces variable by index in template
39,084,777
<p>I have a HTML template in django. It get's two variables: list of categories (queryset, as it it returned by <code>.objects.all()</code> function on model in django) and dictionary of contestants. As a key of the dictionary, I'm using id of category, and value is list of contestats. I want to print name of the cate...
0
2016-08-22T16:48:27Z
39,085,425
<p>If you don't want 2 lines like that you should be able to use a filter i think</p> <pre><code>@register.filter def list_index(a, b): return a[b] </code></pre> <p>Then the usage like this</p> <pre><code>{% for contestant in contestants_dict|list_index:category.id %} {{ contestant }} &lt;/br&gt; {% endfor %...
0
2016-08-22T17:28:36Z
[ "python", "django" ]
seaborn: how to make a tsplot square
39,084,813
<p>I would like to create a tsplot, where the x and the y axis are the same length. in other words the aspect ratio of the graph should be 1.</p> <p>this dos not work:</p> <pre><code>fig, ax = plt.subplots() fig.set_size_inches(2, 2) sns.tsplot(data=df, condition=' ', time='time', value='value', unit=' ', ax=ax) </co...
-1
2016-08-22T16:50:32Z
39,085,542
<p>You could change the aspect ratio of your plots by controlling the <a href="http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes.set_aspect" rel="nofollow"><code>aspect</code></a> parameter of a <code>matplotlib</code> object as shown:</p> <pre><code>import numpy as np import seaborn as sns import matplotli...
3
2016-08-22T17:37:08Z
[ "python", "matplotlib", "seaborn" ]
Multilingual issue using django
39,084,823
<p><br> Im Using python3 and django1.10 for my application , and kinnda new to django.<br> Im planning to have many languages for django admin panel. as i follow the rules in <a href="https://docs.djangoproject.com/en/1.10/" rel="nofollow">Django documantion</a>, i find out that i have to use a <code>middleware</code> ...
0
2016-08-22T16:51:06Z
39,085,451
<p>In a view, you can use:</p> <pre><code>from django.utils import translation # to change to French for example translation.activate('fr') # and you set it in the session to change it for the user request.session[settings.LANGUAGE_SESSION_KEY] = 'fr' </code></pre> <p>So, you can add code similar to that in your vi...
0
2016-08-22T17:30:02Z
[ "python", "django", "python-3.x", "django-admin", "multilingual" ]
Convert 160 bit Hash to unique integer ids for machine learning input
39,085,051
<p>I am preparing some data for k-means clustering. At the moment I have the id in 160 bit hash format (this is the format for bitcoin addresses). </p> <pre><code>d = {'Hash' : pd.Series(['1HYKGGzRHDskth2ecKZ2HYvxSvQ1p87m6', '3DndG5HuyP8Ep8p3V1i394AUxG4gtgsvoj', '1HYKGGzRHDskth2ecKZ2HYvxSvQ1p87m6']), 'X1' : pd.S...
0
2016-08-22T17:05:32Z
39,085,229
<p>There are quite a few ways. One way would be to use Categorical codes, and another would be to rank them:</p> <pre><code>In [16]: df1["via_categ"] = pd.Categorical(df1.Hash).codes + 1 In [17]: df1["via_rank"] = df1["Hash"].rank(method="dense").astype(int) In [18]: df1 Out[18]: Ha...
1
2016-08-22T17:17:13Z
[ "python", "pandas", "numpy", "k-means" ]
Convert 160 bit Hash to unique integer ids for machine learning input
39,085,051
<p>I am preparing some data for k-means clustering. At the moment I have the id in 160 bit hash format (this is the format for bitcoin addresses). </p> <pre><code>d = {'Hash' : pd.Series(['1HYKGGzRHDskth2ecKZ2HYvxSvQ1p87m6', '3DndG5HuyP8Ep8p3V1i394AUxG4gtgsvoj', '1HYKGGzRHDskth2ecKZ2HYvxSvQ1p87m6']), 'X1' : pd.S...
0
2016-08-22T17:05:32Z
39,085,281
<pre><code>s = list(set(df1.Hash)) hash2 = dict(zip(s, range(1, len(s) + 1))) df1.Hash = df1.Hash.map(hash2) print(df1) </code></pre> <p>Output:</p> <pre><code> Hash X1 X2 X3 0 2 111 111 111 1 1 222 222 222 2 2 333 333 333 </code></pre>
0
2016-08-22T17:19:40Z
[ "python", "pandas", "numpy", "k-means" ]
Convert 160 bit Hash to unique integer ids for machine learning input
39,085,051
<p>I am preparing some data for k-means clustering. At the moment I have the id in 160 bit hash format (this is the format for bitcoin addresses). </p> <pre><code>d = {'Hash' : pd.Series(['1HYKGGzRHDskth2ecKZ2HYvxSvQ1p87m6', '3DndG5HuyP8Ep8p3V1i394AUxG4gtgsvoj', '1HYKGGzRHDskth2ecKZ2HYvxSvQ1p87m6']), 'X1' : pd.S...
0
2016-08-22T17:05:32Z
39,085,523
<p>You can use <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.LabelEncoder.html" rel="nofollow"><code>sklearn.preprocessing.LabelEncoder</code></a>:</p> <pre><code>from sklearn import preprocessing le = preprocessing.LabelEncoder() le.fit(df1['Hash']) df1['Hash'] = le.transform(df1['H...
0
2016-08-22T17:35:33Z
[ "python", "pandas", "numpy", "k-means" ]
Interrupt python script with a specific key on Linux
39,085,169
<p>I'm trying to have a loop which increments and prints a value. While it's running I would like to press a key (eg. space or shift) and have it print that the key was pressed. Below is example code of what I would like.</p> <pre><code>def space(): print 'You pressed space' def shift(): print 'You presse...
1
2016-08-22T17:13:16Z
39,085,309
<p>If you're on windows, check out <a href="https://docs.python.org/3.5/library/msvcrt.html" rel="nofollow">msvcrt</a>:</p> <pre><code>import msvcrt while True: x += 1 sleep(x) if msvcrt.kbhit(): print "You pressed: %s" % msvcrt.getch() </code></pre>
-1
2016-08-22T17:21:39Z
[ "python", "linux", "python-2.7" ]
Interrupt python script with a specific key on Linux
39,085,169
<p>I'm trying to have a loop which increments and prints a value. While it's running I would like to press a key (eg. space or shift) and have it print that the key was pressed. Below is example code of what I would like.</p> <pre><code>def space(): print 'You pressed space' def shift(): print 'You presse...
1
2016-08-22T17:13:16Z
39,085,785
<p>I can help you with modified answer form here:</p> <p><a href="http://stackoverflow.com/questions/11918999/key-listeners-in-python?answertab=votes#tab-top">http://stackoverflow.com/questions/11918999/key-listeners-in-python</a></p> <p>and for only space and enter:</p> <pre><code>import contextlib import sys impor...
1
2016-08-22T17:52:51Z
[ "python", "linux", "python-2.7" ]
How to stream Csv file into BigQuery?
39,085,231
<p>Examples I found so far is streaming json to BQ, e.g. <a href="https://cloud.google.com/bigquery/streaming-data-into-bigquery" rel="nofollow">https://cloud.google.com/bigquery/streaming-data-into-bigquery</a></p> <p>How do I stream Csv or any file type into BQ? Below is a block of code for streaming and seems "issu...
2
2016-08-22T17:17:24Z
39,085,676
<p>This is how I <a href="https://github.com/DuoSoftware/DigInEngine/blob/master/modules/BigQueryHandler.py#L85" rel="nofollow">wrote</a> using <a href="https://github.com/tylertreat/BigQuery-Python" rel="nofollow">bigquery-python</a> library very easily.</p> <pre><code>def insert_data(datasetname,table_name,DataObjec...
1
2016-08-22T17:45:39Z
[ "python", "streaming", "google-bigquery" ]
Manipulating pandas dataframe using 3 columns of data
39,085,326
<p>I am having trouble coming up with a way to accomplish my task. I've got a dataframe with 3 columns: <code>length, reachcode, and year</code>. </p> <p>My example dataframe: </p> <pre><code>year reachcode length 1988 1000 1.2 1988 1000 2.0 1990 1000 0.3 1993 1000 0.5 </code></pre> <p>...
1
2016-08-22T17:22:43Z
39,085,682
<p>It sounds like you need a double-stage <code>groupby</code>. Firstly groupby <code>year</code> and <code>reachcode</code> and calculate the sum, reset index so that you can groupby <code>reachcode</code> further to take the min of <code>length</code>:</p> <pre><code>df.groupby(['year', 'reachcode']).sum().reset_ind...
2
2016-08-22T17:45:46Z
[ "python", "pandas" ]
Manipulating pandas dataframe using 3 columns of data
39,085,326
<p>I am having trouble coming up with a way to accomplish my task. I've got a dataframe with 3 columns: <code>length, reachcode, and year</code>. </p> <p>My example dataframe: </p> <pre><code>year reachcode length 1988 1000 1.2 1988 1000 2.0 1990 1000 0.3 1993 1000 0.5 </code></pre> <p>...
1
2016-08-22T17:22:43Z
39,085,705
<p>Simply run <code>groupby</code> aggregates:</p> <pre><code>df['lengthsum'] = df.groupby(['year', 'reachcode'])['length'].transform(sum) df['lengthmin'] = df.groupby(['reachcode'])['lengthsum'].transform(min) # year reachcode length lengthsum lengthmin # 0 1988 1000 1.2 3.2 0.3 # 1 ...
2
2016-08-22T17:47:17Z
[ "python", "pandas" ]
Deleting a List of Labels From The Tkinter Window Placed In The Grid
39,085,468
<p>a. Have a scenario where I had created a list of labels as shown below.</p> <pre><code>class test_template: def __init__(self, master): self.master = master ... def nb_code(self): if nb_cnt == 0: for i in range (int(no_of_fs)): self.enul = Label(root, text="Enter The Number Of Fruits I...
0
2016-08-22T17:31:03Z
39,088,767
<p>You can get <code>root</code> children and search for your labels. </p> <pre><code>for child in root.children.values(): info = child.grid_info() if info['column'] == 0: child.grid_forget() </code></pre>
0
2016-08-22T21:08:00Z
[ "python", "python-2.7", "tkinter", "tkinter-canvas" ]
Using pip with two --extra-index-url arguments that both point to the same domain
39,085,531
<p>We use our own python package index at my office, and we're trying to add a new one. When I try to specify both indices at the same time, I get prompted to log in, but if I use only one at a time I don't.</p> <p>For example:</p> <pre><code>$ pip install --user --upgrade \ --extra-index-url https://&lt;api toke...
1
2016-08-22T17:36:02Z
39,085,736
<pre><code>--extra-index-url </code></pre> <p>accepts a list (it should probably be called --extra-index-urls). Try adding your URLs comma separated, like this:</p> <pre><code>pip install --user --upgrade \ --extra-index-url https://&lt;api token&gt;:@packagebutt.io/2rs2ts/oldrepo/pypi/simple, \ https://&lt;o...
0
2016-08-22T17:49:37Z
[ "python", "pip" ]
Using pip with two --extra-index-url arguments that both point to the same domain
39,085,531
<p>We use our own python package index at my office, and we're trying to add a new one. When I try to specify both indices at the same time, I get prompted to log in, but if I use only one at a time I don't.</p> <p>For example:</p> <pre><code>$ pip install --user --upgrade \ --extra-index-url https://&lt;api toke...
1
2016-08-22T17:36:02Z
39,131,265
<p>Apparently this is a bug in pip. The HTTP basic auth information is not stored correctly when specifying multiple <code>--extra-index-url</code>s that point to the same domain. <a href="https://github.com/pypa/pip/issues/3931" rel="nofollow">I filed an issue</a>, but in the meantime, there is a workaround. By specif...
1
2016-08-24T19:08:19Z
[ "python", "pip" ]
Docker Build can't find pip
39,085,599
<p>Trying to follow a few[<a href="https://aws.amazon.com/blogs/aws/run-docker-apps-locally-using-the-elastic-beanstalk-eb-cli/" rel="nofollow">1</a>][<a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_dockerpreconfig.walkthrough.html" rel="nofollow">2</a>] simple Docker tutorials via AWS am a...
3
2016-08-22T17:40:45Z
39,138,501
<p>/var/app/bin/pip is supopsed to work because the <a href="https://github.com/aws/aws-eb-python-dockerfiles/blob/206710af939b622430fe0be3d7d8dcf177ad78e9/3.4.2-aws-eb-onbuild/Dockerfile#L5-L7" rel="nofollow">amazon/aws-eb-python:3.4.2-onbuild-3.5.1 Dockerfile</a> includes:</p> <pre><code>RUN pip3 install virt...
1
2016-08-25T06:50:31Z
[ "python", "amazon-web-services", "docker", "python-3.4" ]
Docker Build can't find pip
39,085,599
<p>Trying to follow a few[<a href="https://aws.amazon.com/blogs/aws/run-docker-apps-locally-using-the-elastic-beanstalk-eb-cli/" rel="nofollow">1</a>][<a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_dockerpreconfig.walkthrough.html" rel="nofollow">2</a>] simple Docker tutorials via AWS am a...
3
2016-08-22T17:40:45Z
39,139,192
<p>I think the issue is how you have organized your bin/pip files</p> <p>From Docker Documentation: <a href="https://docs.docker.com/engine/reference/builder/#add" rel="nofollow">https://docs.docker.com/engine/reference/builder/#add</a></p> <pre><code>If &lt;dest&gt; does not end with a trailing slash, it will be con...
1
2016-08-25T07:29:49Z
[ "python", "amazon-web-services", "docker", "python-3.4" ]
Docker Build can't find pip
39,085,599
<p>Trying to follow a few[<a href="https://aws.amazon.com/blogs/aws/run-docker-apps-locally-using-the-elastic-beanstalk-eb-cli/" rel="nofollow">1</a>][<a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_dockerpreconfig.walkthrough.html" rel="nofollow">2</a>] simple Docker tutorials via AWS am a...
3
2016-08-22T17:40:45Z
39,191,733
<p>Something is very odd here. Why do you have the virtualenv content next to your Dockerfile? <a href="https://github.com/aws/aws-eb-python-dockerfiles/tree/206710af939b622430fe0be3d7d8dcf177ad78e9/3.4.2-aws-eb-onbuild" rel="nofollow">The image you are building from</a> creates the virtualenv on /var/app (within the c...
2
2016-08-28T13:24:26Z
[ "python", "amazon-web-services", "docker", "python-3.4" ]
Find overlapping modularity in two graphs - iGraph in Python
39,085,646
<p>I have two related graphs created in iGraph, A and G. I find community in structure in G using either infomap or label_propagation methods (because they are two that allow for weighted, directional links). From this, I can see the modularity of this community for the G graph. However, I need to see what modularity t...
0
2016-08-22T17:43:51Z
39,185,816
<p>Did you try using the <code>modularity</code> function?</p> <pre><code>im &lt;- infomap.community(graph=G) qG &lt;- modularity(im) memb &lt;- membership(im) qA &lt;- modularity(x=A, membership=memb, weights=E(A)$weight) cat("qG=",qG," vs. qA=",qA,"\n",sep="") </code></pre> <p>Note: tested with igraph v0.7, I don't...
2
2016-08-27T21:15:01Z
[ "python", "graph", "igraph" ]
Find overlapping modularity in two graphs - iGraph in Python
39,085,646
<p>I have two related graphs created in iGraph, A and G. I find community in structure in G using either infomap or label_propagation methods (because they are two that allow for weighted, directional links). From this, I can see the modularity of this community for the G graph. However, I need to see what modularity t...
0
2016-08-22T17:43:51Z
39,735,109
<p>So I figured it out. What you need to do is find a community structure, either pre-defined or using one of the methods provided for community detection, such as infomap or label_propagation. This gives you a vertex clustering, which you can use to place on another graph and from that use .q to find the modularity.</...
-1
2016-09-27T22:08:31Z
[ "python", "graph", "igraph" ]
Django: Print out all choices for a models.Model class
39,085,760
<p>Im trying to write an algorithm that prints out all choices in a Django model class. </p> <p>For example: I have a model: </p> <pre><code>class SomeModel(models.Model): field_a = models.SmallIntegerField(choices=[(1, "a"), (2, "b"), (3, "c")] field_b = models.CharField(max_length=255) </code></pre> <p>The exp...
0
2016-08-22T17:51:17Z
39,086,016
<p>Have a look at the <a href="https://docs.djangoproject.com/en/1.10/ref/models/meta/" rel="nofollow">meta options</a> documentation. You can achieve this in the following way:</p> <pre><code>fields = SomeModel._meta.fields() for field in fields: if field.choices: print "%s: %s" % (field.name, field.choic...
1
2016-08-22T18:06:14Z
[ "python", "django", "django-models" ]
Iterate through Json list object - Python
39,085,867
<p>I have some JSON text I want to iterate through, formatted in the following way:</p> <pre><code>{ "itemsPerPage": 45, "links": { "next": "https://www.12345.com" }, "list": [ { "id": "333333", "placeID": "63333", "description": " ", "displayName": "test-12345", "name": "...
-2
2016-08-22T17:57:20Z
39,085,971
<p>While the JSON you posted isn't valid, I'll assume you left some stuff off the end.</p> <pre><code>for entry in dataset['list']: print(entry['displayName']) </code></pre> <p>Will loop through your JSON data. </p> <p>If you want to do_stuff() if it matches a certain value:</p> <pre><code>for entry in dataset[...
0
2016-08-22T18:03:44Z
[ "python", "json", "loops", "python-3.x", "object" ]
Iterate through Json list object - Python
39,085,867
<p>I have some JSON text I want to iterate through, formatted in the following way:</p> <pre><code>{ "itemsPerPage": 45, "links": { "next": "https://www.12345.com" }, "list": [ { "id": "333333", "placeID": "63333", "description": " ", "displayName": "test-12345", "name": "...
-2
2016-08-22T17:57:20Z
39,086,048
<p>This is work for me.</p> <pre><code>import json text = """{ "itemsPerPage": 45, "links": { "next": "https://www.12345.com" }, "list": [ { "id": "333333", "placeID": "63333", "description": " ", "displayName": "test-12345", "name": "test", "status": "Active", ...
0
2016-08-22T18:08:31Z
[ "python", "json", "loops", "python-3.x", "object" ]
Iterate through Json list object - Python
39,085,867
<p>I have some JSON text I want to iterate through, formatted in the following way:</p> <pre><code>{ "itemsPerPage": 45, "links": { "next": "https://www.12345.com" }, "list": [ { "id": "333333", "placeID": "63333", "description": " ", "displayName": "test-12345", "name": "...
-2
2016-08-22T17:57:20Z
39,086,424
<p>You need to actually perform actions within your loop. Python relies on whitespace to denote blocks. This is something you can't forget when writing Python.</p> <pre><code>for i in range(len(json_obj['list'])): if (json_obj['list'][i]['displayName'] == "some id"): do stuff else: exit() </code></pre> <p>sho...
0
2016-08-22T18:32:43Z
[ "python", "json", "loops", "python-3.x", "object" ]
Opening a gzip file in python Apache Beam
39,085,869
<p>Is it currently possible to read froma a gzip file in python using Apache Beam? My pipeline is pulling gzip files from gcs with this line of code: </p> <pre><code>beam.io.Read(beam.io.TextFileSource('gs://bucket/file.gz', compression_type='GZIP')) </code></pre> <p>But I am getting this error: </p> <pre><code>Un...
4
2016-08-22T17:57:30Z
39,086,383
<p>Today <code>TextIO</code> in the Python SDK does not actually support reading from compressed files.</p>
1
2016-08-22T18:30:11Z
[ "python", "google-cloud-dataflow", "dataflow", "apache-beam" ]
Camera calibration opencv python
39,085,875
<p>I am following the OpenCV tutorial <a href="http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html" rel="nofollow">http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html</a></p> <p>Instead of runnin...
0
2016-08-22T17:57:46Z
39,086,019
<p>You need to use the flag <code>CV_CALIB_USE_INTRINSIC_GUESS</code> </p>
1
2016-08-22T18:06:20Z
[ "python", "opencv", "image-processing", "computer-vision", "camera-calibration" ]
Noob Python Code Wont Work
39,085,906
<p>I get get this to work, and it seems simple but it wont.</p> <pre><code>bob = raw_input("What do you need?") if bob is "Hello": sayhello() def sayhello(): print"yo" </code></pre>
-6
2016-08-22T18:00:06Z
39,085,953
<p>Use the value comparison operator instead <code>==</code>, <code>is</code> checks for references (<a href="http://stackoverflow.com/a/38835030/6320655">short answer I wrote on</a> <code>is</code>, and its <a href="https://docs.python.org/2/reference/expressions.html#not-in" rel="nofollow">official doc</a>).</p> <pr...
3
2016-08-22T18:02:24Z
[ "python" ]
Noob Python Code Wont Work
39,085,906
<p>I get get this to work, and it seems simple but it wont.</p> <pre><code>bob = raw_input("What do you need?") if bob is "Hello": sayhello() def sayhello(): print"yo" </code></pre>
-6
2016-08-22T18:00:06Z
39,086,028
<p>mrdomoboto has the solution for you. But a little background information is never bad.</p> <p><code>is</code> returns True if to variables point to the same object.</p> <pre><code>&gt;&gt;&gt; a = [2, 3] &gt;&gt;&gt; b = a &gt;&gt;&gt; b is a True &gt;&gt;&gt; b == a True &gt;&gt;&gt; b = a[:] &gt;&gt;&gt; b is a...
1
2016-08-22T18:06:48Z
[ "python" ]
Troubles understanding finding elements in python selenium
39,085,910
<p>I'm trying to follow use find elements from <a href="http://selenium-python.readthedocs.io/locating-elements.html#locating-elements-by-class-name" rel="nofollow">http://selenium-python.readthedocs.io/locating-elements.html#locating-elements-by-class-name</a>; however, they seem to work only half the time and usually...
0
2016-08-22T18:00:15Z
39,086,824
<p>You should try using <a href="http://selenium-python.readthedocs.io/waits.html#explicit-waits" rel="nofollow"><code>WebDriverWait</code></a> to wait until element present as below :-</p> <pre><code>from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import W...
0
2016-08-22T18:55:55Z
[ "python", "selenium", "xpath", "find", "element" ]
Batch with Google Bigquery and Python
39,085,925
<p>What's the most efficient way to perform a batch insert in python using Google Bigquery Api. I was tryng to perform a stream row using this <a href="https://cloud.google.com/bigquery/streaming-data-into-bigquery" rel="nofollow">code</a> on a large dataset (1 000 000 +) but it's taking a while to insert them. Is ther...
1
2016-08-22T18:01:09Z
39,086,227
<p>I don't think Streaming (Insert All API) makes sense in your case<br> You rather should try <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load" rel="nofollow">Load Job</a><br> See python code example in <a href="https://cloud.google.com/bigquery/docs/loading-data-cloud-storage#loadi...
1
2016-08-22T18:20:09Z
[ "python", "google-bigquery", "gcloud" ]
Sorting an 3-dimensional array by a single row/column in Python
39,085,948
<p>m,n) shaped numpy array. I would like to sort the whole array by the values in the index [1,2,:] say. Is there an easy way to do this? I tried to use pandas Panel but for whatever reason there is no sort by values function for it.</p> <p>That 'duplicate' someone linked only seems to work for a column in an 2d array...
-2
2016-08-22T18:02:13Z
39,099,113
<p>So how I did it was using argsort as hpaulj said, given a array arr that was (m,n,l) dimension and a column indexed by (i,j,:).</p> <pre><code>sorted = np.empty(arr.shape): for k in range(arr.shape[2]): sorted[:,:,i] = arr[:,:,np.argsort(arr[i,j,:])[i]] </code></pre>
0
2016-08-23T10:50:03Z
[ "python", "pandas", "numpy" ]
python unittest - assert any raise
39,085,998
<p>I have some codes structured in this way:</p> <pre><code>Method(args): try: {method} if "ok": return True else: return False except: raise </code></pre> <p>And I have at least 3 unit tests to perform on this method, one to assert an ideal True condition, at least ...
1
2016-08-22T18:05:03Z
39,086,198
<p>Since you are essentially catching every exception type, your <code>assertRaises</code> should expect the most basic exception type, which is <code>Exception</code>. </p> <pre><code>assertRaises(Exception, Method) </code></pre>
1
2016-08-22T18:18:13Z
[ "python", "unit-testing" ]
Reading every second and fourth line of an input file and perform text processing using python
39,086,000
<p>Normally I would get my second and fourth line using <code>itertools</code></p> <pre><code>secondline = itertools.islice(input_open, 1, None, 4) fourthline = itertools.islice(input_open, 3, None, 4) </code></pre> <p>and perform <code>for line in secondline</code> or <code>for line in fourthline</code> to process e...
3
2016-08-22T18:05:06Z
39,086,212
<p>One way to obtain pairs of "second" line, "fourth" line is to just take an <code>islice</code> with step <code>2</code> and then <code>zip</code>it with itself:</p> <pre><code>lines = islice(input_file, 1, None, 2) for second, fourth in zip(lines, lines): </code></pre> <p>This works because <code>zip</code> first...
1
2016-08-22T18:19:09Z
[ "python", "itertools", "text-processing" ]
Reading every second and fourth line of an input file and perform text processing using python
39,086,000
<p>Normally I would get my second and fourth line using <code>itertools</code></p> <pre><code>secondline = itertools.islice(input_open, 1, None, 4) fourthline = itertools.islice(input_open, 3, None, 4) </code></pre> <p>and perform <code>for line in secondline</code> or <code>for line in fourthline</code> to process e...
3
2016-08-22T18:05:06Z
39,087,235
<p>why not:</p> <pre><code>def 2_and_4(fh): first = fh.readline() second = fh.readline() third = fh.readline() fourth = fh.readline() yield second, fourth </code></pre> <p>Make it a generator</p>
0
2016-08-22T19:22:56Z
[ "python", "itertools", "text-processing" ]
Django - Sort Queryset by Date instead of Datetime
39,086,005
<p>I have a model (representing a 'job') that contains a <strong>DateTimeField</strong> called <strong>date_created</strong>. I have another called <strong>date_modified</strong>.</p> <p>I would like to sort by <strong>-date_modified</strong> so that the most recently modified 'jobs' are at the top of my list. The pr...
0
2016-08-22T18:05:25Z
39,088,118
<p>I would get the queryset then sort it in the view in this case.</p> <pre><code>sorted(DataCollection.objects.all(), key = lambda x: x.date_modified.date(), reverse = True) </code></pre> <p>To sort by two keys you can use <a href="https://wiki.python.org/moin/HowTo/Sorting" rel="nofollow">attrgetter</a>, described ...
2
2016-08-22T20:24:01Z
[ "python", "django", "sorting" ]
Django - Sort Queryset by Date instead of Datetime
39,086,005
<p>I have a model (representing a 'job') that contains a <strong>DateTimeField</strong> called <strong>date_created</strong>. I have another called <strong>date_modified</strong>.</p> <p>I would like to sort by <strong>-date_modified</strong> so that the most recently modified 'jobs' are at the top of my list. The pr...
0
2016-08-22T18:05:25Z
39,088,707
<p>If your database supports datetime_to_date converting, you can try something like this:</p> <pre><code>DataCollection.objects.all().annotate(date_created__date=RawSQL('DATE(date_created)', ())).order_by('-date_created__date') </code></pre>
0
2016-08-22T21:03:26Z
[ "python", "django", "sorting" ]
Django - Sort Queryset by Date instead of Datetime
39,086,005
<p>I have a model (representing a 'job') that contains a <strong>DateTimeField</strong> called <strong>date_created</strong>. I have another called <strong>date_modified</strong>.</p> <p>I would like to sort by <strong>-date_modified</strong> so that the most recently modified 'jobs' are at the top of my list. The pr...
0
2016-08-22T18:05:25Z
39,089,375
<p>I think souldeux answer is probably a lot neater than this but another solution could be to query separately then join them together. I think something along these lines</p> <pre><code>from itertools import chain import datetime # get just todays data ordered by date modified today_min = datetime.datetime.combine(...
0
2016-08-22T21:59:54Z
[ "python", "django", "sorting" ]
How Do I Include ForeignKey in django-rest-framework POST
39,086,026
<p>So I have tried to make a browsable API via <code>django-rest-framework (DRF)</code>, but I have had some issues nesting serializers. So far, I am able to include the <code>Sport</code> and <code>Category</code> fields/foreignkeys into my <code>Article</code>, but when I try to <code>POST</code> via the API, I get a...
0
2016-08-22T18:06:37Z
39,086,228
<p>You need to override the serializer's <code>create</code> method to accommodate your <code>POST</code> request. This probably isn't what you're looking for, but you haven't included your sample request so we haven't got much to go off of. </p> <p>This would've been a comment had I been of high enough reputation. </...
1
2016-08-22T18:20:10Z
[ "python", "django", "api", "post", "django-rest-framework" ]
How Do I Include ForeignKey in django-rest-framework POST
39,086,026
<p>So I have tried to make a browsable API via <code>django-rest-framework (DRF)</code>, but I have had some issues nesting serializers. So far, I am able to include the <code>Sport</code> and <code>Category</code> fields/foreignkeys into my <code>Article</code>, but when I try to <code>POST</code> via the API, I get a...
0
2016-08-22T18:06:37Z
39,087,994
<p>So I was able to answer this question by using some of <code>Carter_Smith</code>'s advice - I am not 100% sure why this worked, but I added this <code>create()</code> method to my <code>ArticleSerializer</code>, and it worked:</p> <pre><code>def create(self, validated_data): # Override default `.create()` metho...
0
2016-08-22T20:16:06Z
[ "python", "django", "api", "post", "django-rest-framework" ]
Animate plot for a condition with matplotlib
39,086,029
<p>im making an animation with matplotlib and python, the animation looks like: <a href="http://i.stack.imgur.com/usuGh.gif" rel="nofollow"><img src="http://i.stack.imgur.com/usuGh.gif" alt="Animation"></a></p> <p>what i want to do is to extend this plot with more animations, i want to complete the next figure:...
0
2016-08-22T18:06:54Z
39,108,031
<p>The main changes are inserted between your original <code>animation.FuncAnimation</code> and before to <code>plt.show()</code>:</p> <pre><code>import matplotlib.pyplot as plt import matplotlib.animation as animation import numpy as np circ = np.linspace(0,360,360) circ *= 2*np.pi/360 ra = np.empty(360) wheel_posit...
1
2016-08-23T18:09:40Z
[ "python", "animation", "matplotlib" ]
Error when Importing Beautifulsoup
39,086,062
<p>I am writing some syntax to parse website and get all the href there. However, when I try to import bs4, it pops out an error saying "ImportError: cannot import name 'HTMLParseError'. I am using Python 3.5.2.</p> <p>I take the past reference and know that it may be due to the old version of bs4 and hence has upgrad...
0
2016-08-22T18:09:14Z
39,086,497
<p>If you want to install lxml manually, you can download lxml .whl file copiled from page <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a>. Next open cmd, cd to dict where you saved this file, and use command:</p> <blockquote> <p>pip install [name_of...
0
2016-08-22T18:37:03Z
[ "python", "beautifulsoup" ]
Error when Importing Beautifulsoup
39,086,062
<p>I am writing some syntax to parse website and get all the href there. However, when I try to import bs4, it pops out an error saying "ImportError: cannot import name 'HTMLParseError'. I am using Python 3.5.2.</p> <p>I take the past reference and know that it may be due to the old version of bs4 and hence has upgrad...
0
2016-08-22T18:09:14Z
39,086,723
<p>As an alternative measure, install Anaconda python, which includes BS 4.4.1 and lxml 3.6 (<a href="https://docs.continuum.io/anaconda/pkg-docs" rel="nofollow">https://docs.continuum.io/anaconda/pkg-docs</a>) already. And in general, Anaconda makes package management easy like a breeze.</p>
0
2016-08-22T18:49:34Z
[ "python", "beautifulsoup" ]
What is the difference between these two lists?
39,086,175
<p>I have a list of dictionaries, and in these dictionaries, there sometimes occurs a particular key. This particular key may have a dictionary as its value, and in that dictionary is a key-value pair of interest. Alternatively, the particular key may contain a list of dictionaries with contain the key-value pair of in...
0
2016-08-22T18:16:08Z
39,086,245
<blockquote> <p>type' object has no attribute '<strong>getitem</strong>'</p> </blockquote> <p>As the error suggest, In the first one, the part <code>list[&lt;object&gt;]</code> is the problem here. </p> <p>You are trying to index by an object, not an integer and hence the error. </p> <p>Just cut down the <code>lis...
1
2016-08-22T18:21:48Z
[ "python", "list", "dictionary", "nested" ]
What is the difference between these two lists?
39,086,175
<p>I have a list of dictionaries, and in these dictionaries, there sometimes occurs a particular key. This particular key may have a dictionary as its value, and in that dictionary is a key-value pair of interest. Alternatively, the particular key may contain a list of dictionaries with contain the key-value pair of in...
0
2016-08-22T18:16:08Z
39,086,246
<p>You don't need <code>list[]</code> to construct a list. It doesn't construct a list. It tries to extract an element from the concept of a list. I think what you meant was <code>list()</code> but that's just more verbose and less clear.</p> <p><code>[]</code> gets an item from an object. <code>list[]</code> tries to...
2
2016-08-22T18:21:49Z
[ "python", "list", "dictionary", "nested" ]
What is the difference between these two lists?
39,086,175
<p>I have a list of dictionaries, and in these dictionaries, there sometimes occurs a particular key. This particular key may have a dictionary as its value, and in that dictionary is a key-value pair of interest. Alternatively, the particular key may contain a list of dictionaries with contain the key-value pair of in...
0
2016-08-22T18:16:08Z
39,086,257
<p>bad_list uses the list func, but attempts to subscript it:</p> <pre><code>bad_list = list['h'] Traceback (most recent call last): File "&lt;stdin&gt;", line 1, \ in &lt;module&gt; TypeError: 'type' object is not subscriptable </code></pre>
0
2016-08-22T18:22:48Z
[ "python", "list", "dictionary", "nested" ]
Disabling odoo 9 progress bar
39,086,182
<p>How do i disable this progress bar on the top menu in Odoo 9.It apparently brings a wizard that shows you how to configure and use inventory.Thank you.</p> <p><a href="http://i.stack.imgur.com/6anCc.png" rel="nofollow">progress-bar</a></p>
0
2016-08-22T18:16:28Z
39,089,759
<p>Login as administrator (or any user who has access to the Settings) Activate debug mode</p> <p>Go to Settings -> Technical -> User Interface -> Planners </p> <p>Find the inventory planner, click on deactivate. </p> <p>Then refresh the page.</p> <p>Navigate back to the Inventory menu and the <code>progressbar</co...
0
2016-08-22T22:38:32Z
[ "python", "openerp", "odoo-9" ]