Search code examples
pythonpathdouble-quotessingle-quotes

How can I use the input function to ask for the Pathname and save it within double quotes instead of single quotes?


I have this line of code: pathname = input("Insert path of h5 file here: ") When I run this line, I paste the Pathname I wish and then that is passed in the pathname variable.

When I type pathname on my console to see what has been passed I see that the path of the file has been passed with single quotes like... 'pathname' whereas I want to save it in the pathname variable with double quotes like... "pathname".

I've tried many things such as using the .replace() function but that didn't work.


Solution

  • Why do you need to do this? Python should be able to open a file by pathname regardless of whether it is shown in the console with single or double quotes. The single quotes in the console just show that the value of pathname is a string. If you really want to store literal double quote characters inside your pathname variable then you can provide them with an escape character as " instead of " which will save a literal double quote character.