10000001
Immer weiter zählen
-
-
1
-
2 - 10.000.000
Diesmal mit einem viel zu komplexem Programm an dem ich viel zu viel Zeit verbracht habe weil mir langweilig war und ich irgentwas in python machen wolltePython: generator.py
Alles anzeigenimport time import pathlib from pathlib import Path import sys import os import subprocess # commands (change here:) command__help = "help" command__open_explorer = "directory" command__file_remover = "remover" command__number_generator = "generator" command__exit = "end" # prefix for commands (change here:) command_prefix = "#" class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100): """ Call in a loop to create terminal progress bar @params: iteration - Required : current iteration (Int) total - Required : total iterations (Int) prefix - Optional : prefix string (Str) suffix - Optional : suffix string (Str) decimals - Optional : positive number of decimals in percent complete (Int) bar_length - Optional : character length of bar (Int) """ str_format = "{0:." + str(decimals) + "f}" percents = str_format.format(100 * (iteration / float(total))) filled_length = int(round(bar_length * iteration / float(total))) bar = '█' * filled_length + ' ' * (bar_length - filled_length) sys.stdout.write('\r%s |%s| %s%s %s' % (prefix, bar, percents, '%', suffix)), if iteration == total: sys.stdout.write('\n') sys.stdout.flush() def open_explorer(): print() print("Opening explorer...") current_path = pathlib.Path(__file__) subprocess.Popen(r'explorer /select, ' + str(current_path)) def file_remover(): print(bcolors.HEADER + "Remove any file in the current directory" + bcolors.ENDC) while True: user_input = input( f"Type the name of the file that you want to delete or {command_prefix}{command__exit} to stop: ") if user_input == command_prefix + command__exit: break try: os.remove(user_input) print(f"Removed {user_input}") except FileNotFoundError: print("This file does not exist.") def number_generator(): print() print(bcolors.HEADER + "Generate numbers into a text file" + bcolors.ENDC) file_name = input("Name of the file: ") start_count = int(input("Start counting at: ")) end_count = int(input("Number to count to: ")) if file_name.lower().endswith(".txt") is not True: file_name = file_name + ".txt" file_name = Path(file_name) if file_name.is_file() != True: file = open(file_name, "w") else: user_input = input( "This file already exists. Are you sure you want to overwrite it? (y/n)\n") if user_input.lower() == "y": file = open(file_name, "w") if user_input.lower() == "n": sys.exit() current_path = pathlib.Path(__file__).parent.absolute() print("File generated at: " + str(current_path) + "\\" + str(file_name)) timer = time.time() display_status_bar = False if start_count == 1: display_status_bar = True else: print("Generating file...") while start_count <= end_count: output = f"{start_count}\n" file.write(output) start_count += 1 if start_count != end_count and display_status_bar == True: print_progress(start_count, end_count, "Generating file...", "", 1, 80) file.close() print() run_time = round((time.time() - timer)) if run_time != 0.0: print(f"File complete. ({run_time}s)") else: print("File complete.") def show_help(): print() # Spacer print(bcolors.HEADER + command_prefix + command__help + ":" + bcolors.ENDC) print("Shows this help section") print() # Spacer print(bcolors.HEADER + command_prefix + command__number_generator + ":" + bcolors.ENDC) print("Starts the number generator which generates a custom txt file with numbers in a defined range") print() # Spacer print(bcolors.HEADER + command_prefix + command__file_remover + ":" + bcolors.ENDC) print("Removes any file in the given directory") print() # Spacer print(bcolors.HEADER + command_prefix + command__open_explorer + ":" + bcolors.ENDC) print("Opens the file explorer in the current directory.") print() # Spacer print(bcolors.HEADER + command_prefix + command__exit + ":" + bcolors.ENDC) print("Stops the program.") print() run_loop = True while run_loop: print() user_input = input( f"{bcolors.OKGREEN}Type a command. For help type {command_prefix}{command__help}:{bcolors.ENDC}\n") user_input = user_input.lower() display_not_command_error = True display_not_valid_command_error = True if user_input.startswith(command_prefix): user_input = user_input.replace(command_prefix, "") if user_input == command__help: show_help() display_not_valid_command_error = False display_not_command_error = False if user_input == command__number_generator: number_generator() display_not_valid_command_error = False display_not_command_error = False if user_input == command__file_remover: file_remover() display_not_valid_command_error = False display_not_command_error = False if user_input == command__open_explorer: open_explorer() display_not_valid_command_error = False display_not_command_error = False if user_input == command__exit: sys.exit() display_not_valid_command_error = False display_not_command_error = False if display_not_valid_command_error == True: print(bcolors.FAIL + f'"{user_input}" is not a valid command.' + bcolors.ENDC) display_not_command_error = False if display_not_command_error == True: print(bcolors.FAIL + f'"{user_input}" is not a command. Commands have to start with: {command_prefix}' + bcolors.ENDC) print(f"{bcolors.FAIL}Example: {command_prefix}{command__help}{bcolors.ENDC}")
-
10000001
btw @Potato_maaan bald @Peridot2.0?
-
Juhu Python.
-
btw @Potato_maaan bald @Peridot2.0?
Natürlich! Die Serverübergabe an mich ist schon geplant.
btw:
10.000.002 -
10.000.003
-
1
-
2
-
2.1
-
3,14
-
3,140000000000000000001