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 |
|---|---|---|---|---|---|---|---|---|---|
getting the id of a created record in SQLAlchemy | 2,188,844 | <p>How can I get the id of the created record in SQLAlchemy?</p>
<p>I'm doing:</p>
<pre><code>engine.execute("insert into users values (1,'john')")
</code></pre>
| 4 | 2010-02-03T00:29:51Z | 2,189,662 | <p>When you execute a plain text statement, you're at the mercy of the DBAPI you're using as to whether or not the new PK value is available and via what means. With SQlite and MySQL DBAPIs you'll have it as result.lastrowid, which just gives you the value of .lastrowid for the cursor. With PG, Oracle, etc., there'... | 12 | 2010-02-03T04:19:12Z | [
"python",
"insert",
"sqlalchemy"
] |
What is the python equivalent of the Perl pattern to track if something has already been seen? | 2,188,863 | <p>In Perl, one can do the following</p>
<pre><code>for (@foo) {
# do something
next if $seen{$_}++;
}
</code></pre>
<p>I would like to be able to do the equivalent in Python, that is to skip a block if it has been executed once. </p>
| 5 | 2010-02-03T00:32:21Z | 2,188,878 | <pre><code>seen = set()
for x in foo:
if x in seen:
continue
seen.add(x)
# do something
</code></pre>
<p>See the <a href="http://docs.python.org/library/stdtypes.html#set-types-set-frozenset" rel="nofollow"><code>set</code></a> documentation for more information.</p>
<p>Also, the examples at the b... | 11 | 2010-02-03T00:35:25Z | [
"python",
"perl"
] |
What is the python equivalent of the Perl pattern to track if something has already been seen? | 2,188,863 | <p>In Perl, one can do the following</p>
<pre><code>for (@foo) {
# do something
next if $seen{$_}++;
}
</code></pre>
<p>I would like to be able to do the equivalent in Python, that is to skip a block if it has been executed once. </p>
| 5 | 2010-02-03T00:32:21Z | 2,188,881 | <pre><code>seen={}
for item in foo:
if seen.has_key(item):
seen[item]+=1
continue # continue is optional, just to illustrate the "next" in Perl
else:
seen[item]=1
</code></pre>
| 1 | 2010-02-03T00:36:09Z | [
"python",
"perl"
] |
What is the python equivalent of the Perl pattern to track if something has already been seen? | 2,188,863 | <p>In Perl, one can do the following</p>
<pre><code>for (@foo) {
# do something
next if $seen{$_}++;
}
</code></pre>
<p>I would like to be able to do the equivalent in Python, that is to skip a block if it has been executed once. </p>
| 5 | 2010-02-03T00:32:21Z | 2,189,781 | <p>If you don't care about the order of the things in foo, and only that the unique items are iterated over, then the solution is <em>much</em> simpler.</p>
<pre><code>for x in set(foo):
do something
</code></pre>
| 1 | 2010-02-03T04:51:36Z | [
"python",
"perl"
] |
SimpleXMLRPCServer, wxPython and Thread - Howto Stop? | 2,189,069 | <p>Here is an example program that illustrates my problem. The program starts a wxPython application and starts a SimpleXMLRPCServer in a thread. This all works fine. My problem is that I can't shut down the SimpleXMLRPCServer thread because it is blocked on the handle_request() call. I am developing on a Windows X... | 1 | 2010-02-03T01:26:17Z | 2,197,131 | <p>This works. Credit goes to the link in my above comment.</p>
<pre><code>import wx
import SimpleXMLRPCServer
import threading
import xmlrpclib
class myServerFunction(object):
def result(self):
print "myServerFunction"
return "Hello World"
class serverThread(threading.Thread):
def __init__(... | 1 | 2010-02-04T03:25:21Z | [
"python",
"multithreading",
"wxpython",
"simplexmlrpcserver"
] |
SimpleXMLRPCServer, wxPython and Thread - Howto Stop? | 2,189,069 | <p>Here is an example program that illustrates my problem. The program starts a wxPython application and starts a SimpleXMLRPCServer in a thread. This all works fine. My problem is that I can't shut down the SimpleXMLRPCServer thread because it is blocked on the handle_request() call. I am developing on a Windows X... | 1 | 2010-02-03T01:26:17Z | 31,687,101 | <p>I am not sure whether it is still of interest, but the code works if</p>
<pre><code>while not self.timeToQuit.isSet():
self.server.handle_request()
</code></pre>
<p>is replaced by</p>
<pre><code>try:
self.server.serve_forever()
except:
print( "SimpleXMLRPCServer stopped" )
</code></pre>
<p>Using the... | 0 | 2015-07-28T21:07:19Z | [
"python",
"multithreading",
"wxpython",
"simplexmlrpcserver"
] |
embedding short python scripts inside a bash script | 2,189,098 | <p>I'd like to embed the text of short python scripts inside of a bash script, for use in say, my <code>.bash_profile</code>. What's the best way to go about doing such a thing?</p>
<p>The solution I have so far is to call the python interpreter with the <code>-c</code> option, and tell the interpreter to <code>exec</... | 26 | 2010-02-03T01:36:41Z | 2,189,116 | <p>Why should you need to use <code>-c</code>? This works for me:</p>
<pre><code>python << END
... code ...
END
</code></pre>
<p>without needing anything extra.</p>
| 21 | 2010-02-03T01:44:25Z | [
"python",
"bash"
] |
embedding short python scripts inside a bash script | 2,189,098 | <p>I'd like to embed the text of short python scripts inside of a bash script, for use in say, my <code>.bash_profile</code>. What's the best way to go about doing such a thing?</p>
<p>The solution I have so far is to call the python interpreter with the <code>-c</code> option, and tell the interpreter to <code>exec</... | 26 | 2010-02-03T01:36:41Z | 2,189,118 | <p>The python interpreter accepts <code>-</code> on the command line as a synonym for <code>stdin</code> so you can replace the calls to pyexec with:</p>
<pre><code>python - <<END
</code></pre>
<p>See command line reference <a href="http://docs.python.org/using/cmdline.html#command-line">here</a>.</p>
| 17 | 2010-02-03T01:45:24Z | [
"python",
"bash"
] |
embedding short python scripts inside a bash script | 2,189,098 | <p>I'd like to embed the text of short python scripts inside of a bash script, for use in say, my <code>.bash_profile</code>. What's the best way to go about doing such a thing?</p>
<p>The solution I have so far is to call the python interpreter with the <code>-c</code> option, and tell the interpreter to <code>exec</... | 26 | 2010-02-03T01:36:41Z | 2,189,230 | <p>Interesting... I want an answer now too ;-)</p>
<p>He is not asking how to execute python code within a bash script but actually have the python set environment variables.</p>
<p>Put this in a bash script and try to get it to say "it worked".</p>
<pre><code>export ASDF="it didn't work"
python <<END
import ... | 2 | 2010-02-03T02:24:56Z | [
"python",
"bash"
] |
embedding short python scripts inside a bash script | 2,189,098 | <p>I'd like to embed the text of short python scripts inside of a bash script, for use in say, my <code>.bash_profile</code>. What's the best way to go about doing such a thing?</p>
<p>The solution I have so far is to call the python interpreter with the <code>-c</code> option, and tell the interpreter to <code>exec</... | 26 | 2010-02-03T01:36:41Z | 20,754,041 | <p>If you need to use the output of the python in the bash script you can do something like this: </p>
<pre><code>#!/bin/bash
ASDF="it didn't work"
ASDF=`python <<END
ASDF = 'it worked'
print ASDF
END`
echo $ASDF
</code></pre>
| 4 | 2013-12-24T02:24:01Z | [
"python",
"bash"
] |
embedding short python scripts inside a bash script | 2,189,098 | <p>I'd like to embed the text of short python scripts inside of a bash script, for use in say, my <code>.bash_profile</code>. What's the best way to go about doing such a thing?</p>
<p>The solution I have so far is to call the python interpreter with the <code>-c</code> option, and tell the interpreter to <code>exec</... | 26 | 2010-02-03T01:36:41Z | 22,870,525 | <p>If you are using zsh you can embed Python inside the script using zsh's <a href="http://zshwiki.org/home/scripting/paramflags#jflag" rel="nofollow">join</a> and python stdin option (<code>python -</code>):</p>
<pre><code>py_cmd=${(j:\n:)"${(f)$(
# You can also add comments, as long as you balance quotes
<... | 0 | 2014-04-04T18:35:33Z | [
"python",
"bash"
] |
embedding short python scripts inside a bash script | 2,189,098 | <p>I'd like to embed the text of short python scripts inside of a bash script, for use in say, my <code>.bash_profile</code>. What's the best way to go about doing such a thing?</p>
<p>The solution I have so far is to call the python interpreter with the <code>-c</code> option, and tell the interpreter to <code>exec</... | 26 | 2010-02-03T01:36:41Z | 32,239,857 | <p>Sometimes it is not a good idea to use here document. Another alternative is to use python -c:</p>
<pre><code>py_script="
import xml.etree.cElementTree as ET,sys
...
"
python -c "$py_script" arg1 arg2 ...
</code></pre>
| 2 | 2015-08-27T02:44:39Z | [
"python",
"bash"
] |
embedding short python scripts inside a bash script | 2,189,098 | <p>I'd like to embed the text of short python scripts inside of a bash script, for use in say, my <code>.bash_profile</code>. What's the best way to go about doing such a thing?</p>
<p>The solution I have so far is to call the python interpreter with the <code>-c</code> option, and tell the interpreter to <code>exec</... | 26 | 2010-02-03T01:36:41Z | 33,077,717 | <p>One problem with using bash <code>here document</code> is that the script is then passed to Python on <code>stdin</code>, so if you want to use the Python script as a filter, it becomes unwieldy. One alternative is to use the <code>bash</code>'s <code>process substitution</code>, something like this:</p>
<pre><code... | 1 | 2015-10-12T09:32:18Z | [
"python",
"bash"
] |
embedding short python scripts inside a bash script | 2,189,098 | <p>I'd like to embed the text of short python scripts inside of a bash script, for use in say, my <code>.bash_profile</code>. What's the best way to go about doing such a thing?</p>
<p>The solution I have so far is to call the python interpreter with the <code>-c</code> option, and tell the interpreter to <code>exec</... | 26 | 2010-02-03T01:36:41Z | 38,690,573 | <p>Ready to copy-paste example:</p>
<pre><code>input="hello"
output=`python <<END
print $input+" world";
END`
echo $output
</code></pre>
| 0 | 2016-08-01T03:27:20Z | [
"python",
"bash"
] |
Django ORM's "related data" loading behavior | 2,189,122 | <p>In LINQ (I come from a C# background), you can manually load data for related tables via the Include("xxx") method </p>
<pre><code>from a in ctx.MainTable.Include("SubTable")
select a;
</code></pre>
<p>In the above code, every instance of MainTable is loaded and all the data for MainTable.SubTable is also loaded. ... | 1 | 2010-02-03T01:46:21Z | 2,189,425 | <p>See this:</p>
<p><a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4</a></p>
<p>You create a <code>select_related</code> query set to follow relationships and pre-fetch related rows.</p>
<p>Normally, you don't waste... | 3 | 2010-02-03T03:12:02Z | [
"python",
"django",
"linq",
"linq-to-sql",
"django-models"
] |
unicode class in Python | 2,189,156 | <p><code>help(unicode)</code> prints something like:</p>
<pre><code>class unicode(basestring)
| unicode(string [, encoding[, errors]]) -> object
...
</code></pre>
<p>but you can use something different from a basestring as argument, you can do unicode(1) and get u'1'. What happens in that call? int don't have a ... | 2 | 2010-02-03T02:02:26Z | 2,189,172 | <p>Same as <code>unicode(str(1))</code>.</p>
<pre>
>>> class thing(object):
... def __str__(self):
... print "__str__ called on " + repr(self)
... return repr(self)
...
>>> a = thing()
>>> a
<__main__.thing object at 0x7f2f972795d0>
>>> unicode(a)
__str__ called on <__main__.thing object at 0... | 2 | 2010-02-03T02:09:04Z | [
"python",
"unicode"
] |
unicode class in Python | 2,189,156 | <p><code>help(unicode)</code> prints something like:</p>
<pre><code>class unicode(basestring)
| unicode(string [, encoding[, errors]]) -> object
...
</code></pre>
<p>but you can use something different from a basestring as argument, you can do unicode(1) and get u'1'. What happens in that call? int don't have a ... | 2 | 2010-02-03T02:02:26Z | 2,189,271 | <p>If <code>__unicode__</code> exists it is called, otherwise it falls back to <code>__str__</code> </p>
<pre><code>class A(int):
def __str__(self):
print "A.str"
return int.__str__(self)
def __unicode__(self):
print "A.unicode"
return int.__str__(self)
class B(int):
def _... | 2 | 2010-02-03T02:35:41Z | [
"python",
"unicode"
] |
unicode class in Python | 2,189,156 | <p><code>help(unicode)</code> prints something like:</p>
<pre><code>class unicode(basestring)
| unicode(string [, encoding[, errors]]) -> object
...
</code></pre>
<p>but you can use something different from a basestring as argument, you can do unicode(1) and get u'1'. What happens in that call? int don't have a ... | 2 | 2010-02-03T02:02:26Z | 2,189,274 | <p>If there is no <code>__unicode__</code> method, the <code>__str__</code> method will be called instead. Regardless of which of these methods is called, if a <code>unicode</code> is returned, it will be passed on as-is. If a <code>str</code> is returned, it will be decoded using the default encoding, as returned by <... | 1 | 2010-02-03T02:36:10Z | [
"python",
"unicode"
] |
What is the elegant way to get the arguments to a playAudio call from this list | 2,189,259 | <p>I know this is the basic.</p>
<p>I'm just wondering what is the elegant way to do it.</p>
<p>For example:</p>
<p>I want the the 'python01.wav' and 'py*thon' strings from this list</p>
<p>The list is like this:</p>
<pre><code>[
[('name', 'entry')],
[('class', 'entry')],
[('type', 'text/javascript'), ('src', '/te... | 1 | 2010-02-03T02:32:04Z | 2,189,276 | <pre><code>return ('python01.wav', 'py*thon')
</code></pre>
<p>This satisfies your specification perfectly.</p>
<p>But if I had to guess, I don't think it's what you want.</p>
<p>So why don't you give us enough information that we can actually figure out what strings you want to get? Is it everything between single-... | 1 | 2010-02-03T02:36:27Z | [
"python",
"list",
"string"
] |
What is the elegant way to get the arguments to a playAudio call from this list | 2,189,259 | <p>I know this is the basic.</p>
<p>I'm just wondering what is the elegant way to do it.</p>
<p>For example:</p>
<p>I want the the 'python01.wav' and 'py*thon' strings from this list</p>
<p>The list is like this:</p>
<pre><code>[
[('name', 'entry')],
[('class', 'entry')],
[('type', 'text/javascript'), ('src', '/te... | 1 | 2010-02-03T02:32:04Z | 2,189,347 | <p>Perhaps not the greatest solution, but appears to do what you want:</p>
<pre><code>l = [huge list from your example]
for e in l: # for each list
for t in e: # for each tuple
for s in t: # each string
if 'playAudio' in s:
args = s[9:].split(',') #skip 'playAudio' split on comm... | 2 | 2010-02-03T02:54:39Z | [
"python",
"list",
"string"
] |
How to exclude DEFAULTs from Python ConfigParser .items()? | 2,189,288 | <p>I'm using ConfigParser to load in data from a configuration file as follows:</p>
<p><strong>test.conf:</strong></p>
<pre><code>[myfiles]
fileone: %(datadir)s/somefile.foo
filetwo: %(datadir)s/nudderfile.foo
</code></pre>
<p><strong>load.py:</strong></p>
<pre><code>import ConfigParser
config = ConfigParser.Confi... | 10 | 2010-02-03T02:39:50Z | 2,189,599 | <p>Try this:</p>
<pre><code>config = ConfigParser.ConfigParser({'blahblahblah': 'blah'})
config.read('test.conf')
</code></pre>
<p>The <code>blahblahblah</code> key will also appear in <code>items</code>, not because it's a template in the .ini file, but because you specified it as a default. This is how ConfigParser... | 1 | 2010-02-03T04:03:14Z | [
"python",
"configuration",
"configparser",
"defaults"
] |
How to exclude DEFAULTs from Python ConfigParser .items()? | 2,189,288 | <p>I'm using ConfigParser to load in data from a configuration file as follows:</p>
<p><strong>test.conf:</strong></p>
<pre><code>[myfiles]
fileone: %(datadir)s/somefile.foo
filetwo: %(datadir)s/nudderfile.foo
</code></pre>
<p><strong>load.py:</strong></p>
<pre><code>import ConfigParser
config = ConfigParser.Confi... | 10 | 2010-02-03T02:39:50Z | 12,600,066 | <p>Generally, I've found the <a href="http://docs.python.org/py3k/library/configparser.html#configparser.ConfigParser" rel="nofollow">configparser.Configparser</a> class very helpful, but also lacking. <a href="http://wiki.python.org/moin/ConfigParserShootout" rel="nofollow">Others have, too</a>.</p>
<p>However, it <e... | 4 | 2012-09-26T10:51:55Z | [
"python",
"configuration",
"configparser",
"defaults"
] |
How to exclude DEFAULTs from Python ConfigParser .items()? | 2,189,288 | <p>I'm using ConfigParser to load in data from a configuration file as follows:</p>
<p><strong>test.conf:</strong></p>
<pre><code>[myfiles]
fileone: %(datadir)s/somefile.foo
filetwo: %(datadir)s/nudderfile.foo
</code></pre>
<p><strong>load.py:</strong></p>
<pre><code>import ConfigParser
config = ConfigParser.Confi... | 10 | 2010-02-03T02:39:50Z | 37,677,334 | <p>Can't you just filter out the defaults? </p>
<p>e.g.:</p>
<p><code>filtered_items = [x for x in config.items('myfiles') if x[0] not in config.defaults()]</code></p>
| 0 | 2016-06-07T10:51:49Z | [
"python",
"configuration",
"configparser",
"defaults"
] |
What do I do with a Concrete Syntax Tree? | 2,189,330 | <p>I'm using <a href="http://fdik.org/pyPEG/" rel="nofollow">pyPEG</a> to create a parse tree for a simple grammar. The tree is represented using lists and tuples. Here's an example:</p>
<pre><code>[('command',
[('directives',
[('directive',
[('name', 'retrieve')]),
('directive',
[('name', 'comm... | 1 | 2010-02-03T02:50:21Z | 2,189,573 | <p>CSTs (concrete syntax trees) are quite hard to work with for <a href="http://eli.thegreenplace.net/2009/02/16/abstract-vs-concrete-syntax-trees/" rel="nofollow">some reasons</a>. Therefore they're commonly converted to ASTs (abstract syntax tree) for further processing (details in the same article). For instance, <a... | 2 | 2010-02-03T03:55:59Z | [
"python",
"parsing",
"concrete-syntax-tree"
] |
What do I do with a Concrete Syntax Tree? | 2,189,330 | <p>I'm using <a href="http://fdik.org/pyPEG/" rel="nofollow">pyPEG</a> to create a parse tree for a simple grammar. The tree is represented using lists and tuples. Here's an example:</p>
<pre><code>[('command',
[('directives',
[('directive',
[('name', 'retrieve')]),
('directive',
[('name', 'comm... | 1 | 2010-02-03T02:50:21Z | 2,438,521 | <p>we have a community board for support for such questions around pyPEG. You can find it here: <a href="https://community.fdik.org/board/show/2/pypeg/" rel="nofollow">https://community.fdik.org/board/show/2/pypeg/</a></p>
<p>Yours,
VB.</p>
| 0 | 2010-03-13T13:39:08Z | [
"python",
"parsing",
"concrete-syntax-tree"
] |
performance issue when import reactor module before os.fork() | 2,189,332 | <p>i got a performance issue when trying to do:</p>
<pre><code>from twisted.internet import reactor
#some codes here
pid = os.fork()
if not pid:
#some codes blahblahblah
reactor.run()
</code></pre>
<p>this caused very low performance and i didn't find useful informations from the official documentation, i bel... | 1 | 2010-02-03T02:51:15Z | 2,189,389 | <p>Can't you use subprocess instead of os.fork?</p>
| 0 | 2010-02-03T03:03:46Z | [
"python",
"performance",
"twisted"
] |
How to create a new datebase(named xx.db) using python and sqlite3 | 2,189,393 | <pre><code>import sqlite3
conn = sqlite3.connect(r"D:\aaa.db")
</code></pre>
<p>Is there a way to automatically create the db file if it doesn't already exist when I connect to it?</p>
<p>thanks</p>
| 45 | 2010-02-03T03:04:34Z | 2,189,437 | <p>The code you give <em>does</em> create <code>'D:\\aaa.db'</code> if it doesn't exist.</p>
| 69 | 2010-02-03T03:16:43Z | [
"python",
"sqlite"
] |
How to create a new datebase(named xx.db) using python and sqlite3 | 2,189,393 | <pre><code>import sqlite3
conn = sqlite3.connect(r"D:\aaa.db")
</code></pre>
<p>Is there a way to automatically create the db file if it doesn't already exist when I connect to it?</p>
<p>thanks</p>
| 45 | 2010-02-03T03:04:34Z | 2,189,439 | <p>Pretty sure .connect will create the file if it doesn't exist.</p>
| 4 | 2010-02-03T03:16:49Z | [
"python",
"sqlite"
] |
How to create a new datebase(named xx.db) using python and sqlite3 | 2,189,393 | <pre><code>import sqlite3
conn = sqlite3.connect(r"D:\aaa.db")
</code></pre>
<p>Is there a way to automatically create the db file if it doesn't already exist when I connect to it?</p>
<p>thanks</p>
| 45 | 2010-02-03T03:04:34Z | 2,189,463 | <p>If it isn't created automatically, make sure that you have the directory permissions correct</p>
| 7 | 2010-02-03T03:23:19Z | [
"python",
"sqlite"
] |
How to create a new datebase(named xx.db) using python and sqlite3 | 2,189,393 | <pre><code>import sqlite3
conn = sqlite3.connect(r"D:\aaa.db")
</code></pre>
<p>Is there a way to automatically create the db file if it doesn't already exist when I connect to it?</p>
<p>thanks</p>
| 45 | 2010-02-03T03:04:34Z | 18,746,612 | <p>.connect should create a new database file on the fly, given sub-directories do exist, and you have adequate permissioning.</p>
| 0 | 2013-09-11T16:32:32Z | [
"python",
"sqlite"
] |
How to create a new datebase(named xx.db) using python and sqlite3 | 2,189,393 | <pre><code>import sqlite3
conn = sqlite3.connect(r"D:\aaa.db")
</code></pre>
<p>Is there a way to automatically create the db file if it doesn't already exist when I connect to it?</p>
<p>thanks</p>
| 45 | 2010-02-03T03:04:34Z | 24,385,687 | <pre><code>import sqlite3
conn=sqlite3.connect('xx.db')
print "Database created and opened succesfully"
</code></pre>
| 2 | 2014-06-24T11:40:42Z | [
"python",
"sqlite"
] |
How to create a new datebase(named xx.db) using python and sqlite3 | 2,189,393 | <pre><code>import sqlite3
conn = sqlite3.connect(r"D:\aaa.db")
</code></pre>
<p>Is there a way to automatically create the db file if it doesn't already exist when I connect to it?</p>
<p>thanks</p>
| 45 | 2010-02-03T03:04:34Z | 38,920,139 | <p>As it was already mentioned, your code should work if you have permissions to write for this path. However, it is important that <strong>directory must exist</strong>. If you make call for non-existing folder:</p>
<pre><code>conn = sqlite3.connect(r"D:\Some new non-existing folder\aaa.db")
</code></pre>
<p>It will... | 0 | 2016-08-12T14:13:29Z | [
"python",
"sqlite"
] |
What are the advantages, if any, to using mako's or pylon's form handlers instead of coding the form manually? | 2,189,432 | <p>Trying to decide if I should be using mako to handle the forms in my application or not. Thanks for the input.</p>
| -1 | 2010-02-03T03:14:58Z | 2,189,442 | <p>It'll save you a lot of time (even if you use them just during development) to use Pylons built-in form handling. Later if you want to strip them out and hard code a full form for each page, you can but I'd use the built-in one and find ways to customize within it before going completely manual about it.</p>
| 1 | 2010-02-03T03:17:29Z | [
"python",
"pylons",
"mako"
] |
django / haystack / solr simple config - partial field matching issue | 2,189,436 | <p>I have a simple config of haystack/solr on my django app:</p>
<p>from the models.py of this app:</p>
<pre><code>class device(models.Model):
...
hostname = models.CharField(max_length=45, help_text="The hostname for this device")
...
</code></pre>
<p>from the search_sites.py of this app:</p>
<pre><cod... | 0 | 2010-02-03T03:16:14Z | 2,210,664 | <p>It's likely an analysis problem. I'd guess you are using the StandardTokenizer in your schema.xml file for this field. </p>
<p>The standard tokenizer tokenizes host names as a single token. (ref: <a href="http://www.lucidimagination.com/search/document/CDRG_ch05_5.5.1" rel="nofollow">http://www.lucidimagination.com... | 0 | 2010-02-05T21:43:36Z | [
"python",
"django",
"solr",
"django-haystack",
"pysolr"
] |
django / haystack / solr simple config - partial field matching issue | 2,189,436 | <p>I have a simple config of haystack/solr on my django app:</p>
<p>from the models.py of this app:</p>
<pre><code>class device(models.Model):
...
hostname = models.CharField(max_length=45, help_text="The hostname for this device")
...
</code></pre>
<p>from the search_sites.py of this app:</p>
<pre><cod... | 0 | 2010-02-03T03:16:14Z | 8,601,738 | <p>Solr has many configuration possible. For your use case, you may want to user an edge ngram in you schema.xml. Here is an example:</p>
<pre><code><fieldType name="edge_ngram" class="solr.TextField" positionIncrementGap="1">
<analyzer type="index">
<tokenizer class="solr.WhitespaceTokenizerFacto... | 0 | 2011-12-22T09:22:43Z | [
"python",
"django",
"solr",
"django-haystack",
"pysolr"
] |
What is a good (fastest, least broken, etc) way to implement JSON in Python? | 2,189,471 | <p>There seems to be a handful of JSON libraries out there for Python even though Python has a built-in library. One even claims to be built according to <a href="http://www.json.org" rel="nofollow">http://www.json.org</a> spec (which caused me to think 'hmmm, is Python's built in library not built fully to spec?', so ... | 2 | 2010-02-03T03:25:00Z | 2,189,486 | <p>The built in library is fine most of the time although occasionally you can get issues to do with character encoding.</p>
<p>There is cjson if you have performance issues to deal with.</p>
<p>Personally, I just use simplejson - for no particular reason.</p>
| 3 | 2010-02-03T03:28:47Z | [
"python",
"json"
] |
What is a good (fastest, least broken, etc) way to implement JSON in Python? | 2,189,471 | <p>There seems to be a handful of JSON libraries out there for Python even though Python has a built-in library. One even claims to be built according to <a href="http://www.json.org" rel="nofollow">http://www.json.org</a> spec (which caused me to think 'hmmm, is Python's built in library not built fully to spec?', so ... | 2 | 2010-02-03T03:25:00Z | 2,189,518 | <p>Python < 2.6 did not include <code>json</code> module. The presence of multiple JSON implementations says <em>nothing</em> about the quality of the built-in module and everything about the history of having no built-in <code>json</code>. </p>
<p>I suggest that your assumption (multiple implemntations means low q... | 3 | 2010-02-03T03:37:23Z | [
"python",
"json"
] |
What is a good (fastest, least broken, etc) way to implement JSON in Python? | 2,189,471 | <p>There seems to be a handful of JSON libraries out there for Python even though Python has a built-in library. One even claims to be built according to <a href="http://www.json.org" rel="nofollow">http://www.json.org</a> spec (which caused me to think 'hmmm, is Python's built in library not built fully to spec?', so ... | 2 | 2010-02-03T03:25:00Z | 2,189,522 | <p>The built-in module <code>json</code> works perfect. If you have to use an earlier python, use <code>simplejson</code>, a third-party module (which is exactly the same interface). These have the serialization interface you expect from Python and are widely used. </p>
<p>(simple)json by default has some very minor e... | 1 | 2010-02-03T03:38:35Z | [
"python",
"json"
] |
flip bytes using Python's struct module | 2,189,600 | <p>I would like to flip from big to little endian this string:</p>
<p><code>\x00\x40</code> </p>
<p>to have it like this:</p>
<p><code>\x40\x00</code></p>
<p>I guess the proper function to use would be struct.pack, but I can't find a way to make it properly work.
A small help would be very appreciated !</p>
<p>Tha... | 0 | 2010-02-03T04:03:21Z | 2,189,618 | <p>You're not showing the whole code, so the simplest solution would be:</p>
<pre><code>data = data[1] + data[0]
</code></pre>
<p>If you insist on using <code>struct</code>:</p>
<pre><code>>>> from struct import pack, unpack
>>> unpack('<H', '\x12\x13')
(4882,)
>>> pack('>H', *unpack... | 5 | 2010-02-03T04:07:00Z | [
"python",
"struct",
"endianness",
"flip"
] |
flip bytes using Python's struct module | 2,189,600 | <p>I would like to flip from big to little endian this string:</p>
<p><code>\x00\x40</code> </p>
<p>to have it like this:</p>
<p><code>\x40\x00</code></p>
<p>I guess the proper function to use would be struct.pack, but I can't find a way to make it properly work.
A small help would be very appreciated !</p>
<p>Tha... | 0 | 2010-02-03T04:03:21Z | 2,189,625 | <p><code>little_endian = big_endian[1] + big_endian[0]</code></p>
| 0 | 2010-02-03T04:09:22Z | [
"python",
"struct",
"endianness",
"flip"
] |
flip bytes using Python's struct module | 2,189,600 | <p>I would like to flip from big to little endian this string:</p>
<p><code>\x00\x40</code> </p>
<p>to have it like this:</p>
<p><code>\x40\x00</code></p>
<p>I guess the proper function to use would be struct.pack, but I can't find a way to make it properly work.
A small help would be very appreciated !</p>
<p>Tha... | 0 | 2010-02-03T04:03:21Z | 2,189,817 | <p><code>data[::-1]</code> works for any number of bytes.</p>
| 4 | 2010-02-03T05:01:46Z | [
"python",
"struct",
"endianness",
"flip"
] |
flip bytes using Python's struct module | 2,189,600 | <p>I would like to flip from big to little endian this string:</p>
<p><code>\x00\x40</code> </p>
<p>to have it like this:</p>
<p><code>\x40\x00</code></p>
<p>I guess the proper function to use would be struct.pack, but I can't find a way to make it properly work.
A small help would be very appreciated !</p>
<p>Tha... | 0 | 2010-02-03T04:03:21Z | 5,289,118 | <p>I could image that what would really want to do here is to convert the input data from big endian (or network) byteorder to your host byteorder (whatever that may be).</p>
<pre><code>>>> from struct import unpack
>>> result = unpack('>H', '\x00\x40')
</code></pre>
<p>This would be a more porta... | 0 | 2011-03-13T11:40:01Z | [
"python",
"struct",
"endianness",
"flip"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 2,189,814 | <p>If you want the length of an integer as in the number of digits in the integer, you can always convert it to string like <code>str(133)</code> and find its length like <code>len(str(123))</code>. </p>
| 111 | 2010-02-03T05:00:53Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 2,189,821 | <p>Assuming you are asking for the largest number you can store in an integer, the value is implementation dependent. I suggest that you don't think in that way when using python. In any case, quite a large value can be stored in a python 'integer'. Remember, Python uses duck typing!</p>
<p><em>Edit:</em>
I gave my an... | 0 | 2010-02-03T05:02:43Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 2,189,827 | <p>Without conversion to string</p>
<pre><code>import math
digits = int(math.log10(n))+1
</code></pre>
<p>To also handle zero and negative numbers</p>
<pre><code>import math
if n > 0:
digits = int(math.log10(n))+1
elif n == 0:
digits = 1
else:
digits = int(math.log10(-n))+2 # +1 if you don't count the... | 104 | 2010-02-03T05:04:54Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 2,189,834 | <p>Python <code>2.*</code> <code>int</code>s take either 4 or 8 bytes (32 or 64 bits), depending on your Python build. <code>sys.maxint</code> (<code>2**31-1</code> for 32-bit ints, <code>2**63-1</code> for 64-bit ints) will tell you which of the two possibilities obtains.</p>
<p>In Python 3, <code>int</code>s (like ... | 17 | 2010-02-03T05:06:44Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 2,189,885 | <pre><code>>>> a=12345
>>> a.__str__().__len__()
5
</code></pre>
| -5 | 2010-02-03T05:22:28Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 3,260,117 | <pre><code>from math import log10
digits = lambda n: ((n==0) and 1) or int(log10(abs(n)))+1
</code></pre>
| 2 | 2010-07-15T21:10:12Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 4,474,099 | <pre><code>def length(i):
return len(str(i))
</code></pre>
| 0 | 2010-12-17T19:32:53Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 7,702,209 | <p>Let the number be n then the number of digits in n is given by:</p>
<pre><code>math.floor(math.log10(n))+1
</code></pre>
<p>Note that this will give correct answers for integers only.</p>
| 8 | 2011-10-09T08:07:04Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 18,910,454 | <p>A little correction to what @gnibbler just mentioned above, everything is fine but I think for negative he mentioned (<code>+2</code>)... It won't work, you may have to use <code>+1</code> instead.</p>
<pre><code>import math
def gui():
n=int(input("Enter any number"))
if n>0:
print(int(math.log1... | 0 | 2013-09-20T06:45:22Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 23,696,915 | <p>For posterity, no doubt by far the slowest solution to this problem:</p>
<pre><code>def num_digits(num, number_of_calls=1):
"Returns the number of digits of an integer num."
if num == 0 or num == -1:
return 1 if number_of_calls == 1 else 0
else:
return 1 + num_digits(num/10, number_of_ca... | 1 | 2014-05-16T13:50:44Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 28,883,802 | <h2>All math.log10 solutions will give you problems.</h2>
<p>math.log10 is fast but gives problem when your number is greater than 999999999999997. This is because the float have too many .9s, causing the result to round up.</p>
<p>The solution is to use a while counter method for numbers above that threshold.</p>
<... | 5 | 2015-03-05T17:17:06Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 32,643,554 | <p>Well, without converting to string I would do something like:</p>
<pre><code>def lenDigits(x):
"""
Assumes int(x)
"""
x = abs(x)
if x < 10:
return 1
return 1 + lenDigits(x / 10)
</code></pre>
<p>Minimalist recursion FTW</p>
| 2 | 2015-09-18T03:50:17Z | [
"python",
"count",
"integer"
] |
Length of an integer in Python | 2,189,800 | <p>In Python, how do you find the number of digits in an integer?</p>
| 96 | 2010-02-03T04:56:52Z | 40,019,997 | <p>It can be done for integers quickly by using:</p>
<pre><code>len(str(abs(1234567890)))
</code></pre>
<p>Which gets the length of the string of the absolute value of "1234567890"</p>
<p><code>abs</code> returns the number WITHOUT any negatives (only the magnitude of the number), <code>str</code> casts/converts it ... | 0 | 2016-10-13T11:42:01Z | [
"python",
"count",
"integer"
] |
python normalized path gets reset in a for loop | 2,189,863 | <p>I am trying to get a normalized path on windows. The paths are stored in a list and i am looping over those as follows:</p>
<pre><code>>>> lst = ['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> lst
['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> for pth in lst:
... print pth
...
C:\
C... | 0 | 2010-02-03T05:16:04Z | 2,189,879 | <p><code>\\</code> is an escape sequence which prints <code>\</code> as the output. If you want to print <code>C:\\</code>, you'll have to use <code>C:\\\\</code> as the input string(or use raw strings ...). I can't see why you would want that. Although if you particularly want to, there are different options available... | 0 | 2010-02-03T05:21:06Z | [
"python",
"string"
] |
python normalized path gets reset in a for loop | 2,189,863 | <p>I am trying to get a normalized path on windows. The paths are stored in a list and i am looping over those as follows:</p>
<pre><code>>>> lst = ['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> lst
['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> for pth in lst:
... print pth
...
C:\
C... | 0 | 2010-02-03T05:16:04Z | 2,189,880 | <p>you need <code>\\</code>? you can use <code>print repr(pth)</code></p>
| 0 | 2010-02-03T05:21:35Z | [
"python",
"string"
] |
python normalized path gets reset in a for loop | 2,189,863 | <p>I am trying to get a normalized path on windows. The paths are stored in a list and i am looping over those as follows:</p>
<pre><code>>>> lst = ['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> lst
['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> for pth in lst:
... print pth
...
C:\
C... | 0 | 2010-02-03T05:16:04Z | 2,189,881 | <p>The double slash is simply string escaping - you need to escape slashes in string literals. Printing <code>lst[0]</code> before the loop will print it without the slash. If you want to really include a double slash in your literal, use the raw string syntax:</p>
<pre><code>>>> lst = ['C:\\', 'C:\\Windows',... | 3 | 2010-02-03T05:21:37Z | [
"python",
"string"
] |
python normalized path gets reset in a for loop | 2,189,863 | <p>I am trying to get a normalized path on windows. The paths are stored in a list and i am looping over those as follows:</p>
<pre><code>>>> lst = ['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> lst
['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> for pth in lst:
... print pth
...
C:\
C... | 0 | 2010-02-03T05:16:04Z | 2,189,920 | <p>If possible, try to use <a href="http://docs.python.org/library/os.path.html" rel="nofollow">os.path.join()</a> for creating your windows path. You don't have to meddle with slashes as much.</p>
<p>eg</p>
<pre><code>from os.path import join
rootdir="C:\\"
path1 = join(rootdir,"windows")
path2 = join(rootdir,"Progr... | 0 | 2010-02-03T05:35:18Z | [
"python",
"string"
] |
python normalized path gets reset in a for loop | 2,189,863 | <p>I am trying to get a normalized path on windows. The paths are stored in a list and i am looping over those as follows:</p>
<pre><code>>>> lst = ['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> lst
['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> for pth in lst:
... print pth
...
C:\
C... | 0 | 2010-02-03T05:16:04Z | 2,189,954 | <p>Use / for sanity on windows (most programs work with both forms of slashes), but failing that, use r'' whenever you are dealing with backslashed path names.</p>
<pre><code>r'C:\My\Windows\Path'
</code></pre>
<p>If you really want double backslashes, then that works too:</p>
<pre><code>r'C:\\My\\Escaped\\Path'
</c... | 0 | 2010-02-03T05:45:29Z | [
"python",
"string"
] |
python normalized path gets reset in a for loop | 2,189,863 | <p>I am trying to get a normalized path on windows. The paths are stored in a list and i am looping over those as follows:</p>
<pre><code>>>> lst = ['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> lst
['C:\\', 'C:\\Windows', 'C:\\Program Files']
>>> for pth in lst:
... print pth
...
C:\
C... | 0 | 2010-02-03T05:16:04Z | 2,189,984 | <p>In Python, when you say</p>
<pre><code>>>> s = 'C:\\'
</code></pre>
<p><code>s</code> contains three characters: <code>C</code>, <code>:</code> and <code>\</code>. This can be easily seen by:</p>
<pre><code>>>> len(s)
3
</code></pre>
<p>In Python, as in many other languages, a backslash is use... | 2 | 2010-02-03T05:54:58Z | [
"python",
"string"
] |
django csv import threading | 2,190,075 | <p>Is it possible to use threading when importing data from csv files to django.</p>
| 0 | 2010-02-03T06:19:40Z | 2,193,358 | <p>I don't know if i got it right.</p>
<p>I've never used threads with django, but this article can help you:
<a href="http://www.artfulcode.net/articles/threading-django/" rel="nofollow">http://www.artfulcode.net/articles/threading-django/</a></p>
<p>In a few words, it's possible to use threads with django, speciall... | 0 | 2010-02-03T16:08:59Z | [
"python",
"django",
"multithreading",
"csv"
] |
django csv import threading | 2,190,075 | <p>Is it possible to use threading when importing data from csv files to django.</p>
| 0 | 2010-02-03T06:19:40Z | 2,196,168 | <p>Django is Python, so yeah you can use threads, processing etc. Look at python docs on this matter.</p>
<p>But, spawning threads in web environment might be not be such a good idea, try searching here for "django asynchronous" - you'll get many ideas of how to this without threading.</p>
| 2 | 2010-02-03T22:59:38Z | [
"python",
"django",
"multithreading",
"csv"
] |
How to animate a graph I've drawn in PyQt? | 2,190,210 | <p>So I've managed to get a graph drawn up on my screen like such:</p>
<pre><code>class Window(QWidget):
#stuff
graphicsView = QGraphicsView(self)
scene = QGraphicsScene(self)
#draw our nodes and edges.
for i in range(0, len(MAIN_WORLD.currentMax.tour) - 1):
node = ... | 4 | 2010-02-03T06:56:19Z | 2,211,876 | <p><code>QGraphicsScene</code> manages the drawing of the items you've added to it. If the position of the rectangles or lines has changed you can update them if you old onto them:</p>
<pre><code>for i in range( ):
nodes[i] = node = QGraphicsRectItem()
scene.add(nodes[i])
</code></pre>
<p>Later, you can updat... | 2 | 2010-02-06T03:18:44Z | [
"python",
"animation",
"pyqt"
] |
None in boost.python | 2,190,349 | <p>I am trying to translate the following code </p>
<pre><code>d = {}
d[0] = None
</code></pre>
<p>into C++ with boost.python</p>
<pre><code>boost::python::dict d;
d[0] = ?None
</code></pre>
<p>How can I get a None object in boost.python?</p>
<p>ANSWER: </p>
<pre><code>boost::python::dict d;
d[0] = boost::python:... | 8 | 2010-02-03T07:33:40Z | 2,190,435 | <p>You could use:</p>
<pre><code>d[0] = d.get(0)
</code></pre>
<p><code>d.get</code> defaults to <code>None</code> if you don't specify a default value.</p>
| 2 | 2010-02-03T07:55:44Z | [
"c++",
"python",
"boost"
] |
None in boost.python | 2,190,349 | <p>I am trying to translate the following code </p>
<pre><code>d = {}
d[0] = None
</code></pre>
<p>into C++ with boost.python</p>
<pre><code>boost::python::dict d;
d[0] = ?None
</code></pre>
<p>How can I get a None object in boost.python?</p>
<p>ANSWER: </p>
<pre><code>boost::python::dict d;
d[0] = boost::python:... | 8 | 2010-02-03T07:33:40Z | 2,191,360 | <p>There is no constructor of <code>boost::python::object</code> that takes a <code>PyObject*</code> (from my understanding, a ctor like that would invalidate the whole idea if mapping Python types to C++ types anyway, because the PyObject* could be anything). According to the <a href="http://www.boost.org/doc/libs/1_4... | 14 | 2010-02-03T11:01:18Z | [
"c++",
"python",
"boost"
] |
Screen scraping with Python | 2,190,502 | <p>Does Python have screen scraping libraries that offer JavaScript support?</p>
<p>I've been using <strong>pycurl</strong> for simple HTML requests, and Java's <strong>HtmlUnit</strong> for more complicated requests requiring JavaScript support.</p>
<p>Ideally I would like to be able to do everything from Python, bu... | 15 | 2010-02-03T08:11:30Z | 2,190,517 | <p>I have not found anything for this. I use a combination of beautifulsoup and custom routines...</p>
| -2 | 2010-02-03T08:14:48Z | [
"python",
"screen-scraping",
"htmlunit",
"pycurl"
] |
Screen scraping with Python | 2,190,502 | <p>Does Python have screen scraping libraries that offer JavaScript support?</p>
<p>I've been using <strong>pycurl</strong> for simple HTML requests, and Java's <strong>HtmlUnit</strong> for more complicated requests requiring JavaScript support.</p>
<p>Ideally I would like to be able to do everything from Python, bu... | 15 | 2010-02-03T08:11:30Z | 2,190,551 | <p>you can try <a href="http://code.google.com/p/python-spidermonkey/" rel="nofollow">spidermonkey</a> ?</p>
<blockquote>
<p>This Python module allows for the implementation of Javascript?
classes, objects and functions in Python, as well as the evaluation
and calling of Javascript scripts and functions. It borr... | 0 | 2010-02-03T08:21:37Z | [
"python",
"screen-scraping",
"htmlunit",
"pycurl"
] |
Screen scraping with Python | 2,190,502 | <p>Does Python have screen scraping libraries that offer JavaScript support?</p>
<p>I've been using <strong>pycurl</strong> for simple HTML requests, and Java's <strong>HtmlUnit</strong> for more complicated requests requiring JavaScript support.</p>
<p>Ideally I would like to be able to do everything from Python, bu... | 15 | 2010-02-03T08:11:30Z | 2,190,631 | <p><a href="http://www.crummy.com/software/BeautifulSoup/">Beautiful soup</a> is still probably your best bet.</p>
<p>If you need "JavaScript support" for the purpose of intercepting Ajax requests then you should use some sort of capture too (such as <a href="http://www.pocketsoap.com/YATT/">YATT</a>) to monitor what ... | 11 | 2010-02-03T08:38:18Z | [
"python",
"screen-scraping",
"htmlunit",
"pycurl"
] |
Screen scraping with Python | 2,190,502 | <p>Does Python have screen scraping libraries that offer JavaScript support?</p>
<p>I've been using <strong>pycurl</strong> for simple HTML requests, and Java's <strong>HtmlUnit</strong> for more complicated requests requiring JavaScript support.</p>
<p>Ideally I would like to be able to do everything from Python, bu... | 15 | 2010-02-03T08:11:30Z | 2,190,843 | <blockquote>
<p>Scrapy is a fast high-level screen scraping and web crawling framework, used to crawl websites and extract structured data from their pages. It can be used for a wide range of purposes, from data mining to monitoring and automated testing.</p>
</blockquote>
<p>Here you go: <a href="http://scrapy.org/... | 4 | 2010-02-03T09:21:32Z | [
"python",
"screen-scraping",
"htmlunit",
"pycurl"
] |
Screen scraping with Python | 2,190,502 | <p>Does Python have screen scraping libraries that offer JavaScript support?</p>
<p>I've been using <strong>pycurl</strong> for simple HTML requests, and Java's <strong>HtmlUnit</strong> for more complicated requests requiring JavaScript support.</p>
<p>Ideally I would like to be able to do everything from Python, bu... | 15 | 2010-02-03T08:11:30Z | 2,215,099 | <p>There are many options when dealing with static HTML, which the other responses cover. However if you need JavaScript support and want to stay in Python I recommend using <a href="http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html#qtwebkit-module" rel="nofollow">webkit</a> to render the webpage (including... | 12 | 2010-02-06T23:08:19Z | [
"python",
"screen-scraping",
"htmlunit",
"pycurl"
] |
Screen scraping with Python | 2,190,502 | <p>Does Python have screen scraping libraries that offer JavaScript support?</p>
<p>I've been using <strong>pycurl</strong> for simple HTML requests, and Java's <strong>HtmlUnit</strong> for more complicated requests requiring JavaScript support.</p>
<p>Ideally I would like to be able to do everything from Python, bu... | 15 | 2010-02-03T08:11:30Z | 7,441,632 | <p><a href="http://seleniumhq.org/" rel="nofollow">Selenium</a> maybe? It allows you to automate an actual browser (Firefox, IE, Safari) using python (amongst other languages). It is meant for testing websites, but seems it should be usable for scraping as well. (disclaimer: never used it myself)</p>
| 3 | 2011-09-16T07:47:27Z | [
"python",
"screen-scraping",
"htmlunit",
"pycurl"
] |
Screen scraping with Python | 2,190,502 | <p>Does Python have screen scraping libraries that offer JavaScript support?</p>
<p>I've been using <strong>pycurl</strong> for simple HTML requests, and Java's <strong>HtmlUnit</strong> for more complicated requests requiring JavaScript support.</p>
<p>Ideally I would like to be able to do everything from Python, bu... | 15 | 2010-02-03T08:11:30Z | 16,070,949 | <p>The <a href="http://docs.webscraping.com/examples.html" rel="nofollow">Webscraping</a> library wraps the PyQt4 WebView into a simple and easy-to-use API.</p>
<p>Here is a simple example to download a web page rendered by WebKit and extract the title element using XPath (taken from the URL above):</p>
<pre><code>fr... | 1 | 2013-04-17T21:55:00Z | [
"python",
"screen-scraping",
"htmlunit",
"pycurl"
] |
Execution of python scripts like udev/rules.d, cron.d or /apt/source.d | 2,190,509 | <p>I use python to patch system settings of linux systems distributed with partimage.
I want to have the following python script structure:</p>
<pre><code>/patch.d/
10_patch_netwok.py
20_patch_hostname.py
...
50_patch_software_xyz.py
InitSystem.py
</code></pre>
<p>The <code>InitSytem.py</code> should... | 1 | 2010-02-03T08:13:58Z | 2,190,549 | <p>Python scripts are also python modules, so the best way to load and run them is to simply import them using</p>
<pre><code>__import__('some_module')
</code></pre>
<p>This will mean that they run in the same process though. If this is undesirable, then your options would be to use the multi-threading or multi-proce... | 1 | 2010-02-03T08:21:25Z | [
"python",
"sysadmin"
] |
How can I load test data into AppEngine automatically? | 2,190,622 | <p>I'd like to automatically load some test data into the AppEngine datastore when a local copy is run by one of my team's developers. I know that the <a href="http://code.google.com/appengine/docs/python/tools/uploadingdata.html" rel="nofollow">bulk uploader</a> lets you do this from the command line, but I'm looking ... | 3 | 2010-02-03T08:36:52Z | 2,191,641 | <p>Why not just automate the bulk loader? It's a command line tool, as you point out, so trivial to run from your build process (or whatever other trigger you want).</p>
| 1 | 2010-02-03T11:56:06Z | [
"python",
"google-app-engine",
"web-applications"
] |
Rebuilding PIL with FreeType | 2,190,711 | <p>Previously I got a suggedtion to Install the FreeType dev files and rebuild PIL again.
but I have no idea how to do it.</p>
<p>any help will be thanked for</p>
| 0 | 2010-02-03T08:54:56Z | 2,190,882 | <p>You do it exactly the same way as you did before, but now with the FreeType-dev files installed.</p>
| 0 | 2010-02-03T09:26:30Z | [
"python"
] |
Python: convert script from procedural to OOP style | 2,190,880 | <p>I wrote this simple Munin plugin to graph average fan speed and I want to redo it to OOP - strictly as a learning exercise. Don't have a clue where to start though. Anyone feel like offering some guidance or even an example of what this script should look like when done. I will use it to redo some other scripts into... | 1 | 2010-02-03T09:26:26Z | 2,190,965 | <p>You remake it in OOP by identifying code and data that goes together. These you then merge into "classes".</p>
<p>You actual data above seems to be the output of a process.
The code is iterating over it. I guess you can make a class out of that if you want to, but it's a bit silly. :)</p>
<p>So, something like thi... | 2 | 2010-02-03T09:39:30Z | [
"python",
"oop"
] |
how to correct the misencoded string? | 2,190,904 | <p>i used <a href="http://code.google.com/p/mutagen/" rel="nofollow">mutagen</a> to read the mp3 metadata, since the id3 tag is read in as unicode but in fact it is GBK encoded. how to correct this in python?</p>
<pre><code>audio = EasyID3(name)
title = audio["title"][0]
print title
print repr(title)
</code></pre>
<... | 0 | 2010-02-03T09:29:51Z | 2,190,976 | <p>Looks like it's auto-decoding using <code>latin1</code>. To fix:</p>
<pre><code>>>> title = u'\xb5\xb1\xc4\xe3\xb9\xc2\xb5\xa5\xc4\xe3\xbb\xe1\xcf\xeb\xc6\xf0\xcb\xad'
>>> print title.encode('latin1').decode('GBK')
å½ä½ å¤åä½ ä¼æ³èµ·è°
</code></pre>
<p>Tested in Python 2.x but should work ... | 2 | 2010-02-03T09:41:25Z | [
"python",
"encoding",
"mp3",
"mutagen"
] |
how to correct the misencoded string? | 2,190,904 | <p>i used <a href="http://code.google.com/p/mutagen/" rel="nofollow">mutagen</a> to read the mp3 metadata, since the id3 tag is read in as unicode but in fact it is GBK encoded. how to correct this in python?</p>
<pre><code>audio = EasyID3(name)
title = audio["title"][0]
print title
print repr(title)
</code></pre>
<... | 0 | 2010-02-03T09:29:51Z | 2,191,006 | <p>It looks like the string has been decoded to unicode using the wrong encoding (latin-1).</p>
<p>You need to encode it to a byte string and then decode it back to unicode using the correct encoding.</p>
<pre><code>title = u'\xb5\xb1\xc4\xe3\xb9\xc2\xb5\xa5\xc4\xe3\xbb\xe1\xcf\xeb\xc6\xf0\xcb\xad'
print title.encode... | 4 | 2010-02-03T09:46:12Z | [
"python",
"encoding",
"mp3",
"mutagen"
] |
Jquery and Django multiple checkbox | 2,190,998 | <p>I am a beginner in jquery so please bear with me.
I have a jquery function that allows me to select multiple checkboxes and create a string as follows:</p>
<pre><code>function getSelectedVals(){
var tmp =[];
$("input[name='checks']").each(function() {
if ($(this).attr('checked'))
{
check... | 2 | 2010-02-03T09:44:25Z | 2,191,085 | <p>From what I see, you do it the way around. You should set the same name on all checkboxes. I don't know why do you send it by GET, I'd suggest sending it by POST.</p>
<pre><code><input type="checkbox" name="vehicle" value="Bike" />
<input type="checkbox" name="vehicle" value="Car" />
<input type="che... | 6 | 2010-02-03T10:01:15Z | [
"jquery",
"python",
"django"
] |
Jquery and Django multiple checkbox | 2,190,998 | <p>I am a beginner in jquery so please bear with me.
I have a jquery function that allows me to select multiple checkboxes and create a string as follows:</p>
<pre><code>function getSelectedVals(){
var tmp =[];
$("input[name='checks']").each(function() {
if ($(this).attr('checked'))
{
check... | 2 | 2010-02-03T09:44:25Z | 2,191,153 | <p>firstly, I don't know if you need to manipulate the checkbox values into a string like you are doing. if you allocate them the same name attribute, http (or jQuery's) serialisation will do it for you.</p>
<p>On the Django side use getlist to grab a list, the [] accessor only gets the last value in a list of params.... | 0 | 2010-02-03T10:16:11Z | [
"jquery",
"python",
"django"
] |
jquery autocomplete tagging | 2,191,116 | <p>Can any one tell me how to use tagging auto-complete in django templates?</p>
<p>I have done this in django admin interface but i am confused to how to do it in the template.</p>
<p>Thanks in advance</p>
| 1 | 2010-02-03T10:08:04Z | 2,191,555 | <p>This is from a template where I implemented autocomplete</p>
<pre><code>$(document).ready(function() {
$("#searchbox").autocomplete('/search_stuff/', {
width: 300,
multiple: false,
matchContains: true,
delay: 900,
extraParams: {
s: function() { return $("#... | 1 | 2010-02-03T11:39:15Z | [
"jquery",
"python",
"django"
] |
jquery autocomplete tagging | 2,191,116 | <p>Can any one tell me how to use tagging auto-complete in django templates?</p>
<p>I have done this in django admin interface but i am confused to how to do it in the template.</p>
<p>Thanks in advance</p>
| 1 | 2010-02-03T10:08:04Z | 2,191,686 | <p>In my template i have this code:</p>
<pre><code>$(document).ready(function(){
$("#tags1").autocomplete("/taglookup/", {
width: 320,
multiple: true,
multipleSeparator: " "
});
}
</code></pre>
<p>and on my url.py i have this on the urlparttern tuple, it can be anything depending... | 2 | 2010-02-03T12:06:08Z | [
"jquery",
"python",
"django"
] |
jquery autocomplete tagging | 2,191,116 | <p>Can any one tell me how to use tagging auto-complete in django templates?</p>
<p>I have done this in django admin interface but i am confused to how to do it in the template.</p>
<p>Thanks in advance</p>
| 1 | 2010-02-03T10:08:04Z | 2,192,060 | <p>You could use <a href="http://code.google.com/p/django-tagging-autocomplete/" rel="nofollow">my django-tagging-autocomplete reusable app</a> and take advantage of provided TagAutocomplete form widget. You can find out more about using the widget <a href="http://code.google.com/p/django-tagging-autocomplete/wiki/Read... | 2 | 2010-02-03T13:13:25Z | [
"jquery",
"python",
"django"
] |
How to match info from a string | 2,191,202 | <p>I have a string which has a version number. I want to read the version number from this code so I can compare it with other code I am using. I have code done below but cannot get it working, can anyone see the problem?</p>
<pre><code>print results
r = re.compile(r'(version\s*\s*)(\S+)')
for l in results:... | 2 | 2010-02-03T10:24:08Z | 2,191,224 | <pre><code>>>> import re
>>> results = "Name Info Type Call version 1.0.40.437 Fri Oct 2 10:54:35 BST 2009"
>>> m = re.search("version ([^ ]+)", results)
>>> if m:
... version = m.group(1)
... print "matched, found:", version
... else:
... print "didn't find a version"
...
ma... | 0 | 2010-02-03T10:29:24Z | [
"python",
"search",
"string"
] |
How to match info from a string | 2,191,202 | <p>I have a string which has a version number. I want to read the version number from this code so I can compare it with other code I am using. I have code done below but cannot get it working, can anyone see the problem?</p>
<pre><code>print results
r = re.compile(r'(version\s*\s*)(\S+)')
for l in results:... | 2 | 2010-02-03T10:24:08Z | 2,191,226 | <p>here's a non regex way</p>
<pre><code>>>> s="Name Info Type Call version 1.0.40.437 Fri Oct 2 10:54:35 BST 2009".split()
>>> for n,i in enumerate(s):
... if "version" in i:
... print s[n+1]
...
1.0.40.437
>>>
</code></pre>
| 2 | 2010-02-03T10:29:53Z | [
"python",
"search",
"string"
] |
How to match info from a string | 2,191,202 | <p>I have a string which has a version number. I want to read the version number from this code so I can compare it with other code I am using. I have code done below but cannot get it working, can anyone see the problem?</p>
<pre><code>print results
r = re.compile(r'(version\s*\s*)(\S+)')
for l in results:... | 2 | 2010-02-03T10:24:08Z | 2,191,234 | <p>I can spot a couple of things:</p>
<ul>
<li><p>You say <code>results</code> is a string, but you're iterating through it - so <code>l</code> is a character each time.</p></li>
<li><p><code>re.match</code> only matches at the <em>beginning</em> of a string. Use <code>re.search</code> instead.</p></li>
</ul>
| 0 | 2010-02-03T10:32:23Z | [
"python",
"search",
"string"
] |
How to match info from a string | 2,191,202 | <p>I have a string which has a version number. I want to read the version number from this code so I can compare it with other code I am using. I have code done below but cannot get it working, can anyone see the problem?</p>
<pre><code>print results
r = re.compile(r'(version\s*\s*)(\S+)')
for l in results:... | 2 | 2010-02-03T10:24:08Z | 2,191,236 | <pre><code>>>> r = re.compile(r'version (\S*)')
>>> r.findall(results)
['1.0.40.437']
</code></pre>
<p>Non regexp way</p>
<pre><code>>>> m=results.split()
>>> m[m.index('version')+1]
'1.0.40.437'
</code></pre>
| 2 | 2010-02-03T10:32:38Z | [
"python",
"search",
"string"
] |
How to match info from a string | 2,191,202 | <p>I have a string which has a version number. I want to read the version number from this code so I can compare it with other code I am using. I have code done below but cannot get it working, can anyone see the problem?</p>
<pre><code>print results
r = re.compile(r'(version\s*\s*)(\S+)')
for l in results:... | 2 | 2010-02-03T10:24:08Z | 2,191,243 | <p>Why regexp? I should use split(' ') and use value next to 'version', or simplier:</p>
<pre><code>print results.split(' ')[5]
</code></pre>
<p>If you must use regexp then try:</p>
<pre><code>rx = re.compile('version\s+([\d.]+)\s+')
rxx = rx.search(results)
if rxx:
print rxx.group(1)
</code></pre>
| 3 | 2010-02-03T10:34:19Z | [
"python",
"search",
"string"
] |
How to match info from a string | 2,191,202 | <p>I have a string which has a version number. I want to read the version number from this code so I can compare it with other code I am using. I have code done below but cannot get it working, can anyone see the problem?</p>
<pre><code>print results
r = re.compile(r'(version\s*\s*)(\S+)')
for l in results:... | 2 | 2010-02-03T10:24:08Z | 2,191,551 | <blockquote>
<blockquote>
<p>The below answers are useful, but the way I had it would read a file and take all the numbers out and put them into a list so all I would have to do is compare the two numbers of the list.</p>
</blockquote>
</blockquote>
<p>I'm going to assume that the version format is fixed (ie. ... | 0 | 2010-02-03T11:38:36Z | [
"python",
"search",
"string"
] |
Differentiate gtk.Entry icons | 2,191,209 | <p>I'm adding two icons to a gtk.Entry in PyGTK. The icons signals are handled by the following method</p>
<pre><code>def entry_icon_event(self, widget, position, event)
</code></pre>
<p>I'm trying to differentiate between the two of them:</p>
<pre><code><enum GTK_ENTRY_ICON_PRIMARY of type GtkEntryIconPosition&g... | 3 | 2010-02-03T10:26:12Z | 2,217,442 | <p>Alright, since no one gave an answer, I'll do with what I actually found. A method to use this icons would look like this:</p>
<pre><code>def entry_icon_event(self, widget, icon, event):
if icon.value_name == "GTK_ENTRY_ICON_PRIMARY":
print "First Button"
if event.button == 0:
print ... | 0 | 2010-02-07T16:58:50Z | [
"python",
"icons",
"pygtk",
"entry"
] |
Differentiate gtk.Entry icons | 2,191,209 | <p>I'm adding two icons to a gtk.Entry in PyGTK. The icons signals are handled by the following method</p>
<pre><code>def entry_icon_event(self, widget, position, event)
</code></pre>
<p>I'm trying to differentiate between the two of them:</p>
<pre><code><enum GTK_ENTRY_ICON_PRIMARY of type GtkEntryIconPosition&g... | 3 | 2010-02-03T10:26:12Z | 2,438,628 | <p>There is better way to do it:</p>
<pre><code>def entry_icon_event(self, widget, icon, event):
if icon == gtk.ENTRY_ICON_PRIMARY:
...
elif icon == gtk.ENTRY_ICON_SECONDARY:
...
</code></pre>
| 1 | 2010-03-13T14:14:43Z | [
"python",
"icons",
"pygtk",
"entry"
] |
Using if-condition to check filename | 2,191,262 | <p>I'm doing a real silly mistake in Python but unable to find what it is</p>
<p>I'm doing something like this in python</p>
<pre><code>filename="file1"
if name == 'file1'
print 1
</code></pre>
<p>I'm getting an invalid syntax error</p>
| 1 | 2010-02-03T10:37:02Z | 2,191,279 | <p>You are missing a colon</p>
<pre><code>filename="file1"
if name == 'file1':
print 1
</code></pre>
| 7 | 2010-02-03T10:41:08Z | [
"python",
"syntax-error"
] |
Using if-condition to check filename | 2,191,262 | <p>I'm doing a real silly mistake in Python but unable to find what it is</p>
<p>I'm doing something like this in python</p>
<pre><code>filename="file1"
if name == 'file1'
print 1
</code></pre>
<p>I'm getting an invalid syntax error</p>
| 1 | 2010-02-03T10:37:02Z | 2,191,283 | <p>You need to put a colon at the end of the if statment</p>
<pre><code>filename="file1"
if name == 'file1':
print 1
</code></pre>
| 4 | 2010-02-03T10:41:30Z | [
"python",
"syntax-error"
] |
Using if-condition to check filename | 2,191,262 | <p>I'm doing a real silly mistake in Python but unable to find what it is</p>
<p>I'm doing something like this in python</p>
<pre><code>filename="file1"
if name == 'file1'
print 1
</code></pre>
<p>I'm getting an invalid syntax error</p>
| 1 | 2010-02-03T10:37:02Z | 2,191,304 | <p>what is name?? did you define it elsewhere?? I assume its "filename" instead, so</p>
<pre><code>filename="file1"
if filename == 'file1':
print 1
</code></pre>
<p>if "name" is defined, then the problem is indeed the ":" at the end of "if" line.</p>
| 1 | 2010-02-03T10:45:20Z | [
"python",
"syntax-error"
] |
Python Creating Unwanted Folder in Directory | 2,191,402 | <p>Python is creating a folder in my directory every time I call this method. The method is in one of my Django applications that requires access to the server's local area. </p>
<pre><code>def filepath(filename, foldername='', envar='MYAPPDIR'):
if envar is not None and envar is os.environ:
dirpath = os.... | 1 | 2010-02-03T11:10:26Z | 2,191,425 | <p>I guess it's going into the second part of your initial <code>if</code> clause. Can you print out the values of envar and the keys in os.environ when you run this in your environment? That should give you your answer. Also, you realise that <code>os.environ</code> is the environment in which your server is running a... | 0 | 2010-02-03T11:14:13Z | [
"python",
"file-access"
] |
Python Creating Unwanted Folder in Directory | 2,191,402 | <p>Python is creating a folder in my directory every time I call this method. The method is in one of my Django applications that requires access to the server's local area. </p>
<pre><code>def filepath(filename, foldername='', envar='MYAPPDIR'):
if envar is not None and envar is os.environ:
dirpath = os.... | 1 | 2010-02-03T11:10:26Z | 2,191,458 | <pre><code>def filepath(filename, foldername=None, envar='MYAPPDIR'):
default = '~/myFolder'
if foldername:
default = os.path.join(default, foldername)
dirpath = os.path.expanduser(os.environ.get(envar, default))
try:
os.makedirs(dirpath)
except OSError as e:
if e.errno != errno.EEXIST:
rai... | 3 | 2010-02-03T11:19:59Z | [
"python",
"file-access"
] |
How to get a reference to the current class from class body? | 2,191,505 | <p>I want to keep a dictionary of (all, non-immediate included) subclasses in a base class, so that I can instantiate them from a string. I'm doing this because the <code>CLSID</code> is sent through a web form, so I want to restrict the choices to the ones set from the subclasses. (I don't want to <code>eval()</code>/... | 3 | 2010-02-03T11:28:40Z | 2,191,704 | <p>You could muck with metaclasses to do the job for you, but I think a simpler solution might suffice:</p>
<pre><code>class BaseClass(object):
CLASS_ID = None
_CLASSES = {}
@classmethod
def create_from_id(cls, class_id):
return CLASSES[class_id]()
@classmethod
def register(cls):
... | 2 | 2010-02-03T12:09:52Z | [
"python",
"inheritance",
"class"
] |
How to get a reference to the current class from class body? | 2,191,505 | <p>I want to keep a dictionary of (all, non-immediate included) subclasses in a base class, so that I can instantiate them from a string. I'm doing this because the <code>CLSID</code> is sent through a web form, so I want to restrict the choices to the ones set from the subclasses. (I don't want to <code>eval()</code>/... | 3 | 2010-02-03T11:28:40Z | 2,191,711 | <p>Irrevocably tying this with the base class:</p>
<pre><code>class AutoRegister(type):
def __new__(mcs, name, bases, D):
self = type.__new__(mcs, name, bases, D)
if "ID" in D: # only register if has ID attribute directly
if self.ID in self._by_id:
raise ValueError("duplicate ID: %r" % self.ID... | 6 | 2010-02-03T12:10:39Z | [
"python",
"inheritance",
"class"
] |
Verify if provided string corresponds to pattern on python | 2,191,581 | <p>could you please advice how to verify in python if provided string correspond to provided pattern and return result.</p>
<p>For example the provided pattern is following:</p>
<p>< [prefix]-[id]> separated by ','>|< log >"</p>
<p>where prefix is any number of alphabetic characters,
id is only numbers but not... | 0 | 2010-02-03T11:44:08Z | 2,191,598 | <p>Python has great regexp library in stdlib. Here is <a href="http://docs.python.org/library/re.html" rel="nofollow">documentation</a>. Simply use re.match and that should be all you need.</p>
| 0 | 2010-02-03T11:48:31Z | [
"python",
"regex",
"string"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.