A query related to os.chdir

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rockzzz
    New Member
    • Aug 2015
    • 2

    #1

    A query related to os.chdir

    Hi guys,
    I have 2 variables a and b and the following code
    a= /user/temp/new
    b= test

    I am using
    Code:
    os.chdir(os.path.join('a','b'))

    to change my directory to test but I am getting following error
    Traceback (most recent call last):
    File "bfm.py", line 50, in <module>
    os.chdir(os.pat h.join('a','b') )
    FileNotFoundErr or: [Errno 2] No such file or directory: 'a/b'

    But I have test directory in new.
    Can any one explain me how to resolve this error
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    print os.path.join('a ','b') to see what the resultant directory is and if it does exist. Take a look at variables vs. strings, and pay attention to which use quotes and which do not, at https://en.wikibooks.org/wiki/Python...es_and_Strings

    Comment

    • Mator
      New Member
      • Aug 2015
      • 3

      #3
      remove the quotes from i.e.
      Code:
      os.path.join(a, b)
      putting quotes mean you are joining strings not the variables created a line before

      Comment

      Working...