Apologies, what frees the "table" variable memory, the exit of the calling code?
DEC pack, unpack and disk-images
DEC pack, unpack and disk-images
|
Jun-18-2024, 07:32 AM
(This post was last modified: Jun-18-2024, 07:32 AM by Gribouillis.)
(Jun-18-2024, 06:52 AM)Curbie Wrote: Apologies, what frees the "table" variable memory, the exit of the calling code?The 256 bytes are freed when the program exits because 'table' is a global variable. You can free them earlier if you don't need to pack() or unpack() anymore. You can free them by deleting the 'table' variable or assigning None to this variable. There is little benefit in doing this because 256 bytes is a small amount of memory.
« We can solve any problem by introducing an extra level of indirection »
Jun-18-2024, 11:37 PM
Quote:because 'table' is a global variablestupid question, are both 'table' and 'res' global variables, if not what makes a global variable?
Jun-19-2024, 07:03 AM
(This post was last modified: Jun-19-2024, 07:03 AM by Gribouillis.)
(Jun-18-2024, 11:37 PM)Curbie Wrote: stupid question, are both 'table' and 'res' global variables, if not what makes a global variable?Yes they are global variables because they are defined at module level and not in the body of a function. In the following code spam = 25 def eggs(): ham = 36 spam is a global variable and ham is a local variable of function eggs() . When function eggs() is called, ham is destroyed at function exit. Spam is never destroyed, unless we write at module leveldel spamWe could also do spam = "...some memory intensive data..." spam = None # does not destroy the name 'spam' but destroys the value at which it points.
« We can solve any problem by introducing an extra level of indirection »
Jun-19-2024, 03:31 PM
Thanks,
If I understand correctly, local variables can ONLY be accessed by the function in which contains them, global variables are outside functions that all functions can access within that module. (and possibly importing modules, question to follow) I think I understand that module functions can be called by either importing the whole module or the particular function from that module, but are global variables initialized if I import and call a particular function in a module, seems like they must be but, still trying to head-wrap this stuff? Can Global variables from an imported module be accessed from the importing module? I haven't found any py libraries tutorial, and I think I'll need to do a spread-sheet on and read every py library to document their content functions unless there is a better suggestion?
Jun-19-2024, 06:42 PM
(This post was last modified: Jun-19-2024, 06:43 PM by Gribouillis.)
(Jun-19-2024, 03:31 PM)Curbie Wrote: are global variables initialized if I import and call a particular function in a module, seems like they must be but, still trying to head-wrap this stuff?Yes. The first time a pure Python module is imported, the code that it contains is executed, hence the global variables are assigned. Also note that functions and classes defined at module level are global variables too. >>> def spam(): ... pass ... >>> spam <function spam at 0x7ff2fb34db40> (Jun-19-2024, 03:31 PM)Curbie Wrote: Can Global variables from an imported module be accessed from the importing module?Yes. (Jun-19-2024, 03:31 PM)Curbie Wrote: I haven't found any py libraries tutorialYour first source of documentation is the official documentation, especially the standard library. Searching the standard library can be a little tedious, you could use my 'pyman' script in a terminal. For example if you type pyman pathlib it will open the Python documentation with the search term pathlib.A comprehensive introduction to the standard library's modules is the pyMOTW-3 site by Doug Hellmann. He gives example code for many standard modules.
« We can solve any problem by introducing an extra level of indirection »
Jun-20-2024, 04:14 PM
thanks Gribouillis,
In light of your "pyman" script and library references I my need to go back to my notes to see if i can create a local library text file of notes on py scripting and py libraries, although, I need work more work with debuggers before I do anything, tutorials show how py scripts work, not how to fix py scripts that don't work. I need to ponder this some. more curbie |
|
Users browsing this thread: 1 Guest(s)