С помощью способа, которым вы хотите записать данный текст, это регулярное выражение должно выполнять вашу работу, поскольку оно собирает докладчика, время и текст в три группы и, используя re.findall
, находит весь текст и помещает их в список, где каждый из эти три информации присутствуют в кортеже как один элемент в списке. Проверьте это регулярное выражение,
(.*?)\s+(\[[^[\]]*\]):\s*([\w\W]*?)(?=\n\n|\Z)
Демо
Примеры кодов Python,
import re
s = """HARPER'S [Day 1, 9:00 A.M.]: When the computer was young, the word hacking was
used to describe the work of brilliant students who explored and expanded the
uses to which this new technology might be employed. There was even talk of a
\"hacker ethic.\" Somehow, in the succeeding years, the word has taken on dark
connotations, suggestion the actions of a criminal. What is the hacker ethic,
and does it survive?
ADELAIDE [Day 1, 9:25 A.M.]: the hacker ethic survives, and it is a fraud. It
survives in anyone excited by technology's power to turn many small,
insignificant things into one vast, beautiful thing. It is a fraud because
there is nothing magical about computers that causes a user to undergo
religious conversion and devote himself to the public good. Early automobile
inventors were hackers too. At first the elite drove in luxury. Later
practically everyone had a car. Now we have traffic jams, drunk drivers, air
pollution, and suburban sprawl. The old magic of an automobile occasionally
surfaces, but we possess no delusions that it automatically invades the
consciousness of anyone who sits behind the wheel. Computers are power, and
direct contact with power can bring out the best or worst in a person. It's
tempting to think that everyone exposed to the technology will be grandly
inspired, but, alas, it just ain't so.
BRAND [Day 1, 9:54 A.M.]: The hacker ethic involves several things. One is
avoiding waste; insisting on using idle computer power -- often hacking into a
system to do so, while taking the greatest precautions not to damage the
system. A second goal of many hackers is the free exchange of technical
information. These hackers feel that patent and copyright restrictions slow
down technological advances. A third goal is the advancement of human
knowledge for its own sake. Often this approach is unconventional. People we
call crackers often explore systems and do mischief. The are called hackers by
the press, which doesn't understand the issues.
KK [Day 1, 11:19 A.M.]: The hacker ethic went unnoticed early on because the
explorations of basement tinkerers were very local. Once we all became
connected, the work of these investigations rippled through the world. today
the hacking spirit is alive and kicking in video, satellite TV, and radio. In
some fields they are called chippers, because the modify and peddle altered
chips. Everything that was once said about \"phone phreaks\" can be said about
them too."""
argument = re.findall(r'(.*?)\s+(\[[^[\]]*\]):\s*([\w\W]*?)(?=\n\n|\Z)', s)
print(argument)
Печатает список, содержащий кортеж из трех элементов presenter
, time
и text
[("HARPER'S", '[Day 1, 9:00 A.M.]', 'When the computer was young, the word hacking was\nused to describe the work of brilliant students who explored and expanded the\nuses to which this new technology might be employed. There was even talk of a\n"hacker ethic." Somehow, in the succeeding years, the word has taken on dark\nconnotations, suggestion the actions of a criminal. What is the hacker ethic,\nand does it survive? '), ('ADELAIDE', '[Day 1, 9:25 A.M.]', "the hacker ethic survives, and it is a fraud. It\nsurvives in anyone excited by technology's power to turn many small,\ninsignificant things into one vast, beautiful thing. It is a fraud because\nthere is nothing magical about computers that causes a user to undergo\nreligious conversion and devote himself to the public good. Early automobile\ninventors were hackers too. At first the elite drove in luxury. Later\npractically everyone had a car. Now we have traffic jams, drunk drivers, air\npollution, and suburban sprawl. The old magic of an automobile occasionally\nsurfaces, but we possess no delusions that it automatically invades the\nconsciousness of anyone who sits behind the wheel. Computers are power, and\ndirect contact with power can bring out the best or worst in a person. It's\ntempting to think that everyone exposed to the technology will be grandly\ninspired, but, alas, it just ain't so."), ('BRAND', '[Day 1, 9:54 A.M.]', "The hacker ethic involves several things. One is\navoiding waste; insisting on using idle computer power -- often hacking into a\nsystem to do so, while taking the greatest precautions not to damage the\nsystem. A second goal of many hackers is the free exchange of technical\ninformation. These hackers feel that patent and copyright restrictions slow\ndown technological advances. A third goal is the advancement of human\nknowledge for its own sake. Often this approach is unconventional. People we\ncall crackers often explore systems and do mischief. The are called hackers by\nthe press, which doesn't understand the issues."), ('KK', '[Day 1, 11:19 A.M.]', 'The hacker ethic went unnoticed early on because the\nexplorations of basement tinkerers were very local. Once we all became\nconnected, the work of these investigations rippled through the world. today\nthe hacking spirit is alive and kicking in video, satellite TV, and radio. In\nsome fields they are called chippers, because the modify and peddle altered\nchips. Everything that was once said about "phone phreaks" can be said about\nthem too.')]