Предположим, что я создал учетную запись службы Google и у меня есть идентификатор документа Google doc_ID.
Проблема:
Когда у меня есть только 2 типа элементов (вложенный список и обычный текст), в соответствии с предложением @Tanaike https://stackoverflow.com/a/78541593/25276165, я успешно записал содержимое в документ Google. Теперь я хочу обобщить свой список, включив в него различные другие элементы. Таким образом, мои списки выглядят следующим образом:
Код: Выделить всё
my_list =
[
"This is the normal text line, without any itemized list format.",
"* This is the outermost list item (number)",
" * This is a first-level indented list item (alpha)",
"# Top-level Heading",
"* This is an outermost list item (number) under the heading, with new numbering",
" * This is a first-level indented list item (alpha) under the heading",
"This is the final normal text line, without any itemized list format.",
]
Чтобы обслуживать различные типы элементов списка, я в первую очередь решил использовать цикл for с условиями if, как показано ниже:
Код: Выделить всё
requests = []
for item in my_list:
if item.startswith("# "):
text = item[2:] + '\n'
end_index = start_index + len(text)
it_request = heading_request(text, start_index, end_index)
elif item.startswith("* "):
text = item[2:] + '\n'
end_index = start_index + len(text)
indent_first = 18
indent_hang = 36
it_request = list_request(text, start_index, end_index)
elif item.startswith(" * "):
text = item[4:] + '\n'
end_index = start_index + len(text)
indent_first = 36
indent_hang = 54
it_request = list_request(text, start_index, end_index)
else:
text = item + '\n'
end_index = start_index + len(text)
it_request = text_request(text, start_index, end_index)
requests.append(it_request)
start_index = end_index
Ожидаемый результат
[img]https:/ /i.sstatic.net/wSKdVSY8.png[/img]
Как это можно успешно запрограммировать, чтобы с помощью API Документов Google я мог писать в документ Google с желаемыми вложенными отступами и текстом типы?
Подробнее здесь: https://stackoverflow.com/questions/785 ... document-p