python

When are function local python variables created?

When are function-local variables are created? For example, in the following code is dictionary d1 created each time the function f1 is called or only once when it is compiled? def f1(): d1 = {1: 2, 3: 4} return id(d1) d2 = {1: 2, 3: 4} def f2(): return id(d2) Is it faster in general to define a dictionary within function...

Size differences between TrueType and OpenType fonts when using PIL ImageFont

I'm trying to create PNGs of letters from the fonts on my system. Seems to work okay with TrueType fonts (.ttf) but not OpenType (.otf). The images formed are the same size but the actual letters appear much smaller with OpenType - see below. I'm using the ImageFont module from the Python Imaging library. There doesn't seem to be a way ...

Return value of os.path in Python

For this code: import os a=os.path.join('dsa','wqqqq','ffff') print a print os.path.exists('dsa\wqqqq\ffff') #what situation this will be print True? When will os.path.exists('what') print True? ...

install pyquery on windows

Hi! I want to install pyquery on windows. But i cant run setup.py install on the command line. Do you have any hint? ...

How to install imagingft in OSX and Ubuntu?

I'm using PIL 1.1.6 to render a truetype font on my local Windows machine. I'd like to be able to get the application running in OSX and Ubuntu (server). So far the instructions I've found all deal with specific ports repositories on OSX (Darwinports, Macports, etc.) or very outdated instructions for Linux. Has anyone recently got ima...

Accessing a file relatively in Python if you do not know your starting point?

Hey. I've got a project in Python, whose directory layout is the following: root |-bin |-conf |-[project] Python files in [project] need to be able to read configuration data from the 'conf' directory, but I cannot guarantee the location of root, plus it may be used on both Linux, Mac and Windows machines so I am trying to relat...

why my code doesn't print os.path.

for code: def a(x): if x=='s': __import__('os')# i think __import__==import print os.path a('s') why,thanks my Questions is from next code: and it doesn't use like 'a=__import__('os')',it only use '__import__('some')',why def import_module(name, package=None): if name.startswith('.'): if not package...

Can a standalone web application built with cherrypy be compiled?

I want to build a web application that stands completely by itself, apache not required. Is cherrypy a good solution, and can this be compiled with something like py2exe? ...

Python Idiom. Need Clarification.

From http://jaynes.colorado.edu/PythonIdioms.html "Build strings as a list and use ''.join at the end. join is a string method called on the separator, not the list. Calling it from the empty string concatenates the pieces with no separator, which is a Python quirk and rather surprising at first. This is important: stri...

Are there other Type in addition to the class to be called by hasattr.

For code: class a(object): a='aaa' b=a() print hasattr(a,'a') print hasattr(b,'a') who can be called by hasattr except 'class somebody'? Thanks! ...

How to use C++ lib from python

I would like to know how to use python to make calls to a C++ library called libwpd to read word perfect files and build python objects from them, but I have no experience with C++ or calling C++ functions from python, and I don't understand how to figure out what the output of these library functions would be. So that's really two quest...

Parse Facebook feed datetime in python?

I am reading a Facebook updates feed using the python library 'feedparser'. I loop through the collection of entries in my Django templates, and display the results. The updated field is returned in a big long string, of some format I am unfamiliar with. Tue, 01 Dec 2009 23:55:52 +0000 How can I... A) Use a Django filter to clean th...

Is it a bad idea to design and develop a python applications backend and then once finished try to apply a GUI to it?

Is it better to do it all at once? I'm very new to wxPython and I'm thinking it would be better to write the program in a way familiar to me, then apply the wxPython gui to it after I'm satisfied with the overall design of the app. Any advice? ...

How to parse/extract data from a mediawiki marked-up article via python

Source Mediawiki markup Right now I'm using a variety of regexes to "parse" the data in the mediawiki mark-up into lists/dictionaries, so that elements within the article can be used. This is hardly the best method, as the number of cases that have to be made are large. How would one parse an article's mediawiki markup into a variety...

i don't know why django do this,it is about os.stat.

What is the benefits of doing so: import os ST_MODE = 0 ST_INO = 1 ST_DEV = 2 ST_NLINK = 3 ST_UID = 4 ST_GID = 5 ST_SIZE = 6 ST_ATIME = 7 ST_MTIME = 8 ST_CTIME = 9 # Extract bits from the mode def S_IMODE(mode): return mode & 07777 def S_IFMT(mode): return mode & 0170000 # Constants used as S_IFMT() for various fil...

How to learn how to program?

I would like to know the best methods for learning to program. I've been directed towards the Python language because I was told it is good for beginners. I ultimately want to make games for OS X/iPhone. My problem is that I understand what I read but I can't apply my knowledge to anything. I am a programming noob. Should I stick with ...

How can I tell if a field has changed value in an AT object in plone?

I have an AT content type in Plone. It has a number of fields, including a file field. When the user edits an object of this type, how can I tell if a new file was uploaded? For that matter, how can I tell if any of the fields have been changed? I am currently using subscribers to hook into the IObjectEditedEvent to do some after the ...

How to detect flash drive plug-in in Windows using Python?

I want to make my Windows computer run a Python script when it detects that a flash drive which has a particular name (for example "My drive") has been plugged in. How can I achieve this? Should I use some tool in Windows or is there a way to write another Python script to detect the presence of a flash drive as soon as it is plugged ...

Enumerations in python

Duplicate: Whats the best way to implement an enum in Python? Whats the recognised way of doing enumerations in python? For example, at the moment I'm writing a game and want to be able to move "up", "down", "left" and "right". I'm using strings because I haven't yet figured out how enumerations work in python, and so my logic...

PyWin32: Windows Classic theme

In the PyWin32 demos folder, the win32gui_dialog.py sample uses the classic windows controls. Can the Windows Vista themed buttons also be displayed using PyWin32, and if so, how? I'm using ActivePython 3.1, if that makes any difference. Sample: ...