I have the following python code in python 2.7.3 , i had recently using a new laptop which has python 3.3 , I don't think I should downgrade back to python 2.7.3 . The code is
:-
nm = input(“enter file name “)
str = raw_input(“enter ur text here: \n”)
f = open(nm,”w”)
f.write(str)
f.close()
print “1.See the file\n”
print “2.Exit\n”
s = input(“enter ur choice “)
if s == 1 :
fi = open(nm,”r”)
cont = fi.readlines()
for i in cont:
print i
else :
print “thank you “
Please tell me what are the changes i should make so that it runs easily without any error .
raw_input()
does not exist in Python 3, use input()
instead:
str = input("enter ur text here: \n")
input()
does not evaluate the value it parses in Python 3, use eval(input())
instead:
s = eval(input("enter ur choice "))
print()
is a function in Python 3 (it was a statement in Python 2), so you have to call it:
print("1.See the file\n")
print("2.Exit\n")
print(i)
print("thank you ")
raw_input()
becomes
input()
and
print " "
becomes
print()
Hope this helped, but more information on converting can be found at http://python3porting.com/ :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With