Online Tools Toolshu.com Log In Sign Up

Using the Online Python Environment to Upload and Call Custom Code Examples

Original Author:bhnw Released on 2025-12-23 13:46 53 views Star (0)

For beginners or temporary users who need to reuse custom code and conduct modular development, configuring the local environment and managing files is often cumbersome. This article will introduce how to use the Online Python Runtime Tool (based on Python 3.12.7) to upload your own custom code files directly in the browser without local software installation, realizing code import, calling and execution, and improving code reusability and development efficiency.

Tool Features (Advantages for Custom Code Upload and Calling)

  • Supports Python 3.12.7 and standard libraries, compatible with custom Python scripts (.py files)
  • Built-in virtual file system that supports uploading, creating, editing, saving and calling custom code files
  • Perfectly supports modular import; multiple associated scripts can be uploaded for cross-file calling
  • Instant code execution with real-time output of calling results, supporting debugging of custom modules
  • No need to configure local environment variables, suitable for modular code verification, teaching demonstrations and lightweight project development

Tool Address: https://toolshu.com/en/python3

Core Usage Process: Upload Custom Code + Call and Execute

Scenario Description: First, we create a custom Python file

  • Utility script (my_utils.py): Encapsulates commonly used calculation, data processing and other custom functions (can be written locally and then uploaded, or created online)

Step 1: Prepare Custom Code Files (Written Locally for Upload)

First, write Python scripts locally (or directly write in the online environment and then save the code files locally), and then upload them to the online environment to realize modular calling.

Custom Utility Script: my_utils.py (Encapsulating Reusable Functions)

# Custom utility class: encapsulates commonly used reusable functions
def calculate_sum(a, b):
    """Custom addition calculation function, returns the sum of two numbers"""
    return a + b

def multiply_list(num_list):
    """Custom list multiplication function, returns the product of all elements in the list"""
    result = 1
    for num in num_list:
        result *= num
    return result

def format_string(text, prefix="[Custom Prefix]", suffix="[Custom Suffix]"):
    """Custom string formatting function, adds prefix and suffix to the text"""
    return f"{prefix}{text}{suffix}"

# Optional: Test code (only takes effect when running locally, does not affect main script calling after upload)
if __name__ == "__main__":
    print("Local test of my_utils.py functions")
    print(calculate_sum(2, 3))
    print(multiply_list([1,2,3,4]))
    print(format_string("Test Text"))

Step 2: Upload Custom Code Files to the Online Python Environment

  1. Open the online Python tool: https://toolshu.com/python3
  2. Find the "Files" function in the interface and click to expand the file management panel
  3. In the file management panel, find the "Upload File" button
  4. Click "Upload File", and in the pop-up local file selection window, select the locally written my_utils.py to complete the upload
    • Tip: Batch upload or single sequential upload is supported. After uploading, files are stored in the same level directory of the compiler environment by default
  5. After the upload is completed, you can see the my_utils.py file in the "File List", indicating that the file upload is successful

Step 3: Call and Execute Custom Code in the Interactive Editor

  1. Clear the default content of the online editor and directly enter the following import and calling code:
    # Directly import the uploaded custom script in the interactive editor
    import my_utils
    from my_utils import format_string  # Directly import the specific function name
    
    # Quickly call custom functions
    print("Direct call to custom function: ", my_utils.calculate_sum(100, 200))
    print("Direct call to custom list multiplication function: ", my_utils.multiply_list([2, 4, 6, 8]))
    print("Direct call to custom string formatting function: ", format_string("Interactive Call Test"))
    
  2. Click the "Run" button to quickly verify the availability of the custom code

Step 4: View Calling Results and File Management

  1. View Execution Results: After running, the console will output the calling log of the custom function, allowing you to intuitively view the calculation results and formatting effects, and verify whether the code logic is correct
  2. Edit Custom Code: If you need to modify the function logic, you can modify it locally and then re-upload the new code file to the "File List" to take effect
  3. Cross-File Calling with Multiple Files: If there are multiple custom modules (such as my_calc.py, my_data.py), you only need to upload all of them to the same directory, and then you can import and call them separately in the main script to realize complex modular development

Common Scenario Examples

Scenario 1: Upload Custom Utility Class to Realize Reusable Data Processing

# Custom data processing script: my_data_processor.py (called after upload)
def clean_data(data_list):
    """Remove null values and duplicate values from the list, and return the cleaned list"""
    # Remove null values
    non_null_data = [item for item in data_list if item is not None and item != ""]
    # Remove duplicate values
    unique_data = list(dict.fromkeys(non_null_data))
    return unique_data

def sort_data(data_list, reverse=False):
    """Sort the list, ascending by default; set reverse=True for descending order"""
    return sorted(data_list, reverse=reverse)
# Main script: call the data processing utility class
from my_data_processor import clean_data, sort_data

# Raw data to be processed
raw_data = [10, 5, None, 8, 10, "", 3, 8]
# Clean data
cleaned_data = clean_data(raw_data)
print("Cleaned data: ", cleaned_data)
# Sort data
sorted_data = sort_data(cleaned_data, reverse=True)
print("Data sorted in descending order: ", sorted_data)

Scenario 2: Upload Custom Business Script to Realize Specific Function Calling

# Custom business script: my_business.py (called after upload)
def calculate_monthly_profit(revenue, cost):
    """Calculate monthly profit: Profit = Revenue - Cost"""
    profit = revenue - cost
    return profit, f"Monthly Revenue: {revenue} Yuan, Monthly Cost: {cost} Yuan, Monthly Profit: {profit} Yuan"

def judge_profit_status(profit):
    """Judge the profit status"""
    if profit > 10000:
        return "Good Profitability"
    elif profit > 0:
        return "Slight Profit"
    elif profit == 0:
        return "Break-even"
    else:
        return "Loss Status"
# Main script: call the business script to realize profit calculation
import my_business

# Pass in business data
monthly_revenue = 50000
monthly_cost = 28000

# Call custom business functions
profit_amount, profit_desc = my_business.calculate_monthly_profit(monthly_revenue, monthly_cost)
profit_status = my_business.judge_profit_status(profit_amount)

# Output results
print(profit_desc)
print(f"This month's profit status: {profit_status}")

Notes

  1. The uploaded custom code files must have the suffix .py and no syntax errors in the files, otherwise the import and calling will fail
  2. When calling multiple files, ensure that all associated files are stored in the same directory (the default root directory of the online tool) to avoid import path errors
  3. Files in the virtual file system are bound to the current session and may be lost when the browser page is closed. It is recommended to download the modified custom code in a timely manner
  4. If the custom code depends on third-party libraries (such as Pandas, NumPy), you need to install the corresponding libraries in the online environment first, and then import and call them
  5. It is suitable for calling small and medium-sized modular scripts. It is not recommended to upload oversized files (such as more than 10MB) or custom code with high resource consumption

Summary

This online Python tool not only supports quick writing and execution of single-file code, but also realizes modular calling of custom code through the file upload function, which significantly reduces the entry threshold for Python modular development. Without configuring the local environment, you can realize the reuse, editing and debugging of custom scripts, which is especially suitable for teaching demonstrations, code verification, temporary project development and modular logic testing.

Experience uploading and calling custom code now: https://toolshu.com/en/python3

发现周边 发现周边
Comment area

Loading...