Re: urllib supports javascript

2008-02-01 Thread J. Peng
js 写道: > AFAIK, nothing. > How abount letting a browser do it? > By using pamie [1] or selenium, you can drive a browser from python. > > [1] http://pamie.sourceforge.net/ > > On Feb 2, 2008 11:07 AM, J. Peng <[EMAIL PROTECTED]> wrote: >> hello, >> >

urllib supports javascript

2008-02-01 Thread J. Peng
hello, Which useragent lib supports javascript? I know something about these libs: urllib,urllib2,cookielib,httplib But I'm not sure which one of them can support javascript scripts. Thanks! -- http://mail.python.org/mailman/listinfo/python-list

python modules collection

2008-01-30 Thread J. Peng
Hello, Is there a site for python,which collects most kinds of python modules? like CPAN for Perl. Sometime I want to use a module,like the time/date modules,don't know where I should search from. Sorry if I have repeated this question on the list. Thanks! -- http://mail.python.org/mailman/listi

Re: what's this instance?

2008-01-22 Thread J. Peng
Bruno Desthuilliers 写道: > J. Peng a écrit : >> def safe_float(object): >> try: >> retval = float(object) >> except (ValueError, TypeError), oops: >> retval = str(oops) >> return retval > >> The code above works well. > > For whi

what's this instance?

2008-01-21 Thread J. Peng
def safe_float(object): try: retval = float(object) except (ValueError, TypeError), oops: retval = str(oops) return retval x=safe_float([1,2,3,4]) print x The code above works well.But what's the instance of "oops"? where is it coming from? I'm totally confused on it.thanks. -- ht

Re: read files

2008-01-21 Thread J. Peng
Gabriel Genellina 写道: > En Tue, 22 Jan 2008 02:03:10 -0200, Paul Rubin > <"http://phr.cx"@NOSPAM.invalid> escribió: > >> "J. Peng" <[EMAIL PROTECTED]> writes: >>> print line, >> Do you really want all the lines crunched toge

Re: read files

2008-01-21 Thread J. Peng
Thank you. That gave so much solutions. And thanks all. Steven D'Aprano 写道: > On Tue, 22 Jan 2008 11:00:53 +0800, J. Peng wrote: > >> first I know this is the correct method to read and print a file: >> >> fd = open("/etc/sysctl.conf") >> done=0

read files

2008-01-21 Thread J. Peng
first I know this is the correct method to read and print a file: fd = open("/etc/sysctl.conf") done=0 while not done: line = fd.readline() if line == '': done = 1 else: print line, fd.close() I dont like that flag of "done",then I tried to re-write it as: fd = open

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread J. Peng
Steven D'Aprano 写道: > On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote: > >> J. Peng 写道: >> >>>k = (i.split())[3] >>>y = (i.split())[1] >> btw, why can't I write the above two into one statement? >> >> (k,y) = (i.split()

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread J. Peng
J. Peng 写道: >k = (i.split())[3] >y = (i.split())[1] btw, why can't I write the above two into one statement? (k,y) = (i.split())[3,1] -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread J. Peng
I tried to write it below,it can work,:) v= """preference 10 host mx1.domain.com preference 30 host anotherhost.domain.com preference 20 host mx2.domain.com""" x=v.split("\n") li =[] for i in x: k = (i.split())[3] y = (i.split())[1] li.append((y,k)) li.sort() print li the output is:

Re: object scope

2008-01-20 Thread J. Peng
Dennis Lee Bieber 写道: > The scope of "name" is the entire function; lacking a "global name" > statement, AND being on the left side of an assignment, it is a function > local name. Thank you. Does python have so-called 'block scope' object? or if you can,please show me the doc for python's o

Re: object scope

2008-01-20 Thread J. Peng
J. Peng 写道: > Please see the code below,what's the scope for object "name"? > I thought it should be located in the while block, but it seems not > really,it can be accessed out of while (the db[name] statement).Thanks > in advance. > > sorry the before code

object scope

2008-01-20 Thread J. Peng
Please see the code below,what's the scope for object "name"? I thought it should be located in the while block, but it seems not really,it can be accessed out of while (the db[name] statement).Thanks in advance. db = {} def newuser(): prompt = 'login desired: ' while 1: name = raw_input(prompt)

dynamic type variable

2008-01-20 Thread J. Peng
Python's variable is dynamic type,is it? But why this can't work? >>> 3 + 'a' Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for +: 'int' and 'str' So I see the number 3 can't be converted to string type automacially. -- http://mail.python.org/ma

Re: array and list

2008-01-18 Thread J. Peng
> On Jan 18, 3:23 am, "J. Peng" <[EMAIL PROTECTED]> wrote: > >> what's the difference between an array and a list in python? >> I see list has all features of array in C or perl. >> so please tell me.thanks. >> > > If you are n

Re: too long float

2008-01-18 Thread J. Peng
thanks all! On Jan 18, 2008 3:49 PM, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Fri, 18 Jan 2008 13:55:17 +0800, "J. Peng" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > > > why this happened on my python? > &g

too long float

2008-01-17 Thread J. Peng
hello, why this happened on my python? >>> a=3.9 >>> a 3.8999 I wanted 3.9 but got 3.89 How to avoid it? thanks. this is my python version: >>> sys.version '2.3.4 (#1, Feb 6 2006, 10:38:46) \n[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)]' -- http://mail.python.org/mailma

array and list

2008-01-17 Thread J. Peng
what's the difference between an array and a list in python? I see list has all features of array in C or perl. so please tell me.thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: assigning values in python and perl

2008-01-16 Thread J. Peng
On Jan 17, 2008 2:55 PM, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > > @$ref = (4, 5, 6) intentionally assigns to the same list pointed to by > the reference. That would be spelled as x[:] = [4, 5, 6] in Python. > What Python does in your example is assign the same as Perl's $ref = > [4, 5, 6]. So

Re: assigning values in python and perl

2008-01-16 Thread J. Peng
On Jan 17, 2008 1:54 PM, Mel <[EMAIL PROTECTED]> wrote: > > test(a) (along with def test(x)) takes the object named 'a' in the > current namespace and binds it with the name 'x' in function test's > local namespace. So, inside test, the name 'x' starts by referring to >the list that contains [

Re: assigning values in python and perl

2008-01-16 Thread J. Peng
On Jan 17, 2008 2:03 PM, Christian Heimes <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > Python's parameter passing is like passing a pointer in C/C++. > [snip] > > It's not (I repeat NOT) like passing a pointer in C. Please read > http://effbot.org/zone/call-by-object.htm > Yes I agree. No

Re: assigning values in python and perl

2008-01-16 Thread J. Peng
May I ask, python's pass-by-reference is passing the object's reference to functions, but perl, or C's pass-by-reference is passing the variable itself's reference to functions. So althought they're all called pass-by-reference,but will get different results.Is it? On

assigning values in python and perl

2008-01-16 Thread J. Peng
I just thought python's way of assigning value to a variable is really different to other language like C,perl. :) Below two ways (python and perl) are called "pass by reference", but they get different results. Yes I'm reading 'Core python programming', I know what happened, but just a little con

Re: no pass-values calling?

2008-01-15 Thread J. Peng
On Jan 16, 2008 3:03 PM, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Wed, 16 Jan 2008 13:59:03 +0800, "J. Peng" <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > > > > How to modify the array passed to the function? I tried somethi

Re: no pass-values calling?

2008-01-15 Thread J. Peng
On Jan 16, 2008 2:30 PM, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Wed, 16 Jan 2008 13:59:03 +0800, J. Peng wrote: > > > Hi, > > > > How to modify the array passed to the function? I tried something like > > this: > > > >>>

Re: no pass-values calling?

2008-01-15 Thread J. Peng
On Jan 16, 2008 1:45 PM, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Wed, 16 Jan 2008 11:09:09 +0800, "J. Peng" <[EMAIL PROTECTED]> > > alist = [] > anint = 2 > astr = "Touch me" > > dummy(alist, anint, astr) > > "

no pass-values calling?

2008-01-15 Thread J. Peng
Hello, I saw this statement in Core Python Programming book, All arguments of function calls are made by reference, meaning that any changes to these parameters within the function affect the original objects in the calling function. Does this mean there is not pass-values calling to a function