import sys, string
class InputString :
filStack = []
def __init__ (self, Echo=0) :
self.echo = Echo
return
def get (self, prompt) :
while 1 :
if self.filStack :
lin = self.filStack[-1].readline()
if lin == "" :
self.filStack[-1].close()
self.filStack = self.filStack[0:-1]
continue
if self.echo : print prompt, lin,
else :
try : lin = raw_input(prompt)+"\n"
except: return ""
if lin[0] == '#' : continue
elif lin[0] == '@' :
fil = open (lin[1:-1])
self.filStack.append(fil)
continue
else : return lin
class InputWord (InputString) :
def __init__ (self, Echo=0) :
InputString.__init__ (self, Echo)
self.words = []
def get (self, prompt) :
while 1 :
if self.words :
word = self.words[0]
self.words = self.words[1:]
return word
lin = InputString.get(self,prompt)
if lin == "" : return ""
self.words = string.split(lin)
class InputNumber (InputWord) :
def __init__ (self, Echo=0) :
InputWord.__init__ (self, Echo)
def get (self, prompt) :
number = InputWord.get(self,prompt)
if number == "" : return ""
return string.atoi(number)