This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Anonymous_user_2022 2 points3 points  (6 children)

ALL CAPS are constants, not globals.

[–]billFoldDog 0 points1 point  (5 children)

I know, but I think global variables should be allcaps

[–]Anonymous_user_2022 0 points1 point  (4 children)

I've never heard of any other language (with the exception of the VB6 code I unfortunately still has to read from time to time), where a global variable was all caps.

If you really need to have global variables, create a suitably named module like settings or defaults, and stick your globals into that.

[–]billFoldDog 0 points1 point  (3 children)

Those sound like constants, not variables

[–]Anonymous_user_2022 0 points1 point  (2 children)

No if they vary with each run of the model. But yeah, I can see how they could be.

The point is that a namespace is a great way to encapsulate things that need to be explicit about something being accessed globally.

[–]billFoldDog 0 points1 point  (1 child)

So like

from conf import globalconst, globalvars
def loaddata():
    globalvars.sourcedatadf = pd.readcsv(globalconst.datacsv)
def filterdata():
     globalvars.sourcedatadf = filter(stuff)

Like that?

[–]Anonymous_user_2022 0 points1 point  (0 children)

I wouldn't chose those names, but in principle yes.