list - How can you use a data created by a python program? -


i've created program gave me list list inside, , want print first element of first list when it, have error tells me list doesn't exist...

my program is:

def prog1():     f=open("dimer.out","r" )     m=open("dimer3.out","w")     g=f.readlines()     k in range(len(g)):         if "molecular orbital" in g[k]:             c=k     n in range(c+1, len(g)):         m.write(g[n])         if "density matrix" in g[n+1]:             break     def readmatrix(numberofrows):         ci = [];         in range(0,numberofrows):             ci.append([]);         f=open("dimer3.out","r")         lines=f.readlines()         numberofblocks = math.ceil(numberofrows / 5)         in range(0,int(numberofblocks)):             j in range(i*(numberofrows+3)+3, i*(numberofrows+3)+3+numberofrows):                 array = re.split('\s+', lines[j])                 k in range(0,len(array)):                     if re.search("\.",array[k]) not none:                         ci[j - 3 - i*(numberofrows+3)].append(array[k])     print('ci = ',ci)     readmatrix(int(26)) 

the error appears when write print(ci[0][0]) after readmatrix(int(26)). question is, how use ci list outside of program.

pass ci argument readmatrix. can declare ci in scope outside function, call readmatrix ci argument , print ci want.

def readmatrix(numberofrows,ci): in range(0,numberofrows):     ci.append([]); f=open("dimer3.out","r") lines=f.readlines() numberofblocks = math.ceil(numberofrows / 5) in range(0,int(numberofblocks)):     j in range(i*(numberofrows+3)+3, i*(numberofrows+3)+3+numberofrows):         array = re.split('\s+', lines[j])         k in range(0,len(array)):             if re.search("\.",array[k]) not none:                 ci[j - 3 - i*(numberofrows+3)].append(array[k]) print('ci = ',ci) readmatrix(int(26))  ci=[] readmatrix(numrows,ci)  print ci 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -