I have the following classes in Python:
class String:
def clean_string(self, corpus):
f = open(corpus, 'r')
raw = f.read().lower()
f.close()
raw1 = re.sub(omissis, '', raw)
self.string = raw1
def print_string(self):
return self.string
class Set:
def letters_set(self, string):
self.let_set = set(re.findall(omissis, string))
class Dict:
def __init__(self, dictionary={}):
self.dictionary = {}
self.string = String()
self.let_set = Set()
def generate_possible_triplets(self, let_set):
triplet = [(ch1, ch2, ch3) for ch1 in let_set
for ch2 in let_set
for ch3 in let_set]
[...]
I have a problem with objects as function arguments. Suppose I want to create an instance of the class Set, one of class String and call the method .letters_set(String.string).
What do I have to put as argument inside the parenthesis? the name of the object of class string I will create? a variable referenced to this object? (same applies for the method .generate_possible_triplets in Dict. What form should let_set take?
You would probably just want to make your methods accept instances of your custom classes…
The methods can then expect to operate on those classes appropriately to access the attributes. This example is not specifically checking the capabilities of the objects being passed in, but they would obviously raise an exception when you try to access an improper object type that does not have a
.stringor.let_setattribute.