要在代码示例中包含一个剧本,可以使用多行字符串或文件的方式来表示剧本内容。
使用多行字符串示例:
script = """
INT. LIVING ROOM - DAY
John is sitting on the couch, reading a book.
SARAH
(entering the room)
Hey John, how was your day?
JOHN
(looking up from the book)
It was good, thanks! How about yours?
SARAH
(sitting next to John)
Mine was busy, but productive. What are you reading?
JOHN
(showing the book)
I'm reading a sci-fi novel. It's really interesting.
SARAH
(smiling)
That sounds fun. Mind if I join you?
JOHN
(scooting over)
Not at all, there's plenty of space.
They both sit on the couch and continue reading.
"""
print(script)
使用文件示例:
# 将剧本内容保存到script.txt文件中
with open('script.txt', 'w') as file:
file.write('''
INT. LIVING ROOM - DAY
John is sitting on the couch, reading a book.
SARAH
(entering the room)
Hey John, how was your day?
JOHN
(looking up from the book)
It was good, thanks! How about yours?
SARAH
(sitting next to John)
Mine was busy, but productive. What are you reading?
JOHN
(showing the book)
I'm reading a sci-fi novel. It's really interesting.
SARAH
(smiling)
That sounds fun. Mind if I join you?
JOHN
(scooting over)
Not at all, there's plenty of space.
They both sit on the couch and continue reading.
''')
# 读取并打印script.txt文件内容
with open('script.txt', 'r') as file:
script = file.read()
print(script)
无论是使用多行字符串还是文件,都可以将剧本内容包含在代码示例中,并以字符串形式进行处理、打印或其他操作。