Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9187933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:53:38+00:00 2026-06-17T19:53:38+00:00

Pylint W0603 states: Using the global statement. Used when you use the global statement

  • 0

Pylint W0603 states:

Using the global statement. Used when you use the “global” statement to
update a global variable. PyLint just try to discourage this usage.
That doesn’t mean you can not use it !

I wonder why is it so? Is there any more Pythonic way of modifying immutable, module-wide variables inside a function? Is it recommended to pack them inside mutable variables like dictionaries? Or maybe turn entire module into class?

In my opinion this warning should disappear when variable is suggested to be “private” (prefixed with _ or __).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:53:39+00:00Added an answer on June 17, 2026 at 7:53 pm

    Generalized use of global variables can make maintenance a nightmare, because they make tracing the flow of your program, and sometimes you get weird bug, because some module has read the variable and acted on its value before some other module changed the value of the variable (and this can result from inverting two import statements in some unrelated 3rd module). See also the wikipedia entry on Global variables.

    This is why you should avoid mutable global variables, IMO, and why Pylint issues a warning (and probably should issue more of them. Detecting the use of the global keyword is just an easy way of spotting some of them).

    Don’t take me wrong: I am not saying you must not use global variables. Only that you should avoid using them. There are lots of legit cases for global variables in Python. As long as you don’t get more than a couple W0603, you should fare OK.

    Now, Logilab (the company maintaining Pylint, and where I used to work) once had to take over maintenance of a piece of > 50kloc of Python code, with heavy duplication and 100+ mutable global variables. And this was hell.

    Solutions to work around global variables include:

    • adding a parameter to the functions which need to access the variable
    • using class attributes
    • using instance attributes (by passing the value you need to the constructor of the class)
    • centralizing mutable global values in a Configuration object which is build so that it is instantiated once at program startup (using environment variables, command line, configuration file…) and never mutated after this.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pylint says W: 6: Using possibly undefined loop variable 'n' ... with this code:
In pylint I use this command --reports=n to disable the reports, but now I
I just ran pylint on my code and it shows up this message: Uses
Which static code analyzer (if any) do you use? I've been using PyLint for
I'm using pylint + pydev, with python 2.6. I have a module with just
I am using pylint utility that returns this error codes: Pylint should leave with
I'm using pylint on a Django project and I'm finding myself frequently copy-pasting this
For a block like this: try: #some stuff except Exception: pass pylint raises warning
I got a small problem using pylint to check my python code. I use
I am trying to use pylint to generate uml diagramms for jython code. If

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.