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
listlengths
1
5
Throttling in Bokeh application
38,375,961
<p>I have Bokeh application with a Slider widget that uses the Slider.on_change callback to update my graphs. However, the slider updates come in much faster than my callback function can handle so I need a way to throttle the incoming change requests. The problem is very prominent since the slider calls into the callb...
1
2016-07-14T13:45:37Z
38,379,136
<p>As of release <code>0.12</code> this is still a bit clunky to accomplish, but not impossible. There is a <code>"mouseup"</code> policy on sliders, but this currently only applies to <code>CustomJS</code> callbacks. However, if that is combined with a "fake" data source, we can communicate and trigger just the last ...
2
2016-07-14T16:08:27Z
[ "python", "bokeh", "throttling" ]
Error evaluating constraint in Pyomo Modelling Language
38,376,004
<p>Hello to the community, </p> <p>So I have the following error: </p> <p>Error evaluating constraint 5965: can't evaluate sqrt'(0). ERROR:pyomo.opt:Solver (asl) returned non-zero return code (1) ERROR:pyomo.opt:See the solver log above for diagnostic information.</p> <p>Solver (asl) did not exit normally</p> <p>Ac...
0
2016-07-14T13:47:46Z
39,134,748
<p>This is technically not a problem with Pyomo – but rather a problem with your formulation. </p> <p>The error is being tossed by the ASL (part of the solver executable) when the solver drives the values of P_branch_ij and Q_branch_ij to 0 (this may be happening because of an inactive line, or bad initial values). ...
1
2016-08-25T00:02:14Z
[ "python", "constraints", "pyomo" ]
Python threading did not execute all threads which created
38,376,139
<p>I have a python script, so I use threading module in python to execute concurrently.</p> <pre><code>class check_bl(threading.Thread): def __init__(self, ip_client, reverse_ip, key, value): threading.Thread.__init__(self) self.ip_client = ip_client self.reverse_ip = reverse_ip sel...
0
2016-07-14T13:53:23Z
38,377,120
<p>My problem is slight different from your's and I didn't use class method I just modified your code based on mine you may give a try. This link helped me to solve my problem : <a href="http://stackoverflow.com/questions/2846653/how-to-use-threading-in-python">How to use threading in Python?</a></p> <p>def chec...
0
2016-07-14T14:37:02Z
[ "python", "multithreading", "python-2.7" ]
How to merge two csv files using multiprocessing with python pandas
38,376,272
<p>I want to merge two csv files with common column using python panda With 32 bit processor after 2 gb memory it will throw memory error how can i do the same with multi processing or any other methods</p> <pre><code>import gc import pandas as pd csv1_chunk = pd.read_csv('/home/subin/Desktop/a.txt',dtype=str, iterat...
0
2016-07-14T14:00:02Z
38,384,925
<p>I think you only need one column from your second file (actually, only unique elements from this column are needed), so there is no need to load the whole data frame.</p> <pre><code>import pandas as pd csv2 = pd.read_csv('/home/subin/Desktop/b.txt', usecols=['L_MSISDN']) unique_msidns = set(csv2['L_MSISDN']) </cod...
0
2016-07-14T21:58:49Z
[ "python", "pandas", "multiprocessing" ]
No module named 'pandas' in Pycharm
38,376,351
<p>I read all the topics about, but I cannot solve my problem:</p> <pre><code> Traceback (most recent call last): File "/home/.../.../.../reading_data.py", line 1, in &lt;module&gt; import pandas as pd ImportError: No module named pandas </code></pre> <p>This is my environment:</p> <p>Ubuntu ...
2
2016-07-14T14:03:48Z
38,382,116
<p>Have you select the project interpreter for your current project? <a href="https://www.jetbrains.com/help/pycharm/2016.1/configuring-python-interpreter-for-a-project.html" rel="nofollow">https://www.jetbrains.com/help/pycharm/2016.1/configuring-python-interpreter-for-a-project.html</a></p> <p>follow this link, chec...
1
2016-07-14T18:54:28Z
[ "python", "pandas", "module", "pycharm", "sklearn-pandas" ]
Drawing static Line on Pyqt Widget
38,376,362
<p>I'm not a programmer but i'd like to programming using pyqt that can apply for some engineering application. So, I want to have a widget that include the graphic (as attached picture) and some other widget such as: textbox, button, etc for user to input or select but I can not figure out which widget or class to mak...
0
2016-07-14T14:04:06Z
38,380,235
<p>You can display pictures with <code>QLabel</code>'s</p> <pre><code>label = QtGui.QLabel() pixmap = QtGui.QPixmap('/path/to/image.png') label.setPixmap(pixmap) </code></pre>
0
2016-07-14T17:08:24Z
[ "python", "qt", "pyqt" ]
Usage of groupBy in Spark
38,376,365
<p>I an currently learning spark in python. I had a small question, in other languages like SQL we can simply group a table by specified columns and then perform further operations like sum, count, etc. on them. How do we do this in Spark? </p> <p>I have schema like : </p> <pre><code> [name:"ABC", city:"New York",...
2
2016-07-14T14:04:14Z
38,376,692
<p>You can use SQL:</p> <pre><code>&gt;&gt;&gt; sc.parallelize([ ... {"name": "ABC", "city": "New York", "money":"50"}, ... {"name": "DEF", "city": "London", "money":"10"}, ... {"name": "ABC", "city": "New York", "money":"30"}, ... {"name": "XYZ", "city": "London", "money":"20"}, ... {"name": "XYZ", "city": "Londo...
2
2016-07-14T14:18:47Z
[ "python", "apache-spark", "pyspark", "apache-spark-sql", "spark-dataframe" ]
Usage of groupBy in Spark
38,376,365
<p>I an currently learning spark in python. I had a small question, in other languages like SQL we can simply group a table by specified columns and then perform further operations like sum, count, etc. on them. How do we do this in Spark? </p> <p>I have schema like : </p> <pre><code> [name:"ABC", city:"New York",...
2
2016-07-14T14:04:14Z
38,377,056
<p>You can do this in a Pythonic way as well (or the SQL version @LostInOverflow posted):</p> <pre><code>grouped = df.groupby('city', 'name').sum('money') </code></pre> <p>It looks like your <code>money</code> column is strings, so you'll need to cast it as an <code>int</code> first (or load it up that way to begin w...
1
2016-07-14T14:34:26Z
[ "python", "apache-spark", "pyspark", "apache-spark-sql", "spark-dataframe" ]
Changing the scale of a tensor in tensorflow
38,376,478
<p>Sorry if I messed up the title, I didn't know how to phrase this. Anyways, I have a tensor of a set of values, but I want to make sure that every element in the tensor has a range from 0 - 255, (or 0 - 1 works too). However, I don't want to make all the values add up to 1 or 255 like softmax, I just want to down sca...
0
2016-07-14T14:08:44Z
38,376,532
<p><code>sigmoid(tensor) * 255</code> should do it.</p>
0
2016-07-14T14:11:05Z
[ "python", "tensorflow", "conv-neural-network" ]
Changing the scale of a tensor in tensorflow
38,376,478
<p>Sorry if I messed up the title, I didn't know how to phrase this. Anyways, I have a tensor of a set of values, but I want to make sure that every element in the tensor has a range from 0 - 255, (or 0 - 1 works too). However, I don't want to make all the values add up to 1 or 255 like softmax, I just want to down sca...
0
2016-07-14T14:08:44Z
38,377,600
<p>You are trying to normalize the data. A classic normalization formula is this one:</p> <pre><code>normalize_value = value − min_value / max_value − min_value </code></pre> <p>The implementation on tensorflow will look like this:</p> <pre><code>tensor = tf.div( tf.sub( tensor, tf.reduce_min(ten...
1
2016-07-14T14:58:17Z
[ "python", "tensorflow", "conv-neural-network" ]
Add new column with existing column names
38,376,533
<p>I'm dealing with a dataframe which looks like:</p> <pre><code> FID geometry Code w1 w2 0 12776 POLYGON ((-1.350000000000025 53.61540813717482... 12776 0 1 1 13892 POLYGON ((6.749999999999988 52.11964001623148,... 13892 1 0 2 14942 POLYGON...
3
2016-07-14T14:11:05Z
38,376,811
<p>Something like this should work:</p> <pre><code>(df['w1'] == df['w2']).map({True: 0}).fillna(df[['w1', 'w2']].idxmax(axis=1)) Out[26]: 0 w2 1 w1 2 0 3 w2 4 w2 dtype: object </code></pre> <p>How it works:</p> <p>The main part is with idxmax:</p> <pre><code>df[['w1', 'w2']].idxmax(axis=1) Out[27]:...
4
2016-07-14T14:23:57Z
[ "python", "pandas", "max" ]
Add new column with existing column names
38,376,533
<p>I'm dealing with a dataframe which looks like:</p> <pre><code> FID geometry Code w1 w2 0 12776 POLYGON ((-1.350000000000025 53.61540813717482... 12776 0 1 1 13892 POLYGON ((6.749999999999988 52.11964001623148,... 13892 1 0 2 14942 POLYGON...
3
2016-07-14T14:11:05Z
38,376,907
<p>Use <code>np.where</code> to choose <code>0</code> when they are equal <code>idxmax(1)</code> when they are not.</p> <pre><code>df['max'] = np.where(df.w1 == df.w2, 0, df[['w1', 'w2']].idxmax(1)) df FID geometry Code w1 w2 Max 0 12776 ... 12776 0 1 w2 1 13892 ... 138...
5
2016-07-14T14:28:10Z
[ "python", "pandas", "max" ]
Using pandas group-by to select specific sub-groups
38,376,876
<p>I have a pandas dataframe on the following form:</p> <pre> id grp values1 values2 0 1 a_1 2 4 1 1 a_2 3 6 2 1 b_1 4 8 3 2 b_2 5 10 4 2 c_1 6 12 5 3 z_1 7 14 6 4 y_1 8 16 7 5 a_1 9 18 8 5 a_2...
1
2016-07-14T14:26:42Z
38,377,089
<p>Or you could take the easier way and:</p> <pre><code> filtered_df = df.ix[(df['grp'] == 'a_1') | (df['grp'] == 'a_2')] </code></pre>
1
2016-07-14T14:35:39Z
[ "python", "pandas" ]
Using pandas group-by to select specific sub-groups
38,376,876
<p>I have a pandas dataframe on the following form:</p> <pre> id grp values1 values2 0 1 a_1 2 4 1 1 a_2 3 6 2 1 b_1 4 8 3 2 b_2 5 10 4 2 c_1 6 12 5 3 z_1 7 14 6 4 y_1 8 16 7 5 a_1 9 18 8 5 a_2...
1
2016-07-14T14:26:42Z
38,378,538
<p>You can simply search for the conditions in the dataframe:</p> <pre><code>reduced_df = df[(df['grp'] == 'a_1') | (df['grp'] == 'a_2')] </code></pre>
0
2016-07-14T15:39:18Z
[ "python", "pandas" ]
Using pandas group-by to select specific sub-groups
38,376,876
<p>I have a pandas dataframe on the following form:</p> <pre> id grp values1 values2 0 1 a_1 2 4 1 1 a_2 3 6 2 1 b_1 4 8 3 2 b_2 5 10 4 2 c_1 6 12 5 3 z_1 7 14 6 4 y_1 8 16 7 5 a_1 9 18 8 5 a_2...
1
2016-07-14T14:26:42Z
38,389,084
<p>I managed to do the "even numbers" solution like this, maybe not the most efficient but it got the job done:</p> <pre><code># One row per id pivot = df[['id', 'grp', 'values1']].pivot_table('values1', index = 'id', columns = 'grp', aggfunc = (lambda i: i.size)).reset_index() # Take out the id rows which fulfills c...
0
2016-07-15T06:19:00Z
[ "python", "pandas" ]
Adding new row in a CSV Python
38,376,925
<p>I am adding a new row to a specific CSV that already exist, but for unknown reason the new row is being added along with the last row and not in a new one.</p> <p>So, it's showing in CSV as:</p> <pre><code>11-07-2016,38361,9076,14487,292,741614-07-2016,38417,9767,15832,301,7416 </code></pre> <p>When should be sho...
0
2016-07-14T14:28:50Z
38,377,017
<p>It looks like the file doesn't have a newline at the end. Try adding one before appending the new line:</p> <pre><code>newRow = "\n%s,%s,%s,%s,%s,%s\n" % (today, yes, ok, war, leg, noag) with open("data.csv", "a") as f: f.write(newRow) </code></pre>
2
2016-07-14T14:32:25Z
[ "python", "csv" ]
Adding new row in a CSV Python
38,376,925
<p>I am adding a new row to a specific CSV that already exist, but for unknown reason the new row is being added along with the last row and not in a new one.</p> <p>So, it's showing in CSV as:</p> <pre><code>11-07-2016,38361,9076,14487,292,741614-07-2016,38417,9767,15832,301,7416 </code></pre> <p>When should be sho...
0
2016-07-14T14:28:50Z
38,377,022
<pre><code>import time import csv today = (time.strftime("%d-%m-%Y")) newRow = """%s,%s,%s,%s,%s,%s""" % (today, yes, ok, war, leg, noag) with open('data.csv','a',newline='') as fd: writer = csv.writer(fd) writer.writerow(newRow) </code></pre> <p>It's writerow instead of write, it'll automatically add a new ...
0
2016-07-14T14:32:40Z
[ "python", "csv" ]
Adding new row in a CSV Python
38,376,925
<p>I am adding a new row to a specific CSV that already exist, but for unknown reason the new row is being added along with the last row and not in a new one.</p> <p>So, it's showing in CSV as:</p> <pre><code>11-07-2016,38361,9076,14487,292,741614-07-2016,38417,9767,15832,301,7416 </code></pre> <p>When should be sho...
0
2016-07-14T14:28:50Z
38,377,121
<p>Right now you are not using the csv module, just the regular write as for text file.</p> <p>To treat the file as a csv change:</p> <pre><code>fd.write(newRow) </code></pre> <p>to:</p> <pre><code>csv_writer = csv.writer(fd) csv_writer.writerow(newRow) </code></pre> <p>If you want to edit the file as a text file ...
0
2016-07-14T14:37:03Z
[ "python", "csv" ]
Print both the duplicate values name from the nested list
38,376,949
<pre><code>students=[['Ash',85.25],['Kai',85.25],['Ray',75],['Jay',55.5]] output:Ash Kai </code></pre> <p>I'm trying to solve a task and i'm new in python.I am not getting what i want can anyone explain me how one can do it </p>
-2
2016-07-14T14:29:59Z
38,377,072
<p>One option would be to group the values into a <a href="https://docs.python.org/3/library/collections.html#collections.defaultdict" rel="nofollow"><code>defaultdict(list)</code></a>:</p> <pre><code>&gt;&gt;&gt; from collections import defaultdict &gt;&gt;&gt; &gt;&gt;&gt; students = [['Ash',85.25],['Kai',85.25],['R...
0
2016-07-14T14:34:56Z
[ "python", "python-2.7", "python-3.x" ]
Print both the duplicate values name from the nested list
38,376,949
<pre><code>students=[['Ash',85.25],['Kai',85.25],['Ray',75],['Jay',55.5]] output:Ash Kai </code></pre> <p>I'm trying to solve a task and i'm new in python.I am not getting what i want can anyone explain me how one can do it </p>
-2
2016-07-14T14:29:59Z
38,377,345
<p>I would do it like that:</p> <pre><code>students = [['Ash', 85.25], ['Kai', 85.25], ['Ray', 75], ['Jay', 55.5]] common_names = [] for i, i_x in enumerate(students): for i_y in students[:i] + students[i + 1:]: if i_x[1] == i_y[1]: common_names.append(i_x[0]) print(common_names) #['Ash', 'Ka...
0
2016-07-14T14:47:50Z
[ "python", "python-2.7", "python-3.x" ]
How to send out two request at the same time with python
38,376,981
<p>So I was following a guide at <a href="http://tavendo.com/blog/post/going-asynchronous-from-flask-to-twisted-klein/" rel="nofollow">http://tavendo.com/blog/post/going-asynchronous-from-flask-to-twisted-klein/</a> to create an asynchronous web service. </p> <p>in my code, I had a function that will send out the requ...
0
2016-07-14T14:31:08Z
38,385,997
<p>What you need to do is use a <a href="https://twistedmatrix.com/documents/current/core/howto/defer.html#deferredlist" rel="nofollow"><code>DeferredList</code></a> instead of <code>inlineCallbacks</code>. Basically you provide a list of deferreds and after each one completes, a final callback with the results of all...
1
2016-07-15T00:04:34Z
[ "python", "python-2.7", "twisted", "klein-mvc" ]
Custom parse callback request not working in Scrapy
38,376,984
<p>I'm trying to fetch URLs for entries in parse_start_url method which yields a request with a callback to parse_link method but the callback doesn't seem to work. What am I getting wrong?</p> <p>Code:</p> <pre><code>from scrapy import Request from scrapy.selector import Selector from scrapy.linkextractors import L...
1
2016-07-14T14:31:13Z
38,377,176
<p>You need to adjust your <code>allowed_domains</code> to allow the extracted URLs to be followed:</p> <pre><code>allowed_domains = ['vivastreet.co.in'] </code></pre> <p>Then, you'll get into invalid expression errors, this is because <code>//*h1[@class = "kiwii-font-xlarge kiwii-margin-none"</code> is invalid and n...
0
2016-07-14T14:39:48Z
[ "python", "scrapy" ]
What is the difference between two below definitions for lambda?
38,377,015
<p>I saw two models for lambda and could not use them instead of them. You suppose:</p> <pre><code>languages = ["HTML", "JavaScript", "Python", "Ruby"] print max(lambda x:x=="Python", languages) </code></pre> <p>You can see it is started with lambda then x:x and at the end the name of list(y). Suppose below:</p> <pr...
-5
2016-07-14T14:32:24Z
38,377,283
<p>From the <a href="https://docs.python.org/2/library/functions.html" rel="nofollow">docs</a>.</p> <p><strong>Filter</strong> takes a <strong>function</strong> and an <strong>iterable</strong> (list) [i.e. <code>filter(function, iterable)</code>]</p> <p>You are passing the lambda (<code>lambda x:x=="Python"</code>)...
0
2016-07-14T14:45:00Z
[ "python" ]
What is the difference between two below definitions for lambda?
38,377,015
<p>I saw two models for lambda and could not use them instead of them. You suppose:</p> <pre><code>languages = ["HTML", "JavaScript", "Python", "Ruby"] print max(lambda x:x=="Python", languages) </code></pre> <p>You can see it is started with lambda then x:x and at the end the name of list(y). Suppose below:</p> <pr...
-5
2016-07-14T14:32:24Z
38,379,213
<p>I answer. These are old versions and cannot be acceptable for paython 3 to above. It can be usable as below:</p> <pre><code>squares=[x**2 for x in range(1,11)] c=max(filter(lambda x: x&gt;=30 and x&lt;=70,squares)) print (squares) print (c) </code></pre> <p>or</p> <pre><code>f=[1,2,3,4,5,6,7,8,9] print(list(filt...
0
2016-07-14T16:12:35Z
[ "python" ]
Python - Threading - Console o/p disapper
38,377,032
<p>I am trying hands on with Socket Programming.Below is my server side code and I have not listed client side code here which is similar. As soon as the thread(in the try block) is called my console o/p disappears. Not sure how to handle this.Running it on DOS of Windows 7.Although I tried to read some existing discus...
0
2016-07-14T14:33:11Z
38,378,728
<p>Ok guys..This worked..:</p> <pre><code> thread1 = Thread(target=Server_outgoing, args=()) thread1.start() thread1.join() </code></pre>
0
2016-07-14T15:47:58Z
[ "python", "multithreading", "sockets" ]
Store graph trained in python, use in Android application
38,377,047
<p>I'd like to be able to train a neural network using the Python API on a computer, and then use the resulting graph later in an Android application (using the C API). Unfortunately, any examples I could find of this workflow refer to parts of the API which have been removed (such as <code>freeze_graph</code>). When a...
0
2016-07-14T14:34:04Z
38,384,799
<p>After significant trial and error, I found that the <code>freeze_graph</code> script is absolutely vital for this to work. You can find it <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py" rel="nofollow">here</a>. My current workflow is:</p> <ol> <li>Generate the...
0
2016-07-14T21:47:43Z
[ "android", "python", "c++", "tensorflow" ]
Get matrix product of 3 matrices
38,377,107
<p>I have 3, 3X3 matrices stored in numpy arrays. I want to get the product, to compute a rotation matrix.</p> <p>Currently what I am doing is <code>rotation_matrix = (a * b * c)</code> but I don't know if this is the correct way to multiply matrices - should I be using <code>.dot</code> I have also tried with <code>...
-2
2016-07-14T14:36:19Z
38,379,682
<p>You can try using <code>dot</code> like this:</p> <pre><code>final= numpy.dot(tilt_matrix, (numpy.dot(rotation_matrix, original)) </code></pre> <p>Things to consider:</p> <ol> <li><code>numpy.dot</code> is a function, not a method (not possible to call <code>A.dot(B)</code>, call <code>np.dot(A, B)</code> instead...
0
2016-07-14T16:37:00Z
[ "python", "numpy", "matrix-multiplication", "rotational-matrices" ]
Tensorflow embedding running out of space
38,377,189
<p>I am trying to create an embedding for 1,000,000 words on tensorflow. Each word will have a 256 float32 vector representing the word. The issue is that I keep running out of memory. This does not make sence to me since I have 8GB of memory on my GTX 1080. The embedding should only take up 1e6 * 256 * 4 = 1 Gb of...
0
2016-07-14T14:40:19Z
38,377,329
<p>What I was not accounting for was the AdamOptimizer. I forgot that this needs to store various parameters for each of the weights in my model. When I changed to a GraidentDecent optimizer it now fits on my GPU.</p>
2
2016-07-14T14:46:53Z
[ "python", "tensorflow" ]
Python automatically generating variables
38,377,190
<h1>Question</h1> <p>I have a question about Python creating new variables derived from other variables. I am struggling to understand how Python automatically knows how to generate variables even when I do not explicitly tell it to.</p> <h1>Details</h1> <p>I am a new Python user, and am following along in the tutor...
1
2016-07-14T14:40:21Z
38,377,284
<p>So you're actually creating the variables in the <code>for</code> loop:</p> <pre><code>for label, friend_count, minute_count in zip(labels, friends, minutes): </code></pre> <p>When you <code>zip</code> those together you're grouping them by the index, so the first item it iterates to is <code>(70, 175, 'a')</code>...
4
2016-07-14T14:45:10Z
[ "python", "matplotlib" ]
Using a for loop to automate a function
38,377,215
<p>I am trying to use this code, which calculates the fraction of overlap at a specific depth, to use at various depths. </p> <pre><code>def score(list1, list2, depth): len_list = len(list1) frac = numpy.ceil(depth * len_list) frac = int(frac) s = slice(0,frac) list1 = list1[s] list2 = list2...
0
2016-07-14T14:41:50Z
38,377,404
<p>Like Kevin said in the comment, your problem is you are creating a list which has another list inside of it in your code <code>a = [numpy.arange(.01,1.01,.01)]</code>. Just remove the extra brackets and it will work.</p>
2
2016-07-14T14:50:07Z
[ "python", "list", "overlap" ]
Instance variables in methods outside the constructor (Python) -- why and how?
38,377,276
<p>My questions concern instance variables that are initialized <em>in methods outside the class constructor</em>. This is for Python. </p> <p>I'll first state what I understand: </p> <ol> <li>Classes may define a constructor, and it may also define other methods.</li> <li>Instance variables are generally defined/ini...
1
2016-07-14T14:44:44Z
38,377,655
<p>Remember that class members in "pure" Python are just a dictionary. Members aren't added to an instance's dictionary until you run the function in which they are defined. Ideally this is the constructor, because that then guarantees that your members will all exist regardless of the order that your functions are c...
3
2016-07-14T15:00:19Z
[ "python", "class", "constructor", "instance-variables" ]
Instance variables in methods outside the constructor (Python) -- why and how?
38,377,276
<p>My questions concern instance variables that are initialized <em>in methods outside the class constructor</em>. This is for Python. </p> <p>I'll first state what I understand: </p> <ol> <li>Classes may define a constructor, and it may also define other methods.</li> <li>Instance variables are generally defined/ini...
1
2016-07-14T14:44:44Z
38,377,999
<p>To initialize instance variables within the constructor, is - as you already pointed out - only recommended in python.</p> <p>First of all, defining all instance variables within the constructor is a <strong>good way to document a class</strong>. Everybody, seeing the code, knows what kind of internal state an inst...
2
2016-07-14T15:14:52Z
[ "python", "class", "constructor", "instance-variables" ]
Instance variables in methods outside the constructor (Python) -- why and how?
38,377,276
<p>My questions concern instance variables that are initialized <em>in methods outside the class constructor</em>. This is for Python. </p> <p>I'll first state what I understand: </p> <ol> <li>Classes may define a constructor, and it may also define other methods.</li> <li>Instance variables are generally defined/ini...
1
2016-07-14T14:44:44Z
38,378,288
<p>Let me try to shed some light on this specific issue:</p> <blockquote> <p>3.) But instance variables can also be defined/initialized outside the constructor, e.g. in the other methods of the same class.</p> </blockquote> <p>I'd recommend providing a default state in initialization, just so its clear what the cla...
1
2016-07-14T15:27:47Z
[ "python", "class", "constructor", "instance-variables" ]
Instance variables in methods outside the constructor (Python) -- why and how?
38,377,276
<p>My questions concern instance variables that are initialized <em>in methods outside the class constructor</em>. This is for Python. </p> <p>I'll first state what I understand: </p> <ol> <li>Classes may define a constructor, and it may also define other methods.</li> <li>Instance variables are generally defined/ini...
1
2016-07-14T14:44:44Z
38,378,757
<blockquote> <p>Why is it best practice to initialize the instance variable within the constructor?</p> </blockquote> <h2>Clarity.</h2> <p>Because it makes it easy to see at a glance all of the attributes of the class. If you initialize the variables in multiple methods, it becomes difficult to understand the com...
1
2016-07-14T15:49:56Z
[ "python", "class", "constructor", "instance-variables" ]
String array data needs to be stripped of dollar sign and turned into a float
38,377,328
<p>I have data such as: </p> <pre><code>['$15.50'] ['$10.00'] ['$15.50'] ['$15.50'] ['$22.28'] ['$50'] ['$15.50'] ['$10.00'] </code></pre> <p>I want to get rid of the dollar sign and turn the strings into floats so I can use the numbers for several calculations. I have tried the following: </p> <pre><code>array[0] =...
1
2016-07-14T14:46:51Z
38,377,367
<p>Try using a <a href="http://treyhunner.com/2015/12/python-list-comprehensions-now-in-color/" rel="nofollow">list comprehension</a>:</p> <pre><code>array = [float(x.strip("$")) for x in array] </code></pre>
3
2016-07-14T14:48:34Z
[ "python", "arrays", "string" ]
String array data needs to be stripped of dollar sign and turned into a float
38,377,328
<p>I have data such as: </p> <pre><code>['$15.50'] ['$10.00'] ['$15.50'] ['$15.50'] ['$22.28'] ['$50'] ['$15.50'] ['$10.00'] </code></pre> <p>I want to get rid of the dollar sign and turn the strings into floats so I can use the numbers for several calculations. I have tried the following: </p> <pre><code>array[0] =...
1
2016-07-14T14:46:51Z
38,377,421
<p>With regex:</p> <pre><code>import re array = ([float(re.sub("\$","",x)) for x in array]) </code></pre> <p>In case '$' is not at the end or beginning of the string</p>
0
2016-07-14T14:50:55Z
[ "python", "arrays", "string" ]
String array data needs to be stripped of dollar sign and turned into a float
38,377,328
<p>I have data such as: </p> <pre><code>['$15.50'] ['$10.00'] ['$15.50'] ['$15.50'] ['$22.28'] ['$50'] ['$15.50'] ['$10.00'] </code></pre> <p>I want to get rid of the dollar sign and turn the strings into floats so I can use the numbers for several calculations. I have tried the following: </p> <pre><code>array[0] =...
1
2016-07-14T14:46:51Z
38,377,639
<p>You can slice and convert the strings as follows:</p> <pre><code>strings_array = map(lambda x: float(x[1:]), strings_array) </code></pre> <p>OR</p> <pre><code>array2=[] for s in array: array2.append(float(s[1:])) </code></pre> <p>OR </p> <pre><code>array = [float(s[1:]) for s in array] </code></pre>
0
2016-07-14T14:59:35Z
[ "python", "arrays", "string" ]
String array data needs to be stripped of dollar sign and turned into a float
38,377,328
<p>I have data such as: </p> <pre><code>['$15.50'] ['$10.00'] ['$15.50'] ['$15.50'] ['$22.28'] ['$50'] ['$15.50'] ['$10.00'] </code></pre> <p>I want to get rid of the dollar sign and turn the strings into floats so I can use the numbers for several calculations. I have tried the following: </p> <pre><code>array[0] =...
1
2016-07-14T14:46:51Z
38,393,383
<p>This should do:</p> <pre><code>[float(s.replace(',', '.').replace('$', '')) for s in array] </code></pre> <p>I have taken the liberty to change your data in order to consider a wider variety of test cases:</p> <pre><code>array = ['$15.50', '$ 10.00', ' $15.50 ', '$15,50', '$2...
0
2016-07-15T10:06:47Z
[ "python", "arrays", "string" ]
Mock modules and subclasses (TypeError: Error when calling the metaclass bases)
38,377,336
<p>To compile documentation on readthedocs, the module h5py has to be mocked. I get an error which can be reproduced with this simple code:</p> <pre><code>from __future__ import print_function import sys try: from unittest.mock import MagicMock except ImportError: # Python 2 from mock import Mock as Magic...
3
2016-07-14T14:47:15Z
38,438,126
<p>You can't really use <code>Mock</code> <em>instances</em> to act as <em>classes</em>; it fails hard on Python 2, and works by Python 3 only by accident (see below).</p> <p>You'd have to return the <code>Mock</code> <em>class</em> itself instead if you wanted them to work in a class hierarchy:</p> <pre><code>&gt;&g...
1
2016-07-18T13:34:17Z
[ "python", "mocking", "read-the-docs" ]
Python File Search Script
38,377,346
<p>I recently wrote this script in Python 3.5 to search a text file for a given string, I can't seem to figure out how to have the script remove the rest of the words after the word "log" shows up in the line.</p> <pre><code>file1 = input ('What is the name of the file? ') search_string = input ('What are you looking ...
0
2016-07-14T14:47:53Z
38,383,430
<p>If all you want is to remove the part of the text after a pattern <code>'log'</code> in a line, you could use either the first part of the output of <a href="https://docs.python.org/3/library/stdtypes.html#str.partition" rel="nofollow"><code>str.partition</code></a> or the 0'th index of <a href="https://docs.python...
0
2016-07-14T20:10:14Z
[ "python", "python-3.x", "scripting" ]
Efficent search through list items
38,377,414
<p>I have a list <code>lst</code> (with 10K items) and query term <code>q</code>, and I want to find if any item in <code>lst</code> ends with <code>q</code>.</p> <p>As a reference timer I set to 1, this statement:</p> <pre><code>x = q in lst </code></pre> <p>I tried these:</p> <pre><code># obvious endswith method ...
1
2016-07-14T14:50:42Z
38,378,421
<p>I don't think regex is the way to go. Even when I assign <code>joined = '~'.join(lst) + '~'</code> outside of the loop, <code>q+'~' in joined</code> outperforms <code>re.search(q + '~', joined)</code> (0.00093 seconds vs 0.0034 seconds).</p> <p>However, assuming that you won't already have the joined string, a meth...
1
2016-07-14T15:33:49Z
[ "python" ]
How to reindex a pandas DataFrame after concatenation
38,377,473
<p>Suppose I concatenate two DataFrames like so:</p> <pre><code>import numpy as np import pandas as pd array1 = np.random.randn(3,3) array2 = np.random.randn(3,3) df1 = pd.DataFrame(array1, columns=list('ABC')) df2 = pd.DataFrame(array2, columns=list('ABC')) df = pd.concat([df1, df2]) </code></pre> <p>The resultin...
2
2016-07-14T14:53:32Z
38,377,508
<p>You want to pass <code>ignore_index=True</code> to <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a>:</p> <pre><code>In [68]: array1 = np.random.randn(3,3) array2 = np.random.randn(3,3) ​ df1 = pd.DataFrame(array1, columns=list('ABC')) df2 = ...
3
2016-07-14T14:54:45Z
[ "python", "pandas" ]
How to reindex a pandas DataFrame after concatenation
38,377,473
<p>Suppose I concatenate two DataFrames like so:</p> <pre><code>import numpy as np import pandas as pd array1 = np.random.randn(3,3) array2 = np.random.randn(3,3) df1 = pd.DataFrame(array1, columns=list('ABC')) df2 = pd.DataFrame(array2, columns=list('ABC')) df = pd.concat([df1, df2]) </code></pre> <p>The resultin...
2
2016-07-14T14:53:32Z
38,377,518
<p>Using EdChum's set up</p> <pre><code>array1 = np.random.randn(3,3) array2 = np.random.randn(3,3) df1 = pd.DataFrame(array1, columns=list('ABC')) df2 = pd.DataFrame(array2, columns=list('ABC')) df = pd.concat([df1, df2]) df.reset_index(drop=True) </code></pre> <p><a href="http://i.stack.imgur.com/iWPuq.png" rel="...
1
2016-07-14T14:55:16Z
[ "python", "pandas" ]
Advanced replace
38,377,502
<p>I have a big file (2GB) containing text, i need to replace in each line (each line is individual), all the substrings of a token present in the row (at an undefined position) and identified by the prefix KEYWORD_ID/ with the token and the original word:</p> <p>Example:</p> <pre><code>This is an example of the KEYW...
0
2016-07-14T14:54:34Z
38,377,664
<p>2GB is not big at all, just iterate over line by line, and use <code>regex</code></p> <p>In case of one replace command:</p> <pre><code>import re str = 'This is an example of the KEYWORD_ID/Replace_Command that is given as an input, replace command should be replaced' print(re.sub(r'\breplace\b', re.search('KEYW...
1
2016-07-14T15:00:38Z
[ "python", "replace" ]
Taking a generator out of a context manager
38,377,597
<p>I just saw the following code:</p> <pre><code>from __future__ import print_function from future_builtins import map # generator with open('test.txt', 'r') as f: linegen = map(str.strip, f) # file handle should be closed here for line in linegen: # using the generator now print(line) </code></pre> <p...
2
2016-07-14T14:58:07Z
38,378,455
<p>This is one of those breaking changes in Python 3.</p> <p>Your question title (Taking a <em>generator</em> ...) implies you are reading it as Python 3 code.</p> <p>But the statement</p> <pre><code>from __future__ import print_function </code></pre> <p>implies it was written for Python 2</p> <p>In Python 2, <cod...
2
2016-07-14T15:35:23Z
[ "python", "generator", "contextmanager" ]
Can I get a pointer to part of the tensor in tensorflow?
38,377,699
<p>Say in tensorflow, I created a variable by </p> <p><code>C = tf.Variable(tf.random_uniform([n_sample, n_sample], -1, 1), name='C')</code>, </p> <p>now I want to get a pointer to the first column of the variable, is there anyway I could do that? Would <code>tf.slice(C, [0,0], [n_sample,1])</code> give me what I wan...
0
2016-07-14T15:02:02Z
38,378,403
<p>As far as I know you can't really get access to the data itself (i.e. like a pointer). The reasoning being is that the code will be data agnostic so that it can pass around the data to different CPUs or GPUs without you worrying about that part (or you could specify device to use but that gets cumbersome). </p> <...
0
2016-07-14T15:33:02Z
[ "python", "machine-learning", "tensorflow" ]
Loop returns false after random number of iteration in python
38,377,788
<p>In the below code </p> <pre><code>import pyzipcode as pyzip location = [] for var in grouped_list_long_zip: holder = pyzip.Pyzipcode.get(var[0][4], 'US', return_json=False) location.append(holder['location']) </code></pre> <p><code>grouped_list_long_zip</code> is a list of list of list which contains locat...
0
2016-07-14T15:05:34Z
38,377,884
<p>I would modify the code like that to get some feedback on the values that <em>disrupt the execution</em>.</p> <pre><code>import pyzipcode as pyzip location = [] for var in grouped_list_long_zip: holder = pyzip.Pyzipcode.get(var[0][4], 'US', return_json=False) if type(holder) == bool: print(var[0]) ...
1
2016-07-14T15:10:02Z
[ "python", "list" ]
Array Definition Modelling in MongoAlchemy
38,377,813
<p>I try to model my MongoAlchemy class in Flask. Here is my model:</p> <pre><code>{ "_id" : ObjectId("adfafdasfafag24t24t"), "name" : "sth." "surname" : "sth." "address" : [ { "city" : "Dublin" "country" : "Ireland" } ] } </code></pre> <p>Here is my documents.py class:</p> <pr...
0
2016-07-14T15:06:42Z
38,377,963
<p>You are asking about the <a href="http://www.mongoalchemy.org/api/schema/fields.html#mongoalchemy.fields.ListField" rel="nofollow"><code>ListField</code></a> from what I understand.</p> <p>Though, I am not sure you actually need a list to store the address, why not use the special document type - <a href="http://ww...
1
2016-07-14T15:13:23Z
[ "python", "mongodb", "flask", "mongoalchemy" ]
Array Definition Modelling in MongoAlchemy
38,377,813
<p>I try to model my MongoAlchemy class in Flask. Here is my model:</p> <pre><code>{ "_id" : ObjectId("adfafdasfafag24t24t"), "name" : "sth." "surname" : "sth." "address" : [ { "city" : "Dublin" "country" : "Ireland" } ] } </code></pre> <p>Here is my documents.py class:</p> <pr...
0
2016-07-14T15:06:42Z
38,396,694
<p>You could use a <a href="http://www.mongoalchemy.org/api/schema/fields.html#mongoalchemy.fields.ListField" rel="nofollow">ListField</a> and access the city as the 1st item on the list and country as the 2nd item on the list.</p> <pre><code>{ "_id" : ObjectId("adfafdasfafag24t24t"), "name" : "sth." "surn...
0
2016-07-15T12:55:13Z
[ "python", "mongodb", "flask", "mongoalchemy" ]
Produce a function that receives the die value and the total number of rolls and prints a single line of the histogram based on the values passed
38,377,882
<p>"You will need to call the function once per possible die value."</p> <p>I'm a programming noob and have spent about seven hours trying to figure this out. </p> <p>My code is just a conglomeration of ideas and hopes that I'm headed in the right direction. I desperately need help and want to understand this stuff...
-2
2016-07-14T15:10:01Z
38,378,098
<p>You're making a mountain out of a molehill. <strong>Slow down</strong> and think about the problem. They want you to do an action a bunch of times. Then based on what each result is, do something with that information.</p> <p>We can use a <code>for</code> loop to do the actions many times, as you've used. Then we c...
0
2016-07-14T15:18:47Z
[ "python" ]
Produce a function that receives the die value and the total number of rolls and prints a single line of the histogram based on the values passed
38,377,882
<p>"You will need to call the function once per possible die value."</p> <p>I'm a programming noob and have spent about seven hours trying to figure this out. </p> <p>My code is just a conglomeration of ideas and hopes that I'm headed in the right direction. I desperately need help and want to understand this stuff...
-2
2016-07-14T15:10:01Z
38,378,226
<p>You'll want to store the result of each die role somehow, rather than just adding up the sum of your roles. This will also extend your function to be able to look at the results of all 50 results if you want, or just one roll at a time.</p> <p>There are a few data structures you could use, but I'd recommend a dicti...
0
2016-07-14T15:24:18Z
[ "python" ]
Django: query various objects in a loop
38,377,967
<p>I have a (duplicate detection) query in Django that I want to apply for several models:</p> <pre><code>Cooperation.objects.values('seo__slug').annotate(count=Count('id')).values('seo__slug).filter(count__gt=1) Article.objects.values('seo__slug').annotate(count=Count('id')).values('seo__slug).filter(count__gt=1) Cit...
0
2016-07-14T15:13:37Z
38,378,219
<p>You can make the list contain the actual classes, then your code will work:</p> <pre><code>information_objects = [Cooperation, Article, City] </code></pre> <p>If you absolutely need to get them based on strings, you can get the classes from <code>globals()</code>:</p> <pre><code>information_objects = [globals()[n...
1
2016-07-14T15:24:01Z
[ "python", "django" ]
black screen when using python PIL paste
38,378,004
<p>I am trying to paste several images end to end and then display on canvas. I cannot figure out why this image is showing as black. Any Ideas?</p> <pre><code>from tkinter import * from PIL import Image, ImageTk root = Tk() canvas = Canvas(root, width=1000, height=800) canvas.pack() grass = Image.open(r"C:\pathto\g...
1
2016-07-14T15:14:58Z
38,378,885
<p>The image is black because it is only partially visible on the Canvas. I replaced </p> <pre><code>canvas.create_image(0,0, image=worldr1) </code></pre> <p>by</p> <pre><code>canvas.create_image(0,0, anchor="nw", image=worldr1) </code></pre> <p>and the full image was visible on the Canvas (the default value is <co...
3
2016-07-14T15:56:16Z
[ "python", "tkinter", "python-imaging-library" ]
Why is idle skipping over f = open('filename' , 'r')
38,378,090
<p>I'm writing a program in python and I am having issues getting idle to read my file out. If I use improper syntax it tells me, so it is being read by the compiler but not printing it for the user. Any help would be appreciated. Here is my code.</p> <pre><code>#! python3.5.2 import sys if input() == ('im bored'): ...
-4
2016-07-14T15:18:35Z
38,378,240
<p>This doesn't do anything. Maybe take a look at the Python documentation? <a href="https://docs.python.org/3/tutorial/inputoutput.html" rel="nofollow">https://docs.python.org/3/tutorial/inputoutput.html</a></p> <p>That's a start.</p> <p>If you want to display the file, you can <em>very</em> easily iterate over a fi...
0
2016-07-14T15:24:57Z
[ "python", "linux", "python-3.x" ]
Why is idle skipping over f = open('filename' , 'r')
38,378,090
<p>I'm writing a program in python and I am having issues getting idle to read my file out. If I use improper syntax it tells me, so it is being read by the compiler but not printing it for the user. Any help would be appreciated. Here is my code.</p> <pre><code>#! python3.5.2 import sys if input() == ('im bored'): ...
-4
2016-07-14T15:18:35Z
38,378,855
<p>You only put file into variable 'f', so you need to read it or work it with someway to show it.</p> <pre><code>import sys if input() == ('im bored'): print('What season is it?') if input() == ('summer'): f = open('callfilesummer.txt', 'r') print f.read() f.close() </code></pre> <p>You...
0
2016-07-14T15:54:51Z
[ "python", "linux", "python-3.x" ]
Django custom save model admin page
38,378,224
<p>When overriding the django save_model method, how do I extract the key value. Let's say the admin page has a input for the key "name". How do I extract that value in the method:</p> <pre><code>def save_model(self, request, obj, form, change): //request.name? </code></pre>
0
2016-07-14T15:24:13Z
38,378,474
<p>You can access a field by making use of <code>form.cleaned_data</code>, like this:</p> <pre><code>def save_model(self, request, obj, form, change): name = form.cleaned_data['name'] # ... </code></pre>
1
2016-07-14T15:36:15Z
[ "python", "django", "override" ]
Reading data in parallel with multiprocess
38,378,310
<p>Can this be done? </p> <p>What i have in mind is the following:</p> <p>i ll have a dict, and each child process will add a new key:value combination to the dict. </p> <p>Can this be done with multiprocessing? Are there any limitations? </p> <p>Thanks!</p>
1
2016-07-14T15:28:35Z
38,378,453
<p><a href="https://docs.python.org/3.5/library/multiprocessing.html" rel="nofollow">Yes, Python supports multiprocessing</a>.</p> <p>Since you intend to work with the same dict for each "process" I would suggest <a href="https://docs.python.org/3.5/library/multiprocessing.html#module-multiprocessing.dummy" rel="nofol...
1
2016-07-14T15:35:20Z
[ "python", "multiprocessing" ]
Reading data in parallel with multiprocess
38,378,310
<p>Can this be done? </p> <p>What i have in mind is the following:</p> <p>i ll have a dict, and each child process will add a new key:value combination to the dict. </p> <p>Can this be done with multiprocessing? Are there any limitations? </p> <p>Thanks!</p>
1
2016-07-14T15:28:35Z
38,378,557
<p>In the case you use multiprocessing, the entries need to be propagated to "parent processes dictionary", but there is a solution for this:</p> <p>Using multiprocessing is helpful due to that guy called GIL ... so yes I did use that without thinking, as it is putting the cores to a good use. But I use a manager. lik...
1
2016-07-14T15:40:02Z
[ "python", "multiprocessing" ]
Reading data in parallel with multiprocess
38,378,310
<p>Can this be done? </p> <p>What i have in mind is the following:</p> <p>i ll have a dict, and each child process will add a new key:value combination to the dict. </p> <p>Can this be done with multiprocessing? Are there any limitations? </p> <p>Thanks!</p>
1
2016-07-14T15:28:35Z
38,378,869
<p>In case you want to just read in the data at the child processes and each child will add single key value pair you can use <a href="https://docs.python.org/2/library/multiprocessing.html#module-multiprocessing.pool" rel="nofollow"><code>Pool</code></a>:</p> <pre><code>import multiprocessing def worker(x): retu...
2
2016-07-14T15:55:21Z
[ "python", "multiprocessing" ]
Receiving Github APi 403 error when I have not exceeded my rate limit
38,378,337
<p>I'm scraping data off of Github via PyGithub. My issue is I receive this error during my scraping:</p> <p>github.GithubException.GithubException: 403 {'documentation_url': '<a href="https://developer.github.com/v3/#rate-limiting" rel="nofollow">https://developer.github.com/v3/#rate-limiting</a>', 'message': 'API ra...
2
2016-07-14T15:29:37Z
38,378,469
<p>i had solved this problem with my previous work...here it is..</p> <p>The 403 HTTP Status denotes a forbidden request, thus you have provided credentials that can't let you access some endpoints.</p> <p>So you may need to provide a valid credentials (username / password) when creating the Github object:</p> <pre>...
0
2016-07-14T15:36:07Z
[ "python", "github", "github-api", "rate-limiting", "pygithub" ]
Receiving Github APi 403 error when I have not exceeded my rate limit
38,378,337
<p>I'm scraping data off of Github via PyGithub. My issue is I receive this error during my scraping:</p> <p>github.GithubException.GithubException: 403 {'documentation_url': '<a href="https://developer.github.com/v3/#rate-limiting" rel="nofollow">https://developer.github.com/v3/#rate-limiting</a>', 'message': 'API ra...
2
2016-07-14T15:29:37Z
38,383,259
<p>So the issue wasn't with my rate limit rather it was with the message the PyGithub wrapper was returning. I traced my error back and found this class in the source code : <a href="https://github.com/PyGithub/PyGithub/blob/master/github/Requester.py" rel="nofollow">https://github.com/PyGithub/PyGithub/blob/master/git...
0
2016-07-14T19:59:54Z
[ "python", "github", "github-api", "rate-limiting", "pygithub" ]
Python printing columns side by side
38,378,349
<p>I'm struggling to align some data after iterating it through a for loop. I'd like to have each for loop output a separate column but failing to figure out how to accomplish this. I've tried ending with end='' for new lines but does not bring the next column back top. Can you please help? Below is a testable exampl...
2
2016-07-14T15:30:14Z
38,379,269
<p>Learn to use the <code>.format</code> method (of a format string). You can specify field length, left/centre/right justification, decimal places and/or leading zeros of numeric values, and much more. <a href="https://docs.python.org/3/library/string.html#formatspec" rel="nofollow">https://docs.python.org/3/library/s...
0
2016-07-14T16:16:03Z
[ "python", "loops" ]
Pygame couldn't read from resource after a time
38,378,423
<p>I am a making a Pygame game called Ninja Quest. So far, I have only worked on it for a couple of days however, I find that when I launch the game, everything works fine but, after about 30 seconds, the game will crash, saying:</p> <blockquote> <p>Traceback (most recent call last): File "NinjaQuest.py", line 151...
1
2016-07-14T15:33:58Z
38,408,891
<p>I think I have finally solved my problem! It appears that I can avoid the game crashing if, instead of using pygame.mixer.music.queue() every iteration of my main loop, instead, I just use:</p> <pre><code>if pygame.mixer.music.get_busy() == False: pygame.mixer.music.load(os.path.join("Resources","Menu","Disaste...
1
2016-07-16T07:28:55Z
[ "python", "crash", "resources", "pygame" ]
Video plays in VLC gui but not when using python libvlc
38,378,578
<p>I'm creating a python script that plays mp3/cdg karaoke files. I can open these files and they play with no problems when using the standalone VLC gui, however when I use the python libvlc library to open them, they play for a few frames then stop while the audio continues.</p> <p>I'm almost certain that this is is...
1
2016-07-14T15:40:54Z
38,379,334
<p>First, make sure you only have one copy of libvlc and that it's current.</p> <p>You can see what options VLC is using to play the file by clicking the "show more options" in the "Open Media" dialog.</p>
0
2016-07-14T16:19:48Z
[ "python", "linux", "vlc", "libvlc" ]
Maximum recursion depth on class
38,378,658
<p>I have a class that I'm trying to set is_duplicate to True like:</p> <pre><code>file = FileProperties(long, lat, timestamp, compas, filename) [...] file.is_duplicate = True </code></pre> <p>And I get a RuntimeError: maximum recursion depth exceeded while calling a Python object what exactly am I doing wrong? The f...
1
2016-07-14T15:44:21Z
38,378,724
<p>In:</p> <pre><code>@is_duplicate.setter def is_duplicate(self, value): self.is_duplicate = value </code></pre> <p>Change self.is_duplicate to self._duplicate and it should work I guess (else please provide a minimal working example).</p> <p>The reason for this bug is that you are assigning the method is_dupli...
3
2016-07-14T15:47:49Z
[ "python", "class", "python-3.x" ]
Having an issues with list comprehension
38,378,662
<pre><code>def divisble_numbers(a_list, terms): b_list = [x for x in [a_list] if (x % [terms] == 0)] c_list = [x for x in b_list if all(x % [terms] == 0)] return c_list divisble_numbers([2,3,5,1,6,7,8,9,10,11,12], [2,3]) </code></pre> <p>Returns this error: <code>TypeError: unsupported operand typ...
-1
2016-07-14T15:44:31Z
38,378,708
<p>You were pretty close. This code should work:</p> <pre><code>def divisble_numbers(a_list, terms): return [x for x in a_list if all(x % term == 0 for term in terms)] print(divisble_numbers([2,3,5,1,6,7,8,9,10,11,12], [2,3])) # Output: # [6, 12] </code></pre> <p>There are two list comprehensions happening here...
2
2016-07-14T15:47:06Z
[ "python" ]
Having an issues with list comprehension
38,378,662
<pre><code>def divisble_numbers(a_list, terms): b_list = [x for x in [a_list] if (x % [terms] == 0)] c_list = [x for x in b_list if all(x % [terms] == 0)] return c_list divisble_numbers([2,3,5,1,6,7,8,9,10,11,12], [2,3]) </code></pre> <p>Returns this error: <code>TypeError: unsupported operand typ...
-1
2016-07-14T15:44:31Z
38,378,954
<pre><code>b_list = [x for x in a_list if x%(reduce(lambda x,y : x*y, terms))==0] </code></pre> <p>Input :</p> <pre><code>a_list, terms = [2,3,5,1,6,7,8,9,10,11,12], [2,3] </code></pre> <p>Output :</p> <pre><code>[6, 12] </code></pre> <p>Your function will be :</p> <pre><code>def divisble_numbers(a_list, terms): ...
0
2016-07-14T15:59:36Z
[ "python" ]
Having an issues with list comprehension
38,378,662
<pre><code>def divisble_numbers(a_list, terms): b_list = [x for x in [a_list] if (x % [terms] == 0)] c_list = [x for x in b_list if all(x % [terms] == 0)] return c_list divisble_numbers([2,3,5,1,6,7,8,9,10,11,12], [2,3]) </code></pre> <p>Returns this error: <code>TypeError: unsupported operand typ...
-1
2016-07-14T15:44:31Z
38,378,960
<p>Your list comprehensions are good, but you've accidentally wrapped a few things in square brackets, such as <code>[terms]</code>, which don't need to be because they are already lists. <code>[terms]</code> will produce a list containing a list.</p> <p>Second, the error that you were getting is because you were taki...
2
2016-07-14T15:59:50Z
[ "python" ]
install cx_oracle for python on Mac OS
38,378,690
<p>I cannot install cx_oracle neither by pip nor from sources. An error is the same. From sources: <code>Traceback (most recent call last): File "setup.py", line 174, in &lt;module&gt; raise DistutilsSetupError("cannot locate an Oracle software " \ distutils.errors.DistutilsSetupError: cannot locate an Oracle sof...
0
2016-07-14T15:46:01Z
38,388,840
<p>Have you installed <a href="http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html" rel="nofollow">Oracle Instant Client 12.1 Basic &amp; SDK packages</a>, and set ORACLE_HOME to its location?</p>
0
2016-07-15T06:00:51Z
[ "python", "oracle", "osx", "cx-oracle" ]
install cx_oracle for python on Mac OS
38,378,690
<p>I cannot install cx_oracle neither by pip nor from sources. An error is the same. From sources: <code>Traceback (most recent call last): File "setup.py", line 174, in &lt;module&gt; raise DistutilsSetupError("cannot locate an Oracle software " \ distutils.errors.DistutilsSetupError: cannot locate an Oracle sof...
0
2016-07-14T15:46:01Z
38,390,843
<p>I forget to add path of Oracle Instant Client 12.1 Basic &amp; SDK packages to $PATH var.</p> <pre> export PATH=/opt/local/lib/share/oracle/instantclient_12_1:$PATH </pre> <p>Then I have to make several more symlinks:</p> <pre> ➜ instantclient_12_1 ln -s libclntsh.dylib.12.1 libclntsh.dylib ...
0
2016-07-15T07:58:18Z
[ "python", "oracle", "osx", "cx-oracle" ]
Scrapy gets NoneType Error when using Privoxy Proxy for Tor
38,378,710
<p>I am using Ubuntu 14.04 LTS. </p> <p>I tried Polipo, but it kept refusing Firefox's connections even if I added myself as allowedClient and hours of researching with no solution. So instead, I installed Privoxy and I verified it work with Firefox by going to the Tor website and it said Congrats this browser is conf...
3
2016-07-14T15:47:08Z
38,399,075
<p>Internally, <a href="https://github.com/scrapy/scrapy/blob/ebef6d7c6dd8922210db8a4a44f48fe27ee0cd16/scrapy/downloadermiddlewares/httpproxy.py#L32" rel="nofollow">Scrapy uses <code>urllib(2)</code>'s <code>_parse_proxy</code></a> to detect proxy settings. From <a href="https://docs.python.org/2/library/urllib.html" r...
2
2016-07-15T14:48:01Z
[ "python", "proxy", "scrapy", "polipo" ]
Finding string in file
38,378,742
<p>So I am trying to find a string from a file. My code looks like this:</p> <pre><code>fname=open('results', 'r') lines=fname.readlines() for i in lines: print i s=lines[41] x= "0x80000680: 0x00000000\n" if (i == x) : stuff happens </code></pre> <p>My code reads the file just finds...
1
2016-07-14T15:49:08Z
38,378,924
<p>your line in your file <strong>is not</strong> <code>"0x80000680: 0x00000000\n"</code></p> <p>its easy to prove your line is not this</p> <pre><code>y="0x80000680: "+ "0x00000000\n" #ensure both x and y have different `id` x= "0x80000680: 0x00000000\n" print "ID:",id(x),id(y) print y == x , y.strip() == x.strip() ...
2
2016-07-14T15:58:19Z
[ "python", "file", "if-statement" ]
Django test DB returning nothing
38,378,750
<p>I'm getting the exact same issue as <a href="http://stackoverflow.com/questions/30232963/when-does-the-database-is-being-destroy-in-django-tests?rq=1">when does the database is being destroy in django tests?</a> , where my test DB seems to be getting deleted between each method. I know it's being cleared out each ti...
3
2016-07-14T15:49:35Z
38,380,663
<p>Actually, according to the <a href="https://docs.djangoproject.com/en/1.9/intro/tutorial05/#testing-our-new-view" rel="nofollow">Django tutorial</a>, the database is rolled back between each test. (See the bottom of the linked section.) </p> <p>If you're looking to have a common setup between tests, you should cons...
1
2016-07-14T17:33:30Z
[ "python", "django", "postgresql", "unit-testing" ]
How to extract all the regular paragraph using xpath for this kind of html?
38,378,943
<p>url = "<a href="http://news.xinhuanet.com/english/2016-07/14/c_135513513.htm" rel="nofollow">http://news.xinhuanet.com/english/2016-07/14/c_135513513.htm</a>" I want to extract all the regular paragraphs for the news, namely all the tag <code>&lt;p&gt;</code> without any attribution. I use:</p> <pre><code>hxs = etr...
2
2016-07-14T15:59:08Z
38,379,146
<p>The HTML you see in the browser is not the same as you get with the HTTP library you are using to download the page. For instance, if I do:</p> <pre><code>import requests url = "http://news.xinhuanet.com/english/2016-07/14/c_135513513.htm" response = requests.get(url) print(response.content) </code></pre> <p>The ...
1
2016-07-14T16:08:43Z
[ "python", "html", "xpath", "html-parsing" ]
df.set_index() on datetime objects list column for future dates not working.
38,378,966
<pre><code>d = {'one':[datetime.datetime(3000, 6, 1, 0, 0), datetime.datetime(2016, 6, 1, 0, 0), datetime.datetime(2016, 7, 1, 0, 0), datetime.datetime(2016, 6, 1, 0, 0),], 'two':[1,2,3,4,5,6,7,8,9,10,11,12,13,14]} df = pd.DataFrame(d) print df df = df.set_index(['one']) print df ERROR: At df = df.set_index(['one'...
0
2016-07-14T16:00:13Z
38,379,737
<p>Your code raises different Exceptions (a <code>SyntaxError</code>, a <code>ValueError: arrays must all be same length</code> and a <code>pandas.tslib.OutOfBoundsDatetime: Out of bounds</code> error) for me but I think the last one, the <code>OutOfBoundsDatetime</code> refers to the same problem you are seeing.</p> ...
1
2016-07-14T16:39:29Z
[ "python", "datetime", "numpy", "pandas" ]
df.set_index() on datetime objects list column for future dates not working.
38,378,966
<pre><code>d = {'one':[datetime.datetime(3000, 6, 1, 0, 0), datetime.datetime(2016, 6, 1, 0, 0), datetime.datetime(2016, 7, 1, 0, 0), datetime.datetime(2016, 6, 1, 0, 0),], 'two':[1,2,3,4,5,6,7,8,9,10,11,12,13,14]} df = pd.DataFrame(d) print df df = df.set_index(['one']) print df ERROR: At df = df.set_index(['one'...
0
2016-07-14T16:00:13Z
38,379,971
<p>As mentioned on the <a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html#timestamp-limitations" rel="nofollow">pandas documentation</a>, pandas <code>Timestamp</code> objects can only reach to the year 2262. However, <a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html#representing-ou...
1
2016-07-14T16:53:17Z
[ "python", "datetime", "numpy", "pandas" ]
Cannot access a list by index that was randomly chosen from a list of lists
38,378,983
<p>I am working on a python learning exercise that requires creating a text game run from the console. I want to create a trivia game. (Yes, it's Harry Potter trivia - please don't judge) To make the question pool, I have made a text file of the questions, answer options, and answers. To keep the correct options and a...
0
2016-07-14T16:01:02Z
38,379,043
<p>Python is reading your file lines as strings. The strings look like a Python list, but they're not. In order to store the questions in a text file, you should use a data format like json. See this question for reference: <a href="http://stackoverflow.com/questions/2835559/parsing-values-from-a-json-file-in-python">P...
1
2016-07-14T16:03:52Z
[ "python", "list", "random" ]
Cannot access a list by index that was randomly chosen from a list of lists
38,378,983
<p>I am working on a python learning exercise that requires creating a text game run from the console. I want to create a trivia game. (Yes, it's Harry Potter trivia - please don't judge) To make the question pool, I have made a text file of the questions, answer options, and answers. To keep the correct options and a...
0
2016-07-14T16:01:02Z
38,379,691
<p>I would also recommend reading on the <code>repr()</code> and <code>eval()</code> built-in functions, in case you consider the json module to be an overkill. In its simplest form, <code>eval()</code> allows you to evaluate a string into its proper data structure, such as a tuple or list (like in your case).</p>
0
2016-07-14T16:37:10Z
[ "python", "list", "random" ]
Python: What is the sense of class instantiation without variable
38,379,001
<p>Why can I do </p> <pre><code>class MyApp(App): def build(self): return Label(text="Hello World") MyApp().run() </code></pre> <p>instead of doing</p> <pre><code> instance = MyApp() instance.run() </code></pre> <p>I am fairly new to OOP and was fairly confused when I saw stuff written in the w...
2
2016-07-14T16:01:55Z
38,379,241
<p>You are basically doing the same thing in the first code block as in the second. The difference is that in the first one <strong>you can't reuse the instantiated MyApp() class again</strong>.</p> <p>In the second example however you define a object that can be reused. </p> <p><strong>EDIT</strong></p> <p>As @arek...
4
2016-07-14T16:14:03Z
[ "python", "oop", "instantiation", "instance-variables" ]
Python: What is the sense of class instantiation without variable
38,379,001
<p>Why can I do </p> <pre><code>class MyApp(App): def build(self): return Label(text="Hello World") MyApp().run() </code></pre> <p>instead of doing</p> <pre><code> instance = MyApp() instance.run() </code></pre> <p>I am fairly new to OOP and was fairly confused when I saw stuff written in the w...
2
2016-07-14T16:01:55Z
38,379,832
<p>It is more than just not being able to reuse the instantiated <code>MyApp()</code> object.</p> <p>Using <code>MyApp.run()</code> instead of assigning it to a variable lets Python free the memory occupied by the object as soon as <code>run()</code> invocation is finished.</p> <p>In the second example, you need to m...
0
2016-07-14T16:44:38Z
[ "python", "oop", "instantiation", "instance-variables" ]
Connect to DynamoDB Local from inside docker container with boto3
38,379,091
<p>For testing, I am trying to run my python 3.4 application from inside docker, and connect to a <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html" rel="nofollow">DynamoDB Local</a> instance. I can access DynamoDB local from the host without problems.</p> <p>However, I get a ...
1
2016-07-14T16:06:07Z
38,426,856
<p>You are using the docker <a href="https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/" rel="nofollow">link feature</a> to connect two containers together. The fundamental principles here are:</p> <ol> <li>You give your DB container a unique name, using <code>--name</code>.</li> <li>You...
1
2016-07-17T23:22:39Z
[ "python", "python-3.x", "amazon-web-services", "docker", "amazon-dynamodb" ]
Python: Iterating List of Dates and Selecting First Day of Fiscal Week
38,379,322
<p>I have a list of dates and fiscal weeks in Python. I am using the following code to pull them in from a CSV and load into a list:</p> <pre><code>import csv with open('Fiscal3.csv', 'rb') as csvfile: reader = csv.reader(csvfile) reader2 = list(reader) </code></pre> <p>Here is what the list looks like:</p> ...
0
2016-07-14T16:19:19Z
38,440,935
<p>Not sure if that's the best solution you can get but. Here I'm assuming that your first line will always be your first fiscal day</p> <p><pre> <code> import csv from datetime import datetime, timedelta, MINYEAR</p> <p>with open ('Fiscal3.csv','rb') as csvfile: r = csv.reader(csvfile) first_day = datetime(1...
0
2016-07-18T15:45:03Z
[ "python", "list", "loops", "pandas" ]
Python: Iterating List of Dates and Selecting First Day of Fiscal Week
38,379,322
<p>I have a list of dates and fiscal weeks in Python. I am using the following code to pull them in from a CSV and load into a list:</p> <pre><code>import csv with open('Fiscal3.csv', 'rb') as csvfile: reader = csv.reader(csvfile) reader2 = list(reader) </code></pre> <p>Here is what the list looks like:</p> ...
0
2016-07-14T16:19:19Z
38,441,085
<pre><code>from datetime import datetime, timedelta res=[] dates=[('1/13/2020', 50),('1/13/2020', 49),('1/13/2020', 52)] for a, b in dates : dt = datetime.strptime(a, '%m/%d/%Y') start = dt - timedelta(days=dt.weekday()) end = start + timedelta(days=6) res.append((a,b, str(start)[:10])) print res </...
0
2016-07-18T15:50:55Z
[ "python", "list", "loops", "pandas" ]
How can I change de parameters of gaussian_kde for a scatter plot colored by density in matplotlib
38,379,327
<p>As explained by Joe Kington answering in this question : <a href="http://stackoverflow.com/questions/20105364/how-can-i-make-a-scatter-plot-colored-by-density-in-matplotlib">How can I make a scatter plot colored by density in matplotlib</a>, I made a scatter plot colored by density. However, due to the complex distr...
0
2016-07-14T16:19:33Z
38,420,625
<p>Did have a look at <a href="https://web.stanford.edu/~mwaskom/software/seaborn/index.html" rel="nofollow">Seaborn</a>? It's not exactly what you're asking for, but it already has functions for generating density plots:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt from scipy.stats import kendall...
1
2016-07-17T11:16:47Z
[ "python", "python-3.x", "matplotlib", "scipy", "density-plot" ]
How to use STAR detector in openCV 3 with python?
38,379,365
<p>I'm trying to use the STAR detector in openCV 3, and it's throwing an error:</p> <pre><code>import cv2 image = cv2.imread('grand_central_terminal.png') gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) star = cv2.xfeatures2d.StarDetector_create() (kps, descs) = star.detectAndCompute(gray, None) print("# of keypoints...
1
2016-07-14T16:21:14Z
38,381,283
<p>The error code <code>-213</code> you are receiving indicates that the <code>detectAndCompute</code> method is not implemented for the STAR detector. That is because STAR is only a feature detector, not a combination detector and descriptor. Your code can be fixed by calling the <code>detect</code> method instead:</p...
1
2016-07-14T18:09:18Z
[ "python", "python-3.x", "opencv", "opencv3.0" ]
Slow image opening python, reccomendation for increased speed?
38,379,372
<p>I'm doing some very basic image augmentation for training a convnet, and it is very slow. I was wondering if anyone has advice about a faster way to open, flip, and close images in python? It has about 100k images to go through and takes a couple hours.</p> <pre><code>print 'Example of image in train.txt: ' + image...
2
2016-07-14T16:21:22Z
38,380,333
<p>I would give the PIL or the Pillow package a try.</p> <p>PIL documentation: <a href="http://www.pythonware.com/products/pil/" rel="nofollow">http://www.pythonware.com/products/pil/</a></p> <p>Pillow documentation: <a href="https://pillow.readthedocs.io/en/3.3.x/" rel="nofollow">https://pillow.readthedocs.io/en/3.3...
0
2016-07-14T17:14:22Z
[ "python", "numpy", "python-imaging-library" ]
Slow image opening python, reccomendation for increased speed?
38,379,372
<p>I'm doing some very basic image augmentation for training a convnet, and it is very slow. I was wondering if anyone has advice about a faster way to open, flip, and close images in python? It has about 100k images to go through and takes a couple hours.</p> <pre><code>print 'Example of image in train.txt: ' + image...
2
2016-07-14T16:21:22Z
38,380,403
<p>I would suggest using <a href="http://keras.io/" rel="nofollow">Keras</a> (which is a deep learning abstraction layer on top of Theano or TensorFlow). It already has built-in a <a href="http://keras.io/preprocessing/image/" rel="nofollow">ImageDataGenerator</a>. You could essentially use it to generate different ima...
1
2016-07-14T17:17:59Z
[ "python", "numpy", "python-imaging-library" ]
Change colormap in SymPy's ``plot3d``
38,379,403
<p>In SymPy you can automatically plot a surface from an expression, namely</p> <pre><code>from sympy import symbols from sympy.plotting import plot3d x, y = symbols('x y') monkey_saddle = x**3 - 3*x*y**2 plot3d(monkey_saddle, cmap="RdYlBu") </code></pre> <p>to get</p> <p><a href="http://i.stack.imgur.com/4IdeM.png...
3
2016-07-14T16:22:55Z
38,399,266
<p>I read the source code of <code>sympy.plotting.plot.py</code>, it seems that the cmap is set to <code>jet</code>:</p> <pre><code>collection = self.ax.plot_surface(x, y, z, cmap=self.cm.jet, rstride=1, cstride=1, ...
4
2016-07-15T14:56:40Z
[ "python", "matplotlib", "plot", "sympy" ]
Read between lines in text file
38,379,423
<p>First of all, the contents of my example text file looks like this:</p> <pre class="lang-none prettyprint-override"><code>Some Data Nothing important Start here This is important Grab this line too And this ono too End here Text goes on, but isn't important Next text Blaah </code></pre> <p>And now, I want to read ...
1
2016-07-14T16:24:01Z
38,379,458
<p>You can use regular expressions (<code>re</code> module) with the <code>re.DOTALL</code> option so that newlines are considered as regular characters.</p> <pre><code>import re source = """Some Data Nothing important Start here This is important Grab this line too And this ono too End here Text goes on, but isn't i...
0
2016-07-14T16:26:07Z
[ "python" ]
Read between lines in text file
38,379,423
<p>First of all, the contents of my example text file looks like this:</p> <pre class="lang-none prettyprint-override"><code>Some Data Nothing important Start here This is important Grab this line too And this ono too End here Text goes on, but isn't important Next text Blaah </code></pre> <p>And now, I want to read ...
1
2016-07-14T16:24:01Z
38,379,472
<p>It's the second loop that needs the break...</p> <pre><code>for line_1 in input: if 'End here' in line_1: break print line_1.strip() </code></pre>
3
2016-07-14T16:26:40Z
[ "python" ]
Read between lines in text file
38,379,423
<p>First of all, the contents of my example text file looks like this:</p> <pre class="lang-none prettyprint-override"><code>Some Data Nothing important Start here This is important Grab this line too And this ono too End here Text goes on, but isn't important Next text Blaah </code></pre> <p>And now, I want to read ...
1
2016-07-14T16:24:01Z
38,379,661
<p>You can read all lines first and enumerate it:</p> <pre><code>filename = 'example_file.txt' useful_content = [] with open(filename, 'r') as input: all_lines = input.readlines() # read all lines for idx in range(len(all_lines)): # iterate all lines if 'Start here' in all_lines[idx]: useful_con...
0
2016-07-14T16:36:06Z
[ "python" ]
Read between lines in text file
38,379,423
<p>First of all, the contents of my example text file looks like this:</p> <pre class="lang-none prettyprint-override"><code>Some Data Nothing important Start here This is important Grab this line too And this ono too End here Text goes on, but isn't important Next text Blaah </code></pre> <p>And now, I want to read ...
1
2016-07-14T16:24:01Z
38,379,714
<p>Your problem is that you should be checking for 'End Here' in your second loop, as the second and third one don't run at the same time. In fact, the third loop won't even run.</p> <p>With that in mind, this code will work:</p> <pre><code>filename = 'mydata.txt' with open(filename, 'r') as f: for line in f: ...
0
2016-07-14T16:38:35Z
[ "python" ]
Using Beautiful Soup to create new_tag with attribute named "name"
38,379,451
<p>I've got a block of XML that I need to insert some elements into</p> <pre><code>&lt;importer in="!SRCFILE!" media="movie"&gt; &lt;video-out id="video_2_importer"&gt;&lt;/video-out&gt; &lt;audio-out id="audio_2_importer"&gt;&lt;/audio-out&gt; &lt;/importer&gt; </code></pre> <p>What I need to do is insert a few opti...
1
2016-07-14T16:25:43Z
38,379,523
<p>In this case, you can create the instance of the <code>Tag</code> this way:</p> <pre><code>from bs4 import BeautifulSoup, Tag in_point = Tag(builder=soup.builder, name='option', attrs={'value':'60','name':'start-time'}) </code></pre> <p>which is essentially what <code>new_tag()</co...
1
2016-07-14T16:28:41Z
[ "python", "beautifulsoup" ]
How to read only part of a list of strings in python
38,379,453
<p>I need to find a way to be able to read x bytes of data from a list containing strings. Each item in the list is ~36MB. I need to be able to run through each item in the list, but only grabbing about ~1KB of that item at a time.</p> <p>Essentially it looks like this:</p> <pre><code>for item in list: #grab part...
4
2016-07-14T16:25:48Z
38,380,111
<p>If you're using <code>str</code>'s (or <code>byte</code>'s in python 3), each character is a byte, so <code>f.read(5)</code> is the same as <code>f[:5]</code>. If you want just the first 5 bytes from every string in a list, you could do</p> <pre><code>[s[:5] for s in buckets] </code></pre> <p>But be aware that th...
2
2016-07-14T17:00:43Z
[ "python", "string", "list" ]
How to read only part of a list of strings in python
38,379,453
<p>I need to find a way to be able to read x bytes of data from a list containing strings. Each item in the list is ~36MB. I need to be able to run through each item in the list, but only grabbing about ~1KB of that item at a time.</p> <p>Essentially it looks like this:</p> <pre><code>for item in list: #grab part...
4
2016-07-14T16:25:48Z
38,381,947
<p>Please check speed of this, if you are wanting to affect the input list.</p> <pre><code>l = [] # Your list x = 0 processed = 0 while processed!=len(l): bts = l[x][:1024] l[x] = l[x][1024:] # Do something with bts if not l[x]: processed += 1 x += 1 if x==len(l): x = 0 </code></pre> <p>This m...
0
2016-07-14T18:46:04Z
[ "python", "string", "list" ]
Flask jinja2 update div content without refresh page
38,379,507
<p>Need achieve some features like [<a href="http://webonise.co.uk/][1]" rel="nofollow">http://webonise.co.uk/][1]</a> when click on contact,resume,resources link will update (location URL&amp;div content) but without refresh the page. <br> <br></p> <h2>Flask view function</h2> <pre><code>@app.route('/') def index(...
-1
2016-07-14T16:28:00Z
38,385,652
<p>You can use <a href="https://pythonhosted.org/Flask-Sijax/" rel="nofollow">Flask-Sijax</a> which helps you add Sijax support to your Flask app. <a href="https://pypi.python.org/pypi/Sijax" rel="nofollow">Sijax</a> is a python/jquery library that makes AJAX easy to use on your web applications. Alternatively you coul...
1
2016-07-14T23:15:11Z
[ "javascript", "jquery", "python", "flask", "jinja2" ]
csv writer pad with zeroes
38,379,574
<p>I have a working python script that takes a .csv input, takes out the 4 columns that I want, trims all white space, and writes it to a new file. There's only one thing I can't figure out how to do...</p> <pre><code>import csv,time,string,os,requests dw = "\\\\network\\folder\\btc.csv" inv_fields = ["id", "rsl", "...
0
2016-07-14T16:31:38Z
38,379,749
<p>You can conver integers to string first, and then use <code>zfill</code> function.</p> <pre><code>&gt;&gt; print str(123).zfill(9) 000000123 &gt;&gt; print str(123).zfill(2) 123 &gt;&gt; print str(123).zfill(3) 123 &gt;&gt; print str(123).zfill(4) 0123 </code></pre> <p>Even if you have negative number, you can sti...
1
2016-07-14T16:39:56Z
[ "python", "csv" ]
csv writer pad with zeroes
38,379,574
<p>I have a working python script that takes a .csv input, takes out the 4 columns that I want, trims all white space, and writes it to a new file. There's only one thing I can't figure out how to do...</p> <pre><code>import csv,time,string,os,requests dw = "\\\\network\\folder\\btc.csv" inv_fields = ["id", "rsl", "...
0
2016-07-14T16:31:38Z
38,379,949
<p>As already proposed in the comments, the following works on my machine:</p> <pre><code># ... row['number'] = "{:09d}".format(int(row['number'])) w.writerow(row) </code></pre>
1
2016-07-14T16:52:02Z
[ "python", "csv" ]
csv writer pad with zeroes
38,379,574
<p>I have a working python script that takes a .csv input, takes out the 4 columns that I want, trims all white space, and writes it to a new file. There's only one thing I can't figure out how to do...</p> <pre><code>import csv,time,string,os,requests dw = "\\\\network\\folder\\btc.csv" inv_fields = ["id", "rsl", "...
0
2016-07-14T16:31:38Z
38,380,253
<p>The simplest way would be to just use the <code>zfill()</code> string method on the one field (no need to convert it into a integer first). You can also handle writing the header row in the output file by just calling the <code>csv.DictWriter.writeheader()</code> method:</p> <pre><code>import csv,time,string,os,req...
1
2016-07-14T17:09:27Z
[ "python", "csv" ]
AsyncHTTPClient blocking my Tornado IOLoop
38,379,630
<p>how are you?</p> <p>I've been through this trouble the last days, and I seem to not being able to completely understand the tornado gen library.</p> <p>I have this piece of code, as an example:</p> <pre><code>@gen.coroutine def get(self, build_id=None): status_query = self.get_query_arguments("status") li...
1
2016-07-14T16:34:11Z
38,380,833
<p>AsyncHTTPClient's default max_clients is 10. When you initiate 15 requests, 10 of them begin immediately, but the remaining 5 must wait for other requests to finish before they can begin. To begin more concurrent requests, raise max_clients to a larger number. <a href="http://www.tornadoweb.org/en/stable/httpclient....
1
2016-07-14T17:44:00Z
[ "python", "tornado", "coroutine" ]