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
Automate Windows GUI operations with Python
2,353,963
<p>I want to make a Python script that automates the process of setting up a VPN server in Windows XP, but the only way I know how to do it is using the Windows GUI dialogs. How would I go about figuring out what those dialogs are doing to the system and designing a Python script to automate it?</p>
10
2010-03-01T05:02:35Z
2,354,022
<p>Take a look at <a href="http://groups.csail.mit.edu/uid/sikuli/" rel="nofollow">SIKULI</a> - there have been some reports of less-than-perfect operation in Windows but it is really simple to play around with and get a simple script up and running.</p>
2
2010-03-01T05:17:51Z
[ "python", "winapi" ]
Automate Windows GUI operations with Python
2,353,963
<p>I want to make a Python script that automates the process of setting up a VPN server in Windows XP, but the only way I know how to do it is using the Windows GUI dialogs. How would I go about figuring out what those dialogs are doing to the system and designing a Python script to automate it?</p>
10
2010-03-01T05:02:35Z
8,731,567
<p>You can also use <a href="http://pywinauto.github.io/" rel="nofollow">pywinauto</a> for GUI automation.</p> <p><strong>Edit:</strong> There seems to be now GUI for creating the scripts, <a href="http://code.google.com/p/swapy/" rel="nofollow">swapy</a>.</p>
13
2012-01-04T17:55:29Z
[ "python", "winapi" ]
Automate Windows GUI operations with Python
2,353,963
<p>I want to make a Python script that automates the process of setting up a VPN server in Windows XP, but the only way I know how to do it is using the Windows GUI dialogs. How would I go about figuring out what those dialogs are doing to the system and designing a Python script to automate it?</p>
10
2010-03-01T05:02:35Z
13,450,655
<p>You can try using <a href="http://www.getautoma.com/" rel="nofollow">Automa</a> - it's a Windows automation tool which can be used as a python library:</p> <pre><code>from automa.api import * </code></pre> <p>And then you can use commands like start(..), click(..) and enter(..) which operate on UI. You can also us...
4
2012-11-19T09:14:43Z
[ "python", "winapi" ]
Automate Windows GUI operations with Python
2,353,963
<p>I want to make a Python script that automates the process of setting up a VPN server in Windows XP, but the only way I know how to do it is using the Windows GUI dialogs. How would I go about figuring out what those dialogs are doing to the system and designing a Python script to automate it?</p>
10
2010-03-01T05:02:35Z
26,197,899
<p>PyAutoGUI can be installed with pip from PyPI. It's cross platform and can control the mouse &amp; keyboard. It has the features of pywinauto and a few more on top. It can't identify windows or GUI controls, but it does have basic screenshot &amp; image recognition features to click on particular buttons. And it's w...
0
2014-10-04T22:46:21Z
[ "python", "winapi" ]
Switching mod_python from using python2.4 to python2.5
2,354,043
<p>My goal is to have Apache process a python script and output to the requesting client.</p> <p>My server has both Python2.4 and Python2.5.5 installed. I have Apache configured to correctly process python scripts and tested with a simple test script. However, the real script I am trying to run requires Python2.5.5. M...
0
2010-03-01T05:26:33Z
2,354,105
<p>No. Rebuild it against 2.5.5 instead.</p>
0
2010-03-01T05:50:53Z
[ "python", "mod-python" ]
Remote system event Notification Library
2,354,064
<p>Hi I am looking for some sort of library that will allow: - multiple remote applications to register with the system on which events it is interested in - When this event occurs, the system will sent out notification to these remote applications regarding this event - Objects, or hash tables information should be ab...
0
2010-03-01T05:31:22Z
2,354,106
<p>I think you are looking for a queuing system. Give JMS a try.</p>
1
2010-03-01T05:50:57Z
[ "java", "python" ]
How do you modify sys.path in Google App Engine (Python)?
2,354,166
<p>I've tried adding the following line to my handler script (main.py), but it doesn't seem to work:</p> <blockquote> <p>sys.path.append('subdir')</p> </blockquote> <p><code>subdir</code> lives in the my root directory (i.e. the one containing <code>app.yaml</code>).</p> <p>This doesn't seem to work, because when ...
8
2010-03-01T06:11:36Z
2,354,273
<p>1) Ensure you have a blank <code>__init__.py</code> file in <code>subdir</code>. </p> <p>2) Use a full path; something like this: </p> <pre><code>import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), 'subdir')) </code></pre> <hr> <p>Edit: providing more info to answer questions asked i...
17
2010-03-01T06:48:29Z
[ "python", "google-app-engine", "sys.path" ]
How do you modify sys.path in Google App Engine (Python)?
2,354,166
<p>I've tried adding the following line to my handler script (main.py), but it doesn't seem to work:</p> <blockquote> <p>sys.path.append('subdir')</p> </blockquote> <p><code>subdir</code> lives in the my root directory (i.e. the one containing <code>app.yaml</code>).</p> <p>This doesn't seem to work, because when ...
8
2010-03-01T06:11:36Z
6,247,272
<p>It worked for me inserting the new dirs as the first entries in sys.path.</p> <p>path_changer.py:</p> <pre><code>import os import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'libs')) sys.path.insert(1, os.path.join(os.path.dirname(__file__), 'apps')) </code></pre> <p>app.py:</p> <pre><code>im...
2
2011-06-06T02:14:15Z
[ "python", "google-app-engine", "sys.path" ]
GoogleAppEngine web proxy
2,354,170
<p>Does anyone know of a simple open source proxy capable of running on google app engine or where to start in making one? (preferably in python, I'm trying to bypass a site blocking system)</p>
2
2010-03-01T06:13:18Z
2,354,235
<p>You can try Mirrorrr:</p> <p><a href="http://code.google.com/p/mirrorrr/" rel="nofollow">http://code.google.com/p/mirrorrr/</a></p> <p>Or Masher Nations, Itube Appengine, Tohr, etc.</p>
2
2010-03-01T06:34:21Z
[ "python", "google-app-engine", "proxy" ]
what's the meaning of %r in python
2,354,329
<p>what's the meaning of <code>%r</code> in the following statement?</p> <pre><code>print '%r' % (1) </code></pre> <p>I think I've heard of <code>%s</code>, <code>%d</code>, and <code>%f</code> but never heard of this.</p>
34
2010-03-01T07:13:09Z
2,354,337
<p>It calls <a href="http://docs.python.org/library/functions.html#repr"><code>repr()</code></a> on the object and inserts the resulting string.</p>
15
2010-03-01T07:15:08Z
[ "python", "sign" ]
what's the meaning of %r in python
2,354,329
<p>what's the meaning of <code>%r</code> in the following statement?</p> <pre><code>print '%r' % (1) </code></pre> <p>I think I've heard of <code>%s</code>, <code>%d</code>, and <code>%f</code> but never heard of this.</p>
34
2010-03-01T07:13:09Z
2,354,345
<p>It prints the replacement as a string with <code>repr()</code>.</p>
4
2010-03-01T07:15:47Z
[ "python", "sign" ]
what's the meaning of %r in python
2,354,329
<p>what's the meaning of <code>%r</code> in the following statement?</p> <pre><code>print '%r' % (1) </code></pre> <p>I think I've heard of <code>%s</code>, <code>%d</code>, and <code>%f</code> but never heard of this.</p>
34
2010-03-01T07:13:09Z
2,354,566
<p>See <a href="http://docs.python.org/dev/library/string.html#string-formatting" rel="nofollow">String Formatting Operations</a> in the docs. Notice that %s and %d etc, might work differently to how you expect if you are used to the way they work in another language such as C.</p> <p>In particular, %s also works well...
0
2010-03-01T08:26:40Z
[ "python", "sign" ]
what's the meaning of %r in python
2,354,329
<p>what's the meaning of <code>%r</code> in the following statement?</p> <pre><code>print '%r' % (1) </code></pre> <p>I think I've heard of <code>%s</code>, <code>%d</code>, and <code>%f</code> but never heard of this.</p>
34
2010-03-01T07:13:09Z
2,354,652
<p>Background:</p> <p>In Python, there are two builtin functions for turning an object into a string: <a href="https://docs.python.org/2/library/functions.html#str"><code>str</code></a> vs. <a href="https://docs.python.org/2/library/functions.html#func-repr"><code>repr</code></a>. <code>str</code> is supposed to be a ...
48
2010-03-01T08:48:07Z
[ "python", "sign" ]
what's the meaning of %r in python
2,354,329
<p>what's the meaning of <code>%r</code> in the following statement?</p> <pre><code>print '%r' % (1) </code></pre> <p>I think I've heard of <code>%s</code>, <code>%d</code>, and <code>%f</code> but never heard of this.</p>
34
2010-03-01T07:13:09Z
29,297,349
<p>Adding to the replies given above, '%r' can be useful in a scenario where you have a list with heterogeneous data type. Let's say, we have a list = [1, 'apple' , 2 , 'r','banana'] Obviously in this case using '%d' or '%s' would cause an error. Instead, we can use '%r' to print all these values.</p>
1
2015-03-27T09:33:05Z
[ "python", "sign" ]
ALTER TABLE Sqlite: how to check if a column exists before alter the table?
2,354,696
<p>I need to execute in python a SQL query that adds a new column, in sqlite3. </p> <p>The problem is that sometimes it already exists. So previous to executing the query I need to check if the column already exists. </p> <p>If it does, then I won't execute the query.</p> <p><strong>Is there a way in sqlite to do th...
6
2010-03-01T08:59:29Z
2,354,763
<p>You can get a list of columns for a table via the following statement:</p> <pre><code>PRAGMA table_info('table_name'); </code></pre> <p>More details on the pragma commands are availabel at <a href="http://www.sqlite.org/pragma.html">the sqlite web site</a> </p>
11
2010-03-01T09:15:59Z
[ "python", "sqlite3", "exists", "alter" ]
ALTER TABLE Sqlite: how to check if a column exists before alter the table?
2,354,696
<p>I need to execute in python a SQL query that adds a new column, in sqlite3. </p> <p>The problem is that sometimes it already exists. So previous to executing the query I need to check if the column already exists. </p> <p>If it does, then I won't execute the query.</p> <p><strong>Is there a way in sqlite to do th...
6
2010-03-01T08:59:29Z
2,354,829
<p>IMO this</p> <pre><code>conn = sqlite3.connect(':memory:') c = conn.cursor() try: c.execute('ALTER TABLE mytable ADD COLUMN newcolumn;') except: pass # handle the error c.close() </code></pre> <p>is a better choice than constructing <em>special case</em> queries. </p> <p>You can wrap the above code in a ...
10
2010-03-01T09:30:35Z
[ "python", "sqlite3", "exists", "alter" ]
Running Python With STDIN From Bash
2,354,724
<p>I have a bash code (<code>Mybash1.sh</code>) where the result I need to pass to another bash code (<code>Mybash2.sh</code>) that contain Python</p> <p>Here are the codes. Mybash1.sh </p> <pre><code>#! /bin/bash # Mybash1.sh cut -f1,3 input_file.txt | sort | ./Mybash2.sh </code></pre> <p>Mybash2.sh is this:</p> ...
2
2010-03-01T09:06:35Z
2,354,858
<p>in your myscript1.sh, you are passing a pipeline to myscript2.sh, therefore, its some sort of STDIN for myscript2.sh. You should read that STDIN from myscript2.sh, not taking in input arguments. eg myscript2.sh</p> <pre><code>#!/bin/bash while read myinput do echo "myinput is $myinput" # assuming you are passing ...
0
2010-03-01T09:36:37Z
[ "python", "linux", "bash", "unix", "stdin" ]
Running Python With STDIN From Bash
2,354,724
<p>I have a bash code (<code>Mybash1.sh</code>) where the result I need to pass to another bash code (<code>Mybash2.sh</code>) that contain Python</p> <p>Here are the codes. Mybash1.sh </p> <pre><code>#! /bin/bash # Mybash1.sh cut -f1,3 input_file.txt | sort | ./Mybash2.sh </code></pre> <p>Mybash2.sh is this:</p> ...
2
2010-03-01T09:06:35Z
2,354,878
<p>In python, you want to have <code>file2 = sys.stdin</code>.</p> <p>And then:</p> <pre><code>#! /bin/bash #Mybash2.sh python mycode.py foo.txt &gt; output.txt </code></pre> <p>EDIT: I've just seen the fileinput docs and it seems that if you supply '-' to fileinput.input(), it will read stdin, so without any change...
2
2010-03-01T09:38:50Z
[ "python", "linux", "bash", "unix", "stdin" ]
Implicitly invoking parent class initializer
2,354,769
<pre><code>class A(object): def __init__(self, a, b, c): #super(A, self).__init__() super(self.__class__, self).__init__() class B(A): def __init__(self, b, c): print super(B, self) print super(self.__class__, self) #super(B, self).__init__(1, b, c) super(self._...
6
2010-03-01T09:17:57Z
2,355,136
<p>Perhaps what you are looking for is metaclasses?</p> <pre><code>class metawrap(type): def __new__(mcs,name, bases, dict): dict['bases'] = bases return type.__new__(mcs,name,bases,dict) class A(object): def __init(self): pass def test(self): print "I am class A" class B(...
1
2010-03-01T10:32:09Z
[ "python", "constructor", "super", "python-2.x", "method-resolution-order" ]
Implicitly invoking parent class initializer
2,354,769
<pre><code>class A(object): def __init__(self, a, b, c): #super(A, self).__init__() super(self.__class__, self).__init__() class B(A): def __init__(self, b, c): print super(B, self) print super(self.__class__, self) #super(B, self).__init__(1, b, c) super(self._...
6
2010-03-01T09:17:57Z
2,743,197
<p>Your code has nothing to do with method resolution order. Method resolution comes in the case of multiple inheritance which is not the case of your example. Your code is simply wrong because you assume that <code>self.__class__</code> is actually the same class of the one where the method is defined and this is wron...
1
2010-04-30T08:24:05Z
[ "python", "constructor", "super", "python-2.x", "method-resolution-order" ]
Implicitly invoking parent class initializer
2,354,769
<pre><code>class A(object): def __init__(self, a, b, c): #super(A, self).__init__() super(self.__class__, self).__init__() class B(A): def __init__(self, b, c): print super(B, self) print super(self.__class__, self) #super(B, self).__init__(1, b, c) super(self._...
6
2010-03-01T09:17:57Z
2,759,132
<p>Short answer: no, there's no way to implicitly invoke the right <code>__init__</code> with the right arguments of the right parent class in Python 2.x.</p> <p>Incidentally, the code as shown here is incorrect: if you use super().<code>__init__</code>, then all classes in your hierarchy must have the same signature ...
2
2010-05-03T15:26:05Z
[ "python", "constructor", "super", "python-2.x", "method-resolution-order" ]
Implicitly invoking parent class initializer
2,354,769
<pre><code>class A(object): def __init__(self, a, b, c): #super(A, self).__init__() super(self.__class__, self).__init__() class B(A): def __init__(self, b, c): print super(B, self) print super(self.__class__, self) #super(B, self).__init__(1, b, c) super(self._...
6
2010-03-01T09:17:57Z
2,767,346
<p>To my knowledge, the following isn't commonly done. But it does seem to work.</p> <p>Methods in a given class definition always mangle double-underscore attributes to include the name of the class they're defined in. So, if you stash a reference to the class in name-mangled form where the instances can see it, you ...
0
2010-05-04T17:06:39Z
[ "python", "constructor", "super", "python-2.x", "method-resolution-order" ]
Reading from the serial port from C++ or Python on windows
2,354,905
<p>I need to read the serial port from windows, using either Python or C++. What API/Library should I use? Can you direct me to a tutorial? Thanks!</p>
6
2010-03-01T09:43:29Z
2,354,937
<p>This is classic article about Win32 serial communications: <a href="http://msdn.microsoft.com/en-us/library/ms810467.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms810467.aspx</a></p>
3
2010-03-01T09:52:39Z
[ "c++", "python", "windows", "serial-port" ]
Reading from the serial port from C++ or Python on windows
2,354,905
<p>I need to read the serial port from windows, using either Python or C++. What API/Library should I use? Can you direct me to a tutorial? Thanks!</p>
6
2010-03-01T09:43:29Z
2,354,951
<p>In C++:</p> <ol> <li><a href="http://msdn.microsoft.com/en-us/library/aa363858%28VS.85%29.aspx"><code>CreateFile</code></a><code>("\\\\.\\COM39", ...)</code></li> <li><a href="http://msdn.microsoft.com/en-us/library/aa363436%28VS.85%29.aspx"><code>SetCommState</code></a></li> <li><a href="http://msdn.microsoft.com/...
5
2010-03-01T09:54:53Z
[ "c++", "python", "windows", "serial-port" ]
Reading from the serial port from C++ or Python on windows
2,354,905
<p>I need to read the serial port from windows, using either Python or C++. What API/Library should I use? Can you direct me to a tutorial? Thanks!</p>
6
2010-03-01T09:43:29Z
2,354,958
<p>In python you've excellent package <a href="http://pyserial.sourceforge.net/">pyserial</a> that should be cross-platform (I've used only in GNU/Linux environment).</p> <p>Give it a look, it's very simple to use but very powerful!</p> <p>Of course <a href="http://pyserial.sourceforge.net/examples.html">examples</a>...
6
2010-03-01T09:57:23Z
[ "c++", "python", "windows", "serial-port" ]
Reading from the serial port from C++ or Python on windows
2,354,905
<p>I need to read the serial port from windows, using either Python or C++. What API/Library should I use? Can you direct me to a tutorial? Thanks!</p>
6
2010-03-01T09:43:29Z
2,354,965
<p>In python it is as simple as importing <strong><a href="http://pyserial.sourceforge.net/" rel="nofollow">pyserial</a></strong> and use its open() method (if you are using quite standard system, otherwise you have to adjust a number of parameters to match your environment of course).</p> <p><em>EDIT</em>:<br> As poi...
3
2010-03-01T09:58:29Z
[ "c++", "python", "windows", "serial-port" ]
Universal construct for STDIN and Fileinput in Python Code
2,355,007
<p>I want my code to be able to accept input from a file AND stdin. What's the construct to do it?</p> <p>I mean a unifying construct that implies </p> <pre><code>file1 = sys.stdin </code></pre> <p>and </p> <pre><code>file1 = fileinput.input(sys.argv[1]) </code></pre>
1
2010-03-01T10:05:02Z
2,355,037
<pre><code>import fileinput for line in fileinput.input(): print line </code></pre>
6
2010-03-01T10:09:49Z
[ "python", "linux", "unix" ]
Universal construct for STDIN and Fileinput in Python Code
2,355,007
<p>I want my code to be able to accept input from a file AND stdin. What's the construct to do it?</p> <p>I mean a unifying construct that implies </p> <pre><code>file1 = sys.stdin </code></pre> <p>and </p> <pre><code>file1 = fileinput.input(sys.argv[1]) </code></pre>
1
2010-03-01T10:05:02Z
2,355,202
<p>"Unifying construct" sounds like you want to be able to access either a file provided as an argument or <code>sys.stdin</code> through one variable, so you can just tell functions to get a line from <em>that thing</em>. Luckily, <code>sys.stdin</code> is just another File object, so you have exactly the same functio...
0
2010-03-01T10:45:17Z
[ "python", "linux", "unix" ]
llvm-py questions
2,355,019
<p>1) Is it possible to use llvm-py on Windows without Visual Studio 2008? Maybe I can compile files on another computer and use on my?</p> <p>2) Is llvm-py mature enough in your opinion? If not, what are the problems?</p>
1
2010-03-01T10:07:14Z
2,536,020
<p>As far as I know, llvm-py is unmaintained. The project would require some kind of compiler, although you should be able to use the free VS express edition I would imagine.</p> <p>On the other hand, the LLVM C bindings are maintained, so it is always possible to use the Python ctypes module to wrap the LLVM C API, w...
3
2010-03-29T05:57:12Z
[ "python", "llvm" ]
python parsing url after string
2,355,177
<p>I want to extract a string from a url (link). That string is in a <code>&lt;h3&gt;&lt;/h3&gt;</code> tag. </p> <pre><code> link = http://www.test.com/page.html Content of link: &lt;h3&gt;Text here&lt;/h3&gt; </code></pre> <p>What would be an elegant way to first get the content/sourcecode of page.html and then e...
1
2010-03-01T10:41:10Z
2,355,185
<p>You can use URLLib2 to retrieve the content of the URL:</p> <p><a href="http://docs.python.org/library/urllib2.html" rel="nofollow">http://docs.python.org/library/urllib2.html</a></p> <p>You could then use the HTML parser in the Python libraries to find the right content:</p> <p><a href="http://docs.python.org/li...
1
2010-03-01T10:42:42Z
[ "python", "regex", "parsing" ]
python parsing url after string
2,355,177
<p>I want to extract a string from a url (link). That string is in a <code>&lt;h3&gt;&lt;/h3&gt;</code> tag. </p> <pre><code> link = http://www.test.com/page.html Content of link: &lt;h3&gt;Text here&lt;/h3&gt; </code></pre> <p>What would be an elegant way to first get the content/sourcecode of page.html and then e...
1
2010-03-01T10:41:10Z
2,355,248
<pre><code>import urllib2 url="http://www.test.com/page.html" page=urllib2.urlopen(url) data=page.read() for item in data.split("&lt;/h3&gt;"): if "&lt;h3&gt;" in item: print item.split("&lt;h3&gt;")[1] </code></pre>
1
2010-03-01T10:53:20Z
[ "python", "regex", "parsing" ]
python parsing url after string
2,355,177
<p>I want to extract a string from a url (link). That string is in a <code>&lt;h3&gt;&lt;/h3&gt;</code> tag. </p> <pre><code> link = http://www.test.com/page.html Content of link: &lt;h3&gt;Text here&lt;/h3&gt; </code></pre> <p>What would be an elegant way to first get the content/sourcecode of page.html and then e...
1
2010-03-01T10:41:10Z
2,355,253
<p>Provided the text you want is the <em>only</em> <code>&lt;h3&gt;</code>-wrapped text on the page, try:</p> <p><code>from urllib2 import urlopen</code><br> <code>from re import search</code><br> <code>text = search(r'(?&lt;=&lt;h3&gt;).+?(?=&lt;/h3&gt;)', urlopen(link).read()).group(0)</code></p> <p>If there are mu...
-1
2010-03-01T10:55:39Z
[ "python", "regex", "parsing" ]
python parsing url after string
2,355,177
<p>I want to extract a string from a url (link). That string is in a <code>&lt;h3&gt;&lt;/h3&gt;</code> tag. </p> <pre><code> link = http://www.test.com/page.html Content of link: &lt;h3&gt;Text here&lt;/h3&gt; </code></pre> <p>What would be an elegant way to first get the content/sourcecode of page.html and then e...
1
2010-03-01T10:41:10Z
2,355,283
<p>I'd recommend <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beatiful Soup</a>. That's a nice parser for botched HTML pages (for the most cases you don't have to worry about the page not being well-formed).</p>
2
2010-03-01T10:59:35Z
[ "python", "regex", "parsing" ]
Problem running Virtualenv on Mac OS X
2,355,188
<p>I'm using virtualenv-1.4.5 on Mac OS X 10.6.2 (Xcode is installed) and Python 2.6. Here's what I get when I attempt to run a virtualenv...</p> <pre><code> Mac-Pro:pylonsdev paul$ virtualenv --no-site-packages -v trythis Creating trythis/lib/python2.6 Symlinking Python bootstrap modules Symlinking trythis/lib/pyth...
14
2010-03-01T10:42:56Z
2,355,219
<p>Well, the error message includes this:</p> <blockquote> <blockquote> <p>you must have Apple's development tools installed</p> </blockquote> </blockquote> <p>Do you? They're on the separate XCode disk that came with OSX.</p>
3
2010-03-01T10:47:10Z
[ "python", "osx", "virtualenv" ]
Problem running Virtualenv on Mac OS X
2,355,188
<p>I'm using virtualenv-1.4.5 on Mac OS X 10.6.2 (Xcode is installed) and Python 2.6. Here's what I get when I attempt to run a virtualenv...</p> <pre><code> Mac-Pro:pylonsdev paul$ virtualenv --no-site-packages -v trythis Creating trythis/lib/python2.6 Symlinking Python bootstrap modules Symlinking trythis/lib/pyth...
14
2010-03-01T10:42:56Z
2,356,063
<p>There's also a bug with virtualenv on 10.6 See <a href="http://bitbucket.org/ianb/virtualenv/issue/17/virtualenv-not-working-with-default-python-on-mac-os" rel="nofollow">the ticket on virtualenv's bitbucket</a>. Even if you solve the problem you're having you'll still run into another problem (I think image not fou...
1
2010-03-01T13:29:13Z
[ "python", "osx", "virtualenv" ]
Problem running Virtualenv on Mac OS X
2,355,188
<p>I'm using virtualenv-1.4.5 on Mac OS X 10.6.2 (Xcode is installed) and Python 2.6. Here's what I get when I attempt to run a virtualenv...</p> <pre><code> Mac-Pro:pylonsdev paul$ virtualenv --no-site-packages -v trythis Creating trythis/lib/python2.6 Symlinking Python bootstrap modules Symlinking trythis/lib/pyth...
14
2010-03-01T10:42:56Z
4,239,066
<p>Install XCode from the App Store to fix the problem. I had the same error, installed XCode, ran it after installing, and now virtualenv works.</p>
12
2010-11-21T17:04:38Z
[ "python", "osx", "virtualenv" ]
Problem running Virtualenv on Mac OS X
2,355,188
<p>I'm using virtualenv-1.4.5 on Mac OS X 10.6.2 (Xcode is installed) and Python 2.6. Here's what I get when I attempt to run a virtualenv...</p> <pre><code> Mac-Pro:pylonsdev paul$ virtualenv --no-site-packages -v trythis Creating trythis/lib/python2.6 Symlinking Python bootstrap modules Symlinking trythis/lib/pyth...
14
2010-03-01T10:42:56Z
8,769,405
<p>There is a solution for this using @gregglind's fork of virtualenv. I answered to the same problem here: <a href="http://stackoverflow.com/questions/6819939/mac-osx-unable-to-use-virtualenv">mac osx: unable to use virtualenv</a></p> <pre><code>git clone https://github.com/gregglind/virtualenv.git cd virtualenv git ...
1
2012-01-07T11:42:41Z
[ "python", "osx", "virtualenv" ]
Problem running Virtualenv on Mac OS X
2,355,188
<p>I'm using virtualenv-1.4.5 on Mac OS X 10.6.2 (Xcode is installed) and Python 2.6. Here's what I get when I attempt to run a virtualenv...</p> <pre><code> Mac-Pro:pylonsdev paul$ virtualenv --no-site-packages -v trythis Creating trythis/lib/python2.6 Symlinking Python bootstrap modules Symlinking trythis/lib/pyth...
14
2010-03-01T10:42:56Z
8,979,311
<p>I had the same error messages trying to run virtualenv on a up-to-date Max OSX Lion installation with XCode installed.</p> <p>However: Mark hints <a href="http://stackoverflow.com/a/2355219/246235">on Mar 1 2010</a>:</p> <blockquote> <p>Well code says you have not installed Xcode but you say you have. What does ...
3
2012-01-23T22:09:16Z
[ "python", "osx", "virtualenv" ]
Problem running Virtualenv on Mac OS X
2,355,188
<p>I'm using virtualenv-1.4.5 on Mac OS X 10.6.2 (Xcode is installed) and Python 2.6. Here's what I get when I attempt to run a virtualenv...</p> <pre><code> Mac-Pro:pylonsdev paul$ virtualenv --no-site-packages -v trythis Creating trythis/lib/python2.6 Symlinking Python bootstrap modules Symlinking trythis/lib/pyth...
14
2010-03-01T10:42:56Z
9,131,560
<p>add install_name_tool to your path</p> <p>export PATH=$PATH:/Developer/usr/bin</p>
0
2012-02-03T15:59:04Z
[ "python", "osx", "virtualenv" ]
Problem running Virtualenv on Mac OS X
2,355,188
<p>I'm using virtualenv-1.4.5 on Mac OS X 10.6.2 (Xcode is installed) and Python 2.6. Here's what I get when I attempt to run a virtualenv...</p> <pre><code> Mac-Pro:pylonsdev paul$ virtualenv --no-site-packages -v trythis Creating trythis/lib/python2.6 Symlinking Python bootstrap modules Symlinking trythis/lib/pyth...
14
2010-03-01T10:42:56Z
9,384,860
<p>All you really need to do is install the Xcode "Command Line Tools", there is two ways to do it:</p> <p>1.- If you already have Xcode installed, go to Preferences -> Downloads and select "Command Line Tools".</p> <p>2.- Download the "Command Line Tools for Xcode" .dmg from: <a href="https://developer.apple.com/dow...
24
2012-02-21T20:44:01Z
[ "python", "osx", "virtualenv" ]
Access module masked by variable name
2,355,310
<p>How do I access a module named x that I masked with a variable named x?</p>
0
2010-03-01T11:04:59Z
2,355,324
<p>use <code>sys.modules[module_name]</code> ... and you should avoid masking module names: use wisely the <code>import</code> statement e.g. import XYZ as ABC.</p> <p>You can also rely on using a more complete namespace "path" e.g. <code>os.path.xxx</code></p>
1
2010-03-01T11:07:30Z
[ "python", "namespaces" ]
Access module masked by variable name
2,355,310
<p>How do I access a module named x that I masked with a variable named x?</p>
0
2010-03-01T11:04:59Z
2,355,328
<p>don't name your variable <code>x</code> or use <code>import ... as</code> style.</p> <pre><code>&gt;&gt;&gt; sys = 2 &gt;&gt;&gt; import sys as s &gt;&gt;&gt; s &lt;module 'sys' (built-in)&gt; &gt;&gt;&gt; sys 2 </code></pre>
3
2010-03-01T11:07:58Z
[ "python", "namespaces" ]
Access module masked by variable name
2,355,310
<p>How do I access a module named x that I masked with a variable named x?</p>
0
2010-03-01T11:04:59Z
2,355,331
<pre><code>import x as someotherx </code></pre>
0
2010-03-01T11:08:15Z
[ "python", "namespaces" ]
Python DBAPI time out for connections?
2,355,401
<p>I was attempting to test for connection failure, and unfortunately it's not failing if the IP address of the host is fire walled.</p> <p>This is the code:</p> <pre><code>def get_connection(self, conn_data): rtu, hst, prt, usr, pwd, db = conn_data try: self.conn = pgdb.connect(host=hst+":"+prt, u...
0
2010-03-01T11:23:19Z
2,355,417
<p>What you are experiencing is the pain of firewalls, and the timeout is the normal TCP timeout.</p>
0
2010-03-01T11:27:12Z
[ "python", "python-db-api" ]
Python DBAPI time out for connections?
2,355,401
<p>I was attempting to test for connection failure, and unfortunately it's not failing if the IP address of the host is fire walled.</p> <p>This is the code:</p> <pre><code>def get_connection(self, conn_data): rtu, hst, prt, usr, pwd, db = conn_data try: self.conn = pgdb.connect(host=hst+":"+prt, u...
0
2010-03-01T11:23:19Z
2,355,424
<p>You can usually pass timeout argument in connect function. If it doesn't exist you could try with socket.timeout or <a href="http://docs.python.org/library/socket.html#socket.setdefaulttimeout" rel="nofollow">default timeout</a>:</p> <pre><code>import socket socket.setdefaulttimeout(10) # sets timeout to 10 seconds...
0
2010-03-01T11:30:06Z
[ "python", "python-db-api" ]
Ugly combination of generator expression with for loop
2,355,542
<p>The following appears in my Python 2.6 code:</p> <pre><code>for src, dst in ([s,d] for s in universe for d in universe if s != d): </code></pre> <p>Can I do much better? What I particularly don't like is that I'm in effect specifying the same pair twice, once for the for loop and again for the generator expression...
8
2010-03-01T11:54:25Z
2,355,580
<p>You could use simple nested for-loops:</p> <pre><code>for src in universe: for dst in universe: if src == dst: continue ... </code></pre> <p>I'd say this is the most easy to read syntax in this case.</p>
5
2010-03-01T12:02:24Z
[ "python", "for-loop", "generator" ]
Ugly combination of generator expression with for loop
2,355,542
<p>The following appears in my Python 2.6 code:</p> <pre><code>for src, dst in ([s,d] for s in universe for d in universe if s != d): </code></pre> <p>Can I do much better? What I particularly don't like is that I'm in effect specifying the same pair twice, once for the for loop and again for the generator expression...
8
2010-03-01T11:54:25Z
2,355,605
<p>itertools.product can take a "repeat" keyword argument if you want to have the same sequence as more than one parameter:</p> <pre><code>itertools.product(universe, repeat=2) </code></pre> <p>it is a matter of opinion as to whether this is more readable.</p> <p>You could replace your original code with:</p> <pre>...
1
2010-03-01T12:07:34Z
[ "python", "for-loop", "generator" ]
Ugly combination of generator expression with for loop
2,355,542
<p>The following appears in my Python 2.6 code:</p> <pre><code>for src, dst in ([s,d] for s in universe for d in universe if s != d): </code></pre> <p>Can I do much better? What I particularly don't like is that I'm in effect specifying the same pair twice, once for the for loop and again for the generator expression...
8
2010-03-01T11:54:25Z
2,355,615
<p>I suggest keeping it entirely functional or entirely with comprehensions. Here's an implementation that's entirely functional.</p> <pre><code>import itertools import operator def inner_product(iterable): "the product of an iterable with itself" return itertools.product(iterable, repeat=2) def same(pair):...
3
2010-03-01T12:09:35Z
[ "python", "for-loop", "generator" ]
Group a string into 3s in a loop (python)
2,355,650
<p>I have a nine character string and need to perform operations on groups of three characters in a loop.</p> <p>How would i achieve this in python?</p>
0
2010-03-01T12:18:43Z
2,355,687
<p>Simplest way:</p> <pre><code>&gt;&gt;&gt; s = "123456789" &gt;&gt;&gt; for group in (s[:3], s[3:6], s[6:]): print group ... 123 456 789 </code></pre> <p>In the more general case, look at: <a href="http://code.activestate.com/recipes/303799-chunks/" rel="nofollow">http://code.activestate.com/recipes/303799-chunks/<...
3
2010-03-01T12:23:53Z
[ "python", "loops" ]
Group a string into 3s in a loop (python)
2,355,650
<p>I have a nine character string and need to perform operations on groups of three characters in a loop.</p> <p>How would i achieve this in python?</p>
0
2010-03-01T12:18:43Z
2,355,704
<p>Maybe something like this?</p> <pre><code>&gt;&gt;&gt; a = "123456789" &gt;&gt;&gt; for grp in [a[:3], a[3:6], a[6:]]: print grp </code></pre> <p>Of course, if you need to generalize,</p> <pre><code>&gt;&gt;&gt; def split3(aString): while len(aString) &gt; 0: yield aString[:3] ...
3
2010-03-01T12:26:14Z
[ "python", "loops" ]
Group a string into 3s in a loop (python)
2,355,650
<p>I have a nine character string and need to perform operations on groups of three characters in a loop.</p> <p>How would i achieve this in python?</p>
0
2010-03-01T12:18:43Z
2,355,724
<pre><code>&gt;&gt;&gt; s = "123456789" &gt;&gt;&gt; import textwrap &gt;&gt;&gt; textwrap.wrap(s,3) ['123', '456', '789'] </code></pre> <p>or you can use itertools</p> <pre><code>import itertools def grouper(n, iterable): args = [iter(iterable)] * n return itertools.izip_longest(*args) for i in grouper(3,"o...
2
2010-03-01T12:31:13Z
[ "python", "loops" ]
Python: Control timeout length
2,355,743
<p>I have code similar to the following running in a script:</p> <pre><code>try: s = ftplib.FTP('xxx.xxx.xxx.xxx','username','password') except: print ('Could not contact FTP serer') sys.exit() </code></pre> <p>IF the FTP site is inaccessible, the script almost seems to 'hang' ... It is taking about 75 ...
4
2010-03-01T12:34:00Z
2,355,762
<p><a href="http://docs.python.org/library/socket.html#socket.socket.settimeout" rel="nofollow">http://docs.python.org/library/socket.html#socket.socket.settimeout</a></p>
1
2010-03-01T12:36:58Z
[ "python" ]
Python: Control timeout length
2,355,743
<p>I have code similar to the following running in a script:</p> <pre><code>try: s = ftplib.FTP('xxx.xxx.xxx.xxx','username','password') except: print ('Could not contact FTP serer') sys.exit() </code></pre> <p>IF the FTP site is inaccessible, the script almost seems to 'hang' ... It is taking about 75 ...
4
2010-03-01T12:34:00Z
2,355,764
<p>if you look at the <a href="http://docs.python.org/library/ftplib.html" rel="nofollow">doc</a>, there's a timeout parameter. </p> <p><code>class ftplib.FTP([host[, user[, passwd[, acct[, timeout]]]]])¶</code></p> <p>maybe you can use that.</p>
1
2010-03-01T12:37:03Z
[ "python" ]
Python: Control timeout length
2,355,743
<p>I have code similar to the following running in a script:</p> <pre><code>try: s = ftplib.FTP('xxx.xxx.xxx.xxx','username','password') except: print ('Could not contact FTP serer') sys.exit() </code></pre> <p>IF the FTP site is inaccessible, the script almost seems to 'hang' ... It is taking about 75 ...
4
2010-03-01T12:34:00Z
2,355,781
<p>Starting with 2.6, the <a href="http://docs.python.org/library/ftplib.html#ftplib.FTP"><code>FTP constructor</code></a> has an optional <code>timeout</code> parameter:</p> <blockquote> <p><code>class ftplib.FTP([host[, user[, passwd[, acct[, timeout]]]]])</code></p> <p>Return a new instance of the FTP class....
7
2010-03-01T12:39:27Z
[ "python" ]
Python: Control timeout length
2,355,743
<p>I have code similar to the following running in a script:</p> <pre><code>try: s = ftplib.FTP('xxx.xxx.xxx.xxx','username','password') except: print ('Could not contact FTP serer') sys.exit() </code></pre> <p>IF the FTP site is inaccessible, the script almost seems to 'hang' ... It is taking about 75 ...
4
2010-03-01T12:34:00Z
2,356,459
<p>since you are on python 2.5, you can set a global timeout for all socket operations (including FTP requests) by using:</p> <pre><code>socket.setdefaulttimeout() </code></pre> <p>(this was added in Python 2.3)</p>
2
2010-03-01T14:32:24Z
[ "python" ]
Python: Control timeout length
2,355,743
<p>I have code similar to the following running in a script:</p> <pre><code>try: s = ftplib.FTP('xxx.xxx.xxx.xxx','username','password') except: print ('Could not contact FTP serer') sys.exit() </code></pre> <p>IF the FTP site is inaccessible, the script almost seems to 'hang' ... It is taking about 75 ...
4
2010-03-01T12:34:00Z
2,731,995
<p>A comment to those suggesting using 'socket.setdefaulttimeout()'. Internally, ftplib makes use of sock.makefile(). According to the python docs, you shouldn't mix makefile() with timeouts. Specifically: <a href="http://docs.python.org/library/socket.html#socket.socket.makefile" rel="nofollow">http://docs.python...
1
2010-04-28T18:01:32Z
[ "python" ]
python socket related question
2,355,794
<p>im totally new to socket programming in python. i was read some tutorial and manual, but i didn't found what i want to make python related socket script in manual or tutorial.</p> <p>i want to make socket script which can send some info to server and also receive some info from server. For example, i want to send m...
0
2010-03-01T12:42:21Z
2,356,308
<p>A Python library to connect to MSN Messenger service:</p> <p><a href="http://blitiri.com.ar/p/msnlib/" rel="nofollow">http://blitiri.com.ar/p/msnlib/</a></p> <p>(Disclaimer: never used this myself.)</p>
1
2010-03-01T14:08:04Z
[ "python", "sockets" ]
python ImportError: No module named primes
2,355,953
<p>I'm really new to Python. I'm trying to import a third party module called primes.py. I have placed this module in C:\Python26\Lib (the location where I installed Python). I then have another file which is trying to import this module. The file attempting to import primes is located at C:\Python26.</p> <p>In my ...
0
2010-03-01T13:08:05Z
2,355,967
<p>Put primes.py in the <code>lib/site-packages/</code> directory.</p> <p>Also: no need to put your own Python files under the installation directory: I'd advise you to put them somewhere else (where it makes sense).</p>
0
2010-03-01T13:10:27Z
[ "python", "importerror" ]
python ImportError: No module named primes
2,355,953
<p>I'm really new to Python. I'm trying to import a third party module called primes.py. I have placed this module in C:\Python26\Lib (the location where I installed Python). I then have another file which is trying to import this module. The file attempting to import primes is located at C:\Python26.</p> <p>In my ...
0
2010-03-01T13:08:05Z
2,355,970
<p>you probably should located this under <code>site-packages</code> directory <strong>or</strong> a private folder instead. Check your <code>sys.path</code> to understand your <code>import</code> paths.</p>
1
2010-03-01T13:10:50Z
[ "python", "importerror" ]
python ImportError: No module named primes
2,355,953
<p>I'm really new to Python. I'm trying to import a third party module called primes.py. I have placed this module in C:\Python26\Lib (the location where I installed Python). I then have another file which is trying to import this module. The file attempting to import primes is located at C:\Python26.</p> <p>In my ...
0
2010-03-01T13:08:05Z
2,355,977
<p>The module needs to be on your PYTHONPATH or in the same directory as the script, app, or module that is trying to import the module.</p> <p>I'm not a Windows programmer but if you have placed the module in 'C:\Python26\Lib' and your path is set to 'C:\Python26' you need to add '\Python26\Lib' to your PYTHONPATH. I...
2
2010-03-01T13:11:26Z
[ "python", "importerror" ]
At what point does importing become the correct solution?
2,356,036
<p>This weekend I was working on a project and I needed to use a binomial distribution to test the probability of an event (the probability that x of y characters would be alphanumeric given random bytes). My first solution was to write the test myself since it is rather simple.</p> <pre><code>def factorial(n): i...
3
2010-03-01T13:24:34Z
2,356,065
<p><strong>"when should I use code already written at the cost of including far more than I need</strong>"</p> <p>Always.</p> <p><strong>When should I just write my own implementation?</strong></p> <p>Never.</p> <p>The "including far more than I need" question is generally quite silly. What do you care how much is...
5
2010-03-01T13:29:25Z
[ "python", "import" ]
At what point does importing become the correct solution?
2,356,036
<p>This weekend I was working on a project and I needed to use a binomial distribution to test the probability of an event (the probability that x of y characters would be alphanumeric given random bytes). My first solution was to write the test myself since it is rather simple.</p> <pre><code>def factorial(n): i...
3
2010-03-01T13:24:34Z
2,362,780
<p>The answer depends on who will use your application and how widely it will be distributed. The Unix/Linux folks tend to heavily favour use of existing libraries, because they are used to every machine being a development machine that can rebuild its own software from source. Partly this is because of necessity, as n...
0
2010-03-02T11:37:56Z
[ "python", "import" ]
Tower of hanoi, python -> scheme, shows error. What am I missing?
2,356,229
<p>The python implementation</p> <pre><code>import sys def move(src, dst, tmp, num): if num == 1: print 'Move from', src, 'to', dst else: move(src, tmp, dst, num-1) move(src, dst, tmp, 1) move(tmp, dst, src, num-1) move('left', 'right', 'middle', int(sys.argv[1])) </code></pre> <p>Gi...
4
2010-03-01T13:55:29Z
2,356,374
<pre><code> ((move src tmp dst (- num 1)) (move src dst tmp 1) (move tmp dst src (- num 1))) </code></pre> <p>The above code doesn't do what you think it does :) </p> <p>To execute a series of expressions / statements you need something like this:</p> <pre><code>((λ () (move src tmp dst (- num 1)) (move sr...
4
2010-03-01T14:15:01Z
[ "python", "scheme", "towers-of-hanoi" ]
Why does supplying stdin to subprocess.Popen cause what is written to stdout to change?
2,356,391
<p>I'm using Python's subprocess.Popen to perform some FTP using the binary client of the host operating system. I can't use ftplib or any other library for various reasons.</p> <p>The behavior of the binary seems to change if I attach a stdin handler to the Popen instance. For example, using XP's ftp client, which ac...
5
2010-03-01T14:18:53Z
2,356,437
<p>The program may be using <a href="http://linux.die.net/man/3/isatty"><code>isatty(3)</code></a> to detect presence of a tty on stdin.</p>
5
2010-03-01T14:29:11Z
[ "python", "subprocess", "stdout", "stdin", "popen" ]
Why does supplying stdin to subprocess.Popen cause what is written to stdout to change?
2,356,391
<p>I'm using Python's subprocess.Popen to perform some FTP using the binary client of the host operating system. I can't use ftplib or any other library for various reasons.</p> <p>The behavior of the binary seems to change if I attach a stdin handler to the Popen instance. For example, using XP's ftp client, which ac...
5
2010-03-01T14:18:53Z
2,357,658
<p>I think I read somewhere (but can't remember where) that Windows ftp client came from one of the original BSD implementations. In that it would certainly shares some relationship with Mac OS X's ftp implementation. </p> <p>For me, this is not related to Popen but to the client ftp program implementation, which make...
3
2010-03-01T17:19:45Z
[ "python", "subprocess", "stdout", "stdin", "popen" ]
Tell if python is in interactive mode
2,356,399
<p>In a python script, is there any way to tell if the interpreter is in interactive mode? This would be useful, for instance, when you run an interactive python session and import a module, slightly different code is executed (for example, log file writing is turned off, or a figure won't be produced, so you can inter...
28
2010-03-01T14:20:57Z
2,356,420
<p><code>__main__.__file__</code> doesn't exist in the interactive interpreter:</p> <pre><code>import __main__ as main print hasattr(main, '__file__') </code></pre> <p>This also goes for code run via <code>python -c</code>, but not <code>python -m</code>.</p>
41
2010-03-01T14:25:26Z
[ "python", "interactive", "python-2.5", "python-2.x" ]
Tell if python is in interactive mode
2,356,399
<p>In a python script, is there any way to tell if the interpreter is in interactive mode? This would be useful, for instance, when you run an interactive python session and import a module, slightly different code is executed (for example, log file writing is turned off, or a figure won't be produced, so you can inter...
28
2010-03-01T14:20:57Z
2,356,427
<p><a href="http://docs.python.org/library/sys.html#sys.ps1" rel="nofollow"><code>sys.ps1</code></a> and <a href="http://docs.python.org/library/sys.html#sys.ps2" rel="nofollow"><code>sys.ps2</code></a> are only defined in interactive mode.</p>
15
2010-03-01T14:27:50Z
[ "python", "interactive", "python-2.5", "python-2.x" ]
Tell if python is in interactive mode
2,356,399
<p>In a python script, is there any way to tell if the interpreter is in interactive mode? This would be useful, for instance, when you run an interactive python session and import a module, slightly different code is executed (for example, log file writing is turned off, or a figure won't be produced, so you can inter...
28
2010-03-01T14:20:57Z
2,356,445
<p>From <a href="http://docs.python.org/using/cmdline.html">TFM</a>: If no interface option is given, -i is implied, sys.argv[0] is an empty string ("") and the current directory will be added to the start of sys.path.</p> <p>If the user invoked the interpreter with <code>python</code> and no arguments, as you mention...
5
2010-03-01T14:30:18Z
[ "python", "interactive", "python-2.5", "python-2.x" ]
Tell if python is in interactive mode
2,356,399
<p>In a python script, is there any way to tell if the interpreter is in interactive mode? This would be useful, for instance, when you run an interactive python session and import a module, slightly different code is executed (for example, log file writing is turned off, or a figure won't be produced, so you can inter...
28
2010-03-01T14:20:57Z
6,615,078
<p>Here's something that would work. Put the following code snippet in a file, and assign the path to that file to the <code>PYTHONSTARTUP</code> environment variable.</p> <pre><code>__pythonIsInteractive__ = None </code></pre> <p>And then you can use</p> <pre><code>if __name__=="__main__": #do stuff elif '__pyt...
-2
2011-07-07T18:03:24Z
[ "python", "interactive", "python-2.5", "python-2.x" ]
Tell if python is in interactive mode
2,356,399
<p>In a python script, is there any way to tell if the interpreter is in interactive mode? This would be useful, for instance, when you run an interactive python session and import a module, slightly different code is executed (for example, log file writing is turned off, or a figure won't be produced, so you can inter...
28
2010-03-01T14:20:57Z
6,879,085
<p>Use <a href="http://docs.python.org/library/sys.html#sys.flags" rel="nofollow"><code>sys.flags</code></a>:</p> <pre><code>if sys.flags.interactive: #interactive else: #not interactive </code></pre>
3
2011-07-29T21:09:54Z
[ "python", "interactive", "python-2.5", "python-2.x" ]
Tell if python is in interactive mode
2,356,399
<p>In a python script, is there any way to tell if the interpreter is in interactive mode? This would be useful, for instance, when you run an interactive python session and import a module, slightly different code is executed (for example, log file writing is turned off, or a figure won't be produced, so you can inter...
28
2010-03-01T14:20:57Z
24,724,674
<p>The following works both with and without the -i switch:</p> <pre><code>#!/usr/bin/python import sys # Set the interpreter bool try: if sys.ps1: interpreter = True except AttributeError: interpreter = False if sys.flags.interactive: interpreter = True # Use the interpreter bool if interpreter: print 'W...
1
2014-07-13T16:13:54Z
[ "python", "interactive", "python-2.5", "python-2.x" ]
Problems with nested loops…
2,356,408
<p><br> I’m going to explain to you in details of what I want to achieve.<br> I have 2 programs about dictionaries.<br> The code for program 1 is here:</p> <pre><code>import re words = {'i':'jeg','am':'er','happy':'glad'} text = "I am happy.".split() translation = [] for word in text: word_mod = re.sub('[^a-z0...
1
2010-03-01T14:23:31Z
4,473,540
<p>My solution flow would be something like this:</p> <pre><code>dict = ... max_group = len(max(dict)) input = ... textWPunc = input.lower().split() textOnly = [re.sub('[^a-z0-9]', '', x) for x in input.lower().split()] translation = [] while textOnly: for m in [max_group..0]: if textOnly[:m] in words: ...
0
2010-12-17T18:15:30Z
[ "python" ]
Python: Import Data from Open Office calc with lxml
2,356,451
<p>How can I import data for example for the field A1? When I use etree.parse() I get an error, because I dont have a xml file. </p>
1
2010-03-01T14:31:36Z
2,356,675
<p>It's a zip file:</p> <pre><code>import zipfile from lxml import etree z = zipfile.ZipFile('mydocument.ods') data = z.read('content.xml') data = etree.XML(data) etree.dump(data) </code></pre>
1
2010-03-01T15:04:43Z
[ "python", "import", "lxml", "openoffice-calc" ]
Python, OpenOffice: Programatically Manipulating spreadsheets
2,356,473
<p>I have an spreadsheet-based automated report that needs to be created daily, with some charts, aggregating functions (e.g. SUM and AVERAGE) and formatted cells (Dates, percentage, etc.).</p> <p>I have tried to <a href="http://stackoverflow.com/questions/2260678/python-creating-excel-worksheets-with-charts">write th...
9
2010-03-01T14:35:47Z
2,356,483
<p>Are you looking for this: <a href="http://ooopy.sourceforge.net/" rel="nofollow">http://ooopy.sourceforge.net/</a> </p> <p>Open Office.org API's accessible from Python?</p> <p>Or this? <a href="http://api.openoffice.org/" rel="nofollow">http://api.openoffice.org/</a></p> <p>The OpenOffice.org API Project?</p> ...
1
2010-03-01T14:37:45Z
[ "python", "excel", "openoffice-calc" ]
Python, OpenOffice: Programatically Manipulating spreadsheets
2,356,473
<p>I have an spreadsheet-based automated report that needs to be created daily, with some charts, aggregating functions (e.g. SUM and AVERAGE) and formatted cells (Dates, percentage, etc.).</p> <p>I have tried to <a href="http://stackoverflow.com/questions/2260678/python-creating-excel-worksheets-with-charts">write th...
9
2010-03-01T14:35:47Z
2,356,505
<p>You can use <a href="http://wiki.services.openoffice.org/wiki/Python">PyUNO</a>, a Python library to use UNO API.</p> <p><a href="http://www.oooforum.org/forum/viewtopic.phtml?p=56037#56037">Here</a> is a Python example to do some manipulations in a Calc document.</p>
5
2010-03-01T14:40:34Z
[ "python", "excel", "openoffice-calc" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
2,356,510
<p>The <a href="https://docs.python.org/2/library/math.html#math.ceil">ceil</a> (ceiling) function:</p> <pre><code>import math print math.ceil(4.2) </code></pre>
341
2010-03-01T14:40:58Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
2,356,515
<p><a href="https://docs.python.org/2/library/math.html#math.ceil" rel="nofollow">Use <code>math.ceil</code></a> to round up:</p> <pre><code>&gt;&gt;&gt; import math &gt;&gt;&gt; math.ceil(5.4) 6.0 </code></pre> <p><strong>NOTE</strong>: The input should be float.</p> <p>If you need an integer, call <code>int</code>...
11
2010-03-01T14:41:23Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
7,950,627
<p>Interesting Python 2.x issue to keep in mind:</p> <pre><code>&gt;&gt;&gt; import math &gt;&gt;&gt; math.ceil(4500/1000) 4.0 &gt;&gt;&gt; math.ceil(4500/1000.0) 5.0 </code></pre> <p>The problem is that dividing two ints in python produces another int and that's rounded before the ceiling call. You have to make one ...
90
2011-10-31T06:39:44Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
16,241,082
<p>You might also like numpy:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; np.ceil(2.3) 3.0 </code></pre> <p>I'm not saying it's better than math, but if you were already using numpy for other purposes, you can keep your code consistent. </p> <p>Anyway, just a detail I came across. I use numpy a lot a...
20
2013-04-26T16:27:43Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
23,590,097
<p>I know this answer is for a question from a while back, but if you don't want to import math and you just want to round up, this works for me.</p> <pre><code>&gt;&gt;&gt; int(21 / 5) 4 &gt;&gt;&gt; int(21 / 5) + (21 % 5 &gt; 0) 5 </code></pre> <p>The first part becomes 4 and the second part evaluates to "True" if ...
36
2014-05-11T07:28:39Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
24,225,543
<p>To do it without any import:</p> <pre><code>&gt;&gt;&gt; round_up = lambda num: int(num + 1) if int(num) != num else int(num) &gt;&gt;&gt; round_up(2.0) 2 &gt;&gt;&gt; round_up(2.1) 3 </code></pre>
-2
2014-06-15T00:34:53Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
25,045,303
<p>Be shure rounded value should be float </p> <pre><code>a = 8 b = 21 print math.ceil(a / b) &gt;&gt;&gt; 0 </code></pre> <p>but</p> <pre><code>print math.ceil(float(a) / b) &gt;&gt;&gt; 1.0 </code></pre>
4
2014-07-30T19:27:18Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
27,938,410
<p>I know this is from quite a while back, but I found a quite interesting answer, so here goes:</p> <pre><code>-round(-x-0.5) </code></pre> <p>This fixes the edges cases and works for both positive and negative numbers, and doesn't require any function import</p> <p>Cheers</p>
-1
2015-01-14T08:15:01Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
29,308,619
<p>The syntax may not be as pythonic as one might like, but it is a powerful library.</p> <p><a href="https://docs.python.org/2/library/decimal.html">https://docs.python.org/2/library/decimal.html</a></p> <pre><code>from decimal import * print(int(Decimal(2.3).quantize(Decimal('1.'), rounding=ROUND_UP))) </code></pre...
5
2015-03-27T19:21:19Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
35,125,872
<p>If working with integers, one way of rounding up is to take advantage of the fact that <code>//</code> rounds down: Just do the division on the negative number, then negate the answer. No import, floating point, or conditional needed.</p> <pre><code>rounded_up = -(-numerator // denominator) </code></pre> <p>For e...
10
2016-02-01T08:23:29Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
37,558,577
<p>I'm basically a beginner at Python, but if you're just trying to round up instead of down why not do:</p> <pre><code>round(integer) + 1 </code></pre>
-2
2016-06-01T02:46:14Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
38,474,535
<p>You can use floor devision and add 1 to it. 2.3 // 2 + 1</p>
0
2016-07-20T07:07:54Z
[ "python", "floating-point", "integer", "rounding" ]
How do you round UP a number in Python?
2,356,501
<p>This problem is killing me. How does one roundup a number UP in Python?</p> <p>I tried round(number) but it round the number down. Example:</p> <pre><code>round(2.3) = 2.0 and not 3, what I would like </code></pre> <p>The I tried int(number + .5) but it round the number down again! Example:</p> <pre><code>int(2....
165
2010-03-01T14:40:04Z
39,383,982
<p>I'm surprised I haven't seen this answer yet <code>round(x + 0.4999)</code>, so I'm going to put it down. Note that this works with any Python version. Changes made to the Python rounding scheme has made things difficult. See this <a href="http://stackoverflow.com/questions/10825926/python-3-x-rounding-behavior">pos...
1
2016-09-08T06:31:20Z
[ "python", "floating-point", "integer", "rounding" ]
Django -- How to filter objects with an "author" from a set of "authors"(users)?
2,356,551
<p>How to filter objects with an "<code>author</code>" from a set of "<code>author</code>s"(<code>User</code>s)?</p> <p>The "objects" are <code>Post</code>s, having an <code>author</code>(<code>ForeignKey</code> to <code>User</code>).</p> <p>I'm pretty much stumped by this, so I'd appreciate help with it. Of course o...
1
2010-03-01T14:46:21Z
2,356,572
<p>Something like:</p> <pre><code>Post.objects.filter(author=user) </code></pre> <p>Where <code>user</code> is the relevant user should work, but it's hard to give a good answer with no models</p> <p><strong>EDIT</strong></p> <p>Now that I understand your question, try this:</p> <pre><code>Post.objects.filter(auth...
4
2010-03-01T14:49:41Z
[ "python", "database", "django", "django-models" ]
Django -- How to filter objects with an "author" from a set of "authors"(users)?
2,356,551
<p>How to filter objects with an "<code>author</code>" from a set of "<code>author</code>s"(<code>User</code>s)?</p> <p>The "objects" are <code>Post</code>s, having an <code>author</code>(<code>ForeignKey</code> to <code>User</code>).</p> <p>I'm pretty much stumped by this, so I'd appreciate help with it. Of course o...
1
2010-03-01T14:46:21Z
2,356,623
<pre><code>Post.objects.filter(author__in=setofusers) </code></pre>
2
2010-03-01T14:55:58Z
[ "python", "database", "django", "django-models" ]
Python try/except ... function always returns false
2,356,573
<p>I'm trying to figure out the problem in this short paragraph of code. Any help would be appreciated. Regardless of what I specify User.email to be, it always returns false.</p> <pre><code>def add(self): #1 -- VALIDATE EMAIL ADDRESS #Check that e-mail has been completed try: #Validate if e-mai...
2
2010-03-01T14:50:24Z
2,356,607
<p>Actually you have two values.</p> <ul> <li><code>0</code></li> <li><code>None</code></li> </ul> <p>If you print the value instead of using it in an if-statement, you'll see the two conditions. Consider adding print statements to see what the value actually is.</p> <pre><code>if (isAddressValid(self.email) == 0):...
1
2010-03-01T14:53:14Z
[ "python", "pylons" ]
Python try/except ... function always returns false
2,356,573
<p>I'm trying to figure out the problem in this short paragraph of code. Any help would be appreciated. Regardless of what I specify User.email to be, it always returns false.</p> <pre><code>def add(self): #1 -- VALIDATE EMAIL ADDRESS #Check that e-mail has been completed try: #Validate if e-mai...
2
2010-03-01T14:50:24Z
2,356,609
<p>You haven't included a <code>return</code> statement for the positive case... Also, when a function doesn't include a <code>return</code> statement, the caller receives <code>None</code> instead... </p> <pre><code>def add(self): #1 -- VALIDATE EMAIL ADDRESS #Check that e-mail has been completed try: ...
4
2010-03-01T14:53:34Z
[ "python", "pylons" ]
Python try/except ... function always returns false
2,356,573
<p>I'm trying to figure out the problem in this short paragraph of code. Any help would be appreciated. Regardless of what I specify User.email to be, it always returns false.</p> <pre><code>def add(self): #1 -- VALIDATE EMAIL ADDRESS #Check that e-mail has been completed try: #Validate if e-mai...
2
2010-03-01T14:50:24Z
2,356,610
<p>Im not sure what problem you are talking about , but you are always returning 0</p> <p>Try adding an else clause for the case of the Valid Email (which you are currently not considering)</p> <pre><code>def add(self): #1 -- VALIDATE EMAIL ADDRESS #Check that e-mail has been completed try: #Validate if e-mail ...
0
2010-03-01T14:53:37Z
[ "python", "pylons" ]
Python try/except ... function always returns false
2,356,573
<p>I'm trying to figure out the problem in this short paragraph of code. Any help would be appreciated. Regardless of what I specify User.email to be, it always returns false.</p> <pre><code>def add(self): #1 -- VALIDATE EMAIL ADDRESS #Check that e-mail has been completed try: #Validate if e-mai...
2
2010-03-01T14:50:24Z
2,359,611
<p>You said <code>isAddressValid</code> is a method, right? Since <code>add</code> is also a method, perhaps you have to prepend a <code>self.</code>:</p> <pre><code>if (self.isAddressValid(self.email) == 0): </code></pre> <p>This most probably will deal with your <code>NameError</code>.</p> <p>After that, add an <c...
0
2010-03-01T22:33:38Z
[ "python", "pylons" ]
Python try/except ... function always returns false
2,356,573
<p>I'm trying to figure out the problem in this short paragraph of code. Any help would be appreciated. Regardless of what I specify User.email to be, it always returns false.</p> <pre><code>def add(self): #1 -- VALIDATE EMAIL ADDRESS #Check that e-mail has been completed try: #Validate if e-mai...
2
2010-03-01T14:50:24Z
2,359,878
<p>If I were re-writing this code, I would go for something like this:</p> <pre><code>def add(self): try: if not isAddressValid(self.email): self.errors['email'] = 'You have entered an invalid e-mail address'; except NameError: self.errors['email'] = 'Please enter your e-mail' r...
1
2010-03-01T23:26:01Z
[ "python", "pylons" ]
How do you make Python wait so that you can read the output?
2,356,651
<p>I've always been a heavy user of Notepad2, as it is fast, feature-rich, and supports syntax highlighting. Recently I've been using it for Python. </p> <p>My problem: when I finish editing a certain Python source code, and try to launch it, the screen disappears before I can see the output pop up. Is there any way ...
2
2010-03-01T15:00:08Z
2,356,657
<p>you could start in the command window. e.g.:</p> <pre><code>c:\tmp\python&gt;main.py </code></pre> <p>adding <code>raw_input()</code> (or <code>input()</code> in py3k) at the end of your script will let you <em>freeze</em> it for until enter is pressed, but it's not a good thing to do.</p>
3
2010-03-01T15:02:10Z
[ "python", "ide" ]
How do you make Python wait so that you can read the output?
2,356,651
<p>I've always been a heavy user of Notepad2, as it is fast, feature-rich, and supports syntax highlighting. Recently I've been using it for Python. </p> <p>My problem: when I finish editing a certain Python source code, and try to launch it, the screen disappears before I can see the output pop up. Is there any way ...
2
2010-03-01T15:00:08Z
2,356,660
<p>You can add a call to <code>raw_input()</code> to the end of your script in order to make it wait until you press Enter.</p>
0
2010-03-01T15:02:22Z
[ "python", "ide" ]
How do you make Python wait so that you can read the output?
2,356,651
<p>I've always been a heavy user of Notepad2, as it is fast, feature-rich, and supports syntax highlighting. Recently I've been using it for Python. </p> <p>My problem: when I finish editing a certain Python source code, and try to launch it, the screen disappears before I can see the output pop up. Is there any way ...
2
2010-03-01T15:00:08Z
2,356,661
<p>This is a "problem" with Notepad2, not Python itself.</p> <p>Unless you want to use input()/sleep (or any other blocking function) in your scripts, I think you have to turn to the settings in Notepad2 and see what that has to offer.</p>
3
2010-03-01T15:02:32Z
[ "python", "ide" ]
How do you make Python wait so that you can read the output?
2,356,651
<p>I've always been a heavy user of Notepad2, as it is fast, feature-rich, and supports syntax highlighting. Recently I've been using it for Python. </p> <p>My problem: when I finish editing a certain Python source code, and try to launch it, the screen disappears before I can see the output pop up. Is there any way ...
2
2010-03-01T15:00:08Z
2,359,165
<p>If you don't want to use <code>raw_input()</code> or <code>input()</code> you could log your output (stdout, stderr) to a file or files.</p> <p>You could either use the <a href="http://docs.python.org/library/logging.html" rel="nofollow"><code>logging</code></a> module, or just redirect <code>sys.stdout</code> and ...
2
2010-03-01T21:22:54Z
[ "python", "ide" ]
Reusing module references in Python (Matplotlib)
2,356,695
<p>I think I may have misunderstood something here... But here goes.</p> <p>I'm using the psd method in matplotlib inside a loop, I'm not making it plot anything, I just want the numerical result, so:</p> <pre><code>import pylab as pyl ... psdResults = pyl.psd(inputData, NFFT=512, Fs=sampleRate, window=blackman) </co...
2
2010-03-01T15:08:39Z
2,356,930
<p>Try this:</p> <pre><code>from matplotlib import mlab psdResults = mlab.psd(inputData, NFFT=512, Fs=sampleRate, window=blackman) </code></pre> <p>Does that improve the situation?</p>
3
2010-03-01T15:40:02Z
[ "python", "matplotlib" ]