I have seen this for a long time, but it never seemed to create any problems
really. As long as you use the same best-practices you'd use to keep code
cross-platform everything should work fine.

If you still want to go ahead with a smart operator, I'd vote for:

3) join, then normalize resulting path to forward slash

since it is consistent with the way os.path 'wants' to work (which is make
the separator compatible with the OS)

Ofer

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Chadrik
Sent: Tuesday, June 09, 2009 3:33 PM
To: python_inside_maya
Subject: [Maya-Python] maya file paths on windows


i've been messing around with maya on windows and i've noticed that
there are some inconsistencies with path slashes that need to be
resolved.  maya returns forward slashes (/) on both windows and unix-
like systems, but python tries to use back slashes (\) on windows.  as
a result, using os.path.join with paths returned by maya ends up
producing mixed slashes:

>>> os.path.join( workspace(q=1, fullName=1), 'scenes' )
'C:/path/to/project\scenes'

i was wondering how people out there are dealing with this.  it seems
that maya and python can both understand paths with mixed slashes, but
are there edge cases where this becomes a problem or where forward
slashes do not work on windows?

pymel provides the Path class, which overrides the / operator to mean
os.path.join, which obviously has the same problem:

>>> workspace.getcwd() / 'scenes'
'C:/path/to/project\scenes'

however, i was considering making this operator smarter. options
include:
1) always join with forward slash
2) choose the joining slash based on the left operand
3) join, then normalize resulting path to forward slash
4) join, then normalize resulting path using slash determined from
left operand

which of these seem like the best measure?  is there any option i'm
leaving out?

-chad






--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to