python

How can you make Pylons email you the full post parameters with an error report?

Pylons can email you errors when something goes wrong in production mode, but it truncates the post parameters so it's hard to see what the error is. Is there a way to make it email you the whole thing? ...

reddit get_comments action, can someone clarify what is going on here?

I'm trying to understand reddit's source, and I am looking at the get_comments action method of front.py This is the action that displays a story: http://code.reddit.com/browser/r2/r2/controllers/front.py#L139 Specifically, what is the top part of the method doing where there is a @Validate marker? And on the bottom near the return, ...

python and using 'self' in methods

From what I read/understand, the 'self' parameter is similiar to 'this'. Is that true? If its optional, what would you do if self wasnt' passed into the method? ...

2 digit years using strptime() is not able to parse birthdays very well.

Consider the following birthdays (as dob): 1-Jun-68 1-Jun-69 When parsed with Python’s datetime.strptime(dob, '%d-%b-%y') will yield: datetime.datetime(2068, 6, 1, 0, 0) datetime.datetime(1969, 6, 1, 0, 0) Well of course they’re supposed to be born in the same decade but now it’s not even in the same century! According to the do...

finding out absolute path to a file from python

if I have a file test.py that resides in some directory, how can I find out from test.py what directory it is in? os.path.curdir will give the current directory but not the directory where the file lives. If I invoke test.py from some directory "foo", os.curdir will return foo but not the path of test.py. thanks. ...

Python "NoneType is not callable" error

I have a function that looks like the following, with a whole lot of optional parameters. One of these parameters, somewhere amidst all the others, is text. I handle text specially because if it is a boolean, then I want to run to do something based on that. If it's not (which means it's just a string), then I do something else. The ...

Fetch an email with imaplib but do not mark it as SEEN

Hello everyone, I want to parse some emails from a user 's inbox but when I do: typ, msg_data = imap_conn.fetch(uid, '(RFC822)') It marks the email as SEEN or read. This is not the desired functionality. Do you know how can I keep the email at its previous stare either SEEN or NOT SEEN? ...

Is this an acceptable pythonic idiom?

I have a class that assists in importing a special type of file, and a 'factory' class that allows me to do these in batch. The factory class uses a generator so the client can iterate through the importers. My question is, did I use the iterator correctly? Is this an acceptable idiom? I've just started using Python. class FileParser...

Can I format a variable in python?

Is there a way of formating a variable? For example, I'd like to automate the creation of a variable named M_color, where M is a string of value "bingo". The final result would be bingo_color. What should I do if the value of M changes during the execution? ...

Mod_python and unit testing

It there an easy way to do unit testing on an application written with mod_python? Something where I can generate dummy request objects easily. Thanks! ...

Running subprocess.call to run a Cocoa command-line application

I have one piece of Cocoa code I wrote that takes in an XML file containing bounding boxes that are then drawn on top of a video (each box has an associated frame). The Cocoa program is meant to be run from the command line (and takes in all its parameters as command line arguments) I can run program just fine with any XML document. How...

Python in Windows

hi , I am new to Python and need some help. i need to write a script that will look for file in c:\script\test\ directory with ext ".dat" and find "^" in there and replace with "|" i am not sure how to write this. There will only be one file for a day in the directory with the current date as the file name. Please help. I am not a go...

Decode Hex String in Python 3

In Python 2, converting the hexadecimal form of a string into the corresponding unicode was straightforward: comments.decode("hex") where the variable 'comments' is a part of a line in a file (the rest of the line does not need to be converted, as it is represented only in ASCII. Now in Python 3, however, this doesn't work (I assume ...

python dictionary, keeping a count of integers

I am trying to count a list of say, integers. I have a list of numbers in a csv file I am able to read in, that looks something like 4,245,34,99,340,... What I am doing is trying to return is a dictionary with key:value pairs where the key is an integer value from the csv file, and the value is the number of times it appears in the list...

How do I get the concrete name (e.g. "<module_name>"."<class_name">) of a class reference in Python?

This is what I have so far: def get_concrete_name_of_class(klass): """Given a class return the concrete name of the class. klass - The reference to the class we're interested in. """ # TODO: How do I check that klass is actually a class? # even better would be determine if it's old style vs new style # at the same time and handle thin...

GAE WSGIApplication and multiple request

In dev_appserver class MainPage(webapp.RequestHandler): def get(self): self.response.out.write("Hello MainPage") class TestPage(webapp.RequestHandler): def get(self): # 10 seconds i = 1 while True: if i == 10: break time.sleep(1) i = i + 1 application = webapp.WSGIApplication([ ('/', Ma...

python handle endless XML

I am working on a application, and my job just is to develop a sample Python interface for the application. The application can provide XML-based document, I can get the document via HTTP Get method, but the problem is the XML-based document is endless which means there will be no end element. I know that the document should be handled ...

Command Line in R code

Hi all, Let me start by saying I am new to programming. I am hoping to run a python script from the command line within an R script. I am running windows xp but also have a machine that runs Windows 7. I can run the following code without error for the dos-prompt. cd C:\Documents and Settings\USER\workspace\UGA - Website python test...

How do I set a world background texture in Blender 2.49 using Python ?

Hello, I'm trying to set a background World Texture in Blender 2.49. I've made a texture: import Blender from Blender import * import bpy world = World.GetCurrent() worldTex = Texture.New('worldTex') worldTex.setType('Image') worldIm = Image.Load('//blender_scene/tex/bg 001.jpg') worldIm.source = Image.Sources.SEQUENCE worldT...

Regex match words and end of string

2 Regex question How can I match a word or 2 words in a subpattern ()? How can i match a word or 2 words that's either followed by a specific word like "with" OR the end of the string $ I tried (\w+\W*\w*\b)(\W*\bwith\b|$) but it's definitely not working edit: I'm thinking of matching both "go to mall" and "go to", in a way that ...