can I get the index number in for x in y loop?

2006-04-03 Thread JuHui
 a='String'
 for x in a:
... print x
...
S
t
r
i
n
g


can I get the index number  of a in the upon loop within for x in a
loop?

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


Re: can I get the index number in for x in y loop?

2006-04-03 Thread JuHui
which one has best performance?

a:for i in range(0,len(a))
b:for x in a
c:for x,y in enumerate(a)

but, it seems I cann't get index number with b format..:(

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


Re: can I get the index number in for x in y loop?

2006-04-03 Thread JuHui
thanks a lot!
:)

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


how to deal with socket.error: (10060, 'Operation timed out')

2006-03-18 Thread JuHui
I wrote a script to get 100 pages from a server.
like below:

1:import httplib
2:conns = httplib.HTTPConnection(www.mytest.com)
3:conn.request(GET, /)

sometimes a socket error was raised.

  File D:\usr\bin\lib\httplib.py, line 627, in connect
raise socket.error, msg
socket.error: (10060, 'Operation timed out')

how to catch this kind of error then retry the GET operation?

btw:
If I want to get many page on same server, which lib is the best
choice? I only know httplib,urllib and urllib2.
thanks a lot.

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


what the best way to get 1000 page on same server?

2006-03-18 Thread JuHui
Hi :
 I want to get many html page on same server.
 I have tried httplib and urllib.
 I think httplib is better one because it's httplib.HTTPConnection. It
will establish one network connection then do other opration before
connection close. The urllib will establish network connection each
time request. Am I wrong? How about urllib2? how about a new socket
client for this requirement?
  is there any other lib shall I use for this requirement?
  Any suggestion are welcome.

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


Re: how to deal with socket.error: (10060, 'Operation timed out')

2006-03-18 Thread JuHui
thanks!
I try the try before, but can't catch the socket error. so strange,
maybe my code was error.
I wrote a retry code block as below.

import httplib,time

while 1:
try:
conn = httplib.HTTPConnection(www.test.com)
conn.request(GET, /)
print success
break
except:
print error
time.sleep(2)

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


Re: How to convert

2006-03-18 Thread JuHui
 10/3.0
3.3335
 int(10/3.0)
3

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


can httplib.HTTPConnection use proxy?

2006-03-16 Thread JuHui
how to use httplib.HTTPConnection with http proxy?

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


can httplib.HTTPConnection use proxy?

2006-03-16 Thread JuHui
how to use httplib.HTTPConnection with http proxy?

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


Re: can httplib.HTTPConnection use proxy?

2006-03-16 Thread JuHui
sorry, would you please give a sample code?
I want to use HTTPConnection to get a html page content via a http
proxy.
thanks.

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


how to get 20000 html pages content quickly from one server?

2006-03-15 Thread JuHui
Hi
  I want to get 20 html pages content from one server, you know
urllib.urlopen need construct network connection, it will be very
slowly, how to speed up this function?
 I try to using multi-thread, it speed up, but I want to quickly more,
any idea about it?
Thanks!

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


Re: how to get 20000 html pages content quickly from one server?

2006-03-15 Thread JuHui
...
I will do it later. but i want to optimize the script first.
after useing muti-thread, the time speed up from 8s to 2.3s per page.

any other suggestions?

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


Re: how to get 20000 html pages content quickly from one server?

2006-03-15 Thread JuHui
in fact, I want to do a script to get news on others site.
I must use script get the content and analyze the html code, where is
the title, where is the body
so, I can't ask permission, use wget  and Physically remove the
harddrive and reinstall it locally
:)

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


how to validate a proxy is alive?

2006-03-10 Thread JuHui
If a proxy is alive then return true, else return fals after 1 second.
thanks

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


Re: how to validate a proxy is alive?

2006-03-10 Thread JuHui
I want to get a html page content via a http proxy.
befor this, I want to check the proxy. how to validate it?
thanks

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


Re: how to validate a proxy is alive?

2006-03-10 Thread JuHui
cool!
thanks !

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


Re: [How to change redirect stderr?]

2006-03-10 Thread JuHui
how about 
$ python test.py 2 /dev/null
?

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


how to get a page's html code via a proxy

2006-03-09 Thread JuHui
who can help me?
please give me a sample code. thanks a lot.

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


Re: how to get a page's html code via a proxy

2006-03-09 Thread JuHui
thank you! I am not good at it.

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