Issue
I have 2 Python scripts which are main_menu.py and inputip.py.
The problem occurs when I press "enter" to be redirected to main_menu.py when my function finishes in inputip.py. The script does not allow me to redirect to main_menu.py instead it shows this error on the Windows command prompt:
Traceback (most recent call last):
File "C:\python\main_menu.py", line 32, in ?
execfile('C:\python\Inputip.py')
File "C:\python\Inputip.py", line 11, in ?
input ("\nSelect enter to proceed back to Main Menu\n")
File "<string>", line 0
^ SyntaxError: unexpected EOF while parsing
Here are my codes (main_menu.py):
def menu():
#print what options you have
print "Welcome to Simple Network Program"
print " "
print "Please enter a following option to proceed"
print " "
print "2) View Personal IP Address"
print " "
return input ("Select an Option here: ")
loop = 1
choice = 0
while loop == 1:
choice = menu()
if choice == 1:
execfile('Inputip.py')
elif choice == 5:
loop = 0
print "Thank you for using the Simple Network Program!"
The code (inputip.py):
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
import socket
import os
print ("\n\n"+socket.gethostbyname(socket.gethostname()))
input ("\nSelect enter to proceed back to Main Menu\n")
execfile('C:\python\main_menu.py')
The error seems to be pointing to the execfile. Some advice on the codes would be great. Thanks!
Solution
Unless you are using python 3.x (but your question is not tagged as such), don't use input. Use raw_input in stead. It will return strings, so convert them to int first, or do a string comparison. E.g.
x = raw_input("Choice")
if x == '1':
do_this()
Answered By - Ivo van der Wijk
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.