the command :<br>2to3-3.2 getcode3.py -w<br>can run in linux<br>it can't run in window xp,can i make it in window xp?<br><div><includetail><div> </div><div> </div><div style="font:Verdana normal 14px;color:#000;"><div style="FONT-SIZE: 12px;FONT-FAMILY: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="FONT-SIZE: 12px;background:#efefef;padding:8px;"><div id="menu_sender"><b>发件人:</b> "1248283536"<1248283536@qq.com>;</div><div><b>发送时间:</b> 2011年9月28日(星期三) 晚上7:50</div><div><b>收件人:</b> "Peter Otten"<__peter__@web.de>; "python-list"<python-list@python.org>; <wbr></div><div></div><div><b>主题:</b> Re: how to run in xp?</div></div><div> </div><br><div><div> it can run ,but there is still a problem ,nothing in my file.<br>please run the code in xp+python32<br>import urllib.request, urllib.parse, urllib.error<br>exchange=['NASDAQ','NYSE','AMEX']<br>for down in exchange:<br>    url='http://www.nasdaq.com/screening/companies-by-industry.aspx?exchange='+down+'&render=download'<br>    file=urllib.request.urlopen(url).read()<br>    print (file)<br>what you get is:<br></div>>>> <br>b''<br>b''<br>b''<br>>>> <br><br>how to fix it?<br><div style="font:Verdana normal 14px;color:#000;"><div style="FONT-SIZE: 12px;FONT-FAMILY: Arial Narrow;padding:2px 0 2px 0;">------------------ Original ------------------</div><div style="FONT-SIZE: 12px;background:#efefef;padding:8px;"><div id="menu_sender"><b>From: </b> "Peter Otten"<__peter__@web.de>;</div><div><b>Date: </b> Wed, Sep 28, 2011 04:04 PM</div><div><b>To: </b> "python-list"<python-list@python.org>; <wbr></div><div></div><div><b>Subject: </b> Re: how to run in xp?</div></div><div> </div>=?gbk?B?ytjW6rT9zcM=?= wrote:<br><br>> #coding:utf-8<br>> import urllib<br>> exchange=['NASDAQ','NYSE','AMEX']<br>> for down in exchange:<br>>     myfile=open('./'+down,'w')<br>>     url='http://www.nasdaq.com/screening/companies- \ <br>>     by-industry.aspx?exchange='+down+'&render=download'<br>>     file=urllib.urlopen(url).read() myfile.write(file)<br>>     print ('ok',down)<br>>     myfile.close()<br>> <br>> it can run in ubuntu+python2.6 ,when it run in window xp+python32,the<br>> output is Traceback (most recent call last):<br>>   File "C:\Python32\getcode.py", line 8, in <module><br>>     file=urllib.urlopen(url).read()<br>> AttributeError: 'module' object has no attribute 'urlopen'<br>> <br>> i change it into:<br>> #coding:utf-8<br>> import urllib.request<br>> exchange=['NASDAQ','NYSE','AMEX']<br>> for down in exchange:<br>>     myfile=open('./'+down,'w')<br>>     url='http://www.nasdaq.com/screening/companies-by-<br>industry.aspx?exchange='+down+'&render=download'<br>>     file=urllib.request.urlopen(url).read()<br>>     myfile.write(file)<br>>     print ('ok',down)<br>>     myfile.close()<br>> <br>> the output is :<br>> Traceback (most recent call last):<br>>   File "C:\Python32\getcode.py", line 9, in <module><br>>     myfile.write(file)<br>> TypeError: must be str, not bytes<br>> <br>> how to make it run in xp+python32?<br><br>The problem here is the switch from Python 2 to 3. Python 3 has some <br>backwards-incompatible Syntax changes along with changes to classes and <br>library organisation. The good news is that there's a tool, 2to3, that can <br>handle most of these changes:<br><br>$ cat getcode.py<br>#coding:utf-8   <br>import urllib   <br>exchange=['NASDAQ','NYSE','AMEX'] <br>for down in exchange:             <br>    myfile=open('./'+down,'wb')   <br>    url='http://www.nasdaq.com/screening/companies-by-<br>industry.aspx?exchange='+down+'&render=download' <br>    file=urllib.urlopen(url).read()                                                                    <br>    myfile.write(file)                                                                                 <br>    print 'ok', down<br>    myfile.close()<br>$ cp getcode.py getcode3.py<br>$ 2to3-3.2 getcode3.py -w<br>RefactoringTool: Skipping implicit fixer: buffer<br>RefactoringTool: Skipping implicit fixer: idioms<br>RefactoringTool: Skipping implicit fixer: set_literal<br>RefactoringTool: Skipping implicit fixer: ws_comma<br>RefactoringTool: Refactored getcode3.py<br>--- getcode3.py (original)<br>+++ getcode3.py (refactored)<br>@@ -1,10 +1,10 @@<br> #coding:utf-8<br>-import urllib<br>+import urllib.request, urllib.parse, urllib.error<br> exchange=['NASDAQ','NYSE','AMEX']<br> for down in exchange:<br>     myfile=open('./'+down,'wb')<br>     url='http://www.nasdaq.com/screening/companies-by-<br>industry.aspx?exchange='+down+'&render=download'<br>-    file=urllib.urlopen(url).read()<br>+    file=urllib.request.urlopen(url).read()<br>     myfile.write(file)<br>-    print 'ok', down<br>+    print('ok', down)<br>     myfile.close()<br>RefactoringTool: Files that were modified:<br>RefactoringTool: getcode3.py<br>$ cat getcode3.py<br>#coding:utf-8<br>import urllib.request, urllib.parse, urllib.error<br>exchange=['NASDAQ','NYSE','AMEX']<br>for down in exchange:<br>    myfile=open('./'+down,'wb')<br>    url='http://www.nasdaq.com/screening/companies-by-<br>industry.aspx?exchange='+down+'&render=download'<br>    file=urllib.request.urlopen(url).read()<br>    myfile.write(file)<br>    print('ok', down)<br>    myfile.close()<br>$ python3.2 getcode3.py<br>ok NASDAQ<br>ok NYSE<br>ok AMEX<br><br><br>-- <br>http://mail.python.org/mailman/listinfo/python-list<br></div></div></div></includetail></div>