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 |
|---|---|---|---|---|---|---|---|---|---|
Traversing a Python object tree | 1,141,039 | <p>I'm trying to implement dynamic reloading objects in Python, that reflect code changes live.</p>
<p>Modules reloading is working, but I have to recreate every instance of the modules' classes for changes to become effective.</p>
<p>The problem is that objects data (objects <code>__dict__</code> content) is lost du... | 1 | 2009-07-17T00:59:26Z | 1,141,337 | <p>For reloading Python code, I came up with this implementation a long time ago.</p>
<p><a href="http://www.codexon.com/posts/a-better-python-reload" rel="nofollow">http://www.codexon.com/posts/a-better-python-reload</a></p>
<p>It's probably the fastest and cleanest way possible.</p>
| 0 | 2009-07-17T03:34:03Z | [
"python",
"reload",
"traversal"
] |
Why was the 'thread' module renamed to '_thread' in Python 3.x? | 1,141,047 | <p>Python 3.x renamed the low-level module 'thread' to '_thread' -- I don't see why in the documentation. Does anyone know?</p>
| 8 | 2009-07-17T01:04:20Z | 1,141,058 | <p>I think the old <code>thread</code> module is deprecated in favour of the higher level <a href="http://docs.python.org/library/threading.html"><code>threading</code></a> module.</p>
| 7 | 2009-07-17T01:10:56Z | [
"python",
"multithreading",
"python-3.x"
] |
Why was the 'thread' module renamed to '_thread' in Python 3.x? | 1,141,047 | <p>Python 3.x renamed the low-level module 'thread' to '_thread' -- I don't see why in the documentation. Does anyone know?</p>
| 8 | 2009-07-17T01:04:20Z | 1,141,059 | <p>It looks like the thread module became obsolete in 3.x in favor of the threading module. See <a href="http://www.python.org/dev/peps/pep-3108/#obsolete">PEP 3108</a>.</p>
| 8 | 2009-07-17T01:11:12Z | [
"python",
"multithreading",
"python-3.x"
] |
Why was the 'thread' module renamed to '_thread' in Python 3.x? | 1,141,047 | <p>Python 3.x renamed the low-level module 'thread' to '_thread' -- I don't see why in the documentation. Does anyone know?</p>
| 8 | 2009-07-17T01:04:20Z | 1,141,115 | <p>It's been quite a long time since the low-level <code>thread</code> module was informally deprecated, with all users heartily encouraged to use the higher-level <code>threading</code> module instead; now with the ability to introduce backwards incompatibilities in Python 3, we've made that deprecation rather more th... | 10 | 2009-07-17T01:43:48Z | [
"python",
"multithreading",
"python-3.x"
] |
Read Block Data in Python? | 1,141,101 | <p>I have a problem reading data file:</p>
<pre><code>///
* ABC Names
A-06,B-18,
* Data
1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
1.219e-01, 1.174e-01, 2.213e-01, 2.875e-01,-2.306e-01,-3.900e-03,-5.269e-02, 7.420e-02,
2.592e-01, 2.513e-01, 2.242e-01, 2.620e-01,-1.346e-0... | 1 | 2009-07-17T01:35:15Z | 1,141,108 | <p>Suppose the file's named "abc.txt" and is in the current directory; then the following Python script:</p>
<pre><code>f = open("abc.txt")
all_lines = f.readlines()
</code></pre>
<p>will read all the lines into list of strings <code>all_lines</code>, each with its ending <code>\n</code> and all.</p>
<p>What you wan... | 0 | 2009-07-17T01:39:55Z | [
"python",
"file"
] |
Read Block Data in Python? | 1,141,101 | <p>I have a problem reading data file:</p>
<pre><code>///
* ABC Names
A-06,B-18,
* Data
1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
1.219e-01, 1.174e-01, 2.213e-01, 2.875e-01,-2.306e-01,-3.900e-03,-5.269e-02, 7.420e-02,
2.592e-01, 2.513e-01, 2.242e-01, 2.620e-01,-1.346e-0... | 1 | 2009-07-17T01:35:15Z | 1,141,117 | <p>Assuming you want to get the block from *Data to *Starting Position, </p>
<pre><code>f=0
for line in open("file"):
line=line.strip()
if "Starting" in line:
f=0
if "Data" in line:
f=1
continue
if f:
print line
</code></pre>
<p>the idea is to set a flag. if *Data is hi... | 0 | 2009-07-17T01:45:27Z | [
"python",
"file"
] |
Read Block Data in Python? | 1,141,101 | <p>I have a problem reading data file:</p>
<pre><code>///
* ABC Names
A-06,B-18,
* Data
1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
1.219e-01, 1.174e-01, 2.213e-01, 2.875e-01,-2.306e-01,-3.900e-03,-5.269e-02, 7.420e-02,
2.592e-01, 2.513e-01, 2.242e-01, 2.620e-01,-1.346e-0... | 1 | 2009-07-17T01:35:15Z | 1,141,148 | <p>This ought to work for files with block names 'a', 'b', and 'c'. It will create a dictionary with keys as block titles like so:</p>
<pre><code>{'a':['line1','line2'],'b':['line1'],'c':['line1','line2','line3']}
</code></pre>
<p>code:</p>
<pre><code>block_names = ['b','a','c']
for line in open('file.txt'):
b... | 1 | 2009-07-17T01:57:31Z | [
"python",
"file"
] |
Read Block Data in Python? | 1,141,101 | <p>I have a problem reading data file:</p>
<pre><code>///
* ABC Names
A-06,B-18,
* Data
1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
1.219e-01, 1.174e-01, 2.213e-01, 2.875e-01,-2.306e-01,-3.900e-03,-5.269e-02, 7.420e-02,
2.592e-01, 2.513e-01, 2.242e-01, 2.620e-01,-1.346e-0... | 1 | 2009-07-17T01:35:15Z | 1,155,094 | <p>Without any other information...</p>
<pre><code>data = [
1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
1.219e-01, 1.174e-01, 2.213e-01, 2.875e-01,-2.306e-01,-3.900e-03,-5.269e-02, 7.420e-02,
2.592e-01, 2.513e-01, 2.242e-01, 2.620e-01,-1.346e-01,-6.844e-02,-4.139e-02, 9.502e... | 0 | 2009-07-20T18:21:56Z | [
"python",
"file"
] |
Read Block Data in Python? | 1,141,101 | <p>I have a problem reading data file:</p>
<pre><code>///
* ABC Names
A-06,B-18,
* Data
1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
1.219e-01, 1.174e-01, 2.213e-01, 2.875e-01,-2.306e-01,-3.900e-03,-5.269e-02, 7.420e-02,
2.592e-01, 2.513e-01, 2.242e-01, 2.620e-01,-1.346e-0... | 1 | 2009-07-17T01:35:15Z | 1,156,722 | <p>Here's a complete guess at some code that might load the type of file this is an example of, but which should be a little robust: </p>
<pre><code>f = open("mdata.txt")
data_dict = {}
section = None
data_for_section = ""
for line in f:
line = line.strip() #remove whitespace at start and end
if section != N... | 2 | 2009-07-21T00:31:31Z | [
"python",
"file"
] |
Read Block Data in Python? | 1,141,101 | <p>I have a problem reading data file:</p>
<pre><code>///
* ABC Names
A-06,B-18,
* Data
1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
1.219e-01, 1.174e-01, 2.213e-01, 2.875e-01,-2.306e-01,-3.900e-03,-5.269e-02, 7.420e-02,
2.592e-01, 2.513e-01, 2.242e-01, 2.620e-01,-1.346e-0... | 1 | 2009-07-17T01:35:15Z | 1,287,071 | <p>Thank you for your reply. However, I attempted to start with Markus's code but failed when between this line and that line exist empty.
Example:
///
"filename.txt" have:
* ABC Names
A-06,B-18,
* Data
1.727e-01, 1.258e-01, 2.724e-01, 2.599e-01,-3.266e-01,-9.425e-02,-6.213e-02, 1.479e-01,
1.219e-01, 1.174e-01, 2.213... | 0 | 2009-08-17T09:47:40Z | [
"python",
"file"
] |
Python networking library for a simple card game | 1,141,130 | <p>I'm trying to implement a fairly simple <a href="http://www.sirlin.net/yomi" rel="nofollow">card game</a> in Python so that two players can play together other the Internet. I have no problem with doing the GUI, but I don't know the first thing about how to do the networking part. A couple libraries I've found so fa... | 3 | 2009-07-17T01:51:34Z | 1,141,183 | <p>Both of those libraries are very good and would work perfectly for your card game.</p>
<p>Pyro might be easier to learn and use, but Twisted will scale better if you ever want to move into a very large number of players.</p>
<p>Twisted can be daunting at first but there are some books to help you get over the hump... | 8 | 2009-07-17T02:11:10Z | [
"python",
"networking"
] |
Python networking library for a simple card game | 1,141,130 | <p>I'm trying to implement a fairly simple <a href="http://www.sirlin.net/yomi" rel="nofollow">card game</a> in Python so that two players can play together other the Internet. I have no problem with doing the GUI, but I don't know the first thing about how to do the networking part. A couple libraries I've found so fa... | 3 | 2009-07-17T01:51:34Z | 1,141,429 | <p>If you decide you don't want to use a 3rd party library, I'd recommend the <a href="http://docs.python.org/library/asynchat.html"><code>asynchat module</code></a> in the standard library. It's perfect for sending/receiving through a simple protocol.</p>
| 5 | 2009-07-17T04:26:15Z | [
"python",
"networking"
] |
Python networking library for a simple card game | 1,141,130 | <p>I'm trying to implement a fairly simple <a href="http://www.sirlin.net/yomi" rel="nofollow">card game</a> in Python so that two players can play together other the Internet. I have no problem with doing the GUI, but I don't know the first thing about how to do the networking part. A couple libraries I've found so fa... | 3 | 2009-07-17T01:51:34Z | 1,142,309 | <p>Twisted is the better of the two libraries but the time spent learning to use it but learning networking will take you similar amount of time (at least for me). </p>
<p>If I were you I'd rather learn networking it will be much more useful to you in the future. The concepts are the same for most languages so its mor... | 3 | 2009-07-17T09:40:42Z | [
"python",
"networking"
] |
trac-past-commit-hook on remote repository | 1,141,157 | <p>Trying to set up the svn commit with trac using <a href="http://trac.edgewall.org/browser/branches/0.11-stable/contrib/trac-post-commit-hook" rel="nofollow">this</a> script.</p>
<p>It is being called without issue, but the problem is this line here:</p>
<pre><code>144 repos = self.env.get_repository()
</code></pre... | 0 | 2009-07-17T02:00:31Z | 1,162,664 | <p>This is totally do-able and just requires a couple of small hacks... woo hoo!</p>
<p>The problem I was having is that get_repository reads the value of the svn repository from the trac.ini file. This was pointing at E:/ and not at Y:/. The simple fix involves a check to see if the repository is at *repository_dir* ... | 0 | 2009-07-22T01:52:00Z | [
"python",
"windows",
"svn",
"trac"
] |
Name this python/ruby language construct (using array values to satisfy function parameters) | 1,141,504 | <p>What is this language construct called?</p>
<p>In Python I can say:</p>
<pre><code>def a(b,c): return b+c
a(*[4,5])
</code></pre>
<p>and get 9. Likewise in Ruby:</p>
<pre><code>def a(b,c) b+c end
a(*[4,5])
</code></pre>
<p>What is this called, when one passes a single array to a function which otherwise require... | 18 | 2009-07-17T05:20:29Z | 1,141,518 | <p>I've been calling it "list expansion", but I don't think that's standard terminology (I don't think there's any...). Lisp in all versions (Scheme included), and Haskell and other functional languages, can do it easily enough, but I don't think it's easy to do in "mainstream" languages (maybe you can pull it off as ... | 2 | 2009-07-17T05:24:43Z | [
"python",
"ruby",
"syntax",
"language-features"
] |
Name this python/ruby language construct (using array values to satisfy function parameters) | 1,141,504 | <p>What is this language construct called?</p>
<p>In Python I can say:</p>
<pre><code>def a(b,c): return b+c
a(*[4,5])
</code></pre>
<p>and get 9. Likewise in Ruby:</p>
<pre><code>def a(b,c) b+c end
a(*[4,5])
</code></pre>
<p>What is this called, when one passes a single array to a function which otherwise require... | 18 | 2009-07-17T05:20:29Z | 1,141,520 | <p>In ruby, it is often called "splat".</p>
<p>Also in ruby, you can use it to mean 'all of the other elements in the list'.</p>
<pre><code>a, *rest = [1,2,3,4,5,6]
a # => 1
rest # => [2, 3, 4, 5, 6]
</code></pre>
<p>It can also appear on either side of the assignment operator:</p>
<pre><code>a = d, *e
... | 10 | 2009-07-17T05:26:05Z | [
"python",
"ruby",
"syntax",
"language-features"
] |
Name this python/ruby language construct (using array values to satisfy function parameters) | 1,141,504 | <p>What is this language construct called?</p>
<p>In Python I can say:</p>
<pre><code>def a(b,c): return b+c
a(*[4,5])
</code></pre>
<p>and get 9. Likewise in Ruby:</p>
<pre><code>def a(b,c) b+c end
a(*[4,5])
</code></pre>
<p>What is this called, when one passes a single array to a function which otherwise require... | 18 | 2009-07-17T05:20:29Z | 1,141,556 | <p>The Python docs call this <a href="http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists">Unpacking Argument Lists</a>. It's a pretty handy feature. In Python, you can also use a double asterisk (**) to unpack a dictionary (hash) into keyword arguments. They also work in reverse. I can define a f... | 25 | 2009-07-17T05:44:12Z | [
"python",
"ruby",
"syntax",
"language-features"
] |
Name this python/ruby language construct (using array values to satisfy function parameters) | 1,141,504 | <p>What is this language construct called?</p>
<p>In Python I can say:</p>
<pre><code>def a(b,c): return b+c
a(*[4,5])
</code></pre>
<p>and get 9. Likewise in Ruby:</p>
<pre><code>def a(b,c) b+c end
a(*[4,5])
</code></pre>
<p>What is this called, when one passes a single array to a function which otherwise require... | 18 | 2009-07-17T05:20:29Z | 1,141,568 | <p>The typical terminology for this is called "applying a function to a list",
or "apply" for short. </p>
<p>See <a href="http://en.wikipedia.org/wiki/Apply">http://en.wikipedia.org/wiki/Apply</a></p>
<p>It has been in LISP since pretty much its inception back in 1960 odd.
Glad python rediscovered it :-}</p>
<p>Appl... | 5 | 2009-07-17T05:48:31Z | [
"python",
"ruby",
"syntax",
"language-features"
] |
Name this python/ruby language construct (using array values to satisfy function parameters) | 1,141,504 | <p>What is this language construct called?</p>
<p>In Python I can say:</p>
<pre><code>def a(b,c): return b+c
a(*[4,5])
</code></pre>
<p>and get 9. Likewise in Ruby:</p>
<pre><code>def a(b,c) b+c end
a(*[4,5])
</code></pre>
<p>What is this called, when one passes a single array to a function which otherwise require... | 18 | 2009-07-17T05:20:29Z | 1,141,642 | <p>Ruby calls it <strong>splat</strong>, though David Black has also come up with the neat <strong>unar{,ra}y operator</strong> (i.e. <strong>unary unarray operator</strong>)</p>
| 3 | 2009-07-17T06:16:04Z | [
"python",
"ruby",
"syntax",
"language-features"
] |
Name this python/ruby language construct (using array values to satisfy function parameters) | 1,141,504 | <p>What is this language construct called?</p>
<p>In Python I can say:</p>
<pre><code>def a(b,c): return b+c
a(*[4,5])
</code></pre>
<p>and get 9. Likewise in Ruby:</p>
<pre><code>def a(b,c) b+c end
a(*[4,5])
</code></pre>
<p>What is this called, when one passes a single array to a function which otherwise require... | 18 | 2009-07-17T05:20:29Z | 1,143,763 | <p>The majority of the questions have already been answered, but as to the question "What is the name of the * operator?": the technical term is "asterisk" (comes from the Latin word <em>asteriscum</em>, meaning "little star", which, in turn, comes from the Greek <em>á¼ÏÏεÏίÏκοÏ</em>). Often, though, it will ... | 1 | 2009-07-17T14:52:18Z | [
"python",
"ruby",
"syntax",
"language-features"
] |
Name this python/ruby language construct (using array values to satisfy function parameters) | 1,141,504 | <p>What is this language construct called?</p>
<p>In Python I can say:</p>
<pre><code>def a(b,c): return b+c
a(*[4,5])
</code></pre>
<p>and get 9. Likewise in Ruby:</p>
<pre><code>def a(b,c) b+c end
a(*[4,5])
</code></pre>
<p>What is this called, when one passes a single array to a function which otherwise require... | 18 | 2009-07-17T05:20:29Z | 1,145,789 | <p>Haskell has it too (for pairs), with the <code>uncurry</code> function:</p>
<pre><code>ghci> let f x y = 2*x + y
f :: (Num a) => a -> a -> a
ghci> f 1 2
4
ghci> f 10 3
23
ghci> uncurry f (1,2)
4
ghci> uncurry f (10,3)
23
</code></pre>
<p>You can also make it into an operator, so it's more s... | 2 | 2009-07-17T21:31:07Z | [
"python",
"ruby",
"syntax",
"language-features"
] |
Using and Installing Django Custom Field Models | 1,141,524 | <p>I found a custom field model (<a href="http://www.djangosnippets.org/snippets/377/" rel="nofollow">JSONField</a>) that I would like to integrate into my Django project. </p>
<ul>
<li><p>Where do I actually put the JSONField.py file? -- Would it reside in my Django project or would I put it in something like: /djang... | 1 | 2009-07-17T05:27:07Z | 1,141,528 | <p>The best thing would be to keep Django and customizations apart. You could place the file anywhere on your pythonpath really </p>
| 0 | 2009-07-17T05:31:10Z | [
"python",
"django",
"django-models"
] |
Using and Installing Django Custom Field Models | 1,141,524 | <p>I found a custom field model (<a href="http://www.djangosnippets.org/snippets/377/" rel="nofollow">JSONField</a>) that I would like to integrate into my Django project. </p>
<ul>
<li><p>Where do I actually put the JSONField.py file? -- Would it reside in my Django project or would I put it in something like: /djang... | 1 | 2009-07-17T05:27:07Z | 1,141,532 | <p>For the first question, I would rather not put it into django directory, because in case of upgrades you may end up loosing all of your changes. It is a general point: modifying an external piece of code will lead to increased maintenance costs.<br />
Therefore, I would suggest you putting it into some place accessi... | 1 | 2009-07-17T05:34:06Z | [
"python",
"django",
"django-models"
] |
Using and Installing Django Custom Field Models | 1,141,524 | <p>I found a custom field model (<a href="http://www.djangosnippets.org/snippets/377/" rel="nofollow">JSONField</a>) that I would like to integrate into my Django project. </p>
<ul>
<li><p>Where do I actually put the JSONField.py file? -- Would it reside in my Django project or would I put it in something like: /djang... | 1 | 2009-07-17T05:27:07Z | 1,143,201 | <p>It's worth remembering that Django is just Python, and so the same rules apply to Django customisations as they would for any other random Python library you might download. To use a bit of code, it has to be in a module somewhere on your Pythonpath, and then you can just to <code>from foo import x</code>. </p>
<p>... | 2 | 2009-07-17T13:15:43Z | [
"python",
"django",
"django-models"
] |
encryption with python | 1,141,542 | <p>If I want to use:</p>
<pre><code>recip = M2Crypto.RSA.load_pub_key(open('recipient_public_key.pem','rb').read())
</code></pre>
<p>Then how will it retrieve the key? What will recip will print?</p>
<p>I need to get the public key of the recipient from the server(open key server) and for that first I need to store ... | 1 | 2009-07-17T05:39:01Z | 1,141,783 | <p>check what public_key.pem returns .clear this how you want to recognize your recipient .</p>
| 0 | 2009-07-17T07:07:52Z | [
"python",
"cryptography",
"rsa"
] |
How to hide a bulletpoint in blog | 1,141,774 | <p>how to hide a bullet points? example like this website</p>
<p><a href="http://www.grainge.org/pages/various_rh_projects/alt_dropdowns/showhide_3/showhide3.htm" rel="nofollow">http://www.grainge.org/pages/various_rh_projects/alt_dropdowns/showhide_3/showhide3.htm</a></p>
<p>you can see the example</p>
<p>first Ho... | 0 | 2009-07-17T07:04:16Z | 1,141,784 | <p>This is done in JavaScript, not python, I would wager.
Basic strategy:</p>
<ul>
<li>Start by adding (in the HTML) class="hideme" to the div's or p's or li's you want to affect. </li>
<li>Then using something like the below hideClass(class) function (jQuery would be worth looking at too), select all parts of the pag... | 1 | 2009-07-17T07:08:15Z | [
"javascript",
"jquery",
"python",
"html",
"css"
] |
How to hide a bulletpoint in blog | 1,141,774 | <p>how to hide a bullet points? example like this website</p>
<p><a href="http://www.grainge.org/pages/various_rh_projects/alt_dropdowns/showhide_3/showhide3.htm" rel="nofollow">http://www.grainge.org/pages/various_rh_projects/alt_dropdowns/showhide_3/showhide3.htm</a></p>
<p>you can see the example</p>
<p>first Ho... | 0 | 2009-07-17T07:04:16Z | 1,141,829 | <p>This is certainly done with javascript.</p>
<p>Another possibility is to have empty elements </p>
<p><code><div id="myelt"></div></code></p>
<p>and to change the html content of this element </p>
<p><code>document.getElementById('myelt').innerHTML = "My text";</code></p>
| 1 | 2009-07-17T07:24:57Z | [
"javascript",
"jquery",
"python",
"html",
"css"
] |
How to hide a bulletpoint in blog | 1,141,774 | <p>how to hide a bullet points? example like this website</p>
<p><a href="http://www.grainge.org/pages/various_rh_projects/alt_dropdowns/showhide_3/showhide3.htm" rel="nofollow">http://www.grainge.org/pages/various_rh_projects/alt_dropdowns/showhide_3/showhide3.htm</a></p>
<p>you can see the example</p>
<p>first Ho... | 0 | 2009-07-17T07:04:16Z | 1,141,845 | <p>In jQuery you could do it like this (v. quick example):</p>
<pre><code>$(function(){
$('ul ul')
.hide() //Hide the sub-lists
.siblings('a').click(function(){
$(this).siblings('ul').toggle(); //show or hide the hidden ul
});
});
</code></pre>
<p>This should also allow for sub... | 0 | 2009-07-17T07:29:49Z | [
"javascript",
"jquery",
"python",
"html",
"css"
] |
MySQL db problem in Python | 1,141,790 | <p>For me mysql db has been successfully instaled in my system.I verified through the following code that it is successfully installed without any errors.</p>
<pre><code>C:\Python26>python
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "l... | 0 | 2009-07-17T07:10:37Z | 1,141,795 | <p>Since you show you are running linux, but you mention that mysql is running on windows, I suspect that you don't have MySQL, or the MySQL libraries or Python bindings, installed on the linux machine.</p>
| 0 | 2009-07-17T07:13:34Z | [
"python",
"mysql"
] |
MySQL db problem in Python | 1,141,790 | <p>For me mysql db has been successfully instaled in my system.I verified through the following code that it is successfully installed without any errors.</p>
<pre><code>C:\Python26>python
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "l... | 0 | 2009-07-17T07:10:37Z | 1,141,894 | <p>1) Try using your package manager to download <strong><a href="http://www.novell.com/products/linuxpackages/server10/i386/python-mysql.html" rel="nofollow">python-mysql</a></strong> which includes MySQLdb.</p>
<p>2) Ensure <code>/usr/lib/python2.4/site-packages/</code> is in your <a href="http://docs.python.org/usi... | 2 | 2009-07-17T07:46:24Z | [
"python",
"mysql"
] |
defining functions in decorator | 1,141,902 | <p>Why does this not work? How can I make it work? That is, how can I make gu accessible inside my decorated function?</p>
<pre><code>def decorate(f):
def new_f():
def gu():
pass
f()
return new_f
@decorate
def fu():
gu()
fu()
</code></pre>
<p>Do I need to add gu to a dictio... | 1 | 2009-07-17T07:50:10Z | 1,141,912 | <p><b>gu</b> is local to the <b>new_f</b> function, which is local to the <b>decorate</b> function.</p>
| 1 | 2009-07-17T07:53:25Z | [
"python",
"aop",
"decorator",
"argument-passing"
] |
defining functions in decorator | 1,141,902 | <p>Why does this not work? How can I make it work? That is, how can I make gu accessible inside my decorated function?</p>
<pre><code>def decorate(f):
def new_f():
def gu():
pass
f()
return new_f
@decorate
def fu():
gu()
fu()
</code></pre>
<p>Do I need to add gu to a dictio... | 1 | 2009-07-17T07:50:10Z | 1,141,918 | <p>gu() is only defined within new_f(). Unless you return it or anchor it to new_f() or something else, it cannot be referenced from outside new_f()</p>
<p>I don't know what you're up to, but this scheme seems very complex. Maybe you can find a less complicated solution.</p>
| 1 | 2009-07-17T07:54:30Z | [
"python",
"aop",
"decorator",
"argument-passing"
] |
defining functions in decorator | 1,141,902 | <p>Why does this not work? How can I make it work? That is, how can I make gu accessible inside my decorated function?</p>
<pre><code>def decorate(f):
def new_f():
def gu():
pass
f()
return new_f
@decorate
def fu():
gu()
fu()
</code></pre>
<p>Do I need to add gu to a dictio... | 1 | 2009-07-17T07:50:10Z | 1,141,922 | <p>If you need to pass <code>gu</code> to <code>fu</code> you need to do this explicitly by parameters:</p>
<pre><code>def decorate(f):
def new_f():
def gu():
pass
f(gu)
return new_f
@decorate
def fu(gu):
gu()
fu()
</code></pre>
| 2 | 2009-07-17T07:56:28Z | [
"python",
"aop",
"decorator",
"argument-passing"
] |
defining functions in decorator | 1,141,902 | <p>Why does this not work? How can I make it work? That is, how can I make gu accessible inside my decorated function?</p>
<pre><code>def decorate(f):
def new_f():
def gu():
pass
f()
return new_f
@decorate
def fu():
gu()
fu()
</code></pre>
<p>Do I need to add gu to a dictio... | 1 | 2009-07-17T07:50:10Z | 1,142,123 | <p>In principle you can create a new function using the same code as the old one but substituting the global scope with an amended one:</p>
<pre><code>import new
def with_bar(func):
def bar(x):
return x + 1
f_globals = func.func_globals.copy()
f_globals['bar'] = bar
return new.function(func.fu... | 0 | 2009-07-17T08:56:36Z | [
"python",
"aop",
"decorator",
"argument-passing"
] |
defining functions in decorator | 1,141,902 | <p>Why does this not work? How can I make it work? That is, how can I make gu accessible inside my decorated function?</p>
<pre><code>def decorate(f):
def new_f():
def gu():
pass
f()
return new_f
@decorate
def fu():
gu()
fu()
</code></pre>
<p>Do I need to add gu to a dictio... | 1 | 2009-07-17T07:50:10Z | 1,144,072 | <p>Why not make your decorator a class rather than a function? It's apparently possible, as I discovered when I looked through the help for the <code>property</code> builtin. (Previously, I had thought that you could merely apply decorators to classes, and not that the decorators themselves could be classes.)</p>
<p>(... | 0 | 2009-07-17T15:38:50Z | [
"python",
"aop",
"decorator",
"argument-passing"
] |
How to modify the local namespace in python | 1,142,068 | <p>How can I modify the local namespace of a function in python? I know that locals() returns the local namespace of the function when called inside it, but I want to do something like this (I have a reason why I want to do this where g is not accessible to f, but it's quicker to give a trivial, stupid example to illu... | 3 | 2009-07-17T08:43:24Z | 1,142,115 | <p>Since the function isn't invoked, it has no "local" stack frame, yet. The most simple solution is to use a global context:</p>
<pre><code>handler = None
def f():
handler()
def g(): pass
handler = g
</code></pre>
<p>Or you could set g on the function object:</p>
<pre><code>f.g = g
</code></pre>
<p>But I'm n... | 2 | 2009-07-17T08:54:45Z | [
"python",
"namespaces",
"local"
] |
How to modify the local namespace in python | 1,142,068 | <p>How can I modify the local namespace of a function in python? I know that locals() returns the local namespace of the function when called inside it, but I want to do something like this (I have a reason why I want to do this where g is not accessible to f, but it's quicker to give a trivial, stupid example to illu... | 3 | 2009-07-17T08:43:24Z | 1,142,120 | <p>A function that's not executing doesn't have any locals; the local context is created when you run the function, and destroyed when it exits, so there's no "local namespace" to modify from outside the function.</p>
<p>You can do something like this, though:</p>
<pre><code>def f():
g = [1]
def func():
... | 1 | 2009-07-17T08:56:19Z | [
"python",
"namespaces",
"local"
] |
How to modify the local namespace in python | 1,142,068 | <p>How can I modify the local namespace of a function in python? I know that locals() returns the local namespace of the function when called inside it, but I want to do something like this (I have a reason why I want to do this where g is not accessible to f, but it's quicker to give a trivial, stupid example to illu... | 3 | 2009-07-17T08:43:24Z | 1,142,244 | <p>I think you could solve the problem tackling it from a completely different point.<br />
Functions are object, with their dictionaries; therefore, you can add g to f, and use it:</p>
<pre><code>def g():
print "g"
def f():
f.g()
f.g = g
</code></pre>
| 1 | 2009-07-17T09:24:05Z | [
"python",
"namespaces",
"local"
] |
How to modify the local namespace in python | 1,142,068 | <p>How can I modify the local namespace of a function in python? I know that locals() returns the local namespace of the function when called inside it, but I want to do something like this (I have a reason why I want to do this where g is not accessible to f, but it's quicker to give a trivial, stupid example to illu... | 3 | 2009-07-17T08:43:24Z | 1,142,259 | <p>Why don't you just add an argument to <code>f()</code> and pass a reference to <code>g()</code>?</p>
<pre><code>def g():
pass
def f(func):
func()
f(g)
</code></pre>
| 3 | 2009-07-17T09:29:45Z | [
"python",
"namespaces",
"local"
] |
How to modify the local namespace in python | 1,142,068 | <p>How can I modify the local namespace of a function in python? I know that locals() returns the local namespace of the function when called inside it, but I want to do something like this (I have a reason why I want to do this where g is not accessible to f, but it's quicker to give a trivial, stupid example to illu... | 3 | 2009-07-17T08:43:24Z | 1,142,397 | <p>I assume you want to do this, because the function f is defined not by you, but by some other module. So you want to change how f() works. In particular, you want to change what is called when g is called.</p>
<p>So I'll suggest this:</p>
<pre><code>import thirdpartypackage
def mynewg():
pass
thirdpartypackag... | 2 | 2009-07-17T10:03:47Z | [
"python",
"namespaces",
"local"
] |
How to modify the local namespace in python | 1,142,068 | <p>How can I modify the local namespace of a function in python? I know that locals() returns the local namespace of the function when called inside it, but I want to do something like this (I have a reason why I want to do this where g is not accessible to f, but it's quicker to give a trivial, stupid example to illu... | 3 | 2009-07-17T08:43:24Z | 1,144,561 | <p>You've a couple of options. First, note that g in your example isn't actually a local to the function (ie. not assigned within it), it's a global (ie hasn't been assigned to a local variable). This means that it will be looked up in the module the function is defined in. This is fortunate, as there's no way of al... | 8 | 2009-07-17T17:07:52Z | [
"python",
"namespaces",
"local"
] |
How to modify the local namespace in python | 1,142,068 | <p>How can I modify the local namespace of a function in python? I know that locals() returns the local namespace of the function when called inside it, but I want to do something like this (I have a reason why I want to do this where g is not accessible to f, but it's quicker to give a trivial, stupid example to illu... | 3 | 2009-07-17T08:43:24Z | 8,741,511 | <p>This seems to work</p>
<pre><code>def add_to_locals(l):
l['newlocal'] = 1
add_to_locals(locals())
assert newlocal
</code></pre>
| 0 | 2012-01-05T11:12:52Z | [
"python",
"namespaces",
"local"
] |
Problem executing with Python+MySQL | 1,142,098 | <p>I am not getting the reason why my python script is not working though I hv put all the things correctly as my knowledge.The below test I did and it worked fine.But when I import the MySQLdb in my script it gives error as no module name MySQLdb.</p>
<p>**C:\Python26>python
Python 2.6.1 (r261:67517, Dec 4 2008, 16:... | -1 | 2009-07-17T08:50:24Z | 1,142,113 | <p>seems like the path is not set properly.</p>
| 0 | 2009-07-17T08:54:14Z | [
"python",
"mysql"
] |
Python @property versus method performance - which one to use? | 1,142,133 | <p>I have written some code that uses attributes of an object:</p>
<pre><code>class Foo:
def __init__(self):
self.bar = "baz"
myFoo = Foo()
print (myFoo.bar)
</code></pre>
<p>Now I want to do some fancy calculation to return <code>bar</code>. I could use <code>@property</code> to make methods act as the a... | 11 | 2009-07-17T08:58:39Z | 1,142,186 | <p>If it's logically a property/attribute of the object, I'd say keep it as a property. If it's likely to become parametrised, by which I mean you may want to invoke <code>myFoo.bar(someArgs)</code> then bite the bullet now and make it a method.</p>
<p>Under most circumstances, performance is unlikely to be an issue.<... | 18 | 2009-07-17T09:11:49Z | [
"python",
"performance",
"properties"
] |
Python @property versus method performance - which one to use? | 1,142,133 | <p>I have written some code that uses attributes of an object:</p>
<pre><code>class Foo:
def __init__(self):
self.bar = "baz"
myFoo = Foo()
print (myFoo.bar)
</code></pre>
<p>Now I want to do some fancy calculation to return <code>bar</code>. I could use <code>@property</code> to make methods act as the a... | 11 | 2009-07-17T08:58:39Z | 1,142,190 | <p>In cases like these, I find it much better to choose the option that makes the most sense. You won't get any noticeable performance loss with small differences like these. It's much more important that your code is easy to use and maintain.</p>
<p>As for choosing between using a method and a <code>@property</code>,... | 6 | 2009-07-17T09:12:16Z | [
"python",
"performance",
"properties"
] |
Python @property versus method performance - which one to use? | 1,142,133 | <p>I have written some code that uses attributes of an object:</p>
<pre><code>class Foo:
def __init__(self):
self.bar = "baz"
myFoo = Foo()
print (myFoo.bar)
</code></pre>
<p>Now I want to do some fancy calculation to return <code>bar</code>. I could use <code>@property</code> to make methods act as the a... | 11 | 2009-07-17T08:58:39Z | 1,142,192 | <p>That's exactly what @property is meant for.</p>
| 1 | 2009-07-17T09:12:40Z | [
"python",
"performance",
"properties"
] |
Python @property versus method performance - which one to use? | 1,142,133 | <p>I have written some code that uses attributes of an object:</p>
<pre><code>class Foo:
def __init__(self):
self.bar = "baz"
myFoo = Foo()
print (myFoo.bar)
</code></pre>
<p>Now I want to do some fancy calculation to return <code>bar</code>. I could use <code>@property</code> to make methods act as the a... | 11 | 2009-07-17T08:58:39Z | 1,142,205 | <p>I would go for the refactoring, but only for a matter of style - it seems clearer to me that "fancy calculations" might be ongoing with a method call, while I would expect a property to be almost a no-op, but this is a matter of taste.</p>
<p>Don't worry about the decorator's performance... if you think that it mig... | 3 | 2009-07-17T09:15:34Z | [
"python",
"performance",
"properties"
] |
Python @property versus method performance - which one to use? | 1,142,133 | <p>I have written some code that uses attributes of an object:</p>
<pre><code>class Foo:
def __init__(self):
self.bar = "baz"
myFoo = Foo()
print (myFoo.bar)
</code></pre>
<p>Now I want to do some fancy calculation to return <code>bar</code>. I could use <code>@property</code> to make methods act as the a... | 11 | 2009-07-17T08:58:39Z | 1,143,856 | <p>Wondering about performance is needless when it's so easy to measure it:</p>
<pre><code>$ python -mtimeit -s'class X(object):
> @property
> def y(self): return 23
> x=X()' 'x.y'
1000000 loops, best of 3: 0.685 usec per loop
$ python -mtimeit -s'class X(object):
def y(self): return 23
x=X()' 'x.y()'
... | 15 | 2009-07-17T15:06:38Z | [
"python",
"performance",
"properties"
] |
Python @property versus method performance - which one to use? | 1,142,133 | <p>I have written some code that uses attributes of an object:</p>
<pre><code>class Foo:
def __init__(self):
self.bar = "baz"
myFoo = Foo()
print (myFoo.bar)
</code></pre>
<p>Now I want to do some fancy calculation to return <code>bar</code>. I could use <code>@property</code> to make methods act as the a... | 11 | 2009-07-17T08:58:39Z | 1,144,085 | <p>I agree with what most people here have said, I did much measurement when building hydrologic models in Python a couple years ago and found that the speed hit from using @property was <em>completely</em> overshadowed by calculation. </p>
<p>As an example, creating method local variables (removing the "dot factor" i... | 2 | 2009-07-17T15:40:53Z | [
"python",
"performance",
"properties"
] |
Django: Why do some model fields clash with each other? | 1,142,378 | <p>I want to create an object that contains 2 links to Users. For example:</p>
<pre><code>class GameClaim(models.Model):
target = models.ForeignKey(User)
claimer = models.ForeignKey(User)
isAccepted = models.BooleanField()
</code></pre>
<p>but I am getting the following errors when running the server:</p>... | 147 | 2009-07-17T09:59:08Z | 1,142,467 | <p>The <code>User</code> model is trying to create two fields with the same name, one for the <code>GameClaims</code> that have that <code>User</code> as the <code>target</code>, and another for the <code>GameClaims</code> that have that <code>User</code> as the <code>claimer</code>. Here's the <a href="http://docs.dja... | 6 | 2009-07-17T10:19:14Z | [
"python",
"django",
"django-models"
] |
Django: Why do some model fields clash with each other? | 1,142,378 | <p>I want to create an object that contains 2 links to Users. For example:</p>
<pre><code>class GameClaim(models.Model):
target = models.ForeignKey(User)
claimer = models.ForeignKey(User)
isAccepted = models.BooleanField()
</code></pre>
<p>but I am getting the following errors when running the server:</p>... | 147 | 2009-07-17T09:59:08Z | 1,142,473 | <p>You have two foreign keys to User. Django automatically creates a reverse relation from User back to GameClaim, which is usually <code>gameclaim_set</code>. However, because you have two FKs, you would have two <code>gameclaim_set</code> attributes, which is obviously impossible. So you need to tell Django what name... | 259 | 2009-07-17T10:20:48Z | [
"python",
"django",
"django-models"
] |
Django: Why do some model fields clash with each other? | 1,142,378 | <p>I want to create an object that contains 2 links to Users. For example:</p>
<pre><code>class GameClaim(models.Model):
target = models.ForeignKey(User)
claimer = models.ForeignKey(User)
isAccepted = models.BooleanField()
</code></pre>
<p>but I am getting the following errors when running the server:</p>... | 147 | 2009-07-17T09:59:08Z | 3,517,643 | <p>The OP isn't using a abstract base class... but if you are, you will find that hard coding the related_name in the FK (e.g. ..., related_name="myname") will result in a number of these conflict errors - one for each inherited class from the base class. The link provided below contains the workaround, which is simple... | 4 | 2010-08-18T23:48:31Z | [
"python",
"django",
"django-models"
] |
Django: Why do some model fields clash with each other? | 1,142,378 | <p>I want to create an object that contains 2 links to Users. For example:</p>
<pre><code>class GameClaim(models.Model):
target = models.ForeignKey(User)
claimer = models.ForeignKey(User)
isAccepted = models.BooleanField()
</code></pre>
<p>but I am getting the following errors when running the server:</p>... | 147 | 2009-07-17T09:59:08Z | 13,407,176 | <p>I seem to come across this occasionally when I add a submodule as an application to a django project, for example given the following structure:</p>
<pre><code>myapp/
myapp/module/
myapp/module/models.py
</code></pre>
<p>If I add the following to INSTALLED_APPS:</p>
<pre><code>'myapp',
'myapp.module',
</code></pr... | 0 | 2012-11-15T22:13:52Z | [
"python",
"django",
"django-models"
] |
Django: Why do some model fields clash with each other? | 1,142,378 | <p>I want to create an object that contains 2 links to Users. For example:</p>
<pre><code>class GameClaim(models.Model):
target = models.ForeignKey(User)
claimer = models.ForeignKey(User)
isAccepted = models.BooleanField()
</code></pre>
<p>but I am getting the following errors when running the server:</p>... | 147 | 2009-07-17T09:59:08Z | 31,903,422 | <p>Just adding to Jordan's answer (thanks for the tip Jordan) it can also happen if you import the level above the apps and then import the apps e.g.</p>
<p><code>myproject/
apps/
foo_app/
bar_app/</code></p>
<p>So if you are importing apps, foo_app and bar_app then you could get this issue. I had... | 0 | 2015-08-09T10:53:13Z | [
"python",
"django",
"django-models"
] |
Django: Why do some model fields clash with each other? | 1,142,378 | <p>I want to create an object that contains 2 links to Users. For example:</p>
<pre><code>class GameClaim(models.Model):
target = models.ForeignKey(User)
claimer = models.ForeignKey(User)
isAccepted = models.BooleanField()
</code></pre>
<p>but I am getting the following errors when running the server:</p>... | 147 | 2009-07-17T09:59:08Z | 34,833,294 | <p>I had the same problem. Using run python manage.py makemigrations "appname" fixed it for me. I had accidentally deleted some migration files. No need to re-delete any files.</p>
| -2 | 2016-01-16T23:25:13Z | [
"python",
"django",
"django-models"
] |
Convert HTML to Django Fixture (JSON) | 1,142,702 | <p>We've got a couple of Django flatpages in our project, that are based on actual HTML files. These files undergo some changes once in a while and hence have to updated in the database. So I came up with the idea of simply copying the plain HTML text into a JSON fixture and do an <code>manage.py loaddata</code>.</p>
... | -1 | 2009-07-17T11:27:50Z | 1,142,887 | <p>You could <a href="http://docs.djangoproject.com/en/dev/howto/custom-management-commands/#howto-custom-management-commands" rel="nofollow">write your own manage.py command</a> to read in the HTML file and adding them to the flatpages:</p>
<pre><code># Assuming variable html contains the new HTML file,
#+ and var i... | 1 | 2009-07-17T12:09:17Z | [
"python",
"django",
"json"
] |
AttributeError: 'unicode' object has no attribute '_meta' | 1,142,717 | <p>I am getting this error on "python manage.py migrate contacts".</p>
<p>The error info does not pinpoint problem location. </p>
<p>Here is the error description:</p>
<p><a href="http://dpaste.com/68162/" rel="nofollow">http://dpaste.com/68162/</a></p>
<p>Hers is a sample model definition:</p>
<p><a href="http://... | 1 | 2009-07-17T11:30:17Z | 1,142,929 | <p>Figured out the problem. There was this line:</p>
<pre><code>note = GenericRelation('Comment', object_id_field='object_pk')
</code></pre>
<p>in model <code>Company</code> and <code>Person</code>. But <code>Comment</code> class was undefined. I commented the line at both places. It works now.</p>
<p>Thanks for yo... | 2 | 2009-07-17T12:16:35Z | [
"python",
"django"
] |
python + Spreadsheet | 1,142,730 | <p>Can anybody please tell me is there any possible way to connect to spreadsheet from python? I want to store some data from a form and submit it to google spreadsheet. Please help on this issue. What steps do I have to follow?</p>
<p>Thanks in advance...</p>
| 4 | 2009-07-17T11:34:59Z | 1,142,742 | <p>There is a python api for google docs <a href="http://code.google.com/intl/fr/apis/gdata/articles/python_client_lib.html" rel="nofollow">http://code.google.com/intl/fr/apis/gdata/articles/python_client_lib.html</a>. I am not sure if it works with app engine</p>
| 1 | 2009-07-17T11:37:36Z | [
"python",
"google-app-engine",
"google-spreadsheet"
] |
python + Spreadsheet | 1,142,730 | <p>Can anybody please tell me is there any possible way to connect to spreadsheet from python? I want to store some data from a form and submit it to google spreadsheet. Please help on this issue. What steps do I have to follow?</p>
<p>Thanks in advance...</p>
| 4 | 2009-07-17T11:34:59Z | 1,143,678 | <p>Sure, you can validate with OAuth then use the gdata Python API -- see <a href="http://groups.google.com/group/gdata-python-client-library-contributors/browse%5Fthread/thread/19d93048d9914cd6" rel="nofollow">this thread</a> for more details and caveats, <a href="http://code.google.com/p/gdata-python-client/source/br... | 1 | 2009-07-17T14:38:04Z | [
"python",
"google-app-engine",
"google-spreadsheet"
] |
python + Spreadsheet | 1,142,730 | <p>Can anybody please tell me is there any possible way to connect to spreadsheet from python? I want to store some data from a form and submit it to google spreadsheet. Please help on this issue. What steps do I have to follow?</p>
<p>Thanks in advance...</p>
| 4 | 2009-07-17T11:34:59Z | 5,413,289 | <p>I have recently written a module to do this. check it out <a href="https://sourceforge.net/projects/pyworkbooks/" rel="nofollow">https://sourceforge.net/projects/pyworkbooks/</a></p>
| 0 | 2011-03-24T00:22:24Z | [
"python",
"google-app-engine",
"google-spreadsheet"
] |
python + Spreadsheet | 1,142,730 | <p>Can anybody please tell me is there any possible way to connect to spreadsheet from python? I want to store some data from a form and submit it to google spreadsheet. Please help on this issue. What steps do I have to follow?</p>
<p>Thanks in advance...</p>
| 4 | 2009-07-17T11:34:59Z | 8,532,699 | <p>The easiest way to connect to Google Spreadsheet is by using this <a href="http://burnash.github.com/gspread">spreadsheet library</a>. These are the steps you need to follow:</p>
<pre><code>import gspread
# Login with your Google account
gc = gspread.login('account@gmail.com','password')
# Spreadsheets can be ope... | 9 | 2011-12-16T10:14:08Z | [
"python",
"google-app-engine",
"google-spreadsheet"
] |
python + Spreadsheet | 1,142,730 | <p>Can anybody please tell me is there any possible way to connect to spreadsheet from python? I want to store some data from a form and submit it to google spreadsheet. Please help on this issue. What steps do I have to follow?</p>
<p>Thanks in advance...</p>
| 4 | 2009-07-17T11:34:59Z | 10,110,465 | <p>Here is a very simple wrapper for the Google Spreasheets API i've recently written:</p>
<p><a href="http://github.com/yoavaviram/python-google-spreadsheet" rel="nofollow">http://github.com/yoavaviram/python-google-spreadsheet</a></p>
<p>Its compatible with App Engine.</p>
| 1 | 2012-04-11T16:54:18Z | [
"python",
"google-app-engine",
"google-spreadsheet"
] |
Merge some list items in a Python List | 1,142,851 | <p>Say I have a list like this:</p>
<pre><code>[a, b, c, d, e, f, g]
</code></pre>
<p>How do modify that list so that it looks like this?</p>
<pre><code>[a, b, c, def, g]
</code></pre>
<p>I would much prefer that it modified the existing list directly, not created a new list. </p>
| 11 | 2009-07-17T12:03:05Z | 1,142,876 | <p>That example is pretty vague, but maybe something like this?</p>
<pre><code>items = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
items[3:6] = [''.join(items[3:6])]
</code></pre>
<p>It basically does a splice (or <a href="http://docs.python.org/tutorial/introduction.html#lists">assignment to a slice</a>) operation. It ... | 20 | 2009-07-17T12:07:51Z | [
"python",
"list",
"concatenation"
] |
Merge some list items in a Python List | 1,142,851 | <p>Say I have a list like this:</p>
<pre><code>[a, b, c, d, e, f, g]
</code></pre>
<p>How do modify that list so that it looks like this?</p>
<pre><code>[a, b, c, def, g]
</code></pre>
<p>I would much prefer that it modified the existing list directly, not created a new list. </p>
| 11 | 2009-07-17T12:03:05Z | 1,142,879 | <p>On what basis should the merging take place? Your question is rather vague. Also, I assume a, b, ..., f are supposed to be strings, that is, 'a', 'b', ..., 'f'.</p>
<pre><code>>>> x = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
>>> x[3:6] = [''.join(x[3:6])]
>>> x
['a', 'b', 'c', 'def', 'g']
</co... | 26 | 2009-07-17T12:08:15Z | [
"python",
"list",
"concatenation"
] |
Merge some list items in a Python List | 1,142,851 | <p>Say I have a list like this:</p>
<pre><code>[a, b, c, d, e, f, g]
</code></pre>
<p>How do modify that list so that it looks like this?</p>
<pre><code>[a, b, c, def, g]
</code></pre>
<p>I would much prefer that it modified the existing list directly, not created a new list. </p>
| 11 | 2009-07-17T12:03:05Z | 1,142,906 | <p>my telepathic abilities are not particularly great, but here is what I think you want:</p>
<pre><code>def merge(list_of_strings, indices):
list_of_strings[indices[0]] = ''.join(list_of_strings[i] for i in indices)
list_of_strings = [s for i, s in enumerate(list_of_strings) if i not in indices[1:]]
retur... | 0 | 2009-07-17T12:12:36Z | [
"python",
"list",
"concatenation"
] |
Merge some list items in a Python List | 1,142,851 | <p>Say I have a list like this:</p>
<pre><code>[a, b, c, d, e, f, g]
</code></pre>
<p>How do modify that list so that it looks like this?</p>
<pre><code>[a, b, c, def, g]
</code></pre>
<p>I would much prefer that it modified the existing list directly, not created a new list. </p>
| 11 | 2009-07-17T12:03:05Z | 1,143,043 | <p>just a variation</p>
<pre><code>alist=["a", "b", "c", "d", "e", 0, "g"]
alist[3:6] = [''.join(map(str,alist[3:6]))]
print alist
</code></pre>
| 2 | 2009-07-17T12:43:12Z | [
"python",
"list",
"concatenation"
] |
PyQt: Overriding QGraphicsView.drawItems | 1,142,970 | <p>I need to customize the drawing process of a QGraphicsView, and so I override the drawItems method like this:</p>
<pre><code>self.graphicsview.drawItems=self.drawer.drawItems
</code></pre>
<p>where <code>self.graphicsview</code> is a QGraphicsView, and <code>self.drawer</code> is a custom class with a method <code... | 3 | 2009-07-17T12:25:04Z | 1,143,218 | <p>The reason why the loop suddenly exits is that an Exception is thrown. Python doesn't handle it (there is no <code>try:</code> block), so it's passed to the called (Qt's C++ code) which has no idea about Python exceptions, so it's lost.</p>
<p>Add a try/except around the loop and you should see the reason why this ... | 0 | 2009-07-17T13:20:47Z | [
"python",
"pyqt"
] |
PyQt: Overriding QGraphicsView.drawItems | 1,142,970 | <p>I need to customize the drawing process of a QGraphicsView, and so I override the drawItems method like this:</p>
<pre><code>self.graphicsview.drawItems=self.drawer.drawItems
</code></pre>
<p>where <code>self.graphicsview</code> is a QGraphicsView, and <code>self.drawer</code> is a custom class with a method <code... | 3 | 2009-07-17T12:25:04Z | 1,143,459 | <p>There is an exception that occurs when the items are painted, but it is not reported right away. On my system (PyQt 4.5.1, Python 2.6), no exception is reported when I monkey-patch the following method:</p>
<pre><code>def drawItems(painter, items, options):
print len(items)
for idx, i in enumerate(items):
... | 3 | 2009-07-17T13:58:52Z | [
"python",
"pyqt"
] |
Create NTFS junction point in Python | 1,143,260 | <p>Is there a way to create an NTFS junction point in Python? I know I can call the <code>junction</code> utility, but it would be better not to rely on external tools.</p>
| 8 | 2009-07-17T13:27:31Z | 1,143,276 | <p>You don't want to rely on external tools but you don't mind relying on the specific environment? I think you could safely assume that, if it's NTFS you're running on, the junction utility will probably be there.</p>
<p>But, if you mean you'd rather not call out to an external program, I've found the <a href="http:/... | 0 | 2009-07-17T13:30:26Z | [
"python",
"windows",
"ntfs",
"junction"
] |
Create NTFS junction point in Python | 1,143,260 | <p>Is there a way to create an NTFS junction point in Python? I know I can call the <code>junction</code> utility, but it would be better not to rely on external tools.</p>
| 8 | 2009-07-17T13:27:31Z | 1,143,329 | <p>you can use python win32 API modules e.g.</p>
<pre><code>import win32file
win32file.CreateSymbolicLink(srcDir, targetDir, 1)
</code></pre>
<p>see <a href="http://docs.activestate.com/activepython/2.5/pywin32/win32file__CreateSymbolicLink_meth.html" rel="nofollow">http://docs.activestate.com/activepython/2.5/pywin... | 8 | 2009-07-17T13:38:16Z | [
"python",
"windows",
"ntfs",
"junction"
] |
Create NTFS junction point in Python | 1,143,260 | <p>Is there a way to create an NTFS junction point in Python? I know I can call the <code>junction</code> utility, but it would be better not to rely on external tools.</p>
| 8 | 2009-07-17T13:27:31Z | 10,221,068 | <p>I answered this in a <a href="http://stackoverflow.com/questions/1447575/symlinks-on-windows/7924557#7924557">similar question</a>, so I'll copy my answer to that below. Since writing that answer, I ended up writing a python-only (if you can call a module that uses ctypes python-only) module to creating, reading, an... | 5 | 2012-04-19T02:59:18Z | [
"python",
"windows",
"ntfs",
"junction"
] |
Create NTFS junction point in Python | 1,143,260 | <p>Is there a way to create an NTFS junction point in Python? I know I can call the <code>junction</code> utility, but it would be better not to rely on external tools.</p>
| 8 | 2009-07-17T13:27:31Z | 35,137,978 | <p>Since Python 3.5 there's a function <code>CreateJunction</code> in <code>_winapi</code> module.</p>
<pre><code>import _winapi
_winapi.CreateJunction(source, target)
</code></pre>
| 1 | 2016-02-01T18:46:26Z | [
"python",
"windows",
"ntfs",
"junction"
] |
Removing duplicates from list of lists in Python | 1,143,379 | <p>Can anyone suggest a good solution to remove duplicates from nested lists if wanting to evaluate duplicates based on first element of each nested list?</p>
<p>The main list looks like this:</p>
<pre><code>L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46]]
</code></pre>
<p>If there is another... | 7 | 2009-07-17T13:45:48Z | 1,143,408 | <p>i am not sure what you meant by "another list", so i assume you are saying those lists inside L</p>
<pre><code>a=[]
L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46],['7','a','b']]
for item in L:
if not item[0] in a:
a.append(item[0])
print item
</code></pre>
| 0 | 2009-07-17T13:50:49Z | [
"python",
"list"
] |
Removing duplicates from list of lists in Python | 1,143,379 | <p>Can anyone suggest a good solution to remove duplicates from nested lists if wanting to evaluate duplicates based on first element of each nested list?</p>
<p>The main list looks like this:</p>
<pre><code>L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46]]
</code></pre>
<p>If there is another... | 7 | 2009-07-17T13:45:48Z | 1,143,419 | <p>use a dict instead like so:</p>
<pre><code>L = {'14': ['65', 76], '2': ['5', 6], '7': ['12', 33]}
L['14'] = ['22', 46]
</code></pre>
<p>if you are receiving the first list from some external source, convert it like so:</p>
<pre><code>L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46]]
L_dict ... | 3 | 2009-07-17T13:52:29Z | [
"python",
"list"
] |
Removing duplicates from list of lists in Python | 1,143,379 | <p>Can anyone suggest a good solution to remove duplicates from nested lists if wanting to evaluate duplicates based on first element of each nested list?</p>
<p>The main list looks like this:</p>
<pre><code>L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46]]
</code></pre>
<p>If there is another... | 7 | 2009-07-17T13:45:48Z | 1,143,432 | <p>Do you care about preserving order / which duplicate is removed? If not, then:</p>
<pre><code>dict((x[0], x) for x in L).values()
</code></pre>
<p>will do it. If you want to preserve order, and want to keep the first one you find then:</p>
<pre><code>def unique_items(L):
found = set()
for item in L:
... | 24 | 2009-07-17T13:54:27Z | [
"python",
"list"
] |
Removing duplicates from list of lists in Python | 1,143,379 | <p>Can anyone suggest a good solution to remove duplicates from nested lists if wanting to evaluate duplicates based on first element of each nested list?</p>
<p>The main list looks like this:</p>
<pre><code>L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46]]
</code></pre>
<p>If there is another... | 7 | 2009-07-17T13:45:48Z | 1,143,486 | <p>If the order does not matter, code below</p>
<pre><code>print [ [k] + v for (k, v) in dict( [ [a[0], a[1:]] for a in reversed(L) ] ).items() ]
</code></pre>
<p>gives</p>
<blockquote>
<p>[['2', '5', '6'], ['14', '65', '76'], ['7', '12', '33']]</p>
</blockquote>
| 0 | 2009-07-17T14:03:11Z | [
"python",
"list"
] |
Removing duplicates from list of lists in Python | 1,143,379 | <p>Can anyone suggest a good solution to remove duplicates from nested lists if wanting to evaluate duplicates based on first element of each nested list?</p>
<p>The main list looks like this:</p>
<pre><code>L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46]]
</code></pre>
<p>If there is another... | 7 | 2009-07-17T13:45:48Z | 36,055,698 | <p>Use Pandas : </p>
<pre><code>import pandas as pd
L = [['14', '65', 76], ['2', '5', 6], ['7', '12', 33], ['14', '22', 46],['7','a','b']]
df = pd.DataFrame(L)
df = df.drop_duplicates()
L_no_duplicates = df.values.tolist()
</code></pre>
<p>If you want to drop duplicates in specific columns only use instead:</p>
<... | 0 | 2016-03-17T08:57:10Z | [
"python",
"list"
] |
Python sorting list of dictionaries by multiple keys | 1,143,671 | <p>I have a list of dicts:</p>
<pre><code>b = [{u'TOT_PTS_Misc': u'Utley, Alex', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Russo, Brandon', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Chappell, Justin', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Foster, Toney', u'Total_Points': 80.0},
{u'TOT_PTS_Misc': u'Lawson... | 55 | 2009-07-17T14:36:48Z | 1,143,719 | <pre><code>def sortkeypicker(keynames):
negate = set()
for i, k in enumerate(keynames):
if k[:1] == '-':
keynames[i] = k[1:]
negate.add(k[1:])
def getit(adict):
composite = [adict[k] for k in keynames]
for i, (k, v) in enumerate(zip(keynames, composite)):
... | 18 | 2009-07-17T14:44:47Z | [
"python"
] |
Python sorting list of dictionaries by multiple keys | 1,143,671 | <p>I have a list of dicts:</p>
<pre><code>b = [{u'TOT_PTS_Misc': u'Utley, Alex', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Russo, Brandon', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Chappell, Justin', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Foster, Toney', u'Total_Points': 80.0},
{u'TOT_PTS_Misc': u'Lawson... | 55 | 2009-07-17T14:36:48Z | 1,143,829 | <pre><code>from operator import itemgetter
from functools import partial
def _neg_itemgetter(key, d):
return -d[key]
def key_getter(key_expr):
keys = key_expr.split(",")
getters = []
for k in keys:
k = k.strip()
if k.startswith("-"):
getters.append(partial(_neg_itemgetter, k... | 0 | 2009-07-17T15:01:59Z | [
"python"
] |
Python sorting list of dictionaries by multiple keys | 1,143,671 | <p>I have a list of dicts:</p>
<pre><code>b = [{u'TOT_PTS_Misc': u'Utley, Alex', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Russo, Brandon', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Chappell, Justin', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Foster, Toney', u'Total_Points': 80.0},
{u'TOT_PTS_Misc': u'Lawson... | 55 | 2009-07-17T14:36:48Z | 1,144,405 | <p>This answer works for any kind of column in the dictionary -- the negated column need not be a number.</p>
<pre><code>def multikeysort(items, columns):
from operator import itemgetter
comparers = [((itemgetter(col[1:].strip()), -1) if col.startswith('-') else
(itemgetter(col.strip()), 1)) ... | 51 | 2009-07-17T16:35:39Z | [
"python"
] |
Python sorting list of dictionaries by multiple keys | 1,143,671 | <p>I have a list of dicts:</p>
<pre><code>b = [{u'TOT_PTS_Misc': u'Utley, Alex', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Russo, Brandon', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Chappell, Justin', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Foster, Toney', u'Total_Points': 80.0},
{u'TOT_PTS_Misc': u'Lawson... | 55 | 2009-07-17T14:36:48Z | 1,144,983 | <p>Since you're already comfortable with lambda, here's a less verbose solution.</p>
<pre><code>>>> def itemgetter(*names):
return lambda mapping: tuple(-mapping[name[1:]] if name.startswith('-') else mapping[name] for name in names)
>>> itemgetter('a', '-b')({'a': 1, 'b': 2})
(1, -2)
</code></p... | 0 | 2009-07-17T18:37:32Z | [
"python"
] |
Python sorting list of dictionaries by multiple keys | 1,143,671 | <p>I have a list of dicts:</p>
<pre><code>b = [{u'TOT_PTS_Misc': u'Utley, Alex', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Russo, Brandon', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Chappell, Justin', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Foster, Toney', u'Total_Points': 80.0},
{u'TOT_PTS_Misc': u'Lawson... | 55 | 2009-07-17T14:36:48Z | 3,301,620 | <p>I use the following for sorting a 2d array on a number of columns</p>
<pre><code>def k(a,b):
def _k(item):
return (item[a],item[b])
return _k
</code></pre>
<p>This could be extended to work on an arbitrary number of items. I tend to think finding a better access pattern to your sortable keys is bet... | 5 | 2010-07-21T16:34:33Z | [
"python"
] |
Python sorting list of dictionaries by multiple keys | 1,143,671 | <p>I have a list of dicts:</p>
<pre><code>b = [{u'TOT_PTS_Misc': u'Utley, Alex', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Russo, Brandon', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Chappell, Justin', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Foster, Toney', u'Total_Points': 80.0},
{u'TOT_PTS_Misc': u'Lawson... | 55 | 2009-07-17T14:36:48Z | 12,925,750 | <p><a href="http://stygianvision.net/updates/python-sort-list-object-dictionary-multiple-key/">http://stygianvision.net/updates/python-sort-list-object-dictionary-multiple-key/</a> has a nice rundown on various techniques for doing this. If your requirements are simpler than "full bidirectional multikey", take a look.... | 13 | 2012-10-17T01:15:02Z | [
"python"
] |
Python sorting list of dictionaries by multiple keys | 1,143,671 | <p>I have a list of dicts:</p>
<pre><code>b = [{u'TOT_PTS_Misc': u'Utley, Alex', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Russo, Brandon', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Chappell, Justin', u'Total_Points': 96.0},
{u'TOT_PTS_Misc': u'Foster, Toney', u'Total_Points': 80.0},
{u'TOT_PTS_Misc': u'Lawson... | 55 | 2009-07-17T14:36:48Z | 29,849,371 | <p>I know this is a rather old question, but none of the answers mention that Python guarantees a stable sort order for its sorting routines such as <code>list.sort()</code> and <code>sorted()</code>, which means items that compare equal retain their original order.</p>
<p>This means that the equivalent of <code>ORDER... | 8 | 2015-04-24T13:54:15Z | [
"python"
] |
How to add a button (Add-in) to Outlook using Python | 1,143,798 | <p>I'm looking the way to build an AddIn for Outlook with Python that add a button to the toolbar that has a behavior (doesn't matter).
I've searched around and didn't found anything. The only things I've found are backend, no GUI.</p>
<p>thanks!</p>
| 0 | 2009-07-17T14:56:53Z | 1,144,428 | <p>You could study the source for the SpamBayes outlook addin:</p>
<ul>
<li><a href="http://spambayes.svn.sourceforge.net/viewvc/spambayes/trunk/spambayes/Outlook2000/addin.py?revision=3243&view=markup" rel="nofollow">http://spambayes.svn.sourceforge.net/viewvc/spambayes/trunk/spambayes/Outlook2000/addin.py?revisi... | 1 | 2009-07-17T16:39:46Z | [
"python",
"winapi",
"outlook"
] |
How do you add a model method to an existing class within an interactive session (in iPython)? | 1,143,833 | <p>I have a basic model:</p>
<pre><code>class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
state = USStateField()
</code></pre>
<p>I start up an iPython session with:</p>
<pre><code>$ python manage.py shell
>>> from app.models imp... | 0 | 2009-07-17T15:02:23Z | 1,143,896 | <p>why can't you just do this
Person.is_midwestern = is_miswestern e.g.</p>
<pre><code>>>> class Person:
... def __init__(self): self.mid = True
...
>>> def is_midwestern(self): return self.mid
...
>>> Person.is_midwestern = is_midwestern
>>> p = Person()
>>> p.is_mid... | 3 | 2009-07-17T15:12:01Z | [
"python",
"django",
"ipython"
] |
How do I convert (or scale) axis values and redefine the tick frequency in matplotlib? | 1,143,848 | <p>I am displaying a jpg image (I rotate this by 90 degrees, if this is relevant) and of course
the axes display the pixel coordinates. I would like to convert the axis so that instead of displaying the pixel number, it will display my unit of choice - be it radians, degrees, or in my case an astronomical coordinate. I... | 20 | 2009-07-17T15:05:17Z | 1,144,137 | <p>It looks like you're dealing with the <code>matplotlib.pyplot</code> interface, which means that you'll be able to bypass most of the dealing with artists, axes, and the like. You can control the values and labels of the tick marks by using the <a href="http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotl... | 30 | 2009-07-17T15:49:08Z | [
"python",
"matplotlib"
] |
Looking for values in nested tuple | 1,144,178 | <p>Say I have:</p>
<pre><code>t = (
('dog', 'Dog'),
('cat', 'Cat'),
('fish', 'Fish'),
)
</code></pre>
<p>And I need to check if a value is in the first bit of the nested tuple (ie. the lowercase bits). How can I do this? The capitalised values do not matter really, I want to search for a string in only th... | 0 | 2009-07-17T15:57:17Z | 1,144,206 | <p>The elements of a tuple can be extracted by specifying an index: <code>('a', 'b')[0] == 'a'</code>. You can use a <a href="http://docs.python.org/3.0/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a> to iterate over all elements of some <em>iterable</em>. A tuple is also iterabl... | 5 | 2009-07-17T16:00:08Z | [
"python"
] |
Looking for values in nested tuple | 1,144,178 | <p>Say I have:</p>
<pre><code>t = (
('dog', 'Dog'),
('cat', 'Cat'),
('fish', 'Fish'),
)
</code></pre>
<p>And I need to check if a value is in the first bit of the nested tuple (ie. the lowercase bits). How can I do this? The capitalised values do not matter really, I want to search for a string in only th... | 0 | 2009-07-17T15:57:17Z | 1,144,208 | <p>Try:</p>
<pre><code>any('fish' == tup[0] for tup in t)
</code></pre>
<p>EDIT: Stephan is right; fixed 'fish' == tup[0]. Also see his more complete answer.</p>
| 4 | 2009-07-17T16:00:51Z | [
"python"
] |
Looking for values in nested tuple | 1,144,178 | <p>Say I have:</p>
<pre><code>t = (
('dog', 'Dog'),
('cat', 'Cat'),
('fish', 'Fish'),
)
</code></pre>
<p>And I need to check if a value is in the first bit of the nested tuple (ie. the lowercase bits). How can I do this? The capitalised values do not matter really, I want to search for a string in only th... | 0 | 2009-07-17T15:57:17Z | 1,144,221 | <p>You could do something like this:</p>
<pre><code>if 'fish' in (item[0] for item in t):
print "Fish in t."
</code></pre>
<p>or this:</p>
<pre><code>if any(item[0] == 'fish' for item in t):
print "Fish in t."
</code></pre>
<p>If you don't care about the order but want to keep the association between <code>... | 2 | 2009-07-17T16:03:22Z | [
"python"
] |
Looking for values in nested tuple | 1,144,178 | <p>Say I have:</p>
<pre><code>t = (
('dog', 'Dog'),
('cat', 'Cat'),
('fish', 'Fish'),
)
</code></pre>
<p>And I need to check if a value is in the first bit of the nested tuple (ie. the lowercase bits). How can I do this? The capitalised values do not matter really, I want to search for a string in only th... | 0 | 2009-07-17T15:57:17Z | 1,145,330 | <p>When you have an iterable of key-value pairs such as:</p>
<pre><code>t = (
('dog', 'Dog'),
('cat', 'Cat'),
('fish', 'Fish'),
)
</code></pre>
<p>You can "cast" it to a dictionary using the <a href="http://docs.python.org/tutorial/datastructures.html#dictionaries" rel="nofollow">dict()</a> constructor, t... | 1 | 2009-07-17T19:51:21Z | [
"python"
] |
Hacking JavaScript Array Into JSON With Python | 1,144,400 | <p>I am fetching a .js file from a remote site that contains data I want to process as JSON using the simplejson library on my Google App Engine site. The .js file looks like this:</p>
<pre><code>var txns = [
{ apples: '100', oranges: '20', type: 'SELL'},
{ apples: '200', oranges: '10', type: 'BUY'}]
</code>... | 4 | 2009-07-17T16:34:59Z | 1,144,451 | <p><a href="http://www.devpro.it/JSON/files/JSON-js.html" rel="nofollow">http://www.devpro.it/JSON/files/JSON-js.html</a></p>
| -1 | 2009-07-17T16:44:10Z | [
"javascript",
"python",
"json"
] |
Hacking JavaScript Array Into JSON With Python | 1,144,400 | <p>I am fetching a .js file from a remote site that contains data I want to process as JSON using the simplejson library on my Google App Engine site. The .js file looks like this:</p>
<pre><code>var txns = [
{ apples: '100', oranges: '20', type: 'SELL'},
{ apples: '200', oranges: '10', type: 'BUY'}]
</code>... | 4 | 2009-07-17T16:34:59Z | 1,144,458 | <p>If you <strong>know</strong> that's what it's always going to look like, you could do a regex to find unquoted space-delimited text that ends with a colon and surround it with quotes.</p>
<p>I'm always worried about unexpected input with a regex like that, though. How do you know the remote source won't change what... | 0 | 2009-07-17T16:44:54Z | [
"javascript",
"python",
"json"
] |
Hacking JavaScript Array Into JSON With Python | 1,144,400 | <p>I am fetching a .js file from a remote site that contains data I want to process as JSON using the simplejson library on my Google App Engine site. The .js file looks like this:</p>
<pre><code>var txns = [
{ apples: '100', oranges: '20', type: 'SELL'},
{ apples: '200', oranges: '10', type: 'BUY'}]
</code>... | 4 | 2009-07-17T16:34:59Z | 1,144,532 | <p>I would use the yaml parser as its better at most things like this. It comes with GAE as well as it is used for the config files. Json is a subset of yaml.</p>
<p>All you have to do is get rid of "var txns =" then yaml should do the rest. </p>
<pre><code>import yaml
string = """[{ apples: '100', oranges: '20', t... | 4 | 2009-07-17T17:03:13Z | [
"javascript",
"python",
"json"
] |
Hacking JavaScript Array Into JSON With Python | 1,144,400 | <p>I am fetching a .js file from a remote site that contains data I want to process as JSON using the simplejson library on my Google App Engine site. The .js file looks like this:</p>
<pre><code>var txns = [
{ apples: '100', oranges: '20', type: 'SELL'},
{ apples: '200', oranges: '10', type: 'BUY'}]
</code>... | 4 | 2009-07-17T16:34:59Z | 1,144,597 | <p>It's not too difficult to write your own little parsor for that using <a href="http://pyparsing.wikispaces.com/">PyParsing</a>.</p>
<pre><code>import json
from pyparsing import *
data = """var txns = [
{ apples: '100', oranges: '20', type: 'SELL'},
{ apples: '200', oranges: '10', type: 'BUY'}]"""
def js_g... | 5 | 2009-07-17T17:12:33Z | [
"javascript",
"python",
"json"
] |
Hacking JavaScript Array Into JSON With Python | 1,144,400 | <p>I am fetching a .js file from a remote site that contains data I want to process as JSON using the simplejson library on my Google App Engine site. The .js file looks like this:</p>
<pre><code>var txns = [
{ apples: '100', oranges: '20', type: 'SELL'},
{ apples: '200', oranges: '10', type: 'BUY'}]
</code>... | 4 | 2009-07-17T16:34:59Z | 1,144,621 | <p>You could create an intermediate page containing a Javascript script that just loads the remote one and dumps it to JSON. Then Python can make requests to your intermediate page and get out nice JSON.</p>
| 0 | 2009-07-17T17:18:43Z | [
"javascript",
"python",
"json"
] |
Using Eval in Python to create class variables | 1,144,702 | <p>I wrote a class that lets me pass in a list of variable types, variable names, prompts, and default values. The class creates a wxPython panel, which is displayed in a frame that lets the user set the input values before pressing the calculate button and getting the results back as a plot. I add all of the variabl... | 1 | 2009-07-17T17:36:01Z | 1,144,726 | <p>You can use the <code>setattr</code> function, which takes three arguments: the object, the name of the attribute, and it's value. For example,</p>
<pre><code>setattr(self, 'wavelength', wavelength_val)
</code></pre>
<p>is equivalent to:</p>
<pre><code>self.wavelength = wavelength_val
</code></pre>
<p>So you cou... | 18 | 2009-07-17T17:40:40Z | [
"python",
"wxpython",
"scientific-computing"
] |
Using Eval in Python to create class variables | 1,144,702 | <p>I wrote a class that lets me pass in a list of variable types, variable names, prompts, and default values. The class creates a wxPython panel, which is displayed in a frame that lets the user set the input values before pressing the calculate button and getting the results back as a plot. I add all of the variabl... | 1 | 2009-07-17T17:36:01Z | 1,155,728 | <p>I agree with mipadi's answer, but wanted to add one more answer, since the Original Post asked if there's a problem using exec. I'd like to address that.</p>
<p>Think like a criminal.</p>
<p>If your malicious adversary knew you had code that read:</p>
<pre>
exec( 'self.' + var_name + ' = ' + var_text_ctrl.GetVal... | 1 | 2009-07-20T20:17:39Z | [
"python",
"wxpython",
"scientific-computing"
] |
Using Eval in Python to create class variables | 1,144,702 | <p>I wrote a class that lets me pass in a list of variable types, variable names, prompts, and default values. The class creates a wxPython panel, which is displayed in a frame that lets the user set the input values before pressing the calculate button and getting the results back as a plot. I add all of the variabl... | 1 | 2009-07-17T17:36:01Z | 1,191,425 | <p>For the security conscious, there might be an acceptable alternative. There used to be a module call rexec that allowed "restricted" execution of arbitrary python code. This module was removed from recent python versions. <a href="http://pypi.python.org/pypi/RestrictedPython" rel="nofollow">http://pypi.python.org/py... | 0 | 2009-07-28T01:01:47Z | [
"python",
"wxpython",
"scientific-computing"
] |
Using Eval in Python to create class variables | 1,144,702 | <p>I wrote a class that lets me pass in a list of variable types, variable names, prompts, and default values. The class creates a wxPython panel, which is displayed in a frame that lets the user set the input values before pressing the calculate button and getting the results back as a plot. I add all of the variabl... | 1 | 2009-07-17T17:36:01Z | 1,196,513 | <p>The module was removed because it had security issues. Very difficult to provide an environment where any code can be executed in a restricted environment, with all the introspection that Python has.</p>
<p>A better bet is to avoid eval and exec.</p>
<p>A really off-the-wall idea is to use Google App Engine, and ... | 0 | 2009-07-28T20:21:24Z | [
"python",
"wxpython",
"scientific-computing"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.