Re: 有中国人乎?

2008-04-13 Thread Penny Y.
[EMAIL PROTECTED] 写道:
> Python这种语言有前途吗?在下想学他一学.

hehe, so humorous you are!
Yes I think python has good future.
But it depends on what you use it to do.
If you're a singer, a financier, a historian etc, you don't need python.
But if you are playing in computer programming, it's valuable for you to 
take some time learning python.
btw,I'm also newbie to python,but I like it.

--penny
-- 
http://mail.python.org/mailman/listinfo/python-list

about the ';'

2008-04-13 Thread Penny Y.
I saw many python programmers add a ';' at the end of each line.
As good style, should or should not we do coding with that?

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Host: header

2008-04-13 Thread Penny Y.
Hello,

I have a problem with a request url,for example, I have the code below,

import httplib

try:
conn = httplib.HTTPConnection("192.168.1.1")
conn.request("GET", "/")
r1 = conn.getresponse()
if r1.status == 200:
result = 0
except Exception:
result = -1


but the server on 192.168.1.1 accept virtual host request only.
That's to say, I need to specify a "Host:" header in the request.
How to do it? thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


mod_python

2008-04-13 Thread Penny Y.
Hello,

I want to rewrite a request url under apache2.0 based on its special 
header, like, the "Accept-Encoding:" one.

With C I think I can do it, but since I get begin with python,so I ask 
that can I do it under mod_python? what's the guide?

Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: 有中国人乎?

2008-04-13 Thread Penny Y.
Steve Holden 写道:

> 但学会从未是立即, 和将需要一点时间。
> 

What do you mean?
If I understand you correctly, maybe it should be,

学习python不可一日而成,需要循序渐进.

Am I right?
-- 
http://mail.python.org/mailman/listinfo/python-list

答复: how to remove \n in the list

2008-04-14 Thread Penny Y.
> lines[:] = [line.rstrip('\n') for line in lines]

why not just:

lines = [line.rstrip('\n') for line in lines]


what's the difference between lines[:] and lines here? Thanks.

-邮件原件-
发件人: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 代表 Gabriel
Genellina
发送时间: 2008年4月14日 12:59
收件人: python-list@python.org
主题: Re: how to remove \n in the list

En Mon, 14 Apr 2008 01:41:55 -0300, reetesh nigam  
<[EMAIL PROTECTED]> escribió:

> hi,
> l=['5\n', '2\n', '7\n', '3\n', '6\n']
>
> how to remove \n from the given list

l is is very poor name... I'll use lines instead:

lines[:] = [line.rstrip('\n') for line in lines]

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list

答复: 答复: how to remove \n in the list

2008-04-14 Thread Penny Y.
that's right. got it thanks. 

-邮件原件-
发件人: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 代表 Eric Brunel
发送时间: 2008年4月14日 16:17
收件人: python-list@python.org
主题: Re: 答复: how to remove \n in the list

(please avoid top-posting... corrected)
On Mon, 14 Apr 2008 09:08:06 +0200, Penny Y. <[EMAIL PROTECTED]> wrote:
> -邮件原件-
> 发件人: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] 代表 Gabriel
> Genellina
> 发送时间: 2008年4月14日 12:59
> 收件人: python-list@python.org
> 主题: Re: how to remove \n in the list
>
> En Mon, 14 Apr 2008 01:41:55 -0300, reetesh nigam
> <[EMAIL PROTECTED]> escribió:
>
>> hi,
>> l=['5\n', '2\n', '7\n', '3\n', '6\n']
>>
>> how to remove \n from the given list
>
> l is is very poor name... I'll use lines instead:
>
> lines[:] = [line.rstrip('\n') for line in lines]
> ---
>
> why not just:
>
> lines = [line.rstrip('\n') for line in lines]
>
>
> what's the difference between lines[:] and lines here? Thanks.

Compare:

>>> lines = ['5\n', '2\n', '7\n', '3\n', '6\n']
>>> lines2 = lines
>>> lines = [line.rstrip('\n') for line in lines]
>>> lines
['5', '2', '7', '3', '6']
>>> lines2
['5\n', '2\n', '7\n', '3\n', '6\n']

with:

>>> lines = ['5\n', '2\n', '7\n', '3\n', '6\n']
>>> lines2 = lines
>>> lines[:] = [line.rstrip('\n') for line in lines]
>>> lines
['5', '2', '7', '3', '6']
>>> lines2
['5', '2', '7', '3', '6']

Assigning to lines[:] changes the original list. Assigning to lines  
rebinds the name to the result of the list comprehension, but doesn't  
affect the original list.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list

-- 
http://mail.python.org/mailman/listinfo/python-list

答复: Java or C++?

2008-04-14 Thread Penny Y.
Javascript is different from Java at all.
Why not Perl? Perl is a functional language, that will show you another way
of programming.
Also C is good, will teach you some system level knowledge. :)

-邮件原件-
发件人: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 代表 Marco Mariani
发送时间: 2008年4月14日 16:38
收件人: python-list@python.org
主题: Re: Java or C++?

[EMAIL PROTECTED] wrote:

 > Which one do you think will educate me the best?

Advanced javascript might teach you something too, and be very useful at 
the same time.

-- 
http://mail.python.org/mailman/listinfo/python-list

答复: 有中国人乎?

2008-04-14 Thread Penny Y.
 

-邮件原件-
发件人: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] 代表 Steve Holden
发送时间: 2008年4月15日 2:17
收件人: python-list@python.org
主题: Re: 有中国人乎?


>Since what I entered in English was something like "Yes, Python has a 
>future. But it will take some study". Perhaps you can tell me whether 
>your translation gives the correect flavor. I'm pretty sure the 
>babelfish mangled my intent.



Babelfish does that thing worse.
yes follow your words, the translation could be:

Python前景光明.然师之非一日而成, 乃须循序渐进.

:-)



-- 
http://mail.python.org/mailman/listinfo/python-list

a name error

2008-04-14 Thread Penny Y.
Hello,

I run this small script:

import urllib2,sys
try:
r=urllib2.urlopen("http://un-know-n.com/";)
except URLError,e:
print str(e)
sys.exit(1)

print r.info()


But got the errors:

Traceback (most recent call last):
  File "t1.py", line 4, in ?
except URLError,e:
NameError: name 'URLError' is not defined


Why these is not the name of URLError? I saw it on this module's page:

http://www.python.org/doc/lib/module-urllib2.html

Thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


about a head line

2008-04-17 Thread Penny Y.
 I saw some scripts have a line at its begin:

# encoding:gb2312

what's this? Why need it? thanks.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: get quote enclosed field in a line

2008-04-17 Thread Penny Y.
Hello,

I don't know Python's RE very well.
But using Perl's RE you can get it.

> cat t1.pl 
$x=qq{189.139.109.235 - - [07/Apr/2008:00:00:16 -0400] "GET
/Periodic_dosage_dir/lacru/manara.html HTTP/1.1" 200 1933 xahlee.org
"http://xahlee.org/Periodic_dosage_dir/lacru/manara2.html"; "Mozilla/5.0
(Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.13)
Gecko/20080311Firefox/2.0.0.13" "-"};

$ua = ($x=~/\"(.+?)\"/g)[-2];
print $ua,"\n";

> perl t1.pl 
Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.13)
Gecko/20080311Firefox/2.0.0.13



> -邮件原件-
> 发件人: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] 代表 
> [EMAIL PROTECTED]

> 
> e.g. the typical line is like this:
> 
> 189.139.109.235 - - [07/Apr/2008:00:00:16 -0400] "GET /
> Periodic_dosage_dir/lacru/manara.html HTTP/1.1" 200 1933 xahlee.org
> "http://xahlee.org/Periodic_dosage_dir/lacru/manara2.html"; "Mozilla/
> 5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.8.1.13) Gecko/20080311
> Firefox/2.0.0.13" "-"
> 
> I want the part: "Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:
> 1.8.1.13) Gecko/20080311 Firefox/2.0.0.13".

-- 
http://mail.python.org/mailman/listinfo/python-list