I am certain I am doing this “incorrectly” even though it works. Right now when I call a function I just pass the whole object i.e.
class my_file_obj:
def __init__(self,filename):
self.filename = filename
self.owner = None
self.file_type = None
self.fileflag = 0
self.md5 = None
The function call, where file_obj1 is an instance of my_file_obj:
some_function(file_obj1)
and then referencing the attributes I need as needed within the function.
What is the “python”/correct way of doing this?
-
some_function(file_obj1) -
some_function(file_obj1.filename) the_filename = file_obj1.filename
some_function(the_filename)
Well, it’s quite obvious. It depends on whether
some_functionneeds the whole object or just the filename, in which case you pass the wholemy_file_objinstance or just the filename.