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 |
|---|---|---|---|---|---|---|---|---|---|
grouping related data in csv excel file | 39,957,573 | <p>this is a csv excel file</p>
<pre><code> Receipt Name Address Date Time Total
25007 A ABC pte ltd 3/7/2016 10:40 12.30
25008 A ABC ptd ltd 3/7/2016 11.30 6.70
25009 B CCC ptd ltd 4/7/2016 07.35 23.40
25010 A ABC pte ltd 4/7/2016 12... | 2 | 2016-10-10T11:47:50Z | 39,957,721 | <p>It can be done pretty easily using Pandas module:</p>
<pre><code>import pandas as pd
df = pd.read_csv('/path/to/file.csv')
df.groupby(['Name','Date']).Time.apply(list).reset_index().to_csv('d:/temp/out.csv', index=False)
</code></pre>
<p>D:\temp\out.csv:</p>
<pre><code>Name,Date,Time
A,3/7/2016,"['10:40', '11.3... | -1 | 2016-10-10T11:56:08Z | [
"python",
"regex",
"group"
] |
grouping related data in csv excel file | 39,957,573 | <p>this is a csv excel file</p>
<pre><code> Receipt Name Address Date Time Total
25007 A ABC pte ltd 3/7/2016 10:40 12.30
25008 A ABC ptd ltd 3/7/2016 11.30 6.70
25009 B CCC ptd ltd 4/7/2016 07.35 23.40
25010 A ABC pte ltd 4/7/2016 12... | 2 | 2016-10-10T11:47:50Z | 39,959,012 | <p>If you don't want to use Pandas, this is a possible solution. It's not the most elegant since your csv format is relatively clunky to parse. If you can change the format to use a non-whitespace field separator, using a proper csv parsing library (like <code>pandas</code> or Python's built-in <code>csv</code> module)... | -1 | 2016-10-10T13:06:13Z | [
"python",
"regex",
"group"
] |
grouping related data in csv excel file | 39,957,573 | <p>this is a csv excel file</p>
<pre><code> Receipt Name Address Date Time Total
25007 A ABC pte ltd 3/7/2016 10:40 12.30
25008 A ABC ptd ltd 3/7/2016 11.30 6.70
25009 B CCC ptd ltd 4/7/2016 07.35 23.40
25010 A ABC pte ltd 4/7/2016 12... | 2 | 2016-10-10T11:47:50Z | 39,960,675 | <p>Presuming your data actually looks like:</p>
<pre><code>Receipt,Name,Address,Date,Time,Items
25007,A,ABC pte ltd,4/7/2016,10:40,"Cheese, Cookie, Pie"
25008,A,CCC pte ltd,4/7/2016,11:30,"Cheese, Cookie"
25009,B,CCC pte ltd,4/7/2016,07:35,"Chocolate"
25010,A,CCC pte ltd,4/7/2016,12:40," Butter, Cookie"
</code></pre>
... | 0 | 2016-10-10T14:31:54Z | [
"python",
"regex",
"group"
] |
Count each occurrence of alphabet and store it in a list in Python 3 | 39,957,615 | <p>Suppose I have a string s </p>
<pre><code>s = "ebber"
</code></pre>
<p>I want a list x, where x = [1,1,2,2,1]<br>
We see the first occurrence of e so our first element in list x is 1, then we see the first occurrence of b so our next element in our list is 1, then we see our second occurrence of b so our next... | -1 | 2016-10-10T11:50:48Z | 39,958,154 | <pre><code>from collections import defaultdict
def count(s):
d, ls = defaultdict(int), []
for e in s:
d[e] += 1 # increment counter of char
ls.append(d[e]) # add counter
return ls
count("ebber") # [1, 1, 2, 2, 1]
</code></pre>
| 0 | 2016-10-10T12:19:24Z | [
"python"
] |
Creating zip file from byte | 39,957,629 | <p>I'm sending byte string of a zip file from client side using <code>JSZip</code> and need to convert it back to zip on server side. the code I've tried isn't working.</p>
<pre><code>b = bytearray()
b.extend(map(ord, request.POST.get("zipFile")))
zipPath = 'uploadFile' + str(uuid.uuid4()) + '.zip'
myzip = zipfile.Zi... | 0 | 2016-10-10T11:51:29Z | 39,958,183 | <p>Haven't tried it, but you could use <a href="https://docs.python.org/3/library/io.html#buffered-streams" rel="nofollow"><code>io.BytesIO</code></a> to construct a Buffered Stream
with your bytes and then create your zip file like so:</p>
<pre><code>import io
with ZipFile('my_file.zip', 'w') as myzip:
myzip.wr... | 1 | 2016-10-10T12:20:54Z | [
"python",
"python-3.x",
"zipfile"
] |
Creating zip file from byte | 39,957,629 | <p>I'm sending byte string of a zip file from client side using <code>JSZip</code> and need to convert it back to zip on server side. the code I've tried isn't working.</p>
<pre><code>b = bytearray()
b.extend(map(ord, request.POST.get("zipFile")))
zipPath = 'uploadFile' + str(uuid.uuid4()) + '.zip'
myzip = zipfile.Zi... | 0 | 2016-10-10T11:51:29Z | 39,958,539 | <p>JSZip already made a zip archive. The zipfile module is for accessing zip file contents, but you don't need to parse it to store it. In addition, bytearray can be created directly from strings so the map(ord,) is superfluous, and write can handle strings as well (bytearray is for handling numeric binary data or maki... | 2 | 2016-10-10T12:40:59Z | [
"python",
"python-3.x",
"zipfile"
] |
Creating zip file from byte | 39,957,629 | <p>I'm sending byte string of a zip file from client side using <code>JSZip</code> and need to convert it back to zip on server side. the code I've tried isn't working.</p>
<pre><code>b = bytearray()
b.extend(map(ord, request.POST.get("zipFile")))
zipPath = 'uploadFile' + str(uuid.uuid4()) + '.zip'
myzip = zipfile.Zi... | 0 | 2016-10-10T11:51:29Z | 39,958,763 | <p><a href="https://docs.python.org/2/library/zipfile.html#zipfile.ZipFile.write" rel="nofollow"><code>ZipFile.write(filename, [arcname[, compress_type]])</code></a> takes the name of a local file to be added to the zip file. To write data from a <code>bytearray</code> or <code>bytes</code> object you need to use the <... | 1 | 2016-10-10T12:52:59Z | [
"python",
"python-3.x",
"zipfile"
] |
store multiple images efficiently in Python data structure | 39,957,657 | <p>I have several images (their number might increase over time) and their corresponding annotated images - let's call them image masks.</p>
<p>I want to convert the original images to Grayscale and the annotated masks to Binary images (B&W) and then save the gray scale values in a Pandas DataFrame/CSV file based ... | 0 | 2016-10-10T11:53:08Z | 39,973,094 | <p>I used several lists and list.append() for storing the image.</p>
<p>For finding the white regions in the black & white images I used <strong>cv2.findNonZero()</strong>.</p>
| 0 | 2016-10-11T08:19:00Z | [
"python",
"image",
"algorithm",
"opencv",
"image-processing"
] |
store multiple images efficiently in Python data structure | 39,957,657 | <p>I have several images (their number might increase over time) and their corresponding annotated images - let's call them image masks.</p>
<p>I want to convert the original images to Grayscale and the annotated masks to Binary images (B&W) and then save the gray scale values in a Pandas DataFrame/CSV file based ... | 0 | 2016-10-10T11:53:08Z | 39,973,408 | <p>PIL and Pillow are only marginally useful for this type of work. </p>
<p>The basic algorithm used for "finding and counting" objects like you are trying to do goes something like this: 1. Conversion to grayscale 2. Thresholding (either automatically via Otsu method, or similar, or by manually setting the threshold ... | 0 | 2016-10-11T08:38:44Z | [
"python",
"image",
"algorithm",
"opencv",
"image-processing"
] |
How can I update Entry without a "submit" button in Tkinter? | 39,957,699 | <p>So I have <code>Entries</code> which have some values assigned to them from a CFG File. I want to modify the CFG file when the <code>Entry</code> is updated, live, without a <code>submit</code> button; </p>
<p>Using <code><Key></code> binding will work but will take only the previous value, not the current on... | 1 | 2016-10-10T11:55:25Z | 39,957,960 | <p>You have this <code>key-press</code> in <code>event.char</code> so you can add it to text.</p>
| 1 | 2016-10-10T12:08:38Z | [
"python",
"user-interface",
"tkinter",
"keypress",
"entry"
] |
How can I update Entry without a "submit" button in Tkinter? | 39,957,699 | <p>So I have <code>Entries</code> which have some values assigned to them from a CFG File. I want to modify the CFG file when the <code>Entry</code> is updated, live, without a <code>submit</code> button; </p>
<p>Using <code><Key></code> binding will work but will take only the previous value, not the current on... | 1 | 2016-10-10T11:55:25Z | 39,957,975 | <p>I decided that <code><Key></code> was not the right option in my case and instead used <code><FocusOut></code>. This way, if you either change the value using the mouse or keyboard <code>TAB</code>, on focus out it will update it.</p>
| 0 | 2016-10-10T12:09:14Z | [
"python",
"user-interface",
"tkinter",
"keypress",
"entry"
] |
How can I update Entry without a "submit" button in Tkinter? | 39,957,699 | <p>So I have <code>Entries</code> which have some values assigned to them from a CFG File. I want to modify the CFG file when the <code>Entry</code> is updated, live, without a <code>submit</code> button; </p>
<p>Using <code><Key></code> binding will work but will take only the previous value, not the current on... | 1 | 2016-10-10T11:55:25Z | 39,958,033 | <p>You can use either </p>
<ul>
<li><code>focus-out</code></li>
<li><code>tab</code> or <code>enter</code> Key</li>
<li><code>key-release</code></li>
</ul>
<p>bindings to achieve that. </p>
<p>Also validation functions can help as they have previous and new values available. Please read the <a href="http://infohost.... | 3 | 2016-10-10T12:12:17Z | [
"python",
"user-interface",
"tkinter",
"keypress",
"entry"
] |
Order of elements from minidom getElementsByTagName | 39,957,761 | <p>Is the order for returned elements from Mindom <code>getElementsByTagName</code> the same as it is in document for elements in the same hierarchy / level?</p>
<pre><code> images = svg_doc.getElementsByTagName('image')
image_siblings = []
for img in images:
if img.parentNode.getAttribute('layerty... | 5 | 2016-10-10T11:57:52Z | 40,001,523 | <p>According to the code (in Python 2.7), the <code>getElementsByName</code> method relays on the <code>_get_elements_by_tagName_helper</code> function, which code is:</p>
<pre><code>def _get_elements_by_tagName_helper(parent, name, rc):
for node in parent.childNodes:
if node.nodeType == Node.ELEMENT_NODE ... | 4 | 2016-10-12T14:41:21Z | [
"python",
"xml",
"python-3.x",
"dom",
"minidom"
] |
Not a JPEG file: starts with 0xc3 0xbf | 39,957,815 | <p>I am trying to decode jpeg file using tf.image.decode_jpeg but it says its not a JPEG file. I don't know what the problem is.Can anyone help me to solve this problem?</p>
<p>This is my test code.</p>
<pre><code>import tensorflow as tf
path = "/root/PycharmProjects/mscoco/train2014/COCO_train2014_000000291797.jpg"... | -1 | 2016-10-10T12:00:44Z | 39,958,615 | <p>You're reading an image file as if it were a text file.</p>
<p>Just change the line:</p>
<pre><code>with open(path, "r", encoding="latin-1") as f:
</code></pre>
<p>with</p>
<pre><code>with open(path, "rb") as f:
</code></pre>
<p>To read the image as a binary ("rb" = Read Binary) file.</p>
| 2 | 2016-10-10T12:45:05Z | [
"python",
"tensorflow"
] |
Putting objects of the same class into a dictionary with different keys Python | 39,957,954 | <p>I have these Objects:</p>
<pre><code>class Object(object):
def __init__(self, name, *parameters):
self.name = name
self.parameters = parameters
def name(self):
return self.name
def parameters(self):
return self.parameters
class Parameter(object):
def __init__(sel... | 1 | 2016-10-10T12:08:27Z | 39,958,421 | <pre><code>data = {parameter: ''.join(['Value ', str(index)])
for index, parameter in enumerate(object.parameters)}
</code></pre>
<p>This will give you <code>{parameter0: 'Value 0', ...}</code> If you want to get the English words for the numbers, you;ll have to either roll your own function for it or use a... | 0 | 2016-10-10T12:34:26Z | [
"python",
"dictionary"
] |
ETL data from Bigquery to Redshift using Python | 39,958,028 | <p>I have this script in Python that set a variable with the result of a query, that runs in Google Bigquery (some library I do not use here, but I was testing converting json to a csv file):</p>
<pre><code>import httplib2
import datetime
import json
import csv
import sys
from oauth2client.service_account import Servi... | 0 | 2016-10-10T12:12:04Z | 40,086,244 | <p>To remove the 'u' before the fields:</p>
<pre><code>results = json.dumps(results)
</code></pre>
<p>Then, to transform the json variable in a csv file, I created:</p>
<pre><code>#Transform json variable to csv
results = json.dumps(results)
results = json.loads(results)
f = csv.writer(open("file.csv", "w"), delim... | 0 | 2016-10-17T12:20:06Z | [
"python",
"json",
"csv",
"etl"
] |
issue: python xml append element inside a for loop | 39,958,031 | <p>thanks for taking the time with this one.
i have an xml file with an element called selectionset. the idea is to take that element and modify some of the subelements attributes and tails, that part i have done.
the shady thing for me to get is why when i try to add the new subelements to the original (called selecti... | 0 | 2016-10-10T12:12:10Z | 39,961,260 | <p>Here's what I've been able to put together and it looks like it'll do what you're looking for. Here are the main differences: (1) This will iterate over multiple selectionset items (if you end up with more than one), (2) It creates a deepcopy of the element before modifying the values (I think you were always modify... | 0 | 2016-10-10T15:03:12Z | [
"python",
"xml"
] |
dask / pandas categorical transformation differences | 39,958,065 | <p>I am managing larger than memory csv files of mostly categorical data. Initially I used to create a large csv file, then read it via Pandas read_csv, convert to categorical and save into hdf5. Once into categorical format, it nicely fits in memory.</p>
<p>Files are growing and I moved to Dask. Same process though.<... | 1 | 2016-10-10T12:13:59Z | 40,027,860 | <p>This is solved in dask ver 0.11.1</p>
<p>See <a href="https://github.com/dask/dask/pull/1578" rel="nofollow">https://github.com/dask/dask/pull/1578</a></p>
| 0 | 2016-10-13T17:57:29Z | [
"python",
"csv",
"pandas",
"dask"
] |
Add elements in a matrix in python | 39,958,095 | <p>I have this matrix:</p>
<pre><code>mat = [[ 0 for x in range(row)] for y in range(column)]
</code></pre>
<p>I tried to add elements to the matrix:</p>
<pre><code>for x in range(row): # row is 2
for y in range(column): # column is 3
mat[x][y] = int(input("number: "))
</code></pre>
<p>but the shell re... | 2 | 2016-10-10T12:15:33Z | 39,958,153 | <p>The inner list should be based on columns:</p>
<pre><code>mat = [[ 0 for x in range(column)] for y in range(row)]
</code></pre>
<p>Here is an example:</p>
<pre><code>In [73]: row = 3
In [74]: column = 4
In [78]: mat = [[ 0 for x in range(column)] for y in range(row)]
In [79]:
In [79]: for x in range(row): # ro... | 4 | 2016-10-10T12:19:21Z | [
"python",
"python-3.x",
"matrix"
] |
Add elements in a matrix in python | 39,958,095 | <p>I have this matrix:</p>
<pre><code>mat = [[ 0 for x in range(row)] for y in range(column)]
</code></pre>
<p>I tried to add elements to the matrix:</p>
<pre><code>for x in range(row): # row is 2
for y in range(column): # column is 3
mat[x][y] = int(input("number: "))
</code></pre>
<p>but the shell re... | 2 | 2016-10-10T12:15:33Z | 39,958,283 | <p>I think it should be:</p>
<pre><code>>>> for x in range(column):
... for y in range(row):
... mat[x][y] = int("number: ")
...
1
2
3
4
5
6
>>> mat
[[1, 2], [3, 4], [5, 6]]
</code></pre>
| 1 | 2016-10-10T12:27:10Z | [
"python",
"python-3.x",
"matrix"
] |
how to complex manage shell processes with asyncio? | 39,958,110 | <p>I want to track reboot process of daemon with python's asyncio module. So I need to run shell command <code>tail -f -n 0 /var/log/daemon.log</code> and analyze it's output while, let's say, <code>service daemon restart</code> executing in background. Daemon continues to write to log after service restart command fin... | 2 | 2016-10-10T12:16:14Z | 39,962,293 | <blockquote>
<p>But how to run track() strictly before reboot to not miss any possible output in log?</p>
</blockquote>
<p>You could <code>await</code> the first subprocess creation before running the second one. </p>
<blockquote>
<p>And how to retrieve return values of both coroutines?</p>
</blockquote>
<p><a h... | 1 | 2016-10-10T16:03:50Z | [
"python",
"concurrency",
"python-asyncio"
] |
Django - choice set, but no drop down in form | 39,958,124 | <p>I would like to have a choice set in my model for template and validation.</p>
<p>However, in the model.form for that model I want to have just an integer field.</p>
<p>How can I change the widget in order to just get a InputField?</p>
<p>I tried to change the widget to forms.Model, but that did not seem to work.... | 0 | 2016-10-10T12:17:12Z | 40,045,044 | <p>I found the solution - NumberInput() is the right widget.</p>
| 0 | 2016-10-14T13:58:55Z | [
"python",
"django",
"django-forms",
"django-crispy-forms"
] |
Calculate multiple modelField from one Formfield | 39,958,232 | <p>I need extract multiple ModelField value from one FormField. where I should do this? in <code>clean_<field></code> functions? with <code>cleaned_data</code> mutation? form <code>__init__</code> function? in <code>model.save</code> or <code>form.save</code> function?</p>
<p>model:</p>
<pre><code>def normalize... | 0 | 2016-10-10T12:23:58Z | 39,986,169 | <p>According to your comment, I would do the stuff in the <code>save()</code> function. </p>
<p><code>__init__(self)</code> is called before entering the data into the form so it can't do anything with attributes. </p>
<p>Theoretically, <code>clean_name</code> could work (in my opinion), but it should be used for va... | 0 | 2016-10-11T20:28:37Z | [
"python",
"django",
"modelform"
] |
Python: how make class, inherited from list, with access to first element? | 39,958,265 | <p>In Python I would like to make class <em>MyList</em> and inherit from <em>list</em>. Besides I would like to make attribute <em>first</em>, which is equal to first element of list.
For example, for such code </p>
<pre><code>l = MyList([0, 1, 2])
print (l.first)
l.first = 3
print (l)
</code></pre>
<p>I would like t... | 1 | 2016-10-10T12:26:01Z | 39,958,319 | <p>You're not calling list's <code>__init__</code> in your <code>__init__</code>.</p>
<pre><code>class MyList(list):
def __init__(self, input_list):
super(MyList, self).__init__(input_list)
self.first = input_list[0]
</code></pre>
<p>Also, rather than affecting first at init, you should use a <a h... | 2 | 2016-10-10T12:28:39Z | [
"python",
"class"
] |
Python: how make class, inherited from list, with access to first element? | 39,958,265 | <p>In Python I would like to make class <em>MyList</em> and inherit from <em>list</em>. Besides I would like to make attribute <em>first</em>, which is equal to first element of list.
For example, for such code </p>
<pre><code>l = MyList([0, 1, 2])
print (l.first)
l.first = 3
print (l)
</code></pre>
<p>I would like t... | 1 | 2016-10-10T12:26:01Z | 39,958,371 | <p>Define <code>first</code> as a <a href="https://docs.python.org/2.7/library/functions.html#property" rel="nofollow"><code>property</code></a> rather than a simple attribute.</p>
<pre><code>class MyList(list):
@property
def first(self):
return self[0]
@first.setter
def first(self, val):
... | 1 | 2016-10-10T12:31:15Z | [
"python",
"class"
] |
Python: how make class, inherited from list, with access to first element? | 39,958,265 | <p>In Python I would like to make class <em>MyList</em> and inherit from <em>list</em>. Besides I would like to make attribute <em>first</em>, which is equal to first element of list.
For example, for such code </p>
<pre><code>l = MyList([0, 1, 2])
print (l.first)
l.first = 3
print (l)
</code></pre>
<p>I would like t... | 1 | 2016-10-10T12:26:01Z | 39,958,414 | <p>You need to add a call to the <code>super</code> class, and for <code>first</code> to work as expected I'd recommend a <code>property</code>:</p>
<pre><code>class MyList(list):
def __init__(self, input_list):
super(MyList, self).__init__(input_list)
self.first = input_list[0]
@property
... | 0 | 2016-10-10T12:33:52Z | [
"python",
"class"
] |
Creating a python dictionary in python from tab delimited text file with headers as keywords | 39,958,305 | <p>I am rather new to Python and am having trouble trying to create a function which reads in tab deliminated text files and creats a dictionary from the data. I am mostly dealing with text files of the following format with a number of tab deliminated numerical data columns with corresponding headers for each column:<... | 0 | 2016-10-10T12:28:03Z | 39,958,396 | <p>Take a look at the <a href="http://pandas.pydata.org/" rel="nofollow">Pandas module</a></p>
<pre><code># This module kicks ass
import pandas as pd
pipe_data = pd.read_csv('pipeData.txt', sep='\t')
print pipe_data.columns # prints Time_(s), Mass_Flow_(kg/s), ...
print pipe_data['Time_(s)'] # print the Time_(s) co... | 1 | 2016-10-10T12:32:30Z | [
"python",
"arrays",
"numpy",
"dictionary",
"text"
] |
Creating a python dictionary in python from tab delimited text file with headers as keywords | 39,958,305 | <p>I am rather new to Python and am having trouble trying to create a function which reads in tab deliminated text files and creats a dictionary from the data. I am mostly dealing with text files of the following format with a number of tab deliminated numerical data columns with corresponding headers for each column:<... | 0 | 2016-10-10T12:28:03Z | 40,012,125 | <p>An alternative might be to use the <strong>csv</strong> module for Python itself.</p>
<pre><code>import csv
with open('temp.txt') as csvfile:
csvrows = csv.reader(csvfile, delimiter='\t')
fieldnames=next(csvrows)
print (fieldnames)
for row in csvrows:
print (row)
</code></pre>
<p>When I pi... | 0 | 2016-10-13T04:07:21Z | [
"python",
"arrays",
"numpy",
"dictionary",
"text"
] |
Numpy dtype invalid index | 39,958,473 | <pre><code>I'm trying to load csv data file:
ACCEPT,organizer@t.net,t,p1@t.net,0,UK,3600000,3,1475917200000,1475920800000,MON,9,0,0,0
</code></pre>
<p>in following way:</p>
<pre><code>dataset = genfromtxt('./training_set.csv', delimiter=',', dtype='a20, a20, a20, a8, i8, a20, i8, i8, i8, i8, a3, i8, i8, i8, i8')
prin... | -1 | 2016-10-10T12:37:21Z | 39,959,279 | <pre><code>n [42]: dataset = np.genfromtxt('./np_inf.txt', delimiter=',', dtype='a20, a20, a20, a8, i8, a20, i8, i8, i8, i8, a3, i8, i8, i8, i8')
In [43]: [x[0] for x in dataset]
Out[43]: ['ACCEPT', 'ACCEPT', 'ACCEPT']
</code></pre>
<p>The issue is that the entries of the <code>dataset</code> are of not very useful t... | 1 | 2016-10-10T13:19:44Z | [
"python",
"numpy"
] |
Numpy dtype invalid index | 39,958,473 | <pre><code>I'm trying to load csv data file:
ACCEPT,organizer@t.net,t,p1@t.net,0,UK,3600000,3,1475917200000,1475920800000,MON,9,0,0,0
</code></pre>
<p>in following way:</p>
<pre><code>dataset = genfromtxt('./training_set.csv', delimiter=',', dtype='a20, a20, a20, a8, i8, a20, i8, i8, i8, i8, a3, i8, i8, i8, i8')
prin... | -1 | 2016-10-10T12:37:21Z | 39,963,162 | <p>With that <code>dtype</code> you have created a structured array - it is 1d with a compound dtype.</p>
<p>I have a sample structured array from another problem:</p>
<pre><code>In [26]: data
Out[26]:
array([(b'1Q11', 252.0, 0.0166), (b'2Q11', 212.4, 0.0122),
(b'3Q11', 425.9, 0.0286), (b'4Q11', 522.3, 0.0322... | 1 | 2016-10-10T16:55:19Z | [
"python",
"numpy"
] |
Python: Program Keeps Repeating Itself | 39,958,566 | <pre><code>import random
print("Welcome To Arthur's Quiz,\nfeel free to revise the answers once you have completed.\n")
redos=0
def multiplyquestion():
first_num=random.randint(1,100)
second_num=random.randint(1,100)
real_answer= first_num*second_num
human_answer=0
while real_answer!=human_answer... | 0 | 2016-10-10T12:42:26Z | 39,958,814 | <p>In the division function do this to avoid comparing recurring answers with non recurring answers. The rest of the program works perfectly in my environment</p>
<pre><code>if int(round(real_answer)) == human_answer:
</code></pre>
| -1 | 2016-10-10T12:55:33Z | [
"python",
"python-3.x"
] |
Python SQLITE3 Inserting Backwards | 39,958,590 | <p>I have a small piece of code which inserts some data into a database. However, the data is being inserting in a reverse order.<br>
If i "commit" after the for loop has run through, it inserts backwards, if i "commit" as part of the for loop, it inserts in the correct order, however it is much slower.<br>
How can i c... | -1 | 2016-10-10T12:43:58Z | 39,959,051 | <p>You can't rely on <em>any</em> ordering in SQL database tables. Insertion takes place in an implementation-dependent manner, and where rows end up depends entirely on the storage implementation used and the data that is already there.</p>
<p>As such, no reversing takes place; if you are selecting data from the tabl... | 1 | 2016-10-10T13:08:06Z | [
"python",
"sqlite3"
] |
How to exclude values from pandas dataframe? | 39,958,646 | <p>I have two dataframes:</p>
<p>1) customer_id,gender
2) customer_id,...[other fields]</p>
<p>The first dataset is an answer dataset (gender is an answer). So, I want to exclude from the second dataset those customer_id which are in the first dataset (which gender we know) and call it 'train'. The rest records shoul... | 1 | 2016-10-10T12:46:19Z | 39,958,731 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a> and condition with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html" rel="nofollow"><code>isin</code></a>, inverting <code>boole... | 2 | 2016-10-10T12:51:16Z | [
"python",
"pandas"
] |
One of threads rewrites console input in Python | 39,958,650 | <p>I have a problem with console app with threading. In first thread i have a function, which write symbol "x" into output. In second thread i have function, which waiting for users input. (Symbol "x" is just random choice for this question).</p>
<p>For ex.</p>
<p>Thread 1:</p>
<pre>
while True:
print "... | 0 | 2016-10-10T12:46:26Z | 39,958,943 | <p>In a console, standard output (produced by the running program(s)) and standard input (produced by your keypresses) are both sent to screen, so they may end up all mixed.</p>
<p>Here your thread 1 writes 1 <code>x</code> by line every second, so if your take more than 1 second to type <code>HELLO</code> then that w... | 0 | 2016-10-10T13:02:22Z | [
"python",
"multithreading",
"console-application"
] |
Python C/API: how to create a normal class | 39,958,741 | <p>Using the Python C/API, how do I create a normal Python class using the normal Python class-creation mechanism (i.e.: not an extension type)?</p>
<p>In other words, what is the Python C/API equivalent (in the sense that it does <em>exactly</em> the same in all cases) of a statement</p>
<pre><code>class X(bases):
... | 0 | 2016-10-10T12:51:54Z | 39,958,885 | <p>I'm not sure what you mean by "the normal Python class-creation mechanism", but...</p>
<p>There's a documentation page dedicated to this: <a href="https://docs.python.org/3/extending/newtypes.html" rel="nofollow">https://docs.python.org/3/extending/newtypes.html</a> -- it creates a new type in an extension module, ... | 1 | 2016-10-10T12:59:34Z | [
"python",
"class",
"python-c-api"
] |
Python C/API: how to create a normal class | 39,958,741 | <p>Using the Python C/API, how do I create a normal Python class using the normal Python class-creation mechanism (i.e.: not an extension type)?</p>
<p>In other words, what is the Python C/API equivalent (in the sense that it does <em>exactly</em> the same in all cases) of a statement</p>
<pre><code>class X(bases):
... | 0 | 2016-10-10T12:51:54Z | 39,964,743 | <p>In Python you can get programmatically create a class by calling the <code>type</code> built in function. See <a href="http://stackoverflow.com/a/15247202/4657412">this answer</a> for example.</p>
<p>This takes three arguments: a name, a tuple of bases, and a dictionary.</p>
<p>You can get the Python <code>type</c... | 3 | 2016-10-10T18:41:53Z | [
"python",
"class",
"python-c-api"
] |
Program hangs when using processes | 39,958,815 | <p>I'm trying to communicate my c code to my python code.
I'm making a name pipe in my c code, sending it to python and python prints it out. I want to do the same where I make a named pipe in python and c reads it out, however my program seems to stall (I want to do both of these at once), hence I'm using processes. <... | 1 | 2016-10-10T12:55:34Z | 39,959,177 | <p>I don't have a unix box on hand to test currently. But the likely problem is that you don't close the fifo in the parent process.</p>
<p>Whenever you have a loop like <code>for line in file</code>, that loop will continue until the file ends. Unlike a normal file, a fifo doesn't "end" until the process on the writi... | 0 | 2016-10-10T13:14:40Z | [
"python",
"c",
"fork"
] |
Django: accessing a table via dict-like interface | 39,958,907 | <p>So I have situation in Django where I have a model called S which can have a series of attributes, but I have no idea currently what attributes will be relevant/required. In order to handle this I am thinking of creating a additional model SAttrib which mimics a dictionary entry and accessing it via a metadata prope... | 0 | 2016-10-10T13:00:34Z | 39,960,640 | <p>Not a lot wrong with the idea, except for the fact that you seem to have made it needlessly complicated with the use of the <code>_get_metadata</code> function. You may be having a bit of a performance issue becaue of it as well. </p>
<p>This kind of two-table approach is or rather was quite popular in many web ap... | 1 | 2016-10-10T14:29:23Z | [
"python",
"django",
"django-models"
] |
Kivy Multiple Screen Transitions not taking place | 39,958,969 | <p>I am trying to builng a multiple screen kivy app in python. There are no compile time errors. App Compiles successfully. I am using Screen Manager in kivy to achieve multiple screens. On clicking the buttons no transitions are taking place. Please help me perform transitions. Here are actual snippets of my code.</p>... | -1 | 2016-10-10T13:03:56Z | 39,964,554 | <p>declare the screen manager a global variable</p>
<pre><code>import kivy
from kivy.app import App
from kivy.app import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmamager import ScreenManager, Screen
screen_manager = ScreenManager()
class LoginScreen(Screen):
pass
</code></pre>... | 0 | 2016-10-10T18:29:59Z | [
"python",
"kivy"
] |
Python 3: How to run functions with parameter in random order? | 39,958,974 | <p>I knew how to run functions which doesn't have parameter. In this case, I want to run functions which has parameter in random order ? </p>
<p>It showed the result but not random and there is some error: Please help me correct the my code. Thank you :)</p>
<pre><code>import random
def hi(name):
print('a ' + nam... | -1 | 2016-10-10T13:04:02Z | 39,959,082 | <p>In your loop, i is a function and not a string, therefore comparing it to a string wont work and you end up in else. Instead use <code>if i.__name__ == 'hi</code></p>
| -1 | 2016-10-10T13:09:34Z | [
"python",
"function",
"random"
] |
Python 3: How to run functions with parameter in random order? | 39,958,974 | <p>I knew how to run functions which doesn't have parameter. In this case, I want to run functions which has parameter in random order ? </p>
<p>It showed the result but not random and there is some error: Please help me correct the my code. Thank you :)</p>
<pre><code>import random
def hi(name):
print('a ' + nam... | -1 | 2016-10-10T13:04:02Z | 39,959,154 | <p>Try something like that:</p>
<pre><code>functions = [(hi, ['John']), (howold, ['20', 'John']), (howmuch, ['50'])]
random.shuffle(functions)
for func, args in functions:
func(*args)
</code></pre>
| 3 | 2016-10-10T13:13:34Z | [
"python",
"function",
"random"
] |
Python 3: How to run functions with parameter in random order? | 39,958,974 | <p>I knew how to run functions which doesn't have parameter. In this case, I want to run functions which has parameter in random order ? </p>
<p>It showed the result but not random and there is some error: Please help me correct the my code. Thank you :)</p>
<pre><code>import random
def hi(name):
print('a ' + nam... | -1 | 2016-10-10T13:04:02Z | 39,959,181 | <p>Your <code>functions</code> list contains results of already evaluated functions, not a partially applied function with no arguments (so that you can call them with <code>i()</code>) in the loop.</p>
<p>You can use lambdas to produce new functions with no arguments like this:</p>
<pre><code>functions = [lambda: hi... | 2 | 2016-10-10T13:14:58Z | [
"python",
"function",
"random"
] |
Python 3: How to run functions with parameter in random order? | 39,958,974 | <p>I knew how to run functions which doesn't have parameter. In this case, I want to run functions which has parameter in random order ? </p>
<p>It showed the result but not random and there is some error: Please help me correct the my code. Thank you :)</p>
<pre><code>import random
def hi(name):
print('a ' + nam... | -1 | 2016-10-10T13:04:02Z | 39,959,234 | <p>When this line executes:</p>
<pre><code>functions = [hi('John'),howold('20', 'John'),howmuch('50')]
</code></pre>
<p>Python will call your 3 functions <code>hi()</code>, <code>howold()</code> then <code>howmuch()</code> in that order, then store their result in a list called <code>functions</code>. So all <code>pr... | 1 | 2016-10-10T13:16:55Z | [
"python",
"function",
"random"
] |
i cannot round up and get it for my GTIN | 39,959,010 | <pre><code>import random
r1 = (random.randint(0,9))
r2 = (random.randint(0,9))
r3 = (random.randint(0,9))
r4 = (random.randint(0,9))
r5 = (random.randint(0,9))
r6 = (random.randint(0,9))
r7 = (random.randint(0,9))
print ("your item barcode number is", r1,r2,r3,r4,r5,r6,r7)
r8 = (r1*3+r2*1+r3*3+r4*1+r5*3+r6*1+r7*3)
roun... | 0 | 2016-10-10T13:06:04Z | 39,959,090 | <pre><code>def round_up_by_ten(num):
return num if not num%10 else ((num//10)+1)*10
</code></pre>
| 0 | 2016-10-10T13:09:56Z | [
"python"
] |
Save a subset of MongoDB(3.0) collection to another collection in Python | 39,959,206 | <p>I found this answer - <a href="http://stackoverflow.com/a/25247084/609782">Answer link</a></p>
<pre><code>db.full_set.aggregate([ { $match: { date: "20120105" } }, { $out: "subset" } ]);
</code></pre>
<p>I want do same thing but with first 15000 documents in collection, I couldn't find how to apply limit to such q... | 2 | 2016-10-10T13:15:39Z | 40,076,716 | <p>Well,<br>
in python, this is how things work - <code>$limit</code> needs to be wrapped in <code>""</code>,<br>
and you need to create a pipeline to execute it as a command.</p>
<p>In my code -</p>
<pre><code> pipeline = [{ '$limit': 15000 },{'$out': "destination_collection"}]
db.command('aggregate', "source... | 0 | 2016-10-16T23:44:42Z | [
"python",
"mongodb",
"mongodb-query",
"aggregation-framework",
"mongodb-aggregation"
] |
Multiple outputs printed slowly at the same time | 39,959,301 | <p>As it's stated in the title, I have N strings (let's say 3) and they go one after the other like:</p>
<pre><code>"string1"
"string2"
"string3"
</code></pre>
<p>With the help of 'sleep' we can make the string get printed out slowly, symbol by symbol, BUT I want to have each of them printed slowly AT THE SAME TIME. ... | -1 | 2016-10-10T13:20:40Z | 39,959,969 | <p>If I understand you correctly, you want to create a label that slowly reveals one character at a time (ie: first you see "s", then "st", then "str", etc).</p>
<p>That can be cone by creating a custom label class, and using <code>after</code> to slowly reveal the text. Each time the function <code>reveal_text</code>... | 1 | 2016-10-10T13:54:56Z | [
"python",
"python-3.x",
"tkinter"
] |
Python 3.5 Dropbox API modified date doesn't update | 39,959,308 | <p>I'm writing a script in python3.5 that needs to check if the file on dropbox is
newer then a local file. If the file is newer, it needs to download the file.</p>
<p>The problem I'm having is that the date on the server doesn't seem to update. Is it possible that it only update on certain times?</p>
<pre><code>cod... | 0 | 2016-10-10T13:21:02Z | 39,960,027 | <p>The problem was the difference between timezones. I'm in GMT +2 while dropbox is GMT +0. So I chanced this line</p>
<pre><code>version_date = datetime.datetime.fromtimestamp(version_epoch) - datetime.timedelta(hours=2)
</code></pre>
<p>Now it works perfectly.</p>
| 0 | 2016-10-10T13:57:32Z | [
"python",
"python-3.x",
"dropbox"
] |
If found brackets found in string, then remove brackets and data inside brackets | 39,959,313 | <p>I would like to detect brackets in a string, and if found, remove the brackets and all data in the brackets</p>
<p>e.g.</p>
<p><code>Developer (12)</code></p>
<p>would become</p>
<p><code>Developer</code></p>
<p>Edit: Note that the string will be a different length/text each time, and the brackets will not alwa... | 2 | 2016-10-10T13:21:24Z | 39,959,456 | <p>You can user regex and replace it:</p>
<pre><code>>>> re.sub(r'\(.*?\)', '','Developer (12)')
'Developer '
>>> a='DEf (asd () . as ( as ssdd (12334))'
>>> re.sub(r'\(.*?\)', '','DEf (asd () . as ( as ssdd (12334))')
'DEf . as )'
</code></pre>
| 3 | 2016-10-10T13:28:28Z | [
"python",
"regex"
] |
If found brackets found in string, then remove brackets and data inside brackets | 39,959,313 | <p>I would like to detect brackets in a string, and if found, remove the brackets and all data in the brackets</p>
<p>e.g.</p>
<p><code>Developer (12)</code></p>
<p>would become</p>
<p><code>Developer</code></p>
<p>Edit: Note that the string will be a different length/text each time, and the brackets will not alwa... | 2 | 2016-10-10T13:21:24Z | 39,959,475 | <p>I believe you want something like this</p>
<pre><code>import re
a = "developer (12)"
print(re.sub("\(.*\)", "", a))
</code></pre>
| 1 | 2016-10-10T13:29:23Z | [
"python",
"regex"
] |
If found brackets found in string, then remove brackets and data inside brackets | 39,959,313 | <p>I would like to detect brackets in a string, and if found, remove the brackets and all data in the brackets</p>
<p>e.g.</p>
<p><code>Developer (12)</code></p>
<p>would become</p>
<p><code>Developer</code></p>
<p>Edit: Note that the string will be a different length/text each time, and the brackets will not alwa... | 2 | 2016-10-10T13:21:24Z | 39,959,531 | <p>Since it's always at the end and there is no nested brackets:</p>
<pre><code>s = "Developer (12)"
s[:s.index('(')] # or s.index(' (') if you want to get rid of the previous space too
</code></pre>
| 0 | 2016-10-10T13:33:10Z | [
"python",
"regex"
] |
If found brackets found in string, then remove brackets and data inside brackets | 39,959,313 | <p>I would like to detect brackets in a string, and if found, remove the brackets and all data in the brackets</p>
<p>e.g.</p>
<p><code>Developer (12)</code></p>
<p>would become</p>
<p><code>Developer</code></p>
<p>Edit: Note that the string will be a different length/text each time, and the brackets will not alwa... | 2 | 2016-10-10T13:21:24Z | 39,960,071 | <p>For nested brackets and multiple pairs in string this solution would work</p>
<pre><code>def replace_parenthesis_with_empty_str(str):
new_str = ""
stack = []
in_bracker = False
for c in str :
if c == '(' :
stack.append(c)
in_bracker = True
continue
... | 0 | 2016-10-10T13:59:49Z | [
"python",
"regex"
] |
Trying to find a quick way to get windows path | 39,959,409 | <p>I'm new to python.
I know how to detect which os is installed but I'm trying to find a quick way to get the windows path rather then go a-z (c:\windows...x:\windows...).
Is there any quick way?</p>
<p>Edit:
Something like %systemroot% in windows (gives you full path).</p>
| 4 | 2016-10-10T13:25:49Z | 39,959,484 | <p>You can use <a href="https://docs.python.org/3/library/os.html#os.environ" rel="nofollow"><code>os.environ</code></a></p>
<pre><code>import os
win_path = os.environ['WINDIR']
</code></pre>
<p><code>WINDIR</code> is an environment variable set by windows that will point to <code>%SystemRoot%</code></p>
| 3 | 2016-10-10T13:30:00Z | [
"python",
"windows"
] |
Class providing methods inherited into class providing underlying data - How is that called? | 39,959,416 | <p>I have a class <code>Library</code> which defines some methods on - kind of - abstract data. This class is then inherited into a class <code>A</code> or <code>B</code> that actually defines the data. The intention is to reuse <code>Library</code> with different underlying data storage models.</p>
<p>In Python:</p>
... | 0 | 2016-10-10T13:26:12Z | 39,974,756 | <p>Your example is leveraging Python's Multiple inheritance mechanism, whereby you add methods from a methods-only, data-free, abstract class <code>A</code>, to one (or several) data-oriented, dumb concrete class <code>B</code>.</p>
<p>As it separates data-storing (representation) from functionality (methods), it is v... | 1 | 2016-10-11T09:58:30Z | [
"python",
"design-patterns"
] |
Set last non-zero element of each row to zero - NumPy | 39,959,435 | <p>I have an array A:</p>
<pre><code>A = array([[1, 2, 3,4], [5,6,7,0] , [8,9,0,0]])
</code></pre>
<p>I want to change the last non-zero of each row to 0 </p>
<pre><code>A = array([[1, 2, 3,0], [5,6,0,0] , [8,0,0,0]])
</code></pre>
<p>how to write the code for any n*m numpy array?
Thanks, S ;-)</p>
| 3 | 2016-10-10T13:27:06Z | 39,959,511 | <p><strong>Approach #1</strong></p>
<p>One approach based on <code>cumsum</code> and <code>argmax</code> -</p>
<pre><code>A[np.arange(A.shape[0]),(A!=0).cumsum(1).argmax(1)] = 0
</code></pre>
<p>Sample run -</p>
<pre><code>In [59]: A
Out[59]:
array([[2, 0, 3, 4],
[5, 6, 7, 0],
[8, 9, 0, 0]])
In [60]... | 4 | 2016-10-10T13:31:49Z | [
"python",
"numpy",
"theano"
] |
Speed up scipy ndimage measurements applied on a numpy 3-d | 39,959,445 | <p>I have multiple large labeled numpy 2d array (10 000x10 000). For each label (connected cells with the same number) I want to calculate multiple measurements based on the values of another numpy 3-d array (mean, std., max, etc.). This is possible with the scipy.ndimage.labeled_comprehension tool if the 3-d numpy is ... | 2 | 2016-10-10T13:27:38Z | 39,962,238 | <p>The list appends in mean_std_measurement is probably forming a bottleneck when dealing with large arrays. <code>labeled_comprehension</code> will return an array on its own, so a first step is to just let scipy handle the array construction under the hood. </p>
<p><code>labeled_comprehension</code> can only apply f... | 0 | 2016-10-10T16:01:10Z | [
"python",
"numpy",
"scipy",
"vectorization",
"ndimage"
] |
Open unique secondary window with Tkinter | 39,959,470 | <p>I'm having a trouble when i open a secondary window. Now I'm just creating a toplevel window with a button and I need to open the same secondary window If i click the button (not generate a new instance).</p>
<p>Which is the better way to generate single secondary window and not generating a new window instance?</p... | 0 | 2016-10-10T13:29:03Z | 40,021,793 | <p>Finally after some tests I've found how to solve that, thanks to the @furas response and some investigation about the Tkinter events with the protocol function.</p>
<p>I've got that working with:</p>
<pre><code>import tkinter
logWindowExists = False
class LogWindow():
def __init__(self, parent):
glob... | 0 | 2016-10-13T13:02:01Z | [
"python",
"tkinter"
] |
How to convert signed string to its Binary equivalent in Python? | 39,959,491 | <p>I am using the itertool function to enter value to a list. The itertool function is taking the value as a str, not as an int. After that, I need to convert the values from the list to its Binary equivalent. The problem arises when I need to convert a negative value e.g. -5. My code is taking the "-" as a str, but I ... | 2 | 2016-10-10T13:30:23Z | 39,960,770 | <p>It's not entirely clear what your problem is and what you want to achieve, so please correct me if I make wrong assumptions.</p>
<p>Anyways, converting integers to binary representation is easily done using <code>bin</code>. For example, <code>bin(5)</code> gives you <code>'0b101'</code>. Now, <code>bin(-5)</code> ... | 0 | 2016-10-10T14:37:09Z | [
"python"
] |
Python - Select elements from matrix within range | 39,959,519 | <p>I have a question regarding python and selecting elements within a range.</p>
<p>If I have a n x m matrix with n row and m columns, I have a defined range for each column (so I have m min and max values).</p>
<p>Now I want to select those rows, where all values are within the range.</p>
<p>Looking at the followin... | 0 | 2016-10-10T13:32:14Z | 39,961,122 | <p>I believe that there is more elegant solution, but i came to this:</p>
<pre><code>def foo(data, boundaries):
zipped_bounds = list(zip(*boundaries))
output = []
for item in data:
for index, bound in enumerate(zipped_bounds):
if not (bound[0] <= item[index] <= bound[1]):
... | 0 | 2016-10-10T14:55:24Z | [
"python"
] |
Python - Select elements from matrix within range | 39,959,519 | <p>I have a question regarding python and selecting elements within a range.</p>
<p>If I have a n x m matrix with n row and m columns, I have a defined range for each column (so I have m min and max values).</p>
<p>Now I want to select those rows, where all values are within the range.</p>
<p>Looking at the followin... | 0 | 2016-10-10T13:32:14Z | 39,963,139 | <p>Your example data syntax is not correct <code>matrix([[],..])</code> so it needs to be restructured like this:</p>
<pre><code>matrix = [[1, 2], [3, 4],[5,6],[1,8]]
bounds = [[2,1],[8,5]]
</code></pre>
<p>I'm not sure exactly what you mean by "efficient", but this solution is readable, computationally efficient, an... | 0 | 2016-10-10T16:53:41Z | [
"python"
] |
Creating a Selenium module to replace testcomplete | 39,959,677 | <p>I'm trying to replace TestComplete with Selenium for our automated tests, ideally without having to re-write all of the different functions.</p>
<p>The plan is to replicate the Aliases structure for finding elements within TestComplete with a python module that can be dropped in to do the finding of web elements. <... | -1 | 2016-10-10T13:39:56Z | 39,961,837 | <p>I don't know the scale of the changes you are talking about but my guess is that it would be faster (and better) to just rewrite the tests than to try to write code so that you don't have to make changes. In the long run, rewriting will likely require less maintenance and be easier to debug. So take the time to rewr... | 0 | 2016-10-10T15:37:29Z | [
"python",
"selenium",
"automated-tests",
"testcomplete"
] |
manifold.Isomap(n_neighbors, n_components).fit_transform - SciKit Learn | 39,959,713 | <p>I have a dataframe called X_train and I am performing Isomap dimensionality reduction using SciKit Learn. The code is the following:</p>
<pre><code> from sklearn import manifold
iso = manifold.Isomap(n_neighbors=4, n_components=2)
iso.fit(X_train)
manifold.Isomap(eigen_solver='auto', max_iter=None, n_components... | -1 | 2016-10-10T13:41:53Z | 39,959,887 | <p>It raises this error because you did not create any variables called <code>n_neighbors</code> nor <code>n_components</code>. </p>
<p>As for the variable <code>iso</code>, you have to indicate the values of your parameters.<code>Isomap(n_neighbors=4, n_components=2)</code></p>
<p>Try this out :</p>
<pre><code>X2_t... | 0 | 2016-10-10T13:50:49Z | [
"python",
"scikit-learn"
] |
Amending datetime format while parsing from csv read - pandas | 39,959,925 | <p>I am reading a csv file (SimResults_Daily.csv) into pandas, that is structured as follows:</p>
<pre><code>#, Job_ID, Date/Time, value1, value2,
0, ID1, 05/01 24:00:00, 5, 6
1, ID2, 05/02 24:00:00, 6, 15
2, ID3, 05/03 24:00:00, 20, 21
</code></pre>
<p>etc.
As the datetime format cannot be read by pandas pa... | 1 | 2016-10-10T13:52:46Z | 39,959,989 | <p>You can use:</p>
<pre><code>import pandas as pd
import io
temp=u"""#,Job_ID,Date/Time,value1,value2,
0,ID1,05/01 24:00:00,5,6
1,ID2,05/02 24:00:00,6,15
2,ID3,05/03 24:00:00,20,21"""
dateparse = lambda x: pd.datetime.strptime(x.replace('24:','00:'), '%m/%d %H:%M:%S')
#after testing replace io.StringIO(temp) to f... | 2 | 2016-10-10T13:55:41Z | [
"python",
"date",
"csv",
"parsing",
"pandas"
] |
How to inject Django template code into template through {{ variable/method }}? | 39,960,259 | <p>I have a model Reservation which I use in many templates. It's handy to create it's own <code>HTML/Django</code> snippet which is being injected into the template through variable/model method. </p>
<p>The raw <code>HTML</code> is correct using the method but Django template language isn't interpreted correctly. </... | 1 | 2016-10-10T14:09:41Z | 39,960,369 | <p>Simply don't ask the template to do it, if you really want to continue to use this method then just do string formatting, and mark it as safe.</p>
<pre><code>desc = """<ul>
<li><b>ID:</b> %(id)s</li>
</ul>""" % { 'id': self.id }
return mark_safe(desc)
</cod... | 1 | 2016-10-10T14:14:54Z | [
"python",
"html",
"django",
"templates",
"django-templates"
] |
How to inject Django template code into template through {{ variable/method }}? | 39,960,259 | <p>I have a model Reservation which I use in many templates. It's handy to create it's own <code>HTML/Django</code> snippet which is being injected into the template through variable/model method. </p>
<p>The raw <code>HTML</code> is correct using the method but Django template language isn't interpreted correctly. </... | 1 | 2016-10-10T14:09:41Z | 39,960,404 | <p>What you are asking for is double substitution and I don't think the Django templating engine will do that. Since you are pulling the data from a <code>Reservation</code> instance, I would just fill it in using string substitution. For example:</p>
<pre><code> return """<ul>
<li><b>... | 1 | 2016-10-10T14:16:51Z | [
"python",
"html",
"django",
"templates",
"django-templates"
] |
Difference between the Python built-in pow and math pow for large integers | 39,960,275 | <p>I find that for large integers, the math.pow does not successfully translate to its integer version. I got a buggy <a href="https://en.wikipedia.org/wiki/Karatsuba_algorithm" rel="nofollow">Karatsuba multiplication</a> when implemented with math.pow. </p>
<p>For instance:</p>
<pre><code>>>> a_Size=32
>... | 0 | 2016-10-10T14:10:22Z | 39,960,433 | <p><code>math.pow()</code> always returns a floating-point number, so you are limited by the precision of <code>float</code> (almost always an IEEE 754 double precision number). The built-in <code>pow()</code> on the other hand will use Python's arbitrary precision integer arithmetic when called with integer arguments... | 1 | 2016-10-10T14:19:10Z | [
"python",
"math",
"largenumber",
"karatsuba"
] |
Python, scipy : minimize multivariable function in integral expression | 39,960,320 | <p>how can I minimize a function (uncostrained), respect a[0] and a[1]?
example (this is a simple example for I uderstand scipy, numpy and py):</p>
<pre><code>import numpy as np
from scipy.integrate import *
from scipy.optimize import *
def function(a):
return(quad(lambda t: ((np.cos(a[0]))*(np.sin(a[1]))*t),0,3))... | 0 | 2016-10-10T14:12:28Z | 39,962,346 | <p>This is just a guess, because you haven't included enough information in the question for anyone to really know what the problem is. Whenever you ask a question about code that generates an error, always include the complete error message in the question. Ideally, you should include a <a href="http://stackoverflow... | 2 | 2016-10-10T16:06:47Z | [
"python",
"numpy",
"optimization",
"scipy"
] |
PyMySQL Python 3 Django VirtualEnv MySQLdb | 39,960,367 | <p>So I had this running yesterday when I was running the virtualenv out of my home directory. I've ran in to this problem a number of times now without a clear answer. I've done a lot of research on this but there seems to be no black and white answer. Today I moved my virtualenv to <code>/usr/local/virtualenvs</co... | 0 | 2016-10-10T14:14:42Z | 39,961,125 | <p>Added</p>
<pre><code>try:
import pymysql
pymysql.install_as_MySQLdb()
except ImportError:
pass
</code></pre>
<p>to <code>manage.py</code> and <code>wsgi.py</code></p>
<p>Now working.</p>
| 0 | 2016-10-10T14:55:32Z | [
"python",
"mysql",
"django",
"virtualenv"
] |
Accessing test database in (Selenium based) functional tests for a Pyramid + sqlalchemy application | 39,960,412 | <p>I have managed to create functional tests using Splinter (Selenium) and <code>StoppableWSGIServer</code>. Here's my code:</p>
<pre><code>...
engine = engine_from_config(settings, prefix='sqlalchemy.')
DBSession.configure(bind=engine)
Base.metadata.create_all(engine)
...
class FunctionalTest(...):
...
de... | 1 | 2016-10-10T14:17:22Z | 39,961,057 | <p>This seems to do the trick:</p>
<pre><code>import trasaction
transaction.commit()
</code></pre>
<p>However I'm not absolutely certain about my implementation, so I'm still awaiting answers. Also, this way I have to <code>DBSession.drop_all</code> before each test case.</p>
| 1 | 2016-10-10T14:51:12Z | [
"python",
"selenium",
"sqlalchemy",
"pyramid",
"functional-testing"
] |
read escaped character \t as '\t' instead of '\\t' Python ConfigParser | 39,960,450 | <p>I have a config.ini file containing <code>delimiter = \t</code> which i now want to read using the python3 ConfigParser.
However, the resulting string is <code>'\\t'</code> instead of <code>'\t'</code> which breaks my program.
Is there a more elegant option to solve this problem instead of just manually stripping th... | 0 | 2016-10-10T14:20:16Z | 39,960,982 | <p>Python3 has a 'unicode_escape' codec.</p>
<pre><code>r"a\tb".decode('unicode_escape')
'a\tb'
</code></pre>
<p>Sources:</p>
<p><a href="https://bytes.com/topic/python/answers/37952-escape-chars-string" rel="nofollow">https://bytes.com/topic/python/answers/37952-escape-chars-string</a></p>
<p><a href="http://stac... | 0 | 2016-10-10T14:47:11Z | [
"python",
"escaping",
"special-characters",
"configparser"
] |
Installing opencv 3.1.0 for python2.7 on kubuntu | 39,960,686 | <p>I try to install opencv for python2.7 on my ubuntu but nothing seem to work.
Whatever I do, I can't import cv2</p>
<p>I tryed to download the sources and cmake / make / make install. (as describe here <a href="http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html" rel="nofollow">http://docs.opencv.org/tru... | 0 | 2016-10-10T14:32:33Z | 39,972,468 | <p>Ok I found the issues. The make install did not put the cv2.so in the correct location.
I had to manually put it in my lib/python2.7/site-packages/</p>
| 0 | 2016-10-11T07:40:09Z | [
"python",
"opencv",
"ubuntu"
] |
Python time function inconsistency | 39,960,754 | <p>I've been gave an assignment were i had to create two small functions that gives, with equal chance, "heads" or "tails" and, similary with a 6 faces thrown dice, 1,2,3,4,5 or 6.</p>
<p>Important: I could NOT use randint or similar functions for this assignment.</p>
<p>So i've created those two functions that gener... | 4 | 2016-10-10T14:36:21Z | 39,961,127 | <p>Your utilization of <code>round</code> means that your coin flip function will tend towards even numbers if the values you get from your time-based random operation are equidistant from one another (i.e. you "flip" your coin more consistently every half second due to your computer internals).</p>
<p><a href="https:... | 2 | 2016-10-10T14:55:38Z | [
"python"
] |
Logarithmic slider with matplotlib | 39,960,791 | <p>I just implemented a slider in my plot which works great. (I used this example: <a href="http://matplotlib.org/examples/widgets/slider_demo.html" rel="nofollow">http://matplotlib.org/examples/widgets/slider_demo.html</a>) Now my question is if it is possible to make the slider logarithmic. My values range between 0 ... | 2 | 2016-10-10T14:37:57Z | 39,960,977 | <p>You can simply <code>np.log()</code> the value of the slider. However then the label next to it would be incorrect. You need to manually set the text of <code>valtext</code> of the slider to the log-value:</p>
<pre><code>def update(val):
amp = np.log(slider.val)
slider.valtext.set_text(amp)
</code></pre>
| 2 | 2016-10-10T14:47:05Z | [
"python",
"matplotlib"
] |
How to get tornado object? | 39,960,806 | <p>I want to get value of a tornado object with key</p>
<p>This is my code : </p>
<pre><code>beanstalk = beanstalkt.Client(host='host', port=port)
beanstalk.connect()
print("ok1")
beanstalk.watch('contracts')
stateTube = beanstalk.stats_tube('contracts', callback=show)
print("ok2")
ioloop = tornado.ioloop.IOLoop.in... | 0 | 2016-10-10T14:38:43Z | 39,961,325 | <p><code>beanstalk.stats_tube</code> is async, it returns a <code>Future</code> which represents a future result that has not yet been resolved.</p>
<p>As <a href="https://github.com/nephics/beanstalkt" rel="nofollow">the README says</a>, Your callback <code>show</code> will be executed with a dict that contains the r... | 2 | 2016-10-10T15:06:08Z | [
"python",
"object",
"tornado",
"beanstalk"
] |
Cannot install a whl library | 39,960,828 | <p>When i try to install this OpenCV file the cmd give me an error. I'm new in python and I'm doing a school job, can someone help me?</p>
<p><img src="http://i.stack.imgur.com/rAxVV.png" alt=""></p>
| 0 | 2016-10-10T14:39:29Z | 39,960,852 | <p>Don't use <code>pip</code> from a python terminal, but from your system terminal/command line interface. </p>
| 1 | 2016-10-10T14:40:30Z | [
"python",
"install",
"pip"
] |
Fastest way to print this in python? | 39,960,877 | <p>Suppose I have a text file containing this, where the number on the left says how many of the characters of the right should be there: </p>
<pre><code>2 a
1 *
3 $
</code></pre>
<p>How would I get this output in the fastest time? </p>
<pre><code>aa*$$$
</code></pre>
<p>This is my code, but has N^2 complexity: ... | -1 | 2016-10-10T14:41:52Z | 39,960,939 | <p>You can multiply strings to repeat them in Python:</p>
<p><code>"foo" * 3</code> gives you <code>foofoofoo</code>.</p>
<pre><code>line = []
with open("a.txt") as f:
for line in f:
n, c = line.rstrip().split(" ")
line.append(c * int(n))
print("".join(line))
</code></pre>
<p>You can print direc... | 1 | 2016-10-10T14:45:26Z | [
"python"
] |
Fastest way to print this in python? | 39,960,877 | <p>Suppose I have a text file containing this, where the number on the left says how many of the characters of the right should be there: </p>
<pre><code>2 a
1 *
3 $
</code></pre>
<p>How would I get this output in the fastest time? </p>
<pre><code>aa*$$$
</code></pre>
<p>This is my code, but has N^2 complexity: ... | -1 | 2016-10-10T14:41:52Z | 39,960,958 | <p>KISS</p>
<pre><code>with open('file.txt') as f:
for line in f:
count, char = line.strip().split(' ')
print char * int(count),
</code></pre>
| 4 | 2016-10-10T14:46:18Z | [
"python"
] |
Fastest way to print this in python? | 39,960,877 | <p>Suppose I have a text file containing this, where the number on the left says how many of the characters of the right should be there: </p>
<pre><code>2 a
1 *
3 $
</code></pre>
<p>How would I get this output in the fastest time? </p>
<pre><code>aa*$$$
</code></pre>
<p>This is my code, but has N^2 complexity: ... | -1 | 2016-10-10T14:41:52Z | 39,960,972 | <p>Just print immediately:</p>
<pre><code>for item in open('a.txt'):
num, char = item.strip().split()
print(int(num) * char, end='')
print() # Newline
</code></pre>
| 3 | 2016-10-10T14:46:59Z | [
"python"
] |
Fastest way to print this in python? | 39,960,877 | <p>Suppose I have a text file containing this, where the number on the left says how many of the characters of the right should be there: </p>
<pre><code>2 a
1 *
3 $
</code></pre>
<p>How would I get this output in the fastest time? </p>
<pre><code>aa*$$$
</code></pre>
<p>This is my code, but has N^2 complexity: ... | -1 | 2016-10-10T14:41:52Z | 39,961,383 | <p>You can try like this,</p>
<pre><code>f = open('a.txt')
print ''.join(int(item.split()[0]) * item.split()[1] for item in f.readlines())
</code></pre>
| 0 | 2016-10-10T15:10:03Z | [
"python"
] |
Fastest way to print this in python? | 39,960,877 | <p>Suppose I have a text file containing this, where the number on the left says how many of the characters of the right should be there: </p>
<pre><code>2 a
1 *
3 $
</code></pre>
<p>How would I get this output in the fastest time? </p>
<pre><code>aa*$$$
</code></pre>
<p>This is my code, but has N^2 complexity: ... | -1 | 2016-10-10T14:41:52Z | 39,961,661 | <p>Your code is actually O(sum(n_i)) where n_i is the number in the row i. You can't do any better and none of the solutions in the other answers do, even if they might be faster than yours.</p>
| 0 | 2016-10-10T15:26:04Z | [
"python"
] |
Django 'ascii' codec can't encode character u'\uff1f' | 39,960,921 | <p>I am still beginner in django. </p>
<p>When I save into database, I got this error.</p>
<blockquote>
<p>'ascii' codec can't encode character u'\uff1f' in position 14: ordinal
not in range(128)</p>
</blockquote>
<p>I have seen similar question here though but I have tried and it is still not okay.</p>
<p><a h... | 0 | 2016-10-10T14:44:16Z | 39,961,488 | <p>It might be that the DB doesn't accept Unicode value as a string field.</p>
<p>To solve this, try two ways:</p>
<ol>
<li><p>Change DB config into using a unicode encoding. E.g. <a href="http://dev.mysql.com/doc/refman/5.7/en/charset-unicode.html" rel="nofollow">This post</a> for mysql.</p></li>
<li><p>Encode that ... | 0 | 2016-10-10T15:15:22Z | [
"python",
"django",
"encoding"
] |
Python best practice: series of "or"s or "in"? | 39,960,941 | <p>I am working on a <a href="https://github.com/johnroper100/CrowdMaster/pull/17" rel="nofollow">project</a> where a question came up about the following line:</p>
<pre><code>a == "EQUAL" or a == "NOT EQUAL" or a == "LESS" or a == "GREATER"
</code></pre>
<p>I proposed a change to make it "simpler" like so:</p>
<pre... | 3 | 2016-10-10T14:45:28Z | 39,961,212 | <p>I'd go with the set. It's much more readable. The string of <code>or</code>s can be faster in some circumstances since the operator short circuits and there is no overhead of constructing the list of items each time but I don't think it's worth the readability sacrifice. Here is a quick and dirty benchmark. This is ... | 3 | 2016-10-10T15:00:23Z | [
"python",
"performance",
"python-3.x"
] |
Python best practice: series of "or"s or "in"? | 39,960,941 | <p>I am working on a <a href="https://github.com/johnroper100/CrowdMaster/pull/17" rel="nofollow">project</a> where a question came up about the following line:</p>
<pre><code>a == "EQUAL" or a == "NOT EQUAL" or a == "LESS" or a == "GREATER"
</code></pre>
<p>I proposed a change to make it "simpler" like so:</p>
<pre... | 3 | 2016-10-10T14:45:28Z | 39,961,343 | <p>Obviously in your case it's better to use <code>in</code> operator. It's just much more readable.</p>
<p>In more complex cases when it's not possible to use <code>in</code> operator, you may use <a href="https://docs.python.org/3/library/functions.html#all" rel="nofollow"><code>all</code></a> and <a href="https://d... | 1 | 2016-10-10T15:07:22Z | [
"python",
"performance",
"python-3.x"
] |
Python best practice: series of "or"s or "in"? | 39,960,941 | <p>I am working on a <a href="https://github.com/johnroper100/CrowdMaster/pull/17" rel="nofollow">project</a> where a question came up about the following line:</p>
<pre><code>a == "EQUAL" or a == "NOT EQUAL" or a == "LESS" or a == "GREATER"
</code></pre>
<p>I proposed a change to make it "simpler" like so:</p>
<pre... | 3 | 2016-10-10T14:45:28Z | 39,972,305 | <p>As suggested by multiple people, go for reability.</p>
<p>performance wise there is a difference, the <code>in</code> operator on sets has an average lookup time of O(1), while for lists it's O(n). You can find this <a href="https://wiki.python.org/moin/TimeComplexity" rel="nofollow">here</a>.</p>
<p>In your case ... | 0 | 2016-10-11T07:28:53Z | [
"python",
"performance",
"python-3.x"
] |
Flask app search bar | 39,960,942 | <p>I am trying to implement a search bar using Flask, but when I enter the url/search, I got a 405 error, <strong>Method Not Allowed</strong>. </p>
<p>Here is a snippet of my code. Any help would be appreciated!</p>
<p><strong>forms.py</strong></p>
<pre><code>from wtforms import StringField
from wtforms.validators i... | -1 | 2016-10-10T14:45:31Z | 39,961,246 | <p>Because when you load page manually you using <code>GET</code> method, but only <code>POST</code> is allowed for <code>search</code> controller. You need to change</p>
<pre><code>@app.route('/search', methods=['POST'])
</code></pre>
<p>to </p>
<pre><code>@app.route('/search', methods=['GET', 'POST'])
</code></pre... | 1 | 2016-10-10T15:02:01Z | [
"python",
"search",
"flask",
"full-text-search",
"whoosh"
] |
Creating an SSL socket with python | 39,960,983 | <p>I'm using Python 2.4.4 and OpenSSL 0.9.8k (not by choice)</p>
<p>I've referred to the documentation: <a href="https://docs.python.org/release/2.4.4/lib/module-socket.html" rel="nofollow">https://docs.python.org/release/2.4.4/lib/module-socket.html</a></p>
<p>and to pretty much every mention of "openSSL" and "pytho... | 0 | 2016-10-10T14:47:18Z | 39,962,070 | <p><code>socket.ssl</code> is only able to initiate a SSL connection and the given optional cert and key are for use of client certificates. <code>socket.ssl</code> is not able to be used on the server side and it looks like python 2.4.4 does not offer this feature in any of the core modules at all. In later versions o... | 1 | 2016-10-10T15:51:41Z | [
"python",
"sockets",
"ssl"
] |
Unicode Error when opening text file - Geany | 39,961,007 | <p>I'm trying to create a little program that reads the contents of two stories, Alice in Wonderland & Moby Dick, and then counts how many times the word 'the' is found in each story.</p>
<p>However I'm having issues with getting Geany text editor to open the files. I've been creating and using my own small text f... | 1 | 2016-10-10T14:48:42Z | 39,964,919 | <p>What OS do you use? There are similar problems in Windows. If so, you can try to run <code>chcp 65001</code> before you command in console. Also you can add <code># encoding: utf-8</code> at the top of you <code>.py</code> file. Hope this will help because I can't reply same encoding problem with .txt file from gute... | 0 | 2016-10-10T18:52:48Z | [
"python",
"python-3.x",
"encoding",
"text-files",
"geany"
] |
How to align y labels in a Seaborn PairGrid | 39,961,147 | <p>Taken from the <a href="https://stanford.edu/~mwaskom/software/seaborn/generated/seaborn.PairGrid.html" rel="nofollow">documentation</a>:</p>
<pre><code>>>> import matplotlib.pyplot as plt
>>> import seaborn as sns; sns.set()
>>> iris = sns.load_dataset("iris")
>>> g = sns.PairGr... | -1 | 2016-10-10T14:56:41Z | 39,968,565 | <p>Yeah, that alignment is terrible. How dare a package that boasts to make <a href="https://stanford.edu/~mwaskom/software/seaborn/" rel="nofollow">"attractive statistical graphics"</a> fail so abysmally at the alignment of labels?! Just kidding, I love me some seaborn, at least for inspiration on how to improve my ow... | 1 | 2016-10-11T00:06:14Z | [
"python",
"matplotlib",
"seaborn"
] |
ERROR __init__() takes exactly 1 argument (3 given) on Django with GAE | 39,961,211 | <p>Im trying to solve one problem that I have on my admin of one Django App.</p>
<p>I have this code:</p>
<p>admin_main.py:</p>
<pre><code>application = webapp.WSGIApplication([
# Admin pages
(r'^(/admin/add_img)', admin.views.AddImage),
(r'^(/admin)(.*)$', admin.Admin),])
</code></pre>
<p>admin/views.py:</p>
<pre... | 0 | 2016-10-10T15:00:22Z | 39,961,724 | <p>I believe you made a mistake in using <code>super()</code>, you need to change in your <code>Admin.__init__()</code> method:</p>
<pre><code>super(Admin, request, response).__init__()
</code></pre>
<p>to:</p>
<pre><code>super(Admin, self).__init__(request=request, response=response)
</code></pre>
| 0 | 2016-10-10T15:29:32Z | [
"python",
"python-2.7",
"google-app-engine",
"webapp2"
] |
django access database from crispy form | 39,961,213 | <p>I'm working on a blog for a client that is using crispy form to make their writing's easier. I have the ability to add an image to the blog - only one and at the top of the post. My client wants to add other pictures throughout the post. The crispy form allows them to do this but only by way of a full http link. Thi... | 0 | 2016-10-10T15:00:28Z | 39,961,786 | <p>I decided to add a simple bootstrap dropdown with each picture in the database, sorted by most recent, and a copy url button. If someone can come up with a better solution, that would be best.</p>
| 0 | 2016-10-10T15:33:30Z | [
"python",
"django",
"django-forms",
"django-crispy-forms"
] |
tfidfvectorizer Predict in saved classifier | 39,961,294 | <p>I trained my model by using TfIdfVectorizer and MultinomialNB and I saved it into a pickle file.</p>
<p>Now that I am trying to use the classifier from another file to predict in unseen data, I cannot do it because it is telling my that the number of features of the classifier is not the same than the number of fea... | 1 | 2016-10-10T15:04:18Z | 39,965,035 | <blockquote>
<p>This means I also have to save my vocabulary from training in order to test? </p>
</blockquote>
<p>Yes, you have to save <strong>whole tfidf vectorizer</strong>, which in particular means saving vocabulary.</p>
<blockquote>
<p>What will happen if there are terms that did not exist on training?</p>... | 1 | 2016-10-10T19:01:36Z | [
"python",
"machine-learning",
"scikit-learn",
"classification",
"prediction"
] |
Issues with thread and dynamic list in python | 39,961,315 | <p>I will try to be clear, hoping everyobdy will understand even if it will not be easy for me.
I'm a beginner in coding in python so every help will be nice !
I've got those librairies import : requests and threading.
I'm trying to send in parrallel several urls to reduce the sending time of data. I used a dynamic li... | 1 | 2016-10-10T15:05:30Z | 39,961,489 | <p>From the <a href="https://docs.python.org/2/library/threading.html#threading.Thread" rel="nofollow">docs</a>, args should be a tuple.</p>
<blockquote>
<p>class <code>threading.Thread</code>(group=None, target=None, name=None, args=(), kwargs={})</p>
<p>args is the argument tuple for the target invocation. De... | 2 | 2016-10-10T15:15:23Z | [
"python",
"multithreading",
"dynamic-list"
] |
Improving database query speed with Python | 39,961,322 | <p>Edit - I am using Windows 10</p>
<p>Is there a faster alternative to pd._read_sql_query for a MS SQL database?</p>
<p>I was using pandas to read the data and add some columns and calculations on the data. I have cut out most of the alterations now and I am basically just reading (1-2 million rows per day at a time... | 1 | 2016-10-10T15:05:52Z | 39,961,398 | <p><strong>UPDATE:</strong></p>
<p>you can also try to unload data using <a href="https://technet.microsoft.com/en-us/library/ms162802(v=sql.110).aspx" rel="nofollow">bcp utility</a>, which might be lot faster compared to <code>pd.read_sql()</code>, but you will need a local installation of <code>Microsoft Command Lin... | 0 | 2016-10-10T15:11:07Z | [
"python",
"pandas",
"sqlalchemy"
] |
PDF Encryption Using Python | 39,961,362 | <p>The code below takes in a single pdf file and then encrypts it, What i want it to do is to take a directory containing pdf files and encrypt the files in that directory automatically, instead of specifying each file explicitly. Please help ! </p>
<pre><code>def main():
parser = argparse.ArgumentParser()
par... | -1 | 2016-10-10T15:08:43Z | 39,961,443 | <pre><code>import glob
import os
os.chdir('/some/directory/that/has/pdfs')
for file in glob.glob('*.pdf'):
set_password(file, upass, opass)
</code></pre>
| 0 | 2016-10-10T15:13:12Z | [
"python",
"python-2.7"
] |
Regex in python for positive and negative integer | 39,961,414 | <p>I am new to learning regex in python and I'm wondering how do I use regex in python to store the integers(positive and negative) i want into a list!</p>
<p>For example</p>
<p>This is the data in a list.</p>
<pre><code>data =
[u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)',
u'\x1b[0m[\x1... | -1 | 2016-10-10T15:12:02Z | 39,961,689 | <p>For a positive and negative integer, with or without commas in between use: <code>-?(?:\d+,?)+</code></p>
<p><code>-?</code> with or without negative sign<br>
<code>(?:</code> opens a group<br>
<code>\d+</code> one or more digits<br>
<code>,?</code> optional comma<br>
<code>)</code> closes the group<br>
<code>(?:\d... | 0 | 2016-10-10T15:27:38Z | [
"python",
"regex"
] |
Regex in python for positive and negative integer | 39,961,414 | <p>I am new to learning regex in python and I'm wondering how do I use regex in python to store the integers(positive and negative) i want into a list!</p>
<p>For example</p>
<p>This is the data in a list.</p>
<pre><code>data =
[u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)',
u'\x1b[0m[\x1... | -1 | 2016-10-10T15:12:02Z | 39,961,751 | <p>Depending on what you are trying to accomplish, this may work:</p>
<pre><code>import re
data = [
u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)',
u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=5,Y=5)',
u'\x1b[0m[\x1b[1m\x1b[10m\xbb\x1b[0m\x1b[36m]\x1b[0m : '
]
for line in data:... | 0 | 2016-10-10T15:31:35Z | [
"python",
"regex"
] |
Working with dictionaries and data to and from database - Python 3 | 39,961,429 | <p>I have a data which looks like (as example) - </p>
<pre><code>{"phone_number": "XXX1","phone_number_country": "XXX2","text": "XXX2"}
</code></pre>
<p>where XXX is my data (it can be different types of data)</p>
<p>Also, I have DB with data, which looks like (as example) -
[<img src="http://i.stack.imgur.com/41UE... | -2 | 2016-10-10T15:12:34Z | 39,973,638 | <p>Dictionaries in python do not maintain the insertion order by default. You need ordered dictionary for this.</p>
<p>I have reproduced a part of your code below:</p>
<pre><code>import collections
a = collections.OrderedDict()
for elem in b:
b[i] = elem
a["phone_number"] = elem[0]
a["phone_number_country"] = ... | 0 | 2016-10-11T08:54:38Z | [
"python",
"arrays",
"database"
] |
Working with dictionaries and data to and from database - Python 3 | 39,961,429 | <p>I have a data which looks like (as example) - </p>
<pre><code>{"phone_number": "XXX1","phone_number_country": "XXX2","text": "XXX2"}
</code></pre>
<p>where XXX is my data (it can be different types of data)</p>
<p>Also, I have DB with data, which looks like (as example) -
[<img src="http://i.stack.imgur.com/41UE... | -2 | 2016-10-10T15:12:34Z | 39,980,250 | <p>Answer here:</p>
<pre><code>a = {"phone_number": "XXX","phone_number_country": "XXX","text": "XXX"}
con = sqlite3.connect('dab')
cur = con.cursor()
c = cur.execute('SELECT * FROM some')
u_data = c.fetchall()
s = list(u_data)
i = 0
for elem in s:
s[i] = elem
a["phone_number"] = elem[0]
a["phone_number_c... | 0 | 2016-10-11T14:56:40Z | [
"python",
"arrays",
"database"
] |
"ImportError: module 'xxxxxxxx' has no attribute 'main'" when porting project to Heroku | 39,961,843 | <p>I'm attempting to port a Python pyramid app to Heroku.</p>
<p>I must admit that I do not understand the file structure of a Python app, even after reading this very informative thread which seems like it contains all the answers: <a href="https://what.thedailywtf.com/topic/18922/python-project-structure/27" rel="n... | 1 | 2016-10-10T15:37:54Z | 40,113,034 | <p>I don't think there is a clear reason this isn't working. There's a few things you could improve though.</p>
<p>1) Most <code>setup.py</code> files expect to be executed from their own directory. When you run <code>python some_folder/setup.py develop</code> you are asking for a bad time. <code>pip</code> solves thi... | 1 | 2016-10-18T16:04:04Z | [
"python",
"heroku",
"pyramid"
] |
Select rows of DataFrame with datetime index based on date | 39,961,862 | <p>From the following DataFrame with datetime index</p>
<pre><code> 'A'
2015-02-17 14:31:00+00:00 127.2801
2015-02-17 14:32:00+00:00 127.7250
2015-02-17 14:33:00+00:00 127.8010
2015-02-17 14:34:00+00:00 127.5450
2015-02-17 14:35:00+00:00 ... | 1 | 2016-10-10T15:38:58Z | 39,961,908 | <p><code>DatetimeIndex</code> supports partial datetime strings for <a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html#datetimeindex-partial-string-indexing" rel="nofollow">label based indexing</a>:</p>
<pre><code>In [18]:
df.loc['2015-02-17']
Out[18]:
A
2015-02-17 14:31:... | 2 | 2016-10-10T15:42:03Z | [
"python",
"datetime",
"pandas"
] |
How to pull out number in string with python? | 39,961,883 | <p>I have a project where I pull out some posts of a subreddit (/r/buildapcsales) and email me with some deals.</p>
<p>For example: </p>
<ol>
<li>[Monitor] AOC 21.5" 1080p 75Hz 1ms FreeSync Monitor - <strong>$105</strong> ($229.99 - $110 sale - $15 promo thru 10/13)</li>
<li>[Monitor] EQD Auria EQ278CG 27 inch 144hz ... | -2 | 2016-10-10T15:40:27Z | 39,961,939 | <blockquote>
<p>I cant use regex because that will pull out the calculations (i.e. $449.99 - $200 Instant Rebate) on the right also.</p>
</blockquote>
<p>You can still use regular expressions and extract <em>the first amount coming after the dash</em>:</p>
<pre><code>import re
lines = [
'1. [Monitor] AOC 21.5"... | 2 | 2016-10-10T15:43:57Z | [
"python",
"regex",
"string",
"reddit"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.