본문 바로가기

Practical Python Design Patterns22

The Prototype Pattern CHAPTER 3 The Prototype Pattern Reality doesn t care if you believe in it. Boba Fett, StarWars extended universe The Problem I can still remember the very first time I wanted to program anything. This was at a time when DOS could not address more than 20 MB at a time, and thus our massive 40 MB hard drive had to be partitioned into two drives. It was a beige Olivetti XT. The local library had a .. 2023. 3. 28.
The Singleton Pattern The Problem We only have a single file to update. Let s create a new file called logger.py and write the following code in the file: logger.py def log_message(msg): with open("./var/log/filename.log", "a") as log_file: log_file.write("{0}\n".format(msg)) if __name__ == "__main__": log_message("error!") Now, we can use our new logger function to write log messages to the file system in our main_s.. 2023. 3. 28.
Before We Begin Becoming a Better Programmer To become a better programmer, you need to decide to obsess about mastery. Every day is a new opportunity to become better than the day before. Every line of code is an opportunity to improve. How do you do that? When you must work on a piece of existing code, leave the code better than you found it. Try to complete a quick problem-solving challenge every day. Look f.. 2023. 3. 28.
Index Practical Python Design Patterns: Pythonic Solutions to Common Problems Wessel Badenhorst Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book s product page, located at www.apress.com/9781484226797. For more detailed information, please visit http://www.apress.com/source-code. Printed on acid-free paper For Tanya, m.. 2023. 3. 28.