Jump to content

Recommended Posts

Posted

I'm taking a couple of online classes in a couple weeks, but one of them requires fluency in Python. I'm reading some online guides, but the "import" keyword is confusing me. Import from where? In PHP, I would use require to acquire access to my functions, classes, and constants.

require '/my/full/path/to/the/file.php';

But in Python, you use this:

import file

How do I specify the location of the file? Any help would be greatly appreciated!

  • 1 year later...
Posted

By Default, Python searches in the project directory and hence the files from other directories cannot be imported as we do for the files available locally in the project folder.

But to accomplish that we might want to amend the system path which can be done in the following way.

import syssys.path.insert(1, '/path/to/your/filefolder/')#also sys.path.append(0,/'path/to/your/filefolder/[file])import [your file]

 

Hope this can help :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...