Thread: Os.path.join

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Os.path.join


    I'm not able to see the bigger picture here i think; but basically I have no idea why you would use os.path.join? why wouldnt you just use a string or string concatenation?

    Simple answers please im very new coming from a soley vbs world
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,840
    Rep Power
    480
    The os module removes operating system dependencies.

    os.path.sep on unix is '/' while on DOS is r'\'
    os.path.join uses os.path.sep to build paths.

    os.listdir(os.curdir)
    has same effect whether on DOS, unix, or other system.


    Use os.path.join for portable programs.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Joensuu, Finland
    Posts
    430
    Rep Power
    66
    Originally Posted by b49P23TIvg
    os.path.sep on unix is '/' while on DOS is r'\'
    Wohoo! FINALLY I’ve been able to spot an error in b49P23TIvg’s postings!

    Code:
    >>> r'\'
    SyntaxError: EOL while scanning string literal
    Using raw strings most of the special handling of \ is removed but a raw string still cannot end in a single \.

    Comments on this post

    • b49P23TIvg agrees :
    My armada: openSUSE 13.1 (home desktop, home laptop), Crunchbang Linux 11 (mini laptop, work laptop), Android 4.2.1 (tablet)

IMN logo majestic logo threadwatch logo seochat tools logo