[英]AttributeError: 'function' object has no attribute 'split'. How I can fix it?
How i can fix it?我该如何解决? What I can to do with this error?
我能用这个错误做什么?
https://github.com/dandayo/formyhoneygirl/blob/main/main.py https://github.com/dandayo/formyhoneygirl/blob/main/main.py
def link():
with open('data.json', 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
with open('data.json', 'r', encoding='utf-8') as s:
image_url = json.load(s)
print(image_url["url"])
filelName = link.split("/")[-1]+".jpg"
answer = requests.get(link, stream=True)
First of all, please let us know where the error occurs next time, it will make it easier to answer your question.首先,请让我们下次知道错误发生在哪里,这样会更容易回答您的问题。
The issue seems to be with the fact that you are... well.. Indeed calling the function itself and trying to split it, which understandably throws the error.问题似乎在于您......好吧......确实调用 function 本身并尝试拆分它,这是可以理解的抛出错误。 There are 2 things that are wrong with your code:
您的代码有两点错误:
You're not returning anything from the function.您不会从 function 返回任何东西。 Use
return image_url['url']
instead of print.使用
return image_url['url']
而不是打印。 Right now all you're doing is simply printing the value to the console and that's it.现在,您所做的只是将值打印到控制台,仅此而已。 Your function returns
None
.您的 function 返回
None
。
You're using link.split()
, when you should be calling the function by using link().split()
.当您应该使用
link().split()
调用 function 时,您正在使用link.split()
) 。
link
is a function, which incidentally returns nothing. link
是一个 function,它顺便什么也不返回。
split
splits nstrings. split
拆分 nstrings。
link.split("/")
tries to split the function. link.split("/")
尝试拆分 function。
Hence, the error.因此,错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.