简体   繁体   English

AttributeError: 'list' object 没有属性 'replace' Python

[英]AttributeError: 'list' object has no attribute 'replace' Python

What am I missing in the below?我在下面缺少什么? I keep getting error message:我不断收到错误消息:

AttributeError: 'list' object has no attribute 'replace'

I've followed the advice here and elsewhere but something is still not working.我已经听从了这里和其他地方的建议,但仍然无法正常工作。

import json
import requests

search_terms = input('Name of university: ')
parameters = {"affiliation": search_terms}
response = requests.get("https://api.ror.org/organizations", params=parameters)

ror_payload = response.json()

name_variations_provisional = []
for organisation in ror_payload['items']:
    if organisation['chosen']==True:
        name_variations_provisional.append(organisation['organization']['name'])
        name_variations_provisional.append(organisation['organization']['aliases'])
        for relationship in organisation['organization']['relationships']:
            if relationship['type'] == 'Child':
               name_variations_provisional.append(relationship['label'])

#this is the line that's not working
name_variations=[str.replace("C", "") for str in name_variations_provisional]

print(name_variations)

organisation['organization']['aliases'] is probably a list. organisation['organization']['aliases']可能是一个列表。 Use extend() rather than append() so that each element is appended separately, rather than the whole list being appended as a single element.使用extend()而不是append()以便单独附加每个元素,而不是将整个列表作为单个元素附加。

name_variations_provisional.extend(organisation['organization']['aliases'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError: 'list' object 没有属性 'replace' Selenium Python - AttributeError: 'list' object has no attribute 'replace' Selenium Python python AttributeError:“ NoneType”对象在列表中没有属性“ replace” - python AttributeError: 'NoneType' object has no attribute 'replace' in list AttributeError:'list'对象没有属性'replace' - AttributeError: 'list' object has no attribute 'replace' AttributeError: 'list' 对象没有属性 'replace' "fasttext" - AttributeError: 'list' object has no attribute 'replace' "fasttext" AttributeError:“列表”对象没有属性“替换”, - AttributeError: 'list' object has no attribute 'replace', “AttributeError:'list' object 没有属性'replace' - "AttributeError: 'list' object has no attribute 'replace' AttributeError:“ filter”对象在Python 3中没有属性“ replace” - AttributeError: 'filter' object has no attribute 'replace' in Python 3 Python-AttributeError:“ dict”对象没有属性“ replace” - Python - AttributeError: 'dict' object has no attribute 'replace' Python:AttributeError:'int'对象没有属性'replace' - Python: AttributeError: 'int' object has no attribute 'replace' Python:“AttributeError:'NoneType' object 没有属性'replace'” - Python: "AttributeError: 'NoneType' object has no attribute 'replace' "
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM