[Tutor] global variables/constants versus volatile variables/constants

Dave Angel davea at davea.name
Fri Jun 13 13:33:53 CEST 2014


diliup gabadamudalige <diliupg at gmail.com> Wrote in message:
>
 there are many dictionaries and lists which are used in various functions. Is it better/pythonic/efficient to have these inside the function itself or declared at the beginning of the program in which case they will be global? They are all read only. I understand that global constants and variable have memory allocated to them but when declared inside a function are created on the fly, used and discarded. 
> 

(Please use text mail to post here, not html. Html messages can
 cause several kinds of problems in a text mailing list.
 )

If they are read-only, you don't want to waste time recreating
 them over and over.  Neither do you want to be repeating the code
 that initializes them. So make them either global or a class
 member, and be sure to name them all caps to signify they
 shouldn't be altered. 

-- 
DaveA



More information about the Tutor mailing list