On Thu, 20 Jul 2006 11:19:46 +0300
[EMAIL PROTECTED] wrote:

> Hi,
> 
> is this the right (shortest) way to get the file extention
> (under MS WIN)?
> 
> 
> def getext(fname):
>     ext = fname.split('.').pop()
>     return ext
> 

Hi Emily,

for filename operations, you should have a look at the os.path module.
In your case

    os.path.splitext(fname)[1]

should do the trick, or if you need to remove the leading period from the 
extension
(as in your example)

    os.path.splitext(fname)[1][1:]
.

I hope this helps

Michael
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to