title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Simple DB query on Google App Engine taking a lot of CPU time | 1,892,325 | <p>I'm fairly new to Google App Engine and Python, but I did just release my first real-world site with it. But now I'm getting problems with one path that is using significantly more CPU (and API CPU) time than the other paths. I've narrowed it down to a single datastore fetch that's causing the problem: <code>Carving... | 0 | 2009-12-12T04:46:27Z | 1,892,423 | <ul>
<li><p>Memcache, if you haven't already, and especially if the same carvings are going to be fetched again and again. If you only have 90 total, I would imagine they would all be in the cache pretty quickly, and then you should be golden.</p></li>
<li><p>Do you need all the properties of the Carvings? For exampl... | 2 | 2009-12-12T05:29:20Z | [
"python",
"google-app-engine",
"cpu-usage",
"gae-datastore"
] |
Simple DB query on Google App Engine taking a lot of CPU time | 1,892,325 | <p>I'm fairly new to Google App Engine and Python, but I did just release my first real-world site with it. But now I'm getting problems with one path that is using significantly more CPU (and API CPU) time than the other paths. I've narrowed it down to a single datastore fetch that's causing the problem: <code>Carving... | 0 | 2009-12-12T04:46:27Z | 1,893,687 | <p>Do you actually need 1000 entities? CPU time goes up more or less linearly with the number of results retrieved, so if you don't actually need all the results, you may be wasting a lot of time fetching and decoding them.</p>
| 0 | 2009-12-12T15:02:21Z | [
"python",
"google-app-engine",
"cpu-usage",
"gae-datastore"
] |
Simple DB query on Google App Engine taking a lot of CPU time | 1,892,325 | <p>I'm fairly new to Google App Engine and Python, but I did just release my first real-world site with it. But now I'm getting problems with one path that is using significantly more CPU (and API CPU) time than the other paths. I've narrowed it down to a single datastore fetch that's causing the problem: <code>Carving... | 0 | 2009-12-12T04:46:27Z | 1,899,059 | <p>It could be the image (and/or Text property) that is taking time to load & marshall into objects, depending on how big those properties are.</p>
<p>First prize: just use the memcache as others say. Then the overhead is incurred only on the first hit.</p>
<p>Second prize: I'm not sure how often your images are ... | 0 | 2009-12-14T05:21:11Z | [
"python",
"google-app-engine",
"cpu-usage",
"gae-datastore"
] |
How to make a window jump to the front? | 1,892,339 | <p>How do I get a Tkinter application to jump to the front. Currently the window appears behind all my other windows and doesn't get focus. </p>
<p>Is there some method I should be calling?</p>
| 21 | 2009-12-12T04:52:34Z | 6,795,115 | <p>Assuming you mean your application windows when you say "my other windows", you can use the <code>lift()</code> method on a Toplevel or Tk:</p>
<pre><code>root.lift()
</code></pre>
<p>If you want the window to stay above all other windows, use: </p>
<pre><code>root.attributes("-topmost", True)
</code></pre>
<p>... | 32 | 2011-07-22T19:32:46Z | [
"python",
"tkinter"
] |
How to make a window jump to the front? | 1,892,339 | <p>How do I get a Tkinter application to jump to the front. Currently the window appears behind all my other windows and doesn't get focus. </p>
<p>Is there some method I should be calling?</p>
| 21 | 2009-12-12T04:52:34Z | 8,775,078 | <p>If you're doing this on a Mac, use AppleEvents to give focus to Python. Eg:</p>
<pre><code>import os
os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "Python" to true' ''')
</code></pre>
| 20 | 2012-01-08T03:07:47Z | [
"python",
"tkinter"
] |
How to make a window jump to the front? | 1,892,339 | <p>How do I get a Tkinter application to jump to the front. Currently the window appears behind all my other windows and doesn't get focus. </p>
<p>Is there some method I should be calling?</p>
| 21 | 2009-12-12T04:52:34Z | 23,571,300 | <p>Regarding the Mac, I noticed there can be a problem in that if there are multiple python GUIs running, every process will be named "Python" and AppleScript will tend to promote the wrong one to the front. Here's my solution. The idea is to grab a list of running process IDs before and after you load Tkinter. (Note t... | 4 | 2014-05-09T18:06:42Z | [
"python",
"tkinter"
] |
How to make a window jump to the front? | 1,892,339 | <p>How do I get a Tkinter application to jump to the front. Currently the window appears behind all my other windows and doesn't get focus. </p>
<p>Is there some method I should be calling?</p>
| 21 | 2009-12-12T04:52:34Z | 28,874,281 | <p>On Mac OS X PyObjC provides a cleaner and less error prone method than shelling out to osascript:</p>
<pre><code>import os
from Cocoa import NSRunningApplication, NSApplicationActivateIgnoringOtherApps
app = NSRunningApplication.runningApplicationWithProcessIdentifier_(os.getpid())
app.activateWithOptions_(NSAppli... | 2 | 2015-03-05T09:29:23Z | [
"python",
"tkinter"
] |
How to make a window jump to the front? | 1,892,339 | <p>How do I get a Tkinter application to jump to the front. Currently the window appears behind all my other windows and doesn't get focus. </p>
<p>Is there some method I should be calling?</p>
| 21 | 2009-12-12T04:52:34Z | 32,121,848 | <p>Recently, I had the same question on the Mac. I have combined several answers using <code>@MagerValp</code> for the Mac and <code>@D K</code> for other systems:</p>
<pre><code>import platform
if platform.system() != 'Darwin':
root.lift()
root.call('wm', 'attributes', '.', '-topmost', True)
root.after_i... | 3 | 2015-08-20T15:05:03Z | [
"python",
"tkinter"
] |
How to make a window jump to the front? | 1,892,339 | <p>How do I get a Tkinter application to jump to the front. Currently the window appears behind all my other windows and doesn't get focus. </p>
<p>Is there some method I should be calling?</p>
| 21 | 2009-12-12T04:52:34Z | 36,191,443 | <p>Add the following lines before the mainloop():</p>
<pre><code>root.lift()
root.attributes('-topmost',True)
root.after_idle(root.attributes,'-topmost',False)
</code></pre>
<p>It works perfectly for me. It makes the window come to the front when the window is generated, and it won't keep it always be in the front.</... | 4 | 2016-03-24T00:56:13Z | [
"python",
"tkinter"
] |
How to make a window jump to the front? | 1,892,339 | <p>How do I get a Tkinter application to jump to the front. Currently the window appears behind all my other windows and doesn't get focus. </p>
<p>Is there some method I should be calling?</p>
| 21 | 2009-12-12T04:52:34Z | 37,235,492 | <p>Somewhat of a combination of various other methods, this works on OS X 10.11, and Python 3.5.1 running in a venv, and should work on other platforms too. It also targets the app by process id rather than app name.</p>
<pre><code>from tkinter import Tk
import os
import subprocess
import platform
def raise_app(root... | 0 | 2016-05-15T07:08:59Z | [
"python",
"tkinter"
] |
Pausing a process in Windows | 1,892,356 | <p>I'm making a nice little Python GUI frontend for ffmpeg on Windows (one that is specifically designed to convert videos to an iPhone-friendly format and automatically import it to iTunes and tag it), and I want it to work so that you can pause the process and resume it if you want.</p>
<p>Since I start ffmpeg as a ... | 2 | 2009-12-12T04:59:49Z | 4,229,561 | <p>You can easily do this by using psutil ( <a href="https://github.com/giampaolo/psutil" rel="nofollow">https://github.com/giampaolo/psutil</a> ):</p>
<pre><code>import psutil
pid = 1034 # replace this with the pid of your process
p = psutil.Process(pid)
p.suspend()
</code></pre>
<p>...to resume it:</p>
<pre><code... | 5 | 2010-11-19T21:32:55Z | [
"python",
"windows"
] |
Web.py on shared hosting | 1,892,805 | <p>I just built a small app with the very cool and minimalistic <code>web.py</code>. </p>
<p>I am using a cheap shared hosting package (at WebFaction) and have installed web.py via virtualenv. I cannot use the system python since I need additional packages which I'm not allowed to install into the system python.</p>
... | 0 | 2009-12-12T08:48:28Z | 1,892,836 | <p>Is there a reason you're not using fastcgi? That's probably considerably better than trying to use some high-numbered port, particularly since your webhost may not be very happy about that at all. There are a few notes on doing that (on dreamhost, but it should be similar for you) in this post:</p>
<p><a href="http... | 2 | 2009-12-12T09:12:27Z | [
"python",
"performance",
"web.py"
] |
sending http request to apache through a python script | 1,892,958 | <p>All,</p>
<p>How do we send a http request through a python script.which will login and in turn call another link?</p>
<p>Thanks.</p>
| 1 | 2009-12-12T10:10:24Z | 1,892,965 | <p>Have you looked at <a href="http://docs.python.org/library/httplib.html" rel="nofollow">httplib</a>? <a href="http://docs.python.org/library/urllib.html" rel="nofollow">urllib</a> may also be worth looking at as it is a slightly higher level interface.</p>
| 0 | 2009-12-12T10:14:01Z | [
"python",
"httprequest"
] |
sending http request to apache through a python script | 1,892,958 | <p>All,</p>
<p>How do we send a http request through a python script.which will login and in turn call another link?</p>
<p>Thanks.</p>
| 1 | 2009-12-12T10:10:24Z | 1,893,007 | <p>I find that <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">Urllib2</a> suffices in most cases. It has great support for passwords, authentication and cookies. Cookielib might help too.</p>
| 1 | 2009-12-12T10:35:40Z | [
"python",
"httprequest"
] |
Why import urlfetch from Google App Engines? | 1,893,012 | <p><a href="http://code.google.com/appengine/docs/python/urlfetch/overview.html">Here in Google App Engines</a> I got this code that would help fetch an HTML code of any web page by its URL:</p>
<pre><code>from google.appengine.api import urlfetch
url = "http://www.google.com/"
result = urlfetch.fetch(url)
if result.s... | 6 | 2009-12-12T10:38:04Z | 1,893,028 | <p>google.appengine.api is a library that contains Google's version of urlfetch class. Quoting <a href="http://code.google.com/intl/et-EE/appengine/docs/python/urlfetch/overview.html">from the manual</a>: </p>
<blockquote>
<p>The URL Fetch service uses Google's
network infrastructure for efficiency
and scaling p... | 6 | 2009-12-12T10:42:46Z | [
"python",
"google-app-engine",
"import",
"urlfetch"
] |
Why import urlfetch from Google App Engines? | 1,893,012 | <p><a href="http://code.google.com/appengine/docs/python/urlfetch/overview.html">Here in Google App Engines</a> I got this code that would help fetch an HTML code of any web page by its URL:</p>
<pre><code>from google.appengine.api import urlfetch
url = "http://www.google.com/"
result = urlfetch.fetch(url)
if result.s... | 6 | 2009-12-12T10:38:04Z | 1,893,680 | <p>Python has libraries such as urllib and httplib for fetching URLs, but on App Engine, all requests must go through the custom urlfetch library. App Engine includes stubs for urllib and httplib that cause them to use urlfetch internally, but if you have a choice, using urlfetch directly is more efficient and flexible... | 15 | 2009-12-12T14:59:32Z | [
"python",
"google-app-engine",
"import",
"urlfetch"
] |
Basic Python Numbers! | 1,893,094 | <p>Why does <code>0.1 + 0.1 + 0.1 - 0.3</code> evaluates to
<code>5.5511151231257827e-17</code> in Python?</p>
| 1 | 2009-12-12T11:20:41Z | 1,893,104 | <p>Because that's how floating point numbers work. If you want precise numbers, use the <a href="http://docs.python.org/library/decimal.html" rel="nofollow"><code>decimal</code></a> module. If you want to use floating point numbers, you have to remember to round them to a specific precision when you are displaying them... | 15 | 2009-12-12T11:23:21Z | [
"python",
"floating-point",
"core"
] |
Basic Python Numbers! | 1,893,094 | <p>Why does <code>0.1 + 0.1 + 0.1 - 0.3</code> evaluates to
<code>5.5511151231257827e-17</code> in Python?</p>
| 1 | 2009-12-12T11:20:41Z | 1,893,110 | <p>Because of the way floating points numbers are represented in a computer. It's not just a Python thing.</p>
| 2 | 2009-12-12T11:24:10Z | [
"python",
"floating-point",
"core"
] |
Basic Python Numbers! | 1,893,094 | <p>Why does <code>0.1 + 0.1 + 0.1 - 0.3</code> evaluates to
<code>5.5511151231257827e-17</code> in Python?</p>
| 1 | 2009-12-12T11:20:41Z | 1,893,113 | <p>This is a problem with floating point numbers in general. See <a href="http://en.wikipedia.org/wiki/Floating%5Fpoint#Accuracy%5Fproblems" rel="nofollow">this section</a> on Wikipedia for a description. Roughly speaking - there are rounding errors. Notice that the number you gave us was very small - about 0.000000000... | 7 | 2009-12-12T11:25:54Z | [
"python",
"floating-point",
"core"
] |
Basic Python Numbers! | 1,893,094 | <p>Why does <code>0.1 + 0.1 + 0.1 - 0.3</code> evaluates to
<code>5.5511151231257827e-17</code> in Python?</p>
| 1 | 2009-12-12T11:20:41Z | 1,893,205 | <p>The answer is here: <a href="http://docs.sun.com/source/806-3568/ncg%5Fgoldberg.html" rel="nofollow">What Every Computer Scientist Should Know About Floating-Point Arithmetic</a></p>
| 4 | 2009-12-12T12:03:37Z | [
"python",
"floating-point",
"core"
] |
Basic Python Numbers! | 1,893,094 | <p>Why does <code>0.1 + 0.1 + 0.1 - 0.3</code> evaluates to
<code>5.5511151231257827e-17</code> in Python?</p>
| 1 | 2009-12-12T11:20:41Z | 1,893,293 | <p>As an example, consider representing 1/3 as a scientific number in base 10. With only a finite number of digits (say, 10), you'll wind up with a rounding error. Say 1/3 â 0.3333333333e0. Then 1/3+1/3+1/3 (after first converting to decimal expansions) is represented as 0.9999999999e0, but 1 is 1.0e0. Similarly, 1/7... | 0 | 2009-12-12T12:39:34Z | [
"python",
"floating-point",
"core"
] |
Basic Python Numbers! | 1,893,094 | <p>Why does <code>0.1 + 0.1 + 0.1 - 0.3</code> evaluates to
<code>5.5511151231257827e-17</code> in Python?</p>
| 1 | 2009-12-12T11:20:41Z | 1,893,442 | <p>You might be interested in knowing that Python 3 has improved the situation by changing how <code>repr</code> works. It will now give you the shortest string representation that will be converted back to the original float:</p>
<pre>
Python 3.1.1+ (r311:74480, Oct 11 2009, 20:19:13)
[GCC 4.3.4] on linux2
Type "hel... | 3 | 2009-12-12T13:36:17Z | [
"python",
"floating-point",
"core"
] |
Cross-Platform Python Notification Library | 1,893,213 | <p>I'm making a python script that should run in the background and notify a user of changes, and I'd quite like it to work cross-platform. Main problem is, I don't have access to a mac at all, so coding specifically for it could be very difficult. wxPython seems like massive overkill for simple popups, so is there any... | 8 | 2009-12-12T12:06:04Z | 1,893,368 | <p><a href="http://labs.adobe.com/technologies/wave/" rel="nofollow">Adobe Wave</a> is a cross-platform notification framework however I have not used it and I do not believe it is a desktop-oriented deal, but rather something for rich Internet Apps and plugging into web sites. Still, it's some sort of cross-platform n... | 1 | 2009-12-12T13:07:30Z | [
"python",
"cross-platform",
"notifications"
] |
Cross-Platform Python Notification Library | 1,893,213 | <p>I'm making a python script that should run in the background and notify a user of changes, and I'd quite like it to work cross-platform. Main problem is, I don't have access to a mac at all, so coding specifically for it could be very difficult. wxPython seems like massive overkill for simple popups, so is there any... | 8 | 2009-12-12T12:06:04Z | 1,893,404 | <p>Does Python on Windows and Mac also ship with Tk wrappers? If so, you might be able to roll your own notification box. I do not think they have a dead-simple notification API (i.e. you pass it a string and a cute box pops up for 5 seconds) however at least you will only have one codebase to maintain.</p>
<p>I am th... | 4 | 2009-12-12T13:23:01Z | [
"python",
"cross-platform",
"notifications"
] |
Cross-Platform Python Notification Library | 1,893,213 | <p>I'm making a python script that should run in the background and notify a user of changes, and I'd quite like it to work cross-platform. Main problem is, I don't have access to a mac at all, so coding specifically for it could be very difficult. wxPython seems like massive overkill for simple popups, so is there any... | 8 | 2009-12-12T12:06:04Z | 11,771,222 | <p>Seems like one way to go would be something like Growl/GNTP. Have you looked at <a href="https://github.com/kfdm/gntp/" rel="nofollow">python's gntp library</a>?</p>
| 0 | 2012-08-02T04:49:42Z | [
"python",
"cross-platform",
"notifications"
] |
return variable outputs in Python function? | 1,893,304 | <p>I have a function that returns a list. When I know the number of elements in the list I can do something like:</p>
<pre><code>x,y,z=foo()
</code></pre>
<p>however, the number of elements in the list can vary. I would like to do something like</p>
<pre><code>x,y*=foo()
</code></pre>
<p>where x would contain the f... | 1 | 2009-12-12T12:42:54Z | 1,893,312 | <p>Like this</p>
<pre><code>results = foo()
x= results[0]
y= results[1:]
</code></pre>
<p>Or change your function to return a two-tuple</p>
<pre><code>def foo():
....
return someList[0], someList[1:]
</code></pre>
| 3 | 2009-12-12T12:45:47Z | [
"python"
] |
return variable outputs in Python function? | 1,893,304 | <p>I have a function that returns a list. When I know the number of elements in the list I can do something like:</p>
<pre><code>x,y,z=foo()
</code></pre>
<p>however, the number of elements in the list can vary. I would like to do something like</p>
<pre><code>x,y*=foo()
</code></pre>
<p>where x would contain the f... | 1 | 2009-12-12T12:42:54Z | 1,893,319 | <p>There is no philosophical objection to your syntax, in fact, it's supported in Python 3.1:</p>
<pre><code>>>> a, *b = range(10)
>>> a
0
>>> b
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> # Or even more flexibly:
>>> a, *b, c = range(10)
>>> a
0
>>> b
[1, 2, 3, 4, 5,... | 13 | 2009-12-12T12:49:30Z | [
"python"
] |
return variable outputs in Python function? | 1,893,304 | <p>I have a function that returns a list. When I know the number of elements in the list I can do something like:</p>
<pre><code>x,y,z=foo()
</code></pre>
<p>however, the number of elements in the list can vary. I would like to do something like</p>
<pre><code>x,y*=foo()
</code></pre>
<p>where x would contain the f... | 1 | 2009-12-12T12:42:54Z | 1,893,741 | <p>A slightly generalized approach:</p>
<pre><code>>>> def unpack(seq, count):
... return seq[:count] + [seq[count:]]
>>> a, b = unpack([1, 2, 3], 1)
>>> a
1
>>> b
[2, 3]
>>> a, b = unpack([1, 2], 1)
>>> a
1
>>> b
[2]
>>> a, b = unpack([1], 1)
&... | 3 | 2009-12-12T15:20:53Z | [
"python"
] |
PYTHONPATH vs. sys.path | 1,893,598 | <p>Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory.</p>
<p>We have a Python project with a typical directory structure:</p>
<pre><code>Project
setup.py
package
__init__.py
lib.... | 40 | 2009-12-12T14:33:36Z | 1,893,622 | <p>If the only reason to modify the path is for developers working from their working tree, then you should use an installation tool to set up your environment for you. virtualenv is very popular, and if you are using setuptools, you can simply run <code>setup.py develop</code> to semi-install the working tree in your... | 24 | 2009-12-12T14:39:06Z | [
"python",
"pythonpath",
"sys.path"
] |
PYTHONPATH vs. sys.path | 1,893,598 | <p>Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory.</p>
<p>We have a Python project with a typical directory structure:</p>
<pre><code>Project
setup.py
package
__init__.py
lib.... | 40 | 2009-12-12T14:33:36Z | 1,893,631 | <p>I think, that in this case using PYTHONPATH is a better thing, mostly because it doesn't introduce (questionable) unneccessary code. </p>
<p>After all, if you think of it, your <em>user</em> doesn't need that <code>sys.path</code> thing, because your package will get installed into site-packages, because you will b... | 2 | 2009-12-12T14:40:48Z | [
"python",
"pythonpath",
"sys.path"
] |
PYTHONPATH vs. sys.path | 1,893,598 | <p>Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory.</p>
<p>We have a Python project with a typical directory structure:</p>
<pre><code>Project
setup.py
package
__init__.py
lib.... | 40 | 2009-12-12T14:33:36Z | 1,893,663 | <p>I hate PYTHONPATH. I find it brittle and annoying to set on a per-user basis (especially for daemon users) and keep track of as project folders move around. I would much rather set <code>sys.path</code> in the invoke scripts for standalone projects.</p>
<p>However <code>sys.path.append</code> isn't the way to do it... | 27 | 2009-12-12T14:54:30Z | [
"python",
"pythonpath",
"sys.path"
] |
PYTHONPATH vs. sys.path | 1,893,598 | <p>Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory.</p>
<p>We have a Python project with a typical directory structure:</p>
<pre><code>Project
setup.py
package
__init__.py
lib.... | 40 | 2009-12-12T14:33:36Z | 1,893,805 | <p>Along with the many other reasons mentioned already, you could also point outh that hard-coding </p>
<p><code>sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))</code></p>
<p>is brittle because it presumes the location of script.py -- it will only work if script.py is located in Project/... | 2 | 2009-12-12T15:44:19Z | [
"python",
"pythonpath",
"sys.path"
] |
PYTHONPATH vs. sys.path | 1,893,598 | <p>Another developer and I disagree about whether PYTHONPATH or sys.path should be used to allow Python to find a Python package in a user (e.g., development) directory.</p>
<p>We have a Python project with a typical directory structure:</p>
<pre><code>Project
setup.py
package
__init__.py
lib.... | 40 | 2009-12-12T14:33:36Z | 1,894,043 | <p>In general I would consider setting up of an environment variable (like PYTHONPATH)
to be a bad practice. While this might be fine for a one off debugging but using this as<br>
a regular practice might not be a good idea. </p>
<p>Usage of environment variable leads to situations like "it works for me" when some ... | 6 | 2009-12-12T17:06:49Z | [
"python",
"pythonpath",
"sys.path"
] |
Color a Button after subprocess has finished | 1,893,629 | <p>I have a Tk python program that creates a list of python files in the current directory and generates a button for each of them. When you click a button the corresponding python program is launched via subprocess in a new gnome-terminal. I'd like to switch the button's color to red after the subprocess has finished ... | 0 | 2009-12-12T14:40:34Z | 1,894,048 | <p>There are two questions here: what command line to use to launch a Python program in gnome-terminal, and how to use <code>subprocess</code> in a Tkinter app. I only know about the latter.</p>
<p><code>subprocess.Popen</code> returns immediately, which is why the button is turning red immediately. I think you probab... | 1 | 2009-12-12T17:08:24Z | [
"python",
"subprocess",
"gnome",
"tk"
] |
Color a Button after subprocess has finished | 1,893,629 | <p>I have a Tk python program that creates a list of python files in the current directory and generates a button for each of them. When you click a button the corresponding python program is launched via subprocess in a new gnome-terminal. I'd like to switch the button's color to red after the subprocess has finished ... | 0 | 2009-12-12T14:40:34Z | 1,894,085 | <p>I believe gnome terminal is doing a double fork, in order to detach itself from the process group of its parent -- so what's actually your subprocess terminates almost immediately, as you observe, and everything is happening in a further descendant that you have no direct access to.</p>
<p>Unfortunately I don't bel... | 1 | 2009-12-12T17:20:51Z | [
"python",
"subprocess",
"gnome",
"tk"
] |
Shaders with pygtkglext | 1,893,641 | <p>Do someone know how to get glsl shaders work in gtk-opengl window? With glut all <code>glCreateProgram</code> etc. functions works, but when I tried to put the same gl code into pygtkglext window, its complaining about NullReference:</p>
<pre><code>OpenGL.error.NullFunctionError: Attempt to call an undefined functi... | 1 | 2009-12-12T14:45:05Z | 2,366,107 | <p>OpenGL entry points are obtained using GetProcAddress routine. I suppose the NULL pointer is the function pointer glCreateProgramObjectARB.</p>
<p>This is strictly related with libraries installed with the driver. Which OpenGL version is running on the host? Maybe the driver doesn't implements the glCreateProgramOb... | 0 | 2010-03-02T19:34:37Z | [
"python",
"pygtk",
"glsl",
"shader"
] |
Shaders with pygtkglext | 1,893,641 | <p>Do someone know how to get glsl shaders work in gtk-opengl window? With glut all <code>glCreateProgram</code> etc. functions works, but when I tried to put the same gl code into pygtkglext window, its complaining about NullReference:</p>
<pre><code>OpenGL.error.NullFunctionError: Attempt to call an undefined functi... | 1 | 2009-12-12T14:45:05Z | 2,797,746 | <p>The answer is its not supported yet. Simply pygtkglext doesn't set glCreateProgram. However git version does.</p>
| 1 | 2010-05-09T13:25:10Z | [
"python",
"pygtk",
"glsl",
"shader"
] |
How to override ord behaivour in Python for str childs? | 1,893,816 | <p>I have this class:</p>
<pre><code>class STR(str):
def __int__(self):
return 42
</code></pre>
<p>If i use it in the promt like this:</p>
<pre><code>>>> a=STR('8')
>>> ord(a)
56
>>> int(a)
42
>>> chr(a)
'*'
</code></pre>
<p>that's the behaivour. I'd like to ord(a) b... | 2 | 2009-12-12T15:52:03Z | 1,893,847 | <p>Here's the C source for Python's builtin <code>ord</code> from the <a href="http://svn.python.org/view/python/trunk/Python/bltinmodule.c?view=markup&pathrev=76648" rel="nofollow">current SVN revision of bltinmodule.c</a>:</p>
<pre><code>static PyObject *
builtin_ord(PyObject *self, PyObject* obj)
{
long ord... | 3 | 2009-12-12T16:05:28Z | [
"python",
"string",
"override"
] |
How to override ord behaivour in Python for str childs? | 1,893,816 | <p>I have this class:</p>
<pre><code>class STR(str):
def __int__(self):
return 42
</code></pre>
<p>If i use it in the promt like this:</p>
<pre><code>>>> a=STR('8')
>>> ord(a)
56
>>> int(a)
42
>>> chr(a)
'*'
</code></pre>
<p>that's the behaivour. I'd like to ord(a) b... | 2 | 2009-12-12T15:52:03Z | 1,893,848 | <p><code>ord</code> is not overloadable, it doesn't call any method on string objects (at least in CPython - <code>Python/bltinmodule.c</code>, <code>builtin_ord</code> function).</p>
<p>The best way is probably to create <code>STR.ord</code> method and call that instead of the built-in.</p>
| 0 | 2009-12-12T16:05:34Z | [
"python",
"string",
"override"
] |
How to override ord behaivour in Python for str childs? | 1,893,816 | <p>I have this class:</p>
<pre><code>class STR(str):
def __int__(self):
return 42
</code></pre>
<p>If i use it in the promt like this:</p>
<pre><code>>>> a=STR('8')
>>> ord(a)
56
>>> int(a)
42
>>> chr(a)
'*'
</code></pre>
<p>that's the behaivour. I'd like to ord(a) b... | 2 | 2009-12-12T15:52:03Z | 1,893,863 | <p>You can't override ord but you can overwrite as variable for example</p>
<p>backup original ord</p>
<pre><code>origord= ord
def ord(x):
return 42
ord(a)
42
origord(a)
56
</code></pre>
<p>But I think its not good a idea to overwrite it.</p>
| 0 | 2009-12-12T16:15:48Z | [
"python",
"string",
"override"
] |
How to override ord behaivour in Python for str childs? | 1,893,816 | <p>I have this class:</p>
<pre><code>class STR(str):
def __int__(self):
return 42
</code></pre>
<p>If i use it in the promt like this:</p>
<pre><code>>>> a=STR('8')
>>> ord(a)
56
>>> int(a)
42
>>> chr(a)
'*'
</code></pre>
<p>that's the behaivour. I'd like to ord(a) b... | 2 | 2009-12-12T15:52:03Z | 1,893,950 | <p>Somebody already posted the builtin ord code, and there is no method call you may intercept.</p>
<p>One solution could be override the ord function, for example:</p>
<pre><code>backup_ord = ord
def ord(obj):
if hasattr(obj, '__ord__'):
return obj.__ord__()
else:
return backup_ord(obj)
</co... | 2 | 2009-12-12T16:44:49Z | [
"python",
"string",
"override"
] |
Python random and int to string question | 1,893,867 | <p>I am using this line of code to generate a random list of integers:</p>
<pre><code>random.sample(range(2000), 100)
</code></pre>
<p>With this code i know i wont have double value's with my result. Is their maybe a faster way to achieve the same results?</p>
<p>Now i actually have to convert these int to string. W... | 0 | 2009-12-12T16:18:16Z | 1,893,877 | <p>random.sample chooses integers from the list <em>without</em> replacement. If you are trying to avoid duplicates then what you are doing is the right method. Could your numbers get much larger? You need to use Python 3, or xrange in Python 2 to avoid generating the entire list of integers in the range.</p>
<p>(Than... | 1 | 2009-12-12T16:22:15Z | [
"python",
"random"
] |
Python random and int to string question | 1,893,867 | <p>I am using this line of code to generate a random list of integers:</p>
<pre><code>random.sample(range(2000), 100)
</code></pre>
<p>With this code i know i wont have double value's with my result. Is their maybe a faster way to achieve the same results?</p>
<p>Now i actually have to convert these int to string. W... | 0 | 2009-12-12T16:18:16Z | 1,893,880 | <pre><code>import random
r = random.sample(range(2000), 100)
# One way to convert them to strings:
s = [str(x) for x in r]
</code></pre>
| 0 | 2009-12-12T16:23:27Z | [
"python",
"random"
] |
Python random and int to string question | 1,893,867 | <p>I am using this line of code to generate a random list of integers:</p>
<pre><code>random.sample(range(2000), 100)
</code></pre>
<p>With this code i know i wont have double value's with my result. Is their maybe a faster way to achieve the same results?</p>
<p>Now i actually have to convert these int to string. W... | 0 | 2009-12-12T16:18:16Z | 1,893,953 | <p>If you'll be generating lots and lots of lists of random numbers, you can pre-generate the strings to accelerate the lookup, something like this. </p>
<pre><code>stringcache = dict((val, str(val)) for val in range(2000))
while some_condition:
r_strings = map(stringcache.get, random.sample(range(2000), 100))
... | 0 | 2009-12-12T16:45:05Z | [
"python",
"random"
] |
Python random and int to string question | 1,893,867 | <p>I am using this line of code to generate a random list of integers:</p>
<pre><code>random.sample(range(2000), 100)
</code></pre>
<p>With this code i know i wont have double value's with my result. Is their maybe a faster way to achieve the same results?</p>
<p>Now i actually have to convert these int to string. W... | 0 | 2009-12-12T16:18:16Z | 1,894,036 | <p>Use <code>xrange</code> instead of <code>range</code>:</p>
<pre><code>lst = random.sample(xrange(10**9), 100)
</code></pre>
<p>To convert to a list of strings:</p>
<pre><code>strings = map(str, lst)
</code></pre>
<p>As one string:</p>
<pre><code>s = ''.join(strings)
</code></pre>
| 2 | 2009-12-12T17:05:30Z | [
"python",
"random"
] |
Why am I getting a file permission error with Python | 1,893,959 | <p>I am working with a shared hosting environment which as well as other things supports Python. I have followed the examples and deployed my cgi file and then through chmod, gave it Read and Execute Permissions to the world and then Read, Write and Execute to the owner.</p>
<p>The code is simply this:</p>
<pre><cod... | 1 | 2009-12-12T16:46:03Z | 1,893,969 | <ol>
<li>Make sure the python location is really <code>/usr/bin/python</code></li>
<li>Give read & execute permissions to all, and write permission to owner: <code>chmod 755 file.py</code></li>
</ol>
<p>EDIT: are you getting the error from the command line or in your web browser? The directory could be configured ... | 3 | 2009-12-12T16:48:46Z | [
"python",
"linux"
] |
Why am I getting a file permission error with Python | 1,893,959 | <p>I am working with a shared hosting environment which as well as other things supports Python. I have followed the examples and deployed my cgi file and then through chmod, gave it Read and Execute Permissions to the world and then Read, Write and Execute to the owner.</p>
<p>The code is simply this:</p>
<pre><cod... | 1 | 2009-12-12T16:46:03Z | 1,893,971 | <p>the account the webserver is running as doesn't have privileges to execute the script, or a directory in the path leading to it.</p>
| 7 | 2009-12-12T16:49:35Z | [
"python",
"linux"
] |
Why am I getting a file permission error with Python | 1,893,959 | <p>I am working with a shared hosting environment which as well as other things supports Python. I have followed the examples and deployed my cgi file and then through chmod, gave it Read and Execute Permissions to the world and then Read, Write and Execute to the owner.</p>
<p>The code is simply this:</p>
<pre><cod... | 1 | 2009-12-12T16:46:03Z | 1,893,990 | <p>Another thing to check: Does the directory you have the script in have ExecCGI permissions (assuming you are running Apache)?</p>
| 1 | 2009-12-12T16:53:29Z | [
"python",
"linux"
] |
Why am I getting a file permission error with Python | 1,893,959 | <p>I am working with a shared hosting environment which as well as other things supports Python. I have followed the examples and deployed my cgi file and then through chmod, gave it Read and Execute Permissions to the world and then Read, Write and Execute to the owner.</p>
<p>The code is simply this:</p>
<pre><cod... | 1 | 2009-12-12T16:46:03Z | 1,894,014 | <p>OK, I listened to the tech support, and it would appear that was the biggest problem, lol :-) I was toldnot to put my cgi file in the cgi-bin, and during testing their servers were crashing quite a lot. So after everything has calmed down with the server and it started working again, I placed the file inside the cg... | 0 | 2009-12-12T16:59:05Z | [
"python",
"linux"
] |
Synchronizing time between simple python-socket-based server and clients | 1,893,987 | <p>I have the beginnings of a small multiplayer game that I'm writing in python as a learning exercise. Currently the server runs at 10 fps, while the clients run at whatever rate they like. This works well to conserve bandwidth, but unless the client tells the server when its input happened, all input gets quantized t... | 6 | 2009-12-12T16:52:43Z | 1,894,062 | <p>This is a very interesting question. Unfortunately there's no easy answer. You just have to understnad the issue well and settle for a solution that is <em>good enough</em> for your application.</p>
<p>My first instinct was that the <a href="http://en.wikipedia.org/wiki/Network%5FTime%5FProtocol" rel="nofollow">N... | 0 | 2009-12-12T17:12:54Z | [
"python",
"networking",
"udp",
"multiplayer"
] |
Synchronizing time between simple python-socket-based server and clients | 1,893,987 | <p>I have the beginnings of a small multiplayer game that I'm writing in python as a learning exercise. Currently the server runs at 10 fps, while the clients run at whatever rate they like. This works well to conserve bandwidth, but unless the client tells the server when its input happened, all input gets quantized t... | 6 | 2009-12-12T16:52:43Z | 1,904,817 | <p>I accidentally came across an <a href="http://gafferongames.com/game-physics/networked-physics/" rel="nofollow">excruciatingly fine blog post</a> on how to do distributed network physics in general (without traditional client prediction). I highly recommend it, along with the GDC slides Fiedler presented a couple of... | 1 | 2009-12-15T02:11:33Z | [
"python",
"networking",
"udp",
"multiplayer"
] |
csv2json.py error | 1,894,099 | <p>I am trying to run the script <a href="http://www.djangosnippets.org/snippets/1680/" rel="nofollow">csv2json.py</a> in the Command Prompt, but I get this error:</p>
<pre><code>C:\Users\A\Documents\PROJECTS\Django\sw2>csv2json.py csvtest1.csv wkw1.Lawyer
Converting C:\Users\A\Documents\PROJECTS\Django\sw2csvtest1... | 0 | 2009-12-12T17:23:44Z | 1,894,114 | <p>You should be using <code>os.path.join</code> rather than just concatenating <code>dirname()</code> and filenames.</p>
<pre><code>import os.path
in_file = os.path.join(dirname(__file__), input_file_name)
out_file = os.path.join(dirname(__file__), input_file_name + ".json")
</code></pre>
<p>will fix your problem, t... | 0 | 2009-12-12T17:28:20Z | [
"python",
"django",
"json",
"csv"
] |
csv2json.py error | 1,894,099 | <p>I am trying to run the script <a href="http://www.djangosnippets.org/snippets/1680/" rel="nofollow">csv2json.py</a> in the Command Prompt, but I get this error:</p>
<pre><code>C:\Users\A\Documents\PROJECTS\Django\sw2>csv2json.py csvtest1.csv wkw1.Lawyer
Converting C:\Users\A\Documents\PROJECTS\Django\sw2csvtest1... | 0 | 2009-12-12T17:23:44Z | 1,894,120 | <pre><code>from os import path
in_file = path.join(dirname(__file__), input_file_name )
out_file = path.join(dirname(__file__), input_file_name + ".json" )
[...]
</code></pre>
| 1 | 2009-12-12T17:29:59Z | [
"python",
"django",
"json",
"csv"
] |
csv2json.py error | 1,894,099 | <p>I am trying to run the script <a href="http://www.djangosnippets.org/snippets/1680/" rel="nofollow">csv2json.py</a> in the Command Prompt, but I get this error:</p>
<pre><code>C:\Users\A\Documents\PROJECTS\Django\sw2>csv2json.py csvtest1.csv wkw1.Lawyer
Converting C:\Users\A\Documents\PROJECTS\Django\sw2csvtest1... | 0 | 2009-12-12T17:23:44Z | 1,894,125 | <p><code>+</code> is used incorrectly here, the proper way to combine directory name and file name is using <code>os.path.join()</code>. But there is no need to combine directory where script is located with file name, since it's common to pass relative path to current working directory. So, change lines 31-32 to the f... | 1 | 2009-12-12T17:32:59Z | [
"python",
"django",
"json",
"csv"
] |
Convert string representation of list to list in Python | 1,894,269 | <p>I was wondering what the simplest way is to convert a <code>string</code> list like the following to a <code>list</code>:</p>
<pre><code>x = u'[ "A","B","C" , " D"]'
</code></pre>
<p>Even in case user puts spaces in between the commas, and spaces inside of the quotes. I need to handle that as well to:</p>
<pre><c... | 129 | 2009-12-12T18:19:03Z | 1,894,283 | <p>There is a quick solution:</p>
<pre><code>x = eval('[ "A","B","C" , " D"]')
</code></pre>
<p>Unwanted whitespaces in the list elements may be removed in this way:</p>
<pre><code>x = [x.strip() for x in eval('[ "A","B","C" , " D"]')]
</code></pre>
| 1 | 2009-12-12T18:24:11Z | [
"python",
"string"
] |
Convert string representation of list to list in Python | 1,894,269 | <p>I was wondering what the simplest way is to convert a <code>string</code> list like the following to a <code>list</code>:</p>
<pre><code>x = u'[ "A","B","C" , " D"]'
</code></pre>
<p>Even in case user puts spaces in between the commas, and spaces inside of the quotes. I need to handle that as well to:</p>
<pre><c... | 129 | 2009-12-12T18:19:03Z | 1,894,292 | <pre><code>import ast
l = ast.literal_eval('[ "A","B","C" , " D"]')
l = [i.strip() for i in l]
</code></pre>
| 7 | 2009-12-12T18:29:02Z | [
"python",
"string"
] |
Convert string representation of list to list in Python | 1,894,269 | <p>I was wondering what the simplest way is to convert a <code>string</code> list like the following to a <code>list</code>:</p>
<pre><code>x = u'[ "A","B","C" , " D"]'
</code></pre>
<p>Even in case user puts spaces in between the commas, and spaces inside of the quotes. I need to handle that as well to:</p>
<pre><c... | 129 | 2009-12-12T18:19:03Z | 1,894,293 | <p>The <code>eval</code> is dangerous - you shouldn't execute user input.</p>
<p>If you have 2.6 or newer, use ast instead of eval:</p>
<pre><code>>>> import ast
>>> ast.literal_eval('["A","B" ,"C" ," D"]')
["A", "B", "C", " D"]
</code></pre>
<p>Once you have that, <code>strip</code> the strings.</... | 29 | 2009-12-12T18:29:08Z | [
"python",
"string"
] |
Convert string representation of list to list in Python | 1,894,269 | <p>I was wondering what the simplest way is to convert a <code>string</code> list like the following to a <code>list</code>:</p>
<pre><code>x = u'[ "A","B","C" , " D"]'
</code></pre>
<p>Even in case user puts spaces in between the commas, and spaces inside of the quotes. I need to handle that as well to:</p>
<pre><c... | 129 | 2009-12-12T18:19:03Z | 1,894,296 | <pre><code>>>> import ast
>>> x = u'[ "A","B","C" , " D"]'
>>> x = ast.literal_eval(x)
>>> x
['A', 'B', 'C', ' D']
>>> x = [n.strip() for n in x]
>>> x
['A', 'B', 'C', 'D']
</code></pre>
<p><a href="http://docs.python.org/library/ast.html#ast.literal%5Feval">ast.li... | 214 | 2009-12-12T18:30:49Z | [
"python",
"string"
] |
Convert string representation of list to list in Python | 1,894,269 | <p>I was wondering what the simplest way is to convert a <code>string</code> list like the following to a <code>list</code>:</p>
<pre><code>x = u'[ "A","B","C" , " D"]'
</code></pre>
<p>Even in case user puts spaces in between the commas, and spaces inside of the quotes. I need to handle that as well to:</p>
<pre><c... | 129 | 2009-12-12T18:19:03Z | 1,894,785 | <p>If you know that your lists only contain quoted strings, this pyparsing example will give you your list of stripped strings (even preserving the original Unicode-ness).</p>
<pre><code>>>> from pyparsing import *
>>> x =u'[ "A","B","C" , " D"]'
>>> LBR,RBR = map(Suppress,"[]")
>>>... | 0 | 2009-12-12T21:38:54Z | [
"python",
"string"
] |
Convert string representation of list to list in Python | 1,894,269 | <p>I was wondering what the simplest way is to convert a <code>string</code> list like the following to a <code>list</code>:</p>
<pre><code>x = u'[ "A","B","C" , " D"]'
</code></pre>
<p>Even in case user puts spaces in between the commas, and spaces inside of the quotes. I need to handle that as well to:</p>
<pre><c... | 129 | 2009-12-12T18:19:03Z | 1,894,876 | <p>Assuming that all your inputs are lists and that the double quotes in the input actually don't matter, this can be done with a simple regexp replace. It is a bit perl-y but works like a charm. Note also that the output is now a list of unicode strings, you didn't specify that you needed that, but it seems to make ... | 4 | 2009-12-12T22:18:37Z | [
"python",
"string"
] |
Convert string representation of list to list in Python | 1,894,269 | <p>I was wondering what the simplest way is to convert a <code>string</code> list like the following to a <code>list</code>:</p>
<pre><code>x = u'[ "A","B","C" , " D"]'
</code></pre>
<p>Even in case user puts spaces in between the commas, and spaces inside of the quotes. I need to handle that as well to:</p>
<pre><c... | 129 | 2009-12-12T18:19:03Z | 19,724,679 | <p>with <code>numpy</code> this is working a very simple way</p>
<pre><code>x = u'[ "A","B","C" , " D"]'
list_string = str(x)
import numpy as np
print np.array(list_string)
</code></pre>
<p>gives</p>
<pre><code>>>>
[ "A","B","C" , " D"]
</code></pre>
| 5 | 2013-11-01T10:12:26Z | [
"python",
"string"
] |
Convert string representation of list to list in Python | 1,894,269 | <p>I was wondering what the simplest way is to convert a <code>string</code> list like the following to a <code>list</code>:</p>
<pre><code>x = u'[ "A","B","C" , " D"]'
</code></pre>
<p>Even in case user puts spaces in between the commas, and spaces inside of the quotes. I need to handle that as well to:</p>
<pre><c... | 129 | 2009-12-12T18:19:03Z | 35,461,204 | <p>The <a href="https://docs.python.org/3/library/json.html" rel="nofollow"><code>json</code></a> module is a better solution whenever there is a <em>stringified</em> list of dictionaries. The <code>json.loads(your_data)</code> function can be used to convert it to a list.</p>
<pre><code>>>> import json
>&... | 4 | 2016-02-17T15:39:52Z | [
"python",
"string"
] |
Processing output from cmdline via a Python script | 1,894,325 | <p>I'm trying to use the subprocess module with Python 2.6 in order to run a command and get its output. The command is typically ran like this:</p>
<pre><code>/usr/local/sbin/kamctl fifo profile_get_size myprofile | awk -F ':: ' '{print $2}'
</code></pre>
<p>What's the best way to use the subprocess module in my scr... | 0 | 2009-12-12T18:39:20Z | 1,894,338 | <p>f.e. stdout you can get like this:</p>
<pre><code>>>> import subprocess
>>> process = subprocess.Popen("echo 'test'", shell=True, stdout=subprocess.PIPE)
>>> process.wait()
0
>>> process.stdout.read()
'test\n'
</code></pre>
| 2 | 2009-12-12T18:45:34Z | [
"python",
"scripting",
"process"
] |
Processing output from cmdline via a Python script | 1,894,325 | <p>I'm trying to use the subprocess module with Python 2.6 in order to run a command and get its output. The command is typically ran like this:</p>
<pre><code>/usr/local/sbin/kamctl fifo profile_get_size myprofile | awk -F ':: ' '{print $2}'
</code></pre>
<p>What's the best way to use the subprocess module in my scr... | 0 | 2009-12-12T18:39:20Z | 1,894,345 | <p>Do you want the output, the return value (AKA status code), or both?</p>
<p>If the amount of data emitted by the pipeline on stdout and/or stderr is not too large, it's pretty simple to get "all of the above":</p>
<pre><code>import subprocess
s = """/usr/local/sbin/kamctl fifo profile_get_size myprofile | awk -F ... | 4 | 2009-12-12T18:47:51Z | [
"python",
"scripting",
"process"
] |
Overlapping partially transparent shapes | 1,894,564 | <p>If I draw any shape onto a surface (with SRCALPHA flag on) in a partially transparent colour it completely replaces what was underneath it, instead of overlapping like you would expect in image editors.</p>
<p>How can I make the shapes overlap properly?</p>
| 0 | 2009-12-12T20:15:00Z | 1,894,599 | <p>You could use <a href="http://www.pygame.org/docs/ref/surface.html#Surface.blit" rel="nofollow">blit</a> with appropriate <code>BLEND_*</code> values (keeping the shapes as separate surfaces, for integrity and editing, and only blitting them for display purposes).</p>
| 1 | 2009-12-12T20:26:36Z | [
"python",
"pygame",
"alpha"
] |
Overlapping partially transparent shapes | 1,894,564 | <p>If I draw any shape onto a surface (with SRCALPHA flag on) in a partially transparent colour it completely replaces what was underneath it, instead of overlapping like you would expect in image editors.</p>
<p>How can I make the shapes overlap properly?</p>
| 0 | 2009-12-12T20:15:00Z | 1,895,651 | <p>Alpha on its own is just an extra 'value' that can serve a purpose. It just so happens that the purpose is typically (but not always) transparency (other uses include reflectance, specular highlighting and even an approach for faking HDR).</p>
<p>You need to specify that you want it to blend (and the equation it sh... | 0 | 2009-12-13T05:41:54Z | [
"python",
"pygame",
"alpha"
] |
Overlapping partially transparent shapes | 1,894,564 | <p>If I draw any shape onto a surface (with SRCALPHA flag on) in a partially transparent colour it completely replaces what was underneath it, instead of overlapping like you would expect in image editors.</p>
<p>How can I make the shapes overlap properly?</p>
| 0 | 2009-12-12T20:15:00Z | 1,901,669 | <p>As noted, the draw functions in PyGame don't actually do blending the way you might expect. From the PyGame documentation:</p>
<blockquote>
<p>Most of the arguments accept a color argument that is an RGB triplet. These can also accept an RGBA quadruplet. The alpha value will be written directly into the Surface i... | 1 | 2009-12-14T15:46:35Z | [
"python",
"pygame",
"alpha"
] |
variable name introspection in Python | 1,894,591 | <p>Is it possible to dynamically determine the name of a variable in Python?</p>
<p>For example, I sometimes have the following situation:</p>
<pre><code>name = foo if bar else baz
type = alpha or bravo
D = {
"name": name,
"type": type
}
</code></pre>
<p>It would be nice if duplication there could be reduce... | 3 | 2009-12-12T20:23:10Z | 1,894,611 | <p>In general, you can't do this in Python, because Python has objects, not variables.</p>
<p>If I have</p>
<pre><code>L1 = [1,2]
L2 = L1
</code></pre>
<p>Then, <code>L1</code> and <code>L2</code> both refer to the same object. It has no <em>single</em> name.</p>
<p>Similarly:</p>
<pre><code>def f1(): pass
f2 = f... | 4 | 2009-12-12T20:29:23Z | [
"python",
"metaprogramming"
] |
variable name introspection in Python | 1,894,591 | <p>Is it possible to dynamically determine the name of a variable in Python?</p>
<p>For example, I sometimes have the following situation:</p>
<pre><code>name = foo if bar else baz
type = alpha or bravo
D = {
"name": name,
"type": type
}
</code></pre>
<p>It would be nice if duplication there could be reduce... | 3 | 2009-12-12T20:23:10Z | 1,894,643 | <p>In the general case, you cannot deduce the name from a value (there might be no name, there might be multiple ones, etc); when you call your hypothetical <code>makedict(name)</code>, the <strong>value</strong> of <code>name</code> is what <code>makedict</code> receives, so (again, in the general case) it cannot disc... | 10 | 2009-12-12T20:44:24Z | [
"python",
"metaprogramming"
] |
variable name introspection in Python | 1,894,591 | <p>Is it possible to dynamically determine the name of a variable in Python?</p>
<p>For example, I sometimes have the following situation:</p>
<pre><code>name = foo if bar else baz
type = alpha or bravo
D = {
"name": name,
"type": type
}
</code></pre>
<p>It would be nice if duplication there could be reduce... | 3 | 2009-12-12T20:23:10Z | 1,894,674 | <p>You can do what you want for functions:</p>
<pre><code>>>> def blagnorf():
pass
>>> print blagnorf.__name__
blagnorf
</code></pre>
<p>But not for variables, unfortunately. You could probably write a preprocessor for your python code to do it for you, though...</p>
<p>Note that you can do th... | 1 | 2009-12-12T20:56:38Z | [
"python",
"metaprogramming"
] |
variable name introspection in Python | 1,894,591 | <p>Is it possible to dynamically determine the name of a variable in Python?</p>
<p>For example, I sometimes have the following situation:</p>
<pre><code>name = foo if bar else baz
type = alpha or bravo
D = {
"name": name,
"type": type
}
</code></pre>
<p>It would be nice if duplication there could be reduce... | 3 | 2009-12-12T20:23:10Z | 1,894,810 | <p>Whenever you get a hankering to make a gazillion simple methods whose internals only differ according to the method's name, you probably should reconsider your interface. Instead, you could do this:</p>
<pre><code>class Item(object):
def item_action(self, action, item):
dispatch(action, item)
</code></p... | 1 | 2009-12-12T21:49:12Z | [
"python",
"metaprogramming"
] |
Can you embed python scripts into the web browser? | 1,894,598 | <p>I'm trying to see how I can get a python script to run in the web browser. Does anyone know if this is possible or would I need to make a plugin?</p>
<p>I'm looking for something that would work like:</p>
<pre><code><embed type="application/x-python" src="myscript.py"></embed>
</code></pre>
<p>Thanks,... | 8 | 2009-12-12T20:26:07Z | 1,894,613 | <p>I don't think any mainstream browser supports this by default so you'd need to write a plugin.</p>
<p>There are people that have tried this before though. For example, <a href="http://www.voidspace.org.uk/ironpython/silverlight/pycon.html" rel="nofollow">Iron Python + Silverlight</a>.</p>
| 4 | 2009-12-12T20:29:41Z | [
"python",
"html",
"plugins",
"browser"
] |
Can you embed python scripts into the web browser? | 1,894,598 | <p>I'm trying to see how I can get a python script to run in the web browser. Does anyone know if this is possible or would I need to make a plugin?</p>
<p>I'm looking for something that would work like:</p>
<pre><code><embed type="application/x-python" src="myscript.py"></embed>
</code></pre>
<p>Thanks,... | 8 | 2009-12-12T20:26:07Z | 1,894,980 | <p><a href="http://pyjs.org/" rel="nofollow">pyjamas</a> might be of interest.</p>
| 2 | 2009-12-12T23:02:55Z | [
"python",
"html",
"plugins",
"browser"
] |
Can you embed python scripts into the web browser? | 1,894,598 | <p>I'm trying to see how I can get a python script to run in the web browser. Does anyone know if this is possible or would I need to make a plugin?</p>
<p>I'm looking for something that would work like:</p>
<pre><code><embed type="application/x-python" src="myscript.py"></embed>
</code></pre>
<p>Thanks,... | 8 | 2009-12-12T20:26:07Z | 1,909,432 | <p>Thank you very much to everyone who contributed <em>hugs to all</em></p>
<p>I've decided that i'll just make a netscape-based plugin for python (source code and all that stuff will be availble when i've done it for everyone)</p>
<p>Joe</p>
| 2 | 2009-12-15T18:32:03Z | [
"python",
"html",
"plugins",
"browser"
] |
Can you embed python scripts into the web browser? | 1,894,598 | <p>I'm trying to see how I can get a python script to run in the web browser. Does anyone know if this is possible or would I need to make a plugin?</p>
<p>I'm looking for something that would work like:</p>
<pre><code><embed type="application/x-python" src="myscript.py"></embed>
</code></pre>
<p>Thanks,... | 8 | 2009-12-12T20:26:07Z | 16,521,323 | <p>There is also <a href="http://www.brython.info/" rel="nofollow">brython</a> and <a href="http://apppyjs.appspot.com/" rel="nofollow">PythonScript</a> but this one is compiled. I forked PythonScript to create Pythonium. There is also pypyjs.</p>
| 3 | 2013-05-13T11:48:25Z | [
"python",
"html",
"plugins",
"browser"
] |
Django loaddata ValidationError | 1,894,628 | <p>This <a href="http://stackoverflow.com/questions/1884827/django-loaddata-error">thread</a> got too confusing (for me) so I am asking the question again. I could not make the csv2json.py script mentioned in the original question work. I am just trying to find a way to import data to sqlite3 database.</p>
<p>Here's t... | 1 | 2009-12-12T20:38:23Z | 1,895,473 | <blockquote>
<p>(I'll fix the duplicate "school" later.)</p>
</blockquote>
<p>Actually, that is your problem. The second definition of school as a foreign key will require it to be an integer, thus the error.</p>
<p>You can confirm this by dumping the schema of your table with </p>
<blockquote>
<p>sqlite3 <i><... | 2 | 2009-12-13T03:29:47Z | [
"python",
"django",
"json",
"csv"
] |
python lxml on app engine? | 1,894,696 | <p>Can I use python lxml on google app engine? ( or do i have to use Beautiful Soup? )</p>
<p>I have started using Beautiful Soup but it seems slow. I am just starting to play with the idea of "screen scraping" data from other websites to create some sort of "mash-up".</p>
| 11 | 2009-12-12T21:04:14Z | 1,894,756 | <p><strong>EDIT</strong>: If you <a href="http://code.google.com/appengine/docs/python/python27/using27.html">use python2.7</a> on AppEngine, the <code>lxml</code> library <a href="http://code.google.com/appengine/docs/python/python27/newin27.html#Supported_Third-Party_Libraries">is supported</a>.</p>
<hr>
<p>Short a... | 23 | 2009-12-12T21:28:19Z | [
"python",
"google-app-engine",
"beautifulsoup",
"lxml"
] |
python lxml on app engine? | 1,894,696 | <p>Can I use python lxml on google app engine? ( or do i have to use Beautiful Soup? )</p>
<p>I have started using Beautiful Soup but it seems slow. I am just starting to play with the idea of "screen scraping" data from other websites to create some sort of "mash-up".</p>
| 11 | 2009-12-12T21:04:14Z | 15,529,850 | <p>To add to Caio's revised answer, you can use <code>lxml</code> and this is how to do it:</p>
<p>In your <code>app.yaml</code> file, add the following:</p>
<pre><code>libraries:
- name: lxml
version: "2.3" # or "latest"
</code></pre>
<p>Now <code>import lxml</code> will work in your Python script.</p>
<p><a h... | 11 | 2013-03-20T16:54:09Z | [
"python",
"google-app-engine",
"beautifulsoup",
"lxml"
] |
How to filter data from a file using Python? | 1,894,711 | <p>I'm trying to filter certain data from an HTML file. For example, the HTML file is as follows:</p>
<pre><code><tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]">software_0.1-0.log</td><td align="right">17-Nov-2009 13:46 </td><td align="right">186K</td><... | 0 | 2009-12-12T21:11:13Z | 1,894,721 | <p>You can extract the strings of interest (and some more text) using for example the popular <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">beautifulsoup</a> package. Then, you'll need some string manipulation (or maybe regular expressions) to separate the exact part of interest, but that depe... | 2 | 2009-12-12T21:16:11Z | [
"python",
"filter",
"parsing"
] |
How to filter data from a file using Python? | 1,894,711 | <p>I'm trying to filter certain data from an HTML file. For example, the HTML file is as follows:</p>
<pre><code><tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]">software_0.1-0.log</td><td align="right">17-Nov-2009 13:46 </td><td align="right">186K</td><... | 0 | 2009-12-12T21:11:13Z | 1,894,742 | <p>Try <a href="http://www.crummy.com/software/BeautifulSoup/documentation.html" rel="nofollow">Beautifull Soup</a>, a parser for HTML. You'll get a structured document out of there and could select the first and second td contents.</p>
<p>It may be overkill in this instance, but especially if your HTML is from the ou... | 0 | 2009-12-12T21:23:47Z | [
"python",
"filter",
"parsing"
] |
How to filter data from a file using Python? | 1,894,711 | <p>I'm trying to filter certain data from an HTML file. For example, the HTML file is as follows:</p>
<pre><code><tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]">software_0.1-0.log</td><td align="right">17-Nov-2009 13:46 </td><td align="right">186K</td><... | 0 | 2009-12-12T21:11:13Z | 1,894,761 | <p>It's quite easy with <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a>:</p>
<pre><code>html = '''<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]">software_0.1-0.log</td><td align="right">17-Nov-2009 13:46 </td><td align="ri... | 6 | 2009-12-12T21:29:41Z | [
"python",
"filter",
"parsing"
] |
How to filter data from a file using Python? | 1,894,711 | <p>I'm trying to filter certain data from an HTML file. For example, the HTML file is as follows:</p>
<pre><code><tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]">software_0.1-0.log</td><td align="right">17-Nov-2009 13:46 </td><td align="right">186K</td><... | 0 | 2009-12-12T21:11:13Z | 1,895,709 | <p>you requirement seems simple, so here's the non BeautifulSoup way, just pure string manipulation</p>
<pre><code>s="""<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]">software_0.1-0.log</td><td align="right">17-Nov-2009 13:46 </td><td align="right">186K</td... | 0 | 2009-12-13T06:06:45Z | [
"python",
"filter",
"parsing"
] |
Printing BFS (Binary Tree) in Level Order with _specific formatting_ | 1,894,846 | <p>To begin with, this question is not a dup of <a href="http://stackoverflow.com/questions/1104644/how-would-you-print-out-the-data-in-a-binary-tree-level-by-level-starting-at-th">this one</a>, but builds on it.</p>
<p>Taking the tree in that question as an example,</p>
<pre><code> 1
/ \
2 3
/ / \
4 ... | 21 | 2009-12-12T22:04:00Z | 1,894,860 | <p>Sounds like <a href="http://www.cs.bu.edu/teaching/cs112/spring-2000/breadth-first/">breadth-first traversal</a> to me.</p>
<p>Breadth-first traversal is implemented with a <a href="http://en.wikipedia.org/wiki/Queue%5F%28data%5Fstructure%29">queue</a>. Here, simply insert in the queue a special token that indicate... | 7 | 2009-12-12T22:11:22Z | [
"python",
"algorithm",
"binary-tree",
"breadth-first-search"
] |
Printing BFS (Binary Tree) in Level Order with _specific formatting_ | 1,894,846 | <p>To begin with, this question is not a dup of <a href="http://stackoverflow.com/questions/1104644/how-would-you-print-out-the-data-in-a-binary-tree-level-by-level-starting-at-th">this one</a>, but builds on it.</p>
<p>Taking the tree in that question as an example,</p>
<pre><code> 1
/ \
2 3
/ / \
4 ... | 21 | 2009-12-12T22:04:00Z | 1,894,914 | <p>Just build one level at a time, e.g.:</p>
<pre><code>class Node(object):
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def traverse(rootnode):
thislevel = [rootnode]
while thislevel:
nextlevel = list()
for n in thislevel:
pr... | 32 | 2009-12-12T22:33:01Z | [
"python",
"algorithm",
"binary-tree",
"breadth-first-search"
] |
Printing BFS (Binary Tree) in Level Order with _specific formatting_ | 1,894,846 | <p>To begin with, this question is not a dup of <a href="http://stackoverflow.com/questions/1104644/how-would-you-print-out-the-data-in-a-binary-tree-level-by-level-starting-at-th">this one</a>, but builds on it.</p>
<p>Taking the tree in that question as an example,</p>
<pre><code> 1
/ \
2 3
/ / \
4 ... | 21 | 2009-12-12T22:04:00Z | 1,894,928 | <p>A version that doesn't require extra storage:</p>
<pre><code>std::deque<Node> bfs;
bfs.push_back(start);
int nodesInThisLayer = 1;
int nodesInNextLayer = 0;
while (!bfs.empty()) {
Node front = bfs.front();
bfs.pop_front();
for (/*iterate over front's children*/) {
++nodesInNextLayer;
... | 0 | 2009-12-12T22:37:07Z | [
"python",
"algorithm",
"binary-tree",
"breadth-first-search"
] |
Printing BFS (Binary Tree) in Level Order with _specific formatting_ | 1,894,846 | <p>To begin with, this question is not a dup of <a href="http://stackoverflow.com/questions/1104644/how-would-you-print-out-the-data-in-a-binary-tree-level-by-level-starting-at-th">this one</a>, but builds on it.</p>
<p>Taking the tree in that question as an example,</p>
<pre><code> 1
/ \
2 3
/ / \
4 ... | 21 | 2009-12-12T22:04:00Z | 3,806,312 | <p>why not keep sentinal in queue and check when all the nodes in current level are processed.</p>
<pre><code>public void printLevel(Node n) {
Queue<Integer> q = new ArrayBlockingQueue<Integer>();
Node sentinal = new Node(-1);
q.put(n);
q.put(sentinal);
while(q.size() > 0) {
... | 4 | 2010-09-27T17:33:48Z | [
"python",
"algorithm",
"binary-tree",
"breadth-first-search"
] |
Printing BFS (Binary Tree) in Level Order with _specific formatting_ | 1,894,846 | <p>To begin with, this question is not a dup of <a href="http://stackoverflow.com/questions/1104644/how-would-you-print-out-the-data-in-a-binary-tree-level-by-level-starting-at-th">this one</a>, but builds on it.</p>
<p>Taking the tree in that question as an example,</p>
<pre><code> 1
/ \
2 3
/ / \
4 ... | 21 | 2009-12-12T22:04:00Z | 7,514,295 | <p>A simple Version based on Bread First Search, This code is applicable for graphs in general and can be used for binary trees as well.</p>
<pre><code>def printBfsLevels(graph,start):
queue=[start]
path=[]
currLevel=1
levelMembers=1
height=[(0,start)]
childCount=0
print queue
while queue:
visNode=... | 2 | 2011-09-22T11:51:51Z | [
"python",
"algorithm",
"binary-tree",
"breadth-first-search"
] |
Printing BFS (Binary Tree) in Level Order with _specific formatting_ | 1,894,846 | <p>To begin with, this question is not a dup of <a href="http://stackoverflow.com/questions/1104644/how-would-you-print-out-the-data-in-a-binary-tree-level-by-level-starting-at-th">this one</a>, but builds on it.</p>
<p>Taking the tree in that question as an example,</p>
<pre><code> 1
/ \
2 3
/ / \
4 ... | 21 | 2009-12-12T22:04:00Z | 13,344,511 | <p>Here my code prints the tree level by level as well as upside down</p>
<pre><code>int counter=0;// to count the toatl no. of elments in the tree
void tree::print_treeupsidedown_levelbylevel(int *array)
{
int j=2;
int next=j;
int temp=0;
while(j<2*counter)
{
if(array[j]==0)
... | 1 | 2012-11-12T13:24:10Z | [
"python",
"algorithm",
"binary-tree",
"breadth-first-search"
] |
Printing BFS (Binary Tree) in Level Order with _specific formatting_ | 1,894,846 | <p>To begin with, this question is not a dup of <a href="http://stackoverflow.com/questions/1104644/how-would-you-print-out-the-data-in-a-binary-tree-level-by-level-starting-at-th">this one</a>, but builds on it.</p>
<p>Taking the tree in that question as an example,</p>
<pre><code> 1
/ \
2 3
/ / \
4 ... | 21 | 2009-12-12T22:04:00Z | 13,598,013 | <p>The following code will print each level of binary tree into new line:</p>
<pre><code>public void printbylevel(node root){
int counter = 0, level = 0;
Queue<node> qu = new LinkedList<node>();
qu.add(root);
level = 1;
if(root.child1 != null)counter++;
if(root.child2 != null)count... | 1 | 2012-11-28T04:50:05Z | [
"python",
"algorithm",
"binary-tree",
"breadth-first-search"
] |
Printing BFS (Binary Tree) in Level Order with _specific formatting_ | 1,894,846 | <p>To begin with, this question is not a dup of <a href="http://stackoverflow.com/questions/1104644/how-would-you-print-out-the-data-in-a-binary-tree-level-by-level-starting-at-th">this one</a>, but builds on it.</p>
<p>Taking the tree in that question as an example,</p>
<pre><code> 1
/ \
2 3
/ / \
4 ... | 21 | 2009-12-12T22:04:00Z | 17,263,948 | <p>My solution is similar to Alex Martelli's, but I separate traversal of the data structure from processing the data structure. I put the meat of the code into iterLayers to keep printByLayer short and sweet.</p>
<pre><code>from collections import deque
class Node:
def __init__(self, val, lc=None, rc=None):
... | 2 | 2013-06-23T18:29:36Z | [
"python",
"algorithm",
"binary-tree",
"breadth-first-search"
] |
Printing BFS (Binary Tree) in Level Order with _specific formatting_ | 1,894,846 | <p>To begin with, this question is not a dup of <a href="http://stackoverflow.com/questions/1104644/how-would-you-print-out-the-data-in-a-binary-tree-level-by-level-starting-at-th">this one</a>, but builds on it.</p>
<p>Taking the tree in that question as an example,</p>
<pre><code> 1
/ \
2 3
/ / \
4 ... | 21 | 2009-12-12T22:04:00Z | 20,588,847 | <p>This is breadth first search, so you can use a queue and recursively do this in a simple and compact way ...</p>
<pre><code># built-in data structure we can use as a queue
from collections import deque
def print_level_order(head, queue = deque()):
if head is None:
return
print head.data
[queue.... | 3 | 2013-12-14T22:12:58Z | [
"python",
"algorithm",
"binary-tree",
"breadth-first-search"
] |
Printing BFS (Binary Tree) in Level Order with _specific formatting_ | 1,894,846 | <p>To begin with, this question is not a dup of <a href="http://stackoverflow.com/questions/1104644/how-would-you-print-out-the-data-in-a-binary-tree-level-by-level-starting-at-th">this one</a>, but builds on it.</p>
<p>Taking the tree in that question as an example,</p>
<pre><code> 1
/ \
2 3
/ / \
4 ... | 21 | 2009-12-12T22:04:00Z | 24,482,214 | <pre><code>class TNode:
def __init__(self, data, left=None, right=None):
self.data = data
self.left = left
self.right = right
class BST:
def __init__(self, root):
self._root = root
def bfs(self):
list = [self._root]
while len(list) > 0:
print [e.data for e in list]
lis... | 1 | 2014-06-30T02:28:00Z | [
"python",
"algorithm",
"binary-tree",
"breadth-first-search"
] |
Django form in Google App Engine unable to find module PIL | 1,894,875 | <p>There are actually a couple of questions here. For what I'm doing, I'm doing a basic image upload with Django 1.1 and Google App Engine. Here is my form class:</p>
<pre><code>class UploadPictureForm(forms.Form):
picture = forms.ImageField()
</code></pre>
<p>And then on submit, I have the following code:</p>
... | 2 | 2009-12-12T22:18:07Z | 1,894,936 | <p>For starters, you shouldn't use GAE with Python 2.6. Google App Engine is created with 2.5 in mind and it usually breaks in multiple ways on 2.6.</p>
<p>More, I'm not quite sure you can use PIL at all with GAE. It's a C-based library and therefore it's a no-no for GAE (which requires custom packages to be pure-Pyth... | 3 | 2009-12-12T22:38:50Z | [
"python",
"google-app-engine",
"python-imaging-library"
] |
Django form in Google App Engine unable to find module PIL | 1,894,875 | <p>There are actually a couple of questions here. For what I'm doing, I'm doing a basic image upload with Django 1.1 and Google App Engine. Here is my form class:</p>
<pre><code>class UploadPictureForm(forms.Form):
picture = forms.ImageField()
</code></pre>
<p>And then on submit, I have the following code:</p>
... | 2 | 2009-12-12T22:18:07Z | 1,896,277 | <p>Can you show us the full stacktrace? Based on what you provided, there's several options:</p>
<ol>
<li>Django is trying to use PIL directly for some reason. This won't work on App Engine, as PIL isn't available there, and you can't upload it because it's C code.</li>
<li>Your own code is trying to use PIL directly.... | 0 | 2009-12-13T11:51:02Z | [
"python",
"google-app-engine",
"python-imaging-library"
] |
Django form in Google App Engine unable to find module PIL | 1,894,875 | <p>There are actually a couple of questions here. For what I'm doing, I'm doing a basic image upload with Django 1.1 and Google App Engine. Here is my form class:</p>
<pre><code>class UploadPictureForm(forms.Form):
picture = forms.ImageField()
</code></pre>
<p>And then on submit, I have the following code:</p>
... | 2 | 2009-12-12T22:18:07Z | 1,896,672 | <blockquote>
<p>More, I'm not quite sure you can use PIL at all with GAE. It's a C-based library and therefore it's a no-no for GAE (which requires custom packages to be pure-Python only) (there's even a ticket for this issue).</p>
</blockquote>
<p>PIL is used by the development server locally to simulate all image ... | 0 | 2009-12-13T14:33:23Z | [
"python",
"google-app-engine",
"python-imaging-library"
] |
How best to hold 1000 different data series using TimeSeries module in Python? | 1,894,981 | <p>I want to create a massive TimeSeries object which will hold 1000 different financial markets data series, each storing 1500 daily-data points. I'm quite new to the TimeSeries module and am a little confused as to how I would best go about it. So a few basic questions:</p>
<p>1) Should I use a huge numpy array of 1... | 1 | 2009-12-12T23:03:36Z | 1,895,174 | <p>1) i once implemented a pagerank algorithm for a small set (~10K) of linked documents, therefore in during the calculation a 10Kx10K matrix had to be handled, for which the <code>numpy</code> array implementation was - as i recall - <em>blazingly</em> fast.</p>
<p>2) imho storing metadata like series name externall... | 1 | 2009-12-13T00:29:19Z | [
"python",
"numpy",
"finance"
] |
How best to hold 1000 different data series using TimeSeries module in Python? | 1,894,981 | <p>I want to create a massive TimeSeries object which will hold 1000 different financial markets data series, each storing 1500 daily-data points. I'm quite new to the TimeSeries module and am a little confused as to how I would best go about it. So a few basic questions:</p>
<p>1) Should I use a huge numpy array of 1... | 1 | 2009-12-12T23:03:36Z | 1,895,182 | <p>For help on this, have a look at <a href="http://quantlib.org/index.shtml" rel="nofollow">Quantlib</a> which is a useful library for financial work, and which has an active users mailing list.</p>
<p>In addition, <a href="http://www.researchandmarkets.com/reports/1053319/financial%5Fmodelling%5Fin%5Fpython.pdf" rel... | 0 | 2009-12-13T00:33:12Z | [
"python",
"numpy",
"finance"
] |
How can I create a regular expression in Python? | 1,895,026 | <p>I'm trying to create regular expressions to filter certain text from a text file. What I want to filter has this format:</p>
<pre><code>word_*_word.word
</code></pre>
<p>So for example, I would like the python code every match. Sample results would be:</p>
<pre><code>program1_0.0-1_log.build
program2_0.1-3_log.bu... | 0 | 2009-12-12T23:21:02Z | 1,895,045 | <p>try with <code>^\w+_.*_\w+\.\w+$</code></p>
| 0 | 2009-12-12T23:30:09Z | [
"python",
"regex"
] |
How can I create a regular expression in Python? | 1,895,026 | <p>I'm trying to create regular expressions to filter certain text from a text file. What I want to filter has this format:</p>
<pre><code>word_*_word.word
</code></pre>
<p>So for example, I would like the python code every match. Sample results would be:</p>
<pre><code>program1_0.0-1_log.build
program2_0.1-3_log.bu... | 0 | 2009-12-12T23:21:02Z | 1,895,052 | <p>Python's regular expression module is called <code>re</code>. You need to import it and use the <a href="http://docs.python.org/library/re.html#module-contents" rel="nofollow">provided functions</a>:</p>
<pre><code>import re
if re.match(r'\w+_.*_\w+.\w+', "some_text_abc.x"):
print "yeah."
</code></pre>
<p>It is... | 1 | 2009-12-12T23:32:35Z | [
"python",
"regex"
] |
How can I create a regular expression in Python? | 1,895,026 | <p>I'm trying to create regular expressions to filter certain text from a text file. What I want to filter has this format:</p>
<pre><code>word_*_word.word
</code></pre>
<p>So for example, I would like the python code every match. Sample results would be:</p>
<pre><code>program1_0.0-1_log.build
program2_0.1-3_log.bu... | 0 | 2009-12-12T23:21:02Z | 1,895,053 | <p>Try something like this:</p>
<pre><code>r'[a-zA-Z0-9]+_[^_]+_[a-zA-Z0-9]+\.[a-zA-Z0-9]+'
</code></pre>
| 3 | 2009-12-12T23:32:56Z | [
"python",
"regex"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.