Stream: helpdesk (published)

Topic: global variable but within the function


view this post on Zulip Dale Black (Nov 27 2021 at 02:39):

Is there a way to make a variable inside a function a "semi" global variable? Not sure that I am using the right wording, but for example, inside a function I have

    try
        pixel_size = header[(0x0028, 0x0030)]
    catch
        FOV = header[(0x0018, 0x1100)]
        matrix_size = header[(0x0028, 0x0010)]

        pixel_size = FOV / matrix_size
    end

and I want to make pixel_size available to the rest of the function but not necessarily globally. Is there a way to do this?

view this post on Zulip Mason Protter (Nov 27 2021 at 03:44):

You should be able to just do

    local pixel_size
    try
        pixel_size = header[(0x0028, 0x0030)]
    catch
        FOV = header[(0x0018, 0x1100)]
        matrix_size = header[(0x0028, 0x0010)]

        pixel_size = FOV / matrix_size
    end

Last updated: Oct 02 2023 at 04:34 UTC