使用文本文件中的变量作为输入

时间:2016-03-16 16:47:17

标签: python input text-files var

正如话题所说..

我想使用文件

indata.txt:

f=lambda x,y:-2*x*y
xa=0
xb=2
A=2 
n=18

进入我的大项目:

from math import *

'''Function which calculates the d.e. using runge-kuttas formula'''
def runge(f,xa,xb,A,n):
    .....



indata=open("indata.txt","r")
runge(f,xa,xb,A,n)
indata.close()

所以我的问题是: 如何使用文本文件indata.txt中的变量作为更大程序的输入?

1 个答案:

答案 0 :(得分:0)

据我所知,您可以使用以下两种方法之一:
 1.如评论和主文件中所述,将文件重命名为inpdata.py

from inpdata import *
  1. 使用内置的python execfile() function。对于Python3 execfile()替代外观here