[Tutor] Modularity
Recently I've decided to write a pong style game with pygame; however, I can't seem to modularize the game successfully. I'm looking to make individual modules for each class eg. Ball, Paddle,bounds, Game, Physics and Logic. Used like this : ball = Ball(), paddle = Paddle() and etc... In a Game class... Mainly, I get errors that say class is not defined.. My questions are what is the best way to achieve this and what is the best way to import yourClass? So far I've tried: Import class as class, >From class import*, Import class Sent from my iPhone ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Private members?
Say I have a basic Circle class, for example: class Circle: def __init__(self, radius): self.__radius = radius Does adding the double underscore make this member directly inaccessible to children of the Circle class? Also, I'd like to know if there are any side effects to programming classes this way? Sent from my iPhone ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Inheritance vs Assignment
Suppose there is -> Class a(): def__init__(self, var): pass Class b(a): def__init__(self): super().__init__(self, var) pass Note: syntax may be incorrect ... Is it better to do b = a() Instead of making b its own class? Also, what would be the benefit of making a separate class for b if any at all? Thanks in advance Unee0x ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Importing classes
Is there a proper way to import a class from a module? If so, please tell. Thank You, Unee0x ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] list of functions
Greetings all, I would like to use a list of functions for an automation project, and this is the prototype I came up with ### def func1(): print('func1') def func2(): print('func2') def func3(): print('func3') func_list = ('func1', 'func2', 'func3') for f in func_list: eval(f)() # The output shows as intended, but I'd like to know if there are any safety or performance issues using this prototype or if there is a better way to acheive a list of functions. Thanks in advance ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] help with subprocess module
I made a python script that will update a Ubuntu Server every second and writes asuccess message and date to a log file, but for some reason the file is not being written to. Here is the Script: #!/usr/bin/python3 import subprocess import time import datetime class UpdateError(Exception): pass def update(): while True: try: update_log = open('update_log.txt', 'r+') time.sleep(1) subprocess.call(['apt-get', 'update', '-y']) date = datetime.datetime.now() update_log.write("System was updated sucessfully on {}\n".format (str(date))) subprocess.call(['reboot']) except UpdateError: print("Update Error!!!") update_log.close() if __name__ == '__main__': update() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor