Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print a File Path ?
#2
The okay ways.
>>> print(r"C:\User\Astrikor\Dataset")
C:\User\Astrikor\Dataset
>>> print("C:/User/Astrikor/Dataset")
C:/User/Astrikor/Dataset
>>> print("C:\\User\\Astrikor\\Dataset")
C:\User\Astrikor\Dataset
Never a singel \ in path for Window,because of escape character.
In case over the problem is \U which gives unicodeescape error.

A other example will never find top folder,because \t Horizontal Tab(TAB).
>>> s = 'C:\top'
>>> s
'C:\top'
>>> print(s)
C:	op
>>> 
>>> # Fix
>>> s = r'C:\top'
>>> s
'C:\\top'
>>> print(s)
C:\top
Reply


Messages In This Thread
How to print a File Path ? - by Astrikor - Sep-24-2018, 09:39 AM
RE: How to print a File Path ? - by snippsat - Sep-24-2018, 09:54 AM
RE: How to print a File Path ? - by wavic - Sep-24-2018, 09:56 AM
RE: How to print a File Path ? - by Astrikor - Sep-24-2018, 10:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  File path by adding various variables Mishal0488 2 1,091 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  Script File Failure-Path Error? jerryf 13 3,569 Nov-30-2022, 09:58 AM
Last Post: jerryf
  Saving the print result in a text file Calli 8 1,908 Sep-25-2022, 06:38 PM
Last Post: snippsat
  failing to print not matched lines from second file tester_V 14 6,238 Apr-05-2022, 11:56 AM
Last Post: codinglearner
  Print to a New Line when Appending File DaveG 0 1,247 Mar-30-2022, 04:14 AM
Last Post: DaveG
Sad Want to Save Print output in csv file Rasedul 5 11,142 Jan-11-2022, 07:04 PM
Last Post: snippsat
  Convert legacy print file to XLSX file davidm 1 1,836 Oct-17-2021, 05:08 AM
Last Post: davidm
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,251 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Why it does not print(file.read()) Rejaul84 1 2,378 Jul-01-2021, 10:37 PM
Last Post: bowlofred
  Subprocess.Popen() not working when reading file path from csv file herwin 13 15,326 May-07-2021, 03:26 PM
Last Post: herwin

Forum Jump:

User Panel Messages

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