My input is folder_src = 'D:\TEST\BOE\7-13-2' , I want to add another \ next to \ as folder_src = 'D:\\TEST\\BOE\\7-13-2'.
How will I be able to do it?
            Asked
            
        
        
            Active
            
        
            Viewed 56 times
        
    -3
            
            
         
    
    
        rermk
        
- 1
- 1
- 
                    Just put `\\\`s together – yoonghm Nov 09 '21 at 06:28
- 
                    I want to skip that process – rermk Nov 09 '21 at 06:38
- 
                    Side note: the process doesn't seem to make sense if this is a file path: the directory separators are single backslashes in Windows, not double. Any reason why you want to do this? – 9769953 Nov 09 '21 at 06:39
- 
                    When converting files through jupyterlab, i need to insert a file address, but it is cumbersome to enter additional \ every time. – rermk Nov 09 '21 at 06:43
- 
                    @rermk: In case the path is hard coded in the script, you could use forward slashes as well: `folder_src = 'D:/TEST/BOE/7-13-2'` – Maurice Meyer Nov 09 '21 at 06:43
- 
                    1As I understand you have a problem with the path itself, why not try `folder_src = r'D:\TEST\BOE\7-13-2'` – Tony Nov 09 '21 at 06:45
2 Answers
1
            
            
        Use replace:
folder_src = 'D:\\TEST\\BOE\\7-13-2'
output = folder_src.replace('\\', '\\\\')
print(output)  # D:\\TEST\\BOE\\7-13-2
 
    
    
        Tim Biegeleisen
        
- 502,043
- 27
- 286
- 360
1
            
            
        One way to use your windows path is with raw string literals like this:
folder_src = r'D:\TEST\BOE\7-13-2'
With this the string will be sent exactly as it is written and you wouldn't need the \\.
 
    
    
        Tony
        
- 618
- 12
- 27