Replace \ with / With an Inputted Directory in Python -


i trying replace inputted paths' "\" "/" avoid escaping character messes code.

path = input("enter directory: ) path.replace('\' , '/') 

first off reason want because when user inputs path (copying , pasting windows explorer), in c:\user\folder convention giving me issues later on in program when have output real path , gives me c:\user\folder double "\" because of raw string method.

my path.replace() not working because '\' thinking escaping character. tried:

path.replace((r'\'), '/') 

but entire input turns string , not work. have advice this, or way inputted path copied have / instead of \? thanks!

replace returns copy of string, you'll need assign result variable

path = input("enter directory: ") path = path.replace('\\' , '/') 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -