python

Assign a value equal only to itself

I wish to assign to a variable (a "constant"), a value that will allow that variable to only ever return True in is and == comparisons against itself. I want to avoid assigning an arbitary value such as an int or some other type on the off chance that the value I choose clashes with some other. I'm considering generating an instance of...

Numpy with python 3.0

NumPy installer can't find python path in the registry. Cannot install Python version 2.6 required, which was not found in the registry. Is there a numpy build which can be used with python 3.0? ...

check that a script is actually using a proxy from a ip list

I have a list of proxy ip's that I want to use in one of my python scripts, but how do I verify that I am using one of the ip addresses from the list and not my own? I'm using mechanize, but any general explanation of how to do this would be helpful. This is the first time I have worked with proxies, so anything you can tell me will ...

What's python complaining about here?

I'm trying to run Adobe's sample python policy server script, linked to here: http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html I'm getting the following error: # python flashpolicyd.py --file=policy.xml File "flashpolicyd.py", line 40 with file(path, 'rb') as f: ^ SyntaxError: invalid syntax ...

Correct way to emulate single precision floating point in python?

What's the best way to emulate single-precision floating point in python? (Or other floating point formats for that matter?) Just use ctypes? ...

How to mount a network directory using python?

I need to mount a directory "dir" on a network machine "data" using python on a linux machine I know that I can send the command via command line: mkdir ~/mnt/data_dir mount -t data:/dir/ /mnt/data_dir but how would I send that command from a python script? ...

Python import MySQLdb, Apache Internal Server Error

I'm having a similar problem to that described in ".cgi problem with web server", although I reviewed and tested the previously suggested solutions without success. I'm running the same program on Mac OS X 10.5.8, Apache 2.2.13, using Python 2.6.4. I can successfully run the code in the python shell and the terminal command-line, but I...

I've got Python built using VS2008, how do I install it?

I'm working with boost::python and wanted to build the whole thing to make sure I can pull it off. However, I don't see any install script or way to build the MSI so I can install it. Anyone know where the directions are? Or the projects I could use to make an MSI file? Doing this on linux seems trivial: make install How do I do th...

Python newbie having a problem using classes

Im just beginning to mess around a bit with classes; however, I am running across a problem. class MyClass(object): def f(self): return 'hello world' print MyClass.f The previous script is returning <unbound method MyClass.f> instead of the intended value. How do I fix this? ...

Does Python PIL resize maintain the aspect ratio?

Edit: Does PIL resize to the exact dimensions I give it no matter what? Or will it try to keep the aspect ratio if I give it something like the Image.ANTIALIAS argument? ...

How to include in code an unique ID related to a mercurial commit?

I'd like to do the same thing that they're doing here in stackoverflow. <link rel="stylesheet" href="http://sstatic.net/so/all.css?v=6274"&gt; <script type="text/javascript" src="http://sstatic.net/so/js/master.js?v=6180"&gt;&lt;/script&gt; <script src="http://sstatic.net/so/js/question.js?v=6274" type="text/javascript"></script> D...

Where do stdout and stderr go when in curses mode?

Where do stdout and stderr go when curses is active? import curses, sys def test_streams(): print "stdout" print >>sys.stderr, "stderr" def curses_mode(stdscr): test_streams() test_streams() curses.wrapper(curses_mode) Actual output is stdout stderr Update0 Expected output is stdout stderr stdout stderr entering,...

How does zip(*[iter(s)]*n) work in Python?

I saw this in the Python documentation for zip(). Apparently, if s is [1,2,3,4,5,6,7,8,9] and n is 3, zip(*[iter(s)]*n) returns [(1,2,3),(4,5,6),(7,8,9)]. How exactly does this work? I'm not sure how the operator precedence works here. What would this look like if it was written with more verbose code? Thanks. (This just looks so cool ...

Python - letter frequency count and translation.

Hi, I am using Python 3.1, but I can downgrade if needed. I have an ASCII file containing a short story written in one of the languages the alphabet of which can be represented with upper and or lower ASCII. I wish to: 1) Detect an encoding to the best of my abilities, get some sort of confidence metric (would vary depending on the len...

How to delete list elements while cycling the list itself without duplicate it

I lost a little bit of time in this Python for statement: class MyListContainer: def __init__(self): self.list = [] def purge(self): for object in self.list: if (object.my_cond()): self.list.remove(object) return self.list container = MyListContainer() # now suppose both obj...

Compiling Mysqldb for jython 2.5 on Solaris

I have used python2.6 + MySQL on Windows and there are binaries available. I wanted to get the whole thing working on Solaris Hence got the Mysql-Python package from here I had to get the setuptools installed which is done. Exploded the MySQL-python-1.2.3c1 When I this /jython2.5.1/jython setup.py build Error - `File "/opt/somepat...

Are there any reputable Python certifications?

My company has a policy of encouraging employee training, but want some evidence of quality of training and tangible achievement. Several of our Java developers are taking advantage of this opportunity to go for Sun certifications, which provide a formal way of verifying competence, and will be useful additions to their CVs in the future...

Can I port my existing python apps on ASE?

I learned that the Android Scripting Environment (ASE) supports python code. Can I take my existing python programs and run them on android? Apart from the GUI, what else will I need to adapt? How can I find the list of supported python libraries for ASE? ...

Overriding urllib2 HTTPError and reading response HTML anyway

I am trying to screen scrape multiple pages of a website, that return an 'HTTP Error 500: Internal Server Error' response, but still give important data inside the error HTML. Normally, I would fetch a page using this (Python 2.6.4): import urllib2 url = "http://google.com" data = urllib2.urlopen(url) data = data.read() But when atte...

overriding bool() for custom class

All I want is for bool(myInstance) to return False (and for myInstance to evaluate to False when in a conditional like if/or/and. I know how to override >, <, =) I've tried this: class test: def __bool__(self): return False myInst = test() print bool(myInst) #prints "True" print myInst.__bool__() #prints "False" Any sugg...