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 |
|---|---|---|---|---|---|---|---|---|---|
Clean from .txt, write new variable as a csv delimited string (not list) into a csv file | 39,934,531 | <p>my .txt file looks like the following:</p>
<pre><code>Page 1 of 49
<="">
View Full Profile
S.S. Anne
Oil Tanker
42 miles offshore
Anchor length is 50 feet
<="">
View Full Profile
S.S. Minnow
Passenger Ship
1502.2 miles offshore
Anchor length is 12 feet
<="">
View Full Profile
S.S. Virginia
Passeng... | 0 | 2016-10-08T16:11:37Z | 39,934,573 | <pre><code>line = line.replace('\n', '')
</code></pre>
<p>Use the replace method</p>
<p>If there is a list of strings:</p>
<pre><code>line = [l.replace('\n', '') for l in line]
</code></pre>
| 0 | 2016-10-08T16:15:57Z | [
"python",
"csv"
] |
Clean from .txt, write new variable as a csv delimited string (not list) into a csv file | 39,934,531 | <p>my .txt file looks like the following:</p>
<pre><code>Page 1 of 49
<="">
View Full Profile
S.S. Anne
Oil Tanker
42 miles offshore
Anchor length is 50 feet
<="">
View Full Profile
S.S. Minnow
Passenger Ship
1502.2 miles offshore
Anchor length is 12 feet
<="">
View Full Profile
S.S. Virginia
Passeng... | 0 | 2016-10-08T16:11:37Z | 39,934,760 | <p>You should strip the terminating newline as soon as you read the line. The first part of your code could become:</p>
<pre><code>data = []
with open('ship.txt','r',encoding='utf8') as f:
for line in lines:
if 'View Full Profile' in line:
x = [ next(f).strip(), next(f).strip(),
... | 0 | 2016-10-08T16:34:35Z | [
"python",
"csv"
] |
How to read files with separators in Python and append characters at the end? | 39,934,586 | <p>I have a file format that looks like this</p>
<pre><code> >1ATGC>2TTTT>3ATGC>$$$>B1ATCG>B2TT-G>3TTCG>B4TT-G>B5TTCG>B6TTCG$$$>C1TTTT>C2ATGC
</code></pre>
<p>Note: "$$$" divides the file, such that anything before $$$ is Set 1 and after $$$ is Set 2 and after the next $$$ Set3 etc... | 1 | 2016-10-08T16:17:12Z | 39,934,848 | <p>It's unclear how fragile your data set is, but if it follows the pattern above (namely the last 4 characters are the ones you are looking for) then you can use a couple of <code>split()</code>s and <code>itertools.zip_longest</code> and <code>zip</code> it back to append the <code>Z</code></p>
<pre><code>>>&g... | 1 | 2016-10-08T16:44:38Z | [
"python",
"append",
"startswith"
] |
Google Vision API Error Code | 39,934,619 | <p>I am trying the example code in
<a href="https://googlecloudplatform.github.io/google-cloud-python/stable/vision-usage.html" rel="nofollow">https://googlecloudplatform.github.io/google-cloud-python/stable/vision-usage.html</a></p>
<pre><code>from google.cloud import vision
client = vision.Client()
image = cl... | 0 | 2016-10-08T16:19:53Z | 40,089,669 | <p><a href="https://code.google.com/p/google-cloud-platform/issues/detail?id=123" rel="nofollow">Here's an issue</a> which also mentions the error. That issue has been forwarded to the Google engineering team.</p>
<p>Could you perhaps try re-encoding your image? Save it as a png or resave to jpg to see if maybe it's c... | 0 | 2016-10-17T14:57:06Z | [
"python",
"google-cloud-vision",
"google-cloud-python"
] |
Python - While-Loop until list is empty | 39,934,635 | <p>I'm working with Django and I have a queryset of objects that has been converted to a list (<code>unpaid_sales</code>). I'm executing a process that iterates through this list and operates on each item until either the list is empty, or a given integer (<code>bucket</code>) reaches zero.</p>
<p>This is how I set it... | 0 | 2016-10-08T16:21:32Z | 39,934,670 | <p>Do not use separate <code>while</code>loops. Do as follows :</p>
<pre><code>while unpaid_sales and bucket > 0 :
unpaid_sale = unpaid_sales.pop(0)
...do stuff
</code></pre>
| 3 | 2016-10-08T16:25:30Z | [
"python"
] |
Python - While-Loop until list is empty | 39,934,635 | <p>I'm working with Django and I have a queryset of objects that has been converted to a list (<code>unpaid_sales</code>). I'm executing a process that iterates through this list and operates on each item until either the list is empty, or a given integer (<code>bucket</code>) reaches zero.</p>
<p>This is how I set it... | 0 | 2016-10-08T16:21:32Z | 39,934,680 | <p>You should do a single loop: <code>while bucket>0 and unpaid_sales</code>. Here, you are popping elements in the <code>bucket</code> loop, and then just just check that <code>bucket</code> is positive, but you do not check that <code>element_sales</code> still has elements in it.</p>
| 2 | 2016-10-08T16:26:24Z | [
"python"
] |
Python - While-Loop until list is empty | 39,934,635 | <p>I'm working with Django and I have a queryset of objects that has been converted to a list (<code>unpaid_sales</code>). I'm executing a process that iterates through this list and operates on each item until either the list is empty, or a given integer (<code>bucket</code>) reaches zero.</p>
<p>This is how I set it... | 0 | 2016-10-08T16:21:32Z | 39,934,685 | <p>Your end criteria must be formulated a little differently: loop while there are items and the <code>bucket</code> is positive. <code>or</code> is not the right operation here.</p>
<pre><code>while unpaid_sales and bucket > 0
unpaid_sale = unpaid_sales.pop(0)
#do stuff
</code></pre>
| 3 | 2016-10-08T16:27:19Z | [
"python"
] |
Find out all the punctuations in a sentence that has been put into a list | 39,934,679 | <p>I have this variable:</p>
<pre><code>Words = ["Hi",".","how","are","you","?","I","feel","like","I","could",",","do","better"]
</code></pre>
<p>From this I want a variable that finds all the punctuations and puts it into a list as well. Like this:</p>
<pre><code>Punctuations = [".","?",","]
</code></pre>
| 1 | 2016-10-08T16:26:24Z | 39,934,787 | <p>You can use <a href="https://docs.python.org/2/library/string.html#string.punctuation" rel="nofollow"><code>string.punctuation</code></a> to identify punctuation marks:</p>
<pre><code>from string import punctuation
punctuations = [w for w in words if w in punctuation]
</code></pre>
| 1 | 2016-10-08T16:37:57Z | [
"python",
"list",
"punctuation"
] |
Find out all the punctuations in a sentence that has been put into a list | 39,934,679 | <p>I have this variable:</p>
<pre><code>Words = ["Hi",".","how","are","you","?","I","feel","like","I","could",",","do","better"]
</code></pre>
<p>From this I want a variable that finds all the punctuations and puts it into a list as well. Like this:</p>
<pre><code>Punctuations = [".","?",","]
</code></pre>
| 1 | 2016-10-08T16:26:24Z | 39,934,966 | <p>The solution using <code>re.findall</code> function:</p>
<pre><code>import re
Words = ["Hi",".","how","are","you","?","I","feel","like","I","could",",","do","better"]
Punctuations = re.findall("[^\w\s]+", ''.join(Words))
print(Punctuations) # ['.', '?', ',']
</code></pre>
| 0 | 2016-10-08T16:57:29Z | [
"python",
"list",
"punctuation"
] |
Invalid format specifier for thousands place | 39,934,706 | <p>I am trying to make a simple chart like output. Here are strings that I want to display:</p>
<p>a = "name", b = "10000.00", c = "code", d = "45.60", e = "30.00"</p>
<pre><code>print("{0:20}${1:,20}{2:20}${3:,20}${4:,<5}".format(a,b,c,d,e),file=outfile)
</code></pre>
<p>I put "," to indicate thousands place in ... | 1 | 2016-10-08T16:29:13Z | 39,934,825 | <p>As per the <a href="https://docs.python.org/3/library/string.html#format-specification-mini-language" rel="nofollow">docs</a>, width has to go after comma. Moreover, your <code>b</code> variable has to be a number (and not a string, as in your MWE):</p>
<pre><code>>>> x = 10000.0
>>> '{0:20,}'.for... | 0 | 2016-10-08T16:42:24Z | [
"python"
] |
Lowest common ancestor in python's NetworkX | 39,934,721 | <p>Using NetworkX</p>
<p>I want to get lowest common ancestor from node1 and node11 in DiGraph.</p>
<p>The following is the code.</p>
<pre><code>import networkx as nx
G = nx.DiGraph() #Directed graph
G.add_nodes_from([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
G.add_edges_from([(2,1),(3,1),(4,1),(5,2),(6,2),(7,3),(8,3),... | 2 | 2016-10-08T16:30:27Z | 39,935,416 | <p>Rerunning Dijkstra in a loop indeed seems like an overkill.</p>
<p>Say we build the digraph obtained by <em>reversing</em> the edges:</p>
<pre><code>import networkx as nx
G = nx.DiGraph() #Directed graph
G.add_nodes_from([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
edges = [(2,1),(3,1),(4,1),(5,2),(6,2),(7,3),(8,3),(9,... | 3 | 2016-10-08T17:42:12Z | [
"python",
"algorithm",
"networkx",
"lowest-common-ancestor"
] |
How to access re-raised exception in Python 3? | 39,934,738 | <p>In Python 3, there's a <a href="https://blog.ionelmc.ro/2014/08/03/the-most-underrated-feature-in-python-3/" rel="nofollow">useful <code>raise ... from ...</code> feature</a> to re-raise an exception. That said, how do you find the original (/ re-raised) exception from the raised exception? Here's a (silly) example ... | 2 | 2016-10-08T16:32:29Z | 39,934,807 | <p>It's in the <code>__cause__</code> attribute of the raised exception. Taken from the <a href="https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement" rel="nofollow">docs on the <code>raise</code> statement</a> it says regarding <code>raise ... from ...</code>:</p>
<blockquote>
<p>The <code>from... | 3 | 2016-10-08T16:40:39Z | [
"python",
"python-3.x",
"exception",
"exception-handling"
] |
How to access re-raised exception in Python 3? | 39,934,738 | <p>In Python 3, there's a <a href="https://blog.ionelmc.ro/2014/08/03/the-most-underrated-feature-in-python-3/" rel="nofollow">useful <code>raise ... from ...</code> feature</a> to re-raise an exception. That said, how do you find the original (/ re-raised) exception from the raised exception? Here's a (silly) example ... | 2 | 2016-10-08T16:32:29Z | 39,934,808 | <p>Whenever an exception is raised from an exception handler (the <code>except</code> clause), the original exception will bestored in new exception's <code>__context__</code>.</p>
<p>Whenever an exception is raised using <code>from</code> syntax, the exception specified in <code>from</code> will be saved in the <code... | 1 | 2016-10-08T16:40:55Z | [
"python",
"python-3.x",
"exception",
"exception-handling"
] |
merge two lists of dictionaries in python? | 39,934,750 | <p>I have two lists of dictionaries:</p>
<pre><code>old = [{'a':'1','b':'2'},{'a':'2','b':'3'},{'a':'3','b':'4'},{'a':'4','b':'5'}]
new = [{'a':'1','b':'100'},{'a':'2','b':'100'},{'a':'5','b':'6'}]
</code></pre>
<p>How can I merge two lists of dictionaries to get:</p>
<pre><code>update = [{'a':'1','b':'2,100'},{'a':... | 0 | 2016-10-08T16:33:36Z | 39,935,532 | <p>If 'a' is the real key here and b is the value, imo it would be easier to convert the list of dicts into one dict, process the merge and then convert it back. This way you can use the standard functions.</p>
<p>Convert into one dict where a is the key:</p>
<pre><code>def intoRealDict(listOfDicts):
values = []
... | 0 | 2016-10-08T17:54:39Z | [
"python",
"list",
"dictionary"
] |
Get intellij python to autocomplete on tab instead of space (and tab) which is does now | 39,934,771 | <p>Is there a way to prevent intelli(Idea) pycharm plugin from not autocompleting on space; I want autocomplete only when I hit the tab.
Space to me means I want to continue typing without being bothered.</p>
<p>E.g. I'm trying to say something like d = 0.
Idea forces me to escape. A space will autocomplete to delatt... | 0 | 2016-10-08T16:36:02Z | 39,935,108 | <p>You can disable "Settings | Editor | General | Code Completion | Insert selected variant by typing dot, space, etc", then only Enter and Tab will choose the selected item in autopopup completion.</p>
| 2 | 2016-10-08T17:13:06Z | [
"python",
"intellij-idea",
"autocomplete"
] |
make a list from string json? python | 39,934,782 | <p>I have a json string i get it from json array below i have given it </p>
<pre><code>annotation = sentence["annotation"]
text = sentence["text"]
#ioblist = [annotation]
ioblist=[[x[0], x[4]] for x in annotation] #nothing
</code></pre>
<p>the proram did not convert here is my string in list at index 0 </p>
<pre><... | -1 | 2016-10-08T16:37:04Z | 39,934,804 | <p><code>range()</code> gives you a iterable of integers, but your dictionary keys are <code>u'...'</code>, i.e. unicode strings. Hence, the lookup <code>ioblist[0]</code> must fail, since <code>0 != u'0'</code> (Python isn't PHP, thankfully).</p>
| 0 | 2016-10-08T16:40:30Z | [
"python"
] |
Popen in a function is blocking that function from being executed in a separate thread | 39,934,799 | <p>I'm trying to execute a binary from a python program (under Linux) and would like to dedicate this to a separate thread. Edit: The binary will run for quite a while and write data to disk. It would be nice if I could retreive stdout and stderr in python so that I can write this to a log. It would also be nice if I c... | 0 | 2016-10-08T16:39:31Z | 39,936,769 | <p>Your <code>record</code> function doesn't work as intended not because of the <code>Popen</code> call but because it's a generator function (because it contains a <code>yield</code> statement). Generator functions don't actually run their code when you call them. Instead, they return a generator object immediately, ... | 1 | 2016-10-08T19:57:35Z | [
"python",
"multithreading"
] |
Popen in a function is blocking that function from being executed in a separate thread | 39,934,799 | <p>I'm trying to execute a binary from a python program (under Linux) and would like to dedicate this to a separate thread. Edit: The binary will run for quite a while and write data to disk. It would be nice if I could retreive stdout and stderr in python so that I can write this to a log. It would also be nice if I c... | 0 | 2016-10-08T16:39:31Z | 39,937,315 | <p>With some small fixes, your code runs:</p>
<ul>
<li>got rid of the generator function, doesn't make sense with threads</li>
<li>simplified the way to get output from the process, but still read line by line (reading the final output with <code>communicate</code> would work but you seem to require having the lines p... | 1 | 2016-10-08T20:59:59Z | [
"python",
"multithreading"
] |
Is pandas read_csv really slow compared to python open? | 39,934,801 | <p>my requirement is to remove duplicate rows from csv file, but the size of the file is 11.3GB. So I bench marked the pandas and python file generator.</p>
<p><strong>Python File Generator:</strong></p>
<pre><code>def fileTestInPy():
with open(r'D:\my-file.csv') as fp, open(r'D:\mining.csv', 'w') as mg:
... | 0 | 2016-10-08T16:39:52Z | 39,934,895 | <p>Pandas is not a good choice for this task. It reads the entire 11.3G file into memory and does string-to-int conversions on all of the columns. I'm not surprised that your machine bogged down!</p>
<p>The line-by-line version is much leaner. It doesn't do any conversions, doesn't bother looking at unimportant column... | 1 | 2016-10-08T16:50:21Z | [
"python",
"windows",
"python-3.x",
"pandas",
"python-3.5"
] |
Dictionary counter | 39,934,806 | <p>Let's say I have a sequence "ADFG"
The script should see if it's in the list (A,T,G,C) and then if it is, get the key from the dictionary and add 1.
So, for the sequence "ADFG", it would add 1 to variable "a" and to variable "g", and add 2 to variable "error".
However, while the script isn't returning an error, the ... | 0 | 2016-10-08T16:40:39Z | 39,934,875 | <p>you mean that t,g,c are unaffected by the adding in <code>dicio</code></p>
<p>That's normal: dictionary has not taken the references of the variables, but just copied the initial values. You're not updating them when you add 1 to the values of the dictionary.
(<code>a</code> is a special case in your code, it gets ... | 0 | 2016-10-08T16:48:02Z | [
"python",
"python-3.x",
"dictionary",
"count"
] |
Dictionary counter | 39,934,806 | <p>Let's say I have a sequence "ADFG"
The script should see if it's in the list (A,T,G,C) and then if it is, get the key from the dictionary and add 1.
So, for the sequence "ADFG", it would add 1 to variable "a" and to variable "g", and add 2 to variable "error".
However, while the script isn't returning an error, the ... | 0 | 2016-10-08T16:40:39Z | 39,935,152 | <p>I think you're trying to use dictionaries to store the values instead of having <code>a,t,g,c</code> be connected to it and updated at the same time. Here's some code that uses some dictionary features to make it a little more concise: </p>
<pre><code>seq= input ("dna seq:").upper()
a,t,g,c,error=0,0,0,0,0
dicio=... | 0 | 2016-10-08T17:17:22Z | [
"python",
"python-3.x",
"dictionary",
"count"
] |
How to only make a variable decrease once before a while loop repeats (Python) | 39,934,847 | <p>At school I have to do a mini homework of programming a quiz. In this quiz, a user has to input the answer. If they're right, they move straight onto the next question, if they're wrong, then the attempts they have left decrease by 1.
I'm using a while loop to make sure that while the amount of attempts there are le... | 0 | 2016-10-08T16:44:26Z | 39,934,872 | <p>You should move the <code>input</code> inside the loop:</p>
<pre><code>while trys != 0:
answer1 = int(input("What is 420 X 15?\n"))
# ...
</code></pre>
| 1 | 2016-10-08T16:47:51Z | [
"python",
"while-loop"
] |
How to only make a variable decrease once before a while loop repeats (Python) | 39,934,847 | <p>At school I have to do a mini homework of programming a quiz. In this quiz, a user has to input the answer. If they're right, they move straight onto the next question, if they're wrong, then the attempts they have left decrease by 1.
I'm using a while loop to make sure that while the amount of attempts there are le... | 0 | 2016-10-08T16:44:26Z | 39,934,954 | <p>You should make your input inside the loop so each time it take from the user the input and check if trys reach zero so the work code should be like this for the question <br></p>
<pre><code>trys = 3
while trys != 0:
answer1 = int(input("What is 420 X 15?\n"))
if answer1 == 420*15:
print("Correct!")... | 1 | 2016-10-08T16:56:42Z | [
"python",
"while-loop"
] |
Combination of PyCharm and ipython fails to import qt5 or Qt5Agg | 39,934,861 | <p>I have installed elementary os and Pycharm and the whole python stack via <code>conda</code>, and now have troubles starting interactive matplotlib in the <code>ipython</code> sesssion.</p>
<p>Here's pycharm's ipython session:</p>
<pre><code>/home/foo/.conda/envs/myenv3/bin/python3.5 /opt/pycharm-2016.2.3/helpers/... | 0 | 2016-10-08T16:46:05Z | 39,944,039 | <p>Pycharm appears to not fully support <code>qt5</code>, the issue is <a href="https://youtrack.jetbrains.com/issue/PY-20981" rel="nofollow">open</a>. Downgrading it is the fastest workaround. </p>
<p>With conda the following will perform a downgrade to the last stable version:</p>
<pre><code>conda install pyqt=4.11... | 1 | 2016-10-09T13:15:17Z | [
"python",
"matplotlib",
"pyqt",
"ipython",
"pycharm"
] |
Deploying Flask Application with pandas to Elastic Beanstalk | 39,934,889 | <p>I a new to AWS. Trying to deploy a simple flask application to AWS. I had no problem until I included pandas package. </p>
<p>No even with the simplest application I get errors such as "your requirements.txt file is invalid". </p>
<p>My test application is very simple:
There are only two files in the folder
appli... | 1 | 2016-10-08T16:49:40Z | 39,935,606 | <p>I have had the same problem deploying a django app to EBS with pandas, and the issue was that there are certain C libraries that need to be installed first. Just add this in your .ebextensions folder:</p>
<pre><code>commands:
install_devtools:
command: yum -y groupinstall 'Development tools'
</code></pre>
<p... | 0 | 2016-10-08T18:02:29Z | [
"python",
"amazon-web-services",
"pandas",
"flask",
"elastic-beanstalk"
] |
Python: selenium select | 39,934,896 | <p>I have a website with some different prices currencies you can select in a <code><select></code> with <code><option></code>, it looks like this:</p>
<pre><code><div class="menu" style="display: none;">
<p class="current-country">
<span class="flag store-7"></span... | 0 | 2016-10-08T16:50:25Z | 39,950,929 | <pre><code># -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.except... | 1 | 2016-10-10T03:32:00Z | [
"python",
"selenium"
] |
Storing updated variables in a loop? | 39,934,898 | <p>I have written this program which asks the user about how many rectangles they wants to print out. It also asks for the width and height of each, and prints the triangles. After asking the height and width of each, it moves onto the next rectangle and so on. </p>
<p>This all works fine using the program I've made b... | 0 | 2016-10-08T16:50:51Z | 39,934,946 | <p>How about you just accumulate the total area?</p>
<p>Above your loop, do:</p>
<pre><code>area = 0
</code></pre>
<p>Then, somewhere inside your loop, after you've got <code>w</code> and <code>h</code> from the user, just do</p>
<pre><code>area += w * h
</code></pre>
<p>When you finish looping, <code>area</code> ... | 3 | 2016-10-08T16:56:11Z | [
"python",
"python-2.7"
] |
Storing updated variables in a loop? | 39,934,898 | <p>I have written this program which asks the user about how many rectangles they wants to print out. It also asks for the width and height of each, and prints the triangles. After asking the height and width of each, it moves onto the next rectangle and so on. </p>
<p>This all works fine using the program I've made b... | 0 | 2016-10-08T16:50:51Z | 39,935,049 | <p>This code should really use a for loop instead of a while loop to keep track of counters, keep numbers in variables instead of just "*" strings, and use += instead of x=x+1 in a few places, among other things, but here's a minimal step to solve the total area problem you specifically asked about:</p>
<pre><code>siz... | 2 | 2016-10-08T17:06:01Z | [
"python",
"python-2.7"
] |
Installed Virtualenv and activating virtualenv doesn't work | 39,934,906 | <p>I cloned my Django Project from Github Account and activated the virtualenv using famous command <code>source nameofenv/bin/activate</code>
And when I run <code>python manage.py runserver</code> </p>
<p>It gives me an error saying:</p>
<blockquote>
<p>ImportError: Couldn't import Django. Are you sure it's instal... | 0 | 2016-10-08T16:51:48Z | 39,935,137 | <p>on ubuntu version</p>
<pre><code>#install python pip
sudo apt-get install python-pip
#install python virtualenv
sudo apt-get install python-virtualenv
# create virtual env
virtualenv myenv
#activate the virtualenv
. myenv/bin/activate
#install django inside virtualenv
pip install django
#create a new django proj... | 1 | 2016-10-08T17:15:36Z | [
"python",
"django",
"virtualenv"
] |
Installed Virtualenv and activating virtualenv doesn't work | 39,934,906 | <p>I cloned my Django Project from Github Account and activated the virtualenv using famous command <code>source nameofenv/bin/activate</code>
And when I run <code>python manage.py runserver</code> </p>
<p>It gives me an error saying:</p>
<blockquote>
<p>ImportError: Couldn't import Django. Are you sure it's instal... | 0 | 2016-10-08T16:51:48Z | 39,936,492 | <blockquote>
<p>I was thinking that every and each dependency I need, might be present inside virtualenv.</p>
</blockquote>
<p>Well, no. By default, a newly created virtualenv comes empty, that is, with no third-party library. (Optionaly, you may allow a virtualenv to access libraries installed system-wide, but that... | 1 | 2016-10-08T19:28:22Z | [
"python",
"django",
"virtualenv"
] |
Installed Virtualenv and activating virtualenv doesn't work | 39,934,906 | <p>I cloned my Django Project from Github Account and activated the virtualenv using famous command <code>source nameofenv/bin/activate</code>
And when I run <code>python manage.py runserver</code> </p>
<p>It gives me an error saying:</p>
<blockquote>
<p>ImportError: Couldn't import Django. Are you sure it's instal... | 0 | 2016-10-08T16:51:48Z | 39,936,515 | <p>I'm guessing you also upload the virtual environment from your other pc. And you hope that only activating that will works, bzz.</p>
<p>It's not recommended to upload the virtualenv files to your git repository, as @Alain says it's a good practice to have a <code>requirements.txt</code> file containing the project ... | 0 | 2016-10-08T19:30:50Z | [
"python",
"django",
"virtualenv"
] |
Python version/import confusion | 39,934,909 | <p>I'm trying to get this Python 2.7 code to work.</p>
<p><a href="https://github.com/slanglab/phrasemachine" rel="nofollow">https://github.com/slanglab/phrasemachine</a></p>
<p>I've downloaded and unzipped the repo from github. Here's what happens when I try to run the code.</p>
<pre><code>phrasemachine$ python
Pyt... | 0 | 2016-10-08T16:52:02Z | 39,937,305 | <p>Since you have two python distributions, you also need two versions of <code>pip</code>. Find out where your <code>pip</code> executables are with <code>which -a pip</code>, and install <code>pip</code> for your Python 2.7 distribution if necessary. Then tell the <code>pip</code> that goes with Python 2.7 (perhaps ... | 1 | 2016-10-08T20:58:57Z | [
"python",
"osx",
"python-3.x",
"pip",
"nltk"
] |
Retrieve Tkinter Checkbutton Status : TclError: can't read "PY_VAR": no such variable | 39,934,913 | <p>I am using <code>Tkinter</code> in a basic Python 2.7 GUI application and I would like to retrieve the <code>Checkbutton</code> widget status (checked/unchecked) by using a <code>IntVar</code> but I am getting the following error. </p>
<pre><code>TclError: can't read "PY_VAR": no such variable
</code></pre>
<p>I h... | 0 | 2016-10-08T16:52:14Z | 39,935,242 | <p>EDIT: First create n number of var for use and than asign for each button and save in a list.</p>
<pre><code>def createWidgets(self,master):
self.vars=[]
for n in range(0,4):
var = tk.IntVar()
self.vars.append(var)
for n in range(0,4):
button = tk.Checkbutton(
master... | 2 | 2016-10-08T17:25:21Z | [
"python",
"python-2.7",
"user-interface",
"tkinter"
] |
Checking if input's characters match the ones given in Python | 39,935,019 | <p>I'm in a Python course for beginners.
We have to create a code that turns input of maximum 6 words into an acronym. </p>
<p>Before creating an acronym, it has to check if the words contain only characters from given set, but I can't just check if it's in alphabet as we are using our local alphabet that has special ... | 0 | 2016-10-08T17:02:47Z | 39,935,060 | <p>Simplest way is to check if the set of characters in the word is a subset of the alphabet using <code>set(word).issubset(alphabet)</code>. For example:</p>
<pre><code>alpha_set = set("best")
print set("test").issubset(alpha_set)
print set("testa").issubset(alpha_set)
</code></pre>
<p>prints:</p>
<pre><code>True
... | 1 | 2016-10-08T17:07:28Z | [
"python",
"acronym"
] |
Checking if input's characters match the ones given in Python | 39,935,019 | <p>I'm in a Python course for beginners.
We have to create a code that turns input of maximum 6 words into an acronym. </p>
<p>Before creating an acronym, it has to check if the words contain only characters from given set, but I can't just check if it's in alphabet as we are using our local alphabet that has special ... | 0 | 2016-10-08T17:02:47Z | 39,937,024 | <p>You can use <a href="https://docs.python.org/3.4/howto/regex.html#regex-howto" rel="nofollow">regular expressions</a> to check if every word in your text matches a certain pattern. The pattern in your case is that all characters in a word should be letters of the alphabet : uppercase <strong>A-Z</strong> as well as ... | 0 | 2016-10-08T20:26:40Z | [
"python",
"acronym"
] |
How does 'range()' work internally? | 39,935,042 | <p>How does the range() differentiate the call being made in this case?</p>
<p><strong>Example:</strong></p>
<pre><code>def ex():
list = [1,2,3,4]
for val in range(len(list)):
print(val)
break
for val in range(len(list)):
print(val)
break
</code></pre>
<p><strong>Output -<... | 0 | 2016-10-08T17:05:25Z | 39,935,074 | <p>I'm not sure why you expect <code>range</code> <em>would</em> remember that it had been called previously. The class does not maintain any state about previous calls; it simply does what you ask. Each call to <code>range(x)</code> returns a new <code>range</code> object that provides numbers from 0 to <code>x-1</cod... | 6 | 2016-10-08T17:08:47Z | [
"python",
"range"
] |
How should a Python module be structured? | 39,935,054 | <p>This is my first time posting on stack overflow, so I apologize if I do something wrong.</p>
<p>I am trying to understand the best way to structure a Python module. As an example, I made a backup module that syncs the source and destination, only copying files if there are differences between source and destination... | 1 | 2016-10-08T17:06:33Z | 39,936,521 | <p>This method (and several others) is wrong:</p>
<pre><code>def copy(source, destination):
"""Copies source file, directory, or symlink to destination"""
</code></pre>
<p>It works the way it was used (<code>Backup.copy(scurr, dcurr)</code>), but it does not work when used on an instance.</p>
<p>All methods in P... | 0 | 2016-10-08T19:31:18Z | [
"python"
] |
return multiple values from scipy root finding / optimization function | 39,935,131 | <p>I'm trying to return multiple values that are obtained inside a scipy root finding function (scipy.optimize.root).</p>
<p>For example:</p>
<pre><code>B = 1
def testfun(x, B):
B = x + 7
return B**2 + 9/18 - x
y = scipy.optimize.root(testfun, 7, (B))
</code></pre>
<p>Is there any way to return the value of... | 1 | 2016-10-08T17:15:17Z | 39,936,198 | <p>I'm not aware of anything SciPy specific, but how about a simple closure:</p>
<pre><code>from scipy import optimize
def testfun_factory():
params = {}
def testfun(x, B):
params['B'] = x + 7
return params['B']**2 + 9/18 - x
return params, testfun
params, testfun = testfun_factory()
y = ... | 1 | 2016-10-08T18:59:03Z | [
"python",
"function",
"optimization",
"scipy"
] |
Mine Tweets between two dates in Python | 39,935,150 | <p>I would like to mine tweets for two keywords for a specific period of time. I currently have the code below, but how do I add so it only mine tweets between two dates? (10/03/2016 - 10/07/2016) Thank you!</p>
<pre><code>#Import the necessary methods from tweepy library
from tweepy.streaming import StreamListener
fr... | 0 | 2016-10-08T17:17:02Z | 39,935,340 | <p>You can't. Have a look at <a href="http://stackoverflow.com/questions/26205102/making-very-specific-time-requests-to-the-second-on-twitter-api-using-python">this question</a>, that is the closest you can get.</p>
<p>The Twitter API does not allow to search by time. Trivially, what you can do is fetching tweets and ... | 1 | 2016-10-08T17:35:21Z | [
"python",
"twitter"
] |
Dividing a Pandas series with the same series shifted one place | 39,935,169 | <p>I have a Pandas series, a time and a value.
I would like to calculate the changes between each value.
Like this: current value / previous value.</p>
<p>When I run this code:</p>
<pre><code>print now.head(n=3)
print before.head(n=3)
delta = now.divide(before)
print delta.iloc[1]
print now.iloc[1] / before.iloc[1]
<... | 0 | 2016-10-08T17:18:48Z | 39,935,230 | <p>the problem is that when you do <code>delta = now.divide(before)</code>it will match indexes. so delta.iloc[1] will be <code>623.53836 / 623.53836</code> representing the division on <code>2014-01-08 09:27:00</code> index</p>
<p>when you use integer location <code>now.iloc[1] / before.iloc[1]</code> it doesn't care... | 0 | 2016-10-08T17:24:18Z | [
"python",
"pandas"
] |
Dividing a Pandas series with the same series shifted one place | 39,935,169 | <p>I have a Pandas series, a time and a value.
I would like to calculate the changes between each value.
Like this: current value / previous value.</p>
<p>When I run this code:</p>
<pre><code>print now.head(n=3)
print before.head(n=3)
delta = now.divide(before)
print delta.iloc[1]
print now.iloc[1] / before.iloc[1]
<... | 0 | 2016-10-08T17:18:48Z | 39,935,513 | <p>You could divide by the values:</p>
<pre><code>now['delta'] = now.values / before.values
</code></pre>
<p>This will add a new column to your now dataframe of course. </p>
<p>Alternately, if you want this in its own dataframe you could write:</p>
<pre><code>delta = now.copy()
delta['delta'] = now.close.values / b... | 0 | 2016-10-08T17:52:49Z | [
"python",
"pandas"
] |
Create nested list using list comprehension | 39,935,226 | <p>I have two lists:</p>
<pre><code>L1 = [3, 5, 7, 8, 9, 5, 6, 7, 4, 3]
L2 = [1, 4, 5, 8, 3, 6, 9, 3, 5, 9]
</code></pre>
<p>And I need to create sub-list for each item in L2 that is smaller than 4, add it to all the numbers in L1 that are smaller than 4.
I tried doing this:</p>
<pre><code>result = [(x+y) for x in L... | 1 | 2016-10-08T17:24:06Z | 39,935,260 | <p>Create a nested list comprehension </p>
<pre><code>>>> [[(x+y) for y in L1 if y < 4] for x in L2 if x < 4]
[[4, 4], [6, 6], [6, 6]]
</code></pre>
<p>Here the inner list comprehension creates the inner lists which are then appended to a single list by the outer comprehension. </p>
| 6 | 2016-10-08T17:26:54Z | [
"python",
"list",
"list-comprehension",
"nested-lists"
] |
Create nested list using list comprehension | 39,935,226 | <p>I have two lists:</p>
<pre><code>L1 = [3, 5, 7, 8, 9, 5, 6, 7, 4, 3]
L2 = [1, 4, 5, 8, 3, 6, 9, 3, 5, 9]
</code></pre>
<p>And I need to create sub-list for each item in L2 that is smaller than 4, add it to all the numbers in L1 that are smaller than 4.
I tried doing this:</p>
<pre><code>result = [(x+y) for x in L... | 1 | 2016-10-08T17:24:06Z | 39,935,277 | <p>The numbers below 4 in L1 are:</p>
<pre><code>L1_below_4 = [x for x in L1 if x < 4]
</code></pre>
<p>And for L2:</p>
<pre><code>L2_below_4 = [y for y in L2 if y < 4]
</code></pre>
<p>Now it's easy:</p>
<pre><code>[[x + y for x in L1_below_4] for y in L2_below_4]
</code></pre>
<p>Or as a one-liner:</p>
<... | 1 | 2016-10-08T17:28:48Z | [
"python",
"list",
"list-comprehension",
"nested-lists"
] |
Self learning url filter | 39,935,279 | <p>I need to classify given urls as porn or non porn via python script (not by visiting them in person and watching videos) and I thought about calculating porn probability for each url by classifying words it contains, e.g. if url contains words 'bang' and '18' there is high probability its porn site, I tried implemen... | 0 | 2016-10-08T17:28:49Z | 39,935,826 | <p>This is a good use case for logistic regression, but it's not a very good question for Stack Overflow. If you already have the training data, go find a tool (or implement this yourself because it wouldn't be that difficult) and then ask a question about the troubles you're having getting it to work. Stack Overflow... | 1 | 2016-10-08T18:24:02Z | [
"python",
"machine-learning",
"artificial-intelligence"
] |
Self learning url filter | 39,935,279 | <p>I need to classify given urls as porn or non porn via python script (not by visiting them in person and watching videos) and I thought about calculating porn probability for each url by classifying words it contains, e.g. if url contains words 'bang' and '18' there is high probability its porn site, I tried implemen... | 0 | 2016-10-08T17:28:49Z | 39,935,832 | <p>The modern approach to do this is to use a character level LSTM sequence classifier. It requires a fairly large amount of data though, but it shouldn't be too hard to find, by getting examples of family filter black lists for example. </p>
<p>Here are some examples of the concept: </p>
<ul>
<li>I would start here,... | 1 | 2016-10-08T18:24:29Z | [
"python",
"machine-learning",
"artificial-intelligence"
] |
Safely using for-loop variables outside the loop | 39,935,281 | <p><a href="http://stackoverflow.com/a/3611987/336527">Most arguments</a> about why the design decision was made to make for-loop variables <em>not</em> local to the loop suggest that there are popular use cases.</p>
<p>The obvious use case is this:</p>
<pre><code>x = default_value
for x in iterator:
# do stuff
#... | 1 | 2016-10-08T17:28:54Z | 39,935,817 | <p>There is no 100% safe way to rely on a variable being set inside a for-loop unless you can be 100% sure that the iterator is never empty. To achieve the 100% assurance, you could do something like <code>for x in iterator or [None]:</code>, but this poses a similar "remembering to do it" problem. It is probably more ... | 0 | 2016-10-08T18:23:28Z | [
"python",
"python-3.x",
"scope"
] |
Safely using for-loop variables outside the loop | 39,935,281 | <p><a href="http://stackoverflow.com/a/3611987/336527">Most arguments</a> about why the design decision was made to make for-loop variables <em>not</em> local to the loop suggest that there are popular use cases.</p>
<p>The obvious use case is this:</p>
<pre><code>x = default_value
for x in iterator:
# do stuff
#... | 1 | 2016-10-08T17:28:54Z | 39,935,819 | <p>I agree that the most obvious reason for loops not to have their own scope, is the complications that would introduce when assigning values to variables in the outer scope.</p>
<p>But that does not necessarily mean the iterated value. Consider the following:</p>
<pre><code>total = 0
for item in some_list:
tota... | 0 | 2016-10-08T18:23:33Z | [
"python",
"python-3.x",
"scope"
] |
Python Get Variable Name Inside Class | 39,935,305 | <p>In Python 3, if you have a class, like this:</p>
<pre><code>LETTERS = list('abcdefghijklmnopqrstuvwxyz')
class letter:
def __init__(self, name):
self.number = LETTERS.index(name)
self.nextLetter = LETTERS[self.number+1]
self.previousLetter = LETTERS[self.number-1]
</code></pre>
<p>and y... | 0 | 2016-10-08T17:31:01Z | 39,935,801 | <p>Think of <code>myLetter</code> as a pointer to the class instance of <code>letter</code>. For example, if you have:</p>
<pre><code>LETTERS = list('abcdefghijklmnopqrstuvwxyz')
class letter:
def __init__(self, name):
self.number = LETTERS.index(name)
self.nextLetter = LETTERS[self.number+1]
... | 2 | 2016-10-08T18:22:19Z | [
"python",
"class",
"python-3.x"
] |
pip install bs4 giving _socketobject error | 39,935,335 | <p>I am trying to install BeautifulSoup4 using the command <code>pip install BeautifulSoup4</code>, as per the bs documentation here:</p>
<p><a href="https://www.crummy.com/software/BeautifulSoup/#Download">https://www.crummy.com/software/BeautifulSoup/#Download</a></p>
<p>I am using Mac OS X 10.7.5, and python 2.7.1... | 7 | 2016-10-08T17:34:30Z | 40,023,593 | <p>From what I understand, the <em><code>pyopenssl</code> package version installed system-wide is not up-to-date</em>. Upgrade it:</p>
<pre><code>sudo pip install --upgrade pyopenssl
</code></pre>
<p>Or, remove it and install the latest in your virtual environment:</p>
<pre><code>$ sudo pip uninstall pyopenssl
$ # ... | 1 | 2016-10-13T14:18:29Z | [
"python",
"python-2.7",
"beautifulsoup"
] |
pip install bs4 giving _socketobject error | 39,935,335 | <p>I am trying to install BeautifulSoup4 using the command <code>pip install BeautifulSoup4</code>, as per the bs documentation here:</p>
<p><a href="https://www.crummy.com/software/BeautifulSoup/#Download">https://www.crummy.com/software/BeautifulSoup/#Download</a></p>
<p>I am using Mac OS X 10.7.5, and python 2.7.1... | 7 | 2016-10-08T17:34:30Z | 40,042,425 | <p>Alternatively, you can install Anaconda Python from: <a href="https://www.continuum.io/downloads" rel="nofollow">https://www.continuum.io/downloads</a></p>
<p>This installation includes BS out of the box as most of the common libraries you will use. Plus it makes library installation quite easy.</p>
| 0 | 2016-10-14T11:47:07Z | [
"python",
"python-2.7",
"beautifulsoup"
] |
pip install bs4 giving _socketobject error | 39,935,335 | <p>I am trying to install BeautifulSoup4 using the command <code>pip install BeautifulSoup4</code>, as per the bs documentation here:</p>
<p><a href="https://www.crummy.com/software/BeautifulSoup/#Download">https://www.crummy.com/software/BeautifulSoup/#Download</a></p>
<p>I am using Mac OS X 10.7.5, and python 2.7.1... | 7 | 2016-10-08T17:34:30Z | 40,078,202 | <p>I'm using <code>OS X 10.12</code> and <code>python 2.7.10</code></p>
<pre><code>sudo easy_install BeautifulSoup4
sudo easy_install pyopenssl
</code></pre>
<p>They all worked fine.</p>
| 0 | 2016-10-17T03:46:11Z | [
"python",
"python-2.7",
"beautifulsoup"
] |
pip install bs4 giving _socketobject error | 39,935,335 | <p>I am trying to install BeautifulSoup4 using the command <code>pip install BeautifulSoup4</code>, as per the bs documentation here:</p>
<p><a href="https://www.crummy.com/software/BeautifulSoup/#Download">https://www.crummy.com/software/BeautifulSoup/#Download</a></p>
<p>I am using Mac OS X 10.7.5, and python 2.7.1... | 7 | 2016-10-08T17:34:30Z | 40,095,393 | <p>See <a href="http://stackoverflow.com/a/31576259/3579910">http://stackoverflow.com/a/31576259/3579910</a>:</p>
<p>Try:</p>
<pre><code>sudo apt-get purge python-openssl
sudo apt-get install libffi-dev
sudo pip install pyopenssl
</code></pre>
<p>Apparently you can't vote duplicate if there is an open bounty.</p>
<... | 0 | 2016-10-17T20:47:34Z | [
"python",
"python-2.7",
"beautifulsoup"
] |
pip install bs4 giving _socketobject error | 39,935,335 | <p>I am trying to install BeautifulSoup4 using the command <code>pip install BeautifulSoup4</code>, as per the bs documentation here:</p>
<p><a href="https://www.crummy.com/software/BeautifulSoup/#Download">https://www.crummy.com/software/BeautifulSoup/#Download</a></p>
<p>I am using Mac OS X 10.7.5, and python 2.7.1... | 7 | 2016-10-08T17:34:30Z | 40,100,036 | <p>"That happend because your OS has old pyOpenSSL library which is does not an accept attribute 'set_tlsext_host_name'.
To fix this, you need to add dependence pyOpenSSL >= 0.13.</p>
<pre><code>$ brew purge python-openssl
$ brew install libffi-dev
$ brew install pyOpenSSL
</code></pre>
<p>Let me know if this is uncl... | 1 | 2016-10-18T05:14:31Z | [
"python",
"python-2.7",
"beautifulsoup"
] |
Multiple regression output nodes in tensorflow learn | 39,935,394 | <p>I am relatively new to tensorflow and want to use the DNNRegressor from tf.contrib.learn for a regression task. But instead of one output node, I would like to have several (let's say ten for example). </p>
<p>How can I configure my regressor to adjust many output nodes to fit my needs? </p>
<p>My question is rela... | 1 | 2016-10-08T17:39:37Z | 40,039,971 | <p>It seems using tflearn will be the other choice.</p>
<p>Update: I realize we should use Keras as an well developed API for tensorflow+ theano .</p>
| 1 | 2016-10-14T09:41:51Z | [
"python",
"tensorflow",
"skflow"
] |
python3 exception invalid syntax error | 39,935,486 | <p>I recently started learning python3, and I am trying to write an exception.
I have this line, which is a list of words.
I want to match the word create to the list, sometimes it's there sometimes its not. When it's not there I get this error:</p>
<pre><code>Traceback (most recent call last):
File "sub_process.py"... | -2 | 2016-10-08T17:49:48Z | 39,935,502 | <p>You need to add <code>try</code> before the <code>if</code> statement:</p>
<pre><code>line = line.split()
try: # added 'try'
if line.index("create"):
print("basd");
except ValueError:
print("123");
</code></pre>
<p>Also note, you don't need the semicolons at the end of statements, and it is general... | 0 | 2016-10-08T17:51:54Z | [
"python",
"exception"
] |
python3 exception invalid syntax error | 39,935,486 | <p>I recently started learning python3, and I am trying to write an exception.
I have this line, which is a list of words.
I want to match the word create to the list, sometimes it's there sometimes its not. When it's not there I get this error:</p>
<pre><code>Traceback (most recent call last):
File "sub_process.py"... | -2 | 2016-10-08T17:49:48Z | 39,935,531 | <p>if/except is not a valid construct. Use try/except:</p>
<pre><code>line = line.split()
try:
if line.index('create'):
print('basd')
except ValueError:
print("123")
</code></pre>
<p>Alternatively, you could avoid the exception and the try/except altogether:</p>
<pre><code>line = line.split()
if '... | 1 | 2016-10-08T17:54:34Z | [
"python",
"exception"
] |
python3 exception invalid syntax error | 39,935,486 | <p>I recently started learning python3, and I am trying to write an exception.
I have this line, which is a list of words.
I want to match the word create to the list, sometimes it's there sometimes its not. When it's not there I get this error:</p>
<pre><code>Traceback (most recent call last):
File "sub_process.py"... | -2 | 2016-10-08T17:49:48Z | 39,935,543 | <p>Rather than using <code>index</code>, you should just be using the <code>in</code> operator, which returns a simple boolean:</p>
<pre><code>if "create" in line:
print("basd")
else:
print("123")
</code></pre>
<p>This will not raise an exception so there is no need for try/except.</p>
| 4 | 2016-10-08T17:55:55Z | [
"python",
"exception"
] |
python3 exception invalid syntax error | 39,935,486 | <p>I recently started learning python3, and I am trying to write an exception.
I have this line, which is a list of words.
I want to match the word create to the list, sometimes it's there sometimes its not. When it's not there I get this error:</p>
<pre><code>Traceback (most recent call last):
File "sub_process.py"... | -2 | 2016-10-08T17:49:48Z | 39,935,564 | <pre><code>#use try block..
line = line.split()
try:
if line.index("create"):
print("basd")
except ValueError:
print("123")
</code></pre>
| -1 | 2016-10-08T17:58:38Z | [
"python",
"exception"
] |
Intellisense in visual studio for app engine python project | 39,935,497 | <p>I am trying to have intellisense support for my python app engine project in visual studio 2015(community edition ptvs installed)</p>
<p>How I could achive this?</p>
<p>What I have tried is: </p>
<p>I installed <code>ndb</code> for <code>from google.appengine.ext import ndb</code> with pip which seems ok for inte... | 0 | 2016-10-08T17:50:54Z | 39,954,367 | <p>Add folder: C:\Program Files (x86)\Google\google_appengine resolves issue:</p>
<p><a href="http://i.stack.imgur.com/iUkWy.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/iUkWy.jpg" alt="enter image description here"></a></p>
<p>and project looks like</p>
<p><a href="http://i.stack.imgur.com/1W1NW.jpg" rel=... | 0 | 2016-10-10T08:39:24Z | [
"python",
"visual-studio",
"google-app-engine",
"visual-studio-2015-comm"
] |
Invalid block tag : 'endblock'. Did you forget to register or load this tag? | 39,935,578 | <p>l get stuck in this error. l'm fresh user of <code>Django</code> and l m learning it by following steps on Youtube channel. l did everything same but l got this block tag error.
here is layout1 html content:</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
... | -1 | 2016-10-08T17:59:55Z | 39,935,688 | <p>Django didn't recognise your starting block tag, because you have a space between the <code>{</code> and the <code>%</code>.</p>
<p>You also have the same error in both start and end tags in the other template file.</p>
| 1 | 2016-10-08T18:10:38Z | [
"python",
"html",
"django"
] |
Invalid block tag : 'endblock'. Did you forget to register or load this tag? | 39,935,578 | <p>l get stuck in this error. l'm fresh user of <code>Django</code> and l m learning it by following steps on Youtube channel. l did everything same but l got this block tag error.
here is layout1 html content:</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
... | -1 | 2016-10-08T17:59:55Z | 39,935,696 | <p>You simply have typos.</p>
<p>You should have <code>{%</code> not <code>{ %</code>, and you got those typos in both of templates.</p>
<p>So you need to have </p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}{% endblock %... | 1 | 2016-10-08T18:11:10Z | [
"python",
"html",
"django"
] |
Python code: explain please | 39,935,607 | <pre><code>first_num = raw input ("Please input first number. ")
sec_num = raw input (" Please input second number:")
answer = into( first_num) +into( sec_num)
print " Now I will add your two numbers : ", answer
print " Pretty cool. huh ?
print " Now I'll count backwards from ",answer
counter = answer
while (counte... | -5 | 2016-10-08T18:02:42Z | 39,936,178 | <p>You should probably try to run the code first and play with it to understand it. The code is simple; the first half take two user inputs and add them to each other then it displays the result. </p>
<pre><code>first_num = input("Please input first number:") # get first number input
sec_num = input("Please input seco... | 1 | 2016-10-08T18:57:57Z | [
"python"
] |
Flask application not reflecting new JS changes | 39,935,655 | <p>I have the following code in my Flask server:</p>
<pre><code> res = Response(resp, mimetype='text/plain')
res.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
res.headers["Pragma"] = "no-cache"
res.headers["Expires"] = "0"
return res
</code></pre>
<p>On the client side I have so... | 0 | 2016-10-08T18:06:58Z | 39,936,150 | <p>One trick for making sure the browser does not cache a file is to change the url when the file changes. That can be done without changing the filename, by appending a query:</p>
<pre><code><script src="myscript.js?version=7">
</code></pre>
<p>Or, even better:</p>
<pre><code><script src="myscript.js?times... | 0 | 2016-10-08T18:55:08Z | [
"javascript",
"python",
"caching",
"flask"
] |
Wrangling a data frame in Pandas (Python) | 39,935,744 | <p>I have the following data in a csv file:</p>
<pre><code>from StringIO import StringIO
import pandas as pd
the_data = """
ABC,2016-6-9 0:00,95,{'//Purple': [115L], '//Yellow': [403L], '//Blue': [16L], '//White-XYZ': [0L]}
ABC,2016-6-10 0:00,0,{'//Purple': [219L], '//Yellow': [381L], '//Blue': [90L], '//White-XYZ': ... | 0 | 2016-10-08T18:16:48Z | 39,937,012 | <p>I really don't think this pandas can do much for you here. You're data is very obtuse and seems to me to be best dealt with using regular expressions. Here's my solution: </p>
<pre><code>import re
static_cols = []
dynamic_cols = []
for line in the_data.splitlines():
if line == '':
continue
# deal ... | 0 | 2016-10-08T20:25:03Z | [
"python",
"regex",
"pandas"
] |
Wrangling a data frame in Pandas (Python) | 39,935,744 | <p>I have the following data in a csv file:</p>
<pre><code>from StringIO import StringIO
import pandas as pd
the_data = """
ABC,2016-6-9 0:00,95,{'//Purple': [115L], '//Yellow': [403L], '//Blue': [16L], '//White-XYZ': [0L]}
ABC,2016-6-10 0:00,0,{'//Purple': [219L], '//Yellow': [381L], '//Blue': [90L], '//White-XYZ': ... | 0 | 2016-10-08T18:16:48Z | 39,938,209 | <p>Consider converting the dictionary column values as Python dictionaries using <a href="https://docs.python.org/2/library/ast.html" rel="nofollow"><code>ast.literal_eval()</code></a> and then cast them as individual dataframes for final merge with original dataframe:</p>
<pre><code>from io import StringIO
import pan... | 0 | 2016-10-08T22:54:19Z | [
"python",
"regex",
"pandas"
] |
Rasterio Geotiff Coordinate Translation | 39,935,789 | <p>I have some geotiff files but the coordinates are slightly off. I want to use rasterio's API (or other python geo API like pygdal) to geometrically translate (shift) the image. For example, how do I move the image's coordinates 'north' by a single pixel width.</p>
<p>When displayed with a tool like qgis the image... | 0 | 2016-10-08T18:21:23Z | 39,948,444 | <p>Modifying the georeference of a geotiff is a really simple task. I will show how to do it using the <code>gdal</code> python module. First, you should have a look at the <a href="http://www.gdal.org/gdal_datamodel.html" rel="nofollow">GDAL data model</a> with particular focus on the '<strong>affine geotransform</str... | 1 | 2016-10-09T20:56:33Z | [
"python",
"gdal",
"geotiff",
"rasterio"
] |
python os.system from input nor working | 39,935,808 | <pre><code>#!/usr/bin/env python
import os
import subprocess
mail=raw_input("")
os.system("mail" + mail + "<<<test")
</code></pre>
<p>When I run this program I`ve got error :sh: 1: Syntax error: redirection unexpected.</p>
<p>The script must send mail using mailutilis</p>
| 0 | 2016-10-08T18:23:01Z | 39,936,033 | <p>Don't use <code>os.system</code>. Replace it with <code>subprocess.Popen</code>:</p>
<pre><code>address = raw_input()
with open('test') as text:
subprocess.Popen(["mail", address], stdin=text).wait()
</code></pre>
| 0 | 2016-10-08T18:43:20Z | [
"python",
"os.system"
] |
How can I print a euro (â¬) symbol in Python? | 39,935,857 | <p>I'm teaching myself Python using the command-line interpreter (v3.5 for Windows).</p>
<p><strong>All I want to do is output some text that includes the euro (â¬) symbol</strong> which I understand to be code 80h (128 dec).</p>
<pre><code>#!
# -*- coding: utf-8 -*-
mytext = 'Please pay \x8035.'
print(mytext)
</co... | 0 | 2016-10-08T18:26:54Z | 39,935,897 | <p>You can use this:</p>
<pre><code>mytext = 'Please pay \u20ac.'
print(mytext)
</code></pre>
<p>... based on <a href="http://www.fileformat.info/info/unicode/char/20ac/index.htm" rel="nofollow">Unicode Character 'EURO SIGN'</a>.</p>
| 2 | 2016-10-08T18:30:49Z | [
"python",
"utf-8",
"character-encoding"
] |
How can I print a euro (â¬) symbol in Python? | 39,935,857 | <p>I'm teaching myself Python using the command-line interpreter (v3.5 for Windows).</p>
<p><strong>All I want to do is output some text that includes the euro (â¬) symbol</strong> which I understand to be code 80h (128 dec).</p>
<pre><code>#!
# -*- coding: utf-8 -*-
mytext = 'Please pay \x8035.'
print(mytext)
</co... | 0 | 2016-10-08T18:26:54Z | 39,935,957 | <p>In Python 3, you can simply copy and paste the ⬠character directly into a UTF-8 encoded text file (no need for codes):</p>
<pre><code>mytext = 'Please pay â¬.'
print(mytext)
</code></pre>
| 0 | 2016-10-08T18:35:12Z | [
"python",
"utf-8",
"character-encoding"
] |
How can I print a euro (â¬) symbol in Python? | 39,935,857 | <p>I'm teaching myself Python using the command-line interpreter (v3.5 for Windows).</p>
<p><strong>All I want to do is output some text that includes the euro (â¬) symbol</strong> which I understand to be code 80h (128 dec).</p>
<pre><code>#!
# -*- coding: utf-8 -*-
mytext = 'Please pay \x8035.'
print(mytext)
</co... | 0 | 2016-10-08T18:26:54Z | 39,935,969 | <p>From <a href="http://www.python-forum.org/viewtopic.php?f=6&t=13995" rel="nofollow">http://www.python-forum.org/viewtopic.php?f=6&t=13995</a> :</p>
<p>This is behavior of python 2,Python 3 dos not do this.</p>
<p>Python 2.7:</p>
<pre><code>>>> s = "â¬"
>>> s
'\xe2\x82\xac'
>>> ... | 0 | 2016-10-08T18:37:03Z | [
"python",
"utf-8",
"character-encoding"
] |
How can I print a euro (â¬) symbol in Python? | 39,935,857 | <p>I'm teaching myself Python using the command-line interpreter (v3.5 for Windows).</p>
<p><strong>All I want to do is output some text that includes the euro (â¬) symbol</strong> which I understand to be code 80h (128 dec).</p>
<pre><code>#!
# -*- coding: utf-8 -*-
mytext = 'Please pay \x8035.'
print(mytext)
</co... | 0 | 2016-10-08T18:26:54Z | 39,936,499 | <p>Here are four ways of printing a string with the Euro symbol in Python 3.x, in increasing order of obscurity.</p>
<p><strong>1. Direct input</strong></p>
<p>Use your keyboard to enter the symbol, or copy and paste it from somewhere else:</p>
<pre class="lang-py prettyprint-override"><code>mytext = "Please pay â¬... | 0 | 2016-10-08T19:28:51Z | [
"python",
"utf-8",
"character-encoding"
] |
Why is this regex expression not working? | 39,935,867 | <p>I want to separate out the links from the string which don't have ':' in between and do not end with '.jpg' or '.svg', and also start with '/wiki/'.</p>
<p>So these are wrong - </p>
<pre><code>"https://boomerrang.com"
"/wiki/sbsbs:kjanw"
"/wiki/aswaa:asawsa.jpg"
"/wiki/awssa.random.jpg"
"/wiki/boom.jpg"
</code></p... | 2 | 2016-10-08T18:27:39Z | 39,935,972 | <p>Why your pattern doesn't work:</p>
<p><code>.*[^:]</code> doesn't prevent a <code>:</code> to be present in the string since <code>.*</code> can match it.</p>
<p><code>(?!jpg|svg)$</code> doesn't make sense since it says that the end of the string isn't followed by "jpg" or "svg". Obviously the end of the string i... | 3 | 2016-10-08T18:37:34Z | [
"python",
"regex"
] |
passing the return of a function into another function in python | 39,935,988 | <p>I am absolutely overlooking something basic here... I'm trying to pass the return of a function (a list of lists) into another function as an argument. When i compile i get the error that the gameGridWords variable is not defined. </p>
<p>Any help would be greatly appreciated!</p>
<p>This is the function that retu... | 1 | 2016-10-08T18:38:29Z | 39,948,473 | <p>You have to assign data returned by first function to variable ie.</p>
<pre><code>result = gridWords()
</code></pre>
<p>and later use this data with second function.</p>
<pre><code>drawGrid(result)
</code></pre>
<p>(btw. name <code>result</code> doesn't matter, you can use different name)</p>
<p>if second funct... | 0 | 2016-10-09T20:59:17Z | [
"python",
"pygame"
] |
Why is this condition-based list comprehension not working? | 39,936,092 | <p>I want to create a list from an existing list after removing all duplicates.
Program works if I use a "for loop" but nothing happens if I use a list comprehension.</p>
<pre><code>#use for loop
l=[1,2,2,3,1,1,2]
j=[]
for i in l:
if i not in j:
j.append(i)
print l
print j
#using list
l1=[1,2,2,3,1,1,2... | 0 | 2016-10-08T18:49:05Z | 39,936,121 | <p>The expression <code>[i for i in l1 if i not in j1]</code> is evaluated and then assigned to <em>j1</em>. So during the evaluation <em>j1</em> stays empty.</p>
<p>BTW: An easy was of removing duplicates is to pass the list to the <a href="https://docs.python.org/3/library/functions.html#func-set" rel="nofollow">set... | 3 | 2016-10-08T18:52:18Z | [
"python",
"list",
"python-2.7",
"list-comprehension"
] |
Why is this condition-based list comprehension not working? | 39,936,092 | <p>I want to create a list from an existing list after removing all duplicates.
Program works if I use a "for loop" but nothing happens if I use a list comprehension.</p>
<pre><code>#use for loop
l=[1,2,2,3,1,1,2]
j=[]
for i in l:
if i not in j:
j.append(i)
print l
print j
#using list
l1=[1,2,2,3,1,1,2... | 0 | 2016-10-08T18:49:05Z | 39,936,145 | <p><code>j1</code> is <code>[]</code> at the start and isn't updated at intermediate points within the list comprehension. Could do this instead of list comprehension though:</p>
<pre><code>l1=[1,2,2,3,1,1,2]
j1=list(set(l1))
print l1
print j1
</code></pre>
| 0 | 2016-10-08T18:54:40Z | [
"python",
"list",
"python-2.7",
"list-comprehension"
] |
In python, how to import just words but not any punctuation from a .txt file? | 39,936,157 | <p>For example ,I have a txt file which content is:</p>
<blockquote>
<p>Blockquote</p>
</blockquote>
<pre><code>star, year, op, ed
ad, ed, offer, year
</code></pre>
<blockquote>
<p>Blockquote</p>
</blockquote>
<p>I want to import them and form a list which have each line as a sublist:
[['star','year','op','... | 1 | 2016-10-08T18:55:25Z | 39,936,192 | <p>All you need is splitting with comma and space:</p>
<pre><code>with open ("file_name") as f:
result = [line.split(', ') for line in f]
</code></pre>
<p>And note that you don't need to close the file manually when you are using <code>whith</code> statement. That's exactly what the <code>with</code> does at the ... | 0 | 2016-10-08T18:58:32Z | [
"python",
"python-3.x",
"split"
] |
In python, how to import just words but not any punctuation from a .txt file? | 39,936,157 | <p>For example ,I have a txt file which content is:</p>
<blockquote>
<p>Blockquote</p>
</blockquote>
<pre><code>star, year, op, ed
ad, ed, offer, year
</code></pre>
<blockquote>
<p>Blockquote</p>
</blockquote>
<p>I want to import them and form a list which have each line as a sublist:
[['star','year','op','... | 1 | 2016-10-08T18:55:25Z | 39,936,433 | <p>in split function try to give ", " as argument like this.</p>
<pre><code>split_line = line[:-2].split(", ")
</code></pre>
<p>Hope this helps.</p>
| 0 | 2016-10-08T19:22:20Z | [
"python",
"python-3.x",
"split"
] |
Accessing global from within lambda | 39,936,195 | <p>I never access globals from within functions, instead I pass them in as arguments. Therefore the following code feels weird to me, where I am accessing a global object directly from within the function: </p>
<pre><code>ws = WebSocket(url)
sch.on_receive(lambda msg: ws.send(msg))
</code></pre>
<p>How should I be ... | 0 | 2016-10-08T18:58:52Z | 39,936,258 | <p>What's wrong with what you've written? It's not necessarily accessing the global scope, it's really accessing the local scope (and if it doesn't find the variable uses the global scope). Just as an example this is perfectly fine:</p>
<pre><code>def func():
ws = WebSocket(url)
sch.on_receive(lambda msg: ws.s... | 0 | 2016-10-08T19:04:47Z | [
"python"
] |
Accessing global from within lambda | 39,936,195 | <p>I never access globals from within functions, instead I pass them in as arguments. Therefore the following code feels weird to me, where I am accessing a global object directly from within the function: </p>
<pre><code>ws = WebSocket(url)
sch.on_receive(lambda msg: ws.send(msg))
</code></pre>
<p>How should I be ... | 0 | 2016-10-08T18:58:52Z | 39,936,261 | <p>There is no problem with <strong>accessing</strong> global variables from functions (including lambdas), without using <code>global</code>:</p>
<pre><code>>>> a = 1
>>> b = list()
>>>
>>> def f():
... b.append(a)
...
>>> f()
>>> print(b)
[1]
</code></pre>
<... | 1 | 2016-10-08T19:04:59Z | [
"python"
] |
How to make sure the sting appear in somewhere in the list | 39,936,199 | <p><a href="http://i.stack.imgur.com/VJH9R.jpg" rel="nofollow">enter image description here</a>Write a function that takes,as an argument,a list and a string, and returns a Boolean based on whether or not all of the letters in the string appear somewhere in the list.
For question 3</p>
<p>def findLetters(myList,myStri... | -1 | 2016-10-08T18:59:07Z | 39,936,586 | <p>Looks like homework task. It is fairly simple so try it yourself.
Use operator <code>in</code> to check if letter is in string.</p>
<pre><code>if c in string:
print(c, 'is in', string)
</code></pre>
| 0 | 2016-10-08T19:37:23Z | [
"python"
] |
Is it safe and pythonic to consume the iterator in the body of a for loop? | 39,936,220 | <p>Is it safe in Python to do something like this (say, in a parser)?</p>
<pre><code>iterator = iter(some_iterable)
for x in iterator:
# do stuff with x
if some_condition(x):
y = next(iterator)
# do stuff with y
</code></pre>
<p>I've tested in Python 2 and 3 and it does what I expect, but I wo... | 3 | 2016-10-08T19:00:51Z | 39,936,333 | <p>Basically it's always better to keep track of your exceptions and handle them properly. But regarding the difference between the <code>while</code> and <code>for</code> loops in this case when you are calling a <code>next()</code> function within a <code>while</code> loop it's always possible to raise an StopIterati... | 1 | 2016-10-08T19:11:21Z | [
"python"
] |
Looking for a regular expression used on variable string | 39,936,275 | <p>I have a string that can vary slightly:</p>
<pre><code>str1 = "[X] text [Y] abc123"
str1 = "(X ) text [y ] abc123"
str1 = "(x) text (Y) abc123"
str1 = "(X ) text (Y) abc123"
str1 = "(X ) text [Y ] abc123"
str1 = "[X] text333 [y] abc123222"
</code></pre>
<p>so basically X and Y are static and they ca... | 0 | 2016-10-08T19:06:09Z | 39,936,426 | <p>How about this? </p>
<pre><code>chars='[]()'
x,text,y,abc123 = ''.join([x for x in str1 if x not in chars]).split()
print(x,text,y,abc123)
</code></pre>
| 0 | 2016-10-08T19:21:21Z | [
"python",
"regex"
] |
Looking for a regular expression used on variable string | 39,936,275 | <p>I have a string that can vary slightly:</p>
<pre><code>str1 = "[X] text [Y] abc123"
str1 = "(X ) text [y ] abc123"
str1 = "(x) text (Y) abc123"
str1 = "(X ) text (Y) abc123"
str1 = "(X ) text [Y ] abc123"
str1 = "[X] text333 [y] abc123222"
</code></pre>
<p>so basically X and Y are static and they ca... | 0 | 2016-10-08T19:06:09Z | 39,936,742 | <p>How about:</p>
<pre><code>[\[)]X[\])]\s*(.+?)\s*[\[(]Y[\])]\s*(.+)
</code></pre>
<p><code>text</code> will be in group 1 and <code>abc123</code> in group 2</p>
<p><strong>Explanation:</strong></p>
<pre><code>[\[)] : character class `[` or `(`
X : whatever X stands for
[\])] : character class `]` or `)`... | 0 | 2016-10-08T19:54:46Z | [
"python",
"regex"
] |
Looking for a regular expression used on variable string | 39,936,275 | <p>I have a string that can vary slightly:</p>
<pre><code>str1 = "[X] text [Y] abc123"
str1 = "(X ) text [y ] abc123"
str1 = "(x) text (Y) abc123"
str1 = "(X ) text (Y) abc123"
str1 = "(X ) text [Y ] abc123"
str1 = "[X] text333 [y] abc123222"
</code></pre>
<p>so basically X and Y are static and they ca... | 0 | 2016-10-08T19:06:09Z | 39,936,902 | <p>The regex you want could be <code>r'(?i)\s*(?:\[\s*(?:X|Y)\s*\]|\(\s*(?:X|Y)\s*\))\s*'</code>
This assumes that <code>[]</code> or <code>()</code> pairs must match, and that (as you show in your example) X and Y can be either upper or lower case (or mixed case, if <code>X</code> or <code>Y</code> is a longer token).... | 0 | 2016-10-08T20:12:57Z | [
"python",
"regex"
] |
Looking for a regular expression used on variable string | 39,936,275 | <p>I have a string that can vary slightly:</p>
<pre><code>str1 = "[X] text [Y] abc123"
str1 = "(X ) text [y ] abc123"
str1 = "(x) text (Y) abc123"
str1 = "(X ) text (Y) abc123"
str1 = "(X ) text [Y ] abc123"
str1 = "[X] text333 [y] abc123222"
</code></pre>
<p>so basically X and Y are static and they ca... | 0 | 2016-10-08T19:06:09Z | 39,937,036 | <pre class="lang-python prettyprint-override"><code>import re
str1 = "( X ) text [Y] abc 123 xyz"
m = re.match( r'^[\(\[][xX ]+[\]\)]\s*(\S*)\s*[\(\[][yY ]+[\]\)]\s*(.*)$', str1)
if m:
str1text = m.group(1)
str1moretext = m.group(2)
print str1text
print str1moretext
else:
print "No match!!"
</code></p... | 0 | 2016-10-08T20:27:22Z | [
"python",
"regex"
] |
Import Error When Adding a Database to a Flask App | 39,936,287 | <p>I'm following this <a href="http://blog.toast38coza.me/adding-a-database-to-a-flask-app/" rel="nofollow">tutorial</a> and when running <code>$ nosetests</code> in Step 2, I'm getting the following import errors:</p>
<pre><code>EE
======================================================================
ERROR: Failure:... | 0 | 2016-10-08T19:07:08Z | 39,937,672 | <p>In Flask, usually the import errors of modules (though installed), directed to the way you are running the application. When you run the run.py, please check the interpreter path. I have seen some times, running ./run.py would not work since the libraries are under flask/* directories.
You can either run ~/flask/bi... | 0 | 2016-10-08T21:42:41Z | [
"python",
"flask",
"flask-sqlalchemy"
] |
Permutations of 2 characters in Python into fixed length string with equal numbers of each character | 39,936,344 | <p>I've looked through the 2 questions below, which seem closest to what I am asking, but don't get me to the answer to my question.</p>
<p><a href="http://stackoverflow.com/questions/36517439/permutation-of-x-length-of-2-characters">Permutation of x length of 2 characters</a></p>
<p><a href="http://stackoverflow.com... | 2 | 2016-10-08T19:12:10Z | 39,936,670 | <p>If all you need is the count, this can be generalized to <a href="https://en.wikipedia.org/wiki/Binomial_coefficient" rel="nofollow"><code>n</code> choose <code>k</code></a>. Your total size is <code>n</code> and the number of elements of <code>"A"</code> is <code>k</code>. So, your answer would be:</p>
<p>(n cho... | 0 | 2016-10-08T19:46:48Z | [
"python",
"string",
"algorithm",
"permutation"
] |
Providing visibility of periodic changes to a database | 39,936,352 | <p>This is quite a general question, though Iâll give the specific use case for context.</p>
<p>I'm using a FileMaker Pro database to record personal bird observations. For each bird on the national list, I have extracted quite a lot of base data by website scraping in Python, for example conservation status, geogra... | 0 | 2016-10-08T19:12:50Z | 39,941,551 | <p>This is not a standard requirement and there is no easy way of doing this. The best way to track changes is a Source Control system like git, but it is not applicable to FileMaker Pro as the files are binary.</p>
<p>You can try your approach, or you can try to add the new records in FileMaker instead of updating th... | 1 | 2016-10-09T08:28:58Z | [
"python",
"filemaker"
] |
Pandas: Get datetime index value from row | 39,936,434 | <p>I have a dataframe with datetime type column set to index.
I want to process the data per row with apply function. how can I access the index value of the current row?</p>
<pre><code> hid lat lon
2016-08-11 10:56:00 549 40.639504 -79.996961
2016-08-11 10:57:00 639 40.53950... | 0 | 2016-10-08T19:22:27Z | 39,936,584 | <p>Since apply will return a Series you could call the name of that Series which represent the index such has:</p>
<pre><code>df['new'] = df.apply(lambda row: row.name, axis=1)
</code></pre>
| 1 | 2016-10-08T19:37:13Z | [
"python",
"datetime",
"pandas"
] |
Secure alternatives to DiD or the UNIX socket? | 39,936,449 | <p>I'm trying to learn more about Docker, what it's for, and how it functions. To that end, I've set up two containers using <code>docker-compose</code>: </p>
<ul>
<li>One container, based on Docker's <code>python:3</code> image, runs some service </li>
<li>The other container, also based on Dockers's <code>python:3... | 1 | 2016-10-08T19:24:25Z | 39,943,864 | <p>You can do what you want (of course if I understood well) like this:</p>
<p><code>
docker run -d -v /var/run/docker.socket:/var/run/docker.socket -v $(which docker):/usr/bin/docker manager-app:latest
</code></p>
<p>Then you can use docker binary to access the other containers on the host and manage your service co... | 0 | 2016-10-09T12:55:29Z | [
"python",
"docker",
"docker-compose"
] |
python multiprocessing, cpu-s and cpu cores | 39,936,480 | <p>I was trying out <code>python3</code> <code>multiprocessing</code> on a machine that has 8 cpu-s and each cpu has four cores (information is from <code>/proc/cpuinfo</code>). I wrote a little script with a useless function and I use <code>time</code> to see how long it takes for it to finish.</p>
<pre><code>from mu... | 0 | 2016-10-08T19:27:14Z | 39,938,798 | <p>Simplified and short.. Cpu-s and cores are hardware that your computer have. On this hardware there is a operating system, the middleman between hardware and the programs running on the computer. The programs running on the computer are allotted cpu time. One of these programs is the python interpetar, which runs al... | 0 | 2016-10-09T00:31:53Z | [
"python",
"multiprocessing"
] |
Using GET and POST to add data to a database in Django | 39,936,494 | <p>I am working on a project that will have a raspberry PI collect data from a set of sensors and then send the data to a django server.</p>
<p>I need the server to then take that data and add it to a database and perform ARIMA time series forecasting on the updated dataset every x seconds after a number of new entrie... | 0 | 2016-10-08T19:28:27Z | 39,936,550 | <p>you can use <strong>urllib</strong> module or <strong>requests</strong> module in python to send POST request to your Django server. </p>
<p>And you can have Django view to respond to that POST request. Inside this view, you can have method to add the data which sent from your Raspberry Pi program into your databas... | 0 | 2016-10-08T19:33:54Z | [
"python",
"django",
"raspberry-pi"
] |
Implementing HTTP/2 client using python 3.5 hyper library | 39,936,497 | <p>Im trying to implement my own HTTP/2 client using python3.5 hyper library. Everything seems to work fine until I request objects larger than 64Kb.</p>
<p>I've already set the <code>network_buffer_size</code> in larger values than the default which is actually 64K, even set the library code to set the network_buffer... | 1 | 2016-10-08T19:28:38Z | 39,939,871 | <p>Flow-control in HTTP/2 is implemented via two type of flow control windows: one for the connection, and one for each stream, in the words of <a href="https://tools.ietf.org/html/rfc7540#section-5.2" rel="nofollow">RFC 7540, 5.2 Flow control</a>: </p>
<blockquote>
<p>A flow-control scheme ensures that streams on t... | 0 | 2016-10-09T03:54:54Z | [
"python",
"http2",
"hyper"
] |
Shortest way to run seven if statements in Python | 39,936,512 | <p>I have an <code>if</code> statements that checks a number and then return a string value accordingly.</p>
<p><strong>code:</strong></p>
<pre><code>def get_weekday(day):
if day in ['1', 1]:
return 'Monday'
elif day in ['2', 2]:
return 'Tuesday'
elif day in ['3', 3]:
return 'Wedne... | 1 | 2016-10-08T19:30:39Z | 39,936,534 | <p>You could use a <strong><a href="https://docs.python.org/2/tutorial/datastructures.html#dictionaries" rel="nofollow">dictionary</a></strong> aka map and simply put in multiple keys for the same values. </p>
<p>Then you only need to ask that dictionary for the value matching the current <em>day</em> key.</p>
| 1 | 2016-10-08T19:32:44Z | [
"python"
] |
Shortest way to run seven if statements in Python | 39,936,512 | <p>I have an <code>if</code> statements that checks a number and then return a string value accordingly.</p>
<p><strong>code:</strong></p>
<pre><code>def get_weekday(day):
if day in ['1', 1]:
return 'Monday'
elif day in ['2', 2]:
return 'Tuesday'
elif day in ['3', 3]:
return 'Wedne... | 1 | 2016-10-08T19:30:39Z | 39,936,548 | <p>A generic solution would be:</p>
<pre><code>def get_day_name(day):
return {
'1': 'Monday',
'2': 'Tuesday',
'3': 'Wednesday',
'4': 'Thursday',
'5': 'Friday',
'6': 'Saturday',
'7': 'Sunday'
}.get(str(day), 'Invalid day selected')
</code></pre>
<p>Severa... | 1 | 2016-10-08T19:33:48Z | [
"python"
] |
Shortest way to run seven if statements in Python | 39,936,512 | <p>I have an <code>if</code> statements that checks a number and then return a string value accordingly.</p>
<p><strong>code:</strong></p>
<pre><code>def get_weekday(day):
if day in ['1', 1]:
return 'Monday'
elif day in ['2', 2]:
return 'Tuesday'
elif day in ['3', 3]:
return 'Wedne... | 1 | 2016-10-08T19:30:39Z | 39,936,562 | <p>You could use a dictionary. The <code>get</code> method of the dictionary returns the default <code>'Invalid day selected'</code> when the given <code>day</code> is not in the dictionary:</p>
<pre><code>days_in_week = {1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4: 'Thursday', 5: 'Friday', 6: 'Saturday', 7: 'Sunday'... | 1 | 2016-10-08T19:34:19Z | [
"python"
] |
Shortest way to run seven if statements in Python | 39,936,512 | <p>I have an <code>if</code> statements that checks a number and then return a string value accordingly.</p>
<p><strong>code:</strong></p>
<pre><code>def get_weekday(day):
if day in ['1', 1]:
return 'Monday'
elif day in ['2', 2]:
return 'Tuesday'
elif day in ['3', 3]:
return 'Wedne... | 1 | 2016-10-08T19:30:39Z | 39,936,571 | <p>What I would do instead, is create a dictionary, and cast your <code>day</code> to a single type, and then look that up in your dictionary. This significantly minimizes your code: </p>
<pre><code>def get_weekday(day):
days_dict = {
'1': 'Monday',
'2': 'Tuesday',
'3': 'Wednesday',
... | 4 | 2016-10-08T19:35:20Z | [
"python"
] |
Shortest way to run seven if statements in Python | 39,936,512 | <p>I have an <code>if</code> statements that checks a number and then return a string value accordingly.</p>
<p><strong>code:</strong></p>
<pre><code>def get_weekday(day):
if day in ['1', 1]:
return 'Monday'
elif day in ['2', 2]:
return 'Tuesday'
elif day in ['3', 3]:
return 'Wedne... | 1 | 2016-10-08T19:30:39Z | 39,936,744 | <p>I would rather use the <code>get</code> method of a dictionary instead of writing multiple <code>elif</code>s:</p>
<pre><code>def get_weekday(day):
WEEK = {"1": "Monday",
"2": "Tuesday",
"3": "Wednesday",
"4": "Thursday",
"5": "Friday",
"6": "Saturday"... | -1 | 2016-10-08T19:55:04Z | [
"python"
] |
python removing references from a scientific paper | 39,936,527 | <p>NOTE: I am inexperienced with regular expressions.</p>
<p>I want to be able to convert scientific articles into iTunes tracks. To do this I copy and paste the text in txt files and convert them to spoken tracks. However when I do this the references are included and the computer's voice reads them aloud e.g. "(Smit... | 0 | 2016-10-08T19:31:59Z | 39,936,761 | <p>This should do the trick:</p>
<pre><code>import re
a = "This method has been shown to outperform previously discussed methods (Smith, J. et al., 2014) and while it has its draw-backs, it is clear that the benefits outweigh the disadvantages (Jones, A. & Karver, B., 2009, Lubber, H. et al., 2013)."
a = re.sub(... | 1 | 2016-10-08T19:56:36Z | [
"python",
"string"
] |
python removing references from a scientific paper | 39,936,527 | <p>NOTE: I am inexperienced with regular expressions.</p>
<p>I want to be able to convert scientific articles into iTunes tracks. To do this I copy and paste the text in txt files and convert them to spoken tracks. However when I do this the references are included and the computer's voice reads them aloud e.g. "(Smit... | 0 | 2016-10-08T19:31:59Z | 39,936,783 | <p>something like</p>
<pre><code> import re
text = ...
re.sub(r'\((?:[\w \.&]+\, )+[0-9]{4}\)', text)
</code></pre>
<p>seems to do it.
You can use <a href="https://www.debuggex.com/" rel="nofollow">Debuggex</a> to train yourself in regex.</p>
| 2 | 2016-10-08T19:58:46Z | [
"python",
"string"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.