title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
python lotus notes: odbc connect error
1,610,781
<p>I am developing a client server application for a cross-database system.</p> <p>I am using Eclipse IDE with Python 2.5 and PyODBC2.5; need to read content from a Lotus Notes database, so run some basic query like - SELECT peronname FROM tablename.</p> <p>'import pyodbc' is ok - python see it!</p> <p>But when I tr...
0
2009-10-23T00:23:29Z
2,063,672
<p>I almost forgot to post the solution here...</p> <p>We have managed to put NotesSQL to work through ODBC with python to access data from our Lotus Notes *.NSF files (database). It works as queries using the same type of queries syntax you would need normally use to get the data when working on MS-Access to grab the...
0
2010-01-14T11:16:13Z
[ "python", "odbc", "lotus-notes", "connect", "lotus" ]
when to use an alternative Python distribution?
1,610,822
<p>I have been programming in Python for a few years now and have always used CPython without thinking about it. The books and documentation I have read always refer to CPython too.</p> <p>When does it make sense to use an alternative distribution (PyPy, Stackless, etc)?</p> <p>Thanks!</p>
5
2009-10-23T00:34:22Z
1,610,835
<p>I think it's clear when to use IronPython or Jython. If you want to use Python on CLR/JVM, either as the main language or a scripting language for your C#/Java application.</p>
0
2009-10-23T00:37:45Z
[ "python", "distribution", "cpython", "pypy" ]
when to use an alternative Python distribution?
1,610,822
<p>I have been programming in Python for a few years now and have always used CPython without thinking about it. The books and documentation I have read always refer to CPython too.</p> <p>When does it make sense to use an alternative distribution (PyPy, Stackless, etc)?</p> <p>Thanks!</p>
5
2009-10-23T00:34:22Z
1,610,844
<p>If you need native interfacing with the JVM, use <a href="http://www.jython.org/" rel="nofollow">Jython</a>.</p> <p>When you need native interfacing with the .Net platform, or want to use Winforms, use <a href="http://www.codeplex.com/IronPython" rel="nofollow">IronPython</a>.</p> <p>If you need the latest version...
8
2009-10-23T00:40:53Z
[ "python", "distribution", "cpython", "pypy" ]
Collate output in Python logging MemoryHandler with SMTPHandler
1,610,845
<p>I have the logging module MemoryHandler set up to queue debug and error messages for the SMTPHandler target. What I want is for an email to be sent when the process errors that contains all debug statements up to that point (one per line). What I get instead is a separate email for every debug message.</p> <p>This ...
8
2009-10-23T00:40:58Z
1,611,958
<p>You might want to use or adapt the <code>BufferingSMTPHandler</code> which is in <a href="https://gist.github.com/1379446">this test script</a>.</p> <p>In general, you don't need to add a handler to a logger if it's the target of a MemoryHandler handler which has been added to a logger. If you set the level of a ha...
11
2009-10-23T07:55:13Z
[ "python", "logging" ]
Collate output in Python logging MemoryHandler with SMTPHandler
1,610,845
<p>I have the logging module MemoryHandler set up to queue debug and error messages for the SMTPHandler target. What I want is for an email to be sent when the process errors that contains all debug statements up to that point (one per line). What I get instead is a separate email for every debug message.</p> <p>This ...
8
2009-10-23T00:40:58Z
7,877,166
<p>For this purpose I use the <em>BufferingSMTPHandler</em> suggested by Vinay Sajip with one minor tweak: I set the buffer length to something really big (say 5000 log records) and manualy call the flush method of the handler every some seconds and after checking for internet conectivity.</p> <pre><code># init log_ha...
0
2011-10-24T14:27:31Z
[ "python", "logging" ]
Collate output in Python logging MemoryHandler with SMTPHandler
1,610,845
<p>I have the logging module MemoryHandler set up to queue debug and error messages for the SMTPHandler target. What I want is for an email to be sent when the process errors that contains all debug statements up to that point (one per line). What I get instead is a separate email for every debug message.</p> <p>This ...
8
2009-10-23T00:40:58Z
8,333,718
<p>I wrote my own beastly thread-safe implementation of <a href="http://pastebin.com/zEELXxTf" rel="nofollow"><code>BufferingSMTPHandler</code></a> which sends emails from a separate thread. The primary goal is to not block the main thread.</p> <p>As written, it uses two queues - this seemed necessary in order to impl...
3
2011-11-30T22:14:31Z
[ "python", "logging" ]
Collate output in Python logging MemoryHandler with SMTPHandler
1,610,845
<p>I have the logging module MemoryHandler set up to queue debug and error messages for the SMTPHandler target. What I want is for an email to be sent when the process errors that contains all debug statements up to that point (one per line). What I get instead is a separate email for every debug message.</p> <p>This ...
8
2009-10-23T00:40:58Z
32,106,951
<p>If you are using django - here is simple buffering handler, which will use standard django email methods:</p> <pre><code>import logging from django.conf import settings from django.core.mail import EmailMessage class DjangoBufferingSMTPHandler(logging.handlers.BufferingHandler): def __init__(self, capacity, ...
0
2015-08-19T22:56:01Z
[ "python", "logging" ]
Python xml.dom.minidom Unicode
1,610,948
<p>I'm trying to create an xml document in python, however some of the strings i'm working with are encoded in unicode. Is there a way to create a text node using xml.dom.minidom using unicode strings? Is there another module I can use?</p> <p>Thanks.</p>
1
2009-10-23T01:27:07Z
1,611,009
<p>The dom objects seem to have an encoding argument, see <a href="http://docs.python.org/library/xml.dom.minidom.html#dom-objects" rel="nofollow">20.7.1</a> of the Python docs. Read the footnote as well; take care to use the proper encoding string.</p>
1
2009-10-23T01:49:03Z
[ "python", "unicode" ]
Python xml.dom.minidom Unicode
1,610,948
<p>I'm trying to create an xml document in python, however some of the strings i'm working with are encoded in unicode. Is there a way to create a text node using xml.dom.minidom using unicode strings? Is there another module I can use?</p> <p>Thanks.</p>
1
2009-10-23T01:27:07Z
1,611,195
<p>In theory, per <a href="http://docs.python.org/library/xml.dom.html?highlight=xml.dom#type-mapping" rel="nofollow">the docs</a>:</p> <blockquote> <p>the DOMString defined in the recommendation is mapped to a Python string or Unicode string. Applications should be able to handle Unicode whenever a string i...
3
2009-10-23T03:07:22Z
[ "python", "unicode" ]
Python xml.dom.minidom Unicode
1,610,948
<p>I'm trying to create an xml document in python, however some of the strings i'm working with are encoded in unicode. Is there a way to create a text node using xml.dom.minidom using unicode strings? Is there another module I can use?</p> <p>Thanks.</p>
1
2009-10-23T01:27:07Z
1,613,151
<blockquote> <p>Is there a way to create a text node using xml.dom.minidom using unicode strings?</p> </blockquote> <p>Yes, createTextNode <strong>always</strong> takes Unicode strings. The text model of the XML information set is Unicode, as you can see:</p> <pre><code>&gt;&gt;&gt; doc= minidom.parseString('&lt;a&...
0
2009-10-23T12:33:53Z
[ "python", "unicode" ]
CherryPy variables in html
1,610,995
<p>I have a cherryPy program that returns a page that has an image (plot) in a table. I would also like to have variables in the table that describe the plot. I am not using any templating just trying to keep it really simple. In the example below I have the variable numberofapplicants where I want it but it does not o...
2
2009-10-23T01:44:36Z
1,611,028
<p>Assuming you're using Python 2.x, just use regular string formatting.</p> <pre><code>return ''' &lt;html&gt; &lt;body&gt; &lt;table width="400" border="1"&gt; &lt;tr&gt; &lt;td&gt;%(numberofapplicants)s&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="400" height="400"&gt;&lt;img src=...
2
2009-10-23T01:53:50Z
[ "python", "cherrypy" ]
CherryPy variables in html
1,610,995
<p>I have a cherryPy program that returns a page that has an image (plot) in a table. I would also like to have variables in the table that describe the plot. I am not using any templating just trying to keep it really simple. In the example below I have the variable numberofapplicants where I want it but it does not o...
2
2009-10-23T01:44:36Z
1,611,033
<p>Your variable 'numberofapplicants' just looks like the rest of the string to Python. If you want to put 'numberofapplicants' into that spot, use <a href="http://docs.python.org/library/stdtypes.html#string-formatting-operations" rel="nofollow">the % syntax</a>, e.g.</p> <pre><code> return '''big long string of stu...
2
2009-10-23T01:54:52Z
[ "python", "cherrypy" ]
Python: static variable decorator
1,611,019
<p>I'd like to create a decorator like below, but I can't seem to think of an implementation that works. I'm starting to think it's not possible, but thought I would ask you guys first.</p> <p>I realize there's various other ways to create static variables in Python, but I find those ways ugly. I'd really like to use ...
2
2009-10-23T01:51:09Z
1,611,117
<p>Here's something that might be much clearer. It doesn't involve any decorators or hacking.</p> <pre><code>class F( object ): def __init__( self ): self.x= 0 def __call__( self ): self.x += 1 print self.x f= F() </code></pre> <p>Now you have your function <code>f</code> with a stat...
0
2009-10-23T02:27:10Z
[ "python", "variables", "static", "namespaces", "decorator" ]
Python: static variable decorator
1,611,019
<p>I'd like to create a decorator like below, but I can't seem to think of an implementation that works. I'm starting to think it's not possible, but thought I would ask you guys first.</p> <p>I realize there's various other ways to create static variables in Python, but I find those ways ugly. I'd really like to use ...
2
2009-10-23T01:51:09Z
1,611,144
<p>By the time your decorator gets the function object <code>f</code>, it's already been compiled -- specifically, it's been compiled with the knowledge that <code>x</code> is local (because it's assigned with the <code>+=</code> assignment), the normal optimization (in <code>2.*</code> you can defeat the optimization,...
8
2009-10-23T02:37:47Z
[ "python", "variables", "static", "namespaces", "decorator" ]
Python: static variable decorator
1,611,019
<p>I'd like to create a decorator like below, but I can't seem to think of an implementation that works. I'm starting to think it's not possible, but thought I would ask you guys first.</p> <p>I realize there's various other ways to create static variables in Python, but I find those ways ugly. I'd really like to use ...
2
2009-10-23T01:51:09Z
1,611,758
<p>How about this, without decorators?</p> <pre><code>class State(dict): """Object interface to dict.""" def __getattr__(self, name): try: return self[name] except KeyError: raise AttributeError, name def f(d=State(x=0)): d.x += 1 return d.x </code></pre> <p>An...
1
2009-10-23T06:51:35Z
[ "python", "variables", "static", "namespaces", "decorator" ]
Python: static variable decorator
1,611,019
<p>I'd like to create a decorator like below, but I can't seem to think of an implementation that works. I'm starting to think it's not possible, but thought I would ask you guys first.</p> <p>I realize there's various other ways to create static variables in Python, but I find those ways ugly. I'd really like to use ...
2
2009-10-23T01:51:09Z
1,616,751
<p>Here is a decorator that seems to work. Note that this requires return locals() at the end of the function due to being unable to set locals from the outside (I don't have much experience programming so if there is a way, I don't know it).</p> <pre><code>class Static(object): def __init__(self, **kwargs): self....
5
2009-10-24T02:29:36Z
[ "python", "variables", "static", "namespaces", "decorator" ]
Python: static variable decorator
1,611,019
<p>I'd like to create a decorator like below, but I can't seem to think of an implementation that works. I'm starting to think it's not possible, but thought I would ask you guys first.</p> <p>I realize there's various other ways to create static variables in Python, but I find those ways ugly. I'd really like to use ...
2
2009-10-23T01:51:09Z
1,619,225
<p>You could do something like that (but I haven't tested this extensively; used CPython 2.6):</p> <pre><code>import types def static(**dict): def doWrap(func): scope = func.func_globals scope.update(dict) return types.FunctionType(func.func_code, scope) return doWrap # if foo() print...
3
2009-10-24T21:43:00Z
[ "python", "variables", "static", "namespaces", "decorator" ]
Python: static variable decorator
1,611,019
<p>I'd like to create a decorator like below, but I can't seem to think of an implementation that works. I'm starting to think it's not possible, but thought I would ask you guys first.</p> <p>I realize there's various other ways to create static variables in Python, but I find those ways ugly. I'd really like to use ...
2
2009-10-23T01:51:09Z
7,488,974
<p>Here is a really simple solution that works just like normal python static variables.</p> <pre><code>def static(**kwargs): def wrap(f): for key, value in kwargs.items(): setattr(f, key, value) return f return wrap </code></pre> <p>Example usage:</p> <pre><code>@static(a=0) def foo(x): foo.a +=...
5
2011-09-20T17:10:08Z
[ "python", "variables", "static", "namespaces", "decorator" ]
Python: static variable decorator
1,611,019
<p>I'd like to create a decorator like below, but I can't seem to think of an implementation that works. I'm starting to think it's not possible, but thought I would ask you guys first.</p> <p>I realize there's various other ways to create static variables in Python, but I find those ways ugly. I'd really like to use ...
2
2009-10-23T01:51:09Z
7,489,579
<p>When you need to save state between invocations of a function, you are almost always better off using a generator/coroutine or an object. Since you want to use "bare" variable names, then you'll want the coroutine version.</p> <pre><code># the coroutine holds the state and yields rather than returns values def tot...
0
2011-09-20T17:57:50Z
[ "python", "variables", "static", "namespaces", "decorator" ]
Python: static variable decorator
1,611,019
<p>I'd like to create a decorator like below, but I can't seem to think of an implementation that works. I'm starting to think it's not possible, but thought I would ask you guys first.</p> <p>I realize there's various other ways to create static variables in Python, but I find those ways ugly. I'd really like to use ...
2
2009-10-23T01:51:09Z
15,918,680
<p>A slight tweak of <a href="http://stackoverflow.com/a/1619225/58668">another anwser</a>:</p> <pre><code>def static(**kwargs): def decorator(func): return type(func)(func.func_code, dict(func.func_globals, **kwargs)) return decorator message = "goodbye, world!" @static(message="hello, world!") def h...
0
2013-04-10T06:38:50Z
[ "python", "variables", "static", "namespaces", "decorator" ]
Embed Python in NI CVI(LabWindows)
1,611,050
<p>I need to access LabWindows API and/or functions written in labwindows from Python.</p> <p>My approach so far I have been able to do so in Visual studio using SWIG to some extent, but my dll creation fails when i try to generate it in Labwindows using the source file and the SWIG generated wrapper file.</p>
0
2009-10-23T02:01:17Z
5,859,154
<p>These links are essentially pointing to the same answer. Hope it is helpful...</p> <p><a href="http://decibel.ni.com/content/docs/DOC-1494" rel="nofollow">http://decibel.ni.com/content/docs/DOC-1494</a></p> <p><a href="http://stackoverflow.com/questions/91666/ni-cvi-with-python">NI CVI with Python</a></p>
0
2011-05-02T15:40:32Z
[ "python", "swig", "labwindows" ]
Getting a list of child entities in App Engine using get_by_key_name (Python)
1,611,148
<p>My adventures with entity groups continue after a slightly embarrassing beginning (see <a href="http://stackoverflow.com/questions/1535114">Under some circumstances an App Engine <code>get_by_key_name</code> call using an existing key_name returns None</a>).</p> <p>I now see that I can't do a normal <code>get_by_ke...
2
2009-10-23T02:41:28Z
1,611,250
<p>Just create a key list and do a get on it.</p> <pre><code>entities = Model.get_by_key_name(key_names) content_keys = [db.Key.from_path('Model', name, 'ContentModel', name) for name in key_names] content_entities = ContentModel.get(content_keys) </code></pre> <p>Note that I assume the key_name for ...
4
2009-10-23T03:34:33Z
[ "python", "performance", "google-app-engine", "model" ]
Getting a list of child entities in App Engine using get_by_key_name (Python)
1,611,148
<p>My adventures with entity groups continue after a slightly embarrassing beginning (see <a href="http://stackoverflow.com/questions/1535114">Under some circumstances an App Engine <code>get_by_key_name</code> call using an existing key_name returns None</a>).</p> <p>I now see that I can't do a normal <code>get_by_ke...
2
2009-10-23T02:41:28Z
1,611,933
<p>I'm embarrassed to say that the restriction ('must be in the same entity group') actually no longer applies in this case. Please do feel free to <a href="http://code.google.com/p/googleappengine/issues/entry" rel="nofollow">file</a> a documentation bug!</p> <p>In any case, get_by_key_name is only syntactic sugar fo...
1
2009-10-23T07:49:23Z
[ "python", "performance", "google-app-engine", "model" ]
Automatically restart program when error occur
1,611,256
<p>The program is like this:</p> <pre><code>HEADER CODE urllib2.initialization() try: while True: urllib2.read(somebytes) urllib2.read(somebytes) urllib2.read(somebytes) ... except Exception, e: print e FOOTER CODE </code></pre> <p>My question is when error occurs (timeout, c...
2
2009-10-23T03:36:43Z
1,611,265
<p>How about just wrap it in another loop?</p> <pre><code>HEADER CODE restart = True while restart == True: urllib2.initialization() try: while True: restart = False urllib2.read(somebytes) urllib2.read(somebytes) urllib2.read(somebytes) ... except...
4
2009-10-23T03:41:01Z
[ "python", "restart" ]
Automatically restart program when error occur
1,611,256
<p>The program is like this:</p> <pre><code>HEADER CODE urllib2.initialization() try: while True: urllib2.read(somebytes) urllib2.read(somebytes) urllib2.read(somebytes) ... except Exception, e: print e FOOTER CODE </code></pre> <p>My question is when error occurs (timeout, c...
2
2009-10-23T03:36:43Z
1,611,284
<p>You could wrap your code in a "while not done" loop:</p> <pre><code>#!/usr/bin/env python HEADER CODE done=False while not done: try: urllib2.initialization() while True: # I assume you have code to break out of this loop urllib2.read(somebytes) urllib2.read(...
5
2009-10-23T03:46:51Z
[ "python", "restart" ]
Automatically restart program when error occur
1,611,256
<p>The program is like this:</p> <pre><code>HEADER CODE urllib2.initialization() try: while True: urllib2.read(somebytes) urllib2.read(somebytes) urllib2.read(somebytes) ... except Exception, e: print e FOOTER CODE </code></pre> <p>My question is when error occurs (timeout, c...
2
2009-10-23T03:36:43Z
1,611,729
<p>Simple way with attempts restrictions</p> <pre><code>HEADER CODE attempts = 5 for attempt in xrange(attempts): urllib2.initialization() try: while True: urllib2.read(somebytes) urllib2.read(somebytes) urllib2.read(somebytes) ... except Exception, e...
2
2009-10-23T06:44:25Z
[ "python", "restart" ]
Calculate web page size in python
1,611,376
<p>How would I go about calculating the size of a web page (url) using Python. I tried urllib2 and grabbing the content-length header but it wasn't present. </p> <pre><code>import urllib2 url = 'http://www.google.com/' r = urllib2.urlopen(url) #Not sure what to do from here </code></pre>
1
2009-10-23T04:31:10Z
1,611,379
<p><code>Content-Length</code> is optional; use it if it's present, to cut down on bandwidth use, but if the server doesn't send it (or you don't trust it for some reason), you'll have to retrieve the entire resource and calculate its length.</p> <pre><code>print len(r.read()) </code></pre>
3
2009-10-23T04:31:49Z
[ "python" ]
Calculate web page size in python
1,611,376
<p>How would I go about calculating the size of a web page (url) using Python. I tried urllib2 and grabbing the content-length header but it wasn't present. </p> <pre><code>import urllib2 url = 'http://www.google.com/' r = urllib2.urlopen(url) #Not sure what to do from here </code></pre>
1
2009-10-23T04:31:10Z
1,611,406
<p>When you use <code>urlopen</code>, you are going requesting the whole contents (an HTTP GET request) so looking for the optional content-length header is not all that useful, once you've gone that way (it's OK, saves you some time and memory, but you have imposed avoidable load on the server and network). Still, as...
5
2009-10-23T04:44:07Z
[ "python" ]
Calculate web page size in python
1,611,376
<p>How would I go about calculating the size of a web page (url) using Python. I tried urllib2 and grabbing the content-length header but it wasn't present. </p> <pre><code>import urllib2 url = 'http://www.google.com/' r = urllib2.urlopen(url) #Not sure what to do from here </code></pre>
1
2009-10-23T04:31:10Z
6,085,812
<p>Here is how I did it. See the code below.</p> <pre><code>import urllib2 url = 'http://www.ueseo.org' r = urllib2.urlopen(url) print len(r.read()) </code></pre>
0
2011-05-22T03:15:11Z
[ "python" ]
Determine if a script is running in pythonw?
1,611,543
<p>I would like to redirect <code>stderr</code> and <code>stdout</code> to files when run inside of <code>pythonw</code>. How can I determine whether a script is running in <code>pythonw</code> or in <code>python</code>?</p>
0
2009-10-23T05:31:37Z
1,611,558
<p><code>sys.executable</code> -- "A string giving the name of the executable binary for the Python interpreter, on systems where this makes sense."</p>
4
2009-10-23T05:37:12Z
[ "python", "pythonw" ]
Can I get the exception from the finally block in python?
1,611,561
<p>I have a <code>try</code>/<code>finally</code> clause in my script. Is it possible to get the exact error message from within the <code>finally</code> clause?</p>
23
2009-10-23T05:37:44Z
1,611,563
<p>You'll want to do that in the except clause, not the finally.</p> <p>Refer to: <a href="http://www.doughellmann.com/articles/Python-Exception-Handling/" rel="nofollow">http://www.doughellmann.com/articles/Python-Exception-Handling/</a></p>
2
2009-10-23T05:40:07Z
[ "python", "error-handling" ]
Can I get the exception from the finally block in python?
1,611,561
<p>I have a <code>try</code>/<code>finally</code> clause in my script. Is it possible to get the exact error message from within the <code>finally</code> clause?</p>
23
2009-10-23T05:37:44Z
1,611,572
<p>No, at <code>finally</code> time <code>sys.exc_info</code> is all-None, whether there has been an exception or not. Use:</p> <pre><code>try: whatever except: here sys.exc_info is valid to re-raise the exception, use a bare `raise` else: here you know there was no exception finally: and here you can do ex...
54
2009-10-23T05:43:41Z
[ "python", "error-handling" ]
Can I get the exception from the finally block in python?
1,611,561
<p>I have a <code>try</code>/<code>finally</code> clause in my script. Is it possible to get the exact error message from within the <code>finally</code> clause?</p>
23
2009-10-23T05:37:44Z
1,611,606
<p>The <code>finally</code> block will be executed regardless of whether an exception was thrown or not, so as Josh points out, you very likely don't want to be handling it there.</p> <p>If you really do need the value of an exception that was raised, then you should catch the exception in an <code>except</code> block...
7
2009-10-23T05:56:35Z
[ "python", "error-handling" ]
In what version of Python was set initialisation syntax added
1,611,625
<p>I only just noticed this feature today! </p> <pre><code>s={1,2,3} #Set initialisation t={x for x in s if x!=3} #Set comprehension t=={1,2} </code></pre> <p>What version is it in? I also noticed that it has set comprehension. Was this added in the same version?</p> <p><strong>Resources</strong></p> <ul> <li><a hr...
3
2009-10-23T06:07:10Z
1,611,632
<p>Well, testing it:</p> <pre><code>&gt;&gt;&gt; s = {1, 2, 3} File "&lt;stdin&gt;", line 1 s = {1, 2, 3} ^ SyntaxError: invalid syntax </code></pre> <p>I'm running 2.5, so I would assume that this syntax was added sometime in 2.6 (Update: actually added in 3.0, but Ian beat me). I should probably be ...
0
2009-10-23T06:10:02Z
[ "python" ]
In what version of Python was set initialisation syntax added
1,611,625
<p>I only just noticed this feature today! </p> <pre><code>s={1,2,3} #Set initialisation t={x for x in s if x!=3} #Set comprehension t=={1,2} </code></pre> <p>What version is it in? I also noticed that it has set comprehension. Was this added in the same version?</p> <p><strong>Resources</strong></p> <ul> <li><a hr...
3
2009-10-23T06:07:10Z
1,611,646
<p>The <code>sets</code> module was added in Python 2.3, but the built-in set type was added to the language in 2.4, with essentially the same interface. (As of 2.6, the <code>sets</code> module has been deprecated.)</p> <p>So you can use sets as far back as 2.3, as long as you</p> <pre><code>import sets </code></pre...
10
2009-10-23T06:15:04Z
[ "python" ]
In what version of Python was set initialisation syntax added
1,611,625
<p>I only just noticed this feature today! </p> <pre><code>s={1,2,3} #Set initialisation t={x for x in s if x!=3} #Set comprehension t=={1,2} </code></pre> <p>What version is it in? I also noticed that it has set comprehension. Was this added in the same version?</p> <p><strong>Resources</strong></p> <ul> <li><a hr...
3
2009-10-23T06:07:10Z
2,056,133
<p>The set literal and set and dict comprehension syntaxes were backported to 2.x trunk, about 2-3 days ago. So I guess this feature should be available from python 2.7.</p>
0
2010-01-13T11:13:48Z
[ "python" ]
Using non-hashable Python objects as keys in dictionaries
1,611,797
<p>Python doesn't allow non-hashable objects to be used as keys in other dictionaries. As pointed out by Andrey Vlasovskikh, there is a nice workaround for the special case of using non-nested dictionaries as keys:</p> <pre><code>frozenset(a.items())#Can be put in the dictionary instead </code></pre> <p>Is there a me...
3
2009-10-23T07:02:31Z
1,611,814
<p>With <a href="http://stackoverflow.com/questions/1611797/using-nested-python-dictionaries-as-keys/1611814#1611814">recursion</a>!</p> <pre><code>def make_hashable(h): items = h.items() for item in items: if type(items) == dict: item = make_hashable(item) return frozenset(items) </cod...
1
2009-10-23T07:07:16Z
[ "python" ]
Using non-hashable Python objects as keys in dictionaries
1,611,797
<p>Python doesn't allow non-hashable objects to be used as keys in other dictionaries. As pointed out by Andrey Vlasovskikh, there is a nice workaround for the special case of using non-nested dictionaries as keys:</p> <pre><code>frozenset(a.items())#Can be put in the dictionary instead </code></pre> <p>Is there a me...
3
2009-10-23T07:02:31Z
1,611,827
<p>Don't. I agree with Andreys comment on the previous question that is doesn't make sense to have dictionaries as keys, and especially not nested ones. Your data-model is obviously quite complex, and dictionaries are probably not the right answer. You should try some OO instead.</p>
8
2009-10-23T07:11:32Z
[ "python" ]
Using non-hashable Python objects as keys in dictionaries
1,611,797
<p>Python doesn't allow non-hashable objects to be used as keys in other dictionaries. As pointed out by Andrey Vlasovskikh, there is a nice workaround for the special case of using non-nested dictionaries as keys:</p> <pre><code>frozenset(a.items())#Can be put in the dictionary instead </code></pre> <p>Is there a me...
3
2009-10-23T07:02:31Z
1,612,220
<p>If you really must, make your objects hashable. Subclass whatever you want to put in as a key, and provide a __hash__ function which returns an unique key to this object. </p> <p>To illustrate:</p> <pre><code>&gt;&gt;&gt; ("a",).__hash__() 986073539 &gt;&gt;&gt; {'a': 'b'}.__hash__() Traceback (most recent call la...
2
2009-10-23T09:01:50Z
[ "python" ]
Using non-hashable Python objects as keys in dictionaries
1,611,797
<p>Python doesn't allow non-hashable objects to be used as keys in other dictionaries. As pointed out by Andrey Vlasovskikh, there is a nice workaround for the special case of using non-nested dictionaries as keys:</p> <pre><code>frozenset(a.items())#Can be put in the dictionary instead </code></pre> <p>Is there a me...
3
2009-10-23T07:02:31Z
1,612,513
<p>Based off solution by Chris Lutz. Note that this doesn't handle objects that are changed by iteration, such as streams, nor does it handle cycles.</p> <pre><code>import collections def make_hashable(obj): """WARNING: This function only works on a limited subset of objects Make a range of objects hashable. ...
3
2009-10-23T10:10:36Z
[ "python" ]
Using non-hashable Python objects as keys in dictionaries
1,611,797
<p>Python doesn't allow non-hashable objects to be used as keys in other dictionaries. As pointed out by Andrey Vlasovskikh, there is a nice workaround for the special case of using non-nested dictionaries as keys:</p> <pre><code>frozenset(a.items())#Can be put in the dictionary instead </code></pre> <p>Is there a me...
3
2009-10-23T07:02:31Z
2,016,745
<p>I totally disagree with comments &amp; answers saying that this shouldn't be done for data model purity reason.</p> <p>A dictionary associates an object with another object using the former one as a key. Dictionaries can't be used as keys because they're not hashable. This doesn't make any less meaningful/practical...
1
2010-01-06T22:23:11Z
[ "python" ]
Using non-hashable Python objects as keys in dictionaries
1,611,797
<p>Python doesn't allow non-hashable objects to be used as keys in other dictionaries. As pointed out by Andrey Vlasovskikh, there is a nice workaround for the special case of using non-nested dictionaries as keys:</p> <pre><code>frozenset(a.items())#Can be put in the dictionary instead </code></pre> <p>Is there a me...
3
2009-10-23T07:02:31Z
5,969,226
<p>I encountered this issue when using a decorator that caches the results of previous calls based on call signature. I do not agree with the comments/answers here to the effect of "you should not do this", but I think it is important to recognize the potential for surprising and unexpected behavior when going down th...
1
2011-05-11T18:59:09Z
[ "python" ]
Using non-hashable Python objects as keys in dictionaries
1,611,797
<p>Python doesn't allow non-hashable objects to be used as keys in other dictionaries. As pointed out by Andrey Vlasovskikh, there is a nice workaround for the special case of using non-nested dictionaries as keys:</p> <pre><code>frozenset(a.items())#Can be put in the dictionary instead </code></pre> <p>Is there a me...
3
2009-10-23T07:02:31Z
6,025,884
<p>Based off solution by Chris Lutz again. </p> <pre><code>import collections def hashable(obj): if isinstance(obj, collections.Hashable): items = obj elif isinstance(obj, collections.Mapping): items = frozenset((k, hashable(v)) for k, v in obj.iteritems()) elif isinstance(obj, collections...
4
2011-05-17T03:19:56Z
[ "python" ]
Using non-hashable Python objects as keys in dictionaries
1,611,797
<p>Python doesn't allow non-hashable objects to be used as keys in other dictionaries. As pointed out by Andrey Vlasovskikh, there is a nice workaround for the special case of using non-nested dictionaries as keys:</p> <pre><code>frozenset(a.items())#Can be put in the dictionary instead </code></pre> <p>Is there a me...
3
2009-10-23T07:02:31Z
15,684,892
<p>I agree with Lennart Regebro that you don't. However I often find it useful to cache some function calls, callable object and/or Flyweight objects, since they may use keyword arguments.</p> <p>But if you really want it, try <code>pickle.dumps</code> (or <code>cPickle</code> if python 2.6) as a quick and dirty hack....
0
2013-03-28T14:48:14Z
[ "python" ]
Preserve case in ConfigParser?
1,611,799
<p>I have tried to use Python's <a href="http://docs.python.org/library/configparser.html">ConfigParser</a> module to save settings. For my app it's important that I preserve the case of each name in my sections. The docs mention that passing str() to <a href="http://docs.python.org/library/configparser.html#ConfigPars...
43
2009-10-23T07:03:53Z
1,611,877
<p>The documentation is confusing. What they mean is this:</p> <pre><code>import ConfigParser, os def get_config(): config = ConfigParser.ConfigParser() config.optionxform=str try: config.read(os.path.expanduser('~/.myrc')) return config except Exception, e: log.error(e) c = ge...
51
2009-10-23T07:33:21Z
[ "python", "configuration-files", "python-2.x", "configparser" ]
Preserve case in ConfigParser?
1,611,799
<p>I have tried to use Python's <a href="http://docs.python.org/library/configparser.html">ConfigParser</a> module to save settings. For my app it's important that I preserve the case of each name in my sections. The docs mention that passing str() to <a href="http://docs.python.org/library/configparser.html#ConfigPars...
43
2009-10-23T07:03:53Z
23,007,845
<p>I know this question is answered, but I thought some people might find this solution useful. This is a class that can easily replace the existing ConfigParser class.</p> <p>Edited to incorporate @OozeMeister's suggestion:</p> <pre><code>class CaseConfigParser(ConfigParser): def optionxform(self, optionstr): ...
1
2014-04-11T08:53:15Z
[ "python", "configuration-files", "python-2.x", "configparser" ]
Preserve case in ConfigParser?
1,611,799
<p>I have tried to use Python's <a href="http://docs.python.org/library/configparser.html">ConfigParser</a> module to save settings. For my app it's important that I preserve the case of each name in my sections. The docs mention that passing str() to <a href="http://docs.python.org/library/configparser.html#ConfigPars...
43
2009-10-23T07:03:53Z
23,836,686
<p>For me worked to set optionxform immediately after creating the object </p> <pre><code>config = ConfigParser.RawConfigParser() config.optionxform = str </code></pre>
10
2014-05-23T19:02:38Z
[ "python", "configuration-files", "python-2.x", "configparser" ]
Pamie and python-win32 question
1,611,852
<p>currently im making some web scrap script. and i was choice PAMIE to use my script. actually im new to python and programming. so i have no idea ,if i use PAMIE,it really helpful to make script to relate with win32-python. ok my problem is , while im making script,i was encounter two probelm. first , i want to let w...
2
2009-10-23T07:23:45Z
1,612,067
<p>PAMIE might be getting a bit dated. You could take a look at Selenium which will also automate a web browser, but is more current. </p> <p><a href="http://jimmyg.org/blog/2009/getting-started-with-selenium-and-python.html" rel="nofollow">http://jimmyg.org/blog/2009/getting-started-with-selenium-and-python.html</a><...
0
2009-10-23T08:24:38Z
[ "python", "winapi", "beautifulsoup", "pamie" ]
Python Pipes - What Happens When Reading Output Incrementally
1,612,349
<p>According to <a href="http://www.greenteapress.com/thinkpython/html/book015.html#toc159" rel="nofollow">a section</a> in <a href="http://www.greenteapress.com/thinkpython/" rel="nofollow">this presumably accurate book</a>,</p> <blockquote> <p>A common use of pipes is to read a compressed file incrementally; tha...
0
2009-10-23T09:33:58Z
1,612,486
<p>Your assumption is faulty. gunzip does not have to see the entire file to unzip it. Read the unzip file format. There's a directory, with offsets to the individual components.</p> <p>It's possible to unzip a file in pieces.</p> <p>"uncompressed file is being stored somewhere in full...right?"</p> <p>Not necess...
2
2009-10-23T10:03:38Z
[ "python", "unix", "pipe" ]
Python Pipes - What Happens When Reading Output Incrementally
1,612,349
<p>According to <a href="http://www.greenteapress.com/thinkpython/html/book015.html#toc159" rel="nofollow">a section</a> in <a href="http://www.greenteapress.com/thinkpython/" rel="nofollow">this presumably accurate book</a>,</p> <blockquote> <p>A common use of pipes is to read a compressed file incrementally; tha...
0
2009-10-23T09:33:58Z
1,612,646
<p>This really comes from <code>gunzip</code> implementation, not from python. It is written in C. It probably uses <code>fwrite()</code> from C's <code>stdio.h</code> to write its output.</p> <p><code>libc6</code> implementation I use automatically creates an output buffer, and when it is filled, blocks on <code>fwri...
1
2009-10-23T10:44:31Z
[ "python", "unix", "pipe" ]
Python Pipes - What Happens When Reading Output Incrementally
1,612,349
<p>According to <a href="http://www.greenteapress.com/thinkpython/html/book015.html#toc159" rel="nofollow">a section</a> in <a href="http://www.greenteapress.com/thinkpython/" rel="nofollow">this presumably accurate book</a>,</p> <blockquote> <p>A common use of pipes is to read a compressed file incrementally; tha...
0
2009-10-23T09:33:58Z
8,809,989
<p>It's not Python that is suspending <code>gunzip</code>, it's that the kernel will stop executing <code>gunzip</code> when it tries writing (using the <code>write()</code> syscall) to a full buffer. This is called <strong>blocking on IO</strong>. The kernel maintains an internal buffer connecting the two ends of the ...
0
2012-01-10T20:23:01Z
[ "python", "unix", "pipe" ]
Including non-Python files with setup.py
1,612,733
<p>How do I make <code>setup.py</code> include a file that isn't part of the code? (Specifically, it's a license file, but it could be any other thing.)</p> <p>I want to be able to control the location of the file. In the original source folder, the file is in the root of the package. (i.e. on the same level as the to...
67
2009-10-23T11:04:57Z
1,613,085
<p>Figured out a workaround: I renamed my <code>lgpl2.1_license.txt</code> to <code>lgpl2.1_license.txt.py</code>, and put some triple quotes around the text. Now I don't need to use the <code>data_files</code> option nor to specify any absolute paths. Making it a Python module is ugly, I know, but I consider it less u...
-11
2009-10-23T12:22:55Z
[ "python", "distutils" ]
Including non-Python files with setup.py
1,612,733
<p>How do I make <code>setup.py</code> include a file that isn't part of the code? (Specifically, it's a license file, but it could be any other thing.)</p> <p>I want to be able to control the location of the file. In the original source folder, the file is in the root of the package. (i.e. on the same level as the to...
67
2009-10-23T11:04:57Z
1,857,436
<p>Probably the best way to do this is to use the setuptools package_data directive. This does mean using <a href="http://peak.telecommunity.com/DevCenter/setuptools">setuptools</a> (or <a href="http://pypi.python.org/pypi/distribute/">distribute</a>) instead of distutils, but this is a very seamless "upgrade".</p> <...
69
2009-12-07T02:20:16Z
[ "python", "distutils" ]
Including non-Python files with setup.py
1,612,733
<p>How do I make <code>setup.py</code> include a file that isn't part of the code? (Specifically, it's a license file, but it could be any other thing.)</p> <p>I want to be able to control the location of the file. In the original source folder, the file is in the root of the package. (i.e. on the same level as the to...
67
2009-10-23T11:04:57Z
3,042,436
<p><strong>To accomplish what you're describing will take two steps...</strong></p> <ul> <li>The file needs to be added to the source tarball</li> <li>setup.py needs to be modified to install the data file to the source path</li> </ul> <p><strong>Step 1: To add the file to the source tarball, include it in the MANIFE...
28
2010-06-15T04:00:06Z
[ "python", "distutils" ]
Including non-Python files with setup.py
1,612,733
<p>How do I make <code>setup.py</code> include a file that isn't part of the code? (Specifically, it's a license file, but it could be any other thing.)</p> <p>I want to be able to control the location of the file. In the original source folder, the file is in the root of the package. (i.e. on the same level as the to...
67
2009-10-23T11:04:57Z
18,069,277
<p>Here is a simpler answer that worked for me. </p> <p>First, per a Python Dev's comment above, setuptools is not required:</p> <pre><code>package_data is also available to pure distutils setup scripts since 2.3. – Éric Araujo </code></pre> <p>That's great because putting a setuptools requirement on your packa...
2
2013-08-05T23:08:39Z
[ "python", "distutils" ]
Including non-Python files with setup.py
1,612,733
<p>How do I make <code>setup.py</code> include a file that isn't part of the code? (Specifically, it's a license file, but it could be any other thing.)</p> <p>I want to be able to control the location of the file. In the original source folder, the file is in the root of the package. (i.e. on the same level as the to...
67
2009-10-23T11:04:57Z
27,664,454
<p>In setup.py under setup( :</p> <pre><code>setup( name = 'foo library' ... package_data={ 'foolibrary.folderA': ['*'], # All files from folder A 'foolibrary.folderB': ['*.txt'] #All text files from folder B }, </code></pre>
3
2014-12-27T04:49:53Z
[ "python", "distutils" ]
Including non-Python files with setup.py
1,612,733
<p>How do I make <code>setup.py</code> include a file that isn't part of the code? (Specifically, it's a license file, but it could be any other thing.)</p> <p>I want to be able to control the location of the file. In the original source folder, the file is in the root of the package. (i.e. on the same level as the to...
67
2009-10-23T11:04:57Z
30,579,479
<p>I just wanted to follow up on something I found working with Python 2.7 on Centos 6. Adding the package_data or data_files as mentioned above did not work for me. I added a MANIFEST.IN with the files I wanted which put the non-python files into the tarball, but did not install them on the target machine via RPM. ...
1
2015-06-01T17:22:40Z
[ "python", "distutils" ]
Rolling my own __repr__
1,613,037
<p>I want to write my own <code>__repr__</code> for some class that I define. I want it to be similar to the default <code>&lt;__main__.O object at 0x00D229D0&gt;</code>, except have a few other details in there. How do I reproduce that <code>&lt;__main__.O object at 0x00D229D0&gt;</code> thing?</p>
1
2009-10-23T12:12:27Z
1,613,070
<p>You can write your own repr like this:</p> <pre><code>class Test (object): def __repr__(self): t = type(self) return "&lt;Instance of %s.%s at %x&gt;" % (t.__module__, t.__name__, id(self)) </code></pre>
3
2009-10-23T12:19:49Z
[ "python" ]
Rolling my own __repr__
1,613,037
<p>I want to write my own <code>__repr__</code> for some class that I define. I want it to be similar to the default <code>&lt;__main__.O object at 0x00D229D0&gt;</code>, except have a few other details in there. How do I reproduce that <code>&lt;__main__.O object at 0x00D229D0&gt;</code> thing?</p>
1
2009-10-23T12:12:27Z
1,613,075
<p>See <a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Frepr%5F%5F" rel="nofollow">http://docs.python.org/reference/datamodel.html#object.%5F%5Frepr%5F%5F</a></p> <pre><code>#!/usr/bin/env python class O(object): def __repr__(self): return '&lt;%s.%s object at 0x%x&gt;'%(self.__module_...
5
2009-10-23T12:21:20Z
[ "python" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,613,053
<p><a href="http://search.cpan.org/perldoc?XML%3A%3ATwig">XML::Twig</a> is very nice, especially because it’s not as awfully verbose as some of the other options.</p>
10
2009-10-23T12:15:56Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,613,055
<p>If you are using Perl then I would recommend <a href="https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5363190.html" rel="nofollow">XML::Simple</a>:</p> <blockquote> <p>As more and more Web sites begin using XML for their content, it's increasingly important for Web devel...
10
2009-10-23T12:16:29Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,613,059
<p>For pure XML parsing, I wouldn't use Java, C#, C++, C, etc. They tend to overcomplicate things, as in you want a banana and get the gorilla with it as well.</p> <p>Higher-level and interpreted languages such as Perl, PHP, Python, Groovy are more suitable. Perl is included in virtually every Linux distro, as is PHP ...
7
2009-10-23T12:17:16Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,613,060
<p>Python has some pretty good support for XML. From the standard library DOM packages to much more 'pythonic' libraries that parse XML directly into more usable object structures.</p> <p>There isn't really a 'right' language though... there are good XML packages for most languages nowadays.</p>
1
2009-10-23T12:17:29Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,613,062
<p>It's all going to be in the libraries.</p> <p>Python has great libraries for XML. My preference is <a href="http://codespeak.net/lxml/" rel="nofollow">lxml</a>. It uses libxml/libxslt so it's fast, but the Python binding make it really easy to use. Perl may very well have equally awesome OO libraries.</p>
6
2009-10-23T12:17:33Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,613,097
<p>Not exactly a scripting language, but you could also consider <a href="http://www.scala-lang.org/node/131" rel="nofollow">Scala</a>. You can start from <a href="http://metacircular.wordpress.com/2007/02/04/scala-makes-xml-processing-easy/" rel="nofollow">here</a>.</p>
3
2009-10-23T12:24:58Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,613,111
<p>It's not a scripting language, but Scala is great for <a href="http://www.scala-lang.org/node/131" rel="nofollow">working with XML natively</a>. Also, see this <a href="http://burak.emir.googlepages.com/scalaxbook.docbk.html" rel="nofollow">book (draft) by Burak</a>.</p>
2
2009-10-23T12:27:16Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,613,371
<p>I saw that people recommend XML::Simple if you decide on Perl.</p> <p>While XML::Simple is, indeed, very simple to use and great, is a DOM parser. As such, it is, sadly, completely unsuitable to processing large XML files as your process would run out of memory (it's a common problem for <strong>any DOM parser</str...
4
2009-10-23T13:19:17Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,613,402
<p>Reading Data out of XML files is dead easy with C# and LINQ to XML!</p> <p>Somehow, although I really love python, I found it hard to parse XML with the standard libraries.</p>
0
2009-10-23T13:23:22Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,613,567
<p>Scala's XML support is rather good, especially as XML can just be typed directly into Scala programs.</p> <p>Microsoft also did some cool integrated stuff with their <a href="http://msdn.microsoft.com/en-us/library/bb308960.aspx" rel="nofollow">LINQ for XML</a></p> <p>But I really like <a href="http://effbot.org/z...
3
2009-10-23T13:46:42Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,614,048
<p>I would say it depends like everything else. VB.NET 2008 uses XML literals, has IntelliSense for <a href="http://en.wikipedia.org/wiki/Language%5FIntegrated%5FQuery#LINQ%5Fto%5FXML" rel="nofollow">LINQ to XML</a>, and a few power toys that help turn XML into <a href="http://en.wikipedia.org/wiki/XML%5FSchema%5F%28W...
0
2009-10-23T15:00:38Z
[ "python", "xml", "ruby", "perl" ]
Parsing XML - right scripting languages / packages for the job?
1,613,042
<p>I know that any language is capable of parsing XML; I'm really just looking for advantages or drawbacks that you may have come across in your own experiences. Perl would be my standard go to here, but I'm open to suggestions.</p> <p>Thanks!</p> <p>UPDATE: I ended up going with XML::Simple which did a nice job, bu...
9
2009-10-23T12:13:34Z
1,633,163
<p>If you're going to use <a href="http://en.wikipedia.org/wiki/Ruby%5F%28programming%5Flanguage%29" rel="nofollow">Ruby</a> to do it then you're going to want to take a look at <a href="http://nokogiri.org/" rel="nofollow">Nokogiri</a> or <a href="http://garrickvanburen.com/archive/parsing-arbitrary-xml-namespaces-in-...
1
2009-10-27T19:36:11Z
[ "python", "xml", "ruby", "perl" ]
NumPy: Comparing Elements in Two Arrays
1,613,249
<p>Anyone ever come up to this problem? Let's say you have two arrays like the following</p> <pre><code>a = array([1,2,3,4,5,6]) b = array([1,4,5]) </code></pre> <p>Is there a way to compare what elements in a exist in b? For example,</p> <pre><code>c = a == b # Wishful example here print c array([1,4,5]) # Or even ...
30
2009-10-23T12:57:26Z
1,613,267
<p>Your example implies set-like behavior, caring more about <em>existance in the array</em> than having the right element at the right place. Numpy does this differently with its mathematical arrays and matrices, it will tell you only about items at the exact right spot. Can you make that work for you?</p> <pre><code...
-2
2009-10-23T13:00:59Z
[ "python", "numpy" ]
NumPy: Comparing Elements in Two Arrays
1,613,249
<p>Anyone ever come up to this problem? Let's say you have two arrays like the following</p> <pre><code>a = array([1,2,3,4,5,6]) b = array([1,4,5]) </code></pre> <p>Is there a way to compare what elements in a exist in b? For example,</p> <pre><code>c = a == b # Wishful example here print c array([1,4,5]) # Or even ...
30
2009-10-23T12:57:26Z
1,613,531
<p>Thanks for your reply kaizer.se. It's not quite what I was looking for, but with a suggestion from a friend and what you said I came up with the following. </p> <pre><code>import numpy as np a = np.array([1,4,5]).astype(np.float32) b = np.arange(10).astype(np.float32) # Assigning matching values from a in b as np...
2
2009-10-23T13:42:23Z
[ "python", "numpy" ]
NumPy: Comparing Elements in Two Arrays
1,613,249
<p>Anyone ever come up to this problem? Let's say you have two arrays like the following</p> <pre><code>a = array([1,2,3,4,5,6]) b = array([1,4,5]) </code></pre> <p>Is there a way to compare what elements in a exist in b? For example,</p> <pre><code>c = a == b # Wishful example here print c array([1,4,5]) # Or even ...
30
2009-10-23T12:57:26Z
1,613,597
<p>Numpy has a set function numpy.setmember1d() that works on sorted and uniqued arrays and returns exactly the boolean array that you want. If the input arrays don't match the criteria you'll need to convert to the set format and invert the transformation on the result.</p> <pre><code>import numpy as np a = np.array(...
2
2009-10-23T13:51:04Z
[ "python", "numpy" ]
NumPy: Comparing Elements in Two Arrays
1,613,249
<p>Anyone ever come up to this problem? Let's say you have two arrays like the following</p> <pre><code>a = array([1,2,3,4,5,6]) b = array([1,4,5]) </code></pre> <p>Is there a way to compare what elements in a exist in b? For example,</p> <pre><code>c = a == b # Wishful example here print c array([1,4,5]) # Or even ...
30
2009-10-23T12:57:26Z
1,614,065
<p>Use np.intersect1d. </p> <pre><code>#!/usr/bin/env python import numpy as np a = np.array([1,2,3,4,5,6]) b = np.array([1,4,5]) c=np.intersect1d(a,b) print(c) # [1 4 5] </code></pre> <p>Note that np.intersect1d gives the wrong answer if a or b have nonunique elements. In that case use np.intersect1d_nu.</p> <p>The...
15
2009-10-23T15:03:24Z
[ "python", "numpy" ]
NumPy: Comparing Elements in Two Arrays
1,613,249
<p>Anyone ever come up to this problem? Let's say you have two arrays like the following</p> <pre><code>a = array([1,2,3,4,5,6]) b = array([1,4,5]) </code></pre> <p>Is there a way to compare what elements in a exist in b? For example,</p> <pre><code>c = a == b # Wishful example here print c array([1,4,5]) # Or even ...
30
2009-10-23T12:57:26Z
1,614,114
<p>ebresset, <a href="http://stackoverflow.com/questions/1613249/numpy-comparing-elements-in-two-arrays/1613531#1613531">your answer</a> won't work unless a is a subset of b (and a and b are sorted). Otherwise the searchsorted will return false indices. I had to do something similar, and combining that with your code...
0
2009-10-23T15:11:05Z
[ "python", "numpy" ]
NumPy: Comparing Elements in Two Arrays
1,613,249
<p>Anyone ever come up to this problem? Let's say you have two arrays like the following</p> <pre><code>a = array([1,2,3,4,5,6]) b = array([1,4,5]) </code></pre> <p>Is there a way to compare what elements in a exist in b? For example,</p> <pre><code>c = a == b # Wishful example here print c array([1,4,5]) # Or even ...
30
2009-10-23T12:57:26Z
4,381,711
<p>Actually, there's an even simpler solution than any of these:</p> <pre><code>import numpy as np a = array([1,2,3,4,5,6]) b = array([1,4,5]) c = np.in1d(a,b) </code></pre> <p>The resulting c is then:</p> <pre><code>array([ True, False, False, True, True, False], dtype=bool) </code></pre>
34
2010-12-07T21:19:57Z
[ "python", "numpy" ]
In python, how can I do a non-blocking system call?
1,613,713
<p>In Python, is it possible to do a non-blocking system call without forking off a thread? i.e., can I avoid:</p> <pre><code>import thread thread.start_new_thread(os.system,('cmd',)) </code></pre>
8
2009-10-23T14:09:03Z
1,613,741
<p>Use the <a href="http://docs.python.org/library/subprocess.html">subprocess</a> module (Popen) and have the result written to a file. You can either "wait" for the subprocess to terminate or proceed with other business and poll for the result in the file etc.</p>
10
2009-10-23T14:13:23Z
[ "python" ]
Accessing Facebook Connect FBML cookie via PyFacebook?
1,613,772
<p>Is it possible, having logged in via a Facebook Connect FBML button, to retrieve and use the session details via <a href="http://github.com/sciyoshi/pyfacebook/" rel="nofollow">PyFacebook</a>? Can i use auth.getSession() in the same way as if I'd fired the login via Python? </p> <p>Basically I'm trying to work out ...
1
2009-10-23T14:17:08Z
1,614,122
<p>Using the <a href="http://wiki.developers.facebook.com/index.php/Verifying%5FThe%5FSignature" rel="nofollow">Verifying the Facebook User</a> page on the developer wiki I tracked down the PyFacebook <em>getSession</em>, *validate_signature* and <em>getLoggedInUser</em> methods and along with the code found in PyFaceb...
1
2009-10-23T15:12:04Z
[ "python", "facebook", "cookies" ]
Accessing Facebook Connect FBML cookie via PyFacebook?
1,613,772
<p>Is it possible, having logged in via a Facebook Connect FBML button, to retrieve and use the session details via <a href="http://github.com/sciyoshi/pyfacebook/" rel="nofollow">PyFacebook</a>? Can i use auth.getSession() in the same way as if I'd fired the login via Python? </p> <p>Basically I'm trying to work out ...
1
2009-10-23T14:17:08Z
1,776,968
<p>I'm not sure if this answers your question and, admittedly, I might be leading you astray because I'm new at this (just rolled my own facebook auth backend using pyfacebook about 30 minutes ago):</p> <p>First, I installed the pyfacebook middleware (letting me call request.facebook in any view):</p> <pre><code>'fac...
0
2009-11-21T22:20:14Z
[ "python", "facebook", "cookies" ]
Python Debugging: code editing on the fly
1,613,927
<p>I am new to python and haven't been able to find out whether this is possible or not.</p> <p>I am using the PyDev plugin under Eclipse, and basically all I want to find out is, is it possible to edit code whilst you're sitting at a breakpoint? I.e. Edit code whilst you're debugging.</p> <p>It allows me to do this ...
6
2009-10-23T14:41:46Z
1,614,052
<p>When you start a Python program, it will be compiled into bytecode (and possibly saved as <code>.pyc</code> file). That means you can change the source but since you don't "open" the source again, the change won't be picked up.</p> <p>There are systems like TurboGears (a web framework) which detect these changes an...
2
2009-10-23T15:01:03Z
[ "python", "debugging", "pydev" ]
Python Debugging: code editing on the fly
1,613,927
<p>I am new to python and haven't been able to find out whether this is possible or not.</p> <p>I am using the PyDev plugin under Eclipse, and basically all I want to find out is, is it possible to edit code whilst you're sitting at a breakpoint? I.e. Edit code whilst you're debugging.</p> <p>It allows me to do this ...
6
2009-10-23T14:41:46Z
1,614,269
<p>PyDev supports this to some extend since version 1.4.8, see the <a href="http://pydev.org/history_pydev.html" rel="nofollow">change notes</a> and the corresponding <a href="http://pydev.blogspot.com/2009/08/pydev-148-released-live-coding-in-pydev.html" rel="nofollow">blog entry</a>.</p>
4
2009-10-23T15:38:41Z
[ "python", "debugging", "pydev" ]
Python Debugging: code editing on the fly
1,613,927
<p>I am new to python and haven't been able to find out whether this is possible or not.</p> <p>I am using the PyDev plugin under Eclipse, and basically all I want to find out is, is it possible to edit code whilst you're sitting at a breakpoint? I.e. Edit code whilst you're debugging.</p> <p>It allows me to do this ...
6
2009-10-23T14:41:46Z
6,309,211
<p>You can run arbitrary commands in the console during the breakpoint. For my needs, this typically achieves the same purpose as coding live, although I do with it were as elegant as simply using the editor.</p>
2
2011-06-10T16:17:48Z
[ "python", "debugging", "pydev" ]
How to make Python speak
1,614,059
<p>How could I make Python say some text?</p> <p>I could use Festival with subprocess but I won't be able to control it (or maybe in interactive mode, but it won't be clean).</p> <p>Is there a Python TTS library? Like an API for Festival, eSpeak, ... ?</p>
34
2009-10-23T15:02:10Z
1,614,098
<p>A simple Google led me to <a href="http://sourceforge.net/projects/uncassist/files/">pyTTS</a>, and a few <a href="http://mindtrove.info/articles/synthesizing-speech-with-pytts/">documents about it</a>. It looks unmaintained and specific to Microsoft's speech engine, however.</p> <p>On at least Mac OS X, you can us...
9
2009-10-23T15:08:45Z
[ "python", "text-to-speech" ]
How to make Python speak
1,614,059
<p>How could I make Python say some text?</p> <p>I could use Festival with subprocess but I won't be able to control it (or maybe in interactive mode, but it won't be clean).</p> <p>Is there a Python TTS library? Like an API for Festival, eSpeak, ... ?</p>
34
2009-10-23T15:02:10Z
1,614,167
<p>There may not be anything 'Python specific', but the KDE and GNOME desktops offer text-to-speech as a part of their accessibility support, and also offer python library bindings. It may be possible to use the python bindings to control the desktop libraries for text to speech.</p> <p>If using the Jython implementa...
2
2009-10-23T15:19:27Z
[ "python", "text-to-speech" ]
How to make Python speak
1,614,059
<p>How could I make Python say some text?</p> <p>I could use Festival with subprocess but I won't be able to control it (or maybe in interactive mode, but it won't be clean).</p> <p>Is there a Python TTS library? Like an API for Festival, eSpeak, ... ?</p>
34
2009-10-23T15:02:10Z
1,827,700
<p><strong>Please note that this only work with python 2.x</strong></p> <p>You should try using the PyTTSx package since PyTTS is outdated. PyTTSx works with the lastest python version. </p> <p><a href="http://pypi.python.org/pypi/pyttsx/1.0" rel="nofollow">http://pypi.python.org/pypi/pyttsx/1.0</a> -> The package</p...
25
2009-12-01T17:30:43Z
[ "python", "text-to-speech" ]
How to make Python speak
1,614,059
<p>How could I make Python say some text?</p> <p>I could use Festival with subprocess but I won't be able to control it (or maybe in interactive mode, but it won't be clean).</p> <p>Is there a Python TTS library? Like an API for Festival, eSpeak, ... ?</p>
34
2009-10-23T15:02:10Z
18,428,496
<p>A bit cheesy, but if you use a mac you can pass a terminal command to the console from python. </p> <p>Try typing the following in the terminal:</p> <pre><code>$ say 'hello world' </code></pre> <p>And there will be a voice from the mac that will speak that. From python such a thing is relatively easy: </p> <pre...
13
2013-08-25T11:27:23Z
[ "python", "text-to-speech" ]
How to make Python speak
1,614,059
<p>How could I make Python say some text?</p> <p>I could use Festival with subprocess but I won't be able to control it (or maybe in interactive mode, but it won't be clean).</p> <p>Is there a Python TTS library? Like an API for Festival, eSpeak, ... ?</p>
34
2009-10-23T15:02:10Z
24,100,605
<p>The <a href="https://launchpad.net/python-espeak">python-espeak</a> package is available in Debian, Ubuntu, Redhat, and other Linux distributions. It has recent updates, and works fine.</p> <pre><code>from espeak import espeak espeak.synth("Hello world.") </code></pre> <p>Jonathan Leaders notes that it also works...
10
2014-06-07T19:00:41Z
[ "python", "text-to-speech" ]
How to make Python speak
1,614,059
<p>How could I make Python say some text?</p> <p>I could use Festival with subprocess but I won't be able to control it (or maybe in interactive mode, but it won't be clean).</p> <p>Is there a Python TTS library? Like an API for Festival, eSpeak, ... ?</p>
34
2009-10-23T15:02:10Z
24,590,934
<p>This is what you are looking for. A complete TTS solution for the Mac. You can use this standalone or as a co-location Mac server for web apps:</p> <p><a href="http://wolfpaulus.com/jounal/mac/ttsserver/" rel="nofollow">http://wolfpaulus.com/jounal/mac/ttsserver/</a></p>
0
2014-07-05T22:03:15Z
[ "python", "text-to-speech" ]
How does `setup.py sdist` work?
1,614,086
<p>I'm trying to make a source distribution of my project with <code>setup.py sdist</code>. I already have a functioning <code>setup.py</code> that I can install with. But when I do the <code>sdist</code>, all I get is another <code>my_project</code> folder inside my <code>my_project</code> folder, a <code>MANIFEST</co...
6
2009-10-23T15:07:06Z
1,614,138
<p>the "sdist" command is for creating a "source" distribution of a package. Usually, one would combine this command with the "upload" command to distribute the package through Pypi (for example).</p>
2
2009-10-23T15:13:50Z
[ "python", "distutils" ]
How does `setup.py sdist` work?
1,614,086
<p>I'm trying to make a source distribution of my project with <code>setup.py sdist</code>. I already have a functioning <code>setup.py</code> that I can install with. But when I do the <code>sdist</code>, all I get is another <code>my_project</code> folder inside my <code>my_project</code> folder, a <code>MANIFEST</co...
6
2009-10-23T15:07:06Z
1,614,159
<p>Tarek Ziade explained this, and related software packaging tools, in <a href="http://zetcode.com/articles/packageinpython/">this article</a> called Writing a Package in Python.</p> <p>Basically, it creates a simple package by creating a release tree where everything needed to run the package is copied. This tree is...
5
2009-10-23T15:17:41Z
[ "python", "distutils" ]
How do I add text describing the code into a Python source file?
1,614,190
<p>When writing code in Python, how can you write something next to it that explains what the code is doing, but which doesn't affect the code?</p>
1
2009-10-23T15:24:32Z
1,614,200
<p>I think you're talking about <a href="http://en.wikipedia.org/wiki/Python%5Fsyntax%5Fand%5Fsemantics#Comments%5Fand%5Fdocstrings" rel="nofollow">comments</a>?</p> <p>There are plain comments, which start with <code>#</code>:</p> <pre><code>return sys.stdin.readline() # This is a comment </code></pre> <p>And...
17
2009-10-23T15:26:36Z
[ "python" ]
How do I add text describing the code into a Python source file?
1,614,190
<p>When writing code in Python, how can you write something next to it that explains what the code is doing, but which doesn't affect the code?</p>
1
2009-10-23T15:24:32Z
1,614,204
<p>Write a comment? Python comments start with <code>#</code>.</p>
2
2009-10-23T15:27:15Z
[ "python" ]
How do I add text describing the code into a Python source file?
1,614,190
<p>When writing code in Python, how can you write something next to it that explains what the code is doing, but which doesn't affect the code?</p>
1
2009-10-23T15:24:32Z
1,614,213
<p>You mean comments? Use the # character before your comment.</p> <p><a href="http://en.wikibooks.org/wiki/Python%5FProgramming/Source%5FDocumentation%5Fand%5FComments" rel="nofollow">http://en.wikibooks.org/wiki/Python%5FProgramming/Source%5FDocumentation%5Fand%5FComments</a></p> <pre> # This is a comment print("He...
2
2009-10-23T15:28:00Z
[ "python" ]
In Python, how to I convert all items in a list to floats?
1,614,236
<p>I have a script which reads a text file, and pulls decimal numbers out of it as strings, and places them into a list.</p> <p>So I have this list: <code>['0.49', '0.54', '0.54', '0.54', '0.54', '0.54', '0.55', '0.54', '0.54', '0.54', '0.55', '0.55', '0.55', '0.54', '0.55', '0.55', '0.54', '0.55', '0.55', '0.54']</co...
63
2009-10-23T15:33:00Z
1,614,247
<pre><code>[float(i) for i in lst] </code></pre> <p>to be precise, it creates a new list with float values. Unlike the <code>map</code> approach it will work in py3k.</p>
139
2009-10-23T15:34:28Z
[ "python" ]
In Python, how to I convert all items in a list to floats?
1,614,236
<p>I have a script which reads a text file, and pulls decimal numbers out of it as strings, and places them into a list.</p> <p>So I have this list: <code>['0.49', '0.54', '0.54', '0.54', '0.54', '0.54', '0.55', '0.54', '0.54', '0.54', '0.55', '0.55', '0.55', '0.54', '0.55', '0.55', '0.54', '0.55', '0.55', '0.54']</co...
63
2009-10-23T15:33:00Z
1,614,249
<p><code>map(float, mylist)</code> should do it. </p> <p>(In Python 3, map ceases to return a list object, so if you want a new list and not just something to iterate over, you either need <code>list(map(float, mylist)</code> - or use SilentGhost's answer which arguably is more pythonic.)</p>
44
2009-10-23T15:34:32Z
[ "python" ]
In Python, how to I convert all items in a list to floats?
1,614,236
<p>I have a script which reads a text file, and pulls decimal numbers out of it as strings, and places them into a list.</p> <p>So I have this list: <code>['0.49', '0.54', '0.54', '0.54', '0.54', '0.54', '0.55', '0.54', '0.54', '0.54', '0.55', '0.55', '0.55', '0.54', '0.55', '0.55', '0.54', '0.55', '0.55', '0.54']</co...
63
2009-10-23T15:33:00Z
1,614,311
<p><code>float(item)</code> do the right thing: it converts its argument to float and and return it, but it doesn't change argument in-place. A simple fix for your code is:</p> <pre><code>new_list = [] for item in list: new_list.append(float(item)) </code></pre> <p>The same code can written shorter using list com...
6
2009-10-23T15:44:43Z
[ "python" ]
In Python, how to I convert all items in a list to floats?
1,614,236
<p>I have a script which reads a text file, and pulls decimal numbers out of it as strings, and places them into a list.</p> <p>So I have this list: <code>['0.49', '0.54', '0.54', '0.54', '0.54', '0.54', '0.55', '0.54', '0.54', '0.54', '0.55', '0.55', '0.55', '0.54', '0.55', '0.55', '0.54', '0.55', '0.55', '0.54']</co...
63
2009-10-23T15:33:00Z
34,658,667
<p>You can use numpy to convert a list directly to a floating array or matrix.</p> <pre><code> import numpy as np list_ex = [1, 0] # This a list list_int = np.array(list_ex) # This is a numpy integer array </code></pre> <p>If you want to convert the integer array to a floating array then add 0. to it</p> ...
0
2016-01-07T15:13:40Z
[ "python" ]
In Python, how to I convert all items in a list to floats?
1,614,236
<p>I have a script which reads a text file, and pulls decimal numbers out of it as strings, and places them into a list.</p> <p>So I have this list: <code>['0.49', '0.54', '0.54', '0.54', '0.54', '0.54', '0.55', '0.54', '0.54', '0.54', '0.55', '0.55', '0.55', '0.54', '0.55', '0.55', '0.54', '0.55', '0.55', '0.54']</co...
63
2009-10-23T15:33:00Z
35,530,616
<p>SilentGhost's answer is the best way but for clarification:</p> <pre><code>lst = [float(x) for x in lst] </code></pre> <p>to assign the new list of floats to the old list of strings.</p>
4
2016-02-21T00:02:21Z
[ "python" ]
Dice Roller using Tkinter
1,614,244
<p>Thank you to everybody who helped answer my last <a href="http://stackoverflow.com/questions/1579741/is-there-a-random-function-in-python-that-accepts-variables">question</a>: </p> <p>My friend took the code, and has attempted to use Tkinter to make a box that we could use to make things nicer-looking, but he has b...
1
2009-10-23T15:34:24Z
1,614,421
<p>Because half the fun is trying to work it out yourself I'll give you a few hints instead of a complete program.</p> <p>You should store the variables for your input entries, so you can use them later to get the values out again, but don't do this:</p> <pre><code>entry = Entry(root,bg = 'white').pack(padx = 10, pad...
2
2009-10-23T15:59:42Z
[ "python", "random", "tkinter" ]