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
Subclassing Decimal in Python
2,044,427
<p>I want to use Decimal class in my Python program for doing financial calculations. Decimals to not work with floats - they need explicit conversion to strings first. So i decided to subclass Decimal to be able to work with floats without explicit conversions.</p> <p>m_Decimal.py:</p> <pre><code># -*- coding: utf-8...
1
2010-01-11T19:42:31Z
2,061,509
<p>Use cdecimal or decimal.py from 2.7 or 3.2. All of those have the from_float class method:</p> <pre><code> class MyDecimal(Decimal): def convert(self, v): if isinstance(v, float): return Decimal.from_float(v) else: return Decimal(v) def __mul__(self, other): o...
0
2010-01-14T00:56:31Z
[ "python", "decimal", "subclassing" ]
Determine if directory is under git control
2,044,574
<p>How can I tell if a given directory is part of a git respository?</p> <p>(The following is in python, but bash or something would be fine.)</p> <pre><code>os.path.isdir('.svn') </code></pre> <p>will tell you if the current directory is controlled by Subversion. Mercurial and Git just have a .hg/.git at the top of...
48
2010-01-11T20:07:43Z
2,044,646
<p>Well, the directory can also be ignored by the .gitignore file - so you need to check for a .git repository, and if there is one, parse the .gitignore to see whether that directory is indeed in the git repository.</p> <p>What exactly do you want to do? There may be a simpler way to do this.</p> <p>EDIT: Do you mea...
4
2010-01-11T20:20:22Z
[ "python", "git" ]
Determine if directory is under git control
2,044,574
<p>How can I tell if a given directory is part of a git respository?</p> <p>(The following is in python, but bash or something would be fine.)</p> <pre><code>os.path.isdir('.svn') </code></pre> <p>will tell you if the current directory is controlled by Subversion. Mercurial and Git just have a .hg/.git at the top of...
48
2010-01-11T20:07:43Z
2,044,677
<p>In ruby, <code>system('git rev-parse')</code> will return true if the current directory is in a git repo, and false otherwise. I imagine the pythonic equivalent should work similarly.</p> <p><strong>EDIT:</strong> Sure enough:</p> <pre><code># in a git repo, running ipython &gt;&gt;&gt; system('git rev-parse') 0 ...
35
2010-01-11T20:27:25Z
[ "python", "git" ]
Determine if directory is under git control
2,044,574
<p>How can I tell if a given directory is part of a git respository?</p> <p>(The following is in python, but bash or something would be fine.)</p> <pre><code>os.path.isdir('.svn') </code></pre> <p>will tell you if the current directory is controlled by Subversion. Mercurial and Git just have a .hg/.git at the top of...
48
2010-01-11T20:07:43Z
2,044,679
<p>For the record, use git status or similar, this is just for completeness: :)</p> <p>Searching upward a tree is no biggie really, in bash you can do this simple one-liner (if you put it on one line...) ;) Returns 0 if one is found, 1 otherwise.</p> <pre><code>d=`pwd` while [ "$d" != "" ]; do [ -d "$d"/.git ] &amp...
4
2010-01-11T20:27:48Z
[ "python", "git" ]
Determine if directory is under git control
2,044,574
<p>How can I tell if a given directory is part of a git respository?</p> <p>(The following is in python, but bash or something would be fine.)</p> <pre><code>os.path.isdir('.svn') </code></pre> <p>will tell you if the current directory is controlled by Subversion. Mercurial and Git just have a .hg/.git at the top of...
48
2010-01-11T20:07:43Z
2,044,714
<p>Just found this in <code>git help rev-parse</code></p> <pre><code>git rev-parse --is-inside-work-tree </code></pre> <p>prints <code>true</code> if it is in the work tree, <code>false</code> if it's in the '.git' tree, and fatal error if it's neither. Both 'true' and 'false' are printed on stdout with an exit statu...
70
2010-01-11T20:33:46Z
[ "python", "git" ]
Determine if directory is under git control
2,044,574
<p>How can I tell if a given directory is part of a git respository?</p> <p>(The following is in python, but bash or something would be fine.)</p> <pre><code>os.path.isdir('.svn') </code></pre> <p>will tell you if the current directory is controlled by Subversion. Mercurial and Git just have a .hg/.git at the top of...
48
2010-01-11T20:07:43Z
2,044,872
<p>Add this to your .bash_profile, and your prompt will always show the active git branch and whether you have uncommitted changes.</p> <pre><code>function parse_git_dirty { [[ $(git status 2&gt; /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] &amp;&amp; echo "*" } function parse_git_branch...
1
2010-01-11T20:57:20Z
[ "python", "git" ]
Determine if directory is under git control
2,044,574
<p>How can I tell if a given directory is part of a git respository?</p> <p>(The following is in python, but bash or something would be fine.)</p> <pre><code>os.path.isdir('.svn') </code></pre> <p>will tell you if the current directory is controlled by Subversion. Mercurial and Git just have a .hg/.git at the top of...
48
2010-01-11T20:07:43Z
14,593,883
<p>From <strong>git help rev-parse</strong> again, I think you can do something like : </p> <pre><code>git rev-parse --resolve-git-dir &lt;directory&gt; </code></pre> <p>and check if the command returns the directory path itself. According to the manual git rev-parse returns the path to the directory if the argument...
1
2013-01-29T23:17:32Z
[ "python", "git" ]
Determine if directory is under git control
2,044,574
<p>How can I tell if a given directory is part of a git respository?</p> <p>(The following is in python, but bash or something would be fine.)</p> <pre><code>os.path.isdir('.svn') </code></pre> <p>will tell you if the current directory is controlled by Subversion. Mercurial and Git just have a .hg/.git at the top of...
48
2010-01-11T20:07:43Z
27,452,421
<p>I did a bit of experimenting to see what Git considers as a Git repository.</p> <p>As of 1.9.1, the minimal directory structure that must be inside a <code>.git</code> directory for Git to consider it is:</p> <pre><code>mkdir objects refs printf 'ref: refs/' &gt; HEAD </code></pre> <p>as recognized by <code>rev-p...
1
2014-12-12T21:30:27Z
[ "python", "git" ]
Determine if directory is under git control
2,044,574
<p>How can I tell if a given directory is part of a git respository?</p> <p>(The following is in python, but bash or something would be fine.)</p> <pre><code>os.path.isdir('.svn') </code></pre> <p>will tell you if the current directory is controlled by Subversion. Mercurial and Git just have a .hg/.git at the top of...
48
2010-01-11T20:07:43Z
29,238,645
<p>If you'd prefer to look for a <code>.git</code>directory, here's a cute way of doing that in Ruby:</p> <pre class="lang-rb prettyprint-override"><code>require 'pathname' def gitcheck() Pathname.pwd.ascend {|p| return true if (p + ".git").directory? } false end </code></pre> <p>I'm unable to find something sim...
0
2015-03-24T17:01:06Z
[ "python", "git" ]
Determine if directory is under git control
2,044,574
<p>How can I tell if a given directory is part of a git respository?</p> <p>(The following is in python, but bash or something would be fine.)</p> <pre><code>os.path.isdir('.svn') </code></pre> <p>will tell you if the current directory is controlled by Subversion. Mercurial and Git just have a .hg/.git at the top of...
48
2010-01-11T20:07:43Z
39,956,648
<p>With Python, you can make a function like this:</p> <pre><code>import git ... def is_git_repo(path): try: _ = git.Repo(path).git_dir return True except git.exc.InvalidGitRepositoryError: return False </code></pre>
0
2016-10-10T10:54:03Z
[ "python", "git" ]
Python XMLRPC: Handling arbitrary exceptions on client-side
2,044,904
<p>I'm trying to pass arbitrary exceptions from a XMLRPC server to a client (both Python scripts, exception types are defined on both sides). There's an exemplary client-side implementation at <a href="http://code.activestate.com/recipes/365244/" rel="nofollow">ActiveState Recipes</a> which parses the returned "faultSt...
1
2010-01-11T21:01:14Z
2,045,579
<p>You could populate the <code>allowed_errors</code> list from <code>__builtins__</code>:</p> <pre><code>[exc for exc in __builtins__ if isinstance(exc, BaseException)] </code></pre> <p>This would handle the common case, for built-in exceptions like <code>ValueError</code>, <code>TypeError</code>, <code>OSError</cod...
2
2010-01-11T23:01:24Z
[ "python", "xml-rpc", "xmlrpclib" ]
Pythonize Me: how to manage caller context variables in Python? (Python/Django)
2,044,941
<p>I'm trying to refactor a fairly hefty view function in Django. There are too many variables floating around and it's a huge function.</p> <p>Ideally, I want to modularize the view into logical functions. However, I have to pass the function context around to get easy access to the variables.</p> <p>For example:</...
4
2010-01-11T21:06:27Z
2,045,011
<p>I like (d) - Create a class for it, and use member functions to do the work.</p> <p>In Django, a view is just a 'callable' that accepts an HTTPRequest object, and whatever other paramaters your URL routing passes to it.</p> <p>Python classes can be callable just like functions, if you define a <code>__call__</code...
10
2010-01-11T21:18:18Z
[ "python", "django", "django-context" ]
Pythonize Me: how to manage caller context variables in Python? (Python/Django)
2,044,941
<p>I'm trying to refactor a fairly hefty view function in Django. There are too many variables floating around and it's a huge function.</p> <p>Ideally, I want to modularize the view into logical functions. However, I have to pass the function context around to get easy access to the variables.</p> <p>For example:</...
4
2010-01-11T21:06:27Z
2,045,028
<p>May I suggest to use something similar to d), like so:</p> <pre><code>class ComplexView_SharedVariables: # Shared variables (to be used as instance variables, not class variables!) a = "somevalue" b = ... c = ... class ComplexView_Methods1: ... some functionality ... class ComplexView_Methods2: ... so...
0
2010-01-11T21:20:12Z
[ "python", "django", "django-context" ]
Pass session information from php to python securely? (in agile)
2,045,131
<p>I have a sign up process that is in a legacy framework and we are trying to switch to a new framework...in fact a different language. So let's say that there are 3 steps in the sign up process and each of those 3 steps has it's own file(step1.php, step2.php, step3.php).<br> Now if I want to change page2.php to a pyt...
2
2010-01-11T21:36:25Z
2,045,154
<p>In PHP, store the session information in a database, encoded in JSON. In Python, pull the session ID from the cookie and look up the session information in the database.</p>
2
2010-01-11T21:41:32Z
[ "php", "python", "session" ]
Regex match even number of letters
2,045,175
<p>I need to match an expression in Python with regular expressions that only matches even number of letter occurrences. For example:</p> <pre> AAA # no match AA # match fsfaAAasdf # match sAfA # match sdAAewAsA # match AeAiA # no match </pre> <p>An even number of As SHOULD match.</p>
4
2010-01-11T21:46:19Z
2,045,187
<p><code>'A*'</code> means match any number of <code>A</code>'s. Even 0.</p> <p>Here's how to match a string with an even number of a's, upper or lower:</p> <pre><code>re.compile(r''' ^ [^a]* ( ( a[^a]* ){2} # if there must be at least 2 (not just 0), change the # '*' ...
2
2010-01-11T21:48:35Z
[ "python", "regex" ]
Regex match even number of letters
2,045,175
<p>I need to match an expression in Python with regular expressions that only matches even number of letter occurrences. For example:</p> <pre> AAA # no match AA # match fsfaAAasdf # match sAfA # match sdAAewAsA # match AeAiA # no match </pre> <p>An even number of As SHOULD match.</p>
4
2010-01-11T21:46:19Z
2,045,190
<p>First of all, note that <code>/A*/</code> matches the empty string.</p> <p>Secondly, there are some things that you just can't do with regular expressions. This'll be a lot easier if you just walk through the string and count up all occurences of the letter you're looking for.</p>
0
2010-01-11T21:49:01Z
[ "python", "regex" ]
Regex match even number of letters
2,045,175
<p>I need to match an expression in Python with regular expressions that only matches even number of letter occurrences. For example:</p> <pre> AAA # no match AA # match fsfaAAasdf # match sAfA # match sdAAewAsA # match AeAiA # no match </pre> <p>An even number of As SHOULD match.</p>
4
2010-01-11T21:46:19Z
2,045,196
<p>A* means match "A" zero or more times.</p> <p>For an even number of "A", try: (AA)+</p>
0
2010-01-11T21:49:51Z
[ "python", "regex" ]
Regex match even number of letters
2,045,175
<p>I need to match an expression in Python with regular expressions that only matches even number of letter occurrences. For example:</p> <pre> AAA # no match AA # match fsfaAAasdf # match sAfA # match sdAAewAsA # match AeAiA # no match </pre> <p>An even number of As SHOULD match.</p>
4
2010-01-11T21:46:19Z
2,045,208
<p>Try this regular expression:</p> <pre><code>^[^A]*((AA)+[^A]*)*$ </code></pre> <p>And if the <code>A</code>s don’t need to be consecutive:</p> <pre><code>^[^A]*(A[^A]*A[^A]*)*$ </code></pre>
13
2010-01-11T21:51:21Z
[ "python", "regex" ]
Regex match even number of letters
2,045,175
<p>I need to match an expression in Python with regular expressions that only matches even number of letter occurrences. For example:</p> <pre> AAA # no match AA # match fsfaAAasdf # match sAfA # match sdAAewAsA # match AeAiA # no match </pre> <p>An even number of As SHOULD match.</p>
4
2010-01-11T21:46:19Z
2,045,237
<p>It's <strong>impossible</strong> to count <strong>arbitrarily</strong> using regular expressions. For example, making sure that you have matching parenthesis. To count you need 'memory' which requires something at least as strong as a <a href="http://en.wikipedia.org/wiki/Pushdown_automaton" rel="nofollow">pushdown...
0
2010-01-11T21:56:11Z
[ "python", "regex" ]
Regex match even number of letters
2,045,175
<p>I need to match an expression in Python with regular expressions that only matches even number of letter occurrences. For example:</p> <pre> AAA # no match AA # match fsfaAAasdf # match sAfA # match sdAAewAsA # match AeAiA # no match </pre> <p>An even number of As SHOULD match.</p>
4
2010-01-11T21:46:19Z
2,045,286
<p>'*' means 0 or more occurences 'AA' should do the trick.</p> <p>The question is if you want the thing to match 'AAA'. In that case you would have to do something like:</p> <pre><code>r = re.compile('(^|[^A])(AA)+(?!A)',) r.search(p) </code></pre> <p>That would work for match even (and only even) number of'A'.</p>...
1
2010-01-11T22:02:54Z
[ "python", "regex" ]
Regex match even number of letters
2,045,175
<p>I need to match an expression in Python with regular expressions that only matches even number of letter occurrences. For example:</p> <pre> AAA # no match AA # match fsfaAAasdf # match sAfA # match sdAAewAsA # match AeAiA # no match </pre> <p>An even number of As SHOULD match.</p>
4
2010-01-11T21:46:19Z
2,047,291
<p>This searches for a block with an odd number of A's. If you found one, the string is bad for you:</p> <pre><code>(?&lt;!A)A(AA)*(?!A) </code></pre> <p>If I understand correctly, the Python code should look like:</p> <pre><code>if re.search("(?&lt;!A)A(AA)*(?!A)", "AeAAi"): print "fail" </code></pre>
1
2010-01-12T07:01:16Z
[ "python", "regex" ]
Regex match even number of letters
2,045,175
<p>I need to match an expression in Python with regular expressions that only matches even number of letter occurrences. For example:</p> <pre> AAA # no match AA # match fsfaAAasdf # match sAfA # match sdAAewAsA # match AeAiA # no match </pre> <p>An even number of As SHOULD match.</p>
4
2010-01-11T21:46:19Z
2,049,173
<p>Why work so hard coming up with a hard to read pattern? Just search for all occurrences of the pattern and count how many you find. </p> <pre><code>len(re.findall("A", "AbcAbcAbcA")) % 2 == 0 </code></pre> <p>That should be instantly understandable by all experienced programmers, whereas a pattern like "(? <p>Sim...
0
2010-01-12T13:20:31Z
[ "python", "regex" ]
Good backend for downloading nzb files to seperate directories
2,045,215
<p>I'm laying out a download management that will segregate each users downloads, separate watched directories each download to their own folders, can't see each others queues, etc. </p> <p>I wanted to use Hellanzb with xml-rpc, however it does not seem to allow me to set separate download directories for each file. I...
0
2010-01-11T21:52:42Z
2,045,272
<p>I'd check out <a href="http://github.com/maddox/pyrot" rel="nofollow">http://github.com/maddox/pyrot</a>. It may do what you need.</p>
0
2010-01-11T22:01:05Z
[ "python", "network-programming", "xml-rpc", "nntp", "usenet" ]
django, location based searches
2,045,318
<p>Excuse my ignorance, I am not even sure of the correct term for this. What I want to do is search by city and state or zip code in my django application and also include results within certain distances of the location (25, 50, 75 miles).</p> <p>I am guessing you probably need to convert the city and state or zip ...
8
2010-01-11T22:08:36Z
2,045,361
<p>You could use <a href="http://geodjango.org/">GeoDjango</a>, which already includes these features. Otherwise you can do exactly as you said: geocode addresses to get latitude and longitude, then just do the math ;-)</p>
7
2010-01-11T22:16:48Z
[ "python", "django", "geolocation", "geodjango" ]
django, location based searches
2,045,318
<p>Excuse my ignorance, I am not even sure of the correct term for this. What I want to do is search by city and state or zip code in my django application and also include results within certain distances of the location (25, 50, 75 miles).</p> <p>I am guessing you probably need to convert the city and state or zip ...
8
2010-01-11T22:08:36Z
6,301,164
<p>You can also use MongoDB which will have better optimization, cf. <a href="http://stackoverflow.com/questions/3182260/python-geocode-filtering-by-distance">Python geocode filtering by distance</a></p> <p><a href="http://www.mongodb.org/display/DOCS/Geospatial+Indexing" rel="nofollow">http://www.mongodb.org/display/...
2
2011-06-10T01:47:33Z
[ "python", "django", "geolocation", "geodjango" ]
PyQt & unittest - Testing signal and slots
2,045,352
<p>I have a pyqt application that I'm writing unit tests for, and it relies heavily on signals and slots. To properly test it, I have to check that the correct signals are sent.</p> <p>What is the best way to do this? I see that the Qt library has a QSignalSpy, but I can't find any reference to this in PyQt. The only ...
3
2010-01-11T22:14:28Z
2,048,095
<p>You can try connecting a slot to your signal, prepare your test, then call qApp.processEvents() to let the signal propagate. But I don't think it's 100% reliable.</p> <p>It's a pity that QSignalSpy is not part of PyQt indeed.</p>
1
2010-01-12T10:10:28Z
[ "python", "pyqt", "unit-testing" ]
PyQt & unittest - Testing signal and slots
2,045,352
<p>I have a pyqt application that I'm writing unit tests for, and it relies heavily on signals and slots. To properly test it, I have to check that the correct signals are sent.</p> <p>What is the best way to do this? I see that the Qt library has a QSignalSpy, but I can't find any reference to this in PyQt. The only ...
3
2010-01-11T22:14:28Z
2,063,216
<p>This is a more elaborate version of what I suggested myself, not necessarily the best solution for unittest, but I think it will be of interest to others that come across this:</p> <p>Posted by Carlos Scheidegger on the pyqt mailing list (http://thread.gmane.org/gmane.comp.python.pyqt-pykde/9242/focus=9245)</p> <p...
1
2010-01-14T09:32:54Z
[ "python", "pyqt", "unit-testing" ]
PyQt & unittest - Testing signal and slots
2,045,352
<p>I have a pyqt application that I'm writing unit tests for, and it relies heavily on signals and slots. To properly test it, I have to check that the correct signals are sent.</p> <p>What is the best way to do this? I see that the Qt library has a QSignalSpy, but I can't find any reference to this in PyQt. The only ...
3
2010-01-11T22:14:28Z
9,016,397
<p><a href="http://www.commandprompt.com/community/pyqt/x5255.htm" rel="nofollow">Testing signals and slots with PyQT</a></p>
2
2012-01-26T09:59:41Z
[ "python", "pyqt", "unit-testing" ]
PyQt & unittest - Testing signal and slots
2,045,352
<p>I have a pyqt application that I'm writing unit tests for, and it relies heavily on signals and slots. To properly test it, I have to check that the correct signals are sent.</p> <p>What is the best way to do this? I see that the Qt library has a QSignalSpy, but I can't find any reference to this in PyQt. The only ...
3
2010-01-11T22:14:28Z
34,305,923
<p>Note QSignalSpy is <a href="http://pyqt.sourceforge.net/Docs/PyQt5/api/qsignalspy.html" rel="nofollow">available</a> as <code>QtTest.QSignalSpy</code> in PyQt5.</p>
0
2015-12-16T07:10:42Z
[ "python", "pyqt", "unit-testing" ]
How to catch an exception in python and get a reference to the exception, WITHOUT knowing the type?
2,045,786
<p>I'm wondering how I can catch <strong>any</strong> raised object (i.e. a type that does not extend <code>Exception</code>), and still get a reference to it.</p> <p>I came across the desire to do this when using Jython. When calling a Java method, if that method raises an exception, it will not extend Python's <co...
19
2010-01-11T23:51:30Z
2,045,828
<p>You can reference exceptions using the <a href="http://docs.python.org/library/sys.html"><code>sys</code></a> module. <a href="http://docs.python.org/library/sys.html#sys.exc_info"><code>sys.exc_info</code></a> is a tuple of the type, the instance and the traceback.</p> <pre><code>import sys try: # some call t...
31
2010-01-12T00:01:25Z
[ "python", "exception-handling", "jython" ]
How to catch an exception in python and get a reference to the exception, WITHOUT knowing the type?
2,045,786
<p>I'm wondering how I can catch <strong>any</strong> raised object (i.e. a type that does not extend <code>Exception</code>), and still get a reference to it.</p> <p>I came across the desire to do this when using Jython. When calling a Java method, if that method raises an exception, it will not extend Python's <co...
19
2010-01-11T23:51:30Z
17,442,748
<p>Just for anyone interested... I spent a bit of time testing stuff because I wanted to find out how to get a proper stack trace whether a Python Exception (BaseException in fact, which is the base class) or a java.lang.Throwable (java base class for Exception, Error, etc.) is thrown... this code illustrates how to ca...
5
2013-07-03T08:03:58Z
[ "python", "exception-handling", "jython" ]
How to catch an exception in python and get a reference to the exception, WITHOUT knowing the type?
2,045,786
<p>I'm wondering how I can catch <strong>any</strong> raised object (i.e. a type that does not extend <code>Exception</code>), and still get a reference to it.</p> <p>I came across the desire to do this when using Jython. When calling a Java method, if that method raises an exception, it will not extend Python's <co...
19
2010-01-11T23:51:30Z
20,632,454
<p>FWIW, I have found that if you add this import to your Jython script:</p> <pre><code>from java.lang import Exception </code></pre> <p>and just use the conventional Python Exception handler:</p> <pre><code>except Exception, e: </code></pre> <p>it will catch <em>both</em> Python exceptions <em>and</em> Java except...
7
2013-12-17T11:04:26Z
[ "python", "exception-handling", "jython" ]
'Invalid Key' error from Paramiko
2,045,880
<p>I'm trying to set up Fabric for deploying my Python web application and Paramiko is barfing on my private RSA key. I had been using my key successfully for 6 months, so I know it's good. In case having a passphrase was the problem, I just made a new key with no passphrase and still get the error. Help?</p>
0
2010-01-12T00:15:30Z
2,069,885
<p>I don't know if this helps you but here's how I set my SSH user/key in fabric.</p> <pre><code>env.user = "username" env.key_filename = "/path/to/ssh/keyfile" </code></pre> <p>And it seems to work fine.</p>
1
2010-01-15T06:37:56Z
[ "python", "ssh", "fabric", "paramiko" ]
PEP8 - 80 Characters - Big Integers
2,045,968
<p>This is somehow related to <a href="http://stackoverflow.com/questions/1874592/pep8-80-characters-big-strings">question about big strings and PEP8</a>.</p> <p>How can I make my script that has the following line PEP8 compliant ("Maximum Line Length" rule)?</p> <pre><code>pub_key = { 'e': 32268333626801261010362...
11
2010-01-12T00:45:19Z
2,045,979
<p>I don't think you can. The guidelines in PEP8 are guidelines, there are situations where it's just not possible to follow the guideline.</p>
2
2010-01-12T00:48:40Z
[ "python", "coding-style", "pep8" ]
PEP8 - 80 Characters - Big Integers
2,045,968
<p>This is somehow related to <a href="http://stackoverflow.com/questions/1874592/pep8-80-characters-big-strings">question about big strings and PEP8</a>.</p> <p>How can I make my script that has the following line PEP8 compliant ("Maximum Line Length" rule)?</p> <pre><code>pub_key = { 'e': 32268333626801261010362...
11
2010-01-12T00:45:19Z
2,045,984
<blockquote> <p>But most importantly: know when to be inconsistent -- sometimes the style guide just doesn't apply. When in doubt, use your best judgment.</p> </blockquote> <p><a href="http://www.python.org/dev/peps/pep-0008/">source</a></p> <p>In this case, I would just leave the big integers as is.</p>
21
2010-01-12T00:50:13Z
[ "python", "coding-style", "pep8" ]
PEP8 - 80 Characters - Big Integers
2,045,968
<p>This is somehow related to <a href="http://stackoverflow.com/questions/1874592/pep8-80-characters-big-strings">question about big strings and PEP8</a>.</p> <p>How can I make my script that has the following line PEP8 compliant ("Maximum Line Length" rule)?</p> <pre><code>pub_key = { 'e': 32268333626801261010362...
11
2010-01-12T00:45:19Z
2,045,985
<p>import this</p> <blockquote> <p>... Special cases aren't special enough to break the rules. Although practicality beats purity. ...</p> </blockquote>
2
2010-01-12T00:50:18Z
[ "python", "coding-style", "pep8" ]
PEP8 - 80 Characters - Big Integers
2,045,968
<p>This is somehow related to <a href="http://stackoverflow.com/questions/1874592/pep8-80-characters-big-strings">question about big strings and PEP8</a>.</p> <p>How can I make my script that has the following line PEP8 compliant ("Maximum Line Length" rule)?</p> <pre><code>pub_key = { 'e': 32268333626801261010362...
11
2010-01-12T00:45:19Z
2,045,994
<pre><code>'e': 3226833362680126101036263622033066816222202666130162062116461326212012L \ * 10**45 \ + 222403311326222666622610430466620224662364142L </code></pre> <p>I in no way endorse this.</p>
4
2010-01-12T00:52:43Z
[ "python", "coding-style", "pep8" ]
PEP8 - 80 Characters - Big Integers
2,045,968
<p>This is somehow related to <a href="http://stackoverflow.com/questions/1874592/pep8-80-characters-big-strings">question about big strings and PEP8</a>.</p> <p>How can I make my script that has the following line PEP8 compliant ("Maximum Line Length" rule)?</p> <pre><code>pub_key = { 'e': 32268333626801261010362...
11
2010-01-12T00:45:19Z
2,045,997
<p>best way I can think of is</p> <pre><code>pub_key = { 'e': long('3226833362680126101036263622033066816222202666130162062116461326' '212012222403311326222666622610430466620224662364142'), 'n': long('2264210038610412484628262261030226082203282422044226842326403312' '3822023222632161626...
5
2010-01-12T00:53:33Z
[ "python", "coding-style", "pep8" ]
PEP8 - 80 Characters - Big Integers
2,045,968
<p>This is somehow related to <a href="http://stackoverflow.com/questions/1874592/pep8-80-characters-big-strings">question about big strings and PEP8</a>.</p> <p>How can I make my script that has the following line PEP8 compliant ("Maximum Line Length" rule)?</p> <pre><code>pub_key = { 'e': 32268333626801261010362...
11
2010-01-12T00:45:19Z
4,733,332
<p>This can be done. Long lines can be broken over multiple lines by wrapping expressions in parentheses. Here is where it is explained:</p> <p><a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">http://www.python.org/dev/peps/pep-0008/</a></p>
1
2011-01-19T08:55:09Z
[ "python", "coding-style", "pep8" ]
Tab Completion in Python Command Line Interface - how to catch Tab events
2,046,050
<p>I'm writing a little CLI in Python (as an extension to Mercurial) and would like to support tab-completion. Specifically, I would like catch tabs in the prompt and show a list of matching options (just like bash).</p> <p>Example: Enter section name:</p> <pre><code> ext*TAB* extensions extras </code></pre> <...
5
2010-01-12T01:11:57Z
2,046,054
<p>For that you use the <a href="http://docs.python.org/library/readline.html"><code>readline</code></a> module.</p> <p>Simplest code I can think:</p> <pre><code>import readline COMMANDS = ['extra', 'extension', 'stuff', 'errors', 'email', 'foobar', 'foo'] def complete(text, state): for cmd in COMMAN...
15
2010-01-12T01:13:35Z
[ "python", "mercurial", "tab-completion", "raw-input" ]
Tab Completion in Python Command Line Interface - how to catch Tab events
2,046,050
<p>I'm writing a little CLI in Python (as an extension to Mercurial) and would like to support tab-completion. Specifically, I would like catch tabs in the prompt and show a list of matching options (just like bash).</p> <p>Example: Enter section name:</p> <pre><code> ext*TAB* extensions extras </code></pre> <...
5
2010-01-12T01:11:57Z
2,046,074
<p>An excellent example of how to do tab-completion in cooperation with <a href="http://docs.python.org/library/readline.html#module-readline" rel="nofollow">readline</a> is supplied in the standard library as the <a href="http://docs.python.org/library/rlcompleter.html" rel="nofollow">rlcompleter</a> module — you ca...
2
2010-01-12T01:22:01Z
[ "python", "mercurial", "tab-completion", "raw-input" ]
Tab Completion in Python Command Line Interface - how to catch Tab events
2,046,050
<p>I'm writing a little CLI in Python (as an extension to Mercurial) and would like to support tab-completion. Specifically, I would like catch tabs in the prompt and show a list of matching options (just like bash).</p> <p>Example: Enter section name:</p> <pre><code> ext*TAB* extensions extras </code></pre> <...
5
2010-01-12T01:11:57Z
2,046,770
<p>You should almost certainly be using the <a href="http://docs.python.org/library/cmd.html" rel="nofollow">cmd module</a>, which already implements tab completion and so on, and probably other parts of what you're trying to do, using the readline module and so on. There's no point reinventing the wheel.</p>
1
2010-01-12T04:49:50Z
[ "python", "mercurial", "tab-completion", "raw-input" ]
i have '__contains__' ,why error
2,046,209
<pre><code>class a(object): def a(self): return True __contains__=a b=a() print 2 in b#why error </code></pre>
1
2010-01-12T02:01:50Z
2,046,225
<p><code>__contains__</code> is meant to take an argument. <code>a</code> doesn't accept an argument.</p> <p>The following is your example with a working <code>__contains__</code>:</p> <pre><code>&gt;&gt;&gt; class a(object): ... def a(self, item): ... return True ... __contains__=a ... &gt;&gt;&gt; b...
6
2010-01-12T02:04:01Z
[ "python" ]
i have '__contains__' ,why error
2,046,209
<pre><code>class a(object): def a(self): return True __contains__=a b=a() print 2 in b#why error </code></pre>
1
2010-01-12T02:01:50Z
2,046,229
<p>The signature of <code>__contains__</code> is:</p> <p><code>object.__contains__(self, item)</code></p> <p>as per <a href="http://docs.python.org/reference/datamodel.html#object.__contains__" rel="nofollow">documentation</a>. You need to extend your "a" method:</p> <p><code>def a(self, item)</code></p> <pre><code...
2
2010-01-12T02:05:14Z
[ "python" ]
Getting String from A TextCtrl Box
2,046,338
<p>I cannot seem to grasp how I would get the strings from a text Ctrl box. I am very new to this, so any help is greatly appricated. Here is the practic code:</p> <pre><code>import wx class citPanel(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) wx.StaticText(s...
7
2010-01-12T02:36:39Z
2,046,354
<pre><code>TextCtrlInstance.GetValue() </code></pre>
15
2010-01-12T02:41:08Z
[ "python", "wxpython", "textctrl" ]
Getting String from A TextCtrl Box
2,046,338
<p>I cannot seem to grasp how I would get the strings from a text Ctrl box. I am very new to this, so any help is greatly appricated. Here is the practic code:</p> <pre><code>import wx class citPanel(wx.Panel): def __init__(self, parent, id): wx.Panel.__init__(self, parent, id) wx.StaticText(s...
7
2010-01-12T02:36:39Z
2,046,355
<p>Use <code>GetValue()</code>, not <code>GetString()</code></p> <p>Look at the API: <a href="http://docs.wxwidgets.org/stable/wx_wxtextctrl.html" rel="nofollow">http://docs.wxwidgets.org/stable/wx_wxtextctrl.html</a></p>
1
2010-01-12T02:41:13Z
[ "python", "wxpython", "textctrl" ]
Is it possible to run function in a subprocess without threading or writing a separate file/script
2,046,603
<pre><code>import subprocess def my_function(x): return x + 100 output = subprocess.Popen(my_function, 1) #I would like to pass the function object and its arguments print output #desired output: 101 </code></pre> <p>I have only found documentation on opening subprocesses using separate scripts. Does anyone kno...
34
2010-01-12T03:49:53Z
2,046,630
<p>I think you're looking for something more like the multiprocessing module:</p> <p><a href="http://docs.python.org/library/multiprocessing.html#the-process-class">http://docs.python.org/library/multiprocessing.html#the-process-class</a></p> <p>The subprocess module is for spawning processes and doing things with th...
49
2010-01-12T03:57:13Z
[ "python", "function", "subprocess", "popen" ]
Is it possible to run function in a subprocess without threading or writing a separate file/script
2,046,603
<pre><code>import subprocess def my_function(x): return x + 100 output = subprocess.Popen(my_function, 1) #I would like to pass the function object and its arguments print output #desired output: 101 </code></pre> <p>I have only found documentation on opening subprocesses using separate scripts. Does anyone kno...
34
2010-01-12T03:49:53Z
2,046,633
<p>You can use the standard Unix <code>fork</code> system call, as <a href="http://docs.python.org/library/os.html#os.fork"><code>os.fork()</code></a>. <code>fork()</code> will create a new process, with the same script running. In the new process, it will return 0, while in the old process it will return the process I...
8
2010-01-12T03:58:47Z
[ "python", "function", "subprocess", "popen" ]
Is it possible to run function in a subprocess without threading or writing a separate file/script
2,046,603
<pre><code>import subprocess def my_function(x): return x + 100 output = subprocess.Popen(my_function, 1) #I would like to pass the function object and its arguments print output #desired output: 101 </code></pre> <p>I have only found documentation on opening subprocesses using separate scripts. Does anyone kno...
34
2010-01-12T03:49:53Z
2,046,641
<p>I believe that you are looking for the <a href="http://docs.python.org/3.1/library/multiprocessing.html" rel="nofollow">multiprocessing</a> module.</p>
1
2010-01-12T04:01:22Z
[ "python", "function", "subprocess", "popen" ]
Is it possible to run function in a subprocess without threading or writing a separate file/script
2,046,603
<pre><code>import subprocess def my_function(x): return x + 100 output = subprocess.Popen(my_function, 1) #I would like to pass the function object and its arguments print output #desired output: 101 </code></pre> <p>I have only found documentation on opening subprocesses using separate scripts. Does anyone kno...
34
2010-01-12T03:49:53Z
25,171,005
<p>Brian McKenna's above post about multiprocessing is really helpful, but if you wanted to go down the threaded route (opposed to process-based), this example will get you started:</p> <pre><code>import threading import time def blocker(): while True: print "Oh, sorry, am I in the way?" time.slee...
2
2014-08-06T22:02:24Z
[ "python", "function", "subprocess", "popen" ]
record output sound in python
2,046,663
<p>i want to programatically record sound coming out of my laptop in python. i found <code>PyAudio</code> and came up with the following program that accomplishes the task:</p> <pre><code>import pyaudio, wave, sys chunk = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 44100 RECORD_SECONDS = 5 WAVE_OUTPUT_FILENAME...
8
2010-01-12T04:08:25Z
2,046,677
<p>unfortunately, theres no foolproof way to do it, but <a href="http://www.rogueamoeba.com/audiohijack/" rel="nofollow">Audio Hijack</a> and <a href="http://www.ambrosiasw.com/utilities/wiretap/" rel="nofollow">Wiretap</a> are the best tools available for that.</p>
0
2010-01-12T04:15:24Z
[ "python", "osx", "audio", "audio-streaming" ]
record output sound in python
2,046,663
<p>i want to programatically record sound coming out of my laptop in python. i found <code>PyAudio</code> and came up with the following program that accomplishes the task:</p> <pre><code>import pyaudio, wave, sys chunk = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 44100 RECORD_SECONDS = 5 WAVE_OUTPUT_FILENAME...
8
2010-01-12T04:08:25Z
4,603,212
<p>You can install <a href="http://cycling74.com/products/soundflower/" rel="nofollow">Soundflower</a>, which allows you to create extra audio devices and route audio between them. This way you can define your system's output to the Soundflower device and read the audio from it using PyAudio.</p> <p>You can also take ...
4
2011-01-05T10:50:12Z
[ "python", "osx", "audio", "audio-streaming" ]
Creating waitable objects in Python
2,046,727
<p>I more or less know how to use select() to take a list of sockets, and only return the ones that are ready to read/write something. The project I'm working on now has a class called 'user'. Each 'user' object contains its own socket. What I would like to do is pass a list of users to a select(), and get back a li...
1
2010-01-12T04:28:37Z
2,046,760
<p>You should have your <code>User</code> class implement a <code>fileno(self)</code> method which returns <code>self.thesocket.fileno()</code> -- that's the way to make <code>select</code> work on your own classes (sockets only on windows, arbitrary files on Unix-like systems). Not sure what <code>switch</code> is su...
2
2010-01-12T04:44:43Z
[ "python", "sockets" ]
Pylons "global name 'c' is not defined"
2,046,789
<p>i had setup Pylons v0.9.7, and created a project using genshi. I tried to code an easy test case, but it is not working.</p> <p>code: member.py</p> <pre><code>coding: utf-8 import logging import foo.model from foo.lib.base import * log = logging.getLogger(__name__) class MemberController(BaseController): ...
1
2010-01-12T04:56:27Z
2,046,817
<pre><code> c.title="title" </code></pre> <p>requires name <code>c</code> to be defined (globally or locally). You never define <strong>anything</strong> named <code>c</code>.</p> <p>So, define a suitable name <code>c</code> (one where attribute <code>title</code> can be set!) before you assign anything to <code>...
3
2010-01-12T05:05:43Z
[ "python", "pylons", "genshi" ]
Google App Engine singletons (Python)
2,046,802
<p>The standard way of doing singletons in Python is</p> <pre><code>class Singleton(object): _instance = None def __new__(cls, *args, **kwargs): if not cls._instance: cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs) return cls._instance </code></pre> <p>However, ...
2
2010-01-12T04:59:45Z
2,046,824
<p><code>__init__</code> cannot usefully <code>return</code> anything: just like in the first example, override <code>__new__</code> instead!</p>
1
2010-01-12T05:06:56Z
[ "python", "google-app-engine", "singleton", "gae-datastore" ]
Google App Engine singletons (Python)
2,046,802
<p>The standard way of doing singletons in Python is</p> <pre><code>class Singleton(object): _instance = None def __new__(cls, *args, **kwargs): if not cls._instance: cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs) return cls._instance </code></pre> <p>However, ...
2
2010-01-12T04:59:45Z
2,051,497
<p>Singletons are usually a bad idea, and I'd be interested to see what makes this an exception. Typically they're just globals in disguise, and apart from all the old problems with globals (eg. see <a href="http://c2.com/cgi/wiki?GlobalVariablesAreBad" rel="nofollow">http://c2.com/cgi/wiki?GlobalVariablesAreBad</a>, i...
4
2010-01-12T18:49:43Z
[ "python", "google-app-engine", "singleton", "gae-datastore" ]
Google App Engine singletons (Python)
2,046,802
<p>The standard way of doing singletons in Python is</p> <pre><code>class Singleton(object): _instance = None def __new__(cls, *args, **kwargs): if not cls._instance: cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs) return cls._instance </code></pre> <p>However, ...
2
2010-01-12T04:59:45Z
2,066,646
<p>If you aren't going to store the data in the datastore, why don't you just create a module with variables instead of a db.Model?</p> <p>Name your file <code>mysettings.py</code> and inside it write:</p> <pre><code>sitename = "My site" footer = "This page owned by X" </code></pre> <p>Then the python module effecti...
2
2010-01-14T18:48:35Z
[ "python", "google-app-engine", "singleton", "gae-datastore" ]
Google App Engine singletons (Python)
2,046,802
<p>The standard way of doing singletons in Python is</p> <pre><code>class Singleton(object): _instance = None def __new__(cls, *args, **kwargs): if not cls._instance: cls._instance = super(Singleton, cls).__new__(cls, *args, **kwargs) return cls._instance </code></pre> <p>However, ...
2
2010-01-12T04:59:45Z
12,077,446
<p>I don't think there's a real "singleton" object you can hold in a distributed environment with multiple instances running. The closest you can come to this is using memcache.</p> <p>Perhaps it's better to think less in terms of singletons and more in terms of data consistency. For this App Engine provides <a href="...
0
2012-08-22T16:25:07Z
[ "python", "google-app-engine", "singleton", "gae-datastore" ]
geodjango - search by city, state or zip code
2,046,887
<p>How can I use geodjango to search by city and state or zip code in my django application? I am very new to geodjango and just trying to wrap my head around what would be involved in this.</p> <p>Also, does anyone know of an app that already implements this functionality?</p>
0
2010-01-12T05:25:10Z
2,298,879
<p>First thing you need to do is create a ZipCode model which will be table of geometry objects that represent each zipcode. You'll also need to have another model that you'll be searching, which needs to have a geographic location field. Then you'd do something like:</p> <pre><code>zip = 10010 zipcode = ZipCode.objec...
2
2010-02-19T19:08:27Z
[ "python", "django", "geodjango" ]
geodjango - search by city, state or zip code
2,046,887
<p>How can I use geodjango to search by city and state or zip code in my django application? I am very new to geodjango and just trying to wrap my head around what would be involved in this.</p> <p>Also, does anyone know of an app that already implements this functionality?</p>
0
2010-01-12T05:25:10Z
7,258,668
<p>I am going to try something similar soon... I have a small database of about 40 locations, and I want the user to be able to filter these 40 locations by entering any zip code or city name, using a function that will return a list of location that are within a 5, 10, 15, 20, etc radius distance.</p> <p>I am thinkin...
0
2011-08-31T14:41:22Z
[ "python", "django", "geodjango" ]
os.listdir etc fails on shared windows path (Python 2.5)
2,046,912
<p>I am seeing some weird behavior while parsing shared paths (shared paths on server, e.g. \storage\Builds)</p> <p>I am reading text file which contains directory paths which I want to process further. In order to do so I do as below:</p> <pre><code>def toWin(path): return path.replace("\\", "\\\\") for line in...
0
2010-01-12T05:32:24Z
2,046,917
<p>This may not be your actual issue, but your UNC paths are actually not correct - they should start with a double backslash, but internally only use a single backslash as a divider.</p> <p>I'm not sure why the same thing would be working within the shell.</p> <p><strong>Update:</strong> I suspect that what's happen...
0
2010-01-12T05:37:29Z
[ "python", "path" ]
os.listdir etc fails on shared windows path (Python 2.5)
2,046,912
<p>I am seeing some weird behavior while parsing shared paths (shared paths on server, e.g. \storage\Builds)</p> <p>I am reading text file which contains directory paths which I want to process further. In order to do so I do as below:</p> <pre><code>def toWin(path): return path.replace("\\", "\\\\") for line in...
0
2010-01-12T05:32:24Z
2,051,646
<p>Have to convert input to forward slash (unix-style) for os.* modules to parse correctly.</p> <p>changed code as below</p> <pre><code>def toUnix(path): return path.replace("\\", "/") </code></pre> <p>Now all modules parse correctly.</p>
-1
2010-01-12T19:15:05Z
[ "python", "path" ]
os.listdir etc fails on shared windows path (Python 2.5)
2,046,912
<p>I am seeing some weird behavior while parsing shared paths (shared paths on server, e.g. \storage\Builds)</p> <p>I am reading text file which contains directory paths which I want to process further. In order to do so I do as below:</p> <pre><code>def toWin(path): return path.replace("\\", "\\\\") for line in...
0
2010-01-12T05:32:24Z
2,119,270
<p>There is simply no reason to "convert". Backslashes are only interpreted when they are contained in string literals in your code, not when you read them programmatically from a file. Therefore, you should disable your conversion function and things will probably work.</p>
0
2010-01-22T17:46:51Z
[ "python", "path" ]
architecture of chat website using twisted matrix
2,046,973
<p>I am willing to devlop a anonymus chat website.The website pairs 2 random people who are logged into the website and then allows them to chat to each other.Now if any one of them gets disconnected then the other will get connected to any other person who is single.</p> <p>Now i have some doubts regarding archicture...
1
2010-01-12T05:55:53Z
2,049,906
<p>Take a look at <a href="http://divmod.org/trac/wiki/DivmodNevow" rel="nofollow">Nevow</a> and <a href="http://divmod.org/trac/wiki/DivmodNevow/Athena" rel="nofollow">Athena</a>. These will let you serve web pages to clients and handle messages sent back from them.</p>
3
2010-01-12T15:09:04Z
[ "python", "chat", "twisted" ]
Find new messages added to an imap mailbox since I last checked with python imaplib2?
2,047,067
<p>I am trying to write a program that monitors an IMAP mailbox and automatically copies every new incoming message into an "Archive" folder. I'm using imaplib2 which implements the IDLE command. Here's my basic program:</p> <pre><code>M = imaplib2.IMAP4("mail.me.com") M.login(username,password) lst = M.list() assert ...
3
2010-01-12T06:12:57Z
2,047,153
<p>See example and references in <a href="http://blog.hokkertjes.nl/2009/03/11/python-imap-idle-with-imaplib2/" rel="nofollow">python-imap-idle-with-imaplib2</a>. The module involves threading, you should pay attention to event synchronization.</p> <p>The example suggests synchronizing with events, and leaves mail pro...
1
2010-01-12T06:31:40Z
[ "python", "imap", "python-idle", "imaplib" ]
Find new messages added to an imap mailbox since I last checked with python imaplib2?
2,047,067
<p>I am trying to write a program that monitors an IMAP mailbox and automatically copies every new incoming message into an "Archive" folder. I'm using imaplib2 which implements the IDLE command. Here's my basic program:</p> <pre><code>M = imaplib2.IMAP4("mail.me.com") M.login(username,password) lst = M.list() assert ...
3
2010-01-12T06:12:57Z
2,512,451
<p>I am finding that recent() is a bit vague (this is an IMAP vagueness, not imaplib2). Seems better to keep a list of message numbers before and after idle, and the difference is new messages.</p> <p>Then use fetch(messages,"UID") to get the message uid.</p>
1
2010-03-25T00:48:00Z
[ "python", "imap", "python-idle", "imaplib" ]
What is/are the Python equivalent(s) to the Java Collections Framework?
2,047,220
<p>The Java Collections Framework is like the C++ Standard Template Library: "a unified architecture for representing and manipulating collections (objects that group multiple elements into a single unit)."</p> <p><a href="http://java.sun.com/docs/books/tutorial/collections/intro/index.html" rel="nofollow">http://java...
4
2010-01-12T06:50:09Z
2,047,256
<p>As it turns out, the equivalent to the Java Collections Framework in Python is... Python. All of the core collections featured in the Java Collections Framework are already present in core Python.</p> <p>Give it a try! Sequences provide lists, queues, stacks, etc. Dictionaries are your hash-tables and maps. Set...
13
2010-01-12T06:55:49Z
[ "java", "c++", "python", "collections" ]
What is/are the Python equivalent(s) to the Java Collections Framework?
2,047,220
<p>The Java Collections Framework is like the C++ Standard Template Library: "a unified architecture for representing and manipulating collections (objects that group multiple elements into a single unit)."</p> <p><a href="http://java.sun.com/docs/books/tutorial/collections/intro/index.html" rel="nofollow">http://java...
4
2010-01-12T06:50:09Z
2,047,273
<p>Other than the built-ins you might what to check out <a href="http://docs.python.org/library/collections.html?highlight=collections#module-collections">collections</a>.</p> <pre><code>&gt;&gt;&gt; import collections &gt;&gt;&gt; dir(collections) ['Callable', 'Container', 'Hashable', 'ItemsView', 'Iterable', 'Iterat...
7
2010-01-12T06:58:27Z
[ "java", "c++", "python", "collections" ]
How to use Python to get local admins from a computer on the Network?
2,047,355
<p>I need to get a list of all people in the company who have local admin rights on their computers. We have a group on each machine called "Administrators." I can get a list of all computers from active directory with:</p> <pre><code>import active_directory for computer in active_directory.search ("objectCategory='C...
0
2010-01-12T07:23:27Z
2,047,390
<p>Is this the data from this operation going to be manipulated afterwards? If this is a manual scan that is going to be looked at by a human, then you're way overthinking it.</p> <p>Just use a network scanner to handle it for you, such as <a href="http://www.softperfect.com/products/networkscanner/" rel="nofollow">th...
0
2010-01-12T07:31:25Z
[ "python", "active-directory", "winreg" ]
How to use Python to get local admins from a computer on the Network?
2,047,355
<p>I need to get a list of all people in the company who have local admin rights on their computers. We have a group on each machine called "Administrators." I can get a list of all computers from active directory with:</p> <pre><code>import active_directory for computer in active_directory.search ("objectCategory='C...
0
2010-01-12T07:23:27Z
2,047,857
<p>I'm not sure of the details but it sounds like you may want to take a look at the <a href="http://timgolden.me.uk/python/wmi/index.html" rel="nofollow">WMI</a> package.</p> <p>Back when I was playing with COM and the windows registry and ran across it. It looks like it's been improved a bit since when I looked at ...
0
2010-01-12T09:24:58Z
[ "python", "active-directory", "winreg" ]
Unit testing file write in Python
2,047,459
<p>I am writing a wrapper for the <code>ConfigParser</code> in Python to provide an easy interface for storing and retrieving application settings.</p> <p>The wrapper has two methods, <code>read</code> and <code>write</code>, and a set of properties for the different application settings.</p> <p>The <code>write</code...
1
2010-01-12T07:47:23Z
2,047,469
<p>Actually, only open could throw an exception in your code. The docs for write() doesn't say anything about exceptions. Possibly only a ValueError or something for a bad file pointer (as a result of open failing, which can't be the case here).</p> <p>Making an IOError for open is easy. Just create the file elsewhere...
4
2010-01-12T07:49:53Z
[ "python", "unit-testing", "file-io" ]
Unit testing file write in Python
2,047,459
<p>I am writing a wrapper for the <code>ConfigParser</code> in Python to provide an easy interface for storing and retrieving application settings.</p> <p>The wrapper has two methods, <code>read</code> and <code>write</code>, and a set of properties for the different application settings.</p> <p>The <code>write</code...
1
2010-01-12T07:47:23Z
2,047,559
<p>Remember you don't have to test that open() or ConfigParser work&mdash;they're not part of your code&mdash;you just have to test that you use them correctly. You can monkeypatch the module with your own open(), just as for the instance attribute, and can return a mock from it that helps you test.</p> <p>However, u...
2
2010-01-12T08:13:32Z
[ "python", "unit-testing", "file-io" ]
Unit testing file write in Python
2,047,459
<p>I am writing a wrapper for the <code>ConfigParser</code> in Python to provide an easy interface for storing and retrieving application settings.</p> <p>The wrapper has two methods, <code>read</code> and <code>write</code>, and a set of properties for the different application settings.</p> <p>The <code>write</code...
1
2010-01-12T07:47:23Z
2,047,577
<p>First, you don't actually need to unit test <code>open()</code>, since it's pretty reasonable to assume that the standard library is correct.</p> <p>Next, you don't want to do file system manipulations to get <code>open()</code> to generate the error you want, because then you're not unit testing, you're doing a fu...
5
2010-01-12T08:18:35Z
[ "python", "unit-testing", "file-io" ]
Dithering in text using PIL and truetype fonts
2,047,534
<p>Consider the following code: from PIL import Image, ImageDraw, ImageFont</p> <pre><code>def addText(img, lTxt): FONT_SIZE = 10 INTERLINE_DISTANCE = FONT_SIZE + 1 font = ImageFont.truetype('arial.ttf', FONT_SIZE) lTxtImageHeight = INTERLINE_DISTANCE * len(lTxt) # create text image lTxtIm...
0
2010-01-12T08:08:24Z
2,047,747
<p>I suggest writing the intermediate text images to file (the text, then the rotated text), to isolate where the artefacts first appear.</p> <p>One other possibility could be that the png encoding is using a pallete with no grayscale values, so those reds are the closest available. I checked the encoding of the files...
0
2010-01-12T09:05:17Z
[ "python", "text", "python-imaging-library", "dithering" ]
Is it possible to store Python class objects in SQLite?
2,047,814
<p>I would like to store Python objects into a <a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> database. Is that possible?</p> <p>If so what would be some links / examples for it?</p>
17
2010-01-12T09:17:47Z
2,047,827
<p>You can use <a href="http://docs.python.org/library/pickle.html" rel="nofollow">pickle</a> to serialize the object. The serialized object can be inserted to the sqlite DB as a bytearray field.</p> <pre><code>f=open('object.dump', 'rw') pickle.dump(obj, f) </code></pre> <p>Now read <code>object.dump</code> from the...
1
2010-01-12T09:19:38Z
[ "python", "sqlite", "serialization" ]
Is it possible to store Python class objects in SQLite?
2,047,814
<p>I would like to store Python objects into a <a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> database. Is that possible?</p> <p>If so what would be some links / examples for it?</p>
17
2010-01-12T09:17:47Z
2,047,840
<p>One option is to use an O/R mapper like <a href="http://sqlobject.org/" rel="nofollow">SQLObject.</a> It will do most of the plumbing to persist the Python object to a database, and it supports SQLite. As mentioned elsewhere you can also serialise the object using a method such as pickle, which dumps out a represe...
0
2010-01-12T09:22:14Z
[ "python", "sqlite", "serialization" ]
Is it possible to store Python class objects in SQLite?
2,047,814
<p>I would like to store Python objects into a <a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> database. Is that possible?</p> <p>If so what would be some links / examples for it?</p>
17
2010-01-12T09:17:47Z
2,047,844
<p>You can't store the object itself in the DB. What you do is to store the data from the object and reconstruct it later.</p> <p>A good way is to use the excellent <a href="http://www.sqlalchemy.org">SQLAlchemy</a> library. It lets you map your defined class to a table in the database. Every mapped attribute will be ...
34
2010-01-12T09:22:47Z
[ "python", "sqlite", "serialization" ]
Is it possible to store Python class objects in SQLite?
2,047,814
<p>I would like to store Python objects into a <a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> database. Is that possible?</p> <p>If so what would be some links / examples for it?</p>
17
2010-01-12T09:17:47Z
2,047,861
<p>You other choice instead of pickling is to use an <strong>ORM</strong>. This lets you map rows in a database to an object. See <a href="http://wiki.python.org/moin/HigherLevelDatabaseProgramming" rel="nofollow">http://wiki.python.org/moin/HigherLevelDatabaseProgramming</a> for a starting point. I'd recommend <a href...
1
2010-01-12T09:25:40Z
[ "python", "sqlite", "serialization" ]
Is it possible to store Python class objects in SQLite?
2,047,814
<p>I would like to store Python objects into a <a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> database. Is that possible?</p> <p>If so what would be some links / examples for it?</p>
17
2010-01-12T09:17:47Z
2,047,863
<p>Yes it's possible but there are different approaches and which one is the suitable one, will depend on your requirements.</p> <ul> <li><p><strong>Pickling</strong></p> <p>You can use the <a href="http://docs.python.org/library/pickle.html">pickle</a> module to serialize objects, then store these objects in a blo...
8
2010-01-12T09:26:00Z
[ "python", "sqlite", "serialization" ]
Is it possible to store Python class objects in SQLite?
2,047,814
<p>I would like to store Python objects into a <a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> database. Is that possible?</p> <p>If so what would be some links / examples for it?</p>
17
2010-01-12T09:17:47Z
2,047,885
<p>You can use <a href="http://docs.python.org/library/pickle.html#what-can-be-pickled-and-unpickled" rel="nofollow">pickle.dumps</a>, its return pickable objects as strings, you would not need to write it to temporary files.</p> <blockquote> <p>Return the pickled representation of the object as a <strong>string</...
3
2010-01-12T09:30:40Z
[ "python", "sqlite", "serialization" ]
Is it possible to store Python class objects in SQLite?
2,047,814
<p>I would like to store Python objects into a <a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> database. Is that possible?</p> <p>If so what would be some links / examples for it?</p>
17
2010-01-12T09:17:47Z
15,393,171
<p>There is relatively simple way to store and compare objects, eaven to index those objects right way and to restrict (with ubique) columns containing objects. And all of that without using ORM engines. Objects mast be stored using pickle dump (so performance might be a issue) Here is example for storing python tuple...
0
2013-03-13T18:09:12Z
[ "python", "sqlite", "serialization" ]
Is it possible to store Python class objects in SQLite?
2,047,814
<p>I would like to store Python objects into a <a href="http://en.wikipedia.org/wiki/SQLite">SQLite</a> database. Is that possible?</p> <p>If so what would be some links / examples for it?</p>
17
2010-01-12T09:17:47Z
38,349,607
<p>Depending on your exact needs, it could be worth looking into Django (www.djangoproject.com) for this task. Django is actually a web framework, but one of the tasks it handles is to allow you to define Models as python objects (inheriting from a base class provided by the framework). It will then automatically creat...
0
2016-07-13T10:51:53Z
[ "python", "sqlite", "serialization" ]
How to plot a graph in Python?
2,048,041
<p>I have installed Matplotlib, and I have created two lists, x and y.</p> <p>I want the x-axis to have values from 0 to 100 in steps of 10 and the y-axis to have values from 0 to 1 in steps of 0.1. How do I plot this graph?</p>
5
2010-01-12T10:02:03Z
2,048,090
<p>Have a look through the matplotlib <a href="http://matplotlib.sourceforge.net/gallery.html">gallery</a>, all the graphs there have their source code available. Find one you like, cut &amp; paste, dissect!</p>
9
2010-01-12T10:10:02Z
[ "python", "matplotlib" ]
How to plot a graph in Python?
2,048,041
<p>I have installed Matplotlib, and I have created two lists, x and y.</p> <p>I want the x-axis to have values from 0 to 100 in steps of 10 and the y-axis to have values from 0 to 1 in steps of 0.1. How do I plot this graph?</p>
5
2010-01-12T10:02:03Z
10,303,500
<p>There is a very good book:</p> <p>Sandro Tosi, Matplotlib for Python Developers, Packt Pub., 2009.</p>
2
2012-04-24T18:05:25Z
[ "python", "matplotlib" ]
How to plot a graph in Python?
2,048,041
<p>I have installed Matplotlib, and I have created two lists, x and y.</p> <p>I want the x-axis to have values from 0 to 100 in steps of 10 and the y-axis to have values from 0 to 1 in steps of 0.1. How do I plot this graph?</p>
5
2010-01-12T10:02:03Z
22,584,367
<p>Use <a href="http://scipy-lectures.github.io/intro/matplotlib/matplotlib.html#setting-limits" rel="nofollow">xlim and ylim</a> to set the range to be displayed, [0; 100] and [0; 1] in this case. Use <a href="http://scipy-lectures.github.io/intro/matplotlib/matplotlib.html#setting-ticks" rel="nofollow">xticks and yti...
0
2014-03-22T22:17:04Z
[ "python", "matplotlib" ]
Sql Alchemy What is wrong?
2,048,084
<p>I got the tutorial </p> <blockquote> <p><a href="http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html">http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html</a></p> </blockquote> <p>When I compile got the error message</p> <pre><code>The debugged program raised the exception unhandled NameError "name 'BoundM...
10
2010-01-12T10:09:17Z
2,048,136
<p>This tutorial is for SQLAlchemy version 0.2. Since the actual version is 0.5.7, I'd say the tutorial is severely outdated.</p> <p>Try the <a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html">official</a> one instead.</p> <hr> <p><strong>EDIT:</strong></p> <p>Now you have a completely different question. ...
16
2010-01-12T10:18:53Z
[ "python", "mysql", "sqlalchemy" ]
Sql Alchemy What is wrong?
2,048,084
<p>I got the tutorial </p> <blockquote> <p><a href="http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html">http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html</a></p> </blockquote> <p>When I compile got the error message</p> <pre><code>The debugged program raised the exception unhandled NameError "name 'BoundM...
10
2010-01-12T10:09:17Z
2,048,220
<p>I believe you need to specify the length of your <code>password</code> field.</p> <pre><code>Column('password', String(100)) </code></pre> <p>MySQL does not allow unbounded varchar columns. If you need that, use the sqlalchemy datatype <a href="http://www.sqlalchemy.org/docs/05/reference/sqlalchemy/types.html#sqla...
2
2010-01-12T10:32:50Z
[ "python", "mysql", "sqlalchemy" ]
Sql Alchemy What is wrong?
2,048,084
<p>I got the tutorial </p> <blockquote> <p><a href="http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html">http://www.rmunn.com/sqlalchemy-tutorial/tutorial.html</a></p> </blockquote> <p>When I compile got the error message</p> <pre><code>The debugged program raised the exception unhandled NameError "name 'BoundM...
10
2010-01-12T10:09:17Z
11,069,954
<p>The fix for the tutorial is to just use <code>MetaData</code> instead of <code>BoundMetaData</code>. BoundMetaData is deprecated and replaced with MetaData.</p> <p>And to avoid getting such error in future, Try the <a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html">official</a> one instead, as <code>Nosk...
17
2012-06-17T08:28:36Z
[ "python", "mysql", "sqlalchemy" ]
PyQt4 signals and slots
2,048,098
<p>I am writing my first Python app with PyQt4. I have a MainWindow and a Dialog class, which is a part of MainWindow class:</p> <pre><code>self.loginDialog = LoginDialog(); </code></pre> <p>I use slots and signals. Here's a connection made in MainWindow:</p> <pre><code>QtCore.QObject.connect(self.loginDialog, QtCor...
5
2010-01-12T10:10:48Z
2,048,224
<p>I haven't used PyQT4 but take a look at <a href="http://zetcode.com/tutorials/pyqt4/eventsandsignals/" rel="nofollow">here</a>.</p>
0
2010-01-12T10:33:38Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
PyQt4 signals and slots
2,048,098
<p>I am writing my first Python app with PyQt4. I have a MainWindow and a Dialog class, which is a part of MainWindow class:</p> <pre><code>self.loginDialog = LoginDialog(); </code></pre> <p>I use slots and signals. Here's a connection made in MainWindow:</p> <pre><code>QtCore.QObject.connect(self.loginDialog, QtCor...
5
2010-01-12T10:10:48Z
2,048,248
<p>Looks like you miss the "SLOT" part in your connect call.</p> <p>Here is an example :</p> <pre><code>QtCore.QObject.connect(self.loginDialog, QtCore.SIGNAL("NotifyMySignal(int)"), QtCore.SLOT("onNotifyMySignal(int)")); </code></pre> <p>then </p> <pre><code>self.emit(QtCore.SIGNAL('NotifyMySignal(1)')); </code></...
0
2010-01-12T10:39:50Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
PyQt4 signals and slots
2,048,098
<p>I am writing my first Python app with PyQt4. I have a MainWindow and a Dialog class, which is a part of MainWindow class:</p> <pre><code>self.loginDialog = LoginDialog(); </code></pre> <p>I use slots and signals. Here's a connection made in MainWindow:</p> <pre><code>QtCore.QObject.connect(self.loginDialog, QtCor...
5
2010-01-12T10:10:48Z
2,048,611
<p>You don't use the same signal, when emitting and connecting. </p> <p><code>QtCore.SIGNAL("aa(str)")</code> is not the same as <code>QtCore.SIGNAL("aa")</code>. Signals must have the same signature. By the way, if you are defining your own signals, don't define parametres. Just write SIGNAL('aa'), because defining p...
10
2010-01-12T11:44:46Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
PyQt4 signals and slots
2,048,098
<p>I am writing my first Python app with PyQt4. I have a MainWindow and a Dialog class, which is a part of MainWindow class:</p> <pre><code>self.loginDialog = LoginDialog(); </code></pre> <p>I use slots and signals. Here's a connection made in MainWindow:</p> <pre><code>QtCore.QObject.connect(self.loginDialog, QtCor...
5
2010-01-12T10:10:48Z
2,048,836
<p>As noted by gruszczy you have to use the same QtCore.SIGNAL('xxx') to connect signal and to emit it. Also I think you should use Qt types in the arguments list of signal function. E.g.:</p> <pre><code>QtCore.QObject.connect(self.loginDialog, QtCore.SIGNAL("aa(QString&amp;)"), self.login) </code></pre> <p>And then ...
1
2010-01-12T12:23:07Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
PyQt4 signals and slots
2,048,098
<p>I am writing my first Python app with PyQt4. I have a MainWindow and a Dialog class, which is a part of MainWindow class:</p> <pre><code>self.loginDialog = LoginDialog(); </code></pre> <p>I use slots and signals. Here's a connection made in MainWindow:</p> <pre><code>QtCore.QObject.connect(self.loginDialog, QtCor...
5
2010-01-12T10:10:48Z
2,052,300
<p>What @bialix suggested should have worked, but try an alternative way of connecting:</p> <pre><code>class Foo(QtCore.QObject): mysignal = QtCore.pyqtSignal(str, name='mysignal') def connect_to_signal(self): # you can use this syntax instead of the 'old' one self.mysignal.connect(self.myslot...
2
2010-01-12T20:55:53Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
PyQt4 signals and slots
2,048,098
<p>I am writing my first Python app with PyQt4. I have a MainWindow and a Dialog class, which is a part of MainWindow class:</p> <pre><code>self.loginDialog = LoginDialog(); </code></pre> <p>I use slots and signals. Here's a connection made in MainWindow:</p> <pre><code>QtCore.QObject.connect(self.loginDialog, QtCor...
5
2010-01-12T10:10:48Z
2,083,789
<p>I checked your code and it looks like the problem is in the way how you're connecting your signal</p> <ol> <li><p>you emit the signal in Ui_Dialog class</p> <p>self.emit(QtCore.SIGNAL("aa()"))</p></li> <li><p>you connect to the signal in Ui_MainWindow's setupUi method by calling</p> <p>QtCore.QObject.connect(self...
3
2010-01-18T03:45:01Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
PyQt4 signals and slots
2,048,098
<p>I am writing my first Python app with PyQt4. I have a MainWindow and a Dialog class, which is a part of MainWindow class:</p> <pre><code>self.loginDialog = LoginDialog(); </code></pre> <p>I use slots and signals. Here's a connection made in MainWindow:</p> <pre><code>QtCore.QObject.connect(self.loginDialog, QtCor...
5
2010-01-12T10:10:48Z
7,618,282
<p>There are some concepts to be clarified</p> <p><strong>[QT signal &amp; slot] VS [Python signal &amp; slot]</strong></p> <p>All the predefined signals &amp; slots provided by pyqt are implemented by QT's c++ code. Whenever you want to have a customized signal &amp; slot in Python, it is a python signal &amp; slot....
26
2011-10-01T05:00:01Z
[ "python", "qt", "qt4", "pyqt", "pyqt4" ]
if there any better way to read bb function souce code.i was very faint
2,048,163
<pre><code>in python ,if a.py from b import bb bb() b.py from c import cc def bb(): do someting else cc() c.py from d import dd def cc(): do someting else dd() d.py from e import ee def dd(): do someting else ee() e.py from f import ff def ee(): do someting else ff() </code></pre> <p>to Understo...
-1
2010-01-12T10:24:17Z
2,048,191
<p>The best way to import the <code>ff</code> function from the <code>f</code> module would be to use an import statement in your program:</p> <pre><code>from f import ff ff(...) </code></pre> <p>Or you could use the form:</p> <pre><code>import f f.ff(...) </code></pre> <p><strong>EDIT:</strong></p> <p>If you are ...
2
2010-01-12T10:28:23Z
[ "python" ]
if there any better way to read bb function souce code.i was very faint
2,048,163
<pre><code>in python ,if a.py from b import bb bb() b.py from c import cc def bb(): do someting else cc() c.py from d import dd def cc(): do someting else dd() d.py from e import ee def dd(): do someting else ee() e.py from f import ff def ee(): do someting else ff() </code></pre> <p>to Understo...
-1
2010-01-12T10:24:17Z
2,048,260
<p>Whoever wrote the code for file a.py should have just written</p> <p>a.py</p> <p>from f import ff</p> <p>I mean isn't that what OO and modules are supposed to do: make code reusable?</p> <p>Or maybe this is an example of obfuscation by tiresomeness.</p>
0
2010-01-12T10:41:50Z
[ "python" ]
if there any better way to read bb function souce code.i was very faint
2,048,163
<pre><code>in python ,if a.py from b import bb bb() b.py from c import cc def bb(): do someting else cc() c.py from d import dd def cc(): do someting else dd() d.py from e import ee def dd(): do someting else ee() e.py from f import ff def ee(): do someting else ff() </code></pre> <p>to Understo...
-1
2010-01-12T10:24:17Z
2,063,027
<p>If you're not already using an IDE, you might like to give <a href="http://bpython-interpreter.org/screenshots/" rel="nofollow">bpython</a> a try</p>
0
2010-01-14T08:46:40Z
[ "python" ]
Error when using astWCS trying to create WCS object
2,048,166
<p>I'm running python2.5 and trying to use the astLib library to analyse WCS information in astronomical images. I try and get the object instanciated with the following skeleton code:</p> <pre><code>from astLib import astWCS w = astWCS.WCS('file.fits') # error here </code></pre> <p>where file.fits is a string point...
1
2010-01-12T10:24:58Z
2,061,882
<p>Oh sorry, I should have seen. Looking at the pastebin in more detail, the only error I can think of is that, for some reason the header has unicode in it. It can't be converted to <code>char *</code>, and you get the error. I tried searching for something in the header, but everything looks okay. Can you do this ...
0
2010-01-14T02:58:36Z
[ "python", "astronomy", "fits" ]
Error when using astWCS trying to create WCS object
2,048,166
<p>I'm running python2.5 and trying to use the astLib library to analyse WCS information in astronomical images. I try and get the object instanciated with the following skeleton code:</p> <pre><code>from astLib import astWCS w = astWCS.WCS('file.fits') # error here </code></pre> <p>where file.fits is a string point...
1
2010-01-12T10:24:58Z
2,413,666
<p>Just found out the updated version of this library has fixed the problem, thanks for everyone's help</p>
1
2010-03-10T00:26:58Z
[ "python", "astronomy", "fits" ]