DataSpell 2023.3 Help

Adding Python files

DataSpell suggests several alternative ways to add a Python file.

Create new files

  1. Do one of the following:

    • In the Workspace tool window (Alt+1), select the directory in which you want to create a new file, and then choose File | New from the main menu.

    • Right-click the directory and select New from the context menu.

    • Select the directory and press Alt+Insert.

  2. Select Python File file.

    New Python file
  3. In the dialog that opens, type the name of the file in the corresponding field. Note that you should not type the filename extension.

    Adding a new Python file

    You can specify the whole directory structure prepending the new filename. If the nested directories do not yet exist, they will be created.

    Creating a new directory and a file
  4. Click OK. The new file that corresponds to the selected file template will be created under the target location.

    If the names of non-existent sub-directories were specified before the new filename, the whole structure will be created under the target directory:

    New file

If you want to ensure that imports from the same directory are resolved, mark that directory as a namespace package.

Mark a directory as a namespace package

  1. Consider two packages, lib1 and lib2 that reside in the same directory. Try to include a lib1 import statement into lib2.py. DataSpell reports a relative import outside of the package.

    Relative import outside of the package
  2. To resolve the import and avoid the warning, mark the mydir directory as a namespace package. You have the following options:

    • Place the caret at the import statement, press Alt+Enter (or click the yellow bulb), and apply the corresponding quick-fix.

    • Right-click the directory in the Project tool window and select Mark Directory as | Namespace Package.

    Make as a namespace package
Last modified: 23 February 2024