python - Error while setting the current working directory using win32com os.chdir() -
i trying open excel sheet in directory. using win32com this. this, set directory excel sheet , tried opening excel sheet. , error. sheet, however, opens fine, when supply full path open() function.
i corrected code (below working code).
# import statements win32com.client import dispatch import os # test_path_02 works # test_path_02 = 'c:\\users\\shardul.kumar\\pythoncode\\testdir\\' test_path_01 = r'c:\users\shardul.kumar\pythoncode\testdir\\' # set current working directory os.chdir(test_path_01) print (os.getcwd()) xlapp = dispatch('excel.application') # name of excel sheet file_list = os.listdir(test_path_01) item in file_list: print item file_path = (test_path_01 + file_list[0]) print (file_path) # supplying file_path works fine # xlwb = xlapp.workbooks.open(file_path) # below statement gives error; supplied file name xlwb = xlapp.workbooks.open(file_list[0]) xlapp.visible = true
but question is: why open() function not work if full path not specified, after setting current working directory?
Comments
Post a Comment