我从java调用python文件
def solve_......(Client_ID,data_folder):
g = open('.........\\'+str(Client_ID)+'\\'+str(data_folder)+'\data_load.log', 'a+')
f= open('...........\\'+str(Client_ID)+'\\'+str(data_folder)+'\conversion\csv\\bom.csv', 'rU')
readfile = csv.reader(f)
bom = [tuple(line) for line in readfile]
Input_Data_df1 = pd.DataFrame(list(bom), columns = ['Material', 'BOM Component', 'Attach Rate', 'Yield', 'Alt. BOM', 'Alternative Item Grp', 'Alternative Priority', 'Usage Probability %', 'Validate From'])
Input_Data_df1['Deletion Flag'] = '0'
Filtered_Data = Input_Data_with_alt_bom_count.drop(Input_Data_with_alt_bom_count[(Input_Data_with_alt_bom_count["Material"] == i) & (Input_Data_with_alt_bom_count["Alt. BOM"] != 1)].index)
pd.options.mode.chained_assignment = None
SP_BOM_Format = Filtered_Data
SP_BOM_Format['Valid To'] = '31.12.9999' ## Added new column 'Valid To' as is not there in Halonix SAP format
required_columns = ['Material', 'BOM Component', 'Attach Rate', 'Yield','Validate From', 'Valid To', 'Deletion Flag']
g.write('777' + "\n")
print 11111111
SP_BOM_Format.to_csv(r'E:\BitBucket\WildFly11.0.0\standalone\dataload\loadedfiles\\'+str(Client_ID)+'\\'+str(data_folder)+'\csv\\bom1.csv',index=False,header = True, columns = required_columns)
print 2222222222
当我从pycharm运行时,py文件正在成功运行,但是当我从java调用py文件时,最后一个语句SP_BOM_Format.to_csv导致问题(没有找到这样的文件),我试图将文件放在该路径中单反斜杠\打印为双\。我的陈述中有什么变化
非常感谢任何帮助,谢谢
答案 0 :(得分:0)
正斜杠(/
)也适用于Windows下的python
。用斜杠替换您的后挡(\
)。此外,始终尝试使用os.path.join
方法管理您的路径:
from os.path import join
variable = 'my folder'
join('e:', 'parent', 'child', variable, 'file.csv')
答案 1 :(得分:0)
导入操作系统 尝试操作。 path.join
try:
outname = 'bom.csv'
outdir = 'E:\BitBucket\WildFly11.0.0\standalone\dataload\loadedfiles\\'+str(Client_ID)+'\\'+str(data_folder)+'\csv'
if not os.path.exists(outdir):
os.mkdir(outdir)
fullname = os.path.join(outdir, outname)
print fullname
SP_BOM_Format.to_csv(fullname)
except Exception as x:
print x