Работаем с атрибутами объектов
Помимо привычного обращения к атрибутам объектов через точку, в Python есть 4 специальных функции: getattr, setattr, delattr и hasattr.
По названиям можно понять, что первые три отвечают за получение, установку и удаление атрибута. А последний проверяет, существует ли атрибут с указанным названием у объекта или нет.
Во всех функциях первыми двумя аргументами идут объект и название атрибута в виде строки. В setattr также нужно передать новое значение для атрибута.
На практике использование подобного — довольно редкий случай, но иногда может сильно выручить, так что берите на вооружение.
#python#tips
Writing #tips from #fiction Authors:
"Read it aloud to yourself because that's the only way to be sure the rhythms of the sentences are OK (prose rhythms are too complex and subtle to be thought out—they can be got right only by ear)."
— Diana Athill
@WritersCafe
Writing #Tips from #Fiction Author:
"It's doubtful that anyone with an internet connection at his workplace is writing good fiction."
— Jonathan Franzen
@WritersCafe
Writing #Tips from #Fiction Authors:
"In the planning stage of a book, don't plan the ending. It has to be earned by all that will go before it." — Rose Tremain
"Always carry a note-book. And I mean always. The short-term memory only retains information for three minutes; unless it is committed to paper you can lose an idea for ever." — Will Self
@WritersCafe
Writing #Tips from #Fiction Author's:
"Introduce your main characters and themes in the first third of your novel. If you are writing a plot-driven genre novel make sure all your major themes/plot elements are introduced in the first third, which you can call the introduction. Develop your themes and characters in your second third, the development. Resolve your themes, mysteries and so on in the final third, the resolution."
— Michael Moorcock
@WritersCafe
Writing #Tips from #Fiction Author's:
"Protect the time and space in which you write. Keep everybody away from it, even the people who are most important to you."
— Zadie Smith
@WritersCafe