Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Config files

$
0
0
I have a directory called config, which contains a file that has the contents:

documents;2;document id;file_location;
inverted_index;2;key word;list_of_document_id;

I have another directory called data, which contains a file,"documents", which has:

101;d1
102;d2
103;d3
104;d4

when I run my program, I get this error:

Please enter name of configuration file:my_database.txt
['documents', '2', 'document id', 'file_location', '\n']
['inverted_index', '2', 'key word', 'list_of_document_id', '\n']
Traceback (most recent call last):
File "/Users/Hameda/assignment2.py", line 20, in <module>
builtins.IOError: [Errno 2] No such file or directory: './data/inverted_index.txt'

this is happening because the data directory has no file named inverted_index

my question is how do I make my program ignore the second line in the config file??

filename=input("Please enter name of configuration file:")
f = open("./config/"+filename,"r")

#read line in config file

for line in f:
    fields=line.split(";")
    print(fields)
    
    if len(fields)>2:
        documents=fields[0]+".txt"
        
        numAttributes = int(fields[1])
        
        attributes = []
        
        for x in fields[2:]:
            attributes.append(x)        
        
        fin = open("./data/"+documents,"r")

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>