-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_2to3.py
163 lines (110 loc) · 2.41 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# print()
########
print "Howdy, Earth!"
with open('out.log', 'w') as f:
print >>f, "This redirects to a log file"
print "Ending with a coma skips the line break",
# range() and xrange()
#######################
for x in (range(2) + [3]):
print(x)
for x in xrange(3):
print(x)
# map() and filter()
#####################
def is_even(num):
return num % 2 == 0
def power_of_2(num):
return num * num
# This is going to be badly converted
map(power_of_2, filter(is_even, range(10)))[:4]
# You should change that manually to:
# [x * x for x in range(10) if x % 2 == 0][:4]
# reduce()
#########
def multiply(a, b):
return a * b
reduce(multiply, range(1, 11))
# zip() and enumerate()
####################
fruits = ["Memberberries", "Gomu Gomu no Mi", "Senzus Beans"]
is_fruit = [True, True, False]
for f, status in zip(fruits, is_fruit)[:2]:
print(f, status)
for num, f in enumerate(fruits)[:2]:
print(num, f)
# input() and raw_input()
##########################
res = input("test")
res = raw_input('test')
# cmp()
########
# This is NOT going to be fixed:
famous_last_words = [
"Yippee ki-yay",
"Kawabunga",
"Kamehameha",
]
def compare(first, second):
if len(first) > len(second):
return 1
elif len(first) < len(second):
return -1
else:
return 0
sorted(famous_last_words, cmp=compare)
# long()
########
a = long(1)
# apply()
########
def marvelous_function(param1, param2, like_param2_but_better):
print(param1)
print(param2)
print(like_param2_but_better)
positional_params = ['First', 'Second']
keyword_argument_params = {"like_param2_but_better": "Best"}
apply(marvelous_function, positional_params, keyword_argument_params)
# execfile()
###########
execfile("some_module.py")
# reload()
###########
# This is not going to be converted
reload('os')
# buffer()
############
# This is not going to be converted
buffer("azertyuiop", 3, 7)
# coerce()
###########
# This is not going to be fixed.
coerce(1, 1.3)
# file()
########
# This is not going to be fixed
file('test')
# intern()
###########
intern("test")
# callable()
#############
callable(str)
# dict
########
d = {}
d.viewsitems()[0]
d.has_key('test')
# division
###########
# This won't be converted
1 / 2
# Exceptions
###############
raise "Woops!"
raise TypeError, "Woops!"
raise StandardError("Woops")
try:
1 / 0
except ImportError, ZeroDivisionError:
return 42