I do not really like to answer so late, but I am not completely satisfied with the existing answers.
I am just starting out Python, and I would like to use an external RSS class. Where do I put this class and how to import it?
You put it in a python file and give the python file a .py extension. Then you can import the module representing this file and access the class. Suppose you want to import it, you should put the python file somewhere in the import search path - you can see it at runtime with sys.path , and perhaps the most important thing to know is that the packages site (installation-specific), and the current directory ('') is usually located in the import search path. When you have one homogeneous project, you usually put it in the same directory as your other modules, and let them import from each other from the same directory.
I would ultimately want to be able to share python programs.
After you configure it as a separate file, you can configure it for distribution using distutils . This way, you donβt have to worry about where it should be installed - distutils will worry about you. There are many other additional distribution tools, many OS-specific - distutils work for modules, but if you want to distribute the proper program that users need to run, there are other options, such as using py2exe for Windows.
As for the module / package differences, well, here it is. If you have a whole bunch of classes you want to split so you don't have one big mess of python file, you can split it into several python files in a directory and provide a __init__.py directory.It is important to note that with Python there is no differences between a package and any other module. A package is a module, it's just another way of representing data in a file system. Similarly, a module is not just a .py file β if it is, sys will not be a module since it does not have a .py file. It is built into the interpreter. There are many ways to represent modules in the file system, since you can add import hooks that can create paths other than directories and .py files to represent modules. Hypothetically, you can create an import hook that used spidermonkey to load Javascript files as Python modules.
source share