#๐ ๐ confused on what i should do when calling a function from a class
78 messages ยท Page 1 of 1 (latest)
@blazing walrus
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.
are you familiar with the concept of instantiating a class?
nope
instantiating?
!instantiating
dang..
methods that have a 'self' parameter are only called on instances of a class, not the class itself
what would i change App.search() to then?
i need the search function to run again
its inside the class 'App'
i need to call it from outside the class
instantiating means to create an instance of a class. in python, you can create an instance by calling a class similar to a function
app = App()
app.search()
huh.. i do that with my watchdog module code
event_handler = MoverHandler()
line 682
yeah, exactly. you need to do that here as well
that would be instantiating right?
but i already do that in my bottom if statement
if __name__ == "__main__":
#WATCHDOG STUFF
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
path = source_dir
event_handler = MoverHandler()
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
app = App()
app.mainloop()
you need access to the app variable you made on line 685 before you can even ask this question
which is a global variable, so i suppose you already have access to it
yeah i aint got a clue what to do now..
so you already have app = App(). how can you access or reuse the app variable inside of your function?
which function? the one im trying to call the function i want from?
so from def move_file(dest, entry, name):
yeah, so instead of App.search you want app.search
where App is your class, and app is an instance of your class
how can you access the app variable you've already declared from inside move_file
then how would it know where to get the function from?
it's an odd design choice for this function move_file to expect a global variable from __name__=='__main__' to be defined, this is spaghetti code, but it'll work...
are you familiar with dictionaries?
not exactly..
im sorry im self taught ;-;
we probably all are, and believe me i've made a lot of nice spaghetti
when you call App(), you're getting back a value which knows how to call the function
oh, what change did you make
ah, well. i suppose in your main if block you're creating a global variable anyway
idk if i should go on self teaching..
there's nothing wrong with self teaching
its a fun hobby but hella sloppy and unprofessional
that's fine
thank you so much you just made it possible to finish off my second ever app
a class won't really teach you any more than you can learn on your own
i dont understand classes tbh but i am using em
so i gotta in some way
i like some of these videos to learn about writing cleaner code, but i'm not sure what level they're suitable for https://www.youtube.com/playlist?list=PLRVdut2KPAguz3xcd22i_o_onnmDKj3MA
i can't tell if you're joking, but i meant like a school class not a python class
i got gcse grade 4 in computer science
OHH whoops :/
looks hella messy
wth
what looks messy?
he is a core contributor to the python programming language
damn thats huge actually.. he updates python?
yes
i heard ai might be huge with python
its good for algorithms i believe so it looks like it
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.
๐ confused on what i should do when calling a function from a class
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.