Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80912

Re: What does this line of code mean?

References <CAA+hu4X4sP=B9ffkos5iY22UGzvmAT=_fvpR2Nuna5nst4FwWA@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2014-11-16 14:53 -0700
Subject Re: What does this line of code mean?
Newsgroups comp.lang.python
Message-ID <mailman.15908.1416174834.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Nov 16, 2014 at 2:45 PM, Abdul Abdul <abdul.sw84@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:

splitext(p)
    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]
'test'
>>> os.path.splitext('test.txt')[0] + ".jpg"
'test.jpg'

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: What does this line of code mean? Ian Kelly <ian.g.kelly@gmail.com> - 2014-11-16 14:53 -0700

csiph-web