May-04-2021, 03:26 PM
(May-04-2021, 08:28 AM)ibreeden Wrote:(May-03-2021, 07:51 PM)herwin Wrote: In the new code
print(prg)will give:
so the correct value is read into the variable.
Output:C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe
No it is not correct. The path should be: "C:\Program Files\Google\Chrome\Application\chrome.exe", so without the double backlashes.
The backslash has a special meaning in Python. So to assign a string literal with backslashes you have to double the backslash to make clear you really mean one backslash.
>>> prg = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe' >>> print(prg) C:\Program Files\Google\Chrome\Application\chrome.exeSo "prg" will contain only single backslashes.
Nowadays a more popular way to assign such a variable is to assign a raw string by putting an "r" before the string literal.
>>> prg = r'C:\Program Files\Google\Chrome\Application\chrome.exe' >>> print(prg) C:\Program Files\Google\Chrome\Application\chrome.exeSo make sure you get rid of the double backslashes.
Thank you for your response and suggestions.
I have tried with the single and double backslashes in the csv file. The error message stays the same in both cases.
How do I read the values from the csv file into the prg variable as a raw string?