Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80915
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: What does this line of code mean? |
| Date | 2014-11-16 22:59 +0100 |
| Organization | None |
| References | <CAA+hu4X4sP=B9ffkos5iY22UGzvmAT=_fvpR2Nuna5nst4FwWA@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.15911.1416175164.18130.python-list@python.org> (permalink) |
Abdul Abdul 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?
You can try it yourself in the interactive interpreter:
>>> 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.
>>> infile = r"c:\some\folder\image.png"
>>> os.path.splitext(infile)
('c:\\some\\folder\\image', '.png')
>>> os.path.splitext(infile)[0]
'c:\\some\\folder\\image'
>>> os.path.splitext(infile)[0] + ".jpg"
'c:\\some\\folder\\image.jpg'
PS: I'm using Linux; If you look close enough at the above session you'll
note that I've cheated a bit.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: What does this line of code mean? Peter Otten <__peter__@web.de> - 2014-11-16 22:59 +0100
csiph-web