Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extra slashes in path
#1
Hi,
This is strange, Confused I have extra slashes in a 'path'.
I do not understand how it could happen. Undecided
I have a Host list, I'm iterating over it and adding a "path" to each name,
I'm going to download files from later on.
The host list goes like this:

CM04TMMV0001EK
CM04TMMV0002EK

Code
lst = 'path/to/the/list.txt' 
with open (lst,'r') as lr :
    for itm in lr :
        itm=itm.strip()
        d_to_sacn =r"\\"+itm+"\c$\SBHI\Debug_Logs" 
        print ("whole string -- ",d_to_sacn)
here is a print out, I have a two extra lines at the bottom :
whole string -- \\CM04TMMV0001EK\c$\SBHI\Debug_Logs
whole string -- \\CM04TMMV0002EK\c$\SBHI\Debug_Logs
whole string -- \\\c$\SBHI\Debug_Logs
whole string -- \\\c$\SBHI\Debug_Logs
Reply
#2
I believe host is "\\" in the last two lines.
Reply
#3
Add repr() and you see all👀
lst = 'list.txt'
with open (lst, 'r') as lr:
    for itm in lr :
        itm = itm.strip()
        print(repr(itm))
        d_to_sacn = fr"\\{itm}\c$\SBHI\Debug_Logs"
        print (f"whole string -- {d_to_sacn}")
Output:
'CM04TMMV0001EK' whole string -- \\CM04TMMV0001EK\c$\SBHI\Debug_Logs 'CM04TMMV0002EK' whole string -- \\CM04TMMV0002EK\c$\SBHI\Debug_Logs
Adding one \ in last \CM04TMMV0002EK
Output:
'CM04TMMV0001EK' whole string -- \\CM04TMMV0001EK\c$\SBHI\Debug_Logs '\\CM04TMMV0002EK' whole string -- \\\CM04TMMV0002EK\c$\SBHI\Debug_Logs
tester_V likes this post
Reply
#4
Thank you!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,224 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  extra slashes in the network path for shutil.copy tester_V 3 3,785 Jun-02-2021, 07:57 AM
Last Post: supuflounder
  An Extra 'None' leoahum 5 3,924 Oct-18-2018, 08:20 PM
Last Post: volcano63
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,780 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  Additional slashes being added to string burvil 8 13,873 Aug-04-2017, 04:15 AM
Last Post: nilamo

Forum Jump:

User Panel Messages

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