[Tutor] python2 vs python3 urllib
wesley chun
wescpy at gmail.com
Sun Apr 24 06:14:05 CEST 2011
i strongly recommend you consider using the 2to3 tool if porting apps
from 2.x to 3.x... it will show you much more than you may think.
here's the output from the 2.7 version of 2to3:
$ 2to3 test.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: idioms
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: Refactored test.py
--- test.py (original)
+++ test.py (refactored)
@@ -1,5 +1,5 @@
-import urllib
-sock = urllib.urlopen("http://diveintopython.org/")
+import urllib.request, urllib.parse, urllib.error
+sock = urllib.request.urlopen("http://diveintopython.org/")
htmlSource = sock.read()
sock.close()
print (htmlSource)
RefactoringTool: Files that need to be modified:
RefactoringTool: test.py
it shows you the diffs, and if you use the -w option, it will
overwrite (and backup) the 2.x version.
hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python", Prentice Hall, (c)2007,2001
"Python Fundamentals", Prentice Hall, (c)2009
http://corepython.com
wesley.chun : wescpy-gmail.com : @wescpy
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
More information about the Tutor
mailing list