title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
Dynamic Table Creation and ORM mapping in SqlAlchemy
973,481
<p>I'm fairly new to using relational databases, so I prefer using a good ORM to simplify things. I spent time evaluating different Python ORMs and I think SQLAlchemy is what I need. However, I've come to a mental dead end.</p> <p>I need to create a new table to go along with each instance of a player I create in my...
7
2009-06-10T02:51:11Z
1,615,689
<p>I faced the same problem when I was trying to automate simple CRUD tasks using SQLAlchemy. Here is simple explanation and some code: <a href="http://www.devx.com/dbzone/Article/42015" rel="nofollow">http://www.devx.com/dbzone/Article/42015</a></p>
1
2009-10-23T20:21:20Z
[ "python", "database", "sqlalchemy" ]
Dynamic Table Creation and ORM mapping in SqlAlchemy
973,481
<p>I'm fairly new to using relational databases, so I prefer using a good ORM to simplify things. I spent time evaluating different Python ORMs and I think SQLAlchemy is what I need. However, I've come to a mental dead end.</p> <p>I need to create a new table to go along with each instance of a player I create in my...
7
2009-06-10T02:51:11Z
16,454,798
<p>maybe i didn't quite understand what you want, but this recipe create identical column in different __tablename__</p> <pre><code>class TBase(object): """Base class is a 'mixin'. Guidelines for declarative mixins is at: http://www.sqlalchemy.org/docs/orm/extensions/declarative.html#mixin-classes ""...
0
2013-05-09T05:10:16Z
[ "python", "database", "sqlalchemy" ]
how to integrate ZSH and (i)python?
973,520
<p>I have been in love with <code>zsh</code> for a long time, and more recently I have been discovering the advantages of the <code>ipython</code> interactive interpreter over <code>python</code> itself. Being able to <i>cd</i>, to <i>ls</i>, to <i>run</i> or to <i>!</i> is indeed very handy. But now it feels weird to ...
9
2009-06-10T03:11:55Z
974,030
<p>You can run shell commands by starting them with an exclamation mark and capture the output in a python variable. Example: listing directories in your <code>/tmp</code> directory:</p> <pre><code>ipy&gt; import os ipy&gt; tmplist = !find /tmp ipy&gt; [dir for dir in tmplist if os.path.isdir(dir)] </code></pre> <p>T...
6
2009-06-10T06:44:42Z
[ "python", "shell", "zsh", "ipython" ]
how to integrate ZSH and (i)python?
973,520
<p>I have been in love with <code>zsh</code> for a long time, and more recently I have been discovering the advantages of the <code>ipython</code> interactive interpreter over <code>python</code> itself. Being able to <i>cd</i>, to <i>ls</i>, to <i>run</i> or to <i>!</i> is indeed very handy. But now it feels weird to ...
9
2009-06-10T03:11:55Z
1,070,597
<p>I asked this question on the zsh list and this answer worked for me. YMMV.</p> <p>In genutils.py after the line </p> <blockquote> <p>if not debug:</p> </blockquote> <p>Remove the line:</p> <blockquote> <p>stat = os.system(cmd)</p> </blockquote> <p>Replace it with:</p> <blockquote> <p>stat = subprocess....
9
2009-07-01T18:19:24Z
[ "python", "shell", "zsh", "ipython" ]
writing to a file via FTP in python
973,551
<p>So i've followed the docs on this page: <a href="http://docs.python.org/library/ftplib.html#ftplib.FTP.retrbinary" rel="nofollow">http://docs.python.org/library/ftplib.html#ftplib.FTP.retrbinary</a></p> <p>And maybe i'm confused just as to what 'retrbinary' does...i'm thinking it retrives a binary file and from the...
1
2009-06-10T03:24:13Z
973,576
<p>It looks like the original code should have worked, <em>if you were trying to download a file from the server</em>. The <code>retrbinary</code> command accepts a function object you specify (that is, the name of the function with no <code>()</code> after it); it is called whenever a piece of data (a binary file) arr...
2
2009-06-10T03:34:54Z
[ "python", "ftp", "ftplib" ]
writing to a file via FTP in python
973,551
<p>So i've followed the docs on this page: <a href="http://docs.python.org/library/ftplib.html#ftplib.FTP.retrbinary" rel="nofollow">http://docs.python.org/library/ftplib.html#ftplib.FTP.retrbinary</a></p> <p>And maybe i'm confused just as to what 'retrbinary' does...i'm thinking it retrives a binary file and from the...
1
2009-06-10T03:24:13Z
973,584
<p>ftp.retrbinary takes second argument as callback function it can be directly write method of file object i.e.open('temp.txt','wb').write but instead you are calling write directly</p> <p>you may supply your own callback and do whatever you want to do with data</p> <pre><code>def mywriter(data): print data ftp....
0
2009-06-10T03:37:56Z
[ "python", "ftp", "ftplib" ]
Python library for playing fixed-frequency sound
974,071
<p>I have a mosquito problem in my house. This wouldn't usually concern a programmers' community; However, I've seen some devices that claim to deter these nasty creatures by playing a 17Khz tone. I would like to do this using my laptop.</p> <p>One method would be creating an MP3 with a a single, fixed-frequency tone ...
22
2009-06-10T07:05:02Z
974,291
<p><a href="http://pypi.python.org/pypi/pyaudiere/" rel="nofollow">PyAudiere</a> is a simple cross-platform solution for the problem:</p> <pre><code>&gt;&gt;&gt; import audiere &gt;&gt;&gt; d = audiere.open_device() &gt;&gt;&gt; t = d.create_tone(17000) # 17 KHz &gt;&gt;&gt; t.play() # non-blocking call &gt;&gt;&gt; i...
11
2009-06-10T08:20:33Z
[ "python", "audio", "mp3", "frequency" ]
Python library for playing fixed-frequency sound
974,071
<p>I have a mosquito problem in my house. This wouldn't usually concern a programmers' community; However, I've seen some devices that claim to deter these nasty creatures by playing a 17Khz tone. I would like to do this using my laptop.</p> <p>One method would be creating an MP3 with a a single, fixed-frequency tone ...
22
2009-06-10T07:05:02Z
974,381
<p>You can use the <a href="http://pygame.seul.org/news.html" rel="nofollow">Python binding</a> of the SDL (<a href="http://www.libsdl.org/" rel="nofollow">Simple Direct Media Library</a>). </p>
0
2009-06-10T08:45:34Z
[ "python", "audio", "mp3", "frequency" ]
Python library for playing fixed-frequency sound
974,071
<p>I have a mosquito problem in my house. This wouldn't usually concern a programmers' community; However, I've seen some devices that claim to deter these nasty creatures by playing a 17Khz tone. I would like to do this using my laptop.</p> <p>One method would be creating an MP3 with a a single, fixed-frequency tone ...
22
2009-06-10T07:05:02Z
976,848
<p>The module <a href="http://docs.python.org/library/winsound.html" rel="nofollow">winsound</a> is included with Python, so there are no external libraries to install, and it should do what you want (and not much else).</p> <pre><code> import winsound winsound.Beep(17000, 100) </code></pre> <p>It's very simple and ...
9
2009-06-10T16:50:20Z
[ "python", "audio", "mp3", "frequency" ]
How to send a SIGINT to Python from a bash script?
974,189
<p>I want to launch a background Python job from a bash script and then gracefully kill it with SIGINT. This works fine from the shell, but I can't seem to get it to work in a script.</p> <p>loop.py:</p> <pre><code>#! /usr/bin/env python if __name__ == "__main__": try: print 'starting loop' while ...
5
2009-06-10T07:46:27Z
974,229
<p>You're not registering a signal handler. Try the below. It seems to work fairly reliably. I think the rare exception is when it catches the signal before Python registers the script's handler. Note that KeyboardInterrupt is only supposed to be raised, "when the user hits the interrupt key". I think the fact tha...
10
2009-06-10T08:00:35Z
[ "python", "bash" ]
How to send a SIGINT to Python from a bash script?
974,189
<p>I want to launch a background Python job from a bash script and then gracefully kill it with SIGINT. This works fine from the shell, but I can't seem to get it to work in a script.</p> <p>loop.py:</p> <pre><code>#! /usr/bin/env python if __name__ == "__main__": try: print 'starting loop' while ...
5
2009-06-10T07:46:27Z
974,257
<p>I agree with Matthew Flaschen; the problem is with python, which apparently doesn't register the KeyboardInterrupt exception with SIGINT when it's not called from an interactive shell.</p> <p>Of course, nothing prevents you from registering your signal handler like this:</p> <pre><code>def signal_handler(signum, f...
3
2009-06-10T08:12:13Z
[ "python", "bash" ]
How to send a SIGINT to Python from a bash script?
974,189
<p>I want to launch a background Python job from a bash script and then gracefully kill it with SIGINT. This works fine from the shell, but I can't seem to get it to work in a script.</p> <p>loop.py:</p> <pre><code>#! /usr/bin/env python if __name__ == "__main__": try: print 'starting loop' while ...
5
2009-06-10T07:46:27Z
975,778
<p>When you run command in background with &amp;, SIGINT will be ignored. Here's the relevant section of man bash:</p> <blockquote> <p>Non-builtin commands run by bash have signal handlers set to the values inherited by the shell from its parent. When job control is not in effect, asynchronous commands ignore S...
0
2009-06-10T13:58:15Z
[ "python", "bash" ]
concurrently iterating through even and odd items of list
974,219
<p>I have a list of items (which are HTML table rows, extracted with Beautiful Soup) and I need to iterate over the list and get even and odd elements (I mean index) for each loop run. My code looks like this:</p> <pre><code>for top, bottom in izip(table[::2], table[1::2]): #do something with top #do somethin...
3
2009-06-10T07:56:19Z
974,238
<p>Looks good. My only suggestion would be to wrap this in a function or method. That way, you can give it a name (<code>evenOddIter()</code>) which makes it much more readable.</p>
0
2009-06-10T08:04:39Z
[ "python", "for-loop", "itertools" ]
concurrently iterating through even and odd items of list
974,219
<p>I have a list of items (which are HTML table rows, extracted with Beautiful Soup) and I need to iterate over the list and get even and odd elements (I mean index) for each loop run. My code looks like this:</p> <pre><code>for top, bottom in izip(table[::2], table[1::2]): #do something with top #do somethin...
3
2009-06-10T07:56:19Z
974,239
<p><code>izip</code> is a pretty good option, but here's a few alternatives since you're unhappy with it:</p> <pre><code>&gt;&gt;&gt; def chunker(seq, size): ... return (tuple(seq[pos:pos+size]) for pos in xrange(0, len(seq), size)) ... &gt;&gt;&gt; x = range(11) &gt;&gt;&gt; x [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] &...
5
2009-06-10T08:04:56Z
[ "python", "for-loop", "itertools" ]
concurrently iterating through even and odd items of list
974,219
<p>I have a list of items (which are HTML table rows, extracted with Beautiful Soup) and I need to iterate over the list and get even and odd elements (I mean index) for each loop run. My code looks like this:</p> <pre><code>for top, bottom in izip(table[::2], table[1::2]): #do something with top #do somethin...
3
2009-06-10T07:56:19Z
974,577
<p>Try:</p> <pre><code>def alternate(i): i = iter(i) while True: yield(i.next(), i.next()) &gt;&gt;&gt; list(alternate(range(10))) [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)] </code></pre> <p>This solution works on any sequence, not just lists, and doesn't copy the sequence (it will be far more efficien...
4
2009-06-10T09:33:42Z
[ "python", "for-loop", "itertools" ]
How to create single Python dict from a list of dicts by summing values with common keys?
974,678
<p>I have a list of dictionaries, e.g:</p> <pre><code>dictList = [ {'a':3, 'b':9, 'c':4}, {'a':9, 'b':24, 'c':99}, {'a':10, 'b':23, 'c':88} ] </code></pre> <p>All the dictionaries have the same keys e.g. <em>a</em>, <em>b</em>, <em>c</em>. I wish to create a single dictionary with the same keys where the ...
7
2009-06-10T10:01:46Z
974,692
<p>If all dicts have all keys, you could do this as:</p> <pre><code>&gt;&gt;&gt; dict((key, sum(d[key] for d in dictList)) for key in dictList[0]) {'a': 22, 'b': 56, 'c': 191} </code></pre> <p><strong>[Edit]</strong> If speed is a big priority, you can also shave off ~20% (though at the cost of some readability) with...
18
2009-06-10T10:06:16Z
[ "python" ]
How to create single Python dict from a list of dicts by summing values with common keys?
974,678
<p>I have a list of dictionaries, e.g:</p> <pre><code>dictList = [ {'a':3, 'b':9, 'c':4}, {'a':9, 'b':24, 'c':99}, {'a':10, 'b':23, 'c':88} ] </code></pre> <p>All the dictionaries have the same keys e.g. <em>a</em>, <em>b</em>, <em>c</em>. I wish to create a single dictionary with the same keys where the ...
7
2009-06-10T10:01:46Z
974,868
<p>Try this.</p> <pre><code>from collections import defaultdict result = defaultdict(int) for myDict in dictList: for k in myDict: result[k] += myDict[k] </code></pre>
7
2009-06-10T10:52:58Z
[ "python" ]
How to create single Python dict from a list of dicts by summing values with common keys?
974,678
<p>I have a list of dictionaries, e.g:</p> <pre><code>dictList = [ {'a':3, 'b':9, 'c':4}, {'a':9, 'b':24, 'c':99}, {'a':10, 'b':23, 'c':88} ] </code></pre> <p>All the dictionaries have the same keys e.g. <em>a</em>, <em>b</em>, <em>c</em>. I wish to create a single dictionary with the same keys where the ...
7
2009-06-10T10:01:46Z
12,960,608
<p>I'm not sure how it relates to the other answers speed wise, but there is always</p> <pre><code>from collections import Counter result = sum(map(Counter,dictList),Counter()) </code></pre> <p><code>Counter</code> is a subclass of <code>dict</code> and it can be used in place of <code>dict</code> in most places. If ...
0
2012-10-18T17:46:56Z
[ "python" ]
Python + MySQLdb executemany
974,702
<p>I'm using Python and its MySQLdb module to import some measurement data into a Mysql database. The amount of data that we have is quite high (currently about ~250 MB of csv files and plenty of more to come).</p> <p>Currently I use cursor.execute(...) to import some metadata. This isn't problematic as there are only...
4
2009-06-10T10:09:58Z
974,917
<p>The message you get indicates that inside the <code>executemany()</code> method, one of the conversions failed. Check your <code>values</code> list for a tuple longer than 3.</p> <p>For a quick verification:</p> <pre><code>max(map(len, values)) </code></pre> <p>If the result is higher than 3, locate your bad tup...
3
2009-06-10T11:02:20Z
[ "python", "mysql", "executemany" ]
Python + MySQLdb executemany
974,702
<p>I'm using Python and its MySQLdb module to import some measurement data into a Mysql database. The amount of data that we have is quite high (currently about ~250 MB of csv files and plenty of more to come).</p> <p>Currently I use cursor.execute(...) to import some metadata. This isn't problematic as there are only...
4
2009-06-10T10:09:58Z
1,002,018
<p>In retrospective this was a really stupid but hard to spot mistake. Values is a keyword in sql so the table name values needs quotes around it.</p> <pre><code>def __insert_values(self, values): cursor = self.connection.cursor() cursor.executemany(""" insert into `values` (ensg, value, sampleid) ...
5
2009-06-16T14:54:47Z
[ "python", "mysql", "executemany" ]
wget Vs urlretrieve of python
974,741
<p>I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.</p> <p>The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.</p> <p>But, ju...
8
2009-06-10T10:18:59Z
974,809
<p>Maybe you can wget and then inspect the data in Python?</p>
1
2009-06-10T10:38:52Z
[ "python", "urllib2", "wget" ]
wget Vs urlretrieve of python
974,741
<p>I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.</p> <p>The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.</p> <p>But, ju...
8
2009-06-10T10:18:59Z
975,759
<p>There shouldn't be a difference really. All urlretrieve does is make a simple HTTP GET request. Have you taken out your data processing code and done a straight throughput comparison of wget vs. pure python?</p>
0
2009-06-10T13:55:34Z
[ "python", "urllib2", "wget" ]
wget Vs urlretrieve of python
974,741
<p>I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.</p> <p>The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.</p> <p>But, ju...
8
2009-06-10T10:18:59Z
976,135
<p>Please show us some code. I'm pretty sure that it has to be with the code and not on urlretrieve. </p> <p>I've worked with it in the past and never had any speed related issues.</p>
0
2009-06-10T14:59:41Z
[ "python", "urllib2", "wget" ]
wget Vs urlretrieve of python
974,741
<p>I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.</p> <p>The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.</p> <p>But, ju...
8
2009-06-10T10:18:59Z
977,289
<pre><code>import subprocess myurl = 'http://some_server/data/' subprocess.call(["wget", "-r", "-np", "-A", "files", myurl]) </code></pre>
1
2009-06-10T18:10:46Z
[ "python", "urllib2", "wget" ]
wget Vs urlretrieve of python
974,741
<p>I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.</p> <p>The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.</p> <p>But, ju...
8
2009-06-10T10:18:59Z
977,311
<p>Probably a unit math error on your part. </p> <p>Just noticing that <a href="http://www.google.com/search?hl=en&amp;rlz=1C1GGLS%5FenUS291US304&amp;q=500%20KB%20in%20Mb&amp;aq=f&amp;oq=&amp;aqi=g1">500KB/s (kilobytes) is equal to 4Mb/s (megabits)</a>.</p>
37
2009-06-10T18:14:50Z
[ "python", "urllib2", "wget" ]
wget Vs urlretrieve of python
974,741
<p>I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.</p> <p>The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.</p> <p>But, ju...
8
2009-06-10T10:18:59Z
977,466
<p>As for the html parsing, the fastest/easiest you will probably get is using <a href="http://codespeak.net/lxml/" rel="nofollow">lxml</a> As for the http requests themselves: <a href="http://code.google.com/p/httplib2/" rel="nofollow">httplib2</a> is very easy to use, and could possibly speed up downloads because it ...
3
2009-06-10T18:46:07Z
[ "python", "urllib2", "wget" ]
wget Vs urlretrieve of python
974,741
<p>I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.</p> <p>The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.</p> <p>But, ju...
8
2009-06-10T10:18:59Z
981,185
<p>Transfer speeds can be easily misleading.. Could you try with the following script, which simply downloads the same URL with both <code>wget</code> and <code>urllib.urlretrieve</code> - run it a few times incase you're behind a proxy which caches the URL on the second attempt.</p> <p>For small files, wget will take...
3
2009-06-11T13:47:59Z
[ "python", "urllib2", "wget" ]
wget Vs urlretrieve of python
974,741
<p>I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.</p> <p>The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.</p> <p>But, ju...
8
2009-06-10T10:18:59Z
2,003,565
<p>urllib works for me as fast as wget. try this code. it shows the progress in percentage just as wget.</p> <pre><code>import sys, urllib def reporthook(a,b,c): # ',' at the end of the line is important! print "% 3.1f%% of %d bytes\r" % (min(100, float(a * b) / c * 100), c), #you can also use sys.stdout....
6
2010-01-05T01:27:12Z
[ "python", "urllib2", "wget" ]
wget Vs urlretrieve of python
974,741
<p>I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.</p> <p>The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.</p> <p>But, ju...
8
2009-06-10T10:18:59Z
2,350,655
<p>You can use <code>wget -k</code> to engage relative links in all urls.</p>
0
2010-02-28T09:35:55Z
[ "python", "urllib2", "wget" ]
wget Vs urlretrieve of python
974,741
<p>I have a task to download Gbs of data from a website. The data is in form of .gz files, each file being 45mb in size.</p> <p>The easy way to get the files is use "wget -r -np -A files url". This will donwload data in a recursive format and mirrors the website. The donwload rate is very high 4mb/sec.</p> <p>But, ju...
8
2009-06-10T10:18:59Z
7,782,898
<p>Since python suggests using <code>urllib2</code> instead of <code>urllib</code>, I take a test between <code>urllib2.urlopen</code> and <code>wget</code>.</p> <p>The result is, it takes nearly the same time for both of them to download the same file.Sometimes, <code>urllib2</code> performs even better. </p> <p>The...
1
2011-10-16T07:13:37Z
[ "python", "urllib2", "wget" ]
Cleaning up an internal pysqlite connection on object destruction
974,813
<p>I have an object with an internal database connection that's active throughout its lifetime. At the end of the program's run, the connection has to be committed and closed. So far I've used an explicit <code>close</code> method, but this is somewhat cumbersome, especially when exceptions can happen in the calling co...
5
2009-06-10T10:39:34Z
974,859
<p>Read up on the <a href="http://docs.python.org/reference/compound%5Fstmts.html#the-with-statement">with</a> statement. You're describing its use case.</p> <p>You'll need to wrap your connection in a "Context Manager" class that handles the <code>__enter__</code> and <code>__exit__</code> methods used by the <code>...
7
2009-06-10T10:51:46Z
[ "python", "destructor", "pysqlite" ]
Cleaning up an internal pysqlite connection on object destruction
974,813
<p>I have an object with an internal database connection that's active throughout its lifetime. At the end of the program's run, the connection has to be committed and closed. So far I've used an explicit <code>close</code> method, but this is somewhat cumbersome, especially when exceptions can happen in the calling co...
5
2009-06-10T10:39:34Z
974,951
<p>You can make a connection module, since modules keep the same object in the whole application, and register a function to close it with the <a href="http://docs.python.org/library/atexit.html" rel="nofollow"><code>atexit</code></a> module</p> <pre><code># db.py: import sqlite3 import atexit con = None def get_con...
4
2009-06-10T11:09:59Z
[ "python", "destructor", "pysqlite" ]
python not starting properly
974,821
<p>I have installed python and django in my system that uses win vista. Now when I go to command prompt and type python or django-admin.py both are not working. Every time I need to set the path to the python folder manually. But i have seen these commands running even without setting path. So how do i make it to run ...
0
2009-06-10T10:42:38Z
974,834
<p>you can't run a command that isn't in your path. it should be set globally when you installed python.</p> <p>type 'set' at a dos prompt and look at the PATH variable. c:\python25 (or whever you installed python) has to be in that variable ie PATH=c:\windows;c:\python25;... etc </p> <p>if it isn't in PATH then you ...
1
2009-06-10T10:45:35Z
[ "python", "windows", "django-admin" ]
python not starting properly
974,821
<p>I have installed python and django in my system that uses win vista. Now when I go to command prompt and type python or django-admin.py both are not working. Every time I need to set the path to the python folder manually. But i have seen these commands running even without setting path. So how do i make it to run ...
0
2009-06-10T10:42:38Z
974,848
<p>Either use the system control panel to set the <code>PATH</code> environment variable that applies permanently or</p> <p>Reinstall Python as a system administrator so that the installer can set the registry and environment variables for you.</p> <p>If you install the "just for me" option, then you have to set the ...
0
2009-06-10T10:48:41Z
[ "python", "windows", "django-admin" ]
python not starting properly
974,821
<p>I have installed python and django in my system that uses win vista. Now when I go to command prompt and type python or django-admin.py both are not working. Every time I need to set the path to the python folder manually. But i have seen these commands running even without setting path. So how do i make it to run ...
0
2009-06-10T10:42:38Z
975,238
<p>You probably need to add Python to you dos path. Here's a video that may help you out:</p> <p><a href="http://showmedo.com/videotutorials/video?name=960000&amp;fromSeriesID=96" rel="nofollow">http://showmedo.com/videotutorials/video?name=960000&amp;fromSeriesID=96</a></p>
2
2009-06-10T12:19:19Z
[ "python", "windows", "django-admin" ]
python not starting properly
974,821
<p>I have installed python and django in my system that uses win vista. Now when I go to command prompt and type python or django-admin.py both are not working. Every time I need to set the path to the python folder manually. But i have seen these commands running even without setting path. So how do i make it to run ...
0
2009-06-10T10:42:38Z
975,292
<p>In your path, I think you need to have both the location of the Python install and the Python\Scripts folder. For example, on XP, I have C:\Python25;C:\Python25\Scripts. Can you verify that you have both?</p>
0
2009-06-10T12:34:46Z
[ "python", "windows", "django-admin" ]
Multiply operator applied to list(data structure)
974,931
<p>I'm reading <a href="http://openbookproject.net/thinkCSpy/">How to think like a computer scientist</a> which is an introductory text for "Python Programming".</p> <p>I want to clarify the behaviour of multiply operator (<code>*</code>) when applied to lists.</p> <p>Consider the function <strong>make_matrix</strong...
11
2009-06-10T11:06:42Z
974,959
<p>lists are not primitives, they are passed by reference. A copy of a list is a pointer to a list (in C jargon). Anything you do to the list happens to all copies of the list and the copies of its contents unless you do a shallow copy.</p> <pre><code>[[0] * columns] * rows </code></pre> <p>Oops, we've just made a bi...
-3
2009-06-10T11:11:43Z
[ "python", "python-datamodel" ]
Multiply operator applied to list(data structure)
974,931
<p>I'm reading <a href="http://openbookproject.net/thinkCSpy/">How to think like a computer scientist</a> which is an introductory text for "Python Programming".</p> <p>I want to clarify the behaviour of multiply operator (<code>*</code>) when applied to lists.</p> <p>Consider the function <strong>make_matrix</strong...
11
2009-06-10T11:06:42Z
975,024
<p>EVERYTHING in python are objects, and python never makes copies unless explicity asked to do so.</p> <p>When you do </p> <pre><code>innerList = [0] * 10 </code></pre> <p>you create a list with 10 elements, <strong>all of them refering to the same <code>int</code> object <em><code>0</code></em></strong>.</p> <p>S...
18
2009-06-10T11:27:19Z
[ "python", "python-datamodel" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
974,956
<p>Just create a string out of it.</p> <pre><code>myinteger = 212345 number_string = str(myinteger) </code></pre> <p>That's enough. Now you can iterate over it:</p> <pre><code>for ch in number_string: print ch # will print each digit in order </code></pre> <p>Or you can slice it:</p> <pre><code>print number_st...
66
2009-06-10T11:11:07Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
974,967
<pre><code>list_of_ints = [int(i) for i in str(ISBN)] </code></pre> <p>Will give you a ordered list of ints. Of course, given duck typing, you might as well work with str(ISBN).</p> <p>Edit: As mentioned in the comments, this list isn't sorted in the sense of being ascending or descending, but it does have a defined ...
15
2009-06-10T11:12:53Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
975,039
<pre><code>while number: digit = number % 10 # do whatever with digit # remove last digit from number (as integer) number //= 10 </code></pre> <p>On each iteration of the loop, it removes the last digit from number, assigning it to $digit. It's in reverse, starts from the last digit, finishes with t...
48
2009-06-10T11:30:36Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
3,706,281
<p>How about a one-liner list of digits...</p> <pre><code>ldigits = lambda n, l=[]: not n and l or l.insert(0,n%10) or ldigits(n/10,l) </code></pre>
0
2010-09-14T05:20:40Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
3,706,468
<p>On Older versions of Python...</p> <pre><code>map(int,str(123)) </code></pre> <p>On New Version 3k</p> <pre><code>list(map(int,str(123))) </code></pre>
10
2010-09-14T06:07:16Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
7,787,740
<p>Convert it to string and map over it with the int() function.</p> <pre><code>map(int, str(1231231231)) </code></pre>
2
2011-10-16T22:19:24Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
12,435,874
<p>Recursion version:</p> <pre><code>def int_digits(n): return [n] if n&lt;10 else int_digits(n/10)+[n%10] </code></pre>
0
2012-09-15T08:38:56Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
17,458,472
<p>Converting to <code>str</code> is definitely slower then dividing by 10.</p> <p><code>map</code> is sligthly slower than list comprehension:</p> <pre><code>convert to string with map 2.13599181175 convert to string with list comprehension 1.92812991142 modulo, division, recursive 0.948769807816 modulo, division 0....
1
2013-07-03T21:33:35Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
21,102,087
<p>Use the body of this loop to do whatever you want to with the digits</p> <pre><code>for digit in map(int, str(my_number)): </code></pre>
1
2014-01-13T21:51:31Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
21,158,316
<p>I have made this program and here is the bit of code that actually calculates the check digit in my program</p> <pre><code> #Get the 10 digit number number=input("Please enter ISBN number: ") #Explained below no11 = (((int(number[0])*11) + (int(number[1])*10) + (int(number[2])*9) + (int(number[3])*8...
1
2014-01-16T09:48:27Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
22,963,974
<pre><code>(number/10**x)%10 </code></pre> <p>You can use this in a loop, where number is the full number, x is each iteration of the loop (0,1,2,3,...,n) with n being the stop point. x = 0 gives the ones place, x = 1 gives the tens, x = 2 gives the hundreds, and so on. Keep in mind that this will give the value of th...
3
2014-04-09T13:24:56Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
30,133,786
<p>Similar to <a href="http://stackoverflow.com/a/975039/18866">this</a> answer but more a more "pythonic" way to iterate over the digis would be:</p> <pre><code>while number: # "pop" the rightmost digit number, digit = divmod(number, 10) </code></pre>
0
2015-05-08T22:31:46Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
32,567,460
<p><strong>Answer:</strong> 165</p> <p><strong>Method:</strong> brute-force! Here is a tiny bit of Python (version 2.7) code to count'em all.</p> <pre><code>from math import sqrt, floor is_ps = lambda x: floor(sqrt(x)) ** 2 == x count = 0 for n in range(1002, 10000, 3): if n % 11 and is_ps(sum(map(int, str(n)))):...
0
2015-09-14T14:32:51Z
[ "python", "integer", "decimal" ]
Split an integer into digits to compute an ISBN checksum
974,952
<p>I'm writing a program which calculates the check digit of an ISBN number. I have to read the user's input (nine digits of an ISBN) into an integer variable, and then multiply the last digit by 2, the second last digit by 3 and so on. How can I "split" the integer into its constituent digits to do this? As this is a ...
38
2009-06-10T11:10:07Z
32,616,787
<p>Just assuming you want to get the <em>i</em>-th least significant digit from an integer number <em>x</em>, you can try:</p> <pre><code>(abs(x)%(10**i))/(10**(i-1)) </code></pre> <p>I hope it helps.</p>
0
2015-09-16T19:09:35Z
[ "python", "integer", "decimal" ]
access is denied in GAE in eclipse
975,016
<p>When I am trying to to do Model.put() in eclipse for a google python app after changing the parameter of --datastore_path="F:/tmp/myapp_datastore" in arguments of debug configurations.I dont know if its related to above change or is there any other magic behind the scene. Any help.</p> <pre><code>exception value:[E...
0
2009-06-10T11:24:18Z
2,046,254
<p>According to this error,</p> <pre><code>TypeError: 'str' object is not callable </code></pre> <p>I guess, you have shadowed built-in object <code>str</code> to something else.</p> <p>For example, you used <code>str="dummy"</code> in your code and <code>str</code> became uncallable object.</p>
1
2010-01-12T02:14:26Z
[ "python", "eclipse", "google-app-engine" ]
access is denied in GAE in eclipse
975,016
<p>When I am trying to to do Model.put() in eclipse for a google python app after changing the parameter of --datastore_path="F:/tmp/myapp_datastore" in arguments of debug configurations.I dont know if its related to above change or is there any other magic behind the scene. Any help.</p> <pre><code>exception value:[E...
0
2009-06-10T11:24:18Z
17,333,455
<p>Error 5 generally means the path you specified is wrong. I recommend you to remove the double quotation marks in your command:</p> <p>Try:</p> <pre><code>--datastore_path=F:/tmp/myapp_datastore </code></pre> <p>and let us know if that helped you</p>
0
2013-06-27T02:11:26Z
[ "python", "eclipse", "google-app-engine" ]
Sending email using google apps SMTP server in Python 2.4
975,065
<p>I'm having difficulty getting python 2.4 to connect to gmail's smtp server. My below script doesn't ever get past "connection". I realise there is an SMTP_SSL class in later versions of python and it seems to work fine, but the production environment I have to deal with only has - and likely will only ever have - py...
2
2009-06-10T11:36:35Z
975,081
<p>When I tried setting something similar up for Django apps, I could never get it to work on port 465. Using port 587, which is the other port listed in the <a href="http://mail.google.com/support/bin/answer.py?hl=en&amp;answer=13287" rel="nofollow">GMail docs</a> seemed to work.</p>
3
2009-06-10T11:40:19Z
[ "python", "python-2.4" ]
Sending email using google apps SMTP server in Python 2.4
975,065
<p>I'm having difficulty getting python 2.4 to connect to gmail's smtp server. My below script doesn't ever get past "connection". I realise there is an SMTP_SSL class in later versions of python and it seems to work fine, but the production environment I have to deal with only has - and likely will only ever have - py...
2
2009-06-10T11:36:35Z
975,102
<p>Yes I used 587 as the port for my vb.net app too. 465 did not work for me too.</p>
1
2009-06-10T11:43:51Z
[ "python", "python-2.4" ]
Sending email using google apps SMTP server in Python 2.4
975,065
<p>I'm having difficulty getting python 2.4 to connect to gmail's smtp server. My below script doesn't ever get past "connection". I realise there is an SMTP_SSL class in later versions of python and it seems to work fine, but the production environment I have to deal with only has - and likely will only ever have - py...
2
2009-06-10T11:36:35Z
980,900
<p>try</p> <p>server.ehlo('user.name@gmail.com')</p> <p>in both places above</p> <p>also look at setting </p> <p>server.set_debuglevel(1) value as required for more info</p>
1
2009-06-11T12:53:39Z
[ "python", "python-2.4" ]
redirecting sys.stdout to python logging
975,248
<p>So right now we have a lot of python scripts and we are trying to consolidate them and fix and redundancies. One of the things we are trying to do, is to ensure that all sys.stdout/sys.stderr goes into the python logging module.</p> <p>Now the main thing is, we want the following printed out: </p> <pre><code>[&lt;...
11
2009-06-10T12:22:23Z
975,504
<p>I think the problem is that your actual log messages are now being created by the <code>logy.error</code> and <code>logy.info</code> calls in <code>cleanMsg</code>, hence that method is the source of the log messages and you are seeing this as <code>__init__.py</code></p> <p>If you look in the source of Python's <c...
2
2009-06-10T13:15:11Z
[ "python", "logging" ]
redirecting sys.stdout to python logging
975,248
<p>So right now we have a lot of python scripts and we are trying to consolidate them and fix and redundancies. One of the things we are trying to do, is to ensure that all sys.stdout/sys.stderr goes into the python logging module.</p> <p>Now the main thing is, we want the following printed out: </p> <pre><code>[&lt;...
11
2009-06-10T12:22:23Z
976,281
<p>The problem is that the logging module is looking a single layer up the call stack to find who called it, but now your function is an intermediate layer at that point (Though I'd have expected it to report <code>cleanMsg</code>, not <code>__init__</code>, as that's where you're calling into log()). Instead, you ne...
6
2009-06-10T15:18:15Z
[ "python", "logging" ]
Why is Logging going in an infinite Loop?
975,456
<p>I have the following code:</p> <pre><code>#!/usr/bin/env python import logging import sys import copy class Wrapper: def write(self, s): #sys.__stdout__.write(s) loggy = logging.getLogger('foobar') loggy.info(s) def blah(): logger = logging.getLogger('foobar') logger.setLevel(l...
0
2009-06-10T13:09:10Z
975,519
<p>The infinite loop is happening because your logger's <code>StreamHandler</code> is set to write its log messages to <code>sys.stdout</code>, but <code>sys.stdout</code> is in turn wrapped and writes back to the very logger that just sent it a write message.</p> <p>Depending on your goals, you're probably better hav...
5
2009-06-10T13:18:05Z
[ "python", "logging" ]
connection reset for concurrent usage by two users GAE
975,651
<p>I am trying to access same python web app in GAE from firefox and IE with different user login and when I start the IE session I get the following error with IE going standstill. why?</p> <pre><code>error: (10054, 'Connection reset by peer') </code></pre>
1
2009-06-10T13:35:40Z
975,692
<p>Do you get a similar outcome when you start the IE session first, then the Firefox session? what about trying two IE sessions, two Firefox sessions, that why you can rule in/out browser differences.</p>
0
2009-06-10T13:42:25Z
[ "python", "google-app-engine", "connection", "reset" ]
connection reset for concurrent usage by two users GAE
975,651
<p>I am trying to access same python web app in GAE from firefox and IE with different user login and when I start the IE session I get the following error with IE going standstill. why?</p> <pre><code>error: (10054, 'Connection reset by peer') </code></pre>
1
2009-06-10T13:35:40Z
979,869
<p>I presume this is on the dev_appserver? Bear in mind that the dev_appserver is single-threaded, so it will not handle multiple concurrent users well.</p> <p>Can you give more detail about exactly what sequence of operations causes this? Are there any stack traces on the dev_appserver console when it happens?</p>
1
2009-06-11T07:54:13Z
[ "python", "google-app-engine", "connection", "reset" ]
connection reset for concurrent usage by two users GAE
975,651
<p>I am trying to access same python web app in GAE from firefox and IE with different user login and when I start the IE session I get the following error with IE going standstill. why?</p> <pre><code>error: (10054, 'Connection reset by peer') </code></pre>
1
2009-06-10T13:35:40Z
993,456
<p>Eclipse creates multiple instances on range of ports and few of them conflicts with pythons working. I could not locate the exact port or did not know how to stop eclipse from doing so. I did simple netstat and observed this behavior of port capturing and causing reset</p>
0
2009-06-14T18:40:55Z
[ "python", "google-app-engine", "connection", "reset" ]
Perl and CopSSH
975,785
<p>I'm trying to automate a process on a remote machine using a python script. The machine is a windows machine and I've installed CopSSH on it in order to SSH into it to run commands. I'm having trouble getting perl scripts to run from the CopSSH terminal. I get a command not found error. Is there a special way that I...
0
2009-06-10T13:59:25Z
975,857
<p>I suspect CopSSH is giving you different environment vars to a normal GUI login. I'd suggest you type 'set' and see if perl is in the path with any other environment vars it might need. </p> <p>Here is some explanation of <a href="http://apps.sourceforge.net/mediawiki/controltier/index.php?title=OpenSSH%5Fon%5FWind...
4
2009-06-10T14:13:29Z
[ "python", "perl", "ssh", "openssh" ]
Perl and CopSSH
975,785
<p>I'm trying to automate a process on a remote machine using a python script. The machine is a windows machine and I've installed CopSSH on it in order to SSH into it to run commands. I'm having trouble getting perl scripts to run from the CopSSH terminal. I get a command not found error. Is there a special way that I...
0
2009-06-10T13:59:25Z
975,889
<p>Are you using <a href="http://www.activestate.com/activeperl/" rel="nofollow">ActiveState</a> or <a href="http://strawberryperl.com/" rel="nofollow">Strawberry</a> Perl? What error messages are you getting? You may find the answers to <a href="http://stackoverflow.com/questions/667471/how-do-i-run-programs-with-st...
2
2009-06-10T14:18:51Z
[ "python", "perl", "ssh", "openssh" ]
Perl and CopSSH
975,785
<p>I'm trying to automate a process on a remote machine using a python script. The machine is a windows machine and I've installed CopSSH on it in order to SSH into it to run commands. I'm having trouble getting perl scripts to run from the CopSSH terminal. I get a command not found error. Is there a special way that I...
0
2009-06-10T13:59:25Z
976,287
<p>I just realized CopSSH is based on Cygwin which I think means paths would have to be specified differently. Try using, for example, </p> <p><code>/cygdrive/c/Program\ Files/My\ Program/myprog.exe</code> </p> <p>instead of </p> <p><code>"C:\Program Files\My Program\myprog.exe"</code>.</p> <p>BTW, the following Co...
2
2009-06-10T15:19:08Z
[ "python", "perl", "ssh", "openssh" ]
Can Python adodbapi be used to connect to a paradox db?
976,324
<p>Can Python adodbapi be used to connect to a paradox db? If yes what would the connection string look like?</p>
0
2009-06-10T15:24:32Z
977,156
<p>Yes, that depends on the Paradox ADODB driver you have installed in your windows.</p> <p>Examples:</p> <p>For Paradox 5.x, using Microsoft Jet OLEDB 4.0 driver:</p> <pre><code>r"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\myDb; Extended Properties=Paradox 5.x;" </code></pre> <p>For Paradox 5.x, using Microso...
0
2009-06-10T17:47:59Z
[ "python", "paradox" ]
Best way to get the name of a button that called an event?
976,395
<p>In the following code (inspired by <a href="http://www.daniweb.com/code/snippet508.html" rel="nofollow">this</a> snippet), I use a single event handler <code>buttonClick</code> to change the title of the window. Currently, I need to evaluate if the Id of the event corresponds to the Id of the button. If I decide to ...
4
2009-06-10T15:34:43Z
976,436
<p>Keep a <code>dict</code> with keys that are the <code>.Id</code> of the buttons and values that are the button names or whatever, so instead of a long <code>if/elif</code> chain you do a single <code>dict</code> lookup in <code>buttonClick</code>.</p> <p>Code snippets: in <code>__init__</code>, add creation and upd...
3
2009-06-10T15:41:22Z
[ "python", "user-interface", "events", "event-handling", "wxpython" ]
Best way to get the name of a button that called an event?
976,395
<p>In the following code (inspired by <a href="http://www.daniweb.com/code/snippet508.html" rel="nofollow">this</a> snippet), I use a single event handler <code>buttonClick</code> to change the title of the window. Currently, I need to evaluate if the Id of the event corresponds to the Id of the button. If I decide to ...
4
2009-06-10T15:34:43Z
976,443
<p>You could create a dictionary of buttons, and do the look based on the <code>id</code> ... something like this:</p> <pre><code>class MyFrame(wx.Frame): def _add_button (self, *args): btn = wx.Button (*args) btn.Bind (wx.EVT_BUTTON, self.buttonClick) self.buttons[btn.id] = btn def __init__ (s...
1
2009-06-10T15:43:12Z
[ "python", "user-interface", "events", "event-handling", "wxpython" ]
Best way to get the name of a button that called an event?
976,395
<p>In the following code (inspired by <a href="http://www.daniweb.com/code/snippet508.html" rel="nofollow">this</a> snippet), I use a single event handler <code>buttonClick</code> to change the title of the window. Currently, I need to evaluate if the Id of the event corresponds to the Id of the button. If I decide to ...
4
2009-06-10T15:34:43Z
976,452
<p>I ran into a similar problem: I was generating buttons based on user-supplied data, and I needed the buttons to affect another class, so I needed to pass along information about the buttonclick. What I did was explicitly assign button IDs to each button I generated, then stored information about them in a dictionar...
0
2009-06-10T15:45:16Z
[ "python", "user-interface", "events", "event-handling", "wxpython" ]
Best way to get the name of a button that called an event?
976,395
<p>In the following code (inspired by <a href="http://www.daniweb.com/code/snippet508.html" rel="nofollow">this</a> snippet), I use a single event handler <code>buttonClick</code> to change the title of the window. Currently, I need to evaluate if the Id of the event corresponds to the Id of the button. If I decide to ...
4
2009-06-10T15:34:43Z
976,691
<p>You could give the button a name, and then look at the name in the event handler.</p> <p>When you make the button</p> <pre><code>b = wx.Button(self, 10, "Default Button", (20, 20)) b.myname = "default button" self.Bind(wx.EVT_BUTTON, self.OnClick, b) </code></pre> <p>When the button is clicked:</p> <pre><code>de...
8
2009-06-10T16:21:51Z
[ "python", "user-interface", "events", "event-handling", "wxpython" ]
Best way to get the name of a button that called an event?
976,395
<p>In the following code (inspired by <a href="http://www.daniweb.com/code/snippet508.html" rel="nofollow">this</a> snippet), I use a single event handler <code>buttonClick</code> to change the title of the window. Currently, I need to evaluate if the Id of the event corresponds to the Id of the button. If I decide to ...
4
2009-06-10T15:34:43Z
977,110
<p>I recommend that you use different event handlers to handle events from each button. If there is a lot of commonality, you can combine that into a function which <em>returns</em> a function with the specific behavior you want, for instance:</p> <pre><code>def goingTo(self, where): def goingToHandler(event): ...
5
2009-06-10T17:38:56Z
[ "python", "user-interface", "events", "event-handling", "wxpython" ]
Best way to get the name of a button that called an event?
976,395
<p>In the following code (inspired by <a href="http://www.daniweb.com/code/snippet508.html" rel="nofollow">this</a> snippet), I use a single event handler <code>buttonClick</code> to change the title of the window. Currently, I need to evaluate if the Id of the event corresponds to the Id of the button. If I decide to ...
4
2009-06-10T15:34:43Z
982,887
<p>Take advantage of what you can do in a language like Python. You can pass extra arguments to your event callback function, like so.</p> <pre><code>import functools def __init__(self): # ... for i in range(10): name = 'Button %d' % i button = wx.Button(parent, -1, name) func = funct...
7
2009-06-11T18:41:41Z
[ "python", "user-interface", "events", "event-handling", "wxpython" ]
Best way to get the name of a button that called an event?
976,395
<p>In the following code (inspired by <a href="http://www.daniweb.com/code/snippet508.html" rel="nofollow">this</a> snippet), I use a single event handler <code>buttonClick</code> to change the title of the window. Currently, I need to evaluate if the Id of the event corresponds to the Id of the button. If I decide to ...
4
2009-06-10T15:34:43Z
1,040,158
<p>I needed to do the same thing to keep track of button-presses . I used a lambda function to bind to the event . That way I could pass in the entire button object to the event handler function to manipulate accordingly.</p> <pre><code> class PlatGridderTop(wx.Frame): numbuttons = 0 buttonlist = []...
0
2009-06-24T18:41:08Z
[ "python", "user-interface", "events", "event-handling", "wxpython" ]
Problem with Python interpreter in Eclipse
976,506
<p>When trying to set the interpreter for python in Eclipse by choosing the executable, clicking OK displays "An error has occured." Does the interpreter name matter?</p>
1
2009-06-10T15:54:47Z
983,463
<p>Testing/running your apps on the command line is the safest bet, especially when writing threaded applications (you can kill your threadlocked program without killing eclipse)</p>
0
2009-06-11T20:29:05Z
[ "python", "eclipse", "ubuntu", "interpreter" ]
Problem with Python interpreter in Eclipse
976,506
<p>When trying to set the interpreter for python in Eclipse by choosing the executable, clicking OK displays "An error has occured." Does the interpreter name matter?</p>
1
2009-06-10T15:54:47Z
1,393,294
<p>I had a similar problems with this on Mac OS X. My problem was that I had a space in Eclipse's application path, e.g. "/Applications/eclipse 3.3/Eclipse".</p> <p>I changed the folder name to "/Applications/eclipse3.3" and it fixed it.</p>
1
2009-09-08T10:50:50Z
[ "python", "eclipse", "ubuntu", "interpreter" ]
Random hash in Python
976,577
<p>What is the <strong>easiest</strong> way to generate a random hash (MD5) in Python?</p>
40
2009-06-10T16:05:02Z
976,607
<p>A md5-hash is just a 128-bit value, so if you want a random one:</p> <pre><code>import random hash = random.getrandbits(128) print "hash value: %032x" % hash </code></pre> <p>I don't really see the point, though. Maybe you should elaborate why you need this...</p>
72
2009-06-10T16:09:12Z
[ "python", "hash", "md5" ]
Random hash in Python
976,577
<p>What is the <strong>easiest</strong> way to generate a random hash (MD5) in Python?</p>
40
2009-06-10T16:05:02Z
984,184
<p>Another approach to this specific question:</p> <pre><code>import random, string def random_md5like_hash(): available_chars= string.hexdigits[:16] return ''.join( random.choice(available_chars) for dummy in xrange(32)) </code></pre> <p>I'm not saying it's faster or preferable to any other ...
5
2009-06-11T22:52:23Z
[ "python", "hash", "md5" ]
Random hash in Python
976,577
<p>What is the <strong>easiest</strong> way to generate a random hash (MD5) in Python?</p>
40
2009-06-10T16:05:02Z
9,011,133
<p>Yet another approach. You won't have to format an int to get it.</p> <pre><code>import random import string def random_string(length): pool = string.letters + string.digits return ''.join(random.choice(pool) for i in xrange(length)) </code></pre> <p>Gives you flexibility on the length of the string.</p> ...
7
2012-01-25T22:10:22Z
[ "python", "hash", "md5" ]
Random hash in Python
976,577
<p>What is the <strong>easiest</strong> way to generate a random hash (MD5) in Python?</p>
40
2009-06-10T16:05:02Z
9,816,388
<p>This works for both python 2.x and 3.x</p> <pre><code>import os import binascii print(binascii.hexlify(os.urandom(16))) '4a4d443679ed46f7514ad6dbe3733c3d' </code></pre>
33
2012-03-22T04:19:41Z
[ "python", "hash", "md5" ]
Random hash in Python
976,577
<p>What is the <strong>easiest</strong> way to generate a random hash (MD5) in Python?</p>
40
2009-06-10T16:05:02Z
17,888,044
<pre><code>import uuid from md5 import md5 print md5(str(uuid.uuid4())).hexdigest() </code></pre>
2
2013-07-26T18:03:28Z
[ "python", "hash", "md5" ]
Random hash in Python
976,577
<p>What is the <strong>easiest</strong> way to generate a random hash (MD5) in Python?</p>
40
2009-06-10T16:05:02Z
20,060,712
<p>I think what you are looking for is a universal unique identifier.Then the module UUID in python is what you are looking for.</p> <pre><code>import uuid uuid.uuid4().hex </code></pre> <p>UUID4 gives you a random unique identifier that has the same length as a md5 sum. Hex will represent is as an hex string instead...
28
2013-11-19T00:18:52Z
[ "python", "hash", "md5" ]
python-scapy: how to translate port numbers to service names?
976,599
<p>A TCP layer in Scapy contains source port:</p> <pre><code>&gt;&gt;&gt; a[TCP].sport 80 </code></pre> <p>Is there a simple way to convert port number to service name? I've seen Scapy has <code>TCP_SERVICES</code> and <code>UDP_SERVICES</code> to translate port number, but </p> <pre><code>print TCP_SERVICES[80] # f...
0
2009-06-10T16:08:05Z
978,667
<p>Python's <a href="http://docs.python.org/library/socket.html">socket</a> module will do that:</p> <pre><code>&gt;&gt;&gt; import socket &gt;&gt;&gt; socket.getservbyport(80) 'http' &gt;&gt;&gt; socket.getservbyport(21) 'ftp' &gt;&gt;&gt; socket.getservbyport(53, 'udp') 'domain' </code></pre>
10
2009-06-10T23:46:23Z
[ "python", "tcp", "scapy" ]
python-scapy: how to translate port numbers to service names?
976,599
<p>A TCP layer in Scapy contains source port:</p> <pre><code>&gt;&gt;&gt; a[TCP].sport 80 </code></pre> <p>Is there a simple way to convert port number to service name? I've seen Scapy has <code>TCP_SERVICES</code> and <code>UDP_SERVICES</code> to translate port number, but </p> <pre><code>print TCP_SERVICES[80] # f...
0
2009-06-10T16:08:05Z
978,677
<p>This may work for you (filtering the dictionary based on the value):</p> <pre><code>&gt;&gt;&gt; [k for k, v in TCP_SERVICES.iteritems() if v == 80][0] 'www' </code></pre>
1
2009-06-10T23:50:58Z
[ "python", "tcp", "scapy" ]
python-scapy: how to translate port numbers to service names?
976,599
<p>A TCP layer in Scapy contains source port:</p> <pre><code>&gt;&gt;&gt; a[TCP].sport 80 </code></pre> <p>Is there a simple way to convert port number to service name? I've seen Scapy has <code>TCP_SERVICES</code> and <code>UDP_SERVICES</code> to translate port number, but </p> <pre><code>print TCP_SERVICES[80] # f...
0
2009-06-10T16:08:05Z
978,695
<p>If this is something you need to do frequently, you can create a reverse mapping of <code>TCP_SERVICES</code>:</p> <pre><code>&gt;&gt;&gt; TCP_REVERSE = dict((TCP_SERVICES[k], k) for k in TCP_SERVICES.keys()) &gt;&gt;&gt; TCP_REVERSE[80] 'www' </code></pre>
3
2009-06-10T23:57:50Z
[ "python", "tcp", "scapy" ]
python-scapy: how to translate port numbers to service names?
976,599
<p>A TCP layer in Scapy contains source port:</p> <pre><code>&gt;&gt;&gt; a[TCP].sport 80 </code></pre> <p>Is there a simple way to convert port number to service name? I've seen Scapy has <code>TCP_SERVICES</code> and <code>UDP_SERVICES</code> to translate port number, but </p> <pre><code>print TCP_SERVICES[80] # f...
0
2009-06-10T16:08:05Z
984,262
<p>If you are using unix or linux there is a file /etc/services which contains this mapping.</p>
0
2009-06-11T23:12:29Z
[ "python", "tcp", "scapy" ]
python-scapy: how to translate port numbers to service names?
976,599
<p>A TCP layer in Scapy contains source port:</p> <pre><code>&gt;&gt;&gt; a[TCP].sport 80 </code></pre> <p>Is there a simple way to convert port number to service name? I've seen Scapy has <code>TCP_SERVICES</code> and <code>UDP_SERVICES</code> to translate port number, but </p> <pre><code>print TCP_SERVICES[80] # f...
0
2009-06-10T16:08:05Z
1,053,486
<p>I've found a good solution filling another dict self.MYTCP_SERVICES</p> <pre><code>for p in scapy.data.TCP_SERVICES.keys(): self.MYTCP_SERVICES[scapy.data.TCP_SERVICES[p]] = p </code></pre>
0
2009-06-27T19:46:15Z
[ "python", "tcp", "scapy" ]
Thinking in AppEngine
976,639
<p>I'm looking for resources to help migrate my design skills from traditional RDBMS data store over to AppEngine DataStore (ie: 'Soft Schema' style). I've seen several presentations and all touch on the the overarching themes and some specific techniques. </p> <p>I'm wondering if there's a place we could pool knowled...
6
2009-06-10T16:13:56Z
977,509
<p>I played around with Google App Engine for Java and found that it had many shortcomings:</p> <p>This is not general purpose Java application hosting. In particular, you do not have access to a full JRE (e.g. cannot create threads, etc.) Given this fact, you pretty much have to build your application from the ground...
1
2009-06-10T18:54:28Z
[ "java", "python", "google-app-engine", "data-modeling" ]
Thinking in AppEngine
976,639
<p>I'm looking for resources to help migrate my design skills from traditional RDBMS data store over to AppEngine DataStore (ie: 'Soft Schema' style). I've seen several presentations and all touch on the the overarching themes and some specific techniques. </p> <p>I'm wondering if there's a place we could pool knowled...
6
2009-06-10T16:13:56Z
978,757
<p>The timeouts are tight and performance was ok but not great, so I found myself using extra space to save time; for example I had a many-to-many relationship between trading cards and players, so I duplicated the information of who owns what: Card objects have a list of Players and Player objects have a list of Cards...
1
2009-06-11T00:21:54Z
[ "java", "python", "google-app-engine", "data-modeling" ]
Thinking in AppEngine
976,639
<p>I'm looking for resources to help migrate my design skills from traditional RDBMS data store over to AppEngine DataStore (ie: 'Soft Schema' style). I've seen several presentations and all touch on the the overarching themes and some specific techniques. </p> <p>I'm wondering if there's a place we could pool knowled...
6
2009-06-10T16:13:56Z
979,391
<p>The non relational database design essentially involves denormalization wherever possible.</p> <p>Example: Since the BigTable doesnt provide enough aggregation features, the sum(cash) option that would be in the RDBMS world is not available. Instead it would have to be stored on the model and the model save method ...
1
2009-06-11T05:00:52Z
[ "java", "python", "google-app-engine", "data-modeling" ]
Thinking in AppEngine
976,639
<p>I'm looking for resources to help migrate my design skills from traditional RDBMS data store over to AppEngine DataStore (ie: 'Soft Schema' style). I've seen several presentations and all touch on the the overarching themes and some specific techniques. </p> <p>I'm wondering if there's a place we could pool knowled...
6
2009-06-10T16:13:56Z
979,412
<blockquote> <p>I'm wondering if there's a place we could pool knowledge from experience</p> </blockquote> <p>Various Google Groups are good for that, though I don't know if any are directly applicable to Java-GAE yet -- my GAE experience so far is all-Python (I'm kind of proud to say that Guido van Rossum, inventor...
6
2009-06-11T05:09:17Z
[ "java", "python", "google-app-engine", "data-modeling" ]
Can I make Python 2.5 exit on ctrl-D in Windows instead of ctrl-Z?
976,796
<p>I'm used to ending the python interactive interpreter using Ctrl-d using Linux and OS X. On windows though, you have to use Ctrl-z and then enter. Is there any way to use Ctrl-d?</p>
5
2009-06-10T16:40:43Z
977,031
<p>You can change the key set that Idle should be using. </p> <ol> <li><p>Under Options->"Configure IDLE..." go to the "Keys" tab. </p></li> <li><p>On the right you can select the "IDLE Classic Unix" key set.</p></li> </ol>
0
2009-06-10T17:28:08Z
[ "python", "windows", "python-2.5" ]
Can I make Python 2.5 exit on ctrl-D in Windows instead of ctrl-Z?
976,796
<p>I'm used to ending the python interactive interpreter using Ctrl-d using Linux and OS X. On windows though, you have to use Ctrl-z and then enter. Is there any way to use Ctrl-d?</p>
5
2009-06-10T16:40:43Z
977,063
<p>You can't use <strong><kbd>CTRL</kbd>+<kbd>D</kbd></strong> on windows. </p> <p><strong><kbd>CTRL</kbd>+<kbd>Z</kbd></strong> is a <a href="http://en.wikipedia.org/wiki/End_of_file" rel="nofollow">windows-specific control char that prints EOF</a>. On *nix, it is typically <strong><kbd>CTRL</kbd>+<kbd>D</kbd></stron...
6
2009-06-10T17:33:23Z
[ "python", "windows", "python-2.5" ]
Can I make Python 2.5 exit on ctrl-D in Windows instead of ctrl-Z?
976,796
<p>I'm used to ending the python interactive interpreter using Ctrl-d using Linux and OS X. On windows though, you have to use Ctrl-z and then enter. Is there any way to use Ctrl-d?</p>
5
2009-06-10T16:40:43Z
977,170
<p>Ctrl-d works to exit from <a href="http://ipython.scipy.org/moin/" rel="nofollow">IPython</a> <br /> (installed by <a href="http://www.pythonxy.com/foreword.php" rel="nofollow">python(x,y)</a> package).<br /></p> <ul> <li>OS: WinXP</li> <li>Python version: 2.5.4</li> </ul> <p><hr /></p> <p><strong>Edit: I've be...
4
2009-06-10T17:51:26Z
[ "python", "windows", "python-2.5" ]
Can I make Python 2.5 exit on ctrl-D in Windows instead of ctrl-Z?
976,796
<p>I'm used to ending the python interactive interpreter using Ctrl-d using Linux and OS X. On windows though, you have to use Ctrl-z and then enter. Is there any way to use Ctrl-d?</p>
5
2009-06-10T16:40:43Z
978,669
<p>Run Cygwin Python if windowisms are bothering you... Unless what you are doing depends on pywin32 that is.</p>
0
2009-06-10T23:47:15Z
[ "python", "windows", "python-2.5" ]
Shuffling a list of objects in python
976,882
<p>I have a list of objects in Python and I want to shuffle them. I thought I could use the <code>random.shuffle</code> method, but this seems to fail when the list is of objects. Is there a method for shuffling object or another way around this?</p> <pre><code>import random class a: foo = "bar" a1 = a() a2 = a(...
290
2009-06-10T16:56:59Z
976,918
<p><a href="https://docs.python.org/library/random.html#random.shuffle"><code>random.shuffle</code></a> should work. Here's an example, where the objects are lists:</p> <pre><code>from random import shuffle x = [[i] for i in range(10)] shuffle(x) # print x gives [[9], [2], [7], [0], [4], [5], [3], [1], [8], [6]] #...
485
2009-06-10T17:03:37Z
[ "python", "list", "random", "shuffle" ]
Shuffling a list of objects in python
976,882
<p>I have a list of objects in Python and I want to shuffle them. I thought I could use the <code>random.shuffle</code> method, but this seems to fail when the list is of objects. Is there a method for shuffling object or another way around this?</p> <pre><code>import random class a: foo = "bar" a1 = a() a2 = a(...
290
2009-06-10T16:56:59Z
976,921
<pre><code>&gt;&gt;&gt; import random &gt;&gt;&gt; a = ['hi','world','cat','dog'] &gt;&gt;&gt; random.shuffle(a,random.random) &gt;&gt;&gt; a ['hi', 'cat', 'dog', 'world'] </code></pre> <p>It works fine for me. Make sure to set the random method.</p>
8
2009-06-10T17:04:16Z
[ "python", "list", "random", "shuffle" ]
Shuffling a list of objects in python
976,882
<p>I have a list of objects in Python and I want to shuffle them. I thought I could use the <code>random.shuffle</code> method, but this seems to fail when the list is of objects. Is there a method for shuffling object or another way around this?</p> <pre><code>import random class a: foo = "bar" a1 = a() a2 = a(...
290
2009-06-10T16:56:59Z
4,353,542
<pre><code>#!/usr/bin/python3 import random s=list(range(5)) random.shuffle(s) # &lt;&lt; shuffle before print or assignment print(s) # print: [2, 4, 1, 3, 0] </code></pre>
19
2010-12-04T12:46:10Z
[ "python", "list", "random", "shuffle" ]
Shuffling a list of objects in python
976,882
<p>I have a list of objects in Python and I want to shuffle them. I thought I could use the <code>random.shuffle</code> method, but this seems to fail when the list is of objects. Is there a method for shuffling object or another way around this?</p> <pre><code>import random class a: foo = "bar" a1 = a() a2 = a(...
290
2009-06-10T16:56:59Z
12,978,830
<p>As you learned the in-place shuffling was the problem. I also have problem frequently, and often seem to forget how to copy a list, too. Using <code>sample(a, len(a))</code> is the solution.</p> <p>Here's a simple version using <code>random.sample()</code> that returns the shuffled result as a new list.</p> <pre><...
49
2012-10-19T16:50:08Z
[ "python", "list", "random", "shuffle" ]
Shuffling a list of objects in python
976,882
<p>I have a list of objects in Python and I want to shuffle them. I thought I could use the <code>random.shuffle</code> method, but this seems to fail when the list is of objects. Is there a method for shuffling object or another way around this?</p> <pre><code>import random class a: foo = "bar" a1 = a() a2 = a(...
290
2009-06-10T16:56:59Z
16,737,991
<p>'print func(foo)' will print the return value of 'func' when called with 'foo'. 'shuffle' however has None as its return type, as the list will be modified in place, hence it prints nothing. Workaround:</p> <pre><code># shuffle the list in place random.shuffle(b) # print it print(b) </code></pre> <p>If you're mo...
2
2013-05-24T14:59:33Z
[ "python", "list", "random", "shuffle" ]