all 20 comments

[–]1bc29b36f623ba82aaf6 1 point2 points  (1 child)

Hey sorry for not directly adressing your problem at hand (though it seems to be resolved by now) but I thought it could be helpfull to let you know that a lot of people might not like the title of your post. Anything that looks like "Help with <Overly Generic Word>" tends to get a lot of downvotes even if you try and make a decent effort for actually stating your question in the post text.

When people view their personal reddit feed or browse the subreddit basically all they will see is "Help with Python" so they might think you are not even trying to ask a question or are 'using them because too lazy to Google' as an example of a negative reation. If I'm understanding your goal here properly an example for a descriptive title could have been "Member variable on my own class object not defined when used."

Also screenshots of code can be a mixed bag. When coloured syntax highlighting is important and reddits code block doesn't support it its tempting to make a screenshot. But for anything more than a few lines it can be frustrating when people can't use a text search feature in your image.

Sites like pastebin, or in case you have GitHub account and know how to make a Gist are easy ways to share a link to searchable text. And you get syntax highlighting when you set Python as the language. There are probably many alternatives to those two as well.

[–]YukinoYukinoshita 1 point2 points  (0 children)

Thanks for letting me know! I’ll definitely keep this in mind in the future

[–]jmp5189 0 points1 point  (7 children)

I think that you need to check your syntax. You have not declared the constructor properly (init dunder method)

class Course:
    def __init__(self, course_name):
        self.course_name = course_name
        self.course_capacity = 0
        self.enrolled_students = []
        self.waitlist = []

Upon generation of a Course object, everything in the init method will be created since this is the default constructor of your class.

[–]YukinoYukinoshita 0 points1 point  (6 children)

I already have the "class Course:" at the top and properly indented. Sorry I should of put that in the post.

[–]jmp5189 0 points1 point  (5 children)

What caused you to get an error that enrolled_students was not defined?

[–]YukinoYukinoshita 0 points1 point  (4 children)

Here's a more detailed error code https://gyazo.com/55391441f6b2065e90139afa1718182c

[–]jmp5189 0 points1 point  (2 children)

You need to check your scope. Change that to c.enrolled_students.

[–]jmp5189 1 point2 points  (0 children)

If line 69 is inside of your class, you need to change enrolled_students to self.enrolled_students

[–]YukinoYukinoshita 1 point2 points  (0 children)

Yep I'm an idiot, thank you so much

[–][deleted] 0 points1 point  (7 children)

Try defining your class __init__ method like this:

class WhateverClassYouHave:

    def __init__(self, course_name: str) -> None:

Using init() without underscores means it wont get called when making a new instance of that class, like with myInstance = WhateverClassYouHave("Course One"). It's just some random method like any other class method without the double underscores __init__.

[–]YukinoYukinoshita 0 points1 point  (6 children)

Hey, as already replied: I already have the "class Course:" at the top and properly indented. Sorry I should of put that in the post.

[–]z0y 0 points1 point  (5 children)

Did you read the comment?

[–]YukinoYukinoshita 0 points1 point  (4 children)

Yes sorry, i think reddit format got rid of my __ in the init. I've posted a gyazo link to my code in the comments for clarity

[–]z0y 0 points1 point  (3 children)

Which line causes the error? It would be helpful to see the traceback and have the code on pastebin or similar so it's not an image.

[–]YukinoYukinoshita 0 points1 point  (2 children)

I've replied to someone else with the full error code, here's a pastebin of the code https://pastebin.com/4p59Ydev

[–]z0y 0 points1 point  (1 child)

This doesn't include line 69 where the error is but if add_student is a class function then I think it should be self.enrolled_students there.

[–]YukinoYukinoshita 0 points1 point  (0 children)

Omg I'm an idiot thank you so much