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
multiprocessing Pool hangs when there is a exception in any of the thread
2,246,384
<p>I am new to Python and trying a multiprocessing.pool program to process files, it works fine as long as there are no exceptions. If any of the thread/process gets an exception the whole program waits for the thread </p> <p>snippet of the code:</p> <pre><code>cp = ConfigParser.ConfigParser() cp.read(gdbini) for tab...
6
2010-02-11T17:46:02Z
6,070,242
<p>I had the same issue. It happens when a worker process raises a <strong>user</strong> exception which has a custom constructor. Make sure your exception (ConfigParser.NoOptionError in that case) initializes the base exception with <strong>exactly</strong> two arguments:</p> <pre><code>class NoOptionError(ValueError...
0
2011-05-20T09:55:32Z
[ "python", "exception", "multiprocessing", "pool", "hang" ]
multiprocessing Pool hangs when there is a exception in any of the thread
2,246,384
<p>I am new to Python and trying a multiprocessing.pool program to process files, it works fine as long as there are no exceptions. If any of the thread/process gets an exception the whole program waits for the thread </p> <p>snippet of the code:</p> <pre><code>cp = ConfigParser.ConfigParser() cp.read(gdbini) for tab...
6
2010-02-11T17:46:02Z
8,974,858
<p>In Python 3.2+ this works as expected. For Python 2, this bug was fixed in r74545 and will be available in Python 2.7.3. In the mean time, you can use the <code>configparser</code> library which is a backport of the configparser from 3.2+. <a href="http://pypi.python.org/pypi/configparser" rel="nofollow">Check it ou...
2
2012-01-23T16:18:04Z
[ "python", "exception", "multiprocessing", "pool", "hang" ]
boolean text search in python
2,246,428
<p>i'm looking for an existing module(s) which enabled me to write basic boolean queries for matching and searching texts, WITHOUT writing my own parser etc.</p> <p>for example,</p> <pre><code>president AND (ronald OR (george NOT bush)) </code></pre> <p>would match TRUE against "the president ronald ragen" "the pres...
8
2010-02-11T17:53:04Z
2,246,526
<p>It would be pretty lucky to find a pre-existing library that happens to be ready to parse the example expression that you provided. I recommend making your expression format a bit more machine readable, while retaining all of its clarity. A Lisp S-expression (which uses prefix notation) is compact and clear:</p> <p...
1
2010-02-11T18:05:51Z
[ "python", "full-text-search", "boolean" ]
boolean text search in python
2,246,428
<p>i'm looking for an existing module(s) which enabled me to write basic boolean queries for matching and searching texts, WITHOUT writing my own parser etc.</p> <p>for example,</p> <pre><code>president AND (ronald OR (george NOT bush)) </code></pre> <p>would match TRUE against "the president ronald ragen" "the pres...
8
2010-02-11T17:53:04Z
2,246,535
<p>You might want to take a look at the <a href="http://pyparsing.wikispaces.com/file/view/simpleBool.py" rel="nofollow">simpleBool.py</a> code on <a href="http://pyparsing.wikispaces.com/Examples?f=print" rel="nofollow">this page</a> that uses the pyparsing module. Otherwise, here's some simple code I wrote.</p> <p>T...
1
2010-02-11T18:07:20Z
[ "python", "full-text-search", "boolean" ]
boolean text search in python
2,246,428
<p>i'm looking for an existing module(s) which enabled me to write basic boolean queries for matching and searching texts, WITHOUT writing my own parser etc.</p> <p>for example,</p> <pre><code>president AND (ronald OR (george NOT bush)) </code></pre> <p>would match TRUE against "the president ronald ragen" "the pres...
8
2010-02-11T17:53:04Z
2,246,685
<p>I use <a href="http://sphinxsearch.com/" rel="nofollow">sphinx for full text search</a> from python in my website. It has a simple syntax that supports <a href="http://sphinxsearch.com/docs/manual-0.9.9.html#boolean-syntax" rel="nofollow">boolean matchings</a>, but with operators, not words. For example, your query ...
1
2010-02-11T18:29:54Z
[ "python", "full-text-search", "boolean" ]
PyScripter - change highlighting options/color scheme Python
2,246,710
<p>Just wondering if anyone else is using PyScripter as a Python editing app.</p> <p>I've been runnign my python IDLE in a black background and now find the default white of PyScripter to be blinding. </p> <p>For the life of me I can't find the menu to change the "highlighting" portion of the program (where you open ...
5
2010-02-11T18:31:38Z
2,246,761
<p>Tools > options > editor options. Not being able to find these things really do irk me. </p>
4
2010-02-11T18:38:23Z
[ "python", "syntax-highlighting", "pyscripter" ]
PyScripter - change highlighting options/color scheme Python
2,246,710
<p>Just wondering if anyone else is using PyScripter as a Python editing app.</p> <p>I've been runnign my python IDLE in a black background and now find the default white of PyScripter to be blinding. </p> <p>For the life of me I can't find the menu to change the "highlighting" portion of the program (where you open ...
5
2010-02-11T18:31:38Z
33,596,106
<p>right click on the editor pane, choose editor options, syntax colors and then change the 'space' color to black. You then have to change all the other syntax color options so that you can see them again though!</p>
0
2015-11-08T16:22:23Z
[ "python", "syntax-highlighting", "pyscripter" ]
Django, template context processors
2,246,725
<p>I have a weird problem, I want to add a global query using context processors. This is how I did it by <a href="http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/">following</a>:</p> <p>made a processor.py in my app as such:</p> <pre><code>from myproject.myapp.models import Foo def...
57
2010-02-11T18:34:03Z
2,246,742
<p>When you specify this:</p> <pre><code>TEMPLATE_CONTEXT_PROCESSORS = ('myapp.processor.foos',) </code></pre> <p>In your settings file, you are overriding the Django's <a href="https://docs.djangoproject.com/en/1.9/ref/settings/#template-context-processors" rel="nofollow">default context processors</a>. In order to ...
50
2010-02-11T18:35:40Z
[ "python", "django", "django-templates" ]
Django, template context processors
2,246,725
<p>I have a weird problem, I want to add a global query using context processors. This is how I did it by <a href="http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/">following</a>:</p> <p>made a processor.py in my app as such:</p> <pre><code>from myproject.myapp.models import Foo def...
57
2010-02-11T18:34:03Z
6,402,129
<p>Here what worked for me for Django 1.3 </p> <pre><code>TEMPLATE_CONTEXT_PROCESSORS = ( "django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.static", ...
6
2011-06-19T11:38:27Z
[ "python", "django", "django-templates" ]
Django, template context processors
2,246,725
<p>I have a weird problem, I want to add a global query using context processors. This is how I did it by <a href="http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/">following</a>:</p> <p>made a processor.py in my app as such:</p> <pre><code>from myproject.myapp.models import Foo def...
57
2010-02-11T18:34:03Z
9,233,283
<p>You need to add the default values of TEMPLATE_CONTEXT_PROCESSORS. However, instead of hard-coding those values, which will be tied to a specific version of Django, you can append your context processor to the default values by the following:</p> <pre><code>from django.conf import global_settings TEMPLATE_CONTEXT_...
170
2012-02-10T19:02:22Z
[ "python", "django", "django-templates" ]
app-engine (python) Modeling relationships, am I doing it wrong?
2,246,727
<p>Using the following models I am trying to figure out a way to generate a news feed of sorts so that when a user logs in they are presented with a list of upcoming events for bars that they choose to follow. Will I be able to query something like “SELECT * FROM Barevent WHERE parent_bar IN UserprofileInstance.follo...
0
2010-02-11T18:34:04Z
2,246,915
<p>There are a lot of ways to do GAE queries but I don't see why yours wouldn't work. If you had a specific Barprofile (B) then I think you could (in Python) do;</p> <pre><code> query = db.GqlQuery("SELECT * FROM Barevent WHERE parent_bar = :1, B.b_user) day = query.get() </code></pre>...
0
2010-02-11T18:59:06Z
[ "python", "google-app-engine", "gae-datastore" ]
app-engine (python) Modeling relationships, am I doing it wrong?
2,246,727
<p>Using the following models I am trying to figure out a way to generate a news feed of sorts so that when a user logs in they are presented with a list of upcoming events for bars that they choose to follow. Will I be able to query something like “SELECT * FROM Barevent WHERE parent_bar IN UserprofileInstance.follo...
0
2010-02-11T18:34:04Z
2,247,157
<p>Your model and your query should work fine, and it would not be inefficient. The one thing that you will want to keep in mind is that if Barprofile entities are deleted, you may want to manually remove their keys from the <strong>following</strong> property of each Userprofile. Having an orphaned Barprofile referenc...
1
2010-02-11T19:34:17Z
[ "python", "google-app-engine", "gae-datastore" ]
app-engine (python) Modeling relationships, am I doing it wrong?
2,246,727
<p>Using the following models I am trying to figure out a way to generate a news feed of sorts so that when a user logs in they are presented with a list of upcoming events for bars that they choose to follow. Will I be able to query something like “SELECT * FROM Barevent WHERE parent_bar IN UserprofileInstance.follo...
0
2010-02-11T18:34:04Z
2,250,786
<p>The structure you're describing will work, but bear in mind that the 'IN' operator requires executing one query for each item in the list - so it could result in a lot of queries.</p> <p>However, what you're dealing with is a 'scatter-gather' problem akin to Twitter, so you don't have much choice - you either gathe...
1
2010-02-12T09:34:00Z
[ "python", "google-app-engine", "gae-datastore" ]
PyScripter - cannot termiate Run with KeyboardInterrupt
2,246,885
<p>I write alot of small apps where I use </p> <pre><code>try: print "always does this until I Ctrl+C" Except KeyboardInterrupt: print "finish program" </code></pre> <p>I've just began to move away from using IDLE and booted up PyScripter. However CTRL+C no longer works. Is it possible to still send in a <cod...
3
2010-02-11T18:54:08Z
2,246,949
<p>I keep answering my own questions, but I believe they are valid..</p> <p>The PyScripter google group has one implementation where they import a progress bar and kill it, simulating an interrupt. however, this is not the same as a keyboard interrupt. Looks like i'm out of luck until a new implementation. </p> <p>Ha...
0
2010-02-11T19:03:48Z
[ "python", "pyscripter", "keyboardinterrupt" ]
PyScripter - cannot termiate Run with KeyboardInterrupt
2,246,885
<p>I write alot of small apps where I use </p> <pre><code>try: print "always does this until I Ctrl+C" Except KeyboardInterrupt: print "finish program" </code></pre> <p>I've just began to move away from using IDLE and booted up PyScripter. However CTRL+C no longer works. Is it possible to still send in a <cod...
3
2010-02-11T18:54:08Z
4,129,618
<p>In PyScripter if you just want to terminate a running program you can always re-initialize the remote engine:</p> <ul> <li>Application Run Menu > Python Engine > Reinitialize Python Engine or </li> <li>Interpreter context menu > Python Engine > Reinitialize Python Engine or</li> <li>Keyboard shortcut CTRL-F2</li> <...
5
2010-11-09T01:12:07Z
[ "python", "pyscripter", "keyboardinterrupt" ]
How can I filter a pcap file by specific protocol using python?
2,247,140
<p>I have some pcap files and I want to filter by protocol, i.e., if I want to filter by HTTP protocol, anything but HTTP packets will remain in the pcap file. </p> <p>There is a tool called <a href="http://www.opendpi.org/">openDPI</a>, and it's perfect for what I need, but there is no wrapper for python language.</...
10
2010-02-11T19:31:32Z
2,247,243
<p>Try <a href="http://pylibpcap.sourceforge.net/" rel="nofollow">pylibpcap</a>.</p>
2
2010-02-11T19:48:18Z
[ "python", "filter", "pcap", "scapy" ]
How can I filter a pcap file by specific protocol using python?
2,247,140
<p>I have some pcap files and I want to filter by protocol, i.e., if I want to filter by HTTP protocol, anything but HTTP packets will remain in the pcap file. </p> <p>There is a tool called <a href="http://www.opendpi.org/">openDPI</a>, and it's perfect for what I need, but there is no wrapper for python language.</...
10
2010-02-11T19:31:32Z
2,248,149
<p>maybe this can help <a href="http://www.secdev.org/projects/scapy/">Scapy</a>?</p>
9
2010-02-11T22:12:51Z
[ "python", "filter", "pcap", "scapy" ]
How can I filter a pcap file by specific protocol using python?
2,247,140
<p>I have some pcap files and I want to filter by protocol, i.e., if I want to filter by HTTP protocol, anything but HTTP packets will remain in the pcap file. </p> <p>There is a tool called <a href="http://www.opendpi.org/">openDPI</a>, and it's perfect for what I need, but there is no wrapper for python language.</...
10
2010-02-11T19:31:32Z
2,250,686
<p>Something along the lines of</p> <pre> from pcapy import open_offline from impacket.ImpactDecoder import EthDecoder from impacket.ImpactPacket import IP, TCP, UDP, ICMP decoder = EthDecoder() def callback(jdr, data): packet = decoder.decode(data) child = packet.child() if isinstance(child, IP): ...
3
2010-02-12T09:15:06Z
[ "python", "filter", "pcap", "scapy" ]
How can I filter a pcap file by specific protocol using python?
2,247,140
<p>I have some pcap files and I want to filter by protocol, i.e., if I want to filter by HTTP protocol, anything but HTTP packets will remain in the pcap file. </p> <p>There is a tool called <a href="http://www.opendpi.org/">openDPI</a>, and it's perfect for what I need, but there is no wrapper for python language.</...
10
2010-02-11T19:31:32Z
4,564,628
<p>A quick example using Scapy, since I just wrote one:</p> <pre><code>pkts = rdpcap('packets.pcap') ports = [80, 25] filtered = (pkt for pkt in pkts if TCP in pkt and (pkt[TCP].sport in ports or pkt[TCP].dport in ports)) wrpcap('filtered.pcap', filtered) </code></pre> <p>That will filter out packets that are...
11
2010-12-30T17:09:52Z
[ "python", "filter", "pcap", "scapy" ]
How can I filter a pcap file by specific protocol using python?
2,247,140
<p>I have some pcap files and I want to filter by protocol, i.e., if I want to filter by HTTP protocol, anything but HTTP packets will remain in the pcap file. </p> <p>There is a tool called <a href="http://www.opendpi.org/">openDPI</a>, and it's perfect for what I need, but there is no wrapper for python language.</...
10
2010-02-11T19:31:32Z
6,081,280
<p>to filter in/out a specific protocol you have to do a per packet analysis otherwise you could miss some http traffic on a non-conventional port that is flowing in your network. of course if you want a loose system, you could check just for source and destination port number but that wont give you exact results. you ...
1
2011-05-21T11:03:39Z
[ "python", "filter", "pcap", "scapy" ]
How can I filter a pcap file by specific protocol using python?
2,247,140
<p>I have some pcap files and I want to filter by protocol, i.e., if I want to filter by HTTP protocol, anything but HTTP packets will remain in the pcap file. </p> <p>There is a tool called <a href="http://www.opendpi.org/">openDPI</a>, and it's perfect for what I need, but there is no wrapper for python language.</...
10
2010-02-11T19:31:32Z
6,630,608
<p>I know this is a super-old question, but I just ran across it thought I'd provide <strong><em>my</em></strong> answer. This is a problem I've encountered several times over the years, and I keep finding myself falling back to <a href="http://code.google.com/p/dpkt/">dpkt</a>. Originally from the very capable <a h...
13
2011-07-08T21:17:23Z
[ "python", "filter", "pcap", "scapy" ]
How can I filter a pcap file by specific protocol using python?
2,247,140
<p>I have some pcap files and I want to filter by protocol, i.e., if I want to filter by HTTP protocol, anything but HTTP packets will remain in the pcap file. </p> <p>There is a tool called <a href="http://www.opendpi.org/">openDPI</a>, and it's perfect for what I need, but there is no wrapper for python language.</...
10
2010-02-11T19:31:32Z
12,196,219
<p>I have tried the same using @nmichaels method, but it becomes cumbersome when I want to iterate it over multiple protocols. I tried finding ways to read the .pcap file and then filter it but found no help. Basically, when one reads a .pcap file there is no function in Scapy which allows to filter these packets, on t...
0
2012-08-30T11:48:49Z
[ "python", "filter", "pcap", "scapy" ]
How can I filter a pcap file by specific protocol using python?
2,247,140
<p>I have some pcap files and I want to filter by protocol, i.e., if I want to filter by HTTP protocol, anything but HTTP packets will remain in the pcap file. </p> <p>There is a tool called <a href="http://www.opendpi.org/">openDPI</a>, and it's perfect for what I need, but there is no wrapper for python language.</...
10
2010-02-11T19:31:32Z
35,591,881
<p>sniff supports a offline option wherein you can provide the pcap file as input. This way you can use the filtering advantages of sniff command on pcap file.</p> <pre><code>&gt;&gt;&gt; packets = sniff(offline='mypackets.pcap') &gt;&gt;&gt; &gt;&gt;&gt; packets &lt;Sniffed: TCP:17 UDP:0 ICMP:0 Other:0&gt; </code></p...
0
2016-02-24T01:59:40Z
[ "python", "filter", "pcap", "scapy" ]
Associative Matrices?
2,247,197
<p>I'm working on a project where I need to store a matrix of numbers indexed by two string keys. The matrix is not jagged, i.e. if a column key exists for any row then it should exist for all rows. Similarly, if a row key exists for any column then it should exist for all columns.</p> <p>The obvious way to express ...
6
2010-02-11T19:39:15Z
2,247,284
<p>Why not just use a standard matrix, but then have two dictionaries - one that converts the row keys to row indices and one that converts the columns keys to columns indices. You could make your own structure that would work this way fairly easily I think. You just make a class that contains the matrix and the two di...
2
2010-02-11T19:53:27Z
[ "python", "data-structures", "matrix", "d", "associative-array" ]
Associative Matrices?
2,247,197
<p>I'm working on a project where I need to store a matrix of numbers indexed by two string keys. The matrix is not jagged, i.e. if a column key exists for any row then it should exist for all rows. Similarly, if a row key exists for any column then it should exist for all columns.</p> <p>The obvious way to express ...
6
2010-02-11T19:39:15Z
2,247,323
<p>In Python you could have a dict indexed by a tuple of two strings, e.g</p> <pre><code>&gt;&gt;&gt; d = {} &gt;&gt;&gt; d["foo","bar"] = 10 &gt;&gt;&gt; d {('foo', 'bar'): 10} </code></pre> <p>I am not sure what "enforce non-jaggedness" means for you, but you could either use a defaultdict to return a default value...
0
2010-02-11T20:00:09Z
[ "python", "data-structures", "matrix", "d", "associative-array" ]
Associative Matrices?
2,247,197
<p>I'm working on a project where I need to store a matrix of numbers indexed by two string keys. The matrix is not jagged, i.e. if a column key exists for any row then it should exist for all rows. Similarly, if a row key exists for any column then it should exist for all columns.</p> <p>The obvious way to express ...
6
2010-02-11T19:39:15Z
2,247,635
<p>the <a href="http://larry.sourceforge.net/" rel="nofollow">larry</a> module for python was recently released. i believe it does what you want.</p>
0
2010-02-11T20:54:16Z
[ "python", "data-structures", "matrix", "d", "associative-array" ]
Python returning the wrong length of string when using special characters
2,247,205
<p>I have a string ë́aúlt that I want to get the length of a manipulate based on character positions and so on. The problem is that the first ë́ is being counted twice, or I guess ë is in position 0 and ´ is in position 1.</p> <p>Is there any possible way in Python to have a character like ë́ be represented a...
7
2010-02-11T19:40:36Z
2,247,236
<p>UTF-8 is an unicode encoding which uses more than one byte for special characters. If you don't want the length of the encoded string, simple decode it and use <code>len()</code> on the <code>unicode</code> object (and not the <code>str</code> object!).</p> <p>Here are some examples:</p> <pre><code>&gt;&gt;&gt; # ...
16
2010-02-11T19:47:05Z
[ "python", "character-encoding" ]
Python returning the wrong length of string when using special characters
2,247,205
<p>I have a string ë́aúlt that I want to get the length of a manipulate based on character positions and so on. The problem is that the first ë́ is being counted twice, or I guess ë is in position 0 and ´ is in position 1.</p> <p>Is there any possible way in Python to have a character like ë́ be represented a...
7
2010-02-11T19:40:36Z
2,247,249
<p>The best you can do is to use <a href="http://docs.python.org/library/unicodedata.html#unicodedata.normalize" rel="nofollow"><code>unicodedata.normalize()</code></a> to decompose the character and then filter out the accents.</p> <p>Don't forget to use <code>unicode</code> and unicode literals in your code.</p>
1
2010-02-11T19:49:21Z
[ "python", "character-encoding" ]
Python returning the wrong length of string when using special characters
2,247,205
<p>I have a string ë́aúlt that I want to get the length of a manipulate based on character positions and so on. The problem is that the first ë́ is being counted twice, or I guess ë is in position 0 and ´ is in position 1.</p> <p>Is there any possible way in Python to have a character like ë́ be represented a...
7
2010-02-11T19:40:36Z
2,247,287
<blockquote> <p>The problem is that the first ë́ is being counted twice, or I guess ë is in position 0 and ´ is in position 1.</p> </blockquote> <p>Yes. That's how code points are defined by Unicode. In general, you can ask Python to convert a letter and a separate ‘combining’ diacritical mark like U+0301 CO...
4
2010-02-11T19:53:49Z
[ "python", "character-encoding" ]
Python returning the wrong length of string when using special characters
2,247,205
<p>I have a string ë́aúlt that I want to get the length of a manipulate based on character positions and so on. The problem is that the first ë́ is being counted twice, or I guess ë is in position 0 and ´ is in position 1.</p> <p>Is there any possible way in Python to have a character like ë́ be represented a...
7
2010-02-11T19:40:36Z
2,248,231
<p>which Python version are you using? Python 3.1 doesn't have this issue.</p> <pre><code>&gt;&gt;&gt; print(len("ë́aúlt")) 6 </code></pre> <p>Regards Djoudi</p>
0
2010-02-11T22:24:14Z
[ "python", "character-encoding" ]
Python returning the wrong length of string when using special characters
2,247,205
<p>I have a string ë́aúlt that I want to get the length of a manipulate based on character positions and so on. The problem is that the first ë́ is being counted twice, or I guess ë is in position 0 and ´ is in position 1.</p> <p>Is there any possible way in Python to have a character like ë́ be represented a...
7
2010-02-11T19:40:36Z
2,250,722
<p>You said: I have a string ë́aúlt that I want to get the length of a manipulate based on character positions and so on. The problem is that the first ë́ is being counted twice, or I guess ë is in position 0 and ´ is in position 1.</p> <p>The first step in working on any Unicode problem is to know exactly what...
0
2010-02-12T09:21:30Z
[ "python", "character-encoding" ]
stream socket send/receive broadcast messages?
2,247,228
<p>I browsed the python socket docs and google for two days but I did not find any answer. Yeah I am a network programming newbie :)</p> <p>I would like to implement some LAN chatting system with specific function for our needs. I am at the very beginning. I was able to implement a client-server model where the client...
6
2010-02-11T19:45:50Z
2,247,237
<p>The broadcast is defined by the destination address.</p> <p>For example if your own ip is 192.168.1.2, the broadcast address would be 192.168.1.255 (in most cases)</p> <p>It is not related directly to python and will probably not be in its documentation. You are searching for network "general" knowledge, to a leve...
3
2010-02-11T19:47:18Z
[ "python" ]
python bisect, it is possible to work with descending sorted lists?
2,247,394
<p>How can I use bisect module on lists that are sorted descending? eg.</p> <pre><code>import bisect x = [1.0,2.0,3.0,4.0] # normal, ascending bisect.insort(x,2.5) # --&gt; x is [1.0, 2.0, 2.5, 3.0, 4.0] ok, works fine for ascending list # however x = [1.0,2.0,3.0,4.0] x.reverse() # --&gt; x is [4.0...
13
2010-02-11T20:13:23Z
2,247,431
<p>I've never used to the bisect package. But if it only works in ascending order and you're always keeping your list sorted (whether ascending or descending) then you could simply sort beforehand and then invert (if you want to keep it descending).</p> <pre><code>x.sort() bisect.insort(x,2.5) x.reverse() </code></pre...
0
2010-02-11T20:18:14Z
[ "python" ]
python bisect, it is possible to work with descending sorted lists?
2,247,394
<p>How can I use bisect module on lists that are sorted descending? eg.</p> <pre><code>import bisect x = [1.0,2.0,3.0,4.0] # normal, ascending bisect.insort(x,2.5) # --&gt; x is [1.0, 2.0, 2.5, 3.0, 4.0] ok, works fine for ascending list # however x = [1.0,2.0,3.0,4.0] x.reverse() # --&gt; x is [4.0...
13
2010-02-11T20:13:23Z
2,247,433
<p>Probably the easiest thing is to borrow the code from the library and make your own version</p> <pre><code>def reverse_insort(a, x, lo=0, hi=None): """Insert item x in list a, and keep it reverse-sorted assuming a is reverse-sorted. If x is already in a, insert it to the right of the rightmost x. ...
8
2010-02-11T20:18:16Z
[ "python" ]
python bisect, it is possible to work with descending sorted lists?
2,247,394
<p>How can I use bisect module on lists that are sorted descending? eg.</p> <pre><code>import bisect x = [1.0,2.0,3.0,4.0] # normal, ascending bisect.insort(x,2.5) # --&gt; x is [1.0, 2.0, 2.5, 3.0, 4.0] ok, works fine for ascending list # however x = [1.0,2.0,3.0,4.0] x.reverse() # --&gt; x is [4.0...
13
2010-02-11T20:13:23Z
2,247,466
<p>From the documentation:</p> <blockquote> <p>Unlike the sorted() function, it does not make sense for the bisect() functions to have key or reversed arguments because that would lead to an inefficent design (successive calls to bisect functions would not “remember” all of the previous key lookup...
1
2010-02-11T20:24:01Z
[ "python" ]
python bisect, it is possible to work with descending sorted lists?
2,247,394
<p>How can I use bisect module on lists that are sorted descending? eg.</p> <pre><code>import bisect x = [1.0,2.0,3.0,4.0] # normal, ascending bisect.insort(x,2.5) # --&gt; x is [1.0, 2.0, 2.5, 3.0, 4.0] ok, works fine for ascending list # however x = [1.0,2.0,3.0,4.0] x.reverse() # --&gt; x is [4.0...
13
2010-02-11T20:13:23Z
6,165,607
<p>I had the same problem and since when I used ordered list.</p> <p>I ended up with solution where I kept original list always in ascending order and just used reversed iterator when I needed to have descending order values.</p> <p>This might not work with your problem...</p>
1
2011-05-29T02:27:09Z
[ "python" ]
python bisect, it is possible to work with descending sorted lists?
2,247,394
<p>How can I use bisect module on lists that are sorted descending? eg.</p> <pre><code>import bisect x = [1.0,2.0,3.0,4.0] # normal, ascending bisect.insort(x,2.5) # --&gt; x is [1.0, 2.0, 2.5, 3.0, 4.0] ok, works fine for ascending list # however x = [1.0,2.0,3.0,4.0] x.reverse() # --&gt; x is [4.0...
13
2010-02-11T20:13:23Z
24,414,594
<p>Hopefully the "key" argument will be added to bisect module functions one day (see: <a href="http://bugs.python.org/issue4356" rel="nofollow">http://bugs.python.org/issue4356</a>). Unfortunately it's not possible without some kind of workaround at the moment (Python version &lt; 3.4).</p> <p>One possible workaround...
0
2014-06-25T17:01:24Z
[ "python" ]
python bisect, it is possible to work with descending sorted lists?
2,247,394
<p>How can I use bisect module on lists that are sorted descending? eg.</p> <pre><code>import bisect x = [1.0,2.0,3.0,4.0] # normal, ascending bisect.insort(x,2.5) # --&gt; x is [1.0, 2.0, 2.5, 3.0, 4.0] ok, works fine for ascending list # however x = [1.0,2.0,3.0,4.0] x.reverse() # --&gt; x is [4.0...
13
2010-02-11T20:13:23Z
37,737,003
<p>Slightly updated <code>bisect</code> library code:</p> <pre><code>def reverse_bisect_right(a, x, lo=0, hi=None): """Return the index where to insert item x in list a, assuming a is sorted in descending order. The return value i is such that all e in a[:i] have e &gt;= x, and all e in a[i:] have e &lt; ...
0
2016-06-09T22:08:14Z
[ "python" ]
Python best way to check for existing key
2,247,412
<p>Which is the more efficient/faster/better way to check if a key exists?</p> <pre><code>if 'subject' in request.POST: subject = request.POST['subject'] else: // handle error </code></pre> <p>OR</p> <pre><code>try: subject = request.POST['subject'] except KeyError: // handle error </code></pre>
9
2010-02-11T20:15:27Z
2,247,430
<pre><code>subject = request.POST.get("subject") if subject is None: ... </code></pre> <p>:)</p>
-2
2010-02-11T20:18:11Z
[ "python" ]
Python best way to check for existing key
2,247,412
<p>Which is the more efficient/faster/better way to check if a key exists?</p> <pre><code>if 'subject' in request.POST: subject = request.POST['subject'] else: // handle error </code></pre> <p>OR</p> <pre><code>try: subject = request.POST['subject'] except KeyError: // handle error </code></pre>
9
2010-02-11T20:15:27Z
2,247,436
<p>I think it depends on whether 'subject' not being in POST is actually an exception. If it is not supposed to happen but you are just being extra careful, then your second method would I assume be more efficient and quicker. However if you are using the check to do 1 thing or another then it is not appropriate to u...
1
2010-02-11T20:18:36Z
[ "python" ]
Python best way to check for existing key
2,247,412
<p>Which is the more efficient/faster/better way to check if a key exists?</p> <pre><code>if 'subject' in request.POST: subject = request.POST['subject'] else: // handle error </code></pre> <p>OR</p> <pre><code>try: subject = request.POST['subject'] except KeyError: // handle error </code></pre>
9
2010-02-11T20:15:27Z
2,247,439
<p>The second will fail with <code>collections.defaultdict</code>, and the exception will cause a small performance bump. Other than there there is no real difference between the two.</p>
2
2010-02-11T20:18:48Z
[ "python" ]
Python best way to check for existing key
2,247,412
<p>Which is the more efficient/faster/better way to check if a key exists?</p> <pre><code>if 'subject' in request.POST: subject = request.POST['subject'] else: // handle error </code></pre> <p>OR</p> <pre><code>try: subject = request.POST['subject'] except KeyError: // handle error </code></pre>
9
2010-02-11T20:15:27Z
2,247,441
<p>Last time I checked, the first one is a few nanoseconds faster. But most phythonistas seem to favor the second one.</p> <p>I think I'm not the only one that want to reserve exceptions for exceptional behavior, so I try to use the first one, reserving the second one when it's invalid not to have the key</p>
2
2010-02-11T20:18:56Z
[ "python" ]
Python best way to check for existing key
2,247,412
<p>Which is the more efficient/faster/better way to check if a key exists?</p> <pre><code>if 'subject' in request.POST: subject = request.POST['subject'] else: // handle error </code></pre> <p>OR</p> <pre><code>try: subject = request.POST['subject'] except KeyError: // handle error </code></pre>
9
2010-02-11T20:15:27Z
2,247,462
<p>The latter (<code>try/except</code>) form is generally the better form. </p> <p><code>try</code> blocks are very cheap but catching an exception can be more expensive. A containment check on a dict tends to be cheap, but not cheaper than nothing. I suspect there will be a balance of efficiency depending on how ofte...
22
2010-02-11T20:22:29Z
[ "python" ]
Python best way to check for existing key
2,247,412
<p>Which is the more efficient/faster/better way to check if a key exists?</p> <pre><code>if 'subject' in request.POST: subject = request.POST['subject'] else: // handle error </code></pre> <p>OR</p> <pre><code>try: subject = request.POST['subject'] except KeyError: // handle error </code></pre>
9
2010-02-11T20:15:27Z
2,247,549
<p>I too like get() you can also specify a default value (other than none) in case that makes sense.</p>
1
2010-02-11T20:38:27Z
[ "python" ]
Python best way to check for existing key
2,247,412
<p>Which is the more efficient/faster/better way to check if a key exists?</p> <pre><code>if 'subject' in request.POST: subject = request.POST['subject'] else: // handle error </code></pre> <p>OR</p> <pre><code>try: subject = request.POST['subject'] except KeyError: // handle error </code></pre>
9
2010-02-11T20:15:27Z
2,248,080
<p><code>dict</code> and many dict-like objects (including Django's <code>HttpRequest</code> you seem to be using) allow passing default value to <code>get()</code>:</p> <pre><code>subject = request.POST.get('subject', '[some_default_subject]') </code></pre> <p>This is preferrable method as it is the shortest and mos...
0
2010-02-11T22:03:55Z
[ "python" ]
Python best way to check for existing key
2,247,412
<p>Which is the more efficient/faster/better way to check if a key exists?</p> <pre><code>if 'subject' in request.POST: subject = request.POST['subject'] else: // handle error </code></pre> <p>OR</p> <pre><code>try: subject = request.POST['subject'] except KeyError: // handle error </code></pre>
9
2010-02-11T20:15:27Z
2,248,365
<p>I use .get() method — it is preferable method.</p> <pre><code>Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import dis &gt;&gt;&gt; def f1(key, d): ... if key in d: ... return...
4
2010-02-11T22:45:42Z
[ "python" ]
"HTTP Error 409: Conflict" when using urllib.request.urlopen()
2,247,418
<p>Under Python 3.1, when trying to run this code: </p> <pre><code>from urllib import request def test(): request.urlopen("http://www.google.com") test() </code></pre> <p>I get an HTTP 409 error. The stack trace is:</p> <pre><code>Traceback (most recent call last): File "C:\Users\Beau\Python\pokescrape.py", ...
1
2010-02-11T20:16:11Z
2,247,838
<p>The HTTP error you're seeing is one the remote end (or the proxy) is giving you. HTTP Error 409 is indeed 'Conflict', which usually means there were conflicting requests being made. If you are indeed using a proxy I would suspect that being the source of the 409, but more debugging would be in order. Either use a to...
1
2010-02-11T21:28:16Z
[ "python", "http", "proxy", "python-3.x" ]
"HTTP Error 409: Conflict" when using urllib.request.urlopen()
2,247,418
<p>Under Python 3.1, when trying to run this code: </p> <pre><code>from urllib import request def test(): request.urlopen("http://www.google.com") test() </code></pre> <p>I get an HTTP 409 error. The stack trace is:</p> <pre><code>Traceback (most recent call last): File "C:\Users\Beau\Python\pokescrape.py", ...
1
2010-02-11T20:16:11Z
2,248,104
<p>It turns out I had to manually set the proxy in-code. I'm assuming this was because I was using an automated proxy script.</p> <p>For anybody with a similar issue, here's the code I used:</p> <pre><code>from urllib import request import random PROXY_URL = "http://wwwcache-{}.lancs.ac.uk:8080/" def setLancsProxy(...
0
2010-02-11T22:06:25Z
[ "python", "http", "proxy", "python-3.x" ]
"HTTP Error 409: Conflict" when using urllib.request.urlopen()
2,247,418
<p>Under Python 3.1, when trying to run this code: </p> <pre><code>from urllib import request def test(): request.urlopen("http://www.google.com") test() </code></pre> <p>I get an HTTP 409 error. The stack trace is:</p> <pre><code>Traceback (most recent call last): File "C:\Users\Beau\Python\pokescrape.py", ...
1
2010-02-11T20:16:11Z
2,330,756
<p>I was running into this problem too (also from Lancaster, as it happens) and found that if I set the environment variable http_proxy, Python would use it. In this case (on Windows) it would be:</p> <pre><code>set http_proxy=http://wwwcache.lancs.ac.uk:8080 </code></pre> <p>and on *nix:</p> <pre><code>export http_...
1
2010-02-25T00:31:17Z
[ "python", "http", "proxy", "python-3.x" ]
How can you access the "calling" object through a RelatedManager in Django?
2,247,508
<p>Say I have a model with a foreign key to a Django Auth user:</p> <pre><code>class Something(models.Model): user = models.ForeignKey(User, related_name='something') </code></pre> <p>I can then access this model through a RelatedManager:</p> <pre><code>u = User.objects.create_user('richardhenry', 'richard@exam...
2
2010-02-11T20:30:09Z
2,247,756
<p>Managers are only directly connected to the model they manage. So in this case, your Manager would be connected to Something, but not directly to User. </p> <p>Also, Managers begin with querysets, not objects, so you'll have to work from there.</p> <p>Keep in mind that to use your custom methods with a RelatedMana...
2
2010-02-11T21:15:29Z
[ "python", "django" ]
Python String Method Conundrum
2,247,600
<p>The following code is supposed to print MyWords after removing SpamWords[0]. However; instead of returning "yes" it instead returns "None". Why is it returning "None"?</p> <pre><code>MyWords = "Spam yes" SpamWords = ["SPAM"] SpamCheckRange = 0 print ((MyWords.upper()).split()).remove(SpamWords[SpamCheckRange]) </co...
3
2010-02-11T20:46:46Z
2,247,616
<p>Because <code>remove</code> is a method that changes the mutable list object it's called on, and returns <code>None</code>.</p> <pre><code>l= MyWords.upper().split() l.remove(SpamWords[SpamCheckRange]) # l is ['YES'] </code></pre> <p>Perhaps you want:</p> <pre><code>&gt;&gt;&gt; [word for word in MyWords.split() ...
8
2010-02-11T20:50:31Z
[ "python", "string", "methods" ]
Python String Method Conundrum
2,247,600
<p>The following code is supposed to print MyWords after removing SpamWords[0]. However; instead of returning "yes" it instead returns "None". Why is it returning "None"?</p> <pre><code>MyWords = "Spam yes" SpamWords = ["SPAM"] SpamCheckRange = 0 print ((MyWords.upper()).split()).remove(SpamWords[SpamCheckRange]) </co...
3
2010-02-11T20:46:46Z
2,247,621
<p><code>remove</code> is a method of <code>list</code> (<code>str.split</code> returns a list), not <code>str</code>. It mutates the original list (removing what you pass) and returns <code>None</code>, <em>not</em> a modified list.</p>
1
2010-02-11T20:51:05Z
[ "python", "string", "methods" ]
Anyone benchmarked virtual machine performance for build servers?
2,247,755
<p>We have been trying to use virtual machines for build servers. Our build servers are all running WinXP32 and we are hosting them on VMWare Server 2.0 running on Ubuntu 9.10. We build a mix of C, C++, python packages, and other various deployment tasks (installers, 7z files, archives, etc). The management using VM...
3
2010-02-11T21:15:24Z
2,248,041
<p>Disk IO is definitely a problem here, you just can't do any significant amount of disk IO activity when you're backing it up with a single spindle. The 32MB cache on a single SATA drive is going to be saturated just by your Host and a couple of Guest OS's ticking over. If you look at the disk queue length counter in...
7
2010-02-11T21:58:59Z
[ "c++", "python", "build", "automation", "vmware" ]
render users' equations in Python
2,247,757
<p>I am a <strong>very</strong> new/inexperienced Python programmer. I teach maths and am trying to create a GUI graph-plotting package suitable for schoolchildren.</p> <p>As well as plotting a graph, I would ideally like to render the equation a user enters [eg. <code>y = (x^2)/3</code>] in a nicely formatted style -...
7
2010-02-11T21:15:36Z
2,247,771
<p>You could look at how <a href="http://lybniz2.sourceforge.net/index.html" rel="nofollow">Lybniz</a> does it. Or you could use Lybniz. Just saying.</p>
8
2010-02-11T21:18:28Z
[ "python", "wxpython", "matplotlib", "equation" ]
render users' equations in Python
2,247,757
<p>I am a <strong>very</strong> new/inexperienced Python programmer. I teach maths and am trying to create a GUI graph-plotting package suitable for schoolchildren.</p> <p>As well as plotting a graph, I would ideally like to render the equation a user enters [eg. <code>y = (x^2)/3</code>] in a nicely formatted style -...
7
2010-02-11T21:15:36Z
2,247,776
<p>I don't <em>know</em> if it will do what you want… But it might be worth looking at <a href="http://scipy.org/" rel="nofollow">Numpy/Scipy/Matplotlib</a>.</p>
0
2010-02-11T21:19:14Z
[ "python", "wxpython", "matplotlib", "equation" ]
render users' equations in Python
2,247,757
<p>I am a <strong>very</strong> new/inexperienced Python programmer. I teach maths and am trying to create a GUI graph-plotting package suitable for schoolchildren.</p> <p>As well as plotting a graph, I would ideally like to render the equation a user enters [eg. <code>y = (x^2)/3</code>] in a nicely formatted style -...
7
2010-02-11T21:15:36Z
2,248,793
<p>Perhaps you could make use of <a href="http://code.google.com/p/sympy/" rel="nofollow">SymPy</a>'s <a href="http://docs.sympy.org/tutorial.html#printing-tutorial" rel="nofollow">printing capabilities</a>.</p>
3
2010-02-12T00:21:02Z
[ "python", "wxpython", "matplotlib", "equation" ]
render users' equations in Python
2,247,757
<p>I am a <strong>very</strong> new/inexperienced Python programmer. I teach maths and am trying to create a GUI graph-plotting package suitable for schoolchildren.</p> <p>As well as plotting a graph, I would ideally like to render the equation a user enters [eg. <code>y = (x^2)/3</code>] in a nicely formatted style -...
7
2010-02-11T21:15:36Z
2,251,572
<p>I am not sure whether you intend to have your students build this plotting tool in python <strong><em>or</em></strong> you want to build the tool yourself so they can use it to e.g., visualize changes in function behavior as inputs are varied. If the latter, then perhaps it's not important which language the tool is...
2
2010-02-12T11:59:27Z
[ "python", "wxpython", "matplotlib", "equation" ]
Tcl/Tk Tkinter version 8.4 and 8.5 conflict on Mac Os X 10.4.11 with python 2.6.4
2,247,971
<p>I am having trouble getting Tkinter up and runnning in order to install matplot lib.</p> <p>I am running Mac OS X 10.4.11, and just installed Python 2.6.4 . </p> <p>After several other fights, one remaining battle for me to get matlotlib installed is to have a working version of Tkinter, although there are several...
1
2010-02-11T21:48:25Z
2,336,766
<p>I think the important point from previous solutions proposed was that Python, upon install, detects the correct version and location of Tk. I assume you installed Tk after installing Python. This problem was solved on my machine when I reinstalled Python2.6 using the .dmg installer. I didn't need to rebuild or anyth...
2
2010-02-25T18:59:57Z
[ "python", "osx", "tkinter", "tk" ]
running BLAST (bl2seq) without creating sequence files
2,248,016
<p>I have a script that performs BLAST queries (bl2seq)</p> <p>The script works like this:</p> <blockquote> <ol> <li>Get sequence a, sequence b</li> <li>write sequence a to filea</li> <li>write sequence b to fileb</li> <li>run command 'bl2seq -i filea -j fileb -n blastn'</li> <li>get output from STDOUT, p...
5
2010-02-11T21:55:57Z
2,248,135
<p>Is this the <code>bl2seq</code> program from <a href="http://search.cpan.org/~birney/bioperl-run-1.4/Bio/Tools/Run/PiseApplication/bl2seq.pm" rel="nofollow">BioPerl</a>? If so, it doesn't look like you can do piping to it. You can, however, code your own hack using <code>Bio::Tools::Run::AnalysisFactory::Pise</code>...
1
2010-02-11T22:10:30Z
[ "python", "perl", "unix", "shell", "bioinformatics" ]
running BLAST (bl2seq) without creating sequence files
2,248,016
<p>I have a script that performs BLAST queries (bl2seq)</p> <p>The script works like this:</p> <blockquote> <ol> <li>Get sequence a, sequence b</li> <li>write sequence a to filea</li> <li>write sequence b to fileb</li> <li>run command 'bl2seq -i filea -j fileb -n blastn'</li> <li>get output from STDOUT, p...
5
2010-02-11T21:55:57Z
2,248,368
<p>Depending on what OS you're running on, you may be able to use something like <a href="http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/process-sub.html" rel="nofollow">bash's process substitution</a>. I'm not sure how you'd set that up in Python, but you're basically using a named pipe (or name...
4
2010-02-11T22:45:54Z
[ "python", "perl", "unix", "shell", "bioinformatics" ]
running BLAST (bl2seq) without creating sequence files
2,248,016
<p>I have a script that performs BLAST queries (bl2seq)</p> <p>The script works like this:</p> <blockquote> <ol> <li>Get sequence a, sequence b</li> <li>write sequence a to filea</li> <li>write sequence b to fileb</li> <li>run command 'bl2seq -i filea -j fileb -n blastn'</li> <li>get output from STDOUT, p...
5
2010-02-11T21:55:57Z
2,248,965
<p>How do you know bl2seq does not support piping.? By the way, pipes is an OS feature, not the program. If your bl2seq program outputs something, whether to STDOUT or to a file, you should be able to parse the output. Check the help file of bl2seq for options to output to file as well, eg <code>-o</code> option. Then ...
1
2010-02-12T01:01:02Z
[ "python", "perl", "unix", "shell", "bioinformatics" ]
running BLAST (bl2seq) without creating sequence files
2,248,016
<p>I have a script that performs BLAST queries (bl2seq)</p> <p>The script works like this:</p> <blockquote> <ol> <li>Get sequence a, sequence b</li> <li>write sequence a to filea</li> <li>write sequence b to fileb</li> <li>run command 'bl2seq -i filea -j fileb -n blastn'</li> <li>get output from STDOUT, p...
5
2010-02-11T21:55:57Z
2,784,039
<p>Wow. I have it figured out.</p> <p>The answer is to use python's subprocess module and pipes!</p> <p>EDIT: forgot to mention that I'm using blast2 which <em>does</em> support piping.</p> <p>(this is part of a class)</p> <pre><code>def _query(self): from subprocess import Popen, PIPE, STDOUT pipe = Popen...
1
2010-05-06T19:58:35Z
[ "python", "perl", "unix", "shell", "bioinformatics" ]
running BLAST (bl2seq) without creating sequence files
2,248,016
<p>I have a script that performs BLAST queries (bl2seq)</p> <p>The script works like this:</p> <blockquote> <ol> <li>Get sequence a, sequence b</li> <li>write sequence a to filea</li> <li>write sequence b to fileb</li> <li>run command 'bl2seq -i filea -j fileb -n blastn'</li> <li>get output from STDOUT, p...
5
2010-02-11T21:55:57Z
3,160,477
<p>I call blast2 using R script:</p> <pre><code>.... system("mkfifo seq1") system("mkfifo seq2") system("echo sequence1 &gt; seq1"), wait = FALSE) system("echo sequence2 &gt; seq2"), wait = FALSE) system("blast2 -p blastp -i seq1 -j seq2 -m 8", intern = TRUE) .... </code></pre> <p>This is 2 times slower(!) vs. writ...
1
2010-07-01T18:09:25Z
[ "python", "perl", "unix", "shell", "bioinformatics" ]
Grid lines in parasitic axes in matplotlib
2,248,118
<p>Can you draw the grid lines in a plot with parasitic axes in matplotlib?</p> <p>I try this, based on the samples for grids and for parasitic axes, but grid drawing is not performed:</p> <pre><code>from mpl_toolkits.axes_grid.parasite_axes import SubplotHost import matplotlib.pyplot as plt fig = plt.figure(1) hos...
1
2010-02-11T22:07:47Z
2,256,496
<p>For plots of this type, it's not always easy to tell at a glance which object should make the call to 'grid'.</p> <p>One way around this inconvenience--i.e., to get the grid lines on your plot without having to change any of your code and worry about whether you have the right object calling 'grid'--is to <strong>e...
3
2010-02-13T04:40:15Z
[ "python", "grid", "matplotlib" ]
Grid lines in parasitic axes in matplotlib
2,248,118
<p>Can you draw the grid lines in a plot with parasitic axes in matplotlib?</p> <p>I try this, based on the samples for grids and for parasitic axes, but grid drawing is not performed:</p> <pre><code>from mpl_toolkits.axes_grid.parasite_axes import SubplotHost import matplotlib.pyplot as plt fig = plt.figure(1) hos...
1
2010-02-11T22:07:47Z
2,258,313
<p>From the discussion <a href="http://www.mail-archive.com/matplotlib-users@lists.sourceforge.net/msg13404.html" rel="nofollow">here</a> it looks like this is a bug in the .99 release. </p> <p>(I'm not sure why it works for doug but no combination of rcParams works for me on version 0.99.1.1-r1.)</p> <p>From that <...
4
2010-02-13T16:53:29Z
[ "python", "grid", "matplotlib" ]
MongoDB/py-mongo for queries with date functions
2,248,146
<p>Im looking to use a document database such as MongoDB but looking through the documents I cant find much on queries that involve date functions. For example lets say that I'm asking one of the following questions of the DB:</p> <ul> <li>"Tell me all the people who bought a product on tuesday"</li> <li>"Get me all s...
2
2010-02-11T22:12:17Z
2,249,250
<p>For the first query the best bet would be to do a range query for dates in between the start and end of tuesday. Something like:</p> <pre><code>db.foo.find({"purchase_date": {"$gt": monday_midnight, "$lte": tuesday_midnight}}) </code></pre> <p>This will be nicer syntactically when the following case is finished, s...
3
2010-02-12T02:15:47Z
[ "python", "mongodb", "pymongo" ]
Python: Identifying a numeric string?
2,248,185
<p>I tried a couple of approaches, I am really only concerned with performance, not correctness. I noticed that the regex based implementation is about 3-4x slower than the one that uses type coercion. Is there another, more efficient way of doing this?</p> <pre><code>def IsNumber(x): try: _ = float(x) ...
1
2010-02-11T22:18:11Z
2,248,197
<p>Not really. Coercion is the accepted way to do this.</p>
2
2010-02-11T22:20:16Z
[ "python", "regex", "coercion" ]
Python: Identifying a numeric string?
2,248,185
<p>I tried a couple of approaches, I am really only concerned with performance, not correctness. I noticed that the regex based implementation is about 3-4x slower than the one that uses type coercion. Is there another, more efficient way of doing this?</p> <pre><code>def IsNumber(x): try: _ = float(x) ...
1
2010-02-11T22:18:11Z
2,248,234
<p>First of all, they're not doing the same thing. Floats can be specified as "1e3", for example, and float() will accept that. It's also not <a href="http://docs.python.org/reference/datamodel.html#coercion-rules" rel="nofollow">coercion</a>, but conversion.</p> <p>Secondly, don't import re in IsNumber2, especially...
6
2010-02-11T22:24:26Z
[ "python", "regex", "coercion" ]
Python: Identifying a numeric string?
2,248,185
<p>I tried a couple of approaches, I am really only concerned with performance, not correctness. I noticed that the regex based implementation is about 3-4x slower than the one that uses type coercion. Is there another, more efficient way of doing this?</p> <pre><code>def IsNumber(x): try: _ = float(x) ...
1
2010-02-11T22:18:11Z
2,248,240
<p>You might try compiling your regular expression first, but I'd imagine it would still be slower. </p> <p>Also, if you want to know if your string is a number because you're going to do calculations with it, you'll have to coerce it anyway. </p>
0
2010-02-11T22:25:13Z
[ "python", "regex", "coercion" ]
Python: Identifying a numeric string?
2,248,185
<p>I tried a couple of approaches, I am really only concerned with performance, not correctness. I noticed that the regex based implementation is about 3-4x slower than the one that uses type coercion. Is there another, more efficient way of doing this?</p> <pre><code>def IsNumber(x): try: _ = float(x) ...
1
2010-02-11T22:18:11Z
2,248,611
<p>The answer depends a lot on what you mean by 'numeric string'. If your definition of numeric string is 'anything that float accepts', then it's difficult to improve on the try-except method.</p> <p>But bear in mind that float may be more liberal than you want it to be: on most machines, it'll accept strings repre...
2
2010-02-11T23:36:38Z
[ "python", "regex", "coercion" ]
(python) issue bash commands from within python script (alla perl system($cmd))
2,248,259
<p>Within a python script, I want to issue a command. In perl, I could define a command, save it as a variable (here, <code>$cmd</code>) then type <code>system($cmd)</code> and then the command is executed.</p> <p>How can i do that in python?</p>
1
2010-02-11T22:28:39Z
2,248,272
<p>You <em>can</em> use <a href="http://docs.python.org/library/subprocess.html#replacing-os-system" rel="nofollow"><code>os.system()</code></a>, but prefer <a href="http://docs.python.org/library/subprocess.html" rel="nofollow"><code>subprocess</code></a> instead.</p>
6
2010-02-11T22:31:16Z
[ "python", "bash" ]
(python) issue bash commands from within python script (alla perl system($cmd))
2,248,259
<p>Within a python script, I want to issue a command. In perl, I could define a command, save it as a variable (here, <code>$cmd</code>) then type <code>system($cmd)</code> and then the command is executed.</p> <p>How can i do that in python?</p>
1
2010-02-11T22:28:39Z
2,248,594
<p>Another good choice is "commands" module: <a href="http://docs.python.org/library/commands.html" rel="nofollow">http://docs.python.org/library/commands.html</a>.</p>
1
2010-02-11T23:32:10Z
[ "python", "bash" ]
(python) issue bash commands from within python script (alla perl system($cmd))
2,248,259
<p>Within a python script, I want to issue a command. In perl, I could define a command, save it as a variable (here, <code>$cmd</code>) then type <code>system($cmd)</code> and then the command is executed.</p> <p>How can i do that in python?</p>
1
2010-02-11T22:28:39Z
2,248,668
<p>you can use os.system(), or the newer subprocess module. Other possible alternatives (for older Python versions) include <a href="http://docs.python.org/library/os.html#process-management" rel="nofollow">these</a>. (eg os.spawn*,os.popen*,etc)</p> <p>Lastly, try using Python's modules to do operating system stuff i...
0
2010-02-11T23:50:54Z
[ "python", "bash" ]
Django MySql Raw Query Error - Parameter index out of range
2,248,321
<p>This view is running fine on plain pyton/Django/mysql on Windows<br> I'm porting this to run over jython/Django/mysql and it gives error -</p> <pre><code>Exception received is : error setting index [10] [SQLCode: 0] Parameter index out of range (10 &gt; number of parameters, which is 0). [SQLCode: 0], [SQLSta...
0
2010-02-11T22:38:31Z
2,248,355
<p>Are you sure that the parameter marker is <code>%s</code> and not <code>?</code> or even <code>:parameter</code>? Check the <a href="http://www.python.org/dev/peps/pep-0249/" rel="nofollow"><code>paramstyle</code></a> argument of the DB-API module to find out.</p>
0
2010-02-11T22:44:02Z
[ "python", "mysql", "django", "jython" ]
Django MySql Raw Query Error - Parameter index out of range
2,248,321
<p>This view is running fine on plain pyton/Django/mysql on Windows<br> I'm porting this to run over jython/Django/mysql and it gives error -</p> <pre><code>Exception received is : error setting index [10] [SQLCode: 0] Parameter index out of range (10 &gt; number of parameters, which is 0). [SQLCode: 0], [SQLSta...
0
2010-02-11T22:38:31Z
2,250,800
<p>It's indeed a parameter style problem. You have to use ? instead of %s.</p> <p>Here is how you reproduce the error you are getting:</p> <pre><code>shell&gt; jython &gt;&gt;&gt; from com.ziclix.python.sql import zxJDBC &gt;&gt;&gt; (d, v) = "jdbc:mysql://localhost/test", "org.gjt.mm.mysql.Driver" &gt;&gt;&gt; cnx =...
1
2010-02-12T09:36:14Z
[ "python", "mysql", "django", "jython" ]
GeoModel with Google App Engine - queries
2,248,341
<p>I'm trying to use GeoModel python module to quickly access geospatial data for my Google App Engine app. I just have a few general questions for issues I'm running into. There's two main methods, proximity_fetch and bounding_box_fetch, that you can use to return queries. They actually return a result set, not a fil...
5
2010-02-11T22:41:16Z
7,339,332
<p>You can also work directly with the <code>location_geocells</code> of your model.</p> <pre><code>from geospatial import geomodel, geocell, geomath # query is a db.GqlQuery # location is a db.GeoPt # A resolution of 4 is box of environs 150km bbox = geocell.compute_box(geocell.compute(geo_point.location, resolutio...
2
2011-09-07T19:14:28Z
[ "python", "google-app-engine", "geolocation", "geospatial" ]
GeoModel with Google App Engine - queries
2,248,341
<p>I'm trying to use GeoModel python module to quickly access geospatial data for my Google App Engine app. I just have a few general questions for issues I'm running into. There's two main methods, proximity_fetch and bounding_box_fetch, that you can use to return queries. They actually return a result set, not a fil...
5
2010-02-11T22:41:16Z
7,342,144
<p>There's no practical way to do this, because a call to geoquery devolves into multiple datastore queries, which it merges together into a single result set. If you were able to specify an offset, geoquery would still have to fetch and discard all the first n results before returning the ones you requested.</p> <p>A...
1
2011-09-08T01:14:44Z
[ "python", "google-app-engine", "geolocation", "geospatial" ]
Are Python global variables thread-safe?
2,248,434
<p>edit: im asking if global variables are safe in a single-threaded web framework like tornado </p> <p>im using the mongoengine orm, which gets a database connection from a global variable: </p> <pre><code>_get_db() # gets the db connection </code></pre> <p>im also using tornado, a single-threaded python web framew...
4
2010-02-11T22:58:00Z
2,248,501
<p>Threads are always required to hold the GIL when interacting with Python objects. The namespace holding the variables is a Python object (either a frameobject or a dict, depending on what kind of variable it is.) It's always safe to get or set variables in multiple threads. You will never get garbage data.</p> <p>...
3
2010-02-11T23:13:05Z
[ "python", "mongodb", "tornado" ]
Are Python global variables thread-safe?
2,248,434
<p>edit: im asking if global variables are safe in a single-threaded web framework like tornado </p> <p>im using the mongoengine orm, which gets a database connection from a global variable: </p> <pre><code>_get_db() # gets the db connection </code></pre> <p>im also using tornado, a single-threaded python web framew...
4
2010-02-11T22:58:00Z
2,248,590
<p>There is nothing about globals that makes them any more or less thread safe than any other variables. Whether or not it's possible for an operation to fail or return incorrect results when run in different threads, the best practice is that you should <em>protect data shared between threads.</em></p> <p>If I'm read...
0
2010-02-11T23:31:36Z
[ "python", "mongodb", "tornado" ]
Are Python global variables thread-safe?
2,248,434
<p>edit: im asking if global variables are safe in a single-threaded web framework like tornado </p> <p>im using the mongoengine orm, which gets a database connection from a global variable: </p> <pre><code>_get_db() # gets the db connection </code></pre> <p>im also using tornado, a single-threaded python web framew...
4
2010-02-11T22:58:00Z
2,249,204
<p>Assuming MongoEngine is wrapping PyMongo (and I believe it is), then you should be fine. PyMongo is completely thread-safe.</p>
2
2010-02-12T02:03:12Z
[ "python", "mongodb", "tornado" ]
Are Python global variables thread-safe?
2,248,434
<p>edit: im asking if global variables are safe in a single-threaded web framework like tornado </p> <p>im using the mongoengine orm, which gets a database connection from a global variable: </p> <pre><code>_get_db() # gets the db connection </code></pre> <p>im also using tornado, a single-threaded python web framew...
4
2010-02-11T22:58:00Z
5,705,716
<p>No, but locks are pretty straightforward to use in python. Use the try: finally: pattern to ensure that a lock is released after you modify your global variable.</p>
1
2011-04-18T16:07:57Z
[ "python", "mongodb", "tornado" ]
Python error while using MysqlDb - sets module is deprecated
2,248,531
<p>I'm currently getting the warning every time I run a Python script that uses MySQLdb:</p> <pre><code>/var/lib/python-support/python2.6/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated from sets import ImmutableSet </code></pre> <p>I'd rather not mess with their lib if possible. I'm on Ub...
6
2010-02-11T23:19:37Z
2,248,565
<p>All it means is the sets module (more specifically the immutableset part) is deprecated, and you should use it's replacement, set. Set is inbuilt so no need to import.</p> <p>If you need an immutable set, <a href="http://docs.python.org/library/stdtypes.html#frozenset" rel="nofollow">frozenset()</a> should work.</p...
0
2010-02-11T23:26:56Z
[ "python", "mysql" ]
Python error while using MysqlDb - sets module is deprecated
2,248,531
<p>I'm currently getting the warning every time I run a Python script that uses MySQLdb:</p> <pre><code>/var/lib/python-support/python2.6/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated from sets import ImmutableSet </code></pre> <p>I'd rather not mess with their lib if possible. I'm on Ub...
6
2010-02-11T23:19:37Z
2,248,585
<p>You can ignore the warning using the <a href="http://docs.python.org/library/warnings" rel="nofollow"><code>warnings</code></a> module, or the <code>-W</code> argument to Python. Don't ignore all <code>DeprecationWarnings</code>, though, just the ones from <code>MySQLdb</code> :)</p>
1
2010-02-11T23:30:54Z
[ "python", "mysql" ]
Python error while using MysqlDb - sets module is deprecated
2,248,531
<p>I'm currently getting the warning every time I run a Python script that uses MySQLdb:</p> <pre><code>/var/lib/python-support/python2.6/MySQLdb/__init__.py:34: DeprecationWarning: the sets module is deprecated from sets import ImmutableSet </code></pre> <p>I'd rather not mess with their lib if possible. I'm on Ub...
6
2010-02-11T23:19:37Z
2,248,660
<p>Do this before the mysql module is imported</p> <pre><code>import warnings warnings.filterwarnings(action="ignore", message='the sets module is deprecated') import sets </code></pre>
6
2010-02-11T23:48:41Z
[ "python", "mysql" ]
subprocess.Popen(..).communicate(..) throw away data at random when used with graphviz!
2,248,795
<p>Hey all! I am using graphviz's dot to generate some svg graphs for a web application. I call dot using Popen:</p> <pre><code> p = subprocess.Popen(u'/usr/bin/dot -Kfdp -Tsvg', shell=True,\ stdin=subprocess.PIPE, stdout=subprocess.PIPE) str = u'long-unicode-string-i-want-to-convert' (stdout,stderr) = ...
4
2010-02-12T00:21:44Z
2,248,820
<p>Sounds like you should be doing:</p> <pre><code>stdout, stderr = p.communicate(str.encode('utf-8')) </code></pre> <p>(except, of course, that you shouldn't shadow the builtin <code>str</code>.) The unicode type in Python holds unicode data, <em>not</em> UTF-8. If you want UTF-8, you need to explicitly encode it.</...
3
2010-02-12T00:26:24Z
[ "python", "pipe", "subprocess", "graphviz", "popen" ]
AppEngine 'explicitly cancelled' error
2,248,811
<p>I'm using Google AppEngine and the deferred library, with the <code>Mapper</code> class, as described <a href="http://code.google.com/appengine/articles/deferred.html" rel="nofollow">here</a> (with some improvements as in <a href="http://www.arikfr.com/blog/app-engine-mapping-entities-using-deferred-tasks.html" rel=...
4
2010-02-12T00:24:15Z
2,249,046
<p>After a <code>DeadlineExceededError</code>, you are allowed a short amount of grace time to handle the exception, eg defer the remainder of the computation.</p> <p>If you run out of grace time the <code>CancelledError</code> kicks in.</p> <p>There should be no way to catch/handle the <code>CancelledError</code></p...
1
2010-02-12T01:22:46Z
[ "python", "google-app-engine", "scheduled-tasks", "gae-datastore" ]
Python equivalent to Java's JNLP Web Start?
2,248,921
<p>Is there any way to achieve the same functionality in Python, i.e., launching a script from a browser and automatically updating it from a central server location?</p>
12
2010-02-12T00:52:18Z
2,261,312
<p>You may be able to achieve some functionality with <a href="http://www.skulpt.org/" rel="nofollow">Skulpt</a> although it uses classless python, so its functionality is rather limited.</p> <p>Well check out <a href="http://wiki.python.org/moin/WebProgramming" rel="nofollow">this python wiki page</a> as it lays out ...
1
2010-02-14T14:04:59Z
[ "python", "jnlp" ]
Python equivalent to Java's JNLP Web Start?
2,248,921
<p>Is there any way to achieve the same functionality in Python, i.e., launching a script from a browser and automatically updating it from a central server location?</p>
12
2010-02-12T00:52:18Z
2,275,969
<p>Well this is still not a full match of the features of JNLP but maybe <a href="http://pypi.python.org/pypi/esky" rel="nofollow" title="esky">esky</a> is closer to what you want. It's not browser based but once your app is installed on the client it can update itself. It might also lack something in the cross-platfor...
2
2010-02-16T20:11:48Z
[ "python", "jnlp" ]
Python equivalent to Java's JNLP Web Start?
2,248,921
<p>Is there any way to achieve the same functionality in Python, i.e., launching a script from a browser and automatically updating it from a central server location?</p>
12
2010-02-12T00:52:18Z
2,307,881
<p>Run your app on Jython and use Java Web Start?</p> <p>From a comment below, <a href="http://blog.pyproject.ninja/posts/2016-03-31-web-start-on-jython.html" rel="nofollow">http://blog.pyproject.ninja/posts/2016-03-31-web-start-on-jython.html</a>, provides a complete example.</p> <p>Note that Jython is not Python- s...
7
2010-02-21T23:21:20Z
[ "python", "jnlp" ]
Grouping Python tuple list
2,249,036
<p>I have a list of (label, count) tuples like this:</p> <pre><code>[('grape', 100), ('grape', 3), ('apple', 15), ('apple', 10), ('apple', 4), ('banana', 3)] </code></pre> <p>From that I want to sum all values with the same label (same labels always adjacent) and return a list in the same label order:</p> <pre><code...
12
2010-02-12T01:19:21Z
2,249,054
<p>using itertools and list comprehensions</p> <pre><code>import itertools [(key, sum(num for _, num in value)) for key, value in itertools.groupby(l, lambda x: x[0])] </code></pre> <p><strong>Edit:</strong> as gnibbler pointed out: if <code>l</code> isn't already sorted replace it with <code>sorted(l)</code>.</...
4
2010-02-12T01:25:22Z
[ "grouping", "python" ]
Grouping Python tuple list
2,249,036
<p>I have a list of (label, count) tuples like this:</p> <pre><code>[('grape', 100), ('grape', 3), ('apple', 15), ('apple', 10), ('apple', 4), ('banana', 3)] </code></pre> <p>From that I want to sum all values with the same label (same labels always adjacent) and return a list in the same label order:</p> <pre><code...
12
2010-02-12T01:19:21Z
2,249,060
<p><code>itertools.groupby</code> can do what you want:</p> <pre><code>import itertools import operator L = [('grape', 100), ('grape', 3), ('apple', 15), ('apple', 10), ('apple', 4), ('banana', 3)] def accumulate(l): it = itertools.groupby(l, operator.itemgetter(0)) for key, subiter in it: yield ...
16
2010-02-12T01:26:41Z
[ "grouping", "python" ]
Grouping Python tuple list
2,249,036
<p>I have a list of (label, count) tuples like this:</p> <pre><code>[('grape', 100), ('grape', 3), ('apple', 15), ('apple', 10), ('apple', 4), ('banana', 3)] </code></pre> <p>From that I want to sum all values with the same label (same labels always adjacent) and return a list in the same label order:</p> <pre><code...
12
2010-02-12T01:19:21Z
2,249,137
<pre><code>import collections d=collections.defaultdict(int) a=[] alist=[('grape', 100), ('banana', 3), ('apple', 10), ('apple', 4), ('grape', 3), ('apple', 15)] for fruit,number in alist: if not fruit in a: a.append(fruit) d[fruit]+=number for f in a: print (f,d[f]) </code></pre> <p>output</p> <pre><code...
2
2010-02-12T01:45:40Z
[ "grouping", "python" ]
Grouping Python tuple list
2,249,036
<p>I have a list of (label, count) tuples like this:</p> <pre><code>[('grape', 100), ('grape', 3), ('apple', 15), ('apple', 10), ('apple', 4), ('banana', 3)] </code></pre> <p>From that I want to sum all values with the same label (same labels always adjacent) and return a list in the same label order:</p> <pre><code...
12
2010-02-12T01:19:21Z
2,249,157
<pre><code>&gt;&gt;&gt; from itertools import groupby &gt;&gt;&gt; from operator import itemgetter &gt;&gt;&gt; L=[('grape', 100), ('grape', 3), ('apple', 15), ('apple', 10), ('apple', 4), ('banana', 3)] &gt;&gt;&gt; [(x,sum(map(itemgetter(1),y))) for x,y in groupby(L, itemgetter(0))] [('grape', 103), ('apple', 29), ('...
3
2010-02-12T01:49:42Z
[ "grouping", "python" ]
Grouping Python tuple list
2,249,036
<p>I have a list of (label, count) tuples like this:</p> <pre><code>[('grape', 100), ('grape', 3), ('apple', 15), ('apple', 10), ('apple', 4), ('banana', 3)] </code></pre> <p>From that I want to sum all values with the same label (same labels always adjacent) and return a list in the same label order:</p> <pre><code...
12
2010-02-12T01:19:21Z
38,295,179
<p>Or a simpler more readable answer ( without itertools ):</p> <pre><code>pairs = [('foo',1),('bar',2),('foo',2),('bar',3)] def sum_pairs(pairs): sums = {} for pair in pairs: sums.setdefault(pair[0], 0) sums[pair[0]] += pair[1] return sums.items() print sum_pairs(pairs) </code></pre>
0
2016-07-10T18:29:45Z
[ "grouping", "python" ]
What are my options for doing multithreaded/concurrent programming in Python?
2,249,126
<p>I'm writing a simple site spider and I've decided to take this opportunity to learn something new in concurrent programming in Python. Instead of using threads and a queue, I decided to try something else, but I don't know what would suit me.</p> <p>I have heard about Stackless, Celery, Twisted, Tornado, and other ...
2
2010-02-12T01:43:11Z
2,249,149
<p>I must say that Twisted gets my vote. </p> <p>Performing event-drive tasks is fairly straightforward in Twisted. Integration with other important system components such as GTK+ and DBus is very easy.</p> <p>The HTTP client support is basic for now but improving (>9.0.0): <strong><a href="http://stackoverflow.com/...
2
2010-02-12T01:47:20Z
[ "python", "multithreading", "concurrency", "parallel-processing", "python-stackless" ]
What are my options for doing multithreaded/concurrent programming in Python?
2,249,126
<p>I'm writing a simple site spider and I've decided to take this opportunity to learn something new in concurrent programming in Python. Instead of using threads and a queue, I decided to try something else, but I don't know what would suit me.</p> <p>I have heard about Stackless, Celery, Twisted, Tornado, and other ...
2
2010-02-12T01:43:11Z
2,249,465
<p>Tornado is a web server, so it wouldn't help you much in writing a spider. Twisted is much more general (and, inevitably, complex), good for all kinds of networking tasks (and with good integration with the event loop of several GUI frameworks). Indeed, there used to be a twisted.web.spider (but it was removed yea...
4
2010-02-12T03:17:22Z
[ "python", "multithreading", "concurrency", "parallel-processing", "python-stackless" ]
What are my options for doing multithreaded/concurrent programming in Python?
2,249,126
<p>I'm writing a simple site spider and I've decided to take this opportunity to learn something new in concurrent programming in Python. Instead of using threads and a queue, I decided to try something else, but I don't know what would suit me.</p> <p>I have heard about Stackless, Celery, Twisted, Tornado, and other ...
2
2010-02-12T01:43:11Z
2,252,717
<p>For a quick look at package sizes, see <a href="http://www.ohloh.net/p/compare?project_0=twisted&amp;project_1=stackless&amp;project_2=celery&amp;submit=Go" rel="nofollow">ohloh.net/p/compare</a> .<br> Of course source size is only a rough metric (what I'd really like is nr pages doc, nr pages examples, dependencies...
1
2010-02-12T15:11:26Z
[ "python", "multithreading", "concurrency", "parallel-processing", "python-stackless" ]
How to check contents of a folder using Python
2,249,132
<p>How can you check the contents of a file with python, and then copy a file from the same folder and move it to a new location? I have Python 3.1 but i can just as easily port to 2.6 thank you!</p>
2
2010-02-12T01:44:36Z
2,249,142
<p><a href="http://docs.python.org/library/os.html#os.listdir" rel="nofollow"><code>os.listdir()</code></a> and <a href="http://docs.python.org/library/shutil.html#shutil.move" rel="nofollow"><code>shutil.move()</code></a>.</p>
1
2010-02-12T01:46:28Z
[ "python", "directory", "folder", "cpython" ]
How to check contents of a folder using Python
2,249,132
<p>How can you check the contents of a file with python, and then copy a file from the same folder and move it to a new location? I have Python 3.1 but i can just as easily port to 2.6 thank you!</p>
2
2010-02-12T01:44:36Z
2,249,219
<p>for example</p> <pre><code>import os,shutil root="/home" destination="/tmp" directory = os.path.join(root,"mydir") os.chdir(directory) for file in os.listdir("."): flag="" #check contents of file ? for line in open(file): if "something" in line: flag="found" if flag=="found": ...
3
2010-02-12T02:06:29Z
[ "python", "directory", "folder", "cpython" ]
Formatting an output file
2,249,162
<p>I'm currently indexing my music collection with python. Ideally I'd like my output file to be formatted as;</p> <pre><code>"Artist; Album; Tracks - length - bitrate - md5 Artist2; Album2; Tracks - length - bitrate - md5" </code></pre> <p>But I can't seem to work out how to achieve this....
0
2010-02-12T01:51:26Z
2,249,209
<pre><code>&gt;&gt;&gt; import textwrap &gt;&gt;&gt; class Album(object): ... def __init__(self, title, artist, tracks, length, bitrate, md5): ... self.title=title ... self.artist=artist ... self.tracks=tracks ... self.length=length ... self.bitrate=bitrate ... self.m...
1
2010-02-12T02:04:14Z
[ "python", "text", "formatting", "logging" ]