Sorry but the above post got posted by accident before it was finished. And now I can't edit it!!!
Sorry about the mistaken early post. I was interrupted and it got posted before I was done. The following is how the original OP was supposed to end.
Next is the Alysha_Read() Class.
Alysha_Read.py
This class reads a text file named "Commands.txt" located at the address contained in "File_Path".
It then converts the content of that file into a Python List and returns the list to the calling program.
Task 1
Task 2
Task 3
Task 4
Task 5
Task 6
Task 7
Task 8
Task 9
Task 10
The program returns the following List as an output:
This program works as expected. My only question is to ask for any suggestions of advice on how I might improve on this software design. Specially in terms of setting up classes as independent files, and in terms of passing variables between these classes. Have I done things correctly? I'm just starting out programming in Python so I'll be surprised if I'm doing things correctly.
Any suggestions for improvements are welcome.
Thanks for reading.
Sorry about the mistaken early post. I was interrupted and it got posted before I was done. The following is how the original OP was supposed to end.
Next is the Alysha_Read() Class.
Alysha_Read.py
This class reads a text file named "Commands.txt" located at the address contained in "File_Path".
It then converts the content of that file into a Python List and returns the list to the calling program.
class Alysha_Read(): """ ---- Alysha_Read:Alysha_Read class to read the Commands.txt ---- This program reads the text file in the Robo_Pass folder on the Raspberry Pi It converts that text file into a Python List and then passes the list back to the program that called this class. The passing list is called "Task_Commands" This is done to place the commands in a List Variable. (or String Array), that can then be accessed via indexes. Task_Commands[i] This Class must be called using Alysha_Read(list), where list should be an empty list. Then upon return you can obtain the Task_Commands by using: Commands = Alysha_Read.Task_Commands """ ### --- Addresses for Commands.txt file ------- # Overseer directory File_Path = 'C:/100_Robo_pass/Commands.txt' # Raspberry Pi directory ### File_Path = /home/pi/Robo_pass/Commands.txt' # ---------- Begin Reading Commands.txt Routine -------------- # Create a string array or list named Raw_Task_Commands # This reads the entire Command File # Required to be able to count how many commands there are. Raw_Task_Commands = [] # Create a new string array to for the individual clean commands. Task_Commands = [] # Read the Commands.txt file on HP-Elite using the Ptyhon open function # Create the file-reading object named "Stream_Reader_1". # --- # --- B E W A R E ! ! ! ---- use the correct filename for each robot. # --- Stream_Reader_1 = open(File_Path, 'r') # Read in the entire file into "Raw_Task_Commands" array. Raw_Task_Commands = Stream_Reader_1.readlines() # Break out the commands, get the count, and clean them up. # (note) len(Raw_Task_Commands) is the count. for i in range(0,len(Raw_Task_Commands)): # Isolate the first command. raw_Command_String = Raw_Task_Commands[i] # Strip off the carriage returns and line feed. raw_Command_String = raw_Command_String.strip() # Append this into the new clean Command array. Task_Commands.append(raw_Command_String) # won't need the following print on the final version. # ---- For Debug Only ---- print raw_Command_String # Close the file! Stream_Reader_1.close def __init__(self, Task_Commands): """ This is my initiation function in Alysha_Read Task_Commands is assigned to this Class as a passable list array using this __init__ function """The Command.txt File contains the following information:
Task 1
Task 2
Task 3
Task 4
Task 5
Task 6
Task 7
Task 8
Task 9
Task 10
The program returns the following List as an output:
Output:['Task 1','Task 2','Task 3','Task 4','Task 5','Task 6','Task 7','Task 8','Task 9','Task 10']
QuestionsThis program works as expected. My only question is to ask for any suggestions of advice on how I might improve on this software design. Specially in terms of setting up classes as independent files, and in terms of passing variables between these classes. Have I done things correctly? I'm just starting out programming in Python so I'll be surprised if I'm doing things correctly.
Any suggestions for improvements are welcome.
Thanks for reading.