I am using windows 10 with jupyter notebook under annaconda.
JavaScript
x
5
1
last_file = glob('../inputs/transactions_all/transactions*.xlsx')[-1] # path to file in the folder
2
last_file
3
4
'../inputs/transactions_all\transactions_finaldf_2021-05-15_12h19m_repo.xlsx'
5
from the above, I got /
and \
for path separators? I am expecting the result like this
JavaScript
1
2
1
'..inputstransactions_alltransactions_finaldf_2021-05-15_12h19m_repo.xlsx'
2
How can I modify my codes to get above results?
Advertisement
Answer
there is no problem working with either or /, python know how to work with those (in windows at least), that being said if you want to ensure the correct one you can use normcase
JavaScript
1
6
1
>>> import os
2
>>> p='../inputs/transactions_all\transactions_finaldf_2021-05-15_12h19m_repo.xlsx'
3
>>> os.path.normcase(p)
4
'..\inputs\transactions_all\transactions_finaldf_2021-05-15_12h19m_repo.xlsx'
5
>>>
6
You can also use the pathlib module to handle your paths that way they always will be the appropriate one for the OS you are working on