title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
Signals registered more than once in django1.1 testserver
1,149,317
<p>I've defined a signal handler function in my models.py file. At the bottom of that file, I use <code>signals.post_save.connect(myhandler, sender=myclass)</code> as recommended in the docs at <a href="http://docs.djangoproject.com/en/dev/topics/signals/" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/sign...
1
2009-07-19T05:59:53Z
1,149,336
<p>The signature for the <code>connect</code> method is </p> <pre><code>def connect(self, receiver, sender=None, weak=True, dispatch_uid=None) </code></pre> <p>where the <code>dispatch_uid</code> parameter is an identifier used to uniquely identify a particular instance of a receiver. This will usually be a string, t...
4
2009-07-19T06:14:06Z
[ "python", "django", "django-models", "django-signals" ]
Exploring and decompiling python bytecode
1,149,513
<p>Lets say I have:</p> <pre><code>&gt;&gt;&gt; def test(a): &gt;&gt;&gt; print a </code></pre> <p>Now, I want to explore see how test looks like in its compiled form.</p> <pre><code>&gt;&gt;&gt; test.func_code.co_code '|\x00\x00GHd\x00\x00S' </code></pre> <p>I can get the disassembled form using the <strong...
12
2009-07-19T08:59:47Z
1,149,523
<p><a href="http://sourceforge.net/projects/decompyle/" rel="nofollow">decompyle</a></p> <blockquote> <p>Decompyle is a python disassembler and decompiler which converts Python byte-code (.pyc or .pyo) back into equivalent Python source. Verification of the produced code (re-compiled) is avaliable as well....
3
2009-07-19T09:06:57Z
[ "python", "decompiling" ]
Exploring and decompiling python bytecode
1,149,513
<p>Lets say I have:</p> <pre><code>&gt;&gt;&gt; def test(a): &gt;&gt;&gt; print a </code></pre> <p>Now, I want to explore see how test looks like in its compiled form.</p> <pre><code>&gt;&gt;&gt; test.func_code.co_code '|\x00\x00GHd\x00\x00S' </code></pre> <p>I can get the disassembled form using the <strong...
12
2009-07-19T08:59:47Z
1,149,590
<p><strong>UnPyc</strong></p> <p><a href="http://sourceforge.net/projects/unpyc/" rel="nofollow">http://sourceforge.net/projects/unpyc/</a></p> <p>It is a maintained fork of the old decompyle updated to work with 2.5 and 2.6.</p>
7
2009-07-19T10:00:58Z
[ "python", "decompiling" ]
Exploring and decompiling python bytecode
1,149,513
<p>Lets say I have:</p> <pre><code>&gt;&gt;&gt; def test(a): &gt;&gt;&gt; print a </code></pre> <p>Now, I want to explore see how test looks like in its compiled form.</p> <pre><code>&gt;&gt;&gt; test.func_code.co_code '|\x00\x00GHd\x00\x00S' </code></pre> <p>I can get the disassembled form using the <strong...
12
2009-07-19T08:59:47Z
11,102,744
<p>get uncompyle2 from github! :)</p>
6
2012-06-19T14:06:44Z
[ "python", "decompiling" ]
Exploring and decompiling python bytecode
1,149,513
<p>Lets say I have:</p> <pre><code>&gt;&gt;&gt; def test(a): &gt;&gt;&gt; print a </code></pre> <p>Now, I want to explore see how test looks like in its compiled form.</p> <pre><code>&gt;&gt;&gt; test.func_code.co_code '|\x00\x00GHd\x00\x00S' </code></pre> <p>I can get the disassembled form using the <strong...
12
2009-07-19T08:59:47Z
19,268,774
<p>Uncompyle2 worked for me with Python 2.7.</p> <p><a href="https://github.com/wibiti/uncompyle2" rel="nofollow">https://github.com/wibiti/uncompyle2</a></p> <p>Quick how to use uncompyle2 , Install it and then </p> <pre><code>&gt;&gt;&gt;import uncompyle2 &gt;&gt;&gt; with open("decompiled.py","wb") as f: ... un...
2
2013-10-09T09:56:57Z
[ "python", "decompiling" ]
Exploring and decompiling python bytecode
1,149,513
<p>Lets say I have:</p> <pre><code>&gt;&gt;&gt; def test(a): &gt;&gt;&gt; print a </code></pre> <p>Now, I want to explore see how test looks like in its compiled form.</p> <pre><code>&gt;&gt;&gt; test.func_code.co_code '|\x00\x00GHd\x00\x00S' </code></pre> <p>I can get the disassembled form using the <strong...
12
2009-07-19T08:59:47Z
21,366,088
<p>In addition to what DevC wrote:</p> <ol> <li><p>Uncompyle2 works with Python 2.7</p></li> <li><p>with Uncompyle2, you can also un-compile from the command line:</p> <p>$ uncompyle2 compiled.pyc >> source.uncompyle2.py</p></li> <li><p>to install Uncompyle2, do</p> <p>$ git clone <a href="https://github.com/wibiti/...
1
2014-01-26T16:30:29Z
[ "python", "decompiling" ]
Exploring and decompiling python bytecode
1,149,513
<p>Lets say I have:</p> <pre><code>&gt;&gt;&gt; def test(a): &gt;&gt;&gt; print a </code></pre> <p>Now, I want to explore see how test looks like in its compiled form.</p> <pre><code>&gt;&gt;&gt; test.func_code.co_code '|\x00\x00GHd\x00\x00S' </code></pre> <p>I can get the disassembled form using the <strong...
12
2009-07-19T08:59:47Z
37,440,699
<p>There is also now <a href="https://pypi.python.org/pypi?name=uncompyle6&amp;:action=display" rel="nofollow">uncompyle6</a> which is written in Python and <a href="https://github.com/zrax/pycdc" rel="nofollow">pycdc</a> which is written in C++. </p> <p>Both of these handle several versions of Python bytecode includi...
0
2016-05-25T14:50:35Z
[ "python", "decompiling" ]
python and ruby - for what to use it?
1,149,581
<p>I'm thinking about learning ruby and python a little bit, and it occurred to me, for what ruby/python is good for? When to use ruby and when python, or for what ruby/python is not for? :)</p> <p>What should I do in these languages?</p> <p>thanks</p>
8
2009-07-19T09:56:34Z
1,149,595
<p>They are good for mostly for rapid prototyping, quick development, dynamic programs, web applications and scripts. They're general purpose languages, so you can use them for pretty much everything you want. You'll have smaller development times (compared to, say, Java or C++), but worse performance and less static e...
11
2009-07-19T10:08:03Z
[ "python", "ruby" ]
python and ruby - for what to use it?
1,149,581
<p>I'm thinking about learning ruby and python a little bit, and it occurred to me, for what ruby/python is good for? When to use ruby and when python, or for what ruby/python is not for? :)</p> <p>What should I do in these languages?</p> <p>thanks</p>
8
2009-07-19T09:56:34Z
1,149,596
<p>If you want to know what people actually use them for, check out <a href="http://pypi.python.org/pypi">Python Package Index</a>, <a href="http://rubyforge.org/">RubyForge</a>, and search <a href="http://web.sourceforge.com/">SourceForge</a> or even StackOverflow.</p> <p>As shylent says, you can easily get into holy...
6
2009-07-19T10:08:46Z
[ "python", "ruby" ]
python and ruby - for what to use it?
1,149,581
<p>I'm thinking about learning ruby and python a little bit, and it occurred to me, for what ruby/python is good for? When to use ruby and when python, or for what ruby/python is not for? :)</p> <p>What should I do in these languages?</p> <p>thanks</p>
8
2009-07-19T09:56:34Z
1,149,661
<p>They are good for everything.</p> <p>Ruby has an edge for munging textfiles awk/perl style. That's slightly easier in Ruby. For the rest, I think Python has a string edge, and that it TOTALLY subjective. See <a href="http://stackoverflow.com/questions/1113611/what-does-ruby-have-that-python-doesnt-and-vice-versa">h...
2
2009-07-19T11:03:32Z
[ "python", "ruby" ]
python and ruby - for what to use it?
1,149,581
<p>I'm thinking about learning ruby and python a little bit, and it occurred to me, for what ruby/python is good for? When to use ruby and when python, or for what ruby/python is not for? :)</p> <p>What should I do in these languages?</p> <p>thanks</p>
8
2009-07-19T09:56:34Z
1,149,723
<p>To avoid the holy war and maybe give another perspective I say (without requesting more information of what fun part of programming the question-ere thinks is cool to do):</p> <p>Learn python first! </p> <p>If you haven't done any scripting language yet I would recommend python. The core of python is somewhat clea...
1
2009-07-19T11:43:42Z
[ "python", "ruby" ]
Use Google AppEngine datastore outside of AppEngine project
1,149,639
<p>For my little framework <a href="http://code.google.com/p/pyxer/">Pyxer</a> I would like to to be able to use the Google AppEngine datastores also outside of AppEngine projects, because I'm now used to this ORM pattern and for little quick hacks this is nice. I can not use Google AppEngine for all of my projects bec...
5
2009-07-19T10:48:19Z
1,150,756
<p>Nick Johnson, from the app engine team himself, has a <a href="http://blog.notdot.net/2009/04/Announcing-BDBDatastore-a-replacement-datastore-for-App-Engine" rel="nofollow">blog posting</a> listing some of the alternatives, including his BDBdatastore.</p> <p>However, that assumes you want to use exactly the same OR...
5
2009-07-19T20:11:30Z
[ "python", "sql", "google-app-engine", "orm" ]
Use Google AppEngine datastore outside of AppEngine project
1,149,639
<p>For my little framework <a href="http://code.google.com/p/pyxer/">Pyxer</a> I would like to to be able to use the Google AppEngine datastores also outside of AppEngine projects, because I'm now used to this ORM pattern and for little quick hacks this is nice. I can not use Google AppEngine for all of my projects bec...
5
2009-07-19T10:48:19Z
1,830,581
<p>You might also want to look at <a href="http://code.google.com/p/appscale/" rel="nofollow">AppScale</a>, which is "a platform that allows users to deploy and host their own Google App Engine applications". </p> <p>It's probably overkill for your purposes, but definitely something to look into.</p>
4
2009-12-02T04:03:57Z
[ "python", "sql", "google-app-engine", "orm" ]
Use Google AppEngine datastore outside of AppEngine project
1,149,639
<p>For my little framework <a href="http://code.google.com/p/pyxer/">Pyxer</a> I would like to to be able to use the Google AppEngine datastores also outside of AppEngine projects, because I'm now used to this ORM pattern and for little quick hacks this is nice. I can not use Google AppEngine for all of my projects bec...
5
2009-07-19T10:48:19Z
2,437,624
<p>There is also the Remote API which the bulkloader tool uses to upload or download data into/from the Datastore.</p> <p>Maybe it could be used to have applications which are not hosted on AppEngine to still use the Datastore there.</p>
0
2010-03-13T07:22:27Z
[ "python", "sql", "google-app-engine", "orm" ]
Pythonic Swap?
1,149,802
<p>I found that i have to perform a swap in python and i write something like this.</p> <pre><code>arr[first], arr[second] = arr[second], arr[first] </code></pre> <p>I suppose this is not so pythonic. Does somebody know how to do a swap in python more elegent?</p> <p><strong>EDIT:</strong> I think another example wi...
13
2009-07-19T12:29:16Z
1,149,804
<pre><code>a, b = b, a </code></pre> <p><a href="http://love-python.blogspot.com/2008/02/swap-values-python-way.html" rel="nofollow">Is a perfectly Pythonic idiom.</a> It is short and readable, as long as your variable names are short enough.</p>
15
2009-07-19T12:31:08Z
[ "python", "swap" ]
Pythonic Swap?
1,149,802
<p>I found that i have to perform a swap in python and i write something like this.</p> <pre><code>arr[first], arr[second] = arr[second], arr[first] </code></pre> <p>I suppose this is not so pythonic. Does somebody know how to do a swap in python more elegent?</p> <p><strong>EDIT:</strong> I think another example wi...
13
2009-07-19T12:29:16Z
1,149,860
<p>It's difficult to imagine how it could be made more elegant: using a hypothetical built-in function ... <code>swap_sequence_elements(arr, first, second)</code> elegant? maybe, but this is in YAGGI territory -- you aren't going to get it ;-) -- and the function call overhead would/should put you off implementing it y...
1
2009-07-19T13:05:52Z
[ "python", "swap" ]
Pythonic Swap?
1,149,802
<p>I found that i have to perform a swap in python and i write something like this.</p> <pre><code>arr[first], arr[second] = arr[second], arr[first] </code></pre> <p>I suppose this is not so pythonic. Does somebody know how to do a swap in python more elegent?</p> <p><strong>EDIT:</strong> I think another example wi...
13
2009-07-19T12:29:16Z
1,149,884
<p><code>a, b = b, a</code> is about as short as you'll get, it's only three characters (aside from the variable names).. It's about as Python'y as you'll get</p> <p>One alternative is the usual use-a-temp-variable:</p> <pre><code>self.memberlist[someindexA], self.memberlist[someindexB] = self.memberlist[someindexB],...
1
2009-07-19T13:17:42Z
[ "python", "swap" ]
Pythonic Swap?
1,149,802
<p>I found that i have to perform a swap in python and i write something like this.</p> <pre><code>arr[first], arr[second] = arr[second], arr[first] </code></pre> <p>I suppose this is not so pythonic. Does somebody know how to do a swap in python more elegent?</p> <p><strong>EDIT:</strong> I think another example wi...
13
2009-07-19T12:29:16Z
1,150,272
<p>The one thing I might change in your example code: if you're going to use some long name such as <code>self.memberlist</code> over an over again, it's often more readable to alias ("assign") it to a shorter name first. So for example instead of the long, hard-to-read:</p> <pre><code>self.memberlist[someindexA], se...
12
2009-07-19T16:36:43Z
[ "python", "swap" ]
Pythonic Swap?
1,149,802
<p>I found that i have to perform a swap in python and i write something like this.</p> <pre><code>arr[first], arr[second] = arr[second], arr[first] </code></pre> <p>I suppose this is not so pythonic. Does somebody know how to do a swap in python more elegent?</p> <p><strong>EDIT:</strong> I think another example wi...
13
2009-07-19T12:29:16Z
1,151,911
<p>I suppose you could take advantage of the step argument of slice notation to do something like this:</p> <p>myarr[:2] = myarr[:2][::-1]</p> <p>I'm not sure this is clearer or more pythonic though...</p>
-1
2009-07-20T06:01:25Z
[ "python", "swap" ]
$_SERVER vs. WSGI environ parameter
1,149,881
<p>I'm designing a site. It is in a very early stage, and I have to make a decision whether or not to use a SingleSignOn service provided by the server. (it's a campus site, and more and more sites are using SSO here, so generally it's a good idea). The target platform is most probably going to be django via mod_wsgi. ...
1
2009-07-19T13:16:11Z
1,149,924
<p>Well, $_SERVER is PHP. You are likely to be able to access the same variables via WSGI as well, but to be sure you need to figure out exactly how the SSO works, so you know what creates these variables (probably Apache) and that you can access them.</p> <p>Or, you can get yourself access and try it out. :)</p>
0
2009-07-19T13:45:11Z
[ "php", "python", "django", "environment-variables" ]
$_SERVER vs. WSGI environ parameter
1,149,881
<p>I'm designing a site. It is in a very early stage, and I have to make a decision whether or not to use a SingleSignOn service provided by the server. (it's a campus site, and more and more sites are using SSO here, so generally it's a good idea). The target platform is most probably going to be django via mod_wsgi. ...
1
2009-07-19T13:16:11Z
1,150,166
<p>In Django, the server environment variables are provided as dictionary members of the <code>META</code> attribute on the <code>request</code> object - so in your view, you can always access them via <code>request.META['foo']</code> where foo is the name of the variable.</p> <p>An easy way to see what is available i...
5
2009-07-19T15:53:10Z
[ "php", "python", "django", "environment-variables" ]
$_SERVER vs. WSGI environ parameter
1,149,881
<p>I'm designing a site. It is in a very early stage, and I have to make a decision whether or not to use a SingleSignOn service provided by the server. (it's a campus site, and more and more sites are using SSO here, so generally it's a good idea). The target platform is most probably going to be django via mod_wsgi. ...
1
2009-07-19T13:16:11Z
1,151,129
<p>To determine the set of variables passed in the raw WSGI environment, before Django does anything to them, put the following code in the WSGI script file in place of your Django stuff.</p> <pre><code>import StringIO def application(environ, start_response): headers = [] headers.append(('Content-type', 'tex...
3
2009-07-19T23:02:33Z
[ "php", "python", "django", "environment-variables" ]
cleaning up when using exceptions and files in python
1,149,983
<p>I'm learning python for a couple of days now and am struggling with its 'spirit'. I'm comming from the C/C++/Java/Perl school and I understand that python is not C (at all) that's why I'm trying to understand the spirit to get the most out of it (and so far it's hard)...</p> <p>My question is especially focused on ...
3
2009-07-19T14:12:25Z
1,149,997
<p>The easiest way to deal with this is to use the fact that file objects in Python 2.5+ are <a href="http://www.python.org/doc/2.5.2/lib/typecontextmanager.html">context managers</a>. You can use the <a href="http://www.python.org/dev/peps/pep-0343/"><code>with</code></a> statement to enter a context; the context mana...
6
2009-07-19T14:20:15Z
[ "python", "exception", "file-io" ]
cleaning up when using exceptions and files in python
1,149,983
<p>I'm learning python for a couple of days now and am struggling with its 'spirit'. I'm comming from the C/C++/Java/Perl school and I understand that python is not C (at all) that's why I'm trying to understand the spirit to get the most out of it (and so far it's hard)...</p> <p>My question is especially focused on ...
3
2009-07-19T14:12:25Z
1,150,000
<p>As of Python 2.5, there's a <code>with</code> command that simplifies some of what you're fighting with. Read more about it <a href="http://effbot.org/zone/python-with-statement.htm" rel="nofollow">here</a>. Here's a transformed version of your code:</p> <pre><code>class FormatError(Exception): def __init__(s...
1
2009-07-19T14:21:45Z
[ "python", "exception", "file-io" ]
cleaning up when using exceptions and files in python
1,149,983
<p>I'm learning python for a couple of days now and am struggling with its 'spirit'. I'm comming from the C/C++/Java/Perl school and I understand that python is not C (at all) that's why I'm trying to understand the spirit to get the most out of it (and so far it's hard)...</p> <p>My question is especially focused on ...
3
2009-07-19T14:12:25Z
1,150,020
<p>OK, I'm an ass. edit:and BTW, many thanx for those who already answered while I was posting this</p> <p>The code below does the trick. You must create a nested block with the 'with as' statement to make sure the file is cleaned:</p> <pre><code>class FormatError(Exception): def __init__(self, message): ...
0
2009-07-19T14:28:07Z
[ "python", "exception", "file-io" ]
cleaning up when using exceptions and files in python
1,149,983
<p>I'm learning python for a couple of days now and am struggling with its 'spirit'. I'm comming from the C/C++/Java/Perl school and I understand that python is not C (at all) that's why I'm trying to understand the spirit to get the most out of it (and so far it's hard)...</p> <p>My question is especially focused on ...
3
2009-07-19T14:12:25Z
1,150,123
<p>Close can to my knowledge never return an error.</p> <p>In fact, the file handle will be closed when garbage collected, so you don't have to do it explicitly in Python. Although it's still good programming to do so, obviously.</p>
0
2009-07-19T15:30:13Z
[ "python", "exception", "file-io" ]
cleaning up when using exceptions and files in python
1,149,983
<p>I'm learning python for a couple of days now and am struggling with its 'spirit'. I'm comming from the C/C++/Java/Perl school and I understand that python is not C (at all) that's why I'm trying to understand the spirit to get the most out of it (and so far it's hard)...</p> <p>My question is especially focused on ...
3
2009-07-19T14:12:25Z
1,150,504
<p>Just a note: you can always declare a variable, and then it would become something like this:</p> <pre><code>file_desc = None try: file_desc = open(file_name, 'r') except IOError, err: pass finally: if file_desc: close(file_desc) </code></pre> <p>Of course, if you are using a newer version of P...
1
2009-07-19T18:19:35Z
[ "python", "exception", "file-io" ]
Can I create a Python extension module in D (instead of C)
1,150,093
<p>I hear D is link-compatible with C. I'd like to use D to create an extension module for Python. Am I overlooking some reason why it's never going to work?</p>
14
2009-07-19T15:10:18Z
1,150,107
<p>Wait? Something like this <a href="http://pyd.dsource.org/">http://pyd.dsource.org/</a></p>
14
2009-07-19T15:21:32Z
[ "python", "module", "d" ]
Can I create a Python extension module in D (instead of C)
1,150,093
<p>I hear D is link-compatible with C. I'd like to use D to create an extension module for Python. Am I overlooking some reason why it's never going to work?</p>
14
2009-07-19T15:10:18Z
1,315,336
<p>Sounds easy and people here who say it's just up to the C API don't know how difficult it is to integrate the Boehm GC used by D within Python. PyD looks like a typical concept proof where people haven't realized the real world problems.</p>
2
2009-08-22T06:45:00Z
[ "python", "module", "d" ]
Generating random sentences from custom text in Python's NLTK?
1,150,144
<p>I'm having trouble with the NLTK under Python, specifically the .generate() method.</p> <blockquote> <p>generate(self, length=100)</p> <p>Print random text, generated using a trigram language model.</p> <p>Parameters:</p> <pre><code> * length (int) - The length of text to generate (default=100) </cod...
5
2009-07-19T15:41:58Z
1,150,154
<p>Maybe you can sort the tokens array randomly before generating a sentence.</p>
-1
2009-07-19T15:47:09Z
[ "python", "random", "nltk" ]
Generating random sentences from custom text in Python's NLTK?
1,150,144
<p>I'm having trouble with the NLTK under Python, specifically the .generate() method.</p> <blockquote> <p>generate(self, length=100)</p> <p>Print random text, generated using a trigram language model.</p> <p>Parameters:</p> <pre><code> * length (int) - The length of text to generate (default=100) </cod...
5
2009-07-19T15:41:58Z
1,150,200
<p>Are you sure that using <code>word_tokenize</code> is the right approach? </p> <p><a href="http://groups.google.com/group/nltk-users/browse%5Fthread/thread/dc97124e8e8d17cb" rel="nofollow">This Google groups page</a> has the example:</p> <pre><code>&gt;&gt;&gt; import nltk &gt;&gt;&gt; text = nltk.Text(nltk.corpu...
-1
2009-07-19T16:07:12Z
[ "python", "random", "nltk" ]
Generating random sentences from custom text in Python's NLTK?
1,150,144
<p>I'm having trouble with the NLTK under Python, specifically the .generate() method.</p> <blockquote> <p>generate(self, length=100)</p> <p>Print random text, generated using a trigram language model.</p> <p>Parameters:</p> <pre><code> * length (int) - The length of text to generate (default=100) </cod...
5
2009-07-19T15:41:58Z
1,150,268
<p>Your sample corpus is most likely to be too small. I don't know how exactly nltk builds its trigram model but it is common practice that beginning and end of sentences are handled somehow. Since there is only one beginning of sentence in your corpus this might be the reason why every sentence has the same beginning....
1
2009-07-19T16:35:15Z
[ "python", "random", "nltk" ]
Generating random sentences from custom text in Python's NLTK?
1,150,144
<p>I'm having trouble with the NLTK under Python, specifically the .generate() method.</p> <blockquote> <p>generate(self, length=100)</p> <p>Print random text, generated using a trigram language model.</p> <p>Parameters:</p> <pre><code> * length (int) - The length of text to generate (default=100) </cod...
5
2009-07-19T15:41:58Z
1,155,231
<p>To generate random text, U need to use <a href="http://mathworld.wolfram.com/MarkovChain.html">Markov Chains</a></p> <p>code to do that: <a href="http://gist.github.com/131679">from here</a></p> <pre><code>import random class Markov(object): def __init__(self, open_file): self.cache = {} self.open_file...
5
2009-07-20T18:48:31Z
[ "python", "random", "nltk" ]
Generating random sentences from custom text in Python's NLTK?
1,150,144
<p>I'm having trouble with the NLTK under Python, specifically the .generate() method.</p> <blockquote> <p>generate(self, length=100)</p> <p>Print random text, generated using a trigram language model.</p> <p>Parameters:</p> <pre><code> * length (int) - The length of text to generate (default=100) </cod...
5
2009-07-19T15:41:58Z
1,481,492
<p>You should be "training" the Markov model with multiple sequences, so that you accurately sample the starting state probabilities as well (called "pi" in Markov-speak). If you use a single sequence then you will always start in the same state.</p> <p>In the case of Orwell's 1984 you would want to use sentence token...
7
2009-09-26T15:50:57Z
[ "python", "random", "nltk" ]
Source interface with Python and urllib2
1,150,332
<p>How do i set the source IP/interface with Python and urllib2?</p>
29
2009-07-19T17:05:12Z
1,150,408
<p>This seems to work.</p> <pre><code>import urllib2, httplib, socket class BindableHTTPConnection(httplib.HTTPConnection): def connect(self): """Connect to the host and port specified in __init__.""" self.sock = socket.socket() self.sock.bind((self.source_ip, 0)) if isinstance(self.timeout, f...
22
2009-07-19T17:36:44Z
[ "python", "urllib2" ]
Source interface with Python and urllib2
1,150,332
<p>How do i set the source IP/interface with Python and urllib2?</p>
29
2009-07-19T17:05:12Z
1,150,423
<p>Unfortunately the stack of standard library modules in use (urllib2, httplib, socket) is somewhat badly designed for the purpose -- at the key point in the operation, <code>HTTPConnection.connect</code> (in httplib) delegates to <code>socket.create_connection</code>, which in turn gives you no "hook" whatsoever betw...
44
2009-07-19T17:43:41Z
[ "python", "urllib2" ]
Source interface with Python and urllib2
1,150,332
<p>How do i set the source IP/interface with Python and urllib2?</p>
29
2009-07-19T17:05:12Z
3,318,747
<p>I thought I'd follow up with a slightly better version of the monkey patch. If you need to be able to set different port options on some of the sockets or are using something like SSL that subclasses socket, the following code works a bit better.</p> <pre><code>_ip_address = None def bind_outgoing_sockets_to_ip(ip_...
1
2010-07-23T13:54:02Z
[ "python", "urllib2" ]
Source interface with Python and urllib2
1,150,332
<p>How do i set the source IP/interface with Python and urllib2?</p>
29
2009-07-19T17:05:12Z
9,980,681
<p>Reasoning that I should monkey-patch at the highest level available, here's an alternative to Alex's answer which patches <code>httplib</code> instead of <code>socket</code>, taking advantage of <code>httplib.HTTPSConnection.__init__()</code>'s <code>source_address</code> keyword argument (which is not exposed by <c...
1
2012-04-02T17:08:15Z
[ "python", "urllib2" ]
Source interface with Python and urllib2
1,150,332
<p>How do i set the source IP/interface with Python and urllib2?</p>
29
2009-07-19T17:05:12Z
14,669,175
<p>Here's a further refinement that makes use of <a href="http://docs.python.org/2/library/httplib.html#httplib.HTTPConnection" rel="nofollow">HTTPConnection's source_address argument</a> (introduced in Python 2.7):</p> <pre><code>import functools import httplib import urllib2 class BoundHTTPHandler(urllib2.HTTPHandl...
9
2013-02-03T03:16:40Z
[ "python", "urllib2" ]
Source interface with Python and urllib2
1,150,332
<p>How do i set the source IP/interface with Python and urllib2?</p>
29
2009-07-19T17:05:12Z
17,170,328
<p>As of Python 2.7 httplib.HTTPConnection had source_address added to it, allowing you to provide an IP port pair to bind to.</p> <p>See: <a href="http://docs.python.org/2/library/httplib.html#httplib.HTTPConnection" rel="nofollow">http://docs.python.org/2/library/httplib.html#httplib.HTTPConnection</a> </p>
1
2013-06-18T13:35:17Z
[ "python", "urllib2" ]
Attribute Cache in Django - What's the point?
1,150,368
<p>I was just looking over EveryBlock's source code and I noticed this code in the alerts/models.py code:</p> <pre><code> def _get_user(self): if not hasattr(self, '_user_cache'): from ebpub.accounts.models import User try: self._user_cache = User.objects.get(id=self.user_id) ...
2
2009-07-19T17:22:49Z
1,150,421
<p>I don't know why this is an IntegerField; it looks like it definitely should be a ForeignKey(User) field--you lose things like select_related() here and other things because of that, too.</p> <p>As to the caching, many databases don't cache results--they (or rather, the OS) will cache the data on disk needed to get...
2
2009-07-19T17:42:51Z
[ "python", "django", "django-models" ]
Attribute Cache in Django - What's the point?
1,150,368
<p>I was just looking over EveryBlock's source code and I noticed this code in the alerts/models.py code:</p> <pre><code> def _get_user(self): if not hasattr(self, '_user_cache'): from ebpub.accounts.models import User try: self._user_cache = User.objects.get(id=self.user_id) ...
2
2009-07-19T17:22:49Z
1,150,444
<p>Although databases do cache things internally, there's still an overhead in going back to the db every time you want to check the value of a related field - setting up the query within Django, the network latency in connecting to the db and returning the data over the network, instantiating the object in Django, etc...
2
2009-07-19T17:52:03Z
[ "python", "django", "django-models" ]
Compile the Python interpreter statically?
1,150,373
<p>I'm building a special-purpose embedded Python interpreter and want to avoid having dependencies on dynamic libraries so I want to compile the interpreter with static libraries instead (e.g. <code>libc.a</code> not <code>libc.so</code>).</p> <p>I would also like to statically link all dynamic libraries that are par...
34
2009-07-19T17:23:56Z
1,150,451
<p>Using freeze doesn't prevent doing it all in one run (no matter what approach you use, you will need multiple build steps - e.g. many compiler invocations). First, you edit <code>Modules/Setup</code> to include all extension modules that you want. Next, you build Python, getting libpythonxy.a. Then, you run freeze, ...
6
2009-07-19T17:54:36Z
[ "c++", "python", "c", "compilation" ]
Compile the Python interpreter statically?
1,150,373
<p>I'm building a special-purpose embedded Python interpreter and want to avoid having dependencies on dynamic libraries so I want to compile the interpreter with static libraries instead (e.g. <code>libc.a</code> not <code>libc.so</code>).</p> <p>I would also like to statically link all dynamic libraries that are par...
34
2009-07-19T17:23:56Z
1,151,005
<p>You can try with <a href="http://statifier.sourceforge.net/" rel="nofollow">ELF STATIFIER</a>. I've been used it before and it works fairly well. I just had problems with it in a couple of cases and then I had to use another similar program called <a href="http://www.magicermine.com/features.html" rel="nofollow">Erm...
3
2009-07-19T22:00:25Z
[ "c++", "python", "c", "compilation" ]
Compile the Python interpreter statically?
1,150,373
<p>I'm building a special-purpose embedded Python interpreter and want to avoid having dependencies on dynamic libraries so I want to compile the interpreter with static libraries instead (e.g. <code>libc.a</code> not <code>libc.so</code>).</p> <p>I would also like to statically link all dynamic libraries that are par...
34
2009-07-19T17:23:56Z
1,155,092
<p>I found this (mainly concerning static compilation of Python modules):</p> <ul> <li><a href="http://bytes.com/groups/python/23235-build-static-python-executable-linux">http://bytes.com/groups/python/23235-build-static-python-executable-linux</a></li> </ul> <p>Which describes a file used for configuration located h...
26
2009-07-20T18:21:42Z
[ "c++", "python", "c", "compilation" ]
Compile the Python interpreter statically?
1,150,373
<p>I'm building a special-purpose embedded Python interpreter and want to avoid having dependencies on dynamic libraries so I want to compile the interpreter with static libraries instead (e.g. <code>libc.a</code> not <code>libc.so</code>).</p> <p>I would also like to statically link all dynamic libraries that are par...
34
2009-07-19T17:23:56Z
27,769,640
<p><a href="https://github.com/davidsansome/python-cmake-buildsystem" rel="nofollow">CPython CMake Buildsystem</a> offers an alternative way to build Python, using <a href="http://www.cmake.org" rel="nofollow">CMake</a>.</p> <p>It can build python lib statically, and include in that lib all the modules you want. Just ...
4
2015-01-04T19:49:26Z
[ "c++", "python", "c", "compilation" ]
How to escape a hash (#) char in python?
1,150,581
<p>I'm using pyodbc to query an AS400 (unfortunately), and some column names have hashes in them! Here is a small example:</p> <pre><code>self.cursor.execute('select LPPLNM, LPPDR# from BSYDTAD.LADWJLFU') for row in self.cursor: p = Patient() p.last = row.LPPLNM p.pcp = row.LPPDR# </code></pre> <p>I get er...
3
2009-07-19T18:52:16Z
1,150,586
<p>Use the <code>getattr</code> function</p> <pre><code>p.pcp = getattr(row, "LPPDR#") </code></pre> <p>This is, in general, the way that you deal with attributes which aren't legal Python identifiers. For example, you can say</p> <pre><code>setattr(p, "&amp;)(@#$@!!~%&amp;", "Hello World!") print getattr(p, "&amp;...
7
2009-07-19T18:54:25Z
[ "python", "odbc", "escaping", "pyodbc" ]
How to escape a hash (#) char in python?
1,150,581
<p>I'm using pyodbc to query an AS400 (unfortunately), and some column names have hashes in them! Here is a small example:</p> <pre><code>self.cursor.execute('select LPPLNM, LPPDR# from BSYDTAD.LADWJLFU') for row in self.cursor: p = Patient() p.last = row.LPPLNM p.pcp = row.LPPDR# </code></pre> <p>I get er...
3
2009-07-19T18:52:16Z
1,150,588
<p>You can try to give the column an alias, i.e.:</p> <pre><code> self.cursor.execute('select LPPLNM, LPPDR# as LPPDR from BSYDTAD.LADWJLFU') </code></pre>
5
2009-07-19T18:54:48Z
[ "python", "odbc", "escaping", "pyodbc" ]
How to escape a hash (#) char in python?
1,150,581
<p>I'm using pyodbc to query an AS400 (unfortunately), and some column names have hashes in them! Here is a small example:</p> <pre><code>self.cursor.execute('select LPPLNM, LPPDR# from BSYDTAD.LADWJLFU') for row in self.cursor: p = Patient() p.last = row.LPPLNM p.pcp = row.LPPDR# </code></pre> <p>I get er...
3
2009-07-19T18:52:16Z
1,150,604
<p><code>self.cursor.execute</code> returns a tuple, so this would also work:</p> <pre><code>for row in self.cursor: p = Patient() p.last = row[0] p.pcp = row[1] </code></pre> <p>But I prefer the other answers :-)</p>
2
2009-07-19T18:59:32Z
[ "python", "odbc", "escaping", "pyodbc" ]
How to escape a hash (#) char in python?
1,150,581
<p>I'm using pyodbc to query an AS400 (unfortunately), and some column names have hashes in them! Here is a small example:</p> <pre><code>self.cursor.execute('select LPPLNM, LPPDR# from BSYDTAD.LADWJLFU') for row in self.cursor: p = Patient() p.last = row.LPPLNM p.pcp = row.LPPDR# </code></pre> <p>I get er...
3
2009-07-19T18:52:16Z
1,151,211
<p>The question has been answered, but this is just another alternative (based on Adam Bernier's answer + tuple unpacking) which I think is the cleanest:</p> <pre><code>for row in self.cursor: p = Patient() p.last, p.pcp = row </code></pre>
1
2009-07-19T23:47:49Z
[ "python", "odbc", "escaping", "pyodbc" ]
Python 2.5 socket._fileobject is what in Python 3.1?
1,150,653
<p>I'm porting some code that runs on Python 2.5 to Python 3.1. A couple of classes subclass the socket._fileobject:</p> <pre><code>class X(socket._fileobject): .... </code></pre> <p>Is there an equivalent to socket._fileobject in Python 3.1? A quick scan of the source code doesn't turn up anything useful. Thanks!<...
1
2009-07-19T19:23:53Z
1,150,774
<p>Python 3 uses SocketIO instead of _fileobject in the makefile() method, so that's probably the way to go. </p>
2
2009-07-19T20:19:14Z
[ "python", "python-3.x" ]
A question regarding string instance uniqueness in python
1,150,765
<p>I was trying to figure out which integers python only instantiates once (-6 to 256 it seems), and in the process stumbled on some string behaviour I can't see the pattern in. Sometimes, equal strings created in different ways share the same id, sometimes not. This code:</p> <pre><code>A = "10000" B = "10000" C = "1...
3
2009-07-19T20:15:45Z
1,150,791
<p>I believe short strings that can be evaluated at compile time, will be interned automatically. In the last examples, the result can't be evaluated at compile time because <code>str</code> or <code>join</code> might be redefined.</p>
1
2009-07-19T20:24:28Z
[ "python", "string", "instance", "uniqueidentifier" ]
A question regarding string instance uniqueness in python
1,150,765
<p>I was trying to figure out which integers python only instantiates once (-6 to 256 it seems), and in the process stumbled on some string behaviour I can't see the pattern in. Sometimes, equal strings created in different ways share the same id, sometimes not. This code:</p> <pre><code>A = "10000" B = "10000" C = "1...
3
2009-07-19T20:15:45Z
1,150,860
<p>Python is allowed to inline string constants; A,B,C,D are actually the same literals (if Python sees a constant expression, it treats it as a constant).</p> <p><code>str</code> is actually a class, so <code>str(whatever)</code> is calling this class' constructor, which should yield a fresh object. This explains E,...
4
2009-07-19T20:47:48Z
[ "python", "string", "instance", "uniqueidentifier" ]
A question regarding string instance uniqueness in python
1,150,765
<p>I was trying to figure out which integers python only instantiates once (-6 to 256 it seems), and in the process stumbled on some string behaviour I can't see the pattern in. Sometimes, equal strings created in different ways share the same id, sometimes not. This code:</p> <pre><code>A = "10000" B = "10000" C = "1...
3
2009-07-19T20:15:45Z
1,150,943
<p>In terms of language specification, any compliant Python compiler and runtime is fully allowed, for any instance of an immutable type, to make a new instance OR find an existing instance of the same type that's equal to the required value and use a new reference to that same instance. This means it's always incorrec...
10
2009-07-19T21:24:36Z
[ "python", "string", "instance", "uniqueidentifier" ]
A question regarding string instance uniqueness in python
1,150,765
<p>I was trying to figure out which integers python only instantiates once (-6 to 256 it seems), and in the process stumbled on some string behaviour I can't see the pattern in. Sometimes, equal strings created in different ways share the same id, sometimes not. This code:</p> <pre><code>A = "10000" B = "10000" C = "1...
3
2009-07-19T20:15:45Z
1,151,200
<p>in answer to S.Lott's suggestion of examining the byte code:</p> <pre><code>import dis def moo(): A = "10000" B = "10000" C = "100" + "00" D = "%i"%10000 E = str(10000) F = str(10000) G = "1000"+str(0) H = "0".join(("10","00")) I = str("10000") for obj in (A,B,C,D,E,F,G,H, I...
1
2009-07-19T23:42:25Z
[ "python", "string", "instance", "uniqueidentifier" ]
Emulate processing with python?
1,150,897
<p>I'm looking for a basic programmatic animation framework similar to processing except in python. That is, something that allows pixel manipulation, has basic drawing/color primitives, and is geared towards animation. Is pygame pretty much the best bet or are there other options?</p>
4
2009-07-19T21:00:28Z
1,150,922
<p>You could get pretty close to processing with vpython:</p> <p><a href="http://vpython.org/" rel="nofollow">http://vpython.org/</a></p> <p>The primitives are very easy to work with, and it is adept at animation. </p> <p>I am not sure what kind of pixel manipulation you are looking for, but there may be something f...
1
2009-07-19T21:12:30Z
[ "python", "pygame", "processing" ]
Emulate processing with python?
1,150,897
<p>I'm looking for a basic programmatic animation framework similar to processing except in python. That is, something that allows pixel manipulation, has basic drawing/color primitives, and is geared towards animation. Is pygame pretty much the best bet or are there other options?</p>
4
2009-07-19T21:00:28Z
1,150,923
<p>"Similar to processing except in python" screams "NodeBox" to me. NodeBox is OSX-only, and i don't know if it allows pixel-level manipulation, but much of its command set was derived directly from processing. You can find it at <a href="http://nodebox.net/" rel="nofollow">the NodeBox site</a>.</p>
2
2009-07-19T21:12:39Z
[ "python", "pygame", "processing" ]
Emulate processing with python?
1,150,897
<p>I'm looking for a basic programmatic animation framework similar to processing except in python. That is, something that allows pixel manipulation, has basic drawing/color primitives, and is geared towards animation. Is pygame pretty much the best bet or are there other options?</p>
4
2009-07-19T21:00:28Z
1,150,930
<p>There's quite recent C++ library, <a href="http://www.sfml-dev.org/" rel="nofollow">SFML</a>, which is a good alternative to SDL. Thus its Python bindings should be a good alternative to Pygame.</p>
0
2009-07-19T21:17:18Z
[ "python", "pygame", "processing" ]
Emulate processing with python?
1,150,897
<p>I'm looking for a basic programmatic animation framework similar to processing except in python. That is, something that allows pixel manipulation, has basic drawing/color primitives, and is geared towards animation. Is pygame pretty much the best bet or are there other options?</p>
4
2009-07-19T21:00:28Z
1,151,320
<p>I prefer pyglet to pygame (but I'm not sure exactly what your needs will be):</p> <ul> <li><a href="http://www.pyglet.org/" rel="nofollow">http://www.pyglet.org/</a></li> </ul> <p>If you need a 3d engine:</p> <ul> <li><a href="http://www.panda3d.org/" rel="nofollow">http://www.panda3d.org/</a></li> <li><a href="h...
1
2009-07-20T00:49:33Z
[ "python", "pygame", "processing" ]
Emulate processing with python?
1,150,897
<p>I'm looking for a basic programmatic animation framework similar to processing except in python. That is, something that allows pixel manipulation, has basic drawing/color primitives, and is geared towards animation. Is pygame pretty much the best bet or are there other options?</p>
4
2009-07-19T21:00:28Z
1,605,005
<p>Well, this is as close as it gets: <a href="http://code.google.com/p/pyprocessing/" rel="nofollow">http://code.google.com/p/pyprocessing/</a></p>
2
2009-10-22T04:19:54Z
[ "python", "pygame", "processing" ]
map raw sql to django orm
1,150,898
<p>Is there a way to simplify this working code? This code gets for an object all the different vote types, there are like 20 possible, and counts each type. I prefer not to write raw sql but use the orm. It is a little bit more tricky because I use generic foreign key in the model.</p> <pre><code>def get_object_votes...
1
2009-07-19T21:01:23Z
1,150,915
<p>Yes, definitely use the ORM. What you should really be doing is this in your model:</p> <pre><code>class Obj(models.Model): #whatever the object has class Vote(models.Model): obj = models.ForeignKey(Obj) #this ties a vote to its object </code></pre> <p>Then to get all of the votes from an object, have the...
0
2009-07-19T21:09:31Z
[ "python", "sql", "django", "orm", "django-models" ]
map raw sql to django orm
1,150,898
<p>Is there a way to simplify this working code? This code gets for an object all the different vote types, there are like 20 possible, and counts each type. I prefer not to write raw sql but use the orm. It is a little bit more tricky because I use generic foreign key in the model.</p> <pre><code>def get_object_votes...
1
2009-07-19T21:01:23Z
1,151,508
<p>The code Below did the trick for me!</p> <pre><code>def get_object_votes(self, obj, all=False): """ Get a dictionary mapping vote to votecount """ object_id = obj._get_pk_val() ctype = ContentType.objects.get_for_model(obj) queryset = self.filter(content_type=ctype, object_id=object_id) ...
1
2009-07-20T02:26:47Z
[ "python", "sql", "django", "orm", "django-models" ]
python saving unicode into file
1,150,994
<p>i'm having some trouble figuring out how to save unicode into a file in python. I have the following code, and if i run it in a script test.py, it should create a new file called priceinfo.txt, and write what's in price_info to the file. But i do not see the file, can anyone enlighten me on what could be the problem...
-1
2009-07-19T21:55:31Z
1,151,017
<p>Assuming no error messages from the program (which would be the result of forgetting to import the codecs module), are you sure you're looking in the right place? That code writes priceinfo.txt in the current working directory (IOW are you sure that you're looking inside the working directory?)</p>
1
2009-07-19T22:06:37Z
[ "python", "file", "unicode" ]
python saving unicode into file
1,150,994
<p>i'm having some trouble figuring out how to save unicode into a file in python. I have the following code, and if i run it in a script test.py, it should create a new file called priceinfo.txt, and write what's in price_info to the file. But i do not see the file, can anyone enlighten me on what could be the problem...
-1
2009-07-19T21:55:31Z
1,151,018
<p>I can think of several reasons:</p> <ol> <li>the file gets created, but in a different directory. Be certain what the working directory of the script is.</li> <li>you don't have permission to create the file, in the directory where you want to create it.</li> <li>you have some error in your Python script, and it d...
3
2009-07-19T22:07:55Z
[ "python", "file", "unicode" ]
Multiple regression in Python
1,151,088
<p>I am currently using scipy's linregress function for single regression. I am unable to find if the same library, or another, is able to do multiple regression, that is, one dependent variable and more than one independent variable. I'd like to avoid R if possible. If you're wondering, I am doing FX market analysis w...
4
2009-07-19T22:41:02Z
1,151,111
<p>I'm not sure if this is what you need, but the <a href="http://mdp-toolkit.sourceforge.net/" rel="nofollow">Modular toolkit for Data Processing (MDP)</a> libray recently implemented <a href="http://mdp-toolkit.sourceforge.net/node_list.html#mdp.nodes.LinearRegressionNode" rel="nofollow">multivariate linear regressio...
2
2009-07-19T22:53:31Z
[ "python", "math", "scipy", "regression" ]
Multiple regression in Python
1,151,088
<p>I am currently using scipy's linregress function for single regression. I am unable to find if the same library, or another, is able to do multiple regression, that is, one dependent variable and more than one independent variable. I'd like to avoid R if possible. If you're wondering, I am doing FX market analysis w...
4
2009-07-19T22:41:02Z
1,152,136
<p>Use the OLS class [<a href="http://www.scipy.org/Cookbook/OLS">http://www.scipy.org/Cookbook/OLS</a>] from the SciPy cookbook.</p>
9
2009-07-20T07:33:51Z
[ "python", "math", "scipy", "regression" ]
Accessing Reuters data in Python
1,151,103
<p>I am currently successfully downloading live Bloomberg market prices, as well as historical series, using the service's COM API and win32com. Does anyone have any experience doing the same for Reuters live and historical data into Python?</p> <p>I know that live feeds are available for both services in Excel, so Re...
3
2009-07-19T22:48:43Z
1,152,290
<p>Reuters seems to charge for their financial data feeds, here is an overview page of their offerings: <a href="http://thomsonreuters.com/products%5Fservices/financial/financial%5Fproducts/event%5Fdriven%5Ftrading/data%5Ffeeds" rel="nofollow">Reuters data feeds</a></p>
1
2009-07-20T08:22:46Z
[ "python", "finance", "reuters" ]
Accessing Reuters data in Python
1,151,103
<p>I am currently successfully downloading live Bloomberg market prices, as well as historical series, using the service's COM API and win32com. Does anyone have any experience doing the same for Reuters live and historical data into Python?</p> <p>I know that live feeds are available for both services in Excel, so Re...
3
2009-07-19T22:48:43Z
1,166,228
<p>I have some experience with their APIs. </p> <p>Reuters also have complete documentations in their <a href="https://customers.reuters.com/developer/" rel="nofollow">Customer Zone Website</a>. More infos on their APIs can be found there. They have their APIs available in Java, C++, and COM. So I believe there are ma...
3
2009-07-22T15:45:23Z
[ "python", "finance", "reuters" ]
Accessing Reuters data in Python
1,151,103
<p>I am currently successfully downloading live Bloomberg market prices, as well as historical series, using the service's COM API and win32com. Does anyone have any experience doing the same for Reuters live and historical data into Python?</p> <p>I know that live feeds are available for both services in Excel, so Re...
3
2009-07-19T22:48:43Z
15,900,170
<p>Check out <a href="http://devcartel.com" rel="nofollow">http://devcartel.com</a> they have PyRFA -- Reuters market data API for Python.</p>
3
2013-04-09T11:04:06Z
[ "python", "finance", "reuters" ]
Accessing Reuters data in Python
1,151,103
<p>I am currently successfully downloading live Bloomberg market prices, as well as historical series, using the service's COM API and win32com. Does anyone have any experience doing the same for Reuters live and historical data into Python?</p> <p>I know that live feeds are available for both services in Excel, so Re...
3
2009-07-19T22:48:43Z
26,461,205
<p>There's an API (SOAP), it is provided under the Thomson Reuters Dataworks Enterprise (former Datastream) subscription. Though it is not free and it does not come with Thomson Reuters Eikon - you'll need to pay some extra for the license of data streaming/storage.</p> <p>If you have this subscription, then pydatastr...
1
2014-10-20T08:17:48Z
[ "python", "finance", "reuters" ]
How to get Python syntax highlighting for Visual Studio?
1,151,207
<p>Visual Studio 2008 is great as text editor, but it lacks Python syntax highlighting, can I get this as an add-on? Where can I find it?</p>
3
2009-07-19T23:46:13Z
1,151,218
<p>Have you considered installing IronPython and using that to edit your work? </p> <ul> <li><a href="http://www.codeplex.com/IronPythonStudio" rel="nofollow">http://www.codeplex.com/IronPythonStudio</a></li> </ul>
2
2009-07-19T23:49:08Z
[ "python", "visual-studio", "visual-studio-2008", "syntax-highlighting" ]
Equivalent of NotImplementedError for fields in Python
1,151,212
<p>In Python 2.x when you want to mark a method as abstract, you can define it like so:</p> <pre><code>class Base: def foo(self): raise NotImplementedError("Subclasses should implement this!") </code></pre> <p>Then if you forget to override it, you get a nice reminder exception. Is there an equivalent way...
32
2009-07-19T23:48:42Z
1,151,260
<p>Yes, you can. Use the <code>@property</code> decorator. For instance, if you have a field called "example" then can't you do something like this:</p> <pre><code>class Base(object): @property def example(self): raise NotImplementedError("Subclasses should implement this!") </code></pre> <p>Running ...
34
2009-07-20T00:08:11Z
[ "python", "abstract-class" ]
Equivalent of NotImplementedError for fields in Python
1,151,212
<p>In Python 2.x when you want to mark a method as abstract, you can define it like so:</p> <pre><code>class Base: def foo(self): raise NotImplementedError("Subclasses should implement this!") </code></pre> <p>Then if you forget to override it, you get a nice reminder exception. Is there an equivalent way...
32
2009-07-19T23:48:42Z
1,151,261
<pre><code>def require_abstract_fields(obj, cls): abstract_fields = getattr(cls, "abstract_fields", None) if abstract_fields is None: return for field in abstract_fields: if not hasattr(obj, field): raise RuntimeError, "object %s failed to define %s" % (obj, field) class a(obje...
1
2009-07-20T00:08:46Z
[ "python", "abstract-class" ]
Equivalent of NotImplementedError for fields in Python
1,151,212
<p>In Python 2.x when you want to mark a method as abstract, you can define it like so:</p> <pre><code>class Base: def foo(self): raise NotImplementedError("Subclasses should implement this!") </code></pre> <p>Then if you forget to override it, you get a nice reminder exception. Is there an equivalent way...
32
2009-07-19T23:48:42Z
1,151,275
<p>Alternate answer:</p> <pre><code>@property def NotImplementedField(self): raise NotImplementedError class a(object): x = NotImplementedField class b(a): # x = 5 pass b().x a().x </code></pre> <p>This is like Evan's, but concise and cheap--you'll only get a single instance of NotImplementedField....
23
2009-07-20T00:15:49Z
[ "python", "abstract-class" ]
Equivalent of NotImplementedError for fields in Python
1,151,212
<p>In Python 2.x when you want to mark a method as abstract, you can define it like so:</p> <pre><code>class Base: def foo(self): raise NotImplementedError("Subclasses should implement this!") </code></pre> <p>Then if you forget to override it, you get a nice reminder exception. Is there an equivalent way...
32
2009-07-19T23:48:42Z
34,535,240
<p>And here is my solution:</p> <pre class="lang-py prettyprint-override"><code>def not_implemented_method(func): from functools import wraps from inspect import getargspec, formatargspec @wraps(func) def wrapper(self, *args, **kwargs): c = self.__class__.__name__ m = func.__name__ ...
0
2015-12-30T18:39:11Z
[ "python", "abstract-class" ]
Mechanize not being installed by easy_install?
1,151,256
<p>I am in the process of migrating from an old Win2K machine to a new and much more powerful Vista 64 bit PC. Most of the migration has gone fairly smoothly - but I did find that I needed to reinstall ALL of my Python related tools.</p> <p>I've downloaded the mechanize-0.1.11.tar.gz file and ran easy_install to insta...
2
2009-07-20T00:06:27Z
1,151,280
<p>There is a <a href="http://www.py2exe.org/index.cgi/ExeWithEggs" rel="nofollow">note on the py2exe site</a> that it does not work if the source is in egg format:</p> <blockquote> <p>py2exe does not currently (as of 0.6.5) work out of the box if some of your program's dependencies are in .egg form.</p> <p...
2
2009-07-20T00:22:28Z
[ "python", "mechanize", "easy-install" ]
Mechanize not being installed by easy_install?
1,151,256
<p>I am in the process of migrating from an old Win2K machine to a new and much more powerful Vista 64 bit PC. Most of the migration has gone fairly smoothly - but I did find that I needed to reinstall ALL of my Python related tools.</p> <p>I've downloaded the mechanize-0.1.11.tar.gz file and ran easy_install to insta...
2
2009-07-20T00:06:27Z
8,323,200
<p>As other users suggested as above... I hereby summarize the steps I need to make Mechanize and BeautifulSoup work with py2exe.</p> <p><strong>Converting .py Files to Windows .exe</strong></p> <p>Follow instructions in here: <a href="http://www.py2exe.org/index.cgi/Tutorial" rel="nofollow">py2exe Tutorial</a></p> ...
0
2011-11-30T08:48:35Z
[ "python", "mechanize", "easy-install" ]
Error on connecting to Oracle from py2exe'd program: Unable to acquire Oracle environment handle
1,151,557
<p>My python program (Python 2.6) works fine when I run it using the Python interpreter, it connects to the Oracle database (10g XE) without error. However, when I compile it using py2exe, the executable version fails with "Unable to acquire Oracle environment handle" at the call to cx_Oracle.connect().</p> <p>I've tr...
5
2009-07-20T02:57:13Z
1,151,577
<p>Did you make sure to exclude the OCI.dll when you built with py2exe? If the version of the DLL on your machine is incompatible with the client version on another machine you test it on (I noticed you tried a 11g client but 10g on your machine), then this configuration will not work (I forget the actual error messag...
8
2009-07-20T03:10:38Z
[ "python", "oracle", "py2exe", "cx-oracle" ]
Error on connecting to Oracle from py2exe'd program: Unable to acquire Oracle environment handle
1,151,557
<p>My python program (Python 2.6) works fine when I run it using the Python interpreter, it connects to the Oracle database (10g XE) without error. However, when I compile it using py2exe, the executable version fails with "Unable to acquire Oracle environment handle" at the call to cx_Oracle.connect().</p> <p>I've tr...
5
2009-07-20T02:57:13Z
1,151,591
<p>Revised build_testora.py, for future reference:</p> <pre><code>from distutils.core import setup import py2exe, sys sys.argv.append('py2exe') setup( options = {'py2exe': { 'bundle_files': 2, 'compressed': True, 'dll_excludes': ["oci.dll"] }}, console = [{'script': "testora.p...
2
2009-07-20T03:21:46Z
[ "python", "oracle", "py2exe", "cx-oracle" ]
Python hashable dicts
1,151,658
<p>As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat parser. The inspiration for this is i'd like to have a better idea about how hygenic macros would work in an algol-like language (as apposed to the syntax free lisp dialects you normally find them in). Because of this, differe...
47
2009-07-20T04:04:30Z
1,151,686
<p>Hashables should be immutable -- not enforcing this but TRUSTING you not to mutate a dict after its first use as a key, the following approach would work:</p> <pre><code>class hashabledict(dict): def __key(self): return tuple((k,self[k]) for k in sorted(self)) def __hash__(self): return hash(self.__key(...
39
2009-07-20T04:18:04Z
[ "python" ]
Python hashable dicts
1,151,658
<p>As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat parser. The inspiration for this is i'd like to have a better idea about how hygenic macros would work in an algol-like language (as apposed to the syntax free lisp dialects you normally find them in). Because of this, differe...
47
2009-07-20T04:04:30Z
1,151,705
<p>Here is the easy way to make a hashable dictionary. Just remember not to mutate them after embedding in another dictionary for obvious reasons.</p> <pre><code>class hashabledict(dict): def __hash__(self): return hash(tuple(sorted(self.items()))) </code></pre>
34
2009-07-20T04:30:24Z
[ "python" ]
Python hashable dicts
1,151,658
<p>As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat parser. The inspiration for this is i'd like to have a better idea about how hygenic macros would work in an algol-like language (as apposed to the syntax free lisp dialects you normally find them in). Because of this, differe...
47
2009-07-20T04:04:30Z
2,705,638
<p>A reasonably clean, straightforward implementation is</p> <pre><code>import collections class FrozenDict(collections.Mapping): """Don't forget the docstrings!!""" def __init__(self, *args, **kwargs): self._d = dict(*args, **kwargs) def __iter__(self): return iter(self._d) def __l...
8
2010-04-24T18:24:55Z
[ "python" ]
Python hashable dicts
1,151,658
<p>As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat parser. The inspiration for this is i'd like to have a better idea about how hygenic macros would work in an algol-like language (as apposed to the syntax free lisp dialects you normally find them in). Because of this, differe...
47
2009-07-20T04:04:30Z
3,161,538
<p>You might also want to add these two methods to get the v2 pickling protocol work with hashdict instances. Otherwise cPickle will try to use hashdict.<strong>_<em>setitem</em>_</strong> resulting in a TypeError. Interestingly, with the other two versions of the protocol your code works just fine. </p> <pre><code>de...
2
2010-07-01T20:47:00Z
[ "python" ]
Python hashable dicts
1,151,658
<p>As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat parser. The inspiration for this is i'd like to have a better idea about how hygenic macros would work in an algol-like language (as apposed to the syntax free lisp dialects you normally find them in). Because of this, differe...
47
2009-07-20T04:04:30Z
6,014,481
<p>The given answers are okay, but they could be improved by using <code>frozenset(...)</code> instead of <code>tuple(sorted(...))</code> to generate the hash:</p> <pre><code>&gt;&gt;&gt; import timeit &gt;&gt;&gt; timeit.timeit('hash(tuple(sorted(d.iteritems())))', "d = dict(a=3, b='4', c=2345, asdfsdkjfew=0.23424, x...
18
2011-05-16T07:50:01Z
[ "python" ]
Python hashable dicts
1,151,658
<p>As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat parser. The inspiration for this is i'd like to have a better idea about how hygenic macros would work in an algol-like language (as apposed to the syntax free lisp dialects you normally find them in). Because of this, differe...
47
2009-07-20T04:04:30Z
10,130,656
<p>If you don't put numbers in the dictionary and you never lose the variables containing your dictionaries, you can do this:</p> <p><code>cache[id(rule)] = "whatever"</code></p> <p>since id() is unique for every dictionary</p> <p>EDIT:</p> <p>Oh sorry, yeah in that case what the other guys said would be better. I ...
-2
2012-04-12T19:46:22Z
[ "python" ]
Python hashable dicts
1,151,658
<p>As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat parser. The inspiration for this is i'd like to have a better idea about how hygenic macros would work in an algol-like language (as apposed to the syntax free lisp dialects you normally find them in). Because of this, differe...
47
2009-07-20T04:04:30Z
12,029,459
<p>I keep coming back to this topic... Here's another variation. I'm uneasy with subclassing <code>dict</code> to add a <code>__hash__</code> method; There's virtually no escape from the problem that dict's are mutable, and trusting that they won't change seems like a weak idea. So I've instead looked at building a m...
3
2012-08-19T19:47:43Z
[ "python" ]
Python hashable dicts
1,151,658
<p>As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat parser. The inspiration for this is i'd like to have a better idea about how hygenic macros would work in an algol-like language (as apposed to the syntax free lisp dialects you normally find them in). Because of this, differe...
47
2009-07-20T04:04:30Z
16,162,138
<p>All that is needed to make dictionaries usable for your purpose is to add a __hash__ method:</p> <pre><code>class Hashabledict(dict): def __hash__(self): return hash(frozenset(self)) </code></pre> <p>Note, the <em>frozenset</em> conversion will work for all dictionaries (i.e. it doesn't require the key...
16
2013-04-23T06:07:31Z
[ "python" ]
Python hashable dicts
1,151,658
<p>As an exercise, and mostly for my own amusement, I'm implementing a backtracking packrat parser. The inspiration for this is i'd like to have a better idea about how hygenic macros would work in an algol-like language (as apposed to the syntax free lisp dialects you normally find them in). Because of this, differe...
47
2009-07-20T04:04:30Z
29,672,632
<p>The accepted answer by @Unknown, as well as the answer by @AlexMartelli work perfectly fine, but only under the following constraints:</p> <ol> <li>The dictionary's values must be hashable. For example, <code>hash(hashabledict({'a':[1,2]}))</code> will raise <code>TypeError</code>.</li> <li>Keys must support compar...
2
2015-04-16T10:57:14Z
[ "python" ]
tkMessageBox
1,151,770
<p>Can anybody help me out in how to activate 'close' button of askquestion() of tkMessageBox??</p>
1
2009-07-20T05:00:42Z
1,151,900
<p>By 'activate', do you mean make it so the user can close the message box by clicking the close ('X') button?</p> <p>I do not think it is possible using <code>tkMessageBox</code>. I guess your best bet is to implement a dialog box with this functionality yourself.</p> <p>BTW: What should <code>askquestion()</code> ...
0
2009-07-20T05:54:48Z
[ "python", "tkmessagebox" ]
How can I perform a ping or traceroute using native python?
1,151,771
<p>I would like to be able to perform a ping and traceroute from within Python without having to execute the corresponding shell commands so I'd prefer a native python solution.</p>
4
2009-07-20T05:01:59Z
1,151,782
<p>Running interpreters as root is often frowned upon on security grounds (and of course you DO need to have root permission to access the "raw" socked as needed by the ICMP specs of ping and traceroute!), but if you have no problems with that it's not hard -- e.g., <a href="http://mail.python.org/pipermail/python-list...
4
2009-07-20T05:06:49Z
[ "python", "ping", "traceroute" ]
How can I perform a ping or traceroute using native python?
1,151,771
<p>I would like to be able to perform a ping and traceroute from within Python without having to execute the corresponding shell commands so I'd prefer a native python solution.</p>
4
2009-07-20T05:01:59Z
1,152,165
<p>you might want to check out the <a href="http://www.secdev.org/projects/scapy/" rel="nofollow">scapy</a> package. it's the swiss army knife of network tools for python.</p>
0
2009-07-20T07:42:16Z
[ "python", "ping", "traceroute" ]
How can I perform a ping or traceroute using native python?
1,151,771
<p>I would like to be able to perform a ping and traceroute from within Python without having to execute the corresponding shell commands so I'd prefer a native python solution.</p>
4
2009-07-20T05:01:59Z
2,974,474
<p>ICMP Ping is standard as part of the ICMP protocol.</p> <p>Traceroute uses features of ICMP and IP to determine a path via Time To Live values. Using TTL values, you can do traceroutes in a variety of protocols as long as IP/ICMP work because it is the ICMP TTL EXceeded messages that tell you about the hop in the...
0
2010-06-04T13:16:41Z
[ "python", "ping", "traceroute" ]
How can I perform a ping or traceroute using native python?
1,151,771
<p>I would like to be able to perform a ping and traceroute from within Python without having to execute the corresponding shell commands so I'd prefer a native python solution.</p>
4
2009-07-20T05:01:59Z
7,018,928
<p>If you don't mind using an external module and not using UDP or TCP, <a href="http://www.secdev.org/projects/scapy/" rel="nofollow">scapy</a> is an easy solution:</p> <pre><code>from scapy.all import * target = ["192.168.1.254"] result, unans = traceroute(target,l4=UDP(sport=RandShort())/DNS(qd=DNSQR(qname="www.goo...
7
2011-08-10T22:57:19Z
[ "python", "ping", "traceroute" ]
How can I perform a ping or traceroute using native python?
1,151,771
<p>I would like to be able to perform a ping and traceroute from within Python without having to execute the corresponding shell commands so I'd prefer a native python solution.</p>
4
2009-07-20T05:01:59Z
15,654,552
<p>I wrote a simple tcptraceroute in python which does not need root privileges <a href="http://www.thomas-guettler.de/scripts/tcptraceroute.py.txt" rel="nofollow">http://www.thomas-guettler.de/scripts/tcptraceroute.py.txt</a></p> <p>But it can't display the IP addresses of the intermediate hops. But sometimes it is u...
0
2013-03-27T08:33:47Z
[ "python", "ping", "traceroute" ]
How can I perform a ping or traceroute using native python?
1,151,771
<p>I would like to be able to perform a ping and traceroute from within Python without having to execute the corresponding shell commands so I'd prefer a native python solution.</p>
4
2009-07-20T05:01:59Z
31,644,021
<p>The <a href="https://github.com/hardikvasa/webb" rel="nofollow">Webb Library</a> is very handy in performing all kinds of web related extracts...and ping and traceroute can be done easily through it. Just include the URL you want to traceroute to:</p> <pre><code>import webb webb.traceroute("your-web-page-url") </co...
3
2015-07-27T02:15:35Z
[ "python", "ping", "traceroute" ]
Where and how is django Model objects attribute defined?
1,151,879
<p>I'm trying to get my head around Django ORM. I've been reading django.db.models.base.py source code but still could understand how does the Model.objects attributes in our Model object gets defined. Does anybody know how does django adds that objects attribute into our Model object?</p> <p>Thanks in advance</p>
1
2009-07-20T05:46:19Z
1,151,977
<p>The Django ORM makes heavy use of Python metaclasses. From <a href="http://en.wikipedia.org/wiki/Metaclass" rel="nofollow">Wikipedia</a>:</p> <blockquote> <p>In object-oriented programming, a metaclass is a class whose instances are classes. Just as an ordinary class defines the behavior of certain objects, a met...
3
2009-07-20T06:35:28Z
[ "python", "django" ]
How can I perform a ping or traceroute in python, accessing the output as it is produced?
1,151,897
<p>Earlier, I asked this question:</p> <p><a href="http://stackoverflow.com/questions/1151771/how-can-i-perform-a-ping-or-traceroute-using-native-python">How can I perform a ping or traceroute using native python?</a></p> <p>However because python is not running as root it doens't have the ability to open the raw ICM...
1
2009-07-20T05:53:54Z
1,151,929
<p><a href="http://pexpect.sourceforge.net/pexpect.html" rel="nofollow">pexpect</a> is what I'd reach for, "by default", for any requirement such as yours -- there are other similar modules, but pexpect is almost invariably the richest, most stable, and most mature one. The one case where I'd bother looking for altern...
5
2009-07-20T06:05:33Z
[ "python", "ping", "traceroute" ]
How can I perform a ping or traceroute in python, accessing the output as it is produced?
1,151,897
<p>Earlier, I asked this question:</p> <p><a href="http://stackoverflow.com/questions/1151771/how-can-i-perform-a-ping-or-traceroute-using-native-python">How can I perform a ping or traceroute using native python?</a></p> <p>However because python is not running as root it doens't have the ability to open the raw ICM...
1
2009-07-20T05:53:54Z
1,151,938
<p>You should read the documentation for the <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess</a> module, it describes how to run an external process and access its output in real time.</p> <p>Basically, you do</p> <pre><code>from subprocess import Popen, PIPE p = Popen(['tracert', h...
3
2009-07-20T06:08:39Z
[ "python", "ping", "traceroute" ]
How can I perform a ping or traceroute in python, accessing the output as it is produced?
1,151,897
<p>Earlier, I asked this question:</p> <p><a href="http://stackoverflow.com/questions/1151771/how-can-i-perform-a-ping-or-traceroute-using-native-python">How can I perform a ping or traceroute using native python?</a></p> <p>However because python is not running as root it doens't have the ability to open the raw ICM...
1
2009-07-20T05:53:54Z
1,151,973
<p>You can create a tty pair for the subprocess and run inside of that. According to the C standard (C99 7.19.3) the only time stdout is line buffered (as opposed to fully buffered which is what you say you don't want) is when it's a terminal. (or the child called setvbuf() obviously).</p> <p>Check out os.openpty().</...
1
2009-07-20T06:32:52Z
[ "python", "ping", "traceroute" ]
How can I perform a ping or traceroute in python, accessing the output as it is produced?
1,151,897
<p>Earlier, I asked this question:</p> <p><a href="http://stackoverflow.com/questions/1151771/how-can-i-perform-a-ping-or-traceroute-using-native-python">How can I perform a ping or traceroute using native python?</a></p> <p>However because python is not running as root it doens't have the ability to open the raw ICM...
1
2009-07-20T05:53:54Z
19,930,626
<p>Here is another approach:</p> <pre><code># const_output.py import sys from subprocess import Popen if len(sys.argv) &lt; 2: print 'Usage: const_output.py "command to watch"' sys.exit(1) cmd_line = sys.argv[1:] p = Popen(cmd_line) p.communicate()[0] </code></pre> <p>Example usage:</p> <p>traceroute:</p>...
1
2013-11-12T13:35:23Z
[ "python", "ping", "traceroute" ]