Problem 1: A CodeFile class Write a CodeFile class with:
时间: 2024-05-14 14:14:28 浏览: 83
attributes:
- filename (string)
- language (string)
- content (string)
methods:
- __init__(self, filename, language, content): initializes a CodeFile object with the given filename, language, and content
- get_filename(self): returns the filename of the CodeFile object
- get_language(self): returns the language of the CodeFile object
- get_content(self): returns the content of the CodeFile object
- set_filename(self, new_filename): updates the filename of the CodeFile object to the new_filename parameter
- set_language(self, new_language): updates the language of the CodeFile object to the new_language parameter
- set_content(self, new_content): updates the content of the CodeFile object to the new_content parameter
Example usage:
```
file1 = CodeFile("hello.py", "Python", "print('Hello, world!')")
print(file1.get_filename()) # "hello.py"
print(file1.get_language()) # "Python"
print(file1.get_content()) # "print('Hello, world!')"
file1.set_filename("greetings.py")
file1.set_language("Python 3")
file1.set_content("print('Greetings, world!')")
print(file1.get_filename()) # "greetings.py"
print(file1.get_language()) # "Python 3"
print(file1.get_content()) # "print('Greetings, world!')"
```
阅读全文