Skip to content

Question Regarding Global Statements #154

@Keydex

Description

@Keydex

Hello!

I wanted to read more on the references on this page https://docs.quantifiedcode.com/python-anti-patterns/maintainability/using_the_global_statement.html

I know the book entails things you should "NEVER" do in practice. So I ask this in the context of putting things in the global scope.

Do we consider instantiating built in modules like logger anti patterns? Or should this be something that should be encapsulated in its own class.

import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

Or perhaps this was meant to deter a developer from using the global statement.

The logging function is something I want to instantiate on any files that logs and it seems safe if I define it everywhere.
The logging module is intended to be thread-safe without any special work needing to be done by its clients. It achieves this though using threading locks; there is one lock to serialize access to the module’s shared data, and each handler also creates a lock to serialize access to its underlying I/O.
https://docs.python.org/3/library/logging.html#thread-safety

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions