[Pythonmac-SIG] Using slash-seperated paths for creating FSSp ecs (was: Mach-O MacPython IDE!!!)

Schollnick, Benjamin Benjamin.Schollnick@usa.xerox.com
Wed, 26 Dec 2001 08:37:53 -0500


Donovan,

	I like the idea....(personally)....

	It's a interesting use of the overloaded parameters....

	I think, this is similiar to what you intend...
	(In a more formalized, function), and suggestions for improvement?

import os

def	create_platform_path ( list_of_directories, *overflow):
    """ """
    if (list_of_directories <> None):
       return os.path.join ( list_of_directories, *overflow )
    else:
        return ""
    
print "path: ", create_platform_path (None)
print "path: ", create_platform_path ( *["develope"] )
print "path: ", create_platform_path ( *["develope", "bas_common"] )
print "path: ", create_platform_path ( *["temp", "delete", "me"] )
test = ["this", "is", "the", "path"]
print "path: ", create_platform_path (*test)

		- Benjamin

-----Original Message-----
From: Donovan Preston [mailto:dp@ulaluma.com]
Sent: Friday, December 21, 2001 8:57 PM
To: pythonmac-sig@python.org
Subject: [Pythonmac-SIG] Using slash-seperated paths for creating
FSSpecs (was: Mach-O MacPython IDE!!!)


On Friday, December 21, 2001, at 01:44 PM, Jack Jansen wrote:
>
> Recently, Donovan Preston <dp@ulaluma.com> said:
>> Hmm. Well, I suppose the only way to get around this is to explicitly
>> state which type of path is being used as Jack suggested, or to always
>> assume slash-delimited paths on X and colon-delimited paths on 9.
>
> I assume you mean "MacPython" where you say 9 and "MachoPython" where
> you say X, right? Pathname interpretation is more a function of the
> runtime library than of the OS, in the case of Python.

Yes, correct, sorry. So I should have said "Always assume 
slash-delimited paths on Mach-O Python and colon-delimited paths on CFM 
MacPython."

>> Since os.path.join creates slash-delimited strings on X, all of the
>> places in the IDE where there is code that looks like
>> os.path.join(rootdir, 'my:subdir:etc') are going to have to be replaced
>> anyway. I suggest replacing them with os.path.join(*[rootdir, 'my',
>> 'subdir', 'etc']) which works no matter what OS you are running under.
>
> Or, alternatively, use macpath. Os.path is great to get rid of
> platform dependencies, but only if you add single components. If
> you're using my:subdir:etc you have a Mac dependency anyway, so
> there's little to be gained from using os.path.

Ah. I wasn't aware there was a macpath module which would do 
colon-delimiting even on X. Hmm. At first glance I thought that might 
work, but upon further inspection I recall why sticking to 
colon-delimited paths won't work on Mach-O MacPython:

There are constructions throughout the IDE that look like this:

	widgetresfile = os.path.join(sys.exec_prefix, 
":Mac:Tools:IDE:Widgets.rsrc")

Since sys.exec_prefix is specified as a slash-delimited string, even 
macpath won't help here. And I am strongly opposed to making 
sys.exec_prefix return a colon-delimited string :-) And rather than 
convert any slash-delimited string such as sys.exec_prefix to a 
colon-delimited string prior to using macpath.join, I still contest that 
it's better to use os.path.join and construct your path segments in a 
platform agnostic way. Maybe this syntax will be a little more to your 
(non-obfuscated) liking ;-)

pathsegments = [sys.exec_prefix, 'Mac', 'Tools', 'IDE']
path = os.path.join(*pathsegments)

Then, the resulting path can be passed to the new FSSpec_New, after it's 
been updated to conform to your pseudocode, no matter what runtime you 
are running under and it will work.

Donovan


_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig