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 |
|---|---|---|---|---|---|---|---|---|---|
Decode HTML entities in Python string? | 2,087,370 | <p>I'm parsing some HTML with Beautiful Soup 3, but it contains HTML entities which Beautiful Soup 3 doesn't automatically decode for me:</p>
<pre><code>>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup("<p>&pound;682m</p>")
>>> text = soup.find("p").strin... | 128 | 2010-01-18T16:08:52Z | 2,087,446 | <p>Beautiful Soup handles entity conversion. In Beautiful Soup 3, you'll need to specify the <code>convertEntities</code> argument to the <code>BeautifulSoup</code> constructor (see the <a href="http://www.crummy.com/software/BeautifulSoup/bs3/documentation.html#Entity%20Conversion">'Entity Conversion'</a> section of t... | 53 | 2010-01-18T16:19:14Z | [
"python",
"html",
"html-entities"
] |
Decode HTML entities in Python string? | 2,087,370 | <p>I'm parsing some HTML with Beautiful Soup 3, but it contains HTML entities which Beautiful Soup 3 doesn't automatically decode for me:</p>
<pre><code>>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup("<p>&pound;682m</p>")
>>> text = soup.find("p").strin... | 128 | 2010-01-18T16:08:52Z | 13,939,198 | <p>This probably isnt relevant here. But to eliminate these html entites from an entire document, you can do something like this: (Assume document = page and please forgive the sloppy code, but if you have ideas as to how to make it better, Im all ears - Im new to this).</p>
<pre><code>import re
import HTMLParser
r... | 2 | 2012-12-18T18:28:55Z | [
"python",
"html",
"html-entities"
] |
Decode HTML entities in Python string? | 2,087,370 | <p>I'm parsing some HTML with Beautiful Soup 3, but it contains HTML entities which Beautiful Soup 3 doesn't automatically decode for me:</p>
<pre><code>>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup("<p>&pound;682m</p>")
>>> text = soup.find("p").strin... | 128 | 2010-01-18T16:08:52Z | 21,110,649 | <p>Beautiful Soup 4 allows you to <a href="http://www.crummy.com/software/BeautifulSoup/bs4/doc/#output-formatters" rel="nofollow">set a formatter to your output</a></p>
<blockquote>
<p>If you pass in <code>formatter=None</code>, Beautiful Soup will not modify strings
at all on output. This is the fastest option, ... | 2 | 2014-01-14T10:03:44Z | [
"python",
"html",
"html-entities"
] |
Decode HTML entities in Python string? | 2,087,370 | <p>I'm parsing some HTML with Beautiful Soup 3, but it contains HTML entities which Beautiful Soup 3 doesn't automatically decode for me:</p>
<pre><code>>>> from BeautifulSoup import BeautifulSoup
>>> soup = BeautifulSoup("<p>&pound;682m</p>")
>>> text = soup.find("p").strin... | 128 | 2010-01-18T16:08:52Z | 38,846,165 | <p>You can use replace_entities from w3lib.html library</p>
<pre><code>In [202]: from w3lib.html import replace_entities
In [203]: replace_entities("&pound;682m")
Out[203]: u'\xa3682m'
In [204]: print replace_entities("&pound;682m")
£682m
</code></pre>
| 1 | 2016-08-09T08:52:54Z | [
"python",
"html",
"html-entities"
] |
Can a Python package depend on a specific version control revision of another Python package? | 2,087,492 | <p>Some useful Python packages are broken on pypi, and the only acceptable version is a particular revision in a revision control system. Can that be expressed in <code>setup.py</code> e.g</p>
<p><code>requires = 'svn://example.org/useful.package/trunk@1234'</code> ?</p>
| 9 | 2010-01-18T16:25:37Z | 2,087,761 | <p>If you really require an obscure version of another package, and there's no way to make do with other versions, you might want to simply distribute that version of the package with your own. If necessary put it in your own namespace to ensure that your version is the one that is used.</p>
| 2 | 2010-01-18T17:07:01Z | [
"python",
"setuptools",
"distutils",
"easy-install",
"pip"
] |
Can a Python package depend on a specific version control revision of another Python package? | 2,087,492 | <p>Some useful Python packages are broken on pypi, and the only acceptable version is a particular revision in a revision control system. Can that be expressed in <code>setup.py</code> e.g</p>
<p><code>requires = 'svn://example.org/useful.package/trunk@1234'</code> ?</p>
| 9 | 2010-01-18T16:25:37Z | 2,088,397 | <p>You can release packages of specific versions, but you have to distribute them together. There is no way to automatically download them with standard Python.</p>
<p>However, you can use Buildout and create a buildout.cfg that makes it possible to replicate the environment. It can check out and install specific revi... | 1 | 2010-01-18T18:45:23Z | [
"python",
"setuptools",
"distutils",
"easy-install",
"pip"
] |
Can a Python package depend on a specific version control revision of another Python package? | 2,087,492 | <p>Some useful Python packages are broken on pypi, and the only acceptable version is a particular revision in a revision control system. Can that be expressed in <code>setup.py</code> e.g</p>
<p><code>requires = 'svn://example.org/useful.package/trunk@1234'</code> ?</p>
| 9 | 2010-01-18T16:25:37Z | 2,150,202 | <p>I haven't figured out how to reference this from <code>setup.py</code> but <code>pip</code> can check out specific revisions of Python packages with a simple requirements file. With a requirements file called <code>requires.txt</code>, <code>pip install -r requires.txt</code> will install all the packages listed in ... | 2 | 2010-01-27T20:59:55Z | [
"python",
"setuptools",
"distutils",
"easy-install",
"pip"
] |
Can a Python package depend on a specific version control revision of another Python package? | 2,087,492 | <p>Some useful Python packages are broken on pypi, and the only acceptable version is a particular revision in a revision control system. Can that be expressed in <code>setup.py</code> e.g</p>
<p><code>requires = 'svn://example.org/useful.package/trunk@1234'</code> ?</p>
| 9 | 2010-01-18T16:25:37Z | 2,163,919 | <p>You need to do two things. First, require the exact version you want, e.g.:</p>
<pre><code>install_requires = "useful.package==1.9dev-r1234"
</code></pre>
<p>and then include a <code>dependency_links</code> setting specifying where to find it:</p>
<pre><code>dependency_links = ["svn://example.org/useful.package/... | 12 | 2010-01-29T17:47:02Z | [
"python",
"setuptools",
"distutils",
"easy-install",
"pip"
] |
Why is my Facebook application with error 104 ("invalid signature")? | 2,087,672 | <p>I am trying to develop a Facebook application using PyFacebook (hosted on Google App Engine). It's an FBML application (runs in a Facebook canvas instead of an iframe). I'm having problems getting any API calls to function. The sequence looks like this:</p>
<pre><code>fb = facebook.Faceboook(api_key, secret_key)... | 1 | 2010-01-18T16:52:14Z | 2,088,294 | <p>Deleting the Facebook application and re-creating it, then configuring my code with the new API key and secret key, resolved this problem.</p>
| 1 | 2010-01-18T18:32:51Z | [
"python",
"authentication",
"facebook",
"cherrypy",
"pyfacebook"
] |
Retrieving Values with p.expect | 2,087,795 | <p>I have a program that logs into a server and issues commands. The results are printed out at the end of the script. The below code shows the script I have created to pass commands through ssh.</p>
<pre><code>import pexpect
ssh_newkey = 'Are you sure you want to continue connecting'
# my ssh command line
p=pexpect.... | 0 | 2010-01-18T17:13:04Z | 2,087,821 | <p>do you mean save it to a file?? then try this</p>
<pre><code>open("output.txt","w").write(results)
</code></pre>
<p>or when you run the script on the command line: </p>
<pre><code>$ python script.py > output.txt
</code></pre>
<p>otherwise, define what you mean by "capture"</p>
| 1 | 2010-01-18T17:16:26Z | [
"python"
] |
Retrieving Values with p.expect | 2,087,795 | <p>I have a program that logs into a server and issues commands. The results are printed out at the end of the script. The below code shows the script I have created to pass commands through ssh.</p>
<pre><code>import pexpect
ssh_newkey = 'Are you sure you want to continue connecting'
# my ssh command line
p=pexpect.... | 0 | 2010-01-18T17:13:04Z | 2,087,999 | <p>Are <code>Value = 1800</code> etc. the contents of <code>results</code>? And you want to "capture" that? </p>
<p>Do you mean you want to parse those results? Or execute them as python?</p>
<p>If the former you could do something like (untested, unclean, doesn't deal carefully with whitespace):</p>
<pre><code>resu... | 1 | 2010-01-18T17:41:57Z | [
"python"
] |
Retrieving Values with p.expect | 2,087,795 | <p>I have a program that logs into a server and issues commands. The results are printed out at the end of the script. The below code shows the script I have created to pass commands through ssh.</p>
<pre><code>import pexpect
ssh_newkey = 'Are you sure you want to continue connecting'
# my ssh command line
p=pexpect.... | 0 | 2010-01-18T17:13:04Z | 2,088,490 | <p>After each call to <code>p.expect</code> returns, whatever the child process emitted just before the matched part (any number of lines), and the matched part itself, are accessible as the <code>before</code> and <code>after</code> properties of <code>p</code> -- that's your "capture" for you!</p>
<p>I.e., as <a hre... | 1 | 2010-01-18T19:00:28Z | [
"python"
] |
Retrieving Values with p.expect | 2,087,795 | <p>I have a program that logs into a server and issues commands. The results are printed out at the end of the script. The below code shows the script I have created to pass commands through ssh.</p>
<pre><code>import pexpect
ssh_newkey = 'Are you sure you want to continue connecting'
# my ssh command line
p=pexpect.... | 0 | 2010-01-18T17:13:04Z | 2,093,258 | <p>Whenever this happens to me, it's because the string I'm splitting does not have the value I expected. Why not look at it directly?</p>
<pre><code>for line in results:
print line
name, val = line.split(' = ')
results_dict[name] = val
</code></pre>
<p>If it were what you think it is, this would work (... | 0 | 2010-01-19T12:04:20Z | [
"python"
] |
How to find out whether a function defined for an instance of a class in Python? | 2,087,911 | <p>I want to know if a function is defined for an instance of a class</p>
<pre><code>class c(object):
def func(self): pass
cc = c()
>>> is_function_defined_for_instance(cc,'func')
True
>>> is_function_defined_for_instance(cc,'cnuf')
False
</code></pre>
<p>my cleanest attempts at the function is:<... | 0 | 2010-01-18T17:29:11Z | 2,087,926 | <p>Can you throw some sort of custom exception if the method is missing? (I'm coming from Ruby land here :) )</p>
| 0 | 2010-01-18T17:31:23Z | [
"python",
"reflection",
"function"
] |
How to find out whether a function defined for an instance of a class in Python? | 2,087,911 | <p>I want to know if a function is defined for an instance of a class</p>
<pre><code>class c(object):
def func(self): pass
cc = c()
>>> is_function_defined_for_instance(cc,'func')
True
>>> is_function_defined_for_instance(cc,'cnuf')
False
</code></pre>
<p>my cleanest attempts at the function is:<... | 0 | 2010-01-18T17:29:11Z | 2,087,987 | <pre><code>>>> def is_func(instance, func):
test = getattr(instance, func, None)
if test and hasattr(test, '__call__'):
return True
>>> is_func('', 'len')
>>> is_func({}, 'fromkeys')
True
</code></pre>
<p>or you could use <a href="http://docs.python.org/library/inspect.html#... | 2 | 2010-01-18T17:39:57Z | [
"python",
"reflection",
"function"
] |
How to find out whether a function defined for an instance of a class in Python? | 2,087,911 | <p>I want to know if a function is defined for an instance of a class</p>
<pre><code>class c(object):
def func(self): pass
cc = c()
>>> is_function_defined_for_instance(cc,'func')
True
>>> is_function_defined_for_instance(cc,'cnuf')
False
</code></pre>
<p>my cleanest attempts at the function is:<... | 0 | 2010-01-18T17:29:11Z | 2,088,255 | <p>In Python 2.6 or better, the recommended approach is:</p>
<pre><code>import collections
def is_func(instance, func):
return isinstance(getattr(instance, func, None), collections.Callable)
</code></pre>
<p>The new ABCs (Abstract Base Classes) in the <code>collections</code> module are the correct way, in Python ... | 3 | 2010-01-18T18:28:37Z | [
"python",
"reflection",
"function"
] |
Storing system-wide DB connection password for a Python module | 2,087,920 | <p>I have a written a Python module which due to its specifics needs to have a MySQL database connection. Right now, details of this connection (host, database, username and password to connect with) are stored in /etc/mymodule.conf in plaintext, which is obviously not a good idea.</p>
<p>Supposedly, the /etc/mymodule... | 0 | 2010-01-18T17:30:26Z | 2,088,188 | <p>Your constraints set a very difficult problem: every user on the system must be able to access that password (since that's the only way for users to access that database)... yet they must not (except when running that script, and presumably only when running it without e.g. a <code>python -i</code> session that woul... | 4 | 2010-01-18T18:16:26Z | [
"python",
"security"
] |
Storing system-wide DB connection password for a Python module | 2,087,920 | <p>I have a written a Python module which due to its specifics needs to have a MySQL database connection. Right now, details of this connection (host, database, username and password to connect with) are stored in /etc/mymodule.conf in plaintext, which is obviously not a good idea.</p>
<p>Supposedly, the /etc/mymodule... | 0 | 2010-01-18T17:30:26Z | 2,088,544 | <p>Why not create a default MySQL user account with restricted permissions? You
could set it up so it can only read the particular database. You could also
restrict the default user to only being able to SELECT, with no ability to INSERT,UPDATE or
DELETE. The particular privileges you should set of course depend on you... | 1 | 2010-01-18T19:09:33Z | [
"python",
"security"
] |
Get kwargs Inside Function | 2,088,056 | <p>If I have a python function like so:</p>
<pre><code>def some_func(arg1, arg2, arg3=1, arg4=2):
</code></pre>
<p>Is there a way to determine which arguments were passed by keyword from inside the function?</p>
<p><strong>EDIT</strong></p>
<p>For those asking why I need this, I have no real reason, it came up in a... | 11 | 2010-01-18T17:52:23Z | 2,088,083 | <p>do you want to know whether <code>arg3</code> was <code>1</code> because it was passed from outside or because it was a default value? No there is no way to do this as far as I'm aware. The main reason, I suspect, that there is no need for such knowledge. What typically is done is the following:</p>
<pre><code>>... | 1 | 2010-01-18T17:55:56Z | [
"python",
"introspection",
"kwargs"
] |
Get kwargs Inside Function | 2,088,056 | <p>If I have a python function like so:</p>
<pre><code>def some_func(arg1, arg2, arg3=1, arg4=2):
</code></pre>
<p>Is there a way to determine which arguments were passed by keyword from inside the function?</p>
<p><strong>EDIT</strong></p>
<p>For those asking why I need this, I have no real reason, it came up in a... | 11 | 2010-01-18T17:52:23Z | 2,088,101 | <p>No, there is no way to do it in Python code with this signature -- if you need this information, you need to change the function's signature.</p>
<p>If you look at the Python C API, you'll see that the actual way arguments are passed to a normal Python function is always as a tuple plus a dict -- i.e., the way that... | 13 | 2010-01-18T18:00:04Z | [
"python",
"introspection",
"kwargs"
] |
Get kwargs Inside Function | 2,088,056 | <p>If I have a python function like so:</p>
<pre><code>def some_func(arg1, arg2, arg3=1, arg4=2):
</code></pre>
<p>Is there a way to determine which arguments were passed by keyword from inside the function?</p>
<p><strong>EDIT</strong></p>
<p>For those asking why I need this, I have no real reason, it came up in a... | 11 | 2010-01-18T17:52:23Z | 2,088,109 | <p>Just do it like this:</p>
<pre><code>def some_func ( arg1, arg2, arg3=None, arg4=None ):
if arg3 is None:
arg3 = 1 # default value
if arg4 is None:
arg4 = 2 # default value
# do something
</code></pre>
<p>That way you can see when something was set, <em>and</em> you are also able to wo... | 1 | 2010-01-18T18:01:07Z | [
"python",
"introspection",
"kwargs"
] |
Get kwargs Inside Function | 2,088,056 | <p>If I have a python function like so:</p>
<pre><code>def some_func(arg1, arg2, arg3=1, arg4=2):
</code></pre>
<p>Is there a way to determine which arguments were passed by keyword from inside the function?</p>
<p><strong>EDIT</strong></p>
<p>For those asking why I need this, I have no real reason, it came up in a... | 11 | 2010-01-18T17:52:23Z | 2,088,111 | <p>You're pretty much going to have to redefine your function:</p>
<pre><code>def some_func(*args, **kwargs):
</code></pre>
<p>and do the marshaling yourself. There's no way to tell the difference between pass-by-position, pass-by-keyword, and default.</p>
| 2 | 2010-01-18T18:01:37Z | [
"python",
"introspection",
"kwargs"
] |
Get kwargs Inside Function | 2,088,056 | <p>If I have a python function like so:</p>
<pre><code>def some_func(arg1, arg2, arg3=1, arg4=2):
</code></pre>
<p>Is there a way to determine which arguments were passed by keyword from inside the function?</p>
<p><strong>EDIT</strong></p>
<p>For those asking why I need this, I have no real reason, it came up in a... | 11 | 2010-01-18T17:52:23Z | 2,088,136 | <p>Here's my solution via decorators:</p>
<pre><code>def showargs(function):
def inner(*args, **kwargs):
return function((args, kwargs), *args, **kwargs)
return inner
@showargs
def some_func(info, arg1, arg2, arg3=1, arg4=2):
print arg1,arg2,arg3,arg4
return info
In [226]: some_func(1,2,3, ar... | 8 | 2010-01-18T18:05:59Z | [
"python",
"introspection",
"kwargs"
] |
Integer to base-x system using recursion in python | 2,088,201 | <p>I am trying to write a recursive code that can convert a number to any base system. for example, the integer 10 into binary would convert to 1010</p>
<p>So far I have this but I'm having "None" in between my output. Can anyone help me with my code?</p>
<pre><code>def convert(a,b):
add = a%b
if a<=1:
... | 1 | 2010-01-18T18:19:54Z | 2,088,212 | <p>The <code>convert</code> function returns None, and <code>print</code> prints it. You should either remove the <code>print</code> call, or accumulate the result as a string and return it.</p>
<p>(I'm assuming that the call to <code>base</code> is actually meant to be a recursive call to <code>convert</code>.)</p>
| 0 | 2010-01-18T18:22:29Z | [
"python",
"recursion"
] |
Integer to base-x system using recursion in python | 2,088,201 | <p>I am trying to write a recursive code that can convert a number to any base system. for example, the integer 10 into binary would convert to 1010</p>
<p>So far I have this but I'm having "None" in between my output. Can anyone help me with my code?</p>
<pre><code>def convert(a,b):
add = a%b
if a<=1:
... | 1 | 2010-01-18T18:19:54Z | 2,088,217 | <p>You have no return statement in your else block, and you have no recursive call to <code>convert</code>.</p>
<p>I think you want:</p>
<pre><code>if a<=1:
return str(a)
else:
return str(convert(a//b,b)) + str(add)
</code></pre>
<p>as in</p>
<pre><code>>>> def convert(a,b):
... add = a%b
... ... | 1 | 2010-01-18T18:22:52Z | [
"python",
"recursion"
] |
Integer to base-x system using recursion in python | 2,088,201 | <p>I am trying to write a recursive code that can convert a number to any base system. for example, the integer 10 into binary would convert to 1010</p>
<p>So far I have this but I'm having "None" in between my output. Can anyone help me with my code?</p>
<pre><code>def convert(a,b):
add = a%b
if a<=1:
... | 1 | 2010-01-18T18:19:54Z | 2,088,440 | <p>I recommend you structure your code in a more precise way. You can split the vaguely-specified task you mention along different sub-tasks, e.g.:</p>
<ul>
<li>determine and normalize the signs of
the number and base (do you <em>need</em> to
support negative bases, or can you
just raise an exception?), also
ensuring ... | 1 | 2010-01-18T18:52:20Z | [
"python",
"recursion"
] |
Integer to base-x system using recursion in python | 2,088,201 | <p>I am trying to write a recursive code that can convert a number to any base system. for example, the integer 10 into binary would convert to 1010</p>
<p>So far I have this but I'm having "None" in between my output. Can anyone help me with my code?</p>
<pre><code>def convert(a,b):
add = a%b
if a<=1:
... | 1 | 2010-01-18T18:19:54Z | 30,479,846 | <p>I'm working on making a pip package for this.</p>
<p>I recommend you use my bases.py <a href="https://github.com/kamijoutouma/bases.py" rel="nofollow">https://github.com/kamijoutouma/bases.py</a> which was inspired by bases.js</p>
<pre><code>from bases import Bases
bases = Bases()
bases.toBase16(200) ... | 0 | 2015-05-27T10:29:22Z | [
"python",
"recursion"
] |
Installing PIL (Python Imaging Library) in Win7 64 bits, Python 2.6.4 | 2,088,304 | <p>I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (<a href="http://effbot.org/zone/python-register.htm">http://effbot.org/zone/python-register.htm</a>) Python, but the sc... | 61 | 2010-01-18T18:34:35Z | 2,088,317 | <p>I think I had a similar problem in the past, with another python library. I believe that it was a windows permission issue. Try adding "Users" to your python directory, and give them full access.</p>
| 1 | 2010-01-18T18:36:13Z | [
"python",
"python-imaging-library",
"windows-7-x64"
] |
Installing PIL (Python Imaging Library) in Win7 64 bits, Python 2.6.4 | 2,088,304 | <p>I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (<a href="http://effbot.org/zone/python-register.htm">http://effbot.org/zone/python-register.htm</a>) Python, but the sc... | 61 | 2010-01-18T18:34:35Z | 2,088,402 | <p>Make sure you have the Visual C++ Redistributable package installed on your machine.</p>
| 0 | 2010-01-18T18:46:17Z | [
"python",
"python-imaging-library",
"windows-7-x64"
] |
Installing PIL (Python Imaging Library) in Win7 64 bits, Python 2.6.4 | 2,088,304 | <p>I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (<a href="http://effbot.org/zone/python-register.htm">http://effbot.org/zone/python-register.htm</a>) Python, but the sc... | 61 | 2010-01-18T18:34:35Z | 2,088,575 | <p>Compiling PIL on Windows x64 is apparently a bit of a pain. (Well, compiling anything on Windows is a bit of a pain in my experience. But still.) As well as PIL itself you'll need to build many dependencies. See <a href="http://mail.python.org/pipermail/image-sig/2009-March/005448.html">these notes</a> from the mail... | 20 | 2010-01-18T19:15:22Z | [
"python",
"python-imaging-library",
"windows-7-x64"
] |
Installing PIL (Python Imaging Library) in Win7 64 bits, Python 2.6.4 | 2,088,304 | <p>I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (<a href="http://effbot.org/zone/python-register.htm">http://effbot.org/zone/python-register.htm</a>) Python, but the sc... | 61 | 2010-01-18T18:34:35Z | 2,722,694 | <p>If you installed a win64 python, you need a win64 PIL. The official PIL download site only has win32, as far as I can tell. The win32 installer will not see your 64-bit python installation.</p>
<p>No amount of tinkering with permissions or redistributables will fix this. You could use the win32 python instead (the ... | 3 | 2010-04-27T15:45:59Z | [
"python",
"python-imaging-library",
"windows-7-x64"
] |
Installing PIL (Python Imaging Library) in Win7 64 bits, Python 2.6.4 | 2,088,304 | <p>I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (<a href="http://effbot.org/zone/python-register.htm">http://effbot.org/zone/python-register.htm</a>) Python, but the sc... | 61 | 2010-01-18T18:34:35Z | 2,862,112 | <p>Just got this error msg on my 32 bit Windows - I read the FAQ here: <a href="http://pythonware.com/products/pil/faq.htm" rel="nofollow">http://pythonware.com/products/pil/faq.htm</a> and this sort of indicates that Windows is funny. Looked again at install pg and downloaded the Windows executable for Python26 # Py... | 0 | 2010-05-19T00:32:49Z | [
"python",
"python-imaging-library",
"windows-7-x64"
] |
Installing PIL (Python Imaging Library) in Win7 64 bits, Python 2.6.4 | 2,088,304 | <p>I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (<a href="http://effbot.org/zone/python-register.htm">http://effbot.org/zone/python-register.htm</a>) Python, but the sc... | 61 | 2010-01-18T18:34:35Z | 3,308,907 | <p>I've just had the same problem (with Python 2.7 and PIL for this versions, but the solution should work also for 2.6) and the way to solve it is to copy all the registry keys from:</p>
<pre><code>HKEY_LOCAL_MACHINE\SOFTWARE\Python
</code></pre>
<p>to</p>
<pre><code>HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Python
<... | 29 | 2010-07-22T12:40:30Z | [
"python",
"python-imaging-library",
"windows-7-x64"
] |
Installing PIL (Python Imaging Library) in Win7 64 bits, Python 2.6.4 | 2,088,304 | <p>I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (<a href="http://effbot.org/zone/python-register.htm">http://effbot.org/zone/python-register.htm</a>) Python, but the sc... | 61 | 2010-01-18T18:34:35Z | 3,474,340 | <p>I was having the same problem so I decided to download the source kit and install it according to how you posted above...</p>
<ol>
<li>Downloaded Source Kit</li>
<li>Opened command prompt on that folder and typed python setup.py build</li>
<li>Then I typed python setup.py install</li>
</ol>
<p>It worked perfectly!... | 0 | 2010-08-13T06:15:57Z | [
"python",
"python-imaging-library",
"windows-7-x64"
] |
Installing PIL (Python Imaging Library) in Win7 64 bits, Python 2.6.4 | 2,088,304 | <p>I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (<a href="http://effbot.org/zone/python-register.htm">http://effbot.org/zone/python-register.htm</a>) Python, but the sc... | 61 | 2010-01-18T18:34:35Z | 4,579,917 | <p>I found a working win7 binary here: <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">Unofficial Windows Binaries for Python Extension Packages </a> It's from Christoph Gohlke at UC Irvine. There are binaries for python 2.5, 2.6, 2.7 , 3.1 and 3.2 for both 32bit and 64 bit windows.</p>
<p>There are a whole l... | 116 | 2011-01-02T18:54:51Z | [
"python",
"python-imaging-library",
"windows-7-x64"
] |
Installing PIL (Python Imaging Library) in Win7 64 bits, Python 2.6.4 | 2,088,304 | <p>I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (<a href="http://effbot.org/zone/python-register.htm">http://effbot.org/zone/python-register.htm</a>) Python, but the sc... | 61 | 2010-01-18T18:34:35Z | 23,530,639 | <p>Pillow is new version</p>
<p>PIL-1.1.7.win-amd64-py2.x installers are available at </p>
<p><a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil</a></p>
| 0 | 2014-05-08T00:16:02Z | [
"python",
"python-imaging-library",
"windows-7-x64"
] |
Installing PIL (Python Imaging Library) in Win7 64 bits, Python 2.6.4 | 2,088,304 | <p>I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (<a href="http://effbot.org/zone/python-register.htm">http://effbot.org/zone/python-register.htm</a>) Python, but the sc... | 61 | 2010-01-18T18:34:35Z | 24,422,198 | <p><a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a></p>
<p>press contrl F
type Pillowâ2.4.0.winâamd64âpy3.3.exe</p>
<p>then click and downloadd the 64 bit version </p>
<p>Pillow is a replacement for PIL, the Python Image Library, which provides... | 0 | 2014-06-26T04:05:45Z | [
"python",
"python-imaging-library",
"windows-7-x64"
] |
Making filenames/line numbers linkable in Emacs gud buffer | 2,088,307 | <p>I'm running pdb on my testcases in Python through the gud buffer. When I get a stacktrace/failure in my testcase, it looks like this:</p>
<pre><code>FAIL: test_foo_function (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test... | 10 | 2010-01-18T18:35:03Z | 2,090,043 | <p>I think what you want to customize is <code>compilation-parse-errors-filename-function</code>, which is a function that takes a filename, and returns a modified version of the filename to be displayed. This is a buffer local variable, so you should set it in each buffer that will be displaying python errors (there i... | 1 | 2010-01-18T23:45:54Z | [
"python",
"emacs",
"pdb",
"gud"
] |
Making filenames/line numbers linkable in Emacs gud buffer | 2,088,307 | <p>I'm running pdb on my testcases in Python through the gud buffer. When I get a stacktrace/failure in my testcase, it looks like this:</p>
<pre><code>FAIL: test_foo_function (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test... | 10 | 2010-01-18T18:35:03Z | 2,092,336 | <p>Adding to Justin's answer:</p>
<p>I have the following in my slime config which is supposed to jump to a file and line from a clojure stack trace.</p>
<p>Unfortunately I must admit that it doesn't actually work for me at the moment - the function isn't able to find the correct file - but as far as I can tell, that... | 0 | 2010-01-19T09:14:59Z | [
"python",
"emacs",
"pdb",
"gud"
] |
Making filenames/line numbers linkable in Emacs gud buffer | 2,088,307 | <p>I'm running pdb on my testcases in Python through the gud buffer. When I get a stacktrace/failure in my testcase, it looks like this:</p>
<pre><code>FAIL: test_foo_function (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test... | 10 | 2010-01-18T18:35:03Z | 2,122,436 | <p>Thanks to a hint by Gerard B I figured it out. I'm doing this from pdbtrack (shell) instead of pure pdb, but it should work in both I believe. You need to enable compilation-shell-minor-mode. And have the following code in your .emacs:</p>
<pre><code>;; if compilation-shell-minor-mode is on, then these regexes
;... | 4 | 2010-01-23T06:53:52Z | [
"python",
"emacs",
"pdb",
"gud"
] |
GObject.add_emission_hook usage | 2,088,451 | <p>I was kindly directed to use <a href="http://www.pygtk.org/docs/pygobject/gobject-functions.html#function-gobject--add-emission-hook" rel="nofollow">GObject's "add_emission_hook"</a> following a <a href="http://stackoverflow.com/questions/2074372/connecting-signals-in-gtk-anonymous-way">recent question on SO</a> b... | 0 | 2010-01-18T18:54:24Z | 2,090,584 | <p>After a discussion with helpful folks on IRC #pygtk, here is what I came up with:</p>
<pre><code>import gobject
class Signals(gobject.GObject):
__gsignals__ = {
"lastfm_username_changed": (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING,)) #@UndefinedVariable
}
def __init__(... | 0 | 2010-01-19T02:00:29Z | [
"python",
"gobject",
"pygobject"
] |
Integrate stiff ODEs with Python | 2,088,473 | <p>I'm looking for a good library that will integrate stiff ODEs in Python. The issue is, scipy's odeint gives me good solutions <em>sometimes</em>, but the slightest change in the initial conditions causes it to fall down and give up. The same problem is solved quite happily by MATLAB's stiff solvers (ode15s and ode23... | 14 | 2010-01-18T18:57:33Z | 2,093,019 | <p>I am currently studying a bit of ODE and its solvers, so your question is very interesting to me...</p>
<p>From what I have heard and read, for stiff problems the right way to go is to choose an implicit method as a step function (correct me if I am wrong, I am still learning the misteries of ODE solvers). I cannot... | 1 | 2010-01-19T11:20:03Z | [
"python",
"scipy",
"pygsl"
] |
Integrate stiff ODEs with Python | 2,088,473 | <p>I'm looking for a good library that will integrate stiff ODEs in Python. The issue is, scipy's odeint gives me good solutions <em>sometimes</em>, but the slightest change in the initial conditions causes it to fall down and give up. The same problem is solved quite happily by MATLAB's stiff solvers (ode15s and ode23... | 14 | 2010-01-18T18:57:33Z | 2,104,485 | <p>Python can call C. The industry standard is <a href="https://computation.llnl.gov/casc/nsde/pubs/u113855.pdf">LSODE</a> in ODEPACK. It is public-domain. You can download the <a href="http://www.koders.com/c/fidC42AC8E93AF65E48DBF9A2548B3D8D8642724CBD.aspx">C version</a>. These solvers are extremely tricky, so it's b... | 10 | 2010-01-20T19:58:01Z | [
"python",
"scipy",
"pygsl"
] |
Integrate stiff ODEs with Python | 2,088,473 | <p>I'm looking for a good library that will integrate stiff ODEs in Python. The issue is, scipy's odeint gives me good solutions <em>sometimes</em>, but the slightest change in the initial conditions causes it to fall down and give up. The same problem is solved quite happily by MATLAB's stiff solvers (ode15s and ode23... | 14 | 2010-01-18T18:57:33Z | 2,243,962 | <p>If you can solve your problem with Matlab's <code>ode15s</code>, you should be able to solve it with the <code>vode</code> solver of scipy. To simulate <code>ode15s</code>, I use the following settings:</p>
<pre><code>ode15s = scipy.integrate.ode(f)
ode15s.set_integrator('vode', method='bdf', order=15, nsteps=3000)... | 15 | 2010-02-11T11:01:28Z | [
"python",
"scipy",
"pygsl"
] |
Integrate stiff ODEs with Python | 2,088,473 | <p>I'm looking for a good library that will integrate stiff ODEs in Python. The issue is, scipy's odeint gives me good solutions <em>sometimes</em>, but the slightest change in the initial conditions causes it to fall down and give up. The same problem is solved quite happily by MATLAB's stiff solvers (ode15s and ode23... | 14 | 2010-01-18T18:57:33Z | 6,835,539 | <p><a href="http://pydstool.sourceforge.net" rel="nofollow">PyDSTool</a> wraps the Radau solver, which is an excellent implicit stiff integrator. This has more setup than odeint, but a lot less than PyGSL. The greatest benefit is that your RHS function is specified as a string (typically, although you can build a syste... | 2 | 2011-07-26T19:38:41Z | [
"python",
"scipy",
"pygsl"
] |
Java equivalent of Pythons urllib.urlencode(HashMap based UrlEncode) | 2,088,502 | <p><a href="http://stackoverflow.com/questions/2018026/should-i-use-urllib-or-urllib2/2018103#2018103">From</a> </p>
<p>Whats the java equivalent of Pythonâs urllib.urlencode?<br>
Like</p>
<pre><code>>>> urllib.urlencode({'abc':'d f', 'def': '-!2'})
'abc=d+f&def=-%212'
</code></pre>
<p>Where I can pa... | 3 | 2010-01-18T19:03:19Z | 2,088,516 | <p><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLEncoder.html" rel="nofollow">java.net.URLEncoder</a> should work for you - though you would have to extend it to accept the hashmap - but that is not very difficult. </p>
| 2 | 2010-01-18T19:05:35Z | [
"java",
"python",
"url",
"encoding",
"urlencode"
] |
How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions | 2,088,569 | <p>When I run the following from a bash shell on my Mac:</p>
<pre><code>$ file /usr/bin/python
</code></pre>
<p>I get the following three lines:</p>
<pre><code>/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/pytho... | 36 | 2010-01-18T19:13:50Z | 2,088,593 | <p><a href="http://www.jaharmi.com/2009/08/29/python_32_bit_execution_on_snow_leopard">http://www.jaharmi.com/2009/08/29/python_32_bit_execution_on_snow_leopard</a></p>
<p><code>$ defaults write com.apple.versioner.python Prefer-32-Bit -bool yes</code></p>
| 24 | 2010-01-18T19:18:13Z | [
"python",
"osx-snow-leopard",
"32bit-64bit"
] |
How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions | 2,088,569 | <p>When I run the following from a bash shell on my Mac:</p>
<pre><code>$ file /usr/bin/python
</code></pre>
<p>I get the following three lines:</p>
<pre><code>/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/pytho... | 36 | 2010-01-18T19:13:50Z | 2,088,618 | <ol>
<li><p>You can find out a lot about the Python version you're running via the <code>platform</code> module (the <code>sys</code> module also has a few simple helpers)</p></li>
<li><p>On Mac OS X, you can run a "fat binary" with your chosen architecture with, for example,</p>
<p>arch -i386 /usr/bin/python</p></li>... | 30 | 2010-01-18T19:21:54Z | [
"python",
"osx-snow-leopard",
"32bit-64bit"
] |
How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions | 2,088,569 | <p>When I run the following from a bash shell on my Mac:</p>
<pre><code>$ file /usr/bin/python
</code></pre>
<p>I get the following three lines:</p>
<pre><code>/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/pytho... | 36 | 2010-01-18T19:13:50Z | 3,059,113 | <p><strong>Fix for use with virtualenv on Snow Leopard</strong></p>
<p>danielrsmith's answer works for me when I am not using virtualenv, but virtualenv makes a copy of the python executable which causes it not to work:</p>
<pre><code>$ which python
/Users/cogg/.virtualenvs/tweakeats/bin/python
$ python
[...]
>&g... | 19 | 2010-06-17T05:33:01Z | [
"python",
"osx-snow-leopard",
"32bit-64bit"
] |
How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions | 2,088,569 | <p>When I run the following from a bash shell on my Mac:</p>
<pre><code>$ file /usr/bin/python
</code></pre>
<p>I get the following three lines:</p>
<pre><code>/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/pytho... | 36 | 2010-01-18T19:13:50Z | 6,551,660 | <p>The answer has been accepted. But I think the 3rd question is still unanswered. I found it to be an interesting question and so did some research for the same. Here is the answer I found in another SO forum - </p>
<blockquote>
<p>SnowLeopard runs 32-bit system software and applications on 32-bit Intel machines, a... | 6 | 2011-07-01T18:10:21Z | [
"python",
"osx-snow-leopard",
"32bit-64bit"
] |
How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions | 2,088,569 | <p>When I run the following from a bash shell on my Mac:</p>
<pre><code>$ file /usr/bin/python
</code></pre>
<p>I get the following three lines:</p>
<pre><code>/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/pytho... | 36 | 2010-01-18T19:13:50Z | 13,274,749 | <p>the third question has to do with the 32 / 64 bit kernel</p>
<p>just because you have a 64 bit capable OS and 64 bit capable CPU processor does not mean you are booting up a 64 bit kernel in Mac OSX</p>
<p>If you got a Mac with 10.6 snow leopard on it from the factory, then it shipped in 32 bit mode by default</p>... | 0 | 2012-11-07T17:15:06Z | [
"python",
"osx-snow-leopard",
"32bit-64bit"
] |
How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions | 2,088,569 | <p>When I run the following from a bash shell on my Mac:</p>
<pre><code>$ file /usr/bin/python
</code></pre>
<p>I get the following three lines:</p>
<pre><code>/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/pytho... | 36 | 2010-01-18T19:13:50Z | 18,130,678 | <p>I tried many different ways of executing the Skype4Py test script using,</p>
<pre><code>arch -i386
</code></pre>
<p>What worked in the end was looking at the segfault path for the claimed 64-bit version of python and putting that in my header file:
#!/System/Library/Frameworks/Python.framework/Versions/2.7/Res... | 0 | 2013-08-08T15:58:50Z | [
"python",
"osx-snow-leopard",
"32bit-64bit"
] |
How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions | 2,088,569 | <p>When I run the following from a bash shell on my Mac:</p>
<pre><code>$ file /usr/bin/python
</code></pre>
<p>I get the following three lines:</p>
<pre><code>/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/pytho... | 36 | 2010-01-18T19:13:50Z | 34,815,185 | <p>After a huge amount of trial and error myself trying out some of the suggestions above, I stumbled upon the following symlink:</p>
<pre><code>/usr/local/bin/python2-32
</code></pre>
<p>pointing to:</p>
<pre><code>/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-32
</code></pre>
<p>And I observe that... | 0 | 2016-01-15T16:07:50Z | [
"python",
"osx-snow-leopard",
"32bit-64bit"
] |
Linking to boost unit test framework with boost build | 2,088,924 | <p>Using boost build, if I can link to a boost python library with this in my jamfile:</p>
<blockquote>
<p>project myProject : requirement
/boost/python//boost_python ;</p>
</blockquote>
<p>how can I link to boost test? I have built the boost test library.</p>
<p>I do... | 0 | 2010-01-18T20:21:02Z | 2,092,705 | <p>If you have standard (or prebuilt) libraries installed in a location which can vary between different machines, you may consider using site-config. Then the site-config can be adapted on each machine but the project Jamfile remains the same.</p>
<p>See the <a href="http://www.boost.org/boost-build2/doc/html/bbv2/r... | 1 | 2010-01-19T10:19:37Z | [
"python",
"boost",
"build",
"testing",
"bjam"
] |
Blobstore is stable enough for production? | 2,088,949 | <p>I <em>really</em> need upload files bigger that 1 Mb, so i only have the Blobstore API. But any use it in production? know any issue or problems?</p>
| 1 | 2010-01-18T20:25:17Z | 2,089,024 | <p>I've used the Google-internal equivalent happily (I work for Google), but the externally-available Blobstore is explicitly tagged as "an experimental feature" in the <a href="http://code.google.com/appengine/docs/python/blobstore/" rel="nofollow">docs</a> -- "the API and behavior of the service may change in ways th... | 3 | 2010-01-18T20:36:25Z | [
"python",
"google-app-engine"
] |
Blobstore is stable enough for production? | 2,088,949 | <p>I <em>really</em> need upload files bigger that 1 Mb, so i only have the Blobstore API. But any use it in production? know any issue or problems?</p>
| 1 | 2010-01-18T20:25:17Z | 10,962,218 | <p>It seems that the blobstore is no longer marked as experimental, so I'm guessing it's now stable enough for serious use.</p>
<p>I don't see any mention of it being experimental here:
<a href="https://developers.google.com/appengine/docs/python/blobstore/overview" rel="nofollow">https://developers.google.com/appengi... | 0 | 2012-06-09T15:26:59Z | [
"python",
"google-app-engine"
] |
Sorting CSV in Python | 2,089,036 | <p>I assumed sorting a CSV file on multiple text/numeric fields using Python would be a problem that was already solved. But I can't find any example code anywhere, except for specific code focusing on sorting date fields.</p>
<p>How would one go about sorting a relatively large CSV file (tens of thousand lines) on mu... | 5 | 2010-01-18T20:38:35Z | 2,089,080 | <p>Python's sort works in-memory only; however, tens of thousands of lines should fit in memory easily on a modern machine. So:</p>
<pre><code>import csv
def sortcsvbymanyfields(csvfilename, themanyfieldscolumnnumbers):
with open(csvfilename, 'rb') as f:
readit = csv.reader(f)
thedata = list(readit)
thed... | 10 | 2010-01-18T20:45:16Z | [
"python",
"sorting",
"csv"
] |
Sorting CSV in Python | 2,089,036 | <p>I assumed sorting a CSV file on multiple text/numeric fields using Python would be a problem that was already solved. But I can't find any example code anywhere, except for specific code focusing on sorting date fields.</p>
<p>How would one go about sorting a relatively large CSV file (tens of thousand lines) on mu... | 5 | 2010-01-18T20:38:35Z | 2,089,131 | <p>You bring up 3 issues:</p>
<ul>
<li>file size</li>
<li>csv data</li>
<li>sorting on multiple fields</li>
</ul>
<p>Here is a solution for the third part. You can handle csv data in a more sophisticated way.</p>
<pre><code>>>> data = 'a,b,c\nb,b,a\nb,c,a\n'
>>> lines = [e.split(',') for e in data... | -1 | 2010-01-18T20:51:37Z | [
"python",
"sorting",
"csv"
] |
Sorting CSV in Python | 2,089,036 | <p>I assumed sorting a CSV file on multiple text/numeric fields using Python would be a problem that was already solved. But I can't find any example code anywhere, except for specific code focusing on sorting date fields.</p>
<p>How would one go about sorting a relatively large CSV file (tens of thousand lines) on mu... | 5 | 2010-01-18T20:38:35Z | 2,090,183 | <p>Here's Alex's answer, reworked to support column data types:</p>
<pre><code>import csv
import operator
def sort_csv(csv_filename, types, sort_key_columns):
"""sort (and rewrite) a csv file.
types: data types (conversion functions) for each column in the file
sort_key_columns: column numbers of columns... | 3 | 2010-01-19T00:18:44Z | [
"python",
"sorting",
"csv"
] |
Sorting CSV in Python | 2,089,036 | <p>I assumed sorting a CSV file on multiple text/numeric fields using Python would be a problem that was already solved. But I can't find any example code anywhere, except for specific code focusing on sorting date fields.</p>
<p>How would one go about sorting a relatively large CSV file (tens of thousand lines) on mu... | 5 | 2010-01-18T20:38:35Z | 2,091,628 | <p>Here's the <code>convert()</code> that's missing from Robert's fix of Alex's answer:</p>
<pre><code>>>> def convert(convert_funcs, seq):
... return [
... item if func is None else func(item)
... for func, item in zip(convert_funcs, seq)
... ]
...
>>> convert(
... (None,... | 1 | 2010-01-19T06:46:48Z | [
"python",
"sorting",
"csv"
] |
Local installation of python | 2,089,054 | <p>I want to install python to my local direcotory:</p>
<pre><code>./configure --prefix=/home/alex/local-install && make && make install
</code></pre>
<p>When i import sqlite3 i get the following:</p>
<pre><code>ImportError: No module named _sqlite3
</code></pre>
<p>the reason: there is no _sqlite3.... | 1 | 2010-01-18T20:41:06Z | 2,089,093 | <p>You need to install the development headers and libraries for sqlite somewhere where the Python build can find them. You didn't say what OS you have. On Linux you usually have to install additional -dev[el] packages to be able to build against a library.</p>
| 3 | 2010-01-18T20:46:57Z | [
"python",
"sqlite3",
"makefile",
"install"
] |
How do I resolve a "Too many open files" error in Bazaar? | 2,089,353 | <p>I am using Bazaar v2.0.1 on Max OS X 10.6.2</p>
<p>When I perform a commit after moving a large number of files/directories (over 10,000) I get the following error message:</p>
<blockquote>
<p>bzr: ERROR: [Errno 24] open: Too many
open files: '.'</p>
</blockquote>
<p>My first work-around was to break the comm... | 0 | 2010-01-18T21:29:44Z | 2,089,374 | <p>You can use <a href="http://www.macosxhints.com/article.php?story=20040121001144687" rel="nofollow"><code>lsof</code></a> to see all open files. You might try grepping for the pid of the bazaar process, or monitoring the number of open files.</p>
<p>Note that you may or may not need to be root to see all files / p... | 3 | 2010-01-18T21:33:34Z | [
"python",
"bazaar"
] |
How do I resolve a "Too many open files" error in Bazaar? | 2,089,353 | <p>I am using Bazaar v2.0.1 on Max OS X 10.6.2</p>
<p>When I perform a commit after moving a large number of files/directories (over 10,000) I get the following error message:</p>
<blockquote>
<p>bzr: ERROR: [Errno 24] open: Too many
open files: '.'</p>
</blockquote>
<p>My first work-around was to break the comm... | 0 | 2010-01-18T21:29:44Z | 2,089,424 | <p>Try <code>ulimit -n 1024</code> (or more) before running bazaar, if your shell supports it (it's a bash builtin).</p>
<p>Jinx! edit: you can put it in your <code>~/.profile</code> if there is one, or <code>~/.bash_profile</code>.</p>
| 2 | 2010-01-18T21:42:30Z | [
"python",
"bazaar"
] |
attribute 'tzinfo' of 'datetime.datetime' objects is not writable | 2,089,419 | <p>How do I set the timezone of a datetime instance that just came out of the datastore?</p>
<p>When it first comes out it is in UTC. I want to change it to EST.</p>
<p>I'm trying, for example:</p>
<pre><code>class Book( db.Model ):
creationTime = db.DateTimeProperty()
</code></pre>
<p>When a Book is retrieved... | 19 | 2010-01-18T21:41:38Z | 2,089,474 | <p>What you want is right there in the <a href="http://docs.python.org/library/datetime.html#available-types" rel="nofollow">docs</a>.</p>
<pre><code>from datetime import tzinfo, timedelta, datetime
ZERO = timedelta(0)
HOUR = timedelta(hours=1)
DSTSTART = datetime(1, 4, 1, 2)
DSTEND = datetime(1, 10, 25, 1)
def firs... | 0 | 2010-01-18T21:49:19Z | [
"python",
"google-app-engine",
"datetime",
"tzinfo"
] |
attribute 'tzinfo' of 'datetime.datetime' objects is not writable | 2,089,419 | <p>How do I set the timezone of a datetime instance that just came out of the datastore?</p>
<p>When it first comes out it is in UTC. I want to change it to EST.</p>
<p>I'm trying, for example:</p>
<pre><code>class Book( db.Model ):
creationTime = db.DateTimeProperty()
</code></pre>
<p>When a Book is retrieved... | 19 | 2010-01-18T21:41:38Z | 2,089,484 | <p>If you're receiving a datetime that's <em>in</em> EST, but doesn't have its tzinfo field set, use <code>dt.replace(tzinfo=tz)</code> to assign a tzinfo without modifying the time. (Your database should be doing this for you.)</p>
<p>If you're receiving a datetime that's in UDT, and you want it in EST, then you nee... | 5 | 2010-01-18T21:50:33Z | [
"python",
"google-app-engine",
"datetime",
"tzinfo"
] |
attribute 'tzinfo' of 'datetime.datetime' objects is not writable | 2,089,419 | <p>How do I set the timezone of a datetime instance that just came out of the datastore?</p>
<p>When it first comes out it is in UTC. I want to change it to EST.</p>
<p>I'm trying, for example:</p>
<pre><code>class Book( db.Model ):
creationTime = db.DateTimeProperty()
</code></pre>
<p>When a Book is retrieved... | 19 | 2010-01-18T21:41:38Z | 2,089,496 | <p><code>datetime</code>'s objects are immutable, so you never change any of their attributes -- you make a <strong>new</strong> object with some attributes the same, and some different, and assign it to whatever you need to assign it to.</p>
<p>I.e., in your case, instead of</p>
<pre><code>book.creationTime.tzinfo =... | 32 | 2010-01-18T21:52:01Z | [
"python",
"google-app-engine",
"datetime",
"tzinfo"
] |
How to send a string from a python script at Google App Engine to the browser client as a file | 2,089,635 | <p>I have a python web-application running inside the Google App Engine.</p>
<p>The application creates on user-demand a string and I want the string to be send to the browser client (application/octet-stream?) as a file.</p>
<p>How can i realize this?</p>
| 1 | 2010-01-18T22:18:42Z | 2,089,653 | <p>Setting a <code>content-disposition: attachment</code> header will cause most browsers to download whatever you send them as a file. Safari sometimes ignores it.</p>
| 0 | 2010-01-18T22:22:12Z | [
"python",
"html",
"google-app-engine",
"mime-types"
] |
How to send a string from a python script at Google App Engine to the browser client as a file | 2,089,635 | <p>I have a python web-application running inside the Google App Engine.</p>
<p>The application creates on user-demand a string and I want the string to be send to the browser client (application/octet-stream?) as a file.</p>
<p>How can i realize this?</p>
| 1 | 2010-01-18T22:18:42Z | 2,090,057 | <p>If you're using App Engine's own, simple <a href="http://code.google.com/appengine/docs/python/tools/webapp/" rel="nofollow">webapp</a> framework, the simplest approach is to have as the <code>get</code> method of your request handler object something like:</p>
<pre><code>def get(self):
thestring = 'helloworld' ... | 3 | 2010-01-18T23:50:26Z | [
"python",
"html",
"google-app-engine",
"mime-types"
] |
SQLAlchemy Column to Row Transformation and vice versa -- is it possible? | 2,089,661 | <p>I'm looking for a SQLAlchemy only solution for converting a dict received from a form submission into a series of rows in the database, one for each field submitted. This is to handle preferences and settings that vary widely across applications. But, it's very likely applicable to creating pivot table like functi... | 4 | 2010-01-18T22:24:05Z | 2,093,103 | <p>Here is a slightly modified example from <a href="http://www.sqlalchemy.org/docs/reference/ext/associationproxy.html#building-complex-views">documentation</a> to work with such table structure mapped to dictionary in model:</p>
<pre><code>from sqlalchemy import *
from sqlalchemy.ext.declarative import declarative_b... | 8 | 2010-01-19T11:35:26Z | [
"python",
"orm",
"sqlalchemy",
"pivot-table",
"transformation"
] |
Server Setup for iPhone Push Notifications | 2,089,701 | <p>I'm new to the whole push notifications thing, and was wondering if somebody could walk me through the process of getting a simple application up and running. I currently rent a server that I use to serve my website that runs cPanel X. </p>
<p>How would I go about setting up the service? What software do I need to ... | 3 | 2010-01-18T22:33:07Z | 2,089,847 | <p>I would go to the <a href="http://devforums.apple.com" rel="nofollow">Apple Developer Forums</a>. They have many questions and answers regarding this. For my apps, I use a Ruby On Rails plugin called <a href="http://github.com/markbates/apn_on_rails" rel="nofollow">apn_on_rails</a>, but this is probably not an opt... | 3 | 2010-01-18T23:00:02Z | [
"iphone",
"python",
"ruby-on-rails",
"push-notification"
] |
Printing correct time using timezones, Python | 2,089,706 | <p><a href="http://stackoverflow.com/questions/2089419/attribute-tzinfo-of-datetime-datetime-objects-is-not-writable">Extends</a></p>
<p>Ok, we are not having a good day today.</p>
<p>When you attach the correct tzinfo object to a datetime instance, and then you strftime() it, it STILL comes out in UTC, seemingly ign... | 9 | 2010-01-18T22:34:12Z | 2,089,793 | <p>With <code>dt.replace(tzinfo=tz)</code> you're not really converting the time value, you're just saying 'hey no, wait, this time was actually in PDT, not in UTC'. You'll probably want to use <code>datetime.astimezone(tz)</code> instead.</p>
| 5 | 2010-01-18T22:50:05Z | [
"python",
"datetime",
"tzinfo"
] |
Printing correct time using timezones, Python | 2,089,706 | <p><a href="http://stackoverflow.com/questions/2089419/attribute-tzinfo-of-datetime-datetime-objects-is-not-writable">Extends</a></p>
<p>Ok, we are not having a good day today.</p>
<p>When you attach the correct tzinfo object to a datetime instance, and then you strftime() it, it STILL comes out in UTC, seemingly ign... | 9 | 2010-01-18T22:34:12Z | 2,089,869 | <p>I think <a href="http://stackoverflow.com/questions/2089706/printing-correct-time-using-timezones-python/2089793#2089793">Wim had the right idea</a>, just backwards. If you want to know what your time would be in UTC, use:</p>
<pre><code>print pst.astimezone(UTC).strftime( "%a %b %d %X" )
</code></pre>
<p>You'll h... | 2 | 2010-01-18T23:05:34Z | [
"python",
"datetime",
"tzinfo"
] |
Printing correct time using timezones, Python | 2,089,706 | <p><a href="http://stackoverflow.com/questions/2089419/attribute-tzinfo-of-datetime-datetime-objects-is-not-writable">Extends</a></p>
<p>Ok, we are not having a good day today.</p>
<p>When you attach the correct tzinfo object to a datetime instance, and then you strftime() it, it STILL comes out in UTC, seemingly ign... | 9 | 2010-01-18T22:34:12Z | 2,090,122 | <p><code>.replace</code> does no computation: it simply <strong>replaces</strong> one or more field in the new returned object, while copying all others from the object it's called on.</p>
<p>If I understand your situation correctly, you start with a datetime object which you <em>know</em> (through other means) is UTC... | 13 | 2010-01-19T00:04:56Z | [
"python",
"datetime",
"tzinfo"
] |
Google app engine after refresh from datastore | 2,089,746 | <p>I want to set the .tzinfo of every <code>datetime</code> instance <em>automatically</em> as soon as it comes out of the datastore.</p>
<p>So if I have</p>
<pre><code>class Message( db.Model ):
creationTime = db.DateTimeProperty()
someOtherTime = db.DateTimeProperty()
## I really want to define a metho... | 1 | 2010-01-18T22:44:23Z | 2,090,027 | <p>IMHO, this is not the best way to handle timezones in GAE. From the <a href="http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#datetime" rel="nofollow">docs</a>:</p>
<blockquote>
<p>If the datetime value has a tzinfo attribute, it will be converted to the UTC time zone for storag... | 1 | 2010-01-18T23:41:16Z | [
"python",
"google-app-engine"
] |
Google app engine after refresh from datastore | 2,089,746 | <p>I want to set the .tzinfo of every <code>datetime</code> instance <em>automatically</em> as soon as it comes out of the datastore.</p>
<p>So if I have</p>
<pre><code>class Message( db.Model ):
creationTime = db.DateTimeProperty()
someOtherTime = db.DateTimeProperty()
## I really want to define a metho... | 1 | 2010-01-18T22:44:23Z | 2,090,163 | <p>I think the best approach is for you to <em>subclass</em> the <a href="http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html#DateTimeProperty" rel="nofollow">DateTimeProperty</a> class and override its method <a href="http://code.google.com/appengine/docs/python/datastore/propertyclass.... | 2 | 2010-01-19T00:14:58Z | [
"python",
"google-app-engine"
] |
Rotate a quad around a centre point in OpenGL | 2,089,849 | <p>I'm making a 2D game. I want to be able to render a texture on the screen after rotating it a certain amount around a centre point. Basically this is for a level rotation around a player. The player position being the rotation point and the direction of the player as the angle. This code wont work:</p>
<pre><code>d... | 3 | 2010-01-18T23:00:12Z | 2,089,889 | <p>try reversing</p>
<pre><code>glTranslatef(point[0],point[1],0)
</code></pre>
<p>and</p>
<pre><code>glRotatef(rotation,0,0,1)
</code></pre>
<p>you're translating to the player, but then rotating about the origin (not the player)</p>
<p>Illustration from the <a href="http://www.glprogramming.com/red/chapter03.htm... | 2 | 2010-01-18T23:09:58Z | [
"python",
"opengl",
"rotation",
"textures",
"primitive"
] |
Rotate a quad around a centre point in OpenGL | 2,089,849 | <p>I'm making a 2D game. I want to be able to render a texture on the screen after rotating it a certain amount around a centre point. Basically this is for a level rotation around a player. The player position being the rotation point and the direction of the player as the angle. This code wont work:</p>
<pre><code>d... | 3 | 2010-01-18T23:00:12Z | 2,089,901 | <p>Unless you have a good reason to do otherwise, I'd leave the drawing code alone, and just change the camera angle. Probably the easiest way to do that is use gluLookAt. In your case, you'll apparently be looking at the player's position, and just change the "up direction", which is given in the last two parameters.<... | 0 | 2010-01-18T23:11:57Z | [
"python",
"opengl",
"rotation",
"textures",
"primitive"
] |
Finding checked QRadioButton among many into a QVBoxLayout | 2,089,897 | <p>I used the code below to dynamically create a group of radio buttons:</p>
<pre><code>self.wPaymantType.qgbSomeSelectionGroup = QtGui.QGroupBox()
vbox = QtGui.QVBoxLayout()
for row in listOfChoices:
radio = QtGui.QRadioButton(row)
if bIsFirst:
radio.setChecked(True)
bIsFirst = False
if l... | 2 | 2010-01-18T23:11:12Z | 2,090,272 | <p>Your code is not minimal and self-contained, so it's really hard to help you -- but I've anyway gone through the effort of building a near-minimal self-contained approximation of what you're trying to do and which does seem to work correctly -- here comes...:</p>
<pre><code>from PyQt4 import QtGui
import sys
clas... | 2 | 2010-01-19T00:37:40Z | [
"python",
"qt",
"pyqt4"
] |
Finding checked QRadioButton among many into a QVBoxLayout | 2,089,897 | <p>I used the code below to dynamically create a group of radio buttons:</p>
<pre><code>self.wPaymantType.qgbSomeSelectionGroup = QtGui.QGroupBox()
vbox = QtGui.QVBoxLayout()
for row in listOfChoices:
radio = QtGui.QRadioButton(row)
if bIsFirst:
radio.setChecked(True)
bIsFirst = False
if l... | 2 | 2010-01-18T23:11:12Z | 2,090,441 | <p>I believe the reason why it's not working is your</p>
<pre><code> radio = QtGui.QRadioButton(child.widget())
</code></pre>
<p>call at the code where you're checking if your checkbox is checked. I think what you're trying to do is typecast the child object to QtGui.QRadioButton and it doesn't work in this case. Ins... | 1 | 2010-01-19T01:19:36Z | [
"python",
"qt",
"pyqt4"
] |
Finding checked QRadioButton among many into a QVBoxLayout | 2,089,897 | <p>I used the code below to dynamically create a group of radio buttons:</p>
<pre><code>self.wPaymantType.qgbSomeSelectionGroup = QtGui.QGroupBox()
vbox = QtGui.QVBoxLayout()
for row in listOfChoices:
radio = QtGui.QRadioButton(row)
if bIsFirst:
radio.setChecked(True)
bIsFirst = False
if l... | 2 | 2010-01-18T23:11:12Z | 11,068,028 | <p>I guess a better way to identify which button is checked is to use a <a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qbuttongroup.html" rel="nofollow"><strong>QButtonGroup</strong></a>, as it provides a container to organize groups of button widgets. It is not a visual object, so it doesn't subst... | 0 | 2012-06-17T00:27:53Z | [
"python",
"qt",
"pyqt4"
] |
How to format search autocompletion part lists? | 2,089,917 | <p>I'm currently working on an AppEngine project, and I'd like to implement autocompletion of search terms. The <em>items</em> that can be searched for are reasonably unambiguous and short, so I was thinking of implementing it by giving each <em>item</em> a list of incomplete typings. So <code>foobar</code> would get a... | 0 | 2010-01-18T23:15:58Z | 2,089,981 | <p>I have already run into the same problem and the solution that I adopted was very similar to your idea. I split the items into words, convert them to lowercase, remove accents, and create a list of startings. For instance, <code>"Báz Bar"</code> would become <code>['b', 'ba', 'bar', 'baz']</code>. </p>
<p>I have p... | 2 | 2010-01-18T23:27:49Z | [
"python",
"google-app-engine",
"search",
"autocomplete",
"autosuggest"
] |
How can I process xml asynchronously in python? | 2,090,096 | <p>I have a large XML data file (>160M) to process, and it seems like SAX/expat/pulldom parsing is the way to go. I'd like to have a thread that sifts through the nodes and pushes nodes to be processed onto a queue, and then other worker threads pull the next available node off the queue and process it.</p>
<p>I have ... | 6 | 2010-01-18T23:59:58Z | 2,090,252 | <p>The only thing I see is wrong is that you are accessing <code>q</code> simultaneously from different threads - no locking as you write indeed. That is asking for trouble - and you're probably getting trouble in the form of the Python interpreter locking up on you. :)</p>
<p>Try locking, it's really not very difficu... | 1 | 2010-01-19T00:31:35Z | [
"python",
"xml",
"multithreading",
"sax"
] |
How can I process xml asynchronously in python? | 2,090,096 | <p>I have a large XML data file (>160M) to process, and it seems like SAX/expat/pulldom parsing is the way to go. I'd like to have a thread that sifts through the nodes and pushes nodes to be processed onto a queue, and then other worker threads pull the next available node off the queue and process it.</p>
<p>I have ... | 6 | 2010-01-18T23:59:58Z | 2,090,259 | <p>I'm not too sure about this problem. I'm guessing the call to ParseFile is blocking and only the parsing thread is being run because of the GIL. A way around this would be to use <a href="http://docs.python.org/library/multiprocessing.html"><code>multiprocessing</code></a> instead. It's designed to work with queues,... | 7 | 2010-01-19T00:35:06Z | [
"python",
"xml",
"multithreading",
"sax"
] |
How can I process xml asynchronously in python? | 2,090,096 | <p>I have a large XML data file (>160M) to process, and it seems like SAX/expat/pulldom parsing is the way to go. I'd like to have a thread that sifts through the nodes and pushes nodes to be processed onto a queue, and then other worker threads pull the next available node off the queue and process it.</p>
<p>I have ... | 6 | 2010-01-18T23:59:58Z | 2,090,271 | <p>I do not know a whole lot about the implementation, but if the parse is C code that executes until complete, other Python threads will not run. If the parser is calling back out to Python code, the GIL may be released for other threads to run, but I am not sure about that. You might want to check those details.</p>
| 0 | 2010-01-19T00:37:38Z | [
"python",
"xml",
"multithreading",
"sax"
] |
How can I process xml asynchronously in python? | 2,090,096 | <p>I have a large XML data file (>160M) to process, and it seems like SAX/expat/pulldom parsing is the way to go. I'd like to have a thread that sifts through the nodes and pushes nodes to be processed onto a queue, and then other worker threads pull the next available node off the queue and process it.</p>
<p>I have ... | 6 | 2010-01-18T23:59:58Z | 2,090,329 | <p><a href="http://docs.python.org/library/pyexpat.html?highlight=parsefile#xml.parsers.expat.xmlparser.ParseFile"><code>ParseFile</code></a>, as you've noticed, just "gulps down" everything -- no good for the <em>incremental</em> parsing you want to do! So, just feed the file to the parser a bit at a time, making sur... | 7 | 2010-01-19T00:51:53Z | [
"python",
"xml",
"multithreading",
"sax"
] |
python search replace using wildcards | 2,090,100 | <p>somewhat confused.. but trying to do a search/repace using wildcards</p>
<p>if i have something like:</p>
<pre><code> <blah.... ssf ff>
<bl.... ssf dfggg ff>
<b.... ssf ghhjj fhf>
</code></pre>
<p>and i want to replace all of the above strings with say, </p>
<pre><code> <hh &g... | 2 | 2010-01-19T00:00:22Z | 2,090,120 | <p>See the rather usable Python <a href="http://en.wikipedia.org/wiki/Regular_expression" rel="nofollow">Regular Expression</a> manual <a href="http://docs.python.org/library/re.html" rel="nofollow">here</a>, or for a more hands-on approach a <a href="http://www.amk.ca/python/howto/regex/" rel="nofollow">Regular Expres... | 2 | 2010-01-19T00:04:52Z | [
"python",
"regex",
"search",
"replace",
"wildcard"
] |
python search replace using wildcards | 2,090,100 | <p>somewhat confused.. but trying to do a search/repace using wildcards</p>
<p>if i have something like:</p>
<pre><code> <blah.... ssf ff>
<bl.... ssf dfggg ff>
<b.... ssf ghhjj fhf>
</code></pre>
<p>and i want to replace all of the above strings with say, </p>
<pre><code> <hh &g... | 2 | 2010-01-19T00:00:22Z | 2,090,189 | <p>don't have to use regex</p>
<pre><code>for line in open("file"):
if "<" in line and ">" in line:
s=line.rstrip().split(">")
for n,i in enumerate(s):
if "<" in i:
ind=i.find("<")
s[n]=i[:ind] +"<hh "
print '>t'.join(s)
</cod... | 0 | 2010-01-19T00:19:51Z | [
"python",
"regex",
"search",
"replace",
"wildcard"
] |
python search replace using wildcards | 2,090,100 | <p>somewhat confused.. but trying to do a search/repace using wildcards</p>
<p>if i have something like:</p>
<pre><code> <blah.... ssf ff>
<bl.... ssf dfggg ff>
<b.... ssf ghhjj fhf>
</code></pre>
<p>and i want to replace all of the above strings with say, </p>
<pre><code> <hh &g... | 2 | 2010-01-19T00:00:22Z | 2,090,316 | <p>Sounds like a job for the "re" module, here's a little sample function for you although you could just use the one re.sub() line.</p>
<p>Use the "re" module, a simple re.sub should do the trick:</p>
<pre><code>import re
def subit(msg):
# Use the below if the string is multiline
# subbed = re.compile("(<... | 0 | 2010-01-19T00:48:59Z | [
"python",
"regex",
"search",
"replace",
"wildcard"
] |
python search replace using wildcards | 2,090,100 | <p>somewhat confused.. but trying to do a search/repace using wildcards</p>
<p>if i have something like:</p>
<pre><code> <blah.... ssf ff>
<bl.... ssf dfggg ff>
<b.... ssf ghhjj fhf>
</code></pre>
<p>and i want to replace all of the above strings with say, </p>
<pre><code> <hh &g... | 2 | 2010-01-19T00:00:22Z | 2,090,331 | <p>How about like this, with regex</p>
<pre><code>import re
YOURTEXT=re.sub("<b[^>]*>","<hh >t",YOURTEXT)
</code></pre>
| 1 | 2010-01-19T00:53:11Z | [
"python",
"regex",
"search",
"replace",
"wildcard"
] |
Weird pynotify behaviour in Ubuntu 9.10 | 2,090,273 | <p>I wrote a <a href="http://github.com/flavioamieiro/dojotools/" rel="nofollow">small app</a> and I am using pynotify to show some messages to the user.</p>
<p>It all works fine here in arch, but when I tested it in Ubuntu, the behaviour was very weird.</p>
<p>Because of the way Ubuntu shows notifications (as what s... | 2 | 2010-01-19T00:37:45Z | 2,091,364 | <p>Yes, Ubuntu 9.10 replaced upstream's <a href="http://www.galago-project.org/" rel="nofollow">notification-daemon</a> with their own <a href="https://launchpad.net/notify-osd" rel="nofollow">notify-osd</a>, and generally made a mess of things.</p>
<p>You can ensure notification-daemon is installed (via whatever your... | 3 | 2010-01-19T05:41:58Z | [
"python",
"linux",
"ubuntu",
"ubuntu-9.10",
"pynotify"
] |
How to swap adjacent bytes in a string of hex bytes (with or without regular expressions) | 2,090,303 | <p>Given the string (or any length string with an even-number of word pairs):
"12345678"</p>
<p>How would I swap adjacent "words"?</p>
<p>The result I want is
"34127856"</p>
<p>As well as, when that's done I need to swap the longs.
The result I want is:
"78563412"</p>
| 1 | 2010-01-19T00:45:47Z | 2,090,320 | <pre><code>import re
re.sub(r'(..)(..)', r'\2\1', '12345678')
re.sub(r'(....)(....)', r'\2\1', '34127856')
</code></pre>
| 2 | 2010-01-19T00:49:38Z | [
"python",
"regex",
"string",
"hex"
] |
How to swap adjacent bytes in a string of hex bytes (with or without regular expressions) | 2,090,303 | <p>Given the string (or any length string with an even-number of word pairs):
"12345678"</p>
<p>How would I swap adjacent "words"?</p>
<p>The result I want is
"34127856"</p>
<p>As well as, when that's done I need to swap the longs.
The result I want is:
"78563412"</p>
| 1 | 2010-01-19T00:45:47Z | 2,090,341 | <p>A regex approach:</p>
<pre><code>import re
twopairs = re.compile(r'(..)(..)')
stringwithswappedwords = twopairs.sub(r'\2\1', basestring)
twoquads = re.compile(r'(....)(....)')
stringwithswappedlongs = twoquads.sub(r'\2\1', stringwithswappedwords)
</code></pre>
<p><strong>Edit</strong>:
However, this is definitely ... | 3 | 2010-01-19T00:55:48Z | [
"python",
"regex",
"string",
"hex"
] |
How to swap adjacent bytes in a string of hex bytes (with or without regular expressions) | 2,090,303 | <p>Given the string (or any length string with an even-number of word pairs):
"12345678"</p>
<p>How would I swap adjacent "words"?</p>
<p>The result I want is
"34127856"</p>
<p>As well as, when that's done I need to swap the longs.
The result I want is:
"78563412"</p>
| 1 | 2010-01-19T00:45:47Z | 2,090,343 | <pre><code>>>> import re
>>> re.sub("(..)(..)","\\2\\1","12345678")
'34127856'
>>> re.sub("(....)(....)","\\2\\1","34127856")
'78563412'
</code></pre>
| 0 | 2010-01-19T00:56:07Z | [
"python",
"regex",
"string",
"hex"
] |
How to swap adjacent bytes in a string of hex bytes (with or without regular expressions) | 2,090,303 | <p>Given the string (or any length string with an even-number of word pairs):
"12345678"</p>
<p>How would I swap adjacent "words"?</p>
<p>The result I want is
"34127856"</p>
<p>As well as, when that's done I need to swap the longs.
The result I want is:
"78563412"</p>
| 1 | 2010-01-19T00:45:47Z | 2,090,357 | <p>If you want to do <strong>endianness conversion</strong>, use Python's <a href="http://docs.python.org/library/struct.html" rel="nofollow">struct module</a> on the original binary data.</p>
<p>If that is not your goal, here's a simple sample code to rearrange one 8 character string:</p>
<pre><code>def wordpairswap... | 0 | 2010-01-19T00:58:14Z | [
"python",
"regex",
"string",
"hex"
] |
How to swap adjacent bytes in a string of hex bytes (with or without regular expressions) | 2,090,303 | <p>Given the string (or any length string with an even-number of word pairs):
"12345678"</p>
<p>How would I swap adjacent "words"?</p>
<p>The result I want is
"34127856"</p>
<p>As well as, when that's done I need to swap the longs.
The result I want is:
"78563412"</p>
| 1 | 2010-01-19T00:45:47Z | 2,090,361 | <p>just for the string "12345678"</p>
<pre><code>from textwrap import wrap
s="12345678"
t=wrap(s,len(s)/2)
a,b=wrap(t[0],len(t[0])/2)
c,d=wrap(t[1],len(t[1])/2)
a,b=b,a
c,d=d,c
print a+b+c+d
</code></pre>
<p>you can make it to a generic function to do variable length string.</p>
<p>output</p>
<pre><code>$ ./python.... | 1 | 2010-01-19T00:59:04Z | [
"python",
"regex",
"string",
"hex"
] |
How to swap adjacent bytes in a string of hex bytes (with or without regular expressions) | 2,090,303 | <p>Given the string (or any length string with an even-number of word pairs):
"12345678"</p>
<p>How would I swap adjacent "words"?</p>
<p>The result I want is
"34127856"</p>
<p>As well as, when that's done I need to swap the longs.
The result I want is:
"78563412"</p>
| 1 | 2010-01-19T00:45:47Z | 12,640,366 | <p>I'm using the following approach:</p>
<pre><code>data = "deadbeef"
if len(data) == 4: #2 bytes, 4 characters
value = socket.ntohs(int(data, 16))
elif len(data) >= 8:
value = socket.ntohl(int(data, 16))
else:
value = int(data, 16)
</code></pre>
<p>works for me!</p>
| 0 | 2012-09-28T12:50:12Z | [
"python",
"regex",
"string",
"hex"
] |
Symbolic Group Names (like in Python) in Ruby Regular Expression | 2,090,424 | <p>Came across this handy regular expression utility in Python (I am a beginner in Python). e.g. By using the regexp </p>
<pre><code>(?P<id>[a-zA-Z_]\w*)
</code></pre>
<p>I can refer to the matched data as </p>
<pre><code>m.group('id')
</code></pre>
<p>(Full documentation: look for "symbolic group name" <a hr... | 7 | 2010-01-19T01:14:54Z | 2,090,471 | <p>Older Ruby releases didn't have named groups (tx Alan for pointing this out in a comment!), but, if you're using Ruby 1.9...:</p>
<p><code>(?<name>subexp)</code> expresses a named group in Ruby expressions too; <code>\k<name></code> is the way you back-reference a named group in substitution, if that's ... | 11 | 2010-01-19T01:27:26Z | [
"python",
"ruby",
"regex"
] |
Symbolic Group Names (like in Python) in Ruby Regular Expression | 2,090,424 | <p>Came across this handy regular expression utility in Python (I am a beginner in Python). e.g. By using the regexp </p>
<pre><code>(?P<id>[a-zA-Z_]\w*)
</code></pre>
<p>I can refer to the matched data as </p>
<pre><code>m.group('id')
</code></pre>
<p>(Full documentation: look for "symbolic group name" <a hr... | 7 | 2010-01-19T01:14:54Z | 2,090,811 | <p>Ruby 1.9 introduced named captures:</p>
<pre><code>m = /(?<prefix>[A-Z]+)(?<hyphen>-?)(?<digits>\d+)/.match("THX1138.")
m.names # => ["prefix", "hyphen", "digits"]
m.captures # => ["THX", "", "1138"]
m[:prefix] # => "THX"
</code></pre>
<p>You can use <code>\k<prefix></code>, etc, f... | 10 | 2010-01-19T03:14:16Z | [
"python",
"ruby",
"regex"
] |
Python Window Activation | 2,090,464 | <p>How would I programmatically activate a window in Windows using Python? I'm sending keystrokes to it and at the moment I'm just making sure it's the last application used then sending the keystroke Alt+Tab to switch over to it from the DOS console. Is there a better way (since I've learned by experience that this wa... | 8 | 2010-01-19T01:25:50Z | 2,091,530 | <p>You can use the win32gui module to do that. First you need to get a valid handle on your window. You can use the <code>win32gui.FindWindow</code> if you know the window class name or the exact title. If not, you can enumerate the windows with the <code>win32gui.EnumWindows</code> and try to find the right one.</p>
... | 18 | 2010-01-19T06:21:50Z | [
"python",
"windows"
] |
Python Window Activation | 2,090,464 | <p>How would I programmatically activate a window in Windows using Python? I'm sending keystrokes to it and at the moment I'm just making sure it's the last application used then sending the keystroke Alt+Tab to switch over to it from the DOS console. Is there a better way (since I've learned by experience that this wa... | 8 | 2010-01-19T01:25:50Z | 23,714,794 | <p><a href="https://code.google.com/p/pywinauto/" rel="nofollow">Pywinauto</a> and <a href="https://code.google.com/p/swapy/" rel="nofollow">SWAPY</a> will probably require the least effort <a href="http://pywinauto.blogspot.com/2006/03/setting-foreground-window.html" rel="nofollow">to set the focus of a window</a>.</p... | 3 | 2014-05-17T18:34:36Z | [
"python",
"windows"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.