Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: sort_user_list.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- - This script sorts a list of user data alphabetically and saves the sorted list to an output file.
- Functions:
- - line():
- Prints a line of underscores for formatting purposes.
- - sort_user_list(local_input_filename, local_output_filename):
- Reads a list of user data from an input file, sorts it alphabetically, and saves the sorted list to an output file.
- Requirements:
- - Python 3.x
- Usage:
- - To use this script, call the sort_user_list function with the input and output filenames as arguments.
- Additional Notes:
- - Make sure the input file exists and is accessible.
- - The output file will be overwritten if it already exists.
- """
- def line():
- """Prints a line of underscores for formatting purposes."""
- print("_" * 50, "\n")
- def sort_user_list(local_input_filename, local_output_filename):
- """
- Reads a list of user data from an input file, sorts it alphabetically, and saves the sorted list to an output file.
- Args:
- local_input_filename (str): The filename of the input file containing the unsorted user data.
- local_output_filename (str): The filename of the output file where the sorted user data will be saved.
- """
- line()
- print("\tSorting user list...\n\tThis may take some time to process.")
- line()
- # Read the user list from the input file
- with open(local_input_filename, 'r', encoding='utf-8') as infile:
- user_list = [line.strip() for line in infile]
- # Sort the user list alphabetically
- sorted_user_list = sorted(user_list)
- # Write the sorted user list to the output file
- with open(local_output_filename, 'w', encoding='utf-8') as outfile:
- for user in sorted_user_list:
- outfile.write(user + '\n')
- print(f"- Sorted user list saved to: '{local_output_filename}' -")
- line()
- print("\tExiting Program...\tGoodBye!\n")
- line()
- if __name__ == "__main__":
- global_input_filename = 'input.txt' # Replace with your list filename
- global_output_filename = 'sum_list.txt'
- sort_user_list(global_input_filename, global_output_filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement