os.path.join() necessary?

Tim Roberts timr at probo.com
Fri May 24 01:14:04 EDT 2002


Thomas Guettler <zopestoller at thomas-guettler.de> wrote:
>
>I was suprised that I can use (dir + '/' + file) on windows.
>Since my application will only run on windows and unix I won't
>use os.path.join()

Windows API calls do accept forward slashes, but Windows commands do not.
Example:

  file = "x/y/z"
  os.system('dir %s' % file)

That will fail.  It would succeed if I had used os.path.join().

I have often used Python to generate command streams or Makefile.  In that
case, the slash direction is critical.

>If you just want to join a directory and a file it is no problem,
>but I store paths in a database. This would mean I would have to
>transform the path to the current operating system each time I get
>it from the database.

...which os.path.join will do for you.

Path are almost never cross-platform.  /usr/local/bin/python doesn't mean
very much on Windows.
--
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.



More information about the Python-list mailing list