title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
What to do with "The input line is too long" error message?
682,799
<p>I am trying to use os.system() to call another program that takes an input and an output file. The command I use is ~250 characters due to the long folder names. </p> <p>When I try to call the command, I'm getting an error: <code>The input line is too long</code>.</p> <p>I'm guessing there's a <code>255 character ...
10
2009-03-25T18:08:42Z
682,824
<p>You should use the subprocess module instead. See <a href="http://docs.python.org/library/subprocess.html#subprocess-replacements">this</a> little doc for how to rewrite os.system calls to use subprocess.</p>
6
2009-03-25T18:15:37Z
[ "python", "command-line", "windows-console" ]
What to do with "The input line is too long" error message?
682,799
<p>I am trying to use os.system() to call another program that takes an input and an output file. The command I use is ~250 characters due to the long folder names. </p> <p>When I try to call the command, I'm getting an error: <code>The input line is too long</code>.</p> <p>I'm guessing there's a <code>255 character ...
10
2009-03-25T18:08:42Z
682,906
<p>You should use <a href="http://docs.python.org/library/subprocess.html" rel="nofollow">subprocess</a> instead of os.system.</p> <p>subprocess has the advantage of being able to change the directory for you:</p> <pre><code>import subprocess my_cwd = r"..\folder\" my_process = subprocess.Popen(["command name", "opti...
2
2009-03-25T18:38:58Z
[ "python", "command-line", "windows-console" ]
What to do with "The input line is too long" error message?
682,799
<p>I am trying to use os.system() to call another program that takes an input and an output file. The command I use is ~250 characters due to the long folder names. </p> <p>When I try to call the command, I'm getting an error: <code>The input line is too long</code>.</p> <p>I'm guessing there's a <code>255 character ...
10
2009-03-25T18:08:42Z
3,583,282
<p>Even it's a good idea to use <code>subprocess.Popen()</code>, this does not solve the issue.</p> <p><strong>Your problem is not the 255 characters limit</strong>, this was true on DOS times, later increased to 2048 for Windows NT/2000, and increased again to 8192 for Windows XP+.</p> <p>The <strong>real solution</...
16
2010-08-27T10:29:48Z
[ "python", "command-line", "windows-console" ]
What to do with "The input line is too long" error message?
682,799
<p>I am trying to use os.system() to call another program that takes an input and an output file. The command I use is ~250 characters due to the long folder names. </p> <p>When I try to call the command, I'm getting an error: <code>The input line is too long</code>.</p> <p>I'm guessing there's a <code>255 character ...
10
2009-03-25T18:08:42Z
4,378,603
<p>I got the same message but it was strange because the command was not that long (130 characters) and it used to work, it just stopped working one day. I just closed the command window and opened a new one and it worked. I have had the command window opened for a long time (maybe months, it's a remote virtual machine...
1
2010-12-07T15:52:02Z
[ "python", "command-line", "windows-console" ]
Redirecting function definitions in python
682,822
<p>This is a very contrived example as it's not easy to explain the context in which I have ended up implementing this solution. However, if anyone can answer why this particular peculiarity happens, I'd be grateful.</p> <p>The example:</p> <pre><code>class A(dict): def __init__(self): self['a'] = 'success...
2
2009-03-25T18:14:49Z
682,836
<p>This is because you can't override special class methods on the fly.</p> <p>I wasn't able to find a reference about this but is basically because they are class methods and are not allowed to be instance methods.</p>
1
2009-03-25T18:19:25Z
[ "python", "class-attributes" ]
Redirecting function definitions in python
682,822
<p>This is a very contrived example as it's not easy to explain the context in which I have ended up implementing this solution. However, if anyone can answer why this particular peculiarity happens, I'd be grateful.</p> <p>The example:</p> <pre><code>class A(dict): def __init__(self): self['a'] = 'success...
2
2009-03-25T18:14:49Z
682,877
<p>When you use brackets <em><code>[]</code></em> python looks in the class. You must set the method in the class.</p> <p>Here's your code adapted:</p> <pre><code>class A(dict): def __init__(self): self['a'] = 'success' def __getitem__(self, name): print 'getitem!' return dict.__get...
7
2009-03-25T18:29:16Z
[ "python", "class-attributes" ]
Dynamically change the choices in a wx.ComboBox()
682,923
<p>I didn't find a better way to change the different choices in a wx.ComboBox() than swap the old ComboBox with a new one. Is there a better way?</p> <p>Oerjan Pettersen</p> <pre><code>#!/usr/bin/python #20_combobox.py import wx import wx.lib.inspection class MyFrame(wx.Frame): def __init__(self, *args, **kwa...
13
2009-03-25T18:42:34Z
682,978
<p><a href="http://docs.wxwidgets.org/stable/classwx_combo_box.html" rel="nofollow">wx.ComboBox</a> derives from <a href="http://docs.wxwidgets.org/stable/classwx_item_container.html" rel="nofollow">wx.ItemContainer</a>, which has methods for <a href="http://docs.wxwidgets.org/stable/classwx_item_container.html#a8fdc00...
23
2009-03-25T18:58:43Z
[ "python", "wxpython", "wxwidgets" ]
Data Synchronization framework / algorithm for server<->device?
682,951
<p>I'm looking to implement data synchronization between servers and distributed clients. The data source on the server is mysql with django on top. The client can vary. Updates can take place on either client or server, and the connection between server and client is not reliable (eg. changes can be made on a disconne...
6
2009-03-25T18:48:46Z
683,394
<p>You may find this link useful: <a href="http://pdis.hiit.fi/pdis/download/" rel="nofollow">http://pdis.hiit.fi/pdis/download/</a></p> <p>It is the Personal Distributed Information Store (PDIS) project download page, and lists out some relevant python packages.</p>
0
2009-03-25T20:52:49Z
[ "python", "django", "synchronization" ]
Data Synchronization framework / algorithm for server<->device?
682,951
<p>I'm looking to implement data synchronization between servers and distributed clients. The data source on the server is mysql with django on top. The client can vary. Updates can take place on either client or server, and the connection between server and client is not reliable (eg. changes can be made on a disconne...
6
2009-03-25T18:48:46Z
955,216
<p>Perhaps using plain old <a href="http://www.samba.org/rsync/" rel="nofollow">rsync</a> is enough.</p>
1
2009-06-05T10:30:05Z
[ "python", "django", "synchronization" ]
Data Synchronization framework / algorithm for server<->device?
682,951
<p>I'm looking to implement data synchronization between servers and distributed clients. The data source on the server is mysql with django on top. The client can vary. Updates can take place on either client or server, and the connection between server and client is not reliable (eg. changes can be made on a disconne...
6
2009-03-25T18:48:46Z
956,790
<p>AFAIK there isnt any generic solution to this mainly due to the diverse requirements for synchronization.</p> <p>In one of our earlier projects we implemented a <a href="http://static.springsource.org/spring-batch/" rel="nofollow">Spring batching</a> based sync mechanism which relies on last updated timestamp field...
1
2009-06-05T16:18:05Z
[ "python", "django", "synchronization" ]
Can pysvn 1.6.3 be made to work with Subversion 1.6 under linux?
683,278
<p>I see no reference on their website for this. I get pysvn to configure and build, but then it fails all the test. Has anyone had any luck getting this to work under linux?</p>
0
2009-03-25T20:19:33Z
749,823
<p>No, it cannot. </p> <p>Your best bet is to use Subversion 1.5.5. See <a href="http://pysvn.tigris.org/project%5Fstatus.html" rel="nofollow">the site</a> for more details. </p>
1
2009-04-15T00:15:24Z
[ "python", "linux", "svn", "pysvn" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
683,481
<p>Here's something, a Python wrapper around the SeaMonkey Javascript interpreter... <a href="http://pypi.python.org/pypi/python-spidermonkey">http://pypi.python.org/pypi/python-spidermonkey</a></p>
15
2009-03-25T21:13:09Z
[ "javascript", "python" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
683,618
<p>There's a bridge based on JavaScriptCore (from WebKit), but it's pretty incomplete: <a href="http://code.google.com/p/pyjscore/" rel="nofollow">http://code.google.com/p/pyjscore/</a></p>
1
2009-03-25T21:47:03Z
[ "javascript", "python" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
683,682
<p>How about <a href="http://pyjs.org/" rel="nofollow">pyjs</a>?</p> <p>From the above website:</p> <blockquote> <p>pyjs is a Rich Internet Application (RIA) Development Platform for both Web and Desktop. With pyjs you can write your JavaScript-powered web applications entirely in Python.</p> </blockquote>
21
2009-03-25T22:00:23Z
[ "javascript", "python" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
683,928
<p>If your just interested in sharing complex data types between javascript and python, check out <a href="http://jsonpickle.googlecode.com/svn/docs/index.html">jsonpickle</a>. It wraps the standard Python JSON libraries, but has some smarts in serializing and deserializing Python classes and other data types. </p> <...
6
2009-03-25T23:26:03Z
[ "javascript", "python" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
684,376
<p>You might also want to check out the PyPy project - they have a Python to (anything) compiler, including Python to Javascript, C, and llvm. This allows you to write your code in Python and then compile it into Javascript as you desire.</p> <p><a href="http://codespeak.net/pypy" rel="nofollow">http://codespeak.net/...
2
2009-03-26T03:01:25Z
[ "javascript", "python" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
731,196
<p>there are two projects that allow an "obvious" transition between python objects and javascript objects, with "obvious" translations from int or float to Number and str or unicode to String: <a href="http://code.google.com/p/pyv8">PyV8</a> and, as one writer has already mentioned: <a href="http://pypi.python.org/pyp...
8
2009-04-08T18:18:28Z
[ "javascript", "python" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
4,788,789
<p>another possibility is to use XPCOM, say in XUL based apps (like firefox, thunderbird, komodo etc.)</p>
1
2011-01-25T00:27:57Z
[ "javascript", "python" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
8,181,668
<p>I was playing with Pyjon some time ago and seems manage to write Javascript's eval directly in Python and ran simple programs... Although it is not complete implementation of JS and rather an experiment. Get it here:</p> <p><a href="http://code.google.com/p/pyjon/" rel="nofollow">http://code.google.com/p/pyjon/</a>...
1
2011-11-18T11:27:41Z
[ "javascript", "python" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
25,085,533
<p><a href="https://pypi.python.org/pypi/PyExecJS" rel="nofollow">PyExecJS</a> is able to use each of PyV8, Node, JavaScriptCore, SpiderMonkey, JScript.</p> <pre><code>&gt;&gt;&gt; import execjs &gt;&gt;&gt; execjs.eval("'red yellow blue'.split(' ')") ['red', 'yellow', 'blue'] &gt;&gt;&gt; execjs.get().name 'Node.js (...
1
2014-08-01T17:24:22Z
[ "javascript", "python" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
27,460,269
<p>Use <a href="https://github.com/PiotrDabkowski/Js2Py" rel="nofollow">Js2Py</a> to translate JavaScript to Python, this is the only tool available :)</p>
1
2014-12-13T15:08:56Z
[ "javascript", "python" ]
Best way to integrate Python and JavaScript?
683,462
<p>Is it possible to integrate Python and JavaScript? For example, imagine you wanted to be able to define classes in JavaScript and use them from Python (or vice versa). If so, what's the best way? I'm interested not only if this is possible but if <strong>anyone has done it within a "serious" project or product</s...
44
2009-03-25T21:08:11Z
39,096,005
<p>This question is not exactly young, but there have come up some alternatives:</p> <ul> <li>"<a href="http://www.skulpt.org" rel="nofollow">Skulpt</a> is an <em>entirely in-browser</em> implementation of Python."</li> <li><a href="https://www.brython.info" rel="nofollow">Brython</a> - "A Python 3 implementation for ...
2
2016-08-23T08:25:03Z
[ "javascript", "python" ]
Timeout on a HTTP request in python
683,493
<p>Very occasionally when making a http request, I am waiting for an age for a response that never comes. What is the recommended way to cancel this request after a reasonable period of time?</p>
1
2009-03-25T21:17:45Z
683,519
<p>Set the HTTP request timeout.</p>
2
2009-03-25T21:22:11Z
[ "python", "httpwebrequest" ]
Timeout on a HTTP request in python
683,493
<p>Very occasionally when making a http request, I am waiting for an age for a response that never comes. What is the recommended way to cancel this request after a reasonable period of time?</p>
1
2009-03-25T21:17:45Z
683,545
<p>The timeout parameter to <a href="http://docs.python.org/library/urllib2.html#urllib2.urlopen" rel="nofollow">urllib2.urlopen</a>, or <a href="http://docs.python.org/library/httplib.html#httplib.HTTPConnection" rel="nofollow">httplib</a>. The original urllib has no such convenient feature. You can also use an asynch...
1
2009-03-25T21:28:29Z
[ "python", "httpwebrequest" ]
Timeout on a HTTP request in python
683,493
<p>Very occasionally when making a http request, I am waiting for an age for a response that never comes. What is the recommended way to cancel this request after a reasonable period of time?</p>
1
2009-03-25T21:17:45Z
683,574
<p>If you are making a lot of HTTP requests, you can change this globally by calling <a href="http://docs.python.org/library/socket.html#socket.setdefaulttimeout" rel="nofollow">socket.setdefaulttimeout</a></p>
1
2009-03-25T21:35:52Z
[ "python", "httpwebrequest" ]
How to save an xml file to disk?
683,494
<p>I did something similar to <a href="http://www.postneo.com/projects/pyxml/" rel="nofollow">this</a>, but couldn't find a way to write the result to an xml file.</p>
2
2009-03-25T21:17:56Z
683,505
<p>The code on the web page you linked to uses <code>doc.toprettyxml</code> to create a string from the XML DOM, so you can just write that string to a file:</p> <pre><code>f = open("output.xml", "w") try: f.write(doc.toprettyxml(indent=" ")) finally: f.close() </code></pre> <p>In Python 2.6 (or 2.7 I suppos...
11
2009-03-25T21:19:59Z
[ "python", "xml" ]
How to save an xml file to disk?
683,494
<p>I did something similar to <a href="http://www.postneo.com/projects/pyxml/" rel="nofollow">this</a>, but couldn't find a way to write the result to an xml file.</p>
2
2009-03-25T21:17:56Z
683,510
<pre><code>f = open('yourfile.xml', 'w') xml.dom.ext.PrettyPrint(doc, f) f.close() </code></pre>
1
2009-03-25T21:21:14Z
[ "python", "xml" ]
How to save an xml file to disk?
683,494
<p>I did something similar to <a href="http://www.postneo.com/projects/pyxml/" rel="nofollow">this</a>, but couldn't find a way to write the result to an xml file.</p>
2
2009-03-25T21:17:56Z
683,978
<p>coonj is kind of right, but xml.dom.ext.PrettyPrint is part of the increasingly neglected PyXML extension package. If you want to stay within the supplied-as-standard minidom, you'd say:</p> <pre><code>f= open('yourfile.xml', 'wb') doc.writexml(f, encoding= 'utf-8') f.close() </code></pre> <p>(Or using the ‘with...
8
2009-03-25T23:43:41Z
[ "python", "xml" ]
how to put a function and arguments into python queue?
683,542
<p>I have a python program with 2 threads ( let's name them 'source' and 'destination' ). Source thread sometimes post a message to destination thread with some arguments. Than destination thread picks a message it must call a corresponding function with aruments saved in message.</p> <p>This task can be solved multip...
8
2009-03-25T21:27:52Z
683,570
<p>Why don't you subclass Queue?</p> <pre><code> class MyQueue(Queue): # by using *args, you can have a variable number of arguments def put(self,*args): for arg in args: Queue.put(self,arg) </code></pre> <p>or, why don't you put a list?</p> <pre><code> list = [function_obj] for arg in function_args: ...
-2
2009-03-25T21:35:34Z
[ "python", "multithreading" ]
how to put a function and arguments into python queue?
683,542
<p>I have a python program with 2 threads ( let's name them 'source' and 'destination' ). Source thread sometimes post a message to destination thread with some arguments. Than destination thread picks a message it must call a corresponding function with aruments saved in message.</p> <p>This task can be solved multip...
8
2009-03-25T21:27:52Z
683,611
<p>So simple:</p> <pre><code>def DestinationThread( a ) : while True : items = q.get() func = items[0] args = items[1:] func(*args) </code></pre>
20
2009-03-25T21:46:41Z
[ "python", "multithreading" ]
how to put a function and arguments into python queue?
683,542
<p>I have a python program with 2 threads ( let's name them 'source' and 'destination' ). Source thread sometimes post a message to destination thread with some arguments. Than destination thread picks a message it must call a corresponding function with aruments saved in message.</p> <p>This task can be solved multip...
8
2009-03-25T21:27:52Z
683,612
<pre><code>from Queue import * from thread import * from time import * q = Queue() def HandleMsg( arg1, arg2 ) : print arg1, arg2 def HandleAnotherMsg( arg1, arg2, arg3 ) : print arg1, arg2, arg3 def DestinationThread() : while True : f, args = q.get() f(*args) start_new_thread( DestinationThread, tu...
7
2009-03-25T21:46:45Z
[ "python", "multithreading" ]
how to put a function and arguments into python queue?
683,542
<p>I have a python program with 2 threads ( let's name them 'source' and 'destination' ). Source thread sometimes post a message to destination thread with some arguments. Than destination thread picks a message it must call a corresponding function with aruments saved in message.</p> <p>This task can be solved multip...
8
2009-03-25T21:27:52Z
683,652
<p>It sounds like you want to use the <code>apply()</code> intrinsic or its successor:</p> <pre><code>def f(x. y): print x+y args = ( 1, 2 ) apply(f, args) # old way f(*args) # new way </code></pre>
0
2009-03-25T21:54:18Z
[ "python", "multithreading" ]
how to put a function and arguments into python queue?
683,542
<p>I have a python program with 2 threads ( let's name them 'source' and 'destination' ). Source thread sometimes post a message to destination thread with some arguments. Than destination thread picks a message it must call a corresponding function with aruments saved in message.</p> <p>This task can be solved multip...
8
2009-03-25T21:27:52Z
683,755
<p>I've used a similar construct before:</p> <pre><code>class Call: def __init__(self, fn, *args, **kwargs): self.fn = fn self.args = args self.kwargs = kwargs def __call__(self): return self.fn(*self.args, **self.kwargs) x = Call(zip, [0,1], [2,3], [4,5]) </code></pre> <p>Y...
2
2009-03-25T22:23:30Z
[ "python", "multithreading" ]
how to put a function and arguments into python queue?
683,542
<p>I have a python program with 2 threads ( let's name them 'source' and 'destination' ). Source thread sometimes post a message to destination thread with some arguments. Than destination thread picks a message it must call a corresponding function with aruments saved in message.</p> <p>This task can be solved multip...
8
2009-03-25T21:27:52Z
683,945
<p>You can create an abstract message class with a run method. Then for each function that need to be transmitted via the queue, subclass and implement the function as the run method. The sending thread will create an instance of the proper sub class and put it into the queue. The receiving thread will get an object fr...
0
2009-03-25T23:33:57Z
[ "python", "multithreading" ]
how to put a function and arguments into python queue?
683,542
<p>I have a python program with 2 threads ( let's name them 'source' and 'destination' ). Source thread sometimes post a message to destination thread with some arguments. Than destination thread picks a message it must call a corresponding function with aruments saved in message.</p> <p>This task can be solved multip...
8
2009-03-25T21:27:52Z
683,969
<p>Another interesting option is simply to pass in a lambda.</p> <pre><code>q.put(lambda: HandleMsg(1,2)) q.put(lambda: HandleAnother(8, "hello", extra="foo")) def DestinationThread() : while True : f = q.get() f() </code></pre>
10
2009-03-25T23:41:43Z
[ "python", "multithreading" ]
can you distinguish between a test & a variable setting?
684,109
<p>I like doctest but when you have complex arguments that you need to set before you pass to a function it become really hard to read.. Hence, you start using multiple lines assigning then calling the function that you would like to test.. This approach however, will report that you have multiple tests rather then the...
0
2009-03-26T00:52:51Z
684,122
<p>Prepend three periods to indicate that you want to continue the current line, like so:</p> <pre><code>def returnme(x): """ Returns what you pass &gt;&gt;&gt; y = (2, 3, 5, 7) ... returnme(y) # Note the difference here. ... # Another blank line ends this test. (2, 3, 5, 7...
5
2009-03-26T00:58:42Z
[ "python", "unit-testing", "doctest" ]
XML schema
684,117
<p>I've a schema file (.xsd), I'd like to generate a xml document using this schema. Is there any online tool available,if not what is quickest way (like couple of lines of code using vb.net).</p> <p>Thanks for your help.</p> <p>-Vuppala </p>
1
2009-03-26T00:55:46Z
684,121
<p>If I'm understanding you correct, this tool might help.</p> <p><a href="http://www.stylusstudio.com/xml%5Fgenerator.html" rel="nofollow">XML Generator</a></p> <p>It's what I usually use when working with XML.</p> <p>If you want a solution through code you can use this:</p> <pre><code>XmlTextWriter textWriter = n...
1
2009-03-26T00:58:30Z
[ "c#", "python", "ruby" ]
XML schema
684,117
<p>I've a schema file (.xsd), I'd like to generate a xml document using this schema. Is there any online tool available,if not what is quickest way (like couple of lines of code using vb.net).</p> <p>Thanks for your help.</p> <p>-Vuppala </p>
1
2009-03-26T00:55:46Z
684,123
<p>Download <a href="http://pyxsd.org/" rel="nofollow">pyXSD</a>.</p> <p>Use it to build Python class definitions from the XSD's.</p> <p>Build objects from those class definitions.</p> <p>Save the Python objects in XML notation.</p> <p>An alternative is <a href="http://www.rexx.com/~dkuhlman/generateDS.html" rel="n...
0
2009-03-26T00:58:44Z
[ "c#", "python", "ruby" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
684,186
<p>"Reload is no longer a function in Python 3. Use imp.reload() instead" copied from comments</p> <p>Use the <code>reload</code> builtin function:</p> <p><a href="https://docs.python.org/2/library/functions.html#reload">https://docs.python.org/2/library/functions.html#reload</a></p> <blockquote> <p>When <code>rel...
206
2009-03-26T01:25:34Z
[ "python" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
684,229
<blockquote> <p>So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p> </blockquote> <p>Yes, just saying <code>import</code> again gives you the existing copy of the module from <code>sys.modules</code>.</p> <p>You can say <code>reload(module)</code...
29
2009-03-26T01:46:28Z
[ "python" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
684,311
<p>See here for a good explanation of how your dependent modules won't be reloaded and the effects that can have:</p> <p><a href="http://pyunit.sourceforge.net/notes/reloading.html" rel="nofollow">http://pyunit.sourceforge.net/notes/reloading.html</a></p> <p>The way pyunit solved it was to track dependent modules by ...
3
2009-03-26T02:23:07Z
[ "python" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
685,004
<p>Basically <a href="http://docs.python.org/library/functions.html#reload">reload</a> as in allyourcode's asnwer. But it won't change underlying the code of already instantiated object or referenced functions. Extending from his answer:</p> <pre><code>#Make a simple function that prints "version 1" shell1$ echo 'def ...
9
2009-03-26T09:04:43Z
[ "python" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
685,040
<p>Not sure if this does all expected things, but you can do just like that:</p> <pre><code>&gt;&gt;&gt; del mymodule &gt;&gt;&gt; import mymodule </code></pre>
3
2009-03-26T09:22:16Z
[ "python" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
8,637,233
<p>Short answer:</p> <p>try using <a href="https://bitbucket.org/petershinners/reimport" rel="nofollow">reimport: a full featured reload for Python</a>.</p> <p>Longer answer: </p> <p>It looks like this question was asked/answered prior to the release of <a href="https://bitbucket.org/petershinners/reimport" rel="nof...
10
2011-12-26T15:58:19Z
[ "python" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
13,121,908
<p>In Python 3, the behaviour changes. </p> <pre><code>&gt;&gt;&gt; import my_stuff </code></pre> <p>... do something with my_stuff, then later:</p> <pre><code>&gt;&gt;&gt;&gt; import imp &gt;&gt;&gt;&gt; imp.reload(my_stuff) </code></pre> <p>and you get a brand new, reloaded my_stuff.</p>
20
2012-10-29T12:45:24Z
[ "python" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
22,894,171
<p>All the answers above about reload() or imp.reload() are deprecated.</p> <p>reload() is no longer a builtin function in python 3 and imp.reload() is marked deprecated (see help(imp)).</p> <p>It's better to use <a href="https://docs.python.org/3.4/library/importlib.html#importlib.reload"><code>importlib.reload()</c...
102
2014-04-06T12:41:19Z
[ "python" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
30,608,568
<pre><code>import sys del sys.modules['module_name'] </code></pre>
0
2015-06-02T23:59:11Z
[ "python" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
34,201,014
<p>dragonfly's answer worked for me (python 3.4.3).</p> <pre><code>import sys del sys.modules['module_name'] </code></pre> <p>Here is a lower level solution :</p> <pre><code>exec(open("MyClass.py").read(), globals()) </code></pre>
-2
2015-12-10T11:42:49Z
[ "python" ]
How to re import an updated package while in Python Interpreter?
684,171
<p>I often test my module in the Python Interpreter, and when I see an error, I quickly update the .py file. But how do I make it reflect on the Interpreter ? So, far I have been exiting and reentering the Interpreter because re importing the file again is not working for me.</p>
252
2009-03-26T01:19:41Z
36,375,742
<p>No matter how many times you import a module, you'll get the same copy of the module from <code>sys.modules</code> - which was loaded at first <code>import mymodule</code></p> <p>I am answering this late, as each of the above/previous answer has a bit of the answer, so I am attempting to sum it all up in a single a...
7
2016-04-02T16:22:16Z
[ "python" ]
Django Template if tag not working under FastCGI when checking bool True
684,371
<p>I have a strange issue specific to my Django deployment under Python 2.6 + Ubuntu + Apache 2.2 + FastCGI.</p> <p>If I have a template as such:</p> <pre><code>{% with True as something %} {%if something%} It Worked!!! {%endif%} {%endwith%} </code></pre> <p>it should output the string "It Worked!!!". It...
2
2009-03-26T02:57:46Z
684,430
<p>Hmm... <code>True</code> is not a valid token in django template language, is it? I have no idea how it worked locally -- unless it's being added to the context with a non-zero value somewhere. Therefore, I think your second problem may not be related to the first one.</p>
3
2009-03-26T03:37:50Z
[ "python", "django", "templates", "fastcgi", "python-2.6" ]
Is it safe to yield from within a "with" block in Python (and why)?
685,046
<p>The combination of coroutines and resource acquisition seems like it could have some unintended (or unintuitive) consequences.</p> <p>The basic question is whether or not something like this works:</p> <pre><code>def coroutine(): with open(path, 'r') as fh: for line in fh: yield line </code...
33
2009-03-26T09:24:56Z
685,157
<p>I don't really understand what conflict you're asking about, nor the problem with the example: it's fine to have two coexisting, independent handles to the same file.</p> <p>One thing I didn't know that I learned in response to your question it that there is a new close() method on generators:</p> <blockquote> <...
17
2009-03-26T10:12:08Z
[ "python", "resources", "coroutine" ]
Is it safe to yield from within a "with" block in Python (and why)?
685,046
<p>The combination of coroutines and resource acquisition seems like it could have some unintended (or unintuitive) consequences.</p> <p>The basic question is whether or not something like this works:</p> <pre><code>def coroutine(): with open(path, 'r') as fh: for line in fh: yield line </code...
33
2009-03-26T09:24:56Z
685,179
<p>That would be how I expected things to work. Yes, the block will not release its resources until it completes, so in that sense the resource has escaped it's lexical nesting. However but this is no different to making a function call that tried to use the same resource within a with block - nothing helps you in the...
0
2009-03-26T10:19:42Z
[ "python", "resources", "coroutine" ]
Is it safe to yield from within a "with" block in Python (and why)?
685,046
<p>The combination of coroutines and resource acquisition seems like it could have some unintended (or unintuitive) consequences.</p> <p>The basic question is whether or not something like this works:</p> <pre><code>def coroutine(): with open(path, 'r') as fh: for line in fh: yield line </code...
33
2009-03-26T09:24:56Z
685,248
<p>I don't think there is a real conflict. You just have to be aware that the generator is just like any other object that holds resources, so it is the creator's responsibility to make sure it is properly finalized (and to avoid conflicts/deadlock with the resources held by the object). The only (minor) problem I see ...
8
2009-03-26T10:44:15Z
[ "python", "resources", "coroutine" ]
Is it safe to yield from within a "with" block in Python (and why)?
685,046
<p>The combination of coroutines and resource acquisition seems like it could have some unintended (or unintuitive) consequences.</p> <p>The basic question is whether or not something like this works:</p> <pre><code>def coroutine(): with open(path, 'r') as fh: for line in fh: yield line </code...
33
2009-03-26T09:24:56Z
685,249
<p>Because <code>yield</code> can execute arbitrary code, I'd be very wary of holding a lock over a yield statement. You can get a similar effect in lots of other ways, though, including calling a method or functions which might be have been overridden or otherwise modified.</p> <p>Generators, however, are always (nea...
1
2009-03-26T10:44:54Z
[ "python", "resources", "coroutine" ]
separate threads in pygtk application
685,224
<p>I'm having some problems threading my pyGTK application. I give the thread some time to complete its task, if there is a problem I just continue anyway but warn the user. However once I continue, this thread stops until gtk.main_quit is called. This is confusing me.</p> <p>The relevant code:</p> <pre><code>clas...
4
2009-03-26T10:36:01Z
686,045
<p>Firstly, don't subclass <code>threading.Thread</code>, use <code>Thread(target=callable).start()</code>.</p> <p>Secondly, and probably the cause of your apparent block is that <code>gtk.main_iteration</code> takes a parameter <code>block</code>, which defaults to <code>True</code>, so your call to <code>gtk.main_it...
8
2009-03-26T14:31:59Z
[ "python", "multithreading", "pygtk" ]
Hierarchy / Flyweight / Instancing Problem in Python
685,253
<p>Here is the problem I am trying to solve, (I have simplified the actual problem, but this should give you all the relevant information). I have a hierarchy like so:</p> <pre><code>1.A 1.B 1.C 2.A 3.D 4.B 5.F </code></pre> <p>(This is hard to illustrate - each number is the parent, each letter is the child).</p> <...
0
2009-03-26T10:45:11Z
685,387
<p>A basic approach will use builtin data types. If I get your drift, the <code>Letter</code> object should be created by a factory with a <code>dict</code> cache to keep previously generated <code>Letter</code> objects. The factory will create only one <code>Letter</code> object for each key.</p> <p>A <code>Number</c...
0
2009-03-26T11:34:52Z
[ "python", "design", "design-patterns" ]
Hierarchy / Flyweight / Instancing Problem in Python
685,253
<p>Here is the problem I am trying to solve, (I have simplified the actual problem, but this should give you all the relevant information). I have a hierarchy like so:</p> <pre><code>1.A 1.B 1.C 2.A 3.D 4.B 5.F </code></pre> <p>(This is hard to illustrate - each number is the parent, each letter is the child).</p> <...
0
2009-03-26T10:45:11Z
687,024
<blockquote> <p>Creating an instance of the 'letter' objects is expensive (IO, database costs, etc), so should only be done once.</p> </blockquote> <p>This is where I'd begin. It seems like it would be easy to get out of the way and would give you a lot more freedom to implement the last 6.</p> <p>Perhaps you coul...
0
2009-03-26T18:32:27Z
[ "python", "design", "design-patterns" ]
Hierarchy / Flyweight / Instancing Problem in Python
685,253
<p>Here is the problem I am trying to solve, (I have simplified the actual problem, but this should give you all the relevant information). I have a hierarchy like so:</p> <pre><code>1.A 1.B 1.C 2.A 3.D 4.B 5.F </code></pre> <p>(This is hard to illustrate - each number is the parent, each letter is the child).</p> <...
0
2009-03-26T10:45:11Z
1,615,837
<p>I wonder if you have made this problem too abstract for people to give useful answers. It seems to me that you might be doing something with genetic codes, and if that is the case, you should look into <a href="http://biopython.org/wiki/Main%5FPage" rel="nofollow">BioPython</a>. Not only does it come with libraries ...
0
2009-10-23T20:54:26Z
[ "python", "design", "design-patterns" ]
querying through wmi & win32.client objects with python
685,351
<p>Could someone shed some lights upon querying through wmi and win32.client objects? </p> <p>Anytime i try to query throught win32.client object i get this error: </p> <blockquote> <p><em>Error: '' object has no attribute 'UserName'</em></p> </blockquote> <p>though, i know (wmic class "Win32_ComputerSystem", wmie...
2
2009-03-26T11:18:44Z
685,639
<p>Why are you doing this?</p> <pre><code>for objItem in colItems:{ print objItem.UserName #Error: '' object has no attribute 'UserName' } </code></pre> <p>What causes you to think that the resulting columns will be attributes of the resulting object? </p> <p>Try this to debug the problem.</p> <pre><code>fo...
0
2009-03-26T12:52:24Z
[ "python", "winapi" ]
querying through wmi & win32.client objects with python
685,351
<p>Could someone shed some lights upon querying through wmi and win32.client objects? </p> <p>Anytime i try to query throught win32.client object i get this error: </p> <blockquote> <p><em>Error: '' object has no attribute 'UserName'</em></p> </blockquote> <p>though, i know (wmic class "Win32_ComputerSystem", wmie...
2
2009-03-26T11:18:44Z
696,368
<p>Okay guys, here is another piece of code (from <a href="http://win32com.goermezer.de/content/view/211/189/" rel="nofollow">http://win32com.goermezer.de/content/view/211/189/</a>):</p> <pre><code>import win32com.client strComputer = "." objWMIService = win32com.client.Dispatch("WbemScripting.SWbemLocator") objSWbemS...
0
2009-03-30T08:10:49Z
[ "python", "winapi" ]
querying through wmi & win32.client objects with python
685,351
<p>Could someone shed some lights upon querying through wmi and win32.client objects? </p> <p>Anytime i try to query throught win32.client object i get this error: </p> <blockquote> <p><em>Error: '' object has no attribute 'UserName'</em></p> </blockquote> <p>though, i know (wmic class "Win32_ComputerSystem", wmie...
2
2009-03-26T11:18:44Z
3,954,429
<p>To find out about the "keys" and "values" in WMI query result, you can use "Properties_"</p> <pre><code>from win32com.client import Dispatch, GetObject import win32con server = Dispatch("WbemScripting.SWbemLocator") c = server.ConnectServer("localhost", "root\\cimv2") p = c.ExecQuery("Select * from Win32_Operating...
2
2010-10-17T17:41:19Z
[ "python", "winapi" ]
querying through wmi & win32.client objects with python
685,351
<p>Could someone shed some lights upon querying through wmi and win32.client objects? </p> <p>Anytime i try to query throught win32.client object i get this error: </p> <blockquote> <p><em>Error: '' object has no attribute 'UserName'</em></p> </blockquote> <p>though, i know (wmic class "Win32_ComputerSystem", wmie...
2
2009-03-26T11:18:44Z
5,159,813
<p>try to access properties of colItems this way:</p> <pre> for objItem in colItems[o].Properties_: print objItem.Name, objItem.Value </pre> <p>in other circumstances you may prefer to use </p> <pre> repr(objItem.Value) </pre> <p>and</p> <pre> repr(objItem.Value) </pre>
1
2011-03-01T20:15:58Z
[ "python", "winapi" ]
PyUnit: stop after first failing test?
685,424
<p>I'm using the following code in my testing framework:</p> <pre><code>testModules = ["test_foo", "test_bar"] suite = unittest.TestLoader().loadTestsFromNames(testModules) runner = unittest.TextTestRunner(sys.stdout, verbosity=2) results = runner.run(suite) return results.wasSuccessful() </code></pre> <p>Is there a...
6
2009-03-26T11:48:21Z
685,503
<p>It's a feature. If you want to override this, you'll need to subclass <code>TestCase</code> and/or <code>TestSuite</code> classes and override logic in the <code>run()</code> method.</p> <p>P.S.: I think you have to subclass <code>unittest.TestCase</code> and override method <code>run()</code> in your class:</p> <...
5
2009-03-26T12:12:55Z
[ "python", "unit-testing" ]
PyUnit: stop after first failing test?
685,424
<p>I'm using the following code in my testing framework:</p> <pre><code>testModules = ["test_foo", "test_bar"] suite = unittest.TestLoader().loadTestsFromNames(testModules) runner = unittest.TextTestRunner(sys.stdout, verbosity=2) results = runner.run(suite) return results.wasSuccessful() </code></pre> <p>Is there a...
6
2009-03-26T11:48:21Z
690,286
<p>Based on Eugene's guidance, I've come up with the following:</p> <pre><code>class TestCase(unittest.TestCase): def run(self, result=None): if result.failures or result.errors: print "aborted" else: super(TestCase, self).run(result) </code></pre> <p>While this works fairly well, it's a bit annoying that...
5
2009-03-27T15:44:25Z
[ "python", "unit-testing" ]
PyUnit: stop after first failing test?
685,424
<p>I'm using the following code in my testing framework:</p> <pre><code>testModules = ["test_foo", "test_bar"] suite = unittest.TestLoader().loadTestsFromNames(testModules) runner = unittest.TextTestRunner(sys.stdout, verbosity=2) results = runner.run(suite) return results.wasSuccessful() </code></pre> <p>Is there a...
6
2009-03-26T11:48:21Z
11,466,102
<p>Building on AnC's answer, this is what I'm using...</p> <pre><code>def aborting_run(self, result=None): if result.failures or result.errors: print "aborted" else: original_run(self, result) original_run = unittest.TestCase.run unittest.TestCase.run = aborting_run </code></pre>
0
2012-07-13T07:36:25Z
[ "python", "unit-testing" ]
Handling file attributes in python 3.0
685,488
<p>I am currently developing an application in python 3 and i need to be able to hide certain files from the view of people. i found a few places that used the win32api and win32con but they don't seem to exist in python 3.</p> <p>Does anyone know if this is possible without rolling back or writing my own attribute li...
1
2009-03-26T12:09:36Z
685,548
<p>You can use <a href="http://docs.python.org/library/ctypes.html" rel="nofollow">ctypes</a> to directly access functions from kernel32.dll. </p> <p>The function you're looking for is <code>windll.kernel32.SetFileAttributesA</code></p>
3
2009-03-26T12:28:01Z
[ "python", "windows", "python-3.x" ]
Handling file attributes in python 3.0
685,488
<p>I am currently developing an application in python 3 and i need to be able to hide certain files from the view of people. i found a few places that used the win32api and win32con but they don't seem to exist in python 3.</p> <p>Does anyone know if this is possible without rolling back or writing my own attribute li...
1
2009-03-26T12:09:36Z
685,599
<p>You need the <a href="http://sourceforge.net/project/showfiles.php?group%5Fid=78018&amp;package%5Fid=79063&amp;release%5Fid=661475">pywin32</a> Python Extensions for Windows. Recently released for Python 3.</p>
5
2009-03-26T12:40:05Z
[ "python", "windows", "python-3.x" ]
python convert microsoft office docs to plain text on linux
685,533
<p>Any recomendations on a method to convert .doc, .ppt, and .xls to plain text on linux using python? Really any method of conversion would be useful. I have already looked at using Open Office but, I would like a solution that does not require having to install Open Office.</p>
11
2009-03-26T12:24:44Z
685,546
<p>The usual tool for converting Microsoft Office documents to HTML or other formats was mswordview, which has since been renamed to <a href="http://wvware.sourceforge.net/" rel="nofollow">vwWare</a>.</p> <p>If you're looking for a command-line tool, they actually recommend using AbiWord to perform the conversion:</p>...
5
2009-03-26T12:27:42Z
[ "python", "linux", "ms-office" ]
python convert microsoft office docs to plain text on linux
685,533
<p>Any recomendations on a method to convert .doc, .ppt, and .xls to plain text on linux using python? Really any method of conversion would be useful. I have already looked at using Open Office but, I would like a solution that does not require having to install Open Office.</p>
11
2009-03-26T12:24:44Z
685,558
<p>For dealing with Excel Spreadsheets <a href="http://pypi.python.org/pypi/xlwt" rel="nofollow">xlwt</a> is good. But it won't help with <code>.doc</code> and <code>.ppt</code> files.</p> <p>(You may have also heard of PyExcelerator. xlwt is a fork of this and better maintained so I think you'd be better of with xl...
1
2009-03-26T12:31:10Z
[ "python", "linux", "ms-office" ]
python convert microsoft office docs to plain text on linux
685,533
<p>Any recomendations on a method to convert .doc, .ppt, and .xls to plain text on linux using python? Really any method of conversion would be useful. I have already looked at using Open Office but, I would like a solution that does not require having to install Open Office.</p>
11
2009-03-26T12:24:44Z
685,562
<p>You can access <a href="http://wiki.services.openoffice.org/wiki/Python" rel="nofollow">OpenOffice via Python API</a>.</p> <p>Try using this as a base: <a href="http://wiki.services.openoffice.org/wiki/Odt2txt.py" rel="nofollow">http://wiki.services.openoffice.org/wiki/Odt2txt.py</a></p>
9
2009-03-26T12:32:11Z
[ "python", "linux", "ms-office" ]
python convert microsoft office docs to plain text on linux
685,533
<p>Any recomendations on a method to convert .doc, .ppt, and .xls to plain text on linux using python? Really any method of conversion would be useful. I have already looked at using Open Office but, I would like a solution that does not require having to install Open Office.</p>
11
2009-03-26T12:24:44Z
685,583
<p>At the command line, <a href="http://www.winfield.demon.nl/" rel="nofollow">antiword</a> or <a href="http://wvware.sourceforge.net/" rel="nofollow">wv</a> work very nicely for .doc files. (Not a Python solution, but they're easy to install and fast.)</p>
1
2009-03-26T12:36:45Z
[ "python", "linux", "ms-office" ]
python convert microsoft office docs to plain text on linux
685,533
<p>Any recomendations on a method to convert .doc, .ppt, and .xls to plain text on linux using python? Really any method of conversion would be useful. I have already looked at using Open Office but, I would like a solution that does not require having to install Open Office.</p>
11
2009-03-26T12:24:44Z
685,656
<p>I've had some success at using XSLT to process the XML-based office files into something usable in the past. It's not necessarily a python-based solution, but it does get the job done.</p>
0
2009-03-26T12:56:01Z
[ "python", "linux", "ms-office" ]
python convert microsoft office docs to plain text on linux
685,533
<p>Any recomendations on a method to convert .doc, .ppt, and .xls to plain text on linux using python? Really any method of conversion would be useful. I have already looked at using Open Office but, I would like a solution that does not require having to install Open Office.</p>
11
2009-03-26T12:24:44Z
687,876
<p>I'd go for the command line-solution (and then use the <a href="http://docs.python.org/library/subprocess.html">Python subprocess module</a> to run the tools from Python).</p> <p>Convertors for msword (<strong>catdoc</strong>), excel (<strong>xls2csv</strong>) and ppt (<strong>catppt</strong>) can be found (in sour...
8
2009-03-26T22:57:39Z
[ "python", "linux", "ms-office" ]
python convert microsoft office docs to plain text on linux
685,533
<p>Any recomendations on a method to convert .doc, .ppt, and .xls to plain text on linux using python? Really any method of conversion would be useful. I have already looked at using Open Office but, I would like a solution that does not require having to install Open Office.</p>
11
2009-03-26T12:24:44Z
4,229,904
<p>Interestingly enough, it looks like if you use OpenOffice to create a .ppt file, (saving it as Microsoft PowerPoint 97/2000/XP), then catppt will fail to extract the words from it. </p>
0
2010-11-19T22:21:31Z
[ "python", "linux", "ms-office" ]
python convert microsoft office docs to plain text on linux
685,533
<p>Any recomendations on a method to convert .doc, .ppt, and .xls to plain text on linux using python? Really any method of conversion would be useful. I have already looked at using Open Office but, I would like a solution that does not require having to install Open Office.</p>
11
2009-03-26T12:24:44Z
9,243,843
<p>Same problem here. Below is my simple script to convert all doc files in dir 'docs/' to dir 'txts/' using catdoc. Hope it will help someone:</p> <pre><code>#!/usr/bin/env python # -*- coding: utf-8 -*- import glob, re, os f = glob.glob('docs/*.doc') + glob.glob('docs/*.DOC') outDir = 'txts' if not os.path.exists...
1
2012-02-11T20:36:52Z
[ "python", "linux", "ms-office" ]
Problem using Python comtypes library to add a querytable to Excel
685,589
<p>I'm trying to create a QueryTable in an excel spreadsheet using the Python comtypes library, but getting a rather uninformative error...</p> <p>In vba (in a module within the workbook), the following code works fine:</p> <pre><code>Sub CreateQuery() Dim con As ADODB.Connection Dim rs As ADODB.Recordset ...
5
2009-03-26T12:37:53Z
685,690
<p>It looks like your error is on this line:</p> <pre><code>qt = ws.QueryTables.Add(rs, ws.Range["A1"]) </code></pre> <p>I think your problem is that you are using python syntax to look up a value in a VBA Collection. Try changing your square brackets to parentheses.</p> <p>i.e.</p> <pre><code>qt = ws.QueryTables....
1
2009-03-26T13:05:30Z
[ "python", "excel", "vba", "com", "comtypes" ]
Problem using Python comtypes library to add a querytable to Excel
685,589
<p>I'm trying to create a QueryTable in an excel spreadsheet using the Python comtypes library, but getting a rather uninformative error...</p> <p>In vba (in a module within the workbook), the following code works fine:</p> <pre><code>Sub CreateQuery() Dim con As ADODB.Connection Dim rs As ADODB.Recordset ...
5
2009-03-26T12:37:53Z
686,763
<p>I simplified your code and this should work fine (I'll explain the changes below):</p> <pre><code>def create_querytable2(): constring = "OLEDB;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\path\to\db.mdb;" SQL = "Select * from tblName;" excel = client.CreateObject("Excel.Application", dynamic=True) ...
2
2009-03-26T17:23:07Z
[ "python", "excel", "vba", "com", "comtypes" ]
In Python, how do I take a list and reduce it to a list of duplicates?
685,671
<p>I have a list of strings that should be unique. I want to be able to check for duplicates quickly. Specifically, I'd like to be able to take the original list and produce a new list containing any repeated items. I don't care how many times the items are repeated so it doesn't have to have a word twice if there are ...
0
2009-03-26T13:01:52Z
685,694
<p>This code should work:</p> <pre><code>duplicates = set() found = set() for item in source: if item in found: duplicates.add(item) else: found.add(item) </code></pre>
19
2009-03-26T13:06:04Z
[ "python" ]
In Python, how do I take a list and reduce it to a list of duplicates?
685,671
<p>I have a list of strings that should be unique. I want to be able to check for duplicates quickly. Specifically, I'd like to be able to take the original list and produce a new list containing any repeated items. I don't care how many times the items are repeated so it doesn't have to have a word twice if there are ...
0
2009-03-26T13:01:52Z
685,705
<p>This will create the list in one line:</p> <pre><code>L = [1, 2, 3, 3, 4, 4, 4] L_dup = set([i for i in L if L.count(i) &gt; 1]) </code></pre>
4
2009-03-26T13:08:43Z
[ "python" ]
In Python, how do I take a list and reduce it to a list of duplicates?
685,671
<p>I have a list of strings that should be unique. I want to be able to check for duplicates quickly. Specifically, I'd like to be able to take the original list and produce a new list containing any repeated items. I don't care how many times the items are repeated so it doesn't have to have a word twice if there are ...
0
2009-03-26T13:01:52Z
685,710
<p>Definitely not the fastest way to do that, but it seem to work solve the problem:</p> <pre><code>&gt;&gt;&gt; lst = [23, 32, 23, None] &gt;&gt;&gt; set(i for i in lst if lst.count(i) &gt; 1) {23} </code></pre>
3
2009-03-26T13:09:41Z
[ "python" ]
In Python, how do I take a list and reduce it to a list of duplicates?
685,671
<p>I have a list of strings that should be unique. I want to be able to check for duplicates quickly. Specifically, I'd like to be able to take the original list and produce a new list containing any repeated items. I don't care how many times the items are repeated so it doesn't have to have a word twice if there are ...
0
2009-03-26T13:01:52Z
685,719
<p><code>groupby</code> from <a href="http://docs.python.org/library/itertools.html" rel="nofollow">itertools</a> will probably be useful here:</p> <pre><code> from itertools import groupby duplicated=[k for (k,g) in groupby(sorted(l)) if len(list(g)) > 1] </code></pre> <p>Basically you use it to find elements that a...
6
2009-03-26T13:12:03Z
[ "python" ]
In Python, how do I take a list and reduce it to a list of duplicates?
685,671
<p>I have a list of strings that should be unique. I want to be able to check for duplicates quickly. Specifically, I'd like to be able to take the original list and produce a new list containing any repeated items. I don't care how many times the items are repeated so it doesn't have to have a word twice if there are ...
0
2009-03-26T13:01:52Z
685,724
<p>If you don't care about the order of the duplicates:</p> <pre><code>a = [1, 2, 3, 4, 5, 4, 6, 4, 7, 8, 8] b = sorted(a) duplicates = set([x for x, y in zip(b[:-1], b[1:]) if x == y]) </code></pre>
1
2009-03-26T13:13:36Z
[ "python" ]
In Python, how do I take a list and reduce it to a list of duplicates?
685,671
<p>I have a list of strings that should be unique. I want to be able to check for duplicates quickly. Specifically, I'd like to be able to take the original list and produce a new list containing any repeated items. I don't care how many times the items are repeated so it doesn't have to have a word twice if there are ...
0
2009-03-26T13:01:52Z
685,794
<p>EDIT : Ok, doesn't work since you want duplicates only.</p> <h2>Whith python > 2.4 :</h2> <p>You have set, just do :</p> <pre><code>my_filtered_list = list(set(mylist)) </code></pre> <p>Set is a data structure that doesn't have duplicate by nature.</p> <h2>With older Python versions :</h2> <pre><code>my_filter...
-1
2009-03-26T13:29:55Z
[ "python" ]
In Python, how do I take a list and reduce it to a list of duplicates?
685,671
<p>I have a list of strings that should be unique. I want to be able to check for duplicates quickly. Specifically, I'd like to be able to take the original list and produce a new list containing any repeated items. I don't care how many times the items are repeated so it doesn't have to have a word twice if there are ...
0
2009-03-26T13:01:52Z
687,905
<p>Personally, I think this is the simplest way to do it with performance O(n). Similar to vartec's solution but no <code>import</code> required and no Python version dependencies to worry about:</p> <pre><code>def getDuplicates(iterable): d = {} for i in iterable: d[i] = d.get(i, 0) + 1 return [i ...
0
2009-03-26T23:10:18Z
[ "python" ]
In Python, how do I take a list and reduce it to a list of duplicates?
685,671
<p>I have a list of strings that should be unique. I want to be able to check for duplicates quickly. Specifically, I'd like to be able to take the original list and produce a new list containing any repeated items. I don't care how many times the items are repeated so it doesn't have to have a word twice if there are ...
0
2009-03-26T13:01:52Z
970,635
<p>the solutions based on 'set' have a small drawback, namely they only work for hashable objects.</p> <p>the solution based on itertools.groupby on the other hand works for all comparable objects (e.g.: dictionaries and lists).</p>
0
2009-06-09T15:06:01Z
[ "python" ]
In Python, how do I take a list and reduce it to a list of duplicates?
685,671
<p>I have a list of strings that should be unique. I want to be able to check for duplicates quickly. Specifically, I'd like to be able to take the original list and produce a new list containing any repeated items. I don't care how many times the items are repeated so it doesn't have to have a word twice if there are ...
0
2009-03-26T13:01:52Z
5,751,556
<p>Here's a simple 1-liner:</p> <pre><code>&gt;&gt;&gt; l = ['a', 'a', 3, 'r', 'r', 's', 's', 2, 3, 't', 'y', 'a', 'w', 'r'] &gt;&gt;&gt; [v for i, v in enumerate(l) if l[i:].count(v) &gt; 1 and l[:i].count(v) == 0] ['a', 3, 'r', 's'] </code></pre> <p><code>enumerate</code> returns an indexed list which we use to spl...
2
2011-04-22T01:49:19Z
[ "python" ]
Is there any particular reason why this syntax is used for instantiating a class?
685,713
<p>I was wondering if anyone knew of a particular reason (other than purely stylistic) why the following languages these syntaxes to initiate a class?</p> <p>Python:</p> <pre><code>class MyClass: def __init__(self): x = MyClass() </code></pre> <p>Ruby:</p> <pre><code>class AnotherClass def initialize() ...
0
2009-03-26T13:10:05Z
685,726
<p>Actually in Python the constructor is <a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Fnew%5F%5F" rel="nofollow"><code>__new__()</code></a>, while <a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Finit%5F%5F" rel="nofollow"><code>__init__()</code></a> is instance initializer....
4
2009-03-26T13:13:51Z
[ "python", "ruby", "constructor" ]
Is there any particular reason why this syntax is used for instantiating a class?
685,713
<p>I was wondering if anyone knew of a particular reason (other than purely stylistic) why the following languages these syntaxes to initiate a class?</p> <p>Python:</p> <pre><code>class MyClass: def __init__(self): x = MyClass() </code></pre> <p>Ruby:</p> <pre><code>class AnotherClass def initialize() ...
0
2009-03-26T13:10:05Z
685,751
<p>When you are creating an object of a class, you are doing more than just initializing it. You are allocating the memory for it, then initializing it, then returning it.</p> <p>Note also that in Ruby, <code>new()</code> is a class method, while <code>initialize()</code> is an instance method. If you simply overrode ...
5
2009-03-26T13:20:56Z
[ "python", "ruby", "constructor" ]
Is there any particular reason why this syntax is used for instantiating a class?
685,713
<p>I was wondering if anyone knew of a particular reason (other than purely stylistic) why the following languages these syntaxes to initiate a class?</p> <p>Python:</p> <pre><code>class MyClass: def __init__(self): x = MyClass() </code></pre> <p>Ruby:</p> <pre><code>class AnotherClass def initialize() ...
0
2009-03-26T13:10:05Z
685,756
<p>This is useful because in Python, a constructor is just another function. For example, I've done this several times:</p> <pre><code>def ClassThatShouldntBeDirectlyInstantiated(): return _classThatShouldntBeDirectlyInstantiated() class _classThatShouldntBeDirectlyInstantiated(object): ... </code></pre> <p...
0
2009-03-26T13:21:36Z
[ "python", "ruby", "constructor" ]
How to compile Python 1.0
685,732
<p>For some perverse reason, I want to try Python 1.0.. How would I go about compiling it, or rather, what is the earlier version that will compile cleanly with current compilers?</p> <p>I'm using Mac OS X 10.5, although since it's for nothing more than curiosity (about how the language has changed), compiling in a Li...
1
2009-03-26T13:16:07Z
685,753
<p>Python 1.0.1 compiles perfectly under Ubuntu 8.10 using GCC 4.3.2. It should compile under Leopard, too.</p> <p>Download the source <a href="http://www.python.org/download/releases/src/python1.0.1.tar.gz">here</a>, and compile the usual way:</p> <pre><code>./configure make </code></pre> <p><strong>UPDATE:</strong...
9
2009-03-26T13:21:13Z
[ "python", "installation", "legacy" ]
How to compile Python 1.0
685,732
<p>For some perverse reason, I want to try Python 1.0.. How would I go about compiling it, or rather, what is the earlier version that will compile cleanly with current compilers?</p> <p>I'm using Mac OS X 10.5, although since it's for nothing more than curiosity (about how the language has changed), compiling in a Li...
1
2009-03-26T13:16:07Z
688,259
<p>Going further backwards in time, I pulled the 0.9.1p1 source from alt.sources via Google Groups' archive. That's 18+ year old code!</p> <p>I made a few changes (documented in README.reconstructed) to get it to compile on my OS 10.4 box. <a href="http://www.dalkescientific.com/writings/diary/archive/2009/03/27/pytho...
4
2009-03-27T02:00:58Z
[ "python", "installation", "legacy" ]
Pythonic ways to use 'else' in a for loop
685,758
<p>I have hardly ever noticed a python program that uses else in a for loop.</p> <p>I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope.</p> <p>What is the pythonic way to use an else in a for loop? Are there any notable use cases?</p> <p>And, yea. I disl...
13
2009-03-26T13:22:32Z
685,802
<p>If you have a for loop you don't really have any condition statement. So break is your choice if you like to abort and then else can serve perfectly to handle the case where you were not happy.</p> <pre><code>for fruit in basket: if fruit.kind in ['Orange', 'Apple']: fruit.eat() break else: prin...
6
2009-03-26T13:32:16Z
[ "for-loop", "python" ]
Pythonic ways to use 'else' in a for loop
685,758
<p>I have hardly ever noticed a python program that uses else in a for loop.</p> <p>I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope.</p> <p>What is the pythonic way to use an else in a for loop? Are there any notable use cases?</p> <p>And, yea. I disl...
13
2009-03-26T13:22:32Z
685,820
<p>Without using <code>break</code>, <code>else</code> blocks have no benefit for <code>for</code> and <code>while</code> statements. The following two examples are equivalent:</p> <pre><code>for x in range(10): pass else: print "else" for x in range(10): pass print "else" </code></pre> <p>The only reason for ...
3
2009-03-26T13:36:16Z
[ "for-loop", "python" ]
Pythonic ways to use 'else' in a for loop
685,758
<p>I have hardly ever noticed a python program that uses else in a for loop.</p> <p>I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope.</p> <p>What is the pythonic way to use an else in a for loop? Are there any notable use cases?</p> <p>And, yea. I disl...
13
2009-03-26T13:22:32Z
685,833
<p>Here you go:</p> <pre><code>a = ('y','a','y') for x in a: print x, else: print '!' </code></pre> <p>It's for the caboose.</p> <p>edit:</p> <pre><code># What happens if we add the ! to a list? def side_effect(your_list): your_list.extend('!') for x in your_list: print x, claimant = ['A',' ','g','u',...
-1
2009-03-26T13:39:31Z
[ "for-loop", "python" ]
Pythonic ways to use 'else' in a for loop
685,758
<p>I have hardly ever noticed a python program that uses else in a for loop.</p> <p>I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope.</p> <p>What is the pythonic way to use an else in a for loop? Are there any notable use cases?</p> <p>And, yea. I disl...
13
2009-03-26T13:22:32Z
686,145
<p>What could be more pythonic than PyPy? </p> <p>Look at what I discovered starting at line 284 in ctypes_configure/configure.py:</p> <pre><code> for i in range(0, info['size'] - csize + 1, info['align']): if layout[i:i+csize] == [None] * csize: layout_addfield(layout, i, ctype, '_alignment')...
15
2009-03-26T14:56:44Z
[ "for-loop", "python" ]
Pythonic ways to use 'else' in a for loop
685,758
<p>I have hardly ever noticed a python program that uses else in a for loop.</p> <p>I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope.</p> <p>What is the pythonic way to use an else in a for loop? Are there any notable use cases?</p> <p>And, yea. I disl...
13
2009-03-26T13:22:32Z
696,324
<p>Perhaps the best answer comes from the official Python tutorial:</p> <p><a href="http://docs.python.org/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops" rel="nofollow">break and continue Statements, and else Clauses on Loops</a>:</p> <blockquote> <p><em>Loop statements may have ...
2
2009-03-30T07:46:48Z
[ "for-loop", "python" ]
Pythonic ways to use 'else' in a for loop
685,758
<p>I have hardly ever noticed a python program that uses else in a for loop.</p> <p>I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope.</p> <p>What is the pythonic way to use an else in a for loop? Are there any notable use cases?</p> <p>And, yea. I disl...
13
2009-03-26T13:22:32Z
1,980,927
<p>Basically, it simplifies any loop that uses a boolean flag like this:</p> <pre><code>found = False # &lt;-- initialize boolean for divisor in range(2, n): if n % divisor == 0: found = True # &lt;-- update boolean break # optional, but continuing would be a waste of time ...
4
2009-12-30T16:03:08Z
[ "for-loop", "python" ]
Pythonic ways to use 'else' in a for loop
685,758
<p>I have hardly ever noticed a python program that uses else in a for loop.</p> <p>I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope.</p> <p>What is the pythonic way to use an else in a for loop? Are there any notable use cases?</p> <p>And, yea. I disl...
13
2009-03-26T13:22:32Z
20,862,778
<p>I was introduced to a wonderful idiom in which you can use a <code>for</code>/<code>break</code>/<code>else</code> scheme with an iterator to save both time and LOC. The example at hand was searching for the candidate for an incompletely qualified path. If you care to see the original context, please see <a href="ht...
0
2013-12-31T20:15:58Z
[ "for-loop", "python" ]
mysqldb on python 2.6+ (win32)
685,869
<p>I am currently using python 2.6 and I would like to use the win32 mysqldb module. Unfortunately it seems it needs the 2.5 version of Python. Is there any way to get rid of this mismatch in the version numbers and install mysqldb with python 2.6?</p>
10
2009-03-26T13:45:56Z
686,631
<p>There are versions of mysqldb for python 2.6, they're just not available on the official site. It took me a while (and unfortunately I lost the link) but you can search google and find people who have compiled and released 2.6 versions of mysqldb for windows x64 and x32.</p> <p>EDIT:</p> <p><a href="http://sourcef...
11
2009-03-26T16:50:17Z
[ "python", "mysql" ]
mysqldb on python 2.6+ (win32)
685,869
<p>I am currently using python 2.6 and I would like to use the win32 mysqldb module. Unfortunately it seems it needs the 2.5 version of Python. Is there any way to get rid of this mismatch in the version numbers and install mysqldb with python 2.6?</p>
10
2009-03-26T13:45:56Z
1,603,137
<p>This one has both 32 and 64 versions for 2.6:<br /> <a href="http://www.codegood.com/archives/4">http://www.codegood.com/archives/4</a></p>
7
2009-10-21T19:42:56Z
[ "python", "mysql" ]