简体   繁体   English

AttributeError: 'function' object 没有属性 'split'。 我该如何解决?

[英]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:您的代码有两点错误:

  1. 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

  2. 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.

相关问题 AttributeError: 'function' object 没有属性 'read' — 我该如何修复? - AttributeError: 'function' object has no attribute 'read' — HOW CAN I FIX? 我该如何解决这个问题:AttributeError: 'NoneType' object has no attribute 'strip - How can i fix this :AttributeError: 'NoneType' object has no attribute 'strip 我该如何修复,AttributeError: 'NoneType' 对象没有属性 'send' - How can I fix, AttributeError: 'NoneType' object has no attribute 'send' AttributeError: 'int' 对象没有属性 'get' 我该如何修复它 - AttributeError: 'int' object has no attribute 'get' how can i fix it 如何修复错误 AttributeError: 'function' object has no attribute 'str' - How can I fix the error AttributeError: 'function' object has no attribute 'str' 如何修复 AttributeError: 'module' 对象没有属性 'function'? - How to fix AttributeError: 'module' object has no attribute 'function'? 如何修复“AttributeError:'function'对象没有属性'rcParams'” - How to fix “AttributeError: 'function' object has no attribute 'rcParams'” 如何修复 AttributeError: 'NoneType' object 没有属性 'lower'? - How do i fix AttributeError: 'NoneType' object has no attribute 'lower'? 如何修复此 AttributeError: 'SubRequest' object 没有属性 'getfuncargvalue'? - How do I fix this AttributeError: 'SubRequest' object has no attribute 'getfuncargvalue'? 我该如何解决这个 AttributeError: 'NoneType' object has no attribute 'text'? - How do i fix this AttributeError: 'NoneType' object has no attribute 'text'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM