I am new to python, just wondering what’s the best way for python to do the following:
file='/var/log/test.txt'
==action==
after ==action==, I want to get the path and the file separated like:
path='/var/log'
file_name='test.txt'
I am not asking how to do this, I am asking the most efficient way to do this using least lines of code.
=EDIT=
What if my file=’test.txt’ instead of file=’/var/log/test.txt’. I would more likely expect:
path='.'
path='test.txt'
other than
path=''
file_name='test.txt'
what’s the tip for this then?
yields:
To use os.path.split() requires
import os. I’d have to think that the Python library is as efficient as it could be.To respond to the update/edit, if no path is specified and you want the
.for path, add:I.e.,
gives: