os.path.join

Discussion in 'Python' started by Ethan Furman, Oct 19, 2009.

  1. Ethan Furman

    Ethan Furman Guest

    Following closely on the heels of the whole sum()ing strings debate, I
    think I found an error -- at least, it's not documented to behave this
    way...

    def uncompress_job(job_num,
    save_path='z:\\old_jobs',
    restore_path='z:\\orders'):
    destination = os.path.join([restore_path, job_num])
    print os.path.join([save_path, job_num])

    As the astute reader will doubt notice, job_num should be a string. As
    I was not an astute typer during development, I just put in an integer:

    -->uncompress_job(18273)
    ['z:\\oldjobs', 19858]

    I did have more interesting errors to lead me to this point, but here I
    am, and my question... shouldn't os.path.join raise an exception if an
    incompatible type is passed to it? I sure wish it had! ;-)

    I was expecting, and the documentation led me to believe, that a string
    would be returned, not a list.

    ~Ethan~


    -- Documentation --
    join( path1[, path2[, ...]])

    Join one or more path components intelligently. If any component is an
    absolute path, all previous components (on Windows, including the
    previous drive letter, if there was one) are thrown away, and joining
    continues. The return value is the concatenation of path1, and
    optionally path2, etc., with exactly one directory separator (os.sep)
    inserted between components, unless path2 is empty. Note that on
    Windows, since there is a current directory for each drive,
    os.path.join("c:", "foo") represents a path relative to the current
    directory on drive C: (c:foo), not c:\\foo.
     
    Ethan Furman, Oct 19, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Silver
    Replies:
    0
    Views:
    907
    Alan Silver
    Jun 5, 2006
  2. Pierre Fortin

    args v. *args passed to: os.path.join()

    Pierre Fortin, Sep 18, 2004, in forum: Python
    Replies:
    2
    Views:
    721
    Pierre Fortin
    Sep 18, 2004
  3. googleboy
    Replies:
    1
    Views:
    947
    Benji York
    Oct 1, 2005
  4. Steve
    Replies:
    1
    Views:
    998
    Fredrik Lundh
    Dec 13, 2005
  5. =?ISO-8859-1?Q?Gregory_Pi=F1ero?=

    os.path.join - Isn't working

    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=, Jan 27, 2006, in forum: Python
    Replies:
    0
    Views:
    295
    =?ISO-8859-1?Q?Gregory_Pi=F1ero?=
    Jan 27, 2006
Loading...

Share This Page