Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First steps in Python (Jython): Importing

I am about to start programming python with jython on WinXP (Later Win7). After I tried out the out of the box interpreter in the comand line, I want to try out programming standalone modules.

My questions are:

Where do I have to put the .py files?

How to run them?

How to import scripts which are not in the same directory like the 'main' script? (Import scripts/classes/functions from an relative/absolute path) I plan to have something like a workspace folder (e.g. 'C:\pythonWorkspace') where I build my own python script library for importing them in several projects.

Edit: Added used OS: WinXP/Win7

like image 986
poeschlorn Avatar asked Apr 16 '26 01:04

poeschlorn


1 Answers

the relative/absolute path should in PYTHONPATH,sample code:

import os,sys
#change to your path
sys.path.append(os.path.join(os.path.dirname(__file__),'lib'))
like image 144
Michael Avatar answered Apr 18 '26 13:04

Michael