title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
python long running daemon job processor
1,107,826
<p>I want to write a long running process (linux daemon) that serves two purposes:</p> <ul> <li>responds to REST web requests</li> <li>executes jobs which can be scheduled </li> </ul> <p>I originally had it working as a simple program that would run through runs and do the updates which I then cron’d, but now I hav...
2
2009-07-10T05:16:44Z
1,108,019
<p>The usual design pattern for a scheduler would be:</p> <ul> <li>Maintain a list of scheduled jobs, sorted by next-run-time (as Date-Time value);</li> <li>When woken up, compare the first job in the list with the current time. If it's due or overdue, remove it from the list and run it. Continue working your way th...
0
2009-07-10T06:36:49Z
[ "python", "web-services", "scheduling", "long-running-processes" ]
python long running daemon job processor
1,107,826
<p>I want to write a long running process (linux daemon) that serves two purposes:</p> <ul> <li>responds to REST web requests</li> <li>executes jobs which can be scheduled </li> </ul> <p>I originally had it working as a simple program that would run through runs and do the updates which I then cron’d, but now I hav...
2
2009-07-10T05:16:44Z
1,108,243
<ul> <li><p>If the REST server and the scheduled jobs have nothing in common, do two separate implementations, the REST server and the jobs stuff, and run them as separate processes.</p></li> <li><p>As mentioned previously, look into existing schedulers for the jobs stuff. I don't know if <a href="http://twistedmatrix....
2
2009-07-10T07:45:54Z
[ "python", "web-services", "scheduling", "long-running-processes" ]
python long running daemon job processor
1,107,826
<p>I want to write a long running process (linux daemon) that serves two purposes:</p> <ul> <li>responds to REST web requests</li> <li>executes jobs which can be scheduled </li> </ul> <p>I originally had it working as a simple program that would run through runs and do the updates which I then cron’d, but now I hav...
2
2009-07-10T05:16:44Z
1,108,777
<p>Here's what we did.</p> <ol> <li><p>Wrote a simple, pure-wsgi web application to respond to REST requests.</p> <ul> <li><p>Start jobs</p></li> <li><p>Report status of jobs</p></li> </ul></li> <li><p>Extended the built-in <a href="http://docs.python.org/library/wsgiref.html" rel="nofollow">wsgiref</a> server to use...
1
2009-07-10T10:16:47Z
[ "python", "web-services", "scheduling", "long-running-processes" ]
Looking for testing/QA idea for Python Web Application Project
1,107,858
<p>I have the 'luck' of develop and enhance a legacy python web application for almost 2 years. The major contribution I consider I made is the introduction of the use of unit test, nosestest, pychecker and CI server. Yes, that's right, there are still project out there that has no single unit test (To be fair, it has ...
1
2009-07-10T05:29:02Z
1,107,890
<p>Feather's <a href="http://rads.stackoverflow.com/amzn/click/0131177052" rel="nofollow">great book</a> is the first resource I always recommend to anybody in your situation (wish I had it in hand before I faced it my first four times or so!-) -- not Python specific but a lot of VERY useful general-purpose pieces of a...
2
2009-07-10T05:44:14Z
[ "python", "testing", "integration-testing" ]
Looking for testing/QA idea for Python Web Application Project
1,107,858
<p>I have the 'luck' of develop and enhance a legacy python web application for almost 2 years. The major contribution I consider I made is the introduction of the use of unit test, nosestest, pychecker and CI server. Yes, that's right, there are still project out there that has no single unit test (To be fair, it has ...
1
2009-07-10T05:29:02Z
1,108,333
<p>Automated testing seems to be as a very interesting approach. If you are developping a web app, you may be interested in WebDriver <a href="http://code.google.com/p/webdriver/" rel="nofollow">http://code.google.com/p/webdriver/</a></p>
1
2009-07-10T08:10:53Z
[ "python", "testing", "integration-testing" ]
Looking for testing/QA idea for Python Web Application Project
1,107,858
<p>I have the 'luck' of develop and enhance a legacy python web application for almost 2 years. The major contribution I consider I made is the introduction of the use of unit test, nosestest, pychecker and CI server. Yes, that's right, there are still project out there that has no single unit test (To be fair, it has ...
1
2009-07-10T05:29:02Z
1,108,346
<p>Since it is a web app, I'm wondering whether browser-based testing would make sense for you. If so, check out <a href="http://seleniumhq.org/" rel="nofollow" title="Selenium">Selenium</a>, an open-source suite of test tools. Here are some items that might be interesting to you:</p> <ul> <li>automatically starts and...
1
2009-07-10T08:14:03Z
[ "python", "testing", "integration-testing" ]
Looking for testing/QA idea for Python Web Application Project
1,107,858
<p>I have the 'luck' of develop and enhance a legacy python web application for almost 2 years. The major contribution I consider I made is the introduction of the use of unit test, nosestest, pychecker and CI server. Yes, that's right, there are still project out there that has no single unit test (To be fair, it has ...
1
2009-07-10T05:29:02Z
1,108,352
<p>Have a look at <a href="http://twill.idyll.org/" rel="nofollow">Twill</a>, it's a headless web browser written in Python, specifically for automated testing. It can record and replay actions, and it can also hook directly into a WSGI stack.</p>
0
2009-07-10T08:16:00Z
[ "python", "testing", "integration-testing" ]
Looking for testing/QA idea for Python Web Application Project
1,107,858
<p>I have the 'luck' of develop and enhance a legacy python web application for almost 2 years. The major contribution I consider I made is the introduction of the use of unit test, nosestest, pychecker and CI server. Yes, that's right, there are still project out there that has no single unit test (To be fair, it has ...
1
2009-07-10T05:29:02Z
1,108,750
<p>Few things help as much as testing.</p> <p>These two quotes are really important.</p> <ul> <li><p>"how many unit tests you can afford to write."</p></li> <li><p>"From time to time embarrassing mistakes still occur,"</p></li> </ul> <p>If mistakes occur, you haven't written enough tests. If you're still having mis...
0
2009-07-10T10:09:11Z
[ "python", "testing", "integration-testing" ]
Komodo Edit Changes Python sys.path If you "Show in Explorer"
1,107,865
<p>I am using <a href="http://www.activestate.com/komodo%5Fedit/" rel="nofollow">Komodo Edit</a>, a code editor.</p> <p>When I right click on projects and click "Show in Explorer", it will pop up a box just like Windows Explorer at the directory my project is. This is very convenient.</p> <p>However, I noticed an ins...
2
2009-07-10T05:31:35Z
1,108,322
<p>Oups! I've the same behavior on my Vista machine. I didn't see any settings for that feature and I think that this is a Komodo bug.</p> <p>I though about a workaround: create a new command in the toolbox with "explorer %D" as command line. But it has the same problem :-( </p> <p>Update: The workaround works if yo...
2
2009-07-10T08:07:16Z
[ "python", "path", "module", "komodo", "komodoedit" ]
Komodo Edit Changes Python sys.path If you "Show in Explorer"
1,107,865
<p>I am using <a href="http://www.activestate.com/komodo%5Fedit/" rel="nofollow">Komodo Edit</a>, a code editor.</p> <p>When I right click on projects and click "Show in Explorer", it will pop up a box just like Windows Explorer at the directory my project is. This is very convenient.</p> <p>However, I noticed an ins...
2
2009-07-10T05:31:35Z
1,108,374
<p>What should your <code>sys.path</code> be instead? It looks like Python is already on the path, but maybe you need other libraries there, too.</p> <p>If you're missing some key directories, use <code>sys.path.append</code> in one of your Python modules. If you need to move the directory of the Python interpreter ...
0
2009-07-10T08:26:25Z
[ "python", "path", "module", "komodo", "komodoedit" ]
Komodo Edit Changes Python sys.path If you "Show in Explorer"
1,107,865
<p>I am using <a href="http://www.activestate.com/komodo%5Fedit/" rel="nofollow">Komodo Edit</a>, a code editor.</p> <p>When I right click on projects and click "Show in Explorer", it will pop up a box just like Windows Explorer at the directory my project is. This is very convenient.</p> <p>However, I noticed an ins...
2
2009-07-10T05:31:35Z
1,108,734
<p>This is indeed a problem in Komodo. It actually stems from the Explorer window spawned by Komodo having the <code>PYTHONHOME</code> environment variable set to include Komodo's path, since the child process inherits the parent's environment. I noticed this by opening a Command Prompt window through an Explorer spawn...
4
2009-07-10T10:04:59Z
[ "python", "path", "module", "komodo", "komodoedit" ]
Komodo Edit Changes Python sys.path If you "Show in Explorer"
1,107,865
<p>I am using <a href="http://www.activestate.com/komodo%5Fedit/" rel="nofollow">Komodo Edit</a>, a code editor.</p> <p>When I right click on projects and click "Show in Explorer", it will pop up a box just like Windows Explorer at the directory my project is. This is very convenient.</p> <p>However, I noticed an ins...
2
2009-07-10T05:31:35Z
4,893,611
<p>I'd recommend going into Komodo Edit's Preferences >> Environment, and changing PYTHONHOME back to the original python install (e.g. c:\python27)</p>
0
2011-02-04T01:16:30Z
[ "python", "path", "module", "komodo", "komodoedit" ]
Datastore access optimization
1,108,072
<p>I'm writing a small program to record reading progress, the data models are simple:</p> <pre><code>class BookState(db.Model): isbn = db.StringProperty() title = db.StringProperty(required=True) pages = db.IntegerProperty(required=True) img = db.StringProperty() class UpdatePoint(db.Model): b...
0
2009-07-10T06:55:39Z
1,108,157
<p>It seems I used Query class in a wrong way. I need to call ups.fetch() first to get the data. Now the code is a lot faster than before:</p> <pre><code>book = db.get(bookkey) q = book.updatepoint_set q.order('date') ups = q.fetch(50) </code></pre>
3
2009-07-10T07:21:48Z
[ "python", "database", "google-app-engine" ]
Datastore access optimization
1,108,072
<p>I'm writing a small program to record reading progress, the data models are simple:</p> <pre><code>class BookState(db.Model): isbn = db.StringProperty() title = db.StringProperty(required=True) pages = db.IntegerProperty(required=True) img = db.StringProperty() class UpdatePoint(db.Model): b...
0
2009-07-10T06:55:39Z
1,108,166
<p>From the look of the code, it appears that your slow down is because its in the loop and have to kinda pop out to find the object you want. Have you tried something like</p> <pre><code>i = 0 for up in ups: if i != 0: days = (up.date - previous.date).days pages = up.page - previous.page i += 1 previous...
0
2009-07-10T07:23:35Z
[ "python", "database", "google-app-engine" ]
How can I extract the call graph of a function from Python source files?
1,108,119
<p>Do you know an integrated tool that will generate the call graph of a function from Python sources? I need one that is consistent and can run on Windows OS.</p>
10
2009-07-10T07:09:58Z
1,108,142
<p>You could try with <a href="http://pycallgraph.slowchop.com/">PyCallGraph</a><br /> From its documentation:</p> <blockquote> <p>Python Call Graph works with Linux, Windows and Mac OS X.</p> </blockquote> <p>Otherwise, you can directly do it on your own, using the traceback module:</p> <pre><code>import traceb...
9
2009-07-10T07:16:55Z
[ "python", "windows", "call-graph" ]
How can I extract the call graph of a function from Python source files?
1,108,119
<p>Do you know an integrated tool that will generate the call graph of a function from Python sources? I need one that is consistent and can run on Windows OS.</p>
10
2009-07-10T07:09:58Z
1,108,153
<p>What about <a href="http://pycallgraph.slowchop.com/">pycallgraph</a>, it's a Python module that creates call graphs for Python programs. It works on windows. Just download <a href="http://www.graphviz.org/Download%5Fwindows.php">graphviz</a> and <a href="http://pycallgraph.slowchop.com/pycallgraph/wiki/documentatio...
5
2009-07-10T07:20:30Z
[ "python", "windows", "call-graph" ]
How can I extract the call graph of a function from Python source files?
1,108,119
<p>Do you know an integrated tool that will generate the call graph of a function from Python sources? I need one that is consistent and can run on Windows OS.</p>
10
2009-07-10T07:09:58Z
10,366,447
<p>PyCallGraph produces the dynamic graph resulting from the specific execution of a Python program and not the static graph extracted from the source code. Does anybody know of a tool which produces the static graph?</p>
9
2012-04-28T18:40:30Z
[ "python", "windows", "call-graph" ]
How to include a python .egg library that is in a subdirectory (relative location)?
1,108,384
<p>How do you import python .egg files that are stored in a relative location to the .py code?</p> <p>For example,</p> <pre><code>My Application/ My Application/library1.egg My Application/libs/library2.egg My Application/test.py </code></pre> <p>How do you import and use library1 and library2 from within test.py, w...
12
2009-07-10T08:29:05Z
1,108,400
<p>An .egg is just a .zip file that acts like a directory from which you can import stuff.</p> <p>You can use the <code>PYTHONPATH</code> variable to add the <code>.egg</code> to your path, or append a directory to <code>sys.path</code>. Another option is to use a <code>.pth</code> file pointing to the eggs.</p> <p>...
18
2009-07-10T08:32:35Z
[ "python", "egg" ]
How to include a python .egg library that is in a subdirectory (relative location)?
1,108,384
<p>How do you import python .egg files that are stored in a relative location to the .py code?</p> <p>For example,</p> <pre><code>My Application/ My Application/library1.egg My Application/libs/library2.egg My Application/test.py </code></pre> <p>How do you import and use library1 and library2 from within test.py, w...
12
2009-07-10T08:29:05Z
1,108,423
<p>You can include each egg on the sys.path, or create a .pth file that mentions each egg.</p> <p>If you have many eggs that you need in your system I'd recommend using something like buildout, that will make the setup easily replicatable. It will handle the eggs for you.</p> <p><a href="http://pypi.python.org/pypi/z...
1
2009-07-10T08:38:58Z
[ "python", "egg" ]
How do I read a date in Excel format in Python?
1,108,428
<p>How can I convert an Excel date (in a number format) to a proper date in Python?</p>
32
2009-07-10T08:41:45Z
1,108,474
<p>You can use <a href="http://pypi.python.org/pypi/xlrd">xlrd</a>.</p> <p>From its <a href="http://www.lexicon.net/sjmachin/xlrd.html">documentation</a>, you can read that dates are always stored as numbers; however, you can use <a href="http://www.lexicon.net/sjmachin/xlrd.html#xlrd.xldate%5Fas%5Ftuple-function"><co...
50
2009-07-10T08:53:44Z
[ "python", "excel", "datetime" ]
How do I read a date in Excel format in Python?
1,108,428
<p>How can I convert an Excel date (in a number format) to a proper date in Python?</p>
32
2009-07-10T08:41:45Z
1,109,523
<p>After testing and a few days wait for feedback, I'll svn-commit the following whole new function in xlrd's xldate module ... note that it won't be available to the diehards still running Python 2.1 or 2.2.</p> <pre><code>## # Convert an Excel number (presumed to represent a date, a datetime or a time) into # a Pyth...
20
2009-07-10T13:29:51Z
[ "python", "excel", "datetime" ]
How do I read a date in Excel format in Python?
1,108,428
<p>How can I convert an Excel date (in a number format) to a proper date in Python?</p>
32
2009-07-10T08:41:45Z
1,112,664
<p>Here's the bare-knuckle no-seat-belts use-at-own-risk version:</p> <pre><code>import datetime def minimalist_xldate_as_datetime(xldate, datemode): # datemode: 0 for 1900-based, 1 for 1904-based return ( datetime.datetime(1899, 12, 30) + datetime.timedelta(days=xldate + 1462 * datemode) ...
17
2009-07-11T01:25:02Z
[ "python", "excel", "datetime" ]
How do I read a date in Excel format in Python?
1,108,428
<p>How can I convert an Excel date (in a number format) to a proper date in Python?</p>
32
2009-07-10T08:41:45Z
24,132,415
<p>For quick and dirty:</p> <pre><code>year, month, day, hour, minute, second = xlrd.xldate_as_tuple(excelDate, wb.datemode) whatYouWant = str(month)+'/'+str(day)+'/'+str(year) </code></pre>
0
2014-06-10T03:35:15Z
[ "python", "excel", "datetime" ]
How do I read a date in Excel format in Python?
1,108,428
<p>How can I convert an Excel date (in a number format) to a proper date in Python?</p>
32
2009-07-10T08:41:45Z
26,231,244
<p>Please refer to this link: <a href="http://stackoverflow.com/questions/13962837/reading-date-as-a-string-not-float-from-excel-using-python-xlrd">Reading date as a string not float from excel using python xlrd</a></p> <p>it worked for me: </p> <p>in shot this the link has: </p> <pre><code>import datetime, xlrd boo...
2
2014-10-07T07:59:29Z
[ "python", "excel", "datetime" ]
How do I read a date in Excel format in Python?
1,108,428
<p>How can I convert an Excel date (in a number format) to a proper date in Python?</p>
32
2009-07-10T08:41:45Z
28,220,798
<p><code>xlrd.xldate_as_tuple</code> is nice, but there's <code>xlrd.xldate.xldate_as_datetime</code> that converts to datetime as well.</p> <pre><code>import xlrd wb = xlrd.open_workbook(filename) xlrd.xldate.xldate_as_datetime(41889, wb.datemode) =&gt; datetime.datetime(2014, 9, 7, 0, 0) </code></pre>
12
2015-01-29T17:21:59Z
[ "python", "excel", "datetime" ]
How do I read a date in Excel format in Python?
1,108,428
<p>How can I convert an Excel date (in a number format) to a proper date in Python?</p>
32
2009-07-10T08:41:45Z
29,336,555
<p>A combination of peoples post gave me the date and the time for excel conversion. I did return it as a string</p> <pre><code>def xldate_to_datetime(xldate): tempDate = datetime.datetime(1900, 1, 1) deltaDays = datetime.timedelta(days=int(xldate)) secs = (int((xldate%1)*86400)-60) detlaSeconds = datetime.tim...
0
2015-03-30T00:14:18Z
[ "python", "excel", "datetime" ]
How do I read a date in Excel format in Python?
1,108,428
<p>How can I convert an Excel date (in a number format) to a proper date in Python?</p>
32
2009-07-10T08:41:45Z
36,034,857
<p>When converting an excel file to CSV the date/time cell looks like this:</p> <p>foo, 3/16/2016 10:38, bar,</p> <p>To convert the datetime text value to datetime python object do this:</p> <pre><code>from datetime import datetime date_object = datetime.strptime('3/16/2016 10:38', '%m/%d/%Y %H:%M') # excel form...
0
2016-03-16T11:49:23Z
[ "python", "excel", "datetime" ]
Returning MatPotLib image as string
1,108,881
<p>I am using matplotlib in a django app and would like to directly return the rendered image. So far I can go <code>plt.savefig(...)</code>, then return the location of the image</p> <p>What I want to do is:</p> <pre><code>return HttpResponse(plt.renderfig(...), mimetype="image/png") </code></pre> <p>Any ideas?</p>...
6
2009-07-10T10:46:42Z
1,108,930
<p>Employ ducktyping and pass a object of your own, in disguise of file object</p> <pre><code>class MyFile(object): def __init__(self): self._data = "" def write(self, data): self._data += data myfile = MyFile() fig.savefig(myfile) print myfile._data </code></pre> <p>you can use myfile = Stri...
0
2009-07-10T11:01:13Z
[ "python", "django", "matplotlib" ]
Returning MatPotLib image as string
1,108,881
<p>I am using matplotlib in a django app and would like to directly return the rendered image. So far I can go <code>plt.savefig(...)</code>, then return the location of the image</p> <p>What I want to do is:</p> <pre><code>return HttpResponse(plt.renderfig(...), mimetype="image/png") </code></pre> <p>Any ideas?</p>...
6
2009-07-10T10:46:42Z
1,108,972
<p>what about <a href="http://docs.python.org/library/stringio.html#module-cStringIO">cStringIO</a>?</p> <pre><code>import pylab import cStringIO pylab.plot([3,7,2,1]) output = cStringIO.StringIO() pylab.savefig('test.png', dpi=75) pylab.savefig(output, dpi=75) print output.getvalue() == open('test.png', 'rb').read() ...
6
2009-07-10T11:12:49Z
[ "python", "django", "matplotlib" ]
Returning MatPotLib image as string
1,108,881
<p>I am using matplotlib in a django app and would like to directly return the rendered image. So far I can go <code>plt.savefig(...)</code>, then return the location of the image</p> <p>What I want to do is:</p> <pre><code>return HttpResponse(plt.renderfig(...), mimetype="image/png") </code></pre> <p>Any ideas?</p>...
6
2009-07-10T10:46:42Z
1,109,442
<p>Django's <code>HttpResponse</code> object supports file-like API and you can pass a file-object to savefig.</p> <pre><code>response = HttpResponse(mimetype="image/png") # create your image as usual, e.g. pylab.plot(...) pylab.savefig(response, format="png") return response </code></pre> <p>Hence, you can return th...
14
2009-07-10T13:13:05Z
[ "python", "django", "matplotlib" ]
Returning MatPotLib image as string
1,108,881
<p>I am using matplotlib in a django app and would like to directly return the rendered image. So far I can go <code>plt.savefig(...)</code>, then return the location of the image</p> <p>What I want to do is:</p> <pre><code>return HttpResponse(plt.renderfig(...), mimetype="image/png") </code></pre> <p>Any ideas?</p>...
6
2009-07-10T10:46:42Z
1,112,190
<p>There is a recipe in the <a href="http://scipy.org/Cookbook/Matplotlib/Django" rel="nofollow">Matplotlib Cookbook</a> that does exactly this. At its core, it looks like:</p> <pre><code>def simple(request): from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure im...
2
2009-07-10T21:56:05Z
[ "python", "django", "matplotlib" ]
How to store an IP in mySQL
1,108,918
<p>We've got a healthy debate going on in the office this week. We're creating a Db to store proxy information, for the most part we have the schema worked out except for how we should store IPs. One camp wants to use 4 smallints, one for each octet and the other wants to use a 1 big int,INET_ATON.</p> <p>These tables...
19
2009-07-10T10:58:42Z
1,108,931
<p>Use PostgreSQL, there's a <a href="http://www.postgresql.org/docs/8.4/static/datatype-net-types.html#DATATYPE-INET" rel="nofollow">native data type</a> for that.</p> <p>More seriously, I would fall into the "one 32-bit integer" camp. An IP address only makes sense when all four octets are considered together, so th...
3
2009-07-10T11:01:16Z
[ "python", "mysql", "perl", "ip-address" ]
How to store an IP in mySQL
1,108,918
<p>We've got a healthy debate going on in the office this week. We're creating a Db to store proxy information, for the most part we have the schema worked out except for how we should store IPs. One camp wants to use 4 smallints, one for each octet and the other wants to use a 1 big int,INET_ATON.</p> <p>These tables...
19
2009-07-10T10:58:42Z
1,108,942
<p>A <code>BIGINT</code> is <code>8</code> bytes in <code>MySQL</code>.</p> <p>To store <code>IPv4</code> addresses, an <code>UNSINGED INT</code> is enough, which I think is what you shoud use.</p> <p>I can't imagine a scenario where <code>4</code> octets would gain more performance than a single <code>INT</code>, an...
12
2009-07-10T11:03:11Z
[ "python", "mysql", "perl", "ip-address" ]
How to store an IP in mySQL
1,108,918
<p>We've got a healthy debate going on in the office this week. We're creating a Db to store proxy information, for the most part we have the schema worked out except for how we should store IPs. One camp wants to use 4 smallints, one for each octet and the other wants to use a 1 big int,INET_ATON.</p> <p>These tables...
19
2009-07-10T10:58:42Z
1,109,046
<p>I would suggest looking at what type of queries you will be running to decide which format you adopt.</p> <p>Only if you need to pull out or compare individual octets would you have to consider splitting them up into separate fields.</p> <p>Otherwise, store it as an 4 byte integer. That also has the bonus of allow...
19
2009-07-10T11:34:58Z
[ "python", "mysql", "perl", "ip-address" ]
How to store an IP in mySQL
1,108,918
<p>We've got a healthy debate going on in the office this week. We're creating a Db to store proxy information, for the most part we have the schema worked out except for how we should store IPs. One camp wants to use 4 smallints, one for each octet and the other wants to use a 1 big int,INET_ATON.</p> <p>These tables...
19
2009-07-10T10:58:42Z
1,109,278
<p>Having seperate fields doesn't sound particularly sensible to me - much like splitting a zipcode into sections or a phone number.</p> <p>Might be useful if you wanted specific info on the sections, but I see no real reason to not use a 32 bit int.</p>
1
2009-07-10T12:38:51Z
[ "python", "mysql", "perl", "ip-address" ]
How to store an IP in mySQL
1,108,918
<p>We've got a healthy debate going on in the office this week. We're creating a Db to store proxy information, for the most part we have the schema worked out except for how we should store IPs. One camp wants to use 4 smallints, one for each octet and the other wants to use a 1 big int,INET_ATON.</p> <p>These tables...
19
2009-07-10T10:58:42Z
1,109,477
<p>Efficient transformation of ip to int and int to ip (could be useful to you): (PERL)</p> <pre><code>sub ip2dec { my @octs = split /\./,shift; return ($octs[0] &lt;&lt; 24) + ($octs[1] &lt;&lt; 16) + ($octs[2] &lt;&lt; 8) + $octs[3]; } sub dec2ip { my $number = shift; my $first_oct = $number &gt;&g...
-1
2009-07-10T13:21:38Z
[ "python", "mysql", "perl", "ip-address" ]
Finding the coordinates of tiles that are covered by a rectangle with x,y,w,h pixel coordinates
1,108,929
<p>Say I have a tile based system using 16x16 pixels. How would you find out what tiles are covered by a rectangle defined by floating point pixel units? </p> <p>for eg,</p> <pre><code>rect(x=16.0,y=16.0, w=1.0, h=1.0) -&gt; tile(x=1, y=1, w=1, h=1) rect(x=16.0,y=16.0, w=16.0, h=16.0) -&gt; tile(x=1, y=1, w=1, h=1)...
2
2009-07-10T11:01:03Z
1,108,981
<p>here is the one which passes your test cases, tell me if there is any edge case</p> <pre><code>TILE_W = TILE_H = 16 from math import floor, ceil def get_tile2(x,y,w,h): x1 = int(x/TILE_W) y1 = int(y/TILE_H) x2 = int((x+w)/TILE_W) y2 = int((y+h)/TILE_H) if (x+w)%16 == 0: #edge case x2-=...
0
2009-07-10T11:15:29Z
[ "python", "algorithm", "math", "geometry", "coordinates" ]
Finding the coordinates of tiles that are covered by a rectangle with x,y,w,h pixel coordinates
1,108,929
<p>Say I have a tile based system using 16x16 pixels. How would you find out what tiles are covered by a rectangle defined by floating point pixel units? </p> <p>for eg,</p> <pre><code>rect(x=16.0,y=16.0, w=1.0, h=1.0) -&gt; tile(x=1, y=1, w=1, h=1) rect(x=16.0,y=16.0, w=16.0, h=16.0) -&gt; tile(x=1, y=1, w=1, h=1)...
2
2009-07-10T11:01:03Z
1,108,992
<p>You could try aligning you pixel coordinates ot integers before dividing by tile width:</p> <pre><code>xlower = int(floor(x)) xupper = int(ceil(x + w)) </code></pre>
0
2009-07-10T11:17:47Z
[ "python", "algorithm", "math", "geometry", "coordinates" ]
Finding the coordinates of tiles that are covered by a rectangle with x,y,w,h pixel coordinates
1,108,929
<p>Say I have a tile based system using 16x16 pixels. How would you find out what tiles are covered by a rectangle defined by floating point pixel units? </p> <p>for eg,</p> <pre><code>rect(x=16.0,y=16.0, w=1.0, h=1.0) -&gt; tile(x=1, y=1, w=1, h=1) rect(x=16.0,y=16.0, w=16.0, h=16.0) -&gt; tile(x=1, y=1, w=1, h=1)...
2
2009-07-10T11:01:03Z
1,117,936
<p>This could probably be condensed a bit more, but here you go.</p> <pre><code>def get_tile(x,y,w,h): x1 = int(x / TILE_W) x2 = (x + w) / TILE_W y1 = int(y / TILE_H) y2 = (x + w) / TILE_H if int(x2) == x2: x2 = int(x2 - 1) else: x2 = int(x2) if int(y2) == y2: y2...
0
2009-07-13T06:25:57Z
[ "python", "algorithm", "math", "geometry", "coordinates" ]
Finding the coordinates of tiles that are covered by a rectangle with x,y,w,h pixel coordinates
1,108,929
<p>Say I have a tile based system using 16x16 pixels. How would you find out what tiles are covered by a rectangle defined by floating point pixel units? </p> <p>for eg,</p> <pre><code>rect(x=16.0,y=16.0, w=1.0, h=1.0) -&gt; tile(x=1, y=1, w=1, h=1) rect(x=16.0,y=16.0, w=16.0, h=16.0) -&gt; tile(x=1, y=1, w=1, h=1)...
2
2009-07-10T11:01:03Z
1,164,203
<p>Matt's solution with bug-fixes:</p> <pre><code>from __future__ import division import math TILE_W = TILE_H = 16 def get_tile(x,y,w,h): x1 = int(math.floor(x/TILE_W)) x2 = int(math.ceil((x + w)/TILE_W)) y1 = int(math.floor(y/TILE_H)) y2 = int(math.ceil((y + h)/TILE_H)) return x1, y1, x2-x1, y2-...
1
2009-07-22T09:52:56Z
[ "python", "algorithm", "math", "geometry", "coordinates" ]
Issues with inspect.py when used inside Jython
1,108,958
<p>I am using an application developed in Jython. When I try to use the inspect.py in that, it shows error message.</p> <p>My code goes like this</p> <pre><code>import inspect,os,sys,pprint,imp def handle_stackframe_without_leak(getframe): frame = inspect.currentframe() try: function = inspect.getfram...
2
2009-07-10T11:07:44Z
1,112,619
<p>This might help <a href="http://grinder.sourceforge.net/faq.html#re-problems" rel="nofollow">http://grinder.sourceforge.net/faq.html#re-problems</a>.</p> <p>For a quick check, try adding <code>import re</code> in findsource method (<em>C:\Program Files\jython221ondiffjava\Lib\inspect.py</em>)</p> <pre><code> def f...
0
2009-07-11T00:58:54Z
[ "python", "module", "jython", "inspect" ]
Issues with inspect.py when used inside Jython
1,108,958
<p>I am using an application developed in Jython. When I try to use the inspect.py in that, it shows error message.</p> <p>My code goes like this</p> <pre><code>import inspect,os,sys,pprint,imp def handle_stackframe_without_leak(getframe): frame = inspect.currentframe() try: function = inspect.getfram...
2
2009-07-10T11:07:44Z
1,167,318
<p>Have you tried running your program on the command line with Jython (so outside of the app)? When I run your program with Jython 2.2.1 or Jython 2.5.0, I get identical output as from Python.</p>
1
2009-07-22T18:42:09Z
[ "python", "module", "jython", "inspect" ]
Separation of ORM and validation
1,108,967
<p>I use django and I wonder in what cases where model validation should go. There are at least two variants:</p> <ol> <li>Validate in the model's save method and to raise IntegrityError or another exception if business rules were violated</li> <li>Validate data using forms and built-in clean_* facilities</li> </ol> ...
0
2009-07-10T11:09:37Z
1,108,987
<p>I am not sure if this is best practise but what I do is that I tend to validate both client side and server side before pushing the data to the database. I know it requires a lot more effort but this can be done by setting some values before use and then maintaining them.</p> <p>You could also try push in size cont...
0
2009-07-10T11:17:22Z
[ "python", "django", "validation", "architecture", "django-models" ]
Separation of ORM and validation
1,108,967
<p>I use django and I wonder in what cases where model validation should go. There are at least two variants:</p> <ol> <li>Validate in the model's save method and to raise IntegrityError or another exception if business rules were violated</li> <li>Validate data using forms and built-in clean_* facilities</li> </ol> ...
0
2009-07-10T11:09:37Z
1,109,190
<p>Your two options are two different things.</p> <ul> <li>Form-based validation can be regarded as syntactic validation + convert HTTP request parameters from text to Python types.</li> <li>Model-based validation can be regarded as semantic validation, sometimes using context not available at the HTTP/form layer.</li...
0
2009-07-10T12:14:50Z
[ "python", "django", "validation", "architecture", "django-models" ]
Separation of ORM and validation
1,108,967
<p>I use django and I wonder in what cases where model validation should go. There are at least two variants:</p> <ol> <li>Validate in the model's save method and to raise IntegrityError or another exception if business rules were violated</li> <li>Validate data using forms and built-in clean_* facilities</li> </ol> ...
0
2009-07-10T11:09:37Z
1,109,221
<p>There's an ongoing Google Summer of Code project that aims to bring validation to the Django model layer. You can read more about it in <a href="http://www.honzakral.com/validation.pdf" rel="nofollow">this presentation</a> from the GSoC student (Honza Kral). There's also a <a href="http://github.com/HonzaKral/django...
0
2009-07-10T12:24:50Z
[ "python", "django", "validation", "architecture", "django-models" ]
Separation of ORM and validation
1,108,967
<p>I use django and I wonder in what cases where model validation should go. There are at least two variants:</p> <ol> <li>Validate in the model's save method and to raise IntegrityError or another exception if business rules were violated</li> <li>Validate data using forms and built-in clean_* facilities</li> </ol> ...
0
2009-07-10T11:09:37Z
1,109,327
<p><strong>"but what the hell all that validation features are doing in django.db.models? "</strong></p> <p>One word: Legacy. Early versions of Django had less robust forms and the validation was scattered.</p> <p><strong>"So should I check such conditions in save method?"</strong></p> <p>No, you should use a form ...
0
2009-07-10T12:49:43Z
[ "python", "django", "validation", "architecture", "django-models" ]
Separation of ORM and validation
1,108,967
<p>I use django and I wonder in what cases where model validation should go. There are at least two variants:</p> <ol> <li>Validate in the model's save method and to raise IntegrityError or another exception if business rules were violated</li> <li>Validate data using forms and built-in clean_* facilities</li> </ol> ...
0
2009-07-10T11:09:37Z
1,111,592
<p><strong>DB/Model validation</strong></p> <p>The data store in database must always be in a certain form/state. For example: required first name, last name, foreign key, unique constraint. This is where the logic of you app resides. No matter where you think the data comes from - it should be "validated" here and a...
0
2009-07-10T19:43:55Z
[ "python", "django", "validation", "architecture", "django-models" ]
switch versions of python
1,108,974
<p>Story: One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty. Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless.</p> <p>Qu...
14
2009-07-10T11:12:53Z
1,108,999
<p>Use <a href="http://pypi.python.org/pypi/virtualenv">Virtualenv</a>.</p> <p>There is more information here: <a href="http://web.archive.org/web/20120303203403/http://www.arthurkoziel.com/2008/10/22/working-virtualenv/">Working with virtualenv</a>.</p> <p>Using virtualenv you can create a new virtual python environ...
30
2009-07-10T11:19:31Z
[ "python", "development-environment", "ubuntu-9.04" ]
switch versions of python
1,108,974
<p>Story: One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty. Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless.</p> <p>Qu...
14
2009-07-10T11:12:53Z
1,109,135
<p>A more grassroot approach than Virtualenv is the side-by-side installation of two Python versions.</p> <p>If there is an existing installation, and you want a second installation into the same root path (e.g. /usr/local), use this target when making install:</p> <pre><code>make altinstall </code></pre> <p>When yo...
3
2009-07-10T11:57:08Z
[ "python", "development-environment", "ubuntu-9.04" ]
switch versions of python
1,108,974
<p>Story: One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty. Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless.</p> <p>Qu...
14
2009-07-10T11:12:53Z
1,109,305
<p>"Question1: How will i tell any framework that go and use version so and so pf python like day django to use 2.6 and say mjango to use 2.4?"</p> <p>You simply run them with the specific python version they need. Run mjango with /usr/bin/python2.4 and django with /usr/bin/python2.6. As easy as that.</p> <p>"Questio...
1
2009-07-10T12:43:57Z
[ "python", "development-environment", "ubuntu-9.04" ]
switch versions of python
1,108,974
<p>Story: One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty. Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless.</p> <p>Qu...
14
2009-07-10T11:12:53Z
9,547,468
<p>I find <a href="http://github.com/utahta/pythonbrew" rel="nofollow">http://github.com/utahta/pythonbrew</a> much easier to install and use than any other solution.</p> <p>Just install it and you'll have these options:</p> <pre><code>pythonbrew install 2.7.2 pythonbrew use 2.7.2 # use 2.7.2 for a current terminal s...
2
2012-03-03T15:57:54Z
[ "python", "development-environment", "ubuntu-9.04" ]
switch versions of python
1,108,974
<p>Story: One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty. Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless.</p> <p>Qu...
14
2009-07-10T11:12:53Z
10,750,234
<p>Pythonbrew is a magical tool. Which can also be called as Python version manager similar to that of RVM-Ruby version manager but Pythonbrew is inspired by Perlbrew.</p> <p>Pythonbrew is a program to automate the building and installation of Python in the users $HOME.</p> <pre><code> Dependencies – curl </cod...
6
2012-05-25T07:26:01Z
[ "python", "development-environment", "ubuntu-9.04" ]
switch versions of python
1,108,974
<p>Story: One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty. Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless.</p> <p>Qu...
14
2009-07-10T11:12:53Z
27,402,164
<p><a href="https://github.com/yyuu/pyenv" rel="nofollow">pyenv</a> is yet another Python manager. The README.md at that link has a good set of instructions, but they basically are:</p> <pre><code>$ cd $ git clone git://github.com/yyuu/pyenv.git .pyenv </code></pre> <p>Then set up your $PATH.</p> <pre><code>$ echo '...
0
2014-12-10T13:24:32Z
[ "python", "development-environment", "ubuntu-9.04" ]
switch versions of python
1,108,974
<p>Story: One of the app that i have works on python 2.4 and other on 2.6. I tried to do a sym link of python2.4 to python and things started to break loose on ubuntu jaunty. Now i am downloading every dependency of 2.4 and installing it using python2.4 setup.py install. The dependencies seem to be endless.</p> <p>Qu...
14
2009-07-10T11:12:53Z
35,381,570
<p>Move to the project directory :</p> <p>Create an environment : virtualenv -p python2.7 --no-site-packages ~/env/twoseven</p> <p>Then activate your source : source ~/env/twoseven/bin/activate</p>
0
2016-02-13T15:18:51Z
[ "python", "development-environment", "ubuntu-9.04" ]
Getting list of pixel values from PIL
1,109,422
<p>Guys, I'm looking for a bit of assistance. I'm a newbie programmer and one of the problems I'm having at the minute is trying to convert a black &amp; white <code>.jpg</code> image into a list which I can then modulate into an audio signal. This is part of a lager project to create a python SSTV program.</p> <p>I h...
12
2009-07-10T13:08:07Z
1,109,747
<p>Python shouldn't crash when you call getdata(). The image might be corrupted or there is something wrong with your PIL installation. Try it with another image or post the image you are using.</p> <p>This should break down the image the way you want:</p> <pre><code>from PIL import Image im = Image.open('um_000000.p...
29
2009-07-10T14:04:23Z
[ "python", "image", "python-imaging-library" ]
Getting list of pixel values from PIL
1,109,422
<p>Guys, I'm looking for a bit of assistance. I'm a newbie programmer and one of the problems I'm having at the minute is trying to convert a black &amp; white <code>.jpg</code> image into a list which I can then modulate into an audio signal. This is part of a lager project to create a python SSTV program.</p> <p>I h...
12
2009-07-10T13:08:07Z
1,110,124
<p>If you have <a href="http://numpy.scipy.org/">numpy</a> installed you can try:</p> <pre><code>data = numpy.asarray(im) </code></pre> <p>(I say "try" here, because it's unclear why <code>getdata()</code> isn't working for you, and I don't know whether <code>asarray</code> uses getdata, but it's worth a test.)</p>
13
2009-07-10T15:12:52Z
[ "python", "image", "python-imaging-library" ]
Getting list of pixel values from PIL
1,109,422
<p>Guys, I'm looking for a bit of assistance. I'm a newbie programmer and one of the problems I'm having at the minute is trying to convert a black &amp; white <code>.jpg</code> image into a list which I can then modulate into an audio signal. This is part of a lager project to create a python SSTV program.</p> <p>I h...
12
2009-07-10T13:08:07Z
1,111,950
<p>I assume you are getting an error like.. <code>TypeError: 'PixelAccess' object is not iterable</code>...?</p> <p>See the <a href="http://effbot.org/imagingbook/image.htm#tag-Image.Image.load">Image.load</a> documentation for how to access pixels..</p> <p>Basically, to get the list of pixels in an image, using <cod...
10
2009-07-10T20:55:24Z
[ "python", "image", "python-imaging-library" ]
Getting list of pixel values from PIL
1,109,422
<p>Guys, I'm looking for a bit of assistance. I'm a newbie programmer and one of the problems I'm having at the minute is trying to convert a black &amp; white <code>.jpg</code> image into a list which I can then modulate into an audio signal. This is part of a lager project to create a python SSTV program.</p> <p>I h...
12
2009-07-10T13:08:07Z
20,018,486
<p>Or if you want to count white or black pixels</p> <p>This is also a solution:</p> <pre><code>from PIL import Image import operator img = Image.open("your_file.png").convert('1') black, white = img.getcolors() print black[0] print white[0] </code></pre>
2
2013-11-16T12:31:29Z
[ "python", "image", "python-imaging-library" ]
Getting list of pixel values from PIL
1,109,422
<p>Guys, I'm looking for a bit of assistance. I'm a newbie programmer and one of the problems I'm having at the minute is trying to convert a black &amp; white <code>.jpg</code> image into a list which I can then modulate into an audio signal. This is part of a lager project to create a python SSTV program.</p> <p>I h...
12
2009-07-10T13:08:07Z
22,503,379
<p>As I commented above, problem seems to be the conversion from PIL internal list format to a standard python list type. I've found that Image.tostring() is much faster, and depending on your needs it might be enough. In my case, I needed to calculate the CRC32 digest of image data, and it suited fine.</p> <p>If you ...
1
2014-03-19T10:49:16Z
[ "python", "image", "python-imaging-library" ]
Getting list of pixel values from PIL
1,109,422
<p>Guys, I'm looking for a bit of assistance. I'm a newbie programmer and one of the problems I'm having at the minute is trying to convert a black &amp; white <code>.jpg</code> image into a list which I can then modulate into an audio signal. This is part of a lager project to create a python SSTV program.</p> <p>I h...
12
2009-07-10T13:08:07Z
38,550,318
<p>Not PIL, but <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.imread.html" rel="nofollow"><code>scipy.misc.imread</code></a> might still be interesting:</p> <pre><code>import scipy.misc im = scipy.misc.imread('um_000000.png', flatten=False, mode='RGB') print(im.shape) </code></pre> <p>gives<...
0
2016-07-24T08:56:36Z
[ "python", "image", "python-imaging-library" ]
What's a good way to render outlined fonts?
1,109,498
<p>I'm writing a game in python with pygame and need to render text onto the screen.</p> <p>I want to render this text in one colour with an outline, so that I don't have to worry about what sort of background the the text is being displayed over.</p> <p>pygame.font doesn't seem to offer support for doing this sort o...
6
2009-07-10T13:24:56Z
1,109,548
<p>I can give you a quick and <em>bad</em> solution:<br><br> print the text 8 times, to surround it, plus one more time for the inner text, like this</p> <pre><code>UUU UIU UUU </code></pre> <p>U for outer color and I for the inner color.</p>
2
2009-07-10T13:35:01Z
[ "python", "fonts", "pygame" ]
What's a good way to render outlined fonts?
1,109,498
<p>I'm writing a game in python with pygame and need to render text onto the screen.</p> <p>I want to render this text in one colour with an outline, so that I don't have to worry about what sort of background the the text is being displayed over.</p> <p>pygame.font doesn't seem to offer support for doing this sort o...
6
2009-07-10T13:24:56Z
1,109,553
<p>A quick and dirty way would be to render your text multiple times with the outline color, shifted by small amounts on a circle around the text position:</p> <pre> 1 8 | 2 \ | / \|/ 7----*----3 /|\ / | \ 6 | 4 5 </pre> <p><strong>Edit</st...
3
2009-07-10T13:35:38Z
[ "python", "fonts", "pygame" ]
Does python have a sorted list?
1,109,804
<p>By which I mean a structure with:</p> <ul> <li>O(log n) complexity for <code>x.push()</code> operations</li> <li>O(log n) complexity to find an element</li> <li>O(n) complexity to compute <code>list(x)</code> which will be sorted</li> </ul> <p>I also had a related question about performance of <code>list(...).inse...
78
2009-07-10T14:18:00Z
1,109,866
<p>The standard Python list is not sorted in any form. The standard heapq module can be used to append in O(log n) and remove the smallest one in O(log n), but isn't a sorted list in your definition.</p> <p>There are various implementations of balanced trees for Python that meet your requirements, e.g. <a href="http:/...
35
2009-07-10T14:26:45Z
[ "python", "list", "sorting" ]
Does python have a sorted list?
1,109,804
<p>By which I mean a structure with:</p> <ul> <li>O(log n) complexity for <code>x.push()</code> operations</li> <li>O(log n) complexity to find an element</li> <li>O(n) complexity to compute <code>list(x)</code> which will be sorted</li> </ul> <p>I also had a related question about performance of <code>list(...).inse...
78
2009-07-10T14:18:00Z
1,109,973
<p>Though it does not (yet) provide a custom search function, the <a href="http://docs.python.org/3.0/library/heapq.html"><code>heapq</code></a> module may suit your needs. It implements a heap queue using a regular list. You'd have to write your own efficient membership test that makes use of the queue's internal stru...
5
2009-07-10T14:43:24Z
[ "python", "list", "sorting" ]
Does python have a sorted list?
1,109,804
<p>By which I mean a structure with:</p> <ul> <li>O(log n) complexity for <code>x.push()</code> operations</li> <li>O(log n) complexity to find an element</li> <li>O(n) complexity to compute <code>list(x)</code> which will be sorted</li> </ul> <p>I also had a related question about performance of <code>list(...).inse...
78
2009-07-10T14:18:00Z
6,130,146
<p>Though I have still never checked the "big O" speeds of basic Python list operations, the <code>bisect</code> standard module is probably also worth mentioning in this context: </p> <pre><code>import bisect L = [0, 100] bisect.insort(L, 50) bisect.insort(L, 20) bisect.insort(L, 21) print L ## [0, 20, 21, 50, 10...
21
2011-05-25T19:59:28Z
[ "python", "list", "sorting" ]
Does python have a sorted list?
1,109,804
<p>By which I mean a structure with:</p> <ul> <li>O(log n) complexity for <code>x.push()</code> operations</li> <li>O(log n) complexity to find an element</li> <li>O(n) complexity to compute <code>list(x)</code> which will be sorted</li> </ul> <p>I also had a related question about performance of <code>list(...).inse...
78
2009-07-10T14:18:00Z
12,829,310
<p>It may not be hard to implement your own sortlist on Python. Below is a proof of concept:</p> <pre><code>import bisect class sortlist: def __init__(self, list): self.list = list self.sort() def sort(self): l = [] for i in range(len(self.list)): bisect.insort(l, s...
0
2012-10-10T22:18:25Z
[ "python", "list", "sorting" ]
Does python have a sorted list?
1,109,804
<p>By which I mean a structure with:</p> <ul> <li>O(log n) complexity for <code>x.push()</code> operations</li> <li>O(log n) complexity to find an element</li> <li>O(n) complexity to compute <code>list(x)</code> which will be sorted</li> </ul> <p>I also had a related question about performance of <code>list(...).inse...
78
2009-07-10T14:18:00Z
22,616,929
<p>Is there a particular reason for your big-O requirements? Or do you just want it to be fast? The <a href="http://www.grantjenks.com/docs/sortedcontainers/">sortedcontainers</a> module is pure-Python and fast (as in fast-as-C implementations like blist and rbtree).</p> <p>The <a href="http://www.grantjenks.com/docs/...
21
2014-03-24T17:52:26Z
[ "python", "list", "sorting" ]
Does python have a sorted list?
1,109,804
<p>By which I mean a structure with:</p> <ul> <li>O(log n) complexity for <code>x.push()</code> operations</li> <li>O(log n) complexity to find an element</li> <li>O(n) complexity to compute <code>list(x)</code> which will be sorted</li> </ul> <p>I also had a related question about performance of <code>list(...).inse...
78
2009-07-10T14:18:00Z
25,101,497
<pre><code>class sortedlist(list): '''just a list but with an insort (insert into sorted position)''' def insort(self,x): self=bisect.insort(self,x) </code></pre>
1
2014-08-03T03:59:14Z
[ "python", "list", "sorting" ]
Does python have a sorted list?
1,109,804
<p>By which I mean a structure with:</p> <ul> <li>O(log n) complexity for <code>x.push()</code> operations</li> <li>O(log n) complexity to find an element</li> <li>O(n) complexity to compute <code>list(x)</code> which will be sorted</li> </ul> <p>I also had a related question about performance of <code>list(...).inse...
78
2009-07-10T14:18:00Z
31,736,695
<p>I would use the <code>biscect</code> or <code>sortedcontainers</code> modules. I don't really am experienced, but I think the <code>heapq</code> module works. It contains a <code>Heap Queue</code></p>
1
2015-07-31T01:26:19Z
[ "python", "list", "sorting" ]
python singleton into multiprocessing
1,109,870
<p>How can I code to share the same instance of a "singletonic" class among processes?</p>
4
2009-07-10T14:27:34Z
1,109,920
<p>The whole point of processes is to have different address spaces. If you want to share information between processes you must use some means of <a href="http://en.wikipedia.org/wiki/Inter-process%5Fcommunication" rel="nofollow">interprocess communication</a>.</p>
4
2009-07-10T14:35:52Z
[ "python", "multiprocessing" ]
python singleton into multiprocessing
1,109,870
<p>How can I code to share the same instance of a "singletonic" class among processes?</p>
4
2009-07-10T14:27:34Z
1,109,930
<p>Best is to designate one specific process as owning that instance and dedicated to it; any other process requiring access to that instance obtains it by sending messages to the owning process via a Queue (as supplied by the multiprocessing module) or other IPC mechanisms for message passing, and gets answers back vi...
5
2009-07-10T14:37:28Z
[ "python", "multiprocessing" ]
python singleton into multiprocessing
1,109,870
<p>How can I code to share the same instance of a "singletonic" class among processes?</p>
4
2009-07-10T14:27:34Z
1,109,978
<p>I do not think you can share the instance between the processes, but you can have the instance access shared memory: <a href="http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes" rel="nofollow">http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes</a> to ...
1
2009-07-10T14:44:14Z
[ "python", "multiprocessing" ]
python singleton into multiprocessing
1,109,870
<p>How can I code to share the same instance of a "singletonic" class among processes?</p>
4
2009-07-10T14:27:34Z
1,109,994
<p>In Python 2.6 the <code>multiprocessing</code> module has a <code>Value</code> object used for <a href="http://docs.python.org/dev/library/multiprocessing.html#sharing-state-between-processes" rel="nofollow">sharing state between processes</a>. They have a code sample that should give you an idea of how to share st...
2
2009-07-10T14:47:41Z
[ "python", "multiprocessing" ]
Python clock function on FreeBSD
1,110,063
<p>While testing Pythons time.clock() function on FreeBSD I've noticed it always returns the same value, around 0.156</p> <p>The time.time() function works properly but I need a something with a slightly higher resolution.</p> <p>Does anyone the C function it's bound to and if there is an alternative high resolution ...
0
2009-07-10T15:02:09Z
1,110,113
<p>Python's time.clock calls C function clock(3) -- <code>man clock</code> should confirm that it's supposed to work on BSD, so I don't know why it's not working for you. Maybe you can try working around this apparent bug in your Python port by using <code>ctypes</code> to call the clock function from the system C libr...
3
2009-07-10T15:11:20Z
[ "python", "timer", "freebsd", "bsd", "gettimeofday" ]
Python clock function on FreeBSD
1,110,063
<p>While testing Pythons time.clock() function on FreeBSD I've noticed it always returns the same value, around 0.156</p> <p>The time.time() function works properly but I need a something with a slightly higher resolution.</p> <p>Does anyone the C function it's bound to and if there is an alternative high resolution ...
0
2009-07-10T15:02:09Z
1,110,116
<p><code>time.clock()</code> returns CPU time on UNIX systems, and wallclock time since program start on Windows. This is a very unfortunate insymmetry, in my opinion.</p> <p>You can find the definition for <code>time.time()</code> in the Python sources <a href="http://www.google.com/codesearch/p?hl=en&amp;sa=N&amp;cd...
1
2009-07-10T15:11:54Z
[ "python", "timer", "freebsd", "bsd", "gettimeofday" ]
Python clock function on FreeBSD
1,110,063
<p>While testing Pythons time.clock() function on FreeBSD I've noticed it always returns the same value, around 0.156</p> <p>The time.time() function works properly but I need a something with a slightly higher resolution.</p> <p>Does anyone the C function it's bound to and if there is an alternative high resolution ...
0
2009-07-10T15:02:09Z
1,110,127
<p>time.clock() is implemented to return a double value resulting from</p> <pre><code> ((double)clock()) / CLOCKS_PER_SEC </code></pre> <p>Why do you think time.time() has bad resolution? It uses gettimeofday, which in turn reads the hardware clock, which has very good resolution.</p>
0
2009-07-10T15:12:58Z
[ "python", "timer", "freebsd", "bsd", "gettimeofday" ]
Python clock function on FreeBSD
1,110,063
<p>While testing Pythons time.clock() function on FreeBSD I've noticed it always returns the same value, around 0.156</p> <p>The time.time() function works properly but I need a something with a slightly higher resolution.</p> <p>Does anyone the C function it's bound to and if there is an alternative high resolution ...
0
2009-07-10T15:02:09Z
1,110,298
<p>time.clock() returns the processor time. That is, how much time the current process has used on the processor. So if you have a Python script called "clock.py", that does <code>import time;print time.clock()</code> it will indeed print about exactly the same each time you run it, as a new process is started each tim...
1
2009-07-10T15:37:25Z
[ "python", "timer", "freebsd", "bsd", "gettimeofday" ]
swfupload failing in my django runserver
1,110,082
<p>I have copied and pasted the code from <a href="http://demo.swfupload.org/v220/simpledemo/" rel="nofollow">http://demo.swfupload.org/v220/simpledemo/</a> into a django template, but when I upload a photo, the demo says "Server (IO) Error" before it actually uploads the entire file. The runserver is getting the reque...
0
2009-07-10T15:05:58Z
1,111,531
<p>Make sure you have write permission to your server. In the folder you installed that thing. Check the user that is running runserver. If in windows - check folder is not readonly.</p>
0
2009-07-10T19:30:47Z
[ "python", "django", "swfupload" ]
swfupload failing in my django runserver
1,110,082
<p>I have copied and pasted the code from <a href="http://demo.swfupload.org/v220/simpledemo/" rel="nofollow">http://demo.swfupload.org/v220/simpledemo/</a> into a django template, but when I upload a photo, the demo says "Server (IO) Error" before it actually uploads the entire file. The runserver is getting the reque...
0
2009-07-10T15:05:58Z
1,119,383
<p>Found it. I was uploading to a dummy view, and for some reason if you don't actually access request.POST or request.FILES it gives that error message.</p>
1
2009-07-13T13:17:46Z
[ "python", "django", "swfupload" ]
What is the most efficent way to store a list in the Django models?
1,110,153
<p>Currently I have a lot of python objects in my code similar to the following:</p> <pre><code>class MyClass(): def __init__(self, name, friends): self.myName = name self.myFriends = [str(x) for x in friends] </code></pre> <p>Now I want to turn this into a Django model, where self.myName is a string fi...
68
2009-07-10T15:16:19Z
1,110,207
<p>Would not this relationship be better expressed as a one-to-many foreign key relationship to a <code>Friends</code> table? I understand that <code>myFriends</code> are just strings but I would think that a better design would be to create a <code>Friend</code> model and have <code>MyClass</code> contain a foreign k...
37
2009-07-10T15:23:18Z
[ "python", "django", "django-models" ]
What is the most efficent way to store a list in the Django models?
1,110,153
<p>Currently I have a lot of python objects in my code similar to the following:</p> <pre><code>class MyClass(): def __init__(self, name, friends): self.myName = name self.myFriends = [str(x) for x in friends] </code></pre> <p>Now I want to turn this into a Django model, where self.myName is a string fi...
68
2009-07-10T15:16:19Z
1,110,237
<p>Remember that this eventually has to end up in a relational database. So using relations really <em>is</em> the common way to solve this problem. If you absolutely insist on storing a list in the object itself, you could make it for example comma-separated, and store it in a string, and then provide accessor functio...
6
2009-07-10T15:27:43Z
[ "python", "django", "django-models" ]
What is the most efficent way to store a list in the Django models?
1,110,153
<p>Currently I have a lot of python objects in my code similar to the following:</p> <pre><code>class MyClass(): def __init__(self, name, friends): self.myName = name self.myFriends = [str(x) for x in friends] </code></pre> <p>Now I want to turn this into a Django model, where self.myName is a string fi...
68
2009-07-10T15:16:19Z
1,111,201
<p>You can store virtually any object using a Django Pickle Field, ala this snippet:</p> <p><a href="http://www.djangosnippets.org/snippets/513/" rel="nofollow">http://www.djangosnippets.org/snippets/513/</a></p>
4
2009-07-10T18:27:21Z
[ "python", "django", "django-models" ]
What is the most efficent way to store a list in the Django models?
1,110,153
<p>Currently I have a lot of python objects in my code similar to the following:</p> <pre><code>class MyClass(): def __init__(self, name, friends): self.myName = name self.myFriends = [str(x) for x in friends] </code></pre> <p>Now I want to turn this into a Django model, where self.myName is a string fi...
68
2009-07-10T15:16:19Z
1,111,475
<pre><code>class Course(models.Model): name = models.CharField(max_length=256) students = models.ManyToManyField(Student) class Student(models.Model): first_name = models.CharField(max_length=256) student_number = models.CharField(max_length=128) # other fields, etc... friends = models.ManyToManyFie...
8
2009-07-10T19:21:37Z
[ "python", "django", "django-models" ]
What is the most efficent way to store a list in the Django models?
1,110,153
<p>Currently I have a lot of python objects in my code similar to the following:</p> <pre><code>class MyClass(): def __init__(self, name, friends): self.myName = name self.myFriends = [str(x) for x in friends] </code></pre> <p>Now I want to turn this into a Django model, where self.myName is a string fi...
68
2009-07-10T15:16:19Z
1,113,039
<h2><strong>"Premature optimization is the root of all evil."</strong></h2> <p>With that firmly in mind, let's do this! Once your apps hit a certain point, denormalizing data is very common. Done correctly, it can save numerous expensive database lookups at the cost of a little more housekeeping.</p> <p>To return a <...
74
2009-07-11T05:43:45Z
[ "python", "django", "django-models" ]
What is the most efficent way to store a list in the Django models?
1,110,153
<p>Currently I have a lot of python objects in my code similar to the following:</p> <pre><code>class MyClass(): def __init__(self, name, friends): self.myName = name self.myFriends = [str(x) for x in friends] </code></pre> <p>Now I want to turn this into a Django model, where self.myName is a string fi...
68
2009-07-10T15:16:19Z
1,113,362
<p>Using one-to-many relation (FK from Friend to parent class) will make your app more scalable (as you can trivially extend the Friend object with additional attributes beyond the simple name). And thus this is the best way </p>
1
2009-07-11T09:51:13Z
[ "python", "django", "django-models" ]
What is the most efficent way to store a list in the Django models?
1,110,153
<p>Currently I have a lot of python objects in my code similar to the following:</p> <pre><code>class MyClass(): def __init__(self, name, friends): self.myName = name self.myFriends = [str(x) for x in friends] </code></pre> <p>Now I want to turn this into a Django model, where self.myName is a string fi...
68
2009-07-10T15:16:19Z
7,151,813
<p>A simple way to store a list in Django is to just convert it into a JSON string, and then save that as Text in the model. You can then retrieve the list by converting the (JSON) string back into a python list. Here's how:</p> <p>The "list" would be stored in your Django model like so:</p> <pre><code>class MyModel(...
21
2011-08-22T18:24:31Z
[ "python", "django", "django-models" ]
What is the most efficent way to store a list in the Django models?
1,110,153
<p>Currently I have a lot of python objects in my code similar to the following:</p> <pre><code>class MyClass(): def __init__(self, name, friends): self.myName = name self.myFriends = [str(x) for x in friends] </code></pre> <p>Now I want to turn this into a Django model, where self.myName is a string fi...
68
2009-07-10T15:16:19Z
14,715,454
<p>As this is an old question, and Django techniques must have changed significantly since, this answer reflects Django version 1.4, and is most likely applicable for v 1.5.</p> <p>Django by default uses relational databases; you should make use of 'em. Map friendships to database relations (foreign key constraints) w...
12
2013-02-05T19:35:21Z
[ "python", "django", "django-models" ]
What is the most efficent way to store a list in the Django models?
1,110,153
<p>Currently I have a lot of python objects in my code similar to the following:</p> <pre><code>class MyClass(): def __init__(self, name, friends): self.myName = name self.myFriends = [str(x) for x in friends] </code></pre> <p>Now I want to turn this into a Django model, where self.myName is a string fi...
68
2009-07-10T15:16:19Z
36,257,323
<p>If you are using 1.9 Django with Postgres you can use advantages of <a href="https://docs.djangoproject.com/en/1.9/ref/contrib/postgres/fields/#django.contrib.postgres.fields.ArrayField" rel="nofollow">ArrayField</a></p> <blockquote> <p>A field for storing lists of data. Most field types can be used, you simply...
2
2016-03-28T06:44:27Z
[ "python", "django", "django-models" ]
What is the most efficent way to store a list in the Django models?
1,110,153
<p>Currently I have a lot of python objects in my code similar to the following:</p> <pre><code>class MyClass(): def __init__(self, name, friends): self.myName = name self.myFriends = [str(x) for x in friends] </code></pre> <p>Now I want to turn this into a Django model, where self.myName is a string fi...
68
2009-07-10T15:16:19Z
38,517,318
<p>In case you're using postgres, you can use something like this:</p> <p>class ChessBoard(models.Model):</p> <pre><code>board = ArrayField( ArrayField( models.CharField(max_length=10, blank=True), size=8, ), size=8, ) </code></pre> <p>if you need more details you can read in the link bel...
0
2016-07-22T02:41:58Z
[ "python", "django", "django-models" ]
How can I tell if my script is being run from a cronjob or from the command line?
1,110,203
<p>I have a script and it's display show's upload progress by writing to the same console line. When the script is run from a cron job, rather than writing to a single line, I get many lines:</p> <pre><code>*** E0710091001.DAT *** [0.67%] *** E0710091001.DAT *** [1.33%] *** E0710091001.DAT *** [2.00%] *...
2
2009-07-10T15:22:22Z
1,110,218
<p>you could create a flag. Possibly undocumented that your cron job would pass to the utility to structure the output.</p>
8
2009-07-10T15:24:39Z
[ "python", "cron" ]
How can I tell if my script is being run from a cronjob or from the command line?
1,110,203
<p>I have a script and it's display show's upload progress by writing to the same console line. When the script is run from a cron job, rather than writing to a single line, I get many lines:</p> <pre><code>*** E0710091001.DAT *** [0.67%] *** E0710091001.DAT *** [1.33%] *** E0710091001.DAT *** [2.00%] *...
2
2009-07-10T15:22:22Z
1,110,221
<p>You want to check if you're on a terminal or not. See this stack overflow question: <a href="http://stackoverflow.com/questions/911168/detect-if-shell-script-is-running-through-a-pipe">http://stackoverflow.com/questions/911168/detect-if-shell-script-is-running-through-a-pipe</a></p>
6
2009-07-10T15:24:51Z
[ "python", "cron" ]
How can I tell if my script is being run from a cronjob or from the command line?
1,110,203
<p>I have a script and it's display show's upload progress by writing to the same console line. When the script is run from a cron job, rather than writing to a single line, I get many lines:</p> <pre><code>*** E0710091001.DAT *** [0.67%] *** E0710091001.DAT *** [1.33%] *** E0710091001.DAT *** [2.00%] *...
2
2009-07-10T15:22:22Z
1,110,223
<p>An easy way would be to have the script take an argument that means to suppress that output, and supply that argument when you call it from cron.</p>
2
2009-07-10T15:25:14Z
[ "python", "cron" ]
How can I tell if my script is being run from a cronjob or from the command line?
1,110,203
<p>I have a script and it's display show's upload progress by writing to the same console line. When the script is run from a cron job, rather than writing to a single line, I get many lines:</p> <pre><code>*** E0710091001.DAT *** [0.67%] *** E0710091001.DAT *** [1.33%] *** E0710091001.DAT *** [2.00%] *...
2
2009-07-10T15:22:22Z
1,110,230
<p>I'd check <code>sys.stderr.isatty()</code> -- this way you avoid useless "decoration" output to stderr whenever it wouldn't be immediately perceptible by the user anyway.</p>
9
2009-07-10T15:26:48Z
[ "python", "cron" ]
How can I tell if my script is being run from a cronjob or from the command line?
1,110,203
<p>I have a script and it's display show's upload progress by writing to the same console line. When the script is run from a cron job, rather than writing to a single line, I get many lines:</p> <pre><code>*** E0710091001.DAT *** [0.67%] *** E0710091001.DAT *** [1.33%] *** E0710091001.DAT *** [2.00%] *...
2
2009-07-10T15:22:22Z
1,110,253
<p>See code below. Replace my print statements with what you want to show.</p> <pre><code>import sys if sys.stdout.isatty(): print "Running from command line" else: print "Running from cron" </code></pre>
5
2009-07-10T15:29:54Z
[ "python", "cron" ]
Performance of list(...).insert(...)
1,110,332
<p>I thought about the following question about computer's architecture. Suppose I do in Python</p> <pre><code>from bisect import bisect index = bisect(x, a) # O(log n) (also, shouldn't it be a standard list function?) x.insert(index, a) # O(1) + memcpy() </code></pre> <p>which takes <code>log n</code>, ...
10
2009-07-10T15:42:33Z
1,110,446
<p>Python is a language. <a href="http://www.python.org/dev/implementations/">Multiple implementations exist</a>, and they <em>may</em> have different implementations for lists. So, without looking at the code of an actual implementation, you cannot know for sure how lists are implemented and how they behave under cert...
12
2009-07-10T15:58:34Z
[ "python", "architecture", "memory", "list", "memcpy" ]
Performance of list(...).insert(...)
1,110,332
<p>I thought about the following question about computer's architecture. Suppose I do in Python</p> <pre><code>from bisect import bisect index = bisect(x, a) # O(log n) (also, shouldn't it be a standard list function?) x.insert(index, a) # O(1) + memcpy() </code></pre> <p>which takes <code>log n</code>, ...
10
2009-07-10T15:42:33Z
1,111,127
<p>CPython lists are contiguous arrays. Which one of the O(log n) bisect and O(n) insert dominates your performance profile depends on the size of your list and also the constant factors inside the O(). Particularly, the comparison function invoked by bisect can be something expensive depending on the type of objects i...
5
2009-07-10T18:12:44Z
[ "python", "architecture", "memory", "list", "memcpy" ]
Performance of list(...).insert(...)
1,110,332
<p>I thought about the following question about computer's architecture. Suppose I do in Python</p> <pre><code>from bisect import bisect index = bisect(x, a) # O(log n) (also, shouldn't it be a standard list function?) x.insert(index, a) # O(1) + memcpy() </code></pre> <p>which takes <code>log n</code>, ...
10
2009-07-10T15:42:33Z
1,111,886
<p>Use the <a href="http://www.python.org/pypi/blist/">blist module</a> if you need a list with better insert performance.</p>
8
2009-07-10T20:44:12Z
[ "python", "architecture", "memory", "list", "memcpy" ]
Performance of list(...).insert(...)
1,110,332
<p>I thought about the following question about computer's architecture. Suppose I do in Python</p> <pre><code>from bisect import bisect index = bisect(x, a) # O(log n) (also, shouldn't it be a standard list function?) x.insert(index, a) # O(1) + memcpy() </code></pre> <p>which takes <code>log n</code>, ...
10
2009-07-10T15:42:33Z
1,112,251
<p>Yes, I think sometimes O(n) is inevitable, <a href="http://www.pycon.it/static/stuff/slides/core-python-containers-under-hood.ppt" rel="nofollow">Core Python Containers: Under the Hood</a> talks about List performance from page 4 to page 14.It is concordant with your viewpoint and is worth reading.</p>
1
2009-07-10T22:14:37Z
[ "python", "architecture", "memory", "list", "memcpy" ]
Python ftplib - uploading multiple files?
1,110,374
<p>I've googled but I could only find how to upload one file... and I'm trying to upload all files from local directory to remote ftp directory. Any ideas how to achieve this?</p>
3
2009-07-10T15:47:30Z
1,110,380
<p>with the loop?</p> <p><strong>edit</strong>: in universal case uploading only files would look like this:</p> <pre><code>import os for root, dirs, files in os.walk('path/to/local/dir'): for fname in files: full_fname = os.path.join(root, fname) ftp.storbinary('STOR remote/dir' + fname, open(ful...
9
2009-07-10T15:48:55Z
[ "python", "ftplib" ]
Python ftplib - uploading multiple files?
1,110,374
<p>I've googled but I could only find how to upload one file... and I'm trying to upload all files from local directory to remote ftp directory. Any ideas how to achieve this?</p>
3
2009-07-10T15:47:30Z
1,110,688
<p>Create a FTP batch file (with a list of files that you need to transfer). Use python to execute ftp.exe with the "-s" option and pass in the list of files.</p> <p>This is kludgy but apparently the FTPlib does not have accept multiple files in its STOR command.</p> <p>Here is a sample ftp batch file.</p> <p>*</p> ...
-1
2009-07-10T16:49:48Z
[ "python", "ftplib" ]