python - How do i call different classes within in a class? -


so made 2 classes, 1 making rectangle , 1 makes star, both being rectangle() , star() there class taking in specific amount of parameters. problem have class called flag() takes in textfile contain specific parameters each class, rectangle has 5 parameters, , star has 4. need flag class read through textfile , read through each line of file, understand each line either rectangle or star, draw it.

class flag(object):     def __init__(self, f_obj):         self.f_obj = f_obj         line in self.f_obj:             line.strip()             if 5 == len(line):                 r = rectangle(line)                 print(r)             elif 4 == len(line):                 s = star(line)                 print(s)      def draw(self,turtle):         r.draw(turtle)         s.draw(turtle) 

are asking file reading? try this:

parts = line.strip().split() if len(parts) == 4:     # star if len(parts) == 5:     # rectangle 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -