I have a question about using glob in python.
I want to know why the path is showing backslashes instead of a forward slash?
Example being C:/Users/Name/Desktop/Pythonfiles\excel.xlsx
My script is
import glob
excel_list = (glob.glob("C:/Users/Name/Desktop/Pythonfiles/*.xlsx"))
This is my output I'm getting:
['C:/Users/Name/Desktop/PythonFiles\\19282.xlsx', 'C:/Users/Name/Desktop/PythonFiles\\19557.xlsx', 'C:/Users/Name/Desktop/PythonFiles\\19667.xlsx', 'C:/Users/Name/Desktop/PythonFiles\\19742.xlsx', 'C:/Users/Name/Desktop/PythonFiles\\CEImport.xlsx']
Any help would be great thank you
\ and / are interchangeable path separators, but if you wanted to normalize the paths so they are uniform, use os.path.normpath
excel_path = [os.path.normpath(i) for i in glob.glob("C:/Users/Name/Desktop/Pythonfiles/*.xlsx")]
#output
['C:\\Users\\Name\\Desktop\\PythonFiles\\19282.xlsx',
'C:\\Users\\Name\\Desktop\\PythonFiles\\19557.xlsx',
'C:\\Users\\Name\\Desktop\\PythonFiles\\19667.xlsx',
'C:\\Users\\Name\\Desktop\\PythonFiles\\19742.xlsx',
'C:\\Users\\Name\\Desktop\\PythonFiles\\CEImport.xlsx']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With