Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python编程困难_Python - Fatal编程技术网

Python编程困难

Python编程困难,python,Python,我有两个计划,我正在努力工作。twitter.py被认为是Tweet.py的管理者。Twitter添加了新的推文,查看最近5条推文,旁边的时间单位最高,例如: Recent Tweets ------------ Dave - 5min Hello world! Tweet定义Tweet.py要管理的类Tweet。Tweet类有三个数据属性:uuu author、uu age和uu text,还有四个方法:get_author、get_text和get_age special,因为假定它计算当

我有两个计划,我正在努力工作。twitter.py被认为是Tweet.py的管理者。Twitter添加了新的推文,查看最近5条推文,旁边的时间单位最高,例如:

Recent Tweets
------------
Dave - 5min
Hello world!
Tweet定义Tweet.py要管理的类Tweet。Tweet类有三个数据属性:uuu author、uu age和uu text,还有四个方法:get_author、get_text和get_age special,因为假定它计算当前时间和u age值之间的差,然后将其作为字符串返回。第三个选项应该允许搜索推文中的任何关键词

例:

twitter.py-

我遇到的问题是:

在执行选项2时,它跳转到消息,而不是显示字典中的任何推文。我没有添加任何推文吗? 在执行选项3时,当没有任何tweets-没有包含tweets时,它会显示假定的消息
所以,我猜我没有在列表中添加任何tweet。我说的对吗?

在twitter.py文件的添加方法中:

def add(mytweets):

    author = input("\nWhat is your name? ")
    while True:
        text = input("what would you like to tweet? ")
        if len(text) > 140:
            print("\nTweets can only be 140 characters!")
            continue
        else:
            break




    entry = Tweet.Tweet(author, text)

    print("\nYour tweet has been saved!")
您没有将Tweet添加到任何字典或列表中,您基本上只是读取用户输入并创建Tweet类的实例

因此,您需要添加以下内容:

mytweets.update({author:text})

您能否澄清选择2的含义?请阅读并尝试改进您的问题,例如,使用更好的标题,并解释为什么有两个python脚本以及它们之间的关系等。请您更好地解释您的问题?
import time

class Tweet:

    def __init__(self, author, text):

        self.__author = author
        self.__text = text
        self.__age = time.time()

    def get_author(self):

        return self.__author

    def get_text(self):

        return self.__text

    def get_age(self):
        now = time.time()

        difference = now - self.__time

        hours = difference // 3600

        difference = difference % 3600

        minutes = difference // 60

        seconds = difference % 60


        # Truncate units of time and convert them to strings for output
        hours = str(int(hours))
        minutes = str(int(minutes))
        seconds = str(int(seconds))

        # Return formatted units of time
        return hours + ":" + minutes + ":" + seconds
def add(mytweets):

    author = input("\nWhat is your name? ")
    while True:
        text = input("what would you like to tweet? ")
        if len(text) > 140:
            print("\nTweets can only be 140 characters!")
            continue
        else:
            break




    entry = Tweet.Tweet(author, text)

    print("\nYour tweet has been saved!")
mytweets.update({author:text})