title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
The Pythonic way to grow a list of lists
39,716,492
<p>I have a large file (2GB) of categorical data (mostly "Nan"--but populated here and there with actual values) that is too large to read into a single data frame. I had a rather difficult time coming up with a object to store all the unique values for each column (Which is my goal--eventually I need to factorize thi...
8
2016-09-27T05:18:07Z
39,716,772
<p>I would suggest instead of a <code>list</code> of <code>list</code>s, using a <a href="https://docs.python.org/2/library/collections.html#collections.defaultdict"><code>collections.defaultdict(set)</code></a>. </p> <p>Say you start with</p> <pre><code>uniques = collections.defaultdict(set) </code></pre> <p>Now th...
8
2016-09-27T05:40:05Z
[ "python", "list", "nested-lists" ]
How to use subprocess.Popen with built-in command on Windows
39,716,557
<p>In my old python script, I use the following code to show the result for Windows cmd command:</p> <pre><code>print(os.popen("dir c:\\").read()) </code></pre> <p>As the python 2.7 document said <code>os.popen</code> is obsolete and <code>subprocess</code> is recommended. I follow the documentation as:</p> <pre><co...
1
2016-09-27T05:23:07Z
39,717,215
<p>You should use call <code>subprocess.Popen</code> with <code>shell=True</code> as below:</p> <pre><code>import subprocess result = subprocess.Popen("dir c:", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output,error = result.communicate() print (output) </code></pre> <p>...
1
2016-09-27T06:11:33Z
[ "python", "windows", "python-2.7", "command-line", "subprocess" ]
How to use subprocess.Popen with built-in command on Windows
39,716,557
<p>In my old python script, I use the following code to show the result for Windows cmd command:</p> <pre><code>print(os.popen("dir c:\\").read()) </code></pre> <p>As the python 2.7 document said <code>os.popen</code> is obsolete and <code>subprocess</code> is recommended. I follow the documentation as:</p> <pre><co...
1
2016-09-27T05:23:07Z
39,717,239
<p>Try:</p> <pre><code>p = subprocess.Popen(["dir", "c:\\"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) outputs = p.communicate() </code></pre> <p>Note that <code>communicate()</code> returns a tuple <code>(stdoutdata, stderrdata)</code>, therefore <code>outputs[0]</code> is the <code>stdout</code> messages and ...
0
2016-09-27T06:12:49Z
[ "python", "windows", "python-2.7", "command-line", "subprocess" ]
Oops, try again. Your function failed on the message yes. It returned 'yes' when it should have returned 'Shutting down'
39,716,763
<p>Here is my pyhton practice program: </p> <pre><code>def shut_down(s): return s if yes(): shut_down("Shutting down") elif no(): shut_down("Shutdown aborted") else: shut_down("Sorry") </code></pre> <p>the question given to me are:</p> <ol> <li>if the shut_down function recei...
-10
2016-09-27T05:39:39Z
39,716,950
<p>As others pointed out in comments your return should at the logical end of your function. </p> <pre><code>def shut_down(s): if s == "yes": r = "Shutting down" elif s == "no": r = "Shutdown aborted" else: r = "Sorry" return r </code></pre>
-2
2016-09-27T05:53:38Z
[ "python", "python-2.7", "python-3.x" ]
Oops, try again. Your function failed on the message yes. It returned 'yes' when it should have returned 'Shutting down'
39,716,763
<p>Here is my pyhton practice program: </p> <pre><code>def shut_down(s): return s if yes(): shut_down("Shutting down") elif no(): shut_down("Shutdown aborted") else: shut_down("Sorry") </code></pre> <p>the question given to me are:</p> <ol> <li>if the shut_down function recei...
-10
2016-09-27T05:39:39Z
39,717,132
<p>Couple of points:</p> <ul> <li>Misplaced return statement. Should be at end.</li> <li><code>if yes():</code> It is wrong. You want to compare function input with yes. It should be <code>if s == 'yes':</code>. Same for rest also.</li> <li>Since you have written function definition as <code>def shut_down(s):</code>, ...
0
2016-09-27T06:06:00Z
[ "python", "python-2.7", "python-3.x" ]
Using Makefile bash to save the contents of a python file
39,717,071
<p>For those who are curious as to why I'm doing this: I need specific files in a tar ball - no more, no less. I have to write unit tests for <code>make check</code>, but since I'm constrained to having "no more" files, I have to write the check within the <code>make check</code>. In this way, I have to write bash(but ...
2
2016-09-27T06:02:16Z
39,717,262
<p>the easiest way is to only use double-quotes in your python code, then, in your bash script, wrap all of your python code in one pair of single-quotes, e.g.,</p> <pre><code>#!/bin/bash python -c 'import os import sys #create number of bytes as specified in the args: if len(sys.argv) != 3: print("We need a cor...
2
2016-09-27T06:14:22Z
[ "python", "bash", "shell", "makefile" ]
docx to list in python
39,717,217
<p>I am trying to read a docx file and to add the text to a list. Now I need the list to contain lines from the docx file.</p> <p>example:</p> <p>docx file:</p> <pre><code>"Hello, my name is blabla, I am 30 years old. I have two kids." </code></pre> <p>result:</p> <pre><code>['Hello, my name is blabla', 'I am 30 y...
0
2016-09-27T06:11:38Z
39,717,637
<p><strong>docx2txt</strong> module reads docx file and converts it in text format. </p> <p>You need to split above output using <code>splitlines()</code> and store it in list.</p> <p><strong>Code (Comments inline) :</strong></p> <pre><code>import docx2txt text = docx2txt.process("a.docx") #Prints output after con...
2
2016-09-27T06:36:21Z
[ "python", "python-2.7" ]
How are ModelFields assigned in Django Models?
39,717,356
<p>When we define a model in django we write something like..</p> <pre><code>class Student(models.Model): name = models.CharField(max_length=64) age = models.IntegerField() ... </code></pre> <p>where, <code>name = models.CharField()</code> implies that <code>name</code> would be an <strong>object</strong>...
1
2016-09-27T06:20:20Z
39,718,936
<h1>How things work</h1> <p>First thing I we need to understand that each field on your models has own validation, <a href="https://github.com/django/django/blob/master/django/db/models/fields/__init__.py#L1040" rel="nofollow">this one</a> refer to the CharField(<code>_check_max_length_attribute</code>) and it also ca...
1
2016-09-27T07:44:40Z
[ "python", "django", "oop", "django-models" ]
Adding items to empty pandas DataFrame
39,717,407
<p>I want to dynamically extend an empty pandas DataFrame in the following way:</p> <pre><code>df=pd.DataFrame() indices=['A','B','C'] colums=['C1','C2','C3'] for colum in colums: for index in indices: #df[index,column] = anyValue </code></pre> <p>Where both indices and colums can have arbitrary sizes whi...
4
2016-09-27T06:23:55Z
39,717,446
<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.loc.html" rel="nofollow"><code>loc</code></a>:</p> <pre><code>df = pd.DataFrame() df.loc[0,1] = 10 df.loc[2,8] = 100 print(df) 1 8 0 10.0 NaN 2 NaN 100.0 </code></pre> <p>Faster solution with <a h...
3
2016-09-27T06:26:06Z
[ "python", "pandas" ]
Adding items to empty pandas DataFrame
39,717,407
<p>I want to dynamically extend an empty pandas DataFrame in the following way:</p> <pre><code>df=pd.DataFrame() indices=['A','B','C'] colums=['C1','C2','C3'] for colum in colums: for index in indices: #df[index,column] = anyValue </code></pre> <p>Where both indices and colums can have arbitrary sizes whi...
4
2016-09-27T06:23:55Z
39,717,498
<p><code>loc</code> works very well, but...<br> For single assignments use <code>at</code></p> <pre><code>df = pd.DataFrame() indices = ['A', 'B', 'C'] columns = ['C1', 'C2', 'C3'] for column in columns: for index in indices: df.at[index, column] = 1 df </code></pre> <p><a href="http://i.stack.imgur.com/...
3
2016-09-27T06:28:49Z
[ "python", "pandas" ]
Tableau download/export images using Rest api python
39,717,464
<p>Need to download image from the tableau server using python script. Tableau Rest API doesn't provide any option to do so.I like to know what is proper way of downloading high resolution/full size image from tableau server using python or any other server scripting language.</p>
0
2016-09-27T06:27:03Z
39,732,617
<p>The simplest approach is to issue an HTTP GET request from Python to your Tableau Server and append a format string to the URL such as ".png" or ".pdf".</p> <p>There are size options you can experiment with as well -- press the Share button to see the syntax.</p> <p>You can also pass filter settings in the URL as ...
1
2016-09-27T19:15:42Z
[ "python", "tableau", "tableau-online" ]
redirecting python -m CGIHTTPserver 8080 to /dev/null
39,717,471
<p>The standard > /dev/null and >> /dev/null don't work when a computer sends a GET to the task. eg: pi@raspberrypi:~/server $ python -m CGIHTTPServer 8080 &amp;</p> <p>results in </p> <p>192.168.0.109 - - [26/Sep/2016 23:14:48] "GET /cgi-bin/DS1822remote.py HTTP/1.1" 200 -</p> <p>As I've put the python app into the...
0
2016-09-27T06:27:30Z
39,717,571
<p>You need to redirect stderr, not stdout; best to redirect both with:</p> <pre><code> python -m CGIHTTPServer 8080 &gt; /dev/null 2&gt;&amp;1 &amp; </code></pre> <p>If you still want to expose stdout (to see the start-up message, for example), use:</p> <pre><code> python -m CGIHTTPServer 8080 2&gt; /dev/null &amp;...
0
2016-09-27T06:33:07Z
[ "python", "cgihttpserver" ]
How to add additional fields to embedded documents without changing the original model
39,717,659
<p>I want to add extra properties to a document before embedding that into other document, but I don't know how to do that.</p> <p>Here's my code and what I have tried so far:</p> <pre class="lang-py prettyprint-override"><code>from mongoengine import * from datetime import datetime class User(Document): name =...
1
2016-09-27T06:37:33Z
39,717,838
<p>use update method to set the new attribute</p> <pre><code>user.update(set__roles = ['admin','writer']) </code></pre>
0
2016-09-27T06:47:52Z
[ "python", "django", "mongoengine", "embedded-documents" ]
Insert list into cells which meet column conditions
39,717,809
<p>Consider <code>df</code></p> <pre><code> A B C 0 3 2 1 1 4 2 3 2 1 4 1 3 2 2 3 </code></pre> <p>I want to add another column <code>"D"</code> such that D contains different Lists based on conditions on <code>"A"</code>, <code>"B"</code> and <code>"C"</code></p> <pre><code> A B C D 0 3 2 1 ...
4
2016-09-27T06:46:12Z
39,718,151
<p>Here's a goofy way to do it</p> <pre><code>cond1 = df.A.gt(1) &amp; df.B.gt(1) cond2 = df.A.eq(1) cond3 = df.A.eq(2) &amp; df.C.ne(0) df['D'] = cond3.map({True: [2, 0]}) \ .combine_first(cond2.map({True: [0, 2]})) \ .combine_first(cond1.map({True: [1, 0]})) \ df </code></pre> <p><a href="http://i.stack.imgur...
4
2016-09-27T07:05:18Z
[ "python", "pandas" ]
Insert list into cells which meet column conditions
39,717,809
<p>Consider <code>df</code></p> <pre><code> A B C 0 3 2 1 1 4 2 3 2 1 4 1 3 2 2 3 </code></pre> <p>I want to add another column <code>"D"</code> such that D contains different Lists based on conditions on <code>"A"</code>, <code>"B"</code> and <code>"C"</code></p> <pre><code> A B C D 0 3 2 1 ...
4
2016-09-27T06:46:12Z
39,719,580
<p>Another solution is create <code>Series</code> filled by <code>list</code> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.shape.html" rel="nofollow"><code>shape</code></a> for generating <code>length</code> of <code>df</code>:</p> <pre><code>df.loc[(df['A'] &gt; 1) &amp; (df['B...
3
2016-09-27T08:18:27Z
[ "python", "pandas" ]
Insert list into cells which meet column conditions
39,717,809
<p>Consider <code>df</code></p> <pre><code> A B C 0 3 2 1 1 4 2 3 2 1 4 1 3 2 2 3 </code></pre> <p>I want to add another column <code>"D"</code> such that D contains different Lists based on conditions on <code>"A"</code>, <code>"B"</code> and <code>"C"</code></p> <pre><code> A B C D 0 3 2 1 ...
4
2016-09-27T06:46:12Z
39,720,329
<p><strong>Disclaimer</strong>: This is my own question.</p> <p>Both the answers provided by <a href="http://stackoverflow.com/users/2901002/jezrael">jezrael</a> and <a href="http://stackoverflow.com/users/2336654/pirsquared">piRSquared</a> work.</p> <p>I just wanted to add another way of doing it, albeit slightly di...
0
2016-09-27T08:56:39Z
[ "python", "pandas" ]
Django ModelForm not saving data that is added to request.POST or through form.save(commit=False)
39,718,015
<p>I have django form that submitted to the view that displays it and want to add some data to it before saving it but it seems not be working.</p> <p><strong>models.py</strong>:</p> <pre><code>from django.contrib.auth.models import User from django.db import models class Profile(models.Model): user = models.One...
1
2016-09-27T06:58:02Z
39,718,288
<p>See this example from <a href="https://docs.djangoproject.com/es/1.10/topics/forms/modelforms/#the-save-method" rel="nofollow">django's official documentation</a>:</p> <pre><code>form = PartialAuthorForm(request.POST) author = form.save(commit=False) author.title = 'Mr' author.save() </code></pre> <p>In your case ...
1
2016-09-27T07:11:47Z
[ "python", "django", "django-forms" ]
Using numbers in a list to access items in a dictionary in python
39,718,095
<p>I have the items:</p> <pre><code>my_list = [18, 15, 22, 22, 25, 10, 7, 25, 2, 22, 14, 10, 27] </code></pre> <p>in a list and I would like to use these to access items inside my dictionary by using a 'for loop', I will then append these items to a new list. My dictionary looks like this:</p> <pre><code>my_dict = {...
1
2016-09-27T07:02:30Z
39,718,181
<p>You can simply use a <a href="https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a> where you implicitly loop through your list of numbers <code>my_list</code> and retrieve the value form your dict <code>my_dict</code> using the respective number as a key:<...
1
2016-09-27T07:07:05Z
[ "python", "list", "dictionary" ]
Using numbers in a list to access items in a dictionary in python
39,718,095
<p>I have the items:</p> <pre><code>my_list = [18, 15, 22, 22, 25, 10, 7, 25, 2, 22, 14, 10, 27] </code></pre> <p>in a list and I would like to use these to access items inside my dictionary by using a 'for loop', I will then append these items to a new list. My dictionary looks like this:</p> <pre><code>my_dict = {...
1
2016-09-27T07:02:30Z
39,718,529
<p>Your code snipped does not seems to be complete because you are using the variable <code>number_values</code> which is not defined in your example. EDIT: You still are using variables which are not defined in the code snipped you provided so I cant reproduce your error. In addition you are overwriting your <code>th...
1
2016-09-27T07:23:37Z
[ "python", "list", "dictionary" ]
Using numbers in a list to access items in a dictionary in python
39,718,095
<p>I have the items:</p> <pre><code>my_list = [18, 15, 22, 22, 25, 10, 7, 25, 2, 22, 14, 10, 27] </code></pre> <p>in a list and I would like to use these to access items inside my dictionary by using a 'for loop', I will then append these items to a new list. My dictionary looks like this:</p> <pre><code>my_dict = {...
1
2016-09-27T07:02:30Z
39,727,537
<p>Others have pointed out the inconsistencies in your code sample, so blithely ignoring those :)</p> <pre><code>my_list = [18, 15, 22, 22, 25, 10, 7, 25, 2, 22, 14, 10, 27] my_dict = {0: '@', 1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E', 6: 'F', 7: 'G', 8: 'H', 9: 'I', 10: 'J', 11: 'K', 12: 'L', 13: 'M', 14: 'N', 15: 'O', ...
0
2016-09-27T14:36:36Z
[ "python", "list", "dictionary" ]
Setting to zero of elements of a numpy array different from a value (python3) : a[a <> 5] = 0
39,718,129
<p>In python 2, the following code works:</p> <pre><code>a = np.array([[1,5],[2,3]]) print a print() a[a&lt;2] = 0 print a a[a &lt;&gt; 5] = 0 print a </code></pre> <p>But in python3, it triggers a syntax error:</p> <pre><code>a[a &lt;&gt; 5] = 0 File "&lt;ipython-input-14-165e29d9f8e4&gt;", line 1 a[a &lt;&gt;...
-1
2016-09-27T07:04:09Z
39,718,162
<p>The correct syntax for "not equal to" is now <code>a[a != 5] = 0</code></p> <p>(Yet another instance of a backward compatibility break in Python 3).</p>
3
2016-09-27T07:05:49Z
[ "python", "arrays", "python-3.x", "numpy" ]
Setting to zero of elements of a numpy array different from a value (python3) : a[a <> 5] = 0
39,718,129
<p>In python 2, the following code works:</p> <pre><code>a = np.array([[1,5],[2,3]]) print a print() a[a&lt;2] = 0 print a a[a &lt;&gt; 5] = 0 print a </code></pre> <p>But in python3, it triggers a syntax error:</p> <pre><code>a[a &lt;&gt; 5] = 0 File "&lt;ipython-input-14-165e29d9f8e4&gt;", line 1 a[a &lt;&gt;...
-1
2016-09-27T07:04:09Z
39,718,179
<p>In Python 3, <code>&lt;&gt;</code> was replaced by <code>!=</code>. It is similar to how <code>print</code> was changed from a statement to a function. See <a href="https://docs.python.org/2/library/stdtypes.html#comparisons" rel="nofollow">Comparisons</a> in the Docs:</p> <blockquote> <p><code>!=</code> can also...
1
2016-09-27T07:06:49Z
[ "python", "arrays", "python-3.x", "numpy" ]
Panda how to groupby rows into different time buckets?
39,718,157
<p>I have a dataframe with a datetime type column called timestamp, I want to split the dataframe into several dataframes based on timestamp the time part, each dataframe contains rows that value by its value modulo x minutes, where x is a variable. </p> <p>Notice that <code>e</code> and <code>f</code> are not in orig...
-1
2016-09-27T07:05:36Z
39,728,612
<p>Your main tools will be <code>df.timestampe.dt.minute % 10</code> and <code>groupby</code>.<br> I used an <code>apply(pd.DataFrame.reset_index)</code> just as a convenience to illustrate</p> <pre><code>df.groupby(df.timestampe.dt.minute % 10).apply(pd.DataFrame.reset_index) </code></pre> <p><a href="http://i.stack...
2
2016-09-27T15:27:13Z
[ "python", "pandas", "numpy", "scipy" ]
Python: gb2312 codec can't decode bytes
39,718,209
<p>I have a word-encoded string from received mail. When parsing encoded word in Python3, I got an exception </p> <blockquote> <p>'gb2312' codec can't decode bytes in position 18-19: illegal multibyte sequence</p> </blockquote> <p>raised from <em>make_header</em> method.</p> <pre><code>from email.header import d...
0
2016-09-27T07:08:34Z
39,718,996
<p>The error message tells you that the bytes <em>in position 18-19</em> are not valid for this encoding.</p> <p><code>decode_header</code> simply extracts a bunch of bytes and an encoding. <code>make_header</code> actually attempts to interpret those bytes in that encoding, and fails, because these bytes are not val...
1
2016-09-27T07:47:52Z
[ "python", "encoding", "gb2312" ]
Flask logout if sessions expires if no activity and redirect for login page
39,718,259
<p>I'm very new to flask and trying updating a website with flask where users have accounts and are able to login. I want to make user session expire and logout if there is no activity for more than 10 mins and redirect the user for login page.</p> <p>I want to update it in @app.before_request and below is my code . ...
0
2016-09-27T07:10:44Z
39,720,888
<p>You can use <code>permanent_session_lifetime</code> and the <code>session.modified</code> flag as described in <a href="http://stackoverflow.com/questions/19760486/resetting-the-expiration-time-for-a-cookie-in-flask/19795394">this question</a>.</p> <p>Note that sessions are not permanent by default, and need to be ...
0
2016-09-27T09:22:40Z
[ "python", "redirect", "flask", "logout", "expired-sessions" ]
Django Zinnia blog error for entries
39,718,261
<p>I am trying to fix issue with Zinnia blog application and its popping up error related to aggregator and entries. Following is the code if someone have a suggestion:</p> <pre><code>def get_authors(context, template='zinnia/tags/authors.html'): """ Return the published authors. """ return {'template...
0
2016-09-27T07:10:49Z
39,720,567
<p>Try registering django_comments after zinnia in the INSTALLED_APPS setting not before.</p> <pre><code>INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.admin', 'django.contrib.sites', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.contenttyp...
2
2016-09-27T09:07:36Z
[ "python", "django" ]
Python : Basic countdown timer & function() > int()
39,718,271
<p>I'm trying to ucreate a timer function that runs in the background of my code and make it so I can use/check the time. What I mean by use/check, I'm trying to make it so I can call upon that timer function and use it as integer.</p> <p>This is the code I currently have:</p> <pre><code>def timer(): for endtime ...
0
2016-09-27T07:11:10Z
39,718,467
<pre><code>import time def timer(tim): time.sleep(1) print tim def hall(): tim = 15 while (tim &gt; 0): print 'do something' timer(tim) tim-=1 </code></pre> <p>Not the cleanest solution, but it will do what you need.</p>
0
2016-09-27T07:20:18Z
[ "python", "timer" ]
Python : Basic countdown timer & function() > int()
39,718,271
<p>I'm trying to ucreate a timer function that runs in the background of my code and make it so I can use/check the time. What I mean by use/check, I'm trying to make it so I can call upon that timer function and use it as integer.</p> <p>This is the code I currently have:</p> <pre><code>def timer(): for endtime ...
0
2016-09-27T07:11:10Z
39,718,470
<p>The way you do it, you'll going to have to use multithread.</p> <p>Here is another, simpler approach : On your script beginning, set a <code>time_start</code> variable with the number of seconds since the epoch using <code>time.time()</code> Then when you need the number of elapsed seconds, use <code>time.time() - ...
1
2016-09-27T07:20:26Z
[ "python", "timer" ]
Python : Basic countdown timer & function() > int()
39,718,271
<p>I'm trying to ucreate a timer function that runs in the background of my code and make it so I can use/check the time. What I mean by use/check, I'm trying to make it so I can call upon that timer function and use it as integer.</p> <p>This is the code I currently have:</p> <pre><code>def timer(): for endtime ...
0
2016-09-27T07:11:10Z
39,718,645
<p>The problem with your code is that when you run <code>hall()</code>, Python first executes the whole of <code>timer()</code> (i.e. the whole <code>for</code> loop), and then moves on with the rest of the code (it can only do one thing at a time). Thus, by the time it reaches the <code>while</code> loop in <code>hall...
0
2016-09-27T07:28:59Z
[ "python", "timer" ]
BadDataError when converting .DBF to .csv
39,718,413
<p>I am trying to convert a .DBF file to .csv using Python3. I am trying using the dbf library (<a href="https://pypi.python.org/pypi/dbf" rel="nofollow">https://pypi.python.org/pypi/dbf</a>) </p> <pre><code>import dbf def dbf_to_csv(dbf_file_name, csv_file_name): dbf_file = dbf.Table(dbf_file_name, ignore_memos...
0
2016-09-27T07:17:32Z
39,719,803
<p>If the file is opening correctly in Excel, then I suggest you use Excel to do the conversion for you to <code>csv</code> format as follows:</p> <pre><code>import win32com.client as win32 excel = win32.gencache.EnsureDispatch('Excel.Application') wb = excel.Workbooks.Open(r"input.dbf") excel.DisplayAlerts = False ...
0
2016-09-27T08:30:41Z
[ "python", "python-3.x", "dbf" ]
Python list to django javascript as text
39,718,574
<p>Hello my generated python output list is </p> <pre><code>l = ["one","two","there"] </code></pre> <p>I am passing that to a django html script as {{list}}</p> <p>in the html it is shown as </p> <pre><code>[&amp;#39;one&amp;#39;,&amp;#39;two&amp;#39;,&amp;#39;three&amp;#39; </code></pre> <p>which i can't use for ...
1
2016-09-27T07:25:36Z
39,719,157
<p>There are two steps here. Firstly, you need to make the view send valid JSON; you've done this with <code>json_dumps</code>.</p> <p>Secondly, you need to ensure that the template outputs it without escaping. You do that by marking it as safe, with <code>{{ data|safe }}</code> (assuming your data is in a variable ca...
1
2016-09-27T07:56:10Z
[ "javascript", "python", "django", "python-3.x" ]
Convert a byte array to single bits in a array [Python 3.5]
39,718,576
<p>I am looking for a operation witch converts my byte array:</p> <pre><code>mem = b'\x01\x02\xff' </code></pre> <p>in something like this:</p> <pre><code>[ [0 0 0 0 0 0 0 1] [0 0 0 0 0 0 1 0] [1 1 1 1 1 1 1 1] ] </code></pre> <p>These are operations that I tried:</p> <pre><code>import numpy as np mem = b'\x0...
2
2016-09-27T07:25:40Z
39,718,863
<p>To solve IndexError you can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndindex.html#numpy.ndindex" rel="nofollow"><code>numpy.ndindex</code></a>:</p> <pre><code>import numpy as np mem = b'\x01\x02\xff' #define my input mem = np.fromstring(mem, dtype=np.uint8) #first convert to int #pr...
0
2016-09-27T07:40:40Z
[ "python", "arrays", "hex", "bit" ]
Convert a byte array to single bits in a array [Python 3.5]
39,718,576
<p>I am looking for a operation witch converts my byte array:</p> <pre><code>mem = b'\x01\x02\xff' </code></pre> <p>in something like this:</p> <pre><code>[ [0 0 0 0 0 0 0 1] [0 0 0 0 0 0 1 0] [1 1 1 1 1 1 1 1] ] </code></pre> <p>These are operations that I tried:</p> <pre><code>import numpy as np mem = b'\x0...
2
2016-09-27T07:25:40Z
39,718,913
<p>Using unpackbits:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; mem = b'\x01\x02\xff' &gt;&gt;&gt; x = np.fromstring(mem, dtype=np.uint8) &gt;&gt;&gt; np.unpackbits(x).reshape(3,8) array([[0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1]], dtype=uint8) </code><...
2
2016-09-27T07:43:23Z
[ "python", "arrays", "hex", "bit" ]
Convert a byte array to single bits in a array [Python 3.5]
39,718,576
<p>I am looking for a operation witch converts my byte array:</p> <pre><code>mem = b'\x01\x02\xff' </code></pre> <p>in something like this:</p> <pre><code>[ [0 0 0 0 0 0 0 1] [0 0 0 0 0 0 1 0] [1 1 1 1 1 1 1 1] ] </code></pre> <p>These are operations that I tried:</p> <pre><code>import numpy as np mem = b'\x0...
2
2016-09-27T07:25:40Z
39,718,934
<p>I'm fairly certain the problem with your code is that you're assuming the <code>int</code> in each item in the list will become 8 bits (so <code>2</code> will, in your assumption, return <code>00000010</code>). But it doesn't (<code>2</code> = <code>10</code>), and that screws up your code.</p> <p>For your last two...
0
2016-09-27T07:44:37Z
[ "python", "arrays", "hex", "bit" ]
Convert a byte array to single bits in a array [Python 3.5]
39,718,576
<p>I am looking for a operation witch converts my byte array:</p> <pre><code>mem = b'\x01\x02\xff' </code></pre> <p>in something like this:</p> <pre><code>[ [0 0 0 0 0 0 0 1] [0 0 0 0 0 0 1 0] [1 1 1 1 1 1 1 1] ] </code></pre> <p>These are operations that I tried:</p> <pre><code>import numpy as np mem = b'\x0...
2
2016-09-27T07:25:40Z
39,719,532
<pre><code>mem = b'\x01\x02\xff' [[int(digit) for digit in "{0:08b}".format(byte)] for byte in mem] </code></pre> <p>outputs:</p> <pre><code>[[0, 0, 0, 0, 0, 0, 0, 1], [0, 0, 0, 0, 0, 0, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1]] </code></pre>
0
2016-09-27T08:15:49Z
[ "python", "arrays", "hex", "bit" ]
Passing variables from normal function to init_UI function
39,718,609
<p>I have been facing a problem in using a variable of a normal class function and <code>initUI</code> function.<br> The code looks like this:</p> <pre><code>def text_trans(self): ... number = 2 ... def init_UI(self): number = text_transfer(self) print(number) QtWidgets.QMessageBox.information(...
-2
2016-09-27T07:26:58Z
39,719,336
<blockquote> <p>I wrote the above code but it shows a name error.</p> </blockquote> <p>Probably because, for starters, <code>text_transfer != text_trans</code> and, secondly, in the body of methods you should use <code>self</code> to access other methods. So, <code>init_UI</code> should look like:</p> <pre><code>de...
1
2016-09-27T08:05:03Z
[ "python", "function", "python-3.x", "pyqt5" ]
Find Regexp and replace expression for CSV file starting with $
39,718,822
<p>I need an Regexp and Replace expression to capture contents from CSV file. My CSV file starts like this.</p> <p>Example- expression should find key name "FC_host" in my CSV file and replace with different value.</p> <pre><code>$TH_appName=tuipatthcrfh3320 #$TH_host=10.145.129.75 $TH_host=10.145.129.75 $TH_casPort=...
-1
2016-09-27T07:39:04Z
39,719,332
<pre><code>with open('items.csv', 'r')as file: for row in file: print row.replace('TH_host', 'Something else') &gt;&gt;$TH_appName=tuipatthcrfh3320 &gt;&gt;#$Something else=10.145.129.75 &gt;&gt;$Something else=10.145.129.75 &gt;&gt;... </code></pre> <p>You don't need regex unless you need to use the regular expr...
0
2016-09-27T08:04:59Z
[ "python", "ansible", "ansible-playbook", "ansible-2.x" ]
Find Regexp and replace expression for CSV file starting with $
39,718,822
<p>I need an Regexp and Replace expression to capture contents from CSV file. My CSV file starts like this.</p> <p>Example- expression should find key name "FC_host" in my CSV file and replace with different value.</p> <pre><code>$TH_appName=tuipatthcrfh3320 #$TH_host=10.145.129.75 $TH_host=10.145.129.75 $TH_casPort=...
-1
2016-09-27T07:39:04Z
39,719,859
<p>The task should look like this:</p> <pre><code>- name: Find and Replace replace: dest: /etc/ansible/kalyan-tui/example.csv regexp: ^\$FC_host=.* replace: "$FC_host={{ new_value }}" </code></pre> <hr> <ul> <li><code>state</code> is not a parameter of <code>replace</code></li> <li>variable name cannot...
0
2016-09-27T08:33:30Z
[ "python", "ansible", "ansible-playbook", "ansible-2.x" ]
Python multiple logger for multiple modules
39,718,895
<p>I have two files namley main.py and my_modules.py. In main.py I have defined two loggers like this</p> <pre><code> #main.py URL_LOGS = "logs/urls.log" GEN_LOGS = 'logs/scrape.log' #Create two logger files formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s', datefmt=...
0
2016-09-27T07:42:23Z
39,719,135
<p>Quote from <a href="https://docs.python.org/2/library/logging.html" rel="nofollow">logging documentation</a>: <em>Multiple calls to getLogger() with the same name will always return a reference to the same Logger object.</em></p> <p>So what you want to do in your my_modules.py is just to call the <code>getLogger()<...
1
2016-09-27T07:55:08Z
[ "python", "logging" ]
Python multiple logger for multiple modules
39,718,895
<p>I have two files namley main.py and my_modules.py. In main.py I have defined two loggers like this</p> <pre><code> #main.py URL_LOGS = "logs/urls.log" GEN_LOGS = 'logs/scrape.log' #Create two logger files formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s', datefmt=...
0
2016-09-27T07:42:23Z
39,719,829
<p>if you transform the second module in a class, you can simply:</p> <ul> <li>declare the logger in the first modulue</li> <li>create the new class passing the 2 logger as parameters</li> <li>use the logger in the new class</li> </ul> <p>Example:</p> <pre><code>import logging class MyClassName: def __init__(s...
1
2016-09-27T08:31:41Z
[ "python", "logging" ]
How to web scrape data using Python from an html table and store it in a csv file. I am able to extract some parts but not the others
39,719,108
<p>I am beginner in Web scraping and I have become very much interested in the process. I set for myself a Project that can keep me motivated till I completed the project.</p> <p><strong>My Project</strong></p> <p>My Aim is to write a Python Program that goes to my university results page and scrape all the results o...
0
2016-09-27T07:53:42Z
39,725,728
<p>Took a lot of time to find a brute force solution.</p> <pre><code>import requests from bs4 import BeautifulSoup import re import csv for x in xrange(44,47): EXAMNO ='15te12'+str(x) data = {"txtregno": EXAMNO, "cmbdegree": r"BTHEE~\BTHEE\result.mdb", # use raw strings "cmbexamno": "B", "dpath": ...
0
2016-09-27T13:18:09Z
[ "python", "html", "csv", "asp-classic", "web-scraping" ]
Cannot import Owlready library into Python
39,719,119
<p>I am a beginner in Python. I am working on an ontology using <a href="http://pythonhosted.org/Owlready/" rel="nofollow">owlready</a>. I've installed <code>owlready</code> library on my PyCharm IDE, but there is an issue with importing <code>owlready</code> in my python code. I've tried <code>from owlready import *</...
1
2016-09-27T07:54:22Z
39,722,375
<p>It looks like Owlready is for Python 3 while you're using Python 2. Change your python version for it to work.</p> <p>The invalid syntax error is because of the new Python 3 argument lists, see: <a href="https://docs.python.org/3/tutorial/controlflow.html#arbitrary-argument-lists" rel="nofollow">https://docs.python...
1
2016-09-27T10:32:31Z
[ "python", "ontology" ]
Pyhon - Best way to find the 1d center of mass in a binary numpy array
39,719,140
<p>Suppose I have the following Numpy array, in which I have one and only one continuous slice of <code>1</code>s:</p> <pre><code>import numpy as np x = np.array([0,0,0,0,1,1,1,0,0,0], dtype=1) </code></pre> <p>and I want to find the index of the 1D center of mass of the <code>1</code> elements. I could type the foll...
4
2016-09-27T07:55:13Z
39,719,208
<p>As one approach we can get the non-zero indices and get the mean of those as the center of mass, like so -</p> <pre><code>np.flatnonzero(x).mean() </code></pre> <p>Here's another approach using shifted array comparison to get the start and stop indices of that slice and getting the mean of those indices for determ...
2
2016-09-27T07:58:24Z
[ "python", "arrays", "numpy", "binary", "boolean" ]
Pyhon - Best way to find the 1d center of mass in a binary numpy array
39,719,140
<p>Suppose I have the following Numpy array, in which I have one and only one continuous slice of <code>1</code>s:</p> <pre><code>import numpy as np x = np.array([0,0,0,0,1,1,1,0,0,0], dtype=1) </code></pre> <p>and I want to find the index of the 1D center of mass of the <code>1</code> elements. I could type the foll...
4
2016-09-27T07:55:13Z
39,719,579
<p>Can't you simply do the following?</p> <pre><code>center_of_mass = (x*np.arange(len(x))).sum()/x.sum() # 5 %timeit center_of_mass = (x*arange(len(x))).sum()/x.sum() # 100000 loops, best of 3: 10.4 µs per loop </code></pre>
2
2016-09-27T08:18:21Z
[ "python", "arrays", "numpy", "binary", "boolean" ]
Python: "while" is too slow, and sleep(0.25) becomes sleep(3) in actual execution
39,719,177
<p>I am running a Python Program on a Raspberry Pi 3 which I want to log the temperature from a DS18B20 sensor once every 0.25 seconds.</p> <p>Earlier, when the program was simple and displaying the temperature on shell, it was quite fast and not having issues. Unfortunately due to the program itself now which include...
0
2016-09-27T07:57:11Z
39,719,488
<ol> <li>Only open the logfile once (and close it on program exit)</li> <li>Don't always re-read the temperature from the sensor. You call <code>read()</code> way too often.</li> <li>Reduce general overhead and simplify your calls.</li> </ol> <p>I am not able to completely test this, but something like this sould work...
2
2016-09-27T08:13:39Z
[ "python", "runtime", "raspberry-pi3" ]
How to pass output from a python program into a processing program
39,719,193
<p>I am reading the orientation a gyroscope <a href="https://www.raspberrypi.org/products/sense-hat/" rel="nofollow">(sense-hat)</a> through a python program that can output the position in strings. I am trying to use this data as an input in a Processing program to make it interactive depending on the orientation of t...
0
2016-09-27T07:57:46Z
39,720,811
<p>I have used the following snippet of code in a bash script to take output from a python program. I hope this helps. </p> <pre><code>OUTPUT="$(python your_program.py)" print($OUTPUT) </code></pre>
0
2016-09-27T09:19:08Z
[ "python", "raspberry-pi", "processing", "gyroscope" ]
How to pass output from a python program into a processing program
39,719,193
<p>I am reading the orientation a gyroscope <a href="https://www.raspberrypi.org/products/sense-hat/" rel="nofollow">(sense-hat)</a> through a python program that can output the position in strings. I am trying to use this data as an input in a Processing program to make it interactive depending on the orientation of t...
0
2016-09-27T07:57:46Z
39,723,042
<p>I've never used the Sense HAT before, but I'm guessing it's using I2C behind the scenes. In theory it should be possible to reimplement the code in Processing using it's <a href="https://processing.org/reference/libraries/io/I2C.html" rel="nofollow">I2C io library</a>, but in practice it may take quite a bit of effo...
1
2016-09-27T11:05:24Z
[ "python", "raspberry-pi", "processing", "gyroscope" ]
Python 3, yield expression return value influenced by its value just received via send()?
39,719,530
<p>after reading documentation, questions, and making my own test code, I believe I have understood how a <code>yield expression</code> works.</p> <p>Nevertheless, I am surprised of the behavior of the following example code:</p> <pre><code>def gen(n=0): while True: n = (yield n) or n+1 g=gen() print( ne...
0
2016-09-27T08:15:46Z
39,719,665
<p>Your confusion lies with <code>generator.send()</code>. Sending is <em>just the same thing as using <code>next()</code></em>, with the difference being that the <code>yield</code> expression produces a different value. Put differently, <code>next(g)</code> is the same thing as <code>g.send(None)</code>, both operati...
4
2016-09-27T08:23:34Z
[ "python", "yield" ]
Not nesting version of @atomic() in Django?
39,719,567
<p>From the <a href="https://docs.djangoproject.com/en/dev/topics/db/transactions/#django.db.transaction.atomic">docs of atomic()</a></p> <blockquote> <p>atomic blocks can be nested</p> </blockquote> <p>This sound like a great feature, but in my use case I want the opposite: I want the transaction to be durable as ...
15
2016-09-27T08:17:37Z
39,721,631
<p>You can't do that through any API.</p> <p>Transactions can't be nested while retaining all ACID properties, and not all databases support nested transactions.</p> <p>Only the outermost atomic block creates a transaction. Inner atomic blocks create a savepoint inside the transaction, and release or roll back the sa...
7
2016-09-27T09:56:10Z
[ "python", "django", "postgresql", "transactions", "acid" ]
Not nesting version of @atomic() in Django?
39,719,567
<p>From the <a href="https://docs.djangoproject.com/en/dev/topics/db/transactions/#django.db.transaction.atomic">docs of atomic()</a></p> <blockquote> <p>atomic blocks can be nested</p> </blockquote> <p>This sound like a great feature, but in my use case I want the opposite: I want the transaction to be durable as ...
15
2016-09-27T08:17:37Z
39,798,947
<p>I agree with knbk's answer that it is not possible: durability is only present at the level of a transaction, and atomic provides that. It does not provide it at the level of save points. Depending on the use case, there may be workarounds.</p> <p>I'm guessing your use case is something like:</p> <pre><code>@atomi...
6
2016-09-30T19:38:21Z
[ "python", "django", "postgresql", "transactions", "acid" ]
Not nesting version of @atomic() in Django?
39,719,567
<p>From the <a href="https://docs.djangoproject.com/en/dev/topics/db/transactions/#django.db.transaction.atomic">docs of atomic()</a></p> <blockquote> <p>atomic blocks can be nested</p> </blockquote> <p>This sound like a great feature, but in my use case I want the opposite: I want the transaction to be durable as ...
15
2016-09-27T08:17:37Z
39,808,352
<p>This type of <em>durability</em> is <strong>impossible due to ACID</strong>, with one connection. (i.e. that a nested block stays committed while the outer block get rolled back) It is a consequence of ACID, not a problem of Django. Imagine a super database and the case that table <code>B</code> has a foreign key to...
6
2016-10-01T15:29:15Z
[ "python", "django", "postgresql", "transactions", "acid" ]
Model Choice Field - get the id
39,719,596
<p>I am busy trying to get the id only in integer format preferably for the ModelChoiceField. I get the list to display but get's returned in a string format. Please helping me in retrieving the id of ModelChoiceField. I think I need to do this in the view. </p> <pre><code>forms.py class ProjectForm(forms.ModelForm): ...
0
2016-09-27T08:19:23Z
39,719,793
<p>From what I can tell, <code>items</code> should never be an <code>IntegerField</code>. Your usage has it set up to be a <code>ForeignKey</code> to a <code>Project</code> so you should just make that explicit</p> <pre><code>items = models.ForeignKey('self', null=True, blank=True) </code></pre> <p>Possibly with a be...
0
2016-09-27T08:30:21Z
[ "python", "django", "django-models", "django-forms" ]
Move patch rather than remove it
39,719,652
<p>I have a graph that is gradually revealed. Since this should happen with a huge dataset and on several subplots simultaneously, I was planning to <em>move</em> the <code>patch</code> rather than remove it and draw it from scratch in order to accelerate the code.</p> <p>My problem is similar to <a href="http://stack...
1
2016-09-27T08:22:34Z
39,720,245
<p>Maybe this works for you. Instead of removing the patch, you just update its position and its width (with <code>rect.set_x(left_x)</code> and <code>rect.set_width(width)</code>), and then redraw the canvas. Try replacing your loop with this (note that the <code>Rectangle</code> is created <em>once</em>, before the...
1
2016-09-27T08:52:28Z
[ "python", "matplotlib" ]
What is the difference between JSON.load() and JSON.loads() functions in PYTHON?
39,719,689
<p>In python, what is he difference between <strong>json.load()</strong> and <strong>json.loads()</strong> ?</p> <p>I guess that the <em>load()</em> function must be used with a file object (I need thus to use a context manager) while the <em>loads()</em> function take the path to the file as a string. It is a bit con...
-6
2016-09-27T08:24:26Z
39,719,701
<p>Yes, it stands for string. The <code>json.loads</code> function does not take the file path, but the file contents as a string. Look at the documentation at <a href="https://docs.python.org/2/library/json.html" rel="nofollow">https://docs.python.org/2/library/json.html</a>!</p>
3
2016-09-27T08:25:26Z
[ "python", "json", "python-2.7" ]
What is the difference between JSON.load() and JSON.loads() functions in PYTHON?
39,719,689
<p>In python, what is he difference between <strong>json.load()</strong> and <strong>json.loads()</strong> ?</p> <p>I guess that the <em>load()</em> function must be used with a file object (I need thus to use a context manager) while the <em>loads()</em> function take the path to the file as a string. It is a bit con...
-6
2016-09-27T08:24:26Z
39,719,723
<p>Documentation is quite clear: <a href="https://docs.python.org/2/library/json.html" rel="nofollow">https://docs.python.org/2/library/json.html</a></p> <pre><code>json.load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]]) </code></pre> <blockquote> <...
0
2016-09-27T08:26:57Z
[ "python", "json", "python-2.7" ]
How to retrieve a Control Flow Graph for python code?
39,719,729
<p>I would like to dump the Control Flow Graph of a given python code, similar to the option given by gcc compiler option: -fdump-tree-cfg for c code.</p> <p>I succeeded getting the AST (Abstract Syntax Trees) of a python code, but it seams quite complex and hassle to get the Control Flow Graph from AST phase.</p> <p...
3
2016-09-27T08:27:12Z
39,720,615
<p>See my <a href="http://stackoverflow.com/a/9989663/120163">SO answer on how to build a control flow graph, using an AST</a>.</p> <p>The original question asked about CFGs for Java, but the approach is actually pretty generic, and the same approach would work for producing a CFG for Python.</p> <p>I wouldn't have c...
1
2016-09-27T09:09:59Z
[ "python", "abstract-syntax-tree", "control-flow-graph" ]
Byte array is a valid UTF8 encoded String in Java but not in Python
39,719,737
<p>When I run the following in Python 2.7.6, I get an exception:</p> <pre><code>import base64 some_bytes = b"\x80\x02\x03" print ("base 64 of the bytes:") print (base64.b64encode(some_bytes)) try: print (some_bytes.decode("utf-8")) except Exception as e: print(e) </code></pre> <p>The output:</p> <pre><code>b...
-1
2016-09-27T08:27:29Z
39,719,936
<blockquote> <p>So in Python 2.7.6 the bytes represented as gAID are not a valid UTF8.</p> </blockquote> <p>This is wrong as you try to decode the <code>Base64</code> encoded bytes.</p> <pre><code>import base64 some_bytes = b"\x80\x02\x03" print ("base 64 of the bytes:") print (base64.b64encode(some_bytes)) # store...
-1
2016-09-27T08:37:09Z
[ "java", "python", "utf-8", "character-encoding" ]
Byte array is a valid UTF8 encoded String in Java but not in Python
39,719,737
<p>When I run the following in Python 2.7.6, I get an exception:</p> <pre><code>import base64 some_bytes = b"\x80\x02\x03" print ("base 64 of the bytes:") print (base64.b64encode(some_bytes)) try: print (some_bytes.decode("utf-8")) except Exception as e: print(e) </code></pre> <p>The output:</p> <pre><code>b...
-1
2016-09-27T08:27:29Z
39,720,372
<p>It's not valid UTF8. <a href="https://en.wikipedia.org/wiki/UTF-8" rel="nofollow">https://en.wikipedia.org/wiki/UTF-8</a></p> <p>Bytes between 0x80 and 0xBF cannot be the first byte of a multi-byte character. They can only be the second byte or later.</p> <p>Java replaces bytes which cannot be decoded with a <code...
0
2016-09-27T08:58:46Z
[ "java", "python", "utf-8", "character-encoding" ]
Byte array is a valid UTF8 encoded String in Java but not in Python
39,719,737
<p>When I run the following in Python 2.7.6, I get an exception:</p> <pre><code>import base64 some_bytes = b"\x80\x02\x03" print ("base 64 of the bytes:") print (base64.b64encode(some_bytes)) try: print (some_bytes.decode("utf-8")) except Exception as e: print(e) </code></pre> <p>The output:</p> <pre><code>b...
-1
2016-09-27T08:27:29Z
39,720,401
<p>This is because the String constructor in Java just doesn't throw exceptions in the case of invalid characters. See documentation <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#String-byte:A-java.nio.charset.Charset-" rel="nofollow">here</a></p> <blockquote> <p>public String(byte[] bytes,...
0
2016-09-27T09:00:18Z
[ "java", "python", "utf-8", "character-encoding" ]
Exception in worker process: No module named wsgi
39,719,839
<p>I am trying to deploy my Django web app on heroku. An Application error message appears to me when I try to open it.</p> <p>this is my log:</p> <pre><code>2016-09-27T07:56:16.836350+00:00 heroku[web.1]: State changed from crashed to starting 2016-09-27T07:56:21.160909+00:00 heroku[web.1]: Starting process with com...
0
2016-09-27T08:32:09Z
39,720,549
<p>change your procfile to :</p> <p><code>web: gunicorn blog.wsgi --log-file -</code></p>
2
2016-09-27T09:06:57Z
[ "python", "django", "heroku", "wsgi" ]
PyQt5 QComboBox in QTableWidget
39,720,036
<p>I have really tried everything to solve my problem but it doesn't work. Here is my simple code to put Comboboxes in each row of the table. It actually works for setItem(), which I use to put strings into each row. But it doesn't work with setCellWidget(), which I have to use to put the Combobox into the rows. It is ...
0
2016-09-27T08:42:10Z
39,720,197
<p>You create a single combo box, so when you put it into a cell, it is removed from the prevoius cell. You must create a combo box for each cell (in the <code>for</code> loop).</p> <p>Example:</p> <pre><code>attr = ['one', 'two', 'three', 'four', 'five'] i = 0 for j in attr: self.tableWidget.setItem(i, 0, QtWidg...
1
2016-09-27T08:50:14Z
[ "python", "qt", "pyqt5", "qtablewidget", "qcombobox" ]
numpy.cross and similiar functions: Do they allocate a new array on every call?
39,720,177
<p>When I use <code>numpy.cross</code>, it will <em>return</em> an array with the results. There's no way to compute <em>into</em> an existing array. The same holds for other functions.</p> <ol> <li>Isn't it extremely inefficient to allocate a new array upon each call?</li> <li>If so, is there a way to speed it up?</l...
1
2016-09-27T08:49:04Z
39,721,269
<p>There is an overhead with the function <code>np.cross</code> as it creates a new NumPy array. You can do <code>x = np.cross(x, y)</code> but it will not suppress the overhead.</p> <p>If you have a program where this is actually a problem (as diagnosed by profiling the program, for instance), you are better off turn...
2
2016-09-27T09:40:30Z
[ "python", "numpy" ]
numpy.cross and similiar functions: Do they allocate a new array on every call?
39,720,177
<p>When I use <code>numpy.cross</code>, it will <em>return</em> an array with the results. There's no way to compute <em>into</em> an existing array. The same holds for other functions.</p> <ol> <li>Isn't it extremely inefficient to allocate a new array upon each call?</li> <li>If so, is there a way to speed it up?</l...
1
2016-09-27T08:49:04Z
39,729,272
<p>The current version of <code>np.cross</code> (as of 1.9) takes great effort to avoid temporary arrays. Where possible is uses views of the inputs, even when it has to roll the axes. It creates the output array</p> <pre><code>cp = empty(shape, dtype) </code></pre> <p>and then takes care to perform calculation in-...
1
2016-09-27T15:58:31Z
[ "python", "numpy" ]
Meaning of the "@package" decorator in Python
39,720,191
<p>I'm trying to understand a class method definition which reads similar to the following:</p> <pre><code>@package(type='accounts', source='system') def get(self, [other arguments]): [function body] </code></pre> <p>What is the meaning of the <code>@package</code> decorator? I was unable to find documentation on...
-1
2016-09-27T08:49:55Z
39,720,308
<p>There is no default <code>package</code> decorator in the Python standard library.</p> <p>A decorator is <em>just a simple expression</em>; there will be a <code>package()</code> callable in the same module (either defined there as a function or class, or imported from another module).</p> <p>The line <code>@packa...
3
2016-09-27T08:55:32Z
[ "python" ]
Can this chained comparison really be simplified like PyCharm claims?
39,720,220
<p>I have a class with two integer attributes, <code>_xp</code> and <code>level</code>. I have a <code>while</code> loop which compares these two to make sure they're both positive:</p> <pre><code>while self.level &gt; 0 and self._xp &lt; 0: self.level -= 1 self._xp += self.get_xp_quota() </code></pre> <p>My ...
0
2016-09-27T08:51:28Z
39,720,359
<p>IIRC, you could rewrite this as:</p> <pre><code>while self._xp &lt; 0 &lt; self.level: self.level -= 1 self._xp += self.get_xp_quota() </code></pre> <p>as per your reference above. It doesn't really matter that there's 2 different attributes or the same variable, ultimately you are simply comparing the val...
3
2016-09-27T08:58:12Z
[ "python", "python-3.x", "comparison", "pycharm" ]
Python--Sending a email with a attachment
39,720,248
<p>I am working on a big project, that includes a database for remembering users. il skip the details, but my client wants me to include a function by wich he can backup all the user data and other files.</p> <p>I was thinking of a email, (since the project is a android app) and I was trying to figure out how you coul...
0
2016-09-27T08:52:37Z
39,721,062
<p>Hi this is the code I used... it turns out that ubunto uses a different way of sending a email than windows.</p> <pre><code>import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.base import MIMEBase from email import encoders import os boodskap = MI...
0
2016-09-27T09:30:49Z
[ "python", "python-2.7", "email", "smtplib" ]
python read multiple serial ports
39,720,315
<p>I am trying to read from multiple serial ports in python. But contrary to <a href="http://stackoverflow.com/questions/27484250/python-pyserial-read-data-form-multiple-serial-ports-at-same-time">this</a> thread I want to be able to change the number of ports dynamically (reading it via command line option).</p> <p>M...
0
2016-09-27T08:55:47Z
39,723,725
<p>I didn't quite clearly understood what you are trying to do, but if I had a file like:</p> <pre><code>'/dev/ttyUSB0',4800 '/dev/ttyUSB1',4801,'/dev/ttyUSB3',4803 </code></pre> <p>and want to read it and store as a list, a way to go would be:</p> <pre><code>with open('ports.txt') as f: lines = f.read().replac...
1
2016-09-27T11:39:50Z
[ "python", "serial-port", "readfile" ]
python read multiple serial ports
39,720,315
<p>I am trying to read from multiple serial ports in python. But contrary to <a href="http://stackoverflow.com/questions/27484250/python-pyserial-read-data-form-multiple-serial-ports-at-same-time">this</a> thread I want to be able to change the number of ports dynamically (reading it via command line option).</p> <p>M...
0
2016-09-27T08:55:47Z
39,724,823
<p>Your config file format is very simple and can easily be parsed without numpy. You can use simple string splitting to load each port definition.</p> <pre><code>serial_ports = [] with open('ports') as f: for line in f: port, baud = line.split(',') serial_ports.append(serial.Serial(port, int(baud)...
2
2016-09-27T12:34:36Z
[ "python", "serial-port", "readfile" ]
Pandas `read_json` function converts strings to DateTime objects even the `convert_dates=False` attr is specified
39,720,332
<p>I have the next JSON:</p> <pre><code>[{ "2016-08": 1355, "2016-09": 2799, "2016-10": 2432, "2016-11": 0 }, { "2016-08": 1475, "2016-09": 1968, "2016-10": 1375, "2016-11": 0 }, { "2016-08": 3097, "2016-09": 1244, "2016-10": 2339, "2016-11": 0 }, { "2016-08": 1305, "2016-09": 1625, "2016-10": 3038, "2016-11": 0 }, { ...
1
2016-09-27T08:56:53Z
39,720,414
<p>You need parameter <code>convert_axes=False</code> in <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_json.html" rel="nofollow"><code>read_json</code></a>:</p> <pre><code>df = pd.read_json('file.json', convert_axes=False) print (df) 2016-08 2016-09 2016-10 2016-11 0 1355 279...
2
2016-09-27T09:00:58Z
[ "python", "json", "python-3.x", "pandas", "jupyter-notebook" ]
How to make screenshot while showing video from cam?
39,720,344
<pre><code>#Importing necessary libraries, mainly the OpenCV, and PyQt libraries import cv2 import numpy as np import sys from PyQt5 import QtCore from PyQt5 import QtWidgets from PyQt5 import QtGui from PyQt5.QtCore import pyqtSignal class ShowVideo(QtCore.QObject): #initiating the built in camera camera_por...
0
2016-09-27T08:57:22Z
39,737,798
<p>You can use cv2.waitKey() for the same, as shown below:</p> <pre><code>while run_video: ret, image = self.camera.read() if(cv2.waitKey(10) &amp; 0xFF == ord('s')): cv2.imwrite("screenshot.jpg",image) </code></pre> <p>(I'm guessing that by the term "screenshot", you mean the cam...
1
2016-09-28T03:58:00Z
[ "python", "opencv", "pyqt5" ]
How to disable syntax warning for the latest sublime text 3?
39,720,413
<p>I have updated the latest Sublime Text 3 build (3124), but when I save the changes of python file, the warning will shown as below:</p> <p><a href="http://i.stack.imgur.com/zsi92.png" rel="nofollow"><img src="http://i.stack.imgur.com/zsi92.png" alt="enter image description here"></a></p> <p>I installed the <a href...
0
2016-09-27T09:00:52Z
39,734,142
<p>Disable the SublimeLinter <code>show_errors_on_save</code> setting.</p> <p><code>Menu &gt; Preferences &gt; Package Settings &gt; SublimeLinter &gt; Setting - User</code></p> <blockquote> <p>Packages/User/SublimeLinter.sublime-settings</p> </blockquote> <pre><code>{ // This setting determines if a Quick Pan...
1
2016-09-27T20:53:59Z
[ "python", "sublimetext3" ]
Pandas DatetimeIndex strange behaviour
39,720,641
<p>I handle a DataFrame, which index is string, year-month, for example:</p> <pre><code>index = ['2007-01', '2007-03', ...] </code></pre> <p>however, the index is not full. e.g. <code>2007-02</code> is missing. What I want is to reindex the DataFrame with full index.</p> <p>What I have tried:</p> <pre><code>In [60]...
1
2016-09-27T09:11:16Z
39,720,677
<p>I think you need add parameter <code>freq='MS'</code> if need frequency first day of months:</p> <pre><code>print (pd.DatetimeIndex(start='2007-01', end='2007-12', freq='MS')) DatetimeIndex(['2007-01-01', '2007-02-01', '2007-03-01', '2007-04-01', '2007-05-01', '2007-06-01', '2007-07-01', '2007-08-01'...
2
2016-09-27T09:12:49Z
[ "python", "pandas", "date-range", "period", "datetimeindex" ]
Laplace transform initial conditions
39,720,658
<p>How to define initial conditions for Laplace transform in Sympy? For example:</p> <pre><code>t,s = symbols('t s') x = Function('x')(t) laplace_transform(diff(x,t),t,s cond=(x(0) = 1)) </code></pre> <p>So the output would be:</p> <pre><code>s*L(x) - 1 </code></pre>
1
2016-09-27T09:11:58Z
39,753,631
<p>Laplace transforms of undefined functions are not yet implemented. There is an <a href="https://github.com/sympy/sympy/issues/7219" rel="nofollow">issue</a> tracking this. Perhaps the simple <a href="https://github.com/sympy/sympy/issues/7219#issuecomment-154768904" rel="nofollow">workaround implementation</a> in th...
0
2016-09-28T17:03:48Z
[ "python", "sympy" ]
How to color a 3d grayscale image in python
39,720,735
<p>I want to color a pixel in 3d</p> <pre><code>import numpy as np import matplotlib.pyplot as plt im = np.random.randint(0, 255, (16, 16)) I = np.dstack([im, im, im]) x = 5 y = 5 I[x, y, :] = [1, 0, 0] plt.imshow(I, interpolation='nearest' ) plt.imshow(im, interpolation='nearest', cmap='Greys') </code></pre> <p>This...
1
2016-09-27T09:15:31Z
39,722,684
<pre><code>import numpy as np import matplotlib.pyplot as plt np.random.seed(4) im = np.random.randint(0, 255, (16, 16)) I = np.dstack([im, im, im]) I[np.logical_and(np.logical_and(I[:, :, 0]==15, I[:, :, 1]==15), I[:, :, 2]==15)] = [0, 1, 0] plt.figure() plt.imshow(I, interpolation='nearest' ) plt.figure() plt.imshow(...
0
2016-09-27T10:48:54Z
[ "python", "image", "image-processing", "grayscale" ]
Why is my VotingClassifier accuracy less than my individual classifier?
39,720,836
<p>I am trying to create an ensemble of three classifiers (Random Forest, Support Vector Machine and XGBoost) using the VotingClassifier() in scikit-learn. However, I find that the accuracy of the ensemble actually decreases instead of increasing. I can't figure out why. </p> <p>Here is the code:</p> <pre><code>from ...
3
2016-09-27T09:20:19Z
39,733,613
<p>VotingClassifiers are not always guaranteed to have better performance, especially when using soft voting if you have poorly calibrated base models. </p> <p>For a contrived example, say all of the models are really wrong when they are wrong (say give a probability of .99 for the incorrect class) but are only slight...
4
2016-09-27T20:19:52Z
[ "python", "machine-learning", "scikit-learn", "xgboost", "ensemble-learning" ]
Load csv file based on selection
39,720,841
<p>Before I put my question here I've looked everywhere and tried everything to find a solution but couldn't find one.</p> <p>I've build a simple GUI in Tkinter. The goal is to first make a selection based on choises in a dropdown box. In my example the subject is "Tennis".</p> <p>My goal is that the user can first s...
0
2016-09-27T09:20:36Z
39,724,414
<p>It is important to understand what your code does. What you were trying to do is open a file at the time of the start of your program while the filename can only be known, after some time when the user has selected an option. Therefore you need to make sure that the <code>file.open()</code> is only executed when the...
0
2016-09-27T12:15:53Z
[ "python", "csv" ]
Django filtering on foreign key properties
39,720,884
<p>I'm trying to filter a table in Django based on the value of a particular field of a foreign key.</p> <p>my models are:</p> <pre><code>class Retailer(SCOPEModel): """ A business or person that exchanges goods for vouchers with recipients """ office = models.ForeignKey(Office, related_name='...
0
2016-09-27T09:22:31Z
39,720,980
<p>Apparently, not all your <code>PointOfSaleTerminalAssignment</code> instances has an <code>assigned_retailer</code>, as the <em>FK</em> field can take <em>NULL</em> values. </p> <p>You can however <em>safely navigate</em> the attributes of each <code>retailer</code> only if the retailer is not <code>None</code> by ...
1
2016-09-27T09:26:42Z
[ "python", "django" ]
Django filtering on foreign key properties
39,720,884
<p>I'm trying to filter a table in Django based on the value of a particular field of a foreign key.</p> <p>my models are:</p> <pre><code>class Retailer(SCOPEModel): """ A business or person that exchanges goods for vouchers with recipients """ office = models.ForeignKey(Office, related_name='...
0
2016-09-27T09:22:31Z
39,721,010
<p>Your <code>assigned_retailer</code> can be blank and null. So first of all check if there is assignment. </p> <pre><code>from maidea.apps.office.models import Office from maidea.apps.redemption.models import Retailer, PointOfSaleTerminalAssignment pos = PointOfSaleTerminalAssignment.objects.filter(office__slug='s...
1
2016-09-27T09:28:11Z
[ "python", "django" ]
Integration Github with web2py web application
39,720,949
<p>How we can integrate GitHub with "web2py" project.I want to connect may application to github.</p>
-1
2016-09-27T09:25:21Z
39,878,821
<p>You should get the json request as a Storage object using:</p> <pre><code>request.post_vars </code></pre>
0
2016-10-05T16:02:22Z
[ "python", "python-2.7", "github", "web2py", "web2py-modules" ]
Python - Put a list in a threading module
39,720,995
<p>I want to put a list into my threading script, but I am facing a problem.</p> <p>Contents of list file (example):</p> <pre><code>http://google.com http://yahoo.com http://bing.com http://python.org </code></pre> <p>My script:</p> <pre><code>import codecs import threading import sys import requests from time impo...
0
2016-09-27T09:27:29Z
39,723,226
<p>Can you please clarify what elaborate on exactly what you're trying to achieve.</p> <p>I'm guessing that you're trying to request urls to load into a web browser or the terminal...</p> <p>Also you shouldn't need to put the urls into a list because when you opened up the file containing the urls, it automatically s...
0
2016-09-27T11:14:58Z
[ "python", "multithreading", "list" ]
Pandas Join Two Tables Based On Time Condition
39,721,008
<p>I'm trying to join two tables in Pandas based on timestamp. Basically the structure looks something like this:</p> <p>Table 2</p> <pre><code>Timestamp Truck MineX MineY 2016-08-27 01:10 CT77 -11346.36655 -650404.405 2016-08-27 01:12 CT45 -11596.88137 -648294.056 2016-08-27...
1
2016-09-27T09:28:00Z
39,721,075
<pre><code>import pandas as pd df=pd.merge(left=Table1,right=Table2, left_on=['TimeStamp1'], right_on=['TimeStamp2']) </code></pre>
0
2016-09-27T09:31:37Z
[ "python", "pandas" ]
Pandas Join Two Tables Based On Time Condition
39,721,008
<p>I'm trying to join two tables in Pandas based on timestamp. Basically the structure looks something like this:</p> <p>Table 2</p> <pre><code>Timestamp Truck MineX MineY 2016-08-27 01:10 CT77 -11346.36655 -650404.405 2016-08-27 01:12 CT45 -11596.88137 -648294.056 2016-08-27...
1
2016-09-27T09:28:00Z
39,723,087
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a>:</p> <pre><code>df = pd.merge(df1, df2, on='Truck', how='left') print (df) Truck LoadLocation Tonnes ArriveTimestamp Timestamp \ 0 CT70 338-001 261.000 2016...
1
2016-09-27T11:07:19Z
[ "python", "pandas" ]
How to set a cron job on Skygear to run every 12 hours?
39,721,031
<p>Trying to set a cron job on my Skygear python cloud code, but not sure what I should enter in the decorator. I only know that it will work for units in second, but how to schedule a job to run every 12 hours? It is hard to calculate the seconds every time.</p> <p>My code is like this, the function is to call a POST...
1
2016-09-27T09:29:00Z
39,721,174
<p>It seems like <code>skygear.every</code> also <a href="https://docs.skygear.io/cloud-code/guide/scheduled" rel="nofollow">accepts crontab notation</a>… so <a href="http://crontab.guru/#0_*/12_*_*_*" rel="nofollow"><code>0 */12 * * *</code></a> could also do the trick.</p> <p>Edit: Reading the <a href="https://git...
2
2016-09-27T09:35:51Z
[ "python", "cron", "crontab", "cloud-code", "skygear" ]
How to overwrite ORM method unlink from a custom module?
39,721,250
<p>I want to overwrite the <code>unlink</code> method of <code>stock.move</code> model. The reason is that I want to remove an OSV exception which warns about a forbidden action, and replace it with other message and other condition.</p> <p>This is the original code:</p> <pre><code>def unlink(self, cr, uid, ids, cont...
1
2016-09-27T09:39:40Z
39,729,472
<p>Not using a <code>super()</code> call can have unexpected behaviour. You could call <code>models.Model.unlink()</code>, but that will skip all <code>unlink()</code> extensions for <code>stock.move</code> by other modules (even Odoo S.A. apps/modules). In your case it would be:</p> <pre><code>class StockMove(models....
0
2016-09-27T16:07:42Z
[ "python", "python-2.7", "openerp", "odoo-8" ]
Display select Mysql query in python with output nice and readable
39,721,290
<p>I need python script for display sql query with nice output and readable this not readable for heavy tables...</p> <pre><code>cnx = mysql.connector.connect(user='root', password='*****', host='127.0.0.1', database='dietetique') c = cnx.cursor() sys.stdout ...
0
2016-09-27T09:41:21Z
39,721,591
<pre><code>import pypyodbc ID=2 ConnectionDtl='Driver={SQL Server};Server=WIN7-297;Database=AdventureWorks2014;trusted_connection=yes' connection = pypyodbc.connect(ConnectionDtl) print("Retrieve row based on [FirstName]='Mani'") cursor = connection.cursor() SQLCommand = ("SELECT [FirstName],[LastName] " ...
0
2016-09-27T09:54:24Z
[ "python", "mysql", "sql", "python-2.7", "web" ]
Display select Mysql query in python with output nice and readable
39,721,290
<p>I need python script for display sql query with nice output and readable this not readable for heavy tables...</p> <pre><code>cnx = mysql.connector.connect(user='root', password='*****', host='127.0.0.1', database='dietetique') c = cnx.cursor() sys.stdout ...
0
2016-09-27T09:41:21Z
39,721,593
<p>you can execute the same code just by adding limits to the Sql Query.</p> <pre><code>cnx = mysql.connector.connect(user='root', password='*****', host='127.0.0.1', database='dietetique') c = cnx.cursor() sys.stdout = open('mysql_data.log', 'w') limitvalue=1000 for offsetv...
0
2016-09-27T09:54:27Z
[ "python", "mysql", "sql", "python-2.7", "web" ]
Tornado gen.sleep add delay
39,721,305
<p>I'm trying to add a delay between requests in an asynchronous way. When I use Tornado gen.sleep(x) my function (launch) doesn't get executed. If I remove <strong>yield</strong> from <strong>yield gen.sleep(1.0)</strong>, function is called, but no delay is added. How to add delay between requests in my for loop? I ...
0
2016-09-27T09:42:00Z
39,725,846
<p>Tornado coroutines have two components:</p> <ol> <li>They contain "yield" statements</li> <li>They are decorated with "gen.coroutine"</li> </ol> <p>Use the "coroutine" decorator on your "launch" function:</p> <pre><code>@gen.coroutine def launch(self): </code></pre> <p>Run a Tornado coroutine from start to finis...
1
2016-09-27T13:23:55Z
[ "python", "asynchronous", "tornado" ]
.apply(pd.to_numeric) returns error message
39,721,559
<p>I have a dataframe with two columns I want to convert to numeric type. I use the following code:</p> <pre><code>df[["GP","G"]]=df[["GP","G"]].apply(pd.to_numeric) </code></pre> <p>Python returns the following error message:</p> <pre><code>File "C:\Users\Alexandros_7\Anaconda3\lib\site-packages\pandas\core\frame....
0
2016-09-27T09:52:36Z
39,721,977
<p>Your code will only work if all the data can be parsed to numeric. </p> <p>If not, there is at least one value in dataframe which is not convertible to numeric. You can use <code>errors</code> parameter according to your choice in such case. Here is an example.</p> <pre><code>&gt;&gt;&gt; df = pd.DataFrame({'A' : ...
1
2016-09-27T10:12:52Z
[ "python" ]
Capturing text with Python regular expressions
39,721,578
<p>I've been having a bit of trouble with capturing strings between html tags using Python regular expressions. I've been trying to capture the string "example link 2" from the string below:</p> <pre><code>&lt;link&gt;example link 1&lt;/link&gt; &lt;item&gt; &lt;link&gt;example link 2&lt;/link&gt; &lt;/item&gt; <...
-1
2016-09-27T09:53:32Z
39,721,742
<p>You need to add 'g' modifier at the end. For example the regex should look like: </p> <pre><code>/(?&lt;=\&lt;link&gt;)(.*)(?=&lt;\/link&gt;)/g </code></pre> <p>The 'g' modifier tells the engine not to stop after the first match has been found, but rather to continue until no more matches can be found.<br> Demo <...
0
2016-09-27T10:01:29Z
[ "python", "regex", "python-2.7" ]
Robocopy based on extensions
39,721,614
<p>Currently I am using robocopy in python to copy out files based on extensions.</p> <p>The code is below:</p> <pre><code>call(["robocopy","C:\",dest,"*.7z","/S","/COPYALL"]) </code></pre> <p>But in a scenario where there is no 7z files, it still creates the dest directory.</p> <p>Is there a way to only create the...
0
2016-09-27T09:55:34Z
39,721,701
<p>Why not check if there are 7z files before calling the copy utility?</p> <pre><code>import glob if glob.glob("*.7z"): call(["robocopy","C:\",dest,"*.7z","/S","/COPYALL"]) </code></pre>
1
2016-09-27T09:59:46Z
[ "python", "robocopy" ]
Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )
39,721,639
<p>I am using suds-client for soap wsdl services. When i try to setup the suds client for soap service, I get the Type not found error. I search everywhere. There are many unanswered questions with the same error. I am adding the links as <a href="http://stackoverflow.com/questions/33611461/typenotfound-type-not-found-...
3
2016-09-27T09:56:27Z
39,735,604
<p>I have been searching for the answer and finally I found a solution that solved my problem. </p> <p>We Just need to add the missing schema to the imports of suds. Below is the code</p> <pre><code>from suds.xsd.doctor import Import, ImportDoctor imp=Import('http://www.w3.org/2001/XMLSchema',location='http://www.w3....
3
2016-09-27T22:59:47Z
[ "python", "python-2.7", "soap", "wsdl", "suds" ]
Convert Pandas dataframe to Dask dataframe
39,721,800
<p>Suppose I have pandas dataframe as:</p> <pre><code>df=pd.DataFrame({'a':[1,2,3],'b':[4,5,6]}) </code></pre> <p>When I convert it into dask dataframe what should <code>name</code> and <code>divisions</code> parameter consist of:</p> <pre><code>from dask import dataframe as dd sd=dd.DataFrame(df.to_dict(),division...
2
2016-09-27T10:04:08Z
39,722,445
<p>I think you can use <a href="http://dask.pydata.org/en/latest/dataframe-api.html#dask.dataframe.from_pandas" rel="nofollow"><code>dask.dataframe.from_pandas</code></a>:</p> <pre><code>from dask import dataframe as dd sd = dd.from_pandas(df, npartitions=3) print (sd) dd.DataFrame&lt;from_pa..., npartitions=2, divis...
2
2016-09-27T10:36:21Z
[ "python", "pandas", "dataframe", "data-conversion", "dask" ]
Use dictwriter and write unstructured data into csv file using python
39,721,841
<p><a href="http://i.stack.imgur.com/Hb2z5.jpg" rel="nofollow">Output CSv file</a>I am currently trying to put the data from a file into csv file using python. My data looks as follows:</p> <pre><code>data_list{} = [{'row': '0', 't0': '8.69E-005', 'elems': ' 4 96 187 ', 'Tspan': '5E-006', 'NP': '625','wave0': '123.65 ...
0
2016-09-27T10:05:46Z
39,723,052
<p>It looks like you are after the dictionary inside your <code>data_list</code> variable. In order to get your desired output, you are going to need to do a little bit of work:</p> <p>Your list of one dictionary:</p> <pre><code>data_list = [{'row': '0', 't0': '8.69E-005', 'elems': ' 4 96 187 ', 'Tspan': '5E-006', 'N...
0
2016-09-27T11:05:42Z
[ "python", "csv" ]
ConnectionURI MSSQL Python
39,721,845
<p>I'm coding a little something in Python. I need to get some data from a MicrosoftSQL database and convert it to a JSONObject. And i think i have some problems with the ConnectionForURI. I'm using simplejson and sqlobject libraries.</p> <p>Im not sure exactly how that string is supposed to look like. </p> <p>I'v tr...
0
2016-09-27T10:06:02Z
39,721,883
<pre><code>##1st option cnxn = pypyodbc.connect("dsn=mydsn;Trusted_Connection=Yes") ##mydsn=DSN Name ##2nd option ConnectionDtl='Driver={SQL Server};Server=WIN7-297;Database=AdventureWorks2014;trusted_connection=yes' connection = pypyodbc.connect(ConnectionDtl) </code></pre>
-1
2016-09-27T10:08:16Z
[ "python", "sql-server", "database-connection", "simplejson", "sqlobject" ]
How to save state of execution in python
39,721,867
<p>i have an assignment in python for which some complicated idea is needed. please help me . . . . . suppose initially i have a file to load into an array 'arr01' then i have two python source code file say 'a.py' and 'b.py'.</p> <p>a.py takes some element from that loaded array 'arr01' and modifies the array 'arr01...
-1
2016-09-27T10:07:11Z
39,722,875
<p>The following approach should get you there:</p> <ul> <li>define in <code>a.py</code> a class with a method that provides data from arr01 and tracks what has been sent</li> <li><code>import a</code> in <code>b.py</code></li> <li>call the class method from <code>a</code> in your code in <code>b</code></li> </ul>
0
2016-09-27T10:57:28Z
[ "python", "python-2.7", "python-3.x" ]
How to save state of execution in python
39,721,867
<p>i have an assignment in python for which some complicated idea is needed. please help me . . . . . suppose initially i have a file to load into an array 'arr01' then i have two python source code file say 'a.py' and 'b.py'.</p> <p>a.py takes some element from that loaded array 'arr01' and modifies the array 'arr01...
-1
2016-09-27T10:07:11Z
39,722,917
<p><code>from a import function_name</code></p> <p><code>from b import other_function_name</code></p> <p>From here, you can use a.py and b.py functions in this python file.</p> <p>E.g.</p> <h1>a.py</h1> <p><code>def say_hi(): print 'hello' </code></p> <h1>b.py</h1> <p><code>from a import say_hi say_hi()</cod...
0
2016-09-27T10:59:30Z
[ "python", "python-2.7", "python-3.x" ]
How to run multiple commands synchronously from one subprocess.Popen command?
39,721,924
<p>Is it possible to execute an arbitrary number of commands in sequence using the same subprocess command?</p> <p>I need each command to wait for the previous one to complete before executing and I need them all to be executed in the same session/shell. I also need this to work in Python 2.6, Python 3.5. I also need ...
0
2016-09-27T10:10:09Z
39,722,419
<p>One possible solution, looks like its running in same shell:</p> <pre><code>subprocess.Popen('echo start;echo mid;echo end', shell=True) </code></pre> <p>Note - If you pass your command as a string then shell has to be True Note - This is working on linux only, you may have to find something similar way out on win...
0
2016-09-27T10:35:16Z
[ "python", "subprocess", "python-3.5", "python-2.6" ]
How to run multiple commands synchronously from one subprocess.Popen command?
39,721,924
<p>Is it possible to execute an arbitrary number of commands in sequence using the same subprocess command?</p> <p>I need each command to wait for the previous one to complete before executing and I need them all to be executed in the same session/shell. I also need this to work in Python 2.6, Python 3.5. I also need ...
0
2016-09-27T10:10:09Z
39,722,695
<p>This one works in python 2.7 and should work also in windows. Probably some small refinement is needed for python >3. </p> <p>The produced output is (using date and sleep it is easy to see that the commands are executed in row):</p> <pre><code>&gt;&gt;&gt;Die Sep 27 12:47:52 CEST 2016 &gt;&gt;&gt; &gt;&gt;&gt;Die ...
0
2016-09-27T10:49:43Z
[ "python", "subprocess", "python-3.5", "python-2.6" ]
How to run multiple commands synchronously from one subprocess.Popen command?
39,721,924
<p>Is it possible to execute an arbitrary number of commands in sequence using the same subprocess command?</p> <p>I need each command to wait for the previous one to complete before executing and I need them all to be executed in the same session/shell. I also need this to work in Python 2.6, Python 3.5. I also need ...
0
2016-09-27T10:10:09Z
39,725,789
<p>Here is a function (and main to run it) that I use. I would say that you can use it for your problem. And it is flexible.</p> <pre><code># processJobsInAList.py # 2016-09-27 7:00:00 AM Central Daylight Time import win32process, win32event def CreateMyProcess2(cmd): ''' create process width no window that...
1
2016-09-27T13:21:28Z
[ "python", "subprocess", "python-3.5", "python-2.6" ]
How to run multiple commands synchronously from one subprocess.Popen command?
39,721,924
<p>Is it possible to execute an arbitrary number of commands in sequence using the same subprocess command?</p> <p>I need each command to wait for the previous one to complete before executing and I need them all to be executed in the same session/shell. I also need this to work in Python 2.6, Python 3.5. I also need ...
0
2016-09-27T10:10:09Z
39,727,561
<p>If you want to execute many commands one after the other in the same <em>session/shell</em>, you must start a shell and feed it with all the commands, one at a time followed by a new line, and close the pipe at the end. It makes sense if some commands are not true processes but shell commands that could for example ...
2
2016-09-27T14:37:26Z
[ "python", "subprocess", "python-3.5", "python-2.6" ]