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 |
|---|---|---|---|---|---|---|---|---|---|
Why z3c.RML ignores the pageSize Attribute of <template> | 40,085,840 | <p>I am trying to get an A4-Landscape output file. The Document i am modifying is A4-Portrait, so i thought simple switch: <strong><em>pageSize="(21cm, 29.7cm)"</em></strong> to <strong><em>pageSize="(29.7cm, 21cm)"</em></strong>, but nothing happend.</p>
<p>I then fount an Attribute: <strong><em>rotation="90"</em></s... | 0 | 2016-10-17T11:59:52Z | 40,088,238 | <p><a href="https://github.com/zopefoundation/z3c.rml/blob/master/RML-DIFFERENCES.rst" rel="nofollow">https://github.com/zopefoundation/z3c.rml/blob/master/RML-DIFFERENCES.rst</a></p>
<p><strong>RML2PDF and z3c.rml Implementation Differences</strong></p>
<p>This document outlines the differences between ReportLab Inc... | 0 | 2016-10-17T13:51:38Z | [
"python",
"reportlab",
"rml"
] |
Python: How to 'refresh' random variables | 40,085,844 | <p>I have this code, i want to know if there is anyway i can get rid of all these variables and instead only have one for each purpose. My code is a password generator with three different password strengths. Code will work without this but for design sake i want to make it smaller. I've tried making them functions but... | 0 | 2016-10-17T12:00:10Z | 40,086,830 | <p>why don't you put the randoms into a function?</p>
<p>f.e.</p>
<pre><code># -*- coding: cp1252 -*-
import string
import random
import time
random_type = ("lower","upper","digit","strange","wordlist1","wordlist2")
list_s = ["!","£","~","%","*","(","}","#",";","@","/",":","-"]
list_w = ["mouse","human","dog","tre... | 0 | 2016-10-17T12:49:19Z | [
"python",
"list",
"variables",
"random"
] |
Matplotlib axis not displayed | 40,085,850 | <p>The python code (python 2.7) running on windows 7 shown below results in the following inconsistent behaviour with respect to the display of axis which I do not understand:</p>
<p>1 - a window is opened and a plot without an axis is displayed showing a point
2 - on closing the window, another window is opened and a... | 0 | 2016-10-17T12:00:23Z | 40,086,527 | <p>try </p>
<pre><code>vp = VectorPlotter(interactive=False, ticks=True)
</code></pre>
| 1 | 2016-10-17T12:34:45Z | [
"python",
"matplotlib"
] |
Localization in 2D world | 40,085,860 | <p>I am struggling with the following code for the localization of robot on 2D world of red and green grid cells. I am basically getting the error which states that list index out of range.</p>
<p><a href="https://i.stack.imgur.com/vZfh9.png" rel="nofollow"><img src="https://i.stack.imgur.com/vZfh9.png" alt="enter ima... | 1 | 2016-10-17T12:01:10Z | 40,086,332 | <p>In routine sense() your program tries to access the 5th element of list <strong>w</strong> (index 4 in the list), unfortunately <strong>w</strong> only has 4 elements (only indices 0, 1, 2, 3 are valid)</p>
<p><strong>range(len(p))</strong> returns [0, 1, 2, 3, 4]</p>
<p>Also <strong>w[i]==z</strong> will never be... | 0 | 2016-10-17T12:24:41Z | [
"python",
"grid",
"cells"
] |
recover values from ipyparallel map if a single evaluation failed | 40,085,888 | <p>I run a quite time consuming (>3 days) simulation using ipyparallel's map function like that in Jupyter Notebook</p>
<pre><code>from ipyparallel import Client
rc = Client()
lview = rc.load_balanced_view()
ar = lview.map(runsimulation, parameter)
</code></pre>
<p>and I really need those results. But unfortunately a... | 1 | 2016-10-17T12:02:19Z | 40,106,864 | <p>You can get partial results for individual msg_ids. With map, each message corresponds to a chunk of the map (a list):</p>
<pre><code>import ipyparallel as ipp
results = []
for msg_id in ar.msg_ids:
chunk_ar = rc.get_result(msg_id)
try:
chunk = chunk_ar.get()
except ipp.RemoteError as e:
... | 1 | 2016-10-18T11:21:06Z | [
"python",
"jupyter",
"ipython-parallel"
] |
How to set a specific download location in Mozilla - Marionette web driver? | 40,086,011 | <p>I am having an automation script which worked well before the recent mozilla update. The selenium-python script automates some of my browser actions, and save certain reports (csv) to a defined location.</p>
<p>I have been using selenium 2.53.6, which uses the following code :</p>
<pre><code>profile = webdriver.fi... | 1 | 2016-10-17T12:08:17Z | 40,088,192 | <p>You can pass <code>profile</code> as well to launch <a href="http://selenium-python.readthedocs.io/api.html#selenium.webdriver.firefox.webdriver.WebDriver" rel="nofollow"><code>FirefoxDriver</code></a> as :-</p>
<pre><code>driver = webdriver.Firefox(capabilities=caps, firefox_profile=profile)
</code></pre>
<p>You ... | 1 | 2016-10-17T13:49:56Z | [
"python",
"selenium",
"firefox",
"firefox-marionette"
] |
Error: [Errno 71] Protocol error: pyvenv | 40,086,091 | <p>I am using Centos7 with vagrant and virtualbox on windows10.
I am trying to create pyvenv virtual environment to develop python web apps with django. I have installed python 3.4. </p>
<p>However, when I type
<code>pyvenv-3.4 name_of_environment</code>,
it gives back an error <code>Error: [Errno 71] Protocol error:... | -1 | 2016-10-17T12:13:05Z | 40,120,623 | <p><code>pyvenv-3.4 --without-pip name_of_environment</code>
worked</p>
<p>looks like pip was not installed.</p>
<p>thanks for the help.</p>
| 0 | 2016-10-19T01:30:50Z | [
"python",
"django",
"python-3.x",
"vagrant",
"centos7"
] |
Interpreter can find a 3rd party module but WIN-R and command line can't | 40,086,193 | <p>I have installed a 3rd party module named <code>pyperclip</code> to my <code>\python31\Lib\site-packages</code> folder using <code>pip install --target</code> as I also have python 2.7 on the computer and it appears modules are put in 2.7 as a default.</p>
<p>I can run the script below through IDLE just fine. </p>
... | 0 | 2016-10-17T12:17:16Z | 40,086,249 | <p>You need to install packages using <code>pip3</code> if you want it to install in your Python3 environment. IE</p>
<pre><code>pip3 install pyperclip
</code></pre>
<blockquote>
<p>I have installed a 3rd party module named pyperclip to my \python31\Lib\site-packages folder using <code>pip install --target</code></... | 1 | 2016-10-17T12:20:31Z | [
"python",
"module"
] |
Errors with pytest | 40,086,292 | <p>I am using @pytest.mark.parametrize with various testcases and expected outputs. Its passing perfectly fine with few test cases and giving this error with some other cases. Not even able to google it. I want to know what could have gone wrong. I would be glad if someone can tell me how to atleast google for this err... | 0 | 2016-10-17T12:22:35Z | 40,094,988 | <p>The example you pasted can be minimized a bit into this file:</p>
<pre><code>import pytest
@pytest.mark.parametrize("foo", ['\n\xcjfeiafa1'])
def test_escapes(foo):
pass
</code></pre>
<p>Which gives us the same error with Python 2, and a clearer error with Python 3:</p>
<pre><code>/usr/lib/python3.5/site-pac... | 1 | 2016-10-17T20:20:23Z | [
"python",
"py.test"
] |
datetime format does not match with content | 40,086,365 | <p>I have checked quite a lot of questions related to this topic but I'm not able to find my error. </p>
<p>My code can be simplified to:</p>
<pre><code>date = "2016/07/20"
time = "11:44:20.920"
date_time = datetime.strptime(date + " " + time, '%y/%m/%d %H:%M:%S.%f')
</code></pre>
<p>The error I get is the followin... | 2 | 2016-10-17T12:26:13Z | 40,086,403 | <p>The year directive should be in caps:</p>
<pre><code>date_time = datetime.strptime(date + " " + time, '%Y/%m/%d %H:%M:%S.%f')
# ^
</code></pre>
<blockquote>
<p><code>%y</code> Year without century as a zero-padded decimal number </p>
<p><code>%Y</code> Year... | 6 | 2016-10-17T12:28:34Z | [
"python",
"datetime"
] |
datetime format does not match with content | 40,086,365 | <p>I have checked quite a lot of questions related to this topic but I'm not able to find my error. </p>
<p>My code can be simplified to:</p>
<pre><code>date = "2016/07/20"
time = "11:44:20.920"
date_time = datetime.strptime(date + " " + time, '%y/%m/%d %H:%M:%S.%f')
</code></pre>
<p>The error I get is the followin... | 2 | 2016-10-17T12:26:13Z | 40,086,417 | <p><code>%y</code> is the specifier for "Year without century as a zero-padded decimal number.", which means a two-digit number. Use <code>%Y</code> instead.</p>
| 2 | 2016-10-17T12:29:20Z | [
"python",
"datetime"
] |
datetime format does not match with content | 40,086,365 | <p>I have checked quite a lot of questions related to this topic but I'm not able to find my error. </p>
<p>My code can be simplified to:</p>
<pre><code>date = "2016/07/20"
time = "11:44:20.920"
date_time = datetime.strptime(date + " " + time, '%y/%m/%d %H:%M:%S.%f')
</code></pre>
<p>The error I get is the followin... | 2 | 2016-10-17T12:26:13Z | 40,086,534 | <p>If you are not very familiar with the <a href="https://docs.python.org/2/library/time.html#time.strftime" rel="nofollow">datetime directives</a>, I will suggest you to use <a href="http://dateutil.readthedocs.io/en/stable/parser.html" rel="nofollow"><code>dateutil.parser</code></a> instead. It is much simpler. For e... | 1 | 2016-10-17T12:35:03Z | [
"python",
"datetime"
] |
Pandas to_sql() not working with Posgresql - value too long for type character varying | 40,086,386 | <p>I'm using Pandas with SQLAlchemy to apply some ETL on one CSV file</p>
<p>After validating the fields and transforming some of them I try to export to my PostgreSQL database, but I'm getting one error which does not make sense:</p>
<pre><code>sqlalchemy.exc.DataError: (psycopg2.DataError) value too long for type c... | 3 | 2016-10-17T12:27:48Z | 40,092,512 | <p>Ok, it's pretty embarrassing what happened. The code above was right since the beginning. The problem is that I'm merging some rows and concatenating in that column the merged values in a different function and I forgot. I thought the error was only in my validation function when it was never there.</p>
<p>What did... | 0 | 2016-10-17T17:40:18Z | [
"python",
"django",
"postgresql",
"pandas",
"django-models"
] |
python importing all images from a local directory | 40,086,387 | <pre><code>import cv2
import os
for filename in os.listdir('C:/Users/Akhil/Downloads/New'):
image = cv2.imread(filename)
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imwrite('gray_image.png',gray_image)
cv2.imshow('color_image',image)
cv2.imshow('gray_image',gray_image)
... | 0 | 2016-10-17T12:27:49Z | 40,086,844 | <p>This is often a symptom of failing to find the image. </p>
<p>Note that the <code>filename</code>s returned by <code>os.listdir()</code> are relative to the directory passed to listdir(). So OpenCV is searching for a file named "image_01.jpg" for example, in your current working directory, and can't find anything. ... | 1 | 2016-10-17T12:49:52Z | [
"python",
"opencv",
"python-import"
] |
Tryng to run 2 Python applications with different Python versions with mod_wsgi | 40,086,415 | <p>I have in my Apache 2 applications: Django app and MoinMoin app. The first one is running now with Python3.4 and the second one (MoinMoin) with Python2.7</p>
<p>When running dpkg:</p>
<pre><code>ruben@babylon:/var/log/apache2$ dpkg -l | grep wsgi
rc libapache2-mod-wsgi 3.4-4ubuntu2.1.14.04.2 ... | 1 | 2016-10-17T12:29:16Z | 40,094,813 | <p>As you were told already in:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/40043543/virtual-environment-not-recognized-in-wsgipythonpath">Virtual environment not recognized in WSGIPythonPath</a></li>
</ul>
<p>you cannot do that within a single Apache instance.</p>
<p>The simple answer as was described ... | 1 | 2016-10-17T20:08:09Z | [
"python",
"django",
"apache",
"mod-wsgi",
"moinmoin"
] |
python calculations are being weird | 40,086,419 | <p>Am having some problems with my code. I need to limit an input by multiples of 5 under a changing maximum.</p>
<p>With what I have now it should work but it isn't. What have i missed?</p>
<pre><code>while True:
print("Place your bet. Must be a multiple of 5")
posBets = range(5, (balance + 1), 5)
... | -1 | 2016-10-17T12:29:25Z | 40,086,984 | <p>Your <code>bet = str(input())</code> converts the number into a string, which is why it can never equal the range. </p>
<p>Even if it was an int, a number cannot equal a range.</p>
<p>What you want is </p>
<pre><code> bet = int(input())
if bet in posBets:
</code></pre>
<p>the rest of the code seems full o... | 1 | 2016-10-17T12:55:48Z | [
"python",
"python-3.x"
] |
How to save/copy value of table column not listed in csv column list in vertica copy command | 40,086,452 | <p>I am using following code to copy data from csv to vertica table.</p>
<pre><code>copy_command = 'COPY cb.table_format2 (ACC_NO, REF_NO, CUSTOMER_NAME, ADDRESS) FROM STDIN '\
'ENCLOSED BY \'"\' delimiter \',\' SKIP 1 '\
'exceptions \'' + file_path_exception + '\' rejected data \'' + file_path_rejected + '\';... | 1 | 2016-10-17T12:30:56Z | 40,086,880 | <p>You need to use <code>AS</code> to sql expressions to fields. You don't mention which python module you are using, but you can do it as a literal. Add in a new field entry that looks like: </p>
<pre><code>FILEID AS 123456
</code></pre>
<p>And just get your string to look that way (probably using a formatter, or a ... | 1 | 2016-10-17T12:51:37Z | [
"python",
"vertica"
] |
Using external class methods inside the imported module | 40,086,500 | <p>My python application consists of various <em>separate</em> processing algorithms/modules combined within a single (Py)Qt GUI for ease of access. </p>
<p>Every processing algorithm sits within its own module and all the communication with GUI elements is implemented within a single class in the main module.
In par... | 2 | 2016-10-17T12:33:18Z | 40,086,840 | <p>No. I think this approach somewhat breaks software engineering principles (e.g. <a href="https://en.wikipedia.org/wiki/Single_responsibility_principle" rel="nofollow">single responsibility</a>). In single responsibility principle, each module is only in charge of its assigned task and nothing else. If we consider UI... | 4 | 2016-10-17T12:49:47Z | [
"python",
"qt",
"class",
"module",
"pyqt"
] |
Retrieve Exchange Calendar event with Python & Suds | 40,086,507 | <p>I'm trying to retrieve Exchange calendar events in Python using the suds library.</p>
<p>I'm able to read FreeBusyResponse data, but I'm not successfull in retrieving the actual calendar event.</p>
<p>The soap requests seems fine:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
x... | 0 | 2016-10-17T12:33:43Z | 40,094,046 | <p>I've found the following solution:</p>
<pre><code>import time
import datetime
import pytz
from suds.client import WebFault
from suds.client import Client
from suds.sax.element import Element
from suds.transport.http import HttpTransport
from suds.sudsobject import asdict
< auth and transport comes here >
# ... | 0 | 2016-10-17T19:18:57Z | [
"python",
"ews",
"exchangewebservices",
"suds"
] |
Convert python list of string to bytearray | 40,086,641 | <p>I would write a list on serial COM through pySerial.</p>
<p>I create a list of string, where each string is a parameter, and then I pass the list to serial write function. There is an error because I cannot write list of string directly on serial</p>
<p>This is my code:</p>
<pre><code>import datetime
import time
... | 0 | 2016-10-17T12:41:03Z | 40,086,942 | <p>If you want an actual bytearray object, pass the list into the bytearray constructor. </p>
<pre><code>serialCOM.write(bytearray(packet))
</code></pre>
<p>Note that <code>unixTime</code> is not converted to a string so you must convert that first.</p>
<p>But what you probably want (based on the comment about semic... | 1 | 2016-10-17T12:54:05Z | [
"python",
"python-2.7",
"type-conversion",
"concatenation",
"pyserial"
] |
How to deal with 0 in modulo in python | 40,086,642 | <p>I want to create code that tells me what date it is based on how many hours passed.</p>
<p>I don't want to import any libraries I just want to calculate this myself. I want code to be flexible and work with whatever snodiy (simple number of days in year), nohiod (number of hours in one day) and number of months I'l... | -1 | 2016-10-17T12:41:04Z | 40,087,367 | <p><em>I'm going to assume we're not bound by all the constraints of real-world time issues like leap years, leap seconds, DST, etc. If we are, you're taking on an extremely non-trivial task, and as others have mentioned you're probably best off leaving it to libraries. Moving on...</em></p>
<p>The essence of the prob... | 1 | 2016-10-17T13:13:24Z | [
"python",
"modulo"
] |
Integrating Python with PingFederate | 40,086,684 | <p>Our application is written in python. I would like to integrate this with PingFederate. Is there any python library I can use for this purpose ?</p>
| -1 | 2016-10-17T12:42:37Z | 40,112,721 | <p>While there's no Python library commercially available from Ping Identity, there are a few options including using the PingFederate Agentless Integration Kit (<a href="https://documentation.pingidentity.com/display/AIK11/Introduction" rel="nofollow">https://documentation.pingidentity.com/display/AIK11/Introduction</... | 1 | 2016-10-18T15:48:52Z | [
"python",
"ping",
"pingfederate"
] |
Importing identically named methods | 40,086,787 | <p>So I have two separate Python packages that I'm importing into my Python script for Raspberry Pi. In this case as;</p>
<pre><code>from rflib import*
from Rpi.GPIO import*
</code></pre>
<p>However, both packages have their own seperate method <code>cleanup(self)</code></p>
<p>So, at the end of the script when I us... | 1 | 2016-10-17T12:47:15Z | 40,086,866 | <p>It is not a good practice to use <code>*</code> with <code>import</code>. You should be doing something like:</p>
<pre><code>import rflib
from Rpi import GPIO
# Clean Up 1
rflib.cleanup
#Clean Up 2
GPIO.cleanup()
</code></pre>
<hr>
<p><em>Additional pice of information:</em> </p>
<p>In case your files/objects ... | 2 | 2016-10-17T12:51:01Z | [
"python",
"python-import"
] |
Importing identically named methods | 40,086,787 | <p>So I have two separate Python packages that I'm importing into my Python script for Raspberry Pi. In this case as;</p>
<pre><code>from rflib import*
from Rpi.GPIO import*
</code></pre>
<p>However, both packages have their own seperate method <code>cleanup(self)</code></p>
<p>So, at the end of the script when I us... | 1 | 2016-10-17T12:47:15Z | 40,086,901 | <p><code>from <module> import *</code> takes all names in a module (those that don't start with a <code>_</code> or everything listed in <code><module>.__all__</code> and assigns those names as globals in your current module.</p>
<p>If two modules define the same name, that means that the last one imported... | 5 | 2016-10-17T12:52:31Z | [
"python",
"python-import"
] |
How to check the language of any text present on Website using Selenium | 40,086,815 | <p>I am testing a website which contains user reviews for hotels which can be in any lang...i.e, Czech or russian or spanish or english etc... and have a question about how can i check in which language the text is by reading the text using Selenium. </p>
<p>for example i am using to element.text method of selenium to... | 0 | 2016-10-17T12:48:27Z | 40,088,603 | <p>Detect a language it is not trivial unless the html tag put the current lang.</p>
<p>If you are using selenium in python you can use this function, for that you need to install nltk and the corpus stopwords:</p>
<pre><code>from nltk import word_tokenize
from nltk.corpus import stopwords
def detect_lang(text):
... | 0 | 2016-10-17T14:07:10Z | [
"python",
"selenium-webdriver"
] |
How to check the language of any text present on Website using Selenium | 40,086,815 | <p>I am testing a website which contains user reviews for hotels which can be in any lang...i.e, Czech or russian or spanish or english etc... and have a question about how can i check in which language the text is by reading the text using Selenium. </p>
<p>for example i am using to element.text method of selenium to... | 0 | 2016-10-17T12:48:27Z | 40,089,095 | <p>Here Nothing to do with selenium driver just get the text and use the below code
If you need to detect language in response to a user action then you could use <a href="http://code.google.com/apis/language/translate/v1/using_rest_langdetect.html" rel="nofollow">google ajax language API</a>:</p>
<pre><code>#!/usr/bi... | 0 | 2016-10-17T14:30:34Z | [
"python",
"selenium-webdriver"
] |
Is there a way to pin an exe in taskbar using python | 40,087,054 | <p>I'm extracting an zip folder contains an EXE file using python. Once extracted, I want to pin the EXE file to the task bar. Is there a way to do that using python?</p>
| 0 | 2016-10-17T12:58:39Z | 40,106,444 | <p><a href="https://blogs.msdn.microsoft.com/oldnewthing/20141230-00/?p=43273/" rel="nofollow">Programs aren't supposed to do this in the first place; there is no supported way to do it even with an installer, so Python isn't going to be any more supported. If you forcibly pin your program, <em>your program is a bad ac... | 0 | 2016-10-18T11:00:47Z | [
"python",
"python-3.x"
] |
Getter and setter methods in a Peewee model | 40,087,094 | <p>I have the following simple model in Peewee:</p>
<pre><code>class SiteText(BaseModel):
url = TextField()
text = TextField()
my_counter = IntegerField()
def get_text_by_url(url):
d = [s.text for s in SiteText.select(SiteText.url == url)]
d = d[0] if len(d) > 0 else None
re... | 0 | 2016-10-17T13:00:16Z | 40,087,382 | <p>Actualy using proporties wouldn't clash with your actual attribute name, because they can be different than the getter/setter function.</p>
<pre><code>class Example:
def __init__(self):
self.value = 5
@property
def value(self):
print('Entering value getter')
return self._value
... | 1 | 2016-10-17T13:14:15Z | [
"python",
"peewee"
] |
"LookupError: Couldn't find path to unrar library" on Win10 | 40,087,192 | <p>I have installed unrar library by using <code>pip install unrar</code>, which installed <code>unrar-0.3</code>.
After compiling my code using <code>unrar</code> library in <code>pydev-eclipse</code> I am getting the following error message:</p>
<pre><code>File "C:\Python27\lib\site-packages\unrar\unrarlib.py", line... | 0 | 2016-10-17T13:04:31Z | 40,087,566 | <p>You should download the UnRAR.dll Library from <a href="http://www.rarlab.com/rar/UnRARDLL.exe" rel="nofollow">http://www.rarlab.com/rar/UnRARDLL.exe</a> and extract it anywhere in your PATH</p>
<p>Edit: You should set the UNRAR_LIB_PATH environment variable with the location of unrar.dll</p>
<p>Edit2: As a last r... | 0 | 2016-10-17T13:22:16Z | [
"python",
"eclipse",
"python-2.7",
"rar",
"unrar"
] |
String manipulation in Python: Quotation marks and apostrophes | 40,087,232 | <p>So I'm having this issue with python: I'm trying to create a string I can use for a gdal operation using os.system on python. My aim is using this operation for a variable number of inputfiles:</p>
<pre><code>os.system('gdal_calc.py -A {0} -B {1} -C {2} --outfile={4} --calc="(1-A)(1-B)(1-C)" '.format(File1, File2, ... | 1 | 2016-10-17T13:07:04Z | 40,087,887 | <p>Do it:</p>
<pre><code>String = ""
for i in range(len(Inputfiles)-1):
String +=" -" + ABC[i] + " '" + Inputfiles[i] + "'"
</code></pre>
<p>Instead of:</p>
<pre><code> for i in range(len(Inputfiles)-1):
partstring.append(" -" + ABC[i] + " '" + Inputfiles[i] + "'")
</code></pre>
<p>And pay attetion wi... | 0 | 2016-10-17T13:35:46Z | [
"python",
"string",
"operating-system"
] |
String manipulation in Python: Quotation marks and apostrophes | 40,087,232 | <p>So I'm having this issue with python: I'm trying to create a string I can use for a gdal operation using os.system on python. My aim is using this operation for a variable number of inputfiles:</p>
<pre><code>os.system('gdal_calc.py -A {0} -B {1} -C {2} --outfile={4} --calc="(1-A)(1-B)(1-C)" '.format(File1, File2, ... | 1 | 2016-10-17T13:07:04Z | 40,088,278 | <p>For this to work you will have to enclose double quote inside single quote and not other way around.</p>
<p>Though in most of the scenarios both of then should have identical impact but this is one of the corner scenario where it matters Its because of the ways string are represented internally in Python. </p>
<pr... | 0 | 2016-10-17T13:53:34Z | [
"python",
"string",
"operating-system"
] |
Importing error in python package skimage | 40,087,362 | <p>I want to use <strong>skimage.restoration.denoise_wavelet</strong> to denoise a image. But problem occurs on importing.</p>
<p><code>from skimage.restoration import denoise_nl_means,denoise_wavelet</code> </p>
<p><code>ImportError Traceback (most recent call last)
<ipython-input-2... | 0 | 2016-10-17T13:13:04Z | 40,087,546 | <p>As you installed this library with pip, it probably installed the latest stable release, which is something within the <strong>0.12</strong> branch.</p>
<p>There are different documentations for different versions of scikit-learn.
<strong>The function</strong> which you want to import <strong>does not exist yet in ... | 0 | 2016-10-17T13:21:36Z | [
"python",
"image-processing",
"filter",
"wavelet",
"skimage"
] |
Python JSON List to Get Data and Retrieve Column Name | 40,087,376 | <p>I am a newbie and can't find the answer so apologies in advance if this is a repeat question.</p>
<p>I'm accessing a historical metal prices api that returns a dictionary of lists. The first item in the list is the column names, and the rest is data that falls under those column headers.</p>
<p>I'm trying to writ... | 0 | 2016-10-17T13:13:49Z | 40,088,349 | <p>One way would be to get the position of 'Date' and 'Cache Buyer' columns, and then iterate through the <em>data</em> part of the JSON. </p>
<p>I will name the dictionary that you loaded from the JSON as dictionary in my example:</p>
<pre><code># Get the columns and the data part of the response dictionary
columns ... | 1 | 2016-10-17T13:56:55Z | [
"python",
"json",
"python-2.7",
"web-services",
"getjson"
] |
Python list integrateUpper/Lowercase check? | 40,087,556 | <p>I currently use following code to select rows from a dataframe:</p>
<pre><code>list = ['3d block','3D Block','3D block','3d Block','cafe','Cafe']
data[data['description'].str.contains('|'.join(list))]
</code></pre>
<p>As you can see, I currently implement different queries for upper/lowercase, as I realized that '... | 1 | 2016-10-17T13:21:57Z | 40,087,594 | <p>You can simply convert them all to lower using the <code>string.lower()</code> function</p>
<p>Make your list contain only lower case characters. But you can do a safe check for that too</p>
<pre><code>my_list=['3d block', 'cafe']
# As karthik suggested, just to be safe, convert your list to lowercase
for i in ra... | 2 | 2016-10-17T13:23:17Z | [
"python",
"list",
"uppercase",
"lowercase"
] |
Python list integrateUpper/Lowercase check? | 40,087,556 | <p>I currently use following code to select rows from a dataframe:</p>
<pre><code>list = ['3d block','3D Block','3D block','3d Block','cafe','Cafe']
data[data['description'].str.contains('|'.join(list))]
</code></pre>
<p>As you can see, I currently implement different queries for upper/lowercase, as I realized that '... | 1 | 2016-10-17T13:21:57Z | 40,087,719 | <p>You can do a <em>case InSeNsitIvE</em> selection by passing the <code>case</code> parameter as <code>False</code>:</p>
<pre><code>lst = ['3D Block', 'cafe']
data[data['description'].str.contains('|'.join(lst), case=False)]
</code></pre>
<p>And remember to not use <code>list</code> as a name as this will shadow th... | 2 | 2016-10-17T13:28:59Z | [
"python",
"list",
"uppercase",
"lowercase"
] |
Numpy array size is shrinking, changing randomly. Index out of bounds error | 40,087,573 | <p>I am making a large, 3-column 10,000 row array and filling it with random numbers. Then, I am indexing through the rows and deleting rows that don't match my criteria. For some reason, as I index through I get the following error:
<code>Traceback (most recent call last):
File "hw_2.py", line 16, in ... | 0 | 2016-10-17T13:22:32Z | 40,088,017 | <p>So you're trying to select certain parts of the array, it seems. There's typically no need to do <code>np.delete</code>, you can use boolean masks instead: </p>
<pre><code>In [34]: np.random.seed(1234)
In [35]: cube = np.random.uniform(-1, 1, size=10000*3).reshape(10000, 3)
In [36]: mask = (cube**2).sum(axis=1) &... | 0 | 2016-10-17T13:41:29Z | [
"python",
"arrays",
"numpy",
"indexing"
] |
Mute printing of an imported Python script | 40,087,681 | <p>I want to import a python script in to another script. </p>
<pre><code>$ cat py1.py
test=("hi", "hello")
print test[0]
$ cat py2.py
from py1 import test
print test
</code></pre>
<p>If I execute <code>py2.py</code>:</p>
<pre><code>$ python py2.py
hi
('hi', 'hello')
</code></pre>
<p>Can I anyway mute the first... | 2 | 2016-10-17T13:27:02Z | 40,087,743 | <p>Simply open the /dev/null device and overwrite the <code>sys.stdout</code> variable to that value when you need it to be quiet.</p>
<pre><code>import os
import sys
old_stdout = sys.stdout
sys.stdout = open(os.devnull, "w")
from py1 import test
sys.stdout = old_stdout
print test
</code></pre>
| 3 | 2016-10-17T13:29:54Z | [
"python"
] |
Mute printing of an imported Python script | 40,087,681 | <p>I want to import a python script in to another script. </p>
<pre><code>$ cat py1.py
test=("hi", "hello")
print test[0]
$ cat py2.py
from py1 import test
print test
</code></pre>
<p>If I execute <code>py2.py</code>:</p>
<pre><code>$ python py2.py
hi
('hi', 'hello')
</code></pre>
<p>Can I anyway mute the first... | 2 | 2016-10-17T13:27:02Z | 40,087,752 | <p>py1.py use an <code>if __name__=="__main__":</code></p>
<p>So like your py1.py would look like: </p>
<pre><code>def main():
test=("hi", "hello")
print test[0]
if __name__=="__main__":
main()
</code></pre>
<p>This will allow you to still use py1.py normally, but when you import it, it won't run the... | 5 | 2016-10-17T13:30:23Z | [
"python"
] |
Mute printing of an imported Python script | 40,087,681 | <p>I want to import a python script in to another script. </p>
<pre><code>$ cat py1.py
test=("hi", "hello")
print test[0]
$ cat py2.py
from py1 import test
print test
</code></pre>
<p>If I execute <code>py2.py</code>:</p>
<pre><code>$ python py2.py
hi
('hi', 'hello')
</code></pre>
<p>Can I anyway mute the first... | 2 | 2016-10-17T13:27:02Z | 40,087,778 | <p>You might want to consider changing the other script to still print when its run 'in the other place' - if you're running py1 as a shell command, try to make sure all "executable statements" in a file are inside a block.</p>
<pre><code>if __name__ == "__main__":
print test
</code></pre>
<p>(see <a href="http:/... | 0 | 2016-10-17T13:31:31Z | [
"python"
] |
Mute printing of an imported Python script | 40,087,681 | <p>I want to import a python script in to another script. </p>
<pre><code>$ cat py1.py
test=("hi", "hello")
print test[0]
$ cat py2.py
from py1 import test
print test
</code></pre>
<p>If I execute <code>py2.py</code>:</p>
<pre><code>$ python py2.py
hi
('hi', 'hello')
</code></pre>
<p>Can I anyway mute the first... | 2 | 2016-10-17T13:27:02Z | 40,087,816 | <p>You could implement this functionality with methods:</p>
<p><code>py1.py</code></p>
<pre><code>test=("hi", "hello")
def print_test():
print(test)
def print_first_index():
print(test[0])
</code></pre>
<p><code>py2.py</code></p>
<pre><code>import py1
py1.print_test()
</code></pre>
<p>As MooingRawr point... | 0 | 2016-10-17T13:33:13Z | [
"python"
] |
How to convert nested list to object | 40,087,800 | <p>When I receive JSON data like </p>
<pre><code>[
{
"id":1,
"name":"New Island",
"residents":[
{
"name":"Paul",
"age":"25"
}
]
},
{
"id":2,
"name":"One Nation",
"residents":[
... | 0 | 2016-10-17T13:32:40Z | 40,088,045 | <p>Override the serializer methods that control transformation from primitive to internal <a href="http://www.django-rest-framework.org/api-guide/serializers/#overriding-serialization-and-deserialization-behavior" rel="nofollow">http://www.django-rest-framework.org/api-guide/serializers/#overriding-serialization-and-de... | 0 | 2016-10-17T13:42:45Z | [
"python",
"django",
"django-rest-framework"
] |
How to convert nested list to object | 40,087,800 | <p>When I receive JSON data like </p>
<pre><code>[
{
"id":1,
"name":"New Island",
"residents":[
{
"name":"Paul",
"age":"25"
}
]
},
{
"id":2,
"name":"One Nation",
"residents":[
... | 0 | 2016-10-17T13:32:40Z | 40,088,119 | <p>From Python's <a href="https://docs.python.org/3.5/library/json.html" rel="nofollow">JSON library</a></p>
<pre><code>import json
data = '[{"id":1,"name":"New Island","residents":[{"name":"Paul","age":"25"}]},{"id":2,"name":"One Nation","residents":[{"name":"James","age":"23"},{"name":"Jessica","age":"26"}]}]'
x =... | 1 | 2016-10-17T13:46:35Z | [
"python",
"django",
"django-rest-framework"
] |
Docker container and virtual python environment | 40,087,910 | <p>I'm getting started working with Docker. I installed Docker Toolbox on Windows 10 and downloaded the desired container. I need full access to containerâs filesystem with the ability to add and edit files. Can I transfer the contents of the container into a Virtual Python Environment in Windows filesystem? How to d... | 1 | 2016-10-17T13:36:57Z | 40,097,954 | <p>Transferring files between Windows and Linux might be a little annoying because of <a href="https://blog.codinghorror.com/the-great-newline-schism/" rel="nofollow">different line endings</a>.</p>
<p>Putting that aside, sounds like you are looking to create a Docker based development environment. There are good tut... | 0 | 2016-10-18T01:09:14Z | [
"python",
"docker"
] |
Open cv face recognition python | 40,087,957 | <p>I started learning some object recognition and I'm interested in <code>openCV</code>. First of all, I tried the tutorial where your face is recognized. I installed numPy and <code>openCV</code>. When I tried running the program below, I received this error: </p>
<blockquote>
<p>File "path to my program\camera.py"... | 0 | 2016-10-17T13:38:51Z | 40,088,784 | <p>I just tried it out and I didn't get the error. If I intentionally mess up one or both of the files I get that error, but not the ones directly from the github project. These are the first ten lines of each file for me:</p>
<pre><code>$ head haarcascade_*.xml
==> haarcascade_eye.xml <==
<?xml version="1.0"... | 0 | 2016-10-17T14:15:43Z | [
"python",
"xml",
"opencv",
"face-recognition"
] |
Open cv face recognition python | 40,087,957 | <p>I started learning some object recognition and I'm interested in <code>openCV</code>. First of all, I tried the tutorial where your face is recognized. I installed numPy and <code>openCV</code>. When I tried running the program below, I received this error: </p>
<blockquote>
<p>File "path to my program\camera.py"... | 0 | 2016-10-17T13:38:51Z | 40,096,889 | <p>Problem solved by re-downloading xml-files. Simple as that, but it takes me a long time to figure.</p>
| 0 | 2016-10-17T22:52:16Z | [
"python",
"xml",
"opencv",
"face-recognition"
] |
Python read lines from a file and write from a specific line number to another file | 40,087,970 | <p>I want to read the lines from a file and write from a specific line number to another file. I have this script, which writes all the read lines. I need to skip the first four lines and write the rest to another fils. Any ideas?</p>
<pre><code>for k in range (0,16):
print 'k =',k
from abaqus import session
... | 0 | 2016-10-17T13:39:24Z | 40,088,047 | <p><a href="https://docs.python.org/3/library/itertools.html#itertools.islice" rel="nofollow"><code>itertools.islice</code> is designed for this</a>:</p>
<pre><code>import itertools
with open('VY_NM_VR_lin_o1_bonded_results_{k}.txt'.format(k=k)) as f1:
# islice w/4 & None skips first four lines of f1, then ge... | 4 | 2016-10-17T13:42:48Z | [
"python",
"file"
] |
BeautifulSoup errors | 40,088,055 | <p>I am getting errors when running it.</p>
<pre><code>import requests
from bs4 import BeautifulSoup
url = "http://sport.citifmonline.com/"
url_page_2 = "url" + "2016/10/15/chelsea-3-0-leicester-city-dominant-blues-comfortable-against-champions-photos/"
r = requests.get(url)
soup = BeautifulSoup(r.content, "html5lib... | -7 | 2016-10-17T13:43:05Z | 40,088,313 | <p>If you haven't installed <code>html5lib</code> (e.g. with <code>pip install html5lib</code>), you won't be able to use this parser without getting an error. You could either install it or go e.g. for <code>"html.parser"</code> instead which is also mentioned in the <a href="https://www.crummy.com/software/BeautifulS... | 0 | 2016-10-17T13:55:04Z | [
"python",
"beautifulsoup",
"html-parsing"
] |
Tensorflow MNIST (Weight and bias variables) | 40,088,132 | <p>I'm learning how to use Tensorflow with the MNIST tutorial, but I'm blocking on a point of the tutorial.</p>
<p>Here is the code provided : </p>
<pre><code>from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
x = tf.place... | 0 | 2016-10-17T13:47:16Z | 40,089,052 | <p>TensorFlow <a href="https://www.tensorflow.org/versions/r0.11/how_tos/variables/index.html" rel="nofollow">variables</a> maintain their state from one <code>run()</code> call to the next. In your program they will be initialized to zero, and then progressively updated in the training loop.</p>
<p>The code that chan... | 2 | 2016-10-17T14:28:04Z | [
"python",
"python-3.x",
"machine-learning",
"tensorflow"
] |
How to get current test case(s) status pass/failed in Robot Framework | 40,088,154 | <p>I have used ${TEST STATUS} (Automatic variable) for getting the status giving error.</p>
| -1 | 2016-10-17T13:48:18Z | 40,088,667 | <p>There is a global variable called <code>${TEST_STATUS}</code>. You can use it in <code>teardown</code> section.</p>
<p>See the corresponding part <code>Automatic Variables</code> in the documentation. </p>
<p><a href="http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#id514" rel="nofollow... | 0 | 2016-10-17T14:09:50Z | [
"python",
"python-2.7",
"robotframework"
] |
How to get current test case(s) status pass/failed in Robot Framework | 40,088,154 | <p>I have used ${TEST STATUS} (Automatic variable) for getting the status giving error.</p>
| -1 | 2016-10-17T13:48:18Z | 40,124,861 | <p>you can use that variable only in <strong>teardown</strong> section. like below example. robot is maintaining two levels "test levels" and "suit levels". inside test level there is another two things called "setup" and "teardown". <strong>setup</strong> means before executing every testcase it will run. and <strong>... | 1 | 2016-10-19T07:28:27Z | [
"python",
"python-2.7",
"robotframework"
] |
python/matplotlib : imposed ticks with ticker partially missing | 40,088,157 | <p>When plotting my figure with <code>plt.axis('auto')</code>, 'natural' x-ticks are written with frequency 500,</p>
<p><a href="https://i.stack.imgur.com/bcG6u.png" rel="nofollow"><img src="https://i.stack.imgur.com/bcG6u.png" alt="enter image description here"></a></p>
<p>Wishing a frequency 200, I have used:</p>
... | 1 | 2016-10-17T13:48:26Z | 40,088,308 | <p>Why don't you simply use <code>xticks</code> instead of <code>ticker</code></p>
<pre><code>fig = plt.figure('Cutlines x-axis')
ax = fig.add_subplot(111)
...
xlim = ax.get_xlim()
plt.xticks(np.arange(xlim[0], xlim[1]+200, 200))
</code></pre>
| 1 | 2016-10-17T13:54:54Z | [
"python",
"matplotlib",
"ticker"
] |
Python sending files over scp using pexpect | 40,088,323 | <p>So I'm trying to send all my torrent files to a server with scp using pexpect. This works for the most part but not all my torrent files get sent. Even though the print function in 'if i==0' prints out all the torrents. And if I go to the server and delete everything that got sent and run it again, the same torre... | 1 | 2016-10-17T13:55:38Z | 40,088,980 | <p>I think I figured it out, thanks to David's comment. The files that include spaces and icelandic letters (since I'm icelandic) don't get transferred.</p>
| 1 | 2016-10-17T14:25:06Z | [
"python",
"operating-system",
"scp",
"pexpect",
"torrent"
] |
groupby on NaN-only column gives IndexError | 40,088,441 | <p>The following gives IndexError: index out of bounds:</p>
<pre><code>import pandas as pd
from numpy import nan
df1 = pd.DataFrame({'Date': {0: '2016-10-11', 1: '2016-10-11', 2: '2016-10-11', 3: '2016-10-11', 4: '2016-10-11',5: '2016-10-11'}, 'Stock': {0: 'ABC', 1: 'ABC', 2: 'ABC', 3: 'ABC', 4: 'ABC', 5: 'XYZ'}, 'St... | 0 | 2016-10-17T14:00:21Z | 40,089,575 | <p>@Rahul, here is the output of your code when using Pandas 0.19.0:</p>
<pre><code>In [5]: df1
Out[5]:
Date EndTime StartTime Stock
0 2016-10-11 NaN 08:00:00.241 ABC
1 2016-10-11 NaN 08:00:00.243 ABC
2 2016-10-11 NaN 12:34:23.563 ABC
3 2016-10-11 NaN 08:14.05.908 ABC
... | 0 | 2016-10-17T14:52:05Z | [
"python",
"pandas",
"dataframe",
"group-by",
null
] |
django app multiple hard drives [Errno 18] Invalid cross-device link | 40,088,442 | <p>I have a django app on a debian server and my current site_media directory on the current disk is full. So I want to upload files On a second disk. The path on server is /disk :</p>
<pre><code> obj = form.save(commit=False)
obj.user_id = self.request.user.pk
obj.save()
initial_path = ... | 0 | 2016-10-17T14:00:21Z | 40,090,305 | <p><code>os.rename()</code> may fail across different file systems.</p>
<blockquote>
<p>The operation may fail on some Unix flavors if src and dst are on different filesystems.
<a href="https://docs.python.org/3/library/os.html#os.rename" rel="nofollow">https://docs.python.org/3/library/os.html#os.rename</a></p>
<... | 1 | 2016-10-17T15:29:04Z | [
"python",
"django",
"server",
"debian-based"
] |
How to use Python's RotatingFileHandler | 40,088,496 | <p>I'm trying to do a test run of the <code>logging</code> module's <code>RotatingFileHandler</code> as follows:</p>
<pre><code>import logging
from logging.handlers import RotatingFileHandler
# logging.basicConfig(filename="example.log", level=logging.DEBUG)
logger = logging.getLogger('my_logger')
handler = Rotating... | 0 | 2016-10-17T14:02:31Z | 40,088,591 | <p>Python provides 5 logging levels out of the box (in increasing order of severity): <code>DEBUG</code>, <code>INFO</code>, <code>WARNING</code>, <code>ERROR</code> and <code>CRITICAL</code>. The default one <a href="https://docs.python.org/3/howto/logging.html#what-happens-if-no-configuration-is-provided" rel="nofoll... | 2 | 2016-10-17T14:06:37Z | [
"python",
"logging"
] |
How to use Python's RotatingFileHandler | 40,088,496 | <p>I'm trying to do a test run of the <code>logging</code> module's <code>RotatingFileHandler</code> as follows:</p>
<pre><code>import logging
from logging.handlers import RotatingFileHandler
# logging.basicConfig(filename="example.log", level=logging.DEBUG)
logger = logging.getLogger('my_logger')
handler = Rotating... | 0 | 2016-10-17T14:02:31Z | 40,088,663 | <p>I found that to obtain the desired behavior one has to use the same name in the <code>basicConfig</code> and <code>RotatingFileHandler</code> initializations:</p>
<pre><code>import logging
from logging.handlers import RotatingFileHandler
logging.basicConfig(filename="my_log.log", level=logging.DEBUG)
logger = log... | 0 | 2016-10-17T14:09:38Z | [
"python",
"logging"
] |
python django call chat.py in template $ajax ? giving error not found | 40,088,503 | <p>hi i am new at python django.
i have template where i wana call a file through ajax</p>
<pre><code> $.ajax({
type: "POST",
url: "chat.py",
data: {foo: 'bar', bar: 'foo'},
</code></pre>
<p>and <code>urls.py</code></p>
<pre><code>from django.conf.urls import include , url
from . import views
from . impo... | 0 | 2016-10-17T14:02:43Z | 40,088,766 | <p>You haven't got a URL "chat.py". Your URLs are defined in the regexes in your urls.py; but you've only defined one, which is just /, although you've defined it twice which can't possibly work.</p>
<p>Make those two URLs different, and use the one you want in your Ajax call.</p>
| 0 | 2016-10-17T14:14:58Z | [
"python",
"ajax",
"django"
] |
Sorting dict items by key, beyond alphanumeric sorting | 40,088,527 | <p>I have written this code:</p>
<pre><code>n=5
dizN={}
for q in range(0,n+1):
h=n-q
dizN['a'+str(q)+'p'+str(h)]=0
</code></pre>
<p>that creates such a dictionary:</p>
<p>dizN</p>
<pre><code>Out[120]: {'a0p5': 0, 'a1p4': 0, 'a2p3': 0, 'a3p2': 0, 'a4p1': 0, 'a5p0': 0}
</code></pre>
<p>Note that "n" is the b... | 1 | 2016-10-17T14:03:44Z | 40,088,802 | <p><em>dicts</em> are <em>unordered</em>, so to get the order you are going to have to sort the items and use an <em>OrderedDict</em> to maintain the sorted order. To get the order you want you can create tuples from the groups of integers so you sort as integers in lexicographical order:</p>
<pre><code>from itertools... | 0 | 2016-10-17T14:16:22Z | [
"python",
"sorting",
"dictionary",
"tuples"
] |
Python - Check if two words are in a string | 40,088,559 | <p>I would like to check whether 2 words "car" and "motorbike" are in each element of an array in Python. I know how to check for one word with <code>in</code> but have no idea how to do with 2 words. Really appreciate any help</p>
| 2 | 2016-10-17T14:05:20Z | 40,088,783 | <p>Two word solution:</p>
<pre><code>for string in array:
if 'car' in string and 'motorbike' in string.split():
print("Car and motorbike are in string")
</code></pre>
<p>n-word solution to check if <strong>all</strong> words in <code>test_words</code> are in <code>string</code>:</p>
<pre><code>test_words... | 4 | 2016-10-17T14:15:37Z | [
"python"
] |
Python - Check if two words are in a string | 40,088,559 | <p>I would like to check whether 2 words "car" and "motorbike" are in each element of an array in Python. I know how to check for one word with <code>in</code> but have no idea how to do with 2 words. Really appreciate any help</p>
| 2 | 2016-10-17T14:05:20Z | 40,088,805 | <p>Use an auxiliar boolean.</p>
<pre><code>car=False
motorbike=False
for elem in array:
if "car" in elem:
car=True
if "motorbike" in elem:
motorbike=True
if car and motorbike:
break
</code></pre>
<p>EDIT: I just read "in each element". Just use AND.</p>
| 1 | 2016-10-17T14:16:25Z | [
"python"
] |
Python - Check if two words are in a string | 40,088,559 | <p>I would like to check whether 2 words "car" and "motorbike" are in each element of an array in Python. I know how to check for one word with <code>in</code> but have no idea how to do with 2 words. Really appreciate any help</p>
| 2 | 2016-10-17T14:05:20Z | 40,089,159 | <p>I think a simple solution is this:</p>
<pre class="lang-py prettyprint-override"><code>all(map(lambda w: w in text, ('car', 'motorbike')))
</code></pre>
<p>But there might be a problem with this, depending on how picky you need the comparison to be:</p>
<pre class="lang-py prettyprint-override"><code>>>>... | 0 | 2016-10-17T14:33:19Z | [
"python"
] |
I have this python function for DFS, why is it throwing error? | 40,088,560 | <pre><code>##This function will return the edges for an undirected graph####
###Example: when edges = [[1,2],[3,2]]
### this will return
{
1: {'nbr': [2], 'id': 1, 'visited': False},
2: {'nbr': [1, 3], 'id': 2, 'visited': False},
3: {'nbr': [2], 'id': 3, 'visited': False}
}
def createEdges(edges):
E =... | 0 | 2016-10-17T14:05:23Z | 40,088,736 | <p>Yes, <code>cc</code> is defined in scope of <code>DFS</code>, that does not make it visible inside <code>explore</code>. You could define it as a parameter to <code>explore</code>;</p>
<pre><code>def explore(vertex, E, cc):
</code></pre>
<p>and pass in the value;</p>
<pre><code>. . .
explore(x, E, cc)
. . .
</co... | 0 | 2016-10-17T14:13:42Z | [
"python",
"graph"
] |
I have this python function for DFS, why is it throwing error? | 40,088,560 | <pre><code>##This function will return the edges for an undirected graph####
###Example: when edges = [[1,2],[3,2]]
### this will return
{
1: {'nbr': [2], 'id': 1, 'visited': False},
2: {'nbr': [1, 3], 'id': 2, 'visited': False},
3: {'nbr': [2], 'id': 3, 'visited': False}
}
def createEdges(edges):
E =... | 0 | 2016-10-17T14:05:23Z | 40,089,792 | <p>you need to define "cc" as parameter of explore or define it as a global var.</p>
<pre><code> cc = 0
def explore(vertex, E):
global cc
if vertex not in E:
return
E[vertex]['ccNum'] = cc
E[vertex]['visited'] = True
for x in E[vertex]['nbr']:
if E[x]['visited'] == False:
explor... | 0 | 2016-10-17T15:03:19Z | [
"python",
"graph"
] |
Python - find highest dictionary key with value greater than zero | 40,088,576 | <p>I have a dictionary</p>
<pre><code>{0: 12, 1: 1, 2: 13, 3: 7, 4: 0}
</code></pre>
<p>I want to find the highest dictionary key with a value greater than 0.</p>
<p>In this case, the answer is 3.</p>
<p>What's the best way to do this?</p>
| 1 | 2016-10-17T14:06:01Z | 40,088,649 | <p>You can use <code>max</code> and <code>dict.items()</code> to do this:</p>
<pre><code>d = {0: 12, 1: 1, 2: 13, 3: 7, 4: 0}
highest = max(i for i,j in d.items() if j > 0)
</code></pre>
| 2 | 2016-10-17T14:09:04Z | [
"python",
"dictionary"
] |
Python - find highest dictionary key with value greater than zero | 40,088,576 | <p>I have a dictionary</p>
<pre><code>{0: 12, 1: 1, 2: 13, 3: 7, 4: 0}
</code></pre>
<p>I want to find the highest dictionary key with a value greater than 0.</p>
<p>In this case, the answer is 3.</p>
<p>What's the best way to do this?</p>
| 1 | 2016-10-17T14:06:01Z | 40,088,687 | <p>Use a genexpr to filter out the "bad" values, and <code>max</code> to keep the highest that remains:</p>
<pre><code># On Py2, use .iteritems() instead of .items()
max(k for k, v in mydict.items() if v > 0)
</code></pre>
<p>Or if you need to have a default if no keys qualify without an exception being raised:</p... | 3 | 2016-10-17T14:10:55Z | [
"python",
"dictionary"
] |
Turn off error bars in Seaborn Bar Plot | 40,088,585 | <p>I'm using GridSpec in matplotlib to create a page that has 9 subplots. One of the subplots is a Seaborn bar plot created with the following code:</p>
<pre><code>import seaborn as sns
sns.barplot(x=df['Time'], y=df['Volume_Count'], ax=ax7)
</code></pre>
<p>Is there a way to turn off the vertical error bars of the ... | 0 | 2016-10-17T14:06:28Z | 40,090,469 | <p>I'm not 100% sure since the seaborn website seems to be down, but have you tried the <code>ci</code> argument? According to the documentation:</p>
<blockquote>
<p>ci : float or None, optional
Size of confidence intervals to draw around estimated values. If
<code>None</code>, no bootstrapping will be p... | 2 | 2016-10-17T15:38:00Z | [
"python",
"matplotlib",
"seaborn"
] |
Linux : unable to install kivy in virtual environment | 40,088,622 | <p>I am using python2.7 and created a virtual environment 'kivyenv'.
First i install Cython and then kivy in kivyenv.</p>
<pre><code>pip install Cython
pip install kivy
</code></pre>
<p>kivy failed to install giving some error :-</p>
<pre><code>In file included from /tmp/pip-build-4T9oG4/kivy/kivy/graphics/opengl.c:... | 0 | 2016-10-17T14:07:40Z | 40,089,362 | <p>This is happening because you do not have dependency libraries installed on your system, specifically the ones for OpenGL - most likely you do not have mesa packages installed.</p>
<p>Follow the instructions for your specific distribution on how to install all of the needed dependencies at: <a href="https://kivy.o... | 2 | 2016-10-17T14:42:41Z | [
"python",
"linux",
"python-2.7",
"virtualenv",
"kivy"
] |
forcing a program to calculate an input | 40,088,634 | <p>I was wondering if I could force the program to calculate an input before converting it to an integer.
for example my code is</p>
<pre><code> shift=int(raw_input("input the shift you want "))
</code></pre>
<p>If I was to input 4**2 which should then in theory equal 16 however as the raw input is a string this c... | 0 | 2016-10-17T14:08:07Z | 40,089,205 | <p>If you don't mind being terribly unsafe, you can use <a href="https://docs.python.org/2/library/functions.html#eval" rel="nofollow">eval</a>, which accepts a single string argument as input, and executes it as Python code:</p>
<pre><code>shift = eval(raw_input("input the shift you want "))
</code></pre>
<p><a href... | 4 | 2016-10-17T14:35:31Z | [
"python",
"python-2.7",
"input",
"raw-input"
] |
How to set the default working directory for run configurations in PyCharm | 40,088,657 | <p>When I want to run one of our many python scripts I hit run, which creates a new run configuration. The working directory for that configuration is the folder in which the python script file resides. Instead, it should run from a project wide fixed folder. I'd like to set that somehow but I really cannot figure out ... | 1 | 2016-10-17T14:09:23Z | 40,088,730 | <p>If you hit the <code>Edit configurations...</code> button in the submenu appearing when clicking on your currently selected run configuration in the top right of PyCharm, you are able to edit the fields (and therefore also the working directory) of Python run configurations by selecting <code>Python</code> from the ... | 2 | 2016-10-17T14:13:20Z | [
"python",
"pycharm",
"run-configuration"
] |
Python help using 'numpy.masked_where' conditionally from another list | 40,088,691 | <p>I am writing an astronomy observation simulation. I have a data array which is 1 measurement per 24 hours:</p>
<pre><code>data = [0,1,2,3,4]
</code></pre>
<p>And I have a array which is the minutes of cloud/rain in a 24 hour period, rounded to the nearest hour:</p>
<pre><code>weather = [0,60,120,180,0]
</code></p... | 0 | 2016-10-17T14:11:15Z | 40,089,060 | <p>Using <code>numpy.ma</code> returns a mask. That is, it <strong>hides</strong> (masks) everything that fits the condition <code>weather < downtime</code>. If you want to <strong>show</strong> everything that fits the condition, just invert the condition:</p>
<pre><code>data = np.array([0,1,2,3,4])
weather = np.a... | 2 | 2016-10-17T14:28:33Z | [
"python",
"arrays",
"numpy",
"masked-array"
] |
Python help using 'numpy.masked_where' conditionally from another list | 40,088,691 | <p>I am writing an astronomy observation simulation. I have a data array which is 1 measurement per 24 hours:</p>
<pre><code>data = [0,1,2,3,4]
</code></pre>
<p>And I have a array which is the minutes of cloud/rain in a 24 hour period, rounded to the nearest hour:</p>
<pre><code>weather = [0,60,120,180,0]
</code></p... | 0 | 2016-10-17T14:11:15Z | 40,089,070 | <p>You'll want to use</p>
<pre><code>np.ma.MaskedArray(data,mask)
</code></pre>
<p>Note that the mask specifies the data that is to be masked. Also, for the following type of operation</p>
<pre><code>weather < downtime
</code></pre>
<p>to work as you intend, 'weather' needs to be an array rather than a list, so:... | 1 | 2016-10-17T14:29:12Z | [
"python",
"arrays",
"numpy",
"masked-array"
] |
Python Pandas - filtering df by the number of unique values within a group | 40,088,710 | <p>Here is an example of data I'm working on. (as a pandas df)</p>
<pre><code> index inv Rev_stream Bill_type Net_rev
1 1 A Original -24.77
2 1 B Original -24.77
3 2 A Original -409.33
4 2 B Original -409.33
... | 1 | 2016-10-17T14:12:04Z | 40,089,226 | <p>You can group your data by <code>inv</code> and <code>Rev_stream</code> columns and then check for each group if both <code>Original</code> and <code>Rebill</code> are in the <code>Bill_type</code> values and filter based on the condition:</p>
<pre><code>(df.groupby(['inv', 'Rev_stream'])
.filter(lambda g: 'Orig... | 2 | 2016-10-17T14:36:24Z | [
"python",
"pandas",
"dataframe",
"filtering"
] |
How to create a loop to return to the start of a function python | 40,088,732 | <p>I am unable to get my <code>while</code> loop to start back at the beginning not to sure what is wrong.</p>
<p>First attempt</p>
<pre><code>def start() :
if choice in weapon:
print('You have taken the ') + choice + (',this is now in your backpack.\n')
inventory.append(choice)
else:
print("Uh oh, I ... | 0 | 2016-10-17T14:13:25Z | 40,088,943 | <p>Your second attempt looks close, but you need an esape if all items are done: but look at your spaces: the if is inside the while:</p>
<pre><code>choice = next_choice()
found = false
while found & :
if choice in weapon_stash:
inventory.append(choice)
found = True
else:
choice = n... | 1 | 2016-10-17T14:23:15Z | [
"python",
"python-2.7"
] |
How to create a loop to return to the start of a function python | 40,088,732 | <p>I am unable to get my <code>while</code> loop to start back at the beginning not to sure what is wrong.</p>
<p>First attempt</p>
<pre><code>def start() :
if choice in weapon:
print('You have taken the ') + choice + (',this is now in your backpack.\n')
inventory.append(choice)
else:
print("Uh oh, I ... | 0 | 2016-10-17T14:13:25Z | 40,089,304 | <p>The reason I commented Visual Studio might not be the best python editor is that other editors would have warned you that you did not increase the indentation after your function definition <code>start()</code> in your first attempt, nor did you indent after the start of your <code>while</code> loop in your second a... | 1 | 2016-10-17T14:40:15Z | [
"python",
"python-2.7"
] |
How to create a loop to return to the start of a function python | 40,088,732 | <p>I am unable to get my <code>while</code> loop to start back at the beginning not to sure what is wrong.</p>
<p>First attempt</p>
<pre><code>def start() :
if choice in weapon:
print('You have taken the ') + choice + (',this is now in your backpack.\n')
inventory.append(choice)
else:
print("Uh oh, I ... | 0 | 2016-10-17T14:13:25Z | 40,089,476 | <p>There are only indentation faults in the second attempt.
Try below code.</p>
<pre><code>the_choice = False
while not the_choice:
if choice in weapon:
print('You have taken the ') + choice + (',this is now in your backpack.\n')
inventory.append(choice)
the_choice = True
# boom n... | 0 | 2016-10-17T14:47:39Z | [
"python",
"python-2.7"
] |
How to download nasa satellite OPeNDAP data using python | 40,088,745 | <p>I have tried requests, pydap, urllib, and netcdf4 and keep either getting redirect errors or permission errors when trying to download the following NASA data:</p>
<p>GLDAS_NOAH025SUBP_3H: GLDAS Noah Land Surface Model L4 3 Hourly 0.25 x 0.25 degree Subsetted V001 (<a href="http://disc.sci.gsfc.nasa.gov/uui/dataset... | 2 | 2016-10-17T14:14:02Z | 40,110,569 | <p>I did not find a solution using python, but given the information I have now it should be possible. I used wget with a .netrc file and cookie file shown as follows (<a href="http://disc.sci.gsfc.nasa.gov/recipes/?q=recipes/How-to-Download-Data-Files-from-HTTP-Service-with-wget" rel="nofollow">http://disc.sci.gsfc.na... | 2 | 2016-10-18T14:11:44Z | [
"python",
"httprequest",
"netcdf",
"opendap"
] |
Convert directory structure to json? | 40,088,789 | <p>I want to convert a project hierarchy with some properties for each class or package in a JSON dictionary. for example</p>
<p>I am using python for this. Can anyone please give me some basic outline. How I can implement this.Thank you. thus i want something like:</p>
<pre><code>a = package, a.b = package, a.b.c = ... | 1 | 2016-10-17T14:15:59Z | 40,089,320 | <p>try to use <code>pkgutil.walk_packages</code> combine with <code>importlib.import_module</code>.</p>
<pre><code>def get_all_module_of_a_package(pkg_name):
pkg = importlib.import_module(pkg_name)
for importer, name, is_pkg in pkgutil.walk_packages(pkg.__path__, pkg.__name__ + '.'):
if is_pkg:
... | 0 | 2016-10-17T14:40:51Z | [
"python",
"json"
] |
How this code convert to arduino | 40,088,907 | <p>I have a problem with implement this python algorithm to arduino. Help me to do this..</p>
<pre><code>def Process(lst):
for k in range(len(lst)):
for i in range(len(lst)-1):
if abs(lst[i]-lst[i+1])==2 and lst[i+1]!=0:
for j in range(i,len(lst)-2):
lst[j]=l... | 0 | 2016-10-17T14:21:26Z | 40,094,496 | <p>Some ideas to get you started:
You don't really have lists in C on the Arduino. A data structure you could use there is an array. See <a href="https://www.arduino.cc/en/Reference/Array" rel="nofollow">https://www.arduino.cc/en/Reference/Array</a> for more info.</p>
<p>Passing around arrays to e.g. functions is done... | 0 | 2016-10-17T19:48:27Z | [
"python",
"arduino"
] |
recursion: make changes with fewest coins | 40,088,908 | <p>I'm studing the data structure and algorithm in python. Here is the classic problem of recursion involving making change with the fewest coins. Here are the codes.
What I do not understand is line 2. why do we need <code>minCoins = change</code>? what does line 8-9 mean? can anyone helo explain that? thank you very ... | -1 | 2016-10-17T14:21:28Z | 40,089,188 | <p><code>minCoins = change</code>: <code>minCoins</code> is initialized with the value of <code>change</code> which is the maximum value that <code>recMC</code> can return as the minimum value of a coin is 1, assuming integer values of coins.</p>
<p><code>if change in coinValueList: return 1</code>: base case 1 - if s... | 1 | 2016-10-17T14:34:45Z | [
"python",
"algorithm",
"recursion"
] |
Code that makes cyclic reference for x spaces in list | 40,088,930 | <p>I have a tasko to make a program in which i get m, n and k. I should create a list a with <code>n*m</code> element.
List <code>b</code> is supposed to have <code>n*m</code> element. It is created from list a with cyclic shift k to the right for m elements of lists.
I know it is poorly explained. Example is:</p>
<p... | 2 | 2016-10-17T14:22:35Z | 40,089,268 | <p>Try this... </p>
<pre><code># Start with an empty list
B = []
# Take A in chunks of m
for i in range( int(len(A)/m) ):
# Take an m-sized chunk of A
chunk = A[m*i:m*(i+1)]
# Shift it to the right by k (python style!)
shift = chunk[-k:] + chunk[:-k]
# Add it to B
B += shift
print (B)
</code></... | 1 | 2016-10-17T14:38:32Z | [
"python",
"list",
"cyclic-reference"
] |
Code that makes cyclic reference for x spaces in list | 40,088,930 | <p>I have a tasko to make a program in which i get m, n and k. I should create a list a with <code>n*m</code> element.
List <code>b</code> is supposed to have <code>n*m</code> element. It is created from list a with cyclic shift k to the right for m elements of lists.
I know it is poorly explained. Example is:</p>
<p... | 2 | 2016-10-17T14:22:35Z | 40,089,666 | <p>Alternative:</p>
<pre><code>m=4
n=3
k=1
A=list(range(1,1+m*n))
print (A)
t_1=[A[_:_+4] for _ in range(0,len(A), 4)]
print (t_1)
t_2=[]
for sublist in t_1:
t_2.append(sublist[-k:]+sublist[:-k])
print (t_2)
B=[]
for sublist in t_2:
B.extend(sublist)
print (B)
</code></pre>
<p>If you want greater speed t... | 0 | 2016-10-17T14:56:58Z | [
"python",
"list",
"cyclic-reference"
] |
Django add common conditions in model | 40,089,017 | <p>I have model </p>
<pre><code>class QuerySetManager(models.Manager):
def get_query_set(self):
return self.model.QuerySet(self.model)
class Post(models.Model):
objects = QuerySetManager()
STATUS = (
(1, 'PENDING'),
(2, 'ACTIVE'),
)
title = models.CharField(max_length=512... | 0 | 2016-10-17T14:26:43Z | 40,089,165 | <p>I can't understand what you're doing here at all. The way to get a manager to return a queryset with the same methods is to use the <a href="https://docs.djangoproject.com/en/1.10/topics/db/managers/#creating-a-manager-with-queryset-methods" rel="nofollow"><code>as_manager</code> classmethod</a>.</p>
<pre><code>cla... | 0 | 2016-10-17T14:33:46Z | [
"python",
"django"
] |
Fill missing categorial values using pandas? | 40,089,042 | <p>I'd like to fill missing categorial cells with new values per column. For example:</p>
<pre><code>c1 c2 c3
a nan a
b q nan
c d nan
a p z
</code></pre>
<p>should become something like</p>
<pre><code>c1 c2 c3
a n1 a
b q n2
c d n2
a p z
</code></pre>
<p>My current problem is... | 1 | 2016-10-16T21:51:30Z | 40,089,043 | <p>Fillna with some uniq string does what you want:</p>
<pre><code>categorial_data = pd.DataFrame({'sex': ['male', 'female', 'male', 'female'],
'nationality': ['American', 'European', float('nan'), 'European']})
print(categorial_data)
categorial_data=categorial_data.fillna('some_unique_... | 0 | 2016-10-16T23:47:28Z | [
"python",
"missing-data",
"pandas"
] |
Difference between GET data as a function parameter and an item from requests.arg | 40,089,134 | <p>I would like to know if there is any difference between:</p>
<pre><code>@app.route('/api/users/<int:id>', methods=['GET'])
def get_user(id):
pass # handle user here with given id
</code></pre>
<p>and</p>
<pre><code>@app.route('/api/users')
def get_user():
id = request.args.get('id')
# handle us... | 2 | 2016-10-17T14:32:33Z | 40,089,289 | <p>Yes, it is. </p>
<p>First method:</p>
<pre><code>@app.route('/api/users/<int:id>', methods=['GET']
def get_user(id):
pass # handle user here with given id
</code></pre>
<p>Defines a route and a method. This function is only triggered with this method over this path.</p>
<p>Second method:</p>
<pre><co... | 2 | 2016-10-17T14:39:43Z | [
"python",
"python-3.x",
"flask",
"flask-restful"
] |
Difference between GET data as a function parameter and an item from requests.arg | 40,089,134 | <p>I would like to know if there is any difference between:</p>
<pre><code>@app.route('/api/users/<int:id>', methods=['GET'])
def get_user(id):
pass # handle user here with given id
</code></pre>
<p>and</p>
<pre><code>@app.route('/api/users')
def get_user():
id = request.args.get('id')
# handle us... | 2 | 2016-10-17T14:32:33Z | 40,089,844 | <p>The main difference is that the URL triggering your function will be different. </p>
<p>If you use the flask function <a href="http://flask.pocoo.org/docs/0.11/api/#flask.url_for" rel="nofollow">url_for</a>(that i REALLY recommend), the URL structure returned by the function will be different because all the variab... | 1 | 2016-10-17T15:06:30Z | [
"python",
"python-3.x",
"flask",
"flask-restful"
] |
export tables from google bigquery to google storage | 40,089,238 | <p>I'm new on bigQuery. I need to export tables from BigQuery to google storage.
For the moment, I can list all tables by dataset.
Does some boody can help me with how can I export then tables?
My python code is below :</p>
<pre><code>#!/usr/bin/env python
from googleapiclient import discovery
from oauth2client.clie... | 0 | 2016-10-17T14:37:11Z | 40,089,413 | <p>There is a full Python example on the docs page. Two functions you need is there.
<a href="https://cloud.google.com/bigquery/docs/exporting-data" rel="nofollow">https://cloud.google.com/bigquery/docs/exporting-data</a></p>
<p>including here for future reference:</p>
<pre><code>def export_data_to_gcs(dataset_name,... | 0 | 2016-10-17T14:44:59Z | [
"python",
"google-bigquery"
] |
I cannot get pygame to work with python | 40,089,274 | <p>I have had a few dozen attempts at installing pygame to my python. I have tried many different versions of the programs.</p>
<p>I am running a 64 bit version of windows 10, and seem to be required to use an unofficial .whl file to get pygame, however i do not know how to use this file. </p>
<p>I have tried running... | -2 | 2016-10-17T14:38:48Z | 40,089,479 | <p>Download the correct .whl file from <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame" rel="nofollow">here</a> and save this file to whatever directory you like. Open a command prompt and navigate to the directory where you saved the .whl file.</p>
<p>Lets say you downloaded the file <code>pygame-1.9.2b1-c... | 0 | 2016-10-17T14:47:57Z | [
"python",
"windows",
"installation",
"pygame",
"64bit"
] |
How to convert this comprehension to a for-loop in Python? | 40,089,306 | <pre><code>sample = [['CGG','ATT'],['GCGC','TAAA']]
base_counts = [[Counter(base) for base in sub] for sub in sample]
#Output : [[Counter({'G': 2, 'C': 1}), Counter({'T': 2, 'A': 1})], [Counter({'C': 2, 'G': 2}), Counter({'A': 3, 'T': 1})]]
base_freqs = [[{k_v[0]:k_v[1]/len(bases[i]) for i,k_v in enumerate(count.items... | 0 | 2016-10-17T14:40:17Z | 40,089,448 | <p>It's not really easier with for loop, but here is how it should look like.</p>
<pre><code>result = []
for counts, bases in zip(base_counts, sample):
some_list = []
for count in counts:
some_dict = {}
for i,k_v in enumerate(count.items()):
some_dict[k_v[0]] = k_v[1]/len(bases[i])
... | 1 | 2016-10-17T14:46:16Z | [
"python",
"for-loop",
"for-comprehension"
] |
How to convert this comprehension to a for-loop in Python? | 40,089,306 | <pre><code>sample = [['CGG','ATT'],['GCGC','TAAA']]
base_counts = [[Counter(base) for base in sub] for sub in sample]
#Output : [[Counter({'G': 2, 'C': 1}), Counter({'T': 2, 'A': 1})], [Counter({'C': 2, 'G': 2}), Counter({'A': 3, 'T': 1})]]
base_freqs = [[{k_v[0]:k_v[1]/len(bases[i]) for i,k_v in enumerate(count.items... | 0 | 2016-10-17T14:40:17Z | 40,089,532 | <p>Yes. The way to read comprehensions in outside in and left to right. Let's format it a little for readability:</p>
<pre><code>base =[
[
{ k_v[0] : k_v[1]/len(bases[i])
for i,k_v in enumerate(count.items())
}
for count in counts
]
... | 2 | 2016-10-17T14:50:22Z | [
"python",
"for-loop",
"for-comprehension"
] |
How to convert this comprehension to a for-loop in Python? | 40,089,306 | <pre><code>sample = [['CGG','ATT'],['GCGC','TAAA']]
base_counts = [[Counter(base) for base in sub] for sub in sample]
#Output : [[Counter({'G': 2, 'C': 1}), Counter({'T': 2, 'A': 1})], [Counter({'C': 2, 'G': 2}), Counter({'A': 3, 'T': 1})]]
base_freqs = [[{k_v[0]:k_v[1]/len(bases[i]) for i,k_v in enumerate(count.items... | 0 | 2016-10-17T14:40:17Z | 40,089,596 | <p>You can always translate a list comprehension such as</p>
<pre><code>ls = [<EXPR> for <VARS> in <ITERABLE> if <CONDITIONAL>]
</code></pre>
<p>to</p>
<pre><code>ls = []
for <VARS> in <ITERABLE>:
if <CONDITIONAL>:
ls.append(<EXPR>)
</code></pre>
<p>Multip... | 2 | 2016-10-17T14:53:05Z | [
"python",
"for-loop",
"for-comprehension"
] |
python 2.6 - print French characters | 40,089,612 | <p>My question regarding printing French characters with python 2.6.
There is no problems when I use python 3.4 but I need using python 2.6!
Instead of société mère I've got société mère etc.
I already tried:</p>
<pre><code>#!/usr/bin/python
# coding=utf-8
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -... | 1 | 2016-10-17T14:54:15Z | 40,089,742 | <p>Try prefixing your string literals with u:</p>
<pre><code>print u'société mère'
</code></pre>
<p>Docs: <a href="https://docs.python.org/2/howto/unicode.html" rel="nofollow">https://docs.python.org/2/howto/unicode.html</a></p>
| 1 | 2016-10-17T15:00:33Z | [
"python",
"python-2.6",
"non-ascii-characters"
] |
creating two separate lists read from a file in python | 40,089,617 | <p>Can i please know how the data from a file can be split into two separate lists. For example,
file contains data as 1,2,3,4;5,6,7 </p>
<pre><code>my code:
for num in open('filename','r'):
list1 = num.strip(';').split()
</code></pre>
<p>Here , i want a new list before semi colon (i.e) [1,2,3,4] and new list afte... | 0 | 2016-10-17T14:54:28Z | 40,089,733 | <p>Depending on the size of your file, you could simply read the whole file into a string at once and then first split by semicolon, then by comma:</p>
<pre class="lang-python prettyprint-override"><code>with open('filename', 'r') as f: #open file
s = f.read() #read entire contents into string
lists = s.spl... | 0 | 2016-10-17T15:00:04Z | [
"python",
"python-2.7",
"python-3.x"
] |
creating two separate lists read from a file in python | 40,089,617 | <p>Can i please know how the data from a file can be split into two separate lists. For example,
file contains data as 1,2,3,4;5,6,7 </p>
<pre><code>my code:
for num in open('filename','r'):
list1 = num.strip(';').split()
</code></pre>
<p>Here , i want a new list before semi colon (i.e) [1,2,3,4] and new list afte... | 0 | 2016-10-17T14:54:28Z | 40,089,736 | <p>If you are certain that your file only contains 2 lists, you can use a list comprehension:</p>
<pre><code>l1, l2 = [sub.split(',') for sub in data.split(';')]
# l1 = ['1', '2', '3', '4']
# l2 = ['5', '6', '7']
</code></pre>
<p>More generally,</p>
<pre><code>lists = [sub.split(',') for sub in data.split(';')]
# li... | 2 | 2016-10-17T15:00:14Z | [
"python",
"python-2.7",
"python-3.x"
] |
creating two separate lists read from a file in python | 40,089,617 | <p>Can i please know how the data from a file can be split into two separate lists. For example,
file contains data as 1,2,3,4;5,6,7 </p>
<pre><code>my code:
for num in open('filename','r'):
list1 = num.strip(';').split()
</code></pre>
<p>Here , i want a new list before semi colon (i.e) [1,2,3,4] and new list afte... | 0 | 2016-10-17T14:54:28Z | 40,089,744 | <p>To get the final list you need to split on <code>","</code> as well (and probably <code>map()</code> the result to <code>int()</code>):</p>
<pre><code>with open("filename") as f:
for line in f:
list1, list2 = [x.split(",") for x in line.rstrip().split(";")]
</code></pre>
| 1 | 2016-10-17T15:00:35Z | [
"python",
"python-2.7",
"python-3.x"
] |
I trying to print sequence but getting KeyError? in python | 40,089,678 | <p>I am getting only first input file correct output but I have A , B, C, D chain in my first file and getting right output, in this case in second input file does't have c and d chain in this case, our code is copying same data of first file data of C and D.? and also I am unable to increase this ids: chainIDs = ['A',... | 0 | 2016-10-17T14:57:46Z | 40,091,354 | <p>Just change the output loop to something like this:</p>
<pre><code>for chainID in chainIDs:
if chainID in d:
for atom_id in d[chainID]:
with open(filenames+'out.pdb', 'a') as f:
f.write(d[chainID][atom_id] + '\n')
</code></pre>
| 0 | 2016-10-17T16:28:27Z | [
"python",
"python-2.7",
"python-3.x",
"bioinformatics"
] |
Sharing global information across requests to flask endpoints on heroku | 40,089,685 | <p>I have a flask application with a single endpoint, like this (simplified below):</p>
<pre><code>@app.route('/classify', methods=['POST'])
def classify():
p = g.model_loader.get_model()
json = request.get_json()
text = json['text']
return p.classify(text)
def main():
model_loader = ResourceLoad... | 0 | 2016-10-17T14:57:59Z | 40,089,812 | <p>You can't load it into memory once, because Heroku workers might be on completely different machines. You need to run this code in every worker, or store the data somewhere it can be read by any process.</p>
| 0 | 2016-10-17T15:04:27Z | [
"python",
"heroku",
"flask"
] |
BeautifulSoup parse table data that doesn't load immediately | 40,089,724 | <p>I'm trying to download earnings announcement data from <a href="https://www.zacks.com/stock/research/MMM/earnings-announcements" rel="nofollow">https://www.zacks.com/stock/research/MMM/earnings-announcements</a> using beautifulsoup. When I look at the tables, the table I am interested in (earnings_announcements_ear... | 0 | 2016-10-17T14:59:40Z | 40,089,939 | <p>One way would be to fire up Selenium and make use of its Javascript engine. That's not really simple, and I offer here an alternative solution which is a total hack, but it should work for the pages you are interested in.</p>
<p>Assuming the pages are generated automatically, we observe that the data you want is in... | 1 | 2016-10-17T15:10:58Z | [
"python",
"beautifulsoup"
] |
BeautifulSoup parse table data that doesn't load immediately | 40,089,724 | <p>I'm trying to download earnings announcement data from <a href="https://www.zacks.com/stock/research/MMM/earnings-announcements" rel="nofollow">https://www.zacks.com/stock/research/MMM/earnings-announcements</a> using beautifulsoup. When I look at the tables, the table I am interested in (earnings_announcements_ear... | 0 | 2016-10-17T14:59:40Z | 40,091,287 | <p>Without using Selenium but still using json as in the first answer you can dig out the content you need with BS.</p>
<pre><code>>>> from bs4 import BeautifulSoup
>>> from urllib import request
>>> URL='https://www.zacks.com/stock/research/MMM/earnings-announcements'
>>> HTML=requ... | 0 | 2016-10-17T16:24:10Z | [
"python",
"beautifulsoup"
] |
Perfect Square function that doesn't return | 40,089,750 | <p>I'm a beginner working with Python and I was given this task: <em>write a function which returns the highest perfect square which is less or equal to its parameter (a positive integer).</em></p>
<pre><code>def perfsq(n):
x = 0
xy = x * x
if n >= 0:
while xy < n:
x += 1
... | 0 | 2016-10-17T15:00:53Z | 40,089,952 | <p>Like Patrick Haugh says, try examining when the while loop exits. It can be helpful to put print() statements throughout your method to figure out how your method executes. In order to figure out when your loop exits, look at the exit condition of your while loop: xy < n. </p>
<p>Remember, a variable isn't updat... | 0 | 2016-10-17T15:11:38Z | [
"python",
"loops",
"if-statement"
] |
Perfect Square function that doesn't return | 40,089,750 | <p>I'm a beginner working with Python and I was given this task: <em>write a function which returns the highest perfect square which is less or equal to its parameter (a positive integer).</em></p>
<pre><code>def perfsq(n):
x = 0
xy = x * x
if n >= 0:
while xy < n:
x += 1
... | 0 | 2016-10-17T15:00:53Z | 40,089,961 | <p>I see your mistake, and it's an easy one for someone to make. When you define</p>
<pre><code>xy = x*x
</code></pre>
<p>the computer calculates <code>x*x</code> and assigns that <em>number</em> to be the value of <code>xy</code>. So when you then add one to <code>x</code> it does not change the value of <code>xy</... | -1 | 2016-10-17T15:12:00Z | [
"python",
"loops",
"if-statement"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.