Use a Python script to read uploaded resource files such as .xlsx and .csv files. Install a third-party library such as openpyxl with pip for file parsing.
Prerequisites
-
The access address
mirrors.aliyun.comand all ports (*) have been added to the sandbox allowlist for your project space. For more information, see Use a client or CLI to connect to an ApsaraDB RDS for MySQL instance. -
A file in a Python-readable format is available, such as TXT, CSV, XLS, XLSX, or PDF.
Step 1: Upload a file
-
In the top navigation bar of the Dataphin homepage, choose Lab > Data Development.
-
In the navigation pane on the left, choose Data Processing > Resources. On the Resources page, click the
icon. -
In the Create resource dialog box, configure the parameters.

Parameter
Description
Type
Select others.
Name
The file name must end with the file extension, for example,
test.xlsx.Description
Enter a description for the resource.
Upload file
Select a local file, such as
test.xlsx.Compute type
Select unassigned engine.
ImportantResource files are stored in the Dataphin system. Therefore, you can only select unassigned engine.
Select directory
The default value is Resource Management.
-
Click Submit.
-
In the Commit message dialog box, enter a message and click OK and Submit.
Step 2: Install a Python package
-
In the top navigation bar of the Dataphin homepage, choose Management Center > System Settings.
-
In the navigation pane on the left, choose Third-Party Library Management > Python Packages. On the Python Packages tab, click Install Python Package.
-
In the Install Python package dialog box, configure the parameters.

Parameter
Description
Package name
Enter the name of the Python package. For example,
openpyxl.Package version
Enter the package version. For example,
1.0.0.Python version
Select Python 3.7.
Installation method
Select Online Installation.
-
Click OK to install the package.
Step 3: Create a Python task
-
In the navigation pane on the left, choose Data Processing > Compute Tasks.
-
On the Compute Tasks page, click the
icon and select Python. -
In the New Python task dialog box, configure the parameters.

Parameter
Description
Task name
Enter a name for the compute task, for example,
Read_file_with_Python.Scheduling type
Select Scheduled Task.
Select directory
The default value is Code Management.
Use template
This feature is disabled by default.
Python version
Select Python 3.7 or a later version.
Python package
Select the openpyxl package that you installed in Step 2.
Description
Enter a brief description for the task.
-
Click OK to create the task.
Step 4: Write and run Python code
-
On the code editing page, write the code. Replace
test.xlsxwith the name of your uploaded file.# -*- coding: utf-8 -*- import os import sys import openpyxl print ('========= python execute ok ==========') print("start===============") @resource_reference{"test.xlsx"} # Open the Excel file and get the sheet name. wb = openpyxl.load_workbook("test.xlsx") # The wb.get_sheet_names method is deprecated and will generate a warning. print(wb.worksheets[0]) -
Click Run at the top of the page to run the task.
A
SUCCESSstatus indicates that the file was read successfully.