#๐ Question about class methods vs functions
16 messages ยท Page 1 of 1 (latest)
@tight sedge
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.
do they require some common state?
ie. would there be any disadvantage to having them as free functions?
if not, stick to free functions
hmm well they are functions that pull data form data bases and some of them clean / do some mainpulations thats about it
sonwould you expand on what doy ou mean by common state
like if you had a class Car, you might have methods on it that manipulate the car's state, like .steer(), .brake() etc.
if there is no obvious common shared state for these functions to manipulate then there's no reason to put them in some class
more like
def pull data from data base (table):
def get_list_x
pull data from data base(table)
do x
I see
does it matter if the mainpulation is in continous time or steps?
no
Look at Python's own standard library. Sometimes library modules contain functions, sometimes classes and sometimes both. They can even contain constants. So to answer your question: it depends how you are going to use what you import and also what purpose it will serve. As the author, you will need to choose the most appropriate content of your supporting module. I would say that usually the simplest is best.
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.