Logo Search packages:      
Sourcecode: relational version File versions  Download package

def relational::relation::relation::__init__ (   self,
  filename = "",
  comma_separated = True 
)
Creates a relation, accepts a filename and then it will load the relation from
that file. If no parameter is supplied an empty relation is created. Empty
relations are used in internal operations.
By default the file will be handled like a comma separated as described in
RFC4180, but it can also be handled like a space separated file (previous
default format) setting to false the 2nd parameter.
The old format is deprecated since it doesn't permit fields
with spaces, you should avoid using it.

Definition at line 28 of file relation.py.

                                                       :
        '''Creates a relation, accepts a filename and then it will load the relation from
        that file. If no parameter is supplied an empty relation is created. Empty
        relations are used in internal operations.
        By default the file will be handled like a comma separated as described in
        RFC4180, but it can also be handled like a space separated file (previous
        default format) setting to false the 2nd parameter.
        The old format is deprecated since it doesn't permit fields
        with spaces, you should avoid using it.'''
        if len(filename)==0:#Empty relation
            self.content=[]
            self.header=header([])
            return
        #Opening file
        fp=file(filename)
        if comma_separated:
            reader=csv.reader(fp) #Creating a csv reader
            self.header=header(reader.next()) # read 1st line
            self.content=[]
            for i in reader.__iter__(): #Iterating rows
                self.content.append(i)
        else: #Old format
            self.header=header(fp.readline().replace("\n","").strip().split(" "))
        
            self.content=[]
            row=fp.readline()
            while len(row)!=0:#Reads the content of the relation
                self.content.append(row.replace("\n","").strip().split(" "))
                row=fp.readline()
        
        #Closing file
        fp.close()
        
    

Generated by  Doxygen 1.6.0   Back to index