Jul-05-2018, 08:40 PM
(This post was last modified: Jul-05-2018, 08:40 PM by Zombie_Programming.)
Thank you for the feedback. It has opened my eyes to a lot that I can improve. It's also opened my eyes to the fact that my Comp Sci 150 class didn't teach me a lot. However, I'm going to spend the next few hours improving :)
When you talk about this, how exactly would you go about doing this in detail. You can be vague about it, that way you're not giving me the answer to solve my problem. I just have never worked with relative file paths.
EDIT:
Did some research on relative files and came up with this. This is a modified version of the genAcctNum function in the bankAccount file above.
I also implemented your more simple design to check if the account number has already been generated.
I plan on working to implement your feedback on using relative file paths instead. Your feedback has been very much appreciated :)
(Jul-05-2018, 07:26 PM)ichabod801 Wrote: Relative paths are better if you can manage them. Otherwise note that you can generate absolute paths to the program file dynamically (os.path.abspath(__file__)), and then add relative paths onto that to get at specific files. Then you don't have to hunt down and change file paths when moving your programs around.
When you talk about this, how exactly would you go about doing this in detail. You can be vague about it, that way you're not giving me the answer to solve my problem. I just have never worked with relative file paths.
EDIT:
Did some research on relative files and came up with this. This is a modified version of the genAcctNum function in the bankAccount file above.
# The projects main directory project_dir = os.path.dirname(os.path.abspath(__file__)).split("\Scripts")[0] def get_abs_file_path(rel_path): # Take a relative file path and join to the main directory of the project file_path = os.path.join(project_dir, rel_path).replace('\\', '/') return file_path def gen_acct_num(): # Set the paths for the account numbers text file and translog folder acct_num_path = get_abs_file_path('Login_Info/acctNum.txt') trans_log_path = get_abs_file_path('Trans Logs') # Open the acct_num_file in read mode and read the contents of the file to compare # This will be used to check if the generated acct # is already in the database of acct #'s acct_num_file = open(acct_num_path) acct_nums = [line.strip for line in acct_num_file] while True: generated_acct_num = str(random.randint(100000000000, 999999999999)) if generated_acct_num not in acct_nums: break # Once the file has been searched and the account # is generated, append the # account # to the database. acct_num_file = open(acct_num_path, 'a') acct_num_file.write(generated_acct_num + "\n") acct_num_file.close() # Create trans log file trans_log = open(trans_log_path+"/transLog"+generated_acct_num+".txt", 'w+') trans_log.close() # Return the account number return generated_acct_num
(Jul-05-2018, 07:26 PM)ichabod801 Wrote: Your check for existing account numbers is very odd and complicated. Why not:
I also implemented your more simple design to check if the account number has already been generated.
I plan on working to implement your feedback on using relative file paths instead. Your feedback has been very much appreciated :)