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 |
|---|---|---|---|---|---|---|---|---|---|
Is there a cross-platform python low-level API to capture or generate keyboard events? | 676,713 | <p>I am trying to write a cross-platform python program that would run in the background, monitor all keyboard events and when it sees some specific shortcuts, it generates one or more keyboard events of its own. For example, this could be handy to have Ctrl-@ mapped to "my.email@address", so that every time some prog... | 11 | 2009-03-24T09:48:25Z | 681,571 | <p>On linux, you might want to have a look at <a href="http://pykeylogger.wiki.sourceforge.net/" rel="nofollow">pykeylogger</a>. For some strange reason, reading from /dev/input/.... doesn't always work when X is running. For example it doesn't work on ubuntu 8.10. Pykeylogger uses xlib, which works exactly when the ot... | 0 | 2009-03-25T13:23:18Z | [
"python",
"cross-platform",
"keyboard-events",
"low-level-api"
] |
Is there a cross-platform python low-level API to capture or generate keyboard events? | 676,713 | <p>I am trying to write a cross-platform python program that would run in the background, monitor all keyboard events and when it sees some specific shortcuts, it generates one or more keyboard events of its own. For example, this could be handy to have Ctrl-@ mapped to "my.email@address", so that every time some prog... | 11 | 2009-03-24T09:48:25Z | 1,189,608 | <p>As the guy that wrote the original pykeylogger linux port, I can say there isn't really a cross platform one. Essentially I rewrote the pyhook API for keyboard events to capture from the xserver itself, using the record extension. Of course, this assumes the record extension is there, loaded into the x server.</p>
... | 5 | 2009-07-27T17:44:51Z | [
"python",
"cross-platform",
"keyboard-events",
"low-level-api"
] |
Is there a cross-platform python low-level API to capture or generate keyboard events? | 676,713 | <p>I am trying to write a cross-platform python program that would run in the background, monitor all keyboard events and when it sees some specific shortcuts, it generates one or more keyboard events of its own. For example, this could be handy to have Ctrl-@ mapped to "my.email@address", so that every time some prog... | 11 | 2009-03-24T09:48:25Z | 1,666,022 | <p>I've made a few tests on Ubuntu 9.10. pykeylogger doesn't seems to be working. I've tryied to change the /etc/X11/xorg.conf in order to allow module to be loaded but in that specific version of ubuntu there is no xorg.conf. So, in my opiniion pykelogger is NOT working on ubuntu 9.10 !!</p>
| 1 | 2009-11-03T08:44:38Z | [
"python",
"cross-platform",
"keyboard-events",
"low-level-api"
] |
Is there a cross-platform python low-level API to capture or generate keyboard events? | 676,713 | <p>I am trying to write a cross-platform python program that would run in the background, monitor all keyboard events and when it sees some specific shortcuts, it generates one or more keyboard events of its own. For example, this could be handy to have Ctrl-@ mapped to "my.email@address", so that every time some prog... | 11 | 2009-03-24T09:48:25Z | 1,802,717 | <p>Under Linux it's possible to do this quite easily with Xlib. See this page for details:</p>
<p><a href="http://www.larsen-b.com/Article/184.html" rel="nofollow">http://www.larsen-b.com/Article/184.html</a></p>
| 0 | 2009-11-26T09:59:02Z | [
"python",
"cross-platform",
"keyboard-events",
"low-level-api"
] |
Intercepting changes of attributes in classes within a class - Python | 676,826 | <p>I have been messing around with pygame and python and I want to be able to call a function when an attribute of my class has changed. My current solution being:</p>
<pre><code>class ExampleClass(parentClass):
def __init__(self):
self.rect = pygame.rect.Rect(0,0,100,100)
def __setattr__(self, name, valu... | 2 | 2009-03-24T10:34:25Z | 676,843 | <p>You could try <code>__getattr__</code>, which should be called on <code>Firstclass.rect</code>.</p>
<p>But do this instead: Create a separate class (subclass of <code>pygame.rect</code>?) for <code>ExampleClass.rect</code>. Implement <code>__setattr__</code> in that class. Now you will be told about anything that g... | 1 | 2009-03-24T10:39:20Z | [
"python",
"class",
"attributes",
"subclass",
"pygame"
] |
Intercepting changes of attributes in classes within a class - Python | 676,826 | <p>I have been messing around with pygame and python and I want to be able to call a function when an attribute of my class has changed. My current solution being:</p>
<pre><code>class ExampleClass(parentClass):
def __init__(self):
self.rect = pygame.rect.Rect(0,0,100,100)
def __setattr__(self, name, valu... | 2 | 2009-03-24T10:34:25Z | 676,872 | <p>Well, the simple answer is you can't. In the case of <code>Firstclass.rect = <...></code> your <code>__setattr__</code> is called. But in the case of <code>Firstclass.rect.bottom = 3</code> the <code>__setattr__</code> method of the Rect instance is called. The only solution I see, is to create a derived class... | 4 | 2009-03-24T10:46:29Z | [
"python",
"class",
"attributes",
"subclass",
"pygame"
] |
Intercepting changes of attributes in classes within a class - Python | 676,826 | <p>I have been messing around with pygame and python and I want to be able to call a function when an attribute of my class has changed. My current solution being:</p>
<pre><code>class ExampleClass(parentClass):
def __init__(self):
self.rect = pygame.rect.Rect(0,0,100,100)
def __setattr__(self, name, valu... | 2 | 2009-03-24T10:34:25Z | 1,112,632 | <p>I think the reason why you have this difficulty deserves a little more information than is provided by the other answers.</p>
<p>The problem is, when you do:</p>
<pre><code>myObject.attribute.thing = value
</code></pre>
<p>You're not assigning a value to attribute. The code is equivalent to this:</p>
<pre><code>... | 0 | 2009-07-11T01:07:07Z | [
"python",
"class",
"attributes",
"subclass",
"pygame"
] |
Intercepting changes of attributes in classes within a class - Python | 676,826 | <p>I have been messing around with pygame and python and I want to be able to call a function when an attribute of my class has changed. My current solution being:</p>
<pre><code>class ExampleClass(parentClass):
def __init__(self):
self.rect = pygame.rect.Rect(0,0,100,100)
def __setattr__(self, name, valu... | 2 | 2009-03-24T10:34:25Z | 15,865,081 | <p>This isn't answering the question but it is relevant:</p>
<pre><code>self.__dict__[name] = value
</code></pre>
<p>is probably better than </p>
<pre><code>parentClass.__setattr__(self, name, value)
</code></pre>
<p>This is recommended by the Python documentation (setattr">http://docs.python.org/2/reference/datamo... | 1 | 2013-04-07T16:56:26Z | [
"python",
"class",
"attributes",
"subclass",
"pygame"
] |
How do I notify a process of an SQLite database change done in a different process? | 677,028 | <p>Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. </p>
<p>The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database.</p>
<p>An "editor"... | 8 | 2009-03-24T11:34:34Z | 677,042 | <p>Just open a socket between the two processes and have the editor tell all the players about the update.</p>
| 2 | 2009-03-24T11:40:26Z | [
"python",
"sqlite",
"notifications"
] |
How do I notify a process of an SQLite database change done in a different process? | 677,028 | <p>Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. </p>
<p>The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database.</p>
<p>An "editor"... | 8 | 2009-03-24T11:34:34Z | 677,066 | <p><strong>Edit:</strong> I am asuming processes on the same machine.</p>
<p>In my opinion there are two ways:</p>
<ul>
<li><p>Polling (as you mentioned), but keep it to a single value (like a table that just keeps the LastUpdateTime of other tables)</p></li>
<li><p>Use whichever interprocess-communication there is a... | 1 | 2009-03-24T11:49:30Z | [
"python",
"sqlite",
"notifications"
] |
How do I notify a process of an SQLite database change done in a different process? | 677,028 | <p>Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. </p>
<p>The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database.</p>
<p>An "editor"... | 8 | 2009-03-24T11:34:34Z | 677,085 | <p>A relational database is not your best first choice for this.</p>
<p>Why?</p>
<p>You want all of your editors to pass changes to your player. </p>
<p>Your player is -- effectively -- a server for all those editors. Your player needs multiple open connections. It must listen to all those connections for changes... | 5 | 2009-03-24T11:55:22Z | [
"python",
"sqlite",
"notifications"
] |
How do I notify a process of an SQLite database change done in a different process? | 677,028 | <p>Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. </p>
<p>The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database.</p>
<p>An "editor"... | 8 | 2009-03-24T11:34:34Z | 677,087 | <p>If it's on the same machine, the simplest way would be to have named pipe, "player" with blocking read() and "editors" putting a token in pipe whenever they modify DB.</p>
| 1 | 2009-03-24T11:56:09Z | [
"python",
"sqlite",
"notifications"
] |
How do I notify a process of an SQLite database change done in a different process? | 677,028 | <p>Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. </p>
<p>The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database.</p>
<p>An "editor"... | 8 | 2009-03-24T11:34:34Z | 677,169 | <p>How many editor processes (why processes?), and how often do you expect updates? This doesn't sound like a good design, especially not considering sqlite really isn't <b>too</b> happy about multiple concurrent accesses to the database.</p>
<p><i>If</i> multiple processes makes sense <b>and</b> you want persistence,... | 1 | 2009-03-24T12:30:20Z | [
"python",
"sqlite",
"notifications"
] |
How do I notify a process of an SQLite database change done in a different process? | 677,028 | <p>Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. </p>
<p>The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database.</p>
<p>An "editor"... | 8 | 2009-03-24T11:34:34Z | 677,215 | <p>I think in that case, I would make a process to manage the database read/writes.</p>
<p>Each editor that want to make some modifications to the database makes a call to this proccess, be it through IPC or network, or whatever method.</p>
<p>This process can then notify the player of a change in the database. The p... | 2 | 2009-03-24T12:45:44Z | [
"python",
"sqlite",
"notifications"
] |
How do I notify a process of an SQLite database change done in a different process? | 677,028 | <p>Let's say I have two or more processes dealing with an SQLite database - a "player" process and many "editor" processes. </p>
<p>The "player" process reads the database and updates a view - in my case it would be a waveform being mixed to the soundcard depending on events stored in the database.</p>
<p>An "editor"... | 8 | 2009-03-24T11:34:34Z | 22,390,871 | <p>SQLite has an <a href="https://www.sqlite.org/c3ref/update_hook.html" rel="nofollow"><code>update_hook</code></a> function which does what you want. Unfortunately it isn't exposed by the Python sqlite module...</p>
<p>Here is a slightly hacky workaround that digs into the C api (from Python code) to make use of it:... | 2 | 2014-03-13T21:03:29Z | [
"python",
"sqlite",
"notifications"
] |
verbose_name_plural unexpected in a model? | 677,172 | <p>I've been doing some models of a future app, and, after adding verbose_name and verbose_name_plural to every entry on a working model, for making it 'beautiful', I've found that at validate time, Django doesn't like that, so it says:</p>
<pre><code> File "/home/andor/Documentos/desarrollo/grundymanage/../grundyman... | 2 | 2009-03-24T12:31:09Z | 677,198 | <p>There is no <code>verbose_name_plural</code>. It does not make sense to have both singular and plural for one field. They are mutually exclusive. In Django, they share the same name: <code>verbose_name</code>.</p>
<p>If your data represents multiple items (e.g. in a one-to-many relationship) use a plural form in... | 5 | 2009-03-24T12:39:49Z | [
"python",
"django",
"django-models"
] |
verbose_name_plural unexpected in a model? | 677,172 | <p>I've been doing some models of a future app, and, after adding verbose_name and verbose_name_plural to every entry on a working model, for making it 'beautiful', I've found that at validate time, Django doesn't like that, so it says:</p>
<pre><code> File "/home/andor/Documentos/desarrollo/grundymanage/../grundyman... | 2 | 2009-03-24T12:31:09Z | 677,199 | <p>Unfortunately, <code>verbose_name_plural</code> is not an option on the field. It's a meta option for the model itself. A field has no plural name since, unless it's a many-to-many relationship (in which case Django will use the plural for the model pointed to by the relationship), there's only one entity in that fi... | 4 | 2009-03-24T12:39:52Z | [
"python",
"django",
"django-models"
] |
condition coverage in python | 677,219 | <p>Is there any tool/library that calculate percent of "condition/decision coverage" of python code. I found only coverage.py but it calculates only percent of "statement coverage".</p>
| 17 | 2009-03-24T12:47:09Z | 677,407 | <p>Are you looking for <a href="http://en.wikipedia.org/wiki/Cyclomatic%5Fcomplexity" rel="nofollow">cyclomatic complexity (Wikipedia)</a>? It basically computes the number of paths through a piece of code. There are some projects to compute that for Python code, for example <a href="http://sourceforge.net/projects/pym... | 2 | 2009-03-24T13:31:46Z | [
"python",
"unit-testing",
"code-coverage"
] |
condition coverage in python | 677,219 | <p>Is there any tool/library that calculate percent of "condition/decision coverage" of python code. I found only coverage.py but it calculates only percent of "statement coverage".</p>
| 17 | 2009-03-24T12:47:09Z | 679,530 | <p>I don't know of any branch coverage tools for Python, though I've contemplated writing one. My thought was to start with the AST and insert additional instrumentation for each branch point. It's doable, but there are some tricky cases.</p>
<p>For example,</p>
<pre><code>raise SomeException(x)
</code></pre>
<p>Br... | 2 | 2009-03-24T22:37:42Z | [
"python",
"unit-testing",
"code-coverage"
] |
condition coverage in python | 677,219 | <p>Is there any tool/library that calculate percent of "condition/decision coverage" of python code. I found only coverage.py but it calculates only percent of "statement coverage".</p>
| 17 | 2009-03-24T12:47:09Z | 680,042 | <p>The very same maintainer of coverage.py has an article discussing a way to <a href="http://nedbatchelder.com/blog/200804/wicked%5Fhack%5Fpython%5Fbytecode%5Ftracing.html" rel="nofollow">get coverage information at the bytecode level</a>. The method is a bit kludgey: it involves re-assembling .pyc files with tweaked ... | 1 | 2009-03-25T02:44:51Z | [
"python",
"unit-testing",
"code-coverage"
] |
condition coverage in python | 677,219 | <p>Is there any tool/library that calculate percent of "condition/decision coverage" of python code. I found only coverage.py but it calculates only percent of "statement coverage".</p>
| 17 | 2009-03-24T12:47:09Z | 683,736 | <p>I haven't used it myself, but if you are willing to replace coverage analysis with <a href="http://en.wikipedia.org/wiki/Mutation%5Ftesting" rel="nofollow" title="mutation testing">mutation testing</a>, I've heard of a mutation tester called "pester".</p>
<p>While I was doing googling, I also came across <a href="h... | 1 | 2009-03-25T22:18:15Z | [
"python",
"unit-testing",
"code-coverage"
] |
condition coverage in python | 677,219 | <p>Is there any tool/library that calculate percent of "condition/decision coverage" of python code. I found only coverage.py but it calculates only percent of "statement coverage".</p>
| 17 | 2009-03-24T12:47:09Z | 1,114,731 | <p>Parse and modify the AST is the right answer, IMHO. See this paper
for a complete description of what you need to do:
"Branch Coverage Made Easy for Arbitrary Languages"</p>
<p><a href="http://www.semanticdesigns.com/Company/Publications/TestCoverage.pdf" rel="nofollow">http://www.semanticdesigns.com/Company/Publi... | 0 | 2009-07-11T21:52:08Z | [
"python",
"unit-testing",
"code-coverage"
] |
condition coverage in python | 677,219 | <p>Is there any tool/library that calculate percent of "condition/decision coverage" of python code. I found only coverage.py but it calculates only percent of "statement coverage".</p>
| 17 | 2009-03-24T12:47:09Z | 1,714,970 | <p><a href="http://nedbatchelder.com/code/coverage/branch.html" rel="nofollow">Coverage.py now includes branch coverage</a>. </p>
<p>For the curious: the code is not modified before running. The trace function tracks which lines follow which in the execution, and compare that information with static analysis of the ... | 7 | 2009-11-11T12:44:20Z | [
"python",
"unit-testing",
"code-coverage"
] |
condition coverage in python | 677,219 | <p>Is there any tool/library that calculate percent of "condition/decision coverage" of python code. I found only coverage.py but it calculates only percent of "statement coverage".</p>
| 17 | 2009-03-24T12:47:09Z | 37,492,466 | <p>It looks like "instrumental" implements condition coverage:</p>
<p><a href="https://pypi.python.org/pypi/instrumental" rel="nofollow">Instrumental on Pypi</a></p>
<p><a href="https://lautaportti.wordpress.com/2011/05/07/test-coverage-analysis/" rel="nofollow">Link about coverage.py and instrumental</a></p>
<p>Has... | 0 | 2016-05-27T21:26:29Z | [
"python",
"unit-testing",
"code-coverage"
] |
Python SVN bindings for Windows | 677,252 | <p>Where can I find precompiled Python SWIG SVN bindings for Windows?</p>
| 18 | 2009-03-24T12:58:01Z | 677,345 | <p>The (old) <a href="http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=8100" rel="nofollow">Windows binaries</a> page at tigris.org contains an installer for <em>python bindings for SVN</em>. View the source for the SWIG bindings at <a href="http://svn.apache.org/viewvc/subversion/trunk/subversion/bin... | 45 | 2009-03-24T13:18:35Z | [
"python",
"windows",
"svn",
"swig",
"precompiled"
] |
Python SVN bindings for Windows | 677,252 | <p>Where can I find precompiled Python SWIG SVN bindings for Windows?</p>
| 18 | 2009-03-24T12:58:01Z | 4,848,786 | <p>You can find working bindings in the Trac project:</p>
<p><a href="http://trac.edgewall.org/wiki/TracSubversion" rel="nofollow">http://trac.edgewall.org/wiki/TracSubversion</a></p>
<p>See the attachment:</p>
<p>svn-win32-1.6.15_py_2.7.zip</p>
| 1 | 2011-01-31T08:10:41Z | [
"python",
"windows",
"svn",
"swig",
"precompiled"
] |
What's the best online tutorial for starting with Spring Python | 677,255 | <p>Spring Python seems to be the gold-standard for how to define good quality APIs in Python - it's based on Spring which also seems to be the gold-standard for Java APIs. </p>
<p>My manager has complained (with good reason) that our APIs are in a mess - we need to impose some order on them. Since we will be re-factor... | 5 | 2009-03-24T12:58:23Z | 677,357 | <p>How did you come to decide on Spring Python as your API of choice? Spring works well on Java where there's a tradition of declarative programming; defining your application primarily using XML to control a core engine is a standard pattern in Java. </p>
<p>In Python, while the underlying patterns like Inversion of ... | 10 | 2009-03-24T13:19:51Z | [
"python",
"spring"
] |
What's the best online tutorial for starting with Spring Python | 677,255 | <p>Spring Python seems to be the gold-standard for how to define good quality APIs in Python - it's based on Spring which also seems to be the gold-standard for Java APIs. </p>
<p>My manager has complained (with good reason) that our APIs are in a mess - we need to impose some order on them. Since we will be re-factor... | 5 | 2009-03-24T12:58:23Z | 677,511 | <p>I won't go so far as to suggest that Spring Python is bad (because I don't know enough about it). But, to call Spring Python the "gold standard for Python APIs" is a stretch. To me, it seems that Spring Python is more of a way to allow Python apps to interact with Java Apps using Spring.</p>
<p>At any rate, after... | 1 | 2009-03-24T13:55:00Z | [
"python",
"spring"
] |
How to check if an RGB image contains only one color? | 677,395 | <p>I'm using Python and PIL.</p>
<p>I have images in RGB and I would like to know those who contain only one color (say #FF0000 for example) or a few very close colors (#FF0000 and #FF0001).</p>
<p>I was thinking about using the histogram but it is very hard to figure out something with the 3 color bands, so I'm look... | 2 | 2009-03-24T13:28:34Z | 677,454 | <p>First, you should define a distance between two colors.
Then you just have to verify for each pixel that it's distance to your color is small enough.</p>
| 0 | 2009-03-24T13:41:58Z | [
"python",
"image",
"colors",
"python-imaging-library"
] |
How to check if an RGB image contains only one color? | 677,395 | <p>I'm using Python and PIL.</p>
<p>I have images in RGB and I would like to know those who contain only one color (say #FF0000 for example) or a few very close colors (#FF0000 and #FF0001).</p>
<p>I was thinking about using the histogram but it is very hard to figure out something with the 3 color bands, so I'm look... | 2 | 2009-03-24T13:28:34Z | 677,545 | <p>Try the <a href="http://www.pythonware.com/library/pil/handbook/imagestat.htm" rel="nofollow">ImageStat module</a>. If the values returned by <code>extrema</code> are the same, you have only a single color in the image.</p>
| 3 | 2009-03-24T14:03:28Z | [
"python",
"image",
"colors",
"python-imaging-library"
] |
How to check if an RGB image contains only one color? | 677,395 | <p>I'm using Python and PIL.</p>
<p>I have images in RGB and I would like to know those who contain only one color (say #FF0000 for example) or a few very close colors (#FF0000 and #FF0001).</p>
<p>I was thinking about using the histogram but it is very hard to figure out something with the 3 color bands, so I'm look... | 2 | 2009-03-24T13:28:34Z | 677,567 | <p>Here's a little snippet you could make use of :</p>
<pre><code>
import Image
im = Image.open("path_to_image")
width,height = im.size
for w in range(0,width):
for h in range(0,height):
# this will hold the value of all the channels
color_tuple = im.getpixel((w,h))
# do something with the colors he... | 0 | 2009-03-24T14:09:00Z | [
"python",
"image",
"colors",
"python-imaging-library"
] |
Using 'old' database with django | 677,476 | <p>I'm using a hand built (Postgres) database with Django. With "inspectdb" I was able to automatically create a model for it. The problem is that some tables have multiple primary keys (for many-to-many relations) and they are not accessible via Django. </p>
<p>What's the best way to access these tables?</p>
| 6 | 2009-03-24T13:48:33Z | 677,549 | <p>There is no way to use composite primary keys in Django's ORM as of now (up to v1.0.2).</p>
<p>I can only think of three solutions/workarounds:</p>
<ol>
<li>There is a <a href="http://github.com/dcramer/django-compositepks/tree/master" rel="nofollow">fork</a> of django with a composite pk patch at github that you ... | 4 | 2009-03-24T14:05:13Z | [
"python",
"django"
] |
Using 'old' database with django | 677,476 | <p>I'm using a hand built (Postgres) database with Django. With "inspectdb" I was able to automatically create a model for it. The problem is that some tables have multiple primary keys (for many-to-many relations) and they are not accessible via Django. </p>
<p>What's the best way to access these tables?</p>
| 6 | 2009-03-24T13:48:33Z | 677,798 | <p>Django does have support for <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#many-to-many-relationships" rel="nofollow">many-to-many relationships</a>. If you want to use a helper table to manage this relationships, the ManyToManyField takes a through argument which specifies the table to use. You ... | 0 | 2009-03-24T15:01:35Z | [
"python",
"django"
] |
distutils: How to pass a user defined parameter to setup.py? | 677,577 | <p>Please prompt me how to pass a user-defined parameter both from the command line and setup.cfg configuration file to distutils' setup.py script. I want to write a setup.py script, which accepts my package specific parameters. For example:</p>
<pre><code>python setup.py install -foo myfoo
</code></pre>
<p>Thank you... | 34 | 2009-03-24T14:12:04Z | 680,473 | <p>You can't really pass custom parameters to the script. However the following things are possible and could solve your problem:</p>
<ul>
<li>optional features can be enabled using <code>--with-featurename</code>, standard features can be disabled using <code>--without-featurename</code>. [AFAIR this requires setupt... | 8 | 2009-03-25T06:48:40Z | [
"python",
"distutils"
] |
distutils: How to pass a user defined parameter to setup.py? | 677,577 | <p>Please prompt me how to pass a user-defined parameter both from the command line and setup.cfg configuration file to distutils' setup.py script. I want to write a setup.py script, which accepts my package specific parameters. For example:</p>
<pre><code>python setup.py install -foo myfoo
</code></pre>
<p>Thank you... | 34 | 2009-03-24T14:12:04Z | 4,792,601 | <p>Here is a very simple solution, all you have to do is filter out <code>sys.argv</code> and handle it yourself before you call to distutils <code>setup(..)</code>.
Something like this:</p>
<pre><code>if "--foo" in sys.argv:
do_foo_stuff()
sys.argv.remove("--foo")
...
setup(..)
</code></pre>
<p>The documenta... | 14 | 2011-01-25T10:54:17Z | [
"python",
"distutils"
] |
distutils: How to pass a user defined parameter to setup.py? | 677,577 | <p>Please prompt me how to pass a user-defined parameter both from the command line and setup.cfg configuration file to distutils' setup.py script. I want to write a setup.py script, which accepts my package specific parameters. For example:</p>
<pre><code>python setup.py install -foo myfoo
</code></pre>
<p>Thank you... | 34 | 2009-03-24T14:12:04Z | 18,940,379 | <p>A quick and easy way similar to that given by totaam would be to use argparse to grab the -foo argument and leave the remaining arguments for the call to distutils.setup(). Using argparse for this would be better than iterating through sys.argv manually imho. For instance, add this at the beginning of your setup.p... | -2 | 2013-09-22T04:39:08Z | [
"python",
"distutils"
] |
distutils: How to pass a user defined parameter to setup.py? | 677,577 | <p>Please prompt me how to pass a user-defined parameter both from the command line and setup.cfg configuration file to distutils' setup.py script. I want to write a setup.py script, which accepts my package specific parameters. For example:</p>
<pre><code>python setup.py install -foo myfoo
</code></pre>
<p>Thank you... | 34 | 2009-03-24T14:12:04Z | 20,248,942 | <p>As Setuptools/Distuils are horribly documented, I had problems finding the answer to this myself. But eventually I stumbled across <a href="http://marc.merlins.org/linux/talks/SvnScalingGvn/svn-tree/gvn-release/setup.py">this</a> example. Also, <a href="http://stackoverflow.com/questions/1710839/custom-distutils-com... | 29 | 2013-11-27T17:17:29Z | [
"python",
"distutils"
] |
distutils: How to pass a user defined parameter to setup.py? | 677,577 | <p>Please prompt me how to pass a user-defined parameter both from the command line and setup.cfg configuration file to distutils' setup.py script. I want to write a setup.py script, which accepts my package specific parameters. For example:</p>
<pre><code>python setup.py install -foo myfoo
</code></pre>
<p>Thank you... | 34 | 2009-03-24T14:12:04Z | 28,329,763 | <p>I successfully used a workaround to use a solution similar to totaam's suggestion. I ended up popping my extra arguments from the sys.argv list:</p>
<pre><code>import sys
from distutils.core import setup
foo = 0
if '--foo' in sys.argv:
index = sys.argv.index('--foo')
sys.argv.pop(index) # Removes the '--fo... | 2 | 2015-02-04T19:29:01Z | [
"python",
"distutils"
] |
distutils: How to pass a user defined parameter to setup.py? | 677,577 | <p>Please prompt me how to pass a user-defined parameter both from the command line and setup.cfg configuration file to distutils' setup.py script. I want to write a setup.py script, which accepts my package specific parameters. For example:</p>
<pre><code>python setup.py install -foo myfoo
</code></pre>
<p>Thank you... | 34 | 2009-03-24T14:12:04Z | 33,181,352 | <p>Yes, it's 2015 and the documentation for adding commands and options in both <code>setuptools</code> and <code>distutils</code> is still largely missing.</p>
<p>After a few frustrating hours I figured out the following code for adding a custom option to the <code>install</code> command of <code>setup.py</code>:</p>... | 2 | 2015-10-17T00:21:10Z | [
"python",
"distutils"
] |
distutils: How to pass a user defined parameter to setup.py? | 677,577 | <p>Please prompt me how to pass a user-defined parameter both from the command line and setup.cfg configuration file to distutils' setup.py script. I want to write a setup.py script, which accepts my package specific parameters. For example:</p>
<pre><code>python setup.py install -foo myfoo
</code></pre>
<p>Thank you... | 34 | 2009-03-24T14:12:04Z | 36,489,371 | <p>Perhaps you are an unseasoned programmer like me that still struggled after reading all the answers above. Thus, you might find another example potentially helpful (<strong>and to address the comments in previous answers about entering the command line arguments</strong>):</p>
<pre><code>class RunClientCommand(Comm... | 2 | 2016-04-08T00:11:34Z | [
"python",
"distutils"
] |
wxPython: Making a scrollable DC | 677,590 | <p>I am drawing inside a wx.Window using a PaintDC. I am drawing circles and stuff like that into that window. Problem is, sometimes the circles go outside the scope of the window. I want a scrollbar to automatically appear whenever the drawing gets too big. What do I do?</p>
| 1 | 2009-03-24T14:15:29Z | 680,574 | <p>Use a <code>wx.ScrolledWindow</code> and set the size of the window as soon as your 'drawing go outside' the window with</p>
<pre><code>SetVirtualSize(width,height)
</code></pre>
<p>If this size is bigger than the client size, then wx will show scrollbars. When drawing in the window make sure to use <code>CalcUnsc... | 1 | 2009-03-25T07:36:46Z | [
"python",
"wxpython",
"scroll",
"scrollbar"
] |
How can I record live video with gstreamer without dropping frames? | 677,641 | <p>I'm trying to use gstreamer 0.10 from Python to simultaneously display a v4l2 video source and record it to xvid-in-avi. Over a long period of time the computer would be fast enough to do this but if another program uses the disk it drops frames. That's bad enough, but on playback there are bursts of movement in the... | 4 | 2009-03-24T14:28:02Z | 677,681 | <p><code>tee</code> will block if either output blocks, so it's probably your bottleneck. I suggest to write the stream that takes longer to encode to disk and encode from there.</p>
| 5 | 2009-03-24T14:35:41Z | [
"python",
"linux",
"gstreamer"
] |
How can I record live video with gstreamer without dropping frames? | 677,641 | <p>I'm trying to use gstreamer 0.10 from Python to simultaneously display a v4l2 video source and record it to xvid-in-avi. Over a long period of time the computer would be fast enough to do this but if another program uses the disk it drops frames. That's bad enough, but on playback there are bursts of movement in the... | 4 | 2009-03-24T14:28:02Z | 2,237,878 | <p>and you need to write xvimagesink, not xvimagesync</p>
| 1 | 2010-02-10T15:20:28Z | [
"python",
"linux",
"gstreamer"
] |
How to extract from a list of objects a list of specific attribute? | 677,656 | <p>I have a list of objects. Object has 3 string attributes. I want to make a list containing only a specific attribute from class.</p>
<p>Is there any built-in functions to do that?</p>
| 7 | 2009-03-24T14:31:43Z | 677,663 | <p>Assuming you want field <code>b</code> for the objects in a list named <code>objects</code> do this: </p>
<pre><code>[o.b for o in objects]
</code></pre>
| 0 | 2009-03-24T14:33:14Z | [
"python"
] |
How to extract from a list of objects a list of specific attribute? | 677,656 | <p>I have a list of objects. Object has 3 string attributes. I want to make a list containing only a specific attribute from class.</p>
<p>Is there any built-in functions to do that?</p>
| 7 | 2009-03-24T14:31:43Z | 677,669 | <p>The first thing that came to my mind:</p>
<pre><code>attrList = map(lambda x: x.attr, objectList)
</code></pre>
| 2 | 2009-03-24T14:34:06Z | [
"python"
] |
How to extract from a list of objects a list of specific attribute? | 677,656 | <p>I have a list of objects. Object has 3 string attributes. I want to make a list containing only a specific attribute from class.</p>
<p>Is there any built-in functions to do that?</p>
| 7 | 2009-03-24T14:31:43Z | 677,679 | <p>are you looking for something like this?</p>
<pre><code>[o.specific_attr for o in objects]
</code></pre>
| 5 | 2009-03-24T14:35:30Z | [
"python"
] |
How to extract from a list of objects a list of specific attribute? | 677,656 | <p>I have a list of objects. Object has 3 string attributes. I want to make a list containing only a specific attribute from class.</p>
<p>Is there any built-in functions to do that?</p>
| 7 | 2009-03-24T14:31:43Z | 677,685 | <p>A list comprehension would work just fine:</p>
<pre><code>[o.my_attr for o in my_list]
</code></pre>
<p>But there is a combination of built-in functions, since you ask :-)</p>
<pre><code>from operator import attrgetter
map(attrgetter('my_attr'), my_list)
</code></pre>
| 14 | 2009-03-24T14:36:50Z | [
"python"
] |
Specifying different template names in Django generic views | 677,793 | <p>I have the code in my urls.py for my generic views;</p>
<pre><code>infodict = {
'queryset': Post.objects.all(),
'date_field': 'date',
'template_name': 'index.html',
'template_object_name': 'latest_post_list',
}
urlpatterns += patterns('django.views.generic.date_based',
(r'^gindex/$', 'archive_index', infodict),
)
... | 2 | 2009-03-24T15:00:49Z | 677,853 | <p>If you want to supply different template names to different views, the common practice is indeed to pass in a unique dictionary to each URL pattern. For example:</p>
<pre><code>urlpatterns = patterns('',
url(r'^home/$', 'my.views.home', {'template_name': 'home.html'}, name='home'),
url(r'^about/$', 'my.vie... | 1 | 2009-03-24T15:15:01Z | [
"python",
"django",
"django-urls"
] |
Specifying different template names in Django generic views | 677,793 | <p>I have the code in my urls.py for my generic views;</p>
<pre><code>infodict = {
'queryset': Post.objects.all(),
'date_field': 'date',
'template_name': 'index.html',
'template_object_name': 'latest_post_list',
}
urlpatterns += patterns('django.views.generic.date_based',
(r'^gindex/$', 'archive_index', infodict),
)
... | 2 | 2009-03-24T15:00:49Z | 677,941 | <p>Not as simple, but possibly useful if you have a whole lot of different patterns matching the same view:</p>
<pre><code>base_dict={
...
#defaults go here
}
def make_dict(template_name,template_object_name):
base_dict.update({
'template_name':template_name,
'template_object_name':template_object_... | 0 | 2009-03-24T15:31:53Z | [
"python",
"django",
"django-urls"
] |
Specifying different template names in Django generic views | 677,793 | <p>I have the code in my urls.py for my generic views;</p>
<pre><code>infodict = {
'queryset': Post.objects.all(),
'date_field': 'date',
'template_name': 'index.html',
'template_object_name': 'latest_post_list',
}
urlpatterns += patterns('django.views.generic.date_based',
(r'^gindex/$', 'archive_index', infodict),
)
... | 2 | 2009-03-24T15:00:49Z | 678,027 | <p>you can define wrapper view functions to parametrize generic views.
In your urls.py add pattern</p>
<pre><code>url(r'^/(?P<tmpl_name>\w+)/$', 'my.views.datebasedproxy')
</code></pre>
<p>in your views.py add view function</p>
<pre><code>def datebasedproxy(request, tmpl_name):
return django.views.generic.... | 0 | 2009-03-24T15:48:03Z | [
"python",
"django",
"django-urls"
] |
Specifying different template names in Django generic views | 677,793 | <p>I have the code in my urls.py for my generic views;</p>
<pre><code>infodict = {
'queryset': Post.objects.all(),
'date_field': 'date',
'template_name': 'index.html',
'template_object_name': 'latest_post_list',
}
urlpatterns += patterns('django.views.generic.date_based',
(r'^gindex/$', 'archive_index', infodict),
)
... | 2 | 2009-03-24T15:00:49Z | 678,441 | <p>Use the dict() constructor:</p>
<pre><code>infodict = {
'queryset': Post.objects.all(),
'date_field': 'date',
'template_name': 'index.html',
'template_object_name': 'latest_post_list',
}
urlpatterns = patterns('django.views.generic.date_based',
url(r'^gindex/$', 'archive_index', dict(infodict, ... | 8 | 2009-03-24T17:35:51Z | [
"python",
"django",
"django-urls"
] |
Python and MySQL: is there an alternative to MySQLdb? | 677,811 | <p>Is there a module written purely in Python that will allow a script to communicate with a MySQL database? I've already tried MySQLdb without success. It requires too much: GCC, zlib, and openssl. I do not have access to these tools; even if I did, I don't want to waste time getting them to work together. I'm looking... | 13 | 2009-03-24T15:04:09Z | 677,841 | <p>Without a doubt MySQLdb is the best solution, but if you can't use itâ¦</p>
<p>If you have <code>libmysqlclient</code>.[<code>so</code>|<code>dll</code>], you could access it directly using <a href="http://docs.python.org/library/ctypes.html" rel="nofollow">ctypes</a> module. </p>
| 1 | 2009-03-24T15:11:47Z | [
"python",
"mysql",
"database"
] |
Python and MySQL: is there an alternative to MySQLdb? | 677,811 | <p>Is there a module written purely in Python that will allow a script to communicate with a MySQL database? I've already tried MySQLdb without success. It requires too much: GCC, zlib, and openssl. I do not have access to these tools; even if I did, I don't want to waste time getting them to work together. I'm looking... | 13 | 2009-03-24T15:04:09Z | 677,844 | <p>As far as I know there is no direct alternative. The only thing I can think of is to use ODBC instead, via <a href="http://pyodbc.sourceforge.net/" rel="nofollow">pyodbc</a>. The MySQL site has an ODBC connector you can <a href="http://dev.mysql.com/downloads/connector/odbc/5.1.html" rel="nofollow">download</a>. ... | 0 | 2009-03-24T15:12:02Z | [
"python",
"mysql",
"database"
] |
Python and MySQL: is there an alternative to MySQLdb? | 677,811 | <p>Is there a module written purely in Python that will allow a script to communicate with a MySQL database? I've already tried MySQLdb without success. It requires too much: GCC, zlib, and openssl. I do not have access to these tools; even if I did, I don't want to waste time getting them to work together. I'm looking... | 13 | 2009-03-24T15:04:09Z | 677,870 | <p>You can find pre-built binary packages for MySQLdb and its dependencies for most operating systems.</p>
<p><a href="http://sourceforge.net/project/showfiles.php?group_id=22307&package_id=15775" rel="nofollow">http://sourceforge.net/project/showfiles.php?group_id=22307&package_id=15775</a></p>
<p>What platf... | 2 | 2009-03-24T15:19:39Z | [
"python",
"mysql",
"database"
] |
Python and MySQL: is there an alternative to MySQLdb? | 677,811 | <p>Is there a module written purely in Python that will allow a script to communicate with a MySQL database? I've already tried MySQLdb without success. It requires too much: GCC, zlib, and openssl. I do not have access to these tools; even if I did, I don't want to waste time getting them to work together. I'm looking... | 13 | 2009-03-24T15:04:09Z | 678,066 | <p>You've looked at these?</p>
<p><a href="http://wiki.python.org/moin/MySQL">http://wiki.python.org/moin/MySQL</a></p>
| 5 | 2009-03-24T15:57:04Z | [
"python",
"mysql",
"database"
] |
Python and MySQL: is there an alternative to MySQLdb? | 677,811 | <p>Is there a module written purely in Python that will allow a script to communicate with a MySQL database? I've already tried MySQLdb without success. It requires too much: GCC, zlib, and openssl. I do not have access to these tools; even if I did, I don't want to waste time getting them to work together. I'm looking... | 13 | 2009-03-24T15:04:09Z | 678,233 | <p>There's a project at Sun to implement 100% python mysql driver. </p>
<p><a href="https://launchpad.net/myconnpy" rel="nofollow">https://launchpad.net/myconnpy</a></p>
<p>I haven't found any code for it though. But according to a <a href="http://lucumr.pocoo.org/2009/1/8/the-sad-state-of-mysql-python#comment-864" r... | 4 | 2009-03-24T16:40:39Z | [
"python",
"mysql",
"database"
] |
Python and MySQL: is there an alternative to MySQLdb? | 677,811 | <p>Is there a module written purely in Python that will allow a script to communicate with a MySQL database? I've already tried MySQLdb without success. It requires too much: GCC, zlib, and openssl. I do not have access to these tools; even if I did, I don't want to waste time getting them to work together. I'm looking... | 13 | 2009-03-24T15:04:09Z | 1,821,657 | <p>Lately there is also <a href="http://pypi.python.org/pypi/oursql/" rel="nofollow">oursql</a> (<a href="http://packages.python.org/oursql/" rel="nofollow">docs</a>), which has various advantages over MySQLdb and other existing drivers -- listed at the top of the documentation.</p>
| 5 | 2009-11-30T18:50:18Z | [
"python",
"mysql",
"database"
] |
Python and MySQL: is there an alternative to MySQLdb? | 677,811 | <p>Is there a module written purely in Python that will allow a script to communicate with a MySQL database? I've already tried MySQLdb without success. It requires too much: GCC, zlib, and openssl. I do not have access to these tools; even if I did, I don't want to waste time getting them to work together. I'm looking... | 13 | 2009-03-24T15:04:09Z | 1,824,573 | <p>As mentioned in earlier answer, MySQL Connector/Python implements the MySQL Server/Client completely in Python. No compiling, just installing.</p>
<p>Here are the links:<br>
* <a href="https://launchpad.net/myconnpy" rel="nofollow">https://launchpad.net/myconnpy</a><br>
* code: <a href="https://code.launchpad.net/m... | 2 | 2009-12-01T07:34:11Z | [
"python",
"mysql",
"database"
] |
Python and MySQL: is there an alternative to MySQLdb? | 677,811 | <p>Is there a module written purely in Python that will allow a script to communicate with a MySQL database? I've already tried MySQLdb without success. It requires too much: GCC, zlib, and openssl. I do not have access to these tools; even if I did, I don't want to waste time getting them to work together. I'm looking... | 13 | 2009-03-24T15:04:09Z | 27,669,112 | <p>I had the problem that I wanted to write code which work for Python 2 and Python 3. I found <a href="http://www.pymysql.org/" rel="nofollow"><code>pymysql</code></a> to fit perfectly. I did not have to adjust code to switch from MySQLdb to pymysql</p>
<h2>Installation</h2>
<pre><code>$ pip install PyMySQL
</code><... | 1 | 2014-12-27T16:18:31Z | [
"python",
"mysql",
"database"
] |
python and symbian - keystroke capture | 677,846 | <p>I'm trying to write a simple prototyping appliaction in python to capture a users keystrokes while writing a text messages (SMS) to collect some stat info for use in a biometric application for Symbian based phones. I have never used python before and have had very little exposure to it. However, I did come across a... | 1 | 2009-03-24T15:13:03Z | 677,887 | <p>I think you are searching for the wrong thing here.</p>
<p>Key codes and keypress events will only capture up, down, etc. (actual buttons), as you already stated. The user can enter letters in multiple ways, which is all done through software (e.g. 22 is a 'b', or 228 might be 'cat' or 'bat') and there is no way to... | 1 | 2009-03-24T15:22:54Z | [
"python",
"symbian",
"pys60"
] |
Doctest for dynamically created objects | 677,931 | <p>What is the best way to test code like this (the one below obviously fails while object is created in different block every time):</p>
<pre><code>def get_session(db_name, verbose, test):
"""Returns current DB session from SQLAlchemy pool.
>>> get_session('Mmusc20090126', False, True)
<sqlalchemy.orm.se... | 3 | 2009-03-24T15:30:12Z | 678,050 | <p>I think you want to use ellipsis, like this:</p>
<pre><code>>>> get_session('Mmusc20090126', False, True) #doctest: +ELLIPSIS
<sqlalchemy.orm.session.Session object at 0x...>
</code></pre>
<p>See <a href="http://docs.python.org/library/doctest.html#doctest.ELLIPSIS" rel="nofollow">here</a> for more ... | 8 | 2009-03-24T15:53:03Z | [
"python",
"testing",
"sqlalchemy",
"doctest",
"docstring"
] |
Fill Django application with data using very large Python script | 677,962 | <p>I wrote a program that outputs a Python program that fills my <a href="http://en.wikipedia.org/wiki/Django_%28web_framework%29" rel="nofollow">Django</a> application with data. This program however is 23 MB large and my computer won't run it. Is there a solution for this?</p>
<p>Another possible solution to fill th... | 0 | 2009-03-24T15:36:39Z | 677,982 | <p>Your computer wouldn't run it because is a large program?</p>
<p>Maybe you should reference an external file, or files, with all the structure, and then dump it inside the database, instead of writing it inside your script/software...</p>
| 0 | 2009-03-24T15:40:32Z | [
"python",
"database",
"django",
"migration"
] |
Fill Django application with data using very large Python script | 677,962 | <p>I wrote a program that outputs a Python program that fills my <a href="http://en.wikipedia.org/wiki/Django_%28web_framework%29" rel="nofollow">Django</a> application with data. This program however is 23 MB large and my computer won't run it. Is there a solution for this?</p>
<p>Another possible solution to fill th... | 0 | 2009-03-24T15:36:39Z | 677,984 | <p>Put the data in a separate file (or files). Then write a small program that reads in the data and populates your database via Django. </p>
| 0 | 2009-03-24T15:41:01Z | [
"python",
"database",
"django",
"migration"
] |
Fill Django application with data using very large Python script | 677,962 | <p>I wrote a program that outputs a Python program that fills my <a href="http://en.wikipedia.org/wiki/Django_%28web_framework%29" rel="nofollow">Django</a> application with data. This program however is 23 MB large and my computer won't run it. Is there a solution for this?</p>
<p>Another possible solution to fill th... | 0 | 2009-03-24T15:36:39Z | 678,248 | <p>If I am reading your post correctly, you are reading from the old database and writing a "python program" based on that data. This seems to me to be the wrong way to do this.</p>
<p>My suggestion would be to create a malleable version of the old database (XML would work well for this) by reading the data from the ... | 0 | 2009-03-24T16:45:03Z | [
"python",
"database",
"django",
"migration"
] |
Fill Django application with data using very large Python script | 677,962 | <p>I wrote a program that outputs a Python program that fills my <a href="http://en.wikipedia.org/wiki/Django_%28web_framework%29" rel="nofollow">Django</a> application with data. This program however is 23 MB large and my computer won't run it. Is there a solution for this?</p>
<p>Another possible solution to fill th... | 0 | 2009-03-24T15:36:39Z | 678,632 | <p>In most cases, you can find a natural hierarchy to your objects. Sometimes there is some kind of "master" and all other objects have foreign key (FK) references to this master and to each other.</p>
<p>In this case, you can use an XML-like structure with each master object "containing" a lot of subsidiary objects.... | 1 | 2009-03-24T18:32:23Z | [
"python",
"database",
"django",
"migration"
] |
weakref list in python | 677,978 | <p>I'm in need of a list of weak references that deletes items when they die. Currently the only way I have of doing this is to keep flushing the list (removing dead references manually).</p>
<p>I'm aware there's a WeakKeyDictionary and a WeakValueDictionary, but I'm really after a WeakList, is there a way of doing th... | 15 | 2009-03-24T15:39:59Z | 678,336 | <p>You could implement it yourself, similarly to how you have done, but with a list subclass that calls flush() before attempting to access an item. </p>
<p>Obviously you don't want to do this on every access, but you can optimize this by setting a callback on the weak reference to mark the list dirty when something ... | 5 | 2009-03-24T17:08:36Z | [
"python",
"weak-references"
] |
weakref list in python | 677,978 | <p>I'm in need of a list of weak references that deletes items when they die. Currently the only way I have of doing this is to keep flushing the list (removing dead references manually).</p>
<p>I'm aware there's a WeakKeyDictionary and a WeakValueDictionary, but I'm really after a WeakList, is there a way of doing th... | 15 | 2009-03-24T15:39:59Z | 2,625,813 | <p>Why can't you just do it like this:</p>
<pre><code>import weakref
class WeakList(list):
def append(self, item):
list.append(self, weakref.ref(item, self.remove))
</code></pre>
<p>And then do similar for <code>__iadd__</code>, <code>extend</code> etc.
Works for me.</p>
| 1 | 2010-04-12T22:09:36Z | [
"python",
"weak-references"
] |
weakref list in python | 677,978 | <p>I'm in need of a list of weak references that deletes items when they die. Currently the only way I have of doing this is to keep flushing the list (removing dead references manually).</p>
<p>I'm aware there's a WeakKeyDictionary and a WeakValueDictionary, but I'm really after a WeakList, is there a way of doing th... | 15 | 2009-03-24T15:39:59Z | 6,272,503 | <p>You can use WeakSet from the very same weakref module (it's actually defined elsewhere by the way, but it's imported there).</p>
<pre><code>>>> from weakref import WeakSet
>>> s = WeakSet()
>>> class Obj(object): pass # can't weakref simple objects
>>> a = Obj()
>>> s.ad... | 2 | 2011-06-07T22:52:26Z | [
"python",
"weak-references"
] |
weakref list in python | 677,978 | <p>I'm in need of a list of weak references that deletes items when they die. Currently the only way I have of doing this is to keep flushing the list (removing dead references manually).</p>
<p>I'm aware there's a WeakKeyDictionary and a WeakValueDictionary, but I'm really after a WeakList, is there a way of doing th... | 15 | 2009-03-24T15:39:59Z | 7,958,838 | <p>How do you plan on using <code>B</code>? The only thing I ever do with the weakref list I built is iterate over it, so its implementation is simple:</p>
<pre><code>import weakref
class WeakRefList(object):
"weakref psuedo list"
def __init__(yo):
yo._items = list()
def __iter__(yo):
yo.... | 0 | 2011-10-31T19:43:32Z | [
"python",
"weak-references"
] |
weakref list in python | 677,978 | <p>I'm in need of a list of weak references that deletes items when they die. Currently the only way I have of doing this is to keep flushing the list (removing dead references manually).</p>
<p>I'm aware there's a WeakKeyDictionary and a WeakValueDictionary, but I'm really after a WeakList, is there a way of doing th... | 15 | 2009-03-24T15:39:59Z | 13,405,875 | <p>Use a callback function passed to second argument of a weakref.</p>
<p>This code should function:</p>
<pre><code>import weakref
class weakRefList(list):
def addReference(self, obj):
self._references.append(weakref.proxy(obj, self.remove))
</code></pre>
| 1 | 2012-11-15T20:44:50Z | [
"python",
"weak-references"
] |
weakref list in python | 677,978 | <p>I'm in need of a list of weak references that deletes items when they die. Currently the only way I have of doing this is to keep flushing the list (removing dead references manually).</p>
<p>I'm aware there's a WeakKeyDictionary and a WeakValueDictionary, but I'm really after a WeakList, is there a way of doing th... | 15 | 2009-03-24T15:39:59Z | 13,486,682 | <p>As I needed a weakref list like you, I've made one and publish it on pypi.</p>
<p>now you can do:</p>
<pre><code>pip install weakreflist
</code></pre>
<p>then:</p>
<pre><code>from weakreflist import WeakList
</code></pre>
| 3 | 2012-11-21T05:06:19Z | [
"python",
"weak-references"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 678,242 | <p>Getting the name of the file without the extension :</p>
<pre><code>import os
print(os.path.splitext("path_to_file")[0])
</code></pre>
<p>As for your import problem, you solve it this way :</p>
<pre><code>from os.path import basename
# now you can call it directly with basename
print(basename("/a/b/c.txt"))
</co... | 425 | 2009-03-24T16:43:15Z | [
"python",
"string",
"path"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 678,247 | <blockquote>
<p>But even when I import os, I am not able to call it path.basename. Is it possible to call it as directly as basename?</p>
</blockquote>
<p><code>import os</code>, and then use <code>os.path.basename</code></p>
<p><code>import</code>ing <code>os</code> doesn't mean you can use <code>os.foo</code> wit... | 7 | 2009-03-24T16:45:02Z | [
"python",
"string",
"path"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 678,266 | <p>Just roll it:</p>
<pre><code>>>> base=os.path.basename('/root/dir/sub/file.ext')
>>> base
'file.ext'
>>> os.path.splitext(base)
('file', '.ext')
>>> os.path.splitext(base)[0]
'file'
>>>
</code></pre>
| 143 | 2009-03-24T16:49:53Z | [
"python",
"string",
"path"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 1,228,618 | <pre><code>>>> print os.path.splitext(os.path.basename("hemanth.txt"))[0]
hemanth
</code></pre>
| 91 | 2009-08-04T16:44:50Z | [
"python",
"string",
"path"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 18,310,208 | <p>On Windows system I used drivername prefix as well, like:</p>
<pre><code>>>> s = 'c:\\temp\\akarmi.txt'
>>> print(os.path.splitext(s)[0])
c:\temp\akarmi
</code></pre>
<p>So because I do not need drive letter or directory name, I use:</p>
<pre><code>>>> print(os.path.splitext(os.path.bas... | 2 | 2013-08-19T09:12:48Z | [
"python",
"string",
"path"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 19,488,791 | <p>If you want to keep the path to the file and just remove the extension</p>
<pre><code>>>> file = '/root/dir/sub.exten/file.data.1.2.dat'
>>> print ('.').join(file.split('.')[:-1])
/root/dir/sub.exten/file.data.1.2
</code></pre>
| 9 | 2013-10-21T07:46:11Z | [
"python",
"string",
"path"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 22,291,806 | <p>If you know the exact file extension for example .txt
then you can use</p>
<blockquote>
<blockquote>
<blockquote>
<p>print fileName[0:-4]</p>
</blockquote>
</blockquote>
</blockquote>
| -5 | 2014-03-10T03:52:20Z | [
"python",
"string",
"path"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 27,873,728 | <p>We could do some simple <code>split</code> / <code>pop</code> magic as seen here (<a href="http://stackoverflow.com/a/424006/1250044">http://stackoverflow.com/a/424006/1250044</a>), to extract the filename (respecting the windows and POSIX differences).</p>
<pre><code>def getFileNameWithoutExtension(path):
return... | 1 | 2015-01-10T07:05:52Z | [
"python",
"string",
"path"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 30,507,881 | <pre><code>import os
path = "a/b/c/abc.txt"
print os.path.splitext(os.path.basename(path))[0]
</code></pre>
| 2 | 2015-05-28T13:24:52Z | [
"python",
"string",
"path"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 37,760,212 | <p>os.path.splitext() <strong>won't</strong> work if there are multiple dots in the extension.</p>
<p>For example, images.tar.gz</p>
<pre><code>>>> import os
>>> file_path = '/home/dc/images.tar.gz'
>>> file_name = os.path.basename(file_path)
>>> print os.path.splitext(file_name)[0... | 2 | 2016-06-11T05:17:08Z | [
"python",
"string",
"path"
] |
How to get the filename without the extension from a path in Python? | 678,236 | <p>How to get the filename without the extension from a path in Python?</p>
<p>I found out a method called <code>os.path.basename</code> to get the filename with extension. But even when I import os, I am not able to call it <code>path.basename</code>. Is it possible to call it as directly as basename?</p>
| 294 | 2009-03-24T16:41:03Z | 39,648,242 | <p>For convenience, a simple function wrapping the two methods from <a href="https://docs.python.org/3/library/os.path.html" rel="nofollow"><code>os.path</code></a> :</p>
<pre><code>def filename(path):
"""Return file name without extension from path.
See https://docs.python.org/3/library/os.path.html
"""
impo... | 0 | 2016-09-22T20:23:28Z | [
"python",
"string",
"path"
] |
Does any one know of an RTF report generator in Django? | 678,308 | <p>I know about the PDF report generator, but I need to use RTF instead.</p>
| 3 | 2009-03-24T17:00:38Z | 678,670 | <p>There is <a href="http://pypi.python.org/pypi/PyRTF/0.45" rel="nofollow">PyRTF</a> but it hasn't been updated in a while.</p>
<p>If that doesn't work and you are willing to do some hacking then I can also point you to the <a href="http://www.gramps-project.org/wiki/index.php?title=Main%5FPage" rel="nofollow">GRAMPS... | 3 | 2009-03-24T18:40:03Z | [
"python",
"django",
"report",
"rtf"
] |
Does any one know of an RTF report generator in Django? | 678,308 | <p>I know about the PDF report generator, but I need to use RTF instead.</p>
| 3 | 2009-03-24T17:00:38Z | 1,336,541 | <p><code>(can't comment yet so I post it as an answer)</code></p>
<p>There's a fork of PyRTF called <a href="http://code.google.com/p/pyrtf-ng/" rel="nofollow">pyrtf-ng</a>, it's maintained and has Unicode support.
Documentation doesn't exist from what I've seen, but api looks nice, and you can figure out a lot from t... | 2 | 2009-08-26T18:11:14Z | [
"python",
"django",
"report",
"rtf"
] |
Does any one know of an RTF report generator in Django? | 678,308 | <p>I know about the PDF report generator, but I need to use RTF instead.</p>
| 3 | 2009-03-24T17:00:38Z | 5,085,766 | <p><a href="http://www.windwardreports.com/" rel="nofollow">Windward Reports</a> has a very nice RTF generator. And you create the template in Word so very easy to use. (Disclaimer - I'm the CTO at Windward.) And yes the Java engine is callable from Python.</p>
| 0 | 2011-02-23T00:31:39Z | [
"python",
"django",
"report",
"rtf"
] |
soaplib with mod_wsgi/cherrypy | 678,409 | <p>I've followed the tutorials for setting up Apache with mod_wsgi to interface cherrypy and make a site running of it. This is my "myapp.wsgi", and opening <a href="http://localhost/" rel="nofollow">http://localhost/</a> works great. Opening <a href="http://localhost/ape/" rel="nofollow">http://localhost/ape/</a> actu... | 1 | 2009-03-24T17:28:40Z | 678,527 | <p>I just tested this myself by replacing the last line of your file with</p>
<pre><code>cherrypy.quickstart(Root(), "/")
</code></pre>
<p>and it worked just fine for me. I suggest trying this and seeing whether it works for you; if it does then you'll know that it's an issue relating to running it under Apache/mod_... | 1 | 2009-03-24T17:59:45Z | [
"python",
"soap",
"mod-wsgi",
"cherrypy"
] |
soaplib with mod_wsgi/cherrypy | 678,409 | <p>I've followed the tutorials for setting up Apache with mod_wsgi to interface cherrypy and make a site running of it. This is my "myapp.wsgi", and opening <a href="http://localhost/" rel="nofollow">http://localhost/</a> works great. Opening <a href="http://localhost/ape/" rel="nofollow">http://localhost/ape/</a> actu... | 1 | 2009-03-24T17:28:40Z | 688,069 | <p>Eli is right; it's not enough to just make an Application instance. You have to mount it on cherrypy.tree, which quickstart() does for you.</p>
| 1 | 2009-03-27T00:27:15Z | [
"python",
"soap",
"mod-wsgi",
"cherrypy"
] |
How can I add non-sequential numbers to a range? | 678,410 | <p>I am trying to iterate through the range(750, 765) and add the non-sequential numbers 769, 770, 774. If I try adding the numbers after the range function, it returns the range list, then the individual numbers:</p>
<pre><code>
>>> for x in range(750, 765), 769, 770, 774: print x
...
[750, 751, 752, 753, 754, 755, ... | 5 | 2009-03-24T17:28:44Z | 678,421 | <p>Use the built-in + operator to append your non-sequential numbers to the range.</p>
<pre><code>for x in range(750, 765) + [769, 770, 774]: print x
</code></pre>
| 21 | 2009-03-24T17:31:23Z | [
"python",
"range"
] |
How can I add non-sequential numbers to a range? | 678,410 | <p>I am trying to iterate through the range(750, 765) and add the non-sequential numbers 769, 770, 774. If I try adding the numbers after the range function, it returns the range list, then the individual numbers:</p>
<pre><code>
>>> for x in range(750, 765), 769, 770, 774: print x
...
[750, 751, 752, 753, 754, 755, ... | 5 | 2009-03-24T17:28:44Z | 678,423 | <p>are you looking for this:</p>
<pre><code>mylist = range(750, 765)
mylist.extend([769, 770, 774])
</code></pre>
| 2 | 2009-03-24T17:32:18Z | [
"python",
"range"
] |
How can I add non-sequential numbers to a range? | 678,410 | <p>I am trying to iterate through the range(750, 765) and add the non-sequential numbers 769, 770, 774. If I try adding the numbers after the range function, it returns the range list, then the individual numbers:</p>
<pre><code>
>>> for x in range(750, 765), 769, 770, 774: print x
...
[750, 751, 752, 753, 754, 755, ... | 5 | 2009-03-24T17:28:44Z | 678,429 | <p>There are two ways to do it.</p>
<pre><code>>>> for x in range(5, 7) + [8, 9]: print x
...
5
6
8
9
>>> import itertools
>>> for x in itertools.chain(xrange(5, 7), [8, 9]): print x
...
5
6
8
9
</code></pre>
<p><a href="http://docs.python.org/library/itertools.html#itertools.chain">itertoo... | 13 | 2009-03-24T17:33:50Z | [
"python",
"range"
] |
How can I add non-sequential numbers to a range? | 678,410 | <p>I am trying to iterate through the range(750, 765) and add the non-sequential numbers 769, 770, 774. If I try adding the numbers after the range function, it returns the range list, then the individual numbers:</p>
<pre><code>
>>> for x in range(750, 765), 769, 770, 774: print x
...
[750, 751, 752, 753, 754, 755, ... | 5 | 2009-03-24T17:28:44Z | 678,436 | <p>The other answers on this page will serve you well. Just a quick note that in Python3.0, <code>range</code> is an iterator (like xrange was in Python2.x... xrange is gone in 3.0). If you try to do this in Python 3.0, be sure to create a list from the range iterator before doing the addition:</p>
<pre><code>for x in... | 5 | 2009-03-24T17:34:51Z | [
"python",
"range"
] |
What payment processing frameworks, like ActiveMerchant, are available for other languages? | 678,525 | <p>Rails has frameworks such as <a href="http://www.activemerchant.org/" rel="nofollow">ActiveMerchant</a> and <a href="http://github.com/cainlevy/freemium/tree/master" rel="nofollow">Freemium</a> (which uses ActiveMerchant) to simplify dealing with payment processing. What other frameworks are there for other programm... | 6 | 2009-03-24T17:59:00Z | 678,542 | <p><strong>Edit</strong> For processing payments, there are several GetPaid modules available for Python.
Check out the <a href="http://pypi.python.org/pypi/getpaid.core/0.7.3" rel="nofollow">core package</a>, as well as <a href="http://pypi.python.org/pypi?%3Aaction=search&term=getpaid&submit=search" rel="nof... | 2 | 2009-03-24T18:04:01Z | [
"php",
"python",
"ruby-on-rails",
"programming-languages",
"activemerchant"
] |
Select Distinct Years and Months for Django Archive Page | 678,927 | <p>I want to make an archive_index page for my django site. However, the date-based generic views really aren't any help. I want the dictionary returned by the view to have all the years and months for which at least one instance of the object type exists. So if my blog started in September 2007, but there were no post... | 7 | 2009-03-24T19:37:30Z | 678,966 | <p>You should be able to get all the info you describe from the built-in views. Can you be more specific as to what you cannot get? This should have everything you need:</p>
<pre><code>django.views.generic.date_based.archive_month
</code></pre>
<p><a href="http://docs.djangobrasil.org/ref/generic-views.html" rel="nof... | 1 | 2009-03-24T19:46:38Z | [
"python",
"django",
"datetime",
"django-views",
"django-queryset"
] |
Select Distinct Years and Months for Django Archive Page | 678,927 | <p>I want to make an archive_index page for my django site. However, the date-based generic views really aren't any help. I want the dictionary returned by the view to have all the years and months for which at least one instance of the object type exists. So if my blog started in September 2007, but there were no post... | 7 | 2009-03-24T19:37:30Z | 679,105 | <p>This will give you a list of unique posting dates:</p>
<pre><code>Posts.objects.filter(draft=False).dates('post_date','month',order='DESC')
</code></pre>
<p>Of course you might not need the draft filter, and change 'post_date' to your field name, etc.</p>
| 28 | 2009-03-24T20:26:37Z | [
"python",
"django",
"datetime",
"django-views",
"django-queryset"
] |
Select Distinct Years and Months for Django Archive Page | 678,927 | <p>I want to make an archive_index page for my django site. However, the date-based generic views really aren't any help. I want the dictionary returned by the view to have all the years and months for which at least one instance of the object type exists. So if my blog started in September 2007, but there were no post... | 7 | 2009-03-24T19:37:30Z | 679,164 | <p>I found the answer to my own question. </p>
<p><a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/">It's on this page</a> in the documentation.</p>
<p>There's a function called dates that will give you distinct dates. So I can do</p>
<p>Entry.objects.dates('pub_date','month') to get a list of date... | 9 | 2009-03-24T20:39:09Z | [
"python",
"django",
"datetime",
"django-views",
"django-queryset"
] |
Why does windows give an sqlite3.OperationalError and linux does not? | 679,162 | <h1>The problem</h1>
<p>I've got a programm that uses <a href="http://storm.canonical.com" rel="nofollow">storm 0.14</a> and it gives me this error on windows:</p>
<pre>
sqlite3.OperationError: database table is locked
</pre>
<p>The thing is, under linux it works correctly.</p>
<p>I've got the impression that it ha... | 3 | 2009-03-24T20:38:04Z | 679,186 | <p>The "database table is locked" error is often a generic/default error in SQLite, so narrowing down your problem is not obvious.</p>
<p>Are you able to execute <em>any</em> SQL queries? I would start there, and get some basic SELECT statements working. It could just be a permissions issue.</p>
| 1 | 2009-03-24T20:48:23Z | [
"python",
"windows",
"linux",
"sqlite"
] |
Why does windows give an sqlite3.OperationalError and linux does not? | 679,162 | <h1>The problem</h1>
<p>I've got a programm that uses <a href="http://storm.canonical.com" rel="nofollow">storm 0.14</a> and it gives me this error on windows:</p>
<pre>
sqlite3.OperationError: database table is locked
</pre>
<p>The thing is, under linux it works correctly.</p>
<p>I've got the impression that it ha... | 3 | 2009-03-24T20:38:04Z | 679,194 | <p>Hard to say without a little more info on the structure of your database access (which is a little obscured by using Storm).</p>
<p><em>I'd start by reading these documents; they contain very relevant information:</em></p>
<ol>
<li><p>https://storm.canonical.com/Manual#SQLite%20and%20threads</p></li>
<li><p><a hre... | 1 | 2009-03-24T20:51:23Z | [
"python",
"windows",
"linux",
"sqlite"
] |
Why does windows give an sqlite3.OperationalError and linux does not? | 679,162 | <h1>The problem</h1>
<p>I've got a programm that uses <a href="http://storm.canonical.com" rel="nofollow">storm 0.14</a> and it gives me this error on windows:</p>
<pre>
sqlite3.OperationError: database table is locked
</pre>
<p>The thing is, under linux it works correctly.</p>
<p>I've got the impression that it ha... | 3 | 2009-03-24T20:38:04Z | 679,291 | <p>Are you running any sort of anti-virus scanners? Anti-virus scanners will frequently lock a file after it has been updated, so that they can inspect it without it being changed. This may explain why you get this error after a lot of changes have been made; the anti-virus scanner has more new data to scan.</p>
<p>If... | 1 | 2009-03-24T21:19:51Z | [
"python",
"windows",
"linux",
"sqlite"
] |
Why does windows give an sqlite3.OperationalError and linux does not? | 679,162 | <h1>The problem</h1>
<p>I've got a programm that uses <a href="http://storm.canonical.com" rel="nofollow">storm 0.14</a> and it gives me this error on windows:</p>
<pre>
sqlite3.OperationError: database table is locked
</pre>
<p>The thing is, under linux it works correctly.</p>
<p>I've got the impression that it ha... | 3 | 2009-03-24T20:38:04Z | 679,438 | <p>It looks to me like storm is broken, though my first guess was virus scanner as Brian suggested.</p>
<p>Have you tried using <code>sqlite3_busy_timeout()</code> to set the timeout very high? This might cause <code>SQLite3</code> to wait long enough for the lock holder, whoever that is, to release the lock.</p>
| 1 | 2009-03-24T22:03:16Z | [
"python",
"windows",
"linux",
"sqlite"
] |
Why does windows give an sqlite3.OperationalError and linux does not? | 679,162 | <h1>The problem</h1>
<p>I've got a programm that uses <a href="http://storm.canonical.com" rel="nofollow">storm 0.14</a> and it gives me this error on windows:</p>
<pre>
sqlite3.OperationError: database table is locked
</pre>
<p>The thing is, under linux it works correctly.</p>
<p>I've got the impression that it ha... | 3 | 2009-03-24T20:38:04Z | 680,390 | <p>I've solved the problem at the moment by replacing the sqlite3-dll with the newest version. I'm still not sure if this was a bug in the windows code of sqlite or if python installed an older version on windows than on linux.</p>
<p>Thanks for your help.</p>
| 1 | 2009-03-25T06:04:53Z | [
"python",
"windows",
"linux",
"sqlite"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.