0

I have project1 and project2 and their structures as:

project1:

F:\sampleproj1
   com
     sampleproj1
       main.py

project2:

E:\sampleproj2
    com
      sampleproj2
         xyz.py

How can I import a class for eg:mainclass(user defined) from project2 in project1?

I tried my luck as:

In main.py (sampleproj1):

import sys
sys.path.append('E:/sampleproj2/com/sampleproj2')

then

from sampleproj2.com.sampleproj2.xyz import mainclass

This doesn't work, and I guess I am wrong with the path appending....Any help is appreciated

KcH
  • 3,302
  • 3
  • 21
  • 46

1 Answers1

0

I found answer from @PRMoureu as

import sys
sys.path.append('E:/sampleproj2/com/sampleproj2')

Then simply,

from xyz import mainclass

Note: If you are using Pycharm as IDE then you might observe warnings while importing,just ignore it

KcH
  • 3,302
  • 3
  • 21
  • 46