[Tutor] global variables

Chris Down chris at chrisdown.name
Thu Aug 22 14:40:34 CEST 2013


On 2013-08-22 13:36, Matthew Ngaha wrote:
> I'm always told to avoid using them. I read discussions on the python
> irc channel about them but honestly i feel there are some times where
> i can't avoid using them. Like where i want to keep track of a state
> variable in many different functions that may or may not alter its
> value and also not wanting any of the functions to return it to the
> caller.

It sounds like you want to use a class.

> My question is how many global variables did your last decent sized
> program have? Also please share any insight you have about them. I do
> try to avoid them, but is this always possible?

I don't have any global variables in any of my projects, and I've been
programming Python in some capacity for almost 8 years now. Why would you not
just use a class if you want to store state?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20130822/02883212/attachment.sig>


More information about the Tutor mailing list