New file in same directory as input file . Python

徘徊边缘 提交于 2019-12-20 07:16:50

问题


import sys,os

name_list = open(sys.argv[1]).read().split('\r')

os.remove(sys.argv[1])

input_file = (sys.argv[2])

def Extractor(input,output='query.txt'):
    query = open(input,'r').read().split('\r')

    dir,file=os.path.split(input)
    temp_out= os.path.join(dir,output)
    out_file=open(temp_out,'w')

print Extractor(input_file)

I have no idea why this isn't working . . .

i am trying to create a new file in the same directory as the input file but it is saying that there is an error . i'm not used to working in Automator's workflow but theoretically this should work since i've used this in python interpreters .

input_file = (sys.argv2) is a string of the file location . when i print the query inside of the function it works fine but once i get to "dir,file = os.path.split(input)" that's where the function fails .

Why isn't this working ?

Error message from Automator isn't telling me much . . .:

来源:https://stackoverflow.com/questions/18970231/new-file-in-same-directory-as-input-file-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!