title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
listlengths
1
5
How would one log into a phpBB3 forum through a Python script using urllib, urllib2 and ClientCookie?
112,768
<p>(ClientCookie is a module for (automatic) cookie-handling: <a href="http://wwwsearch.sourceforge.net/ClientCookie" rel="nofollow">http://wwwsearch.sourceforge.net/ClientCookie</a>)</p> <pre><code># I encode the data I'll be sending: data = urllib.urlencode({'username': 'mandark', 'password': 'deedee'}) # And I sen...
2
2008-09-22T01:28:57Z
112,819
<p>Have you tried fetching the login page first?</p> <p>I would suggest using <a href="https://addons.mozilla.org/en-US/firefox/addon/966" rel="nofollow">Tamper Data</a> to have a peek at exactly what's being sent when you request the login page and then log in normally using a web browser from a fresh start, with no ...
2
2008-09-22T01:54:20Z
[ "python", "post", "urllib" ]
How would one log into a phpBB3 forum through a Python script using urllib, urllib2 and ClientCookie?
112,768
<p>(ClientCookie is a module for (automatic) cookie-handling: <a href="http://wwwsearch.sourceforge.net/ClientCookie" rel="nofollow">http://wwwsearch.sourceforge.net/ClientCookie</a>)</p> <pre><code># I encode the data I'll be sending: data = urllib.urlencode({'username': 'mandark', 'password': 'deedee'}) # And I sen...
2
2008-09-22T01:28:57Z
112,895
<p>I'd recommend taking a look at the <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a> library; it's designed for precisely this type of task. It's also far easier than doing it by hand.</p>
1
2008-09-22T02:33:43Z
[ "python", "post", "urllib" ]
Python - When to use file vs open
112,970
<p>What's the difference between file and open in Python? When should I use which one? (Say I'm in 2.5)</p>
119
2008-09-22T03:04:14Z
112,980
<p>You should always use <code>open()</code>.</p> <p>As the <a href="http://docs.python.org/2/library/functions.html#file" rel="nofollow" title="BuiltinFuncs Doc">documentation</a> states:</p> <blockquote> <p>When opening a file, it's preferable to use open() instead of invoking this constructor directly. file ...
129
2008-09-22T03:07:44Z
[ "python", "file" ]
Python - When to use file vs open
112,970
<p>What's the difference between file and open in Python? When should I use which one? (Say I'm in 2.5)</p>
119
2008-09-22T03:04:14Z
112,982
<p>Functionally, the two are the same; <code>open</code> will call <code>file</code> anyway, so currently the difference is a matter of style. The <a href="http://docs.python.org/lib/built-in-funcs.html" rel="nofollow">Python docs</a> recommend using <code>open</code>. </p> <blockquote> <p>When opening a file, it's ...
4
2008-09-22T03:08:37Z
[ "python", "file" ]
Python - When to use file vs open
112,970
<p>What's the difference between file and open in Python? When should I use which one? (Say I'm in 2.5)</p>
119
2008-09-22T03:04:14Z
112,989
<p>Two reasons: The python philosophy of "There ought to be one way to do it" and <code>file</code> is going away.</p> <p><code>file</code> is the actual type (using e.g. <code>file('myfile.txt')</code> is calling its constructor). <code>open</code> is a factory function that will return a file object.</p> <p>In pyth...
28
2008-09-22T03:10:16Z
[ "python", "file" ]
Python - When to use file vs open
112,970
<p>What's the difference between file and open in Python? When should I use which one? (Say I'm in 2.5)</p>
119
2008-09-22T03:04:14Z
112,990
<p>Only ever use open() for opening files. file() is actually being removed in 3.0, and it's deprecated at the moment. They've had a sort of strange relationship, but file() is going now, so there's no need to worry anymore.</p> <p>The following is from the Python 2.6 docs. [bracket stuff] added by me.</p> <blockquot...
3
2008-09-22T03:10:45Z
[ "python", "file" ]
Python - When to use file vs open
112,970
<p>What's the difference between file and open in Python? When should I use which one? (Say I'm in 2.5)</p>
119
2008-09-22T03:04:14Z
112,993
<p>According to Mr Van Rossum, although open() is currently an alias for file() you should use open() because this might change in the future.</p>
1
2008-09-22T03:12:27Z
[ "python", "file" ]
Python - When to use file vs open
112,970
<p>What's the difference between file and open in Python? When should I use which one? (Say I'm in 2.5)</p>
119
2008-09-22T03:04:14Z
113,050
<p><code>file()</code> is a type, like an int or a list. <code>open()</code> is a function for opening files, and will return a <code>file</code> object.</p> <p>This is an example of when you should use open:</p> <pre><code>f = open(filename, 'r') for line in f: process(line) f.close() </code></pre> <p>This is a...
16
2008-09-22T03:32:08Z
[ "python", "file" ]
Writing to the windows logs in Python
113,007
<p>Is it possible to write to the windows logs in python?</p>
9
2008-09-22T03:15:31Z
113,011
<p>Yes, just use Windows Python Extension, as stated <a href="http://www.ravenbrook.com/project/p4dti/master/design/win32-eventlog/">here</a>.</p> <pre><code>import win32evtlogutil win32evtlogutil.ReportEvent(ApplicationName, EventID, EventCategory, EventType, Inserts, Data, SID) </code></pre>
12
2008-09-22T03:16:58Z
[ "python", "windows", "logging" ]
What are the Python equivalents of the sighold and sigrelse functions found in C?
113,170
<p>It appears the Python signal module doesn't have anything similar to the sighold and sigrelse functions found in C, using signal.h. Are there Python equivalents of <em>any</em> sort?</p> <p>Many thanks!</p>
3
2008-09-22T04:25:22Z
113,201
<p>There is no way to ``block'' signals temporarily from critical sections (since this is not supported by all Unix flavors).</p> <p><a href="https://docs.python.org/library/signal.html" rel="nofollow">https://docs.python.org/library/signal.html</a></p>
2
2008-09-22T04:36:29Z
[ "python", "signals" ]
What are the Python equivalents of the sighold and sigrelse functions found in C?
113,170
<p>It appears the Python signal module doesn't have anything similar to the sighold and sigrelse functions found in C, using signal.h. Are there Python equivalents of <em>any</em> sort?</p> <p>Many thanks!</p>
3
2008-09-22T04:25:22Z
113,219
<p>There are no direct bindings for this in Python. Accessing them through ctypes is easy enough; here is an example.</p> <pre><code>import ctypes, signal libc = ctypes.cdll.LoadLibrary("libc.so.6") libc.sighold(signal.SIGKILL) libc.sigrelse(signal.SIGKILL) </code></pre> <p>I'm not familiar with the use of these call...
2
2008-09-22T04:47:24Z
[ "python", "signals" ]
How do I use owfs to read an iButton temperature logger?
113,185
<p>I've installed <a href="http://www.owfs.org/" rel="nofollow"><code>owfs</code></a> and am trying to read the data off a <a href="http://www.maxim-ic.com/quick_view2.cfm/qv_pk/4088" rel="nofollow">iButton temperature logger</a>.</p> <p><code>owfs</code> lets me mount the iButton as a fuse filesystem and I can see al...
9
2008-09-22T04:30:19Z
117,532
<p>I don't think there is a clever way. owpython doesn't support that telling from the API documentation. I guess <code>/proc</code> is your safest bet. Maybe have a look at the source of the owpython module and check if you can find out how it works.</p>
2
2008-09-22T20:47:15Z
[ "python", "ubuntu", "1wire" ]
How do I use owfs to read an iButton temperature logger?
113,185
<p>I've installed <a href="http://www.owfs.org/" rel="nofollow"><code>owfs</code></a> and am trying to read the data off a <a href="http://www.maxim-ic.com/quick_view2.cfm/qv_pk/4088" rel="nofollow">iButton temperature logger</a>.</p> <p><code>owfs</code> lets me mount the iButton as a fuse filesystem and I can see al...
9
2008-09-22T04:30:19Z
181,511
<p>I've also had problems with owfs. I found it to be an overengineered solution to what is a simple problem. Now I'm using the <a href="http://www.digitemp.com/" rel="nofollow">DigiTemp</a> code without a problem. I found it to be flexible and reliable. For instance, I store the room's temperature in a log file ev...
2
2008-10-08T06:07:29Z
[ "python", "ubuntu", "1wire" ]
How do I use owfs to read an iButton temperature logger?
113,185
<p>I've installed <a href="http://www.owfs.org/" rel="nofollow"><code>owfs</code></a> and am trying to read the data off a <a href="http://www.maxim-ic.com/quick_view2.cfm/qv_pk/4088" rel="nofollow">iButton temperature logger</a>.</p> <p><code>owfs</code> lets me mount the iButton as a fuse filesystem and I can see al...
9
2008-09-22T04:30:19Z
3,383,201
<p>Well I have just started to look at ibuttons and want to use python.</p> <p>This looks more promising:</p> <p><a href="http://www.ohloh.net/p/pyonewire" rel="nofollow">http://www.ohloh.net/p/pyonewire</a></p>
2
2010-08-01T18:22:06Z
[ "python", "ubuntu", "1wire" ]
Python-passing variable between classes
113,341
<p>I'm trying to create a character generation wizard for a game. In one class I calculate the attributes of the character. In a different class, I'm displaying to the user which specialties are available based on the attributes of the character. However, I can't remember how to pass variables between different classes...
2
2008-09-22T05:49:00Z
113,374
<p>If I understood you correctly, then the answer is: You can't.</p> <p>intelligence should be an attribute of WizardPageSimple, if you'd want both classes to inherit it.</p> <p>Depending on your situation, you might try to extract intelligence and related attributes into another baseclass. Then you could inherit fro...
0
2008-09-22T05:59:28Z
[ "python", "oop", "variables", "wxpython" ]
Python-passing variable between classes
113,341
<p>I'm trying to create a character generation wizard for a game. In one class I calculate the attributes of the character. In a different class, I'm displaying to the user which specialties are available based on the attributes of the character. However, I can't remember how to pass variables between different classes...
2
2008-09-22T05:49:00Z
113,388
<p>All you need is a reference. It's not really a simple problem that I can give some one-line solution to (other than a simple ugly global that would probably break something else), but one of program structure. You don't magically get access to a variable that was created on another instance of another class. You hav...
1
2008-09-22T06:05:58Z
[ "python", "oop", "variables", "wxpython" ]
Python-passing variable between classes
113,341
<p>I'm trying to create a character generation wizard for a game. In one class I calculate the attributes of the character. In a different class, I'm displaying to the user which specialties are available based on the attributes of the character. However, I can't remember how to pass variables between different classes...
2
2008-09-22T05:49:00Z
114,114
<p>You may have "Class" and "Instance" confused. It's not clear from your example, so I'll presume that you're using a lot of class definitions and don't have appropriate object instances of those classes.</p> <p>Classes don't really have usable attribute values. A class is just a common set of definitions for a col...
6
2008-09-22T10:12:50Z
[ "python", "oop", "variables", "wxpython" ]
Python-passing variable between classes
113,341
<p>I'm trying to create a character generation wizard for a game. In one class I calculate the attributes of the character. In a different class, I'm displaying to the user which specialties are available based on the attributes of the character. However, I can't remember how to pass variables between different classes...
2
2008-09-22T05:49:00Z
114,128
<p>Each page of a Wizard -- by itself -- shouldn't actually be the container for the information you're gathering.</p> <p>Read up on the <a href="http://en.wikipedia.org/wiki/Model-view-controller" rel="nofollow">Model-View-Control</a> design pattern. Your pages have the View and Control parts of the design. They ar...
3
2008-09-22T10:18:04Z
[ "python", "oop", "variables", "wxpython" ]
Python-passing variable between classes
113,341
<p>I'm trying to create a character generation wizard for a game. In one class I calculate the attributes of the character. In a different class, I'm displaying to the user which specialties are available based on the attributes of the character. However, I can't remember how to pass variables between different classes...
2
2008-09-22T05:49:00Z
120,109
<p>My problem was indeed the confusion of classes vs. instances. I was trying to do everything via classes without ever creating an actual instance. Plus, I was forcing the "BasicInfoPage" class to do too much work.</p> <p>Ultimately, I created a new class (<strong>BaseAttribs</strong>) to hold all the variables I nee...
2
2008-09-23T09:48:59Z
[ "python", "oop", "variables", "wxpython" ]
Is there a function in Python to split a string without ignoring the spaces?
113,534
<p>Is there a function in Python to split a string without ignoring the spaces in the resulting list? </p> <p>E.g:</p> <pre><code>s="This is the string I want to split".split() </code></pre> <p>gives me</p> <pre><code>&gt;&gt;&gt; s ['This', 'is', 'the', 'string', 'I', 'want', 'to', 'split'] </code></pre> <p>I wan...
12
2008-09-22T07:02:04Z
113,554
<p>The hard part with what you're trying to do is that you aren't giving it a character to split on. split() explodes a string on the character you provide to it, and removes that character.</p> <p>Perhaps this may help:</p> <pre><code>s = "String to split" mylist = [] for item in s.split(): mylist.append(item) ...
1
2008-09-22T07:07:58Z
[ "python", "split" ]
Is there a function in Python to split a string without ignoring the spaces?
113,534
<p>Is there a function in Python to split a string without ignoring the spaces in the resulting list? </p> <p>E.g:</p> <pre><code>s="This is the string I want to split".split() </code></pre> <p>gives me</p> <pre><code>&gt;&gt;&gt; s ['This', 'is', 'the', 'string', 'I', 'want', 'to', 'split'] </code></pre> <p>I wan...
12
2008-09-22T07:02:04Z
113,555
<pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; re.split(r"(\s+)", "This is the string I want to split") ['This', ' ', 'is', ' ', 'the', ' ', 'string', ' ', 'I', ' ', 'want', ' ', 'to', ' ', 'split'] </code></pre> <p>Using the capturing parentheses in re.split() causes the function to return the separators as well.</p>...
40
2008-09-22T07:08:04Z
[ "python", "split" ]
Is there a function in Python to split a string without ignoring the spaces?
113,534
<p>Is there a function in Python to split a string without ignoring the spaces in the resulting list? </p> <p>E.g:</p> <pre><code>s="This is the string I want to split".split() </code></pre> <p>gives me</p> <pre><code>&gt;&gt;&gt; s ['This', 'is', 'the', 'string', 'I', 'want', 'to', 'split'] </code></pre> <p>I wan...
12
2008-09-22T07:02:04Z
113,558
<p>I don't think there is a function in the standard library that does that by itself, but "partition" comes close</p> <p>The best way is probably to use regular expressions (which is how I'd do this in any language!)</p> <pre><code>import re print re.split(r"(\s+)", "Your string here") </code></pre>
4
2008-09-22T07:08:59Z
[ "python", "split" ]
Is there a function in Python to split a string without ignoring the spaces?
113,534
<p>Is there a function in Python to split a string without ignoring the spaces in the resulting list? </p> <p>E.g:</p> <pre><code>s="This is the string I want to split".split() </code></pre> <p>gives me</p> <pre><code>&gt;&gt;&gt; s ['This', 'is', 'the', 'string', 'I', 'want', 'to', 'split'] </code></pre> <p>I wan...
12
2008-09-22T07:02:04Z
16,123,808
<p>Silly answer just for the heck of it:</p> <pre><code>mystring.replace(" ","! !").split("!") </code></pre>
2
2013-04-20T18:34:12Z
[ "python", "split" ]
Is there a function in python to split a word into a list?
113,655
<p>Is there a function in python to split a word into a list of single letters? e.g:</p> <pre><code>s="Word to Split" </code></pre> <p>to get</p> <pre><code>wordlist=['W','o','r','d','','t','o' ....] </code></pre>
41
2008-09-22T07:40:50Z
113,662
<pre><code>&gt;&gt;&gt; list("Word to Split") ['W', 'o', 'r', 'd', ' ', 't', 'o', ' ', 'S', 'p', 'l', 'i', 't'] </code></pre>
119
2008-09-22T07:42:15Z
[ "python", "function", "split" ]
Is there a function in python to split a word into a list?
113,655
<p>Is there a function in python to split a word into a list of single letters? e.g:</p> <pre><code>s="Word to Split" </code></pre> <p>to get</p> <pre><code>wordlist=['W','o','r','d','','t','o' ....] </code></pre>
41
2008-09-22T07:40:50Z
113,680
<p>The easiest way is probably just to use <code>list()</code>, but there is at least one other option as well:</p> <pre><code>s = "Word to Split" wordlist = list(s) # option 1, wordlist = [ch for ch in s] # option 2, list comprehension. </code></pre> <p>They should <em>both</em> give you what you...
9
2008-09-22T07:46:45Z
[ "python", "function", "split" ]
Is there a function in python to split a word into a list?
113,655
<p>Is there a function in python to split a word into a list of single letters? e.g:</p> <pre><code>s="Word to Split" </code></pre> <p>to get</p> <pre><code>wordlist=['W','o','r','d','','t','o' ....] </code></pre>
41
2008-09-22T07:40:50Z
113,681
<p>The list function will do this</p> <pre><code>&gt;&gt;&gt; list('foo') ['f', 'o', 'o'] </code></pre>
1
2008-09-22T07:47:20Z
[ "python", "function", "split" ]
Is there a function in python to split a word into a list?
113,655
<p>Is there a function in python to split a word into a list of single letters? e.g:</p> <pre><code>s="Word to Split" </code></pre> <p>to get</p> <pre><code>wordlist=['W','o','r','d','','t','o' ....] </code></pre>
41
2008-09-22T07:40:50Z
115,195
<p>Abuse of the rules, same result: (x for x in 'Word to split')</p> <p>Actually an iterator, not a list. But it's likely you won't really care.</p>
2
2008-09-22T14:36:35Z
[ "python", "function", "split" ]
Deploying Django: How do you do it?
114,112
<p>I have tried following guides like <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modpython/">this one</a> but it just didnt work for me.</p> <p><strong>So my question is this:</strong> What is a good guide for deploying Django, and how do you deploy your Django.</p> <p>I keep hearing that capastra...
12
2008-09-22T10:11:48Z
114,127
<p>This looks like a good place to start: <a href="http://www.unessa.net/en/hoyci/2007/06/using-capistrano-deploy-django-apps/" rel="nofollow">http://www.unessa.net/en/hoyci/2007/06/using-capistrano-deploy-django-apps/</a></p>
0
2008-09-22T10:17:53Z
[ "python", "django-deployment" ]
Deploying Django: How do you do it?
114,112
<p>I have tried following guides like <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modpython/">this one</a> but it just didnt work for me.</p> <p><strong>So my question is this:</strong> What is a good guide for deploying Django, and how do you deploy your Django.</p> <p>I keep hearing that capastra...
12
2008-09-22T10:11:48Z
114,137
<p>The easiest way would be to use one of the sites on <a href="http://djangofriendly.com/hosts/" rel="nofollow">http://djangofriendly.com/hosts/</a> that will provide the hosting and set up for you, but even if you're wanting to roll your own it will allow you to see what set up other sites are using.</p>
-2
2008-09-22T10:20:42Z
[ "python", "django-deployment" ]
Deploying Django: How do you do it?
114,112
<p>I have tried following guides like <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modpython/">this one</a> but it just didnt work for me.</p> <p><strong>So my question is this:</strong> What is a good guide for deploying Django, and how do you deploy your Django.</p> <p>I keep hearing that capastra...
12
2008-09-22T10:11:48Z
114,228
<p>I have had success with <a href="http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango" rel="nofollow">mod_wsgi</a></p>
1
2008-09-22T10:55:39Z
[ "python", "django-deployment" ]
Deploying Django: How do you do it?
114,112
<p>I have tried following guides like <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modpython/">this one</a> but it just didnt work for me.</p> <p><strong>So my question is this:</strong> What is a good guide for deploying Django, and how do you deploy your Django.</p> <p>I keep hearing that capastra...
12
2008-09-22T10:11:48Z
114,268
<p><code>mod_wsgi</code> in combination with a <code>virtualenv</code> for all the dependencies, a mercurial checkout into the virtualenv and a <code>fabric</code> recipe to check out the changes on the server.</p> <p>I wrote an article about my usual workflow: <a href="http://lucumr.pocoo.org/2008/7/17/deploying-pyth...
7
2008-09-22T11:06:01Z
[ "python", "django-deployment" ]
Deploying Django: How do you do it?
114,112
<p>I have tried following guides like <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modpython/">this one</a> but it just didnt work for me.</p> <p><strong>So my question is this:</strong> What is a good guide for deploying Django, and how do you deploy your Django.</p> <p>I keep hearing that capastra...
12
2008-09-22T10:11:48Z
117,095
<p>In my previous work we had real genius guy on deployment duties, he deployed application (Python, SQL, Perl and Java code) as set of deb files built for Ubuntu. Unfortunately now, I have no such support. We are deploying apps manually to virtualenv-ed environments with separate nginx configs for FastCGI. We use <a h...
1
2008-09-22T19:48:45Z
[ "python", "django-deployment" ]
Deploying Django: How do you do it?
114,112
<p>I have tried following guides like <a href="http://docs.djangoproject.com/en/dev/howto/deployment/modpython/">this one</a> but it just didnt work for me.</p> <p><strong>So my question is this:</strong> What is a good guide for deploying Django, and how do you deploy your Django.</p> <p>I keep hearing that capastra...
12
2008-09-22T10:11:48Z
1,546,416
<p>I use mod_python, and have every site in a git repository with the following subdirs:</p> <ul> <li>mysite</li> <li>template</li> <li>media</li> </ul> <p>I have <code>mysite/settings.py</code> in <code>.gitignore</code>, and work like this:</p> <ol> <li>do development on my local machine</li> <li>create remote rep...
0
2009-10-09T22:44:18Z
[ "python", "django-deployment" ]
Class method differences in Python: bound, unbound and static
114,214
<p>What is the difference between the following class methods?</p> <p>Is it that one is static and the other is not?</p> <pre><code>class Test(object): def method_one(self): print "Called method_one" def method_two(): print "Called method_two" a_test = Test() a_test.method_one() a_test.method_two() </co...
190
2008-09-22T10:49:43Z
114,232
<p>When you call a class member, Python automatically uses a reference to the object as the first parameter. The variable <code>self</code> actually means nothing, it's just a coding convention. You could call it <code>gargaloo</code> if you wanted. That said, the call to <code>method_two</code> would raise a <code>Typ...
10
2008-09-22T10:56:27Z
[ "python" ]
Class method differences in Python: bound, unbound and static
114,214
<p>What is the difference between the following class methods?</p> <p>Is it that one is static and the other is not?</p> <pre><code>class Test(object): def method_one(self): print "Called method_one" def method_two(): print "Called method_two" a_test = Test() a_test.method_one() a_test.method_two() </co...
190
2008-09-22T10:49:43Z
114,250
<p>method_two won't work because you're defining a member function but not telling it what the function is a member of. If you execute the last line you'll get:</p> <pre><code>&gt;&gt;&gt; a_test.method_two() Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: method_two() t...
4
2008-09-22T11:00:29Z
[ "python" ]
Class method differences in Python: bound, unbound and static
114,214
<p>What is the difference between the following class methods?</p> <p>Is it that one is static and the other is not?</p> <pre><code>class Test(object): def method_one(self): print "Called method_one" def method_two(): print "Called method_two" a_test = Test() a_test.method_one() a_test.method_two() </co...
190
2008-09-22T10:49:43Z
114,251
<p>The call to method_two will throw an exception for not accepting the self parameter the Python runtime will automatically pass it.</p> <p>If you want to create a static method in a Python class, decorate it with the <code>staticmethod decorator</code>.</p> <pre><code>Class Test(Object): @staticmethod def metho...
1
2008-09-22T11:00:59Z
[ "python" ]
Class method differences in Python: bound, unbound and static
114,214
<p>What is the difference between the following class methods?</p> <p>Is it that one is static and the other is not?</p> <pre><code>class Test(object): def method_one(self): print "Called method_one" def method_two(): print "Called method_two" a_test = Test() a_test.method_one() a_test.method_two() </co...
190
2008-09-22T10:49:43Z
114,267
<p>In Python, there is a distinction between <em>bound</em> and <em>unbound</em> methods. </p> <p>Basically, a call to a member function (like <code>method_one</code>), a bound function</p> <pre><code>a_test.method_one() </code></pre> <p>is translated to</p> <pre><code>Test.method_one(a_test) </code></pre> <p>i.e....
325
2008-09-22T11:05:54Z
[ "python" ]
Class method differences in Python: bound, unbound and static
114,214
<p>What is the difference between the following class methods?</p> <p>Is it that one is static and the other is not?</p> <pre><code>class Test(object): def method_one(self): print "Called method_one" def method_two(): print "Called method_two" a_test = Test() a_test.method_one() a_test.method_two() </co...
190
2008-09-22T10:49:43Z
114,281
<p>that is an error.</p> <p>first of all, first line should be like this (be careful of capitals)</p> <pre><code>class Test(object): </code></pre> <p>Whenever you call a method of a class, it gets itself as the first argument (hence the name self) and method_two gives this error </p> <pre><code>&gt;&gt;&gt; a.metho...
1
2008-09-22T11:10:01Z
[ "python" ]
Class method differences in Python: bound, unbound and static
114,214
<p>What is the difference between the following class methods?</p> <p>Is it that one is static and the other is not?</p> <pre><code>class Test(object): def method_one(self): print "Called method_one" def method_two(): print "Called method_two" a_test = Test() a_test.method_one() a_test.method_two() </co...
190
2008-09-22T10:49:43Z
114,285
<p>The second one won't work because when you call it like that python internally tries to call it with the a_test instance as the first argument, but your method_two doesn't accept any arguments, so it wont work, you'll get a runtime error. If you want the equivalent of a static method you can use a class method. Ther...
1
2008-09-22T11:11:49Z
[ "python" ]
Class method differences in Python: bound, unbound and static
114,214
<p>What is the difference between the following class methods?</p> <p>Is it that one is static and the other is not?</p> <pre><code>class Test(object): def method_one(self): print "Called method_one" def method_two(): print "Called method_two" a_test = Test() a_test.method_one() a_test.method_two() </co...
190
2008-09-22T10:49:43Z
114,289
<p>Methods in Python are a very, very simple thing once you understood the basics of the descriptor system. Imagine the following class:</p> <pre><code>class C(object): def foo(self): pass </code></pre> <p>Now let's have a look at that class in the shell:</p> <pre><code>&gt;&gt;&gt; C.foo &lt;unbound me...
163
2008-09-22T11:12:36Z
[ "python" ]
Class method differences in Python: bound, unbound and static
114,214
<p>What is the difference between the following class methods?</p> <p>Is it that one is static and the other is not?</p> <pre><code>class Test(object): def method_one(self): print "Called method_one" def method_two(): print "Called method_two" a_test = Test() a_test.method_one() a_test.method_two() </co...
190
2008-09-22T10:49:43Z
2,696,019
<pre><code>&gt;&gt;&gt; class Class(object): ... def __init__(self): ... self.i = 0 ... def instance_method(self): ... self.i += 1 ... print self.i ... c = 0 ... @classmethod ... def class_method(cls): ... cls.c += 1 ... print cls.c ... @staticmethod ... ...
10
2010-04-23T03:25:12Z
[ "python" ]
Class method differences in Python: bound, unbound and static
114,214
<p>What is the difference between the following class methods?</p> <p>Is it that one is static and the other is not?</p> <pre><code>class Test(object): def method_one(self): print "Called method_one" def method_two(): print "Called method_two" a_test = Test() a_test.method_one() a_test.method_two() </co...
190
2008-09-22T10:49:43Z
21,213,848
<p>Please read this docs from the Guido <a href="http://python-history.blogspot.in/2009/02/first-class-everything.html" rel="nofollow">First Class everything</a> Clearly explained how Unbound, Bound methods are born.</p>
1
2014-01-19T06:18:41Z
[ "python" ]
Class method differences in Python: bound, unbound and static
114,214
<p>What is the difference between the following class methods?</p> <p>Is it that one is static and the other is not?</p> <pre><code>class Test(object): def method_one(self): print "Called method_one" def method_two(): print "Called method_two" a_test = Test() a_test.method_one() a_test.method_two() </co...
190
2008-09-22T10:49:43Z
39,563,369
<p>Accurate explanation from Armin Ronacher above, expanding on his answers so that beginners like me understand it well:</p> <p>Difference in the methods defined in a class, whether static or instance method(there is yet another type - class method - not discussed here so skipping it), lay in the fact whether they ar...
0
2016-09-18T22:51:16Z
[ "python" ]
Where can a save confirmation page be hooked into the Django admin? (similar to delete confirmation)
114,283
<p>I want to emulate the delete confirmation page behavior before saving certain models in the admin. In my case if I change one object, certain others should be deleted as they depend upon the object's now out-of-date state. </p> <p>I understand where to implement the actual cascaded updates (inside the parent m...
7
2008-09-22T11:11:12Z
114,348
<p>I'm by no means a Django expert, so this answer might misguide you. </p> <p>Start looking somewhere around <code>django.contrib.admin.options.ModelAdmin</code>, especially <code>render_change_form</code> and <code>response_change</code>. I guess you would need to subclass ModelAdmin for your model and provide requi...
1
2008-09-22T11:36:43Z
[ "python", "django" ]
Where can a save confirmation page be hooked into the Django admin? (similar to delete confirmation)
114,283
<p>I want to emulate the delete confirmation page behavior before saving certain models in the admin. In my case if I change one object, certain others should be deleted as they depend upon the object's now out-of-date state. </p> <p>I understand where to implement the actual cascaded updates (inside the parent m...
7
2008-09-22T11:11:12Z
114,373
<p>You could overload the <code>get_form</code> method of your model admin and add an extra checkbox to the generated form that has to be ticket. Alternatively you can override <code>change_view</code> and intercept the request.</p>
2
2008-09-22T11:42:42Z
[ "python", "django" ]
Where can a save confirmation page be hooked into the Django admin? (similar to delete confirmation)
114,283
<p>I want to emulate the delete confirmation page behavior before saving certain models in the admin. In my case if I change one object, certain others should be deleted as they depend upon the object's now out-of-date state. </p> <p>I understand where to implement the actual cascaded updates (inside the parent m...
7
2008-09-22T11:11:12Z
121,796
<p>Have you considered overriding the administrative templates for the models in question? This <a href="http://www.unessa.net/en/hoyci/2006/12/custom-admin-templates/" rel="nofollow">link</a> provides an excellent overview of the process. In this particular situation, having a finer-grained level of control may be t...
0
2008-09-23T15:37:06Z
[ "python", "django" ]
What is the fastest way to scale and display an image in Python?
114,597
<p>I am required to display a two dimensional numpy.array of int16 at 20fps or so. Using Matplotlib's imshow chokes on anything above 10fps. There obviously are some issues with scaling and interpolation. I should add that the dimensions of the array are not known, but will probably be around thirty by four hundred. </...
5
2008-09-22T12:36:53Z
114,626
<p>The fastest way to display 30x400 data points is to:</p> <h2>Use OpenGL color arrays</h2> <p>If you can quickly transform your data to what OpenGL understands as color array, you could create a vertex array describing quads, one for each sensor, then update your color array and draw this orthographically on screen...
6
2008-09-22T12:43:30Z
[ "python", "animation", "matplotlib", "image-scaling" ]
Is a Python dictionary an example of a hash table?
114,830
<p>One of the basic data structures in Python is the dictionary, which allows one to record "keys" for looking up "values" of any type. Is this implemented internally as a hash table? If not, what is it?</p>
88
2008-09-22T13:22:28Z
114,831
<p>Yes, it is a hash mapping or hash table. You can read a description of python's dict implementation, as written by Tim Peters, <a href="http://mail.python.org/pipermail/python-list/2000-March/048085.html">here</a>.</p> <p>That's why you can't use something 'not hashable' as a dict key, like a list:</p> <pre><code>...
127
2008-09-22T13:23:00Z
[ "python", "hash", "dictionary", "hashmap", "hashtable" ]
Is a Python dictionary an example of a hash table?
114,830
<p>One of the basic data structures in Python is the dictionary, which allows one to record "keys" for looking up "values" of any type. Is this implemented internally as a hash table? If not, what is it?</p>
88
2008-09-22T13:22:28Z
114,848
<p>Yes. Internally it is implemented as open hashing based on a primitive polynomial over Z/2 (<a href="http://mail.python.org/pipermail/python-list/2000-February/023645.html">source</a>).</p>
14
2008-09-22T13:25:27Z
[ "python", "hash", "dictionary", "hashmap", "hashtable" ]
Is a Python dictionary an example of a hash table?
114,830
<p>One of the basic data structures in Python is the dictionary, which allows one to record "keys" for looking up "values" of any type. Is this implemented internally as a hash table? If not, what is it?</p>
88
2008-09-22T13:22:28Z
114,853
<p>If you're interested in the technical details, one article in <a href="http://oreilly.com/catalog/9780596510046/">Beautiful Code</a> deals with the internals of Python's <code>dict</code> implementation.</p>
25
2008-09-22T13:26:19Z
[ "python", "hash", "dictionary", "hashmap", "hashtable" ]
Is a Python dictionary an example of a hash table?
114,830
<p>One of the basic data structures in Python is the dictionary, which allows one to record "keys" for looking up "values" of any type. Is this implemented internally as a hash table? If not, what is it?</p>
88
2008-09-22T13:22:28Z
115,379
<p>To expand upon nosklo's explanation:</p> <pre><code>a = {} b = ['some', 'list'] a[b] = 'some' # this won't work a[tuple(b)] = 'some' # this will, same as a['some', 'list'] </code></pre>
5
2008-09-22T15:09:43Z
[ "python", "hash", "dictionary", "hashmap", "hashtable" ]
Is a Python dictionary an example of a hash table?
114,830
<p>One of the basic data structures in Python is the dictionary, which allows one to record "keys" for looking up "values" of any type. Is this implemented internally as a hash table? If not, what is it?</p>
88
2008-09-22T13:22:28Z
33,459,086
<p>There must be more to a Python dictionary than a table lookup on hash(). By brute experimentation I found this <strong>hash collision</strong>:</p> <pre><code>&gt;&gt;&gt; hash(1.1) 2040142438 &gt;&gt;&gt; hash(4504.1) 2040142438 </code></pre> <p>Yet it doesn't break the dictionary:</p> <pre><code>&gt;&gt;&gt; d ...
5
2015-11-01T04:01:49Z
[ "python", "hash", "dictionary", "hashmap", "hashtable" ]
How can I consume a WSDL (SOAP) web service in Python?
115,316
<p>I want to use a WSDL SOAP based web service in Python. I have looked at the <a href="http://diveintopython.net/soap_web_services/">Dive Into Python</a> code but the SOAPpy module does not work under Python 2.5.</p> <p>I have tried using <a href="https://fedorahosted.org/suds">suds</a> which works partly, but breaks...
102
2008-09-22T14:58:53Z
115,700
<p>Right now (as of 2008), all the SOAP libraries available for Python suck. I recommend avoiding SOAP if possible. The last time we where forced to use a SOAP web service from Python, we wrote a wrapper in C# that handled the SOAP on one side and spoke COM out the other. </p>
9
2008-09-22T15:55:07Z
[ "python", "web-services", "soap" ]
How can I consume a WSDL (SOAP) web service in Python?
115,316
<p>I want to use a WSDL SOAP based web service in Python. I have looked at the <a href="http://diveintopython.net/soap_web_services/">Dive Into Python</a> code but the SOAPpy module does not work under Python 2.5.</p> <p>I have tried using <a href="https://fedorahosted.org/suds">suds</a> which works partly, but breaks...
102
2008-09-22T14:58:53Z
117,025
<p>It's not true SOAPpy does not work with Python 2.5 - it works, although it's very simple and really, really basic. If you want to talk to any more complicated webservice, ZSI is your only friend.</p> <p>The really useful demo I found is at <a href="http://www.ebi.ac.uk/Tools/webservices/tutorials/python" rel="nofol...
2
2008-09-22T19:38:22Z
[ "python", "web-services", "soap" ]
How can I consume a WSDL (SOAP) web service in Python?
115,316
<p>I want to use a WSDL SOAP based web service in Python. I have looked at the <a href="http://diveintopython.net/soap_web_services/">Dive Into Python</a> code but the SOAPpy module does not work under Python 2.5.</p> <p>I have tried using <a href="https://fedorahosted.org/suds">suds</a> which works partly, but breaks...
102
2008-09-22T14:58:53Z
1,793,052
<p>I know this is an old thread but it was showing up at the top of Google's results so I wanted to share a more current discussion on Python and SOAP.</p> <p>See: <a href="http://www.diveintopython.net/soap_web_services/index.html">http://www.diveintopython.net/soap_web_services/index.html</a></p>
30
2009-11-24T21:32:02Z
[ "python", "web-services", "soap" ]
How can I consume a WSDL (SOAP) web service in Python?
115,316
<p>I want to use a WSDL SOAP based web service in Python. I have looked at the <a href="http://diveintopython.net/soap_web_services/">Dive Into Python</a> code but the SOAPpy module does not work under Python 2.5.</p> <p>I have tried using <a href="https://fedorahosted.org/suds">suds</a> which works partly, but breaks...
102
2008-09-22T14:58:53Z
2,092,983
<p>If you're rolling your own I'd highly recommend looking at <a href="http://effbot.org/zone/element-soap.htm" rel="nofollow">http://effbot.org/zone/element-soap.htm</a>.</p>
1
2010-01-19T11:13:16Z
[ "python", "web-services", "soap" ]
How can I consume a WSDL (SOAP) web service in Python?
115,316
<p>I want to use a WSDL SOAP based web service in Python. I have looked at the <a href="http://diveintopython.net/soap_web_services/">Dive Into Python</a> code but the SOAPpy module does not work under Python 2.5.</p> <p>I have tried using <a href="https://fedorahosted.org/suds">suds</a> which works partly, but breaks...
102
2008-09-22T14:58:53Z
2,567,815
<p>SOAPpy is now obsolete, AFAIK, replaced by ZSL. It's a moot point, because I can't get either one to work, much less compile, on either Python 2.5 or Python 2.6</p>
1
2010-04-02T16:33:07Z
[ "python", "web-services", "soap" ]
How can I consume a WSDL (SOAP) web service in Python?
115,316
<p>I want to use a WSDL SOAP based web service in Python. I have looked at the <a href="http://diveintopython.net/soap_web_services/">Dive Into Python</a> code but the SOAPpy module does not work under Python 2.5.</p> <p>I have tried using <a href="https://fedorahosted.org/suds">suds</a> which works partly, but breaks...
102
2008-09-22T14:58:53Z
2,829,486
<p>I would recommend that you have a look at <a href="https://fedorahosted.org/suds/">SUDS</a></p> <p>"Suds is a lightweight SOAP python client for consuming Web Services."</p>
44
2010-05-13T19:02:39Z
[ "python", "web-services", "soap" ]
How can I consume a WSDL (SOAP) web service in Python?
115,316
<p>I want to use a WSDL SOAP based web service in Python. I have looked at the <a href="http://diveintopython.net/soap_web_services/">Dive Into Python</a> code but the SOAPpy module does not work under Python 2.5.</p> <p>I have tried using <a href="https://fedorahosted.org/suds">suds</a> which works partly, but breaks...
102
2008-09-22T14:58:53Z
19,835,265
<p>I periodically search for a satisfactory answer to this, but no luck so far. I use soapUI + requests + manual labour.</p> <p>I gave up and used Java the last time I <em>needed</em> to do this, and simply gave up a few times the last time I <em>wanted</em> to do this, but it wasn't essential.</p> <p>Having successf...
5
2013-11-07T11:54:38Z
[ "python", "web-services", "soap" ]
How can I consume a WSDL (SOAP) web service in Python?
115,316
<p>I want to use a WSDL SOAP based web service in Python. I have looked at the <a href="http://diveintopython.net/soap_web_services/">Dive Into Python</a> code but the SOAPpy module does not work under Python 2.5.</p> <p>I have tried using <a href="https://fedorahosted.org/suds">suds</a> which works partly, but breaks...
102
2008-09-22T14:58:53Z
27,302,096
<p>I recently stumbled up on the same problem. Here is the synopsis of my solution. <em>(If you need to see the whole discussion, here is the link for complete discussion of the solution: <a href="http://tedbelay.blogspot.com/2014/12/soap-web-service-client-in-python-27.html">http://tedbelay.blogspot.com/2014/12/soap-w...
12
2014-12-04T19:13:20Z
[ "python", "web-services", "soap" ]
How can I consume a WSDL (SOAP) web service in Python?
115,316
<p>I want to use a WSDL SOAP based web service in Python. I have looked at the <a href="http://diveintopython.net/soap_web_services/">Dive Into Python</a> code but the SOAPpy module does not work under Python 2.5.</p> <p>I have tried using <a href="https://fedorahosted.org/suds">suds</a> which works partly, but breaks...
102
2008-09-22T14:58:53Z
36,910,649
<p>There is a relatively new library which is very promising and albeit still poorly documented, seems very clean and pythonic: <a href="https://github.com/mvantellingen/python-zeep" rel="nofollow">python zeep</a>.</p> <p>See also <a href="http://stackoverflow.com/a/36892846/204634">this answer</a> for an example.</p>...
3
2016-04-28T09:33:04Z
[ "python", "web-services", "soap" ]
What is the simplest way to offer/consume web services in jython?
115,744
<p>I have an application for Tomcat which needs to offer/consume web services. Since Java web services are a nightmare (xml, code generation, etc.) compared with what is possible in Python, I would like to learn from your experience using jython instead of java for offerring/consuming web services.</p> <p>What I have ...
5
2008-09-22T16:01:52Z
116,027
<p><a href="http://www.jython.org/docs/api/org/python/util/PyServlet.html" rel="nofollow">PyServlet</a> helps you configure Tomcat to serve up Jython scripts from a URL. You could use this is a "REST-like" way to do some basic web services without much effort. (It is also described <a href="http://www.informit.com/ar...
0
2008-09-22T16:46:13Z
[ "python", "web-services", "soap", "wsdl", "jython" ]
What is the simplest way to offer/consume web services in jython?
115,744
<p>I have an application for Tomcat which needs to offer/consume web services. Since Java web services are a nightmare (xml, code generation, etc.) compared with what is possible in Python, I would like to learn from your experience using jython instead of java for offerring/consuming web services.</p> <p>What I have ...
5
2008-09-22T16:01:52Z
148,455
<p>I've put together more details on how to use webservices in jython using axis. Read about it here: <a href="http://www.fishandcross.com/blog/?p=503" rel="nofollow">How To Script Webservices with Jython and Axis</a>.</p>
2
2008-09-29T12:23:43Z
[ "python", "web-services", "soap", "wsdl", "jython" ]
Which is more pythonic, factory as a function in a module, or as a method on the class it creates?
115,764
<p>I have some Python code that creates a Calendar object based on parsed VEvent objects from and iCalendar file.</p> <p>The calendar object just has a method that adds events as they get parsed.</p> <p>Now I want to create a factory function that creates a calendar from a file object, path, or URL.</p> <p>I've been...
3
2008-09-22T16:03:41Z
115,777
<p>It's pythonic not to think about esoteric difference in some pattern you read somewhere and now want to use everywhere, like the factory pattern.</p> <p>Most of the time you would think of a @staticmethod as a solution it's probably better to use a module function, except when you stuff multiple classes in one modu...
6
2008-09-22T16:05:25Z
[ "python", "factory" ]
Which is more pythonic, factory as a function in a module, or as a method on the class it creates?
115,764
<p>I have some Python code that creates a Calendar object based on parsed VEvent objects from and iCalendar file.</p> <p>The calendar object just has a method that adds events as they get parsed.</p> <p>Now I want to create a factory function that creates a calendar from a file object, path, or URL.</p> <p>I've been...
3
2008-09-22T16:03:41Z
115,802
<p>The factory pattern has its own <a href="http://en.wikipedia.org/wiki/Factory_method_pattern" rel="nofollow">strengths and weaknesses</a>. However, choosing one way to create instances usually has little pragmatic effect on your code.</p>
0
2008-09-22T16:09:45Z
[ "python", "factory" ]
Which is more pythonic, factory as a function in a module, or as a method on the class it creates?
115,764
<p>I have some Python code that creates a Calendar object based on parsed VEvent objects from and iCalendar file.</p> <p>The calendar object just has a method that adds events as they get parsed.</p> <p>Now I want to create a factory function that creates a calendar from a file object, path, or URL.</p> <p>I've been...
3
2008-09-22T16:03:41Z
115,807
<p>IMHO a module-level method is a cleaner solution. It hides behind the Python module system that gives it a unique namespace prefix, something the "factory pattern" is commonly used for. </p>
2
2008-09-22T16:11:52Z
[ "python", "factory" ]
Which is more pythonic, factory as a function in a module, or as a method on the class it creates?
115,764
<p>I have some Python code that creates a Calendar object based on parsed VEvent objects from and iCalendar file.</p> <p>The calendar object just has a method that adds events as they get parsed.</p> <p>Now I want to create a factory function that creates a calendar from a file object, path, or URL.</p> <p>I've been...
3
2008-09-22T16:03:41Z
115,853
<p>[<strong>Note</strong>. Be very cautious about separating "Calendar" a collection of events, and "Event" - a single event on a calendar. In your question, it seems like there could be some confusion.]</p> <p>There are many variations on the Factory design pattern.</p> <ol> <li><p>A stand-alone convenience functi...
11
2008-09-22T16:20:38Z
[ "python", "factory" ]
Which is more pythonic, factory as a function in a module, or as a method on the class it creates?
115,764
<p>I have some Python code that creates a Calendar object based on parsed VEvent objects from and iCalendar file.</p> <p>The calendar object just has a method that adds events as they get parsed.</p> <p>Now I want to create a factory function that creates a calendar from a file object, path, or URL.</p> <p>I've been...
3
2008-09-22T16:03:41Z
115,933
<p>A staticmethod rarely has value, but a classmethod may be useful. It depends on what you want the class and the factory function to actually do.</p> <p>A factory function in a module would always make an instance of the 'right' type (where 'right' in your case is the 'Calendar' class always, but you might also make...
0
2008-09-22T16:30:48Z
[ "python", "factory" ]
How do I configure the ip address with CherryPy?
115,773
<p>I'm using python and CherryPy to create a simple internal website that about 2 people use. I use the built in webserver with CherryPy.quickstart and never messed with the config files. I recently changed machines so I installed the latest Python and cherrypy and when I run the site I can access it from localhost:808...
15
2008-09-22T16:04:54Z
115,826
<p>That depends on how you are running the cherrypy init.</p> <p>If using cherrypy 3.1 syntax, that wold do it:</p> <pre><code>cherrypy.server.socket_host = 'www.machinename.com' cherrypy.engine.start() cherrypy.engine.block() </code></pre> <p>Of course you can have something more fancy, like subclassing the server ...
13
2008-09-22T16:16:12Z
[ "python", "cherrypy" ]
How do I configure the ip address with CherryPy?
115,773
<p>I'm using python and CherryPy to create a simple internal website that about 2 people use. I use the built in webserver with CherryPy.quickstart and never messed with the config files. I recently changed machines so I installed the latest Python and cherrypy and when I run the site I can access it from localhost:808...
15
2008-09-22T16:04:54Z
152,012
<pre><code>server.socket_host: '0.0.0.0' </code></pre> <p>...would also work. That's IPv4 INADDR_ANY, which means, "listen on all interfaces".</p> <p>In a config file, the syntax is:</p> <pre><code>[global] server.socket_host: '0.0.0.0' </code></pre> <p>In code:</p> <pre><code>cherrypy.server.socket_host = '0.0.0....
29
2008-09-30T06:55:25Z
[ "python", "cherrypy" ]
Convert mysql timestamp to epoch time in python
115,866
<p>Convert mysql timestamp to epoch time in python - is there an easy way to do this?</p>
6
2008-09-22T16:22:16Z
115,903
<p>Why not let MySQL do the hard work?</p> <p>select unix_timestamp(fieldname) from tablename;</p>
24
2008-09-22T16:26:51Z
[ "python", "mysql", "time", "timestamp" ]
Convert mysql timestamp to epoch time in python
115,866
<p>Convert mysql timestamp to epoch time in python - is there an easy way to do this?</p>
6
2008-09-22T16:22:16Z
118,236
<p>If you don't want to have MySQL do the work for some reason, then you can do this in Python easily enough. When you get a datetime column back from MySQLdb, you get a Python datetime.datetime object. To convert one of these, you can use time.mktime. For example:</p> <pre><code>import time # Connecting to databas...
3
2008-09-22T23:34:51Z
[ "python", "mysql", "time", "timestamp" ]
Convert mysql timestamp to epoch time in python
115,866
<p>Convert mysql timestamp to epoch time in python - is there an easy way to do this?</p>
6
2008-09-22T16:22:16Z
126,034
<p>I use something like the following to get seconds since the epoch (UTC) from a MySQL date (local time):</p> <pre><code>calendar.timegm( time.gmtime( time.mktime( time.strptime(t, "%Y-%m-%d %H:%M:%S")))) </code></pre> <p>More info in this question: <a href="http://stackover...
1
2008-09-24T08:30:00Z
[ "python", "mysql", "time", "timestamp" ]
Convert mysql timestamp to epoch time in python
115,866
<p>Convert mysql timestamp to epoch time in python - is there an easy way to do this?</p>
6
2008-09-22T16:22:16Z
2,407,400
<p>converting mysql time to epoch:</p> <pre><code>&gt;&gt;&gt; import time &gt;&gt;&gt; import calendar &gt;&gt;&gt; mysql_time = "2010-01-02 03:04:05" &gt;&gt;&gt; mysql_time_struct = time.strptime(mysql_time, '%Y-%m-%d %H:%M:%S') &gt;&gt;&gt; print mysql_time_struct (2010, 1, 2, 3, 4, 5, 5, 2, -1) &gt;&gt;&gt; mysql...
7
2010-03-09T07:51:59Z
[ "python", "mysql", "time", "timestamp" ]
What would be the simplest way to daemonize a python script in Linux?
115,974
<p>What would be the simplest way to daemonize a python script in Linux ? I need that this works with every flavor of Linux, so it should only use python based tools. </p>
10
2008-09-22T16:39:09Z
115,985
<p><a href="http://en.wikipedia.org/wiki/Nohup" rel="nofollow">nohup</a> </p> <p><a href="http://code.activestate.com/recipes/278731/" rel="nofollow">Creating a daemon the Python way</a></p>
4
2008-09-22T16:41:18Z
[ "python", "scripting", "daemon" ]
What would be the simplest way to daemonize a python script in Linux?
115,974
<p>What would be the simplest way to daemonize a python script in Linux ? I need that this works with every flavor of Linux, so it should only use python based tools. </p>
10
2008-09-22T16:39:09Z
116,035
<p>See <a href="http://www.kohala.com/start/">Stevens</a> and also this <a href="http://code.activestate.com/recipes/278731/">lengthy thread on activestate</a> which I found personally to be both mostly incorrect and much to verbose, and I came up with this:</p> <pre><code>from os import fork, setsid, umask, dup2 from...
20
2008-09-22T16:47:31Z
[ "python", "scripting", "daemon" ]
What would be the simplest way to daemonize a python script in Linux?
115,974
<p>What would be the simplest way to daemonize a python script in Linux ? I need that this works with every flavor of Linux, so it should only use python based tools. </p>
10
2008-09-22T16:39:09Z
116,081
<p>Use <a href="http://www.clapper.org/software/python/grizzled/" rel="nofollow">grizzled.os.daemonize</a>:</p> <pre><code>$ easy_install grizzled &gt;&gt;&gt; from grizzled.os import daemonize &gt;&gt;&gt; daemon.daemonize() </code></pre> <p>To understand how this works or to do it yourself, read <a href="http://co...
0
2008-09-22T16:57:14Z
[ "python", "scripting", "daemon" ]
What would be the simplest way to daemonize a python script in Linux?
115,974
<p>What would be the simplest way to daemonize a python script in Linux ? I need that this works with every flavor of Linux, so it should only use python based tools. </p>
10
2008-09-22T16:39:09Z
117,176
<p>If you do not care for actual discussions (which tend to go offtopic and do not offer authoritative response), you can choose some library that will make your tast easier. I'd recomment taking a look at <a href="http://www.livinglogic.de/Python/Download.html" rel="nofollow">ll-xist</a>, this library contains large a...
1
2008-09-22T19:58:20Z
[ "python", "scripting", "daemon" ]
What would be the simplest way to daemonize a python script in Linux?
115,974
<p>What would be the simplest way to daemonize a python script in Linux ? I need that this works with every flavor of Linux, so it should only use python based tools. </p>
10
2008-09-22T16:39:09Z
3,606,303
<p>I have recently used <a href="http://pypi.python.org/pypi/Turkmenbashi/1.0.0.01" rel="nofollow">Turkmenbashi</a> :</p> <pre><code>$ easy_install turkmenbashi import Turkmenbashi class DebugDaemon (Turkmenbashi.Daemon): def config(self): self.debugging = True def go(self): self.debug('a de...
2
2010-08-31T05:43:08Z
[ "python", "scripting", "daemon" ]
Using Pylint with Django
115,977
<p>I would very much like to integrate <a href="http://www.logilab.org/857">pylint</a> into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:<code>E1101: *%s %r has no %r member*</code>--constantly reports errors when using common dja...
89
2008-09-22T16:39:34Z
116,025
<p>Because of how pylint works (it examines the source itself, without letting Python actually execute it) it's very hard for pylint to figure out how metaclasses and complex baseclasses actually affect a class and its instances. The 'pychecker' tool is a bit better in this regard, because it <em>does</em> actually let...
15
2008-09-22T16:46:00Z
[ "python", "django", "static-analysis", "pylint" ]
Using Pylint with Django
115,977
<p>I would very much like to integrate <a href="http://www.logilab.org/857">pylint</a> into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:<code>E1101: *%s %r has no %r member*</code>--constantly reports errors when using common dja...
89
2008-09-22T16:39:34Z
116,047
<p>Try running pylint with</p> <pre><code>pylint --ignored-classes=Tags </code></pre> <p>If that works, add all the other Django classes - possibly using a script, in say, python :P </p> <p>The documentation for <code>--ignore-classes</code> is:</p> <blockquote> <p><code>--ignored-classes=&lt;members names&gt;</c...
5
2008-09-22T16:50:09Z
[ "python", "django", "static-analysis", "pylint" ]
Using Pylint with Django
115,977
<p>I would very much like to integrate <a href="http://www.logilab.org/857">pylint</a> into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:<code>E1101: *%s %r has no %r member*</code>--constantly reports errors when using common dja...
89
2008-09-22T16:39:34Z
117,299
<p>I resigned from using pylint/pychecker in favor of using pyflakes with Django code - it just tries to import module and reports any problem it finds, like unused imports or uninitialized local names.</p>
6
2008-09-22T20:12:40Z
[ "python", "django", "static-analysis", "pylint" ]
Using Pylint with Django
115,977
<p>I would very much like to integrate <a href="http://www.logilab.org/857">pylint</a> into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:<code>E1101: *%s %r has no %r member*</code>--constantly reports errors when using common dja...
89
2008-09-22T16:39:34Z
118,375
<p>This is not a solution, but you can add <code>objects = models.Manager()</code> to your Django models without changing any behavior.</p> <p>I myself only use pyflakes, primarily due to some dumb defaults in pylint and laziness on my part (not wanting to look up how to change the defaults).</p>
7
2008-09-23T00:17:58Z
[ "python", "django", "static-analysis", "pylint" ]
Using Pylint with Django
115,977
<p>I would very much like to integrate <a href="http://www.logilab.org/857">pylint</a> into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:<code>E1101: *%s %r has no %r member*</code>--constantly reports errors when using common dja...
89
2008-09-22T16:39:34Z
410,860
<p>So far I have found no real solution to that but work around:</p> <ul> <li>In our company we require a pylint score > 8. This allows coding practices pylint doesn't understand while ensuring that the code isn't too "unusual". So far we havn't seen any instance where E1101 kept us from reaching a score of 8 or highe...
2
2009-01-04T11:37:48Z
[ "python", "django", "static-analysis", "pylint" ]
Using Pylint with Django
115,977
<p>I would very much like to integrate <a href="http://www.logilab.org/857">pylint</a> into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:<code>E1101: *%s %r has no %r member*</code>--constantly reports errors when using common dja...
89
2008-09-22T16:39:34Z
1,416,297
<p>I use the following: <code>pylint --generated-members=objects</code></p>
59
2009-09-12T22:21:47Z
[ "python", "django", "static-analysis", "pylint" ]
Using Pylint with Django
115,977
<p>I would very much like to integrate <a href="http://www.logilab.org/857">pylint</a> into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:<code>E1101: *%s %r has no %r member*</code>--constantly reports errors when using common dja...
89
2008-09-22T16:39:34Z
2,456,436
<p>django-lint is a nice tool which wraps pylint with django specific settings : <a href="http://chris-lamb.co.uk/projects/django-lint/" rel="nofollow">http://chris-lamb.co.uk/projects/django-lint/</a> </p> <p>github project: <a href="https://github.com/lamby/django-lint" rel="nofollow">https://github.com/lamby/django...
18
2010-03-16T17:00:16Z
[ "python", "django", "static-analysis", "pylint" ]
Using Pylint with Django
115,977
<p>I would very much like to integrate <a href="http://www.logilab.org/857">pylint</a> into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:<code>E1101: *%s %r has no %r member*</code>--constantly reports errors when using common dja...
89
2008-09-22T16:39:34Z
4,162,971
<p>My ~/.pylintrc contains</p> <pre><code>[TYPECHECK] generated-members=REQUEST,acl_users,aq_parent,objects,_meta,id </code></pre> <p>the last two are specifically for Django.</p> <p>Note that there is a <a href="http://www.logilab.org/ticket/28796">bug in PyLint 0.21.1</a> which needs patching to make this work.</p...
27
2010-11-12T08:59:11Z
[ "python", "django", "static-analysis", "pylint" ]
Using Pylint with Django
115,977
<p>I would very much like to integrate <a href="http://www.logilab.org/857">pylint</a> into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:<code>E1101: *%s %r has no %r member*</code>--constantly reports errors when using common dja...
89
2008-09-22T16:39:34Z
5,104,874
<p>The solution proposed in this <a href="http://stackoverflow.com/questions/3509599/can-an-api-tell-pylint-not-to-complain-in-the-client-code">other question</a> it to simply add <strong>get_attr</strong> to your Tag class. Ugly, but works.</p>
2
2011-02-24T12:48:37Z
[ "python", "django", "static-analysis", "pylint" ]
Using Pylint with Django
115,977
<p>I would very much like to integrate <a href="http://www.logilab.org/857">pylint</a> into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:<code>E1101: *%s %r has no %r member*</code>--constantly reports errors when using common dja...
89
2008-09-22T16:39:34Z
31,000,713
<p>Do not disable or weaken Pylint functionality by adding <code>ignores</code> or <code>generated-members</code>.<br> Use an actively developed Pylint plugin that <strong>understands</strong> Django.<br> <a href="https://github.com/landscapeio/pylint-django">This Pylint plugin for Django</a> works quite well:</p> <pr...
31
2015-06-23T10:47:45Z
[ "python", "django", "static-analysis", "pylint" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
116,194
<p>A docx is just a zip archive with lots of files inside. Maybe you can look at some of the contents of those files? Other than that you probably have to find a lib that understands the word format so that you can filter out things you're not interested in.</p> <p>A second choice would be to interop with word and do ...
4
2008-09-22T17:16:43Z
[ "python", "ms-word", "openxml", "docx" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
116,197
<p>a docx file is essentially a zip file with an xml inside it.<br /> the xml contains the formatting but it also contains the text.</p>
2
2008-09-22T17:17:15Z
[ "python", "ms-word", "openxml", "docx" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
116,199
<p>You should be able to use the MSWord ActiveX interface to extract the text to search (or, possibly, do the search). I have no idea how you access ActiveX from Python though.</p>
0
2008-09-22T17:17:26Z
[ "python", "ms-word", "openxml", "docx" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
116,217
<p>More exactly, a .docx document is a Zip archive in OpenXML format: you have first to uncompress it.<br /> I downloaded a sample (Google: <em>some search term filetype:docx</em>) and after unzipping I found some folders. The <em>word</em> folder contains the document itself, in file <em>document.xml</em>.</p>
30
2008-09-22T17:22:10Z
[ "python", "ms-word", "openxml", "docx" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
118,136
<p>OLE Automation would probably be the easiest. You have to consider formatting, because the text could look like this in the XML:</p> <pre><code>&lt;b&gt;Looking &lt;i&gt;for&lt;/i&gt; this &lt;u&gt;phrase&lt;/u&gt; </code></pre> <p>There's no easy way to find that using a simple text scan.</p>
1
2008-09-22T23:03:32Z
[ "python", "ms-word", "openxml", "docx" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
118,175
<p>In this example, "Course Outline.docx" is a Word 2007 document, which does contain the word "Windows", and does not contain the phrase "random other string".</p> <pre><code>&gt;&gt;&gt; import zipfile &gt;&gt;&gt; z = zipfile.ZipFile("Course Outline.docx") &gt;&gt;&gt; "Windows" in z.read("word/document.xml") True ...
14
2008-09-22T23:12:59Z
[ "python", "ms-word", "openxml", "docx" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
138,231
<p><a href="http://www.codeproject.com/KB/WPF/OpenFlowDoc.aspx?msg=2740533#xx2740533xx" rel="nofollow">Here</a> is a example of using XLINQ to search throu a word document</p>
0
2008-09-26T08:03:35Z
[ "python", "ms-word", "openxml", "docx" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
215,479
<p>You may also consider using the library from <a href="http://openxmldeveloper.org/default.aspx" rel="nofollow">OpenXMLDeveloper.org</a></p>
0
2008-10-18T19:34:32Z
[ "python", "ms-word", "openxml", "docx" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
1,737,242
<p>A problem with searching inside a Word document XML file is that the text can be split into elements at any character. It will certainly be split if formatting is different, for example as in Hello <strong>World</strong>. But it <em>can</em> be split at any point and that is valid in OOXML. So you will end up dealin...
13
2009-11-15T11:01:08Z
[ "python", "ms-word", "openxml", "docx" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
1,979,864
<p>After reading your post above, I made a 100% native Python docx module to solve this specific problem.</p> <pre><code># Import the module from docx import * # Open the .docx file document = opendocx('A document.docx') # Search returns true if found search(document,'your search string') </code></pre> <p>The d...
127
2009-12-30T12:08:33Z
[ "python", "ms-word", "openxml", "docx" ]
How can I search a word in a Word 2007 .docx file?
116,139
<p>I'd like to search a Word 2007 file (.docx) for a text string, e.g., "some special phrase" that could/would be found from a search within Word. </p> <p>Is there a way from Python to see the text? I have no interest in formatting - I just want to classify documents as having or not having "some special phrase".</p...
40
2008-09-22T17:08:12Z
27,377,115
<p>You can use <code>docx2txt</code> to get the text inside the docx, than search in that txt</p> <pre><code>npm install -g docx2txt docx2txt input.docx # This will print the text to stdout </code></pre>
3
2014-12-09T10:51:23Z
[ "python", "ms-word", "openxml", "docx" ]