DataBuddy Studio supports development in the form of standalone Python files (.py), complementing Notebook. Python files are suitable for engineering scenarios such as modular code, scripted jobs, and reusable function libraries, while Notebook is suitable for interactive exploration. This section introduces the basic capabilities of the Python file editor. For running Python files, see Python File Execution. Overview
Python IDE shares the same Studio workspace with Notebook and SQL, with the following features:
Full Python Syntax: Supports the complete Python 3 syntax without enforcing cell-based execution.
Metadata Awareness: You can call the unified Catalog API in the editor to operate on tables.
Cross-File References: You can import other .py modules in the same directory by using import.
AI Assistant: Built-in Buddy assists with code generation, completion, and correction.
Version Management: Each manual save generates a version, with a maximum of 200 versions.
Prerequisites
You have joined the workspace and have Edit or Manage permission on the current Python file.
You have created or own an accessible Python file.
Operation Steps
Step 1: Opening or Creating a Python File
1. In the Development Directory on the left side of Studio:
Click an existing .py file to open it directly.
Alternatively, choose + New > Python, enter a file name, select a parent folder, and then click OK.
2. The file is opened as a Tab in the editor on the right.
Step 2: Writing Python Code
The Python editor provides the following capabilities:
Capability | Description |
Syntax highlighting | Keywords, strings, numbers, comments, and decorators are colored separately. |
Auto-completion | Provides real-time suggestions when standard libraries (os, json), common third-party libraries (pandas, numpy), and functions and variables defined in the current file are entered. |
Error detection | Syntax errors, undefined variables, and type errors are highlighted in real time. |
Bracket matching | Automatically pairs (), [], {}, single quotes, and double quotes. |
Step 3: Cross-File References
You can use the standard import statement to reference other .py files in the same workspace:
3.1 References Within the Same Directory
your_folder/
├── utils.py
└── main.py
# main.py
from utils import add_numbers
result = add_numbers(1, 2)
print(result)
3.2 References in Subdirectories
The subdirectory must contain __init__.py, or use a relative path:
from sub_folder import helper
3.3 Precautions
Files in both local folders and Git folders can be referenced.
The reference scope is limited to files for which the current user has visible permissions in Studio.
Step 4: Interacting with the Notebook File System
When a Python file runs, it can read and write files in the workspace:
import pandas as pd
# Read CSV
df = pd.read_csv('your_folder/data.csv')
# Write out
df.to_csv('your_folder/result.csv', index=False)
Step 5: Using AI Assistant
After selecting a Python snippet, right-click Buddy > Explain: AI explains the meaning of the current code.
After selecting an erroneous snippet, right-click Buddy > Fix Errors: AI fixes syntax errors and provides suggestions.
After entering a natural language comment, right-click Buddy > Continue Writing: AI generates code based on the comment.
Step 6: Saving and Version Management
Auto-save: Automatically caches drafts during editing.
Manual save: Click Save in the toolbar or press ⌘ + S to generate a version record.
Version comparison and rollback: View historical versions in the Version Management drawer on the right, with support for comparison and rollback.
Parameter Description
Top Action Bar of the Editor
Operation | Description |
Run all | Execute the entire Python file. |
Run selection | After selecting a snippet, click Run Selected to execute only the selected code (in the interactive REPL). |
Stop. | Terminate the current run. |
Save | Generate a manual version. |
Formatting | Unify indentation and whitespace according to PEP 8. |
Common Keyboard Shortcuts
Shortcut Keys | Operation |
⌘ + Enter
| Run the line where the cursor is located / selected code |
Ctrl + ⇧ + Enter
| Run all |
⌘ + S
| Save |
⌘ + ⇧ + F
| Formatting |
⌘ + /
| Comment/Uncomment |
Use Limits
The dlcutils library can be used in Python files, with behavior consistent with that in Notebook.
Cross-file references apply only to files within the workspace and cannot reference .py files on the local disk.
The Python interpreter version matches the selected compute resource image. If a specific version is required, select the corresponding compute resource version when creating a Kernel.
FAQs
Q1: Does import utils report ModuleNotFoundError?
Check whether utils.py is in the same directory as the current file.
For cross-directory imports, ensure that the parent directory is a Python package that contains __init__.py.
Check whether the file name is a valid Python identifier that contains no Chinese characters or hyphens.
Q2: Can Python files be directly published to Workflow?
Yes. The Python File task in Workflow supports referencing .py files in Studio. For more information, see Python File Task. Q3: Does Python files support Debug mode?
Yes. After setting breakpoints in the editor, click Debug Run to debug line by line and inspect variables.
References
Git Initialization Configuration / GitFolder Creation and Source Code Management Operations