Python Forum
Class Modules, and Passing Variables: Seeking Advice
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Class Modules, and Passing Variables: Seeking Advice
#5
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

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):
		pass
All 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 Question

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.
Reply


Messages In This Thread
RE: Class Modules, and Passing Variables: Seeking Advice - by Robo_Pi - Mar-01-2018, 03:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Seeking some script design advice... involves asyncio, threads, multiprocessing sawtooth500 1 939 Jul-05-2024, 10:39 PM
Last Post: AdamHensley
  Seeking advice on dask distributed sawtooth500 4 1,825 Apr-15-2024, 11:07 PM
Last Post: sawtooth500
  Unchangeable variables in a class? Calab 12 3,898 Sep-15-2023, 07:15 PM
Last Post: deanhystad
  Class variables and Multiprocessing(or concurrent.futures.ProcessPoolExecutor) Tomli 5 6,961 Nov-12-2021, 09:55 PM
Last Post: snippsat
  How to pass variables from one class to another hobbyist 18 20,961 Oct-01-2021, 05:54 PM
Last Post: deanhystad
  Acess variables from class samuelbachorik 3 2,752 Aug-20-2021, 02:55 PM
Last Post: deanhystad
  Passing Variables between files. victorTJ 3 3,192 Oct-17-2020, 01:45 AM
Last Post: snippsat
  New user seeking help EdRaponi 2 72,715 Jun-23-2020, 12:03 PM
Last Post: EdRaponi
  Class variables menator01 2 2,873 Jun-04-2020, 04:23 PM
Last Post: Yoriz
  Question about naming variables in class methods sShadowSerpent 1 2,793 Mar-25-2020, 04:51 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020