Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80915 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2014-11-16 22:59 +0100 |
| Last post | 2014-11-16 22:59 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: What does this line of code mean? Peter Otten <__peter__@web.de> - 2014-11-16 22:59 +0100
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-11-16 22:59 +0100 |
| Subject | Re: What does this line of code mean? |
| Message-ID | <mailman.15911.1416175164.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web