473,473 Members | 2,169 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

basename with extensions

I'd like to resurrect this subject:

http://groups.google.com/group/comp....2a3b0c0e902114

If I have a path like this:

mypath = /some/long/path/file.xml

and I want "file" I currently have to do:

os.path.basename(os.path.splitext(mypath)[0])

or use the slightly convoluted string method detailed in the groups
link above. An optional second argument to basename to remove a
specified extension, as is available in other languages like PHP and in
the shell version of basename, would seem pretty sensible.

Or have I missed something?

Peter

Aug 30 '06 #1
1 2048

Peter Saffrey wrote:
I'd like to resurrect this subject:

http://groups.google.com/group/comp....2a3b0c0e902114

[snip]

Or have I missed something?
The Python developers are working on a new path module for the standard
library, since the current tools for working with paths are widely
accepted as being quite clumsy. Check out PEP 355 for details.

In the mean time, there are several alternative path modules you can
check out:

Jason Orendorff's path module:
http://www.jorendorff.com/articles/python/path/

PEP 355 reference implementation:
http://wiki.python.org/moin/PathModule

There are also others, to be found with Google.

- Tal

Aug 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Xah Lee | last post by:
Just bumped into another irresponsibility in perl. the crime in question this time is the module File::Basename. Reproduction: 1. create a directory containing a file of this name:...
1
by: Sean Berry | last post by:
I have an online ftp type website for a customer that I wrote in a cgi perl script. If the person is trying to upload a file that already exists on the server I am printing a message telling...
1
by: Wild Pete | last post by:
Is there an equivalent to a "basename" in javascript that returns the last part of a file name? For example, given "C:\My Documents\test.txt" and "/usr/local/test.txt", both should return...
0
by: rithish | last post by:
Hello. We are on PHP 5.0.2 LINUX system. Since an hour ago, the function basename() started resulting inconsistent values. print ( "dirname - " . dirname ( __FILE__ ) . "<br>\n" ); print (...
4
by: PengYu.UT | last post by:
libgen.h has the basename command. But it is not a C++ head file. Is there any C++ head file have a function or a class doing the same thing? Thanks, Peng
2
by: Thomas Ploch | last post by:
Hello, I have a cgi script that handles fileuploads from windows and *nix machines. i need os.path.basename(filename) to get the pure filename. For *nix, thats not a problem, but for windows,...
0
by: Salve =?iso-8859-1?Q?H=E5kedal?= | last post by:
$var = "/home/user/dir/file" // To extract dir from $var, is echo basename(dirname($var)); // a silly thing to do? Salve
5
by: David d'Angers | last post by:
hi group the following lines are taken from basename.c of the linux coreutil group of programs i don't understand the meaning of several of the functions: initialize_main (&argc, &argv); why...
6
TheServant
by: TheServant | last post by:
Hey guys, I am trying to figure out a more efficienct structure for my website and how it handles files and contents. I am trying very hard to separate all my html and php and although it is going...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.