python

parsing XML file in python with cElementTree: dealing with errors and line number in the file

Hello I am using the cElementTree library to parse XML files in Python. Everything is working fine But I would like to provide full error messages for the user when a value in the XML is not correct. For example, let's suppose I have the following XML: <A name="xxxx" href="yyyy"/> and want to tell the user if the href attribute doe...

What is the importance of an IDE when programming in Python?

I'm a beginning Python programmer, just getting my feet wet in the language and its tools and native practices. In the past, I've used languages that were tightly integrated into IDEs, and indeed I had never before considered that it was even possible to program outside of such a tool. However, much of the documentation and tutorials fo...

How to store regular expressions in the Google App Engine datastore?

Regular Expressions are usually expressed as strings, but they also have properties (ie. single line, multi line, ignore case). How would you store them? And for compiled regular expressions, how to store it? Please note that we can write custom property classes: http://googleappengine.blogspot.com/2009/07/writing-custom-property-classe...

How to pickle numpy's Inf objects?

When trying to pickle the object Inf as defined in numpy (I think), the dumping goes Ok but the loading fails: >>> cPickle.dump(Inf, file("c:/temp/a.pcl",'wb')) >>> cPickle.load(file("c:/temp/a.pcl",'rb')) Traceback (most recent call last): File "<pyshell#257>", line 1, in <module> cPickle.load(file("c:/temp/a.pcl",'rb')) ValueErr...

How to find the url using the referer and the href in Python?

Suppose I have window_location = 'http://stackoverflow.com/questions/ask' href = '/users/48465/jader-dias' I want to obtain link = 'http://stackoverflow.com/users/48465/jader-dias' How do I do it in Python? It have to work just as it works in the browser ...

Creating alternative login to Google Users for Google app engine

How does one handle logging in and out/creating users, without using Google Users? I'd like a few more options then just email and password. Is it just a case of making a user model with the fields I need? Is that secure enough? Alternatively, is there a way to get the user to log in using the Google ID, but without being redirected to ...

How do you enable auto-scrolling on GtkSourceView2?

I am having a problem with GtkSourceView used from Python. Two major problems: 1) When a user types text into the GtkSourceView, and types past the bottom of the visible text, the GtkSourceView does not autoscroll to the users cursor. This wouldnt be so bad, except: 2) The arrow keys, page up and page down keys, do not cause the GtkSour...

Decompressing a .bz2 file in Python

So, this is a seemingly simple question, but I'm apparently very very dull. I have a little script that downloads all the .bz2 files from a webpage, but for some reason the decompressing of that file is giving me a MAJOR headache. I'm quite a Python newbie, so the answer is probably quite obvious, please help me. In this bit of the scr...

Network Support for Pygame

I am making a simple multiplayer economic game in pygame. It consists of turns of a certain length, at the end of which, data is sent to the central server. A few quick calculations are done on the data and the results are sent back to the players. My question is how I should implement the network support. I was looking at Twisted and at...

Python Class vs. Module Attributes

I'm interested in hearing some discussion about class attributes in Python. For example, what is a good use case for class attributes? For the most part, I can not come up with a case where a class attribute is preferable to using a module level attribute. If this is true, then why have them around? The problem I have with them, is that...

python urllib, how to watch messages?

How can I watch the messages being sent back and for on urllib shttp requests? If it were simple http I would just watch the socket traffic but of course that won't work for https. Is there a debug flag I can set that will do this? import urllib params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0}) f = urllib.urlopen("https://...

Any reason why socket.send() hangs?

I'm writing an mini FTP server in Python that exposes an underlying database as if it was FTP. The flow is something like this: sock.send("150 Here's the file you wanted\r\n") proc = Popen2(...) for parts in data: data_sock.send(parts) proc.kill() sock.send("226 There's the file you wanted\r\n") data_sock.shutdown(0) data_sock.clos...

Writing Windows GUI applications with embedded Python scripts.

What would be the optimal way to develop a basic graphical application for Windows based on a Python console script? It would be great if the solution could be distributed as a standalone directory, containing the .exe file. ...

Difference between returning modified class and using type().

I guess it's more of a python question than a django one, but I couldn't replicate this behavior anywhere else, so I'll use exact code that doesn't work as expected. I was working on some dynamic forms in django, when I found this factory function snippet: def get_employee_form(employee): """Return the form for a specific Board."""...

Read from socket: Is it guaranteed to at least get x bytes?

I have a rare bug that seems to occur reading a socket. It seems, that during reading of data sometimes I get only 1-3 bytes of a data package that is bigger than this. As I learned from pipe-programming, there I always get at least 512 bytes as long as the sender provides enough data. Also my sender does at least transmit >= 4 Bytes ...

Where is the hidden parameter?

I have this function call here: import test_hosts test_hosts.LocalTestHost(mst, port, local_ip, remote_if_mac, remote_if_ip, service_port) and when I run it, the interpreter fails, and says I'm passing 6 parameters to a function that receives 7 parameters. LocalTestHost is a class which its constructor takes a self parameter and six...

Catmull-Rom splines in python

Hi all, Is there a library or function in python to compute Catmull-Rom spline from three points ? What I need in the end are the x,y coordinates of points along the spline, provided that they are always equidistant of a given amount t along the spline (say, the spline curve is 3 units long and I want the x,y coordinates at spline leng...

Python imports: Will changing a variable in "child" change variable in "parent"/other children?

Suppose you have 3 modules, a.py, b.py, and c.py: a.py: v1 = 1 v2 = 2 etc. b.py: from a import * c.py: from a import * v1 = 0 Will c.py change v1 in a.py and b.py? If not, is there a way to do it? ...

How to enumerate an object's properties in Python?

I C# we do it through reflection. In Javascript it is simple as: for(var propertyName in objectName) var currentPropertyValue = objectName[propertyName]; How to do it in Python? ...

Switching over Industry

Hi my name is P.Srikanth, currently i am working in a Healthcare BPO company but i did my Engineering in Electrical and Electronics completed in the year 2005. I want to switch over my career to my domain but i do not have experience in electrical field, is it possible for me to switch over? Please guide me i m in a big dilomma..... ...