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
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
1,534,532
<pre><code>print "var" print "something_else" </code></pre> <p>Or did you mean something_else?</p>
0
2009-10-07T22:11:58Z
[ "python", "string", "variables" ]
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
1,534,543
<p>You somehow have to refer to the variable you want to print the name of. So it would look like:</p> <pre><code>print varname(something_else) </code></pre> <p>There is no such function, but if there were it would be kind of pointless. You have to type out <code>something_else</code>, so you can as well just type qu...
3
2009-10-07T22:13:17Z
[ "python", "string", "variables" ]
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
1,534,553
<p>This is not possible.</p> <p>In Python, there really isn't any such thing as a "variable". What Python really has are "names" which can have objects bound to them. It makes no difference to the object what names, if any, it might be bound to. It might be bound to dozens of different names, or none.</p> <p>Consi...
7
2009-10-07T22:15:55Z
[ "python", "string", "variables" ]
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
1,534,618
<p>Technically the information is available to you, but as others have asked, how would you make use of it in a sensible way?</p> <pre><code>&gt;&gt;&gt; x = 52 &gt;&gt;&gt; globals() {'__builtins__': &lt;module '__builtin__' (built-in)&gt;, '__name__': '__main__', 'x': 52, '__doc__': None, '__package__': None} </cod...
7
2009-10-07T22:37:22Z
[ "python", "string", "variables" ]
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
1,535,029
<p>What are you trying to achieve? There is absolutely no reason to ever do what you describe, and there is likely a much better solution to the problem you're trying to solve..</p> <p>The most obvious alternative to what you request is a dictionary. For example:</p> <pre><code>&gt;&gt;&gt; my_data = {'var': 'somethi...
3
2009-10-08T00:51:42Z
[ "python", "string", "variables" ]
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
3,683,258
<p>There is an usage scenario where you might need this. I'm not implying there are not better ways or achieving the same functionality.</p> <p>This would be useful in order to 'dump' an arbitrary list of dictionaries in case of error, in debug modes and other similar situations.</p> <p>What would be needed, is the r...
27
2010-09-10T08:46:57Z
[ "python", "string", "variables" ]
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
5,172,892
<p>Does Django not do this when generating field names?</p> <p><a href="http://docs.djangoproject.com/en/dev//topics/db/models/#verbose-field-names" rel="nofollow">http://docs.djangoproject.com/en/dev//topics/db/models/#verbose-field-names</a></p> <p>Seems reasonable to me.</p>
2
2011-03-02T20:15:40Z
[ "python", "string", "variables" ]
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
6,504,497
<p>This will work for simnple data types (str, int, float, list etc.)</p> <pre> >>> def my_print(var_str) : print var_str+':', globals()[var_str] >>> a = 5 >>> b = ['hello', ',world!'] >>> my_print('a') a: 5 >>> my_print('b') b: ['hello', ',world!'] </pre>
0
2011-06-28T09:40:31Z
[ "python", "string", "variables" ]
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
6,797,755
<p>I searched for this question because I wanted a Python program to print assignment statements for some of the variables in the program. For example, it might print "foo = 3, bar = 21, baz = 432". The print function would need the variable names in string form. I could have provided my code with the strings "foo","ba...
4
2011-07-23T01:56:15Z
[ "python", "string", "variables" ]
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
13,279,103
<p>I think this is a cool solution and I suppose the best you can get. But do you see any way to handle the ambigious results, your function may return? As <a href="http://stackoverflow.com/questions/306313/python-is-operator-behaves-unexpectedly-with-integers">Python &quot;is&quot; operator behaves unexpectedly with i...
2
2012-11-07T22:07:19Z
[ "python", "string", "variables" ]
Convert Variable Name to String?
1,534,504
<p>I would like to convert a python variable name into the string equivalent as shown. Any ideas how?</p> <pre><code>var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' </code></pre>
29
2009-10-07T22:06:13Z
15,361,037
<p>as long as it's a variable and not a second class, this here works for me:</p> <pre><code>def print_var_name(variable): for name in globals(): if eval(name) == variable: print name foo = 123 print_var_name(foo) &gt;&gt;&gt;foo </code></pre> <p>this happens for class members:</p> <pre><code>class xyz...
2
2013-03-12T12:20:24Z
[ "python", "string", "variables" ]
Can I sort text by its numeric value in Python?
1,534,542
<p>I have dict in Python with keys of the following form:</p> <pre><code>mydict = {'0' : 10, '1' : 23, '2.0' : 321, '2.1' : 3231, '3' : 3, '4.0.0' : 1, '4.0.1' : 10, '5' : 11, # ... etc '10' : 32, ...
10
2009-10-07T22:13:17Z
1,534,568
<p>You can sort the keys the way that you want, by splitting them on '.' and then converting each of the components into an integer, like this:</p> <pre><code>sorted(mydict.keys(), key=lambda a:map(int,a.split('.'))) </code></pre> <p>which returns this:</p> <pre><code>['0', '1', '2.0', '2.1', '3', '4.0.0', '4....
18
2009-10-07T22:21:10Z
[ "python", "string", "sorting" ]
Can I sort text by its numeric value in Python?
1,534,542
<p>I have dict in Python with keys of the following form:</p> <pre><code>mydict = {'0' : 10, '1' : 23, '2.0' : 321, '2.1' : 3231, '3' : 3, '4.0.0' : 1, '4.0.1' : 10, '5' : 11, # ... etc '10' : 32, ...
10
2009-10-07T22:13:17Z
1,534,569
<p>Python's sorting functions can take a custom compare function, so you just need to define a function that compares keys the way you like:</p> <pre><code>def version_cmp(a, b): '''These keys just look like version numbers to me....''' ai = map(int, a.split('.')) bi = map(int, b.split('.')) return cmp(ai, bi)...
2
2009-10-07T22:21:10Z
[ "python", "string", "sorting" ]
Can I sort text by its numeric value in Python?
1,534,542
<p>I have dict in Python with keys of the following form:</p> <pre><code>mydict = {'0' : 10, '1' : 23, '2.0' : 321, '2.1' : 3231, '3' : 3, '4.0.0' : 1, '4.0.1' : 10, '5' : 11, # ... etc '10' : 32, ...
10
2009-10-07T22:13:17Z
1,534,571
<p>I would do a search on <a href="http://stackoverflow.com/search?q=sorting+a+python+dictionary">"sorting a python dictionary"</a> and take a look at the answers. I would give <a href="http://www.python.org/dev/peps/pep-0265/" rel="nofollow">PEP-265</a> a read as well. The <a href="http://docs.python.org/library/func...
0
2009-10-07T22:21:30Z
[ "python", "string", "sorting" ]
Can I sort text by its numeric value in Python?
1,534,542
<p>I have dict in Python with keys of the following form:</p> <pre><code>mydict = {'0' : 10, '1' : 23, '2.0' : 321, '2.1' : 3231, '3' : 3, '4.0.0' : 1, '4.0.1' : 10, '5' : 11, # ... etc '10' : 32, ...
10
2009-10-07T22:13:17Z
1,534,816
<p>As an addendum to <a href="http://stackoverflow.com/questions/1534542/can-i-sort-text-by-its-numeric-value-in-python#1534568" title="Ian Clelland's">Ian Clelland's</a> answer, the <code>map()</code> call can be replaced with a list comprehension... if you prefer that style. It <em>may</em> also be more efficient (th...
2
2009-10-07T23:42:48Z
[ "python", "string", "sorting" ]
Can I sort text by its numeric value in Python?
1,534,542
<p>I have dict in Python with keys of the following form:</p> <pre><code>mydict = {'0' : 10, '1' : 23, '2.0' : 321, '2.1' : 3231, '3' : 3, '4.0.0' : 1, '4.0.1' : 10, '5' : 11, # ... etc '10' : 32, ...
10
2009-10-07T22:13:17Z
3,590,671
<p>For fun &amp; usefulness (for googling ppl, mostly):</p> <pre><code>f = lambda i: [int(j) if re.match(r"[0-9]+", j) else j for j in re.findall(r"([0-9]+|[^0-9]+)", i)] cmpg = lambda x, y: cmp(f(x), f(y)) </code></pre> <p>use as <code>sorted(list, cmp=cmpg)</code>. Additionally, regexes might be pre-compiled (rarel...
1
2010-08-28T12:02:45Z
[ "python", "string", "sorting" ]
Can I sort text by its numeric value in Python?
1,534,542
<p>I have dict in Python with keys of the following form:</p> <pre><code>mydict = {'0' : 10, '1' : 23, '2.0' : 321, '2.1' : 3231, '3' : 3, '4.0.0' : 1, '4.0.1' : 10, '5' : 11, # ... etc '10' : 32, ...
10
2009-10-07T22:13:17Z
5,039,120
<p>There is a nice sorting HOWTO on the python web site: <a href="http://wiki.python.org/moin/HowTo/Sorting" rel="nofollow">http://wiki.python.org/moin/HowTo/Sorting</a> . It makes a good introduction to sorting, and discusses different techniques to adapt the sorting result to your needs.</p>
0
2011-02-18T08:33:56Z
[ "python", "string", "sorting" ]
Creating a program to be broadcasted by avahi
1,534,655
<p>I'm trying to write a program that outputs data that can be served over a network with avahi. The documentation I've looked at seems to say I have to register the service with dbus and then connect it to avahi, but the documentation to do this is pretty sparse. Does anyone know of good documentation for it? I've be...
3
2009-10-07T22:52:11Z
1,561,594
<p>Avahi is "just" a Client implementation of <a href="http://en.wikipedia.org/wiki/Zero%5Fconfiguration%5Fnetworking" rel="nofollow">ZeroConfig</a> which basically is a "Multicast based DNS" protocol. You can use Avahi to publish the availability of your "data" through end-points. The actual data must be retrieved t...
0
2009-10-13T17:04:36Z
[ "python", "dbus", "avahi" ]
Creating a program to be broadcasted by avahi
1,534,655
<p>I'm trying to write a program that outputs data that can be served over a network with avahi. The documentation I've looked at seems to say I have to register the service with dbus and then connect it to avahi, but the documentation to do this is pretty sparse. Does anyone know of good documentation for it? I've be...
3
2009-10-07T22:52:11Z
1,731,577
<p>If your program is written in Java, then you can use avahi4j which provides an easy to use API to register (and browse) Bonjour services on your local network. <a href="http://avahi4j.googlecode.com" rel="nofollow">http://avahi4j.googlecode.com</a></p>
-2
2009-11-13T20:07:32Z
[ "python", "dbus", "avahi" ]
Creating a program to be broadcasted by avahi
1,534,655
<p>I'm trying to write a program that outputs data that can be served over a network with avahi. The documentation I've looked at seems to say I have to register the service with dbus and then connect it to avahi, but the documentation to do this is pretty sparse. Does anyone know of good documentation for it? I've be...
3
2009-10-07T22:52:11Z
18,104,922
<p>I realise this answer is pretty late, considering your question was asked four years ago. However, it might help others.</p> <p>The following announces a service using avahi/dbus:</p> <pre><code>import avahi import dbus from time import sleep class ServiceAnnouncer: def __init__(self, name, service, port, tx...
9
2013-08-07T13:37:46Z
[ "python", "dbus", "avahi" ]
Attribute as dict of lists using middleman table with SQLAlchemy
1,534,673
<p>My question is about SQLAlchemy but I'm having troubles explaining it in words so I figured I explain it with a simple example of what I'm trying to achieve:</p> <pre><code>parent = Table('parent', metadata, Column('parent_id', Integer, primary_key=True), Column('name', Unicode), ) parent_child = Table('par...
3
2009-10-07T22:55:49Z
1,543,559
<p>You have to define your own collection class. There are only 3 methods to implement: appender, remover, and converter. See <code>sqlalchemy.orm.collections.MappedCollection</code> as an example.</p> <p><strong>Update:</strong> Here is quick-n-dirty implementation according to your requirements:</p> <pre><code>from...
2
2009-10-09T12:50:09Z
[ "python", "sqlalchemy" ]
Calling a RPC function in a running Windows service (process) using Python
1,534,686
<p>I have Windows service (acts as a server) that I want to test using Python scripts. This service is written in C++ and exposes several RPC functions that other services consume. I want to mock those other services using my Python program and call those RPC functions from the script. This is the first stage. The seco...
0
2009-10-07T22:59:40Z
1,534,704
<p>What kind of RPC are you thinking of? If it is XML-RPC, then Python comes with the <a href="http://docs.python.org/library/simplexmlrpcserver.html" rel="nofollow">SimpleXMLRPCServer</a> module, which, well, allows you to write RPC servers in Python.</p> <p>If the remote server uses DCOM, you can use <a href="http:/...
1
2009-10-07T23:04:38Z
[ "python", "rpc", "interprocess" ]
How to remove these duplicates in a list (python)
1,534,736
<pre><code>biglist = [ {'title':'U2 Band','link':'u2.com'}, {'title':'ABC Station','link':'abc.com'}, {'title':'Live Concert by U2','link':'u2.com'} ] </code></pre> <p>I would like to remove the THIRD element inside the list...because it has "u2.com" as a duplicate. I don't want duplicate "link" el...
1
2009-10-07T23:15:44Z
1,534,749
<p>Make a new dictionary, with 'u2.com' and 'abc.com' as the keys, and your list elements as the values. The dictionary will enforce uniqueness. Something like this:</p> <pre><code>uniquelist = dict((element['link'], element) for element in reversed(biglist)) </code></pre> <p>(The reversed is there so that the first ...
3
2009-10-07T23:21:24Z
[ "python", "list" ]
How to remove these duplicates in a list (python)
1,534,736
<pre><code>biglist = [ {'title':'U2 Band','link':'u2.com'}, {'title':'ABC Station','link':'abc.com'}, {'title':'Live Concert by U2','link':'u2.com'} ] </code></pre> <p>I would like to remove the THIRD element inside the list...because it has "u2.com" as a duplicate. I don't want duplicate "link" el...
1
2009-10-07T23:15:44Z
1,534,751
<p>You can sort the list, using the <code>link</code> field of each dictionary as the sort key, then iterate through the list once and remove duplicates (or rather, create a new list with duplicates removed, as is the Python idiom), like so:</p> <pre><code># sort the list using the 'link' item as the sort key biglist....
2
2009-10-07T23:21:53Z
[ "python", "list" ]
How to remove these duplicates in a list (python)
1,534,736
<pre><code>biglist = [ {'title':'U2 Band','link':'u2.com'}, {'title':'ABC Station','link':'abc.com'}, {'title':'Live Concert by U2','link':'u2.com'} ] </code></pre> <p>I would like to remove the THIRD element inside the list...because it has "u2.com" as a duplicate. I don't want duplicate "link" el...
1
2009-10-07T23:15:44Z
1,534,787
<pre><code>biglist = \ [ {'title':'U2 Band','link':'u2.com'}, {'title':'ABC Station','link':'abc.com'}, {'title':'Live Concert by U2','link':'u2.com'} ] def dedupe(lst): d = {} for x in lst: link = x["link"] if link in d: continue d[link] = x return d.val...
1
2009-10-07T23:32:42Z
[ "python", "list" ]
How to remove these duplicates in a list (python)
1,534,736
<pre><code>biglist = [ {'title':'U2 Band','link':'u2.com'}, {'title':'ABC Station','link':'abc.com'}, {'title':'Live Concert by U2','link':'u2.com'} ] </code></pre> <p>I would like to remove the THIRD element inside the list...because it has "u2.com" as a duplicate. I don't want duplicate "link" el...
1
2009-10-07T23:15:44Z
1,535,251
<p>Probably the fastest approach, for a really big list, if you want to preserve the exact order of the items that remain, is the following...:</p> <pre><code>biglist = [ {'title':'U2 Band','link':'u2.com'}, {'title':'ABC Station','link':'abc.com'}, {'title':'Live Concert by U2','link':'u2.com'} ] kno...
8
2009-10-08T02:08:34Z
[ "python", "list" ]
How to remove these duplicates in a list (python)
1,534,736
<pre><code>biglist = [ {'title':'U2 Band','link':'u2.com'}, {'title':'ABC Station','link':'abc.com'}, {'title':'Live Concert by U2','link':'u2.com'} ] </code></pre> <p>I would like to remove the THIRD element inside the list...because it has "u2.com" as a duplicate. I don't want duplicate "link" el...
1
2009-10-07T23:15:44Z
1,535,295
<p>You can use <code>defaultdict</code> to group items by <code>link</code>, then removed duplicates if you want to.</p> <pre><code>from collections import defaultdict nodupes = defaultdict(list) for d in biglist: nodupes[d['url']].append(d['title'] </code></pre> <p>This will give you:</p> <pre><code>defaultdic...
0
2009-10-08T02:22:41Z
[ "python", "list" ]
Need a workaround: Python's select.select() doesn't work with subprocess' stdout?
1,534,825
<p>From within my master python program, I am spawning a child program with this code:</p> <pre><code>child = subprocess.Popen(..., stdout=subprocess.PIPE, stdin=subprocess.PIPE) </code></pre> <p>FWIW, the child is a PHP script which needs to communicate back and forth with the python program.</p> <p>The master pyth...
1
2009-10-07T23:44:32Z
1,534,844
<p>Unfortunately, many uses of pipes on Windows don't work as nicely as they do on Unix, and this is one of them. On Windows, the better solution is probably to have your master program spawn threads to listen to each of its subprocesses. If you know the granularity of data that you expect back from your subprocess, ...
4
2009-10-07T23:49:49Z
[ "python", "sockets", "select", "subprocess" ]
How to transform Python 3 script to Mac OS application bundle?
1,534,933
<p>Is there currently a way to create an application bundle from Py3k script? py2app uses Carbon package and therefore, as far as I understand, cannot be ported to py3k - Carbon development was terminated.</p>
1
2009-10-08T00:13:07Z
1,535,269
<p>I have not checked if that's true, but <a href="http://cx-freeze.sourceforge.net/" rel="nofollow">cx_freeze</a> 4.1 claims to support Python 3.1 (<code>cx_freeze</code> in general has long supported Mac OS X, as well as Windows and Linux, and I believe that also applies to the recent 4.1 release).</p>
0
2009-10-08T02:15:51Z
[ "python", "osx" ]
How to transform Python 3 script to Mac OS application bundle?
1,534,933
<p>Is there currently a way to create an application bundle from Py3k script? py2app uses Carbon package and therefore, as far as I understand, cannot be ported to py3k - Carbon development was terminated.</p>
1
2009-10-08T00:13:07Z
1,552,199
<p>There's always Platypus and PyObjC</p> <p><a href="http://www.sveinbjorn.org/platypus" rel="nofollow">http://www.sveinbjorn.org/platypus</a></p> <p><a href="http://pyobjc.sourceforge.net" rel="nofollow">http://pyobjc.sourceforge.net</a></p>
1
2009-10-12T00:29:04Z
[ "python", "osx" ]
How to trim a list in Python
1,534,939
<p>Suppose I have a list with X elements</p> <pre><code>[4,76,2,8,6,4,3,7,2,1...] </code></pre> <p>I'd like the first 5 elements. Unless it has less than 5 elements.</p> <pre><code>[4,76,2,8,6] </code></pre> <p>How to do that?</p>
14
2009-10-08T00:14:38Z
1,534,956
<pre><code>l = [4,76,2,8,6,4,3,7,2,1] l = l[:5] </code></pre>
0
2009-10-08T00:17:33Z
[ "python", "list" ]
How to trim a list in Python
1,534,939
<p>Suppose I have a list with X elements</p> <pre><code>[4,76,2,8,6,4,3,7,2,1...] </code></pre> <p>I'd like the first 5 elements. Unless it has less than 5 elements.</p> <pre><code>[4,76,2,8,6] </code></pre> <p>How to do that?</p>
14
2009-10-08T00:14:38Z
1,534,957
<p>You just subindex it with <code>[:5]</code> indicating that you want (up to) the first 5 elements.</p> <pre><code>&gt;&gt;&gt; [1,2,3,4,5,6,7,8][:5] [1, 2, 3, 4, 5] &gt;&gt;&gt; [1,2,3][:5] [1, 2, 3] &gt;&gt;&gt; x = [6,7,8,9,10,11,12] &gt;&gt;&gt; x[:5] [6, 7, 8, 9, 10] </code></pre> <p>Also, putting the colon on...
41
2009-10-08T00:17:36Z
[ "python", "list" ]
How to trim a list in Python
1,534,939
<p>Suppose I have a list with X elements</p> <pre><code>[4,76,2,8,6,4,3,7,2,1...] </code></pre> <p>I'd like the first 5 elements. Unless it has less than 5 elements.</p> <pre><code>[4,76,2,8,6] </code></pre> <p>How to do that?</p>
14
2009-10-08T00:14:38Z
1,534,958
<pre><code>&gt;&gt;&gt; [1,2,3,4,5,6,7,8,9][:5] [1, 2, 3, 4, 5] &gt;&gt;&gt; [1,2,3][:5] [1, 2, 3] </code></pre>
1
2009-10-08T00:17:45Z
[ "python", "list" ]
How to trim a list in Python
1,534,939
<p>Suppose I have a list with X elements</p> <pre><code>[4,76,2,8,6,4,3,7,2,1...] </code></pre> <p>I'd like the first 5 elements. Unless it has less than 5 elements.</p> <pre><code>[4,76,2,8,6] </code></pre> <p>How to do that?</p>
14
2009-10-08T00:14:38Z
4,339,929
<p>To trim a list in place without creating copies of it, use <code>del</code>:</p> <pre><code>&gt;&gt;&gt; t = [1, 2, 3, 4, 5] &gt;&gt;&gt; # delete elements starting from index 4 to the end &gt;&gt;&gt; del t[4:] &gt;&gt;&gt; t [1, 2, 3, 4] &gt;&gt;&gt; # delete elements starting from index 5 to the end &gt;&gt;&gt;...
11
2010-12-02T21:09:43Z
[ "python", "list" ]
Jump to Model/View/Controller in emacs
1,534,969
<p>Most rails modes for emacs have this kind of functionality. You are in a controller file over a function "<strong>kaboosh</strong>" in "app/controller/<strong>bla.rb</strong>" and with a keyboard shortcut you switch to "app/views/<strong>kaboosh</strong>.erb" or to app/models/<strong>bla.rb</strong>".</p> <p>A simi...
1
2009-10-08T00:22:21Z
1,535,684
<p><a href="http://www.gnu.org/software/emacs/manual/html%5Fnode/emacs/Find-Tag.html#Find-Tag" rel="nofollow">Tags</a> is set up well to jump you to the definition of a function. <code>M-.</code> will take you to the first occurrence of a function definition, <code>C-u M-.</code> will take you to the next (and one aft...
1
2009-10-08T04:48:31Z
[ "python", "emacs" ]
How do I override delete() on a model and have it still work with related deletes
1,534,986
<p>I'm having a problem because I'm deleting a Widget by using some_widget_instance.delete(). I also have a model called WidgetFile with an override delete() method so that I can delete files off my hard drive when a WidgetFile is deleted. The problem I'm having is that if I delete a Widget, and it has WidgetFiles rela...
15
2009-10-08T00:31:38Z
1,535,013
<p>Is <code>some_widget_instance</code> and instance of <code>Widget</code> or of <code>WidgetFile</code> ? Because if it is an instance of <code>Widget</code> it won't get your custom <code>delete()</code> function, which is in the <code>WidgetFile</code> class.</p>
1
2009-10-08T00:44:39Z
[ "python", "django", "django-models", "method-overloading" ]
How do I override delete() on a model and have it still work with related deletes
1,534,986
<p>I'm having a problem because I'm deleting a Widget by using some_widget_instance.delete(). I also have a model called WidgetFile with an override delete() method so that I can delete files off my hard drive when a WidgetFile is deleted. The problem I'm having is that if I delete a Widget, and it has WidgetFiles rela...
15
2009-10-08T00:31:38Z
1,535,032
<p>This seems only be sense-full if one Widget is connected to one WidgetFile exactly. In that case you should use a <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#one-to-one-relationships" rel="nofollow">OneToOneField</a></p> <p>from <a href="http://www.djangoproject.com/documentation/models/one%5Fto...
1
2009-10-08T00:52:17Z
[ "python", "django", "django-models", "method-overloading" ]
How do I override delete() on a model and have it still work with related deletes
1,534,986
<p>I'm having a problem because I'm deleting a Widget by using some_widget_instance.delete(). I also have a model called WidgetFile with an override delete() method so that I can delete files off my hard drive when a WidgetFile is deleted. The problem I'm having is that if I delete a Widget, and it has WidgetFiles rela...
15
2009-10-08T00:31:38Z
1,535,066
<p>Just to throw in a possible way around this problem: <a href="http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_delete" rel="nofollow">pre-delete</a> <a href="http://docs.djangoproject.com/en/dev/topics/signals/" rel="nofollow">signal</a>. (Not in any way implying there's no actual solut...
1
2009-10-08T01:04:50Z
[ "python", "django", "django-models", "method-overloading" ]
How do I override delete() on a model and have it still work with related deletes
1,534,986
<p>I'm having a problem because I'm deleting a Widget by using some_widget_instance.delete(). I also have a model called WidgetFile with an override delete() method so that I can delete files off my hard drive when a WidgetFile is deleted. The problem I'm having is that if I delete a Widget, and it has WidgetFiles rela...
15
2009-10-08T00:31:38Z
1,535,451
<p>Using <code>clear()</code> prior to deleting, removes all objects from the related object set.</p> <p>see <a href="http://docs.djangoproject.com/en/dev/topics/db/queries/#following-relationships-backward" rel="nofollow">django-following-relationships-backward</a></p> <p>example:</p> <pre><code>group.link_set.clea...
2
2009-10-08T03:21:39Z
[ "python", "django", "django-models", "method-overloading" ]
How do I override delete() on a model and have it still work with related deletes
1,534,986
<p>I'm having a problem because I'm deleting a Widget by using some_widget_instance.delete(). I also have a model called WidgetFile with an override delete() method so that I can delete files off my hard drive when a WidgetFile is deleted. The problem I'm having is that if I delete a Widget, and it has WidgetFiles rela...
15
2009-10-08T00:31:38Z
1,539,182
<p>I figured it out. I just put this on that Widget model:</p> <pre><code>def delete(self): files = WidgetFile.objects.filter(widget=self) if files: for file in files: file.delete() super(Widget, self).delete() </code></pre> <p>This triggered the necessary delete() method on each of th...
19
2009-10-08T17:05:11Z
[ "python", "django", "django-models", "method-overloading" ]
How do I override delete() on a model and have it still work with related deletes
1,534,986
<p>I'm having a problem because I'm deleting a Widget by using some_widget_instance.delete(). I also have a model called WidgetFile with an override delete() method so that I can delete files off my hard drive when a WidgetFile is deleted. The problem I'm having is that if I delete a Widget, and it has WidgetFiles rela...
15
2009-10-08T00:31:38Z
6,121,651
<p>It should look like described on the <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods" rel="nofollow">django</a> site:</p> <pre><code>class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() def save(self, *args, **...
1
2011-05-25T08:35:25Z
[ "python", "django", "django-models", "method-overloading" ]
How do I override delete() on a model and have it still work with related deletes
1,534,986
<p>I'm having a problem because I'm deleting a Widget by using some_widget_instance.delete(). I also have a model called WidgetFile with an override delete() method so that I can delete files off my hard drive when a WidgetFile is deleted. The problem I'm having is that if I delete a Widget, and it has WidgetFiles rela...
15
2009-10-08T00:31:38Z
12,678,428
<p>I'm doing the same thing and noticed a nugget in the Django docs that you should think about.</p> <p><a href="https://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods">Overriding predefined model methods</a></p> <blockquote> <p>Overriding Delete Note that the delete() method for an obje...
41
2012-10-01T17:55:56Z
[ "python", "django", "django-models", "method-overloading" ]
How do I override delete() on a model and have it still work with related deletes
1,534,986
<p>I'm having a problem because I'm deleting a Widget by using some_widget_instance.delete(). I also have a model called WidgetFile with an override delete() method so that I can delete files off my hard drive when a WidgetFile is deleted. The problem I'm having is that if I delete a Widget, and it has WidgetFiles rela...
15
2009-10-08T00:31:38Z
36,510,139
<p>From Django 1.9, if You would just define <code>on_delete=models.CASCADE</code> for field, it will remove all related objects on delete.</p>
0
2016-04-08T22:11:11Z
[ "python", "django", "django-models", "method-overloading" ]
How to write an efficient hit counter for websites
1,535,261
<p>I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. </p> <p>I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinki...
5
2009-10-08T02:12:09Z
1,535,302
<p>Well if you happen to go the PHP route you could use an <a href="http://us.php.net/manual/en/ref.sqlite.php" rel="nofollow">SQLite</a> database, however MySQL is a perfectly reasonable way to store that info and usually (at least from the ones I've seen) is how it is done.</p> <p>If you didn't want to store IP addr...
-1
2009-10-08T02:25:42Z
[ "php", "python", "mysql", "tracking" ]
How to write an efficient hit counter for websites
1,535,261
<p>I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. </p> <p>I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinki...
5
2009-10-08T02:12:09Z
1,535,311
<p>A fascinating subject. Incrementing a counter, simple as it may be, just <em>has</em> to be a transaction... meaning, it can lock out the whole DB for longer than makes sense!-) It can easily be the bottleneck for the whole system.</p> <p>If you need rigorously exact counts but don't need them to be instantly up-...
7
2009-10-08T02:28:22Z
[ "php", "python", "mysql", "tracking" ]
How to write an efficient hit counter for websites
1,535,261
<p>I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. </p> <p>I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinki...
5
2009-10-08T02:12:09Z
1,535,408
<p>There are two really easy ways:</p> <ol> <li>Parse it out of your web logs in batch.</li> <li>Run the hits through <a href="http://kr.github.com/beanstalkd/" rel="nofollow">beanstalkd</a> or <a href="http://gearman.org/" rel="nofollow">gearmand</a> and have a worker do the hard stuff in a controlled way.</li> </ol>...
2
2009-10-08T03:06:30Z
[ "php", "python", "mysql", "tracking" ]
How to write an efficient hit counter for websites
1,535,261
<p>I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. </p> <p>I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinki...
5
2009-10-08T02:12:09Z
1,535,419
<p>Not sure if it's up your alley, but AppEngine is a pretty nice platform to build on. Some sample code you can use to build a counter using their DataStore and transactions is described here: <a href="http://code.google.com/appengine/docs/python/datastore/transactions.html" rel="nofollow">http://code.google.com/appen...
0
2009-10-08T03:09:43Z
[ "php", "python", "mysql", "tracking" ]
How to write an efficient hit counter for websites
1,535,261
<p>I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. </p> <p>I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinki...
5
2009-10-08T02:12:09Z
1,535,794
<p>If accuracy is important, you can do it slightly slower with MySql... create a HEAP / Memory table to store your counter values. These a in-memory tables that are blazingly fast. You can write the data into a normal table at intervals. </p> <p>Based on the app engine ideas, you could use memcache as a temporary sto...
1
2009-10-08T05:34:53Z
[ "php", "python", "mysql", "tracking" ]
How to write an efficient hit counter for websites
1,535,261
<p>I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. </p> <p>I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinki...
5
2009-10-08T02:12:09Z
1,536,049
<p>You could take your webserver's <strong>Access log</strong> (Apache: access.log) and evaluate it time and again (cronjob) in case you do not need to have the data at hand at the exact moment in time when someone visits your site.</p> <p>Usually, the access.log is generated anyway and contains the requested resource...
4
2009-10-08T06:59:13Z
[ "php", "python", "mysql", "tracking" ]
How to write an efficient hit counter for websites
1,535,261
<p>I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. </p> <p>I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinki...
5
2009-10-08T02:12:09Z
1,900,253
<p>You can use <a href="http://code.google.com/p/redis/" rel="nofollow">Redis</a> - it`s very fast key-value storage with support for atomic increments. If need will arise -- counts data could be splitted between multiple servers easily.</p>
0
2009-12-14T11:05:42Z
[ "php", "python", "mysql", "tracking" ]
How to write an efficient hit counter for websites
1,535,261
<p>I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. </p> <p>I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinki...
5
2009-10-08T02:12:09Z
1,900,337
<p>I've done something very similar, on a similar scale (multiple servers, hundreds of domains, several thousand hits per hour) and log file analysis was definitely the way to go. (It also checked hit rates, weighted them by file type, and blacklisted IP addresses at the firewall if they were making too many requests;...
0
2009-12-14T11:21:55Z
[ "php", "python", "mysql", "tracking" ]
How to write an efficient hit counter for websites
1,535,261
<p>I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. </p> <p>I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinki...
5
2009-10-08T02:12:09Z
2,027,895
<p>Without a doubt, Redis is perfect for this problem. It requires about a minute to setup and install, supports atomic increments, is incredibly fast, has client libs for python and php (and many other languages), is durable (snapshots, journal, replication). </p> <p>Store each counter to its own key. Then simply</p>...
2
2010-01-08T13:41:57Z
[ "php", "python", "mysql", "tracking" ]
Python instance method making multiple instance method calls
1,535,313
<p>Here is some snippet code. I have tested the methods listed and they work correctly, yet when I run and test this method (<code>countLOC</code>) it only seems to initialize the first variable that has an instance method call (<code>i = self.countBlankLines()</code>). Anyone know the obvious reason I'm obviously miss...
0
2009-10-08T02:29:40Z
1,535,388
<p>If local variables were not initialized (impossible given your code!) they wouldn't be 0 -- rather, you'd get a NameError exception when you try to use them. It's 100% certain that those other method calls (except the first one) are returning 0 (or numbers totaling to 0 in the expression).</p> <p>Hard to guess, no...
5
2009-10-08T03:00:22Z
[ "python", "methods", "method-call" ]
How to print a class or objects of class using print()?
1,535,327
<p>I am learning the ropes in Python. When I try to print an object of class <strong><code>Foobar</code></strong> using the <strong><code>print()</code></strong> function, I get an output like this:</p> <pre><code>&lt;__main__.Foobar instance at 0x7ff2a18c&gt; </code></pre> <p>Is there a way I can set the <em>printin...
236
2009-10-08T02:35:30Z
1,535,336
<pre><code>&gt;&gt;&gt; class Test: ... def __repr__(self): ... return "Test()" ... def __str__(self): ... return "member of Test" ... &gt;&gt;&gt; t = Test() &gt;&gt;&gt; t Test() &gt;&gt;&gt; print t member of Test </code></pre> <p>The <code>__str__</code> method is what happens when you pri...
247
2009-10-08T02:39:35Z
[ "python", "class", "printing", "object" ]
How to print a class or objects of class using print()?
1,535,327
<p>I am learning the ropes in Python. When I try to print an object of class <strong><code>Foobar</code></strong> using the <strong><code>print()</code></strong> function, I get an output like this:</p> <pre><code>&lt;__main__.Foobar instance at 0x7ff2a18c&gt; </code></pre> <p>Is there a way I can set the <em>printin...
236
2009-10-08T02:35:30Z
1,535,375
<p>As Chris Lutz mentioned, this is defined by the <code>__repr__</code> method in your class.</p> <p>From the documentation of <a href="http://docs.python.org/library/functions.html#repr"><code>repr()</code></a>:</p> <blockquote> <p>For many types, this function makes an attempt to return a string that would yield...
66
2009-10-08T02:55:04Z
[ "python", "class", "printing", "object" ]
How to print a class or objects of class using print()?
1,535,327
<p>I am learning the ropes in Python. When I try to print an object of class <strong><code>Foobar</code></strong> using the <strong><code>print()</code></strong> function, I get an output like this:</p> <pre><code>&lt;__main__.Foobar instance at 0x7ff2a18c&gt; </code></pre> <p>Is there a way I can set the <em>printin...
236
2009-10-08T02:35:30Z
13,971,187
<p>Just to add my two cents to @dbr's answer, following is an example of how to implement this sentence from the official documentation he's cited:</p> <blockquote> <p>"[...] to return a string that would yield an object with the same value when passed to eval(), [...]"</p> </blockquote> <p>Given this class definit...
8
2012-12-20T11:27:39Z
[ "python", "class", "printing", "object" ]
How to print a class or objects of class using print()?
1,535,327
<p>I am learning the ropes in Python. When I try to print an object of class <strong><code>Foobar</code></strong> using the <strong><code>print()</code></strong> function, I get an output like this:</p> <pre><code>&lt;__main__.Foobar instance at 0x7ff2a18c&gt; </code></pre> <p>Is there a way I can set the <em>printin...
236
2009-10-08T02:35:30Z
14,354,579
<p>You need to use <code>__repr__</code>. This is a standard function like <code>__init__</code>. For example:</p> <pre><code>class Foobar(): """This will create Foobar type object.""" def __init__(self): print "Foobar object is created." def __repr__(self): return "Type what do you want ...
9
2013-01-16T09:04:00Z
[ "python", "class", "printing", "object" ]
How to print a class or objects of class using print()?
1,535,327
<p>I am learning the ropes in Python. When I try to print an object of class <strong><code>Foobar</code></strong> using the <strong><code>print()</code></strong> function, I get an output like this:</p> <pre><code>&lt;__main__.Foobar instance at 0x7ff2a18c&gt; </code></pre> <p>Is there a way I can set the <em>printin...
236
2009-10-08T02:35:30Z
31,800,938
<p>There are already a lot of answers in this thread but none of them particularly helped me, I had to work it out myself, so I hope this one is a little more informative.</p> <p>You just have to make sure you have parentheses at the end of your class, e.g:</p> <pre><code>print(class()) </code></pre> <p>Here's an ex...
1
2015-08-04T04:52:21Z
[ "python", "class", "printing", "object" ]
How to print a class or objects of class using print()?
1,535,327
<p>I am learning the ropes in Python. When I try to print an object of class <strong><code>Foobar</code></strong> using the <strong><code>print()</code></strong> function, I get an output like this:</p> <pre><code>&lt;__main__.Foobar instance at 0x7ff2a18c&gt; </code></pre> <p>Is there a way I can set the <em>printin...
236
2009-10-08T02:35:30Z
32,635,523
<p>A generic way that can be applied to any class without specific formatting could be done as follows:</p> <pre><code>class Element: def __init__(self, name, symbol, number): self.name = name self.symbol = symbol self.number = number def __str__(self): return str(self.__class_...
3
2015-09-17T16:35:05Z
[ "python", "class", "printing", "object" ]
How to print a class or objects of class using print()?
1,535,327
<p>I am learning the ropes in Python. When I try to print an object of class <strong><code>Foobar</code></strong> using the <strong><code>print()</code></strong> function, I get an output like this:</p> <pre><code>&lt;__main__.Foobar instance at 0x7ff2a18c&gt; </code></pre> <p>Is there a way I can set the <em>printin...
236
2009-10-08T02:35:30Z
37,349,332
<p>For Python 3:</p> <p>If the specific format isn't important (e.g. for debugging) just inherit from the Printable class below. No need to write code for every object. </p> <p>Inspired by <a href="http://stackoverflow.com/a/23851642/635906">this</a> answer</p> <pre><code>class Printable: def __repr__(self): ...
2
2016-05-20T14:26:51Z
[ "python", "class", "printing", "object" ]
Resource scheduling application
1,535,391
<p>I'm trying to implement an application that coordinates multiple users who are scheduling exclusive resources. The schedule data must maintain strong consistency over a network with a single master node. The scheduled resources could be anything from a conference room to a worker on a job site.</p> <p>We assume the...
1
2009-10-08T03:01:12Z
1,535,554
<p>You'll want to track just start and end times for each exclusionary resource. The data storage in your problem is actually the easy part - the hard(er) part is crafting queries to look for conflicts in time intervals.</p> <p>If my logic is correct after being up for 21 hours, the following psuedo-code should check...
3
2009-10-08T04:00:23Z
[ "python", "google-app-engine", "resources", "scheduling", "schedule" ]
Resource scheduling application
1,535,391
<p>I'm trying to implement an application that coordinates multiple users who are scheduling exclusive resources. The schedule data must maintain strong consistency over a network with a single master node. The scheduled resources could be anything from a conference room to a worker on a job site.</p> <p>We assume the...
1
2009-10-08T03:01:12Z
2,036,990
<p>To automatically optimize a timetable of a school or university (or even other problems) take a look at the following Java tools: </p> <p><a href="http://timefinder.sourceforge.net/" rel="nofollow">TimeFinder</a>, <a href="http://www.unitime.org/index.php?tab=1" rel="nofollow">UniTime</a> or <a href="http://www.jbo...
1
2010-01-10T12:26:39Z
[ "python", "google-app-engine", "resources", "scheduling", "schedule" ]
Python Documentation Refers You To Docs for "the C function wait." Where is that?
1,535,564
<p>There's multiple places in the Python documentation where it refers you to the C function "wait." For instance: "The exit status for the command can be interpreted according to the rules for the C function wait," in the <a href="http://docs.python.org/library/commands.html" rel="nofollow">commands</a> and <a href="h...
4
2009-10-08T04:05:04Z
1,535,568
<p><code>$ man 2 wait</code> (on Linux and Unix systems).</p>
4
2009-10-08T04:06:18Z
[ "python", "c", "documentation", "subprocess" ]
Python Documentation Refers You To Docs for "the C function wait." Where is that?
1,535,564
<p>There's multiple places in the Python documentation where it refers you to the C function "wait." For instance: "The exit status for the command can be interpreted according to the rules for the C function wait," in the <a href="http://docs.python.org/library/commands.html" rel="nofollow">commands</a> and <a href="h...
4
2009-10-08T04:05:04Z
1,535,574
<p>A search for <code>man wait</code> gives <a href="http://www.manpagez.com/man/2/wait/" rel="nofollow">this</a> as the top hit -- <code>man</code> is the Unix command for getting the manual page of something, so a search for <code>man foobar</code> is likely to reveal manual pages for <code>foobar</code> that happen ...
3
2009-10-08T04:07:31Z
[ "python", "c", "documentation", "subprocess" ]
Python Documentation Refers You To Docs for "the C function wait." Where is that?
1,535,564
<p>There's multiple places in the Python documentation where it refers you to the C function "wait." For instance: "The exit status for the command can be interpreted according to the rules for the C function wait," in the <a href="http://docs.python.org/library/commands.html" rel="nofollow">commands</a> and <a href="h...
4
2009-10-08T04:05:04Z
1,535,577
<p><a href="http://www.manpagez.com/man/2/wait/" rel="nofollow">http://www.manpagez.com/man/2/wait/</a></p> <p>(and at many other sources of <code>man</code> pages on the Internet).</p>
1
2009-10-08T04:08:44Z
[ "python", "c", "documentation", "subprocess" ]
Python Documentation Refers You To Docs for "the C function wait." Where is that?
1,535,564
<p>There's multiple places in the Python documentation where it refers you to the C function "wait." For instance: "The exit status for the command can be interpreted according to the rules for the C function wait," in the <a href="http://docs.python.org/library/commands.html" rel="nofollow">commands</a> and <a href="h...
4
2009-10-08T04:05:04Z
1,535,583
<p>Here are some online pages for Linux...</p> <p><a href="http://manpages.ubuntu.com/manpages/jaunty/en/man2/wait.2.html" rel="nofollow">http://manpages.ubuntu.com/manpages/jaunty/en/man2/wait.2.html</a></p> <p>Sometimes the BSD pages have fewer extensions. They aren't always closer to pure posix but they are someti...
4
2009-10-08T04:11:09Z
[ "python", "c", "documentation", "subprocess" ]
How to interpret status code in Python commands.getstatusoutput()
1,535,672
<p>In a <a href="http://stackoverflow.com/questions/1535564">related question</a>, I asked where to find the documentation for the C function "wait." This was an attempt to figure out return codes for the commands.getstatusoutput() module. Stackoverflow came through, but the documentation didn't help. Here's what puzzl...
4
2009-10-08T04:43:50Z
1,535,675
<p>Wow. The insight that it was multiplying by 256 got me there. Searching for "python commands +256" got me to a <a href="http://www.doughellmann.com/PyMOTW/commands/index.html" rel="nofollow">Python Module Of The Week</a> article which explains what's going on.</p> <p>Here's a snippet from that page:</p> <blockquot...
3
2009-10-08T04:44:39Z
[ "python", "documentation", "subprocess", "command", "exit-code" ]
How to interpret status code in Python commands.getstatusoutput()
1,535,672
<p>In a <a href="http://stackoverflow.com/questions/1535564">related question</a>, I asked where to find the documentation for the C function "wait." This was an attempt to figure out return codes for the commands.getstatusoutput() module. Stackoverflow came through, but the documentation didn't help. Here's what puzzl...
4
2009-10-08T04:43:50Z
1,535,695
<p>Looking at <code>commands.py</code>:</p> <pre><code>def getstatusoutput(cmd): """Return (status, output) of executing cmd in a shell.""" import os pipe = os.popen('{ ' + cmd + '; } 2&gt;&amp;1', 'r') text = pipe.read() sts = pipe.close() if sts is None: sts = 0 if text[-1:] == '\n': text...
4
2009-10-08T04:51:46Z
[ "python", "documentation", "subprocess", "command", "exit-code" ]
How to interpret status code in Python commands.getstatusoutput()
1,535,672
<p>In a <a href="http://stackoverflow.com/questions/1535564">related question</a>, I asked where to find the documentation for the C function "wait." This was an attempt to figure out return codes for the commands.getstatusoutput() module. Stackoverflow came through, but the documentation didn't help. Here's what puzzl...
4
2009-10-08T04:43:50Z
1,535,703
<p>There is a set of functions in <code>os</code> module (<code>os.WIFCONTINUED</code>, <code>os.WIFSTOPPED</code>, <code>os.WTERMSIG</code>, <code>os.WCOREDUMP</code>, <code>os.WIFEXITED</code>, <code>os.WEXITSTATUS</code>, <code>os.WIFSIGNALED</code>, <code>os.WSTOPSIG</code>), which correspond to macros from <a href...
8
2009-10-08T04:54:19Z
[ "python", "documentation", "subprocess", "command", "exit-code" ]
How to interpret status code in Python commands.getstatusoutput()
1,535,672
<p>In a <a href="http://stackoverflow.com/questions/1535564">related question</a>, I asked where to find the documentation for the C function "wait." This was an attempt to figure out return codes for the commands.getstatusoutput() module. Stackoverflow came through, but the documentation didn't help. Here's what puzzl...
4
2009-10-08T04:43:50Z
1,675,237
<p>I think the code detection is incorrect.</p> <p>"If a core file was produced, the high bit of the low byte is set." means 128.</p> <p>so I think the core line should be</p> <pre><code>print 'Core? : %s' % bool(status &amp; 128) </code></pre>
0
2009-11-04T17:04:50Z
[ "python", "documentation", "subprocess", "command", "exit-code" ]
Python not a standardized language?
1,535,702
<p>I stumbled upon this 'list of programming' languages and found that popular languages like Python are not standardized? Why is that, and what does 'Standardized' mean anyway?</p>
8
2009-10-08T04:54:18Z
1,535,714
<p>Standardized means there exists a specification for the language (a "standard"). Java, for example, has a specification. Perl 5 does not (the source code is the "standard") but Perl 6 will.</p> <p>See <a href="http://stackoverflow.com/questions/1094961/is-there-a-python-language-specification">Is there a Python lan...
2
2009-10-08T04:57:40Z
[ "php", "python", "standardized" ]
Python not a standardized language?
1,535,702
<p>I stumbled upon this 'list of programming' languages and found that popular languages like Python are not standardized? Why is that, and what does 'Standardized' mean anyway?</p>
8
2009-10-08T04:54:18Z
1,535,727
<p>"Standardized" means that the language has a formal, approved standard, generally written by ISO or ANSI or ECMA. Many modern open-source languages, like Python, Perl, and Ruby, are not formally standardized by an external body, and instead have a <em>de-facto</em> standard: whatever the original working implementat...
28
2009-10-08T05:04:44Z
[ "php", "python", "standardized" ]
Python not a standardized language?
1,535,702
<p>I stumbled upon this 'list of programming' languages and found that popular languages like Python are not standardized? Why is that, and what does 'Standardized' mean anyway?</p>
8
2009-10-08T04:54:18Z
1,537,045
<p>There are "standards" and there are "standards".</p> <p>Most folks mostly mean that a standard is passed by a standards-writing organization: ISO, ECMA, EIA, etc. Lawyers call these De Jure Standards. There's the force of law.</p> <p>Further, there are "De Facto Standards".</p> <p>Some folks, also, corrupt the...
3
2009-10-08T10:51:13Z
[ "php", "python", "standardized" ]
Customizing time zones for Django users using geography
1,536,392
<p>I am working on a Django app that needs to report the local time relative to the user. I would prefer not ask the user to input the time zone directly because I have his address stored in the database. I am only considering American users. Since most states in the USA are in only one time zone it is possible to c...
2
2009-10-08T08:22:34Z
1,536,426
<p>I am not sure such a library exists. Every state in the USA doesn't have only one time zone.</p> <p>Have a look here: <a href="http://en.wikipedia.org/wiki/List%5Fof%5FU.S.%5Fstates%5Fby%5Ftime%5Fzone" rel="nofollow">List of U.S. states by time zone</a></p> <p>Many states have more than one.</p> <p>I guess you co...
3
2009-10-08T08:30:07Z
[ "python", "django", "timezone" ]
Customizing time zones for Django users using geography
1,536,392
<p>I am working on a Django app that needs to report the local time relative to the user. I would prefer not ask the user to input the time zone directly because I have his address stored in the database. I am only considering American users. Since most states in the USA are in only one time zone it is possible to c...
2
2009-10-08T08:22:34Z
1,536,531
<p>I'm not sure how reliable it is, but the HTTP request - encapsulated in Django in the <code>request</code> object - has a <code>TZ</code> header which shows the client's time zone. </p> <pre><code>&gt;&gt;&gt; request.META['TZ'] 'Europe/London' </code></pre>
0
2009-10-08T08:54:43Z
[ "python", "django", "timezone" ]
Customizing time zones for Django users using geography
1,536,392
<p>I am working on a Django app that needs to report the local time relative to the user. I would prefer not ask the user to input the time zone directly because I have his address stored in the database. I am only considering American users. Since most states in the USA are in only one time zone it is possible to c...
2
2009-10-08T08:22:34Z
1,537,346
<p>Like Andre Miller pointed out, time zones are not tied to state. You're probably better off using the zipcode, because a few cities cross timezone lines. </p> <p>There are a few databases you can purchase that that map zipcodes to time zones. Here's one I found that also includes the UTC shift and Daylight Savings:...
0
2009-10-08T11:52:16Z
[ "python", "django", "timezone" ]
Turbogears 2.0 with Python 2.6
1,536,437
<p>I've tried to install TurboGears 2.0 with Python 2.6 on both Windows 7 and Windows XP, but both give the same error:</p> <pre><code>File "D:\PythonProjects\tg2env\Scripts\paster-script.py", line 8, in &lt;module&gt; load_entry_point('pastescript==1.7.3', 'console_scripts', 'paster')() File "D:\PythonProjects\tg2env...
0
2009-10-08T08:32:23Z
1,536,482
<p>did you run python setup.py develop? (as the error message says)</p> <blockquote> <p>I was using virtualenv as recommended in the documentation, but the develop command installs the packages in the original python folder.</p> </blockquote> <p>Okay, that is the cause of your problems. I'm wondering about your com...
1
2009-10-08T08:44:16Z
[ "python", "turbogears" ]
Turbogears 2.0 with Python 2.6
1,536,437
<p>I've tried to install TurboGears 2.0 with Python 2.6 on both Windows 7 and Windows XP, but both give the same error:</p> <pre><code>File "D:\PythonProjects\tg2env\Scripts\paster-script.py", line 8, in &lt;module&gt; load_entry_point('pastescript==1.7.3', 'console_scripts', 'paster')() File "D:\PythonProjects\tg2env...
0
2009-10-08T08:32:23Z
2,374,272
<p>I had the same problem. I was finally able to get it to work. I closed the command window. i opened a new commandwindow and activated the virtualenv by executing the appropriate activate.bat. Afterwards I reexecuted "setup.py develop" and finally i was able to start paster serve as documented in the Turbogears wiki....
0
2010-03-03T19:23:29Z
[ "python", "turbogears" ]
Turbogears 2.0 with Python 2.6
1,536,437
<p>I've tried to install TurboGears 2.0 with Python 2.6 on both Windows 7 and Windows XP, but both give the same error:</p> <pre><code>File "D:\PythonProjects\tg2env\Scripts\paster-script.py", line 8, in &lt;module&gt; load_entry_point('pastescript==1.7.3', 'console_scripts', 'paster')() File "D:\PythonProjects\tg2env...
0
2009-10-08T08:32:23Z
2,837,420
<p>The key is to run <strong>python</strong> setup.py development.ini. If you just run setup.py development.ini, it will use the installed python, and will not litter to your virtualenv</p>
0
2010-05-14T20:32:44Z
[ "python", "turbogears" ]
How to do email-confirmation after registration in Django?
1,536,766
<p>I am using Django's authentication system. Is there an easy way to do this?</p>
2
2009-10-08T09:54:50Z
1,536,774
<p>Have a look at James Bennett's <a href="http://bitbucket.org/ubernostrum/django-registration/wiki/Home" rel="nofollow">django-registration</a> project.</p>
8
2009-10-08T09:56:18Z
[ "python", "django" ]
Can't Delete Function Call
1,536,890
<p>This question is just out of general curiosity. I've just noticed it when working on my current project (surprisingly I haven't came across before today).</p> <p>Take this code:</p> <pre><code>List = ["hi","stack","over","flow","how","you","doing"] del List(len(List)-1) </code></pre> <p>Error:</p> <pre><code>Syn...
0
2009-10-08T10:19:21Z
1,536,903
<p>You are calling a function <code>List()</code> when you should be indexing a list, <code>List[]</code>.</p> <p>In Python, Round parenthesis, <code>()</code>, are used to call functions, while square brackets, <code>[]</code> are used to index lists and other sequences.</p> <p>Try:</p> <pre><code>del List[len(List...
5
2009-10-08T10:21:37Z
[ "python", "syntax-error" ]
Can't Delete Function Call
1,536,890
<p>This question is just out of general curiosity. I've just noticed it when working on my current project (surprisingly I haven't came across before today).</p> <p>Take this code:</p> <pre><code>List = ["hi","stack","over","flow","how","you","doing"] del List(len(List)-1) </code></pre> <p>Error:</p> <pre><code>Syn...
0
2009-10-08T10:19:21Z
1,536,920
<p>You meant to delete the last element of the list, not somehow call <code>List</code> as a function:</p> <pre><code>del List[len(List)-1] </code></pre> <p>Python's <code>del</code> statement must take specific forms like deleting a variable, list[element], or object.property. These forms can be nested deeply, but m...
11
2009-10-08T10:23:16Z
[ "python", "syntax-error" ]
Can't Delete Function Call
1,536,890
<p>This question is just out of general curiosity. I've just noticed it when working on my current project (surprisingly I haven't came across before today).</p> <p>Take this code:</p> <pre><code>List = ["hi","stack","over","flow","how","you","doing"] del List(len(List)-1) </code></pre> <p>Error:</p> <pre><code>Syn...
0
2009-10-08T10:19:21Z
1,536,922
<p>You are allowed. However, you are using the wrong syntax. Correct syntax is:</p> <pre><code>del List[-1] </code></pre> <p>Notice that the "len(List) part is useless.</p>
1
2009-10-08T10:23:55Z
[ "python", "syntax-error" ]
Building universal binaries on Mac - Forcing single compiler child process
1,536,897
<p>Cheers,</p> <p>at company, we're creating a port of our games, and we need to compile <a href="http://www.pythonogre.com/" rel="nofollow">PythonOgre</a>, a wrapper of Ogre3d for Python. This is an enormous chunk of code, particularly the generated wrapper code. We have a Mac Mini with 1GB RAM.</p> <p>We've built i...
1
2009-10-08T10:20:48Z
1,537,300
<p>I've checked the source of Apple's GCC driver (the one that supports those <code>-arch</code> options and runs the children processes), and there's no option or environment variable that you can choose.</p> <p>The only options I see left to you are:</p> <ul> <li>download the Apple driver (e.g. from <a href="http:/...
2
2009-10-08T11:40:43Z
[ "python", "osx", "gcc", "multicore" ]
Building universal binaries on Mac - Forcing single compiler child process
1,536,897
<p>Cheers,</p> <p>at company, we're creating a port of our games, and we need to compile <a href="http://www.pythonogre.com/" rel="nofollow">PythonOgre</a>, a wrapper of Ogre3d for Python. This is an enormous chunk of code, particularly the generated wrapper code. We have a Mac Mini with 1GB RAM.</p> <p>We've built i...
1
2009-10-08T10:20:48Z
1,541,551
<p>Will just turning off one core do? Apparently, installing the Apple Developer Tools (XCode et al.) gives you a Processor system preference pane, allowing you to turn off one core. I was trying to test this, but the XCode install failed for some reason...</p> <p>EDIT: I know this was a while ago, but I just thought ...
1
2009-10-09T02:39:45Z
[ "python", "osx", "gcc", "multicore" ]
Creating Title / Slug based on PK ID
1,537,149
<p>What would be the generic way to create record title and slub based on the ID? I am working with django-photologue here. I want to save a record with title and slug based on the PK. The generic problem is that I can't get the PK until the record is saved into database. On the other side, I can't save it without titl...
1
2009-10-08T11:14:28Z
1,537,172
<p>Normally you don't use the primary key at all. If your concern is just to automatically generate unique slugs (which is the only reason I can see to do what you're trying to do), then you want an <code>AutoSlugField</code>, which creates a unique slug by increasing an appended number on the slug until it is unique.<...
1
2009-10-08T11:18:52Z
[ "python", "django", "django-profiles" ]
Creating Title / Slug based on PK ID
1,537,149
<p>What would be the generic way to create record title and slub based on the ID? I am working with django-photologue here. I want to save a record with title and slug based on the PK. The generic problem is that I can't get the PK until the record is saved into database. On the other side, I can't save it without titl...
1
2009-10-08T11:14:28Z
1,537,448
<p>To name the file based on record ID you have several options:</p> <p>a) Try to predict ID:</p> <pre><code>max_pk = self.__class__.objects.aggregate(max_pk=Max('pk'))['max_pk'] or 0 predicted_id = max_pk+1 </code></pre> <p>b) Rename file in post_save when ID is known.</p> <p>You can also use md5 hash or random st...
0
2009-10-08T12:15:39Z
[ "python", "django", "django-profiles" ]
Creating Title / Slug based on PK ID
1,537,149
<p>What would be the generic way to create record title and slub based on the ID? I am working with django-photologue here. I want to save a record with title and slug based on the PK. The generic problem is that I can't get the PK until the record is saved into database. On the other side, I can't save it without titl...
1
2009-10-08T11:14:28Z
1,537,522
<p>If you URIs are supposed to look like <code>"example.com/${obj.id}-${sluggify( obj.title )}"</code> then <em>generate these uri when you use them</em>. This uri contains no data that's not in the DB already, so don't add it again. The slug's sole purpose is making url's look nicer to people and search engines.</p> ...
1
2009-10-08T12:34:04Z
[ "python", "django", "django-profiles" ]
Reading from sockets and download speed
1,537,161
<p>Just for fun, I develop a download manager and I'd like to know if reading a large stack of data (i.e. 80 or 100KB) from a socket over the net makes the download speed higher, instead of reading 4KB for each loop iteration?</p> <p>(My average download speed is 200KBPS when I download a file with firefox for example...
0
2009-10-08T11:16:47Z
1,537,199
<p>The answer is <strong>NO</strong>.</p> <p>your network transfer rate (200kbps) indicates that buffering 4k or 8k or 200k will hardly make a difference. The time spent between reads is too small. The bottleneck seems to be your transfer rate anyway.</p> <p>Let's try with a <a href="http://itc.conversationsnetwork.o...
2
2009-10-08T11:24:28Z
[ "python", "sockets" ]
Variables inside and outside of a class __init__() function
1,537,202
<p>I'm trying to understand, is there any difference at all between these classes besides the name? Does it make any difference if I use or don't use the __init__() function in declaring the variable "value"?</p> <pre><code>class WithClass (): def __init__(self): self.value = "Bob" def my_func(self): ...
73
2009-10-08T11:25:27Z
1,537,226
<p>Variable set outside <code>__init__</code> belong to the class. They're shared by all instances. </p> <p>Variables created inside <code>__init__</code> (and all other method functions) and prefaced with <code>self.</code> belong to the object instance. </p>
87
2009-10-08T11:29:15Z
[ "python" ]
Variables inside and outside of a class __init__() function
1,537,202
<p>I'm trying to understand, is there any difference at all between these classes besides the name? Does it make any difference if I use or don't use the __init__() function in declaring the variable "value"?</p> <pre><code>class WithClass (): def __init__(self): self.value = "Bob" def my_func(self): ...
73
2009-10-08T11:25:27Z
15,247,457
<p>further to S.Lott's reply, class variables get passed to metaclass <strong>new</strong> method and can be accessed through the dictionary when a metaclass is defined. So, class variables can be accessed even before classes are created and instantiated.</p> <p>for example:</p> <pre><code>class meta(type): def _...
3
2013-03-06T12:32:06Z
[ "python" ]
Variables inside and outside of a class __init__() function
1,537,202
<p>I'm trying to understand, is there any difference at all between these classes besides the name? Does it make any difference if I use or don't use the __init__() function in declaring the variable "value"?</p> <pre><code>class WithClass (): def __init__(self): self.value = "Bob" def my_func(self): ...
73
2009-10-08T11:25:27Z
26,529,574
<p><strong>Without Self</strong></p> <p>Create some objects:</p> <pre><code>class foo(object): x = 'original class' c1, c2 = foo(), foo() </code></pre> <p>I can change the c1 instance, and it will not affect the c2 instance:</p> <pre><code>c1.x = 'changed instance' c2.x &gt;&gt;&gt; 'original class' </code></p...
27
2014-10-23T13:46:36Z
[ "python" ]
What do I need to know/learn for automated python deployment?
1,537,298
<p>I'm starting a new webapp project in Python to get into the Agile mind-set and I'd like to do things "properly" with regards to deployment. However, I'm finding the whole virtualenv/fabric/zc.buildout/etc stuff a little confusing - I'm used to just FTP'ing PHP files to a server and pointing a webserver at it.</p> <...
2
2009-10-08T11:40:12Z
1,537,335
<p>Your deployment story depends on your app. Are you using Django? Then the <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/" rel="nofollow">Apache + <code>mod_wsgi</code> deployment docs</a> make for a good starting point. Then you can google around for more detail, such as this <a href="http:/...
4
2009-10-08T11:49:33Z
[ "python", "deployment", "virtualenv" ]
What do I need to know/learn for automated python deployment?
1,537,298
<p>I'm starting a new webapp project in Python to get into the Agile mind-set and I'd like to do things "properly" with regards to deployment. However, I'm finding the whole virtualenv/fabric/zc.buildout/etc stuff a little confusing - I'm used to just FTP'ing PHP files to a server and pointing a webserver at it.</p> <...
2
2009-10-08T11:40:12Z
1,537,337
<p>I've heard good things about <a href="http://docs.fabfile.org/0.9/" rel="nofollow">Fabric</a>:</p> <blockquote> <p>Fabric is a Python library and command-line tool designed to streamline deploying applications or performing system administration tasks via the SSH protocol. It provides tools for running ...
2
2009-10-08T11:49:55Z
[ "python", "deployment", "virtualenv" ]
What do I need to know/learn for automated python deployment?
1,537,298
<p>I'm starting a new webapp project in Python to get into the Agile mind-set and I'd like to do things "properly" with regards to deployment. However, I'm finding the whole virtualenv/fabric/zc.buildout/etc stuff a little confusing - I'm used to just FTP'ing PHP files to a server and pointing a webserver at it.</p> <...
2
2009-10-08T11:40:12Z
1,537,585
<p>You already mentioned buildout, and it's all you need. Google for example buildouts for the different parts. Takes a while to set it up the first time, but then you can reuse the setup between different projects too.</p> <p>Let supervisord start everything, not just the python server. Then start supervisord at rebo...
2
2009-10-08T12:48:45Z
[ "python", "deployment", "virtualenv" ]
Identifying twitter user's longitude and latitude
1,537,303
<p>As per my requirement in need to search twitter and display user's location on map. Can anyone help me identifying longitude and latitude from search api result?</p>
1
2009-10-08T11:41:16Z
1,537,382
<p>Last time I looked it didn't include it officially, unless the specific client (such as an iphone client) specifically updated your location to lat+long coordinates.</p> <p>When I did something similar I passed the Twitter RSS output through an rss <a href="http://en.wikipedia.org/wiki/Geotagging" rel="nofollow">ge...
1
2009-10-08T12:01:35Z
[ "c#", "asp.net", "python", "twitter" ]
Identifying twitter user's longitude and latitude
1,537,303
<p>As per my requirement in need to search twitter and display user's location on map. Can anyone help me identifying longitude and latitude from search api result?</p>
1
2009-10-08T11:41:16Z
1,537,418
<p>Twitter hasn't released their new geocoding API yet. Twitter's API Documentation is available here.</p> <p><a href="http://apiwiki.twitter.com/Twitter-API-Documentation" rel="nofollow">http://apiwiki.twitter.com/Twitter-API-Documentation</a></p> <p>As you can see, most of the current API methods return an empty "...
1
2009-10-08T12:09:31Z
[ "c#", "asp.net", "python", "twitter" ]
Identifying twitter user's longitude and latitude
1,537,303
<p>As per my requirement in need to search twitter and display user's location on map. Can anyone help me identifying longitude and latitude from search api result?</p>
1
2009-10-08T11:41:16Z
1,537,883
<p>You'd probably be best to see what "location" the user has set then use a geo-coding api to try and convert that location into lat/lng.</p> <p>e.g. use <a href="http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-users%C2%A0show" rel="nofollow">http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-users%C2%A0show...
0
2009-10-08T13:43:05Z
[ "c#", "asp.net", "python", "twitter" ]
SimpleParse non-deterministic grammar until runtime
1,537,708
<p>I'm working on a basic networking protocol in Python, which should be able to transfer both ASCII strings (read: EOL-terminated) and binary data. For the latter to be possible, I chose to create the grammar such that it contains the number of bytes to come which are going to be binary.</p> <p>For SimpleParse, the g...
1
2009-10-08T13:11:07Z
1,599,823
<p>If the grammar is as simple as the one you quoted, then perhaps using a parser generator is overkill? You might find that rolling your own recursive parser by hand is simpler and quicker.</p>
4
2009-10-21T09:59:28Z
[ "python", "parsing", "text-parsing" ]
SimpleParse non-deterministic grammar until runtime
1,537,708
<p>I'm working on a basic networking protocol in Python, which should be able to transfer both ASCII strings (read: EOL-terminated) and binary data. For the latter to be possible, I chose to create the grammar such that it contains the number of bytes to come which are going to be binary.</p> <p>For SimpleParse, the g...
1
2009-10-08T13:11:07Z
1,617,131
<p>I strongly recommend you consider using the <a href="http://construct.wikispaces.com/tutorial" rel="nofollow">construct</a> library for parsing the binary data. It also has support for text (ASCII), so when it detects text you can pass that to your SimpleParse-based parser, but the binary data will be parsed with co...
0
2009-10-24T06:11:01Z
[ "python", "parsing", "text-parsing" ]