oop - Not sure what/what not to put in classes in Python -


I'm very new to Python and programming. Say that I have a text file in which a group of people's names, articles have been written, and their assigned ID. I created a class with these attributes and placed that text file through the class. no problem. Now, the user is encouraged to enter the name of someone from that text file and all the articles of that person are printed. My question is: Do I do this by creating a new function inside the classroom? Or should I make it outside the classroom?

I have a hard time when wrapping my head while not touching a class, I feel that I think a class defines the properties of an object. However, when I add an object to the class, I am having difficulty referencing that object outside the class. Say when entering a user name and comparing an object.

I think this is not the biggest question and I am sure some people will scold me for posting. I'm just running out of options and I am desperate for help. I am reading books, watching online videos, watching videos, and it should not do as I want it to be removed is.

Ah! Thank you all for the replies! I was able to install the function outside the classroom and was comparing the input variable to that category and the author in the KA-Blime! Print it properly! I still have to learn a lot, but it is like moments that turn me towards a spirited little girl. Thanks for your help and so much better!

Class Classical Objects are Lynchpins -Used Programming, defines the data and behavior of objects in that class In your case, you should ask yourself if it is appropriate for the person to print all the articles by the person for the class. But you do not give very much information about your class directly that I present an opinion on it directly. The class representing the authors may look like this:

  Category Author: def __init __ (Self, name, article): self.name = name self.articles = articles  

But this class does not know more than one author, so it's a list of authors It does not mean for a method to search through. But what does it mean to define another class to represent the collection of authors? You know your needs better than my needs, but I do not believe so. The Python collection does very well internally.

Eventually, my advice will be to create objects (through classrooms) that model the real world things that you are trying to represent in the code. They should have data and behavior (Read: Properties and Methods) that understand the context of that model. You are lucky that Python does not apply HabboGoblin to all harsh things-one-class OOP, and allows you to write module-level functions when creating your "author archive" is very cumbersome for your needs:

  Author = [Writer (name, article) for name, article in input_data] def article_distribution author (author_name): Global authors for authors in authors: If author_name == auth.name: return auth.articles  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -