What does this line of code mean?

Tim Chase python.list at tim.thechases.com
Sun Nov 16 22:53:53 CET 2014


On 2014-11-16 22:45, 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?

Have you tried them?

https://docs.python.org/2/library/os.path.html#os.path.splitext

This takes a path and splits it into everything-but-the-extension,
and the extension.  The "[0]" takes the first part (without the
extension), and the "+ '.jpg'" part tacks on that extension.

So it changes whatever the existing extension is to .jpg

-tkc





More information about the Python-list mailing list