使用列表时如何找到特定的字符串?
我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论