Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:code': 0.07; 'os.path': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'bit.': 0.16; 'empty.': 0.16; 'ignoring': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; 'module': 0.19; 'split': 0.19; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; "i've": 0.25; 'extension': 0.26; 'code:': 0.26; 'header:X-Complaints-To:1': 0.27; 'function': 0.29; 'skip:( 20': 0.30; "i'm": 0.30; 'end,': 0.31; 'ext': 0.36; 'subject:?': 0.36; 'skip:o 20': 0.38; 'to:addr :python-list': 0.38; 'explain': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'kindly': 0.61; "you'll": 0.62; 'close': 0.67; 'yourself': 0.78; 'subject:this': 0.83 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: What does this line of code mean? Date: Sun, 16 Nov 2014 22:59:01 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd98f0.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416175164 news.xs4all.nl 2907 [2001:888:2000:d::a6]:60076 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80915 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.