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 |
|---|---|---|---|---|---|---|---|---|---|
App dock icon in wxPython | 824,458 | <p>In wxPython on Mac OS X is it possible to display a custom icon when an application is launched. Right now when I launch the app I wrote, a blank white icon is displayed in the dock. How would I go about changing it?</p>
| 1 | 2009-05-05T11:25:19Z | 824,475 | <p>I have this in my setup file to add an icon:</p>
<pre><code>from setuptools import setup
APP = ['MyApp.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True,
'iconfile': 'MyAppIcon.icns' }
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
</code... | 1 | 2009-05-05T11:30:43Z | [
"python",
"osx",
"wxpython"
] |
Initialisation of keyword args in Python | 824,924 | <p>Why does the following:</p>
<pre><code>class A(object):
def __init__(self, var=[]):
self._var = var
print 'var = %s %s' % (var, id(var))
a1 = A()
a1._var.append('one')
a2 = A()
</code></pre>
<p>result in:</p>
<pre><code>var = [] 182897439952
var = ['one'] 182897439952
</code></pre>
<p>I don't und... | 0 | 2009-05-05T13:47:27Z | 824,943 | <p>The empty list in your function definition is created once, at the time the function itself is created. It isn't created every time the function is called.</p>
<p>If you want a new one each time, do this:</p>
<pre><code>class A(object):
def __init__(self, var=None):
if var is None:
var = [... | 6 | 2009-05-05T13:51:21Z | [
"python",
"initialization",
"arguments",
"instantiation"
] |
Initialisation of keyword args in Python | 824,924 | <p>Why does the following:</p>
<pre><code>class A(object):
def __init__(self, var=[]):
self._var = var
print 'var = %s %s' % (var, id(var))
a1 = A()
a1._var.append('one')
a2 = A()
</code></pre>
<p>result in:</p>
<pre><code>var = [] 182897439952
var = ['one'] 182897439952
</code></pre>
<p>I don't und... | 0 | 2009-05-05T13:47:27Z | 824,951 | <p>This is simply wrong. You can't (meaningfully) provide a mutable object as a default value in a function declaration.</p>
<pre><code>class A(object):
def __init__(self, var=[]):
self._var = var
print 'var = %s %s' % (var, id(var))
</code></pre>
<p>You must do something like this.</p>
<pre><co... | 2 | 2009-05-05T13:52:56Z | [
"python",
"initialization",
"arguments",
"instantiation"
] |
Initialisation of keyword args in Python | 824,924 | <p>Why does the following:</p>
<pre><code>class A(object):
def __init__(self, var=[]):
self._var = var
print 'var = %s %s' % (var, id(var))
a1 = A()
a1._var.append('one')
a2 = A()
</code></pre>
<p>result in:</p>
<pre><code>var = [] 182897439952
var = ['one'] 182897439952
</code></pre>
<p>I don't und... | 0 | 2009-05-05T13:47:27Z | 824,964 | <blockquote>
<p>The empty list in your function definition is created once, at the time the function itself is created. It isn't created every time the function is called.</p>
</blockquote>
<p>Exactly. To work around this assign None int he function definiton and check for None in the function body:</p>
<pre><code>... | 1 | 2009-05-05T13:55:20Z | [
"python",
"initialization",
"arguments",
"instantiation"
] |
Why in the world does Python's Tkinter break using canvas.create_image? | 824,988 | <p>I've got a python GUI app in the workings, which I intend to use on both Windows and Mac. The documentation on Tkinter isn't the greatest, and google-fu has failed me.</p>
<p>In short, I'm doing:</p>
<pre><code>c = Canvas(
master=frame,
width=settings.WINDOW_SIZE[0],
height=settings.WINDOW_SIZE[1],
... | 1 | 2009-05-05T13:59:47Z | 825,493 | <p>Short answer:
Don't use create_bitmap when you mean to use create_image.</p>
| 2 | 2009-05-05T15:41:44Z | [
"python",
"python-imaging-library",
"tkinter",
"tk"
] |
Why in the world does Python's Tkinter break using canvas.create_image? | 824,988 | <p>I've got a python GUI app in the workings, which I intend to use on both Windows and Mac. The documentation on Tkinter isn't the greatest, and google-fu has failed me.</p>
<p>In short, I'm doing:</p>
<pre><code>c = Canvas(
master=frame,
width=settings.WINDOW_SIZE[0],
height=settings.WINDOW_SIZE[1],
... | 1 | 2009-05-05T13:59:47Z | 825,632 | <p>Tk has two types of graphics, bitmap and image. Images come in two flavours, bitmap and photo. Bitmaps and Images of type bitmap are not the same thing, which leads to confusion in docs.
PhotoImage creates an image of type photo, and needs an image object in the canvas, so the solution is, as you already concluded, ... | 4 | 2009-05-05T16:05:38Z | [
"python",
"python-imaging-library",
"tkinter",
"tk"
] |
Why in the world does Python's Tkinter break using canvas.create_image? | 824,988 | <p>I've got a python GUI app in the workings, which I intend to use on both Windows and Mac. The documentation on Tkinter isn't the greatest, and google-fu has failed me.</p>
<p>In short, I'm doing:</p>
<pre><code>c = Canvas(
master=frame,
width=settings.WINDOW_SIZE[0],
height=settings.WINDOW_SIZE[1],
... | 1 | 2009-05-05T13:59:47Z | 828,469 | <p>The <code>create_bitmap()</code> method does not have an <code>image</code> argument; it has a <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/create%5Fbitmap.html" rel="nofollow"><code>bitmap</code></a> argument instead.</p>
<p>The error you get comes from the fact that in Tkinter, a Tcl interpreter is runn... | 0 | 2009-05-06T07:44:52Z | [
"python",
"python-imaging-library",
"tkinter",
"tk"
] |
How do you make the Python Msqldb module use ? in stead of %s for query parameters? | 825,042 | <p>MySqlDb is a fantastic Python module -- but one part is incredibly annoying.
Query parameters look like this</p>
<pre><code>cursor.execute("select * from Books where isbn=%s", (isbn,))
</code></pre>
<p>whereas everywhere else in the known universe (oracle, sqlserver, access, sybase...)
they look like this</p>
<pr... | 3 | 2009-05-05T14:10:36Z | 825,064 | <p>I found a lot of information out there about <code>paramstyle</code> that seemed to imply it might be what you wanted, but <a href="http://helpful.knobs-dials.com/index.php/Python%5Fnotes/Databases#parameters.2C%5Fparamstyle" rel="nofollow">according to this wiki</a> you have to use the <code>paramstyle</code> your ... | 2 | 2009-05-05T14:15:20Z | [
"python",
"sql",
"mysql",
"database"
] |
How do you make the Python Msqldb module use ? in stead of %s for query parameters? | 825,042 | <p>MySqlDb is a fantastic Python module -- but one part is incredibly annoying.
Query parameters look like this</p>
<pre><code>cursor.execute("select * from Books where isbn=%s", (isbn,))
</code></pre>
<p>whereas everywhere else in the known universe (oracle, sqlserver, access, sybase...)
they look like this</p>
<pr... | 3 | 2009-05-05T14:10:36Z | 825,073 | <p>I don't recommend doing this, but the simplest solution is to monkeypatch the <code>Cursor</code> class:</p>
<pre><code>from MySQLdb.cursors import Cursor
old_execute = Cursor.execute
def new_execute(self, query, args):
return old_execute(self, query.replace("?", "%s"), args)
Cursor.execute = new_execute
</code... | 1 | 2009-05-05T14:16:45Z | [
"python",
"sql",
"mysql",
"database"
] |
How do you make the Python Msqldb module use ? in stead of %s for query parameters? | 825,042 | <p>MySqlDb is a fantastic Python module -- but one part is incredibly annoying.
Query parameters look like this</p>
<pre><code>cursor.execute("select * from Books where isbn=%s", (isbn,))
</code></pre>
<p>whereas everywhere else in the known universe (oracle, sqlserver, access, sybase...)
they look like this</p>
<pr... | 3 | 2009-05-05T14:10:36Z | 1,151,575 | <p>From what I can see you cannot use '?' for a parameter marker with
MySQLdb (out of box)</p>
<p>you <strong>can</strong> however use named parameters</p>
<p>i.e. </p>
<pre><code>cursor.execute("%(param1)s = %(param1)s", {'param1':1})
</code></pre>
<p>would effectively execute
<code>1=1</code></p>
<p>in mysql</p>... | 2 | 2009-07-20T03:10:13Z | [
"python",
"sql",
"mysql",
"database"
] |
Change/adapt date widget on admin interface | 825,253 | <p>I'm configuring the admin site for my new app, and I found a little problem with my setup.</p>
<p>I have a 'birth date' field on my database editable via the admin site, but, the date widget isn't very handy for that, because it makes that, if I have to enter i.e. 01-04-1956 in the widget, i would have to page thro... | 2 | 2009-05-05T14:55:00Z | 825,343 | <p>Use the <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield%5Foverrides" rel="nofollow">formfield_overrides</a> option to use a different widget. For example (untested):</p>
<pre><code>class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
m... | 4 | 2009-05-05T15:11:46Z | [
"python",
"django",
"date",
"widget"
] |
Extract domain name from a host name | 825,694 | <p>Is there a programatic way to find the domain name from a given hostname?</p>
<p>given -> www.yahoo.co.jp
return -> yahoo.co.jp</p>
<p>The approach that works but is very slow is:</p>
<p>split on "." and remove 1 group from the left, join and query an SOA record using dnspython
when a valid SOA record is returne... | 15 | 2009-05-05T16:17:13Z | 825,738 | <p>You can use <a href="http://docs.python.org/library/stdtypes.html" rel="nofollow"><code>partition</code></a> instead of <code>split</code>:</p>
<pre><code>>>> 'www.yahoo.co.jp'.partition('.')[2]
'yahoo.co.jp'
</code></pre>
<p>This will help with the parsing but obviously won't check if the returned string... | 3 | 2009-05-05T16:26:17Z | [
"python",
"dns",
"hostname"
] |
Extract domain name from a host name | 825,694 | <p>Is there a programatic way to find the domain name from a given hostname?</p>
<p>given -> www.yahoo.co.jp
return -> yahoo.co.jp</p>
<p>The approach that works but is very slow is:</p>
<p>split on "." and remove 1 group from the left, join and query an SOA record using dnspython
when a valid SOA record is returne... | 15 | 2009-05-05T16:17:13Z | 828,380 | <p>There's no trivial definition of which "domain name" is the parent of any particular "host name".</p>
<p>Your current method of traversing up the tree until you see an <code>SOA</code> record is actually the most correct.</p>
<p>Technically, what you're doing there is finding a "zone cut", and in the vast majority... | 15 | 2009-05-06T07:09:22Z | [
"python",
"dns",
"hostname"
] |
Extract domain name from a host name | 825,694 | <p>Is there a programatic way to find the domain name from a given hostname?</p>
<p>given -> www.yahoo.co.jp
return -> yahoo.co.jp</p>
<p>The approach that works but is very slow is:</p>
<p>split on "." and remove 1 group from the left, join and query an SOA record using dnspython
when a valid SOA record is returne... | 15 | 2009-05-05T16:17:13Z | 828,397 | <p>Your algorithm is the right one. Since zone cuts are <strong>not</strong> reflected in the domain name (you see domain cuts - the dots - but not zone cuts), it is the only correct one.</p>
<p>An <strong>approximate</strong> algorithm is to use a list of zones, like the one mentioned by Alnitak. Remember that these ... | 1 | 2009-05-06T07:16:21Z | [
"python",
"dns",
"hostname"
] |
Extract domain name from a host name | 825,694 | <p>Is there a programatic way to find the domain name from a given hostname?</p>
<p>given -> www.yahoo.co.jp
return -> yahoo.co.jp</p>
<p>The approach that works but is very slow is:</p>
<p>split on "." and remove 1 group from the left, join and query an SOA record using dnspython
when a valid SOA record is returne... | 15 | 2009-05-05T16:17:13Z | 4,985,387 | <p>Whilst not in Python, you could port this code: <a href="http://pastebin.com/raw.php?i=VY3DCNhp" rel="nofollow">http://pastebin.com/raw.php?i=VY3DCNhp</a></p>
| -1 | 2011-02-13T16:37:58Z | [
"python",
"dns",
"hostname"
] |
Catch only some runtime errors in Python | 825,909 | <p>I'm importing a module which raises the following error in some conditions:
RuntimeError: pyparted requires root access</p>
<p>I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there a... | 5 | 2009-05-05T17:01:44Z | 825,931 | <pre><code>try:
import pyparted
except RuntimeError:
print('RuntimeError is raised')
raise
</code></pre>
<p>more on <a href="http://docs.python.org/tutorial/errors.html#handling-exceptions" rel="nofollow">exception handling in tutorial</a>.</p>
<p>This situation should produce <a href="http://docs.python.... | 4 | 2009-05-05T17:08:01Z | [
"python",
"exception-handling",
"try-catch",
"runtime-error"
] |
Catch only some runtime errors in Python | 825,909 | <p>I'm importing a module which raises the following error in some conditions:
RuntimeError: pyparted requires root access</p>
<p>I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there a... | 5 | 2009-05-05T17:01:44Z | 825,932 | <p>Yes.</p>
<pre><code> try:
import module
except RuntimeError:
pass
</code></pre>
<p>imports are interpreted as any other statement, they are not special. You could do an </p>
<pre><code>if condition:
import module
</code></pre>
| 1 | 2009-05-05T17:08:31Z | [
"python",
"exception-handling",
"try-catch",
"runtime-error"
] |
Catch only some runtime errors in Python | 825,909 | <p>I'm importing a module which raises the following error in some conditions:
RuntimeError: pyparted requires root access</p>
<p>I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there a... | 5 | 2009-05-05T17:01:44Z | 825,934 | <pre><code>try:
import ...
except RuntimeError:
# Do something
</code></pre>
| 1 | 2009-05-05T17:08:49Z | [
"python",
"exception-handling",
"try-catch",
"runtime-error"
] |
Catch only some runtime errors in Python | 825,909 | <p>I'm importing a module which raises the following error in some conditions:
RuntimeError: pyparted requires root access</p>
<p>I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there a... | 5 | 2009-05-05T17:01:44Z | 825,978 | <p>You can check attributes of the exception to differentiate from other possible <code>RuntimeError</code> exceptions. For example, re-raise the error if it does not match a predefined message text.</p>
<pre><code> try:
import pypatred
except RuntimeError,e:
if e.message == 'RuntimeError: pyparted re... | 6 | 2009-05-05T17:17:04Z | [
"python",
"exception-handling",
"try-catch",
"runtime-error"
] |
Catch only some runtime errors in Python | 825,909 | <p>I'm importing a module which raises the following error in some conditions:
RuntimeError: pyparted requires root access</p>
<p>I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there a... | 5 | 2009-05-05T17:01:44Z | 826,144 | <blockquote>
<p>I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there any way to differentiate between this RuntimeError and others that might be raised?</p>
</blockquote>
<p>If the error... | 6 | 2009-05-05T17:56:44Z | [
"python",
"exception-handling",
"try-catch",
"runtime-error"
] |
Catch only some runtime errors in Python | 825,909 | <p>I'm importing a module which raises the following error in some conditions:
RuntimeError: pyparted requires root access</p>
<p>I know that I can just check for root access before the import, but I'd like to know how to catch this spesific kind of error via a try/except statement for future reference. Is there a... | 5 | 2009-05-05T17:01:44Z | 16,558,265 | <p><a href="http://docs.python.org/2/library/exceptions.html#exceptions.RuntimeError" rel="nofollow">RuntimeError</a> Raised when an error is detected that doesnât fall in any of the other categories</p>
<pre><code>def foo():
try:
foo()
except RuntimeError, e:
print e
print " Runtime Error oc... | 0 | 2013-05-15T06:29:27Z | [
"python",
"exception-handling",
"try-catch",
"runtime-error"
] |
Abstract class + mixin + multiple inheritance in python | 825,945 | <p>So, I think the code probably explains what I'm trying to do better than I can in words, so here goes:</p>
<pre><code>import abc
class foo(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def bar(self):
pass
class bar_for_foo_mixin(object):
def bar(self):
print "This shoul... | 11 | 2009-05-05T17:10:43Z | 826,118 | <p>Shouldn't the inheritance be the other way round? In the MRO <code>foo</code> currently comes before <code>bar_for_foo_mixin</code>, and then rightfully complains. With <code>class myfoo(bar_for_foo_mixin, foo)</code> it should work.</p>
<p>And I am not sure if your class design is the right way to do it. Since you... | 12 | 2009-05-05T17:49:37Z | [
"python",
"abstract-class",
"multiple-inheritance",
"mixins"
] |
Abstract class + mixin + multiple inheritance in python | 825,945 | <p>So, I think the code probably explains what I'm trying to do better than I can in words, so here goes:</p>
<pre><code>import abc
class foo(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def bar(self):
pass
class bar_for_foo_mixin(object):
def bar(self):
print "This shoul... | 11 | 2009-05-05T17:10:43Z | 18,655,581 | <p>i think (tested in similar case) that reversing the baseclasses works: </p>
<pre><code>class myfoo(bar_for_foo_mixin, foo):
def __init__(self):
print "myfoo __init__ called"
self.bar()
</code></pre>
<p>so in the mro() it would find a concrete version of bar() before it finds the abstract one. N... | 0 | 2013-09-06T10:25:40Z | [
"python",
"abstract-class",
"multiple-inheritance",
"mixins"
] |
Changing case (upper/lower) on adding data through Django admin site | 825,955 | <p>I'm configuring the admin site of my new project, and I have a little doubt on how should I do for, on hitting 'Save' when adding data through the admin site, everything is converted to upper case...</p>
<p>Edit: Ok I know the .upper property, and I I did a view, I would know how to do it, but I'm wondering if ther... | 4 | 2009-05-05T17:11:49Z | 826,088 | <p>you have to <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-predefined-model-methods" rel="nofollow">override save()</a>. An example from the documentation:</p>
<pre><code>class Blog(models.Model):
name = models.CharField(max_length=100)
tagline = models.TextField()
def save... | 1 | 2009-05-05T17:40:47Z | [
"python",
"django",
"admin",
"case"
] |
Changing case (upper/lower) on adding data through Django admin site | 825,955 | <p>I'm configuring the admin site of my new project, and I have a little doubt on how should I do for, on hitting 'Save' when adding data through the admin site, everything is converted to upper case...</p>
<p>Edit: Ok I know the .upper property, and I I did a view, I would know how to do it, but I'm wondering if ther... | 4 | 2009-05-05T17:11:49Z | 826,126 | <p>If your goal is to only have things converted to upper case when saving in the admin section, you'll want to <a href="http://docs.djangoproject.com/en/dev/ref/contrib/admin/#adding-custom-validation-to-the-admin">create a form with custom validation</a> to make the case change:</p>
<pre><code>class MyArticleAdminFo... | 12 | 2009-05-05T17:52:51Z | [
"python",
"django",
"admin",
"case"
] |
Changing case (upper/lower) on adding data through Django admin site | 825,955 | <p>I'm configuring the admin site of my new project, and I have a little doubt on how should I do for, on hitting 'Save' when adding data through the admin site, everything is converted to upper case...</p>
<p>Edit: Ok I know the .upper property, and I I did a view, I would know how to do it, but I'm wondering if ther... | 4 | 2009-05-05T17:11:49Z | 10,072,776 | <p>Updated example from documentation suggests using args, kwargs to pass through as:</p>
<blockquote>
<p>Django will, from time to time, extend the capabilities of built-in
model methods, adding new arguments. If you use *args, **kwargs in
your method definitions, you are guaranteed that your code will
automa... | 2 | 2012-04-09T11:52:36Z | [
"python",
"django",
"admin",
"case"
] |
Python: finding uid/gid for a given username/groupname (for os.chown) | 826,082 | <p>What's a good way to find the uid/gid for a given username or groupname using Python? I need to set file ownership with os.chown and need the integer ids instead of the alphabetic.</p>
<p>[Quick note]: getpwnam works great but is not available on windows, so here's some code that creates stubs to allow you to run t... | 50 | 2009-05-05T17:39:54Z | 826,099 | <p>Use the <a href="http://docs.python.org/library/pwd.html"><code>pwd</code></a> and <a href="http://docs.python.org/library/grp.html"><code>grp</code></a> modules:</p>
<pre><code>from pwd import getpwnam
print getpwnam('someuser')[2]
# or
print getpwnam('someuser').pw_uid
</code></pre>
| 79 | 2009-05-05T17:43:19Z | [
"python"
] |
How do I convert a string 2 bytes long to an integer in python | 826,284 | <p>I have a python program I've inherited and am trying to extend.</p>
<p>I have extracted a two byte long string into a string called pS.</p>
<p>pS 1st byte is 0x01, the second is 0x20, decimal value == 288</p>
<p>I've been trying to get its value as an integer, I've used lines of the form</p>
<pre><code>x = int(p... | 4 | 2009-05-05T18:28:44Z | 826,305 | <p>Look at the <a href="http://www.python.org/doc/2.5.2/lib/module-struct.html">struct</a> module.</p>
<pre><code>struct.unpack( "h", pS[0:2] )
</code></pre>
<p>For a signed 2-byte value. Use "H" for unsigned.</p>
| 18 | 2009-05-05T18:33:17Z | [
"python"
] |
How do I convert a string 2 bytes long to an integer in python | 826,284 | <p>I have a python program I've inherited and am trying to extend.</p>
<p>I have extracted a two byte long string into a string called pS.</p>
<p>pS 1st byte is 0x01, the second is 0x20, decimal value == 288</p>
<p>I've been trying to get its value as an integer, I've used lines of the form</p>
<pre><code>x = int(p... | 4 | 2009-05-05T18:28:44Z | 826,308 | <p>You can convert the characters to their character code with <code>ord</code> and then add them together in the appropriate way:</p>
<pre><code>x = 256*ord(pS[0]) + ord(pS[1])
</code></pre>
| 4 | 2009-05-05T18:34:41Z | [
"python"
] |
List Comprehensions and Conditions? | 826,407 | <p>I am trying to see if I can make this code better using list comprehensions.<br>
Lets say that I have the following lists:</p>
<pre><code>a_list = [
'HELLO',
'FOO',
'FO1BAR',
'ROOBAR',
'SHOEBAR'
]
regex_list = [lambda x: re.search(r'FOO', x, re.IGNORECASE),
... | 7 | 2009-05-05T18:57:53Z | 826,430 | <p>Sure, I think this should do it</p>
<pre><code>newlist = [s for s in a_list if not any(r(s) for r in regex_list)]
</code></pre>
<p><em>EDIT</em>: on closer inspection, I notice that your example code actually adds to the new list each string in <code>a_list</code> that doesn't match <em>all</em> the regexes - and ... | 17 | 2009-05-05T19:02:28Z | [
"python",
"list",
"list-comprehension"
] |
List Comprehensions and Conditions? | 826,407 | <p>I am trying to see if I can make this code better using list comprehensions.<br>
Lets say that I have the following lists:</p>
<pre><code>a_list = [
'HELLO',
'FOO',
'FO1BAR',
'ROOBAR',
'SHOEBAR'
]
regex_list = [lambda x: re.search(r'FOO', x, re.IGNORECASE),
... | 7 | 2009-05-05T18:57:53Z | 826,471 | <p>I'd work your code down to this:</p>
<pre><code>a_list = [
'HELLO',
'FOO',
'FO1BAR',
'ROOBAR',
'SHOEBAR'
]
regex_func = lambda x: not re.search(r'(FOO|RO)', x, re.IGNORECASE)
</code></pre>
<p>Then you have two options:</p>
<ol>
<li><p>Filter</p>
<p>... | 0 | 2009-05-05T19:14:04Z | [
"python",
"list",
"list-comprehension"
] |
Python: Mixing files and loops | 826,493 | <p>I'm writing a script that logs errors from another program and restarts the program where it left off when it encounters an error. For whatever reasons, the developers of this program didn't feel it necessary to put this functionality into their program by default.</p>
<p>Anyways, the program takes an input file, p... | 17 | 2009-05-05T19:20:06Z | 826,518 | <p>Use <code>for</code> and <a href="http://docs.python.org/library/functions.html#enumerate">enumerate</a>.</p>
<p>Example:</p>
<pre><code>for line_num, line in enumerate(file):
if line_num < cut_off:
print line
</code></pre>
<p><strong>NOTE</strong>: This assumes you are already cleaning up your fil... | 10 | 2009-05-05T19:23:58Z | [
"python",
"file",
"loops",
"while-loop"
] |
Python: Mixing files and loops | 826,493 | <p>I'm writing a script that logs errors from another program and restarts the program where it left off when it encounters an error. For whatever reasons, the developers of this program didn't feel it necessary to put this functionality into their program by default.</p>
<p>Anyways, the program takes an input file, p... | 17 | 2009-05-05T19:20:06Z | 826,615 | <p>You get the ValueError because your code probably has <code>for line in original:</code> in addition to <code>original.readline()</code>. An easy solution which fixes the problem without making your program slower or consume more memory is changing</p>
<pre><code>for line in original:
...
</code></pre>
<p>to</... | 38 | 2009-05-05T19:47:25Z | [
"python",
"file",
"loops",
"while-loop"
] |
Python: Mixing files and loops | 826,493 | <p>I'm writing a script that logs errors from another program and restarts the program where it left off when it encounters an error. For whatever reasons, the developers of this program didn't feel it necessary to put this functionality into their program by default.</p>
<p>Anyways, the program takes an input file, p... | 17 | 2009-05-05T19:20:06Z | 828,525 | <p>Assuming you need only one line, this could be of help</p>
<pre><code>import itertools
def getline(fobj, line_no):
"Return a (1-based) line from a file object"
return itertools.islice(fobj, line_no-1, line_no).next() # 1-based!
>>> print getline(open("/etc/passwd", "r"), 4)
'adm:x:3:4:adm:/var/ad... | 0 | 2009-05-06T08:02:56Z | [
"python",
"file",
"loops",
"while-loop"
] |
Controlling VirtualBox via COM from Python? | 826,494 | <p>I'm trying to control latest Sun VirtualBox via it's COM interface from Python. But, unfortunately, the following code don't work:</p>
<pre><code>import win32com.client
VBOX_GUID = "{B1A7A4F2-47B9-4A1E-82B2-07CCD5323C3F}"
try :
oVbox = win32com.client.Dispatch( VBOX_GUID )
oVbox.FindMachine( "kubuntu" )
except ... | 0 | 2009-05-05T19:20:07Z | 829,495 | <p>The problem is that the object returned by <code>FindMachine("kubuntu")</code> does not support the <code>IDispatch interface</code>, and win32com does not support that.</p>
<p>You could use my <code>comtypes</code> package <a href="http://starship.python.net/crew/theller/comtypes/" rel="nofollow">http://starship.p... | 3 | 2009-05-06T13:15:24Z | [
"python",
"com",
"virtualbox"
] |
how to get the n-th record of a datastore query | 826,724 | <p>Suppose that I have the model Foo in GAE and this query:</p>
<p>query = Foo.all().order('-<strong>key</strong>')</p>
<p>I want to get the n-th record. What is the most efficient way to achieve that? </p>
<p>Will the solution break if the ordering property is not unique, such as the one below:</p>
<p>query = Foo.... | 1 | 2009-05-05T20:14:11Z | 827,114 | <p>Documentation for the Query class can be found at:
<a href="http://code.google.com/appengine/docs/python/datastore/queryclass.html#Query" rel="nofollow">http://code.google.com/appengine/docs/python/datastore/queryclass.html#Query</a></p>
<p>The query class provides fetch witch takes a limit and a offset
in your cas... | 2 | 2009-05-05T22:01:27Z | [
"python",
"google-app-engine",
"gae-datastore",
"custompaging"
] |
how to get the n-th record of a datastore query | 826,724 | <p>Suppose that I have the model Foo in GAE and this query:</p>
<p>query = Foo.all().order('-<strong>key</strong>')</p>
<p>I want to get the n-th record. What is the most efficient way to achieve that? </p>
<p>Will the solution break if the ordering property is not unique, such as the one below:</p>
<p>query = Foo.... | 1 | 2009-05-05T20:14:11Z | 827,149 | <p>There is no efficient way to do this - in any DBMS. In every case, you have to at least read sequentially through the index records until you find the nth one, then look up the corresponding data record. This is more or less what fetch(count, offset) does in GAE, with the additional limitation of 1000 records.</p>
... | 3 | 2009-05-05T22:14:26Z | [
"python",
"google-app-engine",
"gae-datastore",
"custompaging"
] |
Combining 2 .csv files by common column | 826,812 | <p>So I have two .csv files where the first line in file 1 is:</p>
<pre><code>MPID,Title,Description,Model,Category ID,Category Description,Subcategory ID,Subcategory Description,Manufacturer ID,Manufacturer Description,URL,Manufacturer (Brand) URL,Image URL,AR Price,Price,Ship Price,Stock,Condition
</code></pre>
<p>... | 8 | 2009-05-05T20:36:44Z | 826,829 | <p>It seems that you're trying to do in a shell script, which is commonly done using SQL server. Is it possible to use SQL for that task? For example, you could import both files into mysql, then create a join, then export it to CSV.</p>
| 0 | 2009-05-05T20:41:46Z | [
"python",
"shell",
"join",
"csv",
"debian"
] |
Combining 2 .csv files by common column | 826,812 | <p>So I have two .csv files where the first line in file 1 is:</p>
<pre><code>MPID,Title,Description,Model,Category ID,Category Description,Subcategory ID,Subcategory Description,Manufacturer ID,Manufacturer Description,URL,Manufacturer (Brand) URL,Image URL,AR Price,Price,Ship Price,Stock,Condition
</code></pre>
<p>... | 8 | 2009-05-05T20:36:44Z | 826,831 | <p>You'll need to look at the <code>join</code> command in the shell. You will also need to sort the data, and probably lose the first lines. The whole process will fall flat if any of the data contains commas. Or you will need to process the data with a CSV-sensitive process that introduces a different field separa... | 1 | 2009-05-05T20:42:15Z | [
"python",
"shell",
"join",
"csv",
"debian"
] |
Combining 2 .csv files by common column | 826,812 | <p>So I have two .csv files where the first line in file 1 is:</p>
<pre><code>MPID,Title,Description,Model,Category ID,Category Description,Subcategory ID,Subcategory Description,Manufacturer ID,Manufacturer Description,URL,Manufacturer (Brand) URL,Image URL,AR Price,Price,Ship Price,Stock,Condition
</code></pre>
<p>... | 8 | 2009-05-05T20:36:44Z | 826,836 | <pre><code>sort -t , -k index1 file1 > sorted1
sort -t , -k index2 file2 > sorted2
join -t , -1 index1 -2 index2 -a 1 -a 2 sorted1 sorted2
</code></pre>
| 13 | 2009-05-05T20:43:30Z | [
"python",
"shell",
"join",
"csv",
"debian"
] |
Combining 2 .csv files by common column | 826,812 | <p>So I have two .csv files where the first line in file 1 is:</p>
<pre><code>MPID,Title,Description,Model,Category ID,Category Description,Subcategory ID,Subcategory Description,Manufacturer ID,Manufacturer Description,URL,Manufacturer (Brand) URL,Image URL,AR Price,Price,Ship Price,Stock,Condition
</code></pre>
<p>... | 8 | 2009-05-05T20:36:44Z | 826,848 | <p>This is the classical "relational join" problem.</p>
<p>You have several algorithms.</p>
<ul>
<li><p>Nested Loops. You read from one file to pick a "master" record. You read the entire other file locating all "detail" records that match the master. This is a bad idea.</p></li>
<li><p>Sort-Merge. You sort each ... | 8 | 2009-05-05T20:46:06Z | [
"python",
"shell",
"join",
"csv",
"debian"
] |
Combining 2 .csv files by common column | 826,812 | <p>So I have two .csv files where the first line in file 1 is:</p>
<pre><code>MPID,Title,Description,Model,Category ID,Category Description,Subcategory ID,Subcategory Description,Manufacturer ID,Manufacturer Description,URL,Manufacturer (Brand) URL,Image URL,AR Price,Price,Ship Price,Stock,Condition
</code></pre>
<p>... | 8 | 2009-05-05T20:36:44Z | 826,891 | <p>You could take a look at my FOSS project <a href="http://code.google.com/p/csvfix/" rel="nofollow">CSVfix</a>, which is a stream editor for manipulating CSV files. It supports joins, among its other features, and requires no scripting to use.</p>
| 0 | 2009-05-05T21:00:33Z | [
"python",
"shell",
"join",
"csv",
"debian"
] |
Combining 2 .csv files by common column | 826,812 | <p>So I have two .csv files where the first line in file 1 is:</p>
<pre><code>MPID,Title,Description,Model,Category ID,Category Description,Subcategory ID,Subcategory Description,Manufacturer ID,Manufacturer Description,URL,Manufacturer (Brand) URL,Image URL,AR Price,Price,Ship Price,Stock,Condition
</code></pre>
<p>... | 8 | 2009-05-05T20:36:44Z | 29,784,804 | <p>For merging multiple files (even > 2) based on one or more common columns, one of the best and efficient approaches in python would be to use "brewery". You could even specify what fields need to be considered for merging and what fields need to be saved.</p>
<pre><code>import brewery
from brewery
import ds
import ... | 0 | 2015-04-21T23:10:25Z | [
"python",
"shell",
"join",
"csv",
"debian"
] |
crontab in python | 826,882 | <p>I'm writing code in python for some sort of daemon that has to execute a specific action at a certain instance in time defined by a crontab string.
Is there a module I can use?
If not, can someone paste/link an algorithm I can use to check whether the instance of time defined by the crontab has occured in the time f... | 2 | 2009-05-05T20:58:43Z | 826,912 | <p><a href="http://docs.python.org/library/sched.html" rel="nofollow">sched</a> ftw</p>
| 3 | 2009-05-05T21:08:20Z | [
"python",
"crontab"
] |
crontab in python | 826,882 | <p>I'm writing code in python for some sort of daemon that has to execute a specific action at a certain instance in time defined by a crontab string.
Is there a module I can use?
If not, can someone paste/link an algorithm I can use to check whether the instance of time defined by the crontab has occured in the time f... | 2 | 2009-05-05T20:58:43Z | 826,939 | <p><a href="http://www.razorvine.net/download/kronos.py" rel="nofollow">Kronos</a> is another option.</p>
<p>Here is a similar SO <a href="http://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python">question</a>.</p>
| 1 | 2009-05-05T21:16:13Z | [
"python",
"crontab"
] |
crontab in python | 826,882 | <p>I'm writing code in python for some sort of daemon that has to execute a specific action at a certain instance in time defined by a crontab string.
Is there a module I can use?
If not, can someone paste/link an algorithm I can use to check whether the instance of time defined by the crontab has occured in the time f... | 2 | 2009-05-05T20:58:43Z | 830,201 | <p>You might want to take a look at <a href="http://www.kalab.com/freeware/pycron/pycron.htm" rel="nofollow">pycron</a>.</p>
| 0 | 2009-05-06T15:33:17Z | [
"python",
"crontab"
] |
Unit testing for D-Bus and HAL? | 827,295 | <p>How does one test a method that does some interactions with the local D-Bus (accessing a HAL object)? </p>
<p>Results of tests will differ depending on the system that the test is run on, so I don't know how to provide the method reliable input. </p>
<p>I'm working in Python, by the way.</p>
| 2 | 2009-05-05T22:56:01Z | 827,391 | <p>If you can not mock the environment then it's probably impossible for you to write the test.
If your access to HAL/D-Bus is via an object and you provide a mock instance to your test then it should be possible to emulate the necessary inputs to your test from the mock implementation.</p>
| 2 | 2009-05-05T23:31:36Z | [
"python",
"unit-testing",
"dbus",
"hal"
] |
Unit testing for D-Bus and HAL? | 827,295 | <p>How does one test a method that does some interactions with the local D-Bus (accessing a HAL object)? </p>
<p>Results of tests will differ depending on the system that the test is run on, so I don't know how to provide the method reliable input. </p>
<p>I'm working in Python, by the way.</p>
| 2 | 2009-05-05T22:56:01Z | 1,993,774 | <p>It's also possible to create a temporary D-Bus buses for tests, and emulate any services your program uses in your test code. You can use this approach for programs which are D-Bus services, D-Bus clients, or both. The downside is that the bus setup is a bit hairy. There's <a href="http://git.collabora.co.uk/?p=tele... | 0 | 2010-01-03T02:46:07Z | [
"python",
"unit-testing",
"dbus",
"hal"
] |
Is there a way to list all the available drive letters in python? | 827,371 | <p>More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system?</p>
<p>(My google-fu seems to have let me down on this one.)</p>
<p>Related:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/286534/enumerating-all-available-drive-le... | 25 | 2009-05-05T23:23:47Z | 827,397 | <pre><code>import win32api
drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')[:-1]
print drives
</code></pre>
<p>Adapted from:
<a href="http://www.faqts.com/knowledge_base/view.phtml/aid/4670">http://www.faqts.com/knowledge_base/view.phtml/aid/4670</a></p>
| 40 | 2009-05-05T23:32:57Z | [
"python",
"windows"
] |
Is there a way to list all the available drive letters in python? | 827,371 | <p>More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system?</p>
<p>(My google-fu seems to have let me down on this one.)</p>
<p>Related:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/286534/enumerating-all-available-drive-le... | 25 | 2009-05-05T23:23:47Z | 827,398 | <p>Without using any external libraries, if that matters to you:</p>
<pre><code>import string
from ctypes import windll
def get_drives():
drives = []
bitmask = windll.kernel32.GetLogicalDrives()
for letter in string.uppercase:
if bitmask & 1:
drives.append(letter)
bitmask &... | 43 | 2009-05-05T23:33:19Z | [
"python",
"windows"
] |
Is there a way to list all the available drive letters in python? | 827,371 | <p>More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system?</p>
<p>(My google-fu seems to have let me down on this one.)</p>
<p>Related:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/286534/enumerating-all-available-drive-le... | 25 | 2009-05-05T23:23:47Z | 827,484 | <p>Those look like better answers. Here's my hackish cruft</p>
<pre><code>import os, re
re.findall(r"[A-Z]+:.*$",os.popen("mountvol /").read(),re.MULTILINE)
</code></pre>
| 6 | 2009-05-06T00:05:22Z | [
"python",
"windows"
] |
Is there a way to list all the available drive letters in python? | 827,371 | <p>More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system?</p>
<p>(My google-fu seems to have let me down on this one.)</p>
<p>Related:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/286534/enumerating-all-available-drive-le... | 25 | 2009-05-05T23:23:47Z | 827,490 | <p>The <a href="http://www.microsoft.com/technet/scriptcenter/scripts/python/default.mspx?mfr=true" rel="nofollow">Microsoft Script Repository</a> includes <a href="http://www.microsoft.com/technet/scriptcenter/scripts/python/storage/disks/drives/stdvpy05.mspx" rel="nofollow">this recipe</a> which might help. I don't ... | 8 | 2009-05-06T00:10:02Z | [
"python",
"windows"
] |
Is there a way to list all the available drive letters in python? | 827,371 | <p>More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system?</p>
<p>(My google-fu seems to have let me down on this one.)</p>
<p>Related:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/286534/enumerating-all-available-drive-le... | 25 | 2009-05-05T23:23:47Z | 23,431,616 | <p>As I don't have win32api installed on my field of notebooks I used this solution using wmic:</p>
<pre><code>import subprocess
import string
#define alphabet
alphabet = []
for i in string.ascii_uppercase:
alphabet.append(i + ':')
#get letters that are mounted somewhere
mounted_letters = subprocess.Popen("wmic ... | 0 | 2014-05-02T15:23:21Z | [
"python",
"windows"
] |
Is there a way to list all the available drive letters in python? | 827,371 | <p>More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system?</p>
<p>(My google-fu seems to have let me down on this one.)</p>
<p>Related:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/286534/enumerating-all-available-drive-le... | 25 | 2009-05-05T23:23:47Z | 25,752,504 | <p>As part of a similar task I also needed to grab a free drive letter. I decided I wanted the highest available letter. I first wrote it out more idiomatically, then crunched it to a 1-liner to see if it still made sense. As awesome as list comprehensions are I love sets for this: <code>unused=set(alphabet)-set(us... | 0 | 2014-09-09T19:49:42Z | [
"python",
"windows"
] |
Is there a way to list all the available drive letters in python? | 827,371 | <p>More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system?</p>
<p>(My google-fu seems to have let me down on this one.)</p>
<p>Related:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/286534/enumerating-all-available-drive-le... | 25 | 2009-05-05T23:23:47Z | 34,187,346 | <p>Found this solution on Google, slightly modified from original. Seem pretty pythonic and does not need any "exotic" imports</p>
<pre><code>import os, string
available_drives = ['%s:' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)]
</code></pre>
| 2 | 2015-12-09T19:26:32Z | [
"python",
"windows"
] |
Is there a way to list all the available drive letters in python? | 827,371 | <p>More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system?</p>
<p>(My google-fu seems to have let me down on this one.)</p>
<p>Related:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/286534/enumerating-all-available-drive-le... | 25 | 2009-05-05T23:23:47Z | 37,761,506 | <p>I wrote this piece of code:</p>
<p><code>import os
drives = [chr(x) + ":" for x in range(65,90) if os.path.exists(chr(x) + ":")]</code></p>
<p>It´s based on @Barmaley ´s answer, but has the advantage of not using the <code>string</code>
module, in case you don´t want to use it. It also works on my system, other... | 0 | 2016-06-11T08:14:47Z | [
"python",
"windows"
] |
Is there a way to list all the available drive letters in python? | 827,371 | <p>More or less what it says on the tin: is there an (easy) way in Python to list all the currently in-use drive letters in a windows system?</p>
<p>(My google-fu seems to have let me down on this one.)</p>
<p>Related:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/286534/enumerating-all-available-drive-le... | 25 | 2009-05-05T23:23:47Z | 38,584,073 | <p>More optimal solution based on @RichieHindle</p>
<pre><code>def get_drives():
drives = []
bitmask = windll.kernel32.GetLogicalDrives()
letter = ord('A')
while bitmask > 0:
if bitmask & 1:
drives.append(chr(letter) + ':\\')
bitmask >>= 1
letter += 1
... | 0 | 2016-07-26T07:54:16Z | [
"python",
"windows"
] |
Should my python web app use unicode for all strings? | 827,415 | <p>I see some frameworks like Django using unicode all over the place so it seems like it might be a good idea.</p>
<p>On the other hand, it seems like a big pain to have all these extra 'u's floating around everywhere. </p>
<p>What will be a problem if I don't do this?</p>
<p>Are there any issues that will come up ... | 6 | 2009-05-05T23:39:38Z | 827,429 | <p>In Python 3, all strings are Unicode. So, you can prepare for this by using <code>u''</code> strings everywhere you need to, and then when you eventually upgrade to Python 3 using the <code>2to3</code> tool all the <code>u</code>s will disappear. And you'll be in a better position because you will have already teste... | 10 | 2009-05-05T23:43:40Z | [
"python",
"django",
"web-applications",
"unicode",
"pylons"
] |
Should my python web app use unicode for all strings? | 827,415 | <p>I see some frameworks like Django using unicode all over the place so it seems like it might be a good idea.</p>
<p>On the other hand, it seems like a big pain to have all these extra 'u's floating around everywhere. </p>
<p>What will be a problem if I don't do this?</p>
<p>Are there any issues that will come up ... | 6 | 2009-05-05T23:39:38Z | 827,461 | <p>You can avoid the <code>u''</code> in python 2.6 by doing:</p>
<pre><code>from __future__ import unicode_literals
</code></pre>
<p>That will make <code>'string literals'</code> to be unicode objects, just like it is in python 3;</p>
| 19 | 2009-05-05T23:55:49Z | [
"python",
"django",
"web-applications",
"unicode",
"pylons"
] |
Should my python web app use unicode for all strings? | 827,415 | <p>I see some frameworks like Django using unicode all over the place so it seems like it might be a good idea.</p>
<p>On the other hand, it seems like a big pain to have all these extra 'u's floating around everywhere. </p>
<p>What will be a problem if I don't do this?</p>
<p>Are there any issues that will come up ... | 6 | 2009-05-05T23:39:38Z | 829,155 | <blockquote>
<p>What will be a problem if I don't do this?</p>
</blockquote>
<p>I'm a westerner living in Japan, so I've seen first-hand what is needed to work with non-ASCII characters. The problem if you don't use Unicode strings is that your code will be a frustration to the parts of the world that use anything o... | 3 | 2009-05-06T11:29:45Z | [
"python",
"django",
"web-applications",
"unicode",
"pylons"
] |
Should my python web app use unicode for all strings? | 827,415 | <p>I see some frameworks like Django using unicode all over the place so it seems like it might be a good idea.</p>
<p>On the other hand, it seems like a big pain to have all these extra 'u's floating around everywhere. </p>
<p>What will be a problem if I don't do this?</p>
<p>Are there any issues that will come up ... | 6 | 2009-05-05T23:39:38Z | 1,440,981 | <p>Using Unicode internally is a good way to avoid problems with non-ASCII characters. Convert at the boundaries of your application (incoming data to unicode, outgoing data to UTF-8 or whatever). Pylons can do the conversion for you in many cases: e.g. controllers can safely return unicode strings; SQLAlchemy models... | 1 | 2009-09-17T19:52:32Z | [
"python",
"django",
"web-applications",
"unicode",
"pylons"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 827,585 | <p>The regex provided should match any url of the form <a href="http://www.ietf.org/rfc/rfc3986.txt" rel="nofollow">http://www.ietf.org/rfc/rfc3986.txt</a>; and does when tested in the python interpreter.</p>
<p>What format have the URLs you've been having trouble parsing had?</p>
| 3 | 2009-05-06T00:55:26Z | [
"python",
"regex",
"google-app-engine"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 827,592 | <pre><code>urlfinders = [
re.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}|(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+)(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\),\\\"]"),
re.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9... | 0 | 2009-05-06T00:58:19Z | [
"python",
"regex",
"google-app-engine"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 827,621 | <p>An easy way to parse (and validate) URL's is the <code>urlparse</code> (<a href="https://docs.python.org/2/library/urlparse.html" rel="nofollow">py2</a>, <a href="https://docs.python.org/3.0/library/urllib.parse.html" rel="nofollow">py3</a>) module. </p>
<p>A regex is too much work.</p>
<hr>
<p>There's no "valid... | 125 | 2009-05-06T01:09:19Z | [
"python",
"regex",
"google-app-engine"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 827,639 | <p>I admit, I find your regular expression totally incomprehensible. I wonder if you could use urlparse instead? Something like:</p>
<pre><code>pieces = urlparse.urlparse(url)
assert all([pieces.scheme, pieces.netloc])
assert set(pieces.netloc) <= set(string.letters + string.digits + '-.') # and others?
assert p... | 17 | 2009-05-06T01:18:04Z | [
"python",
"regex",
"google-app-engine"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 827,645 | <p>I've needed to do this many times over the years and always end up copying someone else's regular expression who has thought about it way more than I <em>want</em> to think about it.</p>
<p>Having said that, there is a regex in the Django forms code which should do the trick:</p>
<p><a href="http://code.djangoproj... | 1 | 2009-05-06T01:23:09Z | [
"python",
"regex",
"google-app-engine"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 835,527 | <p>Here's the complete regexp to parse a URL.</p>
<pre class="lang-none prettyprint-override"><code>(?:http://(?:(?:(?:(?:(?:[a-zA-Z\d](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?)\.
)*(?:[a-zA-Z](?:(?:[a-zA-Z\d]|-)*[a-zA-Z\d])?))|(?:(?:\d+)(?:\.(?:\d+)
){3}))(?::(?:\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\d$\-_.+!*'(),]|(?:%[a-fA-F
\d]{2}... | 199 | 2009-05-07T15:59:04Z | [
"python",
"regex",
"google-app-engine"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 2,431,517 | <p><code>urlparse</code> quite happily takes invalid URLs, it is more a string string-splitting library than any kind of validator. For example:</p>
<pre><code>from urlparse import urlparse
urlparse('http://----')
# returns: ParseResult(scheme='http', netloc='----', path='', params='', query='', fragment='')
</code></... | 5 | 2010-03-12T09:11:04Z | [
"python",
"regex",
"google-app-engine"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 2,758,281 | <p><strong>note</strong> - Lepl is no longer maintained or supported.</p>
<p>RFC 3696 defines "best practices" for URL validation - <a href="http://www.faqs.org/rfcs/rfc3696.html" rel="nofollow">http://www.faqs.org/rfcs/rfc3696.html</a></p>
<p>The latest release of Lepl (a Python parser library) includes an implement... | 6 | 2010-05-03T13:18:59Z | [
"python",
"regex",
"google-app-engine"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 7,995,979 | <p>I'm using the one used by Django and it seems pretty well:</p>
<pre><code>def is_valid_url(url):
import re
regex = re.compile(
r'^https?://' # http:// or https://
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+[A-Z]{2,6}\.?|' # domain...
r'localhost|' # localhost...
r'\d{... | 13 | 2011-11-03T13:49:07Z | [
"python",
"regex",
"google-app-engine"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 9,837,658 | <p><a href="http://pypi.python.org/pypi/rfc3987">http://pypi.python.org/pypi/rfc3987</a> gives regular expressions for consistency with the rules in RFC 3986 and RFC 3987 (that is, not with scheme-specific rules).</p>
<p>A regexp for IRI_reference is:</p>
<pre><code>(?P<scheme>[a-zA-Z][a-zA-Z0-9+.-]*):(?://(?P&... | 6 | 2012-03-23T10:31:27Z | [
"python",
"regex",
"google-app-engine"
] |
How do you validate a URL with a regular expression in Python? | 827,557 | <p>I'm building an app on Google App Engine. I'm incredibly new to Python and have been beating my head against the following problem for the past 3 days.</p>
<p>I have a class to represent an RSS Feed and in this class I have a method called setUrl. Input to this method is a URL. </p>
<p>I'm trying to use the re pyt... | 73 | 2009-05-06T00:40:30Z | 34,266,413 | <p>Nowadays In 90% of case if you working with URL in python than you probably use python-requests. So now is the question "Why do not reuse URL validation from requests" ?</p>
<pre><code>from requests.models import PreparedRequest
import requests.exceptions
def check_url(url):
prepared_request = PreparedRequest... | 0 | 2015-12-14T11:54:33Z | [
"python",
"regex",
"google-app-engine"
] |
Python interpreter with Linux Screen | 827,879 | <p>I was working with Python with a <a href="http://www.rackaid.com/resources/linux-tutorials/general-tutorials/using-screen/" rel="nofollow">Linux terminal screen</a>. When I typed:</p>
<pre><code>help(somefunction)
</code></pre>
<p>It printed the appropriate output, but then my screen was stuck, and at the bottom o... | 1 | 2009-05-06T03:12:46Z | 827,881 | <p>That program uses your pager, which is by default more. You can exit just by pressing q.</p>
| 5 | 2009-05-06T03:14:25Z | [
"python",
"linux",
"terminal"
] |
Python interpreter with Linux Screen | 827,879 | <p>I was working with Python with a <a href="http://www.rackaid.com/resources/linux-tutorials/general-tutorials/using-screen/" rel="nofollow">Linux terminal screen</a>. When I typed:</p>
<pre><code>help(somefunction)
</code></pre>
<p>It printed the appropriate output, but then my screen was stuck, and at the bottom o... | 1 | 2009-05-06T03:12:46Z | 827,936 | <p>The standard on GNU (or other Unix-like) systems is to use the environment variable <code>PAGER</code> for the command that should receive output for <strong>viewing one screenful ("page") at a time</strong>.</p>
<p>Mine is set to:</p>
<pre><code>$ echo $PAGER
less
</code></pre>
<p>Yours might be set to <code>mor... | 10 | 2009-05-06T03:41:29Z | [
"python",
"linux",
"terminal"
] |
How do I constrain the SCons Command builder to run only if its dependencies have changed? | 828,075 | <p>I am using the Command builder in scons to specify that a particular script needs to be invoked to produce a particular file. </p>
<p>I would like to only run the script if it has been modified since the file was previously generated. The default behaviour of the Command builder seems to be to always run the script... | 4 | 2009-05-06T04:53:18Z | 830,071 | <p>Maybe your example is incomplete, but aren't you supposed to do:</p>
<pre><code>env = Environment()
env.Command(....
</code></pre>
<p>I think you need to specify your dependencies as the second argument to Command:</p>
<pre><code>Command('speed_analysis.tex','code/speed.py','python code/speed.py')
</code></pre>
| 1 | 2009-05-06T15:07:13Z | [
"python",
"scons"
] |
How do I constrain the SCons Command builder to run only if its dependencies have changed? | 828,075 | <p>I am using the Command builder in scons to specify that a particular script needs to be invoked to produce a particular file. </p>
<p>I would like to only run the script if it has been modified since the file was previously generated. The default behaviour of the Command builder seems to be to always run the script... | 4 | 2009-05-06T04:53:18Z | 2,512,948 | <p>First, it looks like <code>code/speed.py</code> has no control on the output filename... Hardcoded output filenames are usually considered bad practice in scons (see yacc tool). It would read better like this:</p>
<pre><code>speed = Command('speed_analysis.tex', [], 'python code/speed.py -o $TARGET')
</code></pre>
... | 11 | 2010-03-25T03:43:09Z | [
"python",
"scons"
] |
Python double pointer | 828,139 | <p>I'm trying to get the values from a pointer to a float array, but it returns as c_void_p in python</p>
<p>The C code</p>
<pre><code>double v;
const void *data;
pa_stream_peek(s, &data, &length);
v = ((const float*) data)[length / sizeof(float) -1];
</code></pre>
<p>Python so far</p>
<pre><code>import... | 4 | 2009-05-06T05:23:05Z | 828,154 | <p>My ctypes is rusty, but I believe you want POINTER(c_float) instead of c_void_p. </p>
<p>So try this:</p>
<pre><code>null_ptr = POINTER(c_float)()
pa_stream_peek(stream, null_ptr, ctypes.c_ulong(length))
null_ptr[0]
null_ptr[5] # etc
</code></pre>
| 2 | 2009-05-06T05:31:40Z | [
"python",
"ctypes"
] |
Python double pointer | 828,139 | <p>I'm trying to get the values from a pointer to a float array, but it returns as c_void_p in python</p>
<p>The C code</p>
<pre><code>double v;
const void *data;
pa_stream_peek(s, &data, &length);
v = ((const float*) data)[length / sizeof(float) -1];
</code></pre>
<p>Python so far</p>
<pre><code>import... | 4 | 2009-05-06T05:23:05Z | 828,503 | <p>You'll also probably want to be passing the null_ptr using byref, e.g.</p>
<pre><code>pa_stream_peek(stream, ctypes.byref(null_ptr), ctypes.c_ulong(length))
</code></pre>
| 0 | 2009-05-06T07:55:41Z | [
"python",
"ctypes"
] |
Python double pointer | 828,139 | <p>I'm trying to get the values from a pointer to a float array, but it returns as c_void_p in python</p>
<p>The C code</p>
<pre><code>double v;
const void *data;
pa_stream_peek(s, &data, &length);
v = ((const float*) data)[length / sizeof(float) -1];
</code></pre>
<p>Python so far</p>
<pre><code>import... | 4 | 2009-05-06T05:23:05Z | 830,493 | <p>To use ctypes in a way that mimics your C code, I would suggest (and I'm out-of-practice and this is untested):</p>
<pre><code>vdata = ctypes.c_void_p()
length = ctypes.c_ulong(0)
pa_stream_peek(stream, ctypes.byref(vdata), ctypes.byref(length))
fdata = ctypes.cast(vdata, POINTER(float))
</code></pre>
| 1 | 2009-05-06T16:29:23Z | [
"python",
"ctypes"
] |
Python double pointer | 828,139 | <p>I'm trying to get the values from a pointer to a float array, but it returns as c_void_p in python</p>
<p>The C code</p>
<pre><code>double v;
const void *data;
pa_stream_peek(s, &data, &length);
v = ((const float*) data)[length / sizeof(float) -1];
</code></pre>
<p>Python so far</p>
<pre><code>import... | 4 | 2009-05-06T05:23:05Z | 830,560 | <p>When you pass pointer arguments without using ctypes.pointer or ctypes.byref, their contents simply get set to the integer value of the memory address (i.e., the pointer bits). These arguments should be passed with <code>byref</code> (or <code>pointer</code>, but <code>byref</code> has less overhead):</p>
<pre><co... | 0 | 2009-05-06T16:43:52Z | [
"python",
"ctypes"
] |
file handling in python | 828,214 | <p><br />
Thanks in advance. I have written a program which works for small files. But that doesn't work for files of 1 GB. Please tell me is there is any way to handle big file. Here is the code.</p>
<pre><code>fh=open('reg.fa','r')
c=fh.readlines()
fh.close()
s=''
for i in range(0,(len(c))):
s=s+c[i]
... | 2 | 2009-05-06T05:55:17Z | 828,224 | <p>With readlines() you read whole file at once, so you use 1 GB of memory.
Insted of this try:</p>
<pre><code>f = open(...)
while 1:
line = f.readline()
if not line:
break
line = line.rstrip()
... do something with line
...
f.close()
</code></pre>
<p>If all you need is to remove \n then do not d... | 5 | 2009-05-06T05:59:43Z | [
"python"
] |
file handling in python | 828,214 | <p><br />
Thanks in advance. I have written a program which works for small files. But that doesn't work for files of 1 GB. Please tell me is there is any way to handle big file. Here is the code.</p>
<pre><code>fh=open('reg.fa','r')
c=fh.readlines()
fh.close()
s=''
for i in range(0,(len(c))):
s=s+c[i]
... | 2 | 2009-05-06T05:55:17Z | 828,234 | <p>The <code>readlines</code> method reads in the <strong>entire</strong> file. You don't want to do that for a file that is large in relation to your physical memory size.</p>
<p>The fix is to read the file in small chunks, and process those individually. You can, for example, do something like this:</p>
<pre><code>... | 17 | 2009-05-06T06:05:40Z | [
"python"
] |
file handling in python | 828,214 | <p><br />
Thanks in advance. I have written a program which works for small files. But that doesn't work for files of 1 GB. Please tell me is there is any way to handle big file. Here is the code.</p>
<pre><code>fh=open('reg.fa','r')
c=fh.readlines()
fh.close()
s=''
for i in range(0,(len(c))):
s=s+c[i]
... | 2 | 2009-05-06T05:55:17Z | 828,652 | <p>The script is not working because it reads all lines of the file in advance, making it nescessary to keep the whole file in memory. The easiest way to iterate over all lines in a file is </p>
<pre><code>for line in open("test.txt", "r"):
# do something with the "line"
</code></pre>
| 7 | 2009-05-06T08:41:32Z | [
"python"
] |
file handling in python | 828,214 | <p><br />
Thanks in advance. I have written a program which works for small files. But that doesn't work for files of 1 GB. Please tell me is there is any way to handle big file. Here is the code.</p>
<pre><code>fh=open('reg.fa','r')
c=fh.readlines()
fh.close()
s=''
for i in range(0,(len(c))):
s=s+c[i]
... | 2 | 2009-05-06T05:55:17Z | 829,133 | <p>Your program is very redundant. Looks like everything you do can be done using these lines:</p>
<pre><code>import sys
for line in open('reg.fa'):
sys.stdout.write(line.rstrip())
</code></pre>
<p>That is enough. This program <strong>gives the same result from your original code in the question</strong> but is m... | 2 | 2009-05-06T11:23:06Z | [
"python"
] |
file handling in python | 828,214 | <p><br />
Thanks in advance. I have written a program which works for small files. But that doesn't work for files of 1 GB. Please tell me is there is any way to handle big file. Here is the code.</p>
<pre><code>fh=open('reg.fa','r')
c=fh.readlines()
fh.close()
s=''
for i in range(0,(len(c))):
s=s+c[i]
... | 2 | 2009-05-06T05:55:17Z | 963,807 | <p>From your coding it is clear that you want string buffer of single line.
As a point of view of coding it is bad that you storethe whole file content in one string buffer. And then you processed your requirement.
And code contain too many local variables.</p>
<p>You could have used following chunk of code.</p>
<p>f... | 0 | 2009-06-08T07:41:09Z | [
"python"
] |
Python - Save the context | 828,494 | <p>I need to save the context of the program before exiting ... I've put all the needed stuff to an object that I've previously created a I tried many times to picke it, but no way !!
I continuously have errors like :</p>
<ul>
<li><p>PicklingError: Can't pickle 'SRE_Match' object: <_sre.SRE_Match object at 0x2a969c... | 0 | 2009-05-06T07:52:51Z | 828,587 | <p>See the python doc <a href="http://docs.python.org/library/pickle.html#what-can-be-pickled-and-unpickled" rel="nofollow">What can be pickled and unpickled</a>. You have objects that can not be pickled.</p>
| 3 | 2009-05-06T08:27:36Z | [
"python",
"serialization",
"pickle"
] |
List a dictionary | 828,578 | <p>In a list appending is possible. But how I achieve appending in dictionary?</p>
<pre><code> Symbols from __ctype_tab.o:
Name Value Class Type Size Line Section
__ctype |00000000| D | OBJECT|00000004| |.data
__ctype_tab |00000000| r |... | 1 | 2009-05-06T08:25:47Z | 828,595 | <p>Look into using an <a href="http://www.python.org/dev/peps/pep-0372/" rel="nofollow">ordered dictionary</a>. I don't think this is in official Python yet, but there's a reference implementation available in the PEP.</p>
| 1 | 2009-05-06T08:29:33Z | [
"python",
"list",
"dictionary"
] |
List a dictionary | 828,578 | <p>In a list appending is possible. But how I achieve appending in dictionary?</p>
<pre><code> Symbols from __ctype_tab.o:
Name Value Class Type Size Line Section
__ctype |00000000| D | OBJECT|00000004| |.data
__ctype_tab |00000000| r |... | 1 | 2009-05-06T08:25:47Z | 828,688 | <p>Appending doesn't make sense to the concept of dictionary in the same way as for list. Instead, it's more sensible to speak in terms of inserting and removing key/values, as there's no "<em>end</em>" to append to - the dict is unordered.</p>
<p>From your desired output, it looks like you want to have a dict of dic... | 7 | 2009-05-06T08:51:50Z | [
"python",
"list",
"dictionary"
] |
How to measure Django cache performance? | 828,702 | <p>I have a rather small (ca. 4.5k pageviews a day) website running on Django, with PostgreSQL 8.3 as the db.</p>
<p>I am using the database as both the cache and the sesssion backend. I've heard a lot of good things about using Memcached for this purpose, and I would definitely like to give it a try. However, I woul... | 4 | 2009-05-06T08:56:44Z | 828,826 | <p>Short answer : If you have enougth ram, memcached will be always faster. You can't really benchhmark memcached vs. database cache, just keep in mind that the big bottleneck with servers is disk access, specially write access.</p>
<p>Anyway, disk cache is better if you have many objects to cache and long time expira... | 2 | 2009-05-06T09:32:27Z | [
"python",
"django",
"postgresql",
"caching",
"memcached"
] |
How to measure Django cache performance? | 828,702 | <p>I have a rather small (ca. 4.5k pageviews a day) website running on Django, with PostgreSQL 8.3 as the db.</p>
<p>I am using the database as both the cache and the sesssion backend. I've heard a lot of good things about using Memcached for this purpose, and I would definitely like to give it a try. However, I woul... | 4 | 2009-05-06T08:56:44Z | 829,260 | <p>At my previous work we tried to measure caching impact on site we was developing. On the same machine we load-tested the set of 10 pages that are most commonly used as start pages (object listings), plus some object detail pages taken randomly from the pool of ~200000. The difference was like 150 requests/second to ... | 5 | 2009-05-06T12:08:36Z | [
"python",
"django",
"postgresql",
"caching",
"memcached"
] |
How to measure Django cache performance? | 828,702 | <p>I have a rather small (ca. 4.5k pageviews a day) website running on Django, with PostgreSQL 8.3 as the db.</p>
<p>I am using the database as both the cache and the sesssion backend. I've heard a lot of good things about using Memcached for this purpose, and I would definitely like to give it a try. However, I woul... | 4 | 2009-05-06T08:56:44Z | 2,105,437 | <p>Just try it out. Use firebug or a similar tool and run memcache with a bit of RAM allocation (e.g. 64mb) on the test server.</p>
<p>Mark your average loading results seen in firebug without memcache, then turn caching on and mark new results. That's done as easy as it said.</p>
<p>The results usually shocks people... | 0 | 2010-01-20T22:19:04Z | [
"python",
"django",
"postgresql",
"caching",
"memcached"
] |
How to measure Django cache performance? | 828,702 | <p>I have a rather small (ca. 4.5k pageviews a day) website running on Django, with PostgreSQL 8.3 as the db.</p>
<p>I am using the database as both the cache and the sesssion backend. I've heard a lot of good things about using Memcached for this purpose, and I would definitely like to give it a try. However, I woul... | 4 | 2009-05-06T08:56:44Z | 28,123,744 | <p>Use <a href="http://django-debug-toolbar.readthedocs.org/en/" rel="nofollow">django-debug-toolbar</a> to see how much time has been saved on <code>SQL</code> query</p>
| 0 | 2015-01-24T08:37:35Z | [
"python",
"django",
"postgresql",
"caching",
"memcached"
] |
How to measure Django cache performance? | 828,702 | <p>I have a rather small (ca. 4.5k pageviews a day) website running on Django, with PostgreSQL 8.3 as the db.</p>
<p>I am using the database as both the cache and the sesssion backend. I've heard a lot of good things about using Memcached for this purpose, and I would definitely like to give it a try. However, I woul... | 4 | 2009-05-06T08:56:44Z | 36,097,439 | <p>The <a href="http://www.grantjenks.com/docs/diskcache/" rel="nofollow" title="Python DiskCache">DiskCache</a> project publishes <a href="http://www.grantjenks.com/docs/diskcache/djangocache-benchmarks.html" rel="nofollow" title="DiskCache Django cache benchmarks">Django cache benchmarks</a> comparing local memory, M... | 2 | 2016-03-19T03:22:06Z | [
"python",
"django",
"postgresql",
"caching",
"memcached"
] |
Debugging swig extensions for Python | 828,843 | <p>Is there any other way to debug swig extensions except for doing </p>
<blockquote>
<p>gdb python stuff.py</p>
</blockquote>
<p>?</p>
<p>I have wrapped the legacy library <a href="http://libkdtree.alioth.debian.org/" rel="nofollow">libkdtree++</a> and followed all the swig related memory managemant points (borro... | 4 | 2009-05-06T09:38:33Z | 829,391 | <p>Well, for debugging, you use a debugger ;-).</p>
<p>When debugging, it may be a good idea to configure Python with '--with-pydebug' and recompile. It does additional checks then.</p>
<p>If you are looking for memory leaks, there is a simple way:</p>
<p>Run your code over and over in a loop, and look for Python's... | 1 | 2009-05-06T12:45:30Z | [
"python",
"debugging",
"swig"
] |
Debugging swig extensions for Python | 828,843 | <p>Is there any other way to debug swig extensions except for doing </p>
<blockquote>
<p>gdb python stuff.py</p>
</blockquote>
<p>?</p>
<p>I have wrapped the legacy library <a href="http://libkdtree.alioth.debian.org/" rel="nofollow">libkdtree++</a> and followed all the swig related memory managemant points (borro... | 4 | 2009-05-06T09:38:33Z | 1,541,358 | <p>gdb 7.0 supports python scripting. It might help you in this particular case.</p>
| 2 | 2009-10-09T01:06:30Z | [
"python",
"debugging",
"swig"
] |
Is Python2.6 stable enough for production use? | 828,862 | <p>Or should I just stick with Python2.5 for a bit longer?</p>
| 7 | 2009-05-06T09:44:28Z | 828,881 | <p>From <a href="http://python.org/download/" rel="nofollow">python.org</a>:</p>
<blockquote>
<p>The current production versions are
Python 2.6.2 and Python 3.0.1.</p>
</blockquote>
<p>So, yes.</p>
<p>Python 3.x contains some backwards incompatible changes, so <a href="http://python.org/download/" rel="nofollow"... | 18 | 2009-05-06T09:51:02Z | [
"python"
] |
Is Python2.6 stable enough for production use? | 828,862 | <p>Or should I just stick with Python2.5 for a bit longer?</p>
| 7 | 2009-05-06T09:44:28Z | 828,894 | <p>Ubuntu has switched to 2.6 in it's latest release, and has not had any significant problems. So I would say "yes, it's stable".</p>
| 10 | 2009-05-06T09:55:39Z | [
"python"
] |
Is Python2.6 stable enough for production use? | 828,862 | <p>Or should I just stick with Python2.5 for a bit longer?</p>
| 7 | 2009-05-06T09:44:28Z | 828,951 | <p>It depends from libraries you use. For example there is no precompiled InformixDB package for 2.6 if you have to use Python on Windows.</p>
<p>Also web2py framework sticks with 2.5 because of some bug in 2.6.</p>
<p>Personally I use CPython 2.6 (workhorse) and 3.0 (experimental), and Jython 2.5 beta (for my test w... | 6 | 2009-05-06T10:14:31Z | [
"python"
] |
Is Python2.6 stable enough for production use? | 828,862 | <p>Or should I just stick with Python2.5 for a bit longer?</p>
| 7 | 2009-05-06T09:44:28Z | 828,994 | <p>Yes it it, but this is not the right question. The right question is "can I use Python 2.6, taking in consideration the incompatibilities it introduces ?". And the short answser is "most probably yes, unless you use a specific lib that wouldn't work with 2.6, which is pretty rare".</p>
| 4 | 2009-05-06T10:30:24Z | [
"python"
] |
Is Python2.6 stable enough for production use? | 828,862 | <p>Or should I just stick with Python2.5 for a bit longer?</p>
| 7 | 2009-05-06T09:44:28Z | 829,464 | <p>I've found 2.6 to be fairly good with two exceptions:</p>
<ol>
<li>If you're using it on a server, I've had trouble in the past with some libraries which are used by elements of the server (Debian Etch IIRC). It's possible with a bit of jiggery pokery to maintain several versions of python in unison though if you'r... | 1 | 2009-05-06T13:06:47Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.