l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2003 Jul 30 09:34

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] Re: vox-tech digest, Vol 1 #843 - 6 msgs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] Re: vox-tech digest, Vol 1 #843 - 6 msgs

On Tue, Jul 29, 2003 at 12:00:01PM -0700, vox-tech-request@lists.lugod.org wrote:

> Message: 5
> Date: Tue, 29 Jul 2003 10:46:23 -0700
> From: David Siedband <david@calteg.org>
> To: vox-tech@lists.lugod.org
> Subject: [vox-tech] python: slicing extensions from file names
> Reply-To: vox-tech@lists.lugod.org
> I'd like to find a way to slice the extension off of a file name in python.
> That is, I'd like to slice everything after the first period in the file 
> name.
> I'm renaming the files based on another algorythm, but I need to keep 
> the extension the same.
> I looked at the slice( ) function, but it seems to want me to specify 
> the size of the slice in characters. andI need to allow for extensions 
> with more or less than 3 characters.

Use split().  Here is an example in Python's interactive mode (it would
be the same in batch mode, of course).

% python
Python 2.2.1 (#1, Aug 30 2002, 12:15:30)
[GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> y = "abc.defg"
>>> z = y.split('.')[0]
>>> z

By the way, I can't resist urging all you Perl users out there to switch
to Python. :-)  It's much cleaner and elegant than Perl, and a joy to
program in.  I have a tutorial at



vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!