1

I use python to write scripts for Autodesk Maya. Maya is a cross-platform software and internally use forward slash. If I use os.path.join operation on windows it can result paths like this:

e:/Test\\TemplatePicture.jpg

My idea is that as long as I don't use ms-dos commands easier way to join path parts like this:

pathPart1 = "e:"
pathPart2 = "Test"
pathPart3 = "TemplatePicture.jpg"
path = "s%/s%/s%" % (pathPart1, pathPart2, pathPart3) 

Is there something that makes it a bad idea?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Prag
  • 529
  • 1
  • 6
  • 12
  • 1
    Yes, windows has the concept of multiple drives, so it will not work. –  Aug 09 '13 at 16:36
  • I'm fairly certain that python has as "realpath" function similar to php. Just give it unix-esque file paths and it will take care of the rest. Just checked, take a look at `os.path.realpath` – Jake Sellers Aug 09 '13 at 16:41

2 Answers2

10

When you import os, python will create an os.path specific to your platform. On linux its posixpath and on windows its ntpath. When you are working on Maya paths, use posixpath. It will follow linux conventions even on windows. When you need to go native, convert using the realpath for your current system.

import os
import posixpath

maya_path = posixpath.join('a','b','c')
local_path = os.path.realpath(maya_path)
tdelaney
  • 73,364
  • 6
  • 83
  • 116
0

I don't see any problems with this.

In fact there is a related question here.

To summarize the discussion within the provided link - you either let python handle file paths or you do it all yourself

Community
  • 1
  • 1
Prahalad Deshpande
  • 4,709
  • 1
  • 20
  • 22