I'm trying to convert the data from a simple object graph into a dictionary. I don't need type information or methods and I don't need to be able to convert it back to an object again.
I found this question about creating a dictionary from an object's fields, but it doesn't do it recursively.
Being relatively new to python, I'm concer...
Hey guys, I have a problem of upgrading python from 2.4 to 2.6:
I have CentOS 5 (Full)
It has python 2.4 living in /usr/lib/python2.4/
Additional modules are living in /usr/lib/python2.4/site-packages/
I've built python 2.6 from sources at /usr/local/lib/python2.6/
I've set default python to python2.6
Now old modules for 2.4 are out...
Being relatively new to Python 2, I'm uncertain how best to organise my class files in the most 'pythonic' way. I wouldn't be asking this but for the fact that Python seems to have quite a few ways of doing things that are very different to what I have come to expect from the languages I am used to.
Initially, I was just treating classe...
import xml.parsers.expat
def start_element(name, attrs):
print('Start element:', name, attrs)
def end_element(name):
print('End element:', name)
def character_data(data):
print('Character data: %s' % data)
parser = xml.parsers.expat.ParserCreate()
parser.StartElementHandler = start_element
parser.EndElementHandler = end_e...
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\ctypes\__init__.py", line 17, in <module>
from struct import ca...
My stuff is developed and running on Python 2.5.2
I want to move some code to 3.x, but that isn't feasible because so many of the external packages I use are not there yet. (Like numpy for instance).
So, I'll do the intermediate step and go to 2.6.2.
My question: If an external module runs on 2.5.2, but doesn't explicitly state th...
I can't make py2exe to pack correctly even a simple script that uses win32file
I'm constantly getting the following error message:
Traceback (most recent call last):
File "dependency_checker.py", line 1, in <module>
File "win32file.pyc", line 12, in <module>
File "win32file.pyc", line 10, in __load
ImportError: DLL load failed: Th...
Does anyone have a simple example using ast.NodeVisitor to walk the abstract syntax tree in Python 2.6? The difference between visit and generic_visit is unclear to me, and I cannot find any example using google codesearch or plain google.
...
I'm using the Python C API on Windows using Visual Studio 2008. When I attempt to use the PyDate_Check macro, and other related macros, they cause an access violation because the static variable PyDateTimeAPI is null. This variable is initialized using the PyDateTime_IMPORT macro which needs calling before using any date time macros. I d...
What I am trying to achieve is something like this:
class object:
def __init__(self):
WidthVariable(self)
print self.width
#Imagine I did this 60frames/1second later
print self.width
#output:
>>0
>>25
What I want happening (as above): When WidthVariable - a class - is created it adds the variable ...
The following sample code:
import token, tokenize, StringIO
def generate_tokens(src):
rawstr = StringIO.StringIO(unicode(src))
tokens = tokenize.generate_tokens(rawstr.readline)
for i, item in enumerate(tokens):
toktype, toktext, (srow,scol), (erow,ecol), line = item
print i, token.tok_name[toktype], toktext...
Hi, I'm trying to pass big strings of random html through regular expressions and my Python 2.6 script is choking on this:
UnicodeEncodeError: 'ascii' codec can't encode character
I traced it back to a trademark superscript on the end of this word: Protection™ -- and I expect to encounter others like it in the future.
Is there a modu...
Hi, I'm trying to pass big strings of random html through regular expressions and my Python 2.6 script is choking on this:
UnicodeEncodeError: 'ascii' codec can't encode character
I traced it back to a trademark superscript on the end of this word: Protection™ -- I do not need to capture the non-ascii stuff, but it is a nuisance and I...
I have a Django app written in Python 2.5 and I plan to upgrade it to be compatible with Python 2.6. It contains hundreds of .py files. Is there a simple way to find all deprecated functions in those files?
...
I am writing a script that will try encoding bytes into many different encodings in python 2.6. This page http://www.python.org/doc/2.6/library/codecs.html?highlight=cp1250#id3 lists all the encodings that python can encode to. Rather than copy & paste that, is there some way to get a list of available encodings that I can iterate over?
...
I've heard that list comprehensions can be slow sometimes, but I'm not sure why? I'm new to Python (coming from a C# background), and I'd like to know more about when to use a list comprehension versus a for loop. Any ideas, suggestions, advice, or examples? Thanks for all the help.
...
I'm trying to get the Yahoo! BOSS package working, but when I try to run the example file I get the following error:
$ python examples/ex5.py
File "examples/ex5.py", line 28
tb = db.group(by=["yn$title"], key="rank", reducer=lambda d1,d2: d1+d2, as="total", table=tb, norm=text.norm)
...
I just noticed that my old codes written in python 2.5 does not work now. I am in python 2.6 btw.
>>> os.spawnl(os.P_NOWAIT,"setup.exe")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\python26\lib\os.py", line 612, in spawnl
return spawnv(mode, file, args)
OSError: [Errno 22] Invalid argument
>>...
I just noticed that I cannot use the Python 2.6 dll anymore. Python 2.5 works just fine.
import ctypes
py1 = ctypes.cdll.python25
py2 = ctypes.cdll.python26
# ctypes.cdll.LoadLibrary("libpython2.6.so") in linux
py1.Py_Initialize()
py2.Py_Initialize()
# segmentation fault in Linux
py1.PyRun_SimpleString("print 'hello world'")
# this ...
I am trying to make an HTTP request in Python 2.6.4, using the urllib module. Is there any way to set the request headers?
I am sure that this is possible using urllib2, but I would prefer to use urllib since it seems simpler.
...