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
Character Translation using Python (like the tr command)
555,705
<p>Is there a way to do character translation (kind of like the tr command) using python</p>
28
2009-02-17T06:33:06Z
23,159,267
<p>In Python 2, <code>unicode.translate()</code> accepts ordinary mappings, ie. there's no need to import anything either:</p> <pre><code>&gt;&gt;&gt; u'abc+-'.translate({ord('+'): u'-', ord('-'): u'+', ord('b'): None}) u'ac-+' </code></pre> <p>The <code>translate()</code> method is especially useful for swapping cha...
1
2014-04-18T17:41:42Z
[ "python" ]
Character Translation using Python (like the tr command)
555,705
<p>Is there a way to do character translation (kind of like the tr command) using python</p>
28
2009-02-17T06:33:06Z
27,964,244
<p>I has developed python-tr, implemented tr algorithm. Let's try it.</p> <p>Install:</p> <pre><code>$ pip install python-tr </code></pre> <p>Example:</p> <pre><code>&gt;&gt;&gt; from tr import tr &gt;&gt;&gt; tr('bn', 'cr', 'bunny') 'curry' &gt;&gt;&gt; tr('n', '', 'bunny', 'd') 'buy' &gt;&gt;&gt; tr('n', 'u', 'bu...
3
2015-01-15T13:11:18Z
[ "python" ]
Character Translation using Python (like the tr command)
555,705
<p>Is there a way to do character translation (kind of like the tr command) using python</p>
28
2009-02-17T06:33:06Z
37,368,639
<p>This one works for Python 3</p> <p><code>-int('(1200)'.translate(str.maketrans('','','()')))</code></p>
-1
2016-05-21T22:31:54Z
[ "python" ]
ImportError: No module named copy_reg pickle
556,269
<p>I'm trying to unpickle an object stored as a blob in a MySQL database. I've manually generated and stored the pickled object in the database, but when I try to unpickle the object, I get the following rather cryptic exception:</p> <p>ImportError: No module named copy_reg</p> <p>Any ideas as to why this happens?</p...
13
2009-02-17T10:42:58Z
556,295
<p>It seems this might be caused by my method of exporting the pickled object.</p> <p><a href="http://www.archivum.info/python-bugs-list@python.org/2007-04/msg00222.html">This bug report</a> seens to suggest that my issue can be resolved by exporting to a file writen in binary mode. I'm going to give this a go now and...
17
2009-02-17T10:52:36Z
[ "python", "pickle" ]
ImportError: No module named copy_reg pickle
556,269
<p>I'm trying to unpickle an object stored as a blob in a MySQL database. I've manually generated and stored the pickled object in the database, but when I try to unpickle the object, I get the following rather cryptic exception:</p> <p>ImportError: No module named copy_reg</p> <p>Any ideas as to why this happens?</p...
13
2009-02-17T10:42:58Z
760,499
<p>Also, simply running dos2unix (under linux) over the (windows-created) pickle file solved the problem for me. (Haven't tried the open mode 'wb' thing.) Dan</p>
9
2009-04-17T13:50:01Z
[ "python", "pickle" ]
ImportError: No module named copy_reg pickle
556,269
<p>I'm trying to unpickle an object stored as a blob in a MySQL database. I've manually generated and stored the pickled object in the database, but when I try to unpickle the object, I get the following rather cryptic exception:</p> <p>ImportError: No module named copy_reg</p> <p>Any ideas as to why this happens?</p...
13
2009-02-17T10:42:58Z
1,245,146
<p>just an interactive python session to show that you don't need any particular code to have this problem:</p> <p>do something like this on a windows machine</p> <pre><code>Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more informa...
3
2009-08-07T14:42:46Z
[ "python", "pickle" ]
ImportError: No module named copy_reg pickle
556,269
<p>I'm trying to unpickle an object stored as a blob in a MySQL database. I've manually generated and stored the pickled object in the database, but when I try to unpickle the object, I get the following rather cryptic exception:</p> <p>ImportError: No module named copy_reg</p> <p>Any ideas as to why this happens?</p...
13
2009-02-17T10:42:58Z
26,446,582
<p>Another thing going on here is that you don't seem to have closed the file after dumping the pickle to it. the error reported here can sometimes be caused (whether on a windows machine or otherwise) by not closing the file. </p>
0
2014-10-19T02:09:30Z
[ "python", "pickle" ]
ImportError: No module named copy_reg pickle
556,269
<p>I'm trying to unpickle an object stored as a blob in a MySQL database. I've manually generated and stored the pickled object in the database, but when I try to unpickle the object, I get the following rather cryptic exception:</p> <p>ImportError: No module named copy_reg</p> <p>Any ideas as to why this happens?</p...
13
2009-02-17T10:42:58Z
33,434,146
<p>As mentioned in the other answer use </p> <pre><code>dos2unix originalPickle.file outputPickle.file </code></pre> <p>OR use the tr command like below (removes carriage returns and ctrl-z)</p> <pre><code> tr -d '\15\32' &lt; originalPickle.file &gt; outputPickle.file </code></pre> <p>OR use <code>awk</code> (<co...
0
2015-10-30T10:47:23Z
[ "python", "pickle" ]
ImportError: No module named copy_reg pickle
556,269
<p>I'm trying to unpickle an object stored as a blob in a MySQL database. I've manually generated and stored the pickled object in the database, but when I try to unpickle the object, I get the following rather cryptic exception:</p> <p>ImportError: No module named copy_reg</p> <p>Any ideas as to why this happens?</p...
13
2009-02-17T10:42:58Z
35,439,754
<p>The pickle load may not be looking in the same location as your python script. Sometimes the directory changes on the basis of your application. Just before you load the pickle, print a os.getcwd() to work out a solution.</p>
0
2016-02-16T17:55:58Z
[ "python", "pickle" ]
Python code to find if x is following y on twitter. More Pythonic way please
556,342
<p>I wrote a twitter application in Python. Following is the code I used for a module where I find if x is following y. This code can be obviously improved upon. A pythonic way to do that?</p> <pre><code>import urllib2 import sys import re import base64 from urlparse import urlparse import simplejson def is_follows(f...
1
2009-02-17T11:11:11Z
556,352
<p>Three things:</p> <ul> <li>Fix the indentation (but then I guess this was not done on purpose).</li> <li>Use formatting instead of concatenation in constructing <code>theurl</code>.</li> <li>Remove the <code>fol</code> variable. Rather, do the following:</li> </ul> <p><hr /></p> <pre><code>try: return simplej...
2
2009-02-17T11:17:05Z
[ "authentication", "twitter", "python" ]
Python code to find if x is following y on twitter. More Pythonic way please
556,342
<p>I wrote a twitter application in Python. Following is the code I used for a module where I find if x is following y. This code can be obviously improved upon. A pythonic way to do that?</p> <pre><code>import urllib2 import sys import re import base64 from urlparse import urlparse import simplejson def is_follows(f...
1
2009-02-17T11:11:11Z
556,361
<p>Google threw this library with an <a href="http://static.unto.net/python-twitter/0.5/doc/twitter.html" rel="nofollow">Twitter API for Python</a> at me. I think such an library would simplify this task alot. It has a GetFollowers() method that lets you look up if someone is following you.</p> <p>Edit: It looks like ...
0
2009-02-17T11:21:13Z
[ "authentication", "twitter", "python" ]
Python code to find if x is following y on twitter. More Pythonic way please
556,342
<p>I wrote a twitter application in Python. Following is the code I used for a module where I find if x is following y. This code can be obviously improved upon. A pythonic way to do that?</p> <pre><code>import urllib2 import sys import re import base64 from urlparse import urlparse import simplejson def is_follows(f...
1
2009-02-17T11:11:11Z
556,498
<p>Konrad gave you a good answer with changes you can make to make your code more Pythonic. All I want to add is if you are interested in seeing some <strong>advanced</strong> code to do this same thing check out <a href="http://mike.verdone.ca/twitter/" rel="nofollow">The Minimalist Twitter API for Python</a>.</p> <...
2
2009-02-17T11:58:36Z
[ "authentication", "twitter", "python" ]
Python code to find if x is following y on twitter. More Pythonic way please
556,342
<p>I wrote a twitter application in Python. Following is the code I used for a module where I find if x is following y. This code can be obviously improved upon. A pythonic way to do that?</p> <pre><code>import urllib2 import sys import re import base64 from urlparse import urlparse import simplejson def is_follows(f...
1
2009-02-17T11:11:11Z
556,574
<p>From your code it looks like you are trying to do a Basic HTTP Authentication. Is this right? Then you shouldn't create the HTTP headers by hand. Instead use the urllib2.HTTPBasicAuthHandler. An example from the <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">docs</a>:</p> <pre><code>import url...
2
2009-02-17T12:23:11Z
[ "authentication", "twitter", "python" ]
Python list serialization - fastest method
556,730
<p>I need to load (de-serialize) a pre-computed list of integers from a file in a Python script (into a Python list). The list is large (upto millions of items), and I can choose the format I store it in, as long as loading is fastest.</p> <p>Which is the fastest method, and why?</p> <ol> <li>Using <code>import</code...
11
2009-02-17T13:16:25Z
556,843
<p>"how can one benchmark such things reliably?" </p> <p>I don't get the question.</p> <p>You write a bunch of little functions to create and save your list in various forms.</p> <p>You write a bunch of little functions to load your lists in their various forms.</p> <p>You write a little timer function to get star...
2
2009-02-17T13:43:57Z
[ "python", "serialization", "caching" ]
Python list serialization - fastest method
556,730
<p>I need to load (de-serialize) a pre-computed list of integers from a file in a Python script (into a Python list). The list is large (upto millions of items), and I can choose the format I store it in, as long as loading is fastest.</p> <p>Which is the fastest method, and why?</p> <ol> <li>Using <code>import</code...
11
2009-02-17T13:16:25Z
556,867
<p>For benchmarking, see the timeit module in the Python standard library. To see what is the fastest way, implement all the ways you can think of and measure them with timeit.</p> <p>Random thought: depending on what you're doing exactly, you may find it fastest to store "sets of integers" in the style used in <stron...
3
2009-02-17T13:50:14Z
[ "python", "serialization", "caching" ]
Python list serialization - fastest method
556,730
<p>I need to load (de-serialize) a pre-computed list of integers from a file in a Python script (into a Python list). The list is large (upto millions of items), and I can choose the format I store it in, as long as loading is fastest.</p> <p>Which is the fastest method, and why?</p> <ol> <li>Using <code>import</code...
11
2009-02-17T13:16:25Z
556,902
<p>To help you with timing, the Python Library provides the <a href="http://docs.python.org/library/timeit.html#module-timeit" rel="nofollow"><code>timeit</code></a> module:</p> <blockquote> <p>This module provides a simple way to time small bits of Python code. It has both command line as well as callable interface...
2
2009-02-17T13:57:14Z
[ "python", "serialization", "caching" ]
Python list serialization - fastest method
556,730
<p>I need to load (de-serialize) a pre-computed list of integers from a file in a Python script (into a Python list). The list is large (upto millions of items), and I can choose the format I store it in, as long as loading is fastest.</p> <p>Which is the fastest method, and why?</p> <ol> <li>Using <code>import</code...
11
2009-02-17T13:16:25Z
556,946
<p>I would guess <a href="http://docs.python.org/library/pickle.html#module-cPickle" rel="nofollow">cPickle</a> will be fastest if you really need the thing in a list.</p> <p>If you can use an <a href="http://docs.python.org/library/array.html" rel="nofollow">array</a>, which is a built-in sequence type, I timed this ...
7
2009-02-17T14:07:06Z
[ "python", "serialization", "caching" ]
Python list serialization - fastest method
556,730
<p>I need to load (de-serialize) a pre-computed list of integers from a file in a Python script (into a Python list). The list is large (upto millions of items), and I can choose the format I store it in, as long as loading is fastest.</p> <p>Which is the fastest method, and why?</p> <ol> <li>Using <code>import</code...
11
2009-02-17T13:16:25Z
556,961
<p>cPickle will be the fastest since it is saved in binary and no real python code has to be parsed.</p> <p>Other advantates are that it is more secure (since it does not execute commands) and you have no problems with setting <code>$PYTHONPATH</code> correctly.</p>
1
2009-02-17T14:11:21Z
[ "python", "serialization", "caching" ]
Python list serialization - fastest method
556,730
<p>I need to load (de-serialize) a pre-computed list of integers from a file in a Python script (into a Python list). The list is large (upto millions of items), and I can choose the format I store it in, as long as loading is fastest.</p> <p>Which is the fastest method, and why?</p> <ol> <li>Using <code>import</code...
11
2009-02-17T13:16:25Z
581,566
<p>Do you need to always load the whole file? If not, <a href="http://docs.python.org/library/struct.html" rel="nofollow">upack_from()</a> might be the best solution. Suppose, that you have 1000000 integers, but you'd like to load just the ones from 50000 to 50099, you'd do:</p> <pre><code>import struct intSize = stru...
2
2009-02-24T12:25:20Z
[ "python", "serialization", "caching" ]
WingIDE no autocompletion for my modules
556,785
<p>If anyone using WingIDE for their python dev needs: For some reason I get auto-completion on all the standard python libraries (like datetime....) but not on my own modules. So if I create my own class and then import it from another class, I get no auto-completion on it.</p> <p>Does anyone know why this is?</p>
0
2009-02-17T13:28:35Z
557,053
<p>Just found an answer, it has to do with pythonpath: <a href="http://www.wingware.com/doc/edit/how-analysis-works" rel="nofollow">http://www.wingware.com/doc/edit/how-analysis-works</a></p>
0
2009-02-17T14:28:17Z
[ "python", "ide" ]
How to get distinct Django apps on same subdomain to share session cookie?
556,907
<p>We have a couple of Django applications deployed on the same subdomain. A few power users need to jump between these applications. I noticed that each time they bounce between applications their session cookie receives a new session ID from Django. </p> <p>I don't use the Django session table much except in one ...
7
2009-02-17T13:58:41Z
557,020
<p>I would instead advise you to set <code>SESSION_COOKIE_NAME</code> to <em>different</em> values for the two apps. Your users will still have to log in twice initially, but their sessions won't conflict - if they log in to app A, then app B, and return to A, they'll still have their A session.</p> <p>Sharing session...
12
2009-02-17T14:21:11Z
[ "python", "django", "deployment", "session", "cookies" ]
How to get distinct Django apps on same subdomain to share session cookie?
556,907
<p>We have a couple of Django applications deployed on the same subdomain. A few power users need to jump between these applications. I noticed that each time they bounce between applications their session cookie receives a new session ID from Django. </p> <p>I don't use the Django session table much except in one ...
7
2009-02-17T13:58:41Z
659,606
<p>I agree that sharing sessions between Django instances is probably not a good idea. If you really wanted to, you could:</p> <ul> <li>make sure the two django applications share the same SECRET_KEY</li> <li>make sure the two django applications share the same SeSSON_COOKIE_NAME</li> <li>make sure the SESSION_COOKIE_...
8
2009-03-18T18:44:25Z
[ "python", "django", "deployment", "session", "cookies" ]
Where should I post my python code?
556,967
<p>Today I needed to parse some data out from an xlsx file (Office open XML Spreadsheet). I could have just opened the files in openoffice and exported to csv. However I will need to reimport data from this spreadsheet later, and I wanted to eliminate the manual operation.</p> <p>I searched on the net for xlsx parser,...
4
2009-02-17T14:12:24Z
556,993
<p>You should post it <a href="http://code.activestate.com/recipes/langs/python/" rel="nofollow">here</a>. There are plenty of recipes here and yours would fit in perfectly.</p> <p>Stack Overflow is meant to be a wiki, where people search for questions and find answers. That being said, if you want to post it here, wh...
5
2009-02-17T14:17:01Z
[ "python", "excel-2007" ]
Where should I post my python code?
556,967
<p>Today I needed to parse some data out from an xlsx file (Office open XML Spreadsheet). I could have just opened the files in openoffice and exported to csv. However I will need to reimport data from this spreadsheet later, and I wanted to eliminate the manual operation.</p> <p>I searched on the net for xlsx parser,...
4
2009-02-17T14:12:24Z
557,004
<p>err, with a more descriptive title, i am sure many people would have found it here itself.(but i wasn't aware of the not-a-question tag).</p> <p>Hence, you can get a free blog, and just put in the bits you want to share, that way you would also have a steady online reference whenever you need it.</p>
1
2009-02-17T14:18:13Z
[ "python", "excel-2007" ]
Where should I post my python code?
556,967
<p>Today I needed to parse some data out from an xlsx file (Office open XML Spreadsheet). I could have just opened the files in openoffice and exported to csv. However I will need to reimport data from this spreadsheet later, and I wanted to eliminate the manual operation.</p> <p>I searched on the net for xlsx parser,...
4
2009-02-17T14:12:24Z
557,059
<p>It seems to me that <a href="http://pypi.python.org/pypi" rel="nofollow">Python Package Index</a> is the right place for you</p>
0
2009-02-17T14:28:50Z
[ "python", "excel-2007" ]
Where should I post my python code?
556,967
<p>Today I needed to parse some data out from an xlsx file (Office open XML Spreadsheet). I could have just opened the files in openoffice and exported to csv. However I will need to reimport data from this spreadsheet later, and I wanted to eliminate the manual operation.</p> <p>I searched on the net for xlsx parser,...
4
2009-02-17T14:12:24Z
557,148
<p><a href="http://github.com/" rel="nofollow">GitHub</a> would also be a great place to post this. Especially as that would allow others to quickly fork their own copies and make any improvements or modifications they need. These changes would then also be available to anyone else who wants them.</p>
5
2009-02-17T14:46:36Z
[ "python", "excel-2007" ]
Where should I post my python code?
556,967
<p>Today I needed to parse some data out from an xlsx file (Office open XML Spreadsheet). I could have just opened the files in openoffice and exported to csv. However I will need to reimport data from this spreadsheet later, and I wanted to eliminate the manual operation.</p> <p>I searched on the net for xlsx parser,...
4
2009-02-17T14:12:24Z
557,160
<p>If your code is short enough to copy and paste, you might want to post it as a <a href="http://code.activestate.com/recipes/langs/python/" rel="nofollow">Python recipe</a>. That site is a great resource for learning Python techniques and its best contents have been <a href="http://www.oreilly.com/catalog/97805960079...
2
2009-02-17T14:48:14Z
[ "python", "excel-2007" ]
Where should I post my python code?
556,967
<p>Today I needed to parse some data out from an xlsx file (Office open XML Spreadsheet). I could have just opened the files in openoffice and exported to csv. However I will need to reimport data from this spreadsheet later, and I wanted to eliminate the manual operation.</p> <p>I searched on the net for xlsx parser,...
4
2009-02-17T14:12:24Z
557,727
<p>In general, <a href="http://www.codeproject.com/" rel="nofollow">CodeProject</a> is a great place to post code as long as you're willing to write a small article about the code. (One of the good things about CodeProject is that they do require some verbiage about the code.) The site gets an extraordinary amount of t...
1
2009-02-17T17:00:06Z
[ "python", "excel-2007" ]
Where should I post my python code?
556,967
<p>Today I needed to parse some data out from an xlsx file (Office open XML Spreadsheet). I could have just opened the files in openoffice and exported to csv. However I will need to reimport data from this spreadsheet later, and I wanted to eliminate the manual operation.</p> <p>I searched on the net for xlsx parser,...
4
2009-02-17T14:12:24Z
562,280
<p>May I humbly suggest my site; <a href="http://utilitymill.com" rel="nofollow">http://utilitymill.com</a>. It lets you not only post your Python code, but also makes it into a runnable web utility. </p> <p>Users can collaberate on the code and write-ups, and it even gives you an automatic RESTful API for the utili...
0
2009-02-18T18:28:00Z
[ "python", "excel-2007" ]
Quick and dirty stripchart in python?
557,069
<p>I have some python code that receives a message every so often containing a timestamp and an edge transition, either low-to-high, or high-to-low. I'd like to graph each transition on a stripchart for a quick and dirty visualization of the digital waveform with the minimal amount of effort.</p> <p>Can you recommend ...
1
2009-02-17T14:30:39Z
557,091
<p>I haven't use it myself, but perhaps <a href="http://linil.wordpress.com/2008/06/14/cairoplot-plotting-graphics-using-python-and-cairo/" rel="nofollow">Cairo Plot</a> is worth taking a look at.</p>
2
2009-02-17T14:35:19Z
[ "python", "graphing", "stripchart" ]
Quick and dirty stripchart in python?
557,069
<p>I have some python code that receives a message every so often containing a timestamp and an edge transition, either low-to-high, or high-to-low. I'd like to graph each transition on a stripchart for a quick and dirty visualization of the digital waveform with the minimal amount of effort.</p> <p>Can you recommend ...
1
2009-02-17T14:30:39Z
557,181
<p>you may try using CairoPlot:</p> <pre><code>import CairoPlot #the data list stands for your low-to-high (1) and high-to-low (0) data data = lambda x : [0,0,1,1,0,0,1][x] CairoPlot.function_plot( 'Up_and_Down', data, 500, 300, discrete = True, x_bounds=( 0,len(data) - 1 ), step = 1 ) </code></pre> <p>For more info...
1
2009-02-17T14:52:53Z
[ "python", "graphing", "stripchart" ]
Quick and dirty stripchart in python?
557,069
<p>I have some python code that receives a message every so often containing a timestamp and an edge transition, either low-to-high, or high-to-low. I'd like to graph each transition on a stripchart for a quick and dirty visualization of the digital waveform with the minimal amount of effort.</p> <p>Can you recommend ...
1
2009-02-17T14:30:39Z
557,542
<p><a href="http://bitworking.org/projects/sparklines/" rel="nofollow">http://bitworking.org/projects/sparklines/</a> provides a tiny graph for you.</p>
0
2009-02-17T16:07:12Z
[ "python", "graphing", "stripchart" ]
Quick and dirty stripchart in python?
557,069
<p>I have some python code that receives a message every so often containing a timestamp and an edge transition, either low-to-high, or high-to-low. I'd like to graph each transition on a stripchart for a quick and dirty visualization of the digital waveform with the minimal amount of effort.</p> <p>Can you recommend ...
1
2009-02-17T14:30:39Z
557,593
<p><a href="http://www.gnuplot.info/" rel="nofollow">GnuPlot</a> is a the old reliable answer here, easy graphing with lots of options. I believe there are python bindings but it's probably easier to export your data and run it through regular gnuplot. Here's an ancient <a href="http://parand.com/docs/gnuplot.html" rel...
0
2009-02-17T16:17:38Z
[ "python", "graphing", "stripchart" ]
Quick and dirty stripchart in python?
557,069
<p>I have some python code that receives a message every so often containing a timestamp and an edge transition, either low-to-high, or high-to-low. I'd like to graph each transition on a stripchart for a quick and dirty visualization of the digital waveform with the minimal amount of effort.</p> <p>Can you recommend ...
1
2009-02-17T14:30:39Z
558,281
<p><a href="http://matplotlib.sourceforge.net" rel="nofollow">Matplotlib</a> might work. Take a look at this <a href="http://matplotlib.sourceforge.net/examples/animation/strip_chart_demo.html" rel="nofollow">strip chart demo</a>.</p>
2
2009-02-17T19:04:22Z
[ "python", "graphing", "stripchart" ]
Quick and dirty stripchart in python?
557,069
<p>I have some python code that receives a message every so often containing a timestamp and an edge transition, either low-to-high, or high-to-low. I'd like to graph each transition on a stripchart for a quick and dirty visualization of the digital waveform with the minimal amount of effort.</p> <p>Can you recommend ...
1
2009-02-17T14:30:39Z
7,605,445
<p>For a realtime stripchart application using only tkinter (no external packages required), see <a href="http://stackoverflow.com/questions/457246/what-is-the-best-real-time-plotting-widget-for-wxpython/7605072#7605072">What is the best real time plotting widget for wxPython?</a>.</p> <p>If I understand your question...
0
2011-09-30T02:44:04Z
[ "python", "graphing", "stripchart" ]
Quick and dirty stripchart in python?
557,069
<p>I have some python code that receives a message every so often containing a timestamp and an edge transition, either low-to-high, or high-to-low. I'd like to graph each transition on a stripchart for a quick and dirty visualization of the digital waveform with the minimal amount of effort.</p> <p>Can you recommend ...
1
2009-02-17T14:30:39Z
34,702,512
<pre><code>#simple stripchart using pygame import pygame, math, random white=(255,255,255) #define colors red=(255,0,0) pygame.init() #initialize pygame width=1000 height=200 size=[width,height] ...
1
2016-01-10T05:49:55Z
[ "python", "graphing", "stripchart" ]
Which Version of TurboGears should I use for a new project?
557,101
<p>I'm planing a new project and I want to use <a href="http://www.turbogears.org" rel="nofollow">TurboGears</a>. The problem is: I'm not sure which version to choose. There are three choices: Turbogears 1.0.8 (stable) Turbogears 1.1 (beta 3) Turbogears 2.0 (beta 4)</p> <p>As this is a new project I dont want to choos...
0
2009-02-17T14:38:19Z
557,178
<p>I personally would go with TG2 (but would also look at other frameworks such as Pylons or repoze.bfg) esp. if it's a new project. Remember that you might need to upgrade at some point (or want to at least). TG2 also is offers full WSGI support which gains more and more traction and is IMHO also something you really ...
5
2009-02-17T14:52:16Z
[ "python", "project", "turbogears" ]
Which Version of TurboGears should I use for a new project?
557,101
<p>I'm planing a new project and I want to use <a href="http://www.turbogears.org" rel="nofollow">TurboGears</a>. The problem is: I'm not sure which version to choose. There are three choices: Turbogears 1.0.8 (stable) Turbogears 1.1 (beta 3) Turbogears 2.0 (beta 4)</p> <p>As this is a new project I dont want to choos...
0
2009-02-17T14:38:19Z
557,498
<p>Yes, TG2. TG1.0.x is legacy, and TG1.1 is meant as a stepping stone to TG2 for legacy apps.</p> <p>I'd look very seriously at Pylons and Django too.</p>
1
2009-02-17T15:56:43Z
[ "python", "project", "turbogears" ]
How to re-use a reusable app in Django
557,171
<h2>Hello Django experts</h2> <p>I am trying to create my first site in Django and as I'm looking for example apps out there to draw inspiration from, I constantly stumble upon a term called <em>"reusable apps"</em>.</p> <p>I understand the <em>concept</em> of an app that is reusable easy enough, but the means of re...
17
2009-02-17T14:50:22Z
557,509
<p>In general, the only thing required to use a reusable app is to make sure it's on <code>sys.path</code>, so that you can import it from Python code. In most cases (if the author follows best practice), the reusable app tarball or bundle will contain a top-level directory with docs, a README, a <code>setup.py</code>...
25
2009-02-17T15:59:50Z
[ "python", "django", "code-reuse" ]
How to re-use a reusable app in Django
557,171
<h2>Hello Django experts</h2> <p>I am trying to create my first site in Django and as I'm looking for example apps out there to draw inspiration from, I constantly stumble upon a term called <em>"reusable apps"</em>.</p> <p>I understand the <em>concept</em> of an app that is reusable easy enough, but the means of re...
17
2009-02-17T14:50:22Z
3,710,136
<p>An old question, but here's what I do:</p> <p>If you're using a version control system (VCS), I suggest putting all of the reusable apps and libraries (including django) that your software needs in the VCS. If you don't want to put them directly under your project root, you can modify settings.py to add their locat...
2
2010-09-14T15:01:39Z
[ "python", "django", "code-reuse" ]
Converting a database-driven (non-OO) python script into a non-database driven, OO-script
557,199
<p>I have some software that is heavily dependent on MySQL, and is written in python without any class definitions. For performance reasons, and because the database is really just being used to store and retrieve large amounts of data, I'd like to convert this to an object-oriented python script that does not use the ...
0
2009-02-17T14:56:13Z
557,241
<p>There's no "one size fits all" answer for this -- it'll depend a lot on the data and how it's used in the application. If the data and usage are simple enough you might want to store your fruit in a dict with id as key and the rest of the data as tuples. Or not. It totally depends. If there's a guiding principle out...
1
2009-02-17T15:06:14Z
[ "python", "object" ]
Converting a database-driven (non-OO) python script into a non-database driven, OO-script
557,199
<p>I have some software that is heavily dependent on MySQL, and is written in python without any class definitions. For performance reasons, and because the database is really just being used to store and retrieve large amounts of data, I'd like to convert this to an object-oriented python script that does not use the ...
0
2009-02-17T14:56:13Z
557,279
<p>you could have a fruit class with id and name instance variables. and a function to read/write the information from a file, and maybe a class variable to keep track of the number of fruits (objects) created</p>
1
2009-02-17T15:14:45Z
[ "python", "object" ]
Converting a database-driven (non-OO) python script into a non-database driven, OO-script
557,199
<p>I have some software that is heavily dependent on MySQL, and is written in python without any class definitions. For performance reasons, and because the database is really just being used to store and retrieve large amounts of data, I'd like to convert this to an object-oriented python script that does not use the ...
0
2009-02-17T14:56:13Z
557,291
<p>Generally you want your Objects to absolutely match your "real world entities".</p> <p>Since you're starting from a database, it's not always the case that the database has any real-world fidelity, either. Some database designs are simply awful.</p> <p>If your database has reasonable models for Fruit, that's wher...
2
2009-02-17T15:17:01Z
[ "python", "object" ]
Converting a database-driven (non-OO) python script into a non-database driven, OO-script
557,199
<p>I have some software that is heavily dependent on MySQL, and is written in python without any class definitions. For performance reasons, and because the database is really just being used to store and retrieve large amounts of data, I'd like to convert this to an object-oriented python script that does not use the ...
0
2009-02-17T14:56:13Z
557,403
<p>In the simple case <a href="http://docs.python.org/dev/library/collections.html#collections.namedtuple" rel="nofollow">namedtuples</a> let get you started:</p> <pre><code>&gt;&gt;&gt; from collections import namedtuple &gt;&gt;&gt; Fruit = namedtuple("Fruit", "name weight color") &gt;&gt;&gt; fruits = [Fruit(*row) ...
1
2009-02-17T15:36:39Z
[ "python", "object" ]
Converting a database-driven (non-OO) python script into a non-database driven, OO-script
557,199
<p>I have some software that is heavily dependent on MySQL, and is written in python without any class definitions. For performance reasons, and because the database is really just being used to store and retrieve large amounts of data, I'd like to convert this to an object-oriented python script that does not use the ...
0
2009-02-17T14:56:13Z
557,473
<p>If the data is a natural fit for database tables ("rectangular data"), why not convert it to sqlite? It's portable -- just one file to move the db around, and sqlite is available anywhere you have python (2.5 and above anyway).</p>
5
2009-02-17T15:51:38Z
[ "python", "object" ]
Converting a database-driven (non-OO) python script into a non-database driven, OO-script
557,199
<p>I have some software that is heavily dependent on MySQL, and is written in python without any class definitions. For performance reasons, and because the database is really just being used to store and retrieve large amounts of data, I'd like to convert this to an object-oriented python script that does not use the ...
0
2009-02-17T14:56:13Z
558,619
<p>Another way would be to use the ZODB to directly store objects persistently. The only thing you have to do is to derive your classes from Peristent and everything from the root object up is then automatically stored in that database as an object. The root object comes from the ZODB connection. There are many backend...
1
2009-02-17T20:38:29Z
[ "python", "object" ]
Converting a database-driven (non-OO) python script into a non-database driven, OO-script
557,199
<p>I have some software that is heavily dependent on MySQL, and is written in python without any class definitions. For performance reasons, and because the database is really just being used to store and retrieve large amounts of data, I'd like to convert this to an object-oriented python script that does not use the ...
0
2009-02-17T14:56:13Z
558,822
<p>Here are a couple points for you to consider. If your data is large reading it all into memory may be wasteful. If you need random access and not just sequential access to your data then you'll either have to scan the at most the entire file each time or read that table into an indexed memory structure like a dict...
1
2009-02-17T21:32:03Z
[ "python", "object" ]
Converting a database-driven (non-OO) python script into a non-database driven, OO-script
557,199
<p>I have some software that is heavily dependent on MySQL, and is written in python without any class definitions. For performance reasons, and because the database is really just being used to store and retrieve large amounts of data, I'd like to convert this to an object-oriented python script that does not use the ...
0
2009-02-17T14:56:13Z
558,830
<p>Abstract persistence from the object class. Put all of the persistence logic in an adapter class, and assign the adapter to the object class. Something like:</p> <pre><code>class Fruit(Object): @classmethod def get(cls, id): return cls.adapter.get(id) def put(self): cls.adapter.put(self) ...
1
2009-02-17T21:35:15Z
[ "python", "object" ]
Make pyunit show output for every assertion
557,213
<p>How can I make python's unittest module show output for every assertion, rather than failing at the first one per test case? It would be much easier to debug if I could see the complete pattern of failures rather than just the first one.</p> <p>In my case the assertions are based on a couple loops over an array con...
1
2009-02-17T14:58:21Z
557,386
<pre><code>import unittest import get_nodes class TestSuper(unittest.TestCase): def setUp( self ): self.root = get_nodes.mmnode_plus.factory('mytree.xml') def condition( self, aNode, skip_traversal, skip_as_child, skip_as_parent, is_leaf ): self.assertEquals( skip_traversal, aNode.skip_traversa...
2
2009-02-17T15:32:58Z
[ "python", "unit-testing", "pyunit" ]
Make pyunit show output for every assertion
557,213
<p>How can I make python's unittest module show output for every assertion, rather than failing at the first one per test case? It would be much easier to debug if I could see the complete pattern of failures rather than just the first one.</p> <p>In my case the assertions are based on a couple loops over an array con...
1
2009-02-17T14:58:21Z
559,006
<p>I was able to do it by making new TestCase classes dynamically using the builtin type() factory:</p> <pre><code>root = get_nodes.mmnode_plus.factory('somenodes.xml') tests = [ (root, {'skip_traversal': False, 'skip_as_child': True, 'skip_as_parent': False, 'is_leaf': False}), (root[0], {'skip_traversal': F...
1
2009-02-17T22:27:41Z
[ "python", "unit-testing", "pyunit" ]
Django - having middleware communicate with views/templates
557,460
<p>Alright, this is probably a really silly question but I am new to Python/Django so I can't really wrap my head around its scoping concepts just yet. Right now I am writing a <a href="http://docs.djangoproject.com/en/dev/topics/http/middleware/#topics-http-middleware">middleware</a> class to handle some stuff, and I ...
7
2009-02-17T15:47:49Z
557,524
<p>1) If you modify 'settings', this is truly going to be global even across requests. In other words, concurrent requests are going to stomp each other if you need each request to have its own value. It's safer to modify the request object itself, which is what some of the common Django middleware does (e.g. django....
4
2009-02-17T16:02:01Z
[ "python", "django" ]
Django - having middleware communicate with views/templates
557,460
<p>Alright, this is probably a really silly question but I am new to Python/Django so I can't really wrap my head around its scoping concepts just yet. Right now I am writing a <a href="http://docs.djangoproject.com/en/dev/topics/http/middleware/#topics-http-middleware">middleware</a> class to handle some stuff, and I ...
7
2009-02-17T15:47:49Z
557,538
<p>Here's what we do. We use a context processor like this...</p> <pre><code>def context_myApp_settings(request): """Insert some additional information into the template context from the settings. Specifically, the LOGOUT_URL, MEDIA_URL and BADGES settings. """ from django.conf import settings ...
12
2009-02-17T16:06:36Z
[ "python", "django" ]
Django - having middleware communicate with views/templates
557,460
<p>Alright, this is probably a really silly question but I am new to Python/Django so I can't really wrap my head around its scoping concepts just yet. Right now I am writing a <a href="http://docs.djangoproject.com/en/dev/topics/http/middleware/#topics-http-middleware">middleware</a> class to handle some stuff, and I ...
7
2009-02-17T15:47:49Z
557,540
<ol> <li><p>It's not the best way. You could set my_var on the request rather than on the settings. Settings are global and apply to the whole site. You don't want to modify it for every request. There could be concurrency issues with multiple request updating/reading the variable at the same time.</p></li> <li><p>To a...
19
2009-02-17T16:06:49Z
[ "python", "django" ]
How do I use easy_install and buildout when pypi is down?
557,462
<p>I am using <a href="http://pypi.python.org/pypi/zc.buildout">buildout</a> to automatically download and setup the many dependencies of my Plone installation. buildout more or less uses easy_install to download and install a bunch of Python eggs. This usually works, but it doesn't work if any of the dependencies cann...
13
2009-02-17T15:48:23Z
557,832
<p>Here are <a href="http://www.zopyx.de/blog/creating-a-local-pypi-mirror">instructions on how to setup your own PyPi mirror</a>. The homepage of this project is <a href="http://www.openplans.org/projects/pypi-mirroring/project-home">here</a>. There also seems to be a growing number of mirrors out there.</p> <p>For i...
12
2009-02-17T17:22:44Z
[ "python", "plone", "easy-install", "buildout" ]
How do I use easy_install and buildout when pypi is down?
557,462
<p>I am using <a href="http://pypi.python.org/pypi/zc.buildout">buildout</a> to automatically download and setup the many dependencies of my Plone installation. buildout more or less uses easy_install to download and install a bunch of Python eggs. This usually works, but it doesn't work if any of the dependencies cann...
13
2009-02-17T15:48:23Z
3,292,240
<p>You can also use a mirror. Put this in the "[global]" section of "~/.pip/pip.conf":</p> <pre><code>index-url = http://d.pypi.python.org/simple/ </code></pre> <p>This is a recent feature as announced <a href="http://mail.python.org/pipermail/catalog-sig/2010-July/003132.html">here</a>.</p>
8
2010-07-20T16:36:12Z
[ "python", "plone", "easy-install", "buildout" ]
How do I use easy_install and buildout when pypi is down?
557,462
<p>I am using <a href="http://pypi.python.org/pypi/zc.buildout">buildout</a> to automatically download and setup the many dependencies of my Plone installation. buildout more or less uses easy_install to download and install a bunch of Python eggs. This usually works, but it doesn't work if any of the dependencies cann...
13
2009-02-17T15:48:23Z
3,393,628
<p>This page shows how to use the alternate mirror mentioned in @moraes post, but for easy_install, buildout and virtualenv as well as pip:</p> <p><a href="http://jacobian.org/writing/when-pypi-goes-down/">http://jacobian.org/writing/when-pypi-goes-down/</a></p>
5
2010-08-03T04:44:42Z
[ "python", "plone", "easy-install", "buildout" ]
How do I use easy_install and buildout when pypi is down?
557,462
<p>I am using <a href="http://pypi.python.org/pypi/zc.buildout">buildout</a> to automatically download and setup the many dependencies of my Plone installation. buildout more or less uses easy_install to download and install a bunch of Python eggs. This usually works, but it doesn't work if any of the dependencies cann...
13
2009-02-17T15:48:23Z
5,589,821
<p>PyPI has had mirroring since mid 2010 <a href="http://pypi.python.org/mirrors" rel="nofollow">http://pypi.python.org/mirrors</a></p>
0
2011-04-08T02:37:06Z
[ "python", "plone", "easy-install", "buildout" ]
How do I use easy_install and buildout when pypi is down?
557,462
<p>I am using <a href="http://pypi.python.org/pypi/zc.buildout">buildout</a> to automatically download and setup the many dependencies of my Plone installation. buildout more or less uses easy_install to download and install a bunch of Python eggs. This usually works, but it doesn't work if any of the dependencies cann...
13
2009-02-17T15:48:23Z
6,147,959
<p>Configure <code>index</code> in <code>buildout.cfg</code>, e.g.</p> <pre><code>[buildout] index = http://a.pypi.python.org/ find-links = </code></pre> <p>More mirrors on : <a href="http://www.pypi-mirrors.org/" rel="nofollow">http://www.pypi-mirrors.org/</a></p>
2
2011-05-27T04:51:34Z
[ "python", "plone", "easy-install", "buildout" ]
How do I use easy_install and buildout when pypi is down?
557,462
<p>I am using <a href="http://pypi.python.org/pypi/zc.buildout">buildout</a> to automatically download and setup the many dependencies of my Plone installation. buildout more or less uses easy_install to download and install a bunch of Python eggs. This usually works, but it doesn't work if any of the dependencies cann...
13
2009-02-17T15:48:23Z
8,333,271
<p>In case of zc.buildout: use its local download caching features. There are mostly three things to cache: </p> <ul> <li>external extends, i.e. <a href="http://dist.plone.org/release/4.1.2/versions.cfg" rel="nofollow">http://dist.plone.org/release/4.1.2/versions.cfg</a></li> <li>eggs from some distserver, i.e. pypi</...
3
2011-11-30T21:36:37Z
[ "python", "plone", "easy-install", "buildout" ]
How do I suppress python-mode's output buffer?
557,555
<p>In python-mode (for emacs), hitting Control-C\Control-C will execute the current buffer. However, when execution is finished, the output buffer springs up and splits my editing window in half. This is a <em>complete</em> pain, especially given that there's generally no output in the buffer anyway!</p> <p>Is there...
5
2009-02-17T16:10:51Z
557,605
<p>Sorry that I can't help you with emacs, but as for your second question, a modified aluminum keyboard from Apple may be a solution:</p> <p><a href="http://www.apple.com/keyboard/" rel="nofollow">http://www.apple.com/keyboard/</a></p>
2
2009-02-17T16:20:54Z
[ "python", "emacs" ]
How do I suppress python-mode's output buffer?
557,555
<p>In python-mode (for emacs), hitting Control-C\Control-C will execute the current buffer. However, when execution is finished, the output buffer springs up and splits my editing window in half. This is a <em>complete</em> pain, especially given that there's generally no output in the buffer anyway!</p> <p>Is there...
5
2009-02-17T16:10:51Z
557,779
<p>You might want to customize the <code>pop-up-windows</code> variable; that controls the splitting functionality.</p>
1
2009-02-17T17:12:38Z
[ "python", "emacs" ]
How do I suppress python-mode's output buffer?
557,555
<p>In python-mode (for emacs), hitting Control-C\Control-C will execute the current buffer. However, when execution is finished, the output buffer springs up and splits my editing window in half. This is a <em>complete</em> pain, especially given that there's generally no output in the buffer anyway!</p> <p>Is there...
5
2009-02-17T16:10:51Z
557,820
<p>Don't know how to stop it from popping up, but <em>C-x, 1</em> will close the window.</p>
0
2009-02-17T17:20:00Z
[ "python", "emacs" ]
How do I suppress python-mode's output buffer?
557,555
<p>In python-mode (for emacs), hitting Control-C\Control-C will execute the current buffer. However, when execution is finished, the output buffer springs up and splits my editing window in half. This is a <em>complete</em> pain, especially given that there's generally no output in the buffer anyway!</p> <p>Is there...
5
2009-02-17T16:10:51Z
559,238
<p>What python-mode are you using? Unfortunately, there are <em>several</em>.</p> <p>Type C-h k and then C-c C-c .. what does it say in the modeline? Does it say "py-execute-buffer" or does it say "python-send-buffer", the first kind indicates you're using Tim Peters' python-mode, while the second indicates you're usi...
5
2009-02-17T23:42:02Z
[ "python", "emacs" ]
How do I suppress python-mode's output buffer?
557,555
<p>In python-mode (for emacs), hitting Control-C\Control-C will execute the current buffer. However, when execution is finished, the output buffer springs up and splits my editing window in half. This is a <em>complete</em> pain, especially given that there's generally no output in the buffer anyway!</p> <p>Is there...
5
2009-02-17T16:10:51Z
8,940,489
<p>In recent <code>python-mode.el</code> that behavior is controlled by a customizable variable:</p> <pre><code>py-shell-switch-buffers-on-execute </code></pre> <p>See these links:</p> <ul> <li><p><a href="http://launchpad.net/python-mode" rel="nofollow">An Emacs mode for editing Python code</a></p></li> <li><p><a h...
2
2012-01-20T11:08:59Z
[ "python", "emacs" ]
Want procmail to run a custom python script, everytime a new mail shows up
557,906
<p>I have a pretty usual requirement with procmail but I am unable to get the results somehow. I have procmailrc file with this content:</p> <pre><code>:0 * ^To.*@myhost | /usr/bin/python /work/scripts/privilege_emails_forward.py </code></pre> <p>Wherein my custom python script(privilege_emails_forward.py) will be sc...
9
2009-02-17T17:37:23Z
557,932
<p>That is just fine, just put <code>fw</code> after <code>:0</code> (<code>:0 fw</code>). Your python program will receive the mail on <code>stdin</code>. You have to 'echo' the possibly transformed mail on <code>stdout</code>.</p> <p><code>fw</code> means:</p> <ul> <li><code>f</code> Consider the pipe as a filter.<...
11
2009-02-17T17:45:04Z
[ "python", "email", "procmail" ]
Want procmail to run a custom python script, everytime a new mail shows up
557,906
<p>I have a pretty usual requirement with procmail but I am unable to get the results somehow. I have procmailrc file with this content:</p> <pre><code>:0 * ^To.*@myhost | /usr/bin/python /work/scripts/privilege_emails_forward.py </code></pre> <p>Wherein my custom python script(privilege_emails_forward.py) will be sc...
9
2009-02-17T17:37:23Z
561,142
<p>The <a href="http://stackoverflow.com/questions/557906/want-procmail-to-run-a-custom-python-script-everytime-a-new-mail-shows-up/561028#561028">log excerpt</a> clearly states that your script is executed, even if it doesn't show the desired effect. I'd expect procmail to log an error if the execution failed.</p> <...
4
2009-02-18T14:01:22Z
[ "python", "email", "procmail" ]
Debugging web apps
557,927
<p>I've gotten pretty used to step-through debuggers over the years, both in builder, and using the pydev debugger in Eclipse. </p> <p>Currently, I'm making something in Python and running it on Google App Engine, and I should add that I'm pretty new to developing any real web app; I've never really done much beyond e...
8
2009-02-17T17:43:59Z
557,938
<p>The dev_appserver is just a python script, you can simply use the pydev debugger on that script with the proper arguments as far as I know.</p> <p>Here is a very detailed guide on how to do that:</p> <p><a href="http://www.ibm.com/developerworks/opensource/library/os-eclipse-mashup-google-pt1/index.html" rel="nofo...
7
2009-02-17T17:47:05Z
[ "python", "eclipse", "debugging", "google-app-engine" ]
Debugging web apps
557,927
<p>I've gotten pretty used to step-through debuggers over the years, both in builder, and using the pydev debugger in Eclipse. </p> <p>Currently, I'm making something in Python and running it on Google App Engine, and I should add that I'm pretty new to developing any real web app; I've never really done much beyond e...
8
2009-02-17T17:43:59Z
558,065
<p>"Is there a better technique for dealing with this?" Not really.</p> <p>"step-through debuggers" are their own problem. They're a kind of mental crutch that make it easy to get something that looks like it works.</p> <p>First, look at <a href="http://code.google.com/appengine/docs/python/tools/devserver.html#The...
2
2009-02-17T18:13:26Z
[ "python", "eclipse", "debugging", "google-app-engine" ]
Debugging web apps
557,927
<p>I've gotten pretty used to step-through debuggers over the years, both in builder, and using the pydev debugger in Eclipse. </p> <p>Currently, I'm making something in Python and running it on Google App Engine, and I should add that I'm pretty new to developing any real web app; I've never really done much beyond e...
8
2009-02-17T17:43:59Z
558,165
<p>I would suggest to use logging statements instead of prints though as you can control them better. Python has a quite good logging library included.</p> <p>For logging from Google App Engine to e.g. Firebug there is also some handy tool called <a href="http://appengine-cookbook.appspot.com/recipe/firepython-logger-...
4
2009-02-17T18:33:49Z
[ "python", "eclipse", "debugging", "google-app-engine" ]
Debugging web apps
557,927
<p>I've gotten pretty used to step-through debuggers over the years, both in builder, and using the pydev debugger in Eclipse. </p> <p>Currently, I'm making something in Python and running it on Google App Engine, and I should add that I'm pretty new to developing any real web app; I've never really done much beyond e...
8
2009-02-17T17:43:59Z
560,779
<p>My debugging toolbox for GAE:</p> <ul> <li>standard Python logging as a substitute for <code>print</code> statements</li> <li><a href="http://dev.pocoo.org/projects/werkzeug/wiki/UsingDebuggerWithAppEngine" rel="nofollow">Werkzeug debugger</a> if I do not want to go to the console log on each error (not everything ...
1
2009-02-18T12:01:10Z
[ "python", "eclipse", "debugging", "google-app-engine" ]
String separation in required format, Pythonic way? (with or w/o Regex)
558,105
<p>I have a string in the format:</p> <pre><code>t='@abc @def Hello this part is text' </code></pre> <p>I want to get this:</p> <pre><code>l=["abc", "def"] s='Hello this part is text' </code></pre> <p>I did this:</p> <pre><code>a=t[t.find(' ',t.rfind('@')):].strip() s=t[:t.find(' ',t.rfind('@'))].strip() b=a.spli...
6
2009-02-17T18:22:07Z
558,181
<pre><code> [i.strip('@') for i in t.split(' ', 2)[:2]] # for a fixed number of @def a = [i.strip('@') for i in t.split(' ') if i.startswith('@')] s = ' '.join(i for i in t.split(' ') if not i.startwith('@')) </code></pre>
3
2009-02-17T18:37:22Z
[ "regex", "string", "format", "python" ]
String separation in required format, Pythonic way? (with or w/o Regex)
558,105
<p>I have a string in the format:</p> <pre><code>t='@abc @def Hello this part is text' </code></pre> <p>I want to get this:</p> <pre><code>l=["abc", "def"] s='Hello this part is text' </code></pre> <p>I did this:</p> <pre><code>a=t[t.find(' ',t.rfind('@')):].strip() s=t[:t.find(' ',t.rfind('@'))].strip() b=a.spli...
6
2009-02-17T18:22:07Z
558,189
<p>You might also use regular expressions:</p> <pre><code>import re rx = re.compile("@([\w]+) @([\w]+) (.*)") t='@abc @def Hello this part is text and my email is foo@ba.r' a,b,s = rx.match(t).groups() </code></pre> <p>But this all depends on how your data can look like. So you might need to adjust it. What it does i...
3
2009-02-17T18:40:23Z
[ "regex", "string", "format", "python" ]
String separation in required format, Pythonic way? (with or w/o Regex)
558,105
<p>I have a string in the format:</p> <pre><code>t='@abc @def Hello this part is text' </code></pre> <p>I want to get this:</p> <pre><code>l=["abc", "def"] s='Hello this part is text' </code></pre> <p>I did this:</p> <pre><code>a=t[t.find(' ',t.rfind('@')):].strip() s=t[:t.find(' ',t.rfind('@'))].strip() b=a.spli...
6
2009-02-17T18:22:07Z
558,278
<p>How about this:</p> <ol> <li>Splitting by space.</li> <li><p>foreach word, check </p> <p>2.1. if word starts with @ then Push to first list</p> <p>2.2. otherwise just join the remaining words by spaces.</p></li> </ol>
5
2009-02-17T19:03:38Z
[ "regex", "string", "format", "python" ]
String separation in required format, Pythonic way? (with or w/o Regex)
558,105
<p>I have a string in the format:</p> <pre><code>t='@abc @def Hello this part is text' </code></pre> <p>I want to get this:</p> <pre><code>l=["abc", "def"] s='Hello this part is text' </code></pre> <p>I did this:</p> <pre><code>a=t[t.find(' ',t.rfind('@')):].strip() s=t[:t.find(' ',t.rfind('@'))].strip() b=a.spli...
6
2009-02-17T18:22:07Z
558,345
<p>[<strong>edit</strong>: this is implementing what was suggested by Osama above]</p> <p>This will create L based on the @ variables from the beginning of the string, and then once a non @ var is found, just grab the rest of the string.</p> <pre><code>t = '@one @two @three some text afterward with @ symbols@ meow@...
3
2009-02-17T19:21:39Z
[ "regex", "string", "format", "python" ]
String separation in required format, Pythonic way? (with or w/o Regex)
558,105
<p>I have a string in the format:</p> <pre><code>t='@abc @def Hello this part is text' </code></pre> <p>I want to get this:</p> <pre><code>l=["abc", "def"] s='Hello this part is text' </code></pre> <p>I did this:</p> <pre><code>a=t[t.find(' ',t.rfind('@')):].strip() s=t[:t.find(' ',t.rfind('@'))].strip() b=a.spli...
6
2009-02-17T18:22:07Z
558,392
<p>Building unashamedly on MrTopf's effort:</p> <pre><code>import re rx = re.compile("((?:@\w+ +)+)(.*)") t='@abc @def @xyz Hello this part is text and my email is foo@ba.r' a,s = rx.match(t).groups() l = re.split('[@ ]+',a)[1:-1] print l print s </code></pre> <p>prints:</p> <blockquote> <p>['abc', 'def', 'xyz'...
13
2009-02-17T19:32:42Z
[ "regex", "string", "format", "python" ]
String separation in required format, Pythonic way? (with or w/o Regex)
558,105
<p>I have a string in the format:</p> <pre><code>t='@abc @def Hello this part is text' </code></pre> <p>I want to get this:</p> <pre><code>l=["abc", "def"] s='Hello this part is text' </code></pre> <p>I did this:</p> <pre><code>a=t[t.find(' ',t.rfind('@')):].strip() s=t[:t.find(' ',t.rfind('@'))].strip() b=a.spli...
6
2009-02-17T18:22:07Z
558,393
<pre><code>t='@abc @def Hello this part is text' words = t.split(' ') names = [] while words: w = words.pop(0) if w.startswith('@'): names.append(w[1:]) else: break text = ' '.join(words) print names print text </code></pre>
7
2009-02-17T19:32:42Z
[ "regex", "string", "format", "python" ]
String separation in required format, Pythonic way? (with or w/o Regex)
558,105
<p>I have a string in the format:</p> <pre><code>t='@abc @def Hello this part is text' </code></pre> <p>I want to get this:</p> <pre><code>l=["abc", "def"] s='Hello this part is text' </code></pre> <p>I did this:</p> <pre><code>a=t[t.find(' ',t.rfind('@')):].strip() s=t[:t.find(' ',t.rfind('@'))].strip() b=a.spli...
6
2009-02-17T18:22:07Z
563,299
<p>Here's just another variation that uses split() and no regexpes:</p> <pre><code>t='@abc @def My email is red@hjk.com' tags = [] words = iter(t.split()) # iterate over words until first non-tag word for w in words: if not w.startswith("@"): # join this word and all the following s = w + " " + (" ".join(wo...
1
2009-02-18T23:14:31Z
[ "regex", "string", "format", "python" ]
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
558,216
<p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p> <pre><code>def nearlyequal( a, b, sigfig=5 ): </code></pre> <p>The pu...
13
2009-02-17T18:49:20Z
558,289
<p>Here's a take.</p> <pre><code>def nearly_equal(a,b,sig_fig=5): return ( a==b or int(a*10**sig_fig) == int(b*10**sig_fig) ) </code></pre>
8
2009-02-17T19:07:04Z
[ "python", "math", "floating-point", "numpy" ]
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
558,216
<p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p> <pre><code>def nearlyequal( a, b, sigfig=5 ): </code></pre> <p>The pu...
13
2009-02-17T18:49:20Z
558,298
<p>"Significant figures" in decimal is a matter of adjusting the decimal point and truncating to an integer. </p> <pre><code>&gt;&gt;&gt; int(3.1415926 * 10**3) 3141 &gt;&gt;&gt; int(1234567 * 10**-3) 1234 &gt;&gt;&gt; </code></pre>
2
2009-02-17T19:10:06Z
[ "python", "math", "floating-point", "numpy" ]
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
558,216
<p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p> <pre><code>def nearlyequal( a, b, sigfig=5 ): </code></pre> <p>The pu...
13
2009-02-17T18:49:20Z
558,322
<p>There is a function <code>assert_approx_equal</code> in <code>numpy.testing</code> (source <a href="https://github.com/numpy/numpy/blob/1225aef37298ec82048d0828f6cb7e0be8ed58cc/numpy/testing/utils.py#L513" rel="nofollow">here) </a>which may be a good starting point. </p> <pre><code>def assert_approx_equal(actual,de...
16
2009-02-17T19:16:25Z
[ "python", "math", "floating-point", "numpy" ]
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
558,216
<p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p> <pre><code>def nearlyequal( a, b, sigfig=5 ): </code></pre> <p>The pu...
13
2009-02-17T18:49:20Z
558,359
<p>I believe your question is not defined well enough, and the unit-tests you present prove it:</p> <p>If by 'round to N sig-fig decimal places' you mean 'N decimal places to the right of the decimal point', then the test <code>assert nearlyequal(1e9, 1e9 + 1 , 5)</code> should fail, because even when you round 100000...
4
2009-02-17T19:24:29Z
[ "python", "math", "floating-point", "numpy" ]
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
558,216
<p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p> <pre><code>def nearlyequal( a, b, sigfig=5 ): </code></pre> <p>The pu...
13
2009-02-17T18:49:20Z
563,955
<p>This is a fairly common issue with floating point numbers. I solve it based on the discussion in Section 1.5 of Demmel[1]. (1) Calculate the roundoff error. (2) Check that the roundoff error is less than some epsilon. I haven't used python in some time and only have version 2.4.3, but I'll try to get this correct.</...
1
2009-02-19T04:30:15Z
[ "python", "math", "floating-point", "numpy" ]
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
558,216
<p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p> <pre><code>def nearlyequal( a, b, sigfig=5 ): </code></pre> <p>The pu...
13
2009-02-17T18:49:20Z
563,993
<p>Oren Shemesh got part of the problem with the problem as stated but there's more:</p> <p>assert nearlyequal( 0.0, 1e-15, 5 ) </p> <p>also fails the second definition (and that's the definition I learned in school.)</p> <p>No matter how many digits you are looking at, 0 will not equal a not-zero. This could prove...
1
2009-02-19T04:55:15Z
[ "python", "math", "floating-point", "numpy" ]
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
558,216
<p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p> <pre><code>def nearlyequal( a, b, sigfig=5 ): </code></pre> <p>The pu...
13
2009-02-17T18:49:20Z
564,086
<p>There are already plenty of great answers, but here's a think:</p> <pre><code>def closeness(a, b): """Returns measure of equality (for two floats), in unit of decimal significant figures.""" if a == b: return float("infinity") difference = abs(a - b) avg = (a + b)/2 return math.log10( avg / diffe...
3
2009-02-19T05:50:20Z
[ "python", "math", "floating-point", "numpy" ]
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
558,216
<p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p> <pre><code>def nearlyequal( a, b, sigfig=5 ): </code></pre> <p>The pu...
13
2009-02-17T18:49:20Z
1,595,078
<p>There is a interesting solution to this by B. Dawson (with C++ code) at <a href="http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm" rel="nofollow">"Comparing Floating Point Numbers"</a>. His approach relies on strict IEEE representation of two numbers and the enforced lexicographical orderin...
1
2009-10-20T14:36:50Z
[ "python", "math", "floating-point", "numpy" ]
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
558,216
<p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p> <pre><code>def nearlyequal( a, b, sigfig=5 ): </code></pre> <p>The pu...
13
2009-02-17T18:49:20Z
20,585,965
<p>There are lots of ways of comparing two numbers to see if they agree to N significant digits. Roughly speaking you just want to make sure that their difference is less than 10^-N times the largest of the two numbers being compared. That's easy enough.</p> <p>But, what if one of the numbers is zero? The whole concep...
0
2013-12-14T17:11:49Z
[ "python", "math", "floating-point", "numpy" ]
Function to determine if two numbers are nearly equal when rounded to n significant decimal digits
558,216
<p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p> <pre><code>def nearlyequal( a, b, sigfig=5 ): </code></pre> <p>The pu...
13
2009-02-17T18:49:20Z
36,407,955
<p>As of Python 3.5, the standard way to do this (using the standard library) is with the <a href="https://docs.python.org/3/library/math.html#math.isclose" rel="nofollow"><code>math.isclose</code></a> function.</p> <p>It has the following signature:</p> <pre><code>isclose(a, b, rel_tol=1e-9, abs_tol=0.0) </code></pr...
5
2016-04-04T16:24:31Z
[ "python", "math", "floating-point", "numpy" ]
Bayesian spam filtering library for Python
558,219
<p>I am looking for a Python library which does Bayesian Spam Filtering. I looked at SpamBayes and OpenBayes, but both seem to be unmaintained (I might be wrong).</p> <p>Can anyone suggest a good Python (or Clojure, Common Lisp, even Ruby) library which implements Bayesian Spam Filtering?</p> <p>Thanks in advance.</p...
19
2009-02-17T18:50:18Z
558,299
<p>Try to use <a href="http://bogofilter.sourceforge.net/" rel="nofollow">bogofilter</a>, I'm not sure how it can be used from Python. Bogofilter is integrated with many mail systems, which means a relative ease of interfacing.</p>
3
2009-02-17T19:10:11Z
[ "python", "spam-prevention", "bayesian", "bayesian-networks" ]
Bayesian spam filtering library for Python
558,219
<p>I am looking for a Python library which does Bayesian Spam Filtering. I looked at SpamBayes and OpenBayes, but both seem to be unmaintained (I might be wrong).</p> <p>Can anyone suggest a good Python (or Clojure, Common Lisp, even Ruby) library which implements Bayesian Spam Filtering?</p> <p>Thanks in advance.</p...
19
2009-02-17T18:50:18Z
558,405
<p>Do you want spam filtering or Bayesian classification?</p> <p>For Bayesian classification there are a number of Python modules. I was just recently reviewing <a href="http://www.ailab.si/orange/">Orange</a> which looks very impressive. R has a number of Bayesian modules. You can use <a href="http://rpy.sourcefor...
11
2009-02-17T19:35:52Z
[ "python", "spam-prevention", "bayesian", "bayesian-networks" ]
Bayesian spam filtering library for Python
558,219
<p>I am looking for a Python library which does Bayesian Spam Filtering. I looked at SpamBayes and OpenBayes, but both seem to be unmaintained (I might be wrong).</p> <p>Can anyone suggest a good Python (or Clojure, Common Lisp, even Ruby) library which implements Bayesian Spam Filtering?</p> <p>Thanks in advance.</p...
19
2009-02-17T18:50:18Z
561,654
<p>Try <a href="http://bazaar.launchpad.net/~divmod-dev/divmod.org/trunk/files/head:/Reverend/" rel="nofollow">Reverend</a>. It's a spam filtering module.</p>
12
2009-02-18T15:50:37Z
[ "python", "spam-prevention", "bayesian", "bayesian-networks" ]
Bayesian spam filtering library for Python
558,219
<p>I am looking for a Python library which does Bayesian Spam Filtering. I looked at SpamBayes and OpenBayes, but both seem to be unmaintained (I might be wrong).</p> <p>Can anyone suggest a good Python (or Clojure, Common Lisp, even Ruby) library which implements Bayesian Spam Filtering?</p> <p>Thanks in advance.</p...
19
2009-02-17T18:50:18Z
806,101
<p><a href="http://spambayes.org" rel="nofollow">SpamBayes</a> <strong>is</strong> maintained, and is mature (i.e. it works without having to have new releases all the time). It will easily do what you want. Note that SpamBayes is only loosely Bayesian (it uses chi-squared combining), but presumably you're after any ...
3
2009-04-30T09:31:01Z
[ "python", "spam-prevention", "bayesian", "bayesian-networks" ]
Bayesian spam filtering library for Python
558,219
<p>I am looking for a Python library which does Bayesian Spam Filtering. I looked at SpamBayes and OpenBayes, but both seem to be unmaintained (I might be wrong).</p> <p>Can anyone suggest a good Python (or Clojure, Common Lisp, even Ruby) library which implements Bayesian Spam Filtering?</p> <p>Thanks in advance.</p...
19
2009-02-17T18:50:18Z
978,043
<p>A module in the Python natural language toolkit (nltk) does naïve Bayesian classification: <a href="http://nltk.googlecode.com/svn/trunk/doc/api/nltk.classify.naivebayes-module.html" rel="nofollow"><code>nltk.classify.naivebayes</code></a>.</p> <p><em>Disclaimer:</em> I know crap all about Bayesian classification,...
1
2009-06-10T20:44:01Z
[ "python", "spam-prevention", "bayesian", "bayesian-networks" ]
Bayesian spam filtering library for Python
558,219
<p>I am looking for a Python library which does Bayesian Spam Filtering. I looked at SpamBayes and OpenBayes, but both seem to be unmaintained (I might be wrong).</p> <p>Can anyone suggest a good Python (or Clojure, Common Lisp, even Ruby) library which implements Bayesian Spam Filtering?</p> <p>Thanks in advance.</p...
19
2009-02-17T18:50:18Z
11,917,279
<p>RedisBayes looks good to me:</p> <p><a href="http://pypi.python.org/pypi/redisbayes/0.1.3">http://pypi.python.org/pypi/redisbayes/0.1.3</a></p> <p>In my experience Redis is an awesome addition to your stack and can help process data at blazing fast speeds compared to MySQL, PostgreSQL or any other RDBMS.</p> <pre...
8
2012-08-11T20:11:51Z
[ "python", "spam-prevention", "bayesian", "bayesian-networks" ]
What is wrong with my nested loops in Python?
558,539
<p>How do I make nested loops in Python (version 3.0)?</p> <p>I am trying to get the following loops to show me the products of two numbers:</p> <pre><code>def PrintProductsBelowNumber(number): number1 = 1 number2 = 1 while number1 &lt;= number: while number2 &lt;= number: print(number...
0
2009-02-17T20:19:26Z
558,552
<p>Because you aren't setting number2 back to 1 after the inner loop completes the first time. number1 then increments, but since number2 is still too high the inner loop doesn't run again. </p> <pre><code>def PrintProductsBelowNumber(number): number1 = 1 while number1 &lt;= number: number2 = 1 ...
8
2009-02-17T20:22:32Z
[ "python", "loops", "nested" ]
What is wrong with my nested loops in Python?
558,539
<p>How do I make nested loops in Python (version 3.0)?</p> <p>I am trying to get the following loops to show me the products of two numbers:</p> <pre><code>def PrintProductsBelowNumber(number): number1 = 1 number2 = 1 while number1 &lt;= number: while number2 &lt;= number: print(number...
0
2009-02-17T20:19:26Z
558,554
<p><code>number2</code> only gets initialized once, you need to re-initialize it for each iteration of the inner loop. However, this code is very C-like and not very Pythonic. The better way to do it would be to use the <code>for number in range(n)</code> construct:</p> <pre><code>def PrintProductsBelowNumber(number...
14
2009-02-17T20:22:58Z
[ "python", "loops", "nested" ]
What is wrong with my nested loops in Python?
558,539
<p>How do I make nested loops in Python (version 3.0)?</p> <p>I am trying to get the following loops to show me the products of two numbers:</p> <pre><code>def PrintProductsBelowNumber(number): number1 = 1 number2 = 1 while number1 &lt;= number: while number2 &lt;= number: print(number...
0
2009-02-17T20:19:26Z
558,891
<p>You could modify Adam's solution with a list comprehension:</p> <pre><code>def PrintProductsBelowNumber(number): results = [(i, j, i * j) for i in range(1, number + 1) for j in range(1, number + 1)] for number1, number2, result in results: print(number1, "*", number2,...
0
2009-02-17T21:54:59Z
[ "python", "loops", "nested" ]
Detect script start up from command prompt or "double click" on Windows
558,776
<p>Is is possible to detect if a Python script was started from the command prompt or by a user "double clicking" a .py file in the file explorer on Windows?</p>
4
2009-02-17T21:20:24Z
558,804
<p>The command-prompt started script has a parent process named <code>cmd.exe</code> (or a non-existent process, in case the console has been closed in the mean time). </p> <p>The doubleclick-started script should have a parent process named <code>explorer.exe</code>.</p>
3
2009-02-17T21:26:13Z
[ "python", "windows" ]
Detect script start up from command prompt or "double click" on Windows
558,776
<p>Is is possible to detect if a Python script was started from the command prompt or by a user "double clicking" a .py file in the file explorer on Windows?</p>
4
2009-02-17T21:20:24Z
558,808
<p>Good question. One thing you could do is create a shortcut to the script in Windows, and pass arguments (using the shortcut's Target property) that would denote the script was launched by double-clicking (in this case, a shortcut).</p>
2
2009-02-17T21:26:57Z
[ "python", "windows" ]
Detect script start up from command prompt or "double click" on Windows
558,776
<p>Is is possible to detect if a Python script was started from the command prompt or by a user "double clicking" a .py file in the file explorer on Windows?</p>
4
2009-02-17T21:20:24Z
573,426
<p>Here is an example of how to obtain the parent process id and name of the current running script. As suggested by <a href="http://stackoverflow.com/users/18771/tomalak">Tomalak</a> this can be used to detect if the script was started from the command prompt or by double clicking in explorer.</p> <pre><code>import w...
3
2009-02-21T17:27:56Z
[ "python", "windows" ]
Detect script start up from command prompt or "double click" on Windows
558,776
<p>Is is possible to detect if a Python script was started from the command prompt or by a user "double clicking" a .py file in the file explorer on Windows?</p>
4
2009-02-17T21:20:24Z
14,394,730
<p>If running from the command line there is an extra environment variable 'PROMPT' defined.</p> <p>This script will pause if clicked from the explorer and not pause if run from the command line: </p> <pre><code>import os print 'Hello, world!' if not 'PROMPT' in os.environ: raw_input() </code></pre> <p>Tested ...
4
2013-01-18T08:05:45Z
[ "python", "windows" ]