Пример #1
0
def loadfile(filename):
   "return a list of lines, trailing whitespace removed"
   try:
     f = open(filename)
   except:
     raise source_open_error(filename)
   data = f.readlines()
   f.close()
   for i in range(len(data)):
     data[i]=data[i].rstrip()
   return data
Пример #2
0
  def __init__(self,pass_frame,filename, prefix='', encoding='utf8', **kwds):
    file_source.__init__(*(self,encoding), **kwds)
    self.iflist_index = len(pass_frame.iflist)
    pass_frame.iflist.append([filename,0])
    self.name = filename
    self.pass_frame = pass_frame
    self.process = pass_frame.process
    if 'sources' in self.process.trace:
      self.process.acquire_object(self, 'NAMED FILE SOURCE '+self.name+' ['+encoding+']')

    pathlist, self.basename, self.directory, self.filename =\
      parse_source_filename(filename, prefix)

    try:
      self.file = open(self.filename,'r')
      self.closed = 0
    except:
      raise source_open_error(filename)