python-3.x

How remove a program installed with distutils ?

I have installed a python application with this setup.py: #!/usr/bin/env python from distutils.core import setup from libyouandme import APP_NAME, APP_DESCRIPTION, APP_VERSION, APP_AUTHORS, APP_HOMEPAGE, APP_LICENSE setup( name=APP_NAME.replace(" ","-").lower(), version=APP_VERSION, description=APP_DESCRIPTION, author=...

smallest value of hash() function?

in python (3), what is the smallest value that hash(x) can return? i want to use hashes to give a quick 'fingerprint' to database values (basically making it easy to see whether two longish, similar texts are actually equal or not), and want to get rid of negative numbers (for simplicity), so i thought i'd just add the smallest possibl...

Use PYTHONSTARTUP to interactively test a python file in the interpreter

I want to establish a standard script file that is imported into python at startup using the PYTHONSTARTUP environment variable. Additionally, I want to be able to conveniently reload the same script file after modifying it in an external editor, to test its behavior after the modification. I created a ~/.pythonrc.py file and set it as P...

Python 3.1 code and error

64-bit VISTA Python 3.1 from urllib import request a = request.urlopen('http://www.marketwatch.com/investing/currency/CUR_USDYEN').read(20500) b = a[19000:20500] idx_pricewrap = b.find('pricewrap') context = b[idx_pricewrap:idx_pricewrap+80] idx_bgLast = context.find('bgLast') rate = context[idx_bgLast+8:idx_bgLast+15] print(rate) Tr...

capitalization of library class names

Why do collection.defaultdict and collection.OrderedDict have different capitalizations? Is there some subtle difference that I should be aware of? (P3K) ...

CGI not working with built-in Python 3.1 http.server

I'm using http.server with the CGIHTTPRequestHandler on OS X 10.6 and the posix code path in run_cgi() does not appear to work properly. I'm calling a located at /cgi-bin/test.py from a form submit. For the better part of this afternoon I was receiving the error 'OSError: [Errno 2] No such file or directory' at the os.execve() line 105...

Python3 and terminal widgets

Hi, I'm looking for a terminal UI library having widgets (like buttons, checkbox, ...), and compatible with python3. I tried : pycdk (pyrex does not work with python3, and porting it is a mess) urwid (does not work with python3, it has a port but not working well with new curses interface). Does anyone know such a library ? Thanks...

(Python, IDLE, Windows) Pressing Stack Viewer exits all IDLE windows

I am running Python 3.1.2 with IDLE 3.1.2 on Windows 7. When I try to use the Stack Viewer, blue text and a new window briefly appear before all open IDLE windows exit (I don't have time to read the text or new window). This is the first time I have used Stack Viewer. Is this normal behavior? How can I get the Stack Viewer to stay open?...

parallel file parsing, multiple CPU cores

I asked a related but very general question earlier (see especially this response). This question is very specific. This is all the code I care about: result = {} for line in open('input.txt'): key, value = parse(line) result[key] = value The function parse is completely self-contained (i.e., doesn't use any shared resources). ...

parsing options in a config module

I use config module to store variables global to all modules. Is it a good place to parse the script arguments? (Note: config module is my own module, it just contains a bunch of global variables.) ----- config.py ----- from optparse import OptionParser parser = OptionParser() parser.add_option("-t", "--test", action = "store_true", de...

printing tab-separated values of a list

Here's my current code: print(list[0], list[1], list[2], list[3], list[4], sep = '\t') I'd like to write it better. But print('\t'.join(list)) won't work because list elements may numbers, other lists, etc., so join would complain. ...

using float('nan') to represent missing values - safe?

Python 3.1 I am doing some calculations on a data that has missing values. Any calculation that involves a missing value should result in a missing value. I am thinking of using float('nan') to represent missing values. Is it safe? At the end I'll just check def is_missing(x): return x!=x # I hope it's safe to use to check for NaN ...

Strange newline when attempting unbuffered reading in python

I have this code: def getch(self): if os.name == 'posix': fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(fd) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) elif os.name == 'nt': ch = m...