#SteeringParams.py
import csv
def GetSteeringParams(x):
steeringdict = {'steeringsymbol':'steeringparam'}
with open("/Users/xyz/Documents/CI-data/steeringdict.csv","r") as paramsfile:
paramline = csv.reader(paramsfile, delimiter=',')
for row in paramline:
if len(row) > 0:
steeringdict[row[0]] = row[1]
paramsfile.close()
return steeringdict
if __name__ == "__main__":
print GetSteeringParams(0)
此代码将一组转向参数导入字典。像冠军一样工作。 接下来我要做的是将其作为模块导入,如下所示:
import csv
from SteeringParams import *
print GetSteeringParams(0)
它返回:
NameError:未定义全局名称'csv'
两个脚本都从同一目录运行。即使我(也)全局导入csv我得到这个NameError返回。如何解释以及如何导入和运行“SteeringParams.py”作为模块?