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
Tornado templates setting value field
39,232,936
<p>I have a python array:</p> <pre><code>a=["a","b","c","d","e","f"] </code></pre> <p>I pass this as a value to tornado render:</p> <pre><code> self.render("index.html", a=a) </code></pre> <p>In my html I have the following:</p> <pre><code> &lt;input type="hidden" id="xxx" value=" {% for c in a %} {{c}} ...
0
2016-08-30T16:43:28Z
39,233,815
<p>Try Tornado's <a href="http://www.tornadoweb.org/en/stable/template.html#tornado.template.filter_whitespace" rel="nofollow">filter_whitespace</a> feature, new in version 4.3.</p> <pre><code> {% whitespace oneline %} &lt;input type="hidden" id="xxx" value="{% for c in a %} {{c}} {% end %}"/&gt; {% whites...
2
2016-08-30T17:38:33Z
[ "python", "html", "tornado" ]
Tornado templates setting value field
39,232,936
<p>I have a python array:</p> <pre><code>a=["a","b","c","d","e","f"] </code></pre> <p>I pass this as a value to tornado render:</p> <pre><code> self.render("index.html", a=a) </code></pre> <p>In my html I have the following:</p> <pre><code> &lt;input type="hidden" id="xxx" value=" {% for c in a %} {{c}} ...
0
2016-08-30T16:43:28Z
39,238,177
<p>The same as @Avinash answered, only in-template:</p> <pre><code>&lt;input type="hidden" id="xxx" value="{{ ' '.join(a) }}" /&gt; </code></pre> <p>Tornado templates, unlike some other templating engines like Django or Jinja, allows arbitrary Python expressions in the templates.</p>
0
2016-08-30T22:41:49Z
[ "python", "html", "tornado" ]
How can I perform a "match or create" operation in py2neo v3?
39,233,017
<p>I want to create a Node/Relationship only if a Node/Relationship with the same attribute<strong>s</strong> doesn't already exist in the graph. If they do, I would like to fetch the relevant item.</p> <p>Right now I am doing something that I suppose is both unidiomatic and inefficient. Assuming each <code>Person</co...
0
2016-08-30T16:48:34Z
39,235,540
<p>You can use the Cypher <a href="http://neo4j.com/docs/developer-manual/current/cypher/#query-merge" rel="nofollow">MERGE</a> clause to perform a "match or create":</p> <pre><code>node = graph.data('MERGE (n:Person) WHERE n.name = {name} AND' 'n.age = {age} RETURN n LIMIT 1', name...
1
2016-08-30T19:22:13Z
[ "python", "database", "neo4j", "py2neo" ]
Launch command through popen on OpenShift
39,233,057
<p>When I launch this command through <strong>popen</strong></p> <pre><code>try: os.popen("myCustomCmdHere") except IOError: logging.error('Error on myCustomCmdHere') </code></pre> <p><strong>I don't have error but the command does not launch</strong></p> <p>And when I launch myCustomCmdHere directly on Openshif...
0
2016-08-30T16:51:12Z
39,236,912
<p>Try using the '&amp;' to start a separate process and send to background. I use this for python 3.3 on Openshift. </p> <pre><code>import subprocess subprocess.Popen(['myCustomcmdHere &amp;']) </code></pre> <p>Or this</p> <pre><code>os.system("myCustomcmdHere &amp;") </code></pre>
0
2016-08-30T20:53:06Z
[ "python", "python-2.7", "openshift", "popen" ]
How to import a function from a module in the same folder?
39,233,077
<p>I am trying to separate my script into several files with functions, so I moved some functions into separate files and want to import them into one main file. The structure is:</p> <pre><code>core/ main.py posts_run.py </code></pre> <p><code>posts_run.py</code> has two functions, <code>get_all_posts</code> and...
1
2016-08-30T16:52:51Z
39,233,152
<p>You need to add <code>__init__.py</code> in your core folder. You getting this error because python does not recognise your folder as <a href="https://docs.python.org/3/tutorial/modules.html#packages" rel="nofollow">python package</a></p> <p>After that do</p> <pre><code>from .posts_run import get_all_posts # ^ ...
1
2016-08-30T16:58:01Z
[ "python", "python-3.x" ]
How to import a function from a module in the same folder?
39,233,077
<p>I am trying to separate my script into several files with functions, so I moved some functions into separate files and want to import them into one main file. The structure is:</p> <pre><code>core/ main.py posts_run.py </code></pre> <p><code>posts_run.py</code> has two functions, <code>get_all_posts</code> and...
1
2016-08-30T16:52:51Z
39,233,202
<p>MyFile.py:</p> <pre><code>def myfunc(): return 12 </code></pre> <p>start python interpreter:</p> <pre><code>&gt;&gt;&gt; from MyFile import myFunc &gt;&gt;&gt; myFunc() 12 </code></pre> <p>Alternatively: </p> <pre><code>&gt;&gt;&gt; import MyFile &gt;&gt;&gt; MyFile.myFunc() 12 </code></pre> <p>Does this n...
1
2016-08-30T17:00:38Z
[ "python", "python-3.x" ]
How to import a function from a module in the same folder?
39,233,077
<p>I am trying to separate my script into several files with functions, so I moved some functions into separate files and want to import them into one main file. The structure is:</p> <pre><code>core/ main.py posts_run.py </code></pre> <p><code>posts_run.py</code> has two functions, <code>get_all_posts</code> and...
1
2016-08-30T16:52:51Z
39,233,265
<p>Python doesn't find the module to import because it is executed from another directory.</p> <p>Open a terminal and cd into the script's folder, then execute python from there.</p> <p>Run this code in your script to print from where python is being executed from:</p> <pre><code>import os print(os.getcwd()) </code>...
0
2016-08-30T17:04:44Z
[ "python", "python-3.x" ]
How to import a function from a module in the same folder?
39,233,077
<p>I am trying to separate my script into several files with functions, so I moved some functions into separate files and want to import them into one main file. The structure is:</p> <pre><code>core/ main.py posts_run.py </code></pre> <p><code>posts_run.py</code> has two functions, <code>get_all_posts</code> and...
1
2016-08-30T16:52:51Z
39,233,501
<p>A cheat solution can be found from this question (question is <a href="http://stackoverflow.com/questions/10095037/why-use-sys-path-appendpath-instead-of-sys-path-insert1-path">Why use sys.path.append(path) instead of sys.path.insert(1, path)?</a> ). Essentially you do the following</p> <pre><code> import sys ...
1
2016-08-30T17:19:19Z
[ "python", "python-3.x" ]
Google Reports API - reports.customerUsageReports.get issue
39,233,118
<p>I am having some issues with the Google Reports API. I have no issues running the sample code provided in the <a href="https://developers.google.com/admin-sdk/reports/v1/quickstart/python" rel="nofollow">documentation</a> to get the reports.activities.list data, but when I change to program to to try and pull full d...
0
2016-08-30T16:56:07Z
39,246,910
<p>Make sure you follow these steps:</p> <ol> <li><p>According to the <a href="https://developers.google.com/admin-sdk/reports/v1/quickstart/python" rel="nofollow">Python quickstart</a>, if you modify the scopes, you need to delete the previously saved credentials at ~/.credentials/admin-reports_v1-python-quickstart.j...
0
2016-08-31T10:19:06Z
[ "python", "google-api", "google-apps", "google-reporting-api" ]
using struct pack and unpack on floating point number 0.01 output 0.009999999776482582.
39,233,151
<p>using 'struct pack and unpack' on floating point number 0.01 outputs 0.009999999776482582. For my project I would have to configure values which are float and the same needs to be stored in binary file and I would need this data to analyze later and I need the exact values that was configured. </p> <p>Can some one...
1
2016-08-30T16:57:53Z
39,233,244
<p>There is no floating point number <code>0.01</code>. IEEE floating point numbers do not represent the entire real number line; they represent an approximation using a particular binary scheme. The closest approximation has the decimal representation 0.009999999776482582. </p> <p>You could try serializing a textual ...
2
2016-08-30T17:03:26Z
[ "python" ]
using struct pack and unpack on floating point number 0.01 output 0.009999999776482582.
39,233,151
<p>using 'struct pack and unpack' on floating point number 0.01 outputs 0.009999999776482582. For my project I would have to configure values which are float and the same needs to be stored in binary file and I would need this data to analyze later and I need the exact values that was configured. </p> <p>Can some one...
1
2016-08-30T16:57:53Z
39,233,341
<p>You say that numbers go from 0 to 5. If you only need two decimal places (0.00, 0.01, ..., 5.00) then you can store the numbers as 16 bit integers, first by multiplying the number by 100, and then when reading dividing the number by 100:</p> <pre><code>&gt;&gt;&gt; import struct &gt;&gt;&gt; digits = 2 &gt;&gt;&gt;...
2
2016-08-30T17:09:13Z
[ "python" ]
Python list only folders that contain specific subfolders
39,233,156
<p>I have a script that will list all folders and subfolders and create a JSON file. What I am trying to have is only folders that contain subfolders named "Maps" or "Reports" listed. If they contain those then only the parent folder will be listed, so "Maps", "Reports" would not be shown. Currently stuck on how to...
0
2016-08-30T16:58:11Z
39,233,490
<p>I'm thinking you're looking for the <code>os.walk</code> command, I've implemented a function using it below. (Also made it slightly more generic)</p> <pre><code>import os # path : string to relative or absolute path to be queried # subdirs: tuple or list containing all names of subfolders that need to be # ...
0
2016-08-30T17:18:45Z
[ "python", "python-2.7" ]
Python list only folders that contain specific subfolders
39,233,156
<p>I have a script that will list all folders and subfolders and create a JSON file. What I am trying to have is only folders that contain subfolders named "Maps" or "Reports" listed. If they contain those then only the parent folder will be listed, so "Maps", "Reports" would not be shown. Currently stuck on how to...
0
2016-08-30T16:58:11Z
39,233,685
<p>If you would like to use glob:</p> <pre><code>def get_list_of_dirs(): from glob import glob import os.path as path # get the directories containing Maps maps = set([path.abspath(path.join(f + path.pardir)) for f in glob('**/Maps/')]) # get the directories containing Reports ...
0
2016-08-30T17:30:43Z
[ "python", "python-2.7" ]
Python cannot seem to find libraries - conflict between user and system python versions
39,233,198
<p>So lets start from the very very top. </p> <p>This is the problem I am currently having:</p> <pre><code>bob@me:~/cloud/simtk/opensim_core_install/lib/python2.7/site-packages$ python Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more inform...
0
2016-08-30T17:00:23Z
39,233,834
<p>From what I get by your question you tried building by simply running <code>python setup.py install</code>.</p> <p>You have to follow the instructions in the Readme and build with the method corresponding to your operating system instead.</p>
0
2016-08-30T17:39:19Z
[ "python" ]
Split and merge pandas dataframe
39,233,205
<p>I am trying to split and merge a Pandas dataframe.</p> <p>The columns of the original data frame are arranged like so:</p> <pre><code>dataTime Record1Field1 ... Record1FieldN Record2Field1 ... Record1FieldN time1 &lt;&lt; record 1 data &gt;&gt; &lt;&lt; record 2 data &gt;&gt; </code></pr...
0
2016-08-30T17:00:45Z
39,233,330
<p>try using <code>concat</code> </p> <p>So trying something like:</p> <pre><code>Combined = [DataFrame1,DataFrame2] Together = pandas.concat(Combined) </code></pre> <p>as one of the others commented - <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html" rel="nofollow">merge</a...
0
2016-08-30T17:08:41Z
[ "python", "pandas", "dataframe" ]
Split and merge pandas dataframe
39,233,205
<p>I am trying to split and merge a Pandas dataframe.</p> <p>The columns of the original data frame are arranged like so:</p> <pre><code>dataTime Record1Field1 ... Record1FieldN Record2Field1 ... Record1FieldN time1 &lt;&lt; record 1 data &gt;&gt; &lt;&lt; record 2 data &gt;&gt; </code></pr...
0
2016-08-30T17:00:45Z
39,233,452
<p>if you know the columns to be selected , then use </p> <pre><code> tempdf = df[['a','b']] </code></pre> <p>else to select last 2 columns use </p> <pre><code> tempdf = df[df.columns[-2:]] </code></pre>
0
2016-08-30T17:16:15Z
[ "python", "pandas", "dataframe" ]
Split and merge pandas dataframe
39,233,205
<p>I am trying to split and merge a Pandas dataframe.</p> <p>The columns of the original data frame are arranged like so:</p> <pre><code>dataTime Record1Field1 ... Record1FieldN Record2Field1 ... Record1FieldN time1 &lt;&lt; record 1 data &gt;&gt; &lt;&lt; record 2 data &gt;&gt; </code></pr...
0
2016-08-30T17:00:45Z
39,233,618
<p>To answer your immediate question, you could use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.filter.html" rel="nofollow"><code>df.filter</code></a> with a regex pattern to select the columns of the form <code>Record2FieldN</code>:</p> <pre><code>In [29]: tempdf = df.filter(regex=...
1
2016-08-30T17:27:11Z
[ "python", "pandas", "dataframe" ]
Split and merge pandas dataframe
39,233,205
<p>I am trying to split and merge a Pandas dataframe.</p> <p>The columns of the original data frame are arranged like so:</p> <pre><code>dataTime Record1Field1 ... Record1FieldN Record2Field1 ... Record1FieldN time1 &lt;&lt; record 1 data &gt;&gt; &lt;&lt; record 2 data &gt;&gt; </code></pr...
0
2016-08-30T17:00:45Z
39,233,913
<p>You could get all your <code>Record2</code> values under the <code>Record1</code> columns as follows:</p> <p><strong>Data Setup:</strong> </p> <pre><code>data = StringIO( ''' dataTime Record1Field1 Record1Field2 Record1Field3 Record2Field1 Record2Field2 Record2Field3 01-01-2015 1 2 3 4 5 6 ''') df = pd.read_cs...
0
2016-08-30T17:44:00Z
[ "python", "pandas", "dataframe" ]
cv.cvtColor(img, cv.COLOR_BGR2GRAY) doesn't work
39,233,231
<p>This is my first attempt to detect faces and eyes in OpenCV 3.1. Here is my code:</p> <pre><code>import cv2 as cv import numpy as np face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml') eye_cascade = cv.CascadeClassifier('haarcascade_eye.xml') cam = cv.VideoCapture(0) while True: tf, im...
1
2016-08-30T17:02:09Z
39,234,039
<blockquote> <p>OpenCV Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale</p> </blockquote> <p>is telling you that the classifier is <em>empty</em>, because you didn't load the xml files correctly. </p> <p>Use the full path to the xml files to be sure to load them properly.</p>
0
2016-08-30T17:51:06Z
[ "python", "opencv", "numpy", "python-3.5", "opencv3.1" ]
retrieve name, phone number, url and role with regex
39,233,259
<p>Is it possible to do complex regex operations to retrieve name, role, designation in python? I have attached the pic for my requirement. <a href="http://i.stack.imgur.com/xqqMz.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/xqqMz.jpg" alt="enter image description here"></a></p>
-1
2016-08-30T17:04:23Z
39,234,489
<p>No. You need actual Natural Language Processing for that.</p>
0
2016-08-30T18:17:37Z
[ "python", "regex", "nltk" ]
retrieve name, phone number, url and role with regex
39,233,259
<p>Is it possible to do complex regex operations to retrieve name, role, designation in python? I have attached the pic for my requirement. <a href="http://i.stack.imgur.com/xqqMz.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/xqqMz.jpg" alt="enter image description here"></a></p>
-1
2016-08-30T17:04:23Z
39,237,171
<p>The answer is Yes and No. </p> <p>Regex is pattern matching. Anything that follows a specific pattern like phone number and url, yes you can extract that information using Regex with a great degree of accuracy.</p> <p>Refer:</p> <p><a href="http://stackoverflow.com/questions/3868753/find-phone-numbers-in-python-s...
0
2016-08-30T21:12:39Z
[ "python", "regex", "nltk" ]
pytest logbook logging to file and stdout
39,233,277
<p>I'm trying to setup logbook in a pytest test to output everything to both stderr and a file. The file should get every log level, but stderr should have a higher threshold (which pytest will manage with it's usual capture settings).</p> <p>I've got the pytest-logbook plugin. That redirects stderr into pytest capt...
0
2016-08-30T17:05:08Z
39,256,372
<p>Answering my own question (in case other run into the same thing).</p> <p>The logging handlers form a stack and you have to allow messages to "bubble" through. This is done as an option when the handlers are created.</p> <p>So the handler creation should be:</p> <pre><code>logger.handlers.append(logbook.FileHand...
0
2016-08-31T18:13:18Z
[ "python", "py.test", "logbook" ]
Check django permission or operator?
39,233,347
<p>For my view, I am checking the permission through the @permission_required decorator but I really wish to check for "either" permission A or permission B. so if user has at least one of two permissions, the view is execute...</p> <p>Is there a way to do this?</p>
0
2016-08-30T17:09:23Z
39,233,603
<p>You could write your own decorator for this. Or use <code>django.contrib.auth.decorators.user_passes_test(your_test_func)</code> to create a custom decorator.</p> <p>In both cases, have a look at the source code of the <code>permission_required</code> decorator in the above module.</p>
0
2016-08-30T17:26:08Z
[ "python", "django", "model-view-controller", "permissions" ]
Regex to parse out a part of URL
39,233,526
<p>I am having the following data,</p> <pre><code>data http://hsotname.com/2016/08/a-b-n-r-y-u https://www.hostname.com/best-food-for-humans http://www.hostname.com/wp-content/uploads/2014/07/a-w-w-2.jpg http://www.hostname.com/a/geniusbar/ http://www.hsotname.com/m/ http://www.hsotname.com/ </code></pre> <p>I want t...
1
2016-08-30T17:21:00Z
39,233,587
<p>Another option is to simply split on "/" and take the last element:</p> <pre><code>"http://hsotname.com/2016/08/a-b-n-r-y-u".split("/")[-1] # 'a-b-n-r-y-u' "http://www.hostname.com/a/geniusbar/".split("/")[-1] # '' </code></pre>
2
2016-08-30T17:25:06Z
[ "python", "regex", "regex-negation" ]
Regex to parse out a part of URL
39,233,526
<p>I am having the following data,</p> <pre><code>data http://hsotname.com/2016/08/a-b-n-r-y-u https://www.hostname.com/best-food-for-humans http://www.hostname.com/wp-content/uploads/2014/07/a-w-w-2.jpg http://www.hostname.com/a/geniusbar/ http://www.hsotname.com/m/ http://www.hsotname.com/ </code></pre> <p>I want t...
1
2016-08-30T17:21:00Z
39,233,592
<p>I'd go with something like this:</p> <pre><code>\/([^/]*)$ </code></pre> <p>It'll match the last slash, then grab anything after it (if anything) that isn't a slash.</p>
0
2016-08-30T17:25:18Z
[ "python", "regex", "regex-negation" ]
Regex to parse out a part of URL
39,233,526
<p>I am having the following data,</p> <pre><code>data http://hsotname.com/2016/08/a-b-n-r-y-u https://www.hostname.com/best-food-for-humans http://www.hostname.com/wp-content/uploads/2014/07/a-w-w-2.jpg http://www.hostname.com/a/geniusbar/ http://www.hsotname.com/m/ http://www.hsotname.com/ </code></pre> <p>I want t...
1
2016-08-30T17:21:00Z
39,233,598
<p>Regex isn't the best tool in this case. Just use str.rfind:</p> <pre><code>[url[url.rfind('/'):] for url in data] </code></pre> <p>Will give you what you're looking for</p>
0
2016-08-30T17:25:48Z
[ "python", "regex", "regex-negation" ]
Regex to parse out a part of URL
39,233,526
<p>I am having the following data,</p> <pre><code>data http://hsotname.com/2016/08/a-b-n-r-y-u https://www.hostname.com/best-food-for-humans http://www.hostname.com/wp-content/uploads/2014/07/a-w-w-2.jpg http://www.hostname.com/a/geniusbar/ http://www.hsotname.com/m/ http://www.hsotname.com/ </code></pre> <p>I want t...
1
2016-08-30T17:21:00Z
39,233,712
<p>Regexes are probably not the way you should do this - considering that you marked the question <code>python</code>, try (assuming the URL is in name <code>url</code>):</p> <pre><code>last-part = url.split('/')[-1] </code></pre> <p>This splits the URL into a list of substrings between slashes, and stores the last o...
1
2016-08-30T17:32:23Z
[ "python", "regex", "regex-negation" ]
Regex to parse out a part of URL
39,233,526
<p>I am having the following data,</p> <pre><code>data http://hsotname.com/2016/08/a-b-n-r-y-u https://www.hostname.com/best-food-for-humans http://www.hostname.com/wp-content/uploads/2014/07/a-w-w-2.jpg http://www.hostname.com/a/geniusbar/ http://www.hsotname.com/m/ http://www.hsotname.com/ </code></pre> <p>I want t...
1
2016-08-30T17:21:00Z
39,233,790
<p>Possibly over kill for the example, but if you need to deal with location fragments/just location names (ie, the last forward slash is part of the http etc... (splitting <code>http://hostname.com</code> and taking the last <code>/</code> will give you <code>hostname.com</code> - <code>urlsplit</code> will give a pat...
0
2016-08-30T17:37:16Z
[ "python", "regex", "regex-negation" ]
Regex to parse out a part of URL
39,233,526
<p>I am having the following data,</p> <pre><code>data http://hsotname.com/2016/08/a-b-n-r-y-u https://www.hostname.com/best-food-for-humans http://www.hostname.com/wp-content/uploads/2014/07/a-w-w-2.jpg http://www.hostname.com/a/geniusbar/ http://www.hsotname.com/m/ http://www.hsotname.com/ </code></pre> <p>I want t...
1
2016-08-30T17:21:00Z
39,235,084
<p>Check from the end of the URL, and match every thing but / </p> <pre><code>[^/]+?$ </code></pre> <p>or</p> <pre><code>\b[^/]+?\b$ </code></pre>
0
2016-08-30T18:54:03Z
[ "python", "regex", "regex-negation" ]
Subplots size/tick spacing pyplot
39,233,569
<p>I have searched for similar problems and not found any, so I apologize.</p> <p>I have this:</p> <pre><code>import matplotlib.pyplot as plt yearlymean_gm = np.load('ts_globalmean_annualmean.npz') ts = yearlymean_gm['ts_aqct'] time = np.arange(0., 45 , 1) plt.figure( figsize=(12, 5), dpi=80, facecolor='w', edgecol...
0
2016-08-30T17:23:19Z
39,237,503
<p>Ok, so several things are happening here. Let got through them one at a time. After you instantiate the plot, you call <code>ax = plt.subplot(3, 4, _)</code> 3 times. However, <code>.subplot(3,4,_)</code> breaks the plot into 3 rows and 4 columns and the underscore selects which piece of this grid to select start...
1
2016-08-30T21:39:21Z
[ "python", "matplotlib", "subplot" ]
Why isnt this simple "rock paper scissors" program working in Python?
39,233,591
<p>Im new to python and Im trying to write a program in which the user plays rock paper scissors against the computer. However, i dont know why it isnt working. Heres the code:</p> <pre><code>import random computerResult = random.randint(1,3) print("Lets play Rock Paper Scissors") playerResult = input("Type 1 for Ro...
0
2016-08-30T17:25:14Z
39,233,629
<p>Because <code>playerResult</code> is a <code>str</code> and <code>computerResult</code> is <code>int</code>. And comparing string to int always results in <code>False</code></p> <p>Change </p> <pre><code>playerResult = input("Type 1 for Rock, 2 for Paper or 3 for Scissors: ") </code></pre> <p>To</p> <pre><code>p...
6
2016-08-30T17:27:55Z
[ "python", "python-3.x" ]
Why isnt this simple "rock paper scissors" program working in Python?
39,233,591
<p>Im new to python and Im trying to write a program in which the user plays rock paper scissors against the computer. However, i dont know why it isnt working. Heres the code:</p> <pre><code>import random computerResult = random.randint(1,3) print("Lets play Rock Paper Scissors") playerResult = input("Type 1 for Ro...
0
2016-08-30T17:25:14Z
39,233,656
<p>This should fix it</p> <pre><code>playerResult = input("Type 1 for Rock, 2 for Paper or 3 for Scissors: ") playerResult = int(playerResult) </code></pre>
1
2016-08-30T17:29:15Z
[ "python", "python-3.x" ]
Why isnt this simple "rock paper scissors" program working in Python?
39,233,591
<p>Im new to python and Im trying to write a program in which the user plays rock paper scissors against the computer. However, i dont know why it isnt working. Heres the code:</p> <pre><code>import random computerResult = random.randint(1,3) print("Lets play Rock Paper Scissors") playerResult = input("Type 1 for Ro...
0
2016-08-30T17:25:14Z
39,233,678
<p>The problem with your code is is that your assuming the <code>input()</code> function returns a integer. It does not, it returns a <strong>string</strong>. Change this line</p> <p><code>playerResult = input("Type 1 for Rock, 2 for Paper or 3 for Scissors: ")</code></p> <p>to this:</p> <p><code>playerResult = int(...
0
2016-08-30T17:30:25Z
[ "python", "python-3.x" ]
Why isnt this simple "rock paper scissors" program working in Python?
39,233,591
<p>Im new to python and Im trying to write a program in which the user plays rock paper scissors against the computer. However, i dont know why it isnt working. Heres the code:</p> <pre><code>import random computerResult = random.randint(1,3) print("Lets play Rock Paper Scissors") playerResult = input("Type 1 for Ro...
0
2016-08-30T17:25:14Z
39,233,772
<p>The problem will be fixed casting the user input to an integer.</p> <p>I'll also add a check to handle the bad input casistic:</p> <pre><code>goodResult = False </code></pre> <p>playerResult = 0</p> <pre><code>while not goodResult: inp = input("Type 1 for Rock, 2 for Paper or 3 for Scissors: ") try: ...
0
2016-08-30T17:35:54Z
[ "python", "python-3.x" ]
Sending in String vs Reading String
39,233,641
<p>I have a text file that contains something like:</p> <pre><code>IP_ADD = "10.10.150.3" BACKUP_IP = "10.10.150.4" </code></pre> <p>and the code to read it in:</p> <pre><code>counter = 0 wordList = [None] * 100 with open("config.txt") as f: content = f.read().splitlines() for line in content: line = line....
0
2016-08-30T17:28:31Z
39,233,707
<p>From what you wrote it appears that your file has the IP addr in quotes. Hence</p> <pre><code> line = line.split(' ',2)[-1] </code></pre> <p>will return an IP address in quotes as a string, aka</p> <pre><code> "\"10.0.0.1\"" </code></pre> <p>This is what you are sending across the wire, which is probably not wha...
3
2016-08-30T17:31:53Z
[ "python", "string", "file", "io" ]
Sending in String vs Reading String
39,233,641
<p>I have a text file that contains something like:</p> <pre><code>IP_ADD = "10.10.150.3" BACKUP_IP = "10.10.150.4" </code></pre> <p>and the code to read it in:</p> <pre><code>counter = 0 wordList = [None] * 100 with open("config.txt") as f: content = f.read().splitlines() for line in content: line = line....
0
2016-08-30T17:28:31Z
39,234,012
<p>You almost got it, you just need to strip the double quotes around your IPs. Use <code>strip('"')</code> to do that.</p> <pre><code>line.split(' ',2)[-1].strip('"') </code></pre> <hr> <p>Your code seems too shabby, no offence. You are doing things many of which are not necessary. You can do it much simply this wa...
0
2016-08-30T17:50:00Z
[ "python", "string", "file", "io" ]
Nonblocking fifo
39,233,663
<p>How can I make a fifo between two python processes, that allow dropping of lines if the reader is not able to handle the input?</p> <ul> <li>If the reader tries to <code>read</code> or <code>readline</code> faster then the writer writes, it should block.</li> <li>If the reader cannot work as fast as the writer writ...
3
2016-08-30T17:29:49Z
39,233,976
<p>Well, that's not actually a FIFO (queue) as far as I am aware - it's a single variable. I suppose it might be implementable if you set up a queue or pipe with a maximum size of 1, but it seems that it would work better to use a <a href="https://docs.python.org/3/library/multiprocessing.html#multiprocessing.Lock" rel...
0
2016-08-30T17:48:04Z
[ "python", "blocking", "nonblocking", "fifo" ]
Nonblocking fifo
39,233,663
<p>How can I make a fifo between two python processes, that allow dropping of lines if the reader is not able to handle the input?</p> <ul> <li>If the reader tries to <code>read</code> or <code>readline</code> faster then the writer writes, it should block.</li> <li>If the reader cannot work as fast as the writer writ...
3
2016-08-30T17:29:49Z
39,259,030
<p>The following code uses a named FIFO to allow communication between two scripts.</p> <ul> <li>If the reader tries to <code>read</code> faster than the writer, it blocks.</li> <li>If the reader cannot keep up with the writer, the writer does not block.</li> <li>Operations are buffer oriented. Line oriented operation...
1
2016-08-31T21:08:08Z
[ "python", "blocking", "nonblocking", "fifo" ]
Interactive HTML plots from Python's Bokeh to Latex
39,233,673
<p>I would like to embed an interactive HTML based plot (For example, <a href="http://bokeh.pydata.org/en/0.10.0/docs/gallery/burtin.html" rel="nofollow">http://bokeh.pydata.org/en/0.10.0/docs/gallery/burtin.html</a>)<br> in a pdf document that I generated using latex. I am able to embed matplotlib based plots in my do...
0
2016-08-30T17:30:14Z
39,234,545
<p>As of Bokeh <code>0.12.1</code> this is not possible. Although Bokeh is a "Python" library, it was designed and conceived for the purpose of making it simple to make interactive visualizations in the browser. Accordingly, it has large JavaScript component (where all the work is done, actually), and requires a runnin...
0
2016-08-30T18:21:30Z
[ "python", "html", "matplotlib", "latex", "bokeh" ]
Insert into oracle table from CSV using python
39,233,742
<p>I am reading a csv file with 5 columns and push to oracle table</p> <p><a href="http://i.stack.imgur.com/kkoNu.jpg" rel="nofollow">CSV file Structure</a></p> <p>I know there are lots of resources on this .. But even then I am unable to find a solution for my problem </p> <p>Code to read the CSV to python : </p> ...
1
2016-08-30T17:33:50Z
39,249,806
<p>That error means what it said <a href="https://bitbucket.org/anthony_tuininga/cx_oracle/issues/36/ora-01484-arrays-can-only-be-bound-to-pl" rel="nofollow">here</a> </p> <blockquote> <p>This is not a bug. You are issuing a SQL query, not a PL/SQL statement and this sort of thing is not supported by Oracle. In this...
0
2016-08-31T12:33:37Z
[ "python", "oracle", "csv", "insert-into", "cx-oracle" ]
Insert into oracle table from CSV using python
39,233,742
<p>I am reading a csv file with 5 columns and push to oracle table</p> <p><a href="http://i.stack.imgur.com/kkoNu.jpg" rel="nofollow">CSV file Structure</a></p> <p>I know there are lots of resources on this .. But even then I am unable to find a solution for my problem </p> <p>Code to read the CSV to python : </p> ...
1
2016-08-30T17:33:50Z
39,251,390
<p>The problem is that you are trying to pass an array to a single insert statement. You have two options here:</p> <p>1) Use a loop to insert each row separately:</p> <pre><code>for line in lines: cursor.execute("insert into ...", line) </code></pre> <p>2) Use cursor.executemany() instead to do an array insert<...
1
2016-08-31T13:44:23Z
[ "python", "oracle", "csv", "insert-into", "cx-oracle" ]
Insert into oracle table from CSV using python
39,233,742
<p>I am reading a csv file with 5 columns and push to oracle table</p> <p><a href="http://i.stack.imgur.com/kkoNu.jpg" rel="nofollow">CSV file Structure</a></p> <p>I know there are lots of resources on this .. But even then I am unable to find a solution for my problem </p> <p>Code to read the CSV to python : </p> ...
1
2016-08-30T17:33:50Z
39,254,043
<p>Thanks for your answers :) The issue got resolved once I changed from </p> <pre><code>cur.execute("INSERT INTO TEST_CSODUPLOAD ('FIRSTNAME','LASTNAME','EMAIL','COURSE_NAME','STATUS') VALUES(:1,:2,:3,:4,:5)",lines) </code></pre> <p>to</p> <pre><code>cur.executemany("insert into TEST_CSODUPLOAD(Firstname,LastName,...
1
2016-08-31T15:52:19Z
[ "python", "oracle", "csv", "insert-into", "cx-oracle" ]
Error with calculator type program in python
39,233,756
<pre><code>numbers=[] while True: print('Input Number '+str(len(numbers)+1)+' (or nothing to close):') number=input() numbers=numbers+[number] if number=='': print('What do you want to do?') answer=input() break if answer==mean: mean def mean(): end_mean=r...
-1
2016-08-30T17:35:04Z
39,233,802
<p>First, you <strong>break</strong> before you get to the check. Your check itself will also fail:</p> <pre><code>if answer==mean: mean </code></pre> <p>You've compared the answer (a string) to mean (a function object). Try:</p> <pre><code>if answer == "mean": mean() </code></pre> <p>Also, I expect that ...
1
2016-08-30T17:38:08Z
[ "python" ]
Error with calculator type program in python
39,233,756
<pre><code>numbers=[] while True: print('Input Number '+str(len(numbers)+1)+' (or nothing to close):') number=input() numbers=numbers+[number] if number=='': print('What do you want to do?') answer=input() break if answer==mean: mean def mean(): end_mean=r...
-1
2016-08-30T17:35:04Z
39,234,209
<p>May be this will help you.</p> <pre><code>numbers=[] def means(): end_mean = reduce(lambda x, y: x + y, numbers) / len(numbers) print(end_mean) while True: print('Input Number '+str(len(numbers)+1)+' (or nothing to close):') try: number= int(input()) numbers.append(number) exce...
1
2016-08-30T18:01:45Z
[ "python" ]
Python: How to search tweets and store in database?
39,233,769
<p>I've got a nice Python script that currently prints out the past 200 tweets from a given username. </p> <p>However, I'd like to modify it so that instead it will collect the past 200 tweets that include a certain hashtag (from any username) and then I'd like to store those results in a database.</p> <p>Can anyone ...
0
2016-08-30T17:35:40Z
39,234,181
<p>Not familiar with the twitter package but this could be a suggestion that you can work on. Depends on how you want to save the tweet, you can replace the "print status" with the way you want. <strong>However, this only allows you to filter the 200 tweets rather than get the 200 tweets that contain certain hashtag.</...
0
2016-08-30T18:00:26Z
[ "python", "twitter" ]
Python: How to search tweets and store in database?
39,233,769
<p>I've got a nice Python script that currently prints out the past 200 tweets from a given username. </p> <p>However, I'd like to modify it so that instead it will collect the past 200 tweets that include a certain hashtag (from any username) and then I'd like to store those results in a database.</p> <p>Can anyone ...
0
2016-08-30T17:35:40Z
39,248,197
<p>I am attaching a java code that will print out past 100 tweets including '#engineeringproblems' hashtag (from any user). You need to add twitter API 'twitter4J' in the library.</p> <p>API download link- <a href="http://twitter4j.org/en/index.html#download" rel="nofollow">http://twitter4j.org/en/index.html#download<...
0
2016-08-31T11:18:26Z
[ "python", "twitter" ]
Python: How to search tweets and store in database?
39,233,769
<p>I've got a nice Python script that currently prints out the past 200 tweets from a given username. </p> <p>However, I'd like to modify it so that instead it will collect the past 200 tweets that include a certain hashtag (from any username) and then I'd like to store those results in a database.</p> <p>Can anyone ...
0
2016-08-30T17:35:40Z
39,261,908
<p>Sorry, but I've really been looking for a Python solution and I believe I've finally found it and tested it successfully. Code is below. Still looking for a way to modify the script to enter each line into a SQL database, but I hopefully I can find that elsewhere.</p> <p>pip install TwitterSearch</p> <pre><code>fr...
0
2016-09-01T02:43:24Z
[ "python", "twitter" ]
Django 1.10: django-storages on S3 error: Not naive datetime (tzinfo is already set)
39,233,853
<p>I've started getting an error since upgrading to Django 1.10. I'm running Django 1.10 on Python 3.5 with <code>django-storages==1.5.0</code> and <code>boto3==1.4.0</code>.</p> <pre><code>You have requested to collect static files at the destination location as specified in your settings. This will overwrite existi...
0
2016-08-30T17:40:44Z
39,234,032
<p>I've figured out a temporary fix which should lead to a permanent fix.</p> <p>After some more sleuthing, a friend found this PR they thought might be related: <a href="https://github.com/jschneier/django-storages/pull/181" rel="nofollow">https://github.com/jschneier/django-storages/pull/181</a></p> <p>I noticed th...
0
2016-08-30T17:50:49Z
[ "python", "django", "boto3", "django-storage" ]
How to split a string to get the last item in braces?
39,233,908
<p>I'm trying to split a string to extract the last item in braces.</p> <p>For example if I had the string</p> <pre><code>'Stud Rd/(after) Ferntree Gully Rd (Scoresby)' </code></pre> <p>I would like to split it into the components</p> <pre><code>('Stud Rd/(after) Ferntree Gully Rd', 'Scoresby') </code></pre> <p>So...
0
2016-08-30T17:43:46Z
39,234,003
<p>I would use this scheme, given <code>t</code> being your text:</p> <pre><code>last = re.findall('\([^())]+\)', t)[-1] </code></pre> <p>The regex searches for an opening parenthesis, then take everything that is neither opening nor closing parenthesis, and then matches the closing parenthesis. Since there could be ...
0
2016-08-30T17:49:24Z
[ "python", "regex" ]
How to split a string to get the last item in braces?
39,233,908
<p>I'm trying to split a string to extract the last item in braces.</p> <p>For example if I had the string</p> <pre><code>'Stud Rd/(after) Ferntree Gully Rd (Scoresby)' </code></pre> <p>I would like to split it into the components</p> <pre><code>('Stud Rd/(after) Ferntree Gully Rd', 'Scoresby') </code></pre> <p>So...
0
2016-08-30T17:43:46Z
39,234,049
<p>This works assuming you don't have any parenthesis prior to the last chunk.</p> <pre><code>var = 'Bell St/Oriel Rd', 'Bellfield (3081)'.split('(') var[-1] = var[-1][:-1] </code></pre>
0
2016-08-30T17:51:58Z
[ "python", "regex" ]
How to split a string to get the last item in braces?
39,233,908
<p>I'm trying to split a string to extract the last item in braces.</p> <p>For example if I had the string</p> <pre><code>'Stud Rd/(after) Ferntree Gully Rd (Scoresby)' </code></pre> <p>I would like to split it into the components</p> <pre><code>('Stud Rd/(after) Ferntree Gully Rd', 'Scoresby') </code></pre> <p>So...
0
2016-08-30T17:43:46Z
39,234,078
<p>You can use this lazy regex:</p> <pre><code>(.*?) \((.*)\)[^()]*$ </code></pre> <p><a href="https://regex101.com/r/yQ8xI8/1" rel="nofollow">RegEx Demo</a></p> <p>Examples:</p> <pre><code>&gt;&gt;&gt; reg = r'(.*?) \((.*)\)[^()]*$' &gt;&gt;&gt; s = 'Bell St/Oriel Rd (Bellfield (3081))' &gt;&gt;&gt; re.findall(re...
4
2016-08-30T17:53:36Z
[ "python", "regex" ]
How to split a string to get the last item in braces?
39,233,908
<p>I'm trying to split a string to extract the last item in braces.</p> <p>For example if I had the string</p> <pre><code>'Stud Rd/(after) Ferntree Gully Rd (Scoresby)' </code></pre> <p>I would like to split it into the components</p> <pre><code>('Stud Rd/(after) Ferntree Gully Rd', 'Scoresby') </code></pre> <p>So...
0
2016-08-30T17:43:46Z
39,234,200
<p>Change your regex pattern and work with <strong>match</strong> object(returned by <code>search</code> function) in proper way:</p> <pre><code>import re str = 'Bell St/Oriel Rd (Bellfield (3081))' result = re.search(r'^(.*?) \((.*?)\)$', str) print(result.group(1,2)) # ('Bell St/Oriel Rd', 'Bellfield (3081)') </...
1
2016-08-30T18:01:14Z
[ "python", "regex" ]
Using a variable as field name in MySQLdb, Python 2.7
39,233,935
<p>This works when I replace the column variable with an actual column name. I do however need a variable. When I use a variable I get a MySQL syntax error. Can a field be a variable? If so, where is the error?</p> <pre><code>conn = self.create_connection() cur = conn[0] db = conn[1] cur.execu...
0
2016-08-30T17:45:30Z
39,236,320
<p>The issue there is that Parameter substitution in the <code>execute</code> method is intended to be used for data only - as you found out. That is not quite explicit in the <a href="https://www.python.org/dev/peps/pep-0249/" rel="nofollow">documentation</a>, but it is how most database drivers implement it. </p> ...
2
2016-08-30T20:13:11Z
[ "python", "python-2.7", "mysql-python" ]
Trying to use a string variable in serial .write in Python
39,233,956
<p>I am communicating with a power supply through rs232. I can communicate no problem when I send for example:</p> <pre><code>port.write("\x31") </code></pre> <p>but if instead I have a string as a variable</p> <pre><code>teststring='"\\x31"' </code></pre> <p>(which prints out as "\x31")</p> <p>and I try:</p>...
0
2016-08-30T17:46:54Z
39,234,044
<p><code>teststring</code> in your example is escaping the backslash; you have <code>"\\x30"</code>, instead of <code>"\x30"</code>. <code>"\x30"</code> is a length-1 string containing the byte 0x30; <code>"\\x30"</code> is a length-4 string containing the characters <code>\</code>, <code>x</code>, <code>3</code> and <...
0
2016-08-30T17:51:32Z
[ "python" ]
how can i put a input to take the (( url )) for this function
39,234,059
<pre><code>import random import urllib.request def down_load_imag(url): name = random.randrange(1, 1000) full_name = str(name) + ".jpg" urllib.request.urlretrieve(url, full_name) down_load_imag ("http://3.bp.blogspot.com/-WjQkpjkw9uQ/Vij8lG0pCdI/AAAAAAAAAJ4/-CifLZ5KG-Y/s1600/fedora_infinity_140x140.png") ...
-4
2016-08-30T17:52:39Z
39,235,020
<p>in python3 you must use <code>input()</code> function:</p> <pre><code>import random import urllib.request def down_load_imag(url): name = random.randrange(1, 1000) full_name = str(name) + ".jpg" urllib.request.urlretrieve(url, full_name) url = input('Enter url: ') # here you can evaluate url with regex...
0
2016-08-30T18:50:26Z
[ "python", "python-3.x" ]
how can i put a input to take the (( url )) for this function
39,234,059
<pre><code>import random import urllib.request def down_load_imag(url): name = random.randrange(1, 1000) full_name = str(name) + ".jpg" urllib.request.urlretrieve(url, full_name) down_load_imag ("http://3.bp.blogspot.com/-WjQkpjkw9uQ/Vij8lG0pCdI/AAAAAAAAAJ4/-CifLZ5KG-Y/s1600/fedora_infinity_140x140.png") ...
-4
2016-08-30T17:52:39Z
39,235,469
<p>Python comes with the <a href="https://docs.python.org/3/library/argparse.html" rel="nofollow" title="argparse">argparse</a> module. Suppose your code lives in <code>downloader.py</code>, then add this:</p> <pre><code>import argparse import sys parser = argparse.ArgumentParser(description="Download image to random...
0
2016-08-30T19:18:05Z
[ "python", "python-3.x" ]
list index out of range in heroku/phython - trying to follow guide to code
39,234,065
<p>I'm trying to follow this guide: <a href="https://medium.com/@sarahnadia/how-to-code-a-simple-twitter-bot-for-complete-beginners-36e37231e67d#.k2cljjf0m" rel="nofollow">https://medium.com/@sarahnadia/how-to-code-a-simple-twitter-bot-for-complete-beginners-36e37231e67d#.k2cljjf0m</a></p> <p>This is the error message...
0
2016-08-30T17:52:57Z
39,235,057
<p>The traceback tells us the error is here:</p> <pre><code>max_id = user_tweets[len(user_tweets)-1].id-1 </code></pre> <p>which will be out of range if user_tweets is an empty list. You can check to make sure it isn't before trying to access its value.</p> <pre><code>if len(user_tweets) &gt; 0: max_id = user_twe...
0
2016-08-30T18:52:33Z
[ "python", "heroku" ]
Could not broadcast input array from shape (1285) into shape (1285, 5334)
39,234,069
<p>I'm trying to follow some example code provided in the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.svd.html" rel="nofollow">documentation</a> for <code>np.linalg.svd</code> in order to compare term and document similarities following an SVD on a TDM matrix. Here's what I've got:</p> <p...
-2
2016-08-30T17:53:04Z
39,234,275
<p>(note, looking at Bi Rico's answer, it looks like perhaps the right interpretation was that you aren't actually trying to broadcast with that command? This answer shows how to actually do the broadcasting.)</p> <pre><code>X = scipy.zeros((5,4)) X &gt; array([[ 0., 0., 0., 0.], [ 0., 0., 0., 0.], ...
0
2016-08-30T18:05:20Z
[ "python", "numpy", "svd" ]
Could not broadcast input array from shape (1285) into shape (1285, 5334)
39,234,069
<p>I'm trying to follow some example code provided in the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.svd.html" rel="nofollow">documentation</a> for <code>np.linalg.svd</code> in order to compare term and document similarities following an SVD on a TDM matrix. Here's what I've got:</p> <p...
-2
2016-08-30T17:53:04Z
39,234,309
<p>You're using slicing when you should be using indexing. Take for example:</p> <pre><code>A = np.zeros((4, 5)) end0, end1 = A.shape # These are both true A == A[:, :] A[:, :] == A[:end0, :end1] # To get the diagonal of an array you want to use range or np.arange A[range(end0), range(end0)] == A.diagonal() </code><...
0
2016-08-30T18:06:59Z
[ "python", "numpy", "svd" ]
Could not broadcast input array from shape (1285) into shape (1285, 5334)
39,234,069
<p>I'm trying to follow some example code provided in the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.svd.html" rel="nofollow">documentation</a> for <code>np.linalg.svd</code> in order to compare term and document similarities following an SVD on a TDM matrix. Here's what I've got:</p> <p...
-2
2016-08-30T17:53:04Z
39,238,203
<p>So according to the error message, the target </p> <pre><code>S[:results_t[2].shape[0], :results_t[2].shape[0]] </code></pre> <p>is <code>(1285,5334)</code>, while the source</p> <pre><code>results_t[1] </code></pre> <p>is <code>(1285,)</code>.</p> <p>So it has to broadcast the source to a shape that matches th...
1
2016-08-30T22:44:26Z
[ "python", "numpy", "svd" ]
'NotImplementedType' object is not iterable django-easy-pdf
39,234,070
<p>I use django-easy-pdf library for my project. When I try to set custom cyrillic font I have </p> <blockquote> <p>TypeError: 'NotImplementedType' object is not iterable</p> </blockquote> <p>I`ve seen where the error appear and here is what I got</p> <p><a href="http://i.stack.imgur.com/04jnk.png" rel="nofollow">...
0
2016-08-30T17:53:08Z
39,235,314
<p>STATIC_ROOT should be os.path.join(PROJECT_ROOT, 'static'). I am assuming automobiles is the main project. </p>
0
2016-08-30T19:08:08Z
[ "python", "django", "python-3.x", "pdf", "django-staticfiles" ]
Python class shared variables gives unexpected output
39,234,297
<p>Based on the explanation on <a href="http://stackoverflow.com/questions/1537202/variables-inside-and-outside-of-a-class-init-function">Shared Variables in Python Class</a> here , I expected the following code to give output as :</p> <pre><code>123 123 200 200 300 300 </code></pre> <p>But it is </p> <pre><code>123...
0
2016-08-30T18:06:25Z
39,234,403
<p>You are creating a new instance variable -> <code>a.abc</code> and setting it to <code>200</code>. Access the shared static variable instead.</p> <pre><code>a = A(2, 4, 6) b = A(3, 9, 27) print a.abc , b.abc A.abc = 200 # Set static class variable, instead of creating new instance member print a.abc , b.abc A.abc ...
5
2016-08-30T18:13:00Z
[ "python", "class", "oop" ]
Python class shared variables gives unexpected output
39,234,297
<p>Based on the explanation on <a href="http://stackoverflow.com/questions/1537202/variables-inside-and-outside-of-a-class-init-function">Shared Variables in Python Class</a> here , I expected the following code to give output as :</p> <pre><code>123 123 200 200 300 300 </code></pre> <p>But it is </p> <pre><code>123...
0
2016-08-30T18:06:25Z
39,234,412
<p>Initially, the class A has an <code>abc</code> defined to be 123, which each of <code>a</code> and <code>b</code> use since neither has an <code>abc</code> of their own.</p> <p>Then you execute <code>a.abc = 200</code>, which creates an <code>abc</code> for <code>a</code>; <code>b</code> still uses the one from <co...
3
2016-08-30T18:13:24Z
[ "python", "class", "oop" ]
Python class shared variables gives unexpected output
39,234,297
<p>Based on the explanation on <a href="http://stackoverflow.com/questions/1537202/variables-inside-and-outside-of-a-class-init-function">Shared Variables in Python Class</a> here , I expected the following code to give output as :</p> <pre><code>123 123 200 200 300 300 </code></pre> <p>But it is </p> <pre><code>123...
0
2016-08-30T18:06:25Z
39,234,501
<p>Your expected output would mean that you can't change the attribute of an object without changing the attribute of every instance of the objects class. That would obviously break the core of the object orientation idea. I think you can overwrite "shared" variables because this gives just more possibilities.</p>
-1
2016-08-30T18:18:29Z
[ "python", "class", "oop" ]
Python class shared variables gives unexpected output
39,234,297
<p>Based on the explanation on <a href="http://stackoverflow.com/questions/1537202/variables-inside-and-outside-of-a-class-init-function">Shared Variables in Python Class</a> here , I expected the following code to give output as :</p> <pre><code>123 123 200 200 300 300 </code></pre> <p>But it is </p> <pre><code>123...
0
2016-08-30T18:06:25Z
39,234,864
<p><a href="http://stackoverflow.com/a/39234412/2373278">@Scott Hunter's answer</a> explains the behavior of code in question best but I would like to add C++ perspective to it here. Unfortunately it couldn't be added as comment in that answer as it is too long. </p> <p>As in C++, to access static members name needs t...
0
2016-08-30T18:40:08Z
[ "python", "class", "oop" ]
Python - Printing a ctype string buffer in my Read/WriteProcessMemory application
39,234,298
<p>Let me say that this was my first attempt at a proper memory reading and writing application. The writing function isn't even implemented yet but it will come in time. Just don't flame me for the code.</p> <p>First thing is the complete program for so everyone can see (don't comment on my "bad coding choices", the ...
1
2016-08-30T18:06:26Z
39,382,072
<p>You are printing the object. Print the contents:</p> <pre><code>&gt;&gt;&gt; import ctypes &gt;&gt;&gt; BufferAddress = ctypes.create_string_buffer(64) &gt;&gt;&gt; print(BufferAddress) &lt;ctypes.c_char_Array_64 object at 0x0000000003124248&gt; &gt;&gt;&gt; dir(BufferAddress) ['__class__', '__ctypes_from_outparam...
0
2016-09-08T03:19:35Z
[ "python", "memory", "buffer", "ctypes", "readprocessmemory" ]
.persist() line sometimes leads to Java Out of Heap Space error
39,234,302
<p>As far as I know, when you use <code>.persist()</code>, writing the line <code>persist</code> sets only the persistence level, and then the next <code>action</code> in the script will cause the actual persistence work to be invoked.</p> <p>However, sometimes, seemingly depending on the dataframe, <code>persist()</c...
1
2016-08-30T18:06:37Z
39,237,323
<p>The whole point of <a href="http://spark.apache.org/docs/latest/programming-guide.html#rdd-persistence" rel="nofollow">RDD Persistence</a> is to store intermediate results in memory, allowing faster access on subsequent use. There are several different levels of persistence, ranging from <code>MEMORY_ONLY</code> (th...
2
2016-08-30T21:25:24Z
[ "python", "apache-spark", "pyspark", "elastic-map-reduce" ]
Towards understanding One Line For loops
39,234,453
<p>After reading <a href="http://stackoverflow.com/questions/12920214/python-for-syntax-block-code-vs-single-line-generator-expressions">this</a> question, I have this PySpark code:</p> <pre><code>model = KMeansModel(model.Cs[0]) first_split = split_vecs.map(lambda x: x[0]) model.computeCost(first_split) model = KMean...
2
2016-08-30T18:15:28Z
39,234,486
<p>Try it without the semi colon. Though honestly I wouldn't recommend using one line for statements outside of generator expressions</p>
0
2016-08-30T18:17:23Z
[ "python", "loops", "for-loop", "apache-spark", "pyspark" ]
Towards understanding One Line For loops
39,234,453
<p>After reading <a href="http://stackoverflow.com/questions/12920214/python-for-syntax-block-code-vs-single-line-generator-expressions">this</a> question, I have this PySpark code:</p> <pre><code>model = KMeansModel(model.Cs[0]) first_split = split_vecs.map(lambda x: x[0]) model.computeCost(first_split) model = KMean...
2
2016-08-30T18:15:28Z
39,234,855
<p>This is untested, but it looks like it could work for you</p> <pre><code>computedCost = [KMeansModel(model.Cs[i]).computeCost(x[i]) for i in xrange(2)] </code></pre> <p>What it does is create a list of results after performing computeCost() on the results of <code>KMeansModel()</code>. the <code>xrange for loop</...
1
2016-08-30T18:39:50Z
[ "python", "loops", "for-loop", "apache-spark", "pyspark" ]
Towards understanding One Line For loops
39,234,453
<p>After reading <a href="http://stackoverflow.com/questions/12920214/python-for-syntax-block-code-vs-single-line-generator-expressions">this</a> question, I have this PySpark code:</p> <pre><code>model = KMeansModel(model.Cs[0]) first_split = split_vecs.map(lambda x: x[0]) model.computeCost(first_split) model = KMean...
2
2016-08-30T18:15:28Z
39,234,861
<p>A list comprehension version of what you did in that example would be:</p> <pre><code>[KMeansModel(model.Cs[i]).computeCost(split_vecs.map(lambda x: x[i])) for i in range(2)] </code></pre> <p>This is no different than:</p> <pre><code>results = [] for i in range(2): results.append(KMeansModel(model.Cs[i]).comp...
4
2016-08-30T18:40:04Z
[ "python", "loops", "for-loop", "apache-spark", "pyspark" ]
Towards understanding One Line For loops
39,234,453
<p>After reading <a href="http://stackoverflow.com/questions/12920214/python-for-syntax-block-code-vs-single-line-generator-expressions">this</a> question, I have this PySpark code:</p> <pre><code>model = KMeansModel(model.Cs[0]) first_split = split_vecs.map(lambda x: x[0]) model.computeCost(first_split) model = KMean...
2
2016-08-30T18:15:28Z
39,235,032
<p>You could wrap the three distinct functions you have (KMeansModel,split_vec.map, and computeCost) in another function, like so:</p> <pre><code>def master_fx(var): return fx_C(fx_B(fx_A(var))) </code></pre> <p>Now that it looks nice, you can either use list comprehension:</p> <pre><code>[master_fx(element) for...
1
2016-08-30T18:51:01Z
[ "python", "loops", "for-loop", "apache-spark", "pyspark" ]
Towards understanding One Line For loops
39,234,453
<p>After reading <a href="http://stackoverflow.com/questions/12920214/python-for-syntax-block-code-vs-single-line-generator-expressions">this</a> question, I have this PySpark code:</p> <pre><code>model = KMeansModel(model.Cs[0]) first_split = split_vecs.map(lambda x: x[0]) model.computeCost(first_split) model = KMean...
2
2016-08-30T18:15:28Z
39,235,078
<p>What you're calling "one-liner for loops" are actually called"list comprehensions", "dictionary comprehensions", or "<a href="https://docs.python.org/3/tutorial/classes.html#generators" rel="nofollow">generator</a> expressions". They are more limited than for-loops, and work as follows:</p> <pre><code># List compre...
2
2016-08-30T18:53:49Z
[ "python", "loops", "for-loop", "apache-spark", "pyspark" ]
Matlab to Python numpy indexing and multiplication issue
39,234,553
<p>I have the following line of code in MATLAB which I am trying to convert to Python <code>numpy</code>:</p> <pre><code>pred = traindata(:,2:257)*beta; </code></pre> <p>In Python, I have:</p> <pre><code>pred = traindata[ : , 1:257]*beta </code></pre> <p><code>beta</code> is a 256 x 1 array. </p> <p>In MATLAB,</...
3
2016-08-30T18:22:03Z
39,234,756
<p>I suspect that <code>beta</code> is in fact a 1D <code>numpy</code> array. In <code>numpy</code>, 1D arrays are not row or column vectors where MATLAB clearly makes this distinction. These are simply 1D arrays agnostic of any shape. If you must, you need to manually introduce a new singleton dimension to the <cod...
8
2016-08-30T18:34:13Z
[ "python", "matlab", "numpy" ]
How do I create dynamically, and manage, new instances of common data types in Python?
39,234,678
<p>I want to make a program which will ask the user for a number (let's say 3) and create three 3x3 lists, or 3 sets of 3 members or some other complex data type (times 3) Python already knows of. </p> <p>Many programs create new objects without strict programming declaration of their instances. For example in Cinema4...
0
2016-08-30T18:29:52Z
39,234,830
<p>try this: </p> <pre><code>num = input() lst = [[0 for __ in range(num)] for _ in range(num)] </code></pre> <p>for specific type you should use numpy arrays or <code>array</code> module</p>
0
2016-08-30T18:38:30Z
[ "python", "class", "object", "types" ]
How do I create dynamically, and manage, new instances of common data types in Python?
39,234,678
<p>I want to make a program which will ask the user for a number (let's say 3) and create three 3x3 lists, or 3 sets of 3 members or some other complex data type (times 3) Python already knows of. </p> <p>Many programs create new objects without strict programming declaration of their instances. For example in Cinema4...
0
2016-08-30T18:29:52Z
39,281,692
<p>If you want a triple nested list, you can create it like this:</p> <pre><code>In [1]: num = 3 In [2]: [[[[0 for __ in range(num)] for _ in range(num)]] for ___ in range(num)] Out[2]: [[[[0, 0, 0], [0, 0, 0], [0, 0, 0]]], [[[0, 0, 0], [0, 0, 0], [0, 0, 0]]], [[[0, 0, 0], [0, 0, 0], [0, 0, 0]]]] </code></pre> <p...
0
2016-09-01T22:16:17Z
[ "python", "class", "object", "types" ]
How do I create dynamically, and manage, new instances of common data types in Python?
39,234,678
<p>I want to make a program which will ask the user for a number (let's say 3) and create three 3x3 lists, or 3 sets of 3 members or some other complex data type (times 3) Python already knows of. </p> <p>Many programs create new objects without strict programming declaration of their instances. For example in Cinema4...
0
2016-08-30T18:29:52Z
39,281,724
<p>OK, I think I've come up with a solution. Instead of trying to find a way to create new lists I will just append as many new indexes I need on a predefined empty list and treat that linear list as many unrelated lists using <code>for</code> loops and modulos related to my input number.</p> <p>I still don't know a g...
0
2016-09-01T22:19:40Z
[ "python", "class", "object", "types" ]
Adding Probability to the predicted value
39,234,697
<p>I have a testDF like this and try to make a binary classification [0;1]:</p> <p><a href="http://i.stack.imgur.com/wTSmJ.png" rel="nofollow"><img src="http://i.stack.imgur.com/wTSmJ.png" alt="enter image description here"></a></p> <p>Also I have a trainDF with the same structured and with filled bad values in it fo...
0
2016-08-30T18:30:51Z
39,236,521
<p>The <code>.predict</code> method selects the most probable assignment for your input. If you want to access the probabilities you can use:</p> <pre><code>log_prob = model.predict_log_proba(test) # Log of probability estimates. prob = model.predict_proba(test) # Probability estimates. </code></pre> <p>You can a...
1
2016-08-30T20:26:22Z
[ "python", "pandas", "scikit-learn", "logistic-regression", "prediction" ]
Python Regular Expression Finding a Specific Text Between Headers
39,234,709
<p>I'm just starting to learn about regular expressions in Python, and I've made a bit of progress on what I want to get done.</p> <pre><code>import urllib.request import urllib.parse import re x = urllib.request.urlopen("http://www.SOMEWEBSITE.com") contents = x.read() paragraphs = re.findall(r'&lt;p&gt;(.*?)&lt;/p...
1
2016-08-30T18:31:30Z
39,234,970
<p>It's better to use BeautifulSoup. Example:</p> <pre><code>import urllib2 html = urllib2.urlopen("http://www.SOMEWEBSITE.com").read() from BeautifulSoup import BeautifulSoup soup = BeautifulSoup(html) # now you can search the soup </code></pre> <p><strong>Documentation:</strong></p> <p><a href="https://www.crummy...
4
2016-08-30T18:47:45Z
[ "python", "regex" ]
Python script to move files to either a train dir or test dir
39,234,734
<p>I am the moment making a python script capable of diving my data into either a train dir or test dir. I provide the script with an ratio, which says what the ratio between train/test should be, an according to that should files randomly be moved either to train or test. </p> <p>ex. if the ratio = 0.5 then would ha...
2
2016-08-30T18:32:37Z
39,234,944
<p>You can take the list of files, <strong>shuffle</strong> it, then <strong>split</strong> it with respect to the split ratio.</p> <pre><code>import os import numpy src_files = os.listdir(".") n_files = len(src_files) split_ratio = 0.5 split_index = int(n_files * split_ratio) numpy.random.shuffle(src_files) print...
3
2016-08-30T18:45:54Z
[ "python", "unix", "filehandle" ]
Plot high-low with Seaborn, Pandas
39,234,843
<p>I have a pandas dataframe that has by category three data points: mean, max, min.</p> <p>I'd like to plot these such that the mean is a dot and the max/min are a line. Similar to a high/low/close graph in stocks, or even just error bars.</p> <p>For the sake of conversation, assume my code looks like</p> <pre><co...
0
2016-08-30T18:39:13Z
39,245,766
<p>You could do it this way:</p> <pre><code>df.set_index('day', inplace=True) # tsplot with error bars ax = sns.tsplot([df['foo_max'], df['foo_min']], err_style="ci_bars", interpolate=False, color='g') ax.set_xticks(np.arange(0, df.shape[0])) ax.set_xticklabels(df.index) ax.set_ylim(0, df.values.ma...
0
2016-08-31T09:28:58Z
[ "python", "pandas", "data-visualization", "seaborn" ]
how can I print key and value form list of dictionaries in python
39,234,906
<p>how can I print key and id from the following in python</p> <pre><code>[&lt;JIRA Issue: key=u'OPS-22158', id=u'566935'&gt;, &lt;JIRA Issue: key=u'OPS-22135', id=u'566480'&gt;, &lt;JIRA Issue: key=u'OPS-22131', id=u'566361'&gt;, &lt;JIRA Issue: key=u'OPS-21850', id=u'561948'&gt;, &lt;JIRA Issue: key=u'OPS-20967'...
1
2016-08-30T18:43:31Z
39,235,398
<p>If you know key,values this is an easy way: </p> <pre><code>In [2]: dict_list = [{'key':'iman','value':21} , {'key': 'hooman', 'value' : 22}] #list of dictionaries In [3]: for dict in dict_list: #dict = a dictionary of list ...: print dict['key'], dict['value'] #key,values ...: iman 21 hooman 22 <...
1
2016-08-30T19:13:09Z
[ "python", "python-2.7", "dictionary" ]
how can I print key and value form list of dictionaries in python
39,234,906
<p>how can I print key and id from the following in python</p> <pre><code>[&lt;JIRA Issue: key=u'OPS-22158', id=u'566935'&gt;, &lt;JIRA Issue: key=u'OPS-22135', id=u'566480'&gt;, &lt;JIRA Issue: key=u'OPS-22131', id=u'566361'&gt;, &lt;JIRA Issue: key=u'OPS-21850', id=u'561948'&gt;, &lt;JIRA Issue: key=u'OPS-20967'...
1
2016-08-30T18:43:31Z
39,235,413
<pre><code>import jira # stuff for issue in jira.search_issues('assignee=hhaddadian'): print(issue.fields.project.key) </code></pre> <p>The result of the jira.search_issues function is a list of Jira objects. These objects are defined here: <a href="https://jira.readthedocs.io/en/latest/" rel="nofollow">https://j...
2
2016-08-30T19:13:55Z
[ "python", "python-2.7", "dictionary" ]
python beautifulsoup search across multiple lines
39,235,110
<p>I am trying to search for the P/E ratio of a finance page, from the input code shown below. So, essentially I am trying to extract '48.98' from the source. As the structure is same for Market cap, book value, etc. I am unable to frame the correct code for a soup.find </p> <p>Would be very grateful for the correct s...
1
2016-08-30T18:55:56Z
39,235,295
<p>Use the text to find the div with <em>"P/E"</em> and get the next div:</p> <pre><code>price = soup.find("div", class_="FL gL_10 UC", text="P/E").find_next("div").text </code></pre> <p>If it is always the second div with the css class <em>FR gD_12</em>, you could also just get the first two and extract the second<...
4
2016-08-30T19:07:08Z
[ "python", "beautifulsoup" ]
Python Parse XML file for certain lines and output the line to Text widget
39,235,119
<p>I need to search a windows msinfo file (.nfo) for certain lines and print them to a Text widget. I can <code>print(line)</code> ever line in the file and I can output every line to the Text widget but as soon as I try to specify lines to output it stops working. I assume this is because the file is an XML but the XM...
1
2016-08-30T18:56:16Z
39,235,631
<p>So you need to understand the structure of the XML and then use the actual tags you're looking for instead of 'Data'</p> <pre><code> item = element.find('Item') print(item.tag ,":",item.text) value = element.find('Value') print(value.tag ,":",value.text) </code></pre> <p>Your actual problem is tha...
1
2016-08-30T19:28:35Z
[ "python", "xml", "python-3.x", "tkinter" ]
Python Parse XML file for certain lines and output the line to Text widget
39,235,119
<p>I need to search a windows msinfo file (.nfo) for certain lines and print them to a Text widget. I can <code>print(line)</code> ever line in the file and I can output every line to the Text widget but as soon as I try to specify lines to output it stops working. I assume this is because the file is an XML but the XM...
1
2016-08-30T18:56:16Z
39,235,757
<p>Here is my code with your sample data, I know it could be written better but I think this solves your problem :)<br> you have to find the root(xml) and then iterate it's texts ! you can also use other methods like <code>iterfind</code> for better solutions</p> <pre><code>xml_file = "&lt;xml&gt;&lt;Item&gt;&lt;![CD...
0
2016-08-30T19:35:35Z
[ "python", "xml", "python-3.x", "tkinter" ]
ImportError: No module named datadog
39,235,163
<p>I'm new to datadog. I followed this <a href="http://docs.datadoghq.com/api/" rel="nofollow">post</a>, and replaced in my app/api keys.</p> <p>I have : <code>nginx_dd.py</code></p> <pre><code># Make sure you replace the API and/or APP key below # with the ones for your account from datadog import initialize, api i...
0
2016-08-30T19:00:17Z
39,235,805
<p>Verify if the datadog package is installed in your environment.</p> <p>You can do this with this command: </p> <pre><code>$ pip freeze | grep datadog </code></pre> <p>If it's not installed, you can install it with this command:</p> <pre><code>$ pip install datadog </code></pre>
3
2016-08-30T19:38:33Z
[ "python", "datadog" ]
what does logging.basicConfig does?
39,235,166
<p>I was reading loggers in python and got confused with logging.basicConfig() method. As mentioned in the python docs that it set many config for root logger, does that mean that it set the configs only for root logger or does it do it even for user created loggers also ?</p> <p>Another doubt is that whenever we crea...
0
2016-08-30T19:00:29Z
39,236,919
<p>To answer your second part:</p> <pre><code> # Pass no arguments to get the root logger root_logger = logging.getLogger() # This logger is a child of the root logger logger_a = logging.getLogger('foo') # Configure logger_a here e.g. change threshold level to logging.DEBUG # This is a child of ...
1
2016-08-30T20:53:22Z
[ "python", "logging" ]
oauth2 POST - twitter
39,235,198
<p>i created a script that will get the users friend list (GET request) and i was successful. Now i am attempting to make a script that will follow a particular user (POST request) and i've been unsuccessful.</p> <p>here is my oauth function (where the problem lies):</p> <pre><code>def augment_POST(url,**kwargs) : ...
1
2016-08-30T19:02:13Z
39,260,091
<p>First it seems you need to <code>import urllib2</code> to make a POST request.<br> You have to send the POST data that you get from the <code>to_postdata</code> method using the <code>data</code> argument of <code>urlopen</code>:</p> <pre><code>def augment_POST(url, **kwargs) : secrets = hidden.oauth() cons...
1
2016-08-31T22:39:27Z
[ "python", "twitter", "oauth-2.0", "twitter-oauth" ]
In python apache beam, is it possible to write elements in a specific order?
39,235,274
<p>I'm using beam to process time series data over overlapping windows. At the end of my pipeline I am writing each element to a file. Each element represents a csv row and one of the fields is a timestamp of the associated window. I would like to write the elements in order of that timestamp. Is there a way to do this...
2
2016-08-30T19:05:57Z
39,255,667
<p>While this isn't part of the base distribution, this is something you could implement by processing these elements and sorting them as part of a global window before writing out to a file, with the following caveats:</p> <ul> <li>The entire contents of the window would need to fit in memory, or you would need to ch...
1
2016-08-31T17:30:23Z
[ "python", "google-cloud-dataflow", "apache-beam" ]
PyCharm and reStructuredText (Sphinx) documentation popups
39,235,275
<p>Let's imagine, I want to see a docstring popup for one simple method in <strong>PyCharm</strong> 4.5 Community Edition (tried also in 5.0).</p> <p>I wrote down these docstrings in both <em>epytext</em> syntax (Epydoc generator is unsupported since 2008 and works only for Python2) and <em>reStructuredText</em> synta...
1
2016-08-30T19:06:02Z
39,284,912
<p>I do not know if this feature present only in recent PyCharm versions so what version do you have? In my PyCharm CE 2016.2.2 it looks like on the screenshot.</p> <p><a href="http://i.stack.imgur.com/15b93.png" rel="nofollow"><img src="http://i.stack.imgur.com/15b93.png" alt="enter image description here"></a></p> ...
0
2016-09-02T05:31:27Z
[ "python", "pycharm", "python-sphinx", "epydoc" ]
How to build the following tables?
39,235,365
<p>Hello I have process a excel file and to take some parameters of it to create many tables the structure of the tables is the following:</p> <pre><code>"AWK|USL|R|SVKDIKG_tVstiKg|S|[PARAMETER1]~BURAGO~[PARAMETER2]~WVDG~333" "AFUSLR~USLSSHS~Farm~~%ERD_ARGV=MR4567.%VRSD%.%23WF%.333.%RVB%.tRt" "AWK|USL|R|Bimbo|S|[PARAM...
0
2016-08-30T19:11:19Z
39,236,481
<p>you try this </p> <pre><code>import pandas as pd # -*- coding: utf-8 -*- df = pd.read_csv("param.csv") print df df=df.drop_duplicates() filename='sample.txt' print "\n\nReplace with new values" for index, row in df.iterrows(): print "New Values \n\n" print row f=open(filename) filedata = f.read() ...
2
2016-08-30T20:23:46Z
[ "python", "pandas" ]
read_fwf in pandas in Python does not use comment character if colspecs argument does not include first column
39,235,377
<p>When reading fixed-width files using the <code>read_fwf</code> function in pandas (0.18.1) with Python (3.4.3), it is possible to specify a comment character using the <code>comment</code> argument. I expected that all lines beginning with the comment character would be ignored. However, if you do not specify the fi...
5
2016-08-30T19:12:09Z
39,282,739
<p>I think this is a bug, the spec in the documentation says "if the line starts with a comment then the entire line is skipped". The problem is that columns are subsetted by <code>FixedWidthReader.__next__</code> before they are checked for comments (in <code>PythonParser</code> or <code>CParserWrapper</code>). The re...
5
2016-09-02T00:37:32Z
[ "python", "python-3.x", "pandas" ]
Python - Auto Detect Email Content Encoding
39,235,436
<p>I am writing a script to process emails, and I have access to the raw string content of the emails. </p> <p>I am currently looking for the string "Content-Transfer-Encoding:" and scanning the characters that follow immediately after, to determine the encoding. Example encodings: base64 or 7bit or quoted-printable ....
1
2016-08-30T19:15:43Z
39,235,771
<p><a href="https://stackoverflow.com/questions/436220/python-is-there-a-way-to-determine-the-encoding-of-text-file">Python: Is there a way to determine the encoding of text file?</a> has some good answers. Basically there's no way to do it perfectly reliably, and the initial approach you're using is the best (and shou...
0
2016-08-30T19:36:13Z
[ "python", "email", "encoding", "html-email" ]
Python - Auto Detect Email Content Encoding
39,235,436
<p>I am writing a script to process emails, and I have access to the raw string content of the emails. </p> <p>I am currently looking for the string "Content-Transfer-Encoding:" and scanning the characters that follow immediately after, to determine the encoding. Example encodings: base64 or 7bit or quoted-printable ....
1
2016-08-30T19:15:43Z
39,236,065
<p>You may use this standard Python package: <a href="https://docs.python.org/2/library/email.html" rel="nofollow">email</a>.</p> <p>For example:</p> <pre><code>import email raw = """From: John Doe &lt;example@example.com&gt; MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi ...
1
2016-08-30T19:56:22Z
[ "python", "email", "encoding", "html-email" ]
Error with calculator type program in python ValueError
39,235,451
<p>this is my script, i am new to python but have come to get this, please be forgiving as such in the answers and keep in mind that i am new to this.</p> <pre><code>import functools numbers=[] def means(): end_mean = functools.reduce(lambda x, y: x + y, numbers) / len(numbers) print(end_mean) def sum(): ...
0
2016-08-30T19:16:49Z
39,235,507
<p><code>elif reply--'yes':</code> should be <code>elif reply == 'yes':</code></p>
3
2016-08-30T19:20:55Z
[ "python" ]
Error with calculator type program in python ValueError
39,235,451
<p>this is my script, i am new to python but have come to get this, please be forgiving as such in the answers and keep in mind that i am new to this.</p> <pre><code>import functools numbers=[] def means(): end_mean = functools.reduce(lambda x, y: x + y, numbers) / len(numbers) print(end_mean) def sum(): ...
0
2016-08-30T19:16:49Z
39,235,528
<p>You had a typo</p> <pre><code>elif reply--'yes' </code></pre> <p>it should be, of course</p> <pre><code>elif reply=='yes' </code></pre>
1
2016-08-30T19:21:44Z
[ "python" ]
PyAutoGUi : How to know if the left mouse click is pressed
39,235,454
<p>Am using PyAutoGUI library, how to know if the left mouse click is pressed?</p> <p>This is what I want to do : </p> <pre><code>if(leftmousebuttonpressed): print("left") else: print("nothing") </code></pre> <p>Help appreciated.</p>
0
2016-08-30T19:17:11Z
39,235,660
<p>I don't think you can use PyAutoGui to listen for mouseclick.</p> <p>Instead try Pyhook (from their source page):</p> <pre><code>import pythoncom, pyHook def OnMouseEvent(event): # called when mouse events are received print 'MessageName:',event.MessageName print 'Message:',event.Message print 'Ti...
0
2016-08-30T19:29:58Z
[ "python", "pyautogui" ]
Python library difference?
39,235,568
<p>If I run </p> <pre><code>bob@me:/usr$ find . -name 'libpython2.7.so' </code></pre> <p>I get two hits:</p> <pre><code>./lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so ./lib/x86_64-linux-gnu/libpython2.7.so </code></pre> <p>What's the difference?</p>
3
2016-08-30T19:24:02Z
39,235,593
<p>One is the configuration for the libpython2.7.so while the other is the exact location where the files for that particular library reside.</p>
3
2016-08-30T19:26:19Z
[ "python", "python-2.7", "shared-libraries" ]
When QComboBox is set editable
39,235,687
<p>The code below creates QComboBox and QPushButton both assigned to the same layout. Combobox is set to be editable so the user is able to type a new combobox item's value. If the user hits <strong>Tab</strong> keyboard key (instead of Enter) the New Value will not be added to the ComboBox. Question: How to make sur...
1
2016-08-30T19:31:49Z
39,236,399
<p>When a user edits the text in the box, the <code>editTextChanged()</code> signal is emitted with the edited text as its argument. In addition, when the widget itself loses focus, as when the user types <code>Tab</code> to move to the button, the widget emits the <code>focusOutEvent()</code> signal. The argument for ...
1
2016-08-30T20:18:40Z
[ "python", "pyqt", "pyside", "qcombobox" ]
Calculate local time derivative of Series
39,235,712
<p>I have data that I'm importing from an hdf5 file. So, it comes in looking like this:</p> <pre><code>import pandas as pd tmp=pd.Series([1.,3.,4.,3.,5.],['2016-06-27 23:52:00','2016-06-27 23:53:00','2016-06-27 23:54:00','2016-06-27 23:55:00','2016-06-27 23:59:00']) tmp.index=pd.to_datetime(tmp.index) &gt;&gt;&gt;tm...
4
2016-08-30T19:33:18Z
39,235,861
<p>Use <code>numpy.gradient</code></p> <pre><code>import numpy as np import pandas as pd slope = pd.Series(np.gradient(tmp.values), tmp.index, name='slope') </code></pre> <p>To address the unequal temporal index, i'd resample over minutes and interpolate. Then my gradients would be over equal intervals.</p> <pre><...
4
2016-08-30T19:41:47Z
[ "python", "datetime", "pandas" ]