#๐Ÿ”’ code review

28 messages ยท Page 1 of 1 (latest)

quiet thunderBOT
#

@median mica

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

remote elbow
#

lgtm

median mica
median mica
remote elbow
#

ah

spiral garden
median mica
#

i started writing the code without knowing about if __name__ == '__main__' at first so i just threw it in there, tried adding it to a main() function but it messes up with scopes

#

but thanks

spiral garden
#

I'd also avoid using exec

#

Put your alienShoot{...} stuff in a dict

median mica
timber plover
# median mica whats wrong with exec?

For one, there's no point in using them how you've used them. For two exec is a bit dangerous because it executes anything its given so when coders use exec to run stuff that's input by a user, you need to consider that the user might supply "bad things"โ„ข๏ธ

#

But um, there's way too many globals in this

median mica
timber plover
#

Can I ask what your thoughts process was behind the execs?

Like, what does exec add to the following line?

exec(f'alienShootList.append(alienShot{alienShootCounter})')

median mica
#

i was pretty rushed when doing this for a class around 2 years ago and i needed a way to "join" a string and a variable and couldnt think of a better solution at the time

timber plover
#

You don't need the exec at all. It's just:

alienShootList.append(alienShot{alienShootCounter})

weak siren
median mica
#

^

weak siren
#

which was the reason for this

median mica
#

pretty stupid, but

timber plover
#

Oh. Well it should just be a dict

weak siren
spiral garden
#

You can use globals()[f"alienShot{alienShootCounter}"] for the simplest change away from exec

quiet thunderBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.