使用列表时如何找到特定的字符串?

发布于 2025-01-25 05:26:26 字数 1365 浏览 1 评论 0原文

我正在使用Python和Cpython制作简单的fileReader。但是,我意识到它显示了一个错误,即typeError:'List'对象必须归因于查找。有什么方法可以在列表中找到特定的角色并返回它?谢谢:D

主Python模块

import io;

class AdvancedReader(object):
  def __init__(self, file, mode=None, buffering=None, encoding=None, *args):
    data_file = io.open(file, mode=mode, buffering=buffering, encoding=encoding)
    striped_list = [lines.strip() for lines in (data_file.readlines())]
    if any(map('['.startswith and ']'.endswith, striped_list)):
       _starter = ([for item in striped_list.startswith('[')])
       # stater = striped_list.filter('[', ‘]’) #Removing brackets

简单使用类,

AdvancedReader('settings.def', mode='r', buffering=-1, encoding='utf-8')

这是我的类内显示的Atributte错误...

Traceback (most recent call last):
File "main. py"
, line 13, in «module>
AdvancedReader("settinas.def".mode='r', buffering=-1. encoding='utf-g)
File "main.py", line 9, in
init
print(striped list. find(r))
AttributeError: list' object has no attribute 'find'

这是settings.def文件,实际上它仅适用于Python的新型存储/文件系统。

[SYSTEM] // Begining acronym
 start: os.system('echo hello world')
[/SYSTEM] // Ending acronym

I was making my simple filereader using python and cpython. But, I realized that it displayed an error that is TypeError: 'list' object has to attribute to find. Is there any way to find a specific character inside a list and return it? Thanks :D

Main python module

import io;

class AdvancedReader(object):
  def __init__(self, file, mode=None, buffering=None, encoding=None, *args):
    data_file = io.open(file, mode=mode, buffering=buffering, encoding=encoding)
    striped_list = [lines.strip() for lines in (data_file.readlines())]
    if any(map('['.startswith and ']'.endswith, striped_list)):
       _starter = ([for item in striped_list.startswith('[')])
       # stater = striped_list.filter('[', ‘]’) #Removing brackets

Simple using for class

AdvancedReader('settings.def', mode='r', buffering=-1, encoding='utf-8')

This is the atributte error that displayed inside my class...

Traceback (most recent call last):
File "main. py"
, line 13, in «module>
AdvancedReader("settinas.def".mode='r', buffering=-1. encoding='utf-g)
File "main.py", line 9, in
init
print(striped list. find(r))
AttributeError: list' object has no attribute 'find'

This is the settings.def file, its practically a new type of storage/file systax for python only.

[SYSTEM] // Begining acronym
 start: os.system('echo hello world')
[/SYSTEM] // Ending acronym

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文