title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Using Python, how do I get an array of file info objects, based on a search of a file system? | 1,617,666 | <p>Currently I have a bash script which runs the <code>find</code> command, like so:</p>
<pre><code>find /storage/disk-1/Media/Video/TV -name *.avi -mtime -7
</code></pre>
<p>This gets a list of TV shows that were added to my system in the last 7 days. I then go on to create some symbolic links so I can get to my new... | 0 | 2009-10-24T11:00:12Z | 1,617,682 | <ul>
<li>You can use "find" through the "subprocess" module. </li>
<li>Afterwards, use the "split" string function to dissect each line</li>
<li>For each file, use the OS module (e.g. getmtime etc.) to get file information</li>
</ul>
<p>or</p>
<ul>
<li>Use the "walk" and "glob" modules to get the file paths in objec... | 1 | 2009-10-24T11:08:54Z | [
"python",
"find",
"fileinfo"
] |
Using Python, how do I get an array of file info objects, based on a search of a file system? | 1,617,666 | <p>Currently I have a bash script which runs the <code>find</code> command, like so:</p>
<pre><code>find /storage/disk-1/Media/Video/TV -name *.avi -mtime -7
</code></pre>
<p>This gets a list of TV shows that were added to my system in the last 7 days. I then go on to create some symbolic links so I can get to my new... | 0 | 2009-10-24T11:00:12Z | 1,617,689 | <p>look into module os: os.walk is the function which walks the file system, os.path is the module which gives the file mtime and other file informations. also os.path defines a lot of functions for parsing and splitting filenames. </p>
<p>also of interest, module glob defines a functions for "globbing" strings (match... | 2 | 2009-10-24T11:10:50Z | [
"python",
"find",
"fileinfo"
] |
Using Python, how do I get an array of file info objects, based on a search of a file system? | 1,617,666 | <p>Currently I have a bash script which runs the <code>find</code> command, like so:</p>
<pre><code>find /storage/disk-1/Media/Video/TV -name *.avi -mtime -7
</code></pre>
<p>This gets a list of TV shows that were added to my system in the last 7 days. I then go on to create some symbolic links so I can get to my new... | 0 | 2009-10-24T11:00:12Z | 1,617,710 | <pre><code>import os, time
allfiles = []
now = time.time()
# walk will return triples (current dir, list of subdirs, list of regular files)
# file names are relative to dir at first
for dir, subdirs, files in os.walk("/storage/disk-1/Media/Video/TV"):
for f in files:
if not f.endswith(".avi"):
... | 3 | 2009-10-24T11:18:29Z | [
"python",
"find",
"fileinfo"
] |
regular expression in python | 1,617,808 | <p>Hi
I am sorry if this question is too simple but I can't seem to reason this out. I want to parse a string. I want to extract the words between 'The final score is: ' and '.'. In other words, if i have a string "The final score is: 25." I want it to extract 25. I don't know how to do this. Should I use match? or spl... | 0 | 2009-10-24T12:02:02Z | 1,617,820 | <p>you don't need a regex to do this... do the split on ":" , then get the last element. OR , just use string slicing </p>
<pre><code>>>> "The final score is: 25."[-3:-1]
'25'
>>> s.split(":")[-1].strip() #use -1 to always get the last element
'25'
</code></pre>
| -1 | 2009-10-24T12:05:14Z | [
"python",
"regex",
"string"
] |
regular expression in python | 1,617,808 | <p>Hi
I am sorry if this question is too simple but I can't seem to reason this out. I want to parse a string. I want to extract the words between 'The final score is: ' and '.'. In other words, if i have a string "The final score is: 25." I want it to extract 25. I don't know how to do this. Should I use match? or spl... | 0 | 2009-10-24T12:02:02Z | 1,617,825 | <p>If you know your information is always going to be formatted like that then you can simply use split:</p>
<pre><code>s = "The final score is: 25"
score = s.split(':')[1].strip()
</code></pre>
<p>This will result in score being <code>25</code>. I use .strip() at the end to remove any whitespace as a safety measure... | 3 | 2009-10-24T12:07:21Z | [
"python",
"regex",
"string"
] |
regular expression in python | 1,617,808 | <p>Hi
I am sorry if this question is too simple but I can't seem to reason this out. I want to parse a string. I want to extract the words between 'The final score is: ' and '.'. In other words, if i have a string "The final score is: 25." I want it to extract 25. I don't know how to do this. Should I use match? or spl... | 0 | 2009-10-24T12:02:02Z | 1,617,847 | <p>You're talking about "capturing" some characters between "The final score is:" and ".". This means you have a group. A group requires ()'s.</p>
<p>See <a href="http://docs.python.org/library/re.html" rel="nofollow">http://docs.python.org/library/re.html</a> for all the rules.</p>
<p>Since this smells like homewo... | 2 | 2009-10-24T12:14:12Z | [
"python",
"regex",
"string"
] |
regular expression in python | 1,617,808 | <p>Hi
I am sorry if this question is too simple but I can't seem to reason this out. I want to parse a string. I want to extract the words between 'The final score is: ' and '.'. In other words, if i have a string "The final score is: 25." I want it to extract 25. I don't know how to do this. Should I use match? or spl... | 0 | 2009-10-24T12:02:02Z | 1,619,247 | <p>If you're trying to understand regular expressions and not just trying to get a value out of a string, you may find this helpful.</p>
<p>The first concept you need is that of grouping. Parentheses in a regular expression delimit a group; <code>re.match()</code> has a <code>groups()</code> method that returns a tup... | 2 | 2009-10-24T21:50:38Z | [
"python",
"regex",
"string"
] |
how to reduce size of exe using py2exe | 1,617,868 | <p>I developed a small program using python and wxwidgets. It is a very simple program that uses only a mini frame to display some information when needed, and the rest of the time it shows nothing, only an icon in the taskbar.</p>
<p>When I build the exe using py2exe (single file exe mode, optimized), I get a 6MB siz... | 6 | 2009-10-24T12:20:44Z | 1,617,919 | <p>Most of the space is the Python runtime itself. py2exe doesn't "compile" your program to native x86 instructions, or anything like that. It just bundles Python, your *.pyc files, and any modules your program uses up into a bundle that runs on its own.</p>
<p>You could therefore choose to distribute only your *.py... | 1 | 2009-10-24T12:41:50Z | [
"python",
"executable",
"py2exe",
"filesize"
] |
how to reduce size of exe using py2exe | 1,617,868 | <p>I developed a small program using python and wxwidgets. It is a very simple program that uses only a mini frame to display some information when needed, and the rest of the time it shows nothing, only an icon in the taskbar.</p>
<p>When I build the exe using py2exe (single file exe mode, optimized), I get a 6MB siz... | 6 | 2009-10-24T12:20:44Z | 1,619,123 | <p>The fact that your program is simple does not mean that it's small. Your program has many dependency through the wxWidget stack and 6 Mb does not look that big with all this in mind.</p>
<p>But, back to the question. To shrink a py2exe generated program, you can do a few obvious things:</p>
<ol>
<li><p>Distribute ... | 4 | 2009-10-24T21:08:14Z | [
"python",
"executable",
"py2exe",
"filesize"
] |
Pyserial problem with Arduino - works with the Python shell but not in a program | 1,618,141 | <p>All right, so I am positive my Arduino circuit is correct and the code for it. I know this because when I use the serial monitor built into the Arduino IDE and send 'H' an LED lights up, when I send 'L' that LED turns off.</p>
<p>Now I made a Python program </p>
<pre><code>import serial
ser = serial.Serial("COM4",... | 9 | 2009-10-24T14:26:54Z | 3,272,988 | <p>I had the same problem and it works if I add a delay of about 2 seconds from opening the serial connection to writing on it, 1 second was not enough.</p>
| 5 | 2010-07-17T19:39:27Z | [
"python",
"serial-port",
"arduino"
] |
Pyserial problem with Arduino - works with the Python shell but not in a program | 1,618,141 | <p>All right, so I am positive my Arduino circuit is correct and the code for it. I know this because when I use the serial monitor built into the Arduino IDE and send 'H' an LED lights up, when I send 'L' that LED turns off.</p>
<p>Now I made a Python program </p>
<pre><code>import serial
ser = serial.Serial("COM4",... | 9 | 2009-10-24T14:26:54Z | 4,941,880 | <p>When you open the serial port, this causes the Arduino to reset. Since the Arduino takes some time to bootup, all the input goes to the bitbucket (or probably to the bootloader which does god knows what with it). If you insert a sleep, you wait for the Arduino to come up so your serial code. This is why it works int... | 7 | 2011-02-09T06:16:15Z | [
"python",
"serial-port",
"arduino"
] |
Pyserial problem with Arduino - works with the Python shell but not in a program | 1,618,141 | <p>All right, so I am positive my Arduino circuit is correct and the code for it. I know this because when I use the serial monitor built into the Arduino IDE and send 'H' an LED lights up, when I send 'L' that LED turns off.</p>
<p>Now I made a Python program </p>
<pre><code>import serial
ser = serial.Serial("COM4",... | 9 | 2009-10-24T14:26:54Z | 18,409,970 | <p>Just to make it a bit more clear I'll modify the code so everyone can see what needs to be added!</p>
<pre><code>import serial
import time
ser = serial.Serial("COM4",9600)
time.sleep(3)
ser.write("H")
</code></pre>
<p>Adding in a sleep statment helps to let the serial open up without any problems!</p>
| 1 | 2013-08-23T18:56:49Z | [
"python",
"serial-port",
"arduino"
] |
Python Tornado Web - AttributeError: 'Connection' object has no attribute '_execute' | 1,618,339 | <p>I'm experiencing a strange behaviour working with the latest branch of tornadoweb when I deploy my app on my production server.</p>
<p>I tested several times the code and it is fully working when I test it on my laptop (Archlinux) with python 2.6.3 and MySQLdb 1.2.3b2.</p>
<p>As soon as I deploy on my production s... | 0 | 2009-10-24T15:53:00Z | 1,625,963 | <p>I finally fixed my problem moving to a fresh ubuntu x64 instead of using a i386 version.</p>
| -2 | 2009-10-26T17:01:11Z | [
"python",
"ubuntu",
"mysql",
"tornado",
"attributeerror"
] |
What's wrong with this `setup.py`? | 1,618,674 | <p>I've been having problems withe getting <code>setup.py</code> to do the <code>sdist</code> thing correctly. I boiled it down to this. I have the following directory structure:</p>
<pre><code>my_package\
my_subpackage\
__init__.py
deep_module.py
__init__.py
module.py
setup.py
</code><... | 0 | 2009-10-24T18:21:46Z | 1,618,691 | <p>Instead of this:</p>
<pre><code>my_package\
my_subpackage\
__init__.py
deep_module.py
__init__.py
module.py
setup.py
</code></pre>
<p>Try this:</p>
<pre><code>my_package_source\
setup.py
README.txt
my_package\
my_subpackage\
__init__.py
d... | 4 | 2009-10-24T18:28:31Z | [
"python",
"distribution",
"distutils"
] |
What's wrong with this `setup.py`? | 1,618,674 | <p>I've been having problems withe getting <code>setup.py</code> to do the <code>sdist</code> thing correctly. I boiled it down to this. I have the following directory structure:</p>
<pre><code>my_package\
my_subpackage\
__init__.py
deep_module.py
__init__.py
module.py
setup.py
</code><... | 0 | 2009-10-24T18:21:46Z | 1,618,725 | <p>The problem is well explained <a href="http://blog.twinapex.fi/2009/07/24/setup-py-sdist-not-including-all-files/">here</a>:</p>
<blockquote>
<p>Setuptools has many silent failure
modes. One of them is failure to
include all files in sdist release
(well not exactly a failure, you could
RTFM, but the defau... | 6 | 2009-10-24T18:41:34Z | [
"python",
"distribution",
"distutils"
] |
Disable link to edit object in django's admin (display list only)? | 1,618,728 | <p>In Django's admin, I want <em>disable</em> the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields).</p>
<p>I see that Django has the ability to <a... | 29 | 2009-10-24T18:42:22Z | 1,619,109 | <p>There isn't a supported way to do this. </p>
<p>Looking at the code, it seems that it automatically sets <code>ModelAdmin.list_display_links</code> to the first element if you don't set it to anything. So the easiest way might be to override the <code>__init__</code> method in your <code>ModelAdmin</code> subclass ... | 2 | 2009-10-24T21:03:27Z | [
"python",
"django",
"django-admin",
"modeladmin"
] |
Disable link to edit object in django's admin (display list only)? | 1,618,728 | <p>In Django's admin, I want <em>disable</em> the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields).</p>
<p>I see that Django has the ability to <a... | 29 | 2009-10-24T18:42:22Z | 1,619,185 | <p>You could also be <strong><em>ridiculously</em></strong> hacky about it (if you didn't want to fuss with overriding <code><strong>init</strong></code>) and provide a value for the first element that basically looks like this:</p>
<pre><code></a>My non-linked value<a>
</code></pre>
<p>I know, I know, no... | 1 | 2009-10-24T21:26:40Z | [
"python",
"django",
"django-admin",
"modeladmin"
] |
Disable link to edit object in django's admin (display list only)? | 1,618,728 | <p>In Django's admin, I want <em>disable</em> the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields).</p>
<p>I see that Django has the ability to <a... | 29 | 2009-10-24T18:42:22Z | 1,659,142 | <p>In your model admin set:</p>
<pre><code>list_display_links = (None,)
</code></pre>
<p>That should do it. (Works in 1.1.1 anyway.)</p>
| 4 | 2009-11-02T02:09:42Z | [
"python",
"django",
"django-admin",
"modeladmin"
] |
Disable link to edit object in django's admin (display list only)? | 1,618,728 | <p>In Django's admin, I want <em>disable</em> the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields).</p>
<p>I see that Django has the ability to <a... | 29 | 2009-10-24T18:42:22Z | 1,982,474 | <p>I wanted a Log viewer as a list only.</p>
<p>I got it working like this:</p>
<pre><code>class LogEntryAdmin(ModelAdmin):
actions = None
list_display = (
'action_time', 'user',
'content_type', 'object_repr',
'change_message')
search_fields = ['=user__username', ]
fieldsets ... | 51 | 2009-12-30T21:02:14Z | [
"python",
"django",
"django-admin",
"modeladmin"
] |
Disable link to edit object in django's admin (display list only)? | 1,618,728 | <p>In Django's admin, I want <em>disable</em> the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields).</p>
<p>I see that Django has the ability to <a... | 29 | 2009-10-24T18:42:22Z | 5,837,386 | <p>As user, omat, mentioned in a comment above, any attempt to simply remove the links does not prevent users from still accessing the change page manually. However, that, too, is easy enough to remedy:</p>
<pre><code>class MyModelAdmin(admin.ModelAdmin)
# Other stuff here
def change_view(self, request, obj=No... | 16 | 2011-04-29T21:04:02Z | [
"python",
"django",
"django-admin",
"modeladmin"
] |
Disable link to edit object in django's admin (display list only)? | 1,618,728 | <p>In Django's admin, I want <em>disable</em> the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields).</p>
<p>I see that Django has the ability to <a... | 29 | 2009-10-24T18:42:22Z | 15,565,655 | <p>Just for the notes, you may modify changelist_view:</p>
<pre><code>class SomeAdmin(admin.ModelAdmin):
def changelist_view(self, request, extra_context=None):
self.list_display_links = (None, )
return super(SomeAdmin, self).changelist_view(request, extra_context=None)
</code></pre>
<p>This works... | 2 | 2013-03-22T08:16:51Z | [
"python",
"django",
"django-admin",
"modeladmin"
] |
Disable link to edit object in django's admin (display list only)? | 1,618,728 | <p>In Django's admin, I want <em>disable</em> the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields).</p>
<p>I see that Django has the ability to <a... | 29 | 2009-10-24T18:42:22Z | 21,923,938 | <p>with django 1.6.2 you can do like this:</p>
<pre><code>class MyAdmin(admin.ModelAdmin):
def get_list_display_links(self, request, list_display):
return []
</code></pre>
<p>it will hide all auto generated links.</p>
| 1 | 2014-02-21T02:16:11Z | [
"python",
"django",
"django-admin",
"modeladmin"
] |
Disable link to edit object in django's admin (display list only)? | 1,618,728 | <p>In Django's admin, I want <em>disable</em> the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields).</p>
<p>I see that Django has the ability to <a... | 29 | 2009-10-24T18:42:22Z | 22,380,856 | <p>In Django 1.7 and later, you can do </p>
<pre><code>class HitAdmin(admin.ModelAdmin):
list_display_links = None
</code></pre>
| 4 | 2014-03-13T13:56:36Z | [
"python",
"django",
"django-admin",
"modeladmin"
] |
Disable link to edit object in django's admin (display list only)? | 1,618,728 | <p>In Django's admin, I want <em>disable</em> the links provided on the "select item to change" page so that users cannot go anywhere to edit the item. (I am going to limit what the users can do with this list to a set of drop down actions - no actual editing of fields).</p>
<p>I see that Django has the ability to <a... | 29 | 2009-10-24T18:42:22Z | 26,514,914 | <p>Doing this properly requires two steps:</p>
<ul>
<li>Hide the edit link, so nobody stumbles on the detail page (change view) by mistake.</li>
<li>Modify the change view to redirect back to the list view.</li>
</ul>
<p>The second part is important: if you don't do this then people will still be able to access the c... | 10 | 2014-10-22T18:50:37Z | [
"python",
"django",
"django-admin",
"modeladmin"
] |
Friendlier error messages on import for missing modules | 1,618,762 | <p>I want to implement some friendlier error messages if the user tries to run a python script which tries to import modules that have not been installed. This includes printing out instructions on how to install the missing module.</p>
<p>One way to do this would be to put a try..catch block around the imports, but t... | 4 | 2009-10-24T18:57:28Z | 1,618,786 | <p>I would put additional modules into the package which, when imported, print out the more helpful message, and then raise a regular ImportError. When the true module is installed, your modules will get shadowed (make sure you add the directory where they live at the <em>end</em> of sys.path).</p>
| 2 | 2009-10-24T19:08:24Z | [
"python",
"exception-handling"
] |
Friendlier error messages on import for missing modules | 1,618,762 | <p>I want to implement some friendlier error messages if the user tries to run a python script which tries to import modules that have not been installed. This includes printing out instructions on how to install the missing module.</p>
<p>One way to do this would be to put a try..catch block around the imports, but t... | 4 | 2009-10-24T18:57:28Z | 1,618,868 | <p>You can put, somewhere that it will always be executed (e.g. in site.py or sitecustomize.py):</p>
<pre><code>import __builtin__
realimport = __builtin__.__import__
def myimport(modname, *a):
try:
return realimport(modname, *a)
except ImportError, e:
print "Oops, couldn't import %s (%s)" % (modname, e)... | 5 | 2009-10-24T19:41:39Z | [
"python",
"exception-handling"
] |
Friendlier error messages on import for missing modules | 1,618,762 | <p>I want to implement some friendlier error messages if the user tries to run a python script which tries to import modules that have not been installed. This includes printing out instructions on how to install the missing module.</p>
<p>One way to do this would be to put a try..catch block around the imports, but t... | 4 | 2009-10-24T18:57:28Z | 1,618,880 | <p>You don't have to catch ImportError for every import. You can use a global <code>try..except</code> block in the entry point of your script.</p>
<p>You can get the name of the missing module from a ImportError instance using the message property.</p>
<p>For example, if the entry point of your script is main.py:</p... | 3 | 2009-10-24T19:45:17Z | [
"python",
"exception-handling"
] |
Friendlier error messages on import for missing modules | 1,618,762 | <p>I want to implement some friendlier error messages if the user tries to run a python script which tries to import modules that have not been installed. This includes printing out instructions on how to install the missing module.</p>
<p>One way to do this would be to put a try..catch block around the imports, but t... | 4 | 2009-10-24T18:57:28Z | 1,620,608 | <p>Replace <code>sys.excepthook</code>:</p>
<pre><code>orig_excepthook = sys.excepthook
def my_excepthook(type, value, tb):
orig_excepthook(type, value, tb)
if issubclass(type, ImportError):
# print some friendly message
sys.excepthook = orig_excepthook
</code></pre>
| 0 | 2009-10-25T10:49:34Z | [
"python",
"exception-handling"
] |
Mapping complex python objects to django models | 1,618,773 | <p>I have a certain class structure in my app, that currently utilizes django for presentation. I was not using the model layer at all, - the database interaction routines are hand-written. </p>
<p>I am, however, considering the possibility of actually using django to its full potential and actually using the database... | 1 | 2009-10-24T19:01:49Z | 1,618,780 | <p>It somewhat depends on what specific behavior you want to encode. In most cases, you should try to put per-object behavior into the model class. It's a regular Python class, after all, so you can give it any methods you desire. You do need to account for the persistant nature, of course, e.g. by avoiding additional ... | 1 | 2009-10-24T19:04:56Z | [
"python",
"django",
"design"
] |
Mapping complex python objects to django models | 1,618,773 | <p>I have a certain class structure in my app, that currently utilizes django for presentation. I was not using the model layer at all, - the database interaction routines are hand-written. </p>
<p>I am, however, considering the possibility of actually using django to its full potential and actually using the database... | 1 | 2009-10-24T19:01:49Z | 1,618,788 | <p>This is largely a philosophical question re: MVC and how you choose to implement it. Arguably there is no right way here, but assuming that you want the model objects to all behave in a certain way regardless of the view that interacts with them, it makes sense to attach this behavior to the model. If the behavio... | 0 | 2009-10-24T19:09:00Z | [
"python",
"django",
"design"
] |
Openoffice3.1 pyuno confusing errors | 1,618,833 | <p>I'm trying to get the <a href="http://wiki.services.openoffice.org/wiki/PyUNO_bridge" rel="nofollow">sample</a> and other sample codes i find for pyuno running with openoffice 3.1.1 and python 2.5 with no luck. </p>
<p>Unfortunately, pyuno does not give any clues about what goes wrong.</p>
<pre>
In [1]: import un... | 2 | 2009-10-24T19:24:17Z | 1,619,251 | <p>In [1]: import uno
In [2]: local = uno.getComponentContext()
In [3]: resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)</p>
<p>OOP gone wrong, imho. i know its OT, but i tried getting uno to work before, and gave up. this is pure Steve Yegge Prose (read up on <a h... | 5 | 2009-10-24T21:53:20Z | [
"python",
"openoffice.org",
"uno",
"pyuno"
] |
detect new or modified files with python | 1,618,853 | <p>I'm trying to detect when a new file is created a directory or when an existing file is modified in a directory.</p>
<p>I tried searching for a script that would do this (preferably in python or bash) but came up short. My environment is linux with Python 2.6</p>
<p><a href="http://stackoverflow.com/questions/4158... | 6 | 2009-10-24T19:34:34Z | 1,618,871 | <p>You can use <code>gio</code> which is the Filesystem part of GLib (In GLib's python bindings)</p>
<pre><code>import gio
def directory_changed(monitor, file1, file2, evt_type):
if (evt_type in (gio.FILE_MONITOR_EVENT_CREATED,
gio.FILE_MONITOR_EVENT_DELETED)):
print "Changed:", file1, file2, evt_typ... | 13 | 2009-10-24T19:41:57Z | [
"python",
"linux",
"file",
"filesystems"
] |
detect new or modified files with python | 1,618,853 | <p>I'm trying to detect when a new file is created a directory or when an existing file is modified in a directory.</p>
<p>I tried searching for a script that would do this (preferably in python or bash) but came up short. My environment is linux with Python 2.6</p>
<p><a href="http://stackoverflow.com/questions/4158... | 6 | 2009-10-24T19:34:34Z | 1,618,887 | <p>If you're using Linux, you may try <a href="http://trac.dbzteam.org/pyinotify" rel="nofollow"><code>pyinotify</code></a> that acts like an object-oriented wrapper around the <a href="http://linux.die.net/man/7/inotify" rel="nofollow"><code>inotify(7)</code></a> system calls. The project website contains quite strai... | 4 | 2009-10-24T19:46:37Z | [
"python",
"linux",
"file",
"filesystems"
] |
detect new or modified files with python | 1,618,853 | <p>I'm trying to detect when a new file is created a directory or when an existing file is modified in a directory.</p>
<p>I tried searching for a script that would do this (preferably in python or bash) but came up short. My environment is linux with Python 2.6</p>
<p><a href="http://stackoverflow.com/questions/4158... | 6 | 2009-10-24T19:34:34Z | 1,618,893 | <p>If you can use PyQt, there's QFileSystemWatcher that does just this.</p>
| 1 | 2009-10-24T19:48:16Z | [
"python",
"linux",
"file",
"filesystems"
] |
detect new or modified files with python | 1,618,853 | <p>I'm trying to detect when a new file is created a directory or when an existing file is modified in a directory.</p>
<p>I tried searching for a script that would do this (preferably in python or bash) but came up short. My environment is linux with Python 2.6</p>
<p><a href="http://stackoverflow.com/questions/4158... | 6 | 2009-10-24T19:34:34Z | 3,702,281 | <p>There are also <a href="http://people.gnome.org/~veillard/gamin/python.html" rel="nofollow">Python bindings for gamin</a>.</p>
| 0 | 2010-09-13T16:16:59Z | [
"python",
"linux",
"file",
"filesystems"
] |
Python zlib output, how to recover out of mysql utf-8 table? | 1,618,926 | <p>In python, I compressed a string using zlib, and then inserted it into a mysql column that is of type blob, using the utf-8 encoding. The string comes back as utf-8, but it's not clear how to get it back into a format where I can decompress it. Here is some pseduo-output:</p>
<p>valueInserted = zlib.compress('a')
=... | 7 | 2009-10-24T20:03:38Z | 1,618,942 | <p>Unicode is designed to be compatible with latin-1, so try:</p>
<pre><code>>>> import zlib
>>> u = zlib.compress("test").decode('latin1')
>>> u
u'x\x9c+I-.\x01\x00\x04]\x01\xc1'
</code></pre>
<p>And then</p>
<pre><code>>>> zlib.decompress(u.encode('latin1'))
'test'
</code></pre>... | 7 | 2009-10-24T20:11:57Z | [
"python",
"mysql",
"unicode",
"utf-8",
"zlib"
] |
Python zlib output, how to recover out of mysql utf-8 table? | 1,618,926 | <p>In python, I compressed a string using zlib, and then inserted it into a mysql column that is of type blob, using the utf-8 encoding. The string comes back as utf-8, but it's not clear how to get it back into a format where I can decompress it. Here is some pseduo-output:</p>
<p>valueInserted = zlib.compress('a')
=... | 7 | 2009-10-24T20:03:38Z | 1,619,495 | <pre><code>valueInserted = zlib.compress('a') = 'x\x9cK\x04\x00\x00b\x00b'
</code></pre>
<p>Note that this is an <em>str</em> object. You say that you "inserted it into a mysql column that is of type blob, using the utf-8 encoding". AS the compressed string is binary, not text, "blob" is an appropriate type of column,... | 1 | 2009-10-24T23:32:17Z | [
"python",
"mysql",
"unicode",
"utf-8",
"zlib"
] |
Python zlib output, how to recover out of mysql utf-8 table? | 1,618,926 | <p>In python, I compressed a string using zlib, and then inserted it into a mysql column that is of type blob, using the utf-8 encoding. The string comes back as utf-8, but it's not clear how to get it back into a format where I can decompress it. Here is some pseduo-output:</p>
<p>valueInserted = zlib.compress('a')
=... | 7 | 2009-10-24T20:03:38Z | 1,619,496 | <p>You have a <strong>unicode object</strong> that is really encoding bytes. That's unfortunate, since unicode strings should really only be coding text, right?</p>
<p>Anyway, what we want to do is to construct a byte string.. this is a <code>str</code> in Python 2.x. We see by the printed string you gave <code>u'x\x9... | 2 | 2009-10-24T23:32:26Z | [
"python",
"mysql",
"unicode",
"utf-8",
"zlib"
] |
Fastest way to convert '(-1,0)' into tuple(-1, 0)? | 1,618,965 | <p>I've got a huge tuple of strings, which are being returned from a program. An example tuple being returned might look like this:</p>
<pre><code>('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)')
</code></pre>
<p>I <em>can</em> convert these strings to real tuples (with integers inside), but i am hopi... | 1 | 2009-10-24T20:19:14Z | 1,618,978 | <p>If you're sure the input is well formed:</p>
<pre><code>tuples = ('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)')
result = [eval(t) for t in tuples]
</code></pre>
| 1 | 2009-10-24T20:23:02Z | [
"python",
"string",
"tuples"
] |
Fastest way to convert '(-1,0)' into tuple(-1, 0)? | 1,618,965 | <p>I've got a huge tuple of strings, which are being returned from a program. An example tuple being returned might look like this:</p>
<pre><code>('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)')
</code></pre>
<p>I <em>can</em> convert these strings to real tuples (with integers inside), but i am hopi... | 1 | 2009-10-24T20:19:14Z | 1,619,017 | <p>You can get a parser up and running pretty quickly with YAPPS. </p>
| 1 | 2009-10-24T20:34:10Z | [
"python",
"string",
"tuples"
] |
Fastest way to convert '(-1,0)' into tuple(-1, 0)? | 1,618,965 | <p>I've got a huge tuple of strings, which are being returned from a program. An example tuple being returned might look like this:</p>
<pre><code>('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)')
</code></pre>
<p>I <em>can</em> convert these strings to real tuples (with integers inside), but i am hopi... | 1 | 2009-10-24T20:19:14Z | 1,619,032 | <pre><code>map(eval, tuples)
</code></pre>
<p>This won't account for the case where one of the tuples isn't syntactically correct. For that, I'd recommend something like:</p>
<pre><code>def do(tup):
try: return eval(tup)
except: return None
map(do, tuples)
</code></pre>
<p>Both methods tested for speed:</p>... | 3 | 2009-10-24T20:39:58Z | [
"python",
"string",
"tuples"
] |
Fastest way to convert '(-1,0)' into tuple(-1, 0)? | 1,618,965 | <p>I've got a huge tuple of strings, which are being returned from a program. An example tuple being returned might look like this:</p>
<pre><code>('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)')
</code></pre>
<p>I <em>can</em> convert these strings to real tuples (with integers inside), but i am hopi... | 1 | 2009-10-24T20:19:14Z | 1,619,046 | <p>you can just use yaml or json to parse it into tuples for you.</p>
| 1 | 2009-10-24T20:44:09Z | [
"python",
"string",
"tuples"
] |
Fastest way to convert '(-1,0)' into tuple(-1, 0)? | 1,618,965 | <p>I've got a huge tuple of strings, which are being returned from a program. An example tuple being returned might look like this:</p>
<pre><code>('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)')
</code></pre>
<p>I <em>can</em> convert these strings to real tuples (with integers inside), but i am hopi... | 1 | 2009-10-24T20:19:14Z | 1,619,076 | <p>I'd do string parsing if you know the format. Faster than eval().</p>
<pre><code>>>> tuples = ["(1,0)"] * 1000000
>>> import time
>>> st = time.time(); parsed = map(eval, tuples); print "%.2f s" % (time.time() - st)
32.71 s
>>> def parse(s) :
... return s[1:-1].split(",")
...
&... | 2 | 2009-10-24T20:54:02Z | [
"python",
"string",
"tuples"
] |
Fastest way to convert '(-1,0)' into tuple(-1, 0)? | 1,618,965 | <p>I've got a huge tuple of strings, which are being returned from a program. An example tuple being returned might look like this:</p>
<pre><code>('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)')
</code></pre>
<p>I <em>can</em> convert these strings to real tuples (with integers inside), but i am hopi... | 1 | 2009-10-24T20:19:14Z | 1,619,093 | <p>I don't advice you to use eval at all. It is slow and insecure. You can do this:</p>
<pre><code>result = map(lambda a: tuple(map(int, a[1:-1].split(','))), s)
</code></pre>
<p>The numbers speak for themselves:</p>
<pre><code>timeit.Timer("map(lambda a: tuple(map(int, a[1:-1].split(','))), s)", "s = ('(-1,0)', '(1... | 10 | 2009-10-24T20:59:28Z | [
"python",
"string",
"tuples"
] |
Fastest way to convert '(-1,0)' into tuple(-1, 0)? | 1,618,965 | <p>I've got a huge tuple of strings, which are being returned from a program. An example tuple being returned might look like this:</p>
<pre><code>('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)')
</code></pre>
<p>I <em>can</em> convert these strings to real tuples (with integers inside), but i am hopi... | 1 | 2009-10-24T20:19:14Z | 1,621,586 | <p>My computer is slower than Nadia's, however this runs faster</p>
<pre><code>>>> timeit.Timer(
"list((int(a),int(c)) for a,b,c in (x[1:-1].partition(',') for x in s))",
"s = ('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)')").timeit(100000)
3.2250211238861084
</code></pre>
<p>than t... | 2 | 2009-10-25T18:10:30Z | [
"python",
"string",
"tuples"
] |
Fastest way to convert '(-1,0)' into tuple(-1, 0)? | 1,618,965 | <p>I've got a huge tuple of strings, which are being returned from a program. An example tuple being returned might look like this:</p>
<pre><code>('(-1,0)', '(1,0)', '(2,0)', '(3,0)', '(4,0)', '(5,0)', '(6,0)')
</code></pre>
<p>I <em>can</em> convert these strings to real tuples (with integers inside), but i am hopi... | 1 | 2009-10-24T20:19:14Z | 1,621,710 | <pre><code>import ast
list_of_tuples = map(ast.literal_eval, tuple_of_strings)
</code></pre>
| 0 | 2009-10-25T18:53:47Z | [
"python",
"string",
"tuples"
] |
python locale currency and negative numbers | 1,618,975 | <p>Why? </p>
<pre><code>C:\path\>manage.py shell
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
('Spanish_Colombia', '1252')
>>> loca... | 0 | 2009-10-24T20:22:07Z | 1,619,003 | <p>In your locale, surrounding a number with brackets indicates it's a negative number. Check this in Control Panel/Regional and Language settings, Python's probably picking it up from there.</p>
| 2 | 2009-10-24T20:29:32Z | [
"python",
"django",
"locale",
"currency"
] |
python locale currency and negative numbers | 1,618,975 | <p>Why? </p>
<pre><code>C:\path\>manage.py shell
Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getlocale()
('Spanish_Colombia', '1252')
>>> loca... | 0 | 2009-10-24T20:22:07Z | 1,619,390 | <p>Parentheses around a number to indicate it's a debit (i.e. negative), not a credit (positive), are a common convention in accounting (I guess because the parentheses are more visible than a small minus/dash in front, and it's crucial to distinguish debits from credits;-).</p>
<p>So, it's not surprising that many lo... | 2 | 2009-10-24T22:40:24Z | [
"python",
"django",
"locale",
"currency"
] |
Grouping on an attribute using itertools.groupby | 1,619,227 | <p>I have a list of instances of the class 'Chromosome'.</p>
<p>The list is sorted on the Chromosome attribute 'equation'</p>
<p>I now want to remove instances where the attribute 'equation' is the same, leaving only one.</p>
<p>I don't know how to pass the key, ie the ?, so that it groups on 'equation'.</p>
<pre><... | 2 | 2009-10-24T21:43:50Z | 1,619,260 | <p>Here is how to do it:</p>
<pre><code>b = [a for a,b in groupby(list, key=lambda a: a.equation)]
</code></pre>
| 3 | 2009-10-24T21:55:00Z | [
"python"
] |
Grouping on an attribute using itertools.groupby | 1,619,227 | <p>I have a list of instances of the class 'Chromosome'.</p>
<p>The list is sorted on the Chromosome attribute 'equation'</p>
<p>I now want to remove instances where the attribute 'equation' is the same, leaving only one.</p>
<p>I don't know how to pass the key, ie the ?, so that it groups on 'equation'.</p>
<pre><... | 2 | 2009-10-24T21:43:50Z | 1,619,350 | <pre><code>import operator
[a for a, b in groupby(thelist, operator.attrgetter('equation')]
</code></pre>
<p>Btw, don't use builtin type names (such as <code>list</code>, <code>file</code>, etc) for your own identifiers, it's a confusing and best-avoided practice that will eventually byte you with peculiar bugs unles... | 6 | 2009-10-24T22:25:55Z | [
"python"
] |
Python + SVN + Windows/Mac = Invalid syntax? | 1,619,229 | <p>I'm pretty sure the following error is related to the fact that I'm sharing code via SVN with a colleague that is using a Windows system. </p>
<p>Myself, I use Python on Mac, editing with TextMate.</p>
<pre><code>#!/usr/bin/python
import os
from google.appengine.api import users
from google.appengine.ext import ... | 0 | 2009-10-24T21:44:05Z | 1,619,252 | <h3>Byte order mark? No, native EOL needed.</h3>
<p>I would be surprised if Python didn't just silently ignore the usual variations on record terminator styles.</p>
<p>A shell or kernel might not, but then you would see something like <code>python: bad interpreter</code>.</p>
<p>It's possible that there is a BOM, or... | 1 | 2009-10-24T21:53:28Z | [
"python",
"svn",
"google-app-engine",
"operating-system",
"textmate"
] |
Python + SVN + Windows/Mac = Invalid syntax? | 1,619,229 | <p>I'm pretty sure the following error is related to the fact that I'm sharing code via SVN with a colleague that is using a Windows system. </p>
<p>Myself, I use Python on Mac, editing with TextMate.</p>
<pre><code>#!/usr/bin/python
import os
from google.appengine.api import users
from google.appengine.ext import ... | 0 | 2009-10-24T21:44:05Z | 1,619,255 | <p>While it's true that line endings are (usually) different between Windows and the rest of the computing world, Python is designed to be agnostic about the issue. Normally Python has no trouble with varied line endings.</p>
<p>I tried running a Python script on my Mac with a wide variety of line endings and had no p... | 1 | 2009-10-24T21:54:15Z | [
"python",
"svn",
"google-app-engine",
"operating-system",
"textmate"
] |
Python + SVN + Windows/Mac = Invalid syntax? | 1,619,229 | <p>I'm pretty sure the following error is related to the fact that I'm sharing code via SVN with a colleague that is using a Windows system. </p>
<p>Myself, I use Python on Mac, editing with TextMate.</p>
<pre><code>#!/usr/bin/python
import os
from google.appengine.api import users
from google.appengine.ext import ... | 0 | 2009-10-24T21:44:05Z | 1,619,257 | <p>Subversion ignores all end-of-line(EOL)-styles. It will <em>never</em> touch your files, unless you told it so.</p>
<p>How can you tell Subversion to use a different EOL-Style?
By setting property <strong>svn:eol-style</strong> to files in question: </p>
<pre><code>svn propset svn:eol-style LF /path/to/my/file/in/... | 1 | 2009-10-24T21:54:32Z | [
"python",
"svn",
"google-app-engine",
"operating-system",
"textmate"
] |
Python + SVN + Windows/Mac = Invalid syntax? | 1,619,229 | <p>I'm pretty sure the following error is related to the fact that I'm sharing code via SVN with a colleague that is using a Windows system. </p>
<p>Myself, I use Python on Mac, editing with TextMate.</p>
<pre><code>#!/usr/bin/python
import os
from google.appengine.api import users
from google.appengine.ext import ... | 0 | 2009-10-24T21:44:05Z | 1,619,346 | <p>While Python shouldn't care about line endings, your Mac won't like having a CRLF line ending on the first line, so this may be your problem.</p>
<pre><code>0000000 # ! / u s r / b i n / p y t h o n \r \n
^^
</code></pre>
<p>SVN can be told to translate line endings by set... | 4 | 2009-10-24T22:23:49Z | [
"python",
"svn",
"google-app-engine",
"operating-system",
"textmate"
] |
How to start a long-running process from a Django view? | 1,619,397 | <p>I need to run a process that might take hours to complete from a Django view. I don't need to know the state or communicate with it but I need that view to redirect away right after starting the process.</p>
<p>I've tried using <code>subprocess.Popen</code>, using it within a new <code>threading.Thread</code>, <cod... | 12 | 2009-10-24T22:42:11Z | 1,619,426 | <p>I don't know if this will be suitable for your case, nevertheless here is what I do: I use a task queue (via a django model); when the view is called, it enters a new record in the tasks and redirects happily. Tasks in turn are executed by cron on a regular basis independently from django. </p>
<p>Edit: cron calls ... | 10 | 2009-10-24T22:57:01Z | [
"python",
"django",
"long-running-processes"
] |
How to start a long-running process from a Django view? | 1,619,397 | <p>I need to run a process that might take hours to complete from a Django view. I don't need to know the state or communicate with it but I need that view to redirect away right after starting the process.</p>
<p>I've tried using <code>subprocess.Popen</code>, using it within a new <code>threading.Thread</code>, <cod... | 12 | 2009-10-24T22:42:11Z | 1,619,595 | <p><a href="http://code.google.com/p/django-command-extensions/wiki/JobsScheduling" rel="nofollow">http://code.google.com/p/django-command-extensions/wiki/JobsScheduling</a></p>
<p>Is a nice library that that you can use to accomplish this task.</p>
| 2 | 2009-10-25T00:29:16Z | [
"python",
"django",
"long-running-processes"
] |
How to start a long-running process from a Django view? | 1,619,397 | <p>I need to run a process that might take hours to complete from a Django view. I don't need to know the state or communicate with it but I need that view to redirect away right after starting the process.</p>
<p>I've tried using <code>subprocess.Popen</code>, using it within a new <code>threading.Thread</code>, <cod... | 12 | 2009-10-24T22:42:11Z | 1,620,571 | <p>First of all - try to using cron for you task, as early say shanyu. </p>
<p>If it doesn't suit you - then try to use <a href="http://www.celeryproject.org/">CeleryProject</a>, for task Queue for Django. For working it uses <a href="http://www.rabbitmq.com/">RabbitMQ</a>. And here is a little <a href="http://www.cel... | 5 | 2009-10-25T10:36:05Z | [
"python",
"django",
"long-running-processes"
] |
How to start a long-running process from a Django view? | 1,619,397 | <p>I need to run a process that might take hours to complete from a Django view. I don't need to know the state or communicate with it but I need that view to redirect away right after starting the process.</p>
<p>I've tried using <code>subprocess.Popen</code>, using it within a new <code>threading.Thread</code>, <cod... | 12 | 2009-10-24T22:42:11Z | 1,620,605 | <p>Take a look at the code in kronos.py to see one solution to this problem.</p>
<p><a href="http://www.razorvine.net/download/kronos.py" rel="nofollow">http://www.razorvine.net/download/kronos.py</a></p>
| 2 | 2009-10-25T10:48:26Z | [
"python",
"django",
"long-running-processes"
] |
python import error | 1,619,469 | <p>I'm trying to use some python-2.1 code to control another program (ArcGIS). The version of python I am using is 2.5. I am getting the following error message when I run the code.</p>
<pre><code><type'exceptions.ImportError'>: No module named win32api
Failed to execute (polyline2geonetwork2).
</code></pre>
<p... | 4 | 2009-10-24T23:20:12Z | 1,619,504 | <p>print out <code>sys.path</code> right before the import and make sure the path to <code>win32com</code> is in there</p>
| 1 | 2009-10-24T23:36:31Z | [
"python",
"import",
"python-2.5",
"python-2.1"
] |
python import error | 1,619,469 | <p>I'm trying to use some python-2.1 code to control another program (ArcGIS). The version of python I am using is 2.5. I am getting the following error message when I run the code.</p>
<pre><code><type'exceptions.ImportError'>: No module named win32api
Failed to execute (polyline2geonetwork2).
</code></pre>
<p... | 4 | 2009-10-24T23:20:12Z | 1,619,563 | <p>everybody please read the error message: "No module named <strong>win32api</strong>" i.e. not win32com</p>
<p>Put some diagnostic stuff up the top of your script, e.g.</p>
<pre><code>import sys
print sys.version
print sys.path
print sys.argv[0]
</code></pre>
<p>and cut the rest of your script down to the minimum ... | 0 | 2009-10-25T00:12:05Z | [
"python",
"import",
"python-2.5",
"python-2.1"
] |
python import error | 1,619,469 | <p>I'm trying to use some python-2.1 code to control another program (ArcGIS). The version of python I am using is 2.5. I am getting the following error message when I run the code.</p>
<pre><code><type'exceptions.ImportError'>: No module named win32api
Failed to execute (polyline2geonetwork2).
</code></pre>
<p... | 4 | 2009-10-24T23:20:12Z | 1,619,711 | <p>Your sys.path is </p>
<pre><code>['C:\\Documents and Settings\\david\\My Documents\\GIS_References\\public\\funconn_public', 'C:\\Python25\\Lib\\idlelib', 'C:\\Program Files\\ArcGIS\\bin', 'C:\\WINDOWS\\system32\\python25.zip', 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win', 'C:\\Python25\... | 2 | 2009-10-25T01:40:40Z | [
"python",
"import",
"python-2.5",
"python-2.1"
] |
with python's win32com and parsing html problem | 1,619,489 | <p>I'm new to python. I want to extract some text from the CNN website.<br>
I want to use python win32com module.<br>
<strong>EDIT</strong>: on [why win32com]<br>
Because of javascript in website... I thought of using win32com; I have looked for other solution but without success in regard to my requirement. In fact, I... | 0 | 2009-10-24T23:29:23Z | 1,619,520 | <p>Are you trying to parse some text on cnn's web site?</p>
<p>You can get the page with</p>
<pre><code>import urllib
f = urllib.urlopen('http://www.cnn.com')
page = f.read()
f.close()
</code></pre>
<p>You can then use BeautifulSoup to find whatever it is you are looking for on page.</p>
<p>Why win32com, dispatch, ... | 1 | 2009-10-24T23:43:44Z | [
"python",
"parsing"
] |
How to extract the member from single-member set in python? | 1,619,514 | <p>I recently encountered a scenario in which if a set only contained a single element, I wanted to do something with that element. To get the element, I settled on this approach:</p>
<pre><code>element = list(myset)[0]
</code></pre>
<p>But this isn't very satisfying, as it creates an unnecessary list. It could als... | 30 | 2009-10-24T23:41:50Z | 1,619,539 | <p>tuple unpacking works.</p>
<pre><code>(element,) = myset
</code></pre>
<p>(By the way, python-dev has explored but rejected the addition of myset.get() to return an arbitrary element from a set. <a href="http://mail.python.org/pipermail/python-dev/2009-October/093227.html">Discussion here</a>, Guido van Rossum ans... | 42 | 2009-10-24T23:54:15Z | [
"python",
"set"
] |
How to extract the member from single-member set in python? | 1,619,514 | <p>I recently encountered a scenario in which if a set only contained a single element, I wanted to do something with that element. To get the element, I settled on this approach:</p>
<pre><code>element = list(myset)[0]
</code></pre>
<p>But this isn't very satisfying, as it creates an unnecessary list. It could als... | 30 | 2009-10-24T23:41:50Z | 1,619,544 | <p>you can use <code>element = tuple(myset)[0]</code> which is a bit more efficient, or, you can do something like </p>
<pre><code>element = iter(myset).next()
</code></pre>
<p>I guess constructing an iterator is more efficient than constructing a tuple/list.</p>
| 2 | 2009-10-24T23:59:05Z | [
"python",
"set"
] |
How to extract the member from single-member set in python? | 1,619,514 | <p>I recently encountered a scenario in which if a set only contained a single element, I wanted to do something with that element. To get the element, I settled on this approach:</p>
<pre><code>element = list(myset)[0]
</code></pre>
<p>But this isn't very satisfying, as it creates an unnecessary list. It could als... | 30 | 2009-10-24T23:41:50Z | 1,620,320 | <p>Between making a tuple and making an iterator, it's almost a wash, but iteration wins by a nose...:</p>
<pre><code>$ python2.6 -mtimeit -s'x=set([1])' 'a=tuple(x)[0]'
1000000 loops, best of 3: 0.465 usec per loop
$ python2.6 -mtimeit -s'x=set([1])' 'a=tuple(x)[0]'
1000000 loops, best of 3: 0.465 usec per loop
$ pyt... | 17 | 2009-10-25T08:05:16Z | [
"python",
"set"
] |
How to extract the member from single-member set in python? | 1,619,514 | <p>I recently encountered a scenario in which if a set only contained a single element, I wanted to do something with that element. To get the element, I settled on this approach:</p>
<pre><code>element = list(myset)[0]
</code></pre>
<p>But this isn't very satisfying, as it creates an unnecessary list. It could als... | 30 | 2009-10-24T23:41:50Z | 4,486,544 | <p>I reckon <a href="http://stackoverflow.com/questions/1619514/how-to-extract-the-member-from-single-member-set-in-python/1619539#1619539">kaizer.se's answer</a> is great. But if your set <em>might</em> contain more than one element, and you want a not-so-arbitrary element, you might want to use <a href="http://docs.p... | 9 | 2010-12-20T02:59:07Z | [
"python",
"set"
] |
Using Python Regular Expression in Django | 1,619,554 | <p>I have an web address:</p>
<p><a href="http://www.example.com/org/companyA">http://www.example.com/org/companyA</a></p>
<p>I want to be able to pass CompanyA to a view using regular expressions. </p>
<p>This is what I have:</p>
<pre><code>(r'^org/?P<company_name>\w+/$',"orgman.views.orgman")
</code></pre>... | 8 | 2009-10-25T00:08:20Z | 1,619,578 | <p>It should look more like <code>r'^org/(?P<company_name>\w+)'</code></p>
<pre><code>>>> r = re.compile(r'^org/(?P<company_name>\w+)')
>>> r.match('org/companyA').groups()
('companyA',)
</code></pre>
| 1 | 2009-10-25T00:19:17Z | [
"python",
"regex",
"django",
"django-urls"
] |
Using Python Regular Expression in Django | 1,619,554 | <p>I have an web address:</p>
<p><a href="http://www.example.com/org/companyA">http://www.example.com/org/companyA</a></p>
<p>I want to be able to pass CompanyA to a view using regular expressions. </p>
<p>This is what I have:</p>
<pre><code>(r'^org/?P<company_name>\w+/$',"orgman.views.orgman")
</code></pre>... | 8 | 2009-10-25T00:08:20Z | 1,619,580 | <p>Your regex isn't valid. It should probably look like</p>
<pre><code>r'^org/(?P<company_name>\w+)/$'
</code></pre>
| 2 | 2009-10-25T00:20:15Z | [
"python",
"regex",
"django",
"django-urls"
] |
Using Python Regular Expression in Django | 1,619,554 | <p>I have an web address:</p>
<p><a href="http://www.example.com/org/companyA">http://www.example.com/org/companyA</a></p>
<p>I want to be able to pass CompanyA to a view using regular expressions. </p>
<p>This is what I have:</p>
<pre><code>(r'^org/?P<company_name>\w+/$',"orgman.views.orgman")
</code></pre>... | 8 | 2009-10-25T00:08:20Z | 1,619,583 | <p>You need to wrap the group name in parentheses. The syntax for named groups is <code>(?P<name>regex)</code>, not <code>?P<name>regex</code>. Also, if you don't want to require a trailing slash, you should make it optional.</p>
<p>It's easy to test regular expression matching with the Python interpreter... | 17 | 2009-10-25T00:20:42Z | [
"python",
"regex",
"django",
"django-urls"
] |
Problems using PyQt's Resource System | 1,619,574 | <p>I am trying to use PyQt's Resource System but it appears I have no clue what I am doing! I already have to application created, along with its GUI I am just trying to import some images to use with the program.</p>
<p>I used the QtDesigner to create the resource file and I compiled it using pyrcc4.exe. But when I a... | 4 | 2009-10-25T00:18:55Z | 1,658,244 | <p>pyrcc generates Python 2.x code by default.</p>
<p>Try regenerating your resource files using pyrcc with flag '-py3'</p>
| 16 | 2009-11-01T20:39:50Z | [
"python",
"pyqt",
"pyqt4"
] |
Extracting decimals from a number in Python | 1,619,818 | <p>I am writing a function to extract decimals from a number. Ignore the exception and its syntax, I am working on 2.5.2 (default Leopard version). My function does not yet handle 0's. My issue is, the function produces random errors with certain numbers, and I don't understand the reason. I will post an error readout ... | 1 | 2009-10-25T02:39:24Z | 1,619,861 | <p>The problem is that (binary) floating point numbers aren't precisely representable as decimals. See <a href="http://stackoverflow.com/questions/1089018/why-cant-decimal-numbers-be-represented-exactly-in-binary">http://stackoverflow.com/questions/1089018/why-cant-decimal-numbers-be-represented-exactly-in-binary</a> ... | 5 | 2009-10-25T02:58:02Z | [
"python",
"python-2.5"
] |
Extracting decimals from a number in Python | 1,619,818 | <p>I am writing a function to extract decimals from a number. Ignore the exception and its syntax, I am working on 2.5.2 (default Leopard version). My function does not yet handle 0's. My issue is, the function produces random errors with certain numbers, and I don't understand the reason. I will post an error readout ... | 1 | 2009-10-25T02:39:24Z | 1,619,881 | <p>As Ned Batchelder said, not all decimals are exactly representable as floats. A float is represented by a certain number of binary digits which are used to approximate the decimal as closely as possible. You can never assume a float is exactly equal to a decimal.</p>
<pre><code>In [49]: num
Out[49]: 1.988
In [50]:... | 1 | 2009-10-25T03:07:43Z | [
"python",
"python-2.5"
] |
Extracting decimals from a number in Python | 1,619,818 | <p>I am writing a function to extract decimals from a number. Ignore the exception and its syntax, I am working on 2.5.2 (default Leopard version). My function does not yet handle 0's. My issue is, the function produces random errors with certain numbers, and I don't understand the reason. I will post an error readout ... | 1 | 2009-10-25T02:39:24Z | 1,619,906 | <p>As others have said in their answers, arithmetic with floats doesn't always result in what you expect due to rounding errors. In this case, perhaps converting the float into a string and back is better?</p>
<pre><code>In [1]: num = 1.988
In [2]: num_str = str(num)
In [3]: decimal = num_str.split('.')[1]
In [4]: ... | 0 | 2009-10-25T03:23:31Z | [
"python",
"python-2.5"
] |
Extracting decimals from a number in Python | 1,619,818 | <p>I am writing a function to extract decimals from a number. Ignore the exception and its syntax, I am working on 2.5.2 (default Leopard version). My function does not yet handle 0's. My issue is, the function produces random errors with certain numbers, and I don't understand the reason. I will post an error readout ... | 1 | 2009-10-25T02:39:24Z | 1,619,909 | <p>As others have already pointed out, the issue you are seeing is due to the inexact representation of floating point numbers</p>
<p>Try your program with Python's <code>Decimal</code></p>
<pre><code>from decimal import Decimal
extractDecimals(Decimal("0.988"))
</code></pre>
| 1 | 2009-10-25T03:24:10Z | [
"python",
"python-2.5"
] |
Extracting decimals from a number in Python | 1,619,818 | <p>I am writing a function to extract decimals from a number. Ignore the exception and its syntax, I am working on 2.5.2 (default Leopard version). My function does not yet handle 0's. My issue is, the function produces random errors with certain numbers, and I don't understand the reason. I will post an error readout ... | 1 | 2009-10-25T02:39:24Z | 1,619,922 | <p>As has already been said, floating point numbers are not exactly equal to decimals. You can see this by using the modulus operator like so:</p>
<pre><code>>>> 0.988 % 1
0.98799999999999999
>>> 9.88 % 1
0.88000000000000078
>>> 98.8 % 1
0.79999999999999716
</code></pre>
<p>This gives the r... | 1 | 2009-10-25T03:31:02Z | [
"python",
"python-2.5"
] |
name a column and then call items with name instead of index | 1,619,880 | <p>I have a list of columns that I will be analyzing. Instead of referring back to the specific index such as data[1][2], I'd like to assign a name to a column and then loop through the rows of the columns for different tasks. How do I assign a name to a column and then is this the correct format to refer back to it?... | 0 | 2009-10-25T03:07:22Z | 1,619,915 | <p>I believe what you want to do is store a column in a variable and then reference it, instead of always using the subscript. Simple enough:</p>
<pre><code>varName=data[columnName]
</code></pre>
<p>For consequent accesses to that column, <code>varName[rowName]</code> should do the trick</p>
| 0 | 2009-10-25T03:26:22Z | [
"python",
"names"
] |
name a column and then call items with name instead of index | 1,619,880 | <p>I have a list of columns that I will be analyzing. Instead of referring back to the specific index such as data[1][2], I'd like to assign a name to a column and then loop through the rows of the columns for different tasks. How do I assign a name to a column and then is this the correct format to refer back to it?... | 0 | 2009-10-25T03:07:22Z | 1,620,021 | <p>The easiest way to use names instead of integers to access your data is to use a dictionary</p>
<pre><code>data = {'pig':[1, 2], 'cow':[3, 4], 'dog':[5,6]}
if data in range(2):
if data['dog'][1]==4:...
</code></pre>
<p>There are other ways as well. For example, you could make a class and override <code>__get... | 2 | 2009-10-25T04:34:49Z | [
"python",
"names"
] |
name a column and then call items with name instead of index | 1,619,880 | <p>I have a list of columns that I will be analyzing. Instead of referring back to the specific index such as data[1][2], I'd like to assign a name to a column and then loop through the rows of the columns for different tasks. How do I assign a name to a column and then is this the correct format to refer back to it?... | 0 | 2009-10-25T03:07:22Z | 1,620,172 | <p>There's a bunch of different ways of doing this. If you know the association between names and columns at the time you write your code, the easiest way by far is this:</p>
<pre><code>for row in data:
(foo, bar, baz, bat) = row
</code></pre>
<p>...assuming that you don't need to update <code>row</code> (and <co... | 3 | 2009-10-25T06:25:11Z | [
"python",
"names"
] |
What is causing this Python exception? | 1,619,908 | <p>I have a C++ app that uses Python to load some scripts. It calls some functions in the scripts, and everything works fine until the app exits and calls Py_Finalize. Then it displays the following: (GetName is a function in one of the scripts)</p>
<p>Exception AttributeError: "'module' object has no attribute 'GetNa... | 2 | 2009-10-25T03:24:01Z | 1,619,944 | <p>From the docs to Py_Finalize():</p>
<blockquote>
<p>Bugs and caveats: The destruction of
modules and objects in modules is done
in random order; this may cause
destructors (<code>__del__()</code> methods) to
fail when they depend on other objects
(even functions) or modules.
Dynamically loaded extensi... | 4 | 2009-10-25T03:42:50Z | [
"python",
"exception",
"attributes"
] |
Are there any mature vector drawing libraries for Python? (that work on Windows) | 1,620,062 | <p>I've tried endlessly to get pycairo to work on Windows, but version 1.8.8 won't install. Is there something comparable out there that actually works on Windows?</p>
| 1 | 2009-10-25T05:03:56Z | 1,620,278 | <p>Have you tried the easy to use <a href="http://ftp.gnome.org/pub/GNOME/binaries/win32/pycairo/" rel="nofollow">PyCairo Installers for Windows</a> created by the PyGTK team?</p>
<p>In addition to the installer you will need <code>libcairo-2.dll</code> <code>libpng12.dll</code> and <code>zlib1.dll</code> and put them... | 3 | 2009-10-25T07:44:05Z | [
"python",
"drawing",
"svg",
"vector-graphics"
] |
Are there any mature vector drawing libraries for Python? (that work on Windows) | 1,620,062 | <p>I've tried endlessly to get pycairo to work on Windows, but version 1.8.8 won't install. Is there something comparable out there that actually works on Windows?</p>
| 1 | 2009-10-25T05:03:56Z | 1,623,339 | <p>maybe <a href="http://codeboje.de/pysvg/" rel="nofollow">pySVG</a> is something for you?!</p>
| 1 | 2009-10-26T06:19:07Z | [
"python",
"drawing",
"svg",
"vector-graphics"
] |
Are there any mature vector drawing libraries for Python? (that work on Windows) | 1,620,062 | <p>I've tried endlessly to get pycairo to work on Windows, but version 1.8.8 won't install. Is there something comparable out there that actually works on Windows?</p>
| 1 | 2009-10-25T05:03:56Z | 1,678,002 | <p>pyAmanith, a python wrapper for the commercial Amanith implementation of the OpenVG spec, might be what you're looking for. I don't know how mature the python wrapper is, but Amanith is pretty mature from what I've heard.</p>
| 0 | 2009-11-05T02:45:59Z | [
"python",
"drawing",
"svg",
"vector-graphics"
] |
In Django, how to clear all the memcached keys and values? | 1,620,072 | <p>I don't want to restart the memcached server!</p>
| 14 | 2009-10-25T05:11:27Z | 1,620,084 | <pre><code>from django.core.cache import cache
cache._cache.flush_all()
</code></pre>
<p>Also see this ticket, it has a patch (that I haven't tested) to flush any type of cache backend: <a href="http://code.djangoproject.com/ticket/11503">http://code.djangoproject.com/ticket/11503</a></p>
| 31 | 2009-10-25T05:31:07Z | [
"python",
"django",
"caching",
"memcached"
] |
In Django, how can I embed something in CSS? | 1,620,122 | <pre><code>background: url({{ MEDIA_URL }}/bg.jpg);
</code></pre>
<p>That does not work, because this Django template function only works in .html!</p>
| 0 | 2009-10-25T05:49:39Z | 1,620,180 | <blockquote>
<p>Django template function only works in .html!</p>
</blockquote>
<p>This is totally wrong. Django templates are independent of the format. It can be easily used on any other format, infact for many other purposes.</p>
<blockquote>
<p>how can I embed something in CSS?</p>
</blockquote>
<p>You serve... | 9 | 2009-10-25T06:28:57Z | [
"python",
"css",
"django",
"templates"
] |
In Django, how can I embed something in CSS? | 1,620,122 | <pre><code>background: url({{ MEDIA_URL }}/bg.jpg);
</code></pre>
<p>That does not work, because this Django template function only works in .html!</p>
| 0 | 2009-10-25T05:49:39Z | 1,620,183 | <p>Actualy image in CSS can be relative to the CSS file.
So you don't really need to put the MEDIA_URL in a CSS file.</p>
| 9 | 2009-10-25T06:34:42Z | [
"python",
"css",
"django",
"templates"
] |
Sankey diagrams in Python | 1,620,125 | <p>Is there a Python library for generating <a href="http://en.wikipedia.org/wiki/Sankey_diagram" rel="nofollow">Sankey diagrams</a>? </p>
<p>I've seen this <a href="http://www.sankey-diagrams.com/sankey-diagram-software/" rel="nofollow">list of Sankey diagram applications and libraries</a>, but none of them is in Pyt... | 8 | 2009-10-25T05:51:11Z | 1,620,307 | <p>I did a Google search on "Python graph visualization" and found some stuff. There are several libraries that have "spring" behavior where the software balances out a graph and makes it pretty; they do much of the work for you. But they draw graph diagrams, with nodes and edges, nothing like a Sankey diagram.</p>
... | 2 | 2009-10-25T08:00:11Z | [
"python",
"graph",
"visualization",
"diagram",
"sankey-diagram"
] |
Sankey diagrams in Python | 1,620,125 | <p>Is there a Python library for generating <a href="http://en.wikipedia.org/wiki/Sankey_diagram" rel="nofollow">Sankey diagrams</a>? </p>
<p>I've seen this <a href="http://www.sankey-diagrams.com/sankey-diagram-software/" rel="nofollow">list of Sankey diagram applications and libraries</a>, but none of them is in Pyt... | 8 | 2009-10-25T05:51:11Z | 7,757,985 | <p>Apparently matplotlib 1.1 can now do this. <a href="http://matplotlib.sourceforge.net/examples/api/sankey_demo_basics.html#api-sankey-demo-basics" rel="nofollow">Code and sample output is here</a>.</p>
<p>Below is a screenshot demonstrating what it can do.</p>
<p><img src="http://i.stack.imgur.com/KAbwS.png" alt="... | 6 | 2011-10-13T17:27:40Z | [
"python",
"graph",
"visualization",
"diagram",
"sankey-diagram"
] |
str.format(list) with negative index doesn't work in Python | 1,620,237 | <p>I use a negative index in replacement fields to output a formatted list,but it raises a TypeError.The codes are as follows:</p>
<pre>
>>> a=[1,2,3]
>>> a[2]
3
>>> a[-1]
3
>>> 'The last:{0[2]}'.format(a)
'The last:3'
>>> 'The last:{0[-1]}'.format(a)
Traceback (most recent call last):
File "", line 1, in
TypeError... | 8 | 2009-10-25T07:16:17Z | 1,620,294 | <p>It's what I would call a design glitch in the format string specs. Per <a href="http://docs.python.org/library/string.html#format-string-syntax" rel="nofollow">the docs</a>,</p>
<pre><code>element_index ::= integer | index_string
</code></pre>
<p>but, alas, <code>-1</code> is not "an integer" -- it's an expr... | 11 | 2009-10-25T07:51:08Z | [
"python",
"string",
"formatting"
] |
str.format(list) with negative index doesn't work in Python | 1,620,237 | <p>I use a negative index in replacement fields to output a formatted list,but it raises a TypeError.The codes are as follows:</p>
<pre>
>>> a=[1,2,3]
>>> a[2]
3
>>> a[-1]
3
>>> 'The last:{0[2]}'.format(a)
'The last:3'
>>> 'The last:{0[-1]}'.format(a)
Traceback (most recent call last):
File "", line 1, in
TypeError... | 8 | 2009-10-25T07:16:17Z | 1,620,465 | <p>There are a few problems here, once you start digging:</p>
<p>The item in question is called "element_index" which is defined to be an integer.</p>
<p>Problem 1: unless users follow the link from "integer" to the language reference manual, they won't know that -1 is deemed to be an expression, not an integer. By t... | 1 | 2009-10-25T09:34:39Z | [
"python",
"string",
"formatting"
] |
str.format(list) with negative index doesn't work in Python | 1,620,237 | <p>I use a negative index in replacement fields to output a formatted list,but it raises a TypeError.The codes are as follows:</p>
<pre>
>>> a=[1,2,3]
>>> a[2]
3
>>> a[-1]
3
>>> 'The last:{0[2]}'.format(a)
'The last:3'
>>> 'The last:{0[-1]}'.format(a)
Traceback (most recent call last):
File "", line 1, in
TypeError... | 8 | 2009-10-25T07:16:17Z | 1,620,482 | <p>Correct, it does not work. solution:</p>
<pre><code>>>> 'The last:{0}'.format(a[-1])
'The last:3'
</code></pre>
| 1 | 2009-10-25T09:54:00Z | [
"python",
"string",
"formatting"
] |
Python: advantages and disvantages of _mysql vs MySQLdb? | 1,620,575 | <p>Two libraries for Mysql.
I've always used _mysql because it's simpler. </p>
<p>Can anyone tell me the difference, and why I should use which one in certain occasions?</p>
| 9 | 2009-10-25T10:37:00Z | 1,620,609 | <p>MySQLdb uses DB-API (described in <a href="http://www.python.org/dev/peps/pep-0249/">PEP 249</a>) which should be preferred, since it's common to all database drivers. IMHO there is no advantage in going low-level with <code>_mysql</code>. I'd rather think of using higher level libraries, like <a href="http://sqlalc... | 13 | 2009-10-25T10:49:40Z | [
"python",
"mysql"
] |
Python: advantages and disvantages of _mysql vs MySQLdb? | 1,620,575 | <p>Two libraries for Mysql.
I've always used _mysql because it's simpler. </p>
<p>Can anyone tell me the difference, and why I should use which one in certain occasions?</p>
| 9 | 2009-10-25T10:37:00Z | 1,620,642 | <p>_mysql is the one-to-one mapping of the rough mysql API. On top of it, the DB-API is built, handling things using cursors and so on. </p>
<p>If you are used to the low-level mysql API provided by libmysqlclient, then the _mysql module is what you need, but as another answer says, there's no real need to go so low-l... | 3 | 2009-10-25T11:07:06Z | [
"python",
"mysql"
] |
Python: advantages and disvantages of _mysql vs MySQLdb? | 1,620,575 | <p>Two libraries for Mysql.
I've always used _mysql because it's simpler. </p>
<p>Can anyone tell me the difference, and why I should use which one in certain occasions?</p>
| 9 | 2009-10-25T10:37:00Z | 1,666,697 | <p>Alternatively, you can use <a href="https://launchpad.net/myconnpy">MySQL Connector/Python</a>:</p>
<blockquote>
<p>MySQL Connector/Python is implementing the MySQL Client/Server protocol completely in Python. This means you don't have to compile anything or MySQL doesn't even have to be installed on the machine.... | 8 | 2009-11-03T11:15:41Z | [
"python",
"mysql"
] |
Installing satchmo without ssh access | 1,620,620 | <p>I want to install satchmo in my virtual hosting, but they dont provide ssh access for it. I want to know if it is possible. As i can see, adding some Satchmo requirements(<a href="http://www.satchmoproject.com/docs/svn/requirements.html" rel="nofollow">http://www.satchmoproject.com/docs/svn/requirements.html</a>) to... | 0 | 2009-10-25T10:55:49Z | 1,620,626 | <p>i doubt you can install only over web (e.g. what about permissions - maybe some could be set over ftp, but other not)</p>
<p>is it possible to ask your hosting provider to include satchmo in their services?</p>
| 0 | 2009-10-25T10:58:57Z | [
"python",
"django",
"ssh",
"satchmo"
] |
Installing satchmo without ssh access | 1,620,620 | <p>I want to install satchmo in my virtual hosting, but they dont provide ssh access for it. I want to know if it is possible. As i can see, adding some Satchmo requirements(<a href="http://www.satchmoproject.com/docs/svn/requirements.html" rel="nofollow">http://www.satchmoproject.com/docs/svn/requirements.html</a>) to... | 0 | 2009-10-25T10:55:49Z | 1,620,629 | <p>Sure you can, In the past I wrote a cgi to download and build Python on hosting that only allowed ftp access.</p>
<p>If you know the target platform it will be easier to set up a virtual machine locally, build the files you need there and upload the compiled versions. Make sure you statically link them if the hosti... | 1 | 2009-10-25T11:00:06Z | [
"python",
"django",
"ssh",
"satchmo"
] |
Send and receive messages via (libpurple) messenger protocols | 1,620,793 | <p>I had an idea that would require me be able to send and receive messages via the standard messenger protocols such as msn, icq, aim, skype, etc...</p>
<p>I am currently only familiar with PHP and Python and would thus enjoy a library which I can access from said languages. I have found phurple (<a href="http://sour... | 4 | 2009-10-25T12:36:26Z | 1,620,832 | <p>A good bet would be to go through the DBus interface: Pidgin (purple) fully supports it and the DBus interface library for Python is quite stable.</p>
| 2 | 2009-10-25T12:52:09Z | [
"php",
"python",
"libpurple"
] |
Send and receive messages via (libpurple) messenger protocols | 1,620,793 | <p>I had an idea that would require me be able to send and receive messages via the standard messenger protocols such as msn, icq, aim, skype, etc...</p>
<p>I am currently only familiar with PHP and Python and would thus enjoy a library which I can access from said languages. I have found phurple (<a href="http://sour... | 4 | 2009-10-25T12:36:26Z | 1,652,156 | <p>Here is how to connect to the Pidgin DBus server.</p>
<pre><code>#!/usr/bin/env python
import dbus
bus = dbus.SessionBus()
if "im.pidgin.purple.PurpleService" in bus.list_names():
purple = bus.get_object("im.pidgin.purple.PurpleService",
"/im/pidgin/purple/PurpleObject",
"im.pidgin.pur... | 11 | 2009-10-30T20:35:44Z | [
"php",
"python",
"libpurple"
] |
Send and receive messages via (libpurple) messenger protocols | 1,620,793 | <p>I had an idea that would require me be able to send and receive messages via the standard messenger protocols such as msn, icq, aim, skype, etc...</p>
<p>I am currently only familiar with PHP and Python and would thus enjoy a library which I can access from said languages. I have found phurple (<a href="http://sour... | 4 | 2009-10-25T12:36:26Z | 1,670,685 | <p>I use <a href="http://www.ustrem.org/en/articles/webicqlite-icq-with-php-en/" rel="nofollow">WebIcqLite: ICQ messages sender</a> for the ICQ protocol. It works and the class is easy to understand. I don't know about other protocols, though. What's wrong with the Phurple library?</p>
| 0 | 2009-11-03T22:55:14Z | [
"php",
"python",
"libpurple"
] |
Send and receive messages via (libpurple) messenger protocols | 1,620,793 | <p>I had an idea that would require me be able to send and receive messages via the standard messenger protocols such as msn, icq, aim, skype, etc...</p>
<p>I am currently only familiar with PHP and Python and would thus enjoy a library which I can access from said languages. I have found phurple (<a href="http://sour... | 4 | 2009-10-25T12:36:26Z | 1,672,150 | <p>If you decompress the file from phurple you get some example like this:</p>
<pre><code><?php
if(!extension_loaded('phurple')) {
dl('phurple.' . PHP_SHLIB_SUFFIX);
}
class CustomPhurpleClient extends PhurpleClient {
private $someVar;
protected function initInternal() {
$this->someVar = "H... | 1 | 2009-11-04T07:15:58Z | [
"php",
"python",
"libpurple"
] |
Python script to print all function definitions of a C/C++ file | 1,620,851 | <p>I want a python script to print list of all functions defined in a C/C++ file.</p>
<p>e.g. <code>abc.c</code> defines two functions as:</p>
<pre><code>void func1() { }
int func2(int i) { printf("%d", i); return 1; }
</code></pre>
<p>I just want to search the file (<code>abc.c</code>) and print all the functions d... | 3 | 2009-10-25T12:59:17Z | 1,620,887 | <p><a href="http://www.antlr.org/" rel="nofollow">antlr</a> is your tool</p>
| 2 | 2009-10-25T13:13:41Z | [
"python",
"parsing",
"string"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.