#๐ code review
28 messages ยท Page 1 of 1 (latest)
@median mica
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.
lgtm
couldnt upload the rar
ah
Best to have only one function call in if __name__ == "__main__":
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
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
how would i do it without the use of globals? since i cant change the variable outside the current scope right?
You would either return the data you require.
Or you encapsulate the game data into a class (or classes) and modify the instance
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})')
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
You don't need the exec at all. It's just:
alienShootList.append(alienShot{alienShootCounter})
i assume alienShot is a variable, like alienShot1 alienShot2 etc
^
which was the reason for this
pretty stupid, but
Oh. Well it should just be a dict
yep, or just a list
You can use globals()[f"alienShot{alienShootCounter}"] for the simplest change away from exec
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.