Methods on file-like objects can only used once on one object?

2011-08-23 Thread Yingjie Lin
Hi Python users, I just realize that my post yesterday shouldn't be specifically for mechanize. It should be a general question for file-like objects. >>> f = open('my_file.txt') >>> print f.readlines() ( prints a list of strings >>> print f.readlines() [] There are quite a few methods

Help on instance of closeable_response in module Mechanize

2011-08-22 Thread Yingjie Lin
Hi Python users, I have a question about the instance of closeable_response in module Mechanize. from mechanize import ParseResponse, urlopen url = "http://wwwsearch.sourceforge.net/mechanize/example.html"; r = urlopen(url) forms = ParseResponse(r, backwards_compat

Re: try... except with unknown error types

2011-08-19 Thread Yingjie Lin
Hi Zero, I see! This is very helpful. Thank you. - Yingjie On Aug 19, 2011, at 3:30 PM, Zero Piraeus wrote: > : > > On 19 August 2011 15:09, Yingjie Lin wrote: >> >> I have been using try...except statements in the situations where I can >> expect a certain

Re: HTML client sctript

2011-08-19 Thread Yingjie Lin
Hi John and Chris, Thanks for the help. I looked at both and think that mechanize suits my needs better, since it simply needs a python script and doesn't depend on Firefox. Yingjie > From: John Gordon > Mechanize seems like what you want. It's built on top of > urllib2.http://wwwsearch.s

try... except with unknown error types

2011-08-19 Thread Yingjie Lin
Hi Python users, I have been using try...except statements in the situations where I can expect a certain type of errors might occur. But sometimes I don't exactly know the possible error types, or sometimes I just can't "spell" the error types correctly. For example, try: response

HTML client sctript

2011-08-19 Thread Yingjie Lin
Hi Python users, I am maintaining a website written with Python CGI scripts. To make sure the website is working well, I would like to have a script which automatically "uses" this website and checks it's output everyday. It would be better if this script runs from the clients' side. Could any

pairwise combination of two lists

2011-08-17 Thread Yingjie Lin
Hi Python users, I have two lists: li1 = ['a', 'b'] li2 = ['1', '2'] and I wish to obtain a list like this li3 = ['a1', 'a2', 'b1', 'b2'] Is there a handy and efficient function to do this, especially when li1 and li2 are long lists. I found zip() but it only gives [('a', '1'), ('b', '2')],

python cgi webpage won't redirect before background children processes finish

2011-02-22 Thread Yingjie Lin
Hi all, I have a python cgi script which looks like this: [CODE STARTING HERE] open('x') print 'Content-Type: text/html\n\n' .. print '' % myURL .. ### after printing the webpage os.system('python myfile.py') logfile.write('END OF SCRIPT') logfile.close() [CODE ENDING] Question: