python

How can I get only class variables?

I have this class definition: class cols: name = 'name' size = 'size' date = 'date' @classmethod def foo(cls): print "This is a class method" With __dict__ I get all class attributes (members and variables). Also there are the "Internal attributes" too (like __main__). How can I get only the class variables...

Is there a way to decode numerical COM error-codes in pywin32

Here is part of a stack-trace from a recent run of an unreliable application written in Python which controls another application written in Excel: pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146788248), None) Obviously something has gone wrong ... but what?[1] These COM error codes seem to be...

How to use storeHtmlSource in python code (Selenium RC)

I found storeHtmlSource method description in Selenium reference, but can't figure out how to use it in python code I generated by exporting recording of my actions from the Selenium IDE. I need to pass the html source code of the current page into a function for processing. How to do that? Can anyone show example of code for calling th...

Finding first and last index of some value in a list in Python

Is there any built-in methods that are part of lists that would give me the first and last index of some value, like: verts.IndexOf(12.345) verts.LastIndexOf(12.345) ...

Is there a way to loop through a sub section of a list in Python

So for a list that has 1000 elements, I want to loop from 400 to 500. How do you do it? I don't see a way by using the for each and for range techniques. ...

Accessing the index in Python for loops

Anyone knows how to access the index itself so for a list like this: ints = [8,23,45,12,78] when I loop through it using a for loop, how do I make access the for loop index, from 1 to 5 in this case? ...

AppEngine: Maintaining DataStore Consistency When Creating Records

I've hit a small dilemma! I have a handler called vote; when it is invoked it sets a user's vote to whatever they have picked. To remember what options they previously picked, I store a VoteRecord options which details what their current vote is set to. Of course, the first time they vote, I have to create the object and store it. But s...

How can I strip Python logging calls without commenting them out?

Today I was thinking about a Python project I wrote about a year back where I used logging pretty extensively. I remember having to comment out a lot of logging calls in inner-loop-like scenarios (the 90% code) because of the overhead (hotshot indicated it was one of my biggest bottlenecks). I wonder now if there's some canonical way to...

how to search for specific file type with yahoo search API?

Does anyone know if there is some parameter available for programmatic search on yahoo allowing to restrict results so only links to files of specific type will be returned (like PDF for example)? It's possible to do that in GUI, but how to make it happen through API? I'd very much appreciate a sample code in Python, but any other solut...

Python cannot create instances

I am trying to create a simple Python extension using [PyCXX]. And I'm compiling against my Python 2.5 installation. My goal is to be able to do the following in Python: import Cats kitty = Cats.Kitty() if type(kitty) == Cats.Kitty: kitty.Speak() But every time I try, this is the error that I get: TypeError: cannot create 'Kit...

Python or php which language would be better for web development?

Python or php which language would be better for web development? ...

Python + Django page redirect

How do I accomplish a simple redirect (e.g. cflocation in ColdFusion, or header(location:http://) in php)? ...

How do I layout a 3 pane window using wxPython?

I am trying to find a simple way to layout a 3 pane window using wxPython. I want to have a tree list in the left pane, then have a right pane that is split into two - with an edit component in the top part and a grid component in the bottom part. Something along the lines of: -------------------------------------- | | ...

How to scale an image without occasionally inverting it (with the Python Imaging Library)

When resizing images along the lines shown in this question occasionally the resulting image is inverted. About 1% of the images I resize are inverted, the rest is fine. So far I was unable to find out what is different about these images. See resized example and original image for examples. Any suggestions on how to track down that pr...

Google Apps HTTP Streaming with Python question

I got a little question here: Some time ago I implemented HTTP Streaming using PHP code, something similar to what is on this page: http://my.opera.com/WebApplications/blog/show.dml/438711#comments And I get data with very similar solution. Now I tried to use second code from this page (in Python), but no matter what I do, I receive r...

Python/Ruby IDE (Windows)?

Are there any Windows IDEs that support both Ruby and Python? I'm talking about the type of IDE that has syntax suggestions (auto-completion feature). I've tried Netbeans but it only seems to support Ruby (maybe there's a way to add Python support?) ...

BaseHTTPRequestHandler freezes while writing to self.wfile after installing Python 3.0

Hey guys, I'm starting to lose my head with this one. I have a class that extends BaseHTTPRequestHandler. It works fine on Python 2.5. And yesterday I was curious and decided to install Python 3.0 on my Mac (I followed this tutorial, to be sure I wasn't messing things up: http://farmdev.com/thoughts/66/python-3-0-on-mac-os-x-alongside-...

Insert Command into Bash Shell

Is there any way to inject a command into a bash prompt in Linux? I am working on a command history app - like the Ctrl+R lookup but different. I am using python for this. I will show a list of commands from history based on the user's search term - if the user presses enter, the app will execute the command and print the results. So fa...

Is there a Python equivalent of Groovy/Grails for Java

I'm thinking of something like Jython/Jango? Does this exist? Or does Jython allow you to do everything-Python in Java including Django (I'm not sure how Jython differs from Python)? ...

How to externally populate a Django model?

What is the best idea to fill up data into a Django model from an external source? E.g. I have a model Run, and runs data in an XML file, which changes weekly. Should I create a view and call that view URL from a curl cronjob (with the advantage that that data can be read anytime, not only when the cronjob runs), or create a python scr...