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 |
|---|---|---|---|---|---|---|---|---|---|
recurse over a list | 2,458,075 | <p>I'm trying to recurse over a list (eg. [True, [[True, False], [False, [False, True]]]]) using Python. I know that the list length will always be 2 and both values will be boolean. I'd like to take those values and substitute them back into the list until there are only 2 values left (or 1 boolean value). Any help... | 2 | 2010-03-16T20:57:18Z | 2,458,105 | <p>You haven't said how to combine the two parts, so I'm assuming <code>or</code> but you could use another function instead.</p>
<pre><code>l = [True, [[True, False], [False, [False, True]]]]
def foo(x):
if isinstance(x, list):
return foo(x[0]) or foo(x[1])
else:
return x
print foo(l)
</code... | 4 | 2010-03-16T21:02:04Z | [
"python",
"recursion"
] |
recurse over a list | 2,458,075 | <p>I'm trying to recurse over a list (eg. [True, [[True, False], [False, [False, True]]]]) using Python. I know that the list length will always be 2 and both values will be boolean. I'd like to take those values and substitute them back into the list until there are only 2 values left (or 1 boolean value). Any help... | 2 | 2010-03-16T20:57:18Z | 2,458,108 | <p>say your list is <code>l</code></p>
<pre><code>def print_list(list):
t = type(list())
for item in list:
if type(item) is t:
print_list(item)
else:
print item
print_list(l)
</code></pre>
<p>Something simple like that would print every item in your list. </p>
| 0 | 2010-03-16T21:02:53Z | [
"python",
"recursion"
] |
Should I strip the XML declaration from suds output before parsing with lxml? | 2,458,244 | <p>Iâm trying to implement a SOAP webservice in Python 2.6 using the <a href="https://fedorahosted.org/suds/" rel="nofollow" title="Suds is a lightweight SOAP python client for consuming Web Services.">suds</a> library. That is working well, but Iâve run into a problem when trying to parse the output with <a href="... | 1 | 2010-03-16T21:21:05Z | 2,458,309 | <p>Hmm, I'm currently implementing my first Suds-based solution and parsing my responses with lxml without a problem, but I think this could be because I'm doing it in a pretty blunt and dumb way. Here's what my code looks like:</p>
<pre><code>try:
result = self.client.service.ExportOwnersDetails(fAccess=self.acce... | 1 | 2010-03-16T21:30:42Z | [
"python",
"unicode",
"soap",
"lxml",
"suds"
] |
Should I strip the XML declaration from suds output before parsing with lxml? | 2,458,244 | <p>Iâm trying to implement a SOAP webservice in Python 2.6 using the <a href="https://fedorahosted.org/suds/" rel="nofollow" title="Suds is a lightweight SOAP python client for consuming Web Services.">suds</a> library. That is working well, but Iâve run into a problem when trying to parse the output with <a href="... | 1 | 2010-03-16T21:21:05Z | 2,458,442 | <p>You and lxml are correct; a valid XML document must be a stream of bytes encoded as declared in the <code><?xml .....</code> header (default: UTF-8).</p>
<p>I'd suggest a third option: leave it in unicode with an XML header that omits the encoding declaration but leaves the version in there (future-safe). That w... | 2 | 2010-03-16T21:54:50Z | [
"python",
"unicode",
"soap",
"lxml",
"suds"
] |
How to schedule hundreds of thousands of tasks? | 2,458,296 | <p>We have hundreds of thousands of tasks that need to be run at a variety of arbitrary intervals, some every hour, some every day, and so on. The tasks are resource intensive and need to be distributed across many machines.</p>
<p>Right now tasks are stored in a database with an "execute at this time" timestamp. To f... | 14 | 2010-03-16T21:28:27Z | 2,458,335 | <p>If you're worried about writes, you can have a set of servers that dispatch the tasks (may be stripe the servers to equalize load) and have each server write bulk checkpoints to the DB (this way, you will not have so many write queries). You still have to write to be able to recover if scheduling server dies, of cou... | 1 | 2010-03-16T21:35:24Z | [
"python"
] |
How to schedule hundreds of thousands of tasks? | 2,458,296 | <p>We have hundreds of thousands of tasks that need to be run at a variety of arbitrary intervals, some every hour, some every day, and so on. The tasks are resource intensive and need to be distributed across many machines.</p>
<p>Right now tasks are stored in a database with an "execute at this time" timestamp. To f... | 14 | 2010-03-16T21:28:27Z | 2,458,367 | <p>Why hundreds of thousands and not hundreds of millions ? :evil:</p>
<p>I think you need stackless python, <a href="http://www.stackless.com/" rel="nofollow">http://www.stackless.com/</a>. created by the genius of Christian Tismer.</p>
<p>Quoting </p>
<blockquote>
<p>Stackless Python is an enhanced
version of ... | 0 | 2010-03-16T21:41:40Z | [
"python"
] |
How to schedule hundreds of thousands of tasks? | 2,458,296 | <p>We have hundreds of thousands of tasks that need to be run at a variety of arbitrary intervals, some every hour, some every day, and so on. The tasks are resource intensive and need to be distributed across many machines.</p>
<p>Right now tasks are stored in a database with an "execute at this time" timestamp. To f... | 14 | 2010-03-16T21:28:27Z | 2,458,389 | <p>If you don't want a database, you could store just the next run timestamp and task id in memory. You could store the properties for each task in a file named [task_id].txt. You would need a data structure to store all the tasks, sorted by timestamp in memory, an AVL tree seems like it would work, here's a simple one... | 3 | 2010-03-16T21:43:55Z | [
"python"
] |
How to schedule hundreds of thousands of tasks? | 2,458,296 | <p>We have hundreds of thousands of tasks that need to be run at a variety of arbitrary intervals, some every hour, some every day, and so on. The tasks are resource intensive and need to be distributed across many machines.</p>
<p>Right now tasks are stored in a database with an "execute at this time" timestamp. To f... | 14 | 2010-03-16T21:28:27Z | 2,459,219 | <p>Since ACID isn't needed and you're okay with tasks potentially running twice, I wouldn't keep the timestamps in the database at all. For each task, create a list of [timestamp_of_next_run, task_id] and use a <a href="http://en.wikipedia.org/wiki/Heap_%28data_structure%29" rel="nofollow">min-heap</a> to store all of... | 5 | 2010-03-17T00:45:24Z | [
"python"
] |
How to schedule hundreds of thousands of tasks? | 2,458,296 | <p>We have hundreds of thousands of tasks that need to be run at a variety of arbitrary intervals, some every hour, some every day, and so on. The tasks are resource intensive and need to be distributed across many machines.</p>
<p>Right now tasks are stored in a database with an "execute at this time" timestamp. To f... | 14 | 2010-03-16T21:28:27Z | 2,459,571 | <blockquote>
<p>350,000 tasks * 48 times per day is
16,800,000 tasks executed per day.</p>
</blockquote>
<p>To schedule the jobs, you don't need a database.</p>
<p>Databases are for things that are <strong>updated</strong>. The only update visible here is a change to the schedule to add, remove or reschedule a j... | 1 | 2010-03-17T02:32:41Z | [
"python"
] |
Giving users a "reputation system" - Should I...? | 2,458,355 | <p>I'm thinking of adding a reputation system to my Django web application; the site is already being used so I'm trying to be careful about my choices.</p>
<p>Reputation is generated in all actions that contribute to the site, similar to Stackoverflow's system.</p>
<p>I know there are literally millions of ways of i... | 3 | 2010-03-16T21:39:08Z | 2,458,375 | <p>keep track of the reasons, IMHO. It surely wouldn't be that complex, and you don't need to store a huge amount of information, just a datetime, point value, command, target, and originator. If the data gets to be too much after some time dump the DB to a backup medium and clear the history.</p>
| 3 | 2010-03-16T21:42:48Z | [
"python",
"django",
"web-applications"
] |
Giving users a "reputation system" - Should I...? | 2,458,355 | <p>I'm thinking of adding a reputation system to my Django web application; the site is already being used so I'm trying to be careful about my choices.</p>
<p>Reputation is generated in all actions that contribute to the site, similar to Stackoverflow's system.</p>
<p>I know there are literally millions of ways of i... | 3 | 2010-03-16T21:39:08Z | 2,458,468 | <p>In Django, I'd suggest having a property on the User (or Profile) model that calculates a user's reputation on-demand. Then, cache the reputation with your caching framework and/or store to the database for fast retrieval.</p>
<p>This way, in addition to having the records of what impacts reputation, you can chang... | 5 | 2010-03-16T21:59:38Z | [
"python",
"django",
"web-applications"
] |
Concatenate multi value into one record | 2,458,585 | <p>I joined two tables together and what I like to do is concatenate multi vaule in one records without duplicated value.</p>
<ol>
<li><p>Input Table<br/><br/>
Table name: TAXLOT_ZONE<br/>
TID ZONE<br/>
1 A<br/>
1 A<br/>
1 B<br/>
1 C<br/>
2 D<br/>
2 D <br/>
2 E<br/>
3 A<br/>
3 B<b... | 0 | 2010-03-16T22:20:08Z | 2,458,638 | <p>Assuming your table is in sorted order and is iterable, you can use <a href="http://docs.python.org/library/itertools.html" rel="nofollow"><code>itertools.groupby</code></a> to group rows with the same first element.</p>
<pre><code>l = [(1, 'A'), (1, 'A'), (1, 'B'), (1, 'C'),
(2, 'D'), (2, 'D'), (2, 'E'),
... | 1 | 2010-03-16T22:32:29Z | [
"python"
] |
How to apply a function to a collection of elements | 2,458,621 | <p>Consider I have an array of elements out of which I want to create a new 'iterable' which on every <em>next</em> applies a custom 'transformation'. What's the proper way of doing it under python 2.x?</p>
<p>For people familiar with Java, the equivalent is Iterables#transform from google's collections framework.</p>... | 1 | 2010-03-16T22:29:16Z | 2,458,633 | <p>A generator expression:</p>
<pre><code>(foobar(x) for x in S)
</code></pre>
| 5 | 2010-03-16T22:31:38Z | [
"python"
] |
How to apply a function to a collection of elements | 2,458,621 | <p>Consider I have an array of elements out of which I want to create a new 'iterable' which on every <em>next</em> applies a custom 'transformation'. What's the proper way of doing it under python 2.x?</p>
<p>For people familiar with Java, the equivalent is Iterables#transform from google's collections framework.</p>... | 1 | 2010-03-16T22:29:16Z | 2,458,654 | <p>Or by using <code>map()</code>:</p>
<pre><code>def foo(x):
return x**x
for y in map(foo,S):
bar(y)
# for simple functions, lambda's are applicable as well
for y in map(lambda x: x**x,S):
bar(y)
</code></pre>
| 1 | 2010-03-16T22:35:40Z | [
"python"
] |
How to apply a function to a collection of elements | 2,458,621 | <p>Consider I have an array of elements out of which I want to create a new 'iterable' which on every <em>next</em> applies a custom 'transformation'. What's the proper way of doing it under python 2.x?</p>
<p>For people familiar with Java, the equivalent is Iterables#transform from google's collections framework.</p>... | 1 | 2010-03-16T22:29:16Z | 2,458,729 | <p>Another way of doing it:</p>
<pre><code>from itertools import imap
my_generator = imap(my_function, my_iterable)
</code></pre>
<p>That's the way I'd do it myself, but I'm kind of weird in that I actually <em>like</em> <code>map</code>.</p>
| 3 | 2010-03-16T22:52:46Z | [
"python"
] |
Abort a slow flush to disk after write? | 2,458,624 | <p>Is there a way to abort a python write operation in such a way that the OS doesn't feel it's necessary to flush the unwritten data to the disc?</p>
<p>I'm writing data to a USB device, typically many megabytes. I'm using 4096 bytes as my block size on the write, but it appears that Linux caches up a bunch of data e... | 3 | 2010-03-16T22:30:18Z | 2,458,697 | <p>It's somewhat filesystem dependent, but in some filesystems, if you delete a file before (all of) it is allocated, the IO to write the blocks will never happen. This might also be true if you truncate it so that the part which is still being written is chopped off.</p>
<p>Not sure that you can really abort a write ... | 2 | 2010-03-16T22:44:58Z | [
"python",
"linux",
"file-io",
"flush"
] |
Abort a slow flush to disk after write? | 2,458,624 | <p>Is there a way to abort a python write operation in such a way that the OS doesn't feel it's necessary to flush the unwritten data to the disc?</p>
<p>I'm writing data to a USB device, typically many megabytes. I'm using 4096 bytes as my block size on the write, but it appears that Linux caches up a bunch of data e... | 3 | 2010-03-16T22:30:18Z | 2,458,709 | <p>Assuming I am understanding this correct, you want to be able to 'abort' and NOT flush the data. This IS possible using a ctype and a little pokery. This is very OS dependent so I'll give you the OSX version and then what you can do to change it to Linux:</p>
<pre><code>f = open('flibble1.txt', 'w')
f.write("hello ... | 2 | 2010-03-16T22:47:12Z | [
"python",
"linux",
"file-io",
"flush"
] |
Abort a slow flush to disk after write? | 2,458,624 | <p>Is there a way to abort a python write operation in such a way that the OS doesn't feel it's necessary to flush the unwritten data to the disc?</p>
<p>I'm writing data to a USB device, typically many megabytes. I'm using 4096 bytes as my block size on the write, but it appears that Linux caches up a bunch of data e... | 3 | 2010-03-16T22:30:18Z | 2,458,871 | <p>When you abort the write operation, trying doing <code>file.truncate(0);</code> before closing it.</p>
| 1 | 2010-03-16T23:17:22Z | [
"python",
"linux",
"file-io",
"flush"
] |
Absolute path of a file object | 2,458,676 | <p>This has been discussed on StackOverflow before - I am trying to find a good way to find the absolute path of a file object, but I need it to be robust to <code>os.chdir()</code>, so cannot use </p>
<pre><code>f = file('test')
os.path.abspath(f.name)
</code></pre>
<p>Instead, I was wondering whether the following ... | 12 | 2010-03-16T22:41:23Z | 2,458,866 | <p>One significant risk is that, once the file is open, the process is dealing with that file by its file descriptor, <em>not</em> its path. On many operating systems, <strong>the file's path can be changed by any other process</strong> (by a <code>mv</code> operation in an unrelated process, say) and the file descript... | 11 | 2010-03-16T23:15:54Z | [
"python",
"file",
"filesystems"
] |
Absolute path of a file object | 2,458,676 | <p>This has been discussed on StackOverflow before - I am trying to find a good way to find the absolute path of a file object, but I need it to be robust to <code>os.chdir()</code>, so cannot use </p>
<pre><code>f = file('test')
os.path.abspath(f.name)
</code></pre>
<p>Instead, I was wondering whether the following ... | 12 | 2010-03-16T22:41:23Z | 2,464,241 | <p>It depends on what you need it for.</p>
<p>As long as you understand the limitations--someone might move, rename, or hard-link the file in the interim--there are plenty of appropriate uses for this. You may want to delete the file when you're done with it or if something goes wrong while writing it (eg. gcc does t... | 1 | 2010-03-17T17:00:43Z | [
"python",
"file",
"filesystems"
] |
Normalising book titles - Python | 2,458,720 | <p>I have a list of books titles:</p>
<ul>
<li>"The Hobbit: 70th Anniversary Edition"</li>
<li>"The Hobbit"</li>
<li>"The Hobbit (Illustrated/Collector Edition)[There and Back Again]"</li>
<li>"The Hobbit: or, There and Back Again"</li>
<li>"The Hobbit: Gift Pack"</li>
</ul>
<p>and so on...</p>
<hr>
<p>I thought th... | 0 | 2010-03-16T22:51:09Z | 2,458,773 | <p>It depends completely on your data. For the examples you gave, a simple normalization solution could be:</p>
<pre><code>import re
book_normalized = re.sub(r':.*|\[.*?\]|\(.*?\)|\{.*?\}', '', book_name).strip()
</code></pre>
<p>This will return "The Hobbit" for all the examples. What it does is remove anything aft... | 1 | 2010-03-16T22:59:09Z | [
"python",
"django",
"string",
"data-cleansing"
] |
Normalising book titles - Python | 2,458,720 | <p>I have a list of books titles:</p>
<ul>
<li>"The Hobbit: 70th Anniversary Edition"</li>
<li>"The Hobbit"</li>
<li>"The Hobbit (Illustrated/Collector Edition)[There and Back Again]"</li>
<li>"The Hobbit: or, There and Back Again"</li>
<li>"The Hobbit: Gift Pack"</li>
</ul>
<p>and so on...</p>
<hr>
<p>I thought th... | 0 | 2010-03-16T22:51:09Z | 2,459,623 | <p>I would suggest using a 3rd party web service, such as <a href="http://librarything.com/" rel="nofollow">librarything</a> which I believe can do what you're asking, for a starting point, see their documentation:</p>
<p><a href="http://www.librarything.com/services/rest/documentation/1.0/librarything.ck.getwork.php"... | 1 | 2010-03-17T02:50:31Z | [
"python",
"django",
"string",
"data-cleansing"
] |
How do I copy only the values and not the references from a Python list? | 2,458,904 | <p>Specifically, I want to create a backup of a list, then make some changes to that list, append all the changes to a third list, but then reset the first list with the backup before making further changes, etc, until I'm finished making changes and want to copy back all the content in the third list to the first one.... | 0 | 2010-03-16T23:25:19Z | 2,458,919 | <p>You want <a href="http://docs.python.org/library/copy.html#copy.deepcopy" rel="nofollow"><code>copy.deepcopy()</code></a> for this.</p>
| 8 | 2010-03-16T23:27:17Z | [
"python",
"list",
"backup",
"python-3.x",
"restore"
] |
How do I copy only the values and not the references from a Python list? | 2,458,904 | <p>Specifically, I want to create a backup of a list, then make some changes to that list, append all the changes to a third list, but then reset the first list with the backup before making further changes, etc, until I'm finished making changes and want to copy back all the content in the third list to the first one.... | 0 | 2010-03-16T23:25:19Z | 2,459,073 | <p>The first thing to understand is why that <code>setEqual</code> method can't work: you need to know <a href="http://python.net/~mwh/hacks/objectthink.html#mwh" rel="nofollow">how identifiers work</a>. (Reading that link should be very helpful.) For a quick rundown with probably too much terminology: in your function... | 5 | 2010-03-17T00:04:03Z | [
"python",
"list",
"backup",
"python-3.x",
"restore"
] |
Log errors to database with Django on Google App Engine | 2,459,246 | <p>Is there a project that can log errors in requests to Django on <a href="http://code.google.com/appengine/" rel="nofollow">Google App Engine</a> to the datastore (like <a href="http://code.google.com/p/django-db-log/" rel="nofollow">django-db-log</a> or <a href="http://code.google.com/p/django-crashlog/" rel="nofoll... | 1 | 2010-03-17T00:53:54Z | 2,459,254 | <ol>
<li>Check out <a href="http://www.allbuttonspressed.com/blog/django/2010/01/Native-Django-on-App-Engine" rel="nofollow">Native Django on GAE</a>. It's a non-relational port of Django to Google's App Engine. </li>
<li>Another project,
<a href="http://code.google.com/p/google-app-engine-django/" rel="nofollow">googl... | 1 | 2010-03-17T00:56:48Z | [
"python",
"django",
"google-app-engine",
"logging",
"error-handling"
] |
Log errors to database with Django on Google App Engine | 2,459,246 | <p>Is there a project that can log errors in requests to Django on <a href="http://code.google.com/appengine/" rel="nofollow">Google App Engine</a> to the datastore (like <a href="http://code.google.com/p/django-db-log/" rel="nofollow">django-db-log</a> or <a href="http://code.google.com/p/django-crashlog/" rel="nofoll... | 1 | 2010-03-17T00:53:54Z | 2,465,166 | <p>I've created a project <a href="http://bitbucket.org/brianmhunt/django-gae-log/" rel="nofollow">Django-GAE-log</a> to solve this issue. Thoughts and input are welcome!</p>
| 0 | 2010-03-17T19:16:23Z | [
"python",
"django",
"google-app-engine",
"logging",
"error-handling"
] |
Log errors to database with Django on Google App Engine | 2,459,246 | <p>Is there a project that can log errors in requests to Django on <a href="http://code.google.com/appengine/" rel="nofollow">Google App Engine</a> to the datastore (like <a href="http://code.google.com/p/django-db-log/" rel="nofollow">django-db-log</a> or <a href="http://code.google.com/p/django-crashlog/" rel="nofoll... | 1 | 2010-03-17T00:53:54Z | 2,467,121 | <p>Use the built-in <a href="http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/ext/ereporter/ereporter.py" rel="nofollow"><code>google.appengine.ext.ereporter</code></a> module:</p>
<blockquote>
<p>A logging handler that records
information about unique exceptions.</p>
<p>'U... | 3 | 2010-03-18T01:52:56Z | [
"python",
"django",
"google-app-engine",
"logging",
"error-handling"
] |
Invertible STFT and ISTFT in Python | 2,459,295 | <p>Is there any general-purpose form of <a href="https://en.wikipedia.org/wiki/Short-time_Fourier_transform">short-time Fourier transform</a> with corresponding inverse transform built into SciPy or NumPy or whatever?</p>
<p>There's the pyplot <code>specgram</code> function in matplotlib, which calls <code>ax.specgram... | 40 | 2010-03-17T01:12:29Z | 2,463,894 | <p>I also found this on GitHub, but it seems to operate on pipelines instead of normal arrays:</p>
<p><a href="http://github.com/ronw/frontend/blob/master/basic.py#LID281" rel="nofollow">http://github.com/ronw/frontend/blob/master/basic.py#LID281</a></p>
<pre><code>def STFT(nfft, nwin=None, nhop=None, winfun=np.hanni... | 0 | 2010-03-17T16:13:47Z | [
"python",
"scipy",
"fft",
"signal-processing"
] |
Invertible STFT and ISTFT in Python | 2,459,295 | <p>Is there any general-purpose form of <a href="https://en.wikipedia.org/wiki/Short-time_Fourier_transform">short-time Fourier transform</a> with corresponding inverse transform built into SciPy or NumPy or whatever?</p>
<p>There's the pyplot <code>specgram</code> function in matplotlib, which calls <code>ax.specgram... | 40 | 2010-03-17T01:12:29Z | 2,470,279 | <p>Found another STFT, but no corresponding inverse function:</p>
<p><a href="http://code.google.com/p/pytfd/source/browse/trunk/pytfd/stft.py" rel="nofollow">http://code.google.com/p/pytfd/source/browse/trunk/pytfd/stft.py</a></p>
<pre><code>def stft(x, w, L=None):
...
return X_stft
</code></pre>
<ul>
<li><... | 1 | 2010-03-18T13:54:53Z | [
"python",
"scipy",
"fft",
"signal-processing"
] |
Invertible STFT and ISTFT in Python | 2,459,295 | <p>Is there any general-purpose form of <a href="https://en.wikipedia.org/wiki/Short-time_Fourier_transform">short-time Fourier transform</a> with corresponding inverse transform built into SciPy or NumPy or whatever?</p>
<p>There's the pyplot <code>specgram</code> function in matplotlib, which calls <code>ax.specgram... | 40 | 2010-03-17T01:12:29Z | 6,891,772 | <p>Here is my Python code, simplified for this answer:</p>
<pre><code>import scipy, pylab
def stft(x, fs, framesz, hop):
framesamp = int(framesz*fs)
hopsamp = int(hop*fs)
w = scipy.hanning(framesamp)
X = scipy.array([scipy.fft(w*x[i:i+framesamp])
for i in range(0, len(x)-framesam... | 54 | 2011-07-31T19:30:16Z | [
"python",
"scipy",
"fft",
"signal-processing"
] |
Invertible STFT and ISTFT in Python | 2,459,295 | <p>Is there any general-purpose form of <a href="https://en.wikipedia.org/wiki/Short-time_Fourier_transform">short-time Fourier transform</a> with corresponding inverse transform built into SciPy or NumPy or whatever?</p>
<p>There's the pyplot <code>specgram</code> function in matplotlib, which calls <code>ax.specgram... | 40 | 2010-03-17T01:12:29Z | 6,906,389 | <p>If you have access to a C binary library that does what you want, then use <a href="http://code.google.com/p/ctypesgen/" rel="nofollow">http://code.google.com/p/ctypesgen/</a> to generate a Python interface to that library.</p>
| -3 | 2011-08-02T01:31:17Z | [
"python",
"scipy",
"fft",
"signal-processing"
] |
Invertible STFT and ISTFT in Python | 2,459,295 | <p>Is there any general-purpose form of <a href="https://en.wikipedia.org/wiki/Short-time_Fourier_transform">short-time Fourier transform</a> with corresponding inverse transform built into SciPy or NumPy or whatever?</p>
<p>There's the pyplot <code>specgram</code> function in matplotlib, which calls <code>ax.specgram... | 40 | 2010-03-17T01:12:29Z | 20,409,020 | <p>Here is the STFT code that I use. STFT + ISTFT here gives <em>perfect reconstruction</em> (even for the first frames). I slightly modified the code given here by Steve Tjoa : here the magnitude of the reconstructed signal is the same as that of the input signal.</p>
<pre><code>import scipy, numpy as np
def stft(x,... | 6 | 2013-12-05T19:38:28Z | [
"python",
"scipy",
"fft",
"signal-processing"
] |
Invertible STFT and ISTFT in Python | 2,459,295 | <p>Is there any general-purpose form of <a href="https://en.wikipedia.org/wiki/Short-time_Fourier_transform">short-time Fourier transform</a> with corresponding inverse transform built into SciPy or NumPy or whatever?</p>
<p>There's the pyplot <code>specgram</code> function in matplotlib, which calls <code>ax.specgram... | 40 | 2010-03-17T01:12:29Z | 23,642,203 | <p>Neither of the above answers worked well OOTB for me. So I modified Steve Tjoa's. </p>
<pre><code>import scipy, pylab
import numpy as np
def stft(x, fs, framesz, hop):
"""
x - signal
fs - sample rate
framesz - frame size
hop - hop size (frame size = overlap + hop size)
"""
framesa... | 1 | 2014-05-13T21:50:42Z | [
"python",
"scipy",
"fft",
"signal-processing"
] |
Invertible STFT and ISTFT in Python | 2,459,295 | <p>Is there any general-purpose form of <a href="https://en.wikipedia.org/wiki/Short-time_Fourier_transform">short-time Fourier transform</a> with corresponding inverse transform built into SciPy or NumPy or whatever?</p>
<p>There's the pyplot <code>specgram</code> function in matplotlib, which calls <code>ax.specgram... | 40 | 2010-03-17T01:12:29Z | 28,036,839 | <p><a href="http://bmcfee.github.io/librosa/librosa.html#librosa.core.stft" rel="nofollow"><code>librosa.core.stft</code></a> and <a href="http://bmcfee.github.io/librosa/librosa.html#librosa.core.istft" rel="nofollow"><code>istft</code></a> look pretty similar to what I was looking for, though they didn't exist at the... | 1 | 2015-01-20T02:32:40Z | [
"python",
"scipy",
"fft",
"signal-processing"
] |
Invertible STFT and ISTFT in Python | 2,459,295 | <p>Is there any general-purpose form of <a href="https://en.wikipedia.org/wiki/Short-time_Fourier_transform">short-time Fourier transform</a> with corresponding inverse transform built into SciPy or NumPy or whatever?</p>
<p>There's the pyplot <code>specgram</code> function in matplotlib, which calls <code>ax.specgram... | 40 | 2010-03-17T01:12:29Z | 36,459,973 | <p>I think scipy.signal has what you are looking for. It has reasonable defaults, supports multiple window types, etc...</p>
<p><a href="http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.signal.spectrogram.html" rel="nofollow">http://docs.scipy.org/doc/scipy-0.17.0/reference/generated/scipy.signal.spect... | 0 | 2016-04-06T18:55:32Z | [
"python",
"scipy",
"fft",
"signal-processing"
] |
Python importing | 2,459,300 | <p>I have a file, <code>myfile.py</code>, which imports <code>Class1</code> from <code>file.py</code> and <code>file.py</code> contains imports to different classes in <code>file2.py</code>, <code>file3.py</code>, <code>file4.py</code>.</p>
<p>In my <code>myfile.py</code>, can I access these classes or do I need to ag... | 1 | 2010-03-17T01:13:33Z | 2,459,311 | <p>Python doesn't automatically introduce anything into the namespace of myfile.py, but you can access everything that is in the namespaces of all the other modules. </p>
<p>That is to say, if in file1.py you did <code>from file2 import SomeClass</code> and in myfile.py you did <code>import file1</code>, then you can ... | 1 | 2010-03-17T01:15:14Z | [
"python",
"import"
] |
Python importing | 2,459,300 | <p>I have a file, <code>myfile.py</code>, which imports <code>Class1</code> from <code>file.py</code> and <code>file.py</code> contains imports to different classes in <code>file2.py</code>, <code>file3.py</code>, <code>file4.py</code>.</p>
<p>In my <code>myfile.py</code>, can I access these classes or do I need to ag... | 1 | 2010-03-17T01:13:33Z | 2,459,322 | <p>In the myfile module, you can either do <code>from file import ClassFromFile2</code> or <code>from file2 import ClassFromFile2</code> to access ClassFromFile2, assuming that the class is also imported in file.</p>
<p>This technique is often used to simplify the API a bit. For example, a db.py module might import va... | 0 | 2010-03-17T01:19:23Z | [
"python",
"import"
] |
Python importing | 2,459,300 | <p>I have a file, <code>myfile.py</code>, which imports <code>Class1</code> from <code>file.py</code> and <code>file.py</code> contains imports to different classes in <code>file2.py</code>, <code>file3.py</code>, <code>file4.py</code>.</p>
<p>In my <code>myfile.py</code>, can I access these classes or do I need to ag... | 1 | 2010-03-17T01:13:33Z | 2,459,332 | <p>If you are using wildcard import, yes, wildcard import actually is the way of creating new aliases in your current namespace for contents of the imported module. If not, you need to use the namespace of the module you have imported as usual.</p>
| 0 | 2010-03-17T01:23:51Z | [
"python",
"import"
] |
Python importing | 2,459,300 | <p>I have a file, <code>myfile.py</code>, which imports <code>Class1</code> from <code>file.py</code> and <code>file.py</code> contains imports to different classes in <code>file2.py</code>, <code>file3.py</code>, <code>file4.py</code>.</p>
<p>In my <code>myfile.py</code>, can I access these classes or do I need to ag... | 1 | 2010-03-17T01:13:33Z | 2,459,384 | <p>Best practice is to import every module that defines identifiers you need, and use those identifiers as <em>qualified</em> by the module's name; I recommend using <code>from</code> only when what you're importing is a module from within a package. The question has often been discussed on SO.</p>
<p>Importing a mod... | 8 | 2010-03-17T01:38:09Z | [
"python",
"import"
] |
web2py or grok (zope) on a big portal, | 2,459,549 | <p>I am planning to make some big project (1 000 000 users, approximately 500 request pre second - in hot time).
For performance I'm going to use no relational dbms (each request could cost lot of instructions in relational dbms like mysql) - so i can't use DAL.</p>
<p>My question is:</p>
<ol>
<li>how web2py is worki... | 3 | 2010-03-17T02:26:22Z | 2,459,620 | <p>First, don't assume that a data abstraction layer will have unacceptable performance, until you actually see it in practice. It is pretty easy to switch to RAW sql if and when you run into a problem.</p>
<p>Second, most users who worry about there server technology handling a million users never finish their appli... | 7 | 2010-03-17T02:48:39Z | [
"python",
"zope",
"web2py",
"zodb",
"grok"
] |
web2py or grok (zope) on a big portal, | 2,459,549 | <p>I am planning to make some big project (1 000 000 users, approximately 500 request pre second - in hot time).
For performance I'm going to use no relational dbms (each request could cost lot of instructions in relational dbms like mysql) - so i can't use DAL.</p>
<p>My question is:</p>
<ol>
<li>how web2py is worki... | 3 | 2010-03-17T02:26:22Z | 2,460,054 | <p>I agree with mikerobi - pick what will let you develop fastest. For me that is web2py.</p>
<p><a href="http://googleappengine.blogspot.com/2009/05/web2py-support-new-datastore-backend.html" rel="nofollow">web2py runs on Google App Engine</a>, so if you don't want to use a relational database then you can use Google... | 4 | 2010-03-17T05:20:12Z | [
"python",
"zope",
"web2py",
"zodb",
"grok"
] |
web2py or grok (zope) on a big portal, | 2,459,549 | <p>I am planning to make some big project (1 000 000 users, approximately 500 request pre second - in hot time).
For performance I'm going to use no relational dbms (each request could cost lot of instructions in relational dbms like mysql) - so i can't use DAL.</p>
<p>My question is:</p>
<ol>
<li>how web2py is worki... | 3 | 2010-03-17T02:26:22Z | 9,985,357 | <p>Zope and the ZODB have been used with big applications, but I'd still consider linking Zope with MySQL or something like that for serious large-scale applications. Even though Zope has had a lot of development cycles, it is usually used with another database engine for good reason. As far as I know, the argument a... | 1 | 2012-04-02T23:48:03Z | [
"python",
"zope",
"web2py",
"zodb",
"grok"
] |
Pass by reference in Boost::Python | 2,459,588 | <p>Consider something like:</p>
<pre><code>struct Parameter
{
int a;
Parameter(){a = 0;}
void setA(int newA){a = newA;}
};
struct MyClass
{
void changeParameter(Parameter &p){ p.setA(-1);}
};
</code></pre>
<p>Well, let's fast forward, and imagine I already wrapped those classes, exposing everythin... | 3 | 2010-03-17T02:37:39Z | 2,483,454 | <p>Python doesn't have references, so when you pass reference to python <code>boost::python</code> calls <code>copy-ctor</code> of your object.</p>
<p>In this case you have two choices: Replace references with pointers (or smart-pointers) <em>or</em> pass into python your own 'smart-reference' object/wrapper.</p>
| 1 | 2010-03-20T14:51:59Z | [
"c++",
"python",
"scripting",
"boost-python"
] |
Are Python properties broken? | 2,459,715 | <p>How can it be that this test case</p>
<pre><code>import unittest
class PropTest(unittest.TestCase):
def test(self):
class C():
val = 'initial val'
def get_p(self):
return self.val
def set_p(self, prop):
if prop == 'legal val':
... | 3 | 2010-03-17T03:23:12Z | 2,459,719 | <p>Your class <code>C</code> does not inherit from <code>object</code> or any other new-style class, so it is an old-style class (and therefore does not support properties). Descriptors are for new-style classes only. To fix, change <code>class C()</code> to <code>class C(object)</code>.</p>
<p><a href="http://www.pyt... | 13 | 2010-03-17T03:25:21Z | [
"python",
"properties",
"message",
"enhancement",
"new-style-class"
] |
Python KMeans clustering words | 2,459,739 | <p>Dear Everyone
I am interested to perform kmeans clustering on a list of words with the distance measure being Leveshtein. </p>
<p>1) I know there are a lot of frameworks out there, including scipy and orange that has a kmeans implementation. However they all require some sort of vector as the data which doesn't rea... | 8 | 2010-03-17T03:29:50Z | 2,460,227 | <p>Not really an answer to your specific question, but I recommend glancing at <a href="http://oreilly.com/catalog/9780596529321" rel="nofollow">"Programming Collective Intelligence"</a>. At the end of each chapter, e.g., clustering, it wanders off into describing all the best reading on the subject.</p>
| 0 | 2010-03-17T06:18:36Z | [
"python",
"cluster-analysis"
] |
Python KMeans clustering words | 2,459,739 | <p>Dear Everyone
I am interested to perform kmeans clustering on a list of words with the distance measure being Leveshtein. </p>
<p>1) I know there are a lot of frameworks out there, including scipy and orange that has a kmeans implementation. However they all require some sort of vector as the data which doesn't rea... | 8 | 2010-03-17T03:29:50Z | 2,460,285 | <p>Yeah I think there isn't a good implementation to what I need. </p>
<p>I have some crazy requirements, like distance caching etc.</p>
<p>So i think i will just write my own lib and release it as GPLv3 soon.</p>
| 1 | 2010-03-17T06:35:34Z | [
"python",
"cluster-analysis"
] |
Python KMeans clustering words | 2,459,739 | <p>Dear Everyone
I am interested to perform kmeans clustering on a list of words with the distance measure being Leveshtein. </p>
<p>1) I know there are a lot of frameworks out there, including scipy and orange that has a kmeans implementation. However they all require some sort of vector as the data which doesn't rea... | 8 | 2010-03-17T03:29:50Z | 8,787,493 | <p>Maybe have a look at <a href="http://www.cs.waikato.ac.nz/ml/weka/" rel="nofollow">Weka</a>. It is a Java library with some unsupervised learning implementations and nice visualization tools. It has been a while since I used it, not sure if it is great for a real production environment but defenitely a good starting... | 0 | 2012-01-09T11:11:43Z | [
"python",
"cluster-analysis"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 2,459,996 | <p>The Python <a href="http://docs.python.org/library/csv.html">csv library</a> can do your parsing and your code can translate them into <code>Products()</code>.</p>
| 9 | 2010-03-17T05:04:15Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 2,462,598 | <p>something like this:</p>
<pre><code>f = open('data.txt', 'r')
for line in f:
line = line.split(';')
product = Product()
product.name = line[2] + '(' + line[1] + ')'
product.description = line[4]
product.price = '' #data is missing from file
product.save()
f.close()
</code></pre... | 5 | 2010-03-17T13:36:34Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 7,625,570 | <p>You can use the django-csv-importer package.
<a href="http://pypi.python.org/pypi/django-csv-importer/0.1.1" rel="nofollow">http://pypi.python.org/pypi/django-csv-importer/0.1.1</a></p>
<p>It works like a django model</p>
<pre><code>MyCsvModel(CsvModel):
field1 = IntegerField()
field2 = CharField()
etc... | 3 | 2011-10-02T09:27:56Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 12,755,224 | <p>You can also use, <a href="http://django-adaptors.readthedocs.org/en/latest/index.html">django-adaptors</a></p>
<pre><code>>>> from adaptor.model import CsvModel
>>> class MyCSvModel(CsvModel):
... name = CharField()
... age = IntegerField()
... length = FloatField()
...
... class ... | 6 | 2012-10-05T23:16:35Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 15,299,953 | <p>Here's a django egg for it: </p>
<p><a href="https://github.com/edcrewe/django-csvimport/tree/master/csvimport" rel="nofollow">django-csvimport</a></p>
| 1 | 2013-03-08T17:34:09Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 15,961,736 | <p>You want to use the csv module that is part of the python language and you should use Django's get_or_create method</p>
<p></p>
<pre><code> with open(path) as f:
reader = csv.reader(f)
for row in reader:
_, created = Teacher.objects.get_or_create(
first_name=row[0],
... | 37 | 2013-04-12T01:41:27Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 24,661,952 | <p>Consider using Django's built-in deserializers. Django's <a href="https://docs.djangoproject.com/en/dev/topics/serialization/#deserializing-data" rel="nofollow">docs</a> are well-written and can help you get started. Consider converting your data from csv to XML or JSON and using a deserializer to import the data. I... | 1 | 2014-07-09T19:12:20Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 24,664,265 | <p>You can give a try to <a href="https://django-import-export.readthedocs.org/en/latest/index.html" rel="nofollow">django-import-export</a>. It has nice admin integration, changes preview, can create, update, delete objects.</p>
| 0 | 2014-07-09T21:42:55Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 24,669,572 | <p>I told you in a comment why you shouldn't be asking this. But you're new and I like new people who come to SO. First of all, look - there's <a href="http://blog.stackoverflow.com/2010/11/qa-is-hard-lets-go-shopping/#howtoask">a way to ask for recommendations</a> - it generally revolves around <em>being specific</em>... | 16 | 2014-07-10T06:12:01Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 31,984,869 | <p>define class in models.py and a function in it.</p>
<pre><code>class all_products(models.Model):
def get_all_products():
fp = open('EXACT FILE PATH OF YOUR CSV FILE','r')
# You can also put relative path of csv file with respect to
# manage.py file
reader1 = csv.reader(fp, delimiter=';')
ite... | 0 | 2015-08-13T09:50:02Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
how to import csv data into django models | 2,459,979 | <p>I have some CSV data and I want to import into django models using the example CSV data:</p>
<pre><code>1;"02-01-101101";"Worm Gear HRF 50";"Ratio 1 : 10";"input shaft, output shaft, direction A, color dark green";
2;"02-01-101102";"Worm Gear HRF 50";"Ratio 1 : 20";"input shaft, output shaft, direction A, color dar... | 33 | 2010-03-17T04:59:20Z | 33,307,642 | <p>Use the <a href="http://pandas.pydata.org/" rel="nofollow">Pandas library</a> to create a dataframe of the csv data.<br>
Name the fields either by including them in the csv file's first line or in code by using the dataframe's columns method.<br>
Then create a list of model instances.<br>
Finally use the django meth... | 1 | 2015-10-23T16:51:30Z | [
"python",
"django",
"csv",
"django-models",
"export"
] |
How to generate lots of redundant ajax elements like checkboxes and pulldowns in Django? | 2,460,014 | <p>I've been getting lots of answers from stackoverflow now that I'm in Django just by searching. Now I hope my question will also create some value for everybody.</p>
<p>In choosing Django, I was hoping there was some similar mechanism to the way you can do partials in ROR. This was going to help me in two ways. O... | 0 | 2010-03-17T05:09:22Z | 2,460,274 | <p>I'm not sure I understand your question, but here's what I think you want, expressed in pseudo-code:</p>
<pre><code>for photo in photos:
form = forms[photo.id]
generate_some_html(photo, form)
</code></pre>
<p>Probably the best way to achieve this is with inclusion tags: <a href="http://docs.djangoproject.c... | 0 | 2010-03-17T06:29:52Z | [
"python",
"django",
"templates",
"forms",
"list"
] |
How to generate lots of redundant ajax elements like checkboxes and pulldowns in Django? | 2,460,014 | <p>I've been getting lots of answers from stackoverflow now that I'm in Django just by searching. Now I hope my question will also create some value for everybody.</p>
<p>In choosing Django, I was hoping there was some similar mechanism to the way you can do partials in ROR. This was going to help me in two ways. O... | 0 | 2010-03-17T05:09:22Z | 8,601,912 | <p>Django doesn't comme with backed AJAX like RAIL, but it let you choose any lib you want to use from the start.</p>
<p>You can do what you want by creating <a href="https://docs.djangoproject.com/en/1.3/ref/forms/widgets/#customizing-widget-instances" rel="nofollow">custom widgets</a> and using <a href="http://ps://... | 0 | 2011-12-22T09:35:57Z | [
"python",
"django",
"templates",
"forms",
"list"
] |
'int' object is not callable when using the sum function on a list | 2,460,087 | <pre><code>coinCount = [2 for i in range(4)]
total = sum(coinCount)
</code></pre>
<p>This gives me</p>
<pre><code>TypeError: 'int' object is not callable
</code></pre>
<p>I don't understand why because</p>
<pre><code>print type(coinCount)
</code></pre>
<p>Gives me</p>
<pre><code>type <'list'>
</code></pre>
| 9 | 2010-03-17T05:32:37Z | 2,460,094 | <p>You no doubt used the identifier <code>sum</code> previously in your code as a local variable name, and the last value you bound to it was an <code>int</code>. So, in that code snippet, you're trying to call the <code>int</code>. <code>print sum</code> just before you try calling it and you'll see, but code inspec... | 34 | 2010-03-17T05:34:29Z | [
"python",
"list"
] |
'int' object is not callable when using the sum function on a list | 2,460,087 | <pre><code>coinCount = [2 for i in range(4)]
total = sum(coinCount)
</code></pre>
<p>This gives me</p>
<pre><code>TypeError: 'int' object is not callable
</code></pre>
<p>I don't understand why because</p>
<pre><code>print type(coinCount)
</code></pre>
<p>Gives me</p>
<pre><code>type <'list'>
</code></pre>
| 9 | 2010-03-17T05:32:37Z | 38,986,381 | <p>I'd like to add on to what Alex Martelli said by saying don't use sum as a variable name but if you're program is too long already or you're using idle and you don't want to start over you can do </p>
<pre><code>sum2 = sum
del sum
</code></pre>
<p>to transfer the value of sum into sum2 (if necessary) and delete th... | 0 | 2016-08-17T00:23:22Z | [
"python",
"list"
] |
Edit Distance in Python | 2,460,177 | <p>I'm programming a spellcheck program in Python. I have a list of valid words (the dictionary) and I need to output a list of words from this dictionary that have an edit distance of 2 from a given invalid word. </p>
<p>I know I need to start by generating a list with an edit distance of one from the invalid word(an... | 14 | 2010-03-17T06:02:07Z | 2,460,201 | <p>You are looking for Norvig's excellent post with source code: </p>
<p>How To Write a Spelling Corrector</p>
<p><a href="http://norvig.com/spell-correct.html">http://norvig.com/spell-correct.html</a></p>
<p>Includes Python source code, theory, and background.</p>
| 20 | 2010-03-17T06:11:19Z | [
"python",
"algorithm",
"edit",
"distance"
] |
Edit Distance in Python | 2,460,177 | <p>I'm programming a spellcheck program in Python. I have a list of valid words (the dictionary) and I need to output a list of words from this dictionary that have an edit distance of 2 from a given invalid word. </p>
<p>I know I need to start by generating a list with an edit distance of one from the invalid word(an... | 14 | 2010-03-17T06:02:07Z | 2,460,612 | <p>The specific algorithm you describe is called Levenshtein distance. A quick Google throws up several Python libraries and recipes to calculate it.</p>
| 2 | 2010-03-17T07:57:41Z | [
"python",
"algorithm",
"edit",
"distance"
] |
Edit Distance in Python | 2,460,177 | <p>I'm programming a spellcheck program in Python. I have a list of valid words (the dictionary) and I need to output a list of words from this dictionary that have an edit distance of 2 from a given invalid word. </p>
<p>I know I need to start by generating a list with an edit distance of one from the invalid word(an... | 14 | 2010-03-17T06:02:07Z | 19,928,962 | <pre><code>#this calculates edit distance not levenstein edit distance
word1="rice"
word2="ice"
len_1=len(word1)
len_2=len(word2)
x =[[0]*(len_2+1) for _ in range(len_1+1)]#the matrix whose last element ->edit distance
for i in range(0,len_1+1): #initialization of base case values
x[i][0]=i
for j in range(... | 7 | 2013-11-12T12:16:49Z | [
"python",
"algorithm",
"edit",
"distance"
] |
Edit Distance in Python | 2,460,177 | <p>I'm programming a spellcheck program in Python. I have a list of valid words (the dictionary) and I need to output a list of words from this dictionary that have an edit distance of 2 from a given invalid word. </p>
<p>I know I need to start by generating a list with an edit distance of one from the invalid word(an... | 14 | 2010-03-17T06:02:07Z | 24,172,422 | <p>Here is my version for Levenshtein distance</p>
<pre>
def edit_distance(s1, s2):
m=len(s1)+1
n=len(s2)+1
tbl = {}
for i in range(m): tbl[i,0]=i
for j in range(n): tbl[0,j]=j
for i in range(1, m):
for j in range(1, n):
cost = 0 if s1[i-1] == s2[j-1] else 1
tbl... | 6 | 2014-06-11T20:56:01Z | [
"python",
"algorithm",
"edit",
"distance"
] |
Edit Distance in Python | 2,460,177 | <p>I'm programming a spellcheck program in Python. I have a list of valid words (the dictionary) and I need to output a list of words from this dictionary that have an edit distance of 2 from a given invalid word. </p>
<p>I know I need to start by generating a list with an edit distance of one from the invalid word(an... | 14 | 2010-03-17T06:02:07Z | 32,558,749 | <p>The thing you are looking at is called an edit distance and here is a <a href="https://en.wikipedia.org/wiki/Edit_distance">nice explanation on wiki</a>. There are a lot of ways how to define a distance between the two words and the one that you want is called Levenshtein distance and here is a DP implementation in ... | 8 | 2015-09-14T06:52:27Z | [
"python",
"algorithm",
"edit",
"distance"
] |
Troubleshooting 'ValueError: time data ... does not match format' when using datetime.strptime | 2,460,233 | <p>My input string is <code>'16-MAR-2010 03:37:04'</code> and i want to store it as datetime. </p>
<p>I am trying to use: </p>
<pre><code>db_inst.HB_Create_Ship_Date = datetime.strptime(fields[7]," %d-%b-%Y %H:%M:%S ")
fields[7] = '16-MAR-2010 03:37:04'
</code></pre>
<p>I am getting an error:</p>
<pre><code>::Val... | 1 | 2010-03-17T06:19:55Z | 2,460,267 | <p>Lose the spaces at the front and back of your format. I thought that strptime was documented to vary depending on the whims of whoever wrote the C runtime for your box. However it seems I'm wrong. Which would mean that there's a bug in Python.</p>
<p>Python 2.6.4 on Windows doesn't like leading trailing spaces; see... | 2 | 2010-03-17T06:28:06Z | [
"python",
"strptime"
] |
Troubleshooting 'ValueError: time data ... does not match format' when using datetime.strptime | 2,460,233 | <p>My input string is <code>'16-MAR-2010 03:37:04'</code> and i want to store it as datetime. </p>
<p>I am trying to use: </p>
<pre><code>db_inst.HB_Create_Ship_Date = datetime.strptime(fields[7]," %d-%b-%Y %H:%M:%S ")
fields[7] = '16-MAR-2010 03:37:04'
</code></pre>
<p>I am getting an error:</p>
<pre><code>::Val... | 1 | 2010-03-17T06:19:55Z | 2,460,268 | <p>Your format string has a leading space and a trailing space, but your input string does not. Remove the space after the starting quotation mark and before the ending quotation mark.</p>
| 2 | 2010-03-17T06:28:16Z | [
"python",
"strptime"
] |
Troubleshooting 'ValueError: time data ... does not match format' when using datetime.strptime | 2,460,233 | <p>My input string is <code>'16-MAR-2010 03:37:04'</code> and i want to store it as datetime. </p>
<p>I am trying to use: </p>
<pre><code>db_inst.HB_Create_Ship_Date = datetime.strptime(fields[7]," %d-%b-%Y %H:%M:%S ")
fields[7] = '16-MAR-2010 03:37:04'
</code></pre>
<p>I am getting an error:</p>
<pre><code>::Val... | 1 | 2010-03-17T06:19:55Z | 2,460,277 | <p>Try this:</p>
<pre><code>db_inst.HB_Create_Ship_Date = datetime.strptime(fields[7],"%d-%b-%Y %H:%M:%S")
</code></pre>
<p>Also, have a <a href="http://docs.python.org/library/datetime.html" rel="nofollow">look here</a> as a reference for DateTime formatting in Python.</p>
| 0 | 2010-03-17T06:30:51Z | [
"python",
"strptime"
] |
Troubleshooting 'ValueError: time data ... does not match format' when using datetime.strptime | 2,460,233 | <p>My input string is <code>'16-MAR-2010 03:37:04'</code> and i want to store it as datetime. </p>
<p>I am trying to use: </p>
<pre><code>db_inst.HB_Create_Ship_Date = datetime.strptime(fields[7]," %d-%b-%Y %H:%M:%S ")
fields[7] = '16-MAR-2010 03:37:04'
</code></pre>
<p>I am getting an error:</p>
<pre><code>::Val... | 1 | 2010-03-17T06:19:55Z | 2,460,322 | <p>Edit:<br>
As <a href="http://stackoverflow.com/questions/2460233/datetime-datetime-strptime-problem/2460267#2460267">John mentions</a>, make it easier on yourself and remove the leading and trailing spaces.</p>
<p>Another thought:<br>
Your current <a href="http://docs.python.org/library/locale.html" rel="nofollow">... | 4 | 2010-03-17T06:44:23Z | [
"python",
"strptime"
] |
How to stop Python program execution in IDLE | 2,460,401 | <p>I have a python script that uses <code>plt.show()</code> as it's last instruction. When it runs, IDLE just hangs after the last instruction. I get the image but I don't get the prompt back.</p>
<p>On other scripts I typically use <code>ctrl-c</code> to break the program (sometimes doesn't work immediately) but how ... | 9 | 2010-03-17T07:04:19Z | 2,460,438 | <p>I have seen this problem with IDLE and matplotlib when using them on Windows. I don't know the exact cause, but Ctrl-c a couple times has typically worked for me. If that doesn't work for you, you can use the normal interpreter instead of write your plot directly to a file instead of the screen.</p>
<p>This is one ... | 4 | 2010-03-17T07:13:55Z | [
"python",
"matplotlib",
"tkinter",
"break",
"python-idle"
] |
How to stop Python program execution in IDLE | 2,460,401 | <p>I have a python script that uses <code>plt.show()</code> as it's last instruction. When it runs, IDLE just hangs after the last instruction. I get the image but I don't get the prompt back.</p>
<p>On other scripts I typically use <code>ctrl-c</code> to break the program (sometimes doesn't work immediately) but how ... | 9 | 2010-03-17T07:04:19Z | 8,235,632 | <p>When you use <code>plt.show()</code>, the python subprocess enters the GUI toolkit's event loop and blocks until the event loop exits. When it exits, you get the prompt back.</p>
<p>If you are using the TkAgg backend, you'll need to move your mouse over a figure after you press Ctrl+C. That will cause the event loo... | 2 | 2011-11-23T00:01:23Z | [
"python",
"matplotlib",
"tkinter",
"break",
"python-idle"
] |
How to stop Python program execution in IDLE | 2,460,401 | <p>I have a python script that uses <code>plt.show()</code> as it's last instruction. When it runs, IDLE just hangs after the last instruction. I get the image but I don't get the prompt back.</p>
<p>On other scripts I typically use <code>ctrl-c</code> to break the program (sometimes doesn't work immediately) but how ... | 9 | 2010-03-17T07:04:19Z | 20,615,556 | <p>Ctrl+F6
(Restart shell)</p>
<p>or Shell->Restart Shell</p>
| 6 | 2013-12-16T16:17:57Z | [
"python",
"matplotlib",
"tkinter",
"break",
"python-idle"
] |
How to stop Python program execution in IDLE | 2,460,401 | <p>I have a python script that uses <code>plt.show()</code> as it's last instruction. When it runs, IDLE just hangs after the last instruction. I get the image but I don't get the prompt back.</p>
<p>On other scripts I typically use <code>ctrl-c</code> to break the program (sometimes doesn't work immediately) but how ... | 9 | 2010-03-17T07:04:19Z | 31,151,803 | <p>I had same issue in Canopy Python Editor, and I was able to interrupt python session with <code>CTRL+.</code> ("dot" button). Hope that helps, or they probably do things in a similar ways</p>
| 1 | 2015-07-01T02:50:56Z | [
"python",
"matplotlib",
"tkinter",
"break",
"python-idle"
] |
developing a chat website | 2,460,407 | <p>I want to develop a anonymous chat website like <a href="http://omgele.com" rel="nofollow">http://omgele.com</a>.
I know that this website is developed in python using <code>twisted matrix</code> framework. Using twisted matrix it's easy to develop such website.
But I am very comfortable in Java and have 1 year's... | 2 | 2010-03-17T07:07:02Z | 2,460,434 | <p><i>I would politely ask the people at omgele.com for a copy of their code and study it to </p>
<ol>
<li>learn Python and twisted matrix</li>
<li>decide to use it or if I decide against it, to apply what I learned from them to write my own Java site</i> </li>
</ol>
<p>unfortunately, the source code is not likely to... | 1 | 2010-03-17T07:12:40Z | [
"java",
"python",
"chat",
"twisted"
] |
developing a chat website | 2,460,407 | <p>I want to develop a anonymous chat website like <a href="http://omgele.com" rel="nofollow">http://omgele.com</a>.
I know that this website is developed in python using <code>twisted matrix</code> framework. Using twisted matrix it's easy to develop such website.
But I am very comfortable in Java and have 1 year's... | 2 | 2010-03-17T07:07:02Z | 2,460,461 | <p>Learning Python can be an informative, interesting, and valuable process. When you really get going, you will probably find you can develop more rapidly than in Java. Twisted is an fairly well-executed framework which lets you avoid many of the pitfalls you can run into with asynchronous IO; it has top-notch impleme... | 0 | 2010-03-17T07:20:46Z | [
"java",
"python",
"chat",
"twisted"
] |
developing a chat website | 2,460,407 | <p>I want to develop a anonymous chat website like <a href="http://omgele.com" rel="nofollow">http://omgele.com</a>.
I know that this website is developed in python using <code>twisted matrix</code> framework. Using twisted matrix it's easy to develop such website.
But I am very comfortable in Java and have 1 year's... | 2 | 2010-03-17T07:07:02Z | 2,460,512 | <p>Learn python. </p>
<p>This will add one very powerful tool to your toolbox. </p>
<p>Also twisted can do much more than just chat which will help you in future.</p>
| 6 | 2010-03-17T07:33:04Z | [
"java",
"python",
"chat",
"twisted"
] |
developing a chat website | 2,460,407 | <p>I want to develop a anonymous chat website like <a href="http://omgele.com" rel="nofollow">http://omgele.com</a>.
I know that this website is developed in python using <code>twisted matrix</code> framework. Using twisted matrix it's easy to develop such website.
But I am very comfortable in Java and have 1 year's... | 2 | 2010-03-17T07:07:02Z | 2,460,529 | <p>To your #2 question, take a look at Jabber (XMPP), it has several Java clients and is widely supported. Example Gtalk, Facebook use XMPP.</p>
<p><a href="http://www.igniterealtime.org/projects/openfire/" rel="nofollow">Here</a> is an excellent server written in Java.</p>
| 1 | 2010-03-17T07:37:57Z | [
"java",
"python",
"chat",
"twisted"
] |
developing a chat website | 2,460,407 | <p>I want to develop a anonymous chat website like <a href="http://omgele.com" rel="nofollow">http://omgele.com</a>.
I know that this website is developed in python using <code>twisted matrix</code> framework. Using twisted matrix it's easy to develop such website.
But I am very comfortable in Java and have 1 year's... | 2 | 2010-03-17T07:07:02Z | 5,104,810 | <p>I've worked with about a dozen different languages, and started with Python about two months ago. Java and Python in developing web apps, middleware, and services ROCKS!!</p>
<p>Learn Python.</p>
| 0 | 2011-02-24T12:41:59Z | [
"java",
"python",
"chat",
"twisted"
] |
Python app engine put(self): | 2,460,431 | <p>I am using this middleware to make my app restful, but it looks like my form parameters are not coming through:</p>
<pre><code>from google.appengine.ext import webapp
class RestHTTPMiddleware(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
method = webapp.... | 1 | 2010-03-17T07:11:32Z | 2,476,923 | <p>Instantiating webapp.Request and calling .get on it causes it to read the request body and parse form parameters in it. When your actual webapp starts later, it instantiates another request object, and once again tries to read the request body - but it's already been read, so nothing is returned.</p>
<p>You could m... | 4 | 2010-03-19T11:50:41Z | [
"python",
"google-app-engine"
] |
In Python, if I have a unix timestamp, how do I insert that into a MySQL datetime field? | 2,460,491 | <p>I am using Python MySQLDB, and I want to insert this into DATETIME field in Mysql . How do I do that with cursor.execute?</p>
| 4 | 2010-03-17T07:28:03Z | 2,460,546 | <p>Solved.</p>
<p>I just did this:</p>
<p>datetime.datetime.now() ...insert that into the column.</p>
| 1 | 2010-03-17T07:41:30Z | [
"python",
"mysql",
"database",
"datetime",
"date"
] |
In Python, if I have a unix timestamp, how do I insert that into a MySQL datetime field? | 2,460,491 | <p>I am using Python MySQLDB, and I want to insert this into DATETIME field in Mysql . How do I do that with cursor.execute?</p>
| 4 | 2010-03-17T07:28:03Z | 2,460,561 | <p>You can use the FROM_UNIXTIME MySQL function:</p>
<pre><code>#import MySQLdb as mysql
import mysql.connector as mysql
if __name__ == '__main__':
cnx = mysql.connect(user='root')
cur = cnx.cursor()
cur.execute("SELECT FROM_UNIXTIME(%s)", (1268811665,))
print cur.fetchall()
cur.close()
cnx.c... | 3 | 2010-03-17T07:46:01Z | [
"python",
"mysql",
"database",
"datetime",
"date"
] |
In Python, if I have a unix timestamp, how do I insert that into a MySQL datetime field? | 2,460,491 | <p>I am using Python MySQLDB, and I want to insert this into DATETIME field in Mysql . How do I do that with cursor.execute?</p>
| 4 | 2010-03-17T07:28:03Z | 2,460,850 | <p>To convert from a UNIX timestamp to a Python datetime object, use <code>datetime.fromtimestamp()</code> (<a href="http://docs.python.org/py3k/library/datetime.html#datetime.datetime.fromtimestamp">documentation</a>).</p>
<pre><code>>>> from datetime import datetime
>>> datetime.fromtimestamp(0)
da... | 5 | 2010-03-17T08:59:29Z | [
"python",
"mysql",
"database",
"datetime",
"date"
] |
MemoryError when running Numpy Meshgrid | 2,460,627 | <p>I have <strong>8823</strong> data points with x,y coordinates. I'm trying to follow the answer on <a href="http://stackoverflow.com/questions/2369492/generate-a-heatmap-in-matplotlib-using-a-scatter-data-set">how to get a scatter dataset to be represented as a heatmap</a> but when I go through the </p>
<p><code>X, ... | 2 | 2010-03-17T08:02:13Z | 2,460,722 | <p>Your call to <code>meshgrid</code> requires a lot of memory -- it produces two 8823*8823 floating point arrays. Each of them are about 0.6 GB.</p>
<p>But your screen can't show (and your eye can't really process) that much information anyway, so you should probably think of a way to smooth your data to something mo... | 5 | 2010-03-17T08:23:43Z | [
"python",
"arrays",
"numpy"
] |
MemoryError when running Numpy Meshgrid | 2,460,627 | <p>I have <strong>8823</strong> data points with x,y coordinates. I'm trying to follow the answer on <a href="http://stackoverflow.com/questions/2369492/generate-a-heatmap-in-matplotlib-using-a-scatter-data-set">how to get a scatter dataset to be represented as a heatmap</a> but when I go through the </p>
<p><code>X, ... | 2 | 2010-03-17T08:02:13Z | 24,043,148 | <p>in numpy 1.7.0 and newer <code>meshgrid</code> has the <code>sparse</code> keyword argument. A sparse meshgrid is setup so it broadcasts to a full meshgrid when used. This can save large amounts of memory e.g. when using the meshgrid to index arrays.</p>
<pre><code>In [2]: np.meshgrid(np.arange(10), np.arange(10), ... | 0 | 2014-06-04T16:49:07Z | [
"python",
"arrays",
"numpy"
] |
Get a unique computer ID in Python on windows and linux | 2,461,141 | <p>I'd like to get an id unique to a computer with Python on Windows and Linux. It could be the CPU ID, the motherboard serial, ... or anything else.</p>
<p>I looked at several modules (pycpuid, psi, ...) without luck.</p>
<p>Any idea on how to do that?</p>
| 11 | 2010-03-17T09:41:21Z | 2,461,173 | <p><a href="http://en.wikipedia.org/wiki/Universally_Unique_Identifier#cite_note-19" rel="nofollow">UUID -Universally Unique Identifier</a></p>
<p><a href="http://docs.python.org/library/uuid.html" rel="nofollow"><strong>Python uuid module</strong></a></p>
<p><a href="http://tools.ietf.org/html/rfc4122.html" rel="nof... | 1 | 2010-03-17T09:46:02Z | [
"python",
"hardware"
] |
Get a unique computer ID in Python on windows and linux | 2,461,141 | <p>I'd like to get an id unique to a computer with Python on Windows and Linux. It could be the CPU ID, the motherboard serial, ... or anything else.</p>
<p>I looked at several modules (pycpuid, psi, ...) without luck.</p>
<p>Any idea on how to do that?</p>
| 11 | 2010-03-17T09:41:21Z | 2,461,182 | <p>How about using the MAC address as unique id?</p>
<p>The discussion here <a href="http://stackoverflow.com/questions/1750803/obtain-mac-address-from-devices-using-python">http://stackoverflow.com/questions/1750803/obtain-mac-address-from-devices-using-python</a> shows how to obtain the MAC address</p>
| 0 | 2010-03-17T09:47:12Z | [
"python",
"hardware"
] |
Get a unique computer ID in Python on windows and linux | 2,461,141 | <p>I'd like to get an id unique to a computer with Python on Windows and Linux. It could be the CPU ID, the motherboard serial, ... or anything else.</p>
<p>I looked at several modules (pycpuid, psi, ...) without luck.</p>
<p>Any idea on how to do that?</p>
| 11 | 2010-03-17T09:41:21Z | 2,462,588 | <p>I don't think there is a reliable, cross platform, way to do this. I know of one network device that changes its MAC address as a form of hardware error reporting, and there are a million other ways this could fail.</p>
<p>The only reliable solution is for your application to assign a unique key to each machine. ... | 4 | 2010-03-17T13:35:22Z | [
"python",
"hardware"
] |
Get a unique computer ID in Python on windows and linux | 2,461,141 | <p>I'd like to get an id unique to a computer with Python on Windows and Linux. It could be the CPU ID, the motherboard serial, ... or anything else.</p>
<p>I looked at several modules (pycpuid, psi, ...) without luck.</p>
<p>Any idea on how to do that?</p>
| 11 | 2010-03-17T09:41:21Z | 2,462,978 | <p>There seems to be no direct "python" way of doing this. On modern PC hardware, there usually is an UUID stored in the BIOS - on Linux there is a command line utility <code>dmidecode</code> that can read this; example from my desktop:</p>
<pre><code>System Information
Manufacturer: Dell Inc.
Product ... | 11 | 2010-03-17T14:23:18Z | [
"python",
"hardware"
] |
Get a unique computer ID in Python on windows and linux | 2,461,141 | <p>I'd like to get an id unique to a computer with Python on Windows and Linux. It could be the CPU ID, the motherboard serial, ... or anything else.</p>
<p>I looked at several modules (pycpuid, psi, ...) without luck.</p>
<p>Any idea on how to do that?</p>
| 11 | 2010-03-17T09:41:21Z | 3,152,570 | <p>for Windows you need <strong>DmiDecode for Windows</strong> (<a href="http://gnuwin32.sourceforge.net/packages/dmidecode.htm">link</a>) : </p>
<pre><code>subprocess.Popen('dmidecode.exe -s system-uuid'.split())
</code></pre>
<p>for Linux (non root):</p>
<pre><code>subprocess.Popen('hal-get-property --udi /org/fre... | 7 | 2010-06-30T19:13:04Z | [
"python",
"hardware"
] |
Get a unique computer ID in Python on windows and linux | 2,461,141 | <p>I'd like to get an id unique to a computer with Python on Windows and Linux. It could be the CPU ID, the motherboard serial, ... or anything else.</p>
<p>I looked at several modules (pycpuid, psi, ...) without luck.</p>
<p>Any idea on how to do that?</p>
| 11 | 2010-03-17T09:41:21Z | 3,877,534 | <p>Or if you don't want to use subprocess, (It's slow) use ctypes. This is for Linux non root.</p>
<pre><code>import ctypes
from ctypes.util import find_library
from ctypes import Structure
class DBusError(Structure):
_fields_ = [("name", ctypes.c_char_p),
("message", ctypes.c_char_p),
... | 4 | 2010-10-06T23:03:57Z | [
"python",
"hardware"
] |
Get a unique computer ID in Python on windows and linux | 2,461,141 | <p>I'd like to get an id unique to a computer with Python on Windows and Linux. It could be the CPU ID, the motherboard serial, ... or anything else.</p>
<p>I looked at several modules (pycpuid, psi, ...) without luck.</p>
<p>Any idea on how to do that?</p>
| 11 | 2010-03-17T09:41:21Z | 7,835,019 | <p>I found something else that I'm using. Mac address for linux, MachineGuid for windows and there is also something for mac.</p>
<p>More details here:
<a href="http://www.serialsense.com/blog/2011/02/generating-unique-machine-ids/" rel="nofollow">http://www.serialsense.com/blog/2011/02/generating-unique-machine-ids/<... | 1 | 2011-10-20T11:08:47Z | [
"python",
"hardware"
] |
Get a unique computer ID in Python on windows and linux | 2,461,141 | <p>I'd like to get an id unique to a computer with Python on Windows and Linux. It could be the CPU ID, the motherboard serial, ... or anything else.</p>
<p>I looked at several modules (pycpuid, psi, ...) without luck.</p>
<p>Any idea on how to do that?</p>
| 11 | 2010-03-17T09:41:21Z | 16,505,802 | <p>Invoke one of these in the shell or through a pipe in Python to get the hardware serial number of Apple machines running OS X >= 10.5:</p>
<p><code>/usr/sbin/system_profiler SPHardwareDataType | fgrep 'Serial' | awk '{print $NF}'</code></p>
<p>or </p>
<p><code>ioreg -l | awk '/IOPlatformSerialNumber/ { print $4 }... | 2 | 2013-05-12T09:08:28Z | [
"python",
"hardware"
] |
Is there a simple way to make lists behave as files (with ftplib) | 2,461,169 | <p>I'd like to use ftplib to upload program-generated data as lists. The nearest method I can see for doing this is ftp.storlines, but this requires a file object with a readlines() method.</p>
<p>Obviously I could create a file, but this seems like overkill as the data isn't persistent.</p>
<p>Is there anything that... | 1 | 2010-03-17T09:45:55Z | 2,461,220 | <p>You could always use <code>StringIO</code> (<a href="http://docs.python.org/library/io.html#io.StringIO" rel="nofollow">documentation</a>), it is a memory buffer that is a file-like object.</p>
<pre><code>from io import StringIO # version < 2.6: from StringIO import StringIO
buffer = StringIO()
buffer.writel... | 3 | 2010-03-17T09:51:19Z | [
"python",
"ftp",
"file-upload",
"list",
"iterator"
] |
Tree implementation in Python | 2,461,170 | <p>How to implement tree in Python?</p>
<p>I am Python beginner.</p>
<p>Give me a general idea!</p>
| 0 | 2010-03-17T09:45:57Z | 2,461,216 | <p>Build a <code>Node</code> class, having some content object and a list of children, which are again instances of <code>Node</code>.</p>
| 5 | 2010-03-17T09:50:18Z | [
"python"
] |
Tree implementation in Python | 2,461,170 | <p>How to implement tree in Python?</p>
<p>I am Python beginner.</p>
<p>Give me a general idea!</p>
| 0 | 2010-03-17T09:45:57Z | 2,461,367 | <pre><code>class Tree(object):
def __init__(self, name, left_subtree = None, right_subtree = None):
self._name = name
self._left_subtree = left_subtree
self._right_subtree = right_subtree
def inorder(tree):
if tree is not None:
inorder(tree._left_subtree)
print tree._nam... | 5 | 2010-03-17T10:16:17Z | [
"python"
] |
Numpy image - rotate matrix 270 degrees | 2,461,303 | <p>I've got a Numpy 2d array that represents a grey-scale image and I need to rotate it 270 degrees. Might be being a bit thick here but the two ways I can find to do this seem quite... circulous:</p>
<pre><code>rotated = numpy.rot90(numpy.rot90(numpy.rot90(orignumpyarray)))
rotated = numpy.fliplr(numpy.flipud(numpy... | 6 | 2010-03-17T10:07:03Z | 2,461,347 | <p>You can tell <code>rot90</code> to <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.rot90.html#numpy.rot90">rotate several times</a>, this should work:</p>
<pre><code>rotated = numpy.rot90(orignumpyarray,3)
</code></pre>
| 7 | 2010-03-17T10:13:24Z | [
"python",
"matrix",
"image-manipulation",
"numpy"
] |
Protocols/Interfaces in Ruby | 2,461,320 | <p>While coding in Ruby I did not really miss the type-orientedness of Java or C++ so far, but for some cases I think it is useful to have them. For Python there was a project <a href="http://peak.telecommunity.com/PyProtocols.html" rel="nofollow">PyProtocols</a> which defined interfaces and protocols for objects. Does... | 0 | 2010-03-17T10:09:22Z | 2,461,406 | <p>Check project <a href="http://rubyforge.org/projects/ruby-contract/" rel="nofollow">Ruby-Contract</a> </p>
<p>Not more work is happening on it. :(</p>
| 1 | 2010-03-17T10:21:57Z | [
"python",
"ruby",
"types",
"interface"
] |
Protocols/Interfaces in Ruby | 2,461,320 | <p>While coding in Ruby I did not really miss the type-orientedness of Java or C++ so far, but for some cases I think it is useful to have them. For Python there was a project <a href="http://peak.telecommunity.com/PyProtocols.html" rel="nofollow">PyProtocols</a> which defined interfaces and protocols for objects. Does... | 0 | 2010-03-17T10:09:22Z | 2,461,565 | <p>This might be interesting for the second part of your question:
<a href="http://www.codecommit.com/blog/ruby/adding-type-checking-to-ruby" rel="nofollow">Type checking in ruby</a></p>
| 1 | 2010-03-17T10:46:58Z | [
"python",
"ruby",
"types",
"interface"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.