1

Looks like function os.chdir() does not works for Jython, is there another way to switch of working directory in a Jython script ?

(Get the following error while running my script: OSError: [Errno 0] chdir not supported in Java)

Thanks in advance for any solution.

EDIT: Question title updated to match the solution. Tags too.

kij
  • 1,421
  • 1
  • 16
  • 40
  • 1
    What is the end objective for you to switch working directory? Is it linked to python scripts path or is it more user data related? – Grimmy Sep 24 '13 at 07:50
  • I'm new to python/jython, my objective was to define a path where to find some local modules, i did it first by providing a custom working directory (with Eclipse launcher) and so thought i was the solution..but not, crappy method! What i have to do is not to switch but define in the sys.path the directory where to find my modules. I post an answer for this. – kij Sep 24 '13 at 07:57
  • See also http://stackoverflow.com/questions/840190/changing-the-current-working-directory-in-java – GeertPt Sep 24 '13 at 08:20

1 Answers1

1

What Grimmy asked make me think different about my original problem (thanks to you)

My goal is (was) to define a path to find local jython modules. And so the correct way is to update 'sys.path'.

Example:

sys.path.append(workingDirectory)

Problem solved. Thanks again Grimmy.

kij
  • 1,421
  • 1
  • 16
  • 40
  • you're welcome :) I was asking because I had exactly that problem last week and were assessing the different way to address the problem. The other one I liked was to have the scripts bundled in the classpath of the application. Jython includes the java application classpath in the python search path. This works well as long as you ship static scripts that are not modified on the fly (see http://www.jython.org/jythonbook/en/1.0/ModulesPackages.html#module-search-path-compilation-and-loading for documentation) – Grimmy Sep 24 '13 at 08:06
  • Thanks for sharing this other solution. I think the append on sys.path is better in my current case because scripts / modules are not static. They are downloaded from a nexus repository by maven, unpacked into a temporary build directory and then run by another maven plugin. All of this into a dedicated maven profile. – kij Sep 24 '13 at 08:49