How to use code open SCDM .scdoc file?

Now my py. file need auto read data, so I put the py. file at data file directory.
but now .scdoc also need in the directory file.
So how to use code open SCDM .scdoc file and read py. file?

Answers

  • CharlesReily
    CharlesReily Member Posts: 2
    First Comment

    It seems like you want to open and read both an .scdoc file and a .py file from the same directory in your Python script. You can use the open function to open and read files in Python. Here's an example of how you can achieve this:

    import os

    Get the current directory

    current_directory = os.path.dirname(os.path.realpath(file))

    Specify the filenames

    scdoc_filename = "your_file.scdoc"
    py_filename = "your_file.py"

    Construct the full paths

    scdoc_path = os.path.join(current_directory, scdoc_filename)
    py_path = os.path.join(current_directory, py_filename)

    Read the content of the .scdoc file

    with open(scdoc_path, 'r') as scdoc_file:
    scdoc_content = scdoc_file.read()
    # Process the content as needed

    Read the content of the .py file

    with open(py_path, 'r') as py_file:
    py_content = py_file.read()
    # Process the content as needed

    Now you can use scdoc_content and py_content in your script