访问python类之外的文件

2024-03-28 09:54:29 发布

您现在位置:Python中文网/ 问答频道 /正文

有一个文件“words.txt”我必须访问它

WORDLIST_FILENAME = 'words.txt'

class Message(object):
  def __init__(self, text):
    self.text = text
    '''
    Initializes a Message object

    text (string): the message's text

    a Message object has two attributes:
        self.message_text (string, determined by input text)
        self.valid_words (list, determined using helper function load_words)
    '''
    # pass #delete this line and replace with your code here

  def get_message_text(self):
    '''
    Used to safely access self.message_text outside of the class
    Returns: self.message_text
    '''
    # pass #delete this line and replace with your code here

有人能帮我吗


Tags: thetextselftxtmessagestringobjectdef