如何获取对象函数的输出为变量

我对此并不陌生,并尝试将此函数的输出作为字符串传递给tweepy更新方法(以雕像形式发布)

              def hello():
                  name = str(input("Enter your name: "))
               if name:
                  print ("Hello " + str(name))
               else:
                 print("Hello World") 
                 return 

                 hello()

这里的问题是Tweepy的“ api.update_status(status)”仅接受字符串或包含字符串的变量。使用函数调用可打印出错误。

如何进行这个简单的过程?

我试图将函数输出作为变量传递

             test = hello()

但是将错误输出到Twitter。

              ...
              api.update_status (test)
xy252510631 回答:如何获取对象函数的输出为变量

您的函数返回None对象,您的函数应返回类似 上面提到的@furas。

尝试一下:

def hello():
    name = input("Enter your name: ")
    if name:
        return "Hello " + name
    else:
        return "Hello World"


hello()

,您仍然将函数调用传递给api

api.update_status(hello())
本文链接:https://www.f2er.com/3127873.html

大家都在问