Re: urllib2.urlopen timeout

2009-08-03 Thread Ben Charrow
Zdenek Maxa wrote: > Hi, > > I would like to ask how I should set timeout for a call: > > f = urllib2.urlopen(url) > > > I know that Python 2.6 offers > urllib2.urlopen(url[, data][, timeout]) > which would elegantly solved my problem, but I have to stick to Python 2.5. > There are three sol

Re: Download the "head" of a large file?

2009-07-27 Thread Ben Charrow
Dennis Lee Bieber wrote: On Mon, 27 Jul 2009 13:38:25 -0700 (PDT), erikcw declaimed the following in gmane.comp.python.general: Something like the Python equivalent of curl http://url.com/file.xml | head -c 2048 Presuming that | is a shell pipe operation, then doesn't that command lin

Re: Download the "head" of a large file?

2009-07-27 Thread Ben Charrow
erikcw wrote: > ...download just the first few lines of a large (50mb) text file form a > server to save bandwidth. Something like the Python equivalent of curl > http://url.com/file.xml | head -c 2048 If you're OK calling curl and head from within python: from subprocess import Popen, PIPE u

Re: Catching control-C

2009-07-06 Thread Ben Charrow
Michael Mossey wrote: > On Jul 6, 2:47 pm, Philip Semanchuk wrote: >> On Jul 6, 2009, at 5:37 PM, Michael Mossey wrote: >> >>> What is required in a python program to make sure it catches a control- >>> c on the command-line? Do some i/o? The OS here is Linux. >> You can use a try/except to catc

Idioms and Anti-Idioms Question

2009-06-21 Thread Ben Charrow
I have a question about the "Using Backslash to Continue Statements" in the howto "Idioms and Anti-Idioms in Python" (http://docs.python.org/howto/doanddont.html#using-backslash-to-continue-statements) It says: "...if the code was: value = foo.bar()['first'][0]*baz.quux(1, 2)[5:9] \

Re: Status of Python threading support (GIL removal)?

2009-06-19 Thread Ben Charrow
Jure Erznožnik wrote: > See here for introduction: > http://groups.google.si/group/comp.lang.python/browse_thread/thread/370f8a1747f0fb91 > > Digging through my problem, I discovered Python isn't exactly thread > safe and to solve the issue, there's this Global Interpreter Lock > (GIL) in place. >

Re: Pythonic way to overwrite a file

2009-06-17 Thread Ben Charrow
Cameron Pulsford wrote: > Hey all, hopefully a simple question. > > I'm writing a simple python tool that opens a file, and does something like > > for line in file.readlines(): > temp.write(line.doStuff()) > > However, I want to provide the option do this "in place", as in have the > desti

Re: Printing dictionary values rather than references

2009-06-10 Thread Ben Charrow
Amit Dor-Shifer wrote: > Hi all. > > I'd like to print-out a dictionary of objects. The printed values are > references. How Do I print the actual objects. > > Thanks, > Amit How about this: class MyClass: def __str__(self): return str(self.__dict__) def __repr__(self):

Re: Start the interactive shell within an application

2009-06-09 Thread Ben Charrow
If you're looking to debug your program, try "import pdb" and then wherever you want to debug put: pdb.set_trace() Your program will then enter the debugger when it executes that line. It's quite nice really. If you get confused on what to do, just type "help" http://docs.python.org/library/pd