I am using flycheck for for Python. For global files that I set using ( globals()['variable']), and later used, it gives the following warning message: undefined name <variable> [F821]


globals()['var1'] = "hello_world"
print(var1) # undefined name 'fID' [F821]

It underlines and colors it with red color.

enter image description here

Added lines to .emacs

(require 'flycheck)
(add-hook 'after-init-hook #'global-flycheck-mode)
(setq-default flycheck-flake8-maximum-line-length 160)
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(setq flycheck-emacs-lisp-load-path 'inherit)
  • 2
    There are nothing to do about it on Emacs side. It's from code checker. flake8 I guess.
    – muffinmad
    Commented Nov 25, 2019 at 10:23
  • @muffinmad Should I ask this question on stackoverflow refering to flake8?
    – alper
    Commented Nov 25, 2019 at 16:18
  • Yes, I think it will help solve your issue.
    – muffinmad
    Commented Nov 26, 2019 at 8:06
  • I have asked but community has removed my question :( @muffinmad
    – alper
    Commented Jan 11, 2020 at 20:19

1 Answer 1


A turnaround is to declare the variable.

# Make flake8 happy
if "var1" not in globals():
    var1 = None

globals()['var1'] = "hello_world"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.