Python Forum
File path by adding various variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File path by adding various variables
#3
You are not allowed to end a string literal with an odd number of backslashes. It doesn't matter if the string is raw or not. So if you need a single backslash at the end of a string, you cannot use a raw string.
FPath = "C:\\Users\\mishal.mohanlal\\Desktop\\"   # this works
Among the other options mentioned (I like pathlib the best), you can also use forward slashes. This will work as a file path in windows even though windows uses backslashes in file paths. Python fixes the separator when opening a file. It addition to avoiding the escape sequence nightmare, this lets you write code that runs on windows an linux.
FPath = "C:/Users/mishal.mohanlal/Desktop/"
Reply


Messages In This Thread
RE: File path by adding various variables - by deanhystad - Apr-28-2023, 07:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  import a function from another file using relative path paul18fr 6 2,750 Aug-01-2024, 06:40 AM
Last Post: paul18fr
  Script File Failure-Path Error? jerryf 13 7,300 Nov-30-2022, 09:58 AM
Last Post: jerryf
  Storing variables into one file for use in multiple Jupyter notebooks devansing 1 2,715 Feb-05-2022, 10:04 AM
Last Post: ibreeden
  Adding to an XML file TeXaSpEtE83 0 1,798 Dec-22-2021, 08:28 AM
Last Post: TeXaSpEtE83
Bug how can i adding custom path for saving the zip_file demonvictor 1 2,158 Oct-09-2021, 09:37 AM
Last Post: snippsat
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 3,129 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Subprocess.Popen() not working when reading file path from csv file herwin 13 23,698 May-07-2021, 03:26 PM
Last Post: herwin
  variables vcnt, ocnt, and mcnt adding previous values and not resetting to 0 archanut 2 2,856 Feb-12-2021, 06:56 PM
Last Post: deanhystad
  Add file to sys.path permanently hcccs 5 13,972 Jan-31-2021, 11:26 AM
Last Post: hcccs
  How to rename a CSV file by adding MODIFIED in the filename? Python_User 25 13,006 Dec-13-2020, 12:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020