title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
What is the sqlalchemy equivalent column type for 'money' and 'OID' in Postgres?
359,409
<p>What is the sqlalchemy equivalent column type for 'money' and 'OID' column types in Postgres?</p>
1
2008-12-11T13:52:21Z
373,062
<p>This is all I could find: <a href="http://docs.sqlalchemy.org/en/rel_0_9/core/types.html" rel="nofollow">http://docs.sqlalchemy.org/en/rel_0_9/core/types.html</a></p> <p>You can make your own type if you want as well.</p>
1
2008-12-16T22:51:45Z
[ "python", "postgresql", "sqlalchemy" ]
What is the sqlalchemy equivalent column type for 'money' and 'OID' in Postgres?
359,409
<p>What is the sqlalchemy equivalent column type for 'money' and 'OID' column types in Postgres?</p>
1
2008-12-11T13:52:21Z
405,923
<p>we've never had an "OID" type specifically, though we've supported the concept of an implicit "OID" column on every table through the 0.4 series, primarily for the benefit of postgres. However since user-table defined OID columns are deprecated in Postgres, and we in fact never really used the OID feature that was ...
2
2009-01-02T02:49:08Z
[ "python", "postgresql", "sqlalchemy" ]
What is the sqlalchemy equivalent column type for 'money' and 'OID' in Postgres?
359,409
<p>What is the sqlalchemy equivalent column type for 'money' and 'OID' column types in Postgres?</p>
1
2008-12-11T13:52:21Z
37,580,913
<p>from the argument on this <a href="https://groups.google.com/forum/#!topic/sqlalchemy/USD3cdng9-s" rel="nofollow">link</a> The final conclusion was:</p> <p>Using FLOAT for monetary amounts is an extremely bad idea because of the inexactness of storage and arithmetic .. Using MONEY is discouraged because it is too l...
0
2016-06-02T00:37:12Z
[ "python", "postgresql", "sqlalchemy" ]
How can I unload a DLL using ctypes in Python?
359,498
<p>I'm using ctypes to load a DLL in Python. This works great.</p> <p>Now we'd like to be able to reload that DLL at runtime. </p> <p>The straightforward approach would seem to be: 1. Unload DLL 2. Load DLL</p> <p>Unfortunately I'm not sure what the correct way to unload the DLL is.</p> <p>_ctypes.FreeLibrary is ...
10
2008-12-11T14:21:06Z
359,570
<p>you should be able to do it by disposing the object</p> <pre><code>mydll = ctypes.CDLL('...') del mydll mydll = ctypes.CDLL('...') </code></pre> <p><strong>EDIT:</strong> Hop's comment is right, this unbinds the name, but garbage collection doesn't happen that quickly, in fact I even doubt it even releases the loa...
10
2008-12-11T14:41:16Z
[ "python", "dll", "ctypes" ]
How can I unload a DLL using ctypes in Python?
359,498
<p>I'm using ctypes to load a DLL in Python. This works great.</p> <p>Now we'd like to be able to reload that DLL at runtime. </p> <p>The straightforward approach would seem to be: 1. Unload DLL 2. Load DLL</p> <p>Unfortunately I'm not sure what the correct way to unload the DLL is.</p> <p>_ctypes.FreeLibrary is ...
10
2008-12-11T14:21:06Z
28,610,285
<p>It is helpful to be able to unload the DLL so that you can rebuild the DLL without having to restart the session if you are using iPython or similar work flow. Working in windows I have only attempted to work with the windows DLL related methods.</p> <pre><code>REBUILD = True if REBUILD: from subprocess import ca...
2
2015-02-19T15:31:41Z
[ "python", "dll", "ctypes" ]
Comparing List of Arguments to it self?
359,903
<p>Kind of a weird question, but. I need to have a list of strings i need to make sure that every string in that list is the same.</p> <p>E.g:</p> <pre><code>a = ['foo', 'foo', 'boo'] #not valid b = ['foo', 'foo', 'foo'] #valid </code></pre> <p>Whats the best way to go about doing that?</p> <p>FYI, i don't know how...
2
2008-12-11T16:14:25Z
359,945
<p>Use list.count to get the number of items in a list that match a value. If that number doesn't match the number of items, you know they aren't all the same.</p> <pre><code>if a.count( "foo" ) != len(a) </code></pre> <p>Which would look like...</p> <pre><code>if a.count( a[0] ) != len(a) </code></pre> <p>...in p...
5
2008-12-11T16:21:34Z
[ "python" ]
Comparing List of Arguments to it self?
359,903
<p>Kind of a weird question, but. I need to have a list of strings i need to make sure that every string in that list is the same.</p> <p>E.g:</p> <pre><code>a = ['foo', 'foo', 'boo'] #not valid b = ['foo', 'foo', 'foo'] #valid </code></pre> <p>Whats the best way to go about doing that?</p> <p>FYI, i don't know how...
2
2008-12-11T16:14:25Z
359,949
<p>No matter what function you use you have to iterate over the entire array at least once. </p> <p>So just use a for loop and compare the first value to each subsequent value. Nothing else could be faster, and it'll be three lines. Anything that does it in less lines will probably be more computationally complex a...
1
2008-12-11T16:22:17Z
[ "python" ]
Comparing List of Arguments to it self?
359,903
<p>Kind of a weird question, but. I need to have a list of strings i need to make sure that every string in that list is the same.</p> <p>E.g:</p> <pre><code>a = ['foo', 'foo', 'boo'] #not valid b = ['foo', 'foo', 'foo'] #valid </code></pre> <p>Whats the best way to go about doing that?</p> <p>FYI, i don't know how...
2
2008-12-11T16:14:25Z
359,952
<p>try (if the lists are not too long):</p> <pre><code>b == [b[0]] * len(b) #valid a == [a[0]] * len(a) #not valid </code></pre> <p>this lets you compare the list to a list of the same size that is all of the same first element</p>
0
2008-12-11T16:22:51Z
[ "python" ]
Comparing List of Arguments to it self?
359,903
<p>Kind of a weird question, but. I need to have a list of strings i need to make sure that every string in that list is the same.</p> <p>E.g:</p> <pre><code>a = ['foo', 'foo', 'boo'] #not valid b = ['foo', 'foo', 'foo'] #valid </code></pre> <p>Whats the best way to go about doing that?</p> <p>FYI, i don't know how...
2
2008-12-11T16:14:25Z
359,963
<p>Try creating a set from that list:</p> <pre><code>if len(set(my_list)) != 1: return False </code></pre> <p>Sets can't have duplicate items.</p> <p>EDIT: S.Lott's suggestion is cleaner:</p> <pre><code>all_items_are_same = len(set(my_list)) == 1 </code></pre> <p>Think of it like this:</p> <pre><code># Equali...
2
2008-12-11T16:27:04Z
[ "python" ]
Comparing List of Arguments to it self?
359,903
<p>Kind of a weird question, but. I need to have a list of strings i need to make sure that every string in that list is the same.</p> <p>E.g:</p> <pre><code>a = ['foo', 'foo', 'boo'] #not valid b = ['foo', 'foo', 'foo'] #valid </code></pre> <p>Whats the best way to go about doing that?</p> <p>FYI, i don't know how...
2
2008-12-11T16:14:25Z
360,069
<p>Perhaps</p> <pre><code>all(a[0] == x for x in a) </code></pre> <p>is the most readable way.</p>
5
2008-12-11T16:54:36Z
[ "python" ]
Comparing List of Arguments to it self?
359,903
<p>Kind of a weird question, but. I need to have a list of strings i need to make sure that every string in that list is the same.</p> <p>E.g:</p> <pre><code>a = ['foo', 'foo', 'boo'] #not valid b = ['foo', 'foo', 'foo'] #valid </code></pre> <p>Whats the best way to go about doing that?</p> <p>FYI, i don't know how...
2
2008-12-11T16:14:25Z
360,107
<p>I think that this should be something you do with a reduce function...</p> <pre><code>&gt;&gt;&gt; a = ['foo', 'foo', 'boo'] #not valid &gt;&gt;&gt; b = ['foo', 'foo', 'foo'] #valid &gt;&gt;&gt; reduce(lambda x,y:x==y and x,a) False &gt;&gt;&gt; reduce(lambda x,y:x==y and x,b) 'foo' </code></pre> <p>I'm not sure i...
0
2008-12-11T17:00:51Z
[ "python" ]
Comparing List of Arguments to it self?
359,903
<p>Kind of a weird question, but. I need to have a list of strings i need to make sure that every string in that list is the same.</p> <p>E.g:</p> <pre><code>a = ['foo', 'foo', 'boo'] #not valid b = ['foo', 'foo', 'foo'] #valid </code></pre> <p>Whats the best way to go about doing that?</p> <p>FYI, i don't know how...
2
2008-12-11T16:14:25Z
360,253
<p>FYI. 5000 iterations of both matching and unmatching versions of a test on different sizes of the input list.</p> <pre><code>List Size 10 0.00530 aList.count(aList[0] ) == len(aList) 0.00699 for with return False if no match found. 0.00892 aList == [aList[0]] * len(aList) 0.00974 len(set(aList)) == 1 0.02334 all(a...
3
2008-12-11T17:49:23Z
[ "python" ]
Split HTML after N words in python
360,036
<p>Is there any way to split a long string of HTML after N words? Obviously I could use:</p> <pre><code>' '.join(foo.split(' ')[:n]) </code></pre> <p>to get the first n words of a plain text string, but that might split in the middle of an html tag, and won't produce valid html because it won't close the tags that ha...
7
2008-12-11T16:47:38Z
360,099
<p>I've heard that <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a> is very good at parsing html. It will probably be able to help you get correct html out.</p>
3
2008-12-11T16:58:58Z
[ "python", "html", "plone", "zope" ]
Split HTML after N words in python
360,036
<p>Is there any way to split a long string of HTML after N words? Obviously I could use:</p> <pre><code>' '.join(foo.split(' ')[:n]) </code></pre> <p>to get the first n words of a plain text string, but that might split in the middle of an html tag, and won't produce valid html because it won't close the tags that ha...
7
2008-12-11T16:47:38Z
360,123
<p>I was going to mention the base <a href="http://docs.python.org/library/htmlparser.html#module-HTMLParser" rel="nofollow">HTMLParser</a> that's built in Python, since I'm not sure what the end-result your trying to get to is, it may or may not get you there, you'll work with the handlers primarily</p>
0
2008-12-11T17:07:16Z
[ "python", "html", "plone", "zope" ]
Split HTML after N words in python
360,036
<p>Is there any way to split a long string of HTML after N words? Obviously I could use:</p> <pre><code>' '.join(foo.split(' ')[:n]) </code></pre> <p>to get the first n words of a plain text string, but that might split in the middle of an html tag, and won't produce valid html because it won't close the tags that ha...
7
2008-12-11T16:47:38Z
360,300
<p>Take a look at the <a href="http://code.djangoproject.com/browser/django/trunk/django/utils/text.py">truncate_html_words</a> function in django.utils.text. Even if you aren't using Django, the code there does exactly what you want.</p>
6
2008-12-11T18:03:44Z
[ "python", "html", "plone", "zope" ]
Split HTML after N words in python
360,036
<p>Is there any way to split a long string of HTML after N words? Obviously I could use:</p> <pre><code>' '.join(foo.split(' ')[:n]) </code></pre> <p>to get the first n words of a plain text string, but that might split in the middle of an html tag, and won't produce valid html because it won't close the tags that ha...
7
2008-12-11T16:47:38Z
360,356
<p>You can use a mix of regex, BeautifulSoup or Tidy (I prefer BeautifulSoup). The idea is simple - strip all the HTML tags first. Find the nth word (n=7 here), find the number of times the nth word appears in the string till n words - coz u are looking only for the last occurrence to be used for truncation.</p> <p>He...
0
2008-12-11T18:24:11Z
[ "python", "html", "plone", "zope" ]
Lambda function for classes in python?
360,368
<p>There must be an easy way to do this, but somehow I can wrap my head around it. The best way I can describe what I want is a lambda function for a class. I have a library that expects as an argument an uninstantiated version of a class to work with. It then instantiates the class itself to work on. The problem is th...
6
2008-12-11T18:27:21Z
360,403
<p>This is sort of cheating, but you could give your Multiply class a <code>__call__</code> method that returns itself:</p> <pre><code>class Multiply: def __init__(self,mult): self.mult = mult def __call__(self): return self def run(self,x): return x*self.mult </code></pre> <p>That...
1
2008-12-11T18:39:04Z
[ "python", "lambda" ]
Lambda function for classes in python?
360,368
<p>There must be an easy way to do this, but somehow I can wrap my head around it. The best way I can describe what I want is a lambda function for a class. I have a library that expects as an argument an uninstantiated version of a class to work with. It then instantiates the class itself to work on. The problem is th...
6
2008-12-11T18:27:21Z
360,415
<pre><code>def mult(x): def f(): return Multiply(x) return f op3 = mult(5) lib3 = Library(op3) print lib3.Op(2) </code></pre>
1
2008-12-11T18:42:25Z
[ "python", "lambda" ]
Lambda function for classes in python?
360,368
<p>There must be an easy way to do this, but somehow I can wrap my head around it. The best way I can describe what I want is a lambda function for a class. I have a library that expects as an argument an uninstantiated version of a class to work with. It then instantiates the class itself to work on. The problem is th...
6
2008-12-11T18:27:21Z
360,425
<p>Does the library really specify that it wants an "uninitialized version" (i.e. a class reference)?</p> <p>It looks to me as if the library actually wants an object factory. In that case, it's acceptable to type:</p> <pre><code>lib3 = Library(lambda: Multiply(5)) </code></pre> <p>To understand how the lambda work...
11
2008-12-11T18:44:54Z
[ "python", "lambda" ]
Lambda function for classes in python?
360,368
<p>There must be an easy way to do this, but somehow I can wrap my head around it. The best way I can describe what I want is a lambda function for a class. I have a library that expects as an argument an uninstantiated version of a class to work with. It then instantiates the class itself to work on. The problem is th...
6
2008-12-11T18:27:21Z
360,443
<p>If I understand your problem space correctly, you have a general interface that takes 1 argument which is called using the <code>Library</code> class. Unfortunately, rather than calling a function, <code>Library</code> assumes that the function is wrapped in a class with a <code>run</code> method.</p> <p>You can c...
1
2008-12-11T18:50:19Z
[ "python", "lambda" ]
Lambda function for classes in python?
360,368
<p>There must be an easy way to do this, but somehow I can wrap my head around it. The best way I can describe what I want is a lambda function for a class. I have a library that expects as an argument an uninstantiated version of a class to work with. It then instantiates the class itself to work on. The problem is th...
6
2008-12-11T18:27:21Z
360,456
<p>There's no need for lambda at all. lambda is just syntatic sugar to define a function and use it at the same time. Just like any lambda call can be replaced with an explicit def, we can solve your problem by creating a real class that meets your needs and returning it. </p> <pre><code>class Double: def ...
8
2008-12-11T18:53:30Z
[ "python", "lambda" ]
Regular Expressions in unicode strings
360,600
<p>I have some unicode text that I want to clean up using regular expressions. For example I have cases where u'(2'. This exists because for formatting reasons the closing paren ends up in an adjacent html cell. My initial solution to this problem was to look ahead at the contents of the next cell and using a string...
1
2008-12-11T19:37:45Z
360,733
<p>Okay sorry for using this a a stream of consciousness thinking stimulator but it appears that writing out my original question got me on the path. It seems to me that this is a solution for what I am trying to do:</p> <pre><code> missingParen=re.compile(r"^\(\d$") </code></pre>
1
2008-12-11T20:13:47Z
[ "python", "regex" ]
What GUI toolkit looks best for a native LAF for Python in Windows and Linux?
360,602
<p>I need to decide on a GUI/Widget toolkit to use with Python for a new project. The target platforms will be Linux with KDE and Windows XP (and probably Vista). What Python GUI toolkit looks best and consistent with the native look and feel of the run time platform?</p> <p>If possible, cite strengths and weaknesses ...
4
2008-12-11T19:38:02Z
361,549
<p>For KDE and Windows, <a href="http://www.trolltech.com/" rel="nofollow">Qt</a> is the best option. Qt is fine for Gnome/Windows too, but in that case you might prefer <a href="http://wxwidgets.org" rel="nofollow">WxWidgets</a>.</p> <p>Qt bindings for python are <a href="http://www.riverbankcomputing.co.uk/software/...
2
2008-12-12T00:33:32Z
[ "python", "windows", "linux", "native", "gui-toolkit" ]
What GUI toolkit looks best for a native LAF for Python in Windows and Linux?
360,602
<p>I need to decide on a GUI/Widget toolkit to use with Python for a new project. The target platforms will be Linux with KDE and Windows XP (and probably Vista). What Python GUI toolkit looks best and consistent with the native look and feel of the run time platform?</p> <p>If possible, cite strengths and weaknesses ...
4
2008-12-11T19:38:02Z
361,672
<p>Python binding of Wx is very strong since at least one of the core developer is a python guy itself. WxWdgets is robust, time proven stable, mature, but also bit more than just GUI. Even is a lot is left out in WxPython - because Python itself offers that already - you might find that extra convenient for your proje...
8
2008-12-12T01:48:15Z
[ "python", "windows", "linux", "native", "gui-toolkit" ]
What GUI toolkit looks best for a native LAF for Python in Windows and Linux?
360,602
<p>I need to decide on a GUI/Widget toolkit to use with Python for a new project. The target platforms will be Linux with KDE and Windows XP (and probably Vista). What Python GUI toolkit looks best and consistent with the native look and feel of the run time platform?</p> <p>If possible, cite strengths and weaknesses ...
4
2008-12-11T19:38:02Z
361,996
<p>Like others said, PyQt or wxPython... The technical difference between the two is more or less imaginary - it's a question of your comfort with the toolkit that matters, really.</p>
0
2008-12-12T05:49:18Z
[ "python", "windows", "linux", "native", "gui-toolkit" ]
Extract ipv6 prefix in python
360,782
<p>Given either the binary or string representation of an IPv6 address and its prefix length, what's the best way to extract the prefix in Python?</p> <p>Is there a library that would do this for me, or would I have to:</p> <ol> <li>convert the address from string to an int (inet_ntop)</li> <li>Mask out the prefix</l...
1
2008-12-11T20:33:39Z
360,989
<p>See <a href="http://code.google.com/p/ipaddr-py/" rel="nofollow">http://code.google.com/p/ipaddr-py/</a></p> <p>With this, you can do</p> <pre><code>py&gt; p=ipaddr.IPv6("2001:888:2000:d::a2") py&gt; p.SetPrefix(64) py&gt; p IPv6('2001:888:2000:d::a2/64') py&gt; p.network_ext '2001:888:2000:d::' </code></pre> <p>...
2
2008-12-11T21:21:41Z
[ "python", "ipv6" ]
Extract ipv6 prefix in python
360,782
<p>Given either the binary or string representation of an IPv6 address and its prefix length, what's the best way to extract the prefix in Python?</p> <p>Is there a library that would do this for me, or would I have to:</p> <ol> <li>convert the address from string to an int (inet_ntop)</li> <li>Mask out the prefix</l...
1
2008-12-11T20:33:39Z
7,661,089
<p>Using the python <a href="https://github.com/drkjam/netaddr" rel="nofollow">netaddr</a> library:</p> <pre><code>&gt;&gt;&gt; from netaddr.ip import IPNetwork, IPAddress &gt;&gt;&gt; IPNetwork('2001:888:2000:d::a2/64').network 2001:888:2000:d:: </code></pre>
0
2011-10-05T12:10:32Z
[ "python", "ipv6" ]
Access CVS through Apache service using SSPI
360,911
<p>I'm running an Apache server (v2.2.10) with mod_python, Python 2.5 and Django. I have a small web app that will show the current projects we have in CVS and allow users to make a build of the different projects (the build checks out the project, and copies certain files over with the source stripped out).</p> <p>O...
0
2008-12-11T21:05:20Z
361,235
<p>Usage of SSPI make me think you are using CVSNT, thus a Windows system; what is the user you are running Apache into? Default user for services is SYSTEM, which does not share the same registry as your current user.</p>
0
2008-12-11T22:28:00Z
[ "python", "apache", "cvs", "sspi" ]
Need Help Understanding how to use less complex regex in Python
361,443
<p>I am trying to learn more about regular expressions I have one below that I believe finds cases where there is a missing close paren on a number up to 999 billion. The one below it I thought should do the same but I do not get similar results</p> <pre><code> missingParenReg=re.compile(r"^\([$]*[0-9]{1,3}[,]?[0-9]...
1
2008-12-11T23:41:55Z
361,475
<p>Are there nested parentheses (your regexps assume there are not)? If not:</p> <pre><code>whether_paren_is_missing = (astring[0] == '(' and not astring[-1] == ')') </code></pre> <p>To validate a dollar amount part:</p> <pre><code>import re cents = r"(?:\.\d\d)" # cents re_dollar_amount = re.compile(r"""(?x) ...
4
2008-12-11T23:57:50Z
[ "python", "regex" ]
Need Help Understanding how to use less complex regex in Python
361,443
<p>I am trying to learn more about regular expressions I have one below that I believe finds cases where there is a missing close paren on a number up to 999 billion. The one below it I thought should do the same but I do not get similar results</p> <pre><code> missingParenReg=re.compile(r"^\([$]*[0-9]{1,3}[,]?[0-9]...
1
2008-12-11T23:41:55Z
361,485
<p>One difference I see at a glance is that your regex will not find strings like:</p> <pre><code>(123,,, </code></pre> <p>That's because the corrected version requires at least one digit between commas. (A reasonable requirement, I'd say.) </p>
-1
2008-12-12T00:02:56Z
[ "python", "regex" ]
Need Help Understanding how to use less complex regex in Python
361,443
<p>I am trying to learn more about regular expressions I have one below that I believe finds cases where there is a missing close paren on a number up to 999 billion. The one below it I thought should do the same but I do not get similar results</p> <pre><code> missingParenReg=re.compile(r"^\([$]*[0-9]{1,3}[,]?[0-9]...
1
2008-12-11T23:41:55Z
361,512
<p>The trickier part about regular expressions isn't making them accept valid input, it's making them reject invalid input. For example, the second expression accepts input that is clearly wrong, including:</p> <ul> <li><code>(1,2,3,4</code> -- one digit between each comma</li> <li><code>(12,34,56</code> -- two digit...
3
2008-12-12T00:14:10Z
[ "python", "regex" ]
Need Help Understanding how to use less complex regex in Python
361,443
<p>I am trying to learn more about regular expressions I have one below that I believe finds cases where there is a missing close paren on a number up to 999 billion. The one below it I thought should do the same but I do not get similar results</p> <pre><code> missingParenReg=re.compile(r"^\([$]*[0-9]{1,3}[,]?[0-9]...
1
2008-12-11T23:41:55Z
867,212
<p>I've found very helpful to use <a href="http://code.google.com/p/kiki-re/" rel="nofollow">kiki</a> when tailoring a regex. It shows you visually what's going on with your regexes. It is a huge time-saver.</p>
0
2009-05-15T06:16:29Z
[ "python", "regex" ]
Techniques for data comparison between different schemas
361,945
<p>Are there techniques for comparing the same data stored in different schemas? The situation is something like this. If I have a db with schema A and it stores data for a feature in say, 5 tables. Schema A -> Schema B is done during an upgrade process. During the upgrade process some transformation logic is applied a...
0
2008-12-12T05:09:04Z
361,988
<p>Basically, you should create object representations for both schema versions, and then compare objects. This is best done if they all fit into memory simultaneously; if not, you need to iterate over all objects in one representation, fetch the corresponding object in the other representation, compare them, and then ...
1
2008-12-12T05:43:31Z
[ "python", "sql", "database" ]
Techniques for data comparison between different schemas
361,945
<p>Are there techniques for comparing the same data stored in different schemas? The situation is something like this. If I have a db with schema A and it stores data for a feature in say, 5 tables. Schema A -> Schema B is done during an upgrade process. During the upgrade process some transformation logic is applied a...
0
2008-12-12T05:09:04Z
362,068
<p>I've used SQLAlchemy successfully for migration between one schema and another - that's a similar process (as indicated by Martin v. Löwis) as comparison. Especially if you use an .equals(other) method.</p>
0
2008-12-12T06:52:54Z
[ "python", "sql", "database" ]
Techniques for data comparison between different schemas
361,945
<p>Are there techniques for comparing the same data stored in different schemas? The situation is something like this. If I have a db with schema A and it stores data for a feature in say, 5 tables. Schema A -> Schema B is done during an upgrade process. During the upgrade process some transformation logic is applied a...
0
2008-12-12T05:09:04Z
362,074
<p>Make "views" on both the schemas that translate to the same buisness representation of data. Export these views to flat files and then you can use any plain vanilla file diff utility to compare and point out differences. </p>
2
2008-12-12T06:56:48Z
[ "python", "sql", "database" ]
Python: Finding partial string matches in a large corpus of strings
362,231
<p>I'm interested in implementing autocomplete in Python. For example, as the user types in a string, I'd like to show the subset of files on disk whose names start with that string. </p> <p>What's an efficient algorithm for finding strings that match some condition in a large corpus (say a few hundred thousand string...
1
2008-12-12T08:49:03Z
362,264
<p>I used <a href="http://pylucene.osafoundation.org/" rel="nofollow">Lucene</a> to autocomplete a text field with more then a hundred thousand possibilities and I perceived it as instantaneous.</p>
3
2008-12-12T09:05:15Z
[ "python", "search" ]
Python: Finding partial string matches in a large corpus of strings
362,231
<p>I'm interested in implementing autocomplete in Python. For example, as the user types in a string, I'd like to show the subset of files on disk whose names start with that string. </p> <p>What's an efficient algorithm for finding strings that match some condition in a large corpus (say a few hundred thousand string...
1
2008-12-12T08:49:03Z
362,266
<p>The flexibility you want for matching your string is called <em>Fuzzy Matching</em> or <em>Fuzzy Searching</em> . I am not aware of any python implementation (but I haven't looked deeply in the subject) but there are C/C++ implementations that you can reuse, like the <a href="http://laurikari.net/tre/" rel="nofollow...
0
2008-12-12T09:05:57Z
[ "python", "search" ]
Python: Finding partial string matches in a large corpus of strings
362,231
<p>I'm interested in implementing autocomplete in Python. For example, as the user types in a string, I'd like to show the subset of files on disk whose names start with that string. </p> <p>What's an efficient algorithm for finding strings that match some condition in a large corpus (say a few hundred thousand string...
1
2008-12-12T08:49:03Z
362,285
<p>Maybe the readline module is what you are looking for. It is an interface to the GNU readline library <a href="http://docs.python.org/library/readline.html#module-readline" rel="nofollow">Python Documentation</a>. Maybe you can supply your own completition function with <code>set_completer()</code>.</p>
1
2008-12-12T09:15:52Z
[ "python", "search" ]
Python: Finding partial string matches in a large corpus of strings
362,231
<p>I'm interested in implementing autocomplete in Python. For example, as the user types in a string, I'd like to show the subset of files on disk whose names start with that string. </p> <p>What's an efficient algorithm for finding strings that match some condition in a large corpus (say a few hundred thousand string...
1
2008-12-12T08:49:03Z
362,288
<p>(addressing just the string matching part of the question)</p> <p>If you want to try something quickly yourself, why not create a few dictionaries, each mapping initial patterns to lists of strings where</p> <ul> <li>Each dictionary is keyed on initial patterns of a particular length</li> <li>All the strings in a ...
0
2008-12-12T09:18:05Z
[ "python", "search" ]
Python: Finding partial string matches in a large corpus of strings
362,231
<p>I'm interested in implementing autocomplete in Python. For example, as the user types in a string, I'd like to show the subset of files on disk whose names start with that string. </p> <p>What's an efficient algorithm for finding strings that match some condition in a large corpus (say a few hundred thousand string...
1
2008-12-12T08:49:03Z
362,433
<p>For exact matching, generally the way to implement something like this is to store your corpus in a <a href="http://en.wikipedia.org/wiki/Trie" rel="nofollow">trie</a>. The idea is that you store each letter as a node in the tree, linking to the next letter in a word. Finding the matches is simply walking the tree...
6
2008-12-12T10:37:07Z
[ "python", "search" ]
Is there a standalone alternative to activerecord-like database schema migrations?
362,334
<p>Is there any standalone alternative to activerecord-like migrations. Something like a script that is able to track current schema version and apply outstanding migrations. Basically, these migration files could be just a plain SQL files, something like:</p> <pre> [timestamp]_create_users.sql reverse_[timestamp]_cre...
1
2008-12-12T09:46:31Z
362,353
<p>Not a linux option, but might answer this question for some people:</p> <p>SQLYog can do this for MySQL - its a windows GUI tool:</p> <p><a href="http://www.webyog.com/en/" rel="nofollow">http://www.webyog.com/en/</a></p> <p>It can (amongst other things) compare schemas and make one schema look like another, or ...
0
2008-12-12T10:01:20Z
[ "php", "python", "sql", "mysql", "shell" ]
Is there a standalone alternative to activerecord-like database schema migrations?
362,334
<p>Is there any standalone alternative to activerecord-like migrations. Something like a script that is able to track current schema version and apply outstanding migrations. Basically, these migration files could be just a plain SQL files, something like:</p> <pre> [timestamp]_create_users.sql reverse_[timestamp]_cre...
1
2008-12-12T09:46:31Z
362,656
<p>Try <a href="http://freshmeat.net/projects/liquibase/" rel="nofollow">http://freshmeat.net/projects/liquibase/</a></p> <p>If you are using MySQL specifically, have a look at: <a href="http://www.mysqldiff.org/" rel="nofollow">http://www.mysqldiff.org/</a> I used this to synchronize the schema of two databases (so ...
2
2008-12-12T12:54:19Z
[ "php", "python", "sql", "mysql", "shell" ]
Is there a standalone alternative to activerecord-like database schema migrations?
362,334
<p>Is there any standalone alternative to activerecord-like migrations. Something like a script that is able to track current schema version and apply outstanding migrations. Basically, these migration files could be just a plain SQL files, something like:</p> <pre> [timestamp]_create_users.sql reverse_[timestamp]_cre...
1
2008-12-12T09:46:31Z
362,662
<p>Check out <a href="http://autopatch.sourceforge.net/" rel="nofollow">AutoPatch</a></p>
0
2008-12-12T12:59:02Z
[ "php", "python", "sql", "mysql", "shell" ]
Is there a standalone alternative to activerecord-like database schema migrations?
362,334
<p>Is there any standalone alternative to activerecord-like migrations. Something like a script that is able to track current schema version and apply outstanding migrations. Basically, these migration files could be just a plain SQL files, something like:</p> <pre> [timestamp]_create_users.sql reverse_[timestamp]_cre...
1
2008-12-12T09:46:31Z
362,705
<p>The ezComponents library has a <a href="http://www.ezcomponents.org/docs/api/latest/introduction_DatabaseSchema.html" rel="nofollow">database schema component</a> that can compare and apply schema differences between two databases (or a database and a file).</p>
0
2008-12-12T13:20:26Z
[ "php", "python", "sql", "mysql", "shell" ]
Is there a standalone alternative to activerecord-like database schema migrations?
362,334
<p>Is there any standalone alternative to activerecord-like migrations. Something like a script that is able to track current schema version and apply outstanding migrations. Basically, these migration files could be just a plain SQL files, something like:</p> <pre> [timestamp]_create_users.sql reverse_[timestamp]_cre...
1
2008-12-12T09:46:31Z
364,122
<p><a href="http://code.google.com/p/sqlalchemy-migrate/" rel="nofollow">http://code.google.com/p/sqlalchemy-migrate/</a></p>
1
2008-12-12T20:59:27Z
[ "php", "python", "sql", "mysql", "shell" ]
Is there a standalone alternative to activerecord-like database schema migrations?
362,334
<p>Is there any standalone alternative to activerecord-like migrations. Something like a script that is able to track current schema version and apply outstanding migrations. Basically, these migration files could be just a plain SQL files, something like:</p> <pre> [timestamp]_create_users.sql reverse_[timestamp]_cre...
1
2008-12-12T09:46:31Z
953,940
<p><a href="https://sourceforge.net/projects/migrations/" rel="nofollow">https://sourceforge.net/projects/migrations/</a></p> <p>This is a tool for managing structural changes to database schemas based on Active Record migrations from Rails. Features multiple schema interactions, runtime substitution of values, script...
0
2009-06-05T01:50:25Z
[ "php", "python", "sql", "mysql", "shell" ]
Implementing a "[command] [action] [parameter]" style command-line interfaces?
362,426
<p>What is the "cleanest" way to implement an command-line UI, similar to git's, for example:</p> <pre><code>git push origin/master git remote add origin git://example.com master </code></pre> <p>Ideally also allowing the more flexible parsing, for example,</p> <pre><code>jump_to_folder app theappname v2 jump_to_fol...
9
2008-12-12T10:35:03Z
362,475
<p>Straight from one of my scripts:</p> <pre><code>import sys def prog1_func1_act1(): print "pfa1" def prog2_func2_act2(): print "pfa2" commands = { "prog1 func1 act1": prog1_func1_act1, "prog2 func2 act2": prog2_func2_act2 } try: commands[" ".join(sys.argv[1:])]() except KeyError: print "Usage: ", ...
2
2008-12-12T11:04:19Z
[ "python", "command-line", "user-interface" ]
Implementing a "[command] [action] [parameter]" style command-line interfaces?
362,426
<p>What is the "cleanest" way to implement an command-line UI, similar to git's, for example:</p> <pre><code>git push origin/master git remote add origin git://example.com master </code></pre> <p>Ideally also allowing the more flexible parsing, for example,</p> <pre><code>jump_to_folder app theappname v2 jump_to_fol...
9
2008-12-12T10:35:03Z
362,476
<p>Python has a module for parsing command line options, <a href="http://docs.python.org/library/optparse.html" rel="nofollow">optparse</a>.</p>
1
2008-12-12T11:04:58Z
[ "python", "command-line", "user-interface" ]
Implementing a "[command] [action] [parameter]" style command-line interfaces?
362,426
<p>What is the "cleanest" way to implement an command-line UI, similar to git's, for example:</p> <pre><code>git push origin/master git remote add origin git://example.com master </code></pre> <p>Ideally also allowing the more flexible parsing, for example,</p> <pre><code>jump_to_folder app theappname v2 jump_to_fol...
9
2008-12-12T10:35:03Z
362,700
<p>The <code>cmd</code> module would probably work well for this.</p> <p>Example:</p> <pre><code>import cmd class Calc(cmd.Cmd): def do_add(self, arg): print sum(map(int, arg.split())) if __name__ == '__main__': Calc().cmdloop() </code></pre> <p>Run it:</p> <pre><code>$python calc.py (Cmd) add 4 5...
9
2008-12-12T13:17:11Z
[ "python", "command-line", "user-interface" ]
Implementing a "[command] [action] [parameter]" style command-line interfaces?
362,426
<p>What is the "cleanest" way to implement an command-line UI, similar to git's, for example:</p> <pre><code>git push origin/master git remote add origin git://example.com master </code></pre> <p>Ideally also allowing the more flexible parsing, for example,</p> <pre><code>jump_to_folder app theappname v2 jump_to_fol...
9
2008-12-12T10:35:03Z
362,936
<p>Here's my suggestion.</p> <ol> <li><p>Change your grammar slightly.</p></li> <li><p>Use optparse.</p></li> </ol> <p>Ideally also allowing the more flexible parsing, for example,</p> <pre><code>jump_to_folder -n theappname -v2 cmd jump_to_folder -n theappname cmd source jump_to_folder -n theappname -v2 cmd sourc...
0
2008-12-12T14:41:32Z
[ "python", "command-line", "user-interface" ]
Implementing a "[command] [action] [parameter]" style command-line interfaces?
362,426
<p>What is the "cleanest" way to implement an command-line UI, similar to git's, for example:</p> <pre><code>git push origin/master git remote add origin git://example.com master </code></pre> <p>Ideally also allowing the more flexible parsing, for example,</p> <pre><code>jump_to_folder app theappname v2 jump_to_fol...
9
2008-12-12T10:35:03Z
10,888,310
<p>You might want to take a look at <a href="http://readthedocs.org/docs/cliff/en/latest/" rel="nofollow">cliff – Command Line Interface Formulation Framework</a></p>
1
2012-06-04T21:02:44Z
[ "python", "command-line", "user-interface" ]
Implementing a "[command] [action] [parameter]" style command-line interfaces?
362,426
<p>What is the "cleanest" way to implement an command-line UI, similar to git's, for example:</p> <pre><code>git push origin/master git remote add origin git://example.com master </code></pre> <p>Ideally also allowing the more flexible parsing, for example,</p> <pre><code>jump_to_folder app theappname v2 jump_to_fol...
9
2008-12-12T10:35:03Z
10,913,734
<p><a href="http://docs.python.org/library/argparse.html#sub-commands">argparse</a> is perfect for this, specifically <a href="http://docs.python.org/library/argparse.html#sub-commands">"sub-commands"</a> and positional args</p> <pre><code>import argparse def main(): arger = argparse.ArgumentParser() # Argu...
7
2012-06-06T11:56:29Z
[ "python", "command-line", "user-interface" ]
Serializing a Python object to/from a S60 phone
362,484
<p>I'm looking for a way to serialize <strong>generic</strong> Python objects between a CherryPy-based server and a Python client running on a Symbian phone.. Since pyS60 doesn't implement the pickle module, how would you do it?</p> <p>I know about <a href="http://home.gna.org/oomadness/en/cerealizer" rel="nofollow">C...
1
2008-12-12T11:11:00Z
362,579
<p>What's wrong with using the pickle module?</p>
2
2008-12-12T12:09:24Z
[ "python", "serialization", "pickle", "pys60" ]
Serializing a Python object to/from a S60 phone
362,484
<p>I'm looking for a way to serialize <strong>generic</strong> Python objects between a CherryPy-based server and a Python client running on a Symbian phone.. Since pyS60 doesn't implement the pickle module, how would you do it?</p> <p>I know about <a href="http://home.gna.org/oomadness/en/cerealizer" rel="nofollow">C...
1
2008-12-12T11:11:00Z
363,355
<p>There is a json module someone wrote for PyS60. I'd simply grab that, serialize things into json and use that as the transfer method between the web/client app. </p> <p>For the json lib and a decent book on PyS60: <a href="http://www.mobilepythonbook.org/" rel="nofollow">http://www.mobilepythonbook.org/</a></p>
1
2008-12-12T16:48:31Z
[ "python", "serialization", "pickle", "pys60" ]
Serializing a Python object to/from a S60 phone
362,484
<p>I'm looking for a way to serialize <strong>generic</strong> Python objects between a CherryPy-based server and a Python client running on a Symbian phone.. Since pyS60 doesn't implement the pickle module, how would you do it?</p> <p>I know about <a href="http://home.gna.org/oomadness/en/cerealizer" rel="nofollow">C...
1
2008-12-12T11:11:00Z
965,984
<p>The last versions of Python (>1.9) have the module pickle and cPickle are available</p> <p>Another alternative to JSON serialization is to use the netstring (look on wikipedia) format to serialize. It's actually more effective than JSON for binary objects.</p> <p>You can find a good netstring module here <a href=...
1
2009-06-08T17:19:45Z
[ "python", "serialization", "pickle", "pys60" ]
How do I add a guard ring to a matrix in NumPy?
362,489
<p>Using <a href="http://numpy.scipy.org/" rel="nofollow">NumPy</a>, a matrix A has n rows and m columns, and I want add a guard ring to matrix A. That guard ring is all zero.</p> <p>What should I do? Use Reshape? But the element is not enough to make a n+1 m+1 matrix.</p> <p>Or etc.?</p> <p>Thanks in advance</p> I...
2
2008-12-12T11:15:15Z
363,040
<p>Following up on your <a href="http://stackoverflow.com/questions/362489/how-do-i-add-a-guard-ring-to-a-matrix-in-numpy#362576">comment</a>: </p> <pre><code>&gt;&gt;&gt; import numpy &gt;&gt;&gt; a = numpy.array(range(9)).reshape((3,3)) &gt;&gt;&gt; b = numpy.zeros(tuple(s+2 for s in a.shape), a.dtype) &gt;&gt;&gt;...
6
2008-12-12T15:12:04Z
[ "python", "numpy" ]
How do I add a guard ring to a matrix in NumPy?
362,489
<p>Using <a href="http://numpy.scipy.org/" rel="nofollow">NumPy</a>, a matrix A has n rows and m columns, and I want add a guard ring to matrix A. That guard ring is all zero.</p> <p>What should I do? Use Reshape? But the element is not enough to make a n+1 m+1 matrix.</p> <p>Or etc.?</p> <p>Thanks in advance</p> I...
2
2008-12-12T11:15:15Z
365,974
<p>This is a less general but easier to understand version of <a href="http://stackoverflow.com/questions/362489/how-do-i-add-a-guard-ring-to-a-matrix-in-numpy#363040">Alex's answer</a>:</p> <pre><code>&gt;&gt;&gt; a = numpy.array(range(9)).reshape((3,3)) &gt;&gt;&gt; a array([[0, 1, 2], [3, 4, 5], [6, 7...
5
2008-12-14T00:10:02Z
[ "python", "numpy" ]
Switching from python-mode.el to python.el
362,522
<p>I recently tried switching from using <code>python-mode.el</code> to <code>python.el</code> for editing python files in emacs, found the experience a little alien and unproductive, and scurried back. I've been using <code>python-mode.el</code> for something like ten years, so perhaps I'm a little set in my ways. I...
29
2008-12-12T11:37:05Z
362,596
<p>python-mode.el is written by the Python community. python.el is written by the emacs community. I've used python-mode.el for as long as I can remember and python.el doesn't even come close to the standards of python-mode.el. I trust the Python community better than the Emacs community to come up with a decent mode f...
1
2008-12-12T12:20:43Z
[ "python", "emacs", "editing" ]
Switching from python-mode.el to python.el
362,522
<p>I recently tried switching from using <code>python-mode.el</code> to <code>python.el</code> for editing python files in emacs, found the experience a little alien and unproductive, and scurried back. I've been using <code>python-mode.el</code> for something like ten years, so perhaps I'm a little set in my ways. I...
29
2008-12-12T11:37:05Z
368,719
<p>For what it's worth, I do not see the behavior you are seeing in issue #1, "Each buffer visiting a python file gets its own inferior interactive python shell."</p> <p>This is what I did using python.el from Emacs 22.2.</p> <p>C-x C-f foo.py [insert: print "foo"]</p> <p>C-x C-f bar.py [insert: print "bar"]</p> <p...
4
2008-12-15T15:34:00Z
[ "python", "emacs", "editing" ]
Switching from python-mode.el to python.el
362,522
<p>I recently tried switching from using <code>python-mode.el</code> to <code>python.el</code> for editing python files in emacs, found the experience a little alien and unproductive, and scurried back. I've been using <code>python-mode.el</code> for something like ten years, so perhaps I'm a little set in my ways. I...
29
2008-12-12T11:37:05Z
1,005,515
<p>python-mode.el has no support triple-quoted strings, so if your program contains long docstrings, all the syntax coloring (and associated syntaxic features) tends to break down.</p> <p>my .02</p>
1
2009-06-17T07:08:48Z
[ "python", "emacs", "editing" ]
Switching from python-mode.el to python.el
362,522
<p>I recently tried switching from using <code>python-mode.el</code> to <code>python.el</code> for editing python files in emacs, found the experience a little alien and unproductive, and scurried back. I've been using <code>python-mode.el</code> for something like ten years, so perhaps I'm a little set in my ways. I...
29
2008-12-12T11:37:05Z
2,554,201
<ol> <li><p>I can't reproduce this behavior on Emacs v23.1, this must have been changed since then.</p></li> <li><p>Forget about any mode's skeleton support and use the hyper-advanced and extensible <a href="http://code.google.com/p/yasnippet/" rel="nofollow">yasnippet</a> instead, it's really worth a try!</p></li> </o...
3
2010-03-31T15:24:02Z
[ "python", "emacs", "editing" ]
Switching from python-mode.el to python.el
362,522
<p>I recently tried switching from using <code>python-mode.el</code> to <code>python.el</code> for editing python files in emacs, found the experience a little alien and unproductive, and scurried back. I've been using <code>python-mode.el</code> for something like ten years, so perhaps I'm a little set in my ways. I...
29
2008-12-12T11:37:05Z
13,267,654
<p>Note nearly everything said here is obsolete meanwhile as things changed.</p> <p>python-mode.el commands are prefixed "py-" basically, you should be able to use commands from both, nonewithstanding which one was loaded first.</p> <p>python-mode.el does not unload python.el; beside of python-mode-map, which is re-d...
2
2012-11-07T10:21:47Z
[ "python", "emacs", "editing" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
362,855
<p>Disable AV Scanning &amp; see if that makes a difference. It could also be caused by Vista. Upgrade to the latest service pack and try again. </p>
0
2008-12-12T14:09:54Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
362,895
<p>I think it's the development server, it's not optimized for speed nor security. I noticed that specially serving static files (i.e. media) is slow.</p>
2
2008-12-12T14:25:51Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
363,563
<p>Since you report your friend's machine has no delays, and I assume yours and his are comparable computers, it could be a DNS related issue. Try to add both the client's and the server's IP address to the server's hosts file.</p> <p>If you run Django on *nix, it's the <code>/etc/hosts</code> file. If run it on MS Wi...
3
2008-12-12T17:41:00Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
363,587
<p>And if all else fails, you can always <a href="http://docs.python.org/library/profile.html" rel="nofollow">cProfile</a> your application and see where exactly is the bottleneck.</p>
1
2008-12-12T17:46:33Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
368,583
<p>Firefox has a problem browsing to localhost on some Windows machines. You can solve it by switching off ipv6, which isn't really recommended. Using 127.0.0.1 directly is another way round the problem.</p>
17
2008-12-15T14:46:40Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
662,541
<p>I have had the same problem in the past. It can be solved by removing the following line from your hosts file.</p> <pre><code>::1 localhost </code></pre> <p>Once that's gone you should be able to use localhost again, quickly.</p>
1
2009-03-19T15:04:52Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
2,135,240
<p>Had the same problem too, I've noticed it with Firefox on Vista and Windows 7 machines. Accessing the development server 127.0.0.1:8000 solved the problem.</p>
2
2010-01-25T20:07:24Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
2,209,435
<p>To completely bypass localhost without altering the hosts file or any settings in Firefox you can install the addon <a href="https://addons.mozilla.org/en-US/firefox/addon/5064" rel="nofollow">Redirector</a> and make a rule to redirect from localhost to 127.0.0.1. Use these settings</p> <pre><code>Include pattern :...
0
2010-02-05T18:30:11Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
7,123,271
<p>None of these posts helped me. In my specific case, <a href="http://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/" rel="nofollow">Justin Carmony</a> gave me the answer.</p> <p><strong>Problem</strong></p> <p>I was mapping [hostname].local to 127.0.0.1 in my /etc/hosts file ...
6
2011-08-19T14:43:11Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
7,158,170
<p>I had the same problem but it was caused by mysqld. </p> <p>The app worked pretty fast on production with wsgi and a mysql server in the same host but slow in the development environtment with the django runserver option and a remote mysql server.</p> <p>I noticed using "show processlist" that connections in datab...
1
2011-08-23T08:29:06Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
7,612,815
<p>i got the same problem.</p> <p>the solution was :</p> <ul> <li>I was trying to start localy a version that was usualy deployed on a webserver in production.</li> <li>The static files in production were served by an apache config and not with django static serve</li> </ul> <p>so I <strong>just uncommented back my ...
0
2011-09-30T15:41:17Z
[ "python", "django", "dns" ]
django is very slow on my machine
362,808
<p>I have a fresh install of django 1.0 and a simple page served from it takes 5 secs to load. On my colleague's computer it takes almost no time.</p> <p>I start the server using </p> <pre> python manage.py testserver </pre> <p>I can see each GET request (PNGs and style sheets) take about half a second.</p> <p>Anot...
12
2008-12-12T13:53:04Z
9,872,341
<p>Upgrade to Django 1.3 or newer.</p> <p>If you still have this problem in 2012 (using Chrome), make sure you're upgrading. In 1.3, a <a href="https://code.djangoproject.com/ticket/16099" rel="nofollow">bug</a> was fixed related to slowness when the dev server was single threaded. </p> <p>Upgrading solved my issues....
1
2012-03-26T12:43:31Z
[ "python", "django", "dns" ]
Best way to organize the folders containing the SQLAlchemy models
362,998
<p>I use SQLAlchemy at work and it does the job really fine. Now I am thinking about best practices.</p> <p>For now, I create a module holding all the SQLA stuff :</p> <pre><code>my_model |__ __init__.py |__ _config.py &lt;&lt;&lt;&lt;&lt; contains LOGIN, HOST, and a MetaData instance |__ ...
6
2008-12-12T15:02:25Z
403,362
<p>Personally I like to keep the database / ORM logic out of the model classes. It makes them easier to test. I typically have something like a <code>types.py</code> which defines the types used in my application, but independent of the database.</p> <p>Then typically there is a <code>db.py</code> or something similar...
3
2008-12-31T16:21:32Z
[ "python", "orm", "sqlalchemy" ]
Regex Problem Group Name Redefinition?
363,171
<p>So I have this regex:</p> <pre><code>(^(\s+)?(?P&lt;NAME&gt;(\w)(\d{7}))((01f\.foo)|(\.bar|\.goo\.moo\.roo))$|(^(\s+)?(?P&lt;NAME2&gt;R1_\d{6}_\d{6}_)((01f\.foo)|(\.bar|\.goo\.moo\.roo))$)) </code></pre> <p>Now if I try and do a match against this:</p> <pre> B048661501f.foo </pre> <p>I get this error:</p> <pre>...
4
2008-12-12T15:58:50Z
363,264
<p>No, you can't have two groups of the same name, this would somehow defy the purpose, wouldn't it?</p> <p>What you probably <em>really</em> want is this:</p> <pre><code>^\s*(?P&lt;NAME&gt;\w\d{7}|R1_(?:\d{6}_){2})(01f\.foo|\.(?:bar|goo|moo|roo))$ </code></pre> <p>I refactored your regex as far as possible. I made ...
6
2008-12-12T16:27:22Z
[ "python", "regex" ]
Regex Problem Group Name Redefinition?
363,171
<p>So I have this regex:</p> <pre><code>(^(\s+)?(?P&lt;NAME&gt;(\w)(\d{7}))((01f\.foo)|(\.bar|\.goo\.moo\.roo))$|(^(\s+)?(?P&lt;NAME2&gt;R1_\d{6}_\d{6}_)((01f\.foo)|(\.bar|\.goo\.moo\.roo))$)) </code></pre> <p>Now if I try and do a match against this:</p> <pre> B048661501f.foo </pre> <p>I get this error:</p> <pre>...
4
2008-12-12T15:58:50Z
14,286,839
<p>Reusing the same name makes sense in your case, contrary to Tamalak's reply.</p> <p>Your regex compiles with python2.7 and also re2. Maybe this problem has been resolved.</p>
6
2013-01-11T21:21:35Z
[ "python", "regex" ]
Equivalent of an HTML multiple SELECT box in wxPython
363,907
<p>I'd like to create a <code>ListBox</code> in wxPython with the same semantics as a multiple <code>select</code> box in HTML. Specifically I'd like the following semantics</p> <ul> <li> When the user clicks on an entry in the list, all other entries become de-selected and the clicked entry becomes selected. If t...
3
2008-12-12T19:45:11Z
363,918
<p>I think what you're looking for is the <a href="http://docs.wxwidgets.org/2.6/wx_wxlistbox.html" rel="nofollow">wxLB_EXTENDED</a> list box style. Specify <code>style = wx.LB_EXTENDED</code> when you create the <code>ListBox</code>.</p> <p>You can then use the <code>GetSelections</code> method to obtain a list of th...
3
2008-12-12T19:49:51Z
[ "python", "wxpython" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
363,955
<pre><code>(get_list() or [None])[0] </code></pre> <p>That should work.</p> <p>BTW I didn't use the variable <code>list</code>, because that overwrites the builtin <code>list()</code> function.</p> <p>Edit: I had a slightly simpler, but wrong version here earlier.</p>
35
2008-12-12T20:00:03Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
363,984
<p>You could use <a href="http://www.refactoring.com/catalog/extractMethod.html" rel="nofollow">Extract Method</a>. In other words extract that code into a method which you'd then call.</p> <p>I wouldn't try to compress it much more, the one liners seem harder to read than the verbose version. And if you use Extract M...
-1
2008-12-12T20:10:04Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
363,995
<p>The best way is this:</p> <pre><code>a = get_list() return a[0] if a else None </code></pre> <p>You could also do it in one line, but it's much harder for the programmer to read:</p> <pre><code>return (get_list()[:1] or [None])[0] </code></pre>
134
2008-12-12T20:12:27Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
364,048
<pre><code>try: return a[0] except IndexError: return None </code></pre>
0
2008-12-12T20:30:19Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
364,244
<p>For the heck of it, here's yet another possibility.</p> <pre><code>return None if not get_list() else get_list()[0] </code></pre> <p>Benefit: This method handles the case where get_list is None, without using try/except or assignment. To my knowledge, none of the implementations above can handle this possibility</...
2
2008-12-12T21:48:11Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
364,249
<pre><code>for item in get_list(): return item </code></pre>
3
2008-12-12T21:48:57Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
364,274
<p>isn't the idiomatic python equivalent to C-style ternary operators </p> <pre><code>cond and true_expr or false_expr </code></pre> <p>ie. </p> <pre><code>list = get_list() return list and list[0] or None </code></pre>
-2
2008-12-12T21:55:53Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
364,405
<p>The OP's solution is nearly there, there are just a few things to make it more Pythonic.</p> <p>For one, there's no need to get the length of the list. Empty lists in Python evaluate to False in an if check. Just simply say</p> <pre><code>if list: </code></pre> <p>Additionally, it's a very Bad Idea to assign to v...
9
2008-12-12T22:41:48Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
364,470
<p>Frankly speaking, I do not think there is a better idiom: your is clear and terse - no need for anything "better". Maybe, but this is really a matter of taste, you could change <code>if len(list) &gt; 0:</code> with <code>if list:</code> - an empty list will always evaluate to False.</p> <p>On a related note, Pytho...
1
2008-12-12T23:14:19Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
364,511
<p>Using the and-or trick:</p> <pre><code>a = get_list() return a and a[0] or None</code></pre>
-1
2008-12-12T23:48:00Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
364,570
<p>Several people have suggested doing something like this:</p> <pre><code>list = get_list() return list and list[0] or None </code></pre> <p>That works in many cases, but it will only work if list[0] is not equal to 0, False, or an empty string. If list[0] is 0, False, or an empty string, the method will incorrectl...
-1
2008-12-13T00:35:13Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
365,934
<pre><code>def get_first(iterable, default=None): if iterable: for item in iterable: return item return default </code></pre> <p>Example:</p> <pre><code>x = get_first(get_first_list()) if x: ... y = get_first(get_second_list()) if y: ... </code></pre> <p>Another option is to inlin...
32
2008-12-13T23:31:55Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
370,621
<p>Out of curiosity, I ran timings on two of the solutions. The solution which uses a return statement to prematurely end a for loop is slightly more costly on my machine with Python 2.5.1, I suspect this has to do with setting up the iterable.</p> <pre><code>import random import timeit def index_first_item(some_list...
1
2008-12-16T07:07:33Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
371,270
<pre><code>def head(iterable): try: return iter(iterable).next() except StopIteration: return None print head(xrange(42, 1000) # 42 print head([]) # None </code></pre> <p>BTW: I'd rework your general program flow into something like this:</p> <pre><code>lists = [ ["first", ...
0
2008-12-16T13:17:12Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
15,665,310
<p>And what about: <code>next(iter(get_list()), None)</code>? Might not be the fastest one here, but is standard (starting from Python 2.6) and succinct.</p>
-1
2013-03-27T17:21:42Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
21,560,637
<p>Probably not the fastest solution, but nobody mentioned this option:</p> <pre><code>dict(enumerate(get_list())).get(0) </code></pre> <p>if <code>get_list()</code> can return <code>None</code> you can use:</p> <pre><code>dict(enumerate(get_list() or [])).get(0) </code></pre> <p>Advantages:</p> <p>-one line</p> ...
-1
2014-02-04T18:37:07Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
25,398,201
<p>The most python idiomatic way is to use the next() on a iterator since list is <em>iterable</em>. just like what @J.F.Sebastian put in the comment on Dec 13, 2011.</p> <p><code>next(iter(the_list), None)</code> This returns None if <code>the_list</code> is empty. see <a href="https://docs.python.org/2/library/funct...
20
2014-08-20T06:36:29Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
31,097,387
<p>How about this:</p> <p><code>(my_list and my_list[0]) or None</code></p>
2
2015-06-28T07:57:26Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
31,487,813
<blockquote> <p><strong>Python idiom to return first item or None?</strong></p> </blockquote> <p>The most Pythonic approach is what the most upvoted answer demonstrated, and it was the first thing to come to my mind when I read the question. Here's how to use it, first if the possibly empty list is passed into a fun...
2
2015-07-18T04:33:11Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
31,510,450
<p>My use case was only to set the value of a local variable.</p> <p>Personally I found the try and except style cleaner to read</p> <pre><code>items = [10, 20] try: first_item = items[0] except IndexError: first_item = None print first_item </code></pre> <p>than slicing a list.</p> <pre><code>items = [10, 20] firs...
-1
2015-07-20T07:00:51Z
[ "python", "idioms", "python-2.4" ]
Python idiom to return first item or None
363,944
<p>I'm sure there's a simpler way of doing this that's just not occurring to me.</p> <p>I'm calling a bunch of methods that return a list. The list may be empty. If the list is non-empty, I want to return the first item; otherwise, I want to return None. This code works:</p> <pre><code>my_list = get_list() if len(...
110
2008-12-12T19:56:02Z
35,702,414
<p>If you find yourself trying to pluck the first thing (or None) from a list comprehension you can switch to a generator to do it like:</p> <pre><code>next((x for x in blah if cond), None) </code></pre> <p>Pro: works if blah isn't indexable Con: it's unfamiliar syntax. It's useful while hacking around and filtering ...
4
2016-02-29T14:43:44Z
[ "python", "idioms", "python-2.4" ]
Best way to monitor services on a few servers with python
363,968
<p>What would be the best way to monitor services like HTTP/FTP/IMAP/POP3/SMTP for a few servers from python? Using sockets and trying to connect to service port http-80, ftp-21, etc... and if connection successful assume service is ok or use python libs to connect to specified services and handle exceptions/return cod...
1
2008-12-12T20:02:13Z
364,021
<p><strong>update 1:</strong></p> <p>Actually, In your code there is no difference between the two option ( in FTP ). The second option should be Preferred for code readability. But way not login to the ftp server, And maybe read some file?</p> <p><strong>update 0:</strong></p> <p>When monitoring, testing the full s...
2
2008-12-12T20:23:45Z
[ "python" ]