The four images show that my Shape class has no troubles reading the "camera_mode" variable from my settings object, while the Camera tells me that it does not exist. Did I order anything incorrectly? Is there another reason as to why it doesn't work? To whoever can help me, thank you in advance
#๐ Why doesn't my Camera class accept a Settings object in its code, whereas my Shape class does?
23 messages ยท Page 1 of 1 (latest)
@raw laurel
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.
Closes after a period of inactivity, or when you send !close.
unsure without seeing the actual code. but it looks like you're trying to access a settings variable in the class body, rather than in a method of the class.
you might want to pass in the settings as argument to Camera() instead, and put it on self inside of the camera class.
I'd like to do that without having the user always put in cam=Camera(settings) at the beginning. Is there a way to do that automatically?
If not, then I am fine with passing it as an argument manually
not any pretty way. It's generally the recommended way to inject things into the class like that, if they're needed in the class.
if it's only needed in very few places in the class, it might also be possible to only pass it as argument to the respective method(s) that need the settings.
how could I do that?
by passing it in as argument, whenever you call a method on the cam instance. Though it's usually better to just pass it in to Camera instead as you already suggested, especially if multple methods need the settings for stuff.
Thank you!
Why do you have if True
To be able to make this take only one line and not clutter up the workspace
Wym? Is it just for indenting?
Yup.
Just so I can avoid scrolling through it
Why not just make a function like def main
How could that work?
def main():
print("Hello, world")
main()
but this is only a temporary setup. The dump() function will give me a copy-pastable form of the shape for me to put in a permanent list
but I do thank you for the idea!
I see
This help channel has been closed. 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.