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
#10
ok here's my upgrade to PEP 8 style conventions:

Changes that I've made:
  1. Changed namespace folder to lowercase. alysha_pass. (Using underscore here because of lowercase)
  2. Removed underscore from the class name AlyshaPass()
  3. Removed the Alysha_ prefix from the read() and write() methods and wrote them using all lowercase.

Alysha.Py

from alysha_pass.AlyshaPass import *

def main():

	Tasks = AlyshaPass().read() 
	print Tasks	
	
	Alysha_Pass().write("Dummy Message")

	return 0
if __name__ == '__main__':
	main()
AlyshaPass.Py

class AlyshaPass():
	def __init__(self):
		pass

	def read(self):
		Tasks = ['Task 1','Task 2','Task 3','Task 4','Task 5']
		return (Tasks)
		
	def write(self, Message):
		print "\n" , Message , "\n"	
Output:
['Task 1', 'Task 2', 'Task 3', 'Task 4', 'Task 5'] Dummy Message
Any other great suggestions? Smile

I'll look into upgrading to Python 3, but I'm not going to do that right away.

I would also like to learn more about how to create and implement a configuration file that Gribouillis had suggested for the file path names and global variables. That sounds interesting I don't like having to hard-code file paths so if there's better way to do that I'm all eyes. Can you point to any instructions on how to do that?

Thanks for all the constructive mentoring thus far. This is what I came here for.

Further Housecleaning via PEP 8 style:

I was concentrating so much on the class and methods formatting that I forgot about the variable names conventions.

So now I realize that Tasks should be tasks in both Alysha.py and AlyshaPass.py and the variable "message" in the write method also should be all lowercase.

So,... here's the latest update:

Alysha.py

from alysha_pass.AlyshaPass import *
 
def main():
 
    tasks = AlyshaPass().read() 
    print tasks 
     
    Alysha_Pass().write("Dummy Message")
 
    return 0
if __name__ == '__main__':
    main()
AlyshaPass.py

class AlyshaPass():
    def __init__(self):
        pass
 
    def read(self):
        tasks = ['Task 1','Task 2','Task 3','Task 4','Task 5']
        return (tasks)
         
    def write(self, message):
        print "\n" , message , "\n" 
I'm learning one step at a time. Cool
Reply


Messages In This Thread
RE: Class Modules, and Passing Variables: Seeking Advice - by Robo_Pi - Mar-01-2018, 02:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Seeking advice on dask distributed sawtooth500 4 428 Apr-15-2024, 11:07 PM
Last Post: sawtooth500
  Unchangeable variables in a class? Calab 12 1,757 Sep-15-2023, 07:15 PM
Last Post: deanhystad
  Class variables and Multiprocessing(or concurrent.futures.ProcessPoolExecutor) Tomli 5 4,007 Nov-12-2021, 09:55 PM
Last Post: snippsat
  How to pass variables from one class to another hobbyist 18 11,180 Oct-01-2021, 05:54 PM
Last Post: deanhystad
  Acess variables from class samuelbachorik 3 1,945 Aug-20-2021, 02:55 PM
Last Post: deanhystad
  Passing Variables between files. victorTJ 3 2,322 Oct-17-2020, 01:45 AM
Last Post: snippsat
  New user seeking help EdRaponi 2 51,698 Jun-23-2020, 12:03 PM
Last Post: EdRaponi
  Class variables menator01 2 2,072 Jun-04-2020, 04:23 PM
Last Post: Yoriz
  Question about naming variables in class methods sShadowSerpent 1 2,056 Mar-25-2020, 04:51 PM
Last Post: ndc85430
  Python 2.7 passing variables from functions zetto33 1 1,825 Mar-19-2020, 07:27 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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