diff --git a/index.html b/index.html index 02f1b6f..d5d5190 100644 --- a/index.html +++ b/index.html @@ -255,57 +255,61 @@ h3{margin-left:3.5em}
2to3print statementhas_key() dictionary methodhttp packageurllib packagedbm packagexmlrpc packagefilter() global functionmap() global functionreduce() global function (3.1+)apply() global functionintern() global functionexec statementexecfile statement (3.1+)repr literals (backticks)try...except statementraise statementthrow statementlong data typexrange() global functionraw_input() and input() global functionsfunc_* function attributesxreadlines() I/O methodlambda functions with multiple parametersnext() iterator method__nonzero__ special class attributesys.maxintunicode() global functioncallable() global functionzip() global functionStandardError() exceptiontypes module constantsisinstance global function (3.1+)basestring datatypeitertools modulesys.exc_type, sys.exc_value, sys.exc_tracebackos.getcwdu() functionset() literalsbuffer() global functionprint statement
+unicode() global function
+long data type
+has_key() dictionary method
+http
+urllib
+dbm
+xmlrpc
+next() iterator method
+filter() global function
+map() global function
+reduce() global function (3.1+)
+apply() global function
+intern() global function
+exec statement
+execfile statement (3.1+)
+repr literals (backticks)
+try...except statement
+raise statement
+throw statement
+xrange() global function
+raw_input() and input() global functions
+func_* function attributes
+xreadlines() I/O method
+lambda functions with multiple parameters
+__nonzero__ special class attribute
+sys.maxint
+callable() global function
+zip() global function
+StandardError() exception
+types module constants
+isinstance() global function (3.1+)
+basestring datatype
+itertools module
+sys.exc_type, sys.exc_value, sys.exc_traceback
+os.getcwdu() function
+set() literals (explicit)
+buffer() global function (explicit)
+This site is optimized for Lynx just because fuck you.
I’m told it also looks good in graphical browsers.
© 2001-4, 2009 ℳark Pilgrim, CC-BY-3.0 diff --git a/porting-code-to-python-3-with-2to3.html b/porting-code-to-python-3-with-2to3.html index 6c3bb1a..ad3f6ad 100644 --- a/porting-code-to-python-3-with-2to3.html +++ b/porting-code-to-python-3-with-2to3.html @@ -9,7 +9,6 @@ h1:before{counter-increment:h1;content:"Appendix A. "} h2:before{counter-increment:h2;content:"A." counter(h2) ". "} h3:before{counter-increment:h3;content:"A." counter(h2) "." counter(h3) ". "} -td{font-family:monospaced}
@@ -674,7 +673,7 @@ except:You should never use a fallback to catch all exceptions when importing modules (or most other times). Doing so will catch things like KeyboardInterrupt (if the user pressed Ctrl-C to interrupt the program) and can make it more difficult to debug errors.
raise statementFIXME intro +
The syntax for raising your own exceptions has changed slightly between Python 2 and Python 3.
| Notes | @@ -682,19 +681,23 @@ except:Python 3 | |
|---|---|---|
| ① | +raise MyException |
+unchanged |
| ② | raise MyException, "error message" |
raise MyException("error message") |
| ② | +||
| ③ | raise MyException, "error message", a_traceback |
raise MyException("error message").with_traceback(a_traceback) |
| ③ | +||
| ④ | raise "error message" |
unsupported |
2to3 will warn you that it was unable to fix this automatically.
throw statementFIXME intro @@ -751,7 +754,7 @@ except:
sum() function will also work with an iterator, so 2to3 makes no changes here either. Like dictionary methods that return views instead of lists, this applies to min(), max(), sum(), list(), tuple(), set(), sorted(), any(), and all().
raw_input() and input() global functionsFIXME intro +
Python 2 had two global functions for asking the user for input on the command line. The first, called input(), expected the user to enter a Python expression (and returned the result). The second, called raw_input(), just returned whatever the user typed. This was wildly confusing for beginners and wildly regarded as a “wart” in the language. Python 3 excises this wart by renaming raw_input() to input(), so it works the way everyone naively expects it to work.
| Notes | @@ -767,15 +770,11 @@ except:||
|---|---|---|
| ③ | input() |
eval(input()) |
| ④ | -input("prompt") |
-eval(input("prompt")) |
raw_input() becomes input().
+raw_input() function could take a prompt as a parameter. This has been retained in Python 3.
+input() function and pass the result to eval().
func_* function attributesFIXME intro