Uh oh!
There was an error while loading. Please reload this page.
forked from earthastronaut/Python2to3
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_2to3.py
More file actions
Latest commit
99 lines (71 loc) · 1.64 KB
/
Copy pathtest_2to3.py
File metadata and controls
99 lines (71 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
PURPOSE: This file was made to test the command line utility 2to3 which assists
in converting python 2 to python 3 code.
AUTHOR: Dylan Gregersen
DATE: Fri Oct 17 16:08:03 2014
"""
# `raw_input` is now use `input`
choose=raw_input("Please enter your name : ")
i=2
o=input("input the letter i : ")
# % for formatting not supported
response="Your name is %s"%choose
# print statement is not a function not a keyword
printresponse
# string formats
response="variable {} equals {}".format(i,o)
printresponse
# types
byte_form=0222
print(type(10) istype(10L)) # Python 2 has two different kinds of integer
# division not casts to a float by default
print5/2
print5//2
# some functions are now just generators
a=range(5)
printa
b=map(float,a)
printb
printzip(a,b)
mydict= {'pi':3.14159,'c':3e8,'e':2.7183}
mydict.iterkeys()
mydict.keys()
foriinrange(5):
print(i)
# changed this method
mydict.has_key('a')
# no more basestring
ifisinstance("mystring",basestring):
print("hello string")
# package renaming
# package support. pyport middy.
# __init__
# callable 3.1
fxn=lambdax:2*x
ifcallable(fxn):
print("lambda function is callable")
# converts syntax
pi=3.1415
pi<>5
deffxn (a,b):
returna+b
# enforce True and False as keywords
# True = 0
# False = 1
len=3# gotcha warning!
# new style classes
classMyClass:
pass
classMyType (object):
pass
printtype(MyClass)
printtype(MyType)
# error handling
try:
1/0
exceptZeroDivisionError,e:
print(e)
# END with other tips and tricks
# inpsect, dictionaries as matching?, *args**kwargs,