Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable not available at Spyder's Variable Explorer when naming it with upper case only

Tags:

python

spyder

I'm getting the following problem using Spyder:

If I name a variable just with upper case letters, it is not shown at the Variable Explorer window.

For example, if I name a variable like: Var = 1, it is in the Variable Explorer.

Otherwise, if I name it like: VAR = 1, it is not shown there.

Anyone know why is that and if there is any way to fix it?

(ps: please, I know that I could just "not name them like that", but that's not what I'm asking)

Thanks

like image 445
Mohamad Avatar asked Apr 07 '16 20:04

Mohamad


People also ask

Can a variable start with an uppercase letter?

By Convention: Variable names begin with a lowercase letter, and class names begin with an uppercase letter. If a variable name consists of more than one word, the words are joined together, and each word after the first begins with an uppercase letter, like this: isVisible .

How do I enable variable Explorer in Spyder?

Go to View/Panes and select Variable Explorer. Save this answer. Show activity on this post. Save this answer.

What is variable Explorer?

The Variable Explorer shows the namespace contents (all global object references, such as variables, functions, modules, etc.) of the currently selected IPython Console session, and allows you to interact with them through a variety of GUI-based editors.


1 Answers

I am a newbie in Python and Spyder but I think I can help you. According with the PEP 8 -- Style Guide for Python Code:

"Constants are usually defined on a module level and written in all capital letters with underscores separating words. Examples include MAX_OVERFLOW and TOTAL".

I guess that Spyder uses this convention. If this is the case, the variable explorer does not support constants. The Spyder 2.3 documentation have a list of the types of objects supported and constants are not included:

  1. Pandas DataFrames and TimeSeries
  2. NumPy arrays and matrices
  3. PIL/Pillow images
  4. datetime dates
  5. Integers
  6. Floats
  7. Complex numbers
  8. Lists
  9. Dictionaries
  10. Tuples
  11. Strings

Hope this helps you.

UPDATE: I have just found an Options icon in the vertical bar at the right of the Variables explorer which allows you to enable/disable the uppercase variables.

like image 52
Roberto A. Real-Rangel Avatar answered Sep 27 '22 23:09

Roberto A. Real-Rangel