0

I have to name the single folder as 'com.apple.com', it has an app.py under the folder. I want to import the app.py using importlib, how to do that?

I have tried using following code, but always got an error.

The structure of folder:

--com.apple.com

----app.py

and code:

importlib.import_module("com.apple.com.app")
ᴀʀᴍᴀɴ
  • 4,443
  • 8
  • 37
  • 57
  • 4
    Possible duplicate of [How to import a module given the full path?](http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path) – Anton Protopopov Jan 13 '16 at 09:52
  • For (future) questions: "*but always got an error.*". What is the exact error message you are getting? – dhke Jan 13 '16 at 09:57

1 Answers1

0

You probably need to use sys and codes are as follows.

a.py:

def p():
    print "hello world"

b.py:

import sys 
sys.path.append('C:***\\com.apple.com') 
import a

a.p()

output:

hello world
Shawn. L
  • 403
  • 1
  • 3
  • 13