I am relatively new in python, hence decided to learn python3. But, now, I realize, that is not implemented in many other machine. So, I need to change it, for python2. In the machine in question, we have:
Python 2.6.8 (unknown, Sep 27 2013, 16:07:59)
So, I am facing a problem of transfering this part:
beta = []
inb = input("Betah\n")
if inb == "/":
betah = "0.1 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 10.0 15.0 20.0 25.0 200.0"
else:
betah = inb
beta = betah.split(" ")
which is giving error:
beta = betah.split(" ")
AttributeError: 'float' object has no attribute 'split'
is it possible to write this part so that it works both in python2
and 3
?
Python 3's input()
is called raw_input()
in Python 2; use the latter on Python 2.
Assign either name to a new one based on what is available:
try:
# Python 2
userinput = raw_input
except NameError:
# Python 3
userinput = input
inb = userinput("Betah\n")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.