I am reading the book Think Python by Allen Downey. For chapter 4, one has to use a suite of modules called Swampy. I have downloaded and installed it.
The problem is that the modules were written in Python 2 and I have Python 3 (in Windows 7 RC1). When I ran the TurtleWorld module from Swampy, I got error messages about the print and e...
Hi!
I'm working on a simple crawler in Python. The aim is to create a sitemap.xml.
(you can find the very alpha version here: http://code.google.com/p/sitemappy/)
I noticed that if I generate the xml with URLs containing non HTML entities (such as &), the xml doesn't validate and it isn't accepted by Google Webmaster Tools.
Is there a qu...
My function is
def validate_latitude(lat):
"""Enforce latitude is in range
>>> validate_latitude(65)
65
>>> validate_latitude(91)
90
>>> validate_latitude(-91)
-90
"""
lat = min(lat, 90)
lat = max(lat, -90)
return lat
And the test fails with this output
********************************...
How to parse the string " {'result':(Boolean, MessageString)} " using Python regular expressions to get Boolean and the MessageString separated into variables?
...
I have a Python program (with Django - does this matter?) that I want to 'bundle', if you like. How do I do this, in the same way one can create a .jar for Java?
...
I'm aware of using globals(), locals() and getattr to referance things in Python by string (as in this question) but unless I'm missing something obvious I can't seem to use this with calling types.
e.g.:
In [12]: locals()['int']
---------------------------------------------------------------------------
KeyError ...
I want to do some image processing with OpenCV (in Python), but I have to start with a PIL Image object, so I can't use the cvLoadImage() call, since that takes a filename.
This recipe (adapted from http://opencv.willowgarage.com/wiki/PythonInterface) does not work because cvSetData complains argument 2 of type 'void *' . Any ideas?
...
In reading "High performance MySQL" from O'Reilly I've stumbled upon the following
Another common garbage query is SET
NAMES UTF8, which is the wrong way to
do things anyway (it does not change
the client library's character set; it
affects only the server).
I'm a bit confused, because I used to put "SET NAMES utf8" on the ...
When checking an object's identity, I am getting assertion errors because the object creation code imports the object-defining module under one notation (base.other_stuff.BarCode) and the identity-checking code imports that same module under a different notation (other_stuff.BarCode). (Please see below for gory details.)
It seems that ...
I'm starting up game programming again. 10 years ago I was making games in qbasic and I havn't done any game programming since, so I am quite rusty. I have been programming all the time though, I am web developer/DBA/admin now. I have several questions, but I'm going to limit it to one per post.
The game I am working on is going to be l...
Can I get the parameters of the last function called in traceback? How?
I want to make a catcher for standard errors to make readable code, yet provide detailed information to user.
In the following example I want GET_PARAMS to return me a tuple of parameters supplied to os.chown. Examining the inspect module advised by Alex Martelli, ...
I have a database which I regularly need to import large amounts of data into via some python scripts. Compacted, the data for a single months imports takes about 280mb, but during the import file size swells to over a gb.
Given the 2gb size limit on mdb files, this is a bit of a concern. Apart from breaking the inserts into chunks and ...
I wish to learn Python but I'm working all day in .Net as a C# developer, so I decided to download and install IronPython and integrated IronPython studio. How different or similar from the original Python it is? As a .Net developer can I expect to run conventional Python script in .Net environment with no problem or this is just the sam...
It seems that Python standard library lacks various useful concurrency-related concepts such as atomic counter, executor and others that can be found in e.g. java.util.concurrent. Are there any external libraries that would provide easier building blocks for concurrent Python applications?
...
I had a very difficult time with understanding the root cause of a problem in an algorithm. Then, by simplifying the functions step by step I found out that evaluation of default arguments in Python doesn't behave as I expected.
The code is as follows:
class Node(object):
def __init__(self, children = []):
self.children = c...
Let's say I have an array or list of words, something like this:
[The,Quick,Brown,Fox,Jumps,Over,The,Lazy,Dog]
I'd like to generate an array of arrays, with each array containing 3 of the words, but with a possible triplet for each one. so it should look something like this:
[The,Quick,Brown]
[Quick,Brown,Fox]
[Brown,Fox,Jumps]
and...
I am new to Python. The following code is causing an error when it attempts to append values to an array. What am I doing wrong?
import re
from array import array
freq_pattern = re.compile("Frequency of Incident[\(\)A-Za-z\s]*\.*\s*([\.0-9]*)")
col_pattern = re.compile("([-\.0-9]+)\s+([-\.0-9]+)\s+([-\.0-9]+)\s+([-\.0-9]+)\s+([-\.0-9...
What would be the best way in python to parse out chunks of text contained in matching brackets?
"{ { a } { b } { { { c } } } }"
should initially return:
[ "{ a } { b } { { { c } } }" ]
putting that as an input should return:
[ "a", "b", "{ { c } }" ]
which should return:
[ "{ c }" ]
[ "c" ]
[]
...
I need to access a webpage using
twisted.web.client.getPage()
or a similar method to download a webpage from a known address (ie:www.google.com), the problem is: I am behind a proxy server and I couldn't find anywhere explanations on how to configure twisted or factories to use my proxy, any ideas?
Bear in mind I have to specify user...
I cant seem to grasp the proper concepts of a factory.
Can anyone help me code a simple test? I read some texts over the internet and cant code it the same way. Actually i cant understand the process. Copying code is easy, but i need to learn why this wont work.
class Factory:
def __init__(self):
self.msg = "teste"
de...