.py) in Studio: from connecting to a Kernel and running the entire file, to interacting with the file system and viewing results and logs. The execution model of Python files is highly consistent with that of Notebook, with the difference being the execution granularity (entire file vs. cell).dlcutils library and installing dependencies via pip install.Method | Entries | Action |
Run all | Operation bar Run All | Execute all code in the file sequentially from beginning to end, equivalent to the command line python file.py. |
Run selection | After selecting the code, press ⌘ + Enter | Execute the selected snippet in the interactive REPL. Variables are retained for subsequent selected runs. |
Stop. | Operation bar Stop | Terminate the current run. |
import osimport shutil# Create a folder.os.makedirs('your_folder/sub', exist_ok=True)# Copy files.shutil.copy('your_folder/data.csv', 'your_folder/sub/data_copy.csv')# Delete files.os.remove('your_folder/sub/data_copy.csv')
import pandas as pd# CSVdf = pd.read_csv('your_folder/data.csv')# JSONimport jsonwith open('your_folder/config.json', 'r') as f:config = json.load(f)
/workspace_1/your_username/your_folder/data.csv.import other .py modules in the same workspace:from utils import add_numbersresult = add_numbers(1, 2)
Area | Description |
Output | print(...), exception stack, and display(df) table results. |
Logs | Spark execution logs, error stacks, and detailed running information. |
Run Information | Runner, running time, running duration, and resources used. |
display(df), the result is displayed as a table below. The supported operations are the same as those in Notebook: copy, download (CSV / Excel / TXT), sort, filter, and field display control. For more information, see Notebook Execution > Processing Run Results.pip install in a Python file is as follows:%pip install pandas==2.2.0 jieba
%shpip install -r requirements.txt
pip install are lost after the run ends, while dependencies are retained at the session level.utils.py is in the same directory as the current file.__init__.py..py file in Studio. For more information, see Python File Task.dlcutils.notebook.run to trigger cross-file execution in Notebook, which is suitable for embedded calls.Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários