-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_2to3.py
99 lines (71 loc) · 1.64 KB
/
test_2to3.py
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
print response
# string formats
response = "variable {} equals {}".format(i,o)
print response
# types
byte_form = 0222
print(type(10) is type(10L)) # Python 2 has two different kinds of integer
# division not casts to a float by default
print 5/2
print 5//2
# some functions are now just generators
a = range(5)
print a
b = map(float,a)
print b
print zip(a,b)
mydict = {'pi':3.14159,'c':3e8,'e':2.7183}
mydict.iterkeys()
mydict.keys()
for i in range(5):
print(i)
# changed this method
mydict.has_key('a')
# no more basestring
if isinstance("mystring",basestring):
print("hello string")
# package renaming
# package support. pyport middy.
# __init__
# callable 3.1
fxn = lambda x:2*x
if callable(fxn):
print("lambda function is callable")
# converts syntax
pi = 3.1415
pi <> 5
def fxn (a,b):
return a+b
# enforce True and False as keywords
# True = 0
# False = 1
len = 3 # gotcha warning!
# new style classes
class MyClass:
pass
class MyType (object):
pass
print type(MyClass)
print type(MyType)
# error handling
try:
1/0
except ZeroDivisionError,e:
print(e)
# END with other tips and tricks
# inpsect, dictionaries as matching?, *args**kwargs,