title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Can seek and tell work with UTF-8 encoded documents in Python? | 1,510,188 | <p>I have an application that generates some large log files > 500MB.</p>
<p>I have written some utilities in Python that allows me to quickly browse the log file and find data of interest. But I now get some datasets where the file is too big to load it all into memory.</p>
<p>I thus want to scan the document once, ... | 2 | 2009-10-02T15:17:21Z | 1,510,276 | <p>If true, this sounds like a bug or limitation of the codecs module, as it's probably confusing byte and character offsets.</p>
<p>I would use the regular <code>open()</code> function for opening the file, then <code>seek()</code>/<code>tell()</code> will give you byte offsets that are always consistent. Whenever yo... | 1 | 2009-10-02T15:31:09Z | [
"python",
"utf-8",
"codec",
"seek"
] |
Can seek and tell work with UTF-8 encoded documents in Python? | 1,510,188 | <p>I have an application that generates some large log files > 500MB.</p>
<p>I have written some utilities in Python that allows me to quickly browse the log file and find data of interest. But I now get some datasets where the file is too big to load it all into memory.</p>
<p>I thus want to scan the document once, ... | 2 | 2009-10-02T15:17:21Z | 1,510,282 | <p>For UTF-8, you don't actually need to open the file with codecs.open. Instead, it is reliable to read the file as a byte string first, and only then decode an individual section (invoking the .decode method on the string). Breaking the file at line boundaries is safe; the only unsafe way to split it would be in the ... | 1 | 2009-10-02T15:32:08Z | [
"python",
"utf-8",
"codec",
"seek"
] |
Can seek and tell work with UTF-8 encoded documents in Python? | 1,510,188 | <p>I have an application that generates some large log files > 500MB.</p>
<p>I have written some utilities in Python that allows me to quickly browse the log file and find data of interest. But I now get some datasets where the file is too big to load it all into memory.</p>
<p>I thus want to scan the document once, ... | 2 | 2009-10-02T15:17:21Z | 1,510,303 | <p>Update: You can't do seek/tell on the object returned by codec.open(). You need to use a normal file, and decode the strings to unicode after reading.</p>
<p>I do not know why it doesn't work but I can't make it work. The seek seems to only work once, for example. Then you need to close and reopen the file, which i... | 0 | 2009-10-02T15:36:01Z | [
"python",
"utf-8",
"codec",
"seek"
] |
Can seek and tell work with UTF-8 encoded documents in Python? | 1,510,188 | <p>I have an application that generates some large log files > 500MB.</p>
<p>I have written some utilities in Python that allows me to quickly browse the log file and find data of interest. But I now get some datasets where the file is too big to load it all into memory.</p>
<p>I thus want to scan the document once, ... | 2 | 2009-10-02T15:17:21Z | 1,510,468 | <p>Much of what goes on with UTF8 in python makes sense if you look at how it was done in Python 3. In your case, it'll make quite a bit more sense if you read the Files chapter in Dive into Python 3: <a href="http://diveintopython3.org/files.html" rel="nofollow">http://diveintopython3.org/files.html</a></p>
<p>The sh... | 0 | 2009-10-02T16:03:55Z | [
"python",
"utf-8",
"codec",
"seek"
] |
Link Checker (Spider Crawler) | 1,510,211 | <p>I am looking for a link checker to spider my website and log invalid links, the problem is that I have a Login page at the start which is required. What i want is a link checker to run through the command post login details then spider the rest of the website. </p>
<p>Any ideas guys will be appreciated.</p>
| 2 | 2009-10-02T15:20:49Z | 1,510,371 | <p>You want to look at the cookielib module: <a href="http://docs.python.org/library/cookielib.html" rel="nofollow">http://docs.python.org/library/cookielib.html</a>. It implements a full implementation of cookies, which will let you store login details. Once you're using a CookieJar, you just have to get login details... | 2 | 2009-10-02T15:48:29Z | [
"python",
"hyperlink",
"web-crawler"
] |
Link Checker (Spider Crawler) | 1,510,211 | <p>I am looking for a link checker to spider my website and log invalid links, the problem is that I have a Login page at the start which is required. What i want is a link checker to run through the command post login details then spider the rest of the website. </p>
<p>Any ideas guys will be appreciated.</p>
| 2 | 2009-10-02T15:20:49Z | 1,511,607 | <p>I've just recently solved a similar problem like this:</p>
<pre><code>import urllib
import urllib2
import cookielib
login = 'user@host.com'
password = 'secret'
cookiejar = cookielib.CookieJar()
urlOpener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
# adjust this to match the form's field names
... | 3 | 2009-10-02T20:20:23Z | [
"python",
"hyperlink",
"web-crawler"
] |
Django model refactoring and migration | 1,510,215 | <p>I'd like to refactor a number of django apps in a way which involves moving Models from one app into another where they can be more readily reused. </p>
<p>A number of these models have either ForeignKey relationships or M2M relationships to other models (such as User). For example:</p>
<pre><code>class Departmen... | 2 | 2009-10-02T15:20:58Z | 1,510,443 | <p>Have you looked at using a migration tool such as <a href="http://south.aeracode.org/">South</a> or <a href="http://code.google.com/p/django-evolution/">django-evolution</a>?</p>
| 6 | 2009-10-02T15:59:41Z | [
"python",
"django",
"django-models"
] |
Django model refactoring and migration | 1,510,215 | <p>I'd like to refactor a number of django apps in a way which involves moving Models from one app into another where they can be more readily reused. </p>
<p>A number of these models have either ForeignKey relationships or M2M relationships to other models (such as User). For example:</p>
<pre><code>class Departmen... | 2 | 2009-10-02T15:20:58Z | 1,510,762 | <p>You can very easily solve the immediate problem by just providing a related_name argument to the ForeignKey in either the new or old model, exactly as the error message tells you to. Not confident that will solve all your problems with this migration, but it will take you one step forward.</p>
| 0 | 2009-10-02T17:06:08Z | [
"python",
"django",
"django-models"
] |
Follow-up on iterating over a graph using XML minidom | 1,510,447 | <p>This is a follow-up to the question (<a href="http://stackoverflow.com/questions/1412004/reading-xml-using-python-minidom-and-iterating-over-each-node">Link</a>)</p>
<p>What I intend on doing is using the XML to create a graph using NetworkX. Looking at the DOM structure below, all nodes within the same node shou... | 0 | 2009-10-02T16:00:12Z | 1,510,710 | <blockquote>
<p>I'm unsure about how to connect authors to each other.</p>
</blockquote>
<p>You need to generate (author, otherauthor) pairs so you can add them as edges. The typical way to do that would be a nested iteration:</p>
<pre><code>for thing in things:
for otherthing in things:
add_edge(thing,... | 0 | 2009-10-02T16:53:15Z | [
"python",
"parsing",
"xmldom"
] |
Follow-up on iterating over a graph using XML minidom | 1,510,447 | <p>This is a follow-up to the question (<a href="http://stackoverflow.com/questions/1412004/reading-xml-using-python-minidom-and-iterating-over-each-node">Link</a>)</p>
<p>What I intend on doing is using the XML to create a graph using NetworkX. Looking at the DOM structure below, all nodes within the same node shou... | 0 | 2009-10-02T16:00:12Z | 1,510,732 | <p>im not entirely sure what you're looking for, but based on your description i threw together a graph which I think encapsulates the relationships you describe.</p>
<p><a href="http://imgur.com/o2HvT.png" rel="nofollow">http://imgur.com/o2HvT.png</a></p>
<p>i used openfst to do this. i find it much easier to clear... | 0 | 2009-10-02T16:59:43Z | [
"python",
"parsing",
"xmldom"
] |
How to make this Python program compile? | 1,510,609 | <p>I have this Python code:</p>
<pre><code>import re
s = "aa67bc54c9"
for t, n in re.findall(r"([a-z]+)([0-9]+)", s)
</code></pre>
<p>And I get this error message when I try to run it: </p>
<pre><code> File "<stdin>", line 1
for t, n in re.findall(r"([a-z]+)([0-9]+)", s)
... | 4 | 2009-10-02T16:28:09Z | 1,510,616 | <p>You need a colon (<code>:</code>) on the end of the line.</p>
<p>And after that line, you will need an indented statement(s) of what to actually <em>do</em> in the loop. If you don't want to do anything in the loop (perhaps until you get more code written) you can use the statement <code>pass</code> to indicate ba... | 4 | 2009-10-02T16:29:15Z | [
"python",
"syntax-error"
] |
How to make this Python program compile? | 1,510,609 | <p>I have this Python code:</p>
<pre><code>import re
s = "aa67bc54c9"
for t, n in re.findall(r"([a-z]+)([0-9]+)", s)
</code></pre>
<p>And I get this error message when I try to run it: </p>
<pre><code> File "<stdin>", line 1
for t, n in re.findall(r"([a-z]+)([0-9]+)", s)
... | 4 | 2009-10-02T16:28:09Z | 1,510,617 | <p><code>for</code> starts a loop, so you need to end the line with a <code>:</code>, and put the loop body, indented, on the following lines.</p>
<p>EDIT:</p>
<p>For further information I suggest you go to the <a href="http://docs.python.org/reference/compound%5Fstmts.html#the-for-statement" rel="nofollow">main docu... | 7 | 2009-10-02T16:29:34Z | [
"python",
"syntax-error"
] |
Retrieving tags for a specific queryset with django-tagging | 1,510,936 | <p>I'm using django-tagging, and am trying to retrieve a list of tags for a specific queryset. Here's what I've got:</p>
<pre><code>tag = Tag.objects.get(name='tag_name')
queryset = TaggedItem.objects.get_by_model(Article, tag)
tags = Tag.objects.usage_for_queryset(queryset, counts=True)
</code></pre>
<p>"qu... | 2 | 2009-10-02T17:43:33Z | 1,511,015 | <p>This appears to be a bug in django-tagging. A patch has been written, but it has not yet been committed to trunk. Find the patch here:</p>
<p><a href="http://code.google.com/p/django-tagging/issues/detail?id=44" rel="nofollow">http://code.google.com/p/django-tagging/issues/detail?id=44</a></p>
| 1 | 2009-10-02T18:04:49Z | [
"python",
"django",
"django-tagging"
] |
Venn Diagram from a list of sentences | 1,510,972 | <p>I have a list of many sentences in Excel on each row in a column. I have like 3 or more columns with such sentences. There are some common sentences in these. Is it possible to create a script to create a Venn diagram and get the common ones between all. </p>
<p>Example: These are sentences in a column. Similarly t... | 0 | 2009-10-02T17:56:22Z | 1,511,003 | <p>Your question is not fully clear, so I might be misunderstanding what you're looking for.</p>
<p>A Venn diagram is just a few simple Set operations. Python has this stuff built into the <a href="http://docs.python.org/tutorial/datastructures.html#sets" rel="nofollow">Set</a> datatype. Basically, take your two gro... | 0 | 2009-10-02T18:02:58Z | [
"python",
"venn-diagram"
] |
Venn Diagram from a list of sentences | 1,510,972 | <p>I have a list of many sentences in Excel on each row in a column. I have like 3 or more columns with such sentences. There are some common sentences in these. Is it possible to create a script to create a Venn diagram and get the common ones between all. </p>
<p>Example: These are sentences in a column. Similarly t... | 0 | 2009-10-02T17:56:22Z | 1,511,183 | <p>This is my interpretation of the question...</p>
<p>Give the data file z.csv (export your data from excel into a csv file)</p>
<pre><code>"Blood lymphocytes from cancer","Blood lymphocytes from sausages","Ovarian tumor_Grade III"
"Blood lymphocytes from patients","Ovarian tumor_Grade III","Peritoneum tumor_Grade I... | 2 | 2009-10-02T18:43:34Z | [
"python",
"venn-diagram"
] |
Can Django/Javascript handle conditional "Ajax" responses to HTTP POST requests? | 1,511,049 | <p>How do I design a Django/Javascript application to provide for conditional Ajax responses to conventional HTTP requests?</p>
<p>On the server, I have a custom-built Form object. When the browser POSTS the form's data, the server checks the submitted data against existing data and rules (eg, if the form adds some e... | 0 | 2009-10-02T18:11:49Z | 1,511,068 | <p>FYI, this isn't an answer...but it might help you think about it a different way</p>
<p>Here's the problem I'm running into...<a href="http://stackoverflow.com/questions/1292111/google-app-engine-jquery-ajax-405-method-not-allowed">http://stackoverflow.com/questions/1292111/google-app-engine-jquery-ajax-405-method-... | 0 | 2009-10-02T18:17:00Z | [
"javascript",
"python",
"ajax",
"django"
] |
Can Django/Javascript handle conditional "Ajax" responses to HTTP POST requests? | 1,511,049 | <p>How do I design a Django/Javascript application to provide for conditional Ajax responses to conventional HTTP requests?</p>
<p>On the server, I have a custom-built Form object. When the browser POSTS the form's data, the server checks the submitted data against existing data and rules (eg, if the form adds some e... | 0 | 2009-10-02T18:11:49Z | 1,511,097 | <p>Although you can arrange for your views to examine the request data to decide if the response should be an AJAXish or plain HTML, I don't really recommend it. Put AJAX request handlers in a separate URL structure, for instance all your regular html views have urls like /foo/bar and a corresponding api call for the ... | 3 | 2009-10-02T18:23:09Z | [
"javascript",
"python",
"ajax",
"django"
] |
Can Django/Javascript handle conditional "Ajax" responses to HTTP POST requests? | 1,511,049 | <p>How do I design a Django/Javascript application to provide for conditional Ajax responses to conventional HTTP requests?</p>
<p>On the server, I have a custom-built Form object. When the browser POSTS the form's data, the server checks the submitted data against existing data and rules (eg, if the form adds some e... | 0 | 2009-10-02T18:11:49Z | 1,511,125 | <p>When dealing with AJAX, I use this:</p>
<pre><code>from django.utils import simplejson
...
status = simplejson.dumps({'status': "success"})
return HttpResponse(status, mimetype="application/json")
</code></pre>
<p>Then, AJAX (jQuery) can do what it wants based on the return value of 'status'.</p>
<p>I'm not sure ... | 3 | 2009-10-02T18:29:59Z | [
"javascript",
"python",
"ajax",
"django"
] |
Django: How to access originating instance from a RelatedManager? | 1,511,256 | <p>I would like to access the <code>Foo</code> instance <code>foo</code> within my manager method <code>baz</code>:</p>
<pre><code>foo.bar_set.baz()
</code></pre>
<p><code>baz</code> would normally take an argument of <code>Foo</code> type:</p>
<pre><code>BarManager(models.Manager):
def baz(self, foo=None):
... | 0 | 2009-10-02T18:56:34Z | 1,511,280 | <p>If I'm understanding what you want correctly, you need to do this:</p>
<pre><code> BarManager(models.Manager):
use_for_related_fields = True
</code></pre>
<p><strong>Edit:</strong> apparently I managed to miss the point completely. You can use something like this (maybe a bit too "magic" for my taste, but oh... | 1 | 2009-10-02T19:06:10Z | [
"python",
"django",
"django-models",
"django-orm"
] |
Using lambda for a constraint function | 1,511,354 | <pre><code>import numpy
from numpy import asarray
Initial = numpy.asarray [2.0, 4.0, 5.0, 3.0, 5.0, 6.0] # Initial values to start with
bounds = [(1, 5000), (1, 6000), (2, 100000), (1, 50000), (1.0, 5000), (2, 1000000)]
# actual passed bounds
b1 = lambda x: numpy.asarray([1.4*x[0] - x[0]])
b2 = lambda x:... | 1 | 2009-10-02T19:25:08Z | 1,511,564 | <p>Based on the comment from Robert Kern, I have removed my previous answer. Here are the constraints as continuous functions:</p>
<pre><code>b1 = lambda x: x[4]-x[0] if x[4]<1.2*x[0] else 1.4*x[0]-x[4]
b2 = lambda x: x[5]-x[1] if x[5]<1.2*x[1] else 1.4*x[1]-x[5]
b3 = lambda x: x[2]-x[3]
</code></pre>
<p>Note: ... | 1 | 2009-10-02T20:10:46Z | [
"python",
"lambda",
"numpy",
"scipy"
] |
Queue for producers and consumers in a tree | 1,511,359 | <p>I am reading up on how to utilize Python Queues to send and receive short messages between nodes. I am simulating a set of nodes that are in a nice tree structure. I want some of these nodes to send a fixed-size data to its parent. Once this parent receives data from some of its child-nodes, it will "process" it and... | 1 | 2009-10-02T19:26:17Z | 1,511,556 | <p>I'm not commenting on the python code in particular, but as far as your queues are designed, it seems you just need one queue in the node 1,2,3 scenario you were describing. Basically, you have one queue, where you have node 1 and node 2 putting messages to, and node 3 reading from.</p>
<p>You should be able to te... | 1 | 2009-10-02T20:09:06Z | [
"python",
"queue"
] |
py2exe and the file system | 1,511,461 | <p>I have a Python app. It loads config files (and various other files) by
doing stuff such as:</p>
<pre><code>_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CONFIG_DIR = os.path.join(_path, 'conf')
</code></pre>
<p>This works fine. However, when I package the app with py2exe, bad things happen:<... | 3 | 2009-10-02T19:49:55Z | 1,511,555 | <p>What do you think about using relative paths for all of the included files? I guess it should be possible to use <code>sys.path.append(".." + os.path.sep + "images")</code> for your example about ok.png, then you could just <code>open("ok.png", "rb")</code>. Using relative paths should fix the issues with the librar... | 2 | 2009-10-02T20:08:48Z | [
"python",
"configuration",
"file",
"py2exe"
] |
py2exe and the file system | 1,511,461 | <p>I have a Python app. It loads config files (and various other files) by
doing stuff such as:</p>
<pre><code>_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CONFIG_DIR = os.path.join(_path, 'conf')
</code></pre>
<p>This works fine. However, when I package the app with py2exe, bad things happen:<... | 3 | 2009-10-02T19:49:55Z | 1,844,634 | <p>The usual approach to doing this sort of thing (if I understand properly) is this:</p>
<ol>
<li>check sys.frozen, which py2exe contrives to set, using something like getattr(sys, 'frozen', '')</li>
<li>if that's not set, use the usual method since you're running from source</li>
<li>if it's set, check sys.executabl... | 10 | 2009-12-04T03:20:38Z | [
"python",
"configuration",
"file",
"py2exe"
] |
py2exe and the file system | 1,511,461 | <p>I have a Python app. It loads config files (and various other files) by
doing stuff such as:</p>
<pre><code>_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CONFIG_DIR = os.path.join(_path, 'conf')
</code></pre>
<p>This works fine. However, when I package the app with py2exe, bad things happen:<... | 3 | 2009-10-02T19:49:55Z | 2,859,959 | <p>Use os.path.dirname(os.path.abspath(sys.argv[0])) from a py2exe app, it'll work the same way from the python script (so you can test without creating the exe every time) and from the exe.</p>
<p>This can be much better than using relative paths because you don't have to worry about where your app (.py or .exe) is r... | 2 | 2010-05-18T18:32:24Z | [
"python",
"configuration",
"file",
"py2exe"
] |
py2exe and the file system | 1,511,461 | <p>I have a Python app. It loads config files (and various other files) by
doing stuff such as:</p>
<pre><code>_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CONFIG_DIR = os.path.join(_path, 'conf')
</code></pre>
<p>This works fine. However, when I package the app with py2exe, bad things happen:<... | 3 | 2009-10-02T19:49:55Z | 10,162,341 | <p>Here's my solution (tested on Windows, Linux and Mac). It also works if the application or Python script is started via a symbolic link.</p>
<pre><code># Get if frozen
is_frozen = bool( getattr(sys, 'frozen', None) )
# Get path variable
path = sys.path if is_frozen else sys.argv
# Get nonempty first element or ra... | 2 | 2012-04-15T13:12:55Z | [
"python",
"configuration",
"file",
"py2exe"
] |
py2exe and the file system | 1,511,461 | <p>I have a Python app. It loads config files (and various other files) by
doing stuff such as:</p>
<pre><code>_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CONFIG_DIR = os.path.join(_path, 'conf')
</code></pre>
<p>This works fine. However, when I package the app with py2exe, bad things happen:<... | 3 | 2009-10-02T19:49:55Z | 25,517,547 | <p>I use the following trick in windows.<br>
When the program is frozen in a py2exe 'executable' (i.e <strong>my_application.exe</strong>), <code>dirname(__file__)</code> returns the folder where your main python script is running.
Oddly enough, that folder is not the folder containing <strong>my_application.exe</stro... | 0 | 2014-08-27T01:25:49Z | [
"python",
"configuration",
"file",
"py2exe"
] |
Python loop | "do-while" over a tree | 1,511,506 | <p>Is there a more Pythonic way to put this loop together?:</p>
<pre><code>while True:
children = tree.getChildren()
if not children:
break
tree = children[0]
</code></pre>
<p>UPDATE:
I think this syntax is probably what I'm going to go with:</p>
<pre><code>while tree.getChildren():
tree = tr... | 2 | 2009-10-02T19:57:51Z | 1,511,518 | <pre><code>children = tree.getChildren()
while children:
tree = children[0]
children = tree.getChildren()
</code></pre>
<p>It would be easier to suggest something if I knew what kind of collection api you're working with. In a good api, you could probably do something like</p>
<pre><code>while tree.hasChildre... | 4 | 2009-10-02T20:00:51Z | [
"python"
] |
Python loop | "do-while" over a tree | 1,511,506 | <p>Is there a more Pythonic way to put this loop together?:</p>
<pre><code>while True:
children = tree.getChildren()
if not children:
break
tree = children[0]
</code></pre>
<p>UPDATE:
I think this syntax is probably what I'm going to go with:</p>
<pre><code>while tree.getChildren():
tree = tr... | 2 | 2009-10-02T19:57:51Z | 1,511,600 | <p>I think the code you have is fine. If you really wanted to, you could wrap it all up in a try/except:</p>
<pre><code>while True:
try:
tree = tree.getChildren()[0]
except (IndexError, TypeError):
break
</code></pre>
<p><code>IndexError</code> will work if <code>getChildren()</code> retur... | 0 | 2009-10-02T20:19:21Z | [
"python"
] |
Python loop | "do-while" over a tree | 1,511,506 | <p>Is there a more Pythonic way to put this loop together?:</p>
<pre><code>while True:
children = tree.getChildren()
if not children:
break
tree = children[0]
</code></pre>
<p>UPDATE:
I think this syntax is probably what I'm going to go with:</p>
<pre><code>while tree.getChildren():
tree = tr... | 2 | 2009-10-02T19:57:51Z | 1,511,605 | <p>Without further testing, I believe this should work:</p>
<pre><code>try: while True: tree=tree.getChildren()[0]
except: pass
</code></pre>
<p>You might also want to override the <code>__getitem__()</code> (the brackets operator) in the <code>Tree</code> class, for further neatification.</p>
<pre><code>try: ... | 0 | 2009-10-02T20:20:10Z | [
"python"
] |
Python loop | "do-while" over a tree | 1,511,506 | <p>Is there a more Pythonic way to put this loop together?:</p>
<pre><code>while True:
children = tree.getChildren()
if not children:
break
tree = children[0]
</code></pre>
<p>UPDATE:
I think this syntax is probably what I'm going to go with:</p>
<pre><code>while tree.getChildren():
tree = tr... | 2 | 2009-10-02T19:57:51Z | 1,511,942 | <p>(My first answer suggested to use <code>iter(tree.getChildren, None)</code> directly, but that won't work as we are not calling the same <code>tree.getChildren</code> function all the time.)</p>
<p>To fix this up I propose a solution using lambda's non-binding of its variables as a possible workaround. I think at t... | 2 | 2009-10-02T21:40:28Z | [
"python"
] |
Python loop | "do-while" over a tree | 1,511,506 | <p>Is there a more Pythonic way to put this loop together?:</p>
<pre><code>while True:
children = tree.getChildren()
if not children:
break
tree = children[0]
</code></pre>
<p>UPDATE:
I think this syntax is probably what I'm going to go with:</p>
<pre><code>while tree.getChildren():
tree = tr... | 2 | 2009-10-02T19:57:51Z | 1,512,034 | <p>Do you really only want the first branch? I'm gonna assume you don't and that you want the whole tree. First I'd do this:</p>
<pre><code>def allitems(tree):
for child in tree.getChildren():
yield child
for grandchild in allitems(child):
yield grandchild
</code></pre>
<p>This will go... | 1 | 2009-10-02T22:10:18Z | [
"python"
] |
Python distutils - copy_tree with filter | 1,511,808 | <p>I want to copy a data directory into my distribution dir. <code>copy_tree</code> does this just fine. However, the project is also an svn repository, and I don't want the distribution to have all the .svn files that the data dir has. Is there any easy way to do a <code>copy_tree</code> excluding the <code>.svn</code... | 1 | 2009-10-02T21:13:30Z | 1,511,907 | <p>I just used <code>shutil.copytree</code>, which takes an <code>ignore</code> kwd arg.</p>
| 2 | 2009-10-02T21:32:15Z | [
"python",
"file",
"distribution",
"py2exe",
"distutils"
] |
Parse a cron entry in Python | 1,511,854 | <p>All. I am trying to find a python module that I can use to parse a cron entry and get the next time it will run. With perl I use the Schedule::Cron::Events module but I would like to convert to python. Thanks in advance.</p>
| 4 | 2009-10-02T21:22:56Z | 1,511,891 | <p>Take a look at <a href="http://pypi.python.org/pypi/python-crontab/0.9.2" rel="nofollow">http://pypi.python.org/pypi/python-crontab/0.9.2</a></p>
| 2 | 2009-10-02T21:28:52Z | [
"python",
"module",
"cron"
] |
Parse a cron entry in Python | 1,511,854 | <p>All. I am trying to find a python module that I can use to parse a cron entry and get the next time it will run. With perl I use the Schedule::Cron::Events module but I would like to convert to python. Thanks in advance.</p>
| 4 | 2009-10-02T21:22:56Z | 1,516,146 | <p>The documentation for python-crontab is in <a href="http://en.wikipedia.org/wiki/Docstring#Python" rel="nofollow">docstrings</a> in the source code, as is usual for python. You can also explore the documentation via the python interpreter with the built-in <code>help()</code> function. The full source for python-cro... | 7 | 2009-10-04T10:55:53Z | [
"python",
"module",
"cron"
] |
Parse a cron entry in Python | 1,511,854 | <p>All. I am trying to find a python module that I can use to parse a cron entry and get the next time it will run. With perl I use the Schedule::Cron::Events module but I would like to convert to python. Thanks in advance.</p>
| 4 | 2009-10-02T21:22:56Z | 3,256,325 | <p>I could be wrong but doesn't python crontab offer ways to read and write to crontab but nothing regarding parsing the crontab to determine the time until the next time a job will be run?</p>
| 3 | 2010-07-15T14:10:09Z | [
"python",
"module",
"cron"
] |
py2exe'd version of GTK app can't read png files | 1,511,916 | <p>I'm working on making a py2exe version of my app. Py2exe fails at copying some
modules in. My original app loads <code>.png</code> files fine, but the exe version does not:</p>
<pre><code>Traceback (most recent call last):
File "app.py", line 1, in <module>
from gui.main import run
File "gui\main.pyc"... | 0 | 2009-10-02T21:33:50Z | 1,511,932 | <p>What platform is this?
Lately I think they improved the png support on windows,
so the version of pygtk you're using is pertinent also.
<a href="http://aruiz.typepad.com/siliconisland/2008/02/goodbye-zlib-li.html" rel="nofollow">http://aruiz.typepad.com/siliconisland/2008/02/goodbye-zlib-li.html</a></p>
| 2 | 2009-10-02T21:38:45Z | [
"python",
"image",
"gtk",
"pygtk",
"py2exe"
] |
py2exe'd version of GTK app can't read png files | 1,511,916 | <p>I'm working on making a py2exe version of my app. Py2exe fails at copying some
modules in. My original app loads <code>.png</code> files fine, but the exe version does not:</p>
<pre><code>Traceback (most recent call last):
File "app.py", line 1, in <module>
from gui.main import run
File "gui\main.pyc"... | 0 | 2009-10-02T21:33:50Z | 1,512,020 | <p>This is a known problem with <a href="http://www.pythonware.com/products/pil/" rel="nofollow">PIL</a> and <a href="http://www.py2exe.org/" rel="nofollow">py2exe</a></p>
<p>PIL (python image library) imports its plugins dynamically which py2exe doesn't pick up on, so it doesn't include the plugins in the .exe file.<... | 4 | 2009-10-02T22:06:56Z | [
"python",
"image",
"gtk",
"pygtk",
"py2exe"
] |
py2exe'd version of GTK app can't read png files | 1,511,916 | <p>I'm working on making a py2exe version of my app. Py2exe fails at copying some
modules in. My original app loads <code>.png</code> files fine, but the exe version does not:</p>
<pre><code>Traceback (most recent call last):
File "app.py", line 1, in <module>
from gui.main import run
File "gui\main.pyc"... | 0 | 2009-10-02T21:33:50Z | 1,579,606 | <p>Make sure you bundle the loaders when you install your application. Py2exe won't know about these, but they are a needed part of GTK, and live where the rest of the GTK "data" files live.</p>
<p>From <a href="http://unpythonic.blogspot.com/2007/07/pygtk-py2exe-and-inno-setup-for-single.html" rel="nofollow">http://u... | 2 | 2009-10-16T18:24:36Z | [
"python",
"image",
"gtk",
"pygtk",
"py2exe"
] |
Please help me with this program to parse a file into an XML file | 1,511,950 | <p>To parse an input text file and generate a) an XML file and b) an SVG (also XML) file.</p>
<p>The input text file (input.txt) contains the description of a number of produce distribution centers and storage centers around the country. Each line describes either a single distribution center (dcenter) or a storage ce... | 0 | 2009-10-02T21:42:45Z | 1,511,977 | <p>Suppose the input is in string s; either from direct assignment or from file.read:</p>
<pre><code>s="""dcenter: code=d1, loc=San Jose, x=100, y=100, ctype=ct1
dcenter: code=d2, loc=San Ramon, x=300, y=200, ctype=ct2
storage: code=s1, locFrom=d1, x=50, y=50, rtype=rt1
storage: code=s2, locFrom=d1, x=-50,y=100, rtype... | 0 | 2009-10-02T21:54:12Z | [
"python",
"xml",
"fileparsing"
] |
urlopen error 10045, 'address already in use' while downloading in Python 2.5 on Windows | 1,512,057 | <p>I'm writing code that will run on Linux, OS X, and Windows. It downloads a list of approximately 55,000 files from the server, then steps through the list of files, checking if the files are present locally. (With SHA hash verification and a few other goodies.) If the files aren't present locally or the hash doesn't... | 5 | 2009-10-02T22:15:24Z | 1,512,326 | <p>Thinking outside the box, the problem you seem to be trying to solve has already been solved by a program called rsync. You might look for a Windows implementation and see if it meets your needs.</p>
| 1 | 2009-10-02T23:44:41Z | [
"python",
"windows",
"http",
"download",
"urllib2"
] |
urlopen error 10045, 'address already in use' while downloading in Python 2.5 on Windows | 1,512,057 | <p>I'm writing code that will run on Linux, OS X, and Windows. It downloads a list of approximately 55,000 files from the server, then steps through the list of files, checking if the files are present locally. (With SHA hash verification and a few other goodies.) If the files aren't present locally or the hash doesn't... | 5 | 2009-10-02T22:15:24Z | 1,537,736 | <p>If it is really a resource problem (freeing os socket resources)</p>
<p>try this:</p>
<pre><code>request = urllib2.Request(file_remote_path)
opener = urllib2.build_opener()
retry = 3 # 3 tries
while retry :
try :
datastream = opener.open(request)
except urllib2.URLError, ue:
if ue.reason.f... | 5 | 2009-10-08T13:15:28Z | [
"python",
"windows",
"http",
"download",
"urllib2"
] |
urlopen error 10045, 'address already in use' while downloading in Python 2.5 on Windows | 1,512,057 | <p>I'm writing code that will run on Linux, OS X, and Windows. It downloads a list of approximately 55,000 files from the server, then steps through the list of files, checking if the files are present locally. (With SHA hash verification and a few other goodies.) If the files aren't present locally or the hash doesn't... | 5 | 2009-10-02T22:15:24Z | 1,541,415 | <p>You should seriously consider copying and modifying <a href="http://pycurl.cvs.sourceforge.net/pycurl/pycurl/examples/retriever-multi.py?view=markup" rel="nofollow">this pyCurl example</a> for efficient downloading of a large collection of files. </p>
| 1 | 2009-10-09T01:34:51Z | [
"python",
"windows",
"http",
"download",
"urllib2"
] |
urlopen error 10045, 'address already in use' while downloading in Python 2.5 on Windows | 1,512,057 | <p>I'm writing code that will run on Linux, OS X, and Windows. It downloads a list of approximately 55,000 files from the server, then steps through the list of files, checking if the files are present locally. (With SHA hash verification and a few other goodies.) If the files aren't present locally or the hash doesn't... | 5 | 2009-10-02T22:15:24Z | 1,551,171 | <p>Instead of opening a new TCP connection for each request you should really use persistent HTTP connections - have a look at <a href="http://linux.duke.edu/projects/urlgrabber/" rel="nofollow">urlgrabber</a> (or alternatively, just at <a href="http://linux.duke.edu/projects/urlgrabber/contents/urlgrabber/keepalive.py... | 1 | 2009-10-11T17:03:06Z | [
"python",
"windows",
"http",
"download",
"urllib2"
] |
urlopen error 10045, 'address already in use' while downloading in Python 2.5 on Windows | 1,512,057 | <p>I'm writing code that will run on Linux, OS X, and Windows. It downloads a list of approximately 55,000 files from the server, then steps through the list of files, checking if the files are present locally. (With SHA hash verification and a few other goodies.) If the files aren't present locally or the hash doesn't... | 5 | 2009-10-02T22:15:24Z | 1,551,327 | <p>All indications point to a lack of available sockets. Are you sure that only 6 are in TIME_WAIT status? If you're running so many download operations it's very likely that netstat overruns your terminal buffer. I find that netstat stat overruns my terminal during normal useage periods.</p>
<p>The solution is to ei... | 1 | 2009-10-11T18:11:15Z | [
"python",
"windows",
"http",
"download",
"urllib2"
] |
Django: Get an object form the DB, or 'None' if nothing matches | 1,512,059 | <p>Is there any Django function which will let me get an object form the database, or None if nothing matches?</p>
<p>Right now I'm using something like:</p>
<pre><code>foo = Foo.objects.filter(bar=baz)
foo = len(foo) > 0 and foo.get() or None
</code></pre>
<p>But that's not very clear, and it's messy to have eve... | 73 | 2009-10-02T22:15:33Z | 1,512,094 | <p>There are two ways to do this;</p>
<pre><code>try:
foo = Foo.objects.get(bar=baz)
except model.DoesNotExist:
foo = None
</code></pre>
<p>Or you can use a wrapper:</p>
<pre><code>def get_or_none(model, *args, **kwargs):
try:
return model.objects.get(*args, **kwargs)
except model.DoesNotExis... | 113 | 2009-10-02T22:27:49Z | [
"python",
"django"
] |
Django: Get an object form the DB, or 'None' if nothing matches | 1,512,059 | <p>Is there any Django function which will let me get an object form the database, or None if nothing matches?</p>
<p>Right now I'm using something like:</p>
<pre><code>foo = Foo.objects.filter(bar=baz)
foo = len(foo) > 0 and foo.get() or None
</code></pre>
<p>But that's not very clear, and it's messy to have eve... | 73 | 2009-10-02T22:15:33Z | 1,512,104 | <p>Give Foo <a href="http://www.djangoproject.com/documentation/models/custom_managers/" rel="nofollow">its custom manager</a>. It's pretty easy - just put your code into function in custom manager, set custom manager in your model and call it with <code>Foo.objects.your_new_func(...)</code>.</p>
<p>If you need generi... | 9 | 2009-10-02T22:30:44Z | [
"python",
"django"
] |
Django: Get an object form the DB, or 'None' if nothing matches | 1,512,059 | <p>Is there any Django function which will let me get an object form the database, or None if nothing matches?</p>
<p>Right now I'm using something like:</p>
<pre><code>foo = Foo.objects.filter(bar=baz)
foo = len(foo) > 0 and foo.get() or None
</code></pre>
<p>But that's not very clear, and it's messy to have eve... | 73 | 2009-10-02T22:15:33Z | 2,021,833 | <p>To add some sample code to sorki's answer (I'd add this as a comment, but this is my first post, and I don't have enough reputation to leave comments), I implemented a get_or_none custom manager like so:</p>
<pre><code>from django.db import models
class GetOrNoneManager(models.Manager):
"""Adds get_or_none met... | 69 | 2010-01-07T16:24:54Z | [
"python",
"django"
] |
Django: Get an object form the DB, or 'None' if nothing matches | 1,512,059 | <p>Is there any Django function which will let me get an object form the database, or None if nothing matches?</p>
<p>Right now I'm using something like:</p>
<pre><code>foo = Foo.objects.filter(bar=baz)
foo = len(foo) > 0 and foo.get() or None
</code></pre>
<p>But that's not very clear, and it's messy to have eve... | 73 | 2009-10-02T22:15:33Z | 13,614,419 | <p>Whether doing it via a manager or generic function, you may also want to catch 'MultipleObjectsReturned' in the TRY statement, as the get() function will raise this if your kwargs retrieve more than one object.</p>
<p>Building on the generic function:</p>
<pre><code>def get_unique_or_none(model, *args, **kwargs):
... | 4 | 2012-11-28T21:07:36Z | [
"python",
"django"
] |
Django: Get an object form the DB, or 'None' if nothing matches | 1,512,059 | <p>Is there any Django function which will let me get an object form the database, or None if nothing matches?</p>
<p>Right now I'm using something like:</p>
<pre><code>foo = Foo.objects.filter(bar=baz)
foo = len(foo) > 0 and foo.get() or None
</code></pre>
<p>But that's not very clear, and it's messy to have eve... | 73 | 2009-10-02T22:15:33Z | 17,938,407 | <p>In Django <strong>1.6</strong> you can use the <code>first()</code> Queryset method. It returns the first object matched by the queryset, or None if there is no matching object.</p>
<p>Usage:</p>
<pre><code>p = Article.objects.order_by('title', 'pub_date').first()
</code></pre>
| 59 | 2013-07-30T04:37:02Z | [
"python",
"django"
] |
Django: Get an object form the DB, or 'None' if nothing matches | 1,512,059 | <p>Is there any Django function which will let me get an object form the database, or None if nothing matches?</p>
<p>Right now I'm using something like:</p>
<pre><code>foo = Foo.objects.filter(bar=baz)
foo = len(foo) > 0 and foo.get() or None
</code></pre>
<p>But that's not very clear, and it's messy to have eve... | 73 | 2009-10-02T22:15:33Z | 23,548,184 | <p>You can also try to use django annoying (it has another useful functions!)</p>
<p>install it with:</p>
<pre><code>pip install django-annoying
from annoying.functions import get_object_or_None
get_object_or_None(Foo, bar=baz)
</code></pre>
| 10 | 2014-05-08T17:04:40Z | [
"python",
"django"
] |
Django: Get an object form the DB, or 'None' if nothing matches | 1,512,059 | <p>Is there any Django function which will let me get an object form the database, or None if nothing matches?</p>
<p>Right now I'm using something like:</p>
<pre><code>foo = Foo.objects.filter(bar=baz)
foo = len(foo) > 0 and foo.get() or None
</code></pre>
<p>But that's not very clear, and it's messy to have eve... | 73 | 2009-10-02T22:15:33Z | 25,025,658 | <p>Here's a variation on the helper function that allows you to optionally pass in a <code>QuerySet</code> instance, in case you want to get the unique object (if present) from a queryset other than the model's <code>all</code> objects queryset (e.g. from a subset of child items belonging to a parent instance):</p>
<p... | 0 | 2014-07-29T21:58:00Z | [
"python",
"django"
] |
Generic Foreign Keys and get_or_create in django 1.0: Broken? | 1,512,152 | <p>As you can see, create() works, but get_or_create() doesn't. Am I missing something obvious here?</p>
<pre><code>In [7]: f = FeedItem.objects.create(source=u, dest=q, type="greata")
In [8]: f, created = FeedItem.objects.get_or_create(source=u, dest=q, type="greata")
------------------------------------------------... | 1 | 2009-10-02T22:42:04Z | 1,512,228 | <p>Look like there's different logic used in <code>create</code> and <code>get_or_create</code> as in <code>get_or_create</code> there is no <code>source</code> argument but <code>src_object_id</code> and <code>src_content_type</code> but it is easy to resolve this - pass <code>scr_object_id</code> as <code>u.id</code>... | 2 | 2009-10-02T23:07:17Z | [
"python",
"django",
"foreign-keys"
] |
What is a good reference for Server side development? | 1,512,155 | <p>I am more interested in the design of the code (i.e functional design vs object oriented design). What are the best practices and what is the communities thoughts on this subject?</p>
<p>Not that it should matter, but I am working with Apache and Python technology stack.</p>
| 1 | 2009-10-02T22:43:00Z | 1,512,239 | <p>If you are using Apache+Python, this sounds like you are using Python for dynamic web pages. In that case, I would strongly urge you to look into <a href="http://www.djangoproject.com/" rel="nofollow">Django</a>. There are also other Python web development environments, but Django is perhaps the most popular; and ... | 1 | 2009-10-02T23:11:09Z | [
"python",
"apache",
"architecture"
] |
Python optparse defaults vs function defaults | 1,512,242 | <p>I'm writing a python script which I would like to be able to both call from the command line and import as a library function.
Ideally the command line options and the function should use the same set of default values.
What is the best way to allow me to reuse a single set of defaults in both places?</p>
<p>Here's... | 5 | 2009-10-02T23:11:22Z | 1,512,332 | <p>Here's the solution - it's trivial if you only need keyword arguments - just use locals.update. Following handles both, positional and key word args (key word args overrides positional).</p>
<pre><code>from optparse import OptionParser
ARGS = {'opt1': 'a',
'opt2': 'b',
'opt3': 'c'}
def do_stuff(*... | 2 | 2009-10-02T23:48:57Z | [
"python",
"dry",
"optparse"
] |
Python optparse defaults vs function defaults | 1,512,242 | <p>I'm writing a python script which I would like to be able to both call from the command line and import as a library function.
Ideally the command line options and the function should use the same set of default values.
What is the best way to allow me to reuse a single set of defaults in both places?</p>
<p>Here's... | 5 | 2009-10-02T23:11:22Z | 1,512,579 | <p>I'd handle it by introspecting the function of interest to set options and defaults appropriately. For example:</p>
<pre><code>import inspect
from optparse import OptionParser
import sys
def do_stuff(opt0, opt1="a", opt2="b", opt3="c"):
print opt0, opt1, opt2, opt3
if __name__ == "__main__":
parser = Opt... | 3 | 2009-10-03T01:59:42Z | [
"python",
"dry",
"optparse"
] |
Python optparse defaults vs function defaults | 1,512,242 | <p>I'm writing a python script which I would like to be able to both call from the command line and import as a library function.
Ideally the command line options and the function should use the same set of default values.
What is the best way to allow me to reuse a single set of defaults in both places?</p>
<p>Here's... | 5 | 2009-10-02T23:11:22Z | 1,513,680 | <p>The inspect solution by Alex is very powerful!</p>
<p>For lightweight programs, you could also simply use this:</p>
<pre><code>def do_stuff(opt1="a", opt2="b", opt3="c"):
print opt1, opt2, opt3
if __name__ == "__main__":
from optparse import OptionParser
opts = do_stuff.func_defaults
parser = Opti... | 1 | 2009-10-03T12:58:37Z | [
"python",
"dry",
"optparse"
] |
Converting urls into lowercase? | 1,512,389 | <p>Is there any straightforward to convert all incoming urls to lowercase before they get matched against urlpatterns in <code>run_wsgi_app(webapp.WSGIApplication(urlpatterns))</code>? </p>
| 0 | 2009-10-03T00:21:15Z | 1,512,414 | <p>You'd have to wrap the instance of <code>WSGIApplication</code> with your own WSGI app that lowercases the URL in the WSGI environment -- but then the environment would just stay modified, which may have other unpleasant effects. Why not just add <code>(?i)</code> to the regex patterns you use in <code>urlpatterns</... | 3 | 2009-10-03T00:31:10Z | [
"python",
"google-app-engine",
"web-applications"
] |
Converting urls into lowercase? | 1,512,389 | <p>Is there any straightforward to convert all incoming urls to lowercase before they get matched against urlpatterns in <code>run_wsgi_app(webapp.WSGIApplication(urlpatterns))</code>? </p>
| 0 | 2009-10-03T00:21:15Z | 1,512,665 | <p>I wonder if you could modify your CGI environment variables before executing the WSGIApplication instance.</p>
<pre><code>os.putenv(os.getenv('PATH_INFO').lower())
</code></pre>
<p>Something along those lines. I've done this myself for slight URL modifications, however I 301 redirected to the new URL; I didn't con... | 0 | 2009-10-03T03:01:44Z | [
"python",
"google-app-engine",
"web-applications"
] |
Python: how to write a data struct to a file as text (not pickled) | 1,512,401 | <p>Is there a way to write python data structs to a file as text.</p>
<p>e.g. an app is running and has a variable/object: OPTIONS = ('ON', 'OFF', )</p>
<p>I need to write/merge the OPTIONS tuple into another file, not as a
pickled object, but as text, verbatim: OPTIONS = ('ON', 'OFF', )</p>
<p>I could traverse the... | 2 | 2009-10-03T00:26:22Z | 1,512,417 | <p>You could use <a href="http://docs.python.org/library/functions.html#repr" rel="nofollow">repr</a> (repr works well with things that have a <code>__repr__()</code> method):</p>
<pre><code>>>> OPTIONS=('ON', 'OFF', )
>>> "OPTIONS="+repr(OPTIONS)
"OPTIONS=('ON', 'OFF')"
</code></pre>
| 4 | 2009-10-03T00:32:28Z | [
"python"
] |
Python: how to write a data struct to a file as text (not pickled) | 1,512,401 | <p>Is there a way to write python data structs to a file as text.</p>
<p>e.g. an app is running and has a variable/object: OPTIONS = ('ON', 'OFF', )</p>
<p>I need to write/merge the OPTIONS tuple into another file, not as a
pickled object, but as text, verbatim: OPTIONS = ('ON', 'OFF', )</p>
<p>I could traverse the... | 2 | 2009-10-03T00:26:22Z | 1,512,419 | <p><code>fout.write(str(OPTIONS))</code> does what you want in this case, but no doubt in many others it won't; <code>repr</code> instead of <code>str</code> may be closer to your desires (but then again it might not be, as you express them so vaguely and generally, beyond that single example).</p>
| 1 | 2009-10-03T00:33:44Z | [
"python"
] |
Python: how to write a data struct to a file as text (not pickled) | 1,512,401 | <p>Is there a way to write python data structs to a file as text.</p>
<p>e.g. an app is running and has a variable/object: OPTIONS = ('ON', 'OFF', )</p>
<p>I need to write/merge the OPTIONS tuple into another file, not as a
pickled object, but as text, verbatim: OPTIONS = ('ON', 'OFF', )</p>
<p>I could traverse the... | 2 | 2009-10-03T00:26:22Z | 1,512,490 | <p>I don't know your scope but you could use another serialisation/persistence system like <a href="http://docs.python.org/library/json.html" rel="nofollow">JSON</a>, or <a href="http://twistedmatrix.com/documents/current/api/twisted.spread.jelly.html" rel="nofollow">Twisted Jelly</a> that are more human readable (ther... | 1 | 2009-10-03T01:08:30Z | [
"python"
] |
How do you retrieve the tags of a file in a list with Python (Windows Vista)? | 1,512,435 | <p>I want to make something of a tag cloud for various folders I have, but unfortunately, I can't seem to find a way to access the tags of a file in Windows Vista. I tried looking at the win32 module, and os.stat, but I can't seem to find a way. Can I get some help on this?</p>
| 3 | 2009-10-03T00:40:49Z | 1,512,539 | <p>Apparently, you need to use the <a href="http://msdn.microsoft.com/en-us/library/bb331575%28VS.85%29.aspx" rel="nofollow">Windows Search API</a> looking for <a href="http://msdn.microsoft.com/en-us/library/bb787519%28VS.85%29.aspx" rel="nofollow">System.Keywords</a> -- you can access the API directly via <a href="ht... | 4 | 2009-10-03T01:37:51Z | [
"python",
"windows-vista",
"tags"
] |
How do you retrieve the tags of a file in a list with Python (Windows Vista)? | 1,512,435 | <p>I want to make something of a tag cloud for various folders I have, but unfortunately, I can't seem to find a way to access the tags of a file in Windows Vista. I tried looking at the win32 module, and os.stat, but I can't seem to find a way. Can I get some help on this?</p>
| 3 | 2009-10-03T00:40:49Z | 1,512,552 | <p>It appears that Windows <strong>stores the tags in the files</strong>.
Just <strong>tag any image</strong> and <strong>open</strong> the image <strong>in notepad</strong> and <strong>look for</strong> something <strong>XML</strong>-like(<a href="http://en.wikipedia.org/wiki/Resource%5FDescription%5FFramework" rel="n... | 2 | 2009-10-03T01:45:48Z | [
"python",
"windows-vista",
"tags"
] |
How do you retrieve the tags of a file in a list with Python (Windows Vista)? | 1,512,435 | <p>I want to make something of a tag cloud for various folders I have, but unfortunately, I can't seem to find a way to access the tags of a file in Windows Vista. I tried looking at the win32 module, and os.stat, but I can't seem to find a way. Can I get some help on this?</p>
| 3 | 2009-10-03T00:40:49Z | 5,846,091 | <p>I went about it with the win32 extensions package, along with some demo code I found. I posted a detailed explanation of the process on <a href="http://stackoverflow.com/questions/4584038/get-the-list-of-metadata-associated-to-a-file-using-python/5846021">this thread</a>. I don't want to reproduce it all here, but... | 5 | 2011-05-01T02:47:58Z | [
"python",
"windows-vista",
"tags"
] |
How do you retrieve the tags of a file in a list with Python (Windows Vista)? | 1,512,435 | <p>I want to make something of a tag cloud for various folders I have, but unfortunately, I can't seem to find a way to access the tags of a file in Windows Vista. I tried looking at the win32 module, and os.stat, but I can't seem to find a way. Can I get some help on this?</p>
| 3 | 2009-10-03T00:40:49Z | 11,290,737 | <p>There are actually 2 different implentations of document properties (<a href="http://mail.python.org/pipermail/python-win32/2005-June/003489.html" rel="nofollow">source</a>).</p>
<ol>
<li><p>The COM implementation embeds them directly in the file itself : this is the approach used for Office documents for example. ... | 1 | 2012-07-02T09:08:58Z | [
"python",
"windows-vista",
"tags"
] |
Determining if stdout for a Python process is redirected | 1,512,457 | <p>I've noticed that curl can tell whether or not I'm redirecting its output (in which case it puts up a progress bar).</p>
<p>Is there a reasonable way to do this in a Python script? So: </p>
<p>$ python my_script.py<br />
Not redirected</p>
<p>$ python my_script.py > output.txt<br />
Redirected!</p>
| 10 | 2009-10-03T00:51:25Z | 1,512,466 | <p>Look at </p>
<pre><code>os.isatty(fd)
</code></pre>
<p>(I don't think this works on Windows, however)</p>
| 4 | 2009-10-03T00:55:34Z | [
"python"
] |
Determining if stdout for a Python process is redirected | 1,512,457 | <p>I've noticed that curl can tell whether or not I'm redirecting its output (in which case it puts up a progress bar).</p>
<p>Is there a reasonable way to do this in a Python script? So: </p>
<p>$ python my_script.py<br />
Not redirected</p>
<p>$ python my_script.py > output.txt<br />
Redirected!</p>
| 10 | 2009-10-03T00:51:25Z | 1,512,494 | <pre><code>import sys
if sys.stdout.isatty():
print "Not redirected"
else:
sys.stderr.write("Redirected!\n")
</code></pre>
| 26 | 2009-10-03T01:11:17Z | [
"python"
] |
Determining if stdout for a Python process is redirected | 1,512,457 | <p>I've noticed that curl can tell whether or not I'm redirecting its output (in which case it puts up a progress bar).</p>
<p>Is there a reasonable way to do this in a Python script? So: </p>
<p>$ python my_script.py<br />
Not redirected</p>
<p>$ python my_script.py > output.txt<br />
Redirected!</p>
| 10 | 2009-10-03T00:51:25Z | 1,512,526 | <p>Actually, what you want to do here is find out if <code>stdin</code> and <code>stdout</code> are the same thing.</p>
<pre><code>$ cat test.py
import os
print os.fstat(0) == os.fstat(1)
$ python test.py
True
$ python test.py > f
$ cat f
False
$
</code></pre>
<p>The longer but more traditional version of the <em>... | 7 | 2009-10-03T01:31:14Z | [
"python"
] |
can't install lxml (python 2.6.3, osx 10.6 snow leopard) | 1,512,530 | <p>I try to: </p>
<blockquote>
<p>easy_install lxml</p>
</blockquote>
<p>and I get this error:</p>
<blockquote>
<p>File "build/bdist.macosx-10.3-fat/egg/setuptools/command/build_ext.py", line 85, in get_ext_filename
KeyError: 'etree'</p>
</blockquote>
<p>any hints?</p>
| 4 | 2009-10-03T01:33:26Z | 1,512,681 | <p>Due to incompatible changes in the 2.6.3 version of python's distutils, the old <code>easy_install</code> from <a href="http://pypi.python.org/pypi/setuptools" rel="nofollow">setuptools</a> no longer works. You need to replace it with <code>easy_install</code> from <a href="http://pypi.python.org/pypi/distribute" r... | 7 | 2009-10-03T03:08:05Z | [
"python",
"osx",
"port",
"osx-leopard",
"lxml"
] |
can't install lxml (python 2.6.3, osx 10.6 snow leopard) | 1,512,530 | <p>I try to: </p>
<blockquote>
<p>easy_install lxml</p>
</blockquote>
<p>and I get this error:</p>
<blockquote>
<p>File "build/bdist.macosx-10.3-fat/egg/setuptools/command/build_ext.py", line 85, in get_ext_filename
KeyError: 'etree'</p>
</blockquote>
<p>any hints?</p>
| 4 | 2009-10-03T01:33:26Z | 1,513,810 | <p>Ned :</p>
<blockquote>
<p>incompatible changes in the 2.6.3 version of python's distutil</p>
</blockquote>
<p>Not precisely. The API hasn't changed but Setuptools overrides them, and makes the assumption they are called in a particular order.</p>
<p>Lennart:</p>
<blockquote>
<p>The Distribute installation do... | 3 | 2009-10-03T13:57:49Z | [
"python",
"osx",
"port",
"osx-leopard",
"lxml"
] |
How to access file metadata with Python? | 1,512,600 | <p>I'm trying to write a program in python that retrieves and updates file metadata on windows. I've tried searching on Google regarding what modules to use but I haven't found anything very concrete or useful.</p>
<p>Some people suggested the <a href="http://www.python.org/doc/2.5.2/lib/module-stat.html" rel="nofollo... | 3 | 2009-10-03T02:15:52Z | 1,512,611 | <p>Essentially as I said <a href="http://stackoverflow.com/questions/1512435/how-do-you-retrieve-the-tags-of-a-file-in-a-list-with-python-windows-vista">here</a> less than an hour ago,</p>
<blockquote>
<p>Apparently, you need to use the
Windows Search API looking for
System.Keywords -- you can access the
API d... | 2 | 2009-10-03T02:25:52Z | [
"python",
"windows",
"metadata"
] |
Python Pypi: what is your process for releasing packages for different Python versions? (Linux) | 1,512,644 | <p>I've got several eggs I maintain on Pypi but up until now I've always focused on Python 2.5x.
I'd like to release my eggs under both Python 2.5 & Python 2.6 in an automated fashion i.e.</p>
<ol>
<li>running tests </li>
<li>generating doc</li>
<li>preparing eggs</li>
<li>uploading to Pypi</li>
</ol>
<p>How do y... | 5 | 2009-10-03T02:45:36Z | 1,513,605 | <p>I use a script to switch my Python version, run the tests, switch to the next Python version, run the tests again, and so on. I use this to test on 2.3, 2.4, 2.5, 2.6, and 3.1. In addition, I run all my tests under two different configuration scenarios (C extension available, or not), so this runs my full test sui... | 0 | 2009-10-03T12:21:54Z | [
"python",
"release-management",
"pypi"
] |
Python Pypi: what is your process for releasing packages for different Python versions? (Linux) | 1,512,644 | <p>I've got several eggs I maintain on Pypi but up until now I've always focused on Python 2.5x.
I'd like to release my eggs under both Python 2.5 & Python 2.6 in an automated fashion i.e.</p>
<ol>
<li>running tests </li>
<li>generating doc</li>
<li>preparing eggs</li>
<li>uploading to Pypi</li>
</ol>
<p>How do y... | 5 | 2009-10-03T02:45:36Z | 1,513,884 | <p>You don't need to release eggs for anything else than Windows, and then only if your package uses C extensions so that they have compiled parts. Otherwise you simply release one source distribution. That will be enough for all Python versions on all platforms.</p>
<p>Running the tests for different versions automat... | 1 | 2009-10-03T14:34:22Z | [
"python",
"release-management",
"pypi"
] |
Simple Facebook Connect in Google App Engine (Python) | 1,512,658 | <p>Does anyone have a simple and successful demo implementation of facebook connect in an google app engine application. I am developing an web application and want facebook connect to be the primary method for logging in.</p>
| 15 | 2009-10-03T02:56:13Z | 5,539,662 | <p>Here is the "<a href="http://stackoverflow.com/questions/2690723/facebook-graph-api-and-django/5539531#5539531">Start with Beginner guide on facebook application</a>". Hope this will help you... :)</p>
| -2 | 2011-04-04T14:07:35Z | [
"python",
"google-app-engine",
"authentication",
"facebook"
] |
Simple Facebook Connect in Google App Engine (Python) | 1,512,658 | <p>Does anyone have a simple and successful demo implementation of facebook connect in an google app engine application. I am developing an web application and want facebook connect to be the primary method for logging in.</p>
| 15 | 2009-10-03T02:56:13Z | 33,281,983 | <p>I recently used python-social-auth to use Google login, should also work with Facebook:</p>
<p><a href="https://python-social-auth.readthedocs.org/en/latest/" rel="nofollow">https://python-social-auth.readthedocs.org/en/latest/</a></p>
<p>I had some troubles with the implementation, but this tutorial really helped... | 1 | 2015-10-22T13:16:23Z | [
"python",
"google-app-engine",
"authentication",
"facebook"
] |
How to access YQL in Python (Django)? | 1,512,926 | <p>Hey, I need a simple example for the following task:<br />
Send a query to YQL and receive a response<br />
I am accessing public data from python backend of my Django app.</p>
<p>If I just copy/paste an example from YQL, it says "Please provide valid credentials".<br />
I guess, I need OAuth authorization to do it... | 0 | 2009-10-03T05:50:21Z | 1,514,556 | <p>Ok, I sort of resolved the problem.<br />
In YQL console example for data/html the following url was presented as an example:</p>
<p>http://query.yahooapis.com/v1/yql?q=select+*+from+html+where+url%3D%22http%3A%2F%2Ffinance.yahoo.com%2Fq%3Fs%3Dyhoo%22+and%0A++++++xpath%3D%27%2F%2Fdiv%5B%40id%3D%22yfi_headlines%22%5... | 0 | 2009-10-03T19:07:01Z | [
"python",
"django",
"api",
"oauth",
"yql"
] |
How to access YQL in Python (Django)? | 1,512,926 | <p>Hey, I need a simple example for the following task:<br />
Send a query to YQL and receive a response<br />
I am accessing public data from python backend of my Django app.</p>
<p>If I just copy/paste an example from YQL, it says "Please provide valid credentials".<br />
I guess, I need OAuth authorization to do it... | 0 | 2009-10-03T05:50:21Z | 1,665,320 | <p>If you only are accessing public data you can just make a direct rest call from python.</p>
<pre><code>>>> import urllib2
>>> result = urllib2.urlopen("http://query.yahooapis.com/v1/public/yql?q=select%20title%2Cabstract%20from%20search.web%20where%20query%3D%22paul%20tarjan%22&format=json").r... | 2 | 2009-11-03T04:53:10Z | [
"python",
"django",
"api",
"oauth",
"yql"
] |
How to access YQL in Python (Django)? | 1,512,926 | <p>Hey, I need a simple example for the following task:<br />
Send a query to YQL and receive a response<br />
I am accessing public data from python backend of my Django app.</p>
<p>If I just copy/paste an example from YQL, it says "Please provide valid credentials".<br />
I guess, I need OAuth authorization to do it... | 0 | 2009-10-03T05:50:21Z | 1,734,456 | <p>I've just released <a href="https://launchpad.net/python-yql" rel="nofollow">python-yql</a> also available on pypi. It can do public, two-legged oauth a.k.a signed requests and facilitate 3-legged outh too.</p>
<p>It's brand new so there may be some bugs whilst I work on improving the test coverage but should hopef... | 3 | 2009-11-14T14:59:11Z | [
"python",
"django",
"api",
"oauth",
"yql"
] |
text diff on django/google appengine | 1,512,966 | <p>I am developing a wiki using django which i plan to deploy later in google appengine. Is it possible to deploy textdiff like system in appengine?</p>
| 0 | 2009-10-03T06:16:59Z | 1,513,067 | <p>The <a href="http://docs.python.org/library/difflib.html" rel="nofollow">difflib</a> package can be useful for generating diffs. It's written in pure Python and it's in the standard Python library, so I'd expect it to be available in Google App Engine.</p>
| 2 | 2009-10-03T07:19:01Z | [
"python",
"django"
] |
Deploying a web service to my Google App Engine application | 1,513,038 | <p>We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we deployed, using GAEL again, to our appid. It works fine. </p>
<p>Now, we made a web service. We ran that locally using GAEL and a very thin local python client. It works fine.</p>
<p>We deployed that, and we get this me... | 0 | 2009-10-03T07:04:43Z | 1,514,062 | <p>Looks like you're not setting the Content-Type header correctly in your service (assuming you ARE actually trying to send XML -- e.g. SOAP, XML-RPC, &c). What code are you using to set that header? Without some indication about what protocol you're implementing and via what framework, it's impossible to help in... | 1 | 2009-10-03T15:32:32Z | [
"iphone",
"python",
"web-services",
"google-app-engine"
] |
Deploying a web service to my Google App Engine application | 1,513,038 | <p>We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we deployed, using GAEL again, to our appid. It works fine. </p>
<p>Now, we made a web service. We ran that locally using GAEL and a very thin local python client. It works fine.</p>
<p>We deployed that, and we get this me... | 0 | 2009-10-03T07:04:43Z | 1,604,138 | <p>Looks like we aren't going to get to the bottom of this one. Just not enough information available at debug time. We've managed to affect a fix on the service, although I hate ot admit it we never found out what was causing this bug.</p>
| 0 | 2009-10-21T23:02:49Z | [
"iphone",
"python",
"web-services",
"google-app-engine"
] |
Is there a portable way of finding if a path is absolute, using Python? | 1,513,155 | <p>Is there some built-in function that tells me if a path is absolute or not? I'd like something that is platform independent.</p>
| 2 | 2009-10-03T08:06:23Z | 1,513,159 | <p>The <a href="http://docs.python.org/library/os.path.html#os.path.isabs" rel="nofollow"><code>os.path.isabs</code></a> function does this.</p>
| 13 | 2009-10-03T08:08:20Z | [
"python",
"absolute-path"
] |
What should I use instead of assignment-in-an-expression in Python? | 1,513,436 | <p>according to <a href="http://pyfaq.infogami.com/why-can-t-i-use-an-assignment-in-an-expression" rel="nofollow">this page</a> one can't use code like</p>
<pre><code>if variable = something():
#do something with variable, whose value is the result of something() and is true
</code></pre>
<p>So in case I want to have... | 3 | 2009-10-03T10:33:33Z | 1,513,456 | <p>You could do this:</p>
<pre><code>a = something()
if a:
#do something with a
else:
a = somethingelse()
if a:
#...
else:
#5 more nested ifs
</code></pre>
<p>Or, inside a function you can limit the nesting level with a <code>return</code> in each matching case:</p>
<pre><code>def f()... | 3 | 2009-10-03T10:42:24Z | [
"python"
] |
What should I use instead of assignment-in-an-expression in Python? | 1,513,436 | <p>according to <a href="http://pyfaq.infogami.com/why-can-t-i-use-an-assignment-in-an-expression" rel="nofollow">this page</a> one can't use code like</p>
<pre><code>if variable = something():
#do something with variable, whose value is the result of something() and is true
</code></pre>
<p>So in case I want to have... | 3 | 2009-10-03T10:33:33Z | 1,513,627 | <p>Another alternative which offers some flexibility:</p>
<pre><code># Functions to be tested (can be expanded):
tests = [something, somethingelse, yetsomethingelse, anotherfunction, another]
for i, f in enumerate(tests):
a = f()
if a:
if i == 0:
# do something with a
elif 1 <= i... | 3 | 2009-10-03T12:34:43Z | [
"python"
] |
What should I use instead of assignment-in-an-expression in Python? | 1,513,436 | <p>according to <a href="http://pyfaq.infogami.com/why-can-t-i-use-an-assignment-in-an-expression" rel="nofollow">this page</a> one can't use code like</p>
<pre><code>if variable = something():
#do something with variable, whose value is the result of something() and is true
</code></pre>
<p>So in case I want to have... | 3 | 2009-10-03T10:33:33Z | 1,513,629 | <p>You could use a decorator like this memorise for those functions - assuming they always return the same value. Notice that you can call expensive_foo and expensive_bar as many times as you like and the function body only ever gets executed once</p>
<pre><code>def memoize(f):
mem = {}
def inner(*args):
... | 1 | 2009-10-03T12:35:14Z | [
"python"
] |
What should I use instead of assignment-in-an-expression in Python? | 1,513,436 | <p>according to <a href="http://pyfaq.infogami.com/why-can-t-i-use-an-assignment-in-an-expression" rel="nofollow">this page</a> one can't use code like</p>
<pre><code>if variable = something():
#do something with variable, whose value is the result of something() and is true
</code></pre>
<p>So in case I want to have... | 3 | 2009-10-03T10:33:33Z | 1,513,894 | <p>I might be missing something, but couldn't you factor each of the branches in your top-level <code>if</code> statement into separate functions, create a list of <em>test</em> to <em>action</em> tuples and loop over them? You should be able to apply this pattern to mimic <code>if (value=condition()) {} else if (valu... | 1 | 2009-10-03T14:38:01Z | [
"python"
] |
What should I use instead of assignment-in-an-expression in Python? | 1,513,436 | <p>according to <a href="http://pyfaq.infogami.com/why-can-t-i-use-an-assignment-in-an-expression" rel="nofollow">this page</a> one can't use code like</p>
<pre><code>if variable = something():
#do something with variable, whose value is the result of something() and is true
</code></pre>
<p>So in case I want to have... | 3 | 2009-10-03T10:33:33Z | 1,513,987 | <p>Make yourself a simple callable object that saves its returned value:</p>
<pre><code>class ConditionValue(object):
def __call__(self, x):
self.value = x
return bool(x)
</code></pre>
<p>Now use it like this:</p>
<pre><code># example code
makelower = lambda c : c.isalpha() and c.lower()
add10 = ... | 1 | 2009-10-03T15:07:11Z | [
"python"
] |
What should I use instead of assignment-in-an-expression in Python? | 1,513,436 | <p>according to <a href="http://pyfaq.infogami.com/why-can-t-i-use-an-assignment-in-an-expression" rel="nofollow">this page</a> one can't use code like</p>
<pre><code>if variable = something():
#do something with variable, whose value is the result of something() and is true
</code></pre>
<p>So in case I want to have... | 3 | 2009-10-03T10:33:33Z | 1,514,109 | <p>I had this problem years ago, in 2001 -- since I was transliterating to Python from a reference-algorithm in C which used assign-and-test heavily, I was keen to keep a similar structure for the first draft (then refactor later once correctness was well tested). So I wrote a <a href="http://books.google.com/books?id=... | 10 | 2009-10-03T15:49:48Z | [
"python"
] |
What should I use instead of assignment-in-an-expression in Python? | 1,513,436 | <p>according to <a href="http://pyfaq.infogami.com/why-can-t-i-use-an-assignment-in-an-expression" rel="nofollow">this page</a> one can't use code like</p>
<pre><code>if variable = something():
#do something with variable, whose value is the result of something() and is true
</code></pre>
<p>So in case I want to have... | 3 | 2009-10-03T10:33:33Z | 1,515,430 | <p>I would solve this the same way I solve several other problems of tricky flow control: move the tricky bit into a function, and then use <code>return</code> to cause an early exit from the function. Like so:</p>
<pre><code>def do_correct_something():
a = something()
if a:
# do something with a
... | 1 | 2009-10-04T02:24:02Z | [
"python"
] |
What should I use instead of assignment-in-an-expression in Python? | 1,513,436 | <p>according to <a href="http://pyfaq.infogami.com/why-can-t-i-use-an-assignment-in-an-expression" rel="nofollow">this page</a> one can't use code like</p>
<pre><code>if variable = something():
#do something with variable, whose value is the result of something() and is true
</code></pre>
<p>So in case I want to have... | 3 | 2009-10-03T10:33:33Z | 39,776,949 | <p>This is possible if we working with strings - because we can convert string to list and use method <code>extends</code> for list that logically make inline appending one string to another (in list format):</p>
<pre><code>>>> my_str = list('xxx')
>>> if not my_str.extend(list('yyy')) and 'yyy' in '... | 0 | 2016-09-29T17:53:32Z | [
"python"
] |
verifiedEmail AOL OpenID | 1,513,543 | <p>I can't seem to fetch the verifiedEmail field when trying to login to AOLs OpenID on my site. Every other provider that I know of provides this property, but not AOL.</p>
<p>I realize that AOL somehow uses an old OpenID version, although is it feasible to just assume that their e-mail ends in @aol.com? I'm using th... | 0 | 2009-10-03T11:40:18Z | 1,513,794 | <p>I believe that OpenID lets the user decide how much information to "share" during the login process. I can't say that I am an expert on the subject, but I know that my identity at myopenid.com lets me specify precisely what information to make available.</p>
<p>Is it possible that the AOL default is to share nothi... | 0 | 2009-10-03T13:47:49Z | [
"python",
"openid",
"rpxnow"
] |
python: is there an XML parser implemented as a generator? | 1,513,592 | <p>I'd like to parse a big XML file "on the fly". I'd like to use a python generator to perform this. I've tried "iterparse" of "xml.etree.cElementTree" (which is really nice) but still not a generator.</p>
<p>Other suggestions?</p>
| 8 | 2009-10-03T12:14:31Z | 1,513,604 | <p>"On the fly" parsing and document trees are not really compatible. SAX-style parsers are usually used for that (for example, Python's standard <a href="http://docs.python.org/library/xml.sax.html">xml.sax</a>). You basically have to define a class with handlers for various events like startElement, endElement, etc. ... | 6 | 2009-10-03T12:20:44Z | [
"python",
"xml",
"parsing",
"generator"
] |
python: is there an XML parser implemented as a generator? | 1,513,592 | <p>I'd like to parse a big XML file "on the fly". I'd like to use a python generator to perform this. I've tried "iterparse" of "xml.etree.cElementTree" (which is really nice) but still not a generator.</p>
<p>Other suggestions?</p>
| 8 | 2009-10-03T12:14:31Z | 1,513,621 | <p><a href="http://docs.python.org/3/library/xml.dom.pulldom.html" rel="nofollow">PullDom</a> does what you want. It reads XML from a stream, like SAX, but then builds a DOM for a selected piece of it.</p>
<p><em>"PullDOM is a really simple API for working with DOM objects in a streaming (efficient!) manner rather th... | 4 | 2009-10-03T12:30:57Z | [
"python",
"xml",
"parsing",
"generator"
] |
python: is there an XML parser implemented as a generator? | 1,513,592 | <p>I'd like to parse a big XML file "on the fly". I'd like to use a python generator to perform this. I've tried "iterparse" of "xml.etree.cElementTree" (which is really nice) but still not a generator.</p>
<p>Other suggestions?</p>
| 8 | 2009-10-03T12:14:31Z | 1,513,640 | <p><code>xml.etree.cElementTree</code> comes close to a generator with correct usage; by default you receive each element after its 'end' event, at which point you can process it. You should use element.clear() on the element if you don't need it after processing; thereby you save the memory.</p>
<p><hr /></p>
<p>Her... | 14 | 2009-10-03T12:40:25Z | [
"python",
"xml",
"parsing",
"generator"
] |
python: is there an XML parser implemented as a generator? | 1,513,592 | <p>I'd like to parse a big XML file "on the fly". I'd like to use a python generator to perform this. I've tried "iterparse" of "xml.etree.cElementTree" (which is really nice) but still not a generator.</p>
<p>Other suggestions?</p>
| 8 | 2009-10-03T12:14:31Z | 8,693,481 | <p>This is possible with elementtree and incremental parsing:
<a href="http://effbot.org/zone/element-iterparse.htm#incremental-parsing" rel="nofollow">http://effbot.org/zone/element-iterparse.htm#incremental-parsing</a></p>
<pre><code>import xml.etree.cElementTree as etree
for event, elem in etree.iterparse(source):
... | 0 | 2012-01-01T14:10:47Z | [
"python",
"xml",
"parsing",
"generator"
] |
python: is there an XML parser implemented as a generator? | 1,513,592 | <p>I'd like to parse a big XML file "on the fly". I'd like to use a python generator to perform this. I've tried "iterparse" of "xml.etree.cElementTree" (which is really nice) but still not a generator.</p>
<p>Other suggestions?</p>
| 8 | 2009-10-03T12:14:31Z | 11,354,614 | <p>BeautifulSoup is an excellent XML/HTML parser / generator</p>
<p>Check out: <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">http://www.crummy.com/software/BeautifulSoup/</a></p>
| 0 | 2012-07-06T01:05:05Z | [
"python",
"xml",
"parsing",
"generator"
] |
Python .sort() not working as expected | 1,513,727 | <p>Tackling a few puzzle problems on a quiet Saturday night (wooohoo... not) and am struggling with sort(). The results aren't quite what I expect. The program iterates through every combination from 100 - 999 and checks if the product is a palindome. If it is, append to the list. I need the list sorted :D Here's my pr... | 3 | 2009-10-03T13:22:03Z | 1,513,735 | <p>You are sorting strings, not numbers. <code>'101101' < '10201'</code> because <code>'1' < '2'</code>. Change <code>list.append(reversed)</code> to <code>list.append(int(reversed))</code> and it will work (or use a different sorting function).</p>
| 16 | 2009-10-03T13:25:20Z | [
"python",
"list",
"sorting"
] |
Python .sort() not working as expected | 1,513,727 | <p>Tackling a few puzzle problems on a quiet Saturday night (wooohoo... not) and am struggling with sort(). The results aren't quite what I expect. The program iterates through every combination from 100 - 999 and checks if the product is a palindome. If it is, append to the list. I need the list sorted :D Here's my pr... | 3 | 2009-10-03T13:22:03Z | 1,513,736 | <p>You have your numbers stored as strings, so python is sorting them accordingly. So: '101x' comes before '102x' (the same way that 'abcd' will come before 'az').</p>
| 0 | 2009-10-03T13:26:17Z | [
"python",
"list",
"sorting"
] |
Python .sort() not working as expected | 1,513,727 | <p>Tackling a few puzzle problems on a quiet Saturday night (wooohoo... not) and am struggling with sort(). The results aren't quite what I expect. The program iterates through every combination from 100 - 999 and checks if the product is a palindome. If it is, append to the list. I need the list sorted :D Here's my pr... | 3 | 2009-10-03T13:22:03Z | 1,513,737 | <p>No, it is sorting properly, just that it is sorting <strong>lexographically</strong> and you want <strong>numeric</strong> sorting... so remove the "str()"</p>
| 0 | 2009-10-03T13:26:30Z | [
"python",
"list",
"sorting"
] |
Python .sort() not working as expected | 1,513,727 | <p>Tackling a few puzzle problems on a quiet Saturday night (wooohoo... not) and am struggling with sort(). The results aren't quite what I expect. The program iterates through every combination from 100 - 999 and checks if the product is a palindome. If it is, append to the list. I need the list sorted :D Here's my pr... | 3 | 2009-10-03T13:22:03Z | 1,513,744 | <p>You're sorting strings, not numbers. Strings compare left-to-right.</p>
| 1 | 2009-10-03T13:28:01Z | [
"python",
"list",
"sorting"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.