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
From python to AIML
38,411,748
<p>I'm trying to create my first chatbot that I want to use for my home automation project. </p> <p>This might sound stupid and maybe this is not the way to go but I would like to have your opinion and perhaps a way to make it work.</p> <p>I want to be able to ask my bot what is my location and I want it to run my py...
0
2016-07-16T13:34:12Z
38,536,351
<p>If your location is Chicago, You can use <code>kernel.setPredicate("location", "Chicago")</code> in Python and then put out the value in AIML like this:</p> <pre><code>&lt;category&gt; &lt;pattern&gt;WHAT IS MY LOCATION&lt;/pattern&gt; &lt;template&gt;Your location: &lt;get name="location"&gt;&lt;/get&gt;&lt;/templ...
0
2016-07-22T22:57:06Z
[ "python", "aiml" ]
How do I make "x += 5" (with x a custom class) add to a property of x?
38,411,794
<p>I have a class like this:</p> <pre><code>class C(object): a = 5 def __iadd__(self, other): self.a += other </code></pre> <p>I would like to be able to do something like:</p> <pre><code>b = C() b += 7 </code></pre> <p>And have b the same, but with 7 added to b.a. However, if I actually run this, i...
1
2016-07-16T13:39:47Z
38,411,816
<p>You forgot to return <code>self</code> from the <code>__iadd__</code> method:</p> <pre><code>def __iadd__(self, other): self.a += other return self </code></pre> <p>From the <a href="https://docs.python.org/2/reference/datamodel.html#object.__iadd__"><code>object.__iadd__()</code> documentation</a>:</p> <...
7
2016-07-16T13:41:43Z
[ "python", "python-2.7", "oop" ]
Iso-compliant conversion
38,411,892
<p>I'm new in django and I'm still bit confused with something written in documentation. I'm using django 1.8 with python 2. Reading this paragraph <a href="https://docs.djangoproject.com/en/1.8/ref/models/instances/#what-happens-when-you-save" rel="nofollow">about saving an object in db</a>, I got puzzled reading th...
-1
2016-07-16T13:50:54Z
38,412,259
<p>I think you skimmed over the first part of that page in the <a href="https://docs.djangoproject.com/en/1.8/ref/models/instances/#what-happens-when-you-save" rel="nofollow">documentation</a>.</p> <blockquote> <p>What happens when you save?</p> <p>When you save an object, <strong>Django performs</strong> the f...
1
2016-07-16T14:39:29Z
[ "python", "django", "django-models" ]
Iso-compliant conversion
38,411,892
<p>I'm new in django and I'm still bit confused with something written in documentation. I'm using django 1.8 with python 2. Reading this paragraph <a href="https://docs.djangoproject.com/en/1.8/ref/models/instances/#what-happens-when-you-save" rel="nofollow">about saving an object in db</a>, I got puzzled reading th...
-1
2016-07-16T13:50:54Z
38,412,488
<p>Your problem has nothing at all to do with field conversion.</p> <p>Your model does not actually include the <code>data_creation</code> or <code>subcommunity_flag</code> fields, because you did not call the field classes in your model definition.</p> <pre><code> data_creation = models.DateField() subcommunity_f...
0
2016-07-16T15:12:10Z
[ "python", "django", "django-models" ]
anaconda/conda - install a specific package version
38,411,942
<p>I want to install the 'rope' package in my current active environment using conda. Currently, the following 'rope' versions are available:</p> <pre><code>(data_downloader)user@user-ThinkPad ~/code/data_downloader $ conda search rope Using Anaconda Cloud api site https://api.anaconda.org Fetching package metadata: ....
0
2016-07-16T13:57:22Z
38,412,024
<p>There is no version <code>1.3.0</code> for <code>rope</code>. <code>1.3.0</code> refers to the package <code>cached-property</code>. The highest available version of <code>rope</code> is <code>0.9.4</code>.</p> <p>You can install different versions with <code>conda install package=version</code>. But in this case t...
1
2016-07-16T14:08:27Z
[ "python", "anaconda" ]
Django QuerySet in template for relational models
38,411,946
<p>I am trying to setup a relation with another model using FK in django but I can't call FK related model fields in django templates. In template when I call "provider.name" it shows me "None" as result. I do have 5 different suppliers listed and can see from admin. I have providers and I got products like below:</p> ...
0
2016-07-16T13:58:09Z
38,411,994
<p>I case of calling <code>provider</code> you call related manager so it return <code>None</code> because manager have no method like this.<br> If you want to retrieve objects from managers, you should call <code>self.providers.all()</code><br> In your case, template tags should looks like this: </p> <pre><code>{% f...
2
2016-07-16T14:04:16Z
[ "python", "django", "django-templates", "django-template-filters" ]
\b python doesnt delete caracter
38,411,949
<p>So I go through a book, and copied the exact same code as in there. What the code should do, is that the \b deletes the line so the position gets updated always at the same place. In my case though it draws wierd blue cirlces. I tried it without flush= True but it gives same result.</p> <pre><code>while True: x...
1
2016-07-16T13:58:32Z
38,411,998
<pre><code>while True: x, y = pyautogui.position() print('X: %4d Y: %4d' % (x, y), end = '\r') </code></pre> <p><code>\r</code> will cause the next print to write to the same. your string must have the same length or you can pad with spaces.</p> <p><code>\n</code> would start a newline <code>\r</code> do no...
1
2016-07-16T14:04:37Z
[ "python", "shell", "python-3.x" ]
How to calculate the growth rate, and time amount of an algorithm?
38,411,971
<p>I am currently enjoying <em>Think Complexity</em> by Allen Downey and a few hours ago I finished the section on growth rate. I paused reading and googled growth rates, and expanded on the info the book gave me. I also found out that you can calculate the amount of <em>time</em> it takes for an algorithm to calculate...
-1
2016-07-16T14:02:05Z
38,412,542
<p>Generally it is not a good approach to calculate the time a function takes since it is dependent on many factors. For this reason we often express complexity in terms of computational steps.</p> <p>Multiple notations exist (big-Oh, big-Omega, big-Theta). Big-Oh represents an upper bound, hence O(n) indicates that i...
0
2016-07-16T15:20:32Z
[ "python", "algorithm", "time", "complexity-theory" ]
If request timeout skip url python requests
38,411,983
<p>I would like the following script to try every url in url_list, and if it exist print it exist(url) and if not print don't(url) and if request timeout skip to the next url using "requests" lib:</p> <pre><code>url_list = ['www.google.com','www.urlthatwilltimeout.com','www.urlthatdon\'t exist'] def exist: if req...
0
2016-07-16T14:03:04Z
38,413,142
<p>Based on <a href="http://stackoverflow.com/a/22096841/866915">this SO answer</a> below is code which will limit the total time taken by a GET request as well as discern other exceptions that may happen.</p> <p>Note that in requests 2.4.0 and later you may specify a connection timeout and read timeout by using the s...
0
2016-07-16T16:23:22Z
[ "python", "timeout", "python-requests" ]
can't run python3 on ubuntu
38,412,089
<p>I can't run python3 on ubuntu 14.04</p> <pre><code>alias python=python3 python --version </code></pre> <p>outputs:</p> <pre><code>Python 2.7.6 </code></pre> <p>and </p> <pre><code>python3 --version </code></pre> <p>gives same output</p> <p>As I understand python3 should be preinstalled on the system?</p> <p>...
0
2016-07-16T14:17:47Z
38,412,114
<p>Check if <code>python3</code> is installed:</p> <pre><code>python3 --version </code></pre> <p>Add <code>alias python=python3</code> into <code>~/.bashrc</code> or <code>~/.bash_aliases</code> file.</p> <p>You must logout then login again.</p> <p>I recommend using <code>python3</code> for python 3.x. There are a ...
4
2016-07-16T14:21:48Z
[ "python", "python-2.7", "python-3.x", "ubuntu" ]
can't run python3 on ubuntu
38,412,089
<p>I can't run python3 on ubuntu 14.04</p> <pre><code>alias python=python3 python --version </code></pre> <p>outputs:</p> <pre><code>Python 2.7.6 </code></pre> <p>and </p> <pre><code>python3 --version </code></pre> <p>gives same output</p> <p>As I understand python3 should be preinstalled on the system?</p> <p>...
0
2016-07-16T14:17:47Z
38,412,133
<p>You misunderstand how aliases work. You need to reset the hash table via <code>hash -r</code> (see <code>man bash</code> for details). </p> <p>Also:</p> <pre><code>edd@max:~$ python3 --version Python 3.5.1+ edd@max:~$ lsb_release -d Description: Ubuntu 16.04 LTS edd@max:~$ </code></pre> <p>and</p> <pre><code...
3
2016-07-16T14:23:43Z
[ "python", "python-2.7", "python-3.x", "ubuntu" ]
Python calling Rust FFI with ctypes crashes at exit with "pointer being freed was not allocated"
38,412,184
<p>I'm trying to free memory allocated to a <code>CString</code>and passed to Python using ctypes. However, Python is crashing with a malloc error:</p> <pre class="lang-none prettyprint-override"><code>python(30068,0x7fff73f79000) malloc: *** error for object 0x103be2490: pointer being freed was not allocated </code>...
1
2016-07-16T14:31:09Z
38,419,426
<p>I think that the Rust side of the code assumes ownership of the data and tries to deallocate the data when the process exits, so the Python code is not to be blamed. As a proof, the following C code that calls <code>encode_coordinates_ffi</code> and <code>drop_cstring</code> also causes a segmentation fault.</p> <p...
2
2016-07-17T08:43:47Z
[ "python", "rust", "ctypes", "ffi" ]
Python calling Rust FFI with ctypes crashes at exit with "pointer being freed was not allocated"
38,412,184
<p>I'm trying to free memory allocated to a <code>CString</code>and passed to Python using ctypes. However, Python is crashing with a malloc error:</p> <pre class="lang-none prettyprint-override"><code>python(30068,0x7fff73f79000) malloc: *** error for object 0x103be2490: pointer being freed was not allocated </code>...
1
2016-07-16T14:31:09Z
38,422,230
<p>Thanks to the effort made in <a href="http://stackoverflow.com/a/38419426/155423">J.J. Hakala's answer</a>, I was able to produce a <a href="/help/mcve">MCVE</a> in pure Rust:</p> <pre><code>extern crate libc; use std::ffi::CString; use libc::c_void; fn encode_coordinates(coordinates: &amp;Vec&lt;[f64; 2]&gt;) -&...
1
2016-07-17T14:21:23Z
[ "python", "rust", "ctypes", "ffi" ]
Python script executing two other python scripts asynchronously
38,412,223
<p>I have a python script myscript that when run it "stays open" with a GUI. I would like to write a python script launching myscript two times like this: </p> <pre><code>bash&gt;python runNTimes.py 2 </code></pre> <p>I have the following code for runNTimes.py</p> <pre><code>import subprocess for i in range(int(sys....
0
2016-07-16T14:35:47Z
38,412,374
<p>Use Popen instead: <code>call()</code> blocks <code>Popen()</code> doesn't</p> <pre><code>from subprocess import Popen import sys for i in range(int(sys.argv[1])): Popen(['python', 'synccall1.py']) </code></pre> <p>synccall1.py</p> <pre><code>try: import Tkinter as tk # for Python2 except: i...
1
2016-07-16T14:55:09Z
[ "python", "subprocess", "launch" ]
JSON Using Python
38,412,248
<p>I tried running this code and get error:</p> <pre><code>Traceback (most recent call last): File "/Users/ccharest/Desktop/PCC/remember_me_2.py", line 7, in &lt;module&gt; username = json.load(f_obj) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 268, in load ...
0
2016-07-16T14:38:02Z
38,412,350
<p>As the comments suggest above, your code is fine. The contents of your file, however, are almost certainly empty or not JSON. A quick proof of concept:</p> <pre><code>In [1]: import json In [2]: json.loads("a") --------------------------------------------------------------------------- JSONDecodeError ...
1
2016-07-16T14:52:01Z
[ "python", "json" ]
How to avoid accidentally messing up the base class in Python?
38,412,261
<p>Python uses the underscore convention for private variables. However, nothing seems to stop you from messing up the base class accidentally in, for example</p> <pre><code>class Derived(Base): def __init__(self, ...): ... super(Derived, self).__init__(...) ... self._x = ... </code...
2
2016-07-16T14:39:33Z
38,412,317
<p>Use <a href="https://docs.python.org/3.3/tutorial/classes.html#private-variables" rel="nofollow">private variables with two underscores</a>. This way, name mangling protects you from messing up your parent class (<em>in normal use cases</em>).</p> <blockquote> <p>Since there is a valid use-case for class-private ...
4
2016-07-16T14:48:16Z
[ "python", "oop", "encapsulation" ]
How to initialize a 2D integer array using raw_input() in PYTHON
38,412,326
<p>I need to initialize a 2D integer array[10*10] taking input from user in PYTHON. What is the code for this? I have tried doing this but it shows error as list index out of range<br/></p> <pre><code>board = [[]] for i in range(0,10): for j in range(0,10): board[i].append(raw_input()) </code></pre> <p>Tr...
-1
2016-07-16T14:49:21Z
38,412,671
<pre><code>board = [] for i in range(10): row = [] for j in range(10): row.append(j) # row.append(raw_input()) board.append(row) &gt;&gt;&gt; board [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4...
0
2016-07-16T15:35:22Z
[ "python", "arrays", "input", "initialization", "raw-input" ]
Plotting in python using matplotlib?
38,412,382
<p>I have been trying to simulate the first order differential equation using the fourth order <a href="https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods" rel="nofollow">Runge-Kutta method</a>, but I am having problems plotting it.</p> <pre><code>#simulation of ode using 4th order rk method dy/dx=-2y+1.3e^-x,...
0
2016-07-16T14:56:32Z
38,412,445
<p>As suggested in the comment, you can create two lists to store <code>x</code> and <code>y</code> values and plot it after the <code>while</code> loop:</p> <pre><code>import math import numpy as np import matplotlib.pyplot as plt h=0.01; ti=0; x=0; n=0; y=5; def f(x,y): return 1.3*math.exp(-x)-2*y xs = [x] ...
2
2016-07-16T15:06:35Z
[ "python", "matplotlib" ]
Plotting in python using matplotlib?
38,412,382
<p>I have been trying to simulate the first order differential equation using the fourth order <a href="https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods" rel="nofollow">Runge-Kutta method</a>, but I am having problems plotting it.</p> <pre><code>#simulation of ode using 4th order rk method dy/dx=-2y+1.3e^-x,...
0
2016-07-16T14:56:32Z
38,686,894
<p>Another source for wrong results is the first line in the RK4 loop. Instead of </p> <pre><code> k1=f(x,5); </code></pre> <p>use</p> <pre><code> k1=f(x,y); </code></pre> <p>since the value of <code>y</code> does not stay constant at the initial value.</p>
0
2016-07-31T17:59:05Z
[ "python", "matplotlib" ]
How can I extract the values from a dictionary returned from my beautifulsoup results?
38,412,478
<p>I am working on an app that uses beatifulsoup, Python, requests and django. I've been kind of grasping how to use beautiful soup. But drilling down seems to different elements is confusing at times. I created a function, albeit not the best, that scrapes links from posts and uses those links to go to the posts detai...
0
2016-07-16T15:10:44Z
38,415,520
<p>If I understand well, you want to find 2 elements from your <code>p.tube</code> BeautifulSoup object. I'll call it <code>soup</code> for easier understanding.</p> <p>First, I would get rid of the <code>&lt;script&gt;</code> with <code>soup.text</code> function.</p> <p>Then I would use regular expression re package...
0
2016-07-16T20:52:03Z
[ "python", "json", "django", "beautifulsoup" ]
Difference between os.path.dirname(os.path.abspath(__file__)) and os.path.dirname(__file__)
38,412,495
<p>I am a beginner working on Django Project. Settings.py file of a Django project contains these two lines:</p> <pre><code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) </code></pre> <p>I want to know the difference as I think both ar...
1
2016-07-16T15:13:34Z
38,412,504
<p><code>BASE_DIR</code> is pointing to the <em>parent</em> directory of <code>PROJECT_ROOT</code>. You can re-write the two definitions as:</p> <pre><code>PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) BASE_DIR = os.path.dirname(PROJECT_ROOT) </code></pre> <p>because the <a href="https://docs.python.org/3...
5
2016-07-16T15:15:33Z
[ "python", "django", "os.path" ]
Python3 function to auto adjust decimal value
38,412,511
<p>Is there any function in python3 to auto adjust the decimal value to nearest integer? <strong>like 4.8 to 5 and 4.3 to 4</strong></p>
-4
2016-07-16T15:16:40Z
38,412,527
<p>You can use the built in <a href="https://docs.python.org/3/library/functions.html#round" rel="nofollow"><code>round</code></a> function. E.g.:</p> <pre><code>&gt;&gt;&gt; round(4.8) 5 &gt;&gt;&gt; round(4.3) 4 </code></pre>
0
2016-07-16T15:18:29Z
[ "python" ]
How to compare if two sklearn estimators are equals?
38,412,526
<p>I have two sklearn estimators and want to compare them:</p> <pre><code>import numpy as np from sklearn.tree import DecisionTreeClassifier X, y = np.random.random((100,2)), np.random.choice(2,100) dt1 = DecisionTreeClassifier() dt1.fit(X, y) dt2 = DecisionTreeClassifier() dt3 = sklearn.base.copy.deepcopy(dt1) <...
1
2016-07-16T15:18:19Z
38,427,515
<p>You will want to compare the params assigned to the classifier instance and the <code>.tree_.value</code> of the trained classifiers:</p> <pre><code># the trees have the same params def compare_trees(tree1, tree2): if hash(tree1.__dict__.values())==hash(tree2.__dict__.values()): # the trees have both be...
2
2016-07-18T01:35:55Z
[ "python", "scikit-learn" ]
how to find the index for a quantile
38,412,616
<p>I'm using a pandas series and I want to find the index value that represents the quantile.</p> <p>If I have:</p> <pre><code>np.random.seed(8) s = pd.Series(np.random.rand(6), ['a', 'b', 'c', 'd', 'e', 'f']) s a 0.873429 b 0.968541 c 0.869195 d 0.530856 e 0.232728 f 0.011399 dtype: float64 </code...
1
2016-07-16T15:30:19Z
38,412,623
<p>Use <code>sort_values</code>, reverse the order, find all that are less than or equal to the quantile calculated, then find the <code>idxmax</code>.</p> <pre><code>(s.sort_values()[::-1] &lt;= s.quantile(.5)).idxmax() </code></pre> <p>Or:</p> <pre><code>(s.sort_values(ascending=False) &lt;= s.quantile(.5)).idxmax...
1
2016-07-16T15:31:12Z
[ "python", "pandas" ]
How to match through new line in regular expression in python?
38,412,704
<p>This is my code. I want to ignore whatever that is within ~~. Even if it contains new lines, white spaces. So that I can ignore the comments.</p> <pre><code>for letter in code : tok += letter #adding each character to the token. if not is_str and (tok == " " or tok == "\n...
0
2016-07-16T15:38:37Z
38,412,766
<p>You can use the <a href="https://docs.python.org/2/library/re.html#re.DOTALL" rel="nofollow"><code>re.DOTALL</code></a> flag:</p> <blockquote> <p>Make the <code>'.'</code> special character match any character at all, including a <strong>newline</strong>; without this flag, <code>'.'</code> will match anything ...
2
2016-07-16T15:44:28Z
[ "python", "regex" ]
How to match through new line in regular expression in python?
38,412,704
<p>This is my code. I want to ignore whatever that is within ~~. Even if it contains new lines, white spaces. So that I can ignore the comments.</p> <pre><code>for letter in code : tok += letter #adding each character to the token. if not is_str and (tok == " " or tok == "\n...
0
2016-07-16T15:38:37Z
38,412,807
<p>If no other <code>~</code> is allowed within <code>~</code> strings, you can use: </p> <pre><code>r'~[^~]*~' </code></pre> <p>This will match any character but <code>~</code>.</p>
2
2016-07-16T15:48:20Z
[ "python", "regex" ]
Setting default values in wtforms form
38,412,715
<p>I am developing "add member details" and "edit member details" page. For "add member details" I am using wtf form shown below ( Stripped version )</p> <pre><code>class RegisterForm(Form): name = TextField( 'Name', validators=[DataRequired(), Length(min=3, max=25)] ) phone = TextField(...
0
2016-07-16T15:39:24Z
39,815,027
<p>When using <code>TextField</code> you should set <code>self.field.data</code> instead of <code>self.field.default</code>. And in this case you can accomplish your default values simply by passing the <code>member</code> in the default constructor of your form using the <code>obj</code> keyword. Here's what I mean:</...
0
2016-10-02T08:00:32Z
[ "python", "flask", "flask-wtforms" ]
python script not running with web.py
38,412,867
<p>I am new to Python and am trying to run a very simple Python script on a web page, using the tutorial on <a href="http://webpy.org/docs/0.3/tutorial" rel="nofollow">web.py</a>. When I installed web.py through the terminal it said it installed successfully, but when I try to run hello.py I get the following error me...
0
2016-07-16T15:54:42Z
38,413,000
<p>It looks like you have a file named <code>cgi.py</code> (/Users/swanstro/Desktop/cgi.py) that is conflicting with the Python standard library <code>cgi</code> module when you try to <code>import cgi</code>. Try renaming <code>cgi.py</code> to something else.</p>
1
2016-07-16T16:08:11Z
[ "python", "web.py" ]
How to send a list through TCP sockets - Python
38,412,887
<p>I want to send a list through TCP sockets but i can't get the exact list when receiving from the server-side . To be more specific say that i have this list:</p> <pre><code> y=[0,12,6,8,3,2,10] </code></pre> <p>Then, i send each item of the list like this:</p> <pre><code> for x in y : s.send(str(x)) </code></pr...
1
2016-07-16T15:56:29Z
38,413,006
<p>Use <code>pickle</code> or <code>json</code> to send list(or any other object for that matter) over sockets depending on the receiving side. You don't need <code>json</code> in this case as your receiving host is using python.</p> <pre><code>import pickle y=[0,12,6,8,3,2,10] data=pickle.dumps(y) s.send(y) </code><...
2
2016-07-16T16:09:04Z
[ "python", "list", "sockets", "tcp" ]
Convert TKinter Into an Exe File
38,413,050
<p>As I was creating a program using python (tkinter), I am unable to convert it into executable form (<code>.exe)</code>. </p> <p>My program uses several images, a bitmap icon and widgets. </p> <p>I tried <code>cx_freeze</code>. It compiles well and generates <code>exe</code> and other files but doesn't run. I tried...
0
2016-07-16T16:14:35Z
38,417,379
<p>I would highly recommend py2exe, I use it and it works flawlessly.</p> <p>This is a youtube video that explains how to use it. (i cant insert links as im on a mobile) </p> <p><a href="http://m.youtube.com/watch?v=VKQ1Ph81Gps" rel="nofollow">http://m.youtube.com/watch?v=VKQ1Ph81Gps</a></p> <p>Any errors just ask, ...
0
2016-07-17T02:33:28Z
[ "python", "tkinter" ]
not able to scrape data using selenium
38,413,072
<p>I used selenium to scrape data from angel.co but still getting no data from the site </p> <pre><code>from scrapy import Request,Spider import urllib from selenium import webdriver class AngelSpider(Spider): name = "angel" allowed_domains = ["angel.co"] AJAXCRAWL_ENABLED = True start_urls = ( ...
-1
2016-07-16T16:16:26Z
38,416,605
<p>The reason you see nothing printed is that you are using the <em>bare except clause</em> and basically <em>silently ignore all the exceptions raised</em>.</p> <p>The problem is in the way you find elements on the page, on this line, you are locating a single div element since you are using <code>find_element_by_xpa...
0
2016-07-16T23:38:58Z
[ "python", "selenium", "web-scraping", "scrapy" ]
Using a fresh initial migration to squash migrations
38,413,099
<p>I have an app with 35 migrations which take a while to run (for instance before tests), so I would like to squash them.</p> <p>The <code>squashmigrations</code> command reduces the operations from 99 to 88, but it is still far from optimal. This is probably due to the fact that I have multiple <code>RunPython</code...
1
2016-07-16T16:19:08Z
38,413,258
<p>If you don't have any important data in your test or production databases your can use fresh initial migration and it will be appropriate solution.</p> <p>I've used this trick a lot of times and it works for me.</p> <p>A few thoughts:</p> <ul> <li><p>sometimes, first you need to create migrations for one of your ...
1
2016-07-16T16:35:04Z
[ "python", "django", "migration", "squash" ]
Splitting numpy array at an index
38,413,117
<p>How do i split a numpy array at an index</p> <pre><code>import numpy as np a = np.random.random((3,3,3)) #What i want to achieve is 3 x (3x3) matrix </code></pre> <p>I would like to convert my (3,3,3) matrix into a list of (3x3) matrix</p> <p>I could do:</p> <pre><code>b = [] for i in a: b.append(i) </code><...
-3
2016-07-16T16:21:00Z
38,413,210
<p>A more pythonic way would be to use a list comprehension:</p> <pre><code>b = [x for x in a] </code></pre>
0
2016-07-16T16:30:42Z
[ "python", "numpy" ]
Splitting numpy array at an index
38,413,117
<p>How do i split a numpy array at an index</p> <pre><code>import numpy as np a = np.random.random((3,3,3)) #What i want to achieve is 3 x (3x3) matrix </code></pre> <p>I would like to convert my (3,3,3) matrix into a list of (3x3) matrix</p> <p>I could do:</p> <pre><code>b = [] for i in a: b.append(i) </code><...
-3
2016-07-16T16:21:00Z
38,413,216
<p>To be clear you want to convert a <em>3-dimensional</em> array into a list containing three <em>2-dimensional</em> arrays.</p> <p>You can directly assign the arrays, to new names (3 of them):</p> <pre><code>import numpy as np a = np.random.random((3,3,3)) b,c,d = a my_list = [b, c, d] </code></pre> <p>You have t...
3
2016-07-16T16:31:14Z
[ "python", "numpy" ]
Splitting numpy array at an index
38,413,117
<p>How do i split a numpy array at an index</p> <pre><code>import numpy as np a = np.random.random((3,3,3)) #What i want to achieve is 3 x (3x3) matrix </code></pre> <p>I would like to convert my (3,3,3) matrix into a list of (3x3) matrix</p> <p>I could do:</p> <pre><code>b = [] for i in a: b.append(i) </code><...
-3
2016-07-16T16:21:00Z
38,413,651
<p><code>list</code> can take any iterable so you could just use it:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; array = np.ones((3,3,3)) &gt;&gt;&gt; list_of_arrays = list(array) # convert it to a list &gt;&gt;&gt; list_of_arrays [array([[ 1., 1., 1.], [ 1., 1., 1.], [ 1., 1., ...
0
2016-07-16T17:16:19Z
[ "python", "numpy" ]
While loop movement in Zork-like python game
38,413,198
<p>I've been having trouble making movement that works in my python adventure game. When run the player can move to a different room but when trying to move back into a room the code stops.</p> <p>Here is the code:</p> <pre><code>A = False B = False Location = "A1" Attack = 0 Defence = 0 Speed = 0 Health = 20 Knives ...
-1
2016-07-16T16:29:33Z
38,413,253
<p>You should probably wrap the whole shebang in a while loop. Right now your code does the following...</p> <ol> <li>intro</li> <li>Run the room A1 logic</li> <li>Run the room B1 logic</li> <li>Exit</li> </ol> <p>After that last while loop is no longer true, there is no more code for it to go to (and no way for it ...
0
2016-07-16T16:34:51Z
[ "python", "adventure" ]
While loop movement in Zork-like python game
38,413,198
<p>I've been having trouble making movement that works in my python adventure game. When run the player can move to a different room but when trying to move back into a room the code stops.</p> <p>Here is the code:</p> <pre><code>A = False B = False Location = "A1" Attack = 0 Defence = 0 Speed = 0 Health = 20 Knives ...
-1
2016-07-16T16:29:33Z
38,413,313
<p>You should enclose a block of code where you taking and evaluating commands to the one additional big while loop. Something like:</p> <pre><code>while IsCharacterAlive: Command = input() ... </code></pre>
0
2016-07-16T16:40:40Z
[ "python", "adventure" ]
PHP passthru: unable to get full response from python script
38,413,320
<p>I'm trying to get data from Python script:</p> <pre><code>import pymorphy2 import json import sys morph = pymorphy2.MorphAnalyzer() butyavka = morph.parse(sys.argv[1])[0] for item in butyavka.lexeme: print(item.word) </code></pre> <p>PHP code:</p> <pre><code>&lt;?php chdir('C:\\Users\Michael-PC\AppData\Local...
1
2016-07-16T16:41:20Z
38,413,875
<p>This is obvious encoding problem (Russian letters become unreadable). So, try to set (i.e. change default) encoding in the PHP code, e.g. add to header usage of Unicode:</p> <pre><code> header('Content-Type: text/html; charset=utf-8'); </code></pre> <p>If <code>charset=utf-8</code> does not help, try <code>charset...
0
2016-07-16T17:40:15Z
[ "php", "python", "response", "passthru" ]
PyQt5 - pythonw.exe crash on handling clicked event
38,413,327
<p>I'm new to PyQt5 and I've got an error (pythonw.exe not working anymore) with the following code: <pre> import sys from PyQt5.QtWidgets import QWidget, QPushButton, QApplication from PyQt5.QtCore import QCoreApplication</p> <p>class Example(QWidget):</p> <pre><code>def __init__(self): super().__init__() se...
0
2016-07-16T16:41:39Z
38,416,177
<p>that's because when <code>q()</code> is inside the class it's expects a compulsory argument as the first parameter, this is usually called <code>self</code> and is passed for you implicitly by python when you're calling the method (<code>q()</code> not <code>q(self)</code>). just as you've done with the <code>initUI...
1
2016-07-16T22:19:43Z
[ "python", "python-3.x", "pyqt", "pyqt5" ]
How do you make python create lists
38,413,394
<p>Hi i dident know really how to write the title but i hope i can explain it better. Anyway im making a tool for Cable marking for my work. Its pretty simple the program asks what the Cable name is and how many parts it has. then it should print it out. This is how i want it to work. The program will ask the Cable nam...
-7
2016-07-16T16:47:58Z
38,660,372
<p>Here you can find more how to build a lists in Python: <a href="https://docs.python.org/3/tutorial/datastructures.html" rel="nofollow">https://docs.python.org/3/tutorial/datastructures.html</a></p> <p>Longer version:</p> <pre><code>cablename = input("What's the cable name?: ") parts = input("How many parts do your...
0
2016-07-29T13:39:00Z
[ "python", "python-3.x" ]
Selenium Page Source is Missing Elements
38,413,427
<p>I have a basic Selenium script that makes use of the chromedriver binary. I'm trying to display a page with recaptcha on it and then hang until the answer has been completed and then store that in a variable for future use. </p> <p>The roadblock I'm hitting is that I am unable to find the recaptcha element.</p> <p...
2
2016-07-16T16:51:23Z
38,420,812
<p>The element you are looking for (the <code>input</code>) is in an iframe. You'll need switch to the iframe before you can locate the element and interact with it.</p> <pre><code>import os from selenium import webdriver driver=webdriver.Chrome() try: driver.implicitly_wait(5) driver.get('http://patrickhlauk...
0
2016-07-17T11:42:20Z
[ "python", "selenium", "captcha", "recaptcha", "hidden" ]
Refer to created object that is assigned to a variable in Python
38,413,481
<p>I have a question regarding classes in Python. When I create a new object like this and add it to a variable:</p> <pre><code>user = User.objects.create(name='The Name') </code></pre> <p>Can I use that variable to refer to that newly created object? Like this:</p> <pre><code>print(user.name) </code></pre>
-4
2016-07-16T16:56:49Z
38,413,522
<p>Of course you can. Actually, it's the only way to use newly generated object - if you, for instance, did this:</p> <pre><code>User.objects.create(name='The Name') </code></pre> <p>you couldn't access that same object ever again. After that, if you do this:</p> <pre><code>print(User.objects.create(name='The Name')...
0
2016-07-16T17:01:54Z
[ "python", "django", "python-3.x" ]
module object has no attribute sound. keep getting this error do not know how to fix it?
38,413,525
<p>This is the start to my code in which the error occurs. </p> <p>The whole idea of the whole code was to play a beep noise when the user successfully logs in . (its a log in system. fairly basic; I am am running Python 3.3.3 and Pygame 1.9.1 ):</p> <pre><code>import pygame import time from os import path import os...
0
2016-07-16T17:02:03Z
38,515,697
<p>You need to initialize the pygame.mixer to actually play Sound objects. Search "pygame.mixer" in your browser and read the documentation, that should tell you all you need to know. If you don't need pygame and are using a Windows OS, python has a built-in module "winsound" for playing sound files on Windows systems....
0
2016-07-21T23:01:04Z
[ "python", "pygame" ]
Counting the number of occurrences of a specific value in a text file
38,413,553
<p>I have text file with 30 columns. and using python I want to count the number of rows based on the value in column 3. in fact how many times "cement" occurs in column 3. also columns do not have name (or header).</p> <pre><code>count = 0 with open('first_basic.txt') as infile: for line in infile: for ...
0
2016-07-16T17:04:56Z
38,413,678
<p>You are checking each character of 3rd column (word) of every line, to check if it equals cement:</p> <pre><code>'c' == 'cement' =&gt; False 'e' == 'cement' =&gt; False etc. </code></pre> <p>You should replace</p> <pre><code>for j in (line.split()[2]): if j == "cement": count += 1 </code></pre> <p>...
0
2016-07-16T17:19:19Z
[ "python", "text" ]
Counting the number of occurrences of a specific value in a text file
38,413,553
<p>I have text file with 30 columns. and using python I want to count the number of rows based on the value in column 3. in fact how many times "cement" occurs in column 3. also columns do not have name (or header).</p> <pre><code>count = 0 with open('first_basic.txt') as infile: for line in infile: for ...
0
2016-07-16T17:04:56Z
38,413,808
<p>Say you define a predicate function for your matches:</p> <pre><code>def match(line): return line.split()[2] == 'cement' </code></pre> <p>You can use this predicate with a <code>filter</code> and calculate the count of matching lines:</p> <pre><code>with open('first_basic.txt') as infile: print(len(list(...
0
2016-07-16T17:34:07Z
[ "python", "text" ]
Counting the number of occurrences of a specific value in a text file
38,413,553
<p>I have text file with 30 columns. and using python I want to count the number of rows based on the value in column 3. in fact how many times "cement" occurs in column 3. also columns do not have name (or header).</p> <pre><code>count = 0 with open('first_basic.txt') as infile: for line in infile: for ...
0
2016-07-16T17:04:56Z
38,414,280
<p>Arrays has the start position as 0 not as 1. So if you want to get the third element of <code>['DUMMY', 'DUMMY', 'CEMENT', 'NOT_CEMENT']</code> yoy have to take the <code>[2]</code> position. Because the <code>[3]</code> position is 'NOT_CEMENT'.</p> <p>And the seccond for, is taking letter by letter, not row by ro...
0
2016-07-16T18:28:01Z
[ "python", "text" ]
What is the difference between sklearn LabelEncoder and pd.get_dummies?
38,413,579
<p>I wanted to know the difference between sklearn LabelEncoder vs pandas get_dummies. Why would one choose LabelEncoder over get_dummies. What is the advantage of using one over another? Disadvantages? </p> <p>As far as I understand if I have a class A</p> <pre><code>ClassA = ["Apple", "Ball", "Cat"] encoder = [1, ...
3
2016-07-16T17:08:07Z
38,413,780
<p>These are just convenience functions falling naturally into the way these two libraries tend to do things, respectively. The first one "condenses" the information by changing things to integers, and the second one "expands" the dimensions allowing (possibly) more convenient access.</p> <hr> <p><a href="http://scik...
2
2016-07-16T17:30:52Z
[ "python", "pandas", "scikit-learn" ]
Multilinear maps in python using numpy
38,413,670
<p>In python I have a three dimensional array <code>T</code> with size <code>(n,n,n)</code>, and a 2-D array, with size <code>(n,k)</code>.</p> <p>In linear algebra, the multilinear map defined by <code>T</code> and applied to <code>W</code>, in code would be:</p> <pre><code>X3 = np.zeros((k,k,k)) for i in xrange...
2
2016-07-16T17:18:34Z
38,413,768
<p>Einstein summation convention? Use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.einsum.html" rel="nofollow"><code>np.einsum</code></a>!</p> <pre><code>X3 = np.einsum('lmh,li,mj,ht-&gt;ijt', M3, W, W, W) </code></pre> <p>EDIT:</p> <p>Out of curiosity, I just ran some benchmarks comparing <cod...
3
2016-07-16T17:29:34Z
[ "python", "arrays", "numpy" ]
Multilinear maps in python using numpy
38,413,670
<p>In python I have a three dimensional array <code>T</code> with size <code>(n,n,n)</code>, and a 2-D array, with size <code>(n,k)</code>.</p> <p>In linear algebra, the multilinear map defined by <code>T</code> and applied to <code>W</code>, in code would be:</p> <pre><code>X3 = np.zeros((k,k,k)) for i in xrange...
2
2016-07-16T17:18:34Z
38,413,871
<p>Here's an approach using a series of dot-products -</p> <pre><code># Get partial products and thus reach to final output p1 = np.tensordot(W,M3,axes=(0,0)) p2 = np.tensordot(p1,W,axes=(1,0)) X3out = np.tensordot(p2,W,axes=(1,0)) </code></pre>
3
2016-07-16T17:39:23Z
[ "python", "arrays", "numpy" ]
How can I get formatter string from a logging.formatter object in Python?
38,413,674
<p>Hi I want to make a logging manager gui. Basically I want to get the tree structure of loggers and show their level and formatter in a pyqt gui. How can I get the format string from a formatter associated a handler object?</p> <p>eg:</p> <pre><code>import logging _logger = logging.getLogger('myLogger') ch = loggi...
0
2016-07-16T17:19:01Z
38,413,697
<p><code>logging.Formatter</code> instances have a <code>_fmt</code> attribute:</p> <pre><code>&gt;&gt;&gt; _logger.handlers[0].formatter &lt;logging.Formatter object at 0x102c72fd0&gt; &gt;&gt;&gt; _logger.handlers[0].formatter._fmt '%(name)s:%(levelname)s: %(message)s' </code></pre> <p>You can always use <code>dir(...
2
2016-07-16T17:21:39Z
[ "python", "logging" ]
django queryset of two models
38,413,743
<p>I have two models:</p> <pre><code>class AuthUser(models.Model): id = models.IntegerField(primary_key=True) password = models.CharField(max_length=128) last_login = models.DateTimeField(blank=True, null=True) is_superuser = models.BooleanField() first_name = models.CharField(max_length=30) l...
0
2016-07-16T17:26:24Z
38,413,866
<p>Should add rename=True attribute to namedtuple call</p> <pre><code>namedtuple('Result', [col[0] for col in desc], rename=True) </code></pre>
0
2016-07-16T17:38:38Z
[ "python", "django" ]
django queryset of two models
38,413,743
<p>I have two models:</p> <pre><code>class AuthUser(models.Model): id = models.IntegerField(primary_key=True) password = models.CharField(max_length=128) last_login = models.DateTimeField(blank=True, null=True) is_superuser = models.BooleanField() first_name = models.CharField(max_length=30) l...
0
2016-07-16T17:26:24Z
38,413,898
<p>You should use <code>select_related</code> and <code>prefetch_related</code> for these purposes.<br> When you want get table from related model, use 'select_related': </p> <pre><code>SocialAuthUsersocialauth.objects.select_related('user') </code></pre> <p>When you want get all related tables, use 'prefetch_rela...
0
2016-07-16T17:42:58Z
[ "python", "django" ]
How to handle the score method in sklearn?
38,413,762
<p>This is an extension from my previous question <a href="http://stackoverflow.com/questions/38411854/how-to-convert-a-groupby-mean-into-a-callable-object">How to convert a groupby().mean() into a callable object?</a></p> <p>I am grateful for the help that I received from this forum and Alberto Garcia-Raboso in parti...
1
2016-07-16T17:28:17Z
38,413,958
<p>There are two problems in your code...the first one is with the <code>score</code> method. </p> <p>The function definition of score is like -</p> <blockquote> <p>score(X, y[, sample_weight])</p> </blockquote> <p>And just to mention <code>score</code> calls <code>predict</code> itself in the backend.</p> <p>whe...
1
2016-07-16T17:51:15Z
[ "python", "scikit-learn" ]
Logging in Scrapy
38,413,829
<p>I am having trouble with logging in scrapy, and most of what I can find is out of date.</p> <p>I have set <code>LOG_FILE="log.txt"</code> in the <code>settings.py</code> file and from the documentation, this should work:</p> <blockquote> <p>Scrapy provides a logger within each Spider instance, that can be access...
0
2016-07-16T17:35:52Z
38,416,110
<p>It seems that you're not calling your <code>parse_page</code> method at any time. Try to commenting your <code>parse</code> method and you're going to receive a <code>NotImplementedError</code> because you're starting it and you're saying it 'do nothing'.</p> <p>Maybe if you implement your <code>parse_page</code> m...
0
2016-07-16T22:10:28Z
[ "python", "logging", "documentation", "scrapy" ]
Logging in Scrapy
38,413,829
<p>I am having trouble with logging in scrapy, and most of what I can find is out of date.</p> <p>I have set <code>LOG_FILE="log.txt"</code> in the <code>settings.py</code> file and from the documentation, this should work:</p> <blockquote> <p>Scrapy provides a logger within each Spider instance, that can be access...
0
2016-07-16T17:35:52Z
38,417,258
<p>For logging I just put this on the spider class:</p> <pre><code>class SomeSpider(scrapy.Spider): configure_logging(install_root_handler=False) logging.basicConfig( filename='log.txt', format='%(levelname)s: %(message)s', level=logging.INFO ) </code></pre> <p>This will put all sc...
1
2016-07-17T02:02:54Z
[ "python", "logging", "documentation", "scrapy" ]
Do I copy the Flask folder or install afresh?
38,413,837
<p>It's my first time with Flask. I installed Flask by following this tutorial <a href="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world" rel="nofollow">http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world</a>. However, I want to use another tutorial simultaneousl...
1
2016-07-16T17:36:48Z
38,413,908
<p>You'll need to create a new virtual environment and <code>pip install</code> the required modules again.</p> <p>Just copying the old virtualenv folder won't work, since virtualenv hardcodes some absolute paths that won't work in the new location.</p>
0
2016-07-16T17:45:08Z
[ "python", "virtualenv" ]
numpy einsum: nested dot products
38,413,913
<p>I have two <code>n</code>-by-<code>k</code>-by-<code>3</code> arrays <code>a</code> and <code>b</code>, e.g.,</p> <pre><code>import numpy as np a = np.array([ [ [1, 2, 3], [3, 4, 5] ], [ [4, 2, 4], [1, 4, 5] ] ]) b = np.array([ [ [3, 1, 5], ...
1
2016-07-16T17:45:25Z
38,413,931
<p>You are loosing the third axis on those two <code>3D</code> input arrays with that sum-reduction, while keeping the first two axes aligned. Thus, with <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.einsum.html" rel="nofollow"><code>np.einsum</code></a>, we would have the first two strings identic...
3
2016-07-16T17:47:39Z
[ "python", "numpy", "numpy-einsum" ]
opening a file for reading content
38,414,099
<p>I am following Python tutorials (<a href="https://docs.python.org/3/tutorial/inputoutput.html" rel="nofollow">here</a>) on <strong>files</strong>.</p> <p>I have a simple text file, containing 3 lines. According to the tutorial page, putting this simple snippet in a file and executing the script should display the c...
-3
2016-07-16T18:07:16Z
38,415,169
<p>Here is a simple example:</p> <pre class="lang-py prettyprint-override"><code>fp = open(r"d:\test.txt") print ( fp.read() ) fp.close() </code></pre>
2
2016-07-16T20:08:36Z
[ "python", "file" ]
Django. Proxy model with limited set of fields
38,414,153
<p>Main moment - database scheme is not designed from scratch. It's inherited from legacy system and must be left as is at the moment, because it's also shared with some external systems. So we have kind of: </p> <pre><code>class A(models.Model): """ List of 110 fields """ field_1 = models.CharField()...
1
2016-07-16T18:13:37Z
38,417,004
<p>According to the <a href="https://docs.djangoproject.com/en/1.9/topics/db/models/#proxy-models" rel="nofollow">docs</a>, proxy model isn't what you are looking for</p> <blockquote> <p>So, the general rules are:</p> <p>If you are mirroring an existing model or database table and don’t want all the origina...
1
2016-07-17T01:00:56Z
[ "python", "mysql", "django", "django-models" ]
Python assert doesn't work when raised in class instance
38,414,292
<p><code>assert</code> doesn't raise an exception when called in an instance of a class:</p> <pre><code>class TestCaseTest(TestCase): ... def testFailedResutFormatted(self): ... assert False # This doesn't work at all TestCaseTest("testFailedResutFormatted").run() assert False # But this...
0
2016-07-16T18:28:54Z
38,414,304
<p>The <code>assert False</code> works <em>just fine</em>, but the <code>AssertionError</code> is caught by the <code>TestCase.run()</code> method, to be collected later.</p> <p>You didn't pass in a <code>TestResult</code> instance, so in Python 3 the <code>TestCase.run()</code> function returns a <em>new</em> result ...
0
2016-07-16T18:30:03Z
[ "python", "tdd", "assert" ]
Django : extract image from database and display in template
38,414,361
<p>I am beginner in django so struck at a thing, that i can't find out how to do. I want to display an image that is stored in database to my template. Images are uploaded to folder 'static/img' .</p> <p>this is my database:</p> <pre><code>class Post(models.Model): author = models.ForeignKey('auth.User') title = mode...
0
2016-07-16T18:36:02Z
38,414,618
<p>Okay, so firstly it will be great if you can <strong>specify</strong> the exact part or <strong>error</strong> you are stuck at.</p> <p>Secondly, if your only purpose is to <strong>display</strong> the images depending on some condition and <strong>never</strong> ever is your <strong>Web-app user</strong> going to ...
0
2016-07-16T19:04:31Z
[ "python", "django", "web", "pycharm" ]
Django : extract image from database and display in template
38,414,361
<p>I am beginner in django so struck at a thing, that i can't find out how to do. I want to display an image that is stored in database to my template. Images are uploaded to folder 'static/img' .</p> <p>this is my database:</p> <pre><code>class Post(models.Model): author = models.ForeignKey('auth.User') title = mode...
0
2016-07-16T18:36:02Z
38,415,856
<pre><code>{% for post in posts %} &lt;div class="panel panel-lg panel-custom"&gt; &lt;div class="panel-heading post-heading1"&gt; &lt;img src="/{{ post.img_brief.url }}"&gt; &lt;/div&gt; .... &lt;/div&gt; {% endfor %} </code></pre> <p>As you don't use the <code>{% static "" %}</code> you need to add the <code...
0
2016-07-16T21:35:19Z
[ "python", "django", "web", "pycharm" ]
Django : extract image from database and display in template
38,414,361
<p>I am beginner in django so struck at a thing, that i can't find out how to do. I want to display an image that is stored in database to my template. Images are uploaded to folder 'static/img' .</p> <p>this is my database:</p> <pre><code>class Post(models.Model): author = models.ForeignKey('auth.User') title = mode...
0
2016-07-16T18:36:02Z
38,421,165
<p>Only thing that i was missing that MEDIA_URL and MEDIA_ROOT. changed these to :-</p> <pre><code>MEDIA_ROOT='&lt;the full path to your media folder&gt;' (i.e: '/home/ike/project/media/') MEDIA_URL='/media/' </code></pre> <p>and also updated url.py file :-</p> <pre><code>from django.conf.urls.static import static ...
0
2016-07-17T12:27:06Z
[ "python", "django", "web", "pycharm" ]
Django : extract image from database and display in template
38,414,361
<p>I am beginner in django so struck at a thing, that i can't find out how to do. I want to display an image that is stored in database to my template. Images are uploaded to folder 'static/img' .</p> <p>this is my database:</p> <pre><code>class Post(models.Model): author = models.ForeignKey('auth.User') title = mode...
0
2016-07-16T18:36:02Z
38,422,930
<p><strong>Option-1:</strong> No need to put .url after post.img_breif.</p> <pre><code> {% for post in posts %} &lt;div class="panel panel-lg panel-custom"&gt; &lt;div class="panel-heading post-heading1"&gt; &lt;img src="{{ post.img_brief}}"&gt; &lt;/div&gt; .... ...
0
2016-07-17T15:35:35Z
[ "python", "django", "web", "pycharm" ]
How to autogenerate Getters from a json file in Pycharm
38,414,404
<p>I have really big <code>config.json</code> file that I am trying to read and generate getters from in <code>pycharm IDE</code>.</p> <p>Sample <code>config.json</code> looks like this (<code>. . .</code> indicates lot of similar items) : </p> <pre><code>{ "key1" : "value1", "key2" : "value2", . . . "key...
-1
2016-07-16T18:39:52Z
38,414,563
<p>Have you considered implementing <code>__getitem__</code> instead? <code>__getitem__</code> is the magic method that lets you use the <code>[]</code> operator, which I think is a much more sustainable approach to what you're trying to do, because it doesn't require you to change your source code every time the confi...
1
2016-07-16T18:57:37Z
[ "python", "json", "python-2.7", "pycharm", "getter" ]
Matplotlib boxplot visual styles: `whiskerprops` does not work
38,414,434
<p>In the documentation of matplotlib's <code>boxplot</code> we can read: </p> <blockquote> <p>whiskerprops : dict or None (default) If provided, will set the plotting style of the whiskers</p> </blockquote> <p>Ok, so I passed a dict to set some visual styles on the whiskers:</p> <pre><code>whiskerprops =...
1
2016-07-16T18:42:21Z
38,414,516
<p>When you pass a dict to set any of these properties, matplotlib will add elements to your dictionary, avoiding only to overwrite the existing keys. But it is not aware that there are abbreviations for some of the properties: if you have <code>ls</code>, it will add <code>'linestyle': '--'</code>, if you have <code>l...
2
2016-07-16T18:51:54Z
[ "python", "matplotlib", "boxplot" ]
Android Errno -2
38,414,462
<p>I have a script that I want to run on my Android phone using the ADB and SL4A. This script worked fine on my Windows machine but when I've tried it from Linux I get the following error:</p> <pre><code>Traceback (most recent call last): File "test_device.py", line 12, in &lt;module&gt; droid = android.An...
-1
2016-07-16T18:45:09Z
38,445,498
<p>The issue was in how I set up the environment. Normally, on Windows I would do:</p> <pre><code>set AP_PORT = 99999 adb forward tcp:99999 tcp:99999 </code></pre> <p>and then I would be able to use the SL4A. However, because the system was Linux, not Windows, I had to do this:</p> <pre><code>export AP_PORT=99999 ad...
0
2016-07-18T20:29:35Z
[ "android", "python", "adb", "sl4a" ]
How do function arguments work in python?
38,414,472
<p>I started coding 2 days back and just for some practice i decided to make a calculator. It keeps giving me errors saying num1 is not defined.</p> <pre><code>#data collection def a1(num1, op, num2) : num1 = int[input("enter the first number: ")] op = input("enter the operation: ") num2 = int[input("enter the sec...
0
2016-07-16T18:46:23Z
38,414,500
<p>Function arguments are positional variables. You need to call the function and pass it the variables in order for it to work.</p> <p>Variables passed to a function are local, only usable in the function. You want to either change a global variable or return from that function.</p> <p>What your code is doing is pas...
1
2016-07-16T18:50:19Z
[ "python", "function", "arguments" ]
How do function arguments work in python?
38,414,472
<p>I started coding 2 days back and just for some practice i decided to make a calculator. It keeps giving me errors saying num1 is not defined.</p> <pre><code>#data collection def a1(num1, op, num2) : num1 = int[input("enter the first number: ")] op = input("enter the operation: ") num2 = int[input("enter the sec...
0
2016-07-16T18:46:23Z
38,414,544
<p>Here's a way to fix up your existing code:</p> <pre><code>#data collection def a1(): num1 = int(input("enter the first number: ")) op = input("enter the operation: ") num2 = int(input("enter the second number: ")) return num1, op, num2 #running the operations def a2(num1, op, num2): if (op == ...
0
2016-07-16T18:55:13Z
[ "python", "function", "arguments" ]
How do function arguments work in python?
38,414,472
<p>I started coding 2 days back and just for some practice i decided to make a calculator. It keeps giving me errors saying num1 is not defined.</p> <pre><code>#data collection def a1(num1, op, num2) : num1 = int[input("enter the first number: ")] op = input("enter the operation: ") num2 = int[input("enter the sec...
0
2016-07-16T18:46:23Z
38,414,556
<p>The last two lines: </p> <pre><code>a1(num1, op, num2) a2() </code></pre> <p>are the "main" body of your program. Before that are two function definitions. When you invoke <code>a1</code>, what is the value of <code>num1</code>? Indeed, what is its type? Answer: it's a name with no value associated with it. T...
0
2016-07-16T18:56:32Z
[ "python", "function", "arguments" ]
Kill a subprocess after a time interval with Python in OS X
38,414,474
<p>I wrote a python script to initiate a subprocess and then want to kill this after an interval of n seconds . When I use time.sleep(n) it doesn't kills the process but when I remove this sleep part then it kills by using os.kill(proc.pid, signal.SIGKILL) . Can somebody please help me in this ? </p> <pre><code> im...
-1
2016-07-16T18:46:28Z
38,414,604
<pre><code>import time,subprocess,os,signal proc = subprocess.Popen(["notepad.exe","data.out"]) timeLeft = 5 while timeLeft &gt; 0: print('Time left is ' + str(timeLeft)) time.sleep(1) timeLeft = timeLeft - 1 pass os.kill(proc.pid, signal.SIGTERM) </code></pre> <p>If you rearrange you code like this, i...
0
2016-07-16T19:03:03Z
[ "python", "osx", "subprocess" ]
Kill a subprocess after a time interval with Python in OS X
38,414,474
<p>I wrote a python script to initiate a subprocess and then want to kill this after an interval of n seconds . When I use time.sleep(n) it doesn't kills the process but when I remove this sleep part then it kills by using os.kill(proc.pid, signal.SIGKILL) . Can somebody please help me in this ? </p> <pre><code> im...
-1
2016-07-16T18:46:28Z
38,414,617
<p>Just kill it with <code>sys.exit(0).</code></p>
1
2016-07-16T19:04:24Z
[ "python", "osx", "subprocess" ]
Second Window is blank after a button was clicked in Main Window
38,414,483
<p>I have two python file, the first one is contain the mainWindow, second python file contains another Window. I manage to make the second window appear but the window is blank after it appear. Here is the screen shot of the error. <a href="http://i.stack.imgur.com/zLWqi.jpg" rel="nofollow"><img src="http://i.stack.im...
0
2016-07-16T18:47:28Z
38,415,678
<p>1) I think there are some <code>root</code> that should be <code>master</code> in the <code>__init__</code> function of <code>TracingInterface</code>. </p> <p>2) The master you pass to <code>ConfigureUAinterface</code> is not a window but a <code>TracingInterface</code> which is a frame and doesn't have <code>minsi...
1
2016-07-16T21:12:37Z
[ "python", "tkinter", "interface", "window", "toplevel" ]
Python - file.write() Throws Error With Variables
38,414,520
<p>In my game there are Rounds (Round 1, 2 etc...). I want to store them inside of a text file to be saved.</p> <p>To do this I use the following code:</p> <pre><code>global roundNumber roundNumber += 1 file = open('file/roundNumber.txt', 'w') file.write(roundNumber) </code></pre> <p>However, I get an error for <co...
-1
2016-07-16T18:52:46Z
38,414,543
<p>You will have to store a str(roundNumber) and then after reading it convert back to int(). Text files are for holding text - strings.</p>
1
2016-07-16T18:55:12Z
[ "python" ]
Python - file.write() Throws Error With Variables
38,414,520
<p>In my game there are Rounds (Round 1, 2 etc...). I want to store them inside of a text file to be saved.</p> <p>To do this I use the following code:</p> <pre><code>global roundNumber roundNumber += 1 file = open('file/roundNumber.txt', 'w') file.write(roundNumber) </code></pre> <p>However, I get an error for <co...
-1
2016-07-16T18:52:46Z
38,414,546
<p>Anyway it will be stored as text - use</p> <pre><code> file.write(str(roundNumber)) </code></pre> <p>and when reading parse to the int</p> <pre><code> newNumber = int(readNumber) </code></pre>
1
2016-07-16T18:55:29Z
[ "python" ]
How do I attach a different database to each user in Django?
38,414,696
<p>I am building a calendar and appointment website in Django. I want each user to have their own database. I want to know firstly how do I create and save user details and then how do I attach each user to their database?? Thanks in advance.</p>
0
2016-07-16T19:14:52Z
38,414,812
<ul> <li><p>To attach multiple databases/users, you just need to specify them in the settings.py, see <a href="https://docs.djangoproject.com/en/1.9/topics/db/multi-db/" rel="nofollow">https://docs.djangoproject.com/en/1.9/topics/db/multi-db/</a>.</p></li> <li><p>If you want to create initial data for each users and fo...
0
2016-07-16T19:26:29Z
[ "python", "html", "django", "python-2.7" ]
Handling Unicode in python 2.7 when saving string to a file
38,414,724
<p>Dealing with Unicode is my only challenge programming with Python, I had many problems in my past project and I always brute forced my way out testing different encoding till something works (if there is any tutorial for beginners it will be very handy).</p> <p>For example I have this code:</p> <pre><code># -*- co...
0
2016-07-16T19:17:29Z
38,414,900
<p>The coding line just tells the Python interpreter how <em>it</em> should interpret the bytes. That doesn't mean the script actually <em>contains</em> UTF-8-encoded text. In fact, the error message suggests that the file was saved as ISO-8859-encoded (Latin-1) text. 0xc5 is the Latin-1 encoding for Å; 0xc3 0x85 is t...
2
2016-07-16T19:36:11Z
[ "python", "python-2.7", "unicode" ]
Recording sound using python language
38,414,742
<p>I want to create an audio microphone recorder in Python but I don't know how to do it. Will I need a library. Which one ? I am on a Mac (OS X 10.11)</p>
0
2016-07-16T19:20:09Z
38,414,844
<p>Python-sounddevice looks good :</p> <p><a href="http://python-sounddevice.readthedocs.io/en/0.3.3/" rel="nofollow">http://python-sounddevice.readthedocs.io/en/0.3.3/</a></p> <p>you have a bunch of parameters to control duration and/or wait... See the doc. I'm testing it right now. </p> <p>Edit : For your install...
0
2016-07-16T19:30:34Z
[ "python" ]
Django-tables2 - can't I use [A('argument')] inside the "text" parameter?
38,414,868
<p>I'm trying to make this table with a clickable field which changes the boolean for the entry to its opposite value. It works, but I want an alternative text as "False" or "True" does not look nice, and the users are mainly Norwegian. </p> <pre><code>def bool_to_norwegian(boolean): if boolean: return "Ja...
0
2016-07-16T19:32:38Z
38,417,882
<p>The <code>text</code> argument expects a callable that accepts a record, and returns a text value. You are passing it a list (which it will just ignore), and your function is expecting a boolean instead of a record. There is also no need for using accessors here. </p> <p>Something like this should work:</p> <pre><...
0
2016-07-17T04:22:15Z
[ "python", "django", "django-tables2" ]
int(x)- Is x numeric/non-numeric string?
38,414,888
<p>In the code below, <code>int(x)</code> throws an exception. I understand that <code>x</code> should be a string but -numeric or non-numeric string?</p> <pre><code>def temp_convert(var): try: return int(var) except ValueError, Argument: print "The argument does not contain numbers\n", Argument # C...
0
2016-07-16T19:34:56Z
38,415,301
<p>The string you supply as the function argument has to be representable as an integer. What would you consider the numerical representation of <code>"xyz"</code> to be?</p> <p>If you pass the function string representations of numbers, positive or negative, then you won't trigger the exception.</p> <p>When numbers ...
1
2016-07-16T20:24:56Z
[ "python", "type-conversion" ]
can't add properties to object returned from mongo in python
38,414,911
<p>I'm getting data from Mongo with Python. I move all the documents from the cursor into an array. Then I process the documents and try to add some new properties to the object / dictionary, but it says KeyError. I've seen this behavior in Nodejs when trying to modify objects returned by mongo and the solution there i...
0
2016-07-16T19:38:00Z
39,808,998
<p>KeyError's are not raised when setting new keys on a dict. Meaning you are doing something wrong.</p> <p>See when a KeyError is raised: <a href="http://stackoverflow.com/a/10116540/4273834">http://stackoverflow.com/a/10116540/4273834</a></p> <p>Just to recap: A KeyError is not raised if you try to SET a key but ra...
0
2016-10-01T16:34:51Z
[ "python", "mongodb", "pymongo" ]
Converting a Coordinate Value to a fixed64 protobuf object
38,414,918
<p>I need to convert a Coordinate value, which is a float, to a protobuf object to send to a server Problem is i need to convert it to a fixed64 object, which is a 64bit long and javascript doesn't support numbers this long.</p> <p>I am using <a href="https://github.com/mafintosh/protocol-buffers" rel="nofollow">this<...
0
2016-07-16T19:39:25Z
38,415,742
<p>As you mentioned, JS doesn't support 64-bit integers, so you won't be able to get the <em>same</em> output. The closest you can get would be two 32-bit integers that represent the same 64-bit integer, which may or may not work depending on what kind of input your Protobuf library is expecting.</p> <p>I'd suggest to...
1
2016-07-16T21:20:19Z
[ "javascript", "python", "node.js", "protocol-buffers" ]
Pyglet HUD text location / scaling
38,414,995
<h1>Background</h1> <p>I have a game with a HUD I based on <a href="http://tartley.com/?p=250">this example</a></p> <p>I have a pyglet application with two <code>gluOrtho2D</code> views. One which is mapped 1/1 to the screen, which acts as my HUD. One which is mapped to the game world, so it scales.</p> <h1>Problem<...
6
2016-07-16T19:49:56Z
38,521,442
<p>I am not a python programmer but I think i understand enough of the opengl part of the problem so I will attempt to answer. Please forgive my syntax.</p> <p>I believe you want a 2D position that represents a 3D point in your scene. You want to know the position in 2D so you can draw some text there. You have the mo...
4
2016-07-22T08:13:43Z
[ "python", "opengl", "pyglet" ]
A neat way to create an infinite cyclic generator?
38,415,014
<p>I want a generator that cycle infinitely through a list of values.</p> <p>Here is my solution, but I may be missing a more obvious one.</p> <p>The ingredients: a generator function that flatten an infinitely nested list, and a list appendant to itself</p> <pre><code>def ge(x): for it in x: if isinstan...
2
2016-07-16T19:51:41Z
38,415,018
<p>You can use <a href="https://docs.python.org/2.7/library/itertools.html#itertools.cycle"><code>itertools.cycle</code></a> to achieve the same result</p> <blockquote> <p>Make an iterator returning elements from the iterable and saving a copy of each. When the iterable is exhausted, return elements from the <st...
7
2016-07-16T19:52:34Z
[ "python", "python-3.x" ]
A neat way to create an infinite cyclic generator?
38,415,014
<p>I want a generator that cycle infinitely through a list of values.</p> <p>Here is my solution, but I may be missing a more obvious one.</p> <p>The ingredients: a generator function that flatten an infinitely nested list, and a list appendant to itself</p> <pre><code>def ge(x): for it in x: if isinstan...
2
2016-07-16T19:51:41Z
38,415,385
<p>It must be the hour :-). The one obvious way I realized after posting:</p> <pre><code>def infinitecyclegenerator(l): while True: for it in l: yield it </code></pre> <p>Sorry for missing the obvious.</p>
0
2016-07-16T20:34:18Z
[ "python", "python-3.x" ]
TypeError: Unsupported only when writing to file not when printing
38,415,029
<p>I've written some code (below) which worked fine until i added a statement to write it to a file. </p> <p>The error i get is TypeError: unsupported operand type(s) for %: 'NoneType' and 'float' which occurs on line 43.</p> <p>What is confusing me is the fact that it doesn't throw this error when i use the exact sa...
0
2016-07-16T19:53:54Z
38,415,064
<p>I think you need to escape the <code>%</code> sign here by making it a double-%:</p> <pre><code>target.write("The bill was %r before the tip \n You tipped %r%% \n The total bill was %r \n Split between %r people it was %r each") % (billAmount, tipAmount*100, billAndTip, peopleAmount, billDivided) </code></pre> <p>...
1
2016-07-16T19:58:04Z
[ "python", "typeerror", "writefile" ]
TypeError: Unsupported only when writing to file not when printing
38,415,029
<p>I've written some code (below) which worked fine until i added a statement to write it to a file. </p> <p>The error i get is TypeError: unsupported operand type(s) for %: 'NoneType' and 'float' which occurs on line 43.</p> <p>What is confusing me is the fact that it doesn't throw this error when i use the exact sa...
0
2016-07-16T19:53:54Z
38,415,077
<pre><code>target.write("The bill was %r before the tip") % (billAmount) </code></pre> <p>Here you are using the <code>%</code> operator with the result of <code>target.write(...)</code>. <code>target.write(...)</code> returns <code>None</code> which is why the error is saying what it says.</p> <p>Presumably you want...
0
2016-07-16T19:59:08Z
[ "python", "typeerror", "writefile" ]
Add/subtract dataframes with different column labels
38,415,048
<p>I'm trying to add/subtract two dataframes with different column labels. Is it possible to do this without renaming the columns to align them? I would like to keep the original labels.</p>
2
2016-07-16T19:56:24Z
38,415,477
<p>Consider dataframes <code>A</code> and <code>B</code></p> <pre><code>A = pd.DataFrame([[1, 2], [3, 4]], ['a', 'b'], ['A', 'B']) B = pd.DataFrame([[1, 2], [3, 4]], ['c', 'd'], ['C', 'D']) </code></pre> <hr> <pre><code>A </code></pre> <p><a href="http://i.stack.imgur.com/7Jitu.png" rel="nofollow"><img src="http://...
1
2016-07-16T20:45:19Z
[ "python", "pandas" ]
pandas - vectorized code slower than for loop
38,415,166
<p>I have two functions that give the same result, one vectorized and one with a "for" loop. Suprisingly the for loop is faster than the vectorized version. Any idea why is it so ? </p> <pre><code>def loop_for(df): gpd = df.groupby([pd.TimeGrouper(freq="QS-JAN"), 'CD_PDP']) result = [] for (quarter, uni...
0
2016-07-16T20:08:25Z
38,417,254
<p>Doing <code>.nunique()</code> on a <code>SeriesGroupBy</code> object does take advantage of vectorization:</p> <pre><code>grouped = df.groupby([pd.TimeGrouper(freq="QS-JAN"), 'CD_PDP']) b = df.groupby('a').agg({'MAT_RH': 'nunique', 'MAT_RHPI': 'nunique'}) b = b.rename(columns={'MAT_RH': 'nb_mat_rh', 'MAT_RHPI': 'n...
1
2016-07-17T02:01:22Z
[ "python", "pandas" ]
AngularJS not working with Flask
38,415,171
<p>I have this <a href="http://codehandbook.org/angularjs-not-working-in-python-flask-web-app/" rel="nofollow">simple app</a>:</p> <pre><code>&lt;!doctype html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt; &lt;title&gt;work...
-1
2016-07-16T20:08:39Z
38,415,266
<p>To achieve your expected result, use below option to bind your scope value</p> <p>{a message a} Start tag and end tag should be '{a' and 'a}' respectively without {{}} inside them</p> <p>HTML:</p> <pre><code>&lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;meta http-equiv="X-UA-Compat...
1
2016-07-16T20:20:31Z
[ "python", "angularjs" ]
Finding which parts of a string does not match the regex
38,415,176
<p>I have written a program which checks email addresses entered by a user against a regex. When a user enters an incorrect email that does not match the regex, a print statement is executed telling the user that the email is incorrect. What i want to do is be able to tell them why the email is incorrect, in other word...
-3
2016-07-16T20:09:35Z
38,415,238
<p>I would recommend using an existing library for this. Perhaps you can use this instead of recreating the wheel:</p> <p><a href="https://pypi.python.org/pypi/validate_email" rel="nofollow">https://pypi.python.org/pypi/validate_email</a></p> <p>or this:</p> <p><a href="https://github.com/JoshData/python-email-valid...
0
2016-07-16T20:17:12Z
[ "python", "regex" ]
Finding which parts of a string does not match the regex
38,415,176
<p>I have written a program which checks email addresses entered by a user against a regex. When a user enters an incorrect email that does not match the regex, a print statement is executed telling the user that the email is incorrect. What i want to do is be able to tell them why the email is incorrect, in other word...
-3
2016-07-16T20:09:35Z
38,417,365
<h1>Foreward</h1> <p>There are a lot of rules that describe a valid email address. My proposed solution here is only test the rules you described in your original question <code>^[A-Za-z0-9]{5,25}@{1}[A-Za-z]{5,15}[.]{1}[A-Za-z {3,10}$</code></p> <p>I recommend making the following changes to your base expression:</p...
0
2016-07-17T02:30:11Z
[ "python", "regex" ]
Daphne server cannot connect with websockets on HTTPS
38,415,209
<p>I'm deploying a Django project on the Openshift cloud. This project uses <a href="http://channels.readthedocs.io/en/latest/index.html" rel="nofollow">channels</a> and Websockets to make it work asynchronously. The problem is that I can't successfully connect websockets from the browser to the Daphne Server I got run...
1
2016-07-16T20:13:17Z
38,516,482
<p>I managed to make it work. The problem seems related to a port forwarding thing that made me impossible to connect websockets through the apache server on openshift cloud to my daphne server.</p> <p>To solve this problem:</p> <p>1) With the default cartridge for django projects I was unable to modify apache conf f...
2
2016-07-22T00:42:15Z
[ "python", "django", "websocket", "openshift", "django-channels" ]
import widget in kivy file
38,415,217
<p>I created some custom widget.</p> <pre><code>from kivy.uix.widget import Widget from kivy.lang import Builder class ExampleWidget(Widget): Builder.load_file("kv/example.kv") </code></pre> <p>kv/example.kv</p> <pre><code>#:kivy 1.9.1 &lt;ExampleWidget&gt;: Label: text: Example </code></pre> <p...
1
2016-07-16T20:14:00Z
38,415,999
<p>You can import it using following syntax (assuming that <code>ExampleWidget</code> is defined in <code>example.py</code> file and you have <code>__init__.py</code> in your directory):</p> <pre><code>#: import ExampleWidget example.ExampleWidget &lt;SecondWidget&gt;: ExampleWidget: </code></pre> <p>Described i...
2
2016-07-16T21:53:52Z
[ "android", "python", "kivy", "kivy-language" ]
Django Error with custom login model
38,415,256
<p>Hello I trying to make django custom user model but I am getting the following error. - </p> <p>ERRORS:</p> <blockquote> <p>auth.User.groups: (fields.E304) Reverse accessor for 'User.groups' clashes with reverse accessor for 'Freelancer.groups'. HINT: Add or change a related_name argument to the defi...
0
2016-07-16T20:19:33Z
38,415,476
<p>You need to set the <code>AUTH_USER_MODEL</code> setting to point to your Freelancer class, so Django knows not to load the default User model.</p> <p>Also it makes no sense for Freelancer to have a OneToOne to User; it is a <em>replacement</em> for that model.</p>
0
2016-07-16T20:45:14Z
[ "python", "django" ]
python script for searching jpeg files in multiple folders
38,415,287
<p>I have a directory which contains multiple directories within it. The sub directories each have jpeg images in them. Can you help me to find a way to extract those images and copy them to a single folder using python.</p> <p>Thanks in advance</p>
-2
2016-07-16T20:23:01Z
38,415,450
<p>you could do for example : </p> <pre><code>import glob, os from shutil import copyfile os.chdir("yourdirectory") for file in glob.glob("*.jpeg"): copyfile(file, "destinationdirectory/"+file) </code></pre>
0
2016-07-16T20:42:00Z
[ "python", "jpeg" ]
Twisted ExtendSelected Reactor error
38,415,289
<p>I pulled the following code from the txtnettools package on git hub the code is largely incomplete so I am trying to figure out how to actually make the code send packets I need to call I think the sendEcho() method as a reactor so I added the appropriate line. </p> <pre><code>from random import randint import sock...
2
2016-07-16T20:23:11Z
38,448,455
<p>The answer was totally in how I was accessing the Pinger class. The corrected line of code would be </p> <pre><code> reactor.callWhenRunning(Pinger().sendEcho) </code></pre> <p>Instead of:</p> <pre><code> reactor.Pinger.sendEcho() </code></pre> <p>You need to specify to the reactor how when and how to defer itse...
1
2016-07-19T02:02:07Z
[ "python", "twisted", "reactor" ]
Python Tkinter Text Scroll Past Last Line
38,415,308
<p>In programs like Sublime Text, users are able to scroll past the last line of their text. Like so:<a href="http://i.stack.imgur.com/ZxgP7.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZxgP7.png" alt="enter image description here"></a></p> <p>I was wondering if there was any way this could be achieved with ...
1
2016-07-16T20:25:47Z
38,415,788
<p>There is no way, other than to add a bunch of blank lines at the end.</p>
1
2016-07-16T21:26:44Z
[ "python", "text", "scroll", "tkinter" ]
Pandas Rolling Window - datetime64[ns] are not implemented
38,415,314
<p>I'm attempting to use Python/Pandas to build some charts. I have data that is sampled every second. Here is a sample:</p> <pre><code>Index, Time, Value 31362, 1975-05-07 07:59:18, 36.151612 31363, 1975-05-07 07:59:19, 36.181368 31364, 1975-05-07 07:59:20, 36.197195 31365, 1975-05-07 07:59:21, 36.151413 31366...
1
2016-07-16T20:26:18Z
38,415,555
<h3>Setup</h3> <pre><code>from StringIO import StringIO import pandas as pd text = """Index,Time,Value 31362,1975-05-07 07:59:18,36.151612 31363,1975-05-07 07:59:19,36.181368 31364,1975-05-07 07:59:20,36.197195 31365,1975-05-07 07:59:21,36.151413 31366,1975-05-07 07:59:22,36.138009 31367,1975-05-07 07:59:23,36.142962...
2
2016-07-16T20:56:58Z
[ "python", "pandas", "time-series" ]
How to find nearest bigger 2**n value to a value?
38,415,324
<p>My goal is to get nearest bigger number than an input integer that is two to the n.</p> <p>For example, what should <code>nearestbigger</code> be?</p> <pre><code>integerinput = [2016, 300, 9001] for x in integerinput: print(nearestbigger(x)) </code></pre> <p>Expected Output</p> <pre><code>2048 512 16384 </co...
1
2016-07-16T20:27:21Z
38,415,411
<pre><code>def nearesbigger(n): if n &lt;= 0: return 1 return 2 ** (n-1).bit_length() </code></pre>
1
2016-07-16T20:37:13Z
[ "python" ]