Here is a simple Python class that you can run in another Python file:

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def say_hello(self):
        print("Hello, my name is", self.name, "and I am", self.age, "years old.")

# Create an instance of the Person class
person1 = Person("John", 30)

# Call the say_hello method on the person1 instance
person1.say_hello()

To run this class in another Python file, you just need to import it and create an instance of the class:

from my_module import Person

# Create an instance of the Person class
person1 = Person("John", 30)

# Call the say_hello method on the person1 instance
person1.say_hello()

Make sure that the class is saved in a separate Python file called "my_module.py" in the same directory as your main Python file.

write python class coding, run the class in other python file, simple for beginner

原文地址: http://www.cveoy.top/t/topic/yY2 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录