most efficient way to substring path and file out of a string
Question: 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?


Answer: 
    file = '/var/log/test.txt'
    path, file_name = os.path.split(file)
    

yields:

    
    
    path
    '/var/log'
    
    file_name
    'test.txt'
    

To use
[os.path.split()](http://docs.python.org/library/os.path.html?highlight=os.path.split#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:

    
    
    if not path: path = '.'
    

I.e.,

    
    
    file = 'test.txt'
    path, file_name = os.path.split(file)
    if not path: path = '.'
    

gives:

    
    
    path
    '.'
    
    file_name
    'test.txt'
    

