Mar-01-2018, 03:59 AM
Sorry. I was trying to give an overview of what I'm trying to do. I can offer a very simplified version for the purpose of asking my questions.
Simplified Version:
I am creating a separate class of methods from my main program and I just wanted to ask if I'm doing this correctly.
Here's my main program saved as
Alysha.py
Alysha_Pass.py
Is the above code a valid way to do this? Mainly in terms of creating an independent class that is separate from the main program, and in terms of passing the variables back and forth?
The reason I'm asking is because I just pieced this together on the fly by trial and error. I'm just learning Python and I want to be sure that I'm getting off on a solid foundation. I'll be writing many classes and methods using a similar structure. So I just want to be sure I'm getting off on the right foot.
Thanks.
Simplified Version:
I am creating a separate class of methods from my main program and I just wanted to ask if I'm doing this correctly.
Here's my main program saved as
Alysha.py
from Alysha_Pass.Alysha_Pass import * def main(): Tasks = Alysha_Pass().Alysha_Read() print Tasks Alysha_Pass().Alysha_Write("Dummy Message") return 0 if __name__ == '__main__': main()Here's the new class I've just created that contains two methods:
Alysha_Pass.py
class Alysha_Pass: def Alysha_Read(self): Tasks = ['Task 1','Task 2','Task 3','Task 4','Task 5'] return (Tasks) def Alysha_Write(self, Message): print "\n" , Message , "\n" def __init__(self): passAll this code works just fine and produces the expected output below:
Output:['Task 1', 'Task 2', 'Task 3', 'Task 4', 'Task 5']
Dummy Message
My QuestionIs the above code a valid way to do this? Mainly in terms of creating an independent class that is separate from the main program, and in terms of passing the variables back and forth?
The reason I'm asking is because I just pieced this together on the fly by trial and error. I'm just learning Python and I want to be sure that I'm getting off on a solid foundation. I'll be writing many classes and methods using a similar structure. So I just want to be sure I'm getting off on the right foot.
Thanks.