1

I am trying to set working directory through IronPython. Its basically for ANSYS Workbench. I am getting the directory path from excel and i am storing it in a variable in IronPython.

dirpath = worksheet.range["E25"].value

and I am giving this variable value as input path to AbsUserPathName and chdir commands.

dir = AbsUserPathName(dirpath)
os.chdir(dirpath)

But none of it is working, it gives error as expected str, got _comObject

Any help is appreciated.

Simon Opelt
  • 6,136
  • 2
  • 35
  • 66
Kartiki
  • 95
  • 2
  • 14

1 Answers1

0

Assuming you are using Microsoft.Office.Interop.Excel you could use one of the following statements:

dirpath = worksheet.Range["E25"].Text

or

dirpath = worksheet.Cells[25, "E"].Text

or

dirpath = worksheet.Cells[25, 5].Text

Your current statement exposes a COM object from the interop-API that might even represent multiple cells and therefore can not be used by chdir as there is no way of implicitly converting the range to a string.

Simon Opelt
  • 6,136
  • 2
  • 35
  • 66
  • You can either go the python way with `os.chdir` or set `Environment.CurrentDirectory` after having `from System import Environment` to use the corresponding .NET API. The result will be the same. – Simon Opelt May 06 '15 at 15:29