python

Python generates an IO error while interleaving open/close/readline/write on the same file

I'm learning Python-this gives me an IO error- f = open('money.txt') while True: currentmoney = float(f.readline()) print(currentmoney, end='') if currentmoney >= 0: howmuch = (float(input('How much did you put in or take out?:'))) now = currentmoney + howmuch print(now) str(now) f.cl...

mod_php vs mod_python

Why mod_python is oop but mod_php is not ? Example :We go to www.example.com/dir1/dir2 if you use mod_python apache opens www/dir1.py and calls dir2 method but if you use php module apache opens www/dir1/dir2/index.php ...

does someone know how to show content on screen (covering up any window) using Ruby or Python?

using Ruby or Python, does someone know how to draw on the screen, covering up any other window? Kind of like, press a key, and the program will show current weather or stock quote on the screen (using the whole screen as the canvas), and then press the key again, and everything restores to the same as before? (like Mac OS X's dash boa...

pycurl: RETURNTRANSFER option doesn't exist

I'm using pycurl to access a JSON web API, but when I try to use the following: ocurl.setopt(pycurl.URL, gaurl) # host + endpoint ocurl.setopt(pycurl.RETURNTRANSFER, 1) ocurl.setopt(pycurl.HTTPHEADER, gaheader) # Send extra headers ocurl.setopt(pycurl.CUSTOMREQUEST, "POST") # HTTP POST req ocurl.setopt(pycurl.CONNECTTIMEOUT, 2) ...

Pythonic Way to Initialize (Complex) Static Data Members

Hello, I have a class with a complex data member that I want to keep "static". I want to initialize it once, using a function. How Pythonic is something like this: def generate_data(): ... do some analysis and return complex object e.g. list ... class Coo: data_member = generate_data() ... rest of class code ... The func...

How do you pass script arguments to pdb (Python)?

I've got python script (ala #! /usr/bin/python) and I want to debug it with pdb. How can I pass arguments to the script? ...

Python's most efficient way to choose longest string in list?

I have a list of variable length and am trying to find (most likely) a list comprehension to allow me to see if the list item currently being evaluated is the longest string contained in the list. And am using Pythong 2.6.1 ie. mylist = ['123','123456','1234'] for each in mylist: if condition1: do_something() elif ____...

How do I put a scrollbar inside of a gtk.ComboBoxEntry?

I have a Combobox with over a hundred of entries and it is very awkward to skim through with out a scrollbar. I want to do exactly what is in the picture. With the scrollbar on the right so It'd be easier to move through the entries. I used gtk.Combo to make that example but the problem is that is deprecated. I need an example of ho...

Converting to safe unicode in python

I'm dealing with unknown data and trying to insert into a MySQL database using Python/Django. I'm getting some errors that I don't quite understand and am looking for some help. Here is the error. Incorrect string value: '\xEF\xBF\xBDs m...' My guess is that the string is not being properly converted to unicode? Here is my code for...

Timesheet Program to Track Days/Hours worked?

Say I make a program that keeps track of the days I worked and the hours I worked, would I use a dictionary? And how would I differentiate from a Monday on week 1 from a Monday on week 2? How do I get it to store this information after I close the program? (Python Language) ...

How to install cogen python coroutine framework on Mac OS X

I did sudo easy_install cogen and got : Searching for cogen Best match: cogen 0.2.1 Processing cogen-0.2.1-py2.5.egg cogen 0.2.1 is already the active version in easy-install.pth Using /Library/Python/2.5/site-packages/cogen-0.2.1-py2.5.egg Processing dependencies for cogen Searching for py-kqueue>=2.0 Reading http://pypi.python.or...

GitPython and sending commands to the Git object

GitPython is a way of interacting with git from python. I'm trying to access the basic git commands (e.g. git commit -m "message") from this module, which according to this should be accessed through the Git module. Here's what I've tried so far to get these commands working: >>> import git >>> foo = git.Git("~/git/GitPython") >>> bar =...

Print space after each word

Hi, what is an easy/effective way to combine an array of words together with a space in between, but no space before or after? I suppose it is possible to remove the space after combining everything in a loop (something like sum += (term + " "))...I don't like it though. Preferably code in Java, Python, or Ruby. Thanks! ...

Rapid Prototyping Twitter Applications?

I'm looking forward to create a bunch of Twitter applications for a website, and was wondering what solution stack worked best when trying to rapidly prototype small twitter applications? Google App Engine + Python/Django? Google App Engine + Java? Heroku + RoR? Good Old LAMP? Also, any recommendations on particular frameworks/librar...

Google App Engine: Production versus Development Settings

How do you setup a settings file? One is for your local development server and another set of setting values for when you upload to Google App Engine? For example, I would like to set up a settings file where I store the Absolute Root URL. ...

Python Django: Handling URL with Google App Engine - Post then Get

I have something like this set up: class CategoryPage (webapp.RequestHandler): def get(self): ** DO SOMETHING HERE ** def post(self): ** DO SOMETHING HERE ** ** RENDER THE SAME AS get(self) The question is, after I process the posted data, how would I be able to display the same information as the get(self) function? ...

Python: load words from file into a set

Hello, I have a simple text file with several thousands of words, each in its own line, e.g. aardvark hello piper I use the following code to load the words into a set (I need the list of words to test membership, so set is the data structure I chose): my_set = set(open('filename.txt')) The above code produces a set with the follo...

Python list of objects with random attributes

(Edit: randrange is just random.randrange, I didn't write my own RNG) I'm trying to create a list of instances of a class I defined. Here's the entire class (by request): from random import randrange class Poly: points = [0] * 8 fill = 'red' alpha = 1.0 def __init__(self, width=100, height=100): for i in ran...

List of non-datastore types in AppEngine?

I'm building an AppEngine model class. I need a simple list of tuples: class MyTuple(object): field1 = "string" field2 = 3 class MyModel(db.Model): the_list = db.ListProperty(MyTuple) This does not work, since AppEngine does not accept MyTuple as a valid field. Solutions I can think of: Make MyTuple extend db.Model. But does...

Python ctypes and function pointers

This is related to my other question, but I felt like I should ask it in a new question. Basically FLAC uses function pointers for callbacks, and to implement callbacks with ctypes, you use CFUNCTYPE to prototype them, and then you use the prototype() function to create them. The problem I have with this is that I figured that I would...