4

I am using python 2.7 and am running into an error message. I am following a tutorial and am not sure if my error is because of the version of python I am using.

HostIP = input("Enter Host IP: ")

I get a syntax error once I add the second period. 192.168 gives no error. 192.168. - error begins. I am trying to write a script that will be using the socket module. Any guidance would be helpful.

Thank You!

admdrew
  • 3,790
  • 4
  • 27
  • 39
user2565554
  • 447
  • 4
  • 13
  • 22

1 Answers1

3

You are using python2.7 in which, the input method instantly does eval() on the input. Use raw_input instead to get the string:

HostIP = raw_input("Enter Host IP: ")

input in python3 works similar to python2's raw_input in that it gives you a string but input in python2 tries to evaluate the input.

Therefore, when you input 192.168, it immediately converts that to double however, when you do 192.168., it is unable to recognize it and thus raises an error.

Hope that helps

sshashank124
  • 31,495
  • 9
  • 67
  • 76