title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
dictionary interface for large data sets
2,550,980
<p>I have a set of key/values (all text) that is too large to load in memory at once. I would like to interact with this data via a Python dictionary-like interface. </p> <p>Does such a module already exist? </p> <p>Reading key values should be efficient and values compressed on disk to save space.</p> <p>Edit:</p> ...
2
2010-03-31T06:51:59Z
2,551,283
<p>Try <a href="http://www.jcea.es/programacion/pybsddb.htm" rel="nofollow">bsddb(Python bindings for Berkley db)</a></p>
1
2010-03-31T07:59:53Z
[ "python", "dictionary", "dataset", "large-files" ]
dictionary interface for large data sets
2,550,980
<p>I have a set of key/values (all text) that is too large to load in memory at once. I would like to interact with this data via a Python dictionary-like interface. </p> <p>Does such a module already exist? </p> <p>Reading key values should be efficient and values compressed on disk to save space.</p> <p>Edit:</p> ...
2
2010-03-31T06:51:59Z
2,734,075
<p>ended up creating <a href="http://code.google.com/p/webscraping/source/browse/pdict.py" rel="nofollow">my own solution</a> based on <a href="http://code.google.com/p/persistentdict/" rel="nofollow">this existing module</a>. </p>
1
2010-04-29T00:37:48Z
[ "python", "dictionary", "dataset", "large-files" ]
exe created by py2exe give error
2,551,003
<p>i have created an exe from py2exe. After successfully creating the exe, i got the following error when i run main.exe.</p> <pre><code> File "_mssql.pyc", line 12, in &lt;module&gt; File "_mssql.pyc", line 10, in __load ImportError: DLL load failed: The specified module could not be found. </code></pre> <p>I am ...
2
2010-03-31T06:57:13Z
2,551,038
<p>make sure you include the module under the <a href="http://www.py2exe.org/index.cgi/ListOfOptions" rel="nofollow">options</a> dictionary. I think it also needs a dll file called <code>ntwdblib.dll</code>. you can find that file and include it into your <code>setup.py</code>.</p> <pre><code>import os, pymssql from d...
5
2010-03-31T07:07:06Z
[ "python", "py2exe" ]
How to list directory hierarchy in GtkTreeView widget?
2,551,147
<p>I am trying to generate a hierarchical directory listing in pyGTK.</p> <p>Currently, I have this following directory tree:</p> <pre><code>/root folderA - subdirA - subA.py - a.py folderB - b.py </code></pre> <p>I have written a function that -almost- seem to work:</p>...
1
2010-03-31T07:30:36Z
2,551,800
<p>About the performance, <a href="http://faq.pygtk.org/index.py?req=show&amp;file=faq13.043.htp" rel="nofollow">this is a FAQ</a>. About your algorithm: when you reach <code>subdirA</code> <code>piter</code> points to <code>subdirA</code>, at the next iteration when you reach <code>a.py</code> <code>piter</code> still...
1
2010-03-31T09:36:58Z
[ "python", "pygtk", "gtktreeview" ]
Processing RSS/RDF via xml.dom.minidom
2,551,214
<p>I'm trying to process a delicious rss feed via python. Here's a sample:</p> <pre><code>... &lt;item rdf:about="http://weblist.me/"&gt; &lt;title&gt;WebList - The Place To Find The Best List On The Web&lt;/title&gt; &lt;dc:date&gt;2009-12-24T17:46:14Z&lt;/dc:date&gt; &lt;link&gt;http://weblist.me/&lt;...
2
2010-03-31T07:43:09Z
2,551,579
<p>You are passing the <code>title</code> nodes to <code>getText</code>, whose <code>nodeType</code>s are not <code>node.TEXT_NODE</code>. You have to loop over all the children of the node instead in your <code>getText</code> method:</p> <pre><code>def getTextSingle(node): parts = [child.data for child in node.ch...
4
2010-03-31T08:58:50Z
[ "python", "rss" ]
String formatting: string specifier in a string constant
2,551,236
<p>Is there a way to insert a string in a string constant/variable that contains a string specifier?</p> <p>Example:</p> <pre><code>temp_body = 'Hello %s, please visit %s to confirm your registration.' body = temp_body % (name, url) </code></pre> <p>But this raises a TypeError. </p>
0
2010-03-31T07:48:56Z
2,551,251
<p>Works on my machine(TM).</p> <p>Are you sure that <code>name</code> and <code>url</code> really are strings? What do you get when you do</p> <pre><code>&gt;&gt;&gt; type(name), type(url) </code></pre>
1
2010-03-31T07:52:17Z
[ "python" ]
String formatting: string specifier in a string constant
2,551,236
<p>Is there a way to insert a string in a string constant/variable that contains a string specifier?</p> <p>Example:</p> <pre><code>temp_body = 'Hello %s, please visit %s to confirm your registration.' body = temp_body % (name, url) </code></pre> <p>But this raises a TypeError. </p>
0
2010-03-31T07:48:56Z
2,551,255
<p>Usually it is the way strings are generated e.g. msg template will be loaded from db or some file and things inserted in between, what is url and name in your case?</p> <p>This works on my machine</p> <pre><code>&gt;&gt;&gt; temp_body = 'Hello %s, please visit %s to confirm your registration.' &gt;&gt;&gt; temp_bo...
1
2010-03-31T07:52:48Z
[ "python" ]
How do you invoke a python script inside a jar file using python?
2,551,269
<p>I'm working on an application that intersperses a bunch of jython and java code. Due to the nature of the program (using wsadmin) we are really restricted to Python 2.1</p> <p>We currently have a jar containing both java source and .py modules. The code is currently invoked using java, but I'd like to remove this...
6
2010-03-31T07:56:24Z
2,552,214
<p>the following works for me :</p> <pre><code>import sys import os import java.lang.ClassLoader import java.io.InputStreamReader import java.io.BufferedReader loader = java.lang.ClassLoader.getSystemClassLoader() stream = loader.getResourceAsStream("com/example/action/myAction.py") reader = java.io.BufferedReader(...
5
2010-03-31T10:51:39Z
[ "java", "python", "import", "jar", "jython" ]
django send_mail from queryset
2,551,353
<p>I am trying to use the django send_mail method. I am running into 2 issues, notably converting mail addresses from a list into a csv to be used in the recipients. The second issue is getting the list of user emails from the notifications model.</p> <p>my models</p> <pre><code>class notifications(models.Model): ...
1
2010-03-31T08:12:33Z
2,551,419
<pre><code>UserProfile.objects.filter(mailCom='1').values_list('email', flat=True) </code></pre>
2
2010-03-31T08:24:07Z
[ "python", "django" ]
How can I write this query in Django? (datetime)
2,551,475
<pre><code>| time_before | datetime | YES | MUL | NULL | | | time_after | datetime | YES | MUL | NULL | | the_tag = Tag.objects.get(id=tag_id) Log.objects.filter(blah).extra(where=['last_updated &gt;'+the_tag.time_before, 'last_updated' &lt; the_tag.time_after]) </code>...
0
2010-03-31T08:37:24Z
2,551,487
<p>To get the exact behaviour of your example:</p> <pre><code>Log.objects.filter(last_updated__gt=the_tag.time_before, last_updated__lt=the_tag.time_after) </code></pre> <p>For an inclusive range (equivalent to <code>__gte</code>, <code>__lte</code>) the query is a bit simpler:</p> <pre><code>Log.objects.filter(last...
6
2010-03-31T08:41:04Z
[ "python", "mysql", "database", "django" ]
python mongokit Connection() AssertionError
2,551,530
<p>just installed mongokit and can't figure out why I get AssertionError</p> <p>python console:</p> <pre><code>&gt;&gt;&gt; from mongokit import Connection &gt;&gt;&gt; c = Connection() Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/usr/local/lib/python2.6/dist-packages/...
0
2010-03-31T08:48:57Z
2,554,812
<p>This is a known issue in PyMongo working against devel (>1.4.0) versions of MongoDB. Just released PyMongo 1.5.2 w/ a fix - try upgrading to that.</p>
1
2010-03-31T16:47:02Z
[ "python", "mongodb", "pymongo" ]
Import C++ dll failed in Python
2,551,666
<p>Following document in "Extending and Embedding the Python Interpreter", I created a VC project, and a dll file was successfully created with name "spam_d.dll"</p> <p>Main code was</p> <pre><code>static PyObject * spam_system(PyObject *self, PyObject *args) { const char *command; int sts; if (!PyArg_Pa...
2
2010-03-31T09:14:51Z
9,144,254
<p>The python tries to link against a debug library with suffix _d.pyd, since it's a Debug build. To link aganist spam.pyd, you need a Release build.</p>
1
2012-02-04T20:27:34Z
[ "python", "windows" ]
ActivePython and MySQLdb
2,551,856
<p>I have installed ActivePython and am trying to import MySQLdb</p> <pre><code>&gt;&gt; import mySQLdb </code></pre> <p>gives me an error stating <code>No module called MySQLdb</code></p> <p>I have tried searching but all the resources out there explain how to set up the mySQLdb for unix, not for windows, can you ...
1
2010-03-31T09:45:51Z
2,551,956
<p>You can find a detailed HOWTO <a href="http://www.fuyun.org/2009/12/install-mysql-for-python-on-windows/" rel="nofollow">over here</a></p>
0
2010-03-31T10:07:44Z
[ "python", "mysql", "activepython" ]
ActivePython and MySQLdb
2,551,856
<p>I have installed ActivePython and am trying to import MySQLdb</p> <pre><code>&gt;&gt; import mySQLdb </code></pre> <p>gives me an error stating <code>No module called MySQLdb</code></p> <p>I have tried searching but all the resources out there explain how to set up the mySQLdb for unix, not for windows, can you ...
1
2010-03-31T09:45:51Z
4,222,222
<p>To install <a href="http://code.activestate.com/pypm/mysql-python/" rel="nofollow">MySQL-Python</a>,</p> <pre><code>pypm install mysql-python </code></pre>
0
2010-11-19T04:58:48Z
[ "python", "mysql", "activepython" ]
Supported Audio Formats of Qt4 Phonon?
2,551,873
<p>I am making a music player in PyQt4, and I am using Phonon to play the music itself. This application is aimed primarily at Windows, but I plan on also supporting Mac and Linux versions. What I want to know is which audio formats are supported by Phonon so that I can ensure that the user only enters those files.</p>...
3
2010-03-31T09:49:04Z
2,559,343
<p>You need to <a href="http://doc.trolltech.com/4.4/phonon-overview.html#querying-backends-for-support">call <em>availableMimeTypes()</em> to check what formats the backend supports</a>.</p>
5
2010-04-01T09:20:31Z
[ "python", "qt4", "pyqt4", "phonon" ]
How to extend/patch an existing module or package?
2,551,972
<p>I want to extend some locale-specific features of a python application named OpenERP. All I need is implementing a third party module.function that would be called every time OpenERP calls locale.setlocale() function without changing neither OpenERP nor locale module source code.</p> <p>The only way I can imagine i...
1
2010-03-31T10:11:00Z
2,552,011
<p>Look up <a href="http://en.wikipedia.org/wiki/Monkey_patch" rel="nofollow">Monkey Patching</a>. It's not most elegant technique, but sometimes it's the only option.</p> <p>In your case you can substitute your own function for <code>locale.setlocale()</code> which will do whatever you want. It would look something l...
2
2010-03-31T10:18:10Z
[ "python", "locale", "extend" ]
Hyphenate a random string to an exact format
2,552,027
<p>I am creating a random ID using the below code:</p> <pre><code>from random import * import string # The characters to make up the random password chars = string.ascii_letters + string.digits def random_password(): return "".join(choice(chars) for x in range(32)) </code></pre> <p>This will output something l...
0
2010-03-31T10:21:44Z
2,552,059
<p>What's wrong with generating every part separately? Like that:</p> <pre><code>def random_password(): return "-".join(["".join(choice(chars) for x in range(n)) for n in (8, 4, 4, 4, 8)]) </code></pre>
3
2010-03-31T10:27:01Z
[ "python", "string" ]
Hyphenate a random string to an exact format
2,552,027
<p>I am creating a random ID using the below code:</p> <pre><code>from random import * import string # The characters to make up the random password chars = string.ascii_letters + string.digits def random_password(): return "".join(choice(chars) for x in range(32)) </code></pre> <p>This will output something l...
0
2010-03-31T10:21:44Z
2,552,069
<p>how about simple concat?</p> <pre><code>&gt;&gt;&gt; s="60ff612332b741508bc4432e34ec1d3e" &gt;&gt;&gt; s[:8]+"-"+s[8:12]+"-"+s[12:16]+"-"+s[16:20]+"-"+s[20:] '60ff6123-32b7-4150-8bc4-432e34ec1d3e' </code></pre>
2
2010-03-31T10:28:51Z
[ "python", "string" ]
Hyphenate a random string to an exact format
2,552,027
<p>I am creating a random ID using the below code:</p> <pre><code>from random import * import string # The characters to make up the random password chars = string.ascii_letters + string.digits def random_password(): return "".join(choice(chars) for x in range(32)) </code></pre> <p>This will output something l...
0
2010-03-31T10:21:44Z
2,552,075
<p>The <a href="http://docs.python.org/library/uuid.html" rel="nofollow"><code>uuid</code></a> module can be used for generating UUIDs.</p>
4
2010-03-31T10:29:28Z
[ "python", "string" ]
Hyphenate a random string to an exact format
2,552,027
<p>I am creating a random ID using the below code:</p> <pre><code>from random import * import string # The characters to make up the random password chars = string.ascii_letters + string.digits def random_password(): return "".join(choice(chars) for x in range(32)) </code></pre> <p>This will output something l...
0
2010-03-31T10:21:44Z
2,552,100
<pre><code>pos = set([8, 12, 16]) print "".join(map(lambda x: (x[1], "%s-" % x[1])[x[0] in pos], list(enumerate(random_password())))) </code></pre>
1
2010-03-31T10:33:51Z
[ "python", "string" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
2,552,256
<p>Most functional languages which evaluate lazily can simulate the processing of infinite series. Of course, on a finite computer it is not possible to process infinite series, as I am sure you are aware. Off the top of my head, I guess <em>Mathematica</em> can do most of what you might want, I suspect that <em>Mapl...
18
2010-03-31T10:59:46Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
2,552,296
<p>I have worked in couple of Huge Data Series for Research purpose. I used <strong><a href="http://www.mathworks.com/products/matlab/" rel="nofollow">Matlab</a></strong> for that. I didn't know it can/can't process Infinite Series.</p> <p>But I think there is a possibility. U can try :)</p>
1
2010-03-31T11:06:31Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
2,552,379
<p>One place to look might be the Wikipedia category of <a href="http://en.wikipedia.org/wiki/Category%3aComputer_algebra_systems" rel="nofollow">Computer Algebra Systems</a>.</p>
15
2010-03-31T11:18:16Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
2,552,419
<p>For Python check out <a href="http://code.google.com/p/sympy/" rel="nofollow">SymPy</a> - clone of Mathematica and Matlab.</p> <p>There is also a heavier Python-based math-processing tool called <a href="http://www.sagemath.org/" rel="nofollow">Sage</a>.</p>
7
2010-03-31T11:24:18Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
2,552,434
<p><a href="http://clojure.org/sequences" rel="nofollow">Clojure</a> and <a href="http://www.haskell.org/haskellwiki/Language_and_library_specification" rel="nofollow">Haskell</a> off the top of my head.</p> <p>Sorry I couldn't find a better link to haskell's sequences, if someone else has it, please let me know and I...
2
2010-03-31T11:26:50Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
2,552,469
<p>Maxima can calculate some infinite sums, but in this particular case it doesn't seem to find the answer :-s</p> <pre><code>(%i1) sum((-1)^k/(2*k), k, 1, inf), simpsum; inf ==== k \ (- 1) ...
12
2010-03-31T11:32:07Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
2,555,525
<p>There are two tools available in Haskell for this beyond simply supporting infinite lists.</p> <p>First there is a module that supports looking up sequences in OEIS. This can be applied to the first few terms of your series and can help you identify a series for which you don't know the closed form, etc. The other ...
13
2010-03-31T18:36:19Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
2,662,806
<p>You need something that can do a symbolic computation like <a href="http://www.wolfram.com/" rel="nofollow">Mathematica</a>. You can also consider quering <a href="http://www.wolframalpha.com/input/?i=sum%28%28-1%29%5Ei%2a1%2Fi%2C%20i%2C%201%20%2C%20inf%29" rel="nofollow">wolframaplha: sum((-1)^i*1/i, i, 1 , inf)</a...
4
2010-04-18T15:46:18Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
2,669,723
<p>There is a library called mpmath(python), a module of sympy, which provides the series support for sympy( I believe it also backs sage). <br /> More specifically, all of the series stuff can be found here: <a href="http://mpmath.googlecode.com/svn/trunk/doc/build/functions/zeta.html" rel="nofollow">Series documenta...
3
2010-04-19T18:05:19Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
2,769,839
<p>The C++ iRRAM library performs real arithmetic <em>exactly</em>. Among other things it can compute limits exactly using the limit function. The homepage for iRRAM is <a href="http://www.informatik.uni-trier.de/iRRAM/" rel="nofollow">here</a>. Check out the limit function in the documentation. Note that I'm not talki...
3
2010-05-05T00:28:46Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
3,507,368
<p>You can solve the series problem in <a href="http://sagemath.org">Sage</a> (a free Python-based math software system) exactly as follows:</p> <pre><code>sage: k = var('k'); sum((-1)^k/(2*k+1), k, 1, infinity) 1/4*pi - 1 </code></pre> <p>Behind the scenes, this is really using Maxima (a component of Sage). </p>
8
2010-08-17T22:08:16Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
10,986,708
<p>This can be done in for instance sympy and sage (among open source alternatives) In the following, a few examples using sympy:</p> <p>In [10]: summation(1/k**2,(k,1,oo)) Out[10]: 2 π ── 6 </p> <p>In [11]: summation(1/k**4, (k,1,oo)) Out[11]: 4 π ── 90</p> <p>In [12]: summation( (-1)**k/k, (k,1,oo)...
1
2012-06-11T19:57:40Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Which programming language or a library can process Infinite Series?
2,552,213
<p>Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence.</p> <p>For example, in Python it coul...
26
2010-03-31T10:51:38Z
37,122,445
<p>Just install sympy on your computer. Then do the following code:</p> <pre><code>from sympy.abc import i, k, m, n, x from sympy import Sum, factorial, oo, IndexedBase, Function Sum((-1)**k/(2*k+1), (k, 0, oo)).doit() </code></pre> <p>Result will be: pi/4</p>
0
2016-05-09T18:01:02Z
[ "python", "math", "programming-languages", "functional-programming", "series" ]
Python enumerate built-in error when using the start parameter
2,552,287
<p>I'm modifying some code that calls enumerate on a list declared via a list comprehension e.g. </p> <pre><code>self.groups = [Groups(self, idx) for idx in range(n_groups)] </code></pre> <p>then later:</p> <pre><code>for idx, group in enumerate(self.groups): # do some stuff </code></pre> <p>but when I change t...
1
2010-03-31T11:04:17Z
2,552,311
<p>The problem: Using an indexer with a single argument on a sequence will yield a <em>single</em> object from the sequence. The object picked from your sequence is of type <code>Group</code>, and that type is not iterable.</p> <p>The solution: Use the <a href="http://diveintopython.net/native_data_types/lists.html#od...
2
2010-03-31T11:08:05Z
[ "python", "iterable" ]
Python enumerate built-in error when using the start parameter
2,552,287
<p>I'm modifying some code that calls enumerate on a list declared via a list comprehension e.g. </p> <pre><code>self.groups = [Groups(self, idx) for idx in range(n_groups)] </code></pre> <p>then later:</p> <pre><code>for idx, group in enumerate(self.groups): # do some stuff </code></pre> <p>but when I change t...
1
2010-03-31T11:04:17Z
2,552,317
<p>you're not <em>starting at the second</em>, you're trying to iterate only over the second. To start at the second item do:</p> <pre><code>for idx, group in enumerate(self.groups[1:]): # process </code></pre>
1
2010-03-31T11:08:36Z
[ "python", "iterable" ]
Python enumerate built-in error when using the start parameter
2,552,287
<p>I'm modifying some code that calls enumerate on a list declared via a list comprehension e.g. </p> <pre><code>self.groups = [Groups(self, idx) for idx in range(n_groups)] </code></pre> <p>then later:</p> <pre><code>for idx, group in enumerate(self.groups): # do some stuff </code></pre> <p>but when I change t...
1
2010-03-31T11:04:17Z
2,554,793
<p>If your sequence is large enough than consider using <code>islice</code> function from <code>itertools</code> module, because it's more memory efficient for large sequences than slicing:</p> <pre><code>import itertools for idx, group in enumerate(itertools.islice(self.groups, 1, None)): # process </code></pre>...
1
2010-03-31T16:45:04Z
[ "python", "iterable" ]
Hierarchical checked tree control with tri-state checkboxes in wxPython?
2,552,349
<p>As per the title, is this possible?</p> <p>By tri-state, I mean the parent node is:</p> <ul> <li>Checked if <em>all</em> children are checked</li> <li>Unchecked if <em>all</em> children are unchecked</li> <li>Grey/Filled if <em>some</em> children are checked</li> </ul> <p>I have used them previously in C# but can...
2
2010-03-31T11:13:57Z
2,556,368
<p>Did you look at <a href="http://www.wxpython.org/docs/api/wx.lib.agw.customtreectrl-module.html" rel="nofollow">wx.lib.agw.CustomTreeCtrl</a>? </p> <p>I'm not sure it does tri-state out of the box, but it's written in Python, so it should be quite easy to extend it.</p>
2
2010-03-31T20:50:38Z
[ "python", "treeview", "wxpython", "wxwidgets" ]
Hierarchical checked tree control with tri-state checkboxes in wxPython?
2,552,349
<p>As per the title, is this possible?</p> <p>By tri-state, I mean the parent node is:</p> <ul> <li>Checked if <em>all</em> children are checked</li> <li>Unchecked if <em>all</em> children are unchecked</li> <li>Grey/Filled if <em>some</em> children are checked</li> </ul> <p>I have used them previously in C# but can...
2
2010-03-31T11:13:57Z
7,471,941
<p>I was trying to do the same thing with the <code>CustomTreeCtrl</code> and it does support tri-state check boxes.</p> <p>When you create the root,</p> <pre><code>self.root= self.tree.AddRoot("root node",ct_type=1) </code></pre> <p>or a child node,</p> <pre><code>child= self.tree.AppendItem(parent,"child",ct_type...
2
2011-09-19T13:45:20Z
[ "python", "treeview", "wxpython", "wxwidgets" ]
Pylint only Global evaluation
2,552,605
<p>In pylint I use this command <code>--reports=n</code> to disable the reports, but now I don't see the Global evaluation more.</p> <p>Is possible enable only the Global evaluation?</p>
6
2010-03-31T11:53:27Z
2,552,989
<p>No you can't, Global Evaluation is part of the reports and with <strong>--reports=n</strong> you disable all the reports .</p>
3
2010-03-31T12:53:31Z
[ "python", "pylint" ]
Pylint only Global evaluation
2,552,605
<p>In pylint I use this command <code>--reports=n</code> to disable the reports, but now I don't see the Global evaluation more.</p> <p>Is possible enable only the Global evaluation?</p>
6
2010-03-31T11:53:27Z
3,458,752
<p>As systempunttoout said, this is currently not possible. But you can ask for this on the python-projects@logilab.org mailing list, and submitting a patch is a very good way of getting that feature soon. :-)</p>
0
2010-08-11T13:27:31Z
[ "python", "pylint" ]
Pylint only Global evaluation
2,552,605
<p>In pylint I use this command <code>--reports=n</code> to disable the reports, but now I don't see the Global evaluation more.</p> <p>Is possible enable only the Global evaluation?</p>
6
2010-03-31T11:53:27Z
9,428,536
<p>You can use e.g. --disable=RP0701 to disable the Raw metrics part of the report.</p> <p>This (outdated) list can help to find the IDs of blocks you would like to suppress:</p> <p><a href="http://pylint-messages.wikidot.com/all-codes" rel="nofollow">http://pylint-messages.wikidot.com/all-codes</a></p> <p>Note that...
3
2012-02-24T09:43:01Z
[ "python", "pylint" ]
Pylint only Global evaluation
2,552,605
<p>In pylint I use this command <code>--reports=n</code> to disable the reports, but now I don't see the Global evaluation more.</p> <p>Is possible enable only the Global evaluation?</p>
6
2010-03-31T11:53:27Z
14,971,999
<p>I can nearly just get the Global evaluation. To eliminate everything but Duplication and Global evaluation add;</p> <pre><code>--disable=RP0401 --disable=RP0001 --disable=RP0002 --disable=RP0003 --disable=RP0101 --disable=RP0101 --disable=RP0701 </code></pre> <p>Being unable to disable the duplication report seems...
0
2013-02-20T03:52:05Z
[ "python", "pylint" ]
Pylint only Global evaluation
2,552,605
<p>In pylint I use this command <code>--reports=n</code> to disable the reports, but now I don't see the Global evaluation more.</p> <p>Is possible enable only the Global evaluation?</p>
6
2010-03-31T11:53:27Z
24,287,121
<p>This post is quite old but here's the current solution:</p> <p>To disable EVERYTHING other than the Global evaluation section, you must</p> <pre><code>--disable=RP0001 --disable=RP0002 --disable=RP0003 --disable=RP0101 --disable=RP0401 --disable=RP0701 --disable=RP0801 </code></pre> <p>The link shared in anot...
2
2014-06-18T13:39:31Z
[ "python", "pylint" ]
Copy whole SQL Server database into JSON from Python
2,552,629
<p>I facing an atypical conversion problem. About a decade ago I coded up a large site in ASP. Over the years this turned into ASP.NET but kept the same database.</p> <p>I've just re-done the site in Django and I've copied all the core data but before I cancel my account with the host, I need to make sure I've got a l...
0
2010-03-31T11:57:34Z
2,552,670
<p>Have a look at the sysobjects and syscolumns tables. Also try:</p> <pre><code>SELECT * FROM sysobjects WHERE name LIKE 'sys%' </code></pre> <p>to find any other metatables of interest. See <a href="http://msdn.microsoft.com/en-us/library/ms177596.aspx" rel="nofollow">here</a> for more info on these tables and the ...
1
2010-03-31T12:03:14Z
[ "python", "sql-server", "pymssql" ]
Copy whole SQL Server database into JSON from Python
2,552,629
<p>I facing an atypical conversion problem. About a decade ago I coded up a large site in ASP. Over the years this turned into ASP.NET but kept the same database.</p> <p>I've just re-done the site in Django and I've copied all the core data but before I cancel my account with the host, I need to make sure I've got a l...
0
2010-03-31T11:57:34Z
2,552,763
<p>As an aside to your coding approach - I'd say :</p> <ul> <li>set up a virtual machine with an eval on windows</li> <li>put sql server eval on it</li> <li>restore your data</li> <li>check it manually or automatically using the excellent db scripting tools from <a href="http://www.red-gate.com/" rel="nofollow">red-ga...
1
2010-03-31T12:17:48Z
[ "python", "sql-server", "pymssql" ]
Copy whole SQL Server database into JSON from Python
2,552,629
<p>I facing an atypical conversion problem. About a decade ago I coded up a large site in ASP. Over the years this turned into ASP.NET but kept the same database.</p> <p>I've just re-done the site in Django and I've copied all the core data but before I cancel my account with the host, I need to make sure I've got a l...
0
2010-03-31T11:57:34Z
2,552,772
<p>I've liked the ADOdb python module when I've needed to connect to sql server from python. Here is a link to a simple tutorial/example: <a href="http://phplens.com/lens/adodb/adodb-py-docs.htm#tutorial" rel="nofollow">http://phplens.com/lens/adodb/adodb-py-docs.htm#tutorial</a></p>
1
2010-03-31T12:19:27Z
[ "python", "sql-server", "pymssql" ]
Copy whole SQL Server database into JSON from Python
2,552,629
<p>I facing an atypical conversion problem. About a decade ago I coded up a large site in ASP. Over the years this turned into ASP.NET but kept the same database.</p> <p>I've just re-done the site in Django and I've copied all the core data but before I cancel my account with the host, I need to make sure I've got a l...
0
2010-03-31T11:57:34Z
2,554,160
<p>I know you said JSON, but it's very simple to generate a SQL script to do an entire dump in XML:</p> <pre><code>SELECT REPLACE(REPLACE('SELECT * FROM {TABLE_SCHEMA}.{TABLE_NAME} FOR XML RAW', '{TABLE_SCHEMA}', QUOTENAME(TABLE_SCHEMA)), '{TABLE_NAME}', QUOTENAME(TABLE_NAME)) FROM INFORMAT...
1
2010-03-31T15:18:52Z
[ "python", "sql-server", "pymssql" ]
Missing multiprocessing module when freezing Python code
2,552,682
<p>I'm using cx_Freeze to freeze my Python code so I can distribute it as executable on Windows systems. It works fine but it's missing a few modules. I use some open-source libraries in my project e.g. BeautifulSoup and Periscope. They use some libraries for backward compatibility which i don't need to include as Pyth...
2
2010-03-31T12:04:48Z
2,553,168
<p>There was a similar issue on Google App Engine. See <a href="http://code.google.com/p/googleappengine/issues/detail?id=1504" rel="nofollow">this</a></p> <p>I fixed this my putting a _multiprocessing.py file into the multiprocessing module's folder. This file contained the code:</p> <blockquote> <p>import multipr...
1
2010-03-31T13:14:55Z
[ "python", "distutils", "cx-freeze" ]
Django JSON serializable error
2,552,719
<p>With the following code below, There is an error saying </p> <pre><code> File "/home/user/web_pro/info/views.py", line 184, in headerview, raise TypeError("%r is not JSON serializable" % (o,)) TypeError: &lt;lastname: jerry&gt; is not JSON serializable </code></pre> <p>In the models code</p> <pre...
1
2010-03-31T12:10:10Z
2,552,798
<p>Have you considered using Django's <a href="http://docs.djangoproject.com/en/dev/topics/serialization/" rel="nofollow">own serialization functionality</a>?</p>
1
2010-03-31T12:22:53Z
[ "python", "django", "django-models", "django-views" ]
Django JSON serializable error
2,552,719
<p>With the following code below, There is an error saying </p> <pre><code> File "/home/user/web_pro/info/views.py", line 184, in headerview, raise TypeError("%r is not JSON serializable" % (o,)) TypeError: &lt;lastname: jerry&gt; is not JSON serializable </code></pre> <p>In the models code</p> <pre...
1
2010-03-31T12:10:10Z
2,553,175
<p>The quick read is that obj.lastname is a Lastname model not a String. You probably need to say something like:</p> <pre><code>l_array_obj = [..., obj.lastname.value, .... ] </code></pre> <p>to get the string value, rather than the Model object.</p>
2
2010-03-31T13:16:09Z
[ "python", "django", "django-models", "django-views" ]
How do I resolve this curl-related error?
2,552,865
<p>please tell me the solution</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "build/bdist.linux-x86_64/egg/pycurl.py", line 7, in &lt;module&gt; File "build/bdist.linux-x86_64/egg/pycurl.py", line 6, in __bootstrap__ ImportError: libcurl.so.4: cannot open ...
0
2010-03-31T12:34:18Z
2,552,871
<p>You're trying to invoke the cURL library, but you don't have curl installed (or it's not installed properly). It looks like you're running Linux, so simply install the appropriate package (for instance, <code>sudo apt-get install curl</code> if you're on Ubuntu).</p>
3
2010-03-31T12:36:01Z
[ "python", "pycurl" ]
Django newbie question: can't start a new project
2,553,088
<p>I'm totally new to django, and I'm using its documentation to get help on how to use it <br> but seems like something is missing. i installed django using setup.py install command and i added the ( django/bin ) to system path variable but. i still cant start a new project<br> i use the following syntax to start a p...
0
2010-03-31T13:04:51Z
2,553,104
<p>do you have permission to write to the directory?</p>
2
2010-03-31T13:07:26Z
[ "python", "django", "django-admin" ]
Django newbie question: can't start a new project
2,553,088
<p>I'm totally new to django, and I'm using its documentation to get help on how to use it <br> but seems like something is missing. i installed django using setup.py install command and i added the ( django/bin ) to system path variable but. i still cant start a new project<br> i use the following syntax to start a p...
0
2010-03-31T13:04:51Z
2,553,137
<p>See <a href="http://docs.djangoproject.com/en/dev/ref/django-admin/#startproject-projectname" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/django-admin/#startproject-projectname</a></p> <blockquote> <p>This command is disabled when the --settings option to django-admin.py is used, or when the environme...
2
2010-03-31T13:10:49Z
[ "python", "django", "django-admin" ]
Django newbie question: can't start a new project
2,553,088
<p>I'm totally new to django, and I'm using its documentation to get help on how to use it <br> but seems like something is missing. i installed django using setup.py install command and i added the ( django/bin ) to system path variable but. i still cant start a new project<br> i use the following syntax to start a p...
0
2010-03-31T13:04:51Z
2,559,610
<p>check whether you have djagno or not and the it is in python path or not.if using linux go to terminal type python and then try to import django</p>
0
2010-04-01T10:13:15Z
[ "python", "django", "django-admin" ]
Django newbie question: can't start a new project
2,553,088
<p>I'm totally new to django, and I'm using its documentation to get help on how to use it <br> but seems like something is missing. i installed django using setup.py install command and i added the ( django/bin ) to system path variable but. i still cant start a new project<br> i use the following syntax to start a p...
0
2010-03-31T13:04:51Z
17,631,438
<p>This question is old, but...<br> Here is my answer:<br> I switched to directory <code>C:\Python27\Scripts\</code> and then typed:</p> <pre><code>python django-admin.py startproject MyProject </code></pre> <p>and it worked!</p>
0
2013-07-13T15:10:54Z
[ "python", "django", "django-admin" ]
Which files to distribute using cx_Freeze?
2,553,110
<p>I'm using cx_freeze to freeze a Python script for distribution to other windows systems. I did everything as instructed and cx_freeze generated a <code>build\exe.win32-2.6</code> folder in the folder containing my sources. This directory now contains a a bunch of PYD files, a library.zip file, the python DLL file a...
2
2010-03-31T13:07:40Z
2,553,685
<p>You need all of them.</p>
9
2010-03-31T14:19:07Z
[ "python", "distutils", "cx-freeze" ]
Unexplained file not found for an existing file
2,553,341
<p>Following is the error that occurs in this part of the code. Although the path is valid, a RuntimeError occurs&mdash;strange. What is happening, and how can I get this to work?</p> <pre><code> for root,dirs,files in os.walk(self.path): for f in files : if (f.split('.')[1] == "mb"...
1
2010-03-31T13:37:38Z
2,553,856
<p>Do you have write permission to all the files in the folder?</p>
0
2010-03-31T14:40:30Z
[ "python", "maya" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
2,553,399
<p>This is not possible in Python, which really doesn't have "variables". Python has names, and there can be more than one name for the same object.</p>
10
2010-03-31T13:44:03Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
2,553,421
<p>Most objects don't have a <em>__name__</em> attribute. (Classes, functions, and modules do; any more builtin types that have one?)</p> <p>What else would you expect for <code>print(my_var.__name__)</code> other than <code>print("my_var")</code>? Can you simply use the string directly?</p> <p>You could "slice" a d...
1
2010-03-31T13:46:33Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
2,553,481
<p>As unwind said, this isn't really something you do in Python - variables are actually name mappings to objects.</p> <p><em>However</em>, here's one way to try and do it:</p> <pre><code> &gt;&gt;&gt; a = 1 &gt;&gt;&gt; for k, v in list(locals().iteritems()): if v is a: a_as_str = k &gt;&gt;&...
65
2010-03-31T13:54:20Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
2,553,524
<p>This is a hack. It will not work on all Python implementations distributions (in particular, those that do not have <code>traceback.extract_stack</code>.)</p> <pre><code>import traceback def make_dict(*expr): (filename,line_number,function_name,text)=traceback.extract_stack()[-2] begin=text.find('make_dict...
8
2010-03-31T13:58:45Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
2,553,532
<p>Are you trying to do this?</p> <pre><code>dict( (name,eval(name)) for name in ['some','list','of','vars'] ) </code></pre> <p>Example </p> <pre><code>&gt;&gt;&gt; some= 1 &gt;&gt;&gt; list= 2 &gt;&gt;&gt; of= 3 &gt;&gt;&gt; vars= 4 &gt;&gt;&gt; dict( (name,eval(name)) for name in ['some','list','of','vars'] ) {'li...
17
2010-03-31T13:59:54Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
6,486,008
<p>I've wanted to do this quite a lot. This hack is very similar to rlotun's suggestion, but it's a one-liner, which is important to me:</p> <pre><code>blah = 1 blah_name = [ k for k,v in locals().iteritems() if v is blah][0] </code></pre>
31
2011-06-26T18:50:52Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
10,116,795
<p>In reading the thread, I saw an awful lot of friction. It's easy enough to give a bad answer, then let someone give the correct answer. Anyway, here is what I found.</p> <p>From: [effbot.org] (<a href="http://effbot.org/zone/python-objects.htm#names" rel="nofollow">http://effbot.org/zone/python-objects.htm#names</a...
2
2012-04-12T02:56:19Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
12,288,096
<p>Well, I encountered the very same <em>need</em> a few days ago and <em>had to</em> get a variable's <em>name</em> which was pointing to the <strong>object</strong> itself.</p> <p><strong>And why was it so necessary?</strong></p> <p>In short I was building a plug-in for <em>Maya</em>. The core plug-in was built usi...
1
2012-09-05T19:03:46Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
14,785,838
<p>With python 2.7 and newer there is also dictionary comprehension which makes it a bit shorter. If possible I would use getattr instead eval (eval is evil) like in the top answer. Self can be any object which has the context your a looking at. It can be an object or locals=locals() etc. </p> <pre><code>{name: getatt...
1
2013-02-09T07:11:09Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
16,906,321
<p>I think my problem will help illustrate why this question is useful, and it may give a bit more insight into how to answer it. I wrote a small function to do a quick inline head check on various variables in my code. Basically, it lists the variable name, data type, size, and other attributes, so I can quickly cat...
6
2013-06-03T21:42:16Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
18,265,546
<p>Maybe I'm overthinking this but..</p> <pre><code>str_l = next((k for k,v in locals().items() if id(l) == id(v))) &gt;&gt;&gt; bar = True &gt;&gt;&gt; foo = False &gt;&gt;&gt; my_dict=dict(bar=bar, foo=foo) &gt;&gt;&gt; next((k for k,v in locals().items() if id(bar) == id(v))) 'bar' &gt;&gt;&gt; next((k for k,v in...
1
2013-08-16T03:56:38Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
18,558,377
<p>I was working on a similar problem. @S.Lott said "If you have the list of variables, what's the point of "discovering" their names?" And my answer is just to see if it could be done and if for some reason you want to sort your variables by type into lists. So anyways, in my research I came came across this thread an...
1
2013-09-01T12:19:46Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
19,825,095
<p>I find that if you already have a specific list of values, that the way described by @S. Lotts is the best; however, the way described below works well to get all variables and Classes added throughout the code <strong>WITHOUT</strong> the need to provide variable name though you can specify them if you want. Code c...
5
2013-11-06T23:31:53Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
22,182,558
<p>In python 3 this is easy</p> <pre><code>myVariable = 5 for v in locals(): if id(v) == id("myVariable"): print(v, locals()[v]) </code></pre> <p>this will print:</p> <blockquote> <p>myVariable 5</p> </blockquote>
4
2014-03-04T20:40:42Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
32,302,266
<p>Python3. Use inspect to capture the calling local namespace then use ideas presented here. Can return more than one answer as has been pointed out.</p> <pre><code>def varname(var): import inspect frame = inspect.currentframe() var_id = id(var) for name in frame.f_back.f_locals.keys(): try: if id...
2
2015-08-30T23:43:15Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
38,119,665
<p>you can use easydict</p> <pre><code>&gt;&gt;&gt; from easydict import EasyDict as edict &gt;&gt;&gt; d = edict({'foo':3, 'bar':{'x':1, 'y':2}}) &gt;&gt;&gt; d.foo 3 &gt;&gt;&gt; d.bar.x 1 &gt;&gt;&gt; d = edict(foo=3) &gt;&gt;&gt; d.foo 3 </code></pre> <p>another example:</p> <pre><code>&gt;&gt;&gt; d = EasyDict(...
0
2016-06-30T09:53:48Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
39,535,370
<p>Just for reference, here is answer using keywords:</p> <blockquote> <p>Collect the arguments using the ** specifier in the function’s parameter list; this gives you the keyword arguments as a dictionary.</p> </blockquote> <p><a href="https://docs.python.org/2/faq/programming.html#how-can-i-pass-optional-or-key...
0
2016-09-16T15:39:54Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
39,552,638
<p>The answer of @keflavich for python 2 and 3:</p> <pre><code>my_var = 1 my_var_name = [k for k, v in list(locals().items()) if v is my_var][0] </code></pre>
0
2016-09-17T23:19:39Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
39,557,770
<pre><code>import re import traceback pattren = re.compile(r'[\W+\w+]*get_variable_name\((\w+)\)') def get_variable_name(x): return pattren.match( traceback.extract_stack(limit=2)[0][3]) .group(1) a = 1 b = a c = b print get_variable_name(a) print get_variable_name(b) print get_variable_name(c) </code></pre>
0
2016-09-18T12:46:28Z
[ "python", "string", "variables" ]
How to get a variable name as a string in Python?
2,553,354
<p>I would like to be able to get the name of a variable as a string but I don't know if Python has that much introspection capabilities. Something like:</p> <pre><code>&gt;&gt;&gt; print(my_var.__name__) 'my_var' </code></pre> <p>I want to do that because I have a bunch of vars I'd like to turn into a dictionary lik...
112
2010-03-31T13:39:10Z
40,131,079
<pre><code>&gt;&gt;&gt; a = 1 &gt;&gt;&gt; b = 1 &gt;&gt;&gt; id(a) 34120408 &gt;&gt;&gt; id(b) 34120408 &gt;&gt;&gt; a is b True &gt;&gt;&gt; id(a) == id(b) True </code></pre> <p>this way get varname for a maybe 'a' or 'b'.</p>
0
2016-10-19T12:11:44Z
[ "python", "string", "variables" ]
Setting `axes.linewidth` without changing the `rcParams` global dict
2,553,521
<p>So, it seems one cannot do the following (it raises an error, since <code>axes</code> does not have a <code>set_linewidth</code> method):</p> <pre><code>axes_style = {'linewidth':5} axes_rect = [0.1, 0.1, 0.9, 0.9] axes(axes_rect, **axes_style) </code></pre> <p>and has to use the following old trick instead:</p> ...
7
2010-03-31T13:58:18Z
2,557,264
<p>Yes, there's an easy and clean way to do this.</p> <p>Calling '<strong>axhline</strong>' and '<strong>axvline</strong>' from an axis instance appears to be the technique endorsed in the MPL Documentation. </p> <p>In any event, it is simple and gives you fine-grained control over the appearance of the axes.</p> <p...
7
2010-03-31T23:49:01Z
[ "python", "matplotlib", "plot", "graphing" ]
Setting `axes.linewidth` without changing the `rcParams` global dict
2,553,521
<p>So, it seems one cannot do the following (it raises an error, since <code>axes</code> does not have a <code>set_linewidth</code> method):</p> <pre><code>axes_style = {'linewidth':5} axes_rect = [0.1, 0.1, 0.9, 0.9] axes(axes_rect, **axes_style) </code></pre> <p>and has to use the following old trick instead:</p> ...
7
2010-03-31T13:58:18Z
20,703,611
<p>The above answer does not work, as it is explained in the comments. I suggest to use spines.</p> <pre><code>import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111) # you can change each line separately, like: #ax.spines['right'].set_linewidth(0.5) # to change all, just write: for axis in ['...
23
2013-12-20T12:25:31Z
[ "python", "matplotlib", "plot", "graphing" ]
Setting `axes.linewidth` without changing the `rcParams` global dict
2,553,521
<p>So, it seems one cannot do the following (it raises an error, since <code>axes</code> does not have a <code>set_linewidth</code> method):</p> <pre><code>axes_style = {'linewidth':5} axes_rect = [0.1, 0.1, 0.9, 0.9] axes(axes_rect, **axes_style) </code></pre> <p>and has to use the following old trick instead:</p> ...
7
2010-03-31T13:58:18Z
36,716,300
<pre><code>plt.setp(ax.spines.values(), linewidth=5) </code></pre>
4
2016-04-19T10:54:39Z
[ "python", "matplotlib", "plot", "graphing" ]
Get a specific string from a service list using WSDiscovery
2,553,582
<p>I am using the WSDiscovery module for python. I have been able to search for services on my network. I am trying to discover a client and get the XAddress from this. The WSDiscovery module has very little documentation, actually so little the only piece is in the readme file of the module which is a few lines long. ...
1
2010-03-31T14:05:57Z
2,553,824
<p>Looking at <a href="http://code.google.com/p/python-ws-discovery/source/browse/trunk/WSDiscovery.py?r=2" rel="nofollow">sources</a> you could see that </p> <p>1. searchServices signature has few parameters:</p> <pre><code>def searchServices(self, types=None, scopes=None, timeout=3) </code></pre> <p>and i don't th...
1
2010-03-31T14:36:15Z
[ "python", "string", "search", "list", "ws-discovery" ]
GAE HTTP method support
2,553,672
<p>I get an "unrecognized HTTP method" when trying to do a REPORT request using httplib and gae. Is there a workaround available? An httplib patch for gae? Do you I have to find another host in order to do this natively?</p> <p>According to the docs, only certain fetch actions are valid: GET, POST, HEAD, PUT, and DEL...
2
2010-03-31T14:18:10Z
2,554,542
<p>httplib on App Engine is a wrapper around the <a href="http://code.google.com/appengine/docs/python/urlfetch/overview.html#Requests" rel="nofollow">urlfetch API</a>, which only supports the GET, POST, PUT, HEAD and DELETE methods. I'm afraid you're out of luck unless the API you're accessing supports some sort of X-...
4
2010-03-31T16:10:32Z
[ "python", "google-app-engine", "httpwebrequest" ]
Django: Getting a Python encoding error when handling HTTP response in Latin1?
2,553,748
<p>I'm working in Django, and using urllib2 and simplejson to parse some information from an API.</p> <p>The problem is that the API returns information in the Latin-1 encoding, and just once in a while there's a character in there that causes Django to crash horribly with an encoding error. This is my code:</p> <pre...
1
2010-03-31T14:25:36Z
2,554,376
<p>Call <code>response.read()</code> to get the data of the response. Then in a <code>try/except</code> do your latin1 decoding and json loading. In general, Django should never crash if you wrap potentially error-causing operations in exception handlers and take care of them appropriately (at least log them somewhere ...
0
2010-03-31T15:47:43Z
[ "python", "django", "encoding", "character-encoding" ]
How can i bundle other files when using cx_freeze?
2,553,886
<p>I'm using Python 2.6 and cx_Freeze 4.1.2 on a Windows system. I've created the setup.py to build my executable and everything works fine.</p> <p>When cx_Freeze runs it moves everything to the build directory. I have some other files that I would like included in my build directory. How can I do this? Here's my stru...
40
2010-03-31T14:44:12Z
2,892,707
<p>Figured it out.</p> <pre><code>from cx_Freeze import setup,Executable includefiles = ['README.txt', 'CHANGELOG.txt', 'helpers\uncompress\unRAR.exe', , 'helpers\uncompress\unzip.exe'] includes = [] excludes = ['Tkinter'] packages = ['do','khh'] setup( name = 'myapp', version = '0.1', description = 'A g...
73
2010-05-23T17:31:24Z
[ "python", "distutils", "cx-freeze" ]
How can i bundle other files when using cx_freeze?
2,553,886
<p>I'm using Python 2.6 and cx_Freeze 4.1.2 on a Windows system. I've created the setup.py to build my executable and everything works fine.</p> <p>When cx_Freeze runs it moves everything to the build directory. I have some other files that I would like included in my build directory. How can I do this? Here's my stru...
40
2010-03-31T14:44:12Z
7,819,055
<p>There's a more complex example at <a href="http://wiki.wxpython.org/cx_freeze" rel="nofollow">http://wiki.wxpython.org/cx_freeze</a> The lacking documentation of all the options is at <a href="http://web.archive.org/web/20120622213400/http://cx-freeze.sourceforge.net/cx_Freeze.html" rel="nofollow">http://cx-freeze.s...
6
2011-10-19T09:18:00Z
[ "python", "distutils", "cx-freeze" ]
How can i bundle other files when using cx_freeze?
2,553,886
<p>I'm using Python 2.6 and cx_Freeze 4.1.2 on a Windows system. I've created the setup.py to build my executable and everything works fine.</p> <p>When cx_Freeze runs it moves everything to the build directory. I have some other files that I would like included in my build directory. How can I do this? Here's my stru...
40
2010-03-31T14:44:12Z
24,104,547
<p>Also you can create separate script that will copy files after the build. It's what I use to rebuild the app on windows (you should have "GNU utilities for win32" installed to make "cp" works). </p> <p>build.bat:</p> <pre><code>cd . del build\*.* /Q python setup.py build cp -r icons build/exe.win32-2.7/ cp -r inte...
0
2014-06-08T08:56:53Z
[ "python", "distutils", "cx-freeze" ]
How can i bundle other files when using cx_freeze?
2,553,886
<p>I'm using Python 2.6 and cx_Freeze 4.1.2 on a Windows system. I've created the setup.py to build my executable and everything works fine.</p> <p>When cx_Freeze runs it moves everything to the build directory. I have some other files that I would like included in my build directory. How can I do this? Here's my stru...
40
2010-03-31T14:44:12Z
38,916,822
<p>In order to find your attached files (include_files = [-> your attached files &lt;-]) you should insert the follwing function in your setup.py code:</p> <pre><code>def find_data_file(filename): if getattr(sys, 'frozen', False): # The application is frozen datadir = os.path.dirname(sys.executable) else: ...
0
2016-08-12T11:23:56Z
[ "python", "distutils", "cx-freeze" ]
How Do I code this in python with simplejson
2,553,954
<p>how do i code a python program that return a json element that look like this </p> <pre><code>{1:{'name':foo,'age':xl} 2:{'name':vee,'age':xx} .... } </code></pre> <p>What i meant is that i want return nested dictionaries </p> <p>What i hoped to accomplish is something like this</p> <pre><code>var foo = 1....
0
2010-03-31T14:53:39Z
2,553,976
<pre><code>&gt;&gt;&gt; import simplejson as json # "simplejson" works exactly the same as with "json" &gt;&gt;&gt; json.dumps({}) '{}' &gt;&gt;&gt; json.dumps({'asdf':1,'poi':[2,3,4,{'qwer':5}]}) '{"asdf": 1, "poi": [2, 3, 4, {"qwer": 5}]}' &gt;&gt;&gt; </code></pre>
3
2010-03-31T14:55:54Z
[ "python", "json" ]
Exponential distribution in Python
2,553,994
<p>What's the easiest way to draw a random number from an exponential distribution in Python?</p>
5
2010-03-31T14:58:03Z
2,554,032
<p><a href="http://docs.python.org/library/random.html?highlight=random#random.expovariate">random.expovariate</a> of course.</p>
11
2010-03-31T15:03:14Z
[ "python", "exponential-distribution" ]
Exponential distribution in Python
2,553,994
<p>What's the easiest way to draw a random number from an exponential distribution in Python?</p>
5
2010-03-31T14:58:03Z
2,554,306
<p>You can use the <code>random</code> module. For more information, consult <a href="http://docs.python.org/library/random.html" rel="nofollow">its documentation</a>.</p>
0
2010-03-31T15:37:42Z
[ "python", "exponential-distribution" ]
PyGTK, Glade, Changing the window view and threads
2,554,121
<p>Forgive me if this seems like a stupid question, just so far no where on the internet can I find someone offering a solution to this and I just wanted to get some feedback from someone with more experience than myself (I've only been using python, pyGTK and Glade for 2 days now).</p> <p>I have a UI window displayin...
2
2010-03-31T15:13:53Z
2,554,574
<p>If i well understand the connection is strictly coupled with the window. This seems like a good example of <a href="http://en.wikipedia.org/wiki/Class_diagram#Aggregation" rel="nofollow">aggregation</a> and <a href="http://en.wikipedia.org/wiki/Class_diagram#Composition" rel="nofollow">composition</a>. Simple decoup...
2
2010-03-31T16:14:23Z
[ "python", "multithreading", "pygtk", "glade" ]
PyGTK, Glade, Changing the window view and threads
2,554,121
<p>Forgive me if this seems like a stupid question, just so far no where on the internet can I find someone offering a solution to this and I just wanted to get some feedback from someone with more experience than myself (I've only been using python, pyGTK and Glade for 2 days now).</p> <p>I have a UI window displayin...
2
2010-03-31T15:13:53Z
2,786,478
<p>I think you already know, but GTK (PyGtk) is thread aware and not thread safe, so, modifying the UI from another thread that is not the one that holds gtk's main loop will probably make your program to crash.</p> <p>You can make use of the .glade files several times, you can use just one widget (and its children) i...
0
2010-05-07T05:52:17Z
[ "python", "multithreading", "pygtk", "glade" ]
python list mysteriously getting set to something within my django/piston handler
2,554,127
<p>To start, I'm very new to python, let alone Django and Piston.</p> <p>Note: (I've updated this since the first two suggestions... you can view the old post in txt form here: <a href="http://bennyland.com/old-2554127.txt" rel="nofollow">http://bennyland.com/old-2554127.txt</a>). The update I made was to better unde...
3
2010-03-31T15:14:55Z
2,554,944
<p>I would say that there is a basic flaw in your code, if <code>has_limit()</code> can return True when limit is a list of length 2, but this line will fail if limit is shorter than 3 elements long:</p> <pre><code>s_query = '%swith limit[%s,%s](limit,%s &gt; traceback:%s),' % (s_query, self.limit[0], self....
0
2010-03-31T17:05:36Z
[ "python", "django", "piston" ]
python list mysteriously getting set to something within my django/piston handler
2,554,127
<p>To start, I'm very new to python, let alone Django and Piston.</p> <p>Note: (I've updated this since the first two suggestions... you can view the old post in txt form here: <a href="http://bennyland.com/old-2554127.txt" rel="nofollow">http://bennyland.com/old-2554127.txt</a>). The update I made was to better unde...
3
2010-03-31T15:14:55Z
2,556,327
<p>I think you may be creating an alias to your internal limit list, via the <code>get_limit</code> property accessor. Try removing (or at least adding a print statement) inside this accessor. If you have code externally that binds a local list to get_limit, then it can update the contents using append, del, or assig...
0
2010-03-31T20:42:12Z
[ "python", "django", "piston" ]
How do I do a semijoin using SQLAlchemy?
2,554,132
<p><a href="http://en.wikipedia.org/wiki/Relational_algebra#Semijoin" rel="nofollow">http://en.wikipedia.org/wiki/Relational_algebra#Semijoin</a></p> <p>Let's say that I have two tables: A and B. I want to make a query that would work similarly to the following SQL statement using the SQLAlchemy orm:</p> <pre><code...
2
2010-03-31T15:15:36Z
2,559,649
<p>Let's assume you have models classes <code>A</code> and <code>B</code> mapped to corresponding tables. </p> <p>The simplest case is when you have relation in <code>A</code> pointing to <code>B</code>, let's name it <code>A.b</code>. Then you just use either <code>A.b.has(type='some type')</code> or <code>A.b.any(ty...
2
2010-04-01T10:20:57Z
[ "python", "sql", "orm", "sqlalchemy" ]
How do I access session data in Jinja2 templates (Bottle framework on app engine)?
2,554,174
<p>I'm running the micro framework <a href="http://bottle.paws.de/page/docs">Bottle</a> on Google App Engine. I'm using <a href="http://jinja.pocoo.org/2/">Jinja2</a> for my templates. And I'm using <a href="http://pypi.python.org/pypi/Beaker/0.9.4">Beaker</a> to handle the sessions. I'm still a pretty big Python ne...
7
2010-03-31T15:19:58Z
2,554,466
<p>You can add things to the Jinja2 <a href="http://jinja.pocoo.org/2/documentation/api#jinja2.Environment.globals">environment globals</a> if you want them to be accessible to all templates. See <a href="http://jinja.pocoo.org/2/documentation/api#global-namespace">this page</a> for additional information.</p> <p><str...
10
2010-03-31T16:01:47Z
[ "python", "google-app-engine", "session", "jinja2", "beaker" ]
Match groups in Python
2,554,185
<p>Is there a way in Python to access match groups without explicitely creating a match object (or another way to beautify the example below)?</p> <p>Here is an example to clarify my motivation for the question:</p> <p>Following perl code </p> <pre><code>if ($statement =~ /I love (\w+)/) { print "He loves $1\n"...
24
2010-03-31T15:21:06Z
2,554,238
<p>Less efficient, but simpler-looking:</p> <pre><code>m0 = re.match("I love (\w+)", statement) m1 = re.match("Ich liebe (\w+)", statement) m2 = re.match("Je t'aime (\w+)", statement) if m0: print "He loves",m0.group(1) elif m1: print "Er liebt",m1.group(1) elif m2: print "Il aime",m2.group(1) </code></pre> <p>...
12
2010-03-31T15:28:43Z
[ "python", "regex" ]
Match groups in Python
2,554,185
<p>Is there a way in Python to access match groups without explicitely creating a match object (or another way to beautify the example below)?</p> <p>Here is an example to clarify my motivation for the question:</p> <p>Following perl code </p> <pre><code>if ($statement =~ /I love (\w+)/) { print "He loves $1\n"...
24
2010-03-31T15:21:06Z
2,554,286
<p>this is not a regex solution.</p> <pre><code>alist={"I love ":""He loves"","Je t'aime ":"Il aime","Ich liebe ":"Er liebt"} for k in alist.keys(): if k in statement: print alist[k],statement.split(k)[1:] </code></pre>
2
2010-03-31T15:35:21Z
[ "python", "regex" ]
Match groups in Python
2,554,185
<p>Is there a way in Python to access match groups without explicitely creating a match object (or another way to beautify the example below)?</p> <p>Here is an example to clarify my motivation for the question:</p> <p>Following perl code </p> <pre><code>if ($statement =~ /I love (\w+)/) { print "He loves $1\n"...
24
2010-03-31T15:21:06Z
2,554,295
<p>You could create a helper function:</p> <pre><code>def re_match_group(pattern, str, out_groups): del out_groups[:] result = re.match(pattern, str) if result: out_groups[:len(result.groups())] = result.groups() return result </code></pre> <p>And then use it like this:</p> <pre><code>groups ...
1
2010-03-31T15:36:44Z
[ "python", "regex" ]
Match groups in Python
2,554,185
<p>Is there a way in Python to access match groups without explicitely creating a match object (or another way to beautify the example below)?</p> <p>Here is an example to clarify my motivation for the question:</p> <p>Following perl code </p> <pre><code>if ($statement =~ /I love (\w+)/) { print "He loves $1\n"...
24
2010-03-31T15:21:06Z
2,555,047
<p>You could create a little class that returns the boolean result of calling match, <em>and</em> retains the matched groups for subsequent retrieval:</p> <pre><code>import re class REMatcher(object): def __init__(self, matchstring): self.matchstring = matchstring def match(self,regexp): self...
23
2010-03-31T17:20:10Z
[ "python", "regex" ]