Python Forum
Why wont this path work one way, but will the other way?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why wont this path work one way, but will the other way?
#1
Im trying to run a python script using this as one of the paths to a text file that it needs in order to process

This wont work
\\server01\it\RegisterPing\Lists\Register.txt
But if i map that same path then it works
I:\RegisterPing\Lists\Register.txt
Right now this works because im running it on my pc and can map the drive, but this script is going to be moved to a server where they dont want mapped drives. Does python not work with the full server path as in the first example.
Reply
#2
Don't use "\" in file descriptors. Use "/". "\" can be used as a separator in a file descriptor, but it can also be used to as the start of an escape sequence in a string literal. In your example, "\\" is being ireplaced with "\", the first backslash telling Python to treat the next backslash as a backslash character.

You could do this: \\\\server01\\it\\RegisterPing\\Lists\\Register.txt, but that just looks silly. Instead use: //server01/it/RegisterPing/Lists/Register.txt

You got lucky (or unlucky depending on your point of view) that I:\RegisterPing\Lists\Register.txt worked. if any of the folders started with b, f, n, x, t, o or x, the backslash would have been used as an escape character (\n for new line).
Reply
#3
man oh man lol

thank you for pointing out the issues and reasons for not working as expected. Ill make the changes and retest.

thanks again.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,881 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,241 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Why wont subprocess call work? steve_shambles 3 2,712 Apr-28-2020, 03:06 PM
Last Post: steve_shambles
  When I import a Module it wont run PyNovice 17 6,553 Oct-26-2019, 11:14 AM
Last Post: PyNovice
  Why wont this work? ejected 2 3,240 Mar-29-2019, 05:33 AM
Last Post: snippsat
  wont print last sentence.. mitmit293 2 2,427 Jan-27-2019, 05:38 PM
Last Post: aakashjha001
  Why wont this work :( Nonagon 2 3,048 Nov-03-2018, 03:38 AM
Last Post: wavic
  How does pathlib.Path.rename work? wavic 7 16,982 Aug-02-2018, 10:58 AM
Last Post: wavic
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,813 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  Boolean Wont Work fierygaming 5 4,281 Jun-13-2018, 07:49 PM
Last Post: fierygaming

Forum Jump:

User Panel Messages

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