Noob Question: How to import some imodule in Python?

I am using Python 2.5 on CentOS 5.5

I have a file called MultipartPostHandler.py, I have to use it as follows:

import MultipartPostHandler

But I don’t know where to put the file MultipartPostHandler.pyso that I can use it. Many thanks!

+3
source share
4 answers

http://docs.python.org/tutorial/modules.html#the-module-search-path

, named spam.py , , PYTHONPATH. , PATH, . PYTHONPATH , ; Unix ..:/USR//Library/

, , sys.path, , script ( ), PYTHONPATH . Python , theyre .

, sys.path, , .

+3

- , , .

+2

-, , , , .

-, , , .py, .

( / ), , , /lib/site-packages , Python.

+1

The simplest one, yes, is to put it in the same directory where you have the python importer code. In addition, you can export an environment variable PYTHONPATHthat points to the directory (or directories separated :) where you have it MultipartPostHandler.py. Another option: make it available. This will be useful if you are going to publish your code.

0
source

Source: https://habr.com/ru/post/1779218/


All Articles