[英]Read more than one line of a file
我正在使用python應用程序為腳本(ish)視覺小說框架創建接口。 現在,我能夠讀取文件,創建標簽或函數,但是當我讀取它們時,它只讀取一行。 有點像這樣:
>>> from freddie import Freddie
>>> check = Freddie()
>>> check.read_script('script')
>>> check.read_label('start')
'label start:\n' # Only reads the first line and the whitespace
整個標簽是:
label start:
test "Lorem ipsum"
test "Sir amet"
return
我的職能是:
def read_label(self, label):
search_label = re.search("label %s(.*)\s" % label, self.scripts.read(), re.MULTILINE)
return search_label.group()
有沒有辦法使正則表達式讀取整個標簽和空格?
謝謝你的時間。
的.
在正則表達式通常匹配除 “\\ n”個的任何字符,因此,正則表達式僅第一行(匹配\\s
的“\\ n”個在該行的末尾匹配)。
如果您想要.
要匹配包括 “ \\ n” 在內的任何字符,請使用DOTALL
標志。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.