Python Forum
here is another 2.7 to 3.5 convert
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
here is another 2.7 to 3.5 convert
#2
(Oct-21-2016, 04:37 PM)Blue Dog Wrote: What way is the best to convert the code?
Actually knowing Python help Wink
and what's the difference is between 2 and 3 it's not so much work to convert short code like this.
Use 2to3 it dos a pretty good job.
(Oct-21-2016, 04:37 PM)Blue Dog Wrote: I think this part is the problem:
>>> host = 'google.com'
>>> remote_ip = '111.111.111'
>>> print ('Ip address of ') + host + ' is ' + remote_ip
Ip address of 
Traceback (most recent call last):
 File "<string>", line 301, in runcode
 File "<interactive input>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

# Fix
>>> print('Ip address of ' + host + ' is ' + remote_ip)
Ip address of google.com is 111.111.111

>>> # Better
>>> print('Ip address of {} is {}'.format(host, remote_ip))
Ip address of google.com is 111.111.111
Reply


Messages In This Thread
here is another 2.7 to 3.5 convert - by Blue Dog - Oct-21-2016, 04:37 PM
RE: here is another 2.7 to 3.5 convert - by snippsat - Oct-21-2016, 04:53 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020