What does this line of code mean?

Ian Kelly ian.g.kelly at gmail.com
Sun Nov 16 22:53:04 CET 2014

On Sun, Nov 16, 2014 at 2:45 PM, Abdul Abdul <abdul.sw84 at gmail.com> wrote:
> I just came across the following line of code:
> outputfile = os.path.splitext(infile)[0] + ".jpg"
> Can you kindly explain to me what those parts mean?

>>> import os.path
>>> help(os.path.splitext)
Help on function splitext in module ntpath:

    Split the extension from a pathname.

    Extension is everything from the last dot to the end, ignoring
    leading dots.  Returns "(root, ext)"; ext may be empty.

>>> os.path.splitext('test.txt')
('test', '.txt')
>>> os.path.splitext('test.txt')[0]
>>> os.path.splitext('test.txt')[0] + ".jpg"

More information about the Python-list mailing list