(Before you click "Duplicate", none of the solutions on ANY of the others work)
I am working in Python 2.7.11, trying to convert my code from Python 3.5. I managed to remove all the syntax errors, apart from this annoying one.
NameError: global name 'fileinput' is not defined
Here is my code (The ENTIRETY):
from fileinput import *
from sys import *
callingstops=[]
def Main_Menu ():
print'----------------------------------------------------------------------------------------------------------------------------'
print'RAILWAY SCHEDULE AND DISPATCHING SYSTEM V1.1 - PROVIDED BY ROBSKI'
print'\n'
print'Please choose one of the options:'
print'1) Check Schedule'
print'2) Add schedule'
print'3) Enter Delays Report'
print'4) Delete Schedule'
print''
print'0) EXIT'
Option = int(raw_input("==> "))
if Option == 1:
checkschedule()
if Option == 2:
addschedule()
if Option == 3:
delays()
if Option == 4:
delete()
else:
sys.exit
def checkschedule ():
file = open("Schedule.txt", "r")
Scheduledetails = file.read()
file.close()
print'--------------------------------------------------------------------------------------------------------------------------------'
print(Scheduledetails)
Main_Menu()
def addschedule ():
user1 = raw_input('Enter time in xxxx format: ')
dest = raw_input('Enter Destination of train: ')
op = raw_input('Enter NR Operator Abbreviaton: ')
long = raw_input('Enter number of carriages: ')
notes = raw_input('Remarks (Running days etc.): ')
callingno = int(raw_input('How much calling points are there? (NOT CHANGEABLE): '))
for i in range(0,callingno):
callingstops=[]
callingstops.append(raw_input('Enter the name of stop '+str(i+1)+' (If your stop is a request, put "(r)" at the end): '))
file = open("Schedule.txt", "a")
file.write ("\n\n | Time: "+user1+"\n | Destination: "+dest+"\n | Operator Abbreviation: "+op+"\n | No. of carriages: "+long+"\n | Remarks: "+notes)
for item in callingstops:
file.write("\n | Calling at: "+item)
file.close()
Main_Menu()
def delays ():
delaytitle = raw_input("Enter title of delay (Will be saved in seperate doc, overrides any other file with same name): ")
delaydesc = raw_input("Enter description of delay in detail: ")
file = open(delaytitle+".txt", "w")
file.write("Delay report:\n"+delaydesc)
file.close()
def delete ():
train = raw_input("Enter the train time that you want to remove (You MUST have the file closed): ")
train = train.strip()
train_found_on = None # Rememberes which line the train time is located
for i, line in enumerate(fileinput.fileinput('Schedule.txt', inplace=1)): # Open the file for in-place writing
if 'Time:' in line and train in line: # Don't transfer the lines which match input
train_found_on = i
continue
if train_found_on and i < (train_found_on + 7): # Neither the lines after that
continue
sys.stdout.write(line) # But write the others
Main_Menu()
Main_Menu()
(In case you are wondering, I am converting to be able to use py2exe. I failed with PyInstaller)