2

All,

I wrote a small python program to create a file which is used as an input file to run an external program called srce3d. Here it is:

   fin = open('eff.pwr.template','r')  
   fout = open('eff.pwr','wr')  
   for line in fin:
      if 'li' in line:
        fout.write( line.replace('-2.000000E+00', `-15.0`) )
      else: 
        fout.write(line)
   fin.close
   fout.close    
   os.chmod('eff.pwr',0744)
# call srce3d
   os.system("srce3d -bat -pwr eff.pwr >& junk.out")

This does not work. The input file gets written properly but srce3d complains of an end of file during read. The os.system command works fine with a pre-existing file, without any need to open that file.

Thanks for your help

2 Answers 2

4

Firstly you are missing the function calls for close.

 fin.close() ## the round braces () were missing.
 fout.close()

A better way to do the same is using contexts.

    with open('eff.pwr.template','r') as fin, open('eff.pwr','wr') as fout:
       ## do all processing here
Sign up to request clarification or add additional context in comments.

Comments

1

You didn't actually close the file – you have to call file.close. So,

fin.close
fout.close

should be

fin.close()
fout.close()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.