¡¾ÇóÖú¡¿¹ØÓÚpythonÖÐ×Ö½ÚÊý×éת»»³É×Ö·û´®
ÓÉÓÚÊdzõѧ£¬ÔÚЩÇë½Ì´ó¼Ò¡£
Python code:
from urllib import request
import struct
class csdn:
def __init__(self):
print ('Hello,this is a init')
def getContent(self,url):
self.url = url
result = request.urlopen(self.url).read()#ÕâÀï·µ»ØÒ»¸öbyteÊý×é
#print(type(result))
saveFile = open('f:\\csdn\\1.txt','w')
try:
saveFile.write(struct.pack("s",result))
finally:
saveFile.close()
test = csdn()
test.getContent('http://www.baidu.com')
²é×ÊÁÏ˵ÓÃPACK¿ÉÒÔ£¬µ«ÎÒдÁËÉÏÃæµÄÄǸöTEST£¬Ö´Ðв»³öÀ´£¬»òÕß»¹ÓÐʲô±ðµÄ·½·¨£¬¿ÉÒÔ´Óbyte[] to String µÄ£¬¸æËßÎÒһϣ¬Ð»Ð»¡£
ÎÒµÄÄ¿µÄÊÇÏë°Ñ·µ»ØµÄ½á¹û´æµ½Ò»¸öÎļþÀï¡£
Ö±½Ó saveFile.write(result) ²»¾Í¿ÉÒÔÁËô£¿
³ö´í£¬ÈçÏ´íÎó£º
Python code:
Traceback (most recent call last):
File "F:\Information\Python\test\networkTest.py", line 17, in <module>
test.getContent('http://www.baidu.com')
File "F:\Information\Python\test\networkTest.py", line 12, in getContent
saveFile.write(result)
TypeError: write() argument 1 must be str, not bytes
ÒòΪÄãµÄ³ÌÐòÀïÓкº×Ö£¬ÒªÔÚ´úÂëµÚÒ»Ðмӣº
# -*-
Ïà¹ØÎÊ´ð£º
ÇëÎÊÏ£¬ÎÒµÄÊÇpython2.5°²×°ÁËPILÄ£¿é£¬È»ºó±àд³ÌÐò´ò¿ª±¾»úÉϵÄÒ»¸öͼƬʱ£¬ÎªÊ²Ã´ÀϳöÏÖ´íÎóÄØ£¬ÀÏÊÇÕÒ²»µ½Í¼Æ¬£¬´íÎóÌáʾÈçÏ£ºFile "C:\Python25\Lib\site-packages\PIL\Image.py", line 1888, in o ......
>>> x=-1
>>> if x>0:
print ('11')
>>> else:
SyntaxError: invalid syntax (<pyshell#20>, line 1)
ÍøÉÏËѵÄÒ²ÊÇ£º
>>> x=int(input("Please ent ......
ÎÒÏëÓÃpython½âÎöÍøÒ³ÖеÄurl ÔÚÏÂÔØ֮ǰ, ÎÒÏëÏÈ·¢Ò»¸öheadÇëÇó ²»ÐèÒªÏÂÔØÕû¸öÍøÒ³, ÏÈ»ñµÃ¸ÃÍøÕ¾µÄheadÐÅÏ¢, ¶ÁȡһЩÐÅÏ¢Ö®ºó ÔÚµ÷ÓÃÕâЩ¿âµÄread·½·¨À´¶ÁÈ¡Õû¸öÍøÒ³ ¸ÃÔõô²Ù×÷ÄØ ¶àл
°ï¶¥ÁË
ÓÐÈËÄÜÖ¸½ÌÒ» ......
±ÈÈçÎÒÐèÒªÓÃpython ¶Ôwin32³ÌÐò½øÐÐÒ»¶¨µÄ¿ØÖÆ
¶ÔtextboxÊäÈëÒ»´®×Ö·û´®
°´Ä³¸öbotton
¶ÔlistboxÀïµÄµÄÄÚÈݶÁÈ¡£¬´æ³É×Ö·û´®
¸ÃÈçºÎ²Ù×÷£¿
»òÕßÄÄÀïÓÐÎĵµÀý×Ó£¿
·Ç³£¸Ðл
......
ÎÒÓÃpython¿ª·¢ÁËÒ»×éGUI½çÃ棬ÁíÍâÒ»¸öͬ־ÓÃjavaʵÏÖÁËÓ¦ÓÃÖ÷¿ò¼Ü£¬ÏÖÔÚÒª½«ÕâЩGUI½çÃ漯³Éµ½Ö÷¿ò¼ÜÀïÃæÈ¥¡£²»ÖªµÀÔÚjavaÀïÃæ¸ÃÈçºÎµ÷Ó㿼ò¶øÑÔÖ®£¬¾ÍÊÇjava´úÂëÀïÃæÈçºÎµ÷ÓÃÒ»¸öÍⲿµÄ.pyÎļþ¡£Çë¸ø³öÒ»¸ö¼òµ¥µ ......