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 |
|---|---|---|---|---|---|---|---|---|---|
Python: get the return code of ant sub-process in windows | 1,846,025 | <p>I use python to call ant, I want to get the return code of the ant for detect ant error.</p>
<p>for example, in cmd.exe, </p>
<pre><code>C:\Documents and Settings\Administrator>ant sfsf
Buildfile: build.xml does not exist!
Build failed
C:\Documents and Settings\Administrator>echo %ERRORLEVEL%
1
</code></pre>... | -2 | 2009-12-04T10:08:44Z | 1,846,033 | <p>My idea to solve this:
Get some regex on the output stream. If typical Keywords occur like "Error" you will be informed.</p>
| 0 | 2009-12-04T10:10:58Z | [
"python",
"ant",
"subprocess"
] |
Python: get the return code of ant sub-process in windows | 1,846,025 | <p>I use python to call ant, I want to get the return code of the ant for detect ant error.</p>
<p>for example, in cmd.exe, </p>
<pre><code>C:\Documents and Settings\Administrator>ant sfsf
Buildfile: build.xml does not exist!
Build failed
C:\Documents and Settings\Administrator>echo %ERRORLEVEL%
1
</code></pre>... | -2 | 2009-12-04T10:08:44Z | 9,292,587 | <p>As of this post it is recommended that the subprocess module be used to call applications, so for example:</p>
<pre><code>#Change to the correct project directory (with your build.xml)
os.chdir(project_dir)
print(os.path.abspath(os.curdir))
#debug is your ant task, Get the return code, (note shell=True can be a lar... | 0 | 2012-02-15T11:34:37Z | [
"python",
"ant",
"subprocess"
] |
General Unicode/UTF-8 support for csv files in Python 2.6 | 1,846,135 | <p>The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found, in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python documentation</a> and on other webpages, snippets that work for specific cases but you have to understand well what encoding you are handlin... | 41 | 2009-12-04T10:33:29Z | 1,846,171 | <p>There is the usage of Unicode example already in that <a href="http://docs.python.org/library/csv.html#examples">doc</a>, why still need to find another one or re-invent the wheel?</p>
<pre><code>import csv
def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
# csv.py doesn't do Unicode; enco... | 7 | 2009-12-04T10:41:47Z | [
"python",
"csv",
"unicode",
"utf-8",
"python-2.x"
] |
General Unicode/UTF-8 support for csv files in Python 2.6 | 1,846,135 | <p>The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found, in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python documentation</a> and on other webpages, snippets that work for specific cases but you have to understand well what encoding you are handlin... | 41 | 2009-12-04T10:33:29Z | 6,187,936 | <p>The example code of how to read Unicode given at <a href="http://docs.python.org/library/csv.html#examples">http://docs.python.org/library/csv.html#examples</a> looks to be obsolete, as it doesn't work with Python 2.6 and 2.7.</p>
<p>Here follows <code>UnicodeDictReader</code> which works with utf-8 and may be with... | 51 | 2011-05-31T12:59:51Z | [
"python",
"csv",
"unicode",
"utf-8",
"python-2.x"
] |
General Unicode/UTF-8 support for csv files in Python 2.6 | 1,846,135 | <p>The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found, in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python documentation</a> and on other webpages, snippets that work for specific cases but you have to understand well what encoding you are handlin... | 41 | 2009-12-04T10:33:29Z | 6,496,207 | <p>The wrapper <code>unicode_csv_reader</code> mentioned in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">python documentation</a> accepts Unicode strings. This is because csv does not accept Unicode strings. cvs is probably not aware of encoding or locale and just treats the strings it gets as b... | 3 | 2011-06-27T16:53:01Z | [
"python",
"csv",
"unicode",
"utf-8",
"python-2.x"
] |
General Unicode/UTF-8 support for csv files in Python 2.6 | 1,846,135 | <p>The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found, in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python documentation</a> and on other webpages, snippets that work for specific cases but you have to understand well what encoding you are handlin... | 41 | 2009-12-04T10:33:29Z | 9,347,871 | <p>The module provided <a href="http://halley.cc/code/?python/ucsv.py">here</a>, looks like a cool, simple, drop-in replacement for the csv module that allows you to work with utf-8 csv.</p>
<pre><code>import ucsv as csv
with open('some.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
print ... | 22 | 2012-02-19T08:50:55Z | [
"python",
"csv",
"unicode",
"utf-8",
"python-2.x"
] |
General Unicode/UTF-8 support for csv files in Python 2.6 | 1,846,135 | <p>The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found, in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python documentation</a> and on other webpages, snippets that work for specific cases but you have to understand well what encoding you are handlin... | 41 | 2009-12-04T10:33:29Z | 10,275,281 | <p>A little late answer, but I have used <a href="https://github.com/jdunck/python-unicodecsv">unicodecsv</a> with great success.</p>
| 31 | 2012-04-23T05:34:07Z | [
"python",
"csv",
"unicode",
"utf-8",
"python-2.x"
] |
General Unicode/UTF-8 support for csv files in Python 2.6 | 1,846,135 | <p>The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found, in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python documentation</a> and on other webpages, snippets that work for specific cases but you have to understand well what encoding you are handlin... | 41 | 2009-12-04T10:33:29Z | 12,491,360 | <p>I confirm, <a href="https://github.com/jdunck/python-unicodecsv" rel="nofollow"><code>unicodecsv</code></a> is a great replacement for the <code>csv</code> module, I've just replaced <code>csv</code> by <code>unicodecsv</code> in my source code, and it works like a charm.</p>
| 4 | 2012-09-19T08:54:11Z | [
"python",
"csv",
"unicode",
"utf-8",
"python-2.x"
] |
General Unicode/UTF-8 support for csv files in Python 2.6 | 1,846,135 | <p>The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found, in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python documentation</a> and on other webpages, snippets that work for specific cases but you have to understand well what encoding you are handlin... | 41 | 2009-12-04T10:33:29Z | 15,141,545 | <p>You should consider <a href="http://python-tablib.org/" rel="nofollow">tablib</a>, which has a completely different approach, but should be considered under the "just works" requirement. </p>
<pre><code>with open('some.csv', 'rb') as f:
csv = f.read().decode("utf-8")
import tablib
ds = tablib.Dataset()
ds.csv ... | 1 | 2013-02-28T17:11:02Z | [
"python",
"csv",
"unicode",
"utf-8",
"python-2.x"
] |
General Unicode/UTF-8 support for csv files in Python 2.6 | 1,846,135 | <p>The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found, in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python documentation</a> and on other webpages, snippets that work for specific cases but you have to understand well what encoding you are handlin... | 41 | 2009-12-04T10:33:29Z | 20,749,759 | <p>Maybe this is blatantly obvious, but for sake of beginners I'll mention it. </p>
<p>In python 3.X <code>csv</code> module <a href="http://docs.python.org/3.3/library/csv.html#examples" rel="nofollow">supports any encoding out of the box</a>, so if you use this version you can stick to the standard module. </p>
<pr... | 2 | 2013-12-23T19:14:35Z | [
"python",
"csv",
"unicode",
"utf-8",
"python-2.x"
] |
General Unicode/UTF-8 support for csv files in Python 2.6 | 1,846,135 | <p>The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found, in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python documentation</a> and on other webpages, snippets that work for specific cases but you have to understand well what encoding you are handlin... | 41 | 2009-12-04T10:33:29Z | 31,732,182 | <p>I would add to itsadok's answer. By default, excel saves csv files as latin-1 (which ucsv does not support). You can easily fix this by:</p>
<pre><code>with codecs.open(csv_path, 'rb', 'latin-1') as f:
f = StringIO.StringIO( f.read().encode('utf-8') )
reader = ucsv.UnicodeReader(f)
# etc.
</code></pre>
| 0 | 2015-07-30T19:13:10Z | [
"python",
"csv",
"unicode",
"utf-8",
"python-2.x"
] |
General Unicode/UTF-8 support for csv files in Python 2.6 | 1,846,135 | <p>The csv module in Python doesn't work properly when there's UTF-8/Unicode involved. I have found, in the <a href="http://docs.python.org/library/csv.html" rel="nofollow">Python documentation</a> and on other webpages, snippets that work for specific cases but you have to understand well what encoding you are handlin... | 41 | 2009-12-04T10:33:29Z | 34,257,200 | <p>Here is an slightly improved version of <a href="http://stackoverflow.com/a/6187936/1084488">Maxim's answer</a>, which can also skip the UTF-8 BOM:</p>
<pre><code>import csv
import codecs
class UnicodeCsvReader(object):
def __init__(self, csv_file, encoding='utf-8', **kwargs):
if encoding == 'utf-8-sig... | 1 | 2015-12-13T22:32:44Z | [
"python",
"csv",
"unicode",
"utf-8",
"python-2.x"
] |
how to make import conditionally in Python? | 1,846,158 | <p>I want to do something like this in C:</p>
<pre><code>#ifdef SOMETHING
do_this();
#endif
</code></pre>
<p>But in Python this doesn't jive:</p>
<pre><code>if something:
import module
</code></pre>
<p>What am I doing wrong? Is this possible in the first place?</p>
| 1 | 2009-12-04T10:38:59Z | 1,846,174 | <p>It should work fine:</p>
<pre><code>>>> if False:
... import sys
...
>>> sys
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'sys' is not defined
>>> if True:
... import sys
...
>>> sys
<module 'sys' (built-in)>... | 17 | 2009-12-04T10:42:34Z | [
"python",
"python-import"
] |
how to make import conditionally in Python? | 1,846,158 | <p>I want to do something like this in C:</p>
<pre><code>#ifdef SOMETHING
do_this();
#endif
</code></pre>
<p>But in Python this doesn't jive:</p>
<pre><code>if something:
import module
</code></pre>
<p>What am I doing wrong? Is this possible in the first place?</p>
| 1 | 2009-12-04T10:38:59Z | 1,847,301 | <p>In Python there's a built-in feature called "Exception".. Applying to your needs:</p>
<pre><code>try:
import <module>
except: #Catches every error
raise #and print error
</code></pre>
<p>There are more complex structures so search on the web for more documentation.</p>
| 0 | 2009-12-04T14:31:50Z | [
"python",
"python-import"
] |
how to make import conditionally in Python? | 1,846,158 | <p>I want to do something like this in C:</p>
<pre><code>#ifdef SOMETHING
do_this();
#endif
</code></pre>
<p>But in Python this doesn't jive:</p>
<pre><code>if something:
import module
</code></pre>
<p>What am I doing wrong? Is this possible in the first place?</p>
| 1 | 2009-12-04T10:38:59Z | 1,847,335 | <p>If you're getting this:</p>
<pre><code>NameError: name 'something' is not defined
</code></pre>
<p>then the problem here is not with the <code>import</code> statement but with the use of <code>something</code>, a variable you apparently haven't initialized. Just make sure it's initialized to either True or False,... | 0 | 2009-12-04T14:36:55Z | [
"python",
"python-import"
] |
how to make import conditionally in Python? | 1,846,158 | <p>I want to do something like this in C:</p>
<pre><code>#ifdef SOMETHING
do_this();
#endif
</code></pre>
<p>But in Python this doesn't jive:</p>
<pre><code>if something:
import module
</code></pre>
<p>What am I doing wrong? Is this possible in the first place?</p>
| 1 | 2009-12-04T10:38:59Z | 1,849,942 | <p>In the C construct, the conditional define #ifdef tests whether "SOMETHING" exists only, where your python expression tests whether the <em>value</em> of the expression is either True or False, in my opinion two very different things, in addition, the C construct is evaluated at compile time.</p>
<p>"something" bas... | 0 | 2009-12-04T22:01:54Z | [
"python",
"python-import"
] |
Reverse of os.path.normcase on Windows | 1,846,307 | <p>Is there a simple way to get the "real" case sensitive path from a all lower case path.
Like the reverse of os.path.normcase.</p>
<p>For example, consider the directory:</p>
<pre><code>c:\StackOverFlow
</code></pre>
<p>If I have the following snippet, how to obtain d_real?</p>
<pre><code>>>> import os
&... | 5 | 2009-12-04T11:10:56Z | 1,846,423 | <p>Dirty hack approach,</p>
<pre><code>import glob
...
if os.path.exists(d):
d_real = glob.glob(d + '*')[0][:len(d)]
</code></pre>
| 0 | 2009-12-04T11:35:48Z | [
"python",
"path",
"filenames",
"case-sensitive"
] |
Reverse of os.path.normcase on Windows | 1,846,307 | <p>Is there a simple way to get the "real" case sensitive path from a all lower case path.
Like the reverse of os.path.normcase.</p>
<p>For example, consider the directory:</p>
<pre><code>c:\StackOverFlow
</code></pre>
<p>If I have the following snippet, how to obtain d_real?</p>
<pre><code>>>> import os
&... | 5 | 2009-12-04T11:10:56Z | 1,846,465 | <p><br>
I wouldn't consider this solution <em>simple</em>, but what you can to is:</p>
<pre><code>import os
d = os.path.normcase('C:\\StackOverFlow')
files = os.listdir(os.path.dirname(d))
for f in files:
if not d.endswith(f.lower()):
continue
else
real_d = os.path.join(os.path.dirname(d), f)
</code></pre>... | 1 | 2009-12-04T11:45:18Z | [
"python",
"path",
"filenames",
"case-sensitive"
] |
Reverse of os.path.normcase on Windows | 1,846,307 | <p>Is there a simple way to get the "real" case sensitive path from a all lower case path.
Like the reverse of os.path.normcase.</p>
<p>For example, consider the directory:</p>
<pre><code>c:\StackOverFlow
</code></pre>
<p>If I have the following snippet, how to obtain d_real?</p>
<pre><code>>>> import os
&... | 5 | 2009-12-04T11:10:56Z | 1,853,099 | <p>Definitely ugly, but fun:</p>
<pre><code>def getRealDirPath(path):
try:
open(path)
except IOError, e:
return str(e).split("'")[-2]
</code></pre>
<p>Of course:</p>
<ul>
<li>works only with dirs</li>
<li>will be buggy if dir cannot be open for another reason</li>
</ul>
<p>But can still be u... | -1 | 2009-12-05T19:01:04Z | [
"python",
"path",
"filenames",
"case-sensitive"
] |
Reverse of os.path.normcase on Windows | 1,846,307 | <p>Is there a simple way to get the "real" case sensitive path from a all lower case path.
Like the reverse of os.path.normcase.</p>
<p>For example, consider the directory:</p>
<pre><code>c:\StackOverFlow
</code></pre>
<p>If I have the following snippet, how to obtain d_real?</p>
<pre><code>>>> import os
&... | 5 | 2009-12-04T11:10:56Z | 15,365,154 | <p>You can do this by chaining <code>GetShortPathName</code> and <code>GetLongPathName</code>. This can in theory not work because you can disable short filenames on Windows with some configuration setting. Here's some sample code using ctypes:</p>
<pre><code>def normcase(path):
import ctypes
GetShortPathName ... | 0 | 2013-03-12T15:20:26Z | [
"python",
"path",
"filenames",
"case-sensitive"
] |
Reverse of os.path.normcase on Windows | 1,846,307 | <p>Is there a simple way to get the "real" case sensitive path from a all lower case path.
Like the reverse of os.path.normcase.</p>
<p>For example, consider the directory:</p>
<pre><code>c:\StackOverFlow
</code></pre>
<p>If I have the following snippet, how to obtain d_real?</p>
<pre><code>>>> import os
&... | 5 | 2009-12-04T11:10:56Z | 35,229,926 | <p>Using standard lib only, this one works on all path parts / subdirs (except drive letter):</p>
<pre><code>def casedpath(path):
r = glob.glob(re.sub(r'([^:/\\])(?=[/\\]|$)', r'[\1]', path))
return r and r[0] or path
</code></pre>
<p>And this one handles UNC paths in addition:</p>
<pre><code>def casedpath_u... | 1 | 2016-02-05T17:20:38Z | [
"python",
"path",
"filenames",
"case-sensitive"
] |
Python mechanize loses attributes on second open | 1,846,476 | <p>This is a really specialized case and I feel awkward asking it; however I'm at wits end working on it. </p>
<p>I need to follow a tracking number through a form and to a results page so I've been using mechanize in python, the link after form submission is embedded in javascript so I can't simply follow_link. What ... | 2 | 2009-12-04T11:47:21Z | 1,846,725 | <p>You never make <em>first</em> <code>.read</code> method call on Browser instance. That's because it doesn't have such method. The <code>Browswer.response</code> has <code>read</code> method, so if you want to get the body of response you'd need to do:</p>
<pre><code>response = br.response()
response.read()
</code>... | 7 | 2009-12-04T12:40:25Z | [
"python",
"mechanize"
] |
Django filename from database with non-ascii characters | 1,846,497 | <p>I'm trying to create a file dynamically in Django:</p>
<pre><code>response = HttpResponse(mimetype='text/txt')
response['Content-Disposition'] = 'attachment; filename=%s' % filename # UnicodeEncodeError
response.write('text')
return response
</code></pre>
<p>If I hardcode the filename it works properly, but if I... | 1 | 2009-12-04T11:53:12Z | 1,846,657 | <p>You can fix the problem on the Django side but there is no guarantee it will work in all browsers.</p>
<p>See the testcases at <a href="http://greenbytes.de/tech/tc2231/" rel="nofollow">http://greenbytes.de/tech/tc2231/</a>.</p>
<p>For more details on this see <a href="http://stackoverflow.com/questions/1361604/ho... | 1 | 2009-12-04T12:27:40Z | [
"python",
"django",
"utf-8"
] |
Django filename from database with non-ascii characters | 1,846,497 | <p>I'm trying to create a file dynamically in Django:</p>
<pre><code>response = HttpResponse(mimetype='text/txt')
response['Content-Disposition'] = 'attachment; filename=%s' % filename # UnicodeEncodeError
response.write('text')
return response
</code></pre>
<p>If I hardcode the filename it works properly, but if I... | 1 | 2009-12-04T11:53:12Z | 1,847,817 | <pre><code>from django.utils.encoding import smart_str
...
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(filename)
</code></pre>
| 3 | 2009-12-04T15:46:53Z | [
"python",
"django",
"utf-8"
] |
Django makes strange multiple GET calls on admin-site | 1,846,571 | <p>My Django-Project is making some strange faned-out GET calls when opening on model from the admin-site and i have no idea where this comes from. I will try to provide as much information possible.</p>
<p>Imagine this model called 'Rating', which holds a reference i.e. foreign key to 'Item', 'Usecase' and 'Rater'. S... | 0 | 2009-12-04T12:09:06Z | 1,846,634 | <p>I'd be interested to see the admin.py for that app. I'd guess there's something wrong in the media definitions for the form - the clue is the 'js' at the end of the list. You're probably using a string somewhere Django is expecting a tuple.</p>
| 2 | 2009-12-04T12:24:06Z | [
"python",
"django",
"get"
] |
matching stored keywords/phrases in text | 1,846,833 | <p>I have a database table with around 1000 keywords/phrases (one to four words long) - This table changes rarely, so I could extract the data into something more useful (like a regular expression?) - So this is not finding / guessing at keywords based on natural language processing..</p>
<p>I then have a user inputti... | 1 | 2009-12-04T13:06:09Z | 1,847,031 | <p>If I understand you correctly, you have a unique set of strings, that you want to compare an input strings against. In this case you could use <code>set</code> to store both processing results and db values. Comparison then could be done as follows:</p>
<pre><code>>>> db = {'abc', 'def', 'jhi', 'asdf'}
>... | 0 | 2009-12-04T13:44:07Z | [
"python",
"mysql",
"regex",
"django"
] |
matching stored keywords/phrases in text | 1,846,833 | <p>I have a database table with around 1000 keywords/phrases (one to four words long) - This table changes rarely, so I could extract the data into something more useful (like a regular expression?) - So this is not finding / guessing at keywords based on natural language processing..</p>
<p>I then have a user inputti... | 1 | 2009-12-04T13:06:09Z | 1,847,090 | <p>Just a heads up... you may be interested in <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#regex" rel="nofollow">django's support for regex in queries</a></p>
<p>Example from the linked django docs:</p>
<pre><code>Entry.objects.get(title__regex=r'^(An?|The) +')
</code></pre>
| 0 | 2009-12-04T13:54:56Z | [
"python",
"mysql",
"regex",
"django"
] |
matching stored keywords/phrases in text | 1,846,833 | <p>I have a database table with around 1000 keywords/phrases (one to four words long) - This table changes rarely, so I could extract the data into something more useful (like a regular expression?) - So this is not finding / guessing at keywords based on natural language processing..</p>
<p>I then have a user inputti... | 1 | 2009-12-04T13:06:09Z | 1,847,181 | <p>Here is a slight variation on SilentGhost's answer. You load in the keywords line by line. store them in a set. for each keyword that you find in the user input increase the corresponding entry in the results. </p>
<pre><code>keyword_file = StringIO("""inputting some text
extract the data
a phrase not here"... | 0 | 2009-12-04T14:12:14Z | [
"python",
"mysql",
"regex",
"django"
] |
matching stored keywords/phrases in text | 1,846,833 | <p>I have a database table with around 1000 keywords/phrases (one to four words long) - This table changes rarely, so I could extract the data into something more useful (like a regular expression?) - So this is not finding / guessing at keywords based on natural language processing..</p>
<p>I then have a user inputti... | 1 | 2009-12-04T13:06:09Z | 1,847,839 | <p>Once you've formed your pattern such as <code>(first phrase)|(the second)|(and another)</code> (<em>with</em> the parentheses I indicate) and compiled it into a regular expression object <code>r</code>, a good way to loop on matches and identify which match it was is:</p>
<pre><code>class GroupCounter(object):
de... | 0 | 2009-12-04T15:50:47Z | [
"python",
"mysql",
"regex",
"django"
] |
matching stored keywords/phrases in text | 1,846,833 | <p>I have a database table with around 1000 keywords/phrases (one to four words long) - This table changes rarely, so I could extract the data into something more useful (like a regular expression?) - So this is not finding / guessing at keywords based on natural language processing..</p>
<p>I then have a user inputti... | 1 | 2009-12-04T13:06:09Z | 1,849,025 | <p>If you have 1000 phrases, and you're searching an input string to find which of those phrases are substrings, you're probably not going to be happy with the performance you get from using a big regular expression. A <a href="http://en.wikipedia.org/wiki/Trie" rel="nofollow">trie</a> is a bit more work to implement,... | 0 | 2009-12-04T19:06:24Z | [
"python",
"mysql",
"regex",
"django"
] |
matching stored keywords/phrases in text | 1,846,833 | <p>I have a database table with around 1000 keywords/phrases (one to four words long) - This table changes rarely, so I could extract the data into something more useful (like a regular expression?) - So this is not finding / guessing at keywords based on natural language processing..</p>
<p>I then have a user inputti... | 1 | 2009-12-04T13:06:09Z | 1,849,249 | <p>The algorithm for this job is <a href="http://en.wikipedia.org/wiki/Aho-Corasick%5Falgorithm" rel="nofollow">Aho-Corasick</a> ... see the link at the bottom whch points to a C-extension for Python.</p>
| 0 | 2009-12-04T19:48:12Z | [
"python",
"mysql",
"regex",
"django"
] |
the best shortest path algorithm | 1,846,836 | <p>what is the difference between the <strong>"Floyd-Warshall algorithm"</strong> and <strong>"Dijkstra's Algorithm"</strong>, and which is the best for finding the shortest path in a graph?</p>
<p>I need to calculate the shortest path between all the pairs in a net and save the results to an array as follows:</p>
<p... | 18 | 2009-12-04T13:06:24Z | 1,846,860 | <p>Floyd Warshall find the paths between all pairs of vertices, but Dijkstra only finds the path from one vertex to all others.</p>
<p>Floyd Warshall is O(|V|<sup>3</sup>) and Dikstra is O(|E| + |V| log |V|) but you'll have to run it V times to find all pairs which gives a complexity of O(|E * V| + |V<sup>2</sup>| log... | 6 | 2009-12-04T13:11:16Z | [
"python",
"algorithm",
"numpy",
"shortest-path"
] |
the best shortest path algorithm | 1,846,836 | <p>what is the difference between the <strong>"Floyd-Warshall algorithm"</strong> and <strong>"Dijkstra's Algorithm"</strong>, and which is the best for finding the shortest path in a graph?</p>
<p>I need to calculate the shortest path between all the pairs in a net and save the results to an array as follows:</p>
<p... | 18 | 2009-12-04T13:06:24Z | 1,846,862 | <p>Use the Floyd-Warshall algorithm if you want to find the shortest path between <strong>all</strong> pairs of vertexes, as it has a (far) higher running time than Dijkstra's algorithm.</p>
<p>The Floyd-Warshall algorithm has a worst case performance of O(|V|<sup>3</sup>), where as Dijkstra's has a worse case perform... | 2 | 2009-12-04T13:11:51Z | [
"python",
"algorithm",
"numpy",
"shortest-path"
] |
the best shortest path algorithm | 1,846,836 | <p>what is the difference between the <strong>"Floyd-Warshall algorithm"</strong> and <strong>"Dijkstra's Algorithm"</strong>, and which is the best for finding the shortest path in a graph?</p>
<p>I need to calculate the shortest path between all the pairs in a net and save the results to an array as follows:</p>
<p... | 18 | 2009-12-04T13:06:24Z | 1,846,870 | <p>Dijkstra finds the shortest path from only <strong>one</strong> vertex, Floyd-Warshall finds it between <strong>all</strong> of them.</p>
| 2 | 2009-12-04T13:13:53Z | [
"python",
"algorithm",
"numpy",
"shortest-path"
] |
the best shortest path algorithm | 1,846,836 | <p>what is the difference between the <strong>"Floyd-Warshall algorithm"</strong> and <strong>"Dijkstra's Algorithm"</strong>, and which is the best for finding the shortest path in a graph?</p>
<p>I need to calculate the shortest path between all the pairs in a net and save the results to an array as follows:</p>
<p... | 18 | 2009-12-04T13:06:24Z | 1,846,908 | <p><a href="http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm" rel="nofollow">Dijkstra</a>'s algorithm finds the shortest path between a node and every other node in the graph. You'd run it once for every node. Weights must be non-negative, so if necessary you have to normalise the values in the graph first.</p>
<... | 17 | 2009-12-04T13:22:37Z | [
"python",
"algorithm",
"numpy",
"shortest-path"
] |
the best shortest path algorithm | 1,846,836 | <p>what is the difference between the <strong>"Floyd-Warshall algorithm"</strong> and <strong>"Dijkstra's Algorithm"</strong>, and which is the best for finding the shortest path in a graph?</p>
<p>I need to calculate the shortest path between all the pairs in a net and save the results to an array as follows:</p>
<p... | 18 | 2009-12-04T13:06:24Z | 11,428,258 | <p>Dijkstra's is mainly for single pair shortest path finding i.e. from one node to all other nodes, where as Floyd-Warshall is for all-pair shortest path i.e. shortest path between all pair of vertices. The Floyd-Warshall algorithm has a worst case performance of O(|V|3), where as Dijkstra's has a worse case performan... | 0 | 2012-07-11T08:09:31Z | [
"python",
"algorithm",
"numpy",
"shortest-path"
] |
the best shortest path algorithm | 1,846,836 | <p>what is the difference between the <strong>"Floyd-Warshall algorithm"</strong> and <strong>"Dijkstra's Algorithm"</strong>, and which is the best for finding the shortest path in a graph?</p>
<p>I need to calculate the shortest path between all the pairs in a net and save the results to an array as follows:</p>
<p... | 18 | 2009-12-04T13:06:24Z | 12,927,716 | <p>In the meanwhile better algorithms for the single source shortest path problem are known. A practically relevant one is a <a href="http://www.springerlink.com/content/88jkyvgylkjqlhxh/" rel="nofollow">derivation of Dijkstra's algorithm by Torben Hagerup</a>. The algorithm has the same worst case complexity as Djikst... | 0 | 2012-10-17T05:34:07Z | [
"python",
"algorithm",
"numpy",
"shortest-path"
] |
Getting python.exe path at run time | 1,846,888 | <p>On Windows, how do I find the path to python.exe from within a script at runtime?</p>
| 4 | 2009-12-04T13:18:32Z | 1,846,896 | <pre><code>>>> import sys
>>> sys.executable
'C:\\Program Files\\Python31\\pythonw.exe'
</code></pre>
| 11 | 2009-12-04T13:19:49Z | [
"python"
] |
Print function calls with a variable delay / Python | 1,847,177 | <p>The question is, how can I configure the Python debugger to show me in the console what functions are being called?</p>
<p>In order not to see everything flash by, a delay between the function calls would be needed.</p>
| 1 | 2009-12-04T14:11:58Z | 1,847,244 | <p>You can use the alternative <a href="http://bashdb.sourceforge.net/pydb/" rel="nofollow">pydb</a> debugger. You can invoke it with <code>pydb --fntrace --batch <scriptname></code> to get a function trace.</p>
<p>As for the "flashing-by", use the usual tools like Ctrl-S/Ctrl-Q on an ANSI terminal, or redirect ... | 1 | 2009-12-04T14:21:58Z | [
"python",
"console",
"debugging"
] |
Print function calls with a variable delay / Python | 1,847,177 | <p>The question is, how can I configure the Python debugger to show me in the console what functions are being called?</p>
<p>In order not to see everything flash by, a delay between the function calls would be needed.</p>
| 1 | 2009-12-04T14:11:58Z | 1,847,308 | <p>If you want to monitor when a few particular functions are being called,
you could use this decorator:</p>
<pre><code>import functools
def trace(f):
@functools.wraps(f)
def wrapper(*arg,**kw):
'''This decorator shows how the function was called'''
arg_str=','.join(['%r'%a for a in arg]+['%s... | 2 | 2009-12-04T14:32:39Z | [
"python",
"console",
"debugging"
] |
Python bash pipe | 1,847,195 | <p>I want to pipe a python script's output to a bash script. What i did so far was i tried to use <code>os.popen()</code>, <code>sys.subprocess()</code>, and tried to give a pipe for an example</p>
<pre><code>os.popen('echo "P 1 1 591336 4927369 1 321 " | v.in.ascii -zn out=abcx format=standard --overwrite')
</code></... | 1 | 2009-12-04T14:15:17Z | 1,847,241 | <p>You can just use <code>print</code> to output to stdout and pipe the Python process to the next process, e.g.</p>
<pre><code>python myprogram.py | ...
</code></pre>
<p>Where <code>myprogram.py</code> might look like:</p>
<pre><code>for x in something:
print dosomething(x)
</code></pre>
| 6 | 2009-12-04T14:21:20Z | [
"python",
"bash",
"pipe"
] |
Python bash pipe | 1,847,195 | <p>I want to pipe a python script's output to a bash script. What i did so far was i tried to use <code>os.popen()</code>, <code>sys.subprocess()</code>, and tried to give a pipe for an example</p>
<pre><code>os.popen('echo "P 1 1 591336 4927369 1 321 " | v.in.ascii -zn out=abcx format=standard --overwrite')
</code></... | 1 | 2009-12-04T14:15:17Z | 1,847,284 | <p>This works for me:</p>
<pre><code>>>> stdin, stdout = os.popen2("echo %s | grep 'test'" % 'some test param')
>>> print stdout.read()
some test param
>>>
</code></pre>
| 1 | 2009-12-04T14:28:04Z | [
"python",
"bash",
"pipe"
] |
Python bash pipe | 1,847,195 | <p>I want to pipe a python script's output to a bash script. What i did so far was i tried to use <code>os.popen()</code>, <code>sys.subprocess()</code>, and tried to give a pipe for an example</p>
<pre><code>os.popen('echo "P 1 1 591336 4927369 1 321 " | v.in.ascii -zn out=abcx format=standard --overwrite')
</code></... | 1 | 2009-12-04T14:15:17Z | 1,847,295 | <p>I really like John Paulett's answer.</p>
<p>I think your <code>echo</code> example would work if you used <a href="http://docs.python.org/library/os.html#os.system" rel="nofollow"><code>os.system</code></a> instead of <code>os.popen</code>.</p>
<p>One way to use <code>popen</code> here is like this:</p>
<pre><cod... | 0 | 2009-12-04T14:29:59Z | [
"python",
"bash",
"pipe"
] |
Python bash pipe | 1,847,195 | <p>I want to pipe a python script's output to a bash script. What i did so far was i tried to use <code>os.popen()</code>, <code>sys.subprocess()</code>, and tried to give a pipe for an example</p>
<pre><code>os.popen('echo "P 1 1 591336 4927369 1 321 " | v.in.ascii -zn out=abcx format=standard --overwrite')
</code></... | 1 | 2009-12-04T14:15:17Z | 1,850,352 | <p>As of Python 2.6, the <code>subprocess</code> module is recommended instead of the deprecated <code>os.popen</code>. Here's an example:</p>
<pre><code>from subprocess import Popen, PIPE
p = Popen(["v.in.ascii", "-zn", "out=abcx", "format=standard", "--overwrite"], stdin=PIPE)
p.stdin.write("P 1 1 591336 4927369 1 3... | 1 | 2009-12-04T23:28:58Z | [
"python",
"bash",
"pipe"
] |
How can I correct a corrupted $PYTHONPATH? | 1,847,249 | <p>When trying to launch Mercurial(hg) after a restart in my Ubuntu 9.10 Linux Box I got following message:</p>
<pre><code> abort: couldn't find mercurial libraries in [/usr/bin /usr/local/lib/python2.6/dist-packages/vipy-0.4-py2.6.egg /usr/local/lib/python2.6/dist-packages/nose-0.11.1-py2.6.egg /usr/local/lib/py... | 6 | 2009-12-04T14:22:49Z | 1,847,322 | <p>Is mercurial located in one of the library installation paths (<code>dist-packages</code> or <code>site-packages</code>)? You can use the <code>find</code> tool to look for it?</p>
<p>Did you have luck installing small libraries and access them from Python on this machine?</p>
| 1 | 2009-12-04T14:35:48Z | [
"python",
"version-control",
"mercurial",
"ubuntu-9.10",
"pythonpath"
] |
How can I correct a corrupted $PYTHONPATH? | 1,847,249 | <p>When trying to launch Mercurial(hg) after a restart in my Ubuntu 9.10 Linux Box I got following message:</p>
<pre><code> abort: couldn't find mercurial libraries in [/usr/bin /usr/local/lib/python2.6/dist-packages/vipy-0.4-py2.6.egg /usr/local/lib/python2.6/dist-packages/nose-0.11.1-py2.6.egg /usr/local/lib/py... | 6 | 2009-12-04T14:22:49Z | 1,847,385 | <p>You could try to reinstall affected Python programs with aptitude:</p>
<pre><code>sudo aptitude reinstall mercurial
</code></pre>
| 0 | 2009-12-04T14:44:25Z | [
"python",
"version-control",
"mercurial",
"ubuntu-9.10",
"pythonpath"
] |
How can I correct a corrupted $PYTHONPATH? | 1,847,249 | <p>When trying to launch Mercurial(hg) after a restart in my Ubuntu 9.10 Linux Box I got following message:</p>
<pre><code> abort: couldn't find mercurial libraries in [/usr/bin /usr/local/lib/python2.6/dist-packages/vipy-0.4-py2.6.egg /usr/local/lib/python2.6/dist-packages/nose-0.11.1-py2.6.egg /usr/local/lib/py... | 6 | 2009-12-04T14:22:49Z | 1,847,858 | <p>All of the sites I've googled for this say that your <code>PYTHONPATH </code>is set wrong. The code that you are hitting in mercurial appears to be this:</p>
<pre><code>try:
from mercurial import demandimport; demandimport.enable()
except ImportError:
import sys
sys.stderr.write("abort: couldn't find me... | 5 | 2009-12-04T15:54:07Z | [
"python",
"version-control",
"mercurial",
"ubuntu-9.10",
"pythonpath"
] |
How can I correct a corrupted $PYTHONPATH? | 1,847,249 | <p>When trying to launch Mercurial(hg) after a restart in my Ubuntu 9.10 Linux Box I got following message:</p>
<pre><code> abort: couldn't find mercurial libraries in [/usr/bin /usr/local/lib/python2.6/dist-packages/vipy-0.4-py2.6.egg /usr/local/lib/python2.6/dist-packages/nose-0.11.1-py2.6.egg /usr/local/lib/py... | 6 | 2009-12-04T14:22:49Z | 1,848,560 | <p>Thanks for the effort to all of you.</p>
<p>I've solved the problem thanks to <strong>hughdbrown</strong>. hughdbrown, you've made me realize that I commited a typo when defining doing $PYTHONPATH; instead of adding the path /usr/lib/pymodules/<strong>python2.6</strong>, I wrote /usr/lib/pymodules/ so python couldn... | 1 | 2009-12-04T17:47:30Z | [
"python",
"version-control",
"mercurial",
"ubuntu-9.10",
"pythonpath"
] |
How can I correct a corrupted $PYTHONPATH? | 1,847,249 | <p>When trying to launch Mercurial(hg) after a restart in my Ubuntu 9.10 Linux Box I got following message:</p>
<pre><code> abort: couldn't find mercurial libraries in [/usr/bin /usr/local/lib/python2.6/dist-packages/vipy-0.4-py2.6.egg /usr/local/lib/python2.6/dist-packages/nose-0.11.1-py2.6.egg /usr/local/lib/py... | 6 | 2009-12-04T14:22:49Z | 7,761,520 | <p>Try this:</p>
<p>update-python-modules -p</p>
<p>(might need to sudo that...)
Source:
<a href="http://hg.opensource.lshift.net/mercurial-server/rev/32dba1a70a54">http://hg.opensource.lshift.net/mercurial-server/rev/32dba1a70a54</a></p>
| 8 | 2011-10-13T23:17:35Z | [
"python",
"version-control",
"mercurial",
"ubuntu-9.10",
"pythonpath"
] |
What is the difference between M2Crypto's set_client_CA_list_from_file() and load_verify_info() and when would you use each? | 1,848,160 | <p>The <a href="http://chandlerproject.org/bin/view/Projects/MeTooCrypto" rel="nofollow">M2Crypto library</a> has a few CA-related functions on its <a href="http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.SSL.Context%27.Context-class.html" rel="nofollow">SSL.Context object</a>, but the documentation is very unclear... | 2 | 2009-12-04T16:39:06Z | 1,849,277 | <p>If your server requires the client to present a certificate, it can restrict who are the valid issuers of the client certificates by specifying the issuers calling <a href="http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.SSL.Connection%27.Connection-class.html#set%5Fclient%5FCA%5Flist%5Ffrom%5Ffile" rel="nofollo... | 2 | 2009-12-04T19:54:30Z | [
"python",
"m2crypto"
] |
How can I prevent a Python module from importing itself? | 1,848,268 | <p>For instance, I want to make a sql alchemy plugin for another project. And I want to name that module sqlalchemy.py. The problem with this is that it prevents me from importing <code>sqlalchemy</code>:</p>
<pre><code>#sqlalchemy.py
import sqlalchemy
</code></pre>
<p>This will make the module import itself. I've... | 11 | 2009-12-04T16:54:37Z | 1,848,279 | <p>Don't name it sqlalchemy.py ?</p>
<p>Seriously. I think this is the problem absolute imports is supposed to solve. In python 2.5 it should not happen, but I could be wrong</p>
| 3 | 2009-12-04T16:56:47Z | [
"python",
"import",
"module"
] |
How can I prevent a Python module from importing itself? | 1,848,268 | <p>For instance, I want to make a sql alchemy plugin for another project. And I want to name that module sqlalchemy.py. The problem with this is that it prevents me from importing <code>sqlalchemy</code>:</p>
<pre><code>#sqlalchemy.py
import sqlalchemy
</code></pre>
<p>This will make the module import itself. I've... | 11 | 2009-12-04T16:54:37Z | 1,848,696 | <p>You may just be getting burned by differences between running code in the interactive interpreter and from a file. Remove the test for <code>sys.path[0]</code> being empty (when run from a file, it isn't) and the import should now work as you want.</p>
<pre><code>$ more sqlalchemy.py
import sys
print sys.path[0]
s... | 2 | 2009-12-04T18:11:40Z | [
"python",
"import",
"module"
] |
How can I prevent a Python module from importing itself? | 1,848,268 | <p>For instance, I want to make a sql alchemy plugin for another project. And I want to name that module sqlalchemy.py. The problem with this is that it prevents me from importing <code>sqlalchemy</code>:</p>
<pre><code>#sqlalchemy.py
import sqlalchemy
</code></pre>
<p>This will make the module import itself. I've... | 11 | 2009-12-04T16:54:37Z | 1,848,740 | <p><strong>Edit</strong>: as the OP has now mentioned that the issue is one of relative import being preferred to absolute, the simplest solution for the OP's specific problem is to add at the start of the module <code>from __future__ import absolute_import</code> which changes that "preference"/ordering.</p>
<p>The f... | 12 | 2009-12-04T18:18:09Z | [
"python",
"import",
"module"
] |
build python program with extensions using py2exe | 1,848,275 | <p>I'm having a hard time finding py2exe recipes, especially for cases that require c extensions.</p>
<p>The following recipe works fine without the "ext_modules" part. With it I get "NameError: name 'Extension' is not defined. </p>
<pre><code>from distutils.core import setup
import py2exe
import matplotlib
import ... | 2 | 2009-12-04T16:55:58Z | 1,848,306 | <p>Try changing </p>
<pre><code>from distutils.core import setup
</code></pre>
<p>to </p>
<pre><code>from distutils.core import setup, Extension
</code></pre>
| 0 | 2009-12-04T17:00:57Z | [
"python",
"c",
"py2exe",
"recipe"
] |
build python program with extensions using py2exe | 1,848,275 | <p>I'm having a hard time finding py2exe recipes, especially for cases that require c extensions.</p>
<p>The following recipe works fine without the "ext_modules" part. With it I get "NameError: name 'Extension' is not defined. </p>
<pre><code>from distutils.core import setup
import py2exe
import matplotlib
import ... | 2 | 2009-12-04T16:55:58Z | 1,862,394 | <p>After fixing the small error created by forgetting to import Extension, I ran into other errors stating a problem with the -lsqlite3 flag. Turns out I needed to follow the steps outlined here: <a href="http://cboard.cprogramming.com/cplusplus-programming/82135-sqlite-questions.html" rel="nofollow">http://cboard.cpr... | 1 | 2009-12-07T19:40:53Z | [
"python",
"c",
"py2exe",
"recipe"
] |
lxml Changing Unicode Characters | 1,848,371 | <p>I am using lxml to read through an xml file and change a few details. However, when running it I find that even if I just use lxml to read the file and then write it out again, as below:</p>
<pre><code>fil='iTunes Music Library.XML'
tre=etree.parse(fil)
tre.write('temp.xml')
</code></pre>
<p>I find Queensrÿche co... | 3 | 2009-12-04T17:10:28Z | 1,848,497 | <p>Change your last line to:</p>
<pre><code>tre.write('temp.xml', encoding='utf-8')
</code></pre>
<p>Otherwise <code>lxml</code> writes XML in ASCII encoding, so it have to escape all non-ASCII characters.</p>
| 7 | 2009-12-04T17:34:00Z | [
"python",
"xml",
"lxml"
] |
python web crawler with thread support | 1,848,413 | <p>these day im making some web crawler script, but one of problem is my internet is very slow.
so i was thought whether is it possible webcrawler with multithreading by use mechanize or urllib or so.
if anyone have experience ,share info much appreciate.
i was look for in google ,but not found much useful info.
Thank... | 1 | 2009-12-04T17:19:39Z | 1,848,665 | <p>There's a good, simple example on <a href="http://stackoverflow.com/questions/1628766/python-package-for-multi-threaded-spider-w-proxy-support">this</a> Stack Overflow thread.</p>
| 3 | 2009-12-04T18:06:20Z | [
"python",
"multithreading"
] |
python web crawler with thread support | 1,848,413 | <p>these day im making some web crawler script, but one of problem is my internet is very slow.
so i was thought whether is it possible webcrawler with multithreading by use mechanize or urllib or so.
if anyone have experience ,share info much appreciate.
i was look for in google ,but not found much useful info.
Thank... | 1 | 2009-12-04T17:19:39Z | 1,849,052 | <p>Making multiple requests to many websites at the same time will certainly improve your results, since you don't have to wait for a result to arrive before sending new requests.</p>
<p>However threading is just one of the ways to do that (and a poor one, I might add). Don't use threading for that. Just don't wait fo... | 1 | 2009-12-04T19:11:53Z | [
"python",
"multithreading"
] |
python web crawler with thread support | 1,848,413 | <p>these day im making some web crawler script, but one of problem is my internet is very slow.
so i was thought whether is it possible webcrawler with multithreading by use mechanize or urllib or so.
if anyone have experience ,share info much appreciate.
i was look for in google ,but not found much useful info.
Thank... | 1 | 2009-12-04T17:19:39Z | 1,851,014 | <p><a href="http://www.ibm.com/developerworks/aix/library/au-threadingpython/" rel="nofollow">Practical threaded programming with Python</a> is worth reading.</p>
| 3 | 2009-12-05T03:10:23Z | [
"python",
"multithreading"
] |
Catching a drag exit in Qt? | 1,848,430 | <p>I've got a custom widget descended from QWidget that I want to be able to drop onto, and while the drag is hovering over the widget I'd like to highlight it to provide a little visual feedback to the user. Seems to me the simplest way to do this would be to highlight when dragEnterEvent is called and unhighlight w... | 1 | 2009-12-04T17:22:49Z | 1,848,454 | <p>Open Assistant on the Index tab, type "drag*event" and you will find <a href="http://doc.trolltech.com/4.5/qwidget.html#dragLeaveEvent"><code>dragLeaveEvent</code></a>. :)</p>
| 5 | 2009-12-04T17:27:40Z | [
"python",
"qt",
"drag-and-drop",
"pyqt"
] |
Method Resolution Order (MRO) in new style Python classes | 1,848,474 | <p>In the book "Python in a Nutshell" (2nd Edition) there is an example which uses<br>
old style classes to demonstrate how methods are resolved in classic resolution order and<br>
how is it different with the new order. </p>
<p>I tried the same example by rewriting the example in new style but the result is<br>
no di... | 46 | 2009-12-04T17:30:47Z | 1,848,558 | <p>The result you get is correct. Try changing base class of <code>Base3</code> to <code>Base1</code> and compare with the same hierarchy for classic classes:</p>
<pre><code>class Base1(object):
def amethod(self): print "Base1"
class Base2(Base1):
pass
class Base3(Base1):
def amethod(self): print "Base3"... | 5 | 2009-12-04T17:46:35Z | [
"python"
] |
Method Resolution Order (MRO) in new style Python classes | 1,848,474 | <p>In the book "Python in a Nutshell" (2nd Edition) there is an example which uses<br>
old style classes to demonstrate how methods are resolved in classic resolution order and<br>
how is it different with the new order. </p>
<p>I tried the same example by rewriting the example in new style but the result is<br>
no di... | 46 | 2009-12-04T17:30:47Z | 1,848,581 | <p>You're seeing that behavior because method resolution is depth-first, not breadth-first. Dervied's inheritance looks like</p>
<pre><code> Base2 -> Base1
/
Derived - Base3
</code></pre>
<p>So <code>instance.amethod()</code></p>
<ol>
<li>Checks Base2, doesn't find amethod.</li>
<li>Sees that Bas... | 1 | 2009-12-04T17:53:17Z | [
"python"
] |
Method Resolution Order (MRO) in new style Python classes | 1,848,474 | <p>In the book "Python in a Nutshell" (2nd Edition) there is an example which uses<br>
old style classes to demonstrate how methods are resolved in classic resolution order and<br>
how is it different with the new order. </p>
<p>I tried the same example by rewriting the example in new style but the result is<br>
no di... | 46 | 2009-12-04T17:30:47Z | 1,848,647 | <p>The crucial difference between resolution order for legacy vs new-style classes comes when the same ancestor class occurs more than once in the "naive", depth-first approach -- e.g., consider a "diamond inheritance" case:</p>
<pre><code>>>> class A: x = 'a'
...
>>> class B(A): pass
...
>>&... | 100 | 2009-12-04T18:03:00Z | [
"python"
] |
Method Resolution Order (MRO) in new style Python classes | 1,848,474 | <p>In the book "Python in a Nutshell" (2nd Edition) there is an example which uses<br>
old style classes to demonstrate how methods are resolved in classic resolution order and<br>
how is it different with the new order. </p>
<p>I tried the same example by rewriting the example in new style but the result is<br>
no di... | 46 | 2009-12-04T17:30:47Z | 27,670,178 | <p>Python's method resolution order is actually more complex than just understanding the diamond pattern. To <em>really</em> understand it, take a look at <a href="http://en.wikipedia.org/wiki/C3_linearization">C3 linearization</a>. I've found it really helps to use print statements when extending methods to track th... | 10 | 2014-12-27T18:20:22Z | [
"python"
] |
Python+Qt, QScrollArea problem: what's wrong with this code? | 1,848,547 | <p>I have the following code:</p>
<pre><code>
#!/usr/bin/env python
import sys
from PyQt4 import QtGui, QtCore
class SimfilePanel(QtGui.QWidget):
'''This class provides the simfile panel shown on the right side of the main window.'''
def __init__(self, parent=None):
'''Load song info here.'''
QtGui.QWidg... | 0 | 2009-12-04T17:44:28Z | 1,849,154 | <p>Add the pane to the scroll area <em>after</em> you've added all the grid's contents. In particular you need to call <code>QScrollArea.setWidget</code> after you have <em>finished creating</em> the widget you add.</p>
<p>I don't know exactly why this is the problem, but I do know that I tend to initialize widgets "... | 3 | 2009-12-04T19:33:22Z | [
"python",
"qt",
"pyqt4"
] |
Python+Qt, QScrollArea problem: what's wrong with this code? | 1,848,547 | <p>I have the following code:</p>
<pre><code>
#!/usr/bin/env python
import sys
from PyQt4 import QtGui, QtCore
class SimfilePanel(QtGui.QWidget):
'''This class provides the simfile panel shown on the right side of the main window.'''
def __init__(self, parent=None):
'''Load song info here.'''
QtGui.QWidg... | 0 | 2009-12-04T17:44:28Z | 12,113,848 | <p>I have recently been struggling with the same thing, and I believe I have found the solution you are looking for. </p>
<p>The problem seems to be that when you add an empty widget to the scroll area, it has dimensions of zero by zero (since there is nothing inside of it).</p>
<p>The reason it doesn't get bigger i... | 2 | 2012-08-24T17:12:37Z | [
"python",
"qt",
"pyqt4"
] |
How to do conditional character replacement within a string | 1,849,185 | <p>I have a unicode string in Python and basically need to go through, character by character and replace certain ones based on a list of rules. One such rule is that <code>a</code> is changed to <code>ö</code> if <code>a</code> is after <code>n</code>. Also, if there are two vowel characters in a row, they get replac... | 2 | 2009-12-04T19:38:06Z | 1,849,205 | <p>Given your rules, I'd say you really want a simple state machine. Hmm, on second thought, maybe not; you can just look back in the string as you go.</p>
<p>I have a unicode string in Python and basically need to go through, character by character and replace certain ones based on a list of rules. One such rule is ... | 1 | 2009-12-04T19:40:54Z | [
"python",
"string",
"replace",
"conditional"
] |
How to do conditional character replacement within a string | 1,849,185 | <p>I have a unicode string in Python and basically need to go through, character by character and replace certain ones based on a list of rules. One such rule is that <code>a</code> is changed to <code>ö</code> if <code>a</code> is after <code>n</code>. Also, if there are two vowel characters in a row, they get replac... | 2 | 2009-12-04T19:38:06Z | 1,849,208 | <p>"I know, I'll use regular expressions!"</p>
<p>But seriously, regexes are really good for string manipulation.</p>
<p>You could write one per rule, like so:</p>
<pre><code>s/na/nö/g
s/([aeiou])$1/$1:/g
</code></pre>
<p>Or you could generate them at runtime from some other source which lists them all.</p>
| 2 | 2009-12-04T19:41:08Z | [
"python",
"string",
"replace",
"conditional"
] |
How to do conditional character replacement within a string | 1,849,185 | <p>I have a unicode string in Python and basically need to go through, character by character and replace certain ones based on a list of rules. One such rule is that <code>a</code> is changed to <code>ö</code> if <code>a</code> is after <code>n</code>. Also, if there are two vowel characters in a row, they get replac... | 2 | 2009-12-04T19:38:06Z | 1,849,221 | <p>focus on <em>easy</em> and <strong>correct</strong> first, then consider efficiency if profiling indicates its a bottleneck.</p>
<p>The simple approach is:</p>
<pre><code>prev = None
for ch in string:
if ch == 'a':
if prev == 'n':
...
prev = ch
</code></pre>
| 2 | 2009-12-04T19:43:25Z | [
"python",
"string",
"replace",
"conditional"
] |
How to do conditional character replacement within a string | 1,849,185 | <p>I have a unicode string in Python and basically need to go through, character by character and replace certain ones based on a list of rules. One such rule is that <code>a</code> is changed to <code>ö</code> if <code>a</code> is after <code>n</code>. Also, if there are two vowel characters in a row, they get replac... | 2 | 2009-12-04T19:38:06Z | 1,849,313 | <pre><code># -*- coding: utf-8 -*-
def subpairs(s, prefix, suffix):
def sub(i, sentinal=object()):
r = prefix.get(s[i:i+2], sentinal)
if r is not sentinal: return r
r = suffix.get(s[i-1:i+1], sentinal)
if r is not sentinal: return r
return s[i]
s = '\0'+s+'\0'
retu... | 7 | 2009-12-04T20:01:07Z | [
"python",
"string",
"replace",
"conditional"
] |
How to do conditional character replacement within a string | 1,849,185 | <p>I have a unicode string in Python and basically need to go through, character by character and replace certain ones based on a list of rules. One such rule is that <code>a</code> is changed to <code>ö</code> if <code>a</code> is after <code>n</code>. Also, if there are two vowel characters in a row, they get replac... | 2 | 2009-12-04T19:38:06Z | 1,849,568 | <p>It might be simpler to do with a handmade list of regular expressions, rather than progmatically gererating them. I recommend the following code.</p>
<pre><code>import re
# regsubs is a dictionary of regular expressions as keys,
# and the replacement regexps as values
regsubs = {'na':u'nö',
'([aeiou])... | 1 | 2009-12-04T20:47:21Z | [
"python",
"string",
"replace",
"conditional"
] |
Decorators on Django Template Filters? | 1,849,243 | <p>I have a template filter that performs a very simple task and works well, but I would like to use a decorator on it. Unfortunately the decorator causes a nasty django error that doesn't make any sense...</p>
<p>Code that works:</p>
<pre><code>@register.filter(name="has_network")
def has_network(profile, network):
... | 1 | 2009-12-04T19:47:01Z | 1,849,479 | <p>Final Answer: Add an extra argument to the decorator indicating what is being decorated</p>
<p>There may be something more elegant, but this works.</p>
<pre><code>from django.core.cache import cache
from django.db.models.query import QuerySet
try:
from cPickle import dumps
except:
from pickle import dumps
... | 0 | 2009-12-04T20:31:19Z | [
"python",
"django",
"django-templates",
"filter",
"templatetags"
] |
Do dicts preserve iteration order if they are not modified? | 1,849,324 | <p>If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups).</p>
| 19 | 2009-12-04T20:03:08Z | 1,849,328 | <p>A Python dictionary has no concept of order. So you can't depend on a specific order while iterating. </p>
<p>This is deliberate: since it's a hashmap it's unavoidable if you want 'fast lookups'!</p>
| 2 | 2009-12-04T20:04:12Z | [
"python",
"algorithm",
"dictionary",
"hash"
] |
Do dicts preserve iteration order if they are not modified? | 1,849,324 | <p>If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups).</p>
| 19 | 2009-12-04T20:03:08Z | 1,849,367 | <p>It might be preserved in some implementations, but don't count on it, as it is not a part of the Dict spec.</p>
| 2 | 2009-12-04T20:11:11Z | [
"python",
"algorithm",
"dictionary",
"hash"
] |
Do dicts preserve iteration order if they are not modified? | 1,849,324 | <p>If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups).</p>
| 19 | 2009-12-04T20:03:08Z | 1,849,368 | <p>As Christophe said, a dictionary is used to organise key/value pairs because of the fast access time it provides. If you application needs a fixed index, you should look at the other data structures that provide a specific/known order.</p>
<p>Having said that, it should be safe to assume that the order doesn't chan... | 1 | 2009-12-04T20:11:21Z | [
"python",
"algorithm",
"dictionary",
"hash"
] |
Do dicts preserve iteration order if they are not modified? | 1,849,324 | <p>If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups).</p>
| 19 | 2009-12-04T20:03:08Z | 1,849,393 | <p>Yes. There's no randomisation involved. There's an even stronger guarantee -- see <a href="http://docs.python.org/library/stdtypes.html#dict.items">here</a>.</p>
| 5 | 2009-12-04T20:15:40Z | [
"python",
"algorithm",
"dictionary",
"hash"
] |
Do dicts preserve iteration order if they are not modified? | 1,849,324 | <p>If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups).</p>
| 19 | 2009-12-04T20:03:08Z | 1,849,397 | <p>The standard Python <code>dict</code> like most implementations does not preserve ordering as the items are usually accessed using the key.</p>
<p>However predictable iteration is sometime useful and in Python 3.1 the <code>collections</code> module contains an <a href="http://docs.python.org/dev/py3k/library/colle... | 12 | 2009-12-04T20:17:10Z | [
"python",
"algorithm",
"dictionary",
"hash"
] |
Do dicts preserve iteration order if they are not modified? | 1,849,324 | <p>If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups).</p>
| 19 | 2009-12-04T20:03:08Z | 1,849,418 | <p>Here is what <code>dict.items()</code> <a href="http://www.python.org/doc/2.6.4/library/stdtypes.html#dict.items">documentation</a> says:</p>
<blockquote>
<p>dict.items() return a copy of the dictionaryâs list of (key, value) pairs.</p>
<p>If items(), keys(), values(), iteritems(), iterkeys(), and itervalu... | 31 | 2009-12-04T20:21:35Z | [
"python",
"algorithm",
"dictionary",
"hash"
] |
Do dicts preserve iteration order if they are not modified? | 1,849,324 | <p>If I have a dictionary in Python, and I iterate through it once, and then again later, is the iteration order guaranteed to be preserved given that I didn't insert, delete, or update any items in the dictionary? (But I might have done look-ups).</p>
| 19 | 2009-12-04T20:03:08Z | 1,850,212 | <p><code>collections.OrderedDict</code> will be available in Python 2.7 in addition to Python 3.1.</p>
<p>For Python versions earlier than 2.7, there's <a href="http://pypi.python.org/pypi/collective.ordereddict/" rel="nofollow">collective.ordereddict</a> on PyPI, and Django has its own <a href="http://code.djangoproj... | 4 | 2009-12-04T22:57:39Z | [
"python",
"algorithm",
"dictionary",
"hash"
] |
How do I INSERT INTO t1 (SELECT * FROM t2) in SQLAlchemy? | 1,849,375 | <p>In SQLAlchemy, how do I populate or update a table from a <code>SELECT</code> statement?</p>
| 16 | 2009-12-04T20:12:58Z | 1,849,474 | <p>SQLalchemy doesn't build this construct for you. You can use the query from text.</p>
<pre><code>session.execute('INSERT INTO t1 (SELECT * FROM t2)')
</code></pre>
<hr>
<h1>EDIT:</h1>
<p>More than one year later, but now on sqlalchemy 0.6+ <a href="http://www.sqlalchemy.org/docs/core/compiler.html#compiling-sub-... | 32 | 2009-12-04T20:30:27Z | [
"python",
"sqlalchemy"
] |
How do I INSERT INTO t1 (SELECT * FROM t2) in SQLAlchemy? | 1,849,375 | <p>In SQLAlchemy, how do I populate or update a table from a <code>SELECT</code> statement?</p>
| 16 | 2009-12-04T20:12:58Z | 4,751,553 | <p>As Noslko pointed out in comment, you can now get rid of raw sql:
<a href="http://www.sqlalchemy.org/docs/core/compiler.html#compiling-sub-elements-of-a-custom-expression-construct" rel="nofollow">http://www.sqlalchemy.org/docs/core/compiler.html#compiling-sub-elements-of-a-custom-expression-construct</a></p>
<p></... | 0 | 2011-01-20T19:25:11Z | [
"python",
"sqlalchemy"
] |
How do I INSERT INTO t1 (SELECT * FROM t2) in SQLAlchemy? | 1,849,375 | <p>In SQLAlchemy, how do I populate or update a table from a <code>SELECT</code> statement?</p>
| 16 | 2009-12-04T20:12:58Z | 17,995,969 | <p>As of 0.8.3, you can now do this directly in sqlalchemy: <a href="http://docs.sqlalchemy.org/en/rel_0_8/core/expression_api.html#sqlalchemy.sql.expression.Insert.from_select">Insert.from_select</a>:</p>
<pre><code>sel = select([table1.c.a, table1.c.b]).where(table1.c.c > 5)
ins = table2.insert().from_select(['a'... | 10 | 2013-08-01T13:51:15Z | [
"python",
"sqlalchemy"
] |
What are the advantages and disadvantages of the require vs. import methods of loading code? | 1,849,376 | <p>Ruby uses <code>require</code>, Python uses <code>import</code>. They're substantially different models, and while I'm more used to the <code>require</code> model, I can see a few places where I think I like <code>import</code> more. I'm curious what things people find particularly easy â or more interestingly, ... | 9 | 2009-12-04T20:12:59Z | 1,849,446 | <p>The Python <code>import</code> has a major feature in that it ties two things together -- <em>how to find the import</em> and under <em>what namespace to include it</em>.</p>
<p>This creates very explicit code:</p>
<p><code>import xml.sax</code></p>
<p>This specifies where to find the code we want to use, by the ... | 14 | 2009-12-04T20:26:30Z | [
"python",
"ruby",
"programming-languages",
"language-features",
"language-design"
] |
What are the advantages and disadvantages of the require vs. import methods of loading code? | 1,849,376 | <p>Ruby uses <code>require</code>, Python uses <code>import</code>. They're substantially different models, and while I'm more used to the <code>require</code> model, I can see a few places where I think I like <code>import</code> more. I'm curious what things people find particularly easy â or more interestingly, ... | 9 | 2009-12-04T20:12:59Z | 1,870,774 | <p>Disclaimer, <em>I am by no means a Python expert.</em></p>
<p>The biggest advantage I see to <code>require</code> over <code>import</code> is simply that you don't have to worry about understanding the mapping between namespaces and file paths. It's obvious: it's just a standard file path.</p>
<p>I really like th... | 1 | 2009-12-09T00:05:21Z | [
"python",
"ruby",
"programming-languages",
"language-features",
"language-design"
] |
What are the advantages and disadvantages of the require vs. import methods of loading code? | 1,849,376 | <p>Ruby uses <code>require</code>, Python uses <code>import</code>. They're substantially different models, and while I'm more used to the <code>require</code> model, I can see a few places where I think I like <code>import</code> more. I'm curious what things people find particularly easy â or more interestingly, ... | 9 | 2009-12-04T20:12:59Z | 1,870,801 | <p>A nice property of <code>require</code> is that it is actually a method defined in <code>Kernel</code>. Thus you can override it and implement your own packaging system for Ruby, which is what e.g. Rubygems does!</p>
<p>PS: <em>I am not selling monkey patching here, but the fact that Ruby's package system can be re... | 2 | 2009-12-09T00:13:55Z | [
"python",
"ruby",
"programming-languages",
"language-features",
"language-design"
] |
What are the advantages and disadvantages of the require vs. import methods of loading code? | 1,849,376 | <p>Ruby uses <code>require</code>, Python uses <code>import</code>. They're substantially different models, and while I'm more used to the <code>require</code> model, I can see a few places where I think I like <code>import</code> more. I'm curious what things people find particularly easy â or more interestingly, ... | 9 | 2009-12-04T20:12:59Z | 1,871,126 | <p>Python's import provides a very explicit kind of namespace: the namespace is the path, you don't have to look into files to know what namespace they do their definitions in, and your file is not cluttered with namespace definitions. This makes the namespace scheme of an application simple and fast to understand (jus... | 1 | 2009-12-09T01:44:11Z | [
"python",
"ruby",
"programming-languages",
"language-features",
"language-design"
] |
How can you detect if two regular expressions overlap in the strings they can match? | 1,849,447 | <p>I have a container of regular expressions. I'd like to analyze them to determine if it's possible to generate a string that matches more than 1 of them. Short of writing my own regex engine with this use case in mind, is there an easy way in C++ or Python to solve this problem? </p>
| 19 | 2009-12-04T20:26:42Z | 1,849,487 | <p>There's no easy way.</p>
<p>As long as your regular expressions use only standard features (Perl lets you embed arbitrary code in matching, I think), you can produce from each one a <a href="http://en.wikipedia.org/wiki/Nondeterministic%5Ffinite%5Fstate%5Fmachine">nondeterministic finite-state automaton (NFA)</a> t... | 27 | 2009-12-04T20:34:03Z | [
"c++",
"python",
"regex",
"algorithm",
"overlap"
] |
How can you detect if two regular expressions overlap in the strings they can match? | 1,849,447 | <p>I have a container of regular expressions. I'd like to analyze them to determine if it's possible to generate a string that matches more than 1 of them. Short of writing my own regex engine with this use case in mind, is there an easy way in C++ or Python to solve this problem? </p>
| 19 | 2009-12-04T20:26:42Z | 1,849,615 | <p>In theory, the problem you describe is impossible.</p>
<p>In practice, if you have a manageable number of regular expressions that use a limited subset or of regexp syntax, and/or a limited selection of strings that can be used to match against the container of regular expressions, you might be able to solve it.</p... | 0 | 2009-12-04T20:58:18Z | [
"c++",
"python",
"regex",
"algorithm",
"overlap"
] |
How can you detect if two regular expressions overlap in the strings they can match? | 1,849,447 | <p>I have a container of regular expressions. I'd like to analyze them to determine if it's possible to generate a string that matches more than 1 of them. Short of writing my own regex engine with this use case in mind, is there an easy way in C++ or Python to solve this problem? </p>
| 19 | 2009-12-04T20:26:42Z | 1,849,809 | <p><a href="http://pyparsing.wikispaces.com/file/view/invRegex.py" rel="nofollow">This regex inverter</a> (written using pyparsing) works with a limited subset of re syntax (no * or + allowed, for instance) - you could invert two re's into two sets, and then look for a set intersection.</p>
| 2 | 2009-12-04T21:38:43Z | [
"c++",
"python",
"regex",
"algorithm",
"overlap"
] |
Is pickle file of python cross-platform? | 1,849,523 | <p>I have created a small python script of mine. I saved the pickle file on Linux and then used it on windows and then again used it back on Linux but now that file is not working on Linux but it is working perfectly on windows.
Is is so that python is coss-platform but the pickle file is not.
Is there any solution to... | 10 | 2009-12-04T20:39:58Z | 1,849,549 | <p>You could use <code>json</code> instead of <code>pickle</code>. If it can save your data, you know it's cross platform.</p>
| 0 | 2009-12-04T20:44:37Z | [
"python",
"file-io",
"pickle"
] |
Is pickle file of python cross-platform? | 1,849,523 | <p>I have created a small python script of mine. I saved the pickle file on Linux and then used it on windows and then again used it back on Linux but now that file is not working on Linux but it is working perfectly on windows.
Is is so that python is coss-platform but the pickle file is not.
Is there any solution to... | 10 | 2009-12-04T20:39:58Z | 1,849,560 | <p>Maybe you don't open the file in binary mode? See <a href="http://stackoverflow.com/questions/283766/pickled-file-wont-load-on-mac-linux">this stackoverflow question</a></p>
| 4 | 2009-12-04T20:46:38Z | [
"python",
"file-io",
"pickle"
] |
Is pickle file of python cross-platform? | 1,849,523 | <p>I have created a small python script of mine. I saved the pickle file on Linux and then used it on windows and then again used it back on Linux but now that file is not working on Linux but it is working perfectly on windows.
Is is so that python is coss-platform but the pickle file is not.
Is there any solution to... | 10 | 2009-12-04T20:39:58Z | 1,849,632 | <p>The <code>pickle</code> module <a href="http://docs.python.org/library/pickle.html#data-stream-format">supports several different data formats</a>. If you are specifying a particular pickle format instead of using the default (0), you may be running into cross-platform binary file problems. You can use plain ASCII p... | 9 | 2009-12-04T21:02:51Z | [
"python",
"file-io",
"pickle"
] |
Is pickle file of python cross-platform? | 1,849,523 | <p>I have created a small python script of mine. I saved the pickle file on Linux and then used it on windows and then again used it back on Linux but now that file is not working on Linux but it is working perfectly on windows.
Is is so that python is coss-platform but the pickle file is not.
Is there any solution to... | 10 | 2009-12-04T20:39:58Z | 1,849,642 | <p>Pickle should be cross-platform, there are versioning/protocol issues, (see <a href="http://docs.python.org/library/pickle.html#data-stream-format" rel="nofollow">http://docs.python.org/library/pickle.html#data-stream-format</a>) but in general if you're using the same release of python on your windows and unix boxe... | 4 | 2009-12-04T21:05:56Z | [
"python",
"file-io",
"pickle"
] |
Is pickle file of python cross-platform? | 1,849,523 | <p>I have created a small python script of mine. I saved the pickle file on Linux and then used it on windows and then again used it back on Linux but now that file is not working on Linux but it is working perfectly on windows.
Is is so that python is coss-platform but the pickle file is not.
Is there any solution to... | 10 | 2009-12-04T20:39:58Z | 1,850,176 | <p>One interesting idea to try out is <a href="http://code.google.com/p/pyon/" rel="nofollow">PyON</a> (Python Object Notation). The current version seems to work at least for simple cases according to my tests. There seems to have been some disagreement on mailing lists whether the project is a good idea, though.</p>
| 0 | 2009-12-04T22:50:47Z | [
"python",
"file-io",
"pickle"
] |
Is pickle file of python cross-platform? | 1,849,523 | <p>I have created a small python script of mine. I saved the pickle file on Linux and then used it on windows and then again used it back on Linux but now that file is not working on Linux but it is working perfectly on windows.
Is is so that python is coss-platform but the pickle file is not.
Is there any solution to... | 10 | 2009-12-04T20:39:58Z | 1,850,806 | <p>Python's pickle is perfectly cross-platform.</p>
<p>This is likely due to EOL (End-Of-Line) differences between Windows and Linux. Make sure to open your pickle files in binary mode both when writing them and when reading them, using open()'s "wb" and "rb" modes respectively.</p>
<p>Note: Passing pickles between d... | 18 | 2009-12-05T01:45:36Z | [
"python",
"file-io",
"pickle"
] |
Can SQLAlchemy's session.merge() update its result with newer data from the database? | 1,849,567 | <p>The SQLAlchemy documentation says "<a href="http://docs.sqlalchemy.org/en/latest/orm/session.html?highlight=merge#unitofwork-merging" rel="nofollow">session.merge()</a> reconciles the current state of an instance and its associated children with existing data in the database".</p>
<p>Does the existing object's stat... | 6 | 2009-12-04T20:47:19Z | 1,851,498 | <p>SQLAlchemy is designed to have single object with each identity in session. But sometimes you have to recreate an object with known identity, e.g. when you get it from network or when you implement offline lock to avoid long transactions. And when you create an object with known identity that might exist in database... | 21 | 2009-12-05T07:40:18Z | [
"python",
"sqlalchemy"
] |
Can SQLAlchemy's session.merge() update its result with newer data from the database? | 1,849,567 | <p>The SQLAlchemy documentation says "<a href="http://docs.sqlalchemy.org/en/latest/orm/session.html?highlight=merge#unitofwork-merging" rel="nofollow">session.merge()</a> reconciles the current state of an instance and its associated children with existing data in the database".</p>
<p>Does the existing object's stat... | 6 | 2009-12-04T20:47:19Z | 18,690,373 | <p>One thing I noticed about merge is that even accessing a field on the unattached object will prevent it from being modified during a merge. </p>
<p>For example, if I have a simple class</p>
<pre><code>class X(Base):
__tablename__= 'x'
id = Column(Integer, primary_key=True)
name = Column(String)
v... | 4 | 2013-09-09T01:26:37Z | [
"python",
"sqlalchemy"
] |
python crypt.crypt in ruby? | 1,849,638 | <p>hi i need this code in ruby I don't know how I write the crypt.crypt method in ruby, any ideas?</p>
<p>(I want to simulate the linux comand .htpasswd)</p>
<pre><code>import random
import crypt
letters = 'abcdefghijklmnopqrstuvwxyz' \
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' \
'0123456789/.'
salt = random.... | 0 | 2009-12-04T21:04:38Z | 1,849,695 | <p>I believe Ruby's <a href="http://ruby-doc.org/core/classes/String.html#M000808" rel="nofollow">String#crypt</a> is equivalent to Python's crypt.crypt, so the Ruby equivalent to your code would be something like:</p>
<pre><code>letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/.'
salt = lette... | 0 | 2009-12-04T21:18:43Z | [
"python",
"ruby"
] |
python crypt.crypt in ruby? | 1,849,638 | <p>hi i need this code in ruby I don't know how I write the crypt.crypt method in ruby, any ideas?</p>
<p>(I want to simulate the linux comand .htpasswd)</p>
<pre><code>import random
import crypt
letters = 'abcdefghijklmnopqrstuvwxyz' \
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' \
'0123456789/.'
salt = random.... | 0 | 2009-12-04T21:04:38Z | 1,857,029 | <p>Jordan already told you about String#crypt, so I'll just show you an easier way to create your letters array:</p>
<pre><code>letters = [*'a'..'z'] + [*'A'..'Z'] + [*0..9] + %w(/ .)
</code></pre>
<p><strong>Update:</strong> since this got upvoted after more than 2 years, I might as well add the 1.9 way of doing thi... | 3 | 2009-12-06T23:34:57Z | [
"python",
"ruby"
] |
How to use IPython with IronPython | 1,849,652 | <p>What is the procedure to get IPython to use IronPython as it's Python interpreter?</p>
<p>I know there were previously some issues: <a href="http://stackoverflow.com/questions/1160501/what-is-required-to-use-ipython-in-ironpython">http://stackoverflow.com/questions/1160501/what-is-required-to-use-ipython-in-ironpy... | 8 | 2009-12-04T21:07:59Z | 5,921,254 | <p>The IPython script that installs on my system in <code>/usr/bin/ipython</code> is only two lines of code to invoke the interpreter:</p>
<pre><code>from IPython import start_ipython
start_ipython()
</code></pre>
<p>So run that under IronPython and see how it works.</p>
<p><s>But as of February 2011, it looks like ... | 0 | 2011-05-07T13:04:59Z | [
"python",
"ironpython",
"ipython"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.