我正在从Visual C窗体调用python文件。单击C#中的按钮将调用Python脚本。python脚本将使用配置文件连接到数据库并提供结果。你知道吗
如果我自己调用Python程序,它工作得很好。当我从visualc调用时,问题就出现了。 我的Python代码是这样的:
def db_Connection():
logger.info(':Entering db_Connection().....')
logger.info(':Config file read.....')
config = ConfigParser.RawConfigParser()
config.read('config.cfg')
logger.info(':Config file read complete.....')
USER = config.get('DB_Connector','db.user_name' )
logger.info(':USER acquired.....')
PASSWORD = config.get('DB_Connector','db.password' )
SID = config.get('DB_Connector','db.SID' )
IP = config.get('DB_Connector','db.IP')
PORT = config.get('DB_Connector','db.Port')
engine = create_engine('oracle://{user}:{pwd}@{ip}:{port}/{sid}'.format(user=USER, pwd=PASSWORD, ip=IP, port=PORT, sid=SID), echo=False)
connection = engine.connect()
logger.info(':Connected to DB.....')
p = engine.execute("SELECT * from VAM.ASSET where ASSET_ID = '{}'".format(asset_id))
logger.info(':Calculating for any records.....')
if len(p.fetchall())!=0:
print 'Asset Exists'
看看日志,最后一行是
2015-04-28 15:40:47,361 INFO :Config file read complete.....
我怎么解决这个问题?你知道吗
根据您如何启动C程序以及它如何启动Python脚本,当前目录可能不是您所期望的。你知道吗
在这种情况下,您应该为
config.cfg
使用完整路径而不是相对路径:相关问题 更多 >
编程相关推荐