python

Selenium issues with IE tests

When I change mt test browser to IE using the following line of code: self.selenium = selenium("localhost", 4444, "*iexplore", "http://www.mydomain.net/") I get the following error: Exception: Failed to start new browser session: java.lang.RuntimeException: SystemRoot apparently not set! It works perfectly fine using firefox and Ch...

Readable convention for unpacking single value tuple

There are some related questions about unpacking single-value tuples, but I'd like to know if there is a preferred method in terms of readability for sharing and maintaining code. I'm finding these to be a source of confusion or misreading among colleagues when they involve a long function chain such as an ORM query. Is there some conv...

Parsing unicode attachment names on incoming mail to Google App Engine

I have an app engine app that receives incoming mail with attachments. I check the attachment filename to make sure that the extension is correct. If the filename has umlauts or accented characters in it the encoding makes the filename unreadable to my methods, so I don't know how to check the file type. For example, if I send a file wi...

script to generate 3d to 2d mapping

I want to render a simple scene to png image 800x600 size. png image has 2d (u,v) pixel based coordinate system such that top left corner is (0,0) and moving right u increases and moving down v increases so that u and v is always 0 or positive integer. I want to write a script that would generate 3d mapping table that looks like: (0,0)...

Strings in Python 3

Hi: I am programing VIX API from python 2.5, but now I want to port the code to python 3.2 This funtion opens the virtual machine: self.jobHandle = self.VixLib.vix.VixVM_Open(self.hostHandle, "C:\\MyVirtualMachine.vmx", None, None)e...

Python vs C : Line of Code Comparison vs Dev Time

Hi I'm currently learning Python since the syntax feels so succinct and the idioms match well with my mental model. However I'm also interested in learning about OS internals and reverse engineering software, which ultimately means knowing C in a rather thorough capacity. When originally picking a language I did lots of reading and com...

Help with Python urllib2 and openers - How to make only 1 remote file read

I am trying to download content from a content provider that charges me every time I access a document. The code I have written correctly downloads the content and saves them in a local file but apparently it requests the file twice and I am being double charged. I'm not sure where the file is being requested twice, here is my code: ...

Python char encoding

I have the following code : msgtxt = "é" msg = MIMEText(msgtxt) msg.set_charset('ISO-8859-1') msg['Subject'] = "subject" msg['From'] = "[email protected]" msg['To'] = "[email protected]" serv.sendmail("[email protected]","[email protected]", msg.as_string()) The e-mail arrive with é as its body instead of the expected é I have tried : msgtxt = "é".en...

What is the ruby equivalent of the python BeautifulSoup library?

I'm looking for a forgiving HTML parser for scraping HTML and extracting data in Ruby. I've had success using BeautifulSoup for this - what is the ruby equivalent? ...

mySQL interface error only occuring if ran in Django

Hi all, I'm running a web crawler that gets called as a separate thread via Django. When it tries to store the scraped information I get this error: File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 147, in execute charset = db.character_set_name() InterfaceError: (0, '') If I manually run the script from the command li...

How do I say "not" using a regex when extracting a group of text?

I am trying to extract a section of text that looks something like this: Thing 2A blah blah Thing 2A blah blah Thing 3 Where the "3" above could actually be ANY single digit. The code I have that doesn't work is: ((Thing\s2A).+?(Thing\s\d)) Since the 3 could be any single digit, I cannot simply replace the "\d" with "3". I tried t...

Is it possible to reproduce randn() of MATLAB with NumPy?

Hi, I wonder if it is possible to exactly reproduce the whole sequence of randn() of MATLAB with NumPy. I coded my own routine with Python/Numpy, and it is giving me a little bit different results from the MATLAB code somebody else did, and I am having hard time finding out where it is coming from because of different random draws. I h...

complete beginner trying to create a flat file database in python

trying to keep it stupidly simple. Is it a bad idea to move a txt file into and out of a python list? the txt files will probably get to about 2-5k entries. what is the preferred method to create a simple flat file databse? ...

Adding folder to Python's path permanently

I've written a library in python and I want it to reside in a common location on the file system. From my script, I just want to do: >>> import mylib Now I understand that in order to do this, I can do this: >>> import sys >>> sys.path.append(r'C:\MyFolder\MySubFolder') >>> import mylib But I don't want to have to do that every ti...

Why don't they implement python and ruby on the web browsers?

I wonder, why don't they implement other languages like python and ruby on the web browsers? Don't they fit as client programming languages or did it just happen to be that Javascript was the first one to be implemented, and they then kept on only supporting javascript because it just worked. I mean...I really hate Javascript compared ...

Python internship offered

I was offered a python internship but my skills are very weak. I still have a LOT to learn. What do you think, should I take it or continue on my own learning? I'm thinking such experience is good for a beginner programmer. ...

[Python] Pre declared dictionary size limit?

I have a big dictionary i constantly reference in my code so i have it initialized at the top: import ... myDictionary = {'a':'avalue','b':'bvalue',...} code ... But when i try to get values, some of the keys are not found. It appears as though Python is chopping my dictionary due to a size limit. I tried searching google but could...

Why aren't persistent connections supported by URLLib2?

After scanning the urllib2 source, it seems that connections are automatically closed even if you do specify keep-alive. Why is this? As it is now I just use httplib for my persistent connections... but wonder why this is disabled (or maybe just ambiguous) in urllib2. ...

Python ''.format(): "tuple index out of range"?

Consider the following snippet: >>> def foo(port, out, udp=False, ipv6=False, data=''): ... if not data: ... data = 'foo {family} {:port} {direction}'.format( ... family=('ipv6' if ipv6 else 'ipv4'), ... port=port, ... direction=('out' if...

py2exe, problems

I'm using py2exe and I get the following errors in command prompt. C:\Users\Me>C:\Python26\My_scripts\python.exe setup.py py2exe C:\Python26\My_scripts\python.exe: can't open file 'setup.py': [Errno 2] No such file or directory What am I doing wrong? ...