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
Verify if provided string corresponds to pattern on python
2,191,581
<p>could you please advice how to verify in python if provided string correspond to provided pattern and return result.</p> <p>For example the provided pattern is following:</p> <p>&lt; [prefix]-[id]> separated by ','>|&lt; log >"</p> <p>where prefix is any number of alphabetic characters, id is only numbers but not...
0
2010-02-03T11:44:08Z
2,191,602
<pre><code>(?:[a-z]+-\d{1,5})(?:, [a-z]+-\d{1,5})*\|.* </code></pre> <p>it's not clear what you want to capture, that's why I use non-capturing groups. If you need only boolean:</p> <pre><code>&gt;&gt;&gt; regex = '[a-z]+-\d{1,5}(?:, [a-z]+-\d{1,5})*\|.*' &gt;&gt;&gt; re.match(regex, 'proj-234, proj-345|log message')...
2
2010-02-03T11:48:44Z
[ "python", "regex", "string" ]
Verify if provided string corresponds to pattern on python
2,191,581
<p>could you please advice how to verify in python if provided string correspond to provided pattern and return result.</p> <p>For example the provided pattern is following:</p> <p>&lt; [prefix]-[id]> separated by ','>|&lt; log >"</p> <p>where prefix is any number of alphabetic characters, id is only numbers but not...
0
2010-02-03T11:44:08Z
2,191,701
<p>Extending SilentGhosts' excellent regexp...</p> <p>The following will match more than two comma separated tags and it captures the tags in one group and the log message in another group:</p> <pre><code>import re line = 'proj-234,proj-345,proj-543|log message' match = re.match('((?:[a-zA-Z]+-\d{1,5})(?:,[a-zA-Z]+-...
0
2010-02-03T12:09:02Z
[ "python", "regex", "string" ]
Python: feedback / corrections on first OOP style script
2,191,639
<p>I would like some feedback on my first Python script that makes use of OOP style. This is a Munin plugin that graphs average fan speed or average chassis temp depending on the name of the plugin (dell_fans, dell_temps).</p> <p>An hour or so ago I <a href="http://stackoverflow.com/questions/2190880/python-convert-sc...
2
2010-02-03T11:55:50Z
2,191,661
<p>Is <code>Temps</code> a <code>FanSpeed</code>? That's the litmus test for whether subclassing is appropriate (e.g. an elephant is an animal, a car is not an animal - so it might be appropriate to have a subclass of <code>Animal</code> which models an elephant, but not a subclass of <code>Animal</code> which models a...
2
2010-02-03T11:59:45Z
[ "python", "oop" ]
Python: feedback / corrections on first OOP style script
2,191,639
<p>I would like some feedback on my first Python script that makes use of OOP style. This is a Munin plugin that graphs average fan speed or average chassis temp depending on the name of the plugin (dell_fans, dell_temps).</p> <p>An hour or so ago I <a href="http://stackoverflow.com/questions/2190880/python-convert-sc...
2
2010-02-03T11:55:50Z
2,191,669
<p>A sematically more appropriate way would be to define one main class (for example, <code>FanStatistics</code> or whatever you want to call it), in which you define general methods, like the <code>average</code> method, and the subclass it into <code>FanSpeed</code> and <code>FanTemp</code>. That way you wouldn't con...
1
2010-02-03T12:02:33Z
[ "python", "oop" ]
Python: feedback / corrections on first OOP style script
2,191,639
<p>I would like some feedback on my first Python script that makes use of OOP style. This is a Munin plugin that graphs average fan speed or average chassis temp depending on the name of the plugin (dell_fans, dell_temps).</p> <p>An hour or so ago I <a href="http://stackoverflow.com/questions/2190880/python-convert-sc...
2
2010-02-03T11:55:50Z
2,191,682
<p>It sounds to me like you have two different kinds of statistics that you want to model, fan speed (<code>Fanspeed</code>) and temperatute (<code>Temps</code>). If there is some common functionality that you want share between them create common base class for them lets call it <code>Statistic</code> for example.</p>...
1
2010-02-03T12:05:57Z
[ "python", "oop" ]
Is there any function that returns the out edges of a node?
2,191,687
<p>I am using python with networkx package. I need to find the nodes connected to out edges of a given node. I know there is a function networkx.DiGraph.out_edges but it returns out edges for the entire graph.</p>
3
2010-02-03T12:06:38Z
2,191,740
<p>I'm not a networkx expert, but have you tried <a href="http://networkx.lanl.gov/reference/generated/networkx.DiGraph.out_edges.html#networkx-digraph-out-edges" rel="nofollow">networkx.DiGraph.out_edges</a>, specifying the source node?</p> <blockquote> <pre><code>DiGraph.out_edges(nbunch=None, data=False) </code></p...
4
2010-02-03T12:15:56Z
[ "python", "networkx" ]
Is there any function that returns the out edges of a node?
2,191,687
<p>I am using python with networkx package. I need to find the nodes connected to out edges of a given node. I know there is a function networkx.DiGraph.out_edges but it returns out edges for the entire graph.</p>
3
2010-02-03T12:06:38Z
4,123,208
<p>The simplest way is to use the successors() method:</p> <pre><code>In [1]: import networkx as nx In [2]: G=nx.DiGraph([(0,1),(1,2)]) In [3]: G.edges() Out[3]: [(0, 1), (1, 2)] In [4]: G.successors(1) Out[4]: [2] </code></pre>
4
2010-11-08T10:59:35Z
[ "python", "networkx" ]
How to use listen on basic.return in python client of AMQP
2,191,695
<p>I'd like to make sure that my message was delivered to a queue. </p> <p>To do so I'm adding the mandatory param to the basic_publish. What else should I do to receive the <code>basic.return</code> message if my message wasn't successfully delivered?</p> <p>I can't use <code>channel.wait()</code> to listen for the ...
2
2010-02-03T12:08:06Z
2,240,828
<p>It is currently impossible as the <code>basic.return</code> is sent asynchronously when a message is dropped in broker. When message was sent successfully no data is reported from server. So pyAMQP can't listen for such messages.</p> <p>I've read few threads about this problem. Possible solution were:</p> <ul> <li...
1
2010-02-10T22:30:26Z
[ "python", "rabbitmq", "amqp", "py-amqplib" ]
How to use listen on basic.return in python client of AMQP
2,191,695
<p>I'd like to make sure that my message was delivered to a queue. </p> <p>To do so I'm adding the mandatory param to the basic_publish. What else should I do to receive the <code>basic.return</code> message if my message wasn't successfully delivered?</p> <p>I can't use <code>channel.wait()</code> to listen for the ...
2
2010-02-03T12:08:06Z
6,577,484
<p>Have you tried the only Python AMQP library that is complete? It isn't as widely used because it is not neatly packaged.</p> <p>Step 1. compile the C library - you may need <code>sudo apt-get install autotools-dev autoconf automake libtool</code></p> <pre><code>mkdir rabbitc cd rabbitc hg clone http://hg.rabbitmq....
1
2011-07-05T02:20:03Z
[ "python", "rabbitmq", "amqp", "py-amqplib" ]
How to use listen on basic.return in python client of AMQP
2,191,695
<p>I'd like to make sure that my message was delivered to a queue. </p> <p>To do so I'm adding the mandatory param to the basic_publish. What else should I do to receive the <code>basic.return</code> message if my message wasn't successfully delivered?</p> <p>I can't use <code>channel.wait()</code> to listen for the ...
2
2010-02-03T12:08:06Z
7,751,737
<p>You can't do this synchronously as it is an asynchronous system. But you can solve this problem using threads.</p> <p>The basic idea is that you start a thread which does the wait on the channel, whenever it comes out of the wait it calls the call_back function for any returned message in the returned message queue...
1
2011-10-13T09:02:55Z
[ "python", "rabbitmq", "amqp", "py-amqplib" ]
Find an element in a list of tuples
2,191,699
<p>I have a list 'a'</p> <pre><code>a= [(1,2),(1,4),(3,5),(5,7)] </code></pre> <p>I need to find all the tuples for a particular number. say for 1 it will be</p> <pre><code>result = [(1,2),(1,4)] </code></pre> <p>How do I do that?</p>
54
2010-02-03T12:08:58Z
2,191,707
<p>If you just want the first number to match you can do it like this:</p> <pre><code>[item for item in a if item[0] == 1] </code></pre> <p>If you are just searching for tuples with 1 in them:</p> <pre><code>[item for item in a if 1 in item] </code></pre>
95
2010-02-03T12:10:05Z
[ "python", "list", "search", "tuples" ]
Find an element in a list of tuples
2,191,699
<p>I have a list 'a'</p> <pre><code>a= [(1,2),(1,4),(3,5),(5,7)] </code></pre> <p>I need to find all the tuples for a particular number. say for 1 it will be</p> <pre><code>result = [(1,2),(1,4)] </code></pre> <p>How do I do that?</p>
54
2010-02-03T12:08:58Z
2,191,712
<p>Read up on <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">List Comprehensions</a></p> <pre><code>[ (x,y) for x, y in a if x == 1 ] </code></pre> <p>Also read up up <a href="http://www.python.org/dev/peps/pep-0255/" rel="nofollow">generator functions</a> and the <c...
6
2010-02-03T12:10:54Z
[ "python", "list", "search", "tuples" ]
Find an element in a list of tuples
2,191,699
<p>I have a list 'a'</p> <pre><code>a= [(1,2),(1,4),(3,5),(5,7)] </code></pre> <p>I need to find all the tuples for a particular number. say for 1 it will be</p> <pre><code>result = [(1,2),(1,4)] </code></pre> <p>How do I do that?</p>
54
2010-02-03T12:08:58Z
2,191,722
<pre><code>for item in a: if 1 in item: print item </code></pre>
2
2010-02-03T12:13:01Z
[ "python", "list", "search", "tuples" ]
Find an element in a list of tuples
2,191,699
<p>I have a list 'a'</p> <pre><code>a= [(1,2),(1,4),(3,5),(5,7)] </code></pre> <p>I need to find all the tuples for a particular number. say for 1 it will be</p> <pre><code>result = [(1,2),(1,4)] </code></pre> <p>How do I do that?</p>
54
2010-02-03T12:08:58Z
2,191,734
<pre><code>[tup for tup in a if tup[0] == 1] </code></pre>
5
2010-02-03T12:15:07Z
[ "python", "list", "search", "tuples" ]
Find an element in a list of tuples
2,191,699
<p>I have a list 'a'</p> <pre><code>a= [(1,2),(1,4),(3,5),(5,7)] </code></pre> <p>I need to find all the tuples for a particular number. say for 1 it will be</p> <pre><code>result = [(1,2),(1,4)] </code></pre> <p>How do I do that?</p>
54
2010-02-03T12:08:58Z
18,114,565
<p>There is actually a clever way to do this that is useful for any list of tuples where the size of each tuple is 2: you can convert your list into a single dictionary.</p> <p>For example,</p> <pre><code>test = [("hi", 1), ("there", 2)] test = dict(test) print test["hi"] # prints 1 </code></pre>
44
2013-08-07T22:01:37Z
[ "python", "list", "search", "tuples" ]
Python: How do I force iso-8859-1 file output?
2,191,730
<p>How do I force Latin-1 (which I guess means iso-8859-1?) file output in Python?</p> <p>Here's my code at the moment. It works, but trying to import the resulting output file into a Latin-1 MySQL table produces <a href="http://stackoverflow.com/questions/2188522/importing-text-to-mysql-strange-format">weird encoding...
5
2010-02-03T12:14:28Z
2,191,778
<p>I think it's just:</p> <pre><code>outputFile = file( "textbase.tab", "wb" ) for k, v in textData.iteritems(): complete_line = k + '~~~~~' + v + '~~~~~' + " ENDOFTHELINE" outputFile.write((complete_line + "\n").encode("iso-8859-1")) outputFile.close() </code></pre> <p>As you alluded to, you need to make...
0
2010-02-03T12:22:10Z
[ "python", "character-encoding" ]
Python: How do I force iso-8859-1 file output?
2,191,730
<p>How do I force Latin-1 (which I guess means iso-8859-1?) file output in Python?</p> <p>Here's my code at the moment. It works, but trying to import the resulting output file into a Latin-1 MySQL table produces <a href="http://stackoverflow.com/questions/2188522/importing-text-to-mysql-strange-format">weird encoding...
5
2010-02-03T12:14:28Z
2,191,815
<p>The main problem here is that you don't know what encoding your data is in. If we assume you are correct in that your file ends up being in Mac OS Roman, then you need to decode the data to unicode first, and then encode it as iso-8859-1.</p> <pre><code>inputFile = open("input.rtf", "rb") # The b flag is just a mar...
0
2010-02-03T12:27:11Z
[ "python", "character-encoding" ]
Python: How do I force iso-8859-1 file output?
2,191,730
<p>How do I force Latin-1 (which I guess means iso-8859-1?) file output in Python?</p> <p>Here's my code at the moment. It works, but trying to import the resulting output file into a Latin-1 MySQL table produces <a href="http://stackoverflow.com/questions/2188522/importing-text-to-mysql-strange-format">weird encoding...
5
2010-02-03T12:14:28Z
2,191,845
<p>Simply use the <a href="http://docs.python.org/library/codecs.html"><code>codecs</code></a> module for writing the file:</p> <pre><code>import codecs outputFile = codecs.open("textbase.tab", "w", "ISO-8859-1") </code></pre> <p>Of course, the strings you write have to be Unicode strings (type <code>unicode</code>),...
9
2010-02-03T12:33:57Z
[ "python", "character-encoding" ]
Python: How do I force iso-8859-1 file output?
2,191,730
<p>How do I force Latin-1 (which I guess means iso-8859-1?) file output in Python?</p> <p>Here's my code at the moment. It works, but trying to import the resulting output file into a Latin-1 MySQL table produces <a href="http://stackoverflow.com/questions/2188522/importing-text-to-mysql-strange-format">weird encoding...
5
2010-02-03T12:14:28Z
20,201,465
<p>For me, <code>io.open</code> works a bit faster on python 2.7 for writes, and an order of magnitude faster for reads:</p> <pre><code>import io with io.open("textbase.tab", "w", encoding="ISO-8859-1") as outputFile: ... </code></pre> <p>In python 3, you can just <a href="http://docs.python.org/3/library/functio...
0
2013-11-25T19:23:43Z
[ "python", "character-encoding" ]
Conditional operator in Python?
2,191,890
<p>do you know if Python supports some keyword or expression like in C++ to return values based on <code>if</code> condition, all in the same line (The C++ <code>if</code> expressed with the question mark <code>?</code>)</p> <pre><code>// C++ value = ( a &gt; 10 ? b : c ) </code></pre>
49
2010-02-03T12:44:07Z
2,191,896
<p>From Python 2.5 onwards you can do:</p> <pre><code>value = b if a &gt; 10 else c </code></pre> <p>Previously you would have to do something like the following, although the semantics isn't identical as the short circuiting effect is lost:</p> <pre><code>value = [c, b][a &gt; 10] </code></pre> <p>There's also ano...
88
2010-02-03T12:44:47Z
[ "python", "syntax" ]
Conditional operator in Python?
2,191,890
<p>do you know if Python supports some keyword or expression like in C++ to return values based on <code>if</code> condition, all in the same line (The C++ <code>if</code> expressed with the question mark <code>?</code>)</p> <pre><code>// C++ value = ( a &gt; 10 ? b : c ) </code></pre>
49
2010-02-03T12:44:07Z
2,191,937
<p>simple is the best and works in every version.</p> <pre><code> if a&gt;10: value="b" else: value="c" </code></pre>
-3
2010-02-03T12:51:54Z
[ "python", "syntax" ]
Preventing an Active Directory user from changing his/her password using DirectoryServices
2,191,969
<p>When creating Active Directory users from a script, I also need to set the option that they can't change their passwords. Via the administrative GUI this is easily accomplished, by checking "User cannot change password". Programmatically however, it's another story. I've found a <a href="http://msdn.microsoft.com/en...
0
2010-02-03T12:56:35Z
2,192,603
<p>If you can use .NET 3.5 there's a new namespace in there called <code>System.DirectoryServices.AccountManagment</code>. The <code>UserPrincipal</code> class in that namespace will allow you to set "Cannot Change Password" simply by setting the boolean <a href="http://msdn.microsoft.com/en-us/library/system.directory...
1
2010-02-03T14:29:37Z
[ ".net", "python", "active-directory" ]
Python: convert RTF file to unicode?
2,192,319
<p>I'm trying to convert lines in an RTF file to a series of unicode strings, and then do a regex match on the lines. (I need them to be unicode so that I can output them to another file.)</p> <p>However, my regex match isn't working - I think because they aren't being converted into unicode properly.</p> <p>Here's m...
2
2010-02-03T13:49:42Z
2,192,439
<p>You did not even decode the RTF file. RTFs are <em>not</em> just simple text files. A file containing "äöü", for example, contains this:</p> <blockquote> <p>{\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fswiss\fcharset0 Arial;}}</p> <p>{*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs...
3
2010-02-03T14:08:10Z
[ "python", "unicode" ]
What is the Python egg cache (PYTHON_EGG_CACHE)?
2,192,323
<p>I've just upgraded from Python 2.6.1 to 2.6.4 on my development machine and upon starting a python script was presented with the following message:</p> <blockquote> <p>Can't extract file(s) to egg cache</p> <p>The following error occurred while trying to extract file(s) to the Python egg cache:</p> ...
62
2010-02-03T13:50:10Z
2,192,369
<p>The python egg cache is simply a directory used by setuptools to store packages installed that conform to the <a href="http://peak.telecommunity.com/DevCenter/EggFormats">egg specification</a>. You can <a href="http://pypi.python.org/pypi/setuptools">read more about setuptools here</a>.</p> <p>Additionally, as the...
28
2010-02-03T13:56:10Z
[ "python", "python-egg-cache" ]
What is the Python egg cache (PYTHON_EGG_CACHE)?
2,192,323
<p>I've just upgraded from Python 2.6.1 to 2.6.4 on my development machine and upon starting a python script was presented with the following message:</p> <blockquote> <p>Can't extract file(s) to egg cache</p> <p>The following error occurred while trying to extract file(s) to the Python egg cache:</p> ...
62
2010-02-03T13:50:10Z
2,192,498
<p>Python eggs are zip-compressed packages containing both Python modules and metadata. The egg cache is where the the extracted contents of the egg are stored so that the Python modules contained within are usable.</p>
2
2010-02-03T14:15:17Z
[ "python", "python-egg-cache" ]
What is the Python egg cache (PYTHON_EGG_CACHE)?
2,192,323
<p>I've just upgraded from Python 2.6.1 to 2.6.4 on my development machine and upon starting a python script was presented with the following message:</p> <blockquote> <p>Can't extract file(s) to egg cache</p> <p>The following error occurred while trying to extract file(s) to the Python egg cache:</p> ...
62
2010-02-03T13:50:10Z
2,193,746
<p>From my investigations it turns out that some eggs are packaged as zip files, and are saved as such in Python's <code>site-packages</code> directory.</p> <p>These zipped eggs need to be unzipped before they can be executed, so are expanded into the <code>PYTHON_EGG_CACHE</code> directory which by default is <code>~...
55
2010-02-03T17:03:15Z
[ "python", "python-egg-cache" ]
What is the Python egg cache (PYTHON_EGG_CACHE)?
2,192,323
<p>I've just upgraded from Python 2.6.1 to 2.6.4 on my development machine and upon starting a python script was presented with the following message:</p> <blockquote> <p>Can't extract file(s) to egg cache</p> <p>The following error occurred while trying to extract file(s) to the Python egg cache:</p> ...
62
2010-02-03T13:50:10Z
10,018,293
<p>You can also disable the use of the .egg after it has been installed. You need to go into the site-packages directory, extract the .egg, and then move it to a hidden file (or delete it, or whatever). </p> <p>Here is an example of what I did to disable the MySQLdb module .egg file which was causing this error when t...
3
2012-04-04T19:53:39Z
[ "python", "python-egg-cache" ]
What is the Python egg cache (PYTHON_EGG_CACHE)?
2,192,323
<p>I've just upgraded from Python 2.6.1 to 2.6.4 on my development machine and upon starting a python script was presented with the following message:</p> <blockquote> <p>Can't extract file(s) to egg cache</p> <p>The following error occurred while trying to extract file(s) to the Python egg cache:</p> ...
62
2010-02-03T13:50:10Z
11,958,516
<p>This is a dark side-effect of using otherwise nice eggs mechanism.</p> <p>Eggs are packages (a directory full of files) packed into one <code>.egg</code> file to simplify depolyment. </p> <p>They are stored in <code>/site-packages/</code> dir.</p> <p>As long as the files stored in the egg are <code>.py</code> fil...
8
2012-08-14T18:29:31Z
[ "python", "python-egg-cache" ]
Why isn't there a do while flow control statement in python?
2,192,344
<p>Is there a good reason why there isn't a do while flow control statement in python?<br> Why do pepole have to write while and break explicitly?</p>
13
2010-02-03T13:53:01Z
2,192,371
<p>Probably because Guido didn't think it was necessary. There are a bunch of different flow-control statements you could support, but most of them are variants of each other. Frankly, I've found the do-while statement to be one of the less useful ones.</p>
10
2010-02-03T13:56:20Z
[ "python" ]
Why isn't there a do while flow control statement in python?
2,192,344
<p>Is there a good reason why there isn't a do while flow control statement in python?<br> Why do pepole have to write while and break explicitly?</p>
13
2010-02-03T13:53:01Z
2,192,401
<p>It has been proposed in <a href="http://www.python.org/dev/peps/pep-0315/">PEP 315</a> but hasn't been implemented because nobody has come up with a syntax that's clearer than the <code>while True</code> with an inner <code>if-break</code>.</p>
11
2010-02-03T14:01:31Z
[ "python" ]
Why isn't there a do while flow control statement in python?
2,192,344
<p>Is there a good reason why there isn't a do while flow control statement in python?<br> Why do pepole have to write while and break explicitly?</p>
13
2010-02-03T13:53:01Z
2,192,517
<p>Python adds features only when they significantly simplify some code.</p> <pre><code>while True: ... if not cond: break </code></pre> <p>is not less simple than a do-while loop, for which there is no obvious natural python syntax anyway.</p> <pre><code>do: ... while cond </code></pre> <p>(Looks w...
2
2010-02-03T14:17:25Z
[ "python" ]
Why isn't there a do while flow control statement in python?
2,192,344
<p>Is there a good reason why there isn't a do while flow control statement in python?<br> Why do pepole have to write while and break explicitly?</p>
13
2010-02-03T13:53:01Z
2,195,845
<p>Because then you would have two ways to do something.</p>
3
2010-02-03T22:06:55Z
[ "python" ]
install ImageUtils python
2,192,373
<p>I am trying to install ImageUtils, I found the package but it doesn't have an installer with it. what is the procedure?</p>
0
2010-02-03T13:56:36Z
2,192,497
<p>The general approach to installing Python packages is to use <a href="http://peak.telecommunity.com/DevCenter/EasyInstall" rel="nofollow"><code>easy_install</code></a>, or <a href="http://pypi.python.org/pypi/pip" rel="nofollow"><code>pip</code></a>; the choice between the two tends to get political, so I will just ...
0
2010-02-03T14:15:04Z
[ "python", "image" ]
Verify a file exists over ssh
2,192,442
<p>I am trying to test if a file exists over SSH using pexpect. I have got most of the code working but I need to catch the value so I can assert whether the file exists. The code I have done is below:</p> <pre><code>def VersionID(): ssh_newkey = 'Are you sure you want to continue connecting' # my ssh...
4
2010-02-03T14:08:34Z
2,192,507
<p>I don't have any pexpect experience but looking at their web page it looks like you can call the expect method with multiple values and it returns the index of the one that it matches (this is based purely on me just looking at this example).</p> <pre><code>child.expect('password:') child.sendline (my_secret_passwo...
0
2010-02-03T14:16:39Z
[ "python", "bash", "testing", "ssh", "pexpect" ]
Verify a file exists over ssh
2,192,442
<p>I am trying to test if a file exists over SSH using pexpect. I have got most of the code working but I need to catch the value so I can assert whether the file exists. The code I have done is below:</p> <pre><code>def VersionID(): ssh_newkey = 'Are you sure you want to continue connecting' # my ssh...
4
2010-02-03T14:08:34Z
2,192,569
<p>When you as user type something in ssh, the shell will echo the characters back. That is happening now as well. </p> <p>So, doing:</p> <pre><code>p.sendline('test -f email_tidyup.sh &amp;&amp; echo "File exists" || echo "File does not exist"') </code></pre> <p>Will result in an input of:</p> <pre><code>service@m...
0
2010-02-03T14:25:30Z
[ "python", "bash", "testing", "ssh", "pexpect" ]
Verify a file exists over ssh
2,192,442
<p>I am trying to test if a file exists over SSH using pexpect. I have got most of the code working but I need to catch the value so I can assert whether the file exists. The code I have done is below:</p> <pre><code>def VersionID(): ssh_newkey = 'Are you sure you want to continue connecting' # my ssh...
4
2010-02-03T14:08:34Z
2,192,825
<p>Why not take advantage of the fact that the return code of the command is passed back over SSH?</p> <pre><code>$ ssh victory 'test -f .bash_history' $ echo $? 0 $ ssh victory 'test -f .csh_history' $ echo $? 1 $ ssh hostdoesntexist 'test -f .csh_history' ssh: Could not resolve hostname hostdoesntexist: Name or serv...
9
2010-02-03T14:59:29Z
[ "python", "bash", "testing", "ssh", "pexpect" ]
Verify a file exists over ssh
2,192,442
<p>I am trying to test if a file exists over SSH using pexpect. I have got most of the code working but I need to catch the value so I can assert whether the file exists. The code I have done is below:</p> <pre><code>def VersionID(): ssh_newkey = 'Are you sure you want to continue connecting' # my ssh...
4
2010-02-03T14:08:34Z
2,193,280
<p>I have worked the solution that will do me. The code is below:</p> <pre><code>def VersionID(): ssh_newkey = 'Are you sure you want to continue connecting' # my ssh command line p=pexpect.spawn('ssh service@10.10.0.0') i=p.expect([ssh_newkey,'password:',pexpect.EOF]) if i==0: p.se...
0
2010-02-03T16:00:28Z
[ "python", "bash", "testing", "ssh", "pexpect" ]
Verify a file exists over ssh
2,192,442
<p>I am trying to test if a file exists over SSH using pexpect. I have got most of the code working but I need to catch the value so I can assert whether the file exists. The code I have done is below:</p> <pre><code>def VersionID(): ssh_newkey = 'Are you sure you want to continue connecting' # my ssh...
4
2010-02-03T14:08:34Z
2,193,546
<p>If the server accepts sftp sessions, I wouldn't bother with pexpect, but instead use the <a href="http://www.lag.net/paramiko/" rel="nofollow">paramiko</a> SSH2 module for Python:</p> <pre><code>import paramiko transport=paramiko.Transport("10.10.0.0") transport.connect(username="service",password="word") sftp=para...
3
2010-02-03T16:35:12Z
[ "python", "bash", "testing", "ssh", "pexpect" ]
Verify a file exists over ssh
2,192,442
<p>I am trying to test if a file exists over SSH using pexpect. I have got most of the code working but I need to catch the value so I can assert whether the file exists. The code I have done is below:</p> <pre><code>def VersionID(): ssh_newkey = 'Are you sure you want to continue connecting' # my ssh...
4
2010-02-03T14:08:34Z
19,917,566
<p>I was having some issues with this where every time I ran my program, it would change the output. e.g. If I was looking for <code>/bin/bash</code>, it would sometimes return that it was found and other times it would return that it was missing.</p> <p>I got the following code to work consistently for files and fold...
2
2013-11-11T22:51:20Z
[ "python", "bash", "testing", "ssh", "pexpect" ]
Python: Creating a streaming gzip'd file-like?
2,192,529
<p>I'm trying to figure out the best way to compress a stream with Python's <code>zlib</code>.</p> <p>I've got a file-like input stream (<code>input</code>, below) and an output function which accepts a file-like (<code>output_function</code>, below):</p> <pre><code>with open("file") as input: output_function(inp...
17
2010-02-03T14:19:14Z
2,192,647
<p>The gzip module supports compressing to a file-like object, pass a fileobj parameter to GzipFile, as well as a filename. The filename you pass in doesn't need to exist, but the gzip header has a filename field which needs to be filled out.</p> <p><strong>Update</strong></p> <p>This answer does not work. Example:</...
4
2010-02-03T14:35:26Z
[ "python", "gzip", "zlib" ]
Python: Creating a streaming gzip'd file-like?
2,192,529
<p>I'm trying to figure out the best way to compress a stream with Python's <code>zlib</code>.</p> <p>I've got a file-like input stream (<code>input</code>, below) and an output function which accepts a file-like (<code>output_function</code>, below):</p> <pre><code>with open("file") as input: output_function(inp...
17
2010-02-03T14:19:14Z
2,192,745
<p>Use the cStringIO (or StringIO) module in conjunction with zlib:</p> <pre><code>&gt;&gt;&gt; import zlib &gt;&gt;&gt; from cStringIO import StringIO &gt;&gt;&gt; s.write(zlib.compress("I'm a lumberjack")) &gt;&gt;&gt; s.seek(0) &gt;&gt;&gt; zlib.decompress(s.read()) "I'm a lumberjack" </code></pre>
3
2010-02-03T14:49:08Z
[ "python", "gzip", "zlib" ]
Python: Creating a streaming gzip'd file-like?
2,192,529
<p>I'm trying to figure out the best way to compress a stream with Python's <code>zlib</code>.</p> <p>I've got a file-like input stream (<code>input</code>, below) and an output function which accepts a file-like (<code>output_function</code>, below):</p> <pre><code>with open("file") as input: output_function(inp...
17
2010-02-03T14:19:14Z
2,193,508
<p>It's quite kludgy (self referencing, etc; just put a few minutes writing it, nothing really elegant), but it does what you want if you're still interested in using <code>gzip</code> instead of <code>zlib</code> directly.</p> <p>Basically, <code>GzipWrap</code> is a (very limited) file-like object that produces a gz...
10
2010-02-03T16:29:39Z
[ "python", "gzip", "zlib" ]
Python: Creating a streaming gzip'd file-like?
2,192,529
<p>I'm trying to figure out the best way to compress a stream with Python's <code>zlib</code>.</p> <p>I've got a file-like input stream (<code>input</code>, below) and an output function which accepts a file-like (<code>output_function</code>, below):</p> <pre><code>with open("file") as input: output_function(inp...
17
2010-02-03T14:19:14Z
31,566,082
<p>Here is a cleaner, non-self-referencing version based on Ricardo Cárdenes' very helpful answer.</p> <pre><code>from gzip import GzipFile from collections import deque CHUNK = 16 * 1024 class Buffer (object): def __init__ (self): self.__buf = deque() self.__size = 0 def __len__ (self): ...
2
2015-07-22T14:28:45Z
[ "python", "gzip", "zlib" ]
Is there a better way to convert from decimal to binary in python?
2,192,658
<p>I need to convert from an integer to a list of size 8 that is the binary representation of that number (number &lt;= 255) and back. Currently I am using these lines</p> <pre><code>list(bin(my_num)[2:].rjust(8,'0')) int("".join(my_list),2) </code></pre> <p>I did some googling, but had a hard time finding relevant ...
2
2010-02-03T14:37:12Z
2,192,716
<p>You could use <a href="http://docs.python.org/library/stdtypes.html#str.zfill" rel="nofollow"><code>zfill</code></a> instead of <code>rjust</code>.</p> <pre><code>list(bin(my_num)[2:].zfill(8)) </code></pre>
3
2010-02-03T14:44:29Z
[ "python", "binary" ]
Is there a better way to convert from decimal to binary in python?
2,192,658
<p>I need to convert from an integer to a list of size 8 that is the binary representation of that number (number &lt;= 255) and back. Currently I am using these lines</p> <pre><code>list(bin(my_num)[2:].rjust(8,'0')) int("".join(my_list),2) </code></pre> <p>I did some googling, but had a hard time finding relevant ...
2
2010-02-03T14:37:12Z
2,192,975
<p>In Python 2.6 or newer, use <code>format</code> <a href="http://docs.python.org/library/string.html#format-string-syntax" rel="nofollow">syntax</a>:</p> <pre><code>'{0:0=#10b}'.format(my_num)[2:] # '00001010' </code></pre> <p>One of the neat things about Python strings is that they are sequences. If all you need t...
4
2010-02-03T15:18:47Z
[ "python", "binary" ]
Is there a better way to convert from decimal to binary in python?
2,192,658
<p>I need to convert from an integer to a list of size 8 that is the binary representation of that number (number &lt;= 255) and back. Currently I am using these lines</p> <pre><code>list(bin(my_num)[2:].rjust(8,'0')) int("".join(my_list),2) </code></pre> <p>I did some googling, but had a hard time finding relevant ...
2
2010-02-03T14:37:12Z
8,828,709
<p>I have given here program for decimal to binary conversion.</p> <pre><code>print "Program for Decimal to Binary Conversion" n = 0 bin = 0 pos = 1 print "Enter Decimal Number:", n = input() while(n &gt; 0): bin = bin + (n % 2) * pos; n = n / 2; pos *= 10; print "The Binary Number is: ", bin #sa...
0
2012-01-12T00:35:15Z
[ "python", "binary" ]
Is there a better way to convert from decimal to binary in python?
2,192,658
<p>I need to convert from an integer to a list of size 8 that is the binary representation of that number (number &lt;= 255) and back. Currently I am using these lines</p> <pre><code>list(bin(my_num)[2:].rjust(8,'0')) int("".join(my_list),2) </code></pre> <p>I did some googling, but had a hard time finding relevant ...
2
2010-02-03T14:37:12Z
35,156,641
<p>Here is one method for decimal to binary conversion:</p> <ul> <li>divide the decimal number by 2</li> <li>take the remainder and record it in on the side</li> <li>divide the quotient by 2</li> <li>repeat until the decimal cannot be divided further </li> <li>record the remainder in reverse order and you get the resu...
0
2016-02-02T14:51:25Z
[ "python", "binary" ]
Recommended Django setup?
2,192,685
<p>I am about to embark a major django project. If I install the latest stable release... is the a suggested setup ie. this OS, this RDBMS, this version of python etc?? I'm normally a CentOS man but their repos don't play too well with the django requirements...</p>
1
2010-02-03T14:40:42Z
2,192,704
<p>httpd, mod_wsgi, PostgreSQL, and <a href="http://fedoraproject.org/wiki/EPEL" rel="nofollow">EPEL</a>. CentOS is just fine.</p>
1
2010-02-03T14:43:01Z
[ "python", "django", "apache" ]
Recommended Django setup?
2,192,685
<p>I am about to embark a major django project. If I install the latest stable release... is the a suggested setup ie. this OS, this RDBMS, this version of python etc?? I'm normally a CentOS man but their repos don't play too well with the django requirements...</p>
1
2010-02-03T14:40:42Z
2,192,712
<p>We use Fedora 11, MySQL, Apache, mod_wsgi, Python 2.6. Works great.</p>
1
2010-02-03T14:43:56Z
[ "python", "django", "apache" ]
Recommended Django setup?
2,192,685
<p>I am about to embark a major django project. If I install the latest stable release... is the a suggested setup ie. this OS, this RDBMS, this version of python etc?? I'm normally a CentOS man but their repos don't play too well with the django requirements...</p>
1
2010-02-03T14:40:42Z
2,193,943
<p>Ubuntu is far and away a better platform nowadays. I'm a refugee from RHEL and Fedora. Get Ubuntu 9.10, and if you'd like, spawn it on Amazon ec2 for total flexibility (i.e. launch it in about 90 seconds, play around, do what you want, delete it, and only pay a buck). Otherwise, just use Ubuntu on the desktop.</p...
2
2010-02-03T17:30:37Z
[ "python", "django", "apache" ]
Recommended Django setup?
2,192,685
<p>I am about to embark a major django project. If I install the latest stable release... is the a suggested setup ie. this OS, this RDBMS, this version of python etc?? I'm normally a CentOS man but their repos don't play too well with the django requirements...</p>
1
2010-02-03T14:40:42Z
8,246,936
<p>Ubuntu 11.04, Django, MongoDB, and Python 2.7 for us and everything runs quite snappy. </p> <p>Really a big fan of the NoSQL db solutions. If you're unfamiliar with it I would highly suggest giving it a try because it may change your opinion. Either way, here some food for thought:</p> <p><a href="http://blog.t...
0
2011-11-23T18:01:26Z
[ "python", "django", "apache" ]
Html to image in javascript or python
2,192,799
<p>Just a dumb question... Is there any way you can create an image, say png, with the content of an html page, with a simple click of a button?</p> <p>Thanks to anyone who cares to answers.</p> <hr> <p>Thanks for you answers. But what I wanted was some code in javascript or python that would allow me to create an i...
9
2010-02-03T14:56:45Z
2,192,859
<p>I believe this is what you are looking for:</p> <p><a href="http://code.google.com/p/wkhtmltopdf/" rel="nofollow">http://code.google.com/p/wkhtmltopdf/</a></p>
0
2010-02-03T15:02:18Z
[ "javascript", "jquery", "python", "django" ]
Html to image in javascript or python
2,192,799
<p>Just a dumb question... Is there any way you can create an image, say png, with the content of an html page, with a simple click of a button?</p> <p>Thanks to anyone who cares to answers.</p> <hr> <p>Thanks for you answers. But what I wanted was some code in javascript or python that would allow me to create an i...
9
2010-02-03T14:56:45Z
2,193,724
<p>If you're not locked to having it as a PNG, you could turn it into a PDF with Pisa/Report Lab (http://www.xhtml2pdf.com/). It handles tables pretty well.</p>
0
2010-02-03T17:00:30Z
[ "javascript", "jquery", "python", "django" ]
Html to image in javascript or python
2,192,799
<p>Just a dumb question... Is there any way you can create an image, say png, with the content of an html page, with a simple click of a button?</p> <p>Thanks to anyone who cares to answers.</p> <hr> <p>Thanks for you answers. But what I wanted was some code in javascript or python that would allow me to create an i...
9
2010-02-03T14:56:45Z
2,193,753
<p>There is a service called Webthumb at <a href="http://webthumb.bluga.net/home" rel="nofollow">http://webthumb.bluga.net/home</a> that I have used for something similar.</p> <p>It has a fairly easy REST interface for you to work upon.</p>
0
2010-02-03T17:04:06Z
[ "javascript", "jquery", "python", "django" ]
Html to image in javascript or python
2,192,799
<p>Just a dumb question... Is there any way you can create an image, say png, with the content of an html page, with a simple click of a button?</p> <p>Thanks to anyone who cares to answers.</p> <hr> <p>Thanks for you answers. But what I wanted was some code in javascript or python that would allow me to create an i...
9
2010-02-03T14:56:45Z
2,193,880
<p>Here is code:</p> <p><a href="http://github.com/AdamN/python-webkit2png/">http://github.com/AdamN/python-webkit2png/</a></p> <p>It requires webkit, xvfb (or X) and Qt4, and works best on Ubuntu.</p>
5
2010-02-03T17:22:19Z
[ "javascript", "jquery", "python", "django" ]
Html to image in javascript or python
2,192,799
<p>Just a dumb question... Is there any way you can create an image, say png, with the content of an html page, with a simple click of a button?</p> <p>Thanks to anyone who cares to answers.</p> <hr> <p>Thanks for you answers. But what I wanted was some code in javascript or python that would allow me to create an i...
9
2010-02-03T14:56:45Z
32,768,877
<p>You'll be much better off just subprocessing off to <a href="http://phantomjs.org/screen-capture.html" rel="nofollow">phantomjs</a>. On Ubuntu you can install it via:</p> <pre><code>sudo apt-get install phantomjs </code></pre> <p>Then do something like:</p> <p>generate_image.py:</p> <pre><code>import subprocess...
3
2015-09-24T18:57:25Z
[ "javascript", "jquery", "python", "django" ]
How do Python's class closures work?
2,192,822
<p>If I make a class against a local namespace, how exactly does it work? For instance:</p> <pre><code>&gt;&gt;&gt; def foo(): ... i = 1 ... class bar(object): ... j = i ... return bar ... &gt;&gt;&gt; dis(foo) 2 0 LOAD_CONST 1 (1) 3 STORE_DEREF ...
6
2010-02-03T14:59:07Z
2,193,000
<p>The whole class body, i.e.</p> <pre><code>j = i </code></pre> <p>is a code object, which gets loaded at offset 21 and then invoked at offset 27 via <code>CALL_FUNCTION</code>. The result of the invocation (the local namespace) is then used together with the class name and the bases to create the class. <code>BUILD...
2
2010-02-03T15:22:30Z
[ "python", "closures", "bytecode" ]
Using explicit del in python on local variables
2,192,926
<p>What are the best practices and recommendations for using explicit <code>del</code> statement in python? I understand that it is used to remove attributes or dictionary/list elements and so on, but sometimes I see it used on local variables in code like this:</p> <pre><code>def action(x): result = None some...
10
2010-02-03T15:12:15Z
2,193,029
<p>No.</p> <p>I'm sure someone will come up with some silly reason to do this, e.g. to make sure someone doesn't accidentally use the variable after it's no longer valid. But probably whoever wrote this code was just confused. You can remove them.</p>
3
2010-02-03T15:26:33Z
[ "python", "coding-style" ]
Using explicit del in python on local variables
2,192,926
<p>What are the best practices and recommendations for using explicit <code>del</code> statement in python? I understand that it is used to remove attributes or dictionary/list elements and so on, but sometimes I see it used on local variables in code like this:</p> <pre><code>def action(x): result = None some...
10
2010-02-03T15:12:15Z
2,193,071
<p>I don't remember when I last used <code>del</code> -- the need for it is rare indeed, and typically limited to such tasks as cleaning up a module's namespace after a needed <code>import</code> or the like.</p> <p>In particular, it's <strong>not</strong> true, as another (now-deleted) answer claimed, that</p> <bloc...
28
2010-02-03T15:32:10Z
[ "python", "coding-style" ]
Using explicit del in python on local variables
2,192,926
<p>What are the best practices and recommendations for using explicit <code>del</code> statement in python? I understand that it is used to remove attributes or dictionary/list elements and so on, but sometimes I see it used on local variables in code like this:</p> <pre><code>def action(x): result = None some...
10
2010-02-03T15:12:15Z
25,804,264
<p>When you are running programs handling really large amounts of data ( to my experience when the totals memory consumption of the program approaches something like 1GB) deleting some objects: del largeObject1 del largeObject2 … can give your program the necessary breathing room to function without runni...
1
2014-09-12T08:49:28Z
[ "python", "coding-style" ]
Python: urllib2.urlopen(url, data) Why do you have to urllib.urlencode() the data?
2,192,987
<p>I thought that a post sent all the information in HTTP headers when you used post (I'm not well informed on this subject obviously), so I'm confused why you have to urlencode() the data to a <code>key=value&amp;key2=value2</code> format. How does that formatting come into play when using POST?:</p> <pre><code># Fai...
7
2010-02-03T15:20:45Z
2,193,032
<p>Data must be in the standard <em>application/x-www-form-urlencoded</em> format. <code>urlencode</code> converts your args to a url-encoded string.</p>
2
2010-02-03T15:26:53Z
[ "python", "urllib2", "urllib" ]
Python: urllib2.urlopen(url, data) Why do you have to urllib.urlencode() the data?
2,192,987
<p>I thought that a post sent all the information in HTTP headers when you used post (I'm not well informed on this subject obviously), so I'm confused why you have to urlencode() the data to a <code>key=value&amp;key2=value2</code> format. How does that formatting come into play when using POST?:</p> <pre><code># Fai...
7
2010-02-03T15:20:45Z
2,193,035
<p>It is related to the "Content-Type" header: the client must have an idea of how the POST data is encoded or else how would it know how to decode it?</p> <p>The standard way of doing this is through <em>application/x-www-form-urlencoded</em> encoding format.</p> <p>Now, if the question is "why do we need to encode?...
9
2010-02-03T15:27:30Z
[ "python", "urllib2", "urllib" ]
How to start a "drawing loop" in PyQt?
2,192,993
<p>Often times when we're drawing a GUI, we want our GUI to update based on the data changing in our program. At the start of the program, let's say I've drawn my GUI based on my initial data. That data will be changing constantly, so how can I redraw my GUI constantly?</p>
1
2010-02-03T15:21:20Z
2,193,028
<p>You could create a thread to update the GUI constantly, just pass to it references to the graphical widgets that need to be updated</p>
0
2010-02-03T15:26:23Z
[ "python", "pyqt" ]
How to start a "drawing loop" in PyQt?
2,192,993
<p>Often times when we're drawing a GUI, we want our GUI to update based on the data changing in our program. At the start of the program, let's say I've drawn my GUI based on my initial data. That data will be changing constantly, so how can I redraw my GUI constantly?</p>
1
2010-02-03T15:21:20Z
2,194,143
<p>The best way that I have found to do this is to run your core program in a QThread and use signals to communicate with your gui. Here is an example where I update a progress dialog as my main program does some stuff.</p> <p>Here is a code excerpt from a project that I was working on. The basic idea is that I am a...
1
2010-02-03T17:56:29Z
[ "python", "pyqt" ]
extend Python namedtuple with many @properties?
2,193,009
<p>How can namedtuples be extended or subclassed with many additional @properties ?<br> For a few, one can just write the text below; but there are many, so I'm looking for a generator or property factory. One way would be to generate text from <code>_fields</code> and exec it; another would be an add_fields with the s...
7
2010-02-03T15:24:11Z
2,193,111
<p>The answer to your question</p> <blockquote> <p>How can namedtuples be extended or subclassed with additional <code>@properties</code> ?</p> </blockquote> <p>is: exactly the way you're doing it! What error are you getting? To see a simpler case,</p> <pre><code>&gt;&gt;&gt; class x(collections.namedtuple('...
10
2010-02-03T15:37:14Z
[ "python", "properties", "namedtuple" ]
extend Python namedtuple with many @properties?
2,193,009
<p>How can namedtuples be extended or subclassed with many additional @properties ?<br> For a few, one can just write the text below; but there are many, so I'm looking for a generator or property factory. One way would be to generate text from <code>_fields</code> and exec it; another would be an add_fields with the s...
7
2010-02-03T15:24:11Z
2,194,988
<p>How about this?</p> <pre><code>class Top( namedtuple( "Top_", "topid amount personid" )): """ @property .person -&gt; persontable[personid] .pname -&gt; person.pname ... """ __slots__ = () @property def person(self): return persontable[self.personid] def __...
2
2010-02-03T19:56:54Z
[ "python", "properties", "namedtuple" ]
extend Python namedtuple with many @properties?
2,193,009
<p>How can namedtuples be extended or subclassed with many additional @properties ?<br> For a few, one can just write the text below; but there are many, so I'm looking for a generator or property factory. One way would be to generate text from <code>_fields</code> and exec it; another would be an add_fields with the s...
7
2010-02-03T15:24:11Z
2,200,206
<p>Here's one approach, a little language: turn this into Python text like the above, and exec it.<br> (Expanding text-to-text is easy to do, and easy to test &mdash; you can look at the intermediate text.)<br> I'm sure there are similar if not-so-little such, links please ?</p> <pre><code># example of a little langu...
0
2010-02-04T14:10:26Z
[ "python", "properties", "namedtuple" ]
M2Crypto: AttributeError for load_dynamic_engine()
2,193,181
<p>I am using M2Crypto-0.20.2. I want to use engine_pkcs11 from the OpenSC project and the Aladdin PKI client for token based authentication making xmlrpc calls over ssl.</p> <p>I am trying to load the PKCS#11 engine as well as the Aladdin module (see code below). But I get an error: AttributeError: 'module' object ...
0
2010-02-03T15:48:16Z
2,193,667
<p>I was reading the documentation wrong. The load_dynamic_engine() belong in the Engine module.</p> <p>I changed the command and now get a different error: Engine.load_dynamic_engine("dynamic","/usr/local/ssl/lib/engines/engine_pkcs11.so")</p> <p>bad engine id Engine.load_dynamic_engine("dynamic","/usr/local/ssl/li...
0
2010-02-03T16:52:28Z
[ "python", "openssl", "m2crypto" ]
M2Crypto: AttributeError for load_dynamic_engine()
2,193,181
<p>I am using M2Crypto-0.20.2. I want to use engine_pkcs11 from the OpenSC project and the Aladdin PKI client for token based authentication making xmlrpc calls over ssl.</p> <p>I am trying to load the PKCS#11 engine as well as the Aladdin module (see code below). But I get an error: AttributeError: 'module' object ...
0
2010-02-03T15:48:16Z
2,194,111
<p>I haven't used the Engine module myself, so I cannot give you any definite answers. However, you should take a look at <a href="http://svn.osafoundation.org/m2crypto/trunk/tests/test_engine.py" rel="nofollow">test_engine.py</a> module for some pointers. I am guessing that to load engines provided by OpenSSL you shou...
0
2010-02-03T17:52:28Z
[ "python", "openssl", "m2crypto" ]
How to initialize a QT thread in python
2,193,182
<p>As per examples seen online, I've created a <code>Worker</code> thread. I'm looking for a thread to run my GUI while one thread executes my code. <code>Worker</code> thread is defined as:</p> <pre><code>class Worker(QThread): def __init__(self, parent = None): QThread.__init__(self, parent) s...
0
2010-02-03T15:48:23Z
2,193,256
<p>I imagine you're looking at the example <a href="http://diotavelli.net/PyQtWiki/Threading,_Signals_and_Slots" rel="nofollow">here</a>? But that example <em>does</em> "do something with that thread afterwards" -- it hooks up methods to respond to the signals the thread sends when it starts and finishes, in the <code>...
2
2010-02-03T15:57:55Z
[ "python", "qt", "multithreading", "pyqt" ]
Creating a video file from a group of PGM files in python
2,193,192
<p>My python program generates a collection of binary files. I create pgm (portable bitmap files) using this binary data. I would like to create a video using each of the pgm files as a frame in my video. </p> <p>I have had a look an mencoder but I dont think it supports pgm files</p> <p>Can anyone offer any advice.<...
0
2010-02-03T15:50:22Z
2,193,234
<p>If "PGM" is identical with "Portable GrayMap Files", cross-browser command line video processing tool <a href="http://www.ffmpeg.org/" rel="nofollow"><strong>ffmpeg</strong></a> can decode them: <a href="http://en.wikipedia.org/wiki/FFmpeg#Codecs" rel="nofollow"><strong>List of FFMPeg Codecs on Wikipedia</strong></a...
1
2010-02-03T15:55:19Z
[ "python", "pgm" ]
Display function definition in interactive shell
2,193,231
<p>I am working in the Python Interactive Shell (ActiveState ActivePython 2.6.4 under Windows XP). I created a function that does what I want. However, I've cleared the screen so I can't go back and look at the function definition. It is also a multiline function so the up arrow to redisplay lines is of minimal value. ...
8
2010-02-03T15:55:06Z
2,193,294
<p>Unless there is a way of doing it on the activestate shell, no, there is no way to retrieve the exact code you've typed on the shell. At least on Linux, using the Python Shell provided by CPython there is no special way to achieve this. Maybe using iPython.</p> <p>The func_code attribute is an object representing t...
0
2010-02-03T16:01:59Z
[ "python", "shell" ]
Display function definition in interactive shell
2,193,231
<p>I am working in the Python Interactive Shell (ActiveState ActivePython 2.6.4 under Windows XP). I created a function that does what I want. However, I've cleared the screen so I can't go back and look at the function definition. It is also a multiline function so the up arrow to redisplay lines is of minimal value. ...
8
2010-02-03T15:55:06Z
2,193,342
<p>No, <code>__code__</code> and <code>func_code</code> are references to the compiled bytecode -- you can disassemble them (see <code>dis.dis</code>) but not get back to the Python source code.</p> <p>Alas, the source code is simply gone, not remembered anywhere...:</p> <pre><code>&gt;&gt;&gt; import inspect &gt;&gt...
7
2010-02-03T16:07:04Z
[ "python", "shell" ]
Display function definition in interactive shell
2,193,231
<p>I am working in the Python Interactive Shell (ActiveState ActivePython 2.6.4 under Windows XP). I created a function that does what I want. However, I've cleared the screen so I can't go back and look at the function definition. It is also a multiline function so the up arrow to redisplay lines is of minimal value. ...
8
2010-02-03T15:55:06Z
2,193,405
<p>No, not really. You could write yourfunc.func_code.co_code (the actually compiled bytecode) to a file and then try using decompyle or unpyc to decompile them, but both projects are old and unmaintained, and have never supported decompiling very well.</p> <p>It's infinitely easier to simply write your function to a ...
1
2010-02-03T16:14:50Z
[ "python", "shell" ]
Display function definition in interactive shell
2,193,231
<p>I am working in the Python Interactive Shell (ActiveState ActivePython 2.6.4 under Windows XP). I created a function that does what I want. However, I've cleared the screen so I can't go back and look at the function definition. It is also a multiline function so the up arrow to redisplay lines is of minimal value. ...
8
2010-02-03T15:55:06Z
33,562,405
<p>It has been a pretty long time but may someone need it. <code>getsource</code> gives the soruce code:</p> <pre><code>&gt;&gt;&gt; def sum(a, b, c): ... # sum of three number ... return a+b+c ... &gt;&gt;&gt; from dill.source import getsource &gt;&gt;&gt; &gt;&gt;&gt; getsource(sum) 'def sum(a, b, c):\n # sum of t...
0
2015-11-06T08:26:25Z
[ "python", "shell" ]
How to connect to a LDAP server using a p12 certificate
2,193,362
<p>I want to connect to a LDAP server using a .p12 certificate instead of using a username and password. The Java solution for this looks like</p> <pre><code>String ldapURL = "ldaps://"+host+":"+port; System.setProperty("javax.net.ssl.keyStoreType", "PKCS12" ); System.setProperty("javax.net.ssl.keyStore",keystor...
2
2010-02-03T16:09:38Z
2,194,017
<p>It looks like <a href="http://webmail.inoi.fi/open/trac/ldaptor" rel="nofollow">ldaptor</a> can provide you with this functionality. It's built on top of twisted, which has support for SSL built into the <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.ssl.html" rel="nofollow">twisted.internet...
0
2010-02-03T17:38:40Z
[ "python", "ldap", "certificate", "pkcs#12" ]
How to connect to a LDAP server using a p12 certificate
2,193,362
<p>I want to connect to a LDAP server using a .p12 certificate instead of using a username and password. The Java solution for this looks like</p> <pre><code>String ldapURL = "ldaps://"+host+":"+port; System.setProperty("javax.net.ssl.keyStoreType", "PKCS12" ); System.setProperty("javax.net.ssl.keyStore",keystor...
2
2010-02-03T16:09:38Z
3,097,912
<p>If you use python-ldap, you can use the <a href="http://www.python-ldap.org/doc/html/ldap.html#ldap.OPT_X_TLS_CACERTDIR" rel="nofollow">TLS options</a> to set these parameters.</p> <pre><code>ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, "/path/to/trustedcerts.pem") ldap.set_option(ldap.OPT_X_TLS_CERTFILE, "/path/to/u...
1
2010-06-22T23:32:09Z
[ "python", "ldap", "certificate", "pkcs#12" ]
How to launch a background process in Python with a delayed invocation?
2,193,551
<p>Ok, this is a bit of a thorny problem. I need to launch a backgrounded process that will (1) wait N secs, and then (2) execute some command. Additionally, I need to capture the pid of the background process itself, because when the parent process finishes it will kill the backgrounded process if necessary. It looks ...
1
2010-02-03T16:35:46Z
2,193,594
<p>When you give <code>shell</code> as <code>True</code> to <code>subprocess.Popen</code>, the command you execute can be the same as you're executing directly in the shell in your example, i.e., <code>(sleep 15 &amp;&amp; run_some_cmd)</code> should be fine.</p>
1
2010-02-03T16:41:51Z
[ "python" ]
How to launch a background process in Python with a delayed invocation?
2,193,551
<p>Ok, this is a bit of a thorny problem. I need to launch a backgrounded process that will (1) wait N secs, and then (2) execute some command. Additionally, I need to capture the pid of the background process itself, because when the parent process finishes it will kill the backgrounded process if necessary. It looks ...
1
2010-02-03T16:35:46Z
2,193,601
<blockquote> <p>I can't use os.system() or os.fork(), since in each case the parent process does not have access to the pid of the child. </p> </blockquote> <p>Er, the parent gets the pid as a return value from <code>fork()</code>. In any case, I would suggest using the <a href="http://docs.python.org/library/subpro...
3
2010-02-03T16:42:36Z
[ "python" ]
Python conversion to ISO-8859-5
2,193,611
<p>I'm facing problems when trying to convert a UTF-8 file (containing Russian characters) into an ISO-8859-5 file: 'charmap' codec can't encode character u'\ufeff' in position 0: character maps to . Has anyone got an idea of what's wrong(?) given the following:</p> <pre><code>def convert(): try: import co...
3
2010-02-03T16:44:00Z
2,193,637
<p>feff is a <a href="http://en.wikipedia.org/wiki/Byte_order_mark" rel="nofollow">Byte-Order-Mark</a> character. ISO-8859-5 won't have any representation for it.</p> <p>You'll need to strip it off your <code>data</code> variable before encoding it into ISO-8859-5.</p>
2
2010-02-03T16:47:29Z
[ "python", "unicode", "encoding", "character-encoding" ]
Python conversion to ISO-8859-5
2,193,611
<p>I'm facing problems when trying to convert a UTF-8 file (containing Russian characters) into an ISO-8859-5 file: 'charmap' codec can't encode character u'\ufeff' in position 0: character maps to . Has anyone got an idea of what's wrong(?) given the following:</p> <pre><code>def convert(): try: import co...
3
2010-02-03T16:44:00Z
2,195,814
<p>Recent versions of Python have the <code>utf-8-sig</code> codec that will automatically strip the BOM off a UTF-8-encoded string or file when reading it:</p> <pre><code>&gt;&gt;&gt; print '\xef\xbb\xbf\xe3\x81\x82'.decode('utf-8-sig') あ </code></pre>
2
2010-02-03T22:01:35Z
[ "python", "unicode", "encoding", "character-encoding" ]
catching SQLAlchemy exceptions
2,193,670
<p>What is the upper level exception that I can catch SQLAlechmy exceptions with ?</p> <pre><code>&gt;&gt;&gt; from sqlalchemy import exc &gt;&gt;&gt; dir(exc) ['ArgumentError', 'CircularDependencyError', 'CompileError', 'ConcurrentModificationError', 'DBAPIError', 'DataError', 'DatabaseError', 'DisconnectionError', '...
15
2010-02-03T16:53:00Z
2,193,712
<p>From <a href="https://github.com/zzzeek/sqlalchemy/blob/master/lib/sqlalchemy/exc.py#L10">the source</a>:</p> <blockquote> <p>The base exception class is <code>SQLAlchemyError</code>.</p> </blockquote>
16
2010-02-03T16:59:40Z
[ "python", "sqlalchemy", "exception" ]
catching SQLAlchemy exceptions
2,193,670
<p>What is the upper level exception that I can catch SQLAlechmy exceptions with ?</p> <pre><code>&gt;&gt;&gt; from sqlalchemy import exc &gt;&gt;&gt; dir(exc) ['ArgumentError', 'CircularDependencyError', 'CompileError', 'ConcurrentModificationError', 'DBAPIError', 'DataError', 'DatabaseError', 'DisconnectionError', '...
15
2010-02-03T16:53:00Z
4,430,982
<p>To catch any exception SQLAlchemy throws:</p> <pre><code>from sqlalchemy import exc db.add(user) try: db.commit() except exc.SQLAlchemyError: pass </code></pre> <p>See help(sqlalchemy.exc) and help(sqlalchemy.orm.exc) for a list of possible exceptions that sqlalchemy can raise.</p>
22
2010-12-13T16:25:56Z
[ "python", "sqlalchemy", "exception" ]
catching SQLAlchemy exceptions
2,193,670
<p>What is the upper level exception that I can catch SQLAlechmy exceptions with ?</p> <pre><code>&gt;&gt;&gt; from sqlalchemy import exc &gt;&gt;&gt; dir(exc) ['ArgumentError', 'CircularDependencyError', 'CompileError', 'ConcurrentModificationError', 'DBAPIError', 'DataError', 'DatabaseError', 'DisconnectionError', '...
15
2010-02-03T16:53:00Z
30,942,077
<p>Depending on your version of SQLAlchemy (e.g. 1.0.4), you may need to do a little more to get to the base-<code>SQLAlchemyError</code> class:</p> <pre><code>from flask.ext.sqlalchemy import exc exceptions = exc.sa_exc try: my_admin = user_models.User('space cadet', active=True) db.session.add(my_admin) ...
1
2015-06-19T15:36:31Z
[ "python", "sqlalchemy", "exception" ]
Overcoming the "disadvantages" of string immutability
2,193,705
<p>I want to change the value of a particular string index, but unfortunately</p> <pre><code>string[4] = "a" </code></pre> <p>raises a <code>TypeError</code>, because strings are immutable ("item assignment is not supported").</p> <p>So instead I use the rather clumsy</p> <pre><code>string = string[:4] + "a" + stri...
6
2010-02-03T16:58:18Z
2,193,715
<pre><code>mystring=list("abcdef") mystring[4]="Z" print ''.join(mystring) </code></pre>
3
2010-02-03T16:59:50Z
[ "python", "string", "immutability" ]
Overcoming the "disadvantages" of string immutability
2,193,705
<p>I want to change the value of a particular string index, but unfortunately</p> <pre><code>string[4] = "a" </code></pre> <p>raises a <code>TypeError</code>, because strings are immutable ("item assignment is not supported").</p> <p>So instead I use the rather clumsy</p> <pre><code>string = string[:4] + "a" + stri...
6
2010-02-03T16:58:18Z
2,193,721
<pre><code>&gt;&gt;&gt; from UserString import MutableString &gt;&gt;&gt; s = MutableString('abcd') &gt;&gt;&gt; s[2] = 'e' &gt;&gt;&gt; print s abed </code></pre>
0
2010-02-03T17:00:13Z
[ "python", "string", "immutability" ]
Overcoming the "disadvantages" of string immutability
2,193,705
<p>I want to change the value of a particular string index, but unfortunately</p> <pre><code>string[4] = "a" </code></pre> <p>raises a <code>TypeError</code>, because strings are immutable ("item assignment is not supported").</p> <p>So instead I use the rather clumsy</p> <pre><code>string = string[:4] + "a" + stri...
6
2010-02-03T16:58:18Z
2,193,895
<p>The strings in Python are immutable, just like numbers and tuples. This means that you can create them, move them around, but not change them. Why is this so ? For a few reasons (you can find a better discussion online):</p> <ul> <li>By design, strings in Python are considered elemental and unchangeable. This spurs...
8
2010-02-03T17:24:13Z
[ "python", "string", "immutability" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,193,745
<pre><code>for name in files: if not name.startswith("doc"): print name </code></pre>
5
2010-02-03T17:03:12Z
[ "python", "string" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,193,749
<pre><code>if not name.startswith('doc'): print name </code></pre> <p>If you have more prefixes to exclude you can even do this:</p> <pre><code>if not name.startswith(('prefix', 'another', 'yetanother')): print name </code></pre> <p><a href="https://docs.python.org/2/library/stdtypes.html#str.startswith" r...
16
2010-02-03T17:03:30Z
[ "python", "string" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,193,754
<pre><code>for name in files: if name[0:3] == "doc": continue </code></pre>
0
2010-02-03T17:04:08Z
[ "python", "string" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,193,755
<p>If all of them start the same (i.e. with "doc") you could use python's string's startswith() method.</p> <pre><code>for name in files: if not name.startswith("doc"): print name </code></pre>
0
2010-02-03T17:04:13Z
[ "python", "string" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,193,758
<p>Since you didn't say if there are good files starting with 'doc' and ending with '.html' you will have to declare a <code>set</code> of bad filenames and process only files not in that set.</p> <pre><code>bad_files = set(["doc1.html", "doc2.html", "doc3.html"]) for file in files: if file not in bad_files: pr...
0
2010-02-03T17:04:42Z
[ "python", "string" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,193,760
<pre><code>import os os.chdir("/home") for file in os.listdir("."): if os.path.isfile(file) and not file.startswith("doc"): print file </code></pre>
1
2010-02-03T17:04:52Z
[ "python", "string" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,193,795
<p>If you find functional programming matches your style better, Python makes it simple to filter lists with the filter() function:</p> <pre><code>&gt;&gt;&gt; files = ["doc1.html", "doc2.html", "doc3.html", "index.html", "image.jpeg"] &gt;&gt;&gt; filter_function = lambda name: not name.startswith("doc") &gt;&gt;&gt;...
3
2010-02-03T17:11:34Z
[ "python", "string" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,193,935
<p>looks like this problem might be a better fit for list stuff so like Troy said (Although I prefer putting the function directly into the filter)</p> <pre><code>filter(lambda filename: not filename.startswith("doc"),files) </code></pre> <p>or </p> <pre><code>[filename for filename in files if not filename.startsw...
1
2010-02-03T17:30:08Z
[ "python", "string" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,194,103
<p>You could also use a <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow" title="list comprehension">list comprehension</a>.</p> <pre><code>cleaned_list = [filename for filename in files if not filename.startswith('doc')] </code></pre>
1
2010-02-03T17:50:50Z
[ "python", "string" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,196,318
<p>An alternate take to a functional solution to this issue, with the advantage of using recent additions to the standard library (using the same example filenames as Troy J. Farrell in another answer) :</p> <pre><code>&gt;&gt;&gt; import operator, itertools &gt;&gt;&gt; filter_fun= operator.methodcaller("startswith",...
0
2010-02-03T23:29:30Z
[ "python", "string" ]
In python, how do I exclude files from a loop if they begin with a specific set of letters?
2,193,710
<p>I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.</p> <p>Example code:</p> <pre><code>for name in files: if name != "doc1.html" and name != "doc2.html" and name != "doc3.html": print name </code></p...
8
2010-02-03T16:59:31Z
2,222,878
<p>This is my 2 cents:<br> A bit of list comprehension.It's always better for effeciency.</p> <pre><code>file_list = [file for file in directory if not file.startswith(("name1", "name2", "name3"))] </code></pre>
0
2010-02-08T16:03:12Z
[ "python", "string" ]
Convert Chrome history date/time stamp to readable format
2,193,820
<p>I originally posted this question looking for an answer with using python, got some good help, but have still not been able to find a solution. I have a script running on OS X 10.5 client machines that captures internet browsing history (required as part of my sys admin duties in a US public school). Firefox 3.x sto...
3
2010-02-03T17:14:32Z
2,197,334
<p>Use the <a href="http://docs.python.org/library/datetime.html?highlight=datetime#module-datetime" rel="nofollow"><code>datetime</code></a> module. For example, if the number of microseconds in questions is 10**16:</p> <pre><code>&gt;&gt;&gt; datetime.datetime(1601, 1, 1) + datetime.timedelta(microseconds=1e16) dat...
3
2010-02-04T04:34:02Z
[ "python", "osx", "datetime", "google-chrome" ]
Python underlying analysis books/articles?
2,193,829
<p>Does anyone know good books that discuss the underlying architectures, in-depth analysis of CPython implementation. Something like</p> <ul> <li>how list / tuple / dict implemented (and performance comparison...)</li> <li>OOP discussion in Python context</li> </ul> <p>Sorry if it sounds like a silly question :(</p>...
0
2010-02-03T17:15:57Z
2,193,927
<p>Beautiful Code book has a nice explanation about how dicts are implemented.</p>
2
2010-02-03T17:28:54Z
[ "python", "performance", "architecture", "comparison" ]