#๐Ÿ”’ 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
#

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

glass axleBOT
#

@raw laurel

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.

vast merlin
#

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.

raw laurel
#

If not, then I am fine with passing it as an argument manually

vast merlin
#

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.

vast merlin
#

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.

raw laurel
#

Thank you!

paper forge
raw laurel
paper forge
raw laurel
paper forge
#

Why not just make a function like def main

raw laurel
#

How could that work?

paper forge
#
def main():
    print("Hello, world")

main()
raw laurel
#

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!

paper forge
#

I see

glass axleBOT
#
Python help channel closed for inactivity

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.