HiddenLayer555@lemmy.ml to Programmer Humor@programming.devEnglish · 9 months agoPython needs an actual default functionlemmy.mlimagemessage-square5linkfedilinkarrow-up11arrow-down10file-text
arrow-up11arrow-down1imagePython needs an actual default functionlemmy.mlHiddenLayer555@lemmy.ml to Programmer Humor@programming.devEnglish · 9 months agomessage-square5linkfedilinkfile-text
Also, do y’all call main() in the if block or do you just put the code you want to run in the if block?
minus-squarebastion@feddit.nllinkfedilinkarrow-up0·9 months agoI always use if "__main__" == main: __main__() …and earlier in the code: def __main__(): while True: pass main = "__main__" This helps to prevent people from arbitrarily running my code as a library or executable when I don’t went them to.
I call main() in the if
I always use
if "__main__" == main: __main__()…and earlier in the code:
def __main__(): while True: pass main = "__main__"This helps to prevent people from arbitrarily running my code as a library or executable when I don’t went them to.