PyCharm 2016.2 Help

Convert to Python Package/Module

In this section:

Overview

These two refactorings enable easy conversion between a Python module and package.

Both refactorings are performed silently.

Converting a file to a module

To convert a file to a package, follow these steps

  1. In the Project tool window, select the desired file.
  2. On the Refactor menu, choose Convert to Python Package.

The new package named by the original file is created. So doing, the content of the original file moves to the file with the name __init__.py.

Example

BeforeAfter
py_convert_to_package
py_convert_to_package_result

Converting a package to a module

To convert a package to a module, follow these steps

  1. In the Project tool window, select the desired Python package (marked as package), or the nested file __init__.py.
  2. On the Refactor menu, choose Convert to Python Module.

Example

BeforeAfter
py_convert_to_module
py_convert_to_module_result

See Also

Last modified: 29 August 2016