I am having a similar noob problem.
Setup:
I'm calling the python script with arguments from a different program through the command prompt (this other program does not offer full python integration)
This other program collects a file path, turns it into a string variable and passes it to the python script through an argument
The original path comes with a single slash syntax. The python script wants it as a double slash syntax, but I don't know how to convert it.
any help would be appreciated
Here are my tests
Setup:
I'm calling the python script with arguments from a different program through the command prompt (this other program does not offer full python integration)
This other program collects a file path, turns it into a string variable and passes it to the python script through an argument
The original path comes with a single slash syntax. The python script wants it as a double slash syntax, but I don't know how to convert it.
any help would be appreciated
Here are my tests
import os import re s="C:\Users\alex.ogata\Desktop\test001" encode=s.encode('unicode-escape') #r1= re(s) r2= repr(s) r3= re.escape(s) ospath = os.path.normpath(s) st = str(s) newStr=s.replace(chr(92),"\\") print s print encode #print r1 print r2 print ospath print st print newStr print "this is what I want" + r"C:\\Users\\alex.ogata\\Desktop\\test001" this is the python script for reference # these are the arguments coming int scriptname, imagePathIn=argv #this is not working imagePath = re.escape(imagePathIn) filenames = [f for f in listdir(imagePath) if isfile(join(imagePath, f))] print(filenames) print imagePath def get_filepaths(directory): file_paths = for root, directories, files in os.walk(directory): for filename in files: # Join the two strings in order to form the full filepath. filepath = os.path.join(root, filename) file_paths.append(filepath) # Add it to the list. return file_paths fileList= get_filepaths (imagePath)
User has been warned for this post. Reason: Hijack thread, no BBcode