Adding Python files
JetBrains DataSpell suggests several alternative ways to add a Python file.
Create new files
- 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 from the main menu.
Right-click the corresponding directory and select New from the context menu.
Select Python File file.
In the dialog that opens, type the name of the file in the corresponding field. Note that you should not type the filename extension.
You can specify the whole directory structure prepending the new filename. If the nested directories do not yet exist, they will be created.
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:
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
Consider two packages, lib1 and lib2 that reside in the same directory. Try to include a lib1 import statement into
lib2.py. JetBrains DataSpell reports a relative import outside of the package.
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 .