Actually I am stuck in my work. I want to import a txt file into my python program which should have two lists of intergers.
The following program is working fine but I need to import the list 'a' and 'b' with the help of configparser.
It will be so nice if some one help me with it!
I am a begineer in python so please try to answer in an easy way...!
The program is as follow:
a=[5e6,6e6,7e6,8e6,8.5e6,9e6,9.5e6,10e6,11e6,12e6]
p=[0.0,0.001,0.002,0.003,0.004,0.005,0.006,0.007,0.008,0.009,0.01,0.015,0.05,0.1,0.15,0.2]
b=0
x=0
while b<=10:
c=a[b]
x=0
print '\there is the outer loop\n',c
while x<=15:
k=p[x]
print'here is the inner loop\n',k
x=x+1
b=b+1
Seems like ConfigParser is not the best tool for the job. You may implement the parsing logic youself something like:
a, b = [], []
with open('myfile', 'r') as f:
for num, line in enumerate(f.readlines()):
if num >= 10:
b.push(line)
else:
a.push(line)
or you can make up some other logic to devide the lists in your file. It depends on the way you want to represent it in you file