Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
String to File Path
#1
I am trying to create a file path from a string using os.path.normpath, however, I need a double \ at the beginning and this function doesn't allow this (from what I understand). Inside the pd.read_excel function I need the following: r'\\srpx\Folder\Data.xls'

Here is the code that is not working:

import os
import pandas as pd

excel_string = str("r'\\srpx\Folder\Data.xls'")
excel_file = os.path.normpath(excel_string)

pd.read_excel(excel_file)
By the way, this works perfectly:

pd.read_excel(r'\\srpx\Folder\Data.xls')
Reply


Messages In This Thread
String to File Path - by creedX - Apr-06-2020, 04:51 PM
RE: String to File Path - by buran - Apr-06-2020, 06:20 PM
RE: String to File Path - by creedX - Apr-06-2020, 06:51 PM
RE: String to File Path - by buran - Apr-06-2020, 06:57 PM
RE: String to File Path - by creedX - Apr-06-2020, 07:29 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need to replace a string with a file (HTML file) tester_V 1 775 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  File path by adding various variables Mishal0488 2 1,042 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  Script File Failure-Path Error? jerryf 13 3,475 Nov-30-2022, 09:58 AM
Last Post: jerryf
  -i option changes sys.path (removes leading empty string '') markanth 6 1,993 Aug-26-2022, 09:27 PM
Last Post: markanth
  Convert string to path using Python 2.7 tester_V 10 6,472 Nov-20-2021, 02:20 PM
Last Post: snippsat
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,220 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Subprocess.Popen() not working when reading file path from csv file herwin 13 15,123 May-07-2021, 03:26 PM
Last Post: herwin
  Add file to sys.path permanently hcccs 5 8,438 Jan-31-2021, 11:26 AM
Last Post: hcccs
  PyDrive download file path MiniMinnow 0 3,250 Apr-28-2020, 03:01 PM
Last Post: MiniMinnow
  Add path to a local file in pop-up field pythonscripting 1 1,653 Feb-08-2020, 10:57 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