I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries).
d1={key1:1, key2:2}
d2={key1:1, key2:'A', key4:4}
I want to update d1 so it...
A C program spits out consecutive doubles into a binary file. I wish to read them into Python. I tried using struct.unpack('d',f.read(8))
EDIT:
I used the following in C to write a random double number
r = drand48();
fwrite((void*)&r, sizeof(double), 1, data);
The Errors are now fixed but I cannot read the first value. for an all 0.0...
I'm writing a Python package. The package needs to know its version number internally, while also including this version in the setup.py script for distutils.
What's the best way of doing this, so that the version number doesn't need to be maintained in two separate places? I don't want to import the setup.py script from the rest of m...
How do you encode a png image into base64 using python on Windows?
iconfile = open("icon.png")
icondata = iconfile.read()
icondata = base64.b64encode(icondata)
The above works fine in Linux and OSX, but on Windows it will encode the first few characters then cut short. Why is this?
...
I tend to develop my apps in 'setup.py develop' -mode. I'd want the configuration to switch automagically on production mode when the program gets 'setup.py install'ed.
This can be done by poor hacks, like checking whether installation directory contains 'setup.py', but I wonder whether pkg_resources can do this for me somehow.
...
I've looked for other questions, but could not find any...
I have freshly installed my Mac with OSX 10.5. I need to learn Python/Django for a new job, so want to set it all up correctly, ready to develop and run from my browser using http://localhost/
I come from a PHP background and always used MAMP before. But I want to get everythin...
I have a module that I want to keep up to date, and I'm wondering if this is a bad idea:
Have a module (mod1.py) in the
site-packages directory that copies a
different module from some other
location into the site-packages
directory, and then imports * from
that module.
import shutil
from distutils.sysconfig import get_p...
I'm trying to upload a PDF file to a website using Hot Banana's content management system using a Python script. I've successfully logged into the site and can log out, but I can't seem to get file uploads to work.
The file upload is part of a large complicated web form that submits the form data and PDF file though a POST. Using Fi...
I am just trying to write a small web page that can parse some text using a regular expression and return the resulting matches in a table. This is the first I've used python for web development, and I have to say, it looks messy.
My question is why do I only get output for the last match in my data set? I figure it has to be because th...
I have a program in C that communicates via UDP with another program (in Java) and then does process manipulation (start/stop) based on the UDP pkt exchange.
Now this C program has been legacy and I want to convert it to Python - do you think Python will be a good choice for the tasks mentioned?
...
Hi!
I'd like to do something like below: particularly the 'f.eval(field)' part, such that it evaluates the value of the variable as the field name. How does one accomplish this in Python?
def punctuated_object_list(objects, field):
field_list = [f.eval(field) for f in objects]
if len(field_list) > 0:
if len(field_list)...
I need to put different codes in one file to many files.
The file is apparantly shared by AWK's creators at their homepage.
The file is also here for easy use.
My attempt to the problem
I can get the lines where each code locate by
awk '{ print $1 }'
However, I do no know how
to get the exact line numbers so that I can use them
to...
I am writing an IM client for Mac (in python, but an Objective C / Cocoa solution here is fine). I want to detect whether or not the user is currently watching a movie or playing a game in the foreground, or doing anything else that takes up the entire screen. If so, I won't play a sound when a new IM comes in, but if not, I will play th...
I'm currently working on a computation in python shell. What I want to have is Matlab style listout where you can see all the variables that have been defined up to a point (so I know which names I've used, their values and such).
Is there a way and how would one go in python about that ?
...
Am trying build pysqlite 2.5.3 package on SLSE 9, and am getting all sorts of compilation errors i.e.
...
src/module.c:290: error: initializer element is not constant
src/module.c:290: error: (near initialization for `_int_constants[27].constant_value')
src/module.c:290: error: initializer element is not constant
src/module.c:290: erro...
I'm working on an application that will run on Google AppEngine.
I plan to have the web interface of that application wait, among many other things, for notifications coming from the AppEngine server.
Ideally I would have liked to use an XMLHttpRequest() to make a request to the server that would be waiting until the next notification ...
Why (for example web2py) you return data from a controller in a dictionary instead (see Rails) in variables?
For example:
return dict(sape=4139, guido=4127, jack=4098)
instead of (that's the way Rails does it)
@var1 = "jello"
@var2 = "hihi"
Is there any advantage using dictionaries over plain variables (speed-wise/code-wise)?
U...
Im working on a parser here that opens a file, reads it and prints data in another file.
The input file is determined from sys.argv[1] to both handle commandline opening and drag and drop (in windows). However, when drag and dropping a file, it gives me
ioerror 13: Permission denied
Looking at what sys.argv contained, I did the follo...
I was recently reading this document which lists a number of strategies that could be employed to implement a socket server. Namely, they are:
Serve many clients with each thread, and use nonblocking I/O and level-triggered readiness notification
Serve many clients with each thread, and use nonblocking I/O and readiness change notifica...
I am trying the python pyparsing for parsing. I got stuck up while making the recursive parser.
Let me explain the problem
I want to make the Cartesian product of the elements. The syntax is
cross({elements },{element})
I put in more specific way
cross({a},{c1}) or cross({a,b},{c1}) or cross({a,b,c,d},{c1}) or
So the general f...