Using python class as struct?
Go to solution
Solved by Azgoth 2,
There's actually no need for getter and setter functions in Python--that functionality is already built in to classes, so writing those functions in is completely unnecessary. Using your class GROUPS,
foo = GROUPS(var1, var2)
# This does the exact same thing as foo.getGName():
foo.GName
# This does the exact same thing as foo.setGName(var3):
foo.GName = var3
Other object-oriented languages do use and require setter/getter functions, but Python is not one of them. Writing them just duplicates functionality that's already there. So your definition of GROUPS doesn't need any of the set/get functions:
class GROUPS:
def __init__(self, gname, ips):
self.GName = gname
self.IPS = ips
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now