#๐Ÿ”’ Add more functionalities to current code to cover more fundamentals of Python

5 messages ยท Page 1 of 1 (latest)

vestal stratus
#

Hey guys.
So I was working on this task where I want a user to input a path of their choice so the program can interate through the directory and print all files with their extensions.
This is the code:

from collections import defaultdict
from pathlib import Path

def validate_path():
    while True:
        path = Path(input("Enter the path: "))
        if not path.is_dir():
            print("Please enter a valid path.")
        else:
            return path

def group_items(path):
    file_groups = defaultdict(list)
    for item in path.iterdir():
        if not item.is_file():
            continue
        extension = item.suffix.casefold()
        file_groups[extension].append(item)
    return file_groups

def print_groups(file_groups):
    for extension, files in sorted(file_groups.items()):
        print(f"{extension}: {len(files)}")
        for file in sorted(files):
            print(f"        {file.name}")

def main():
    path = validate_path()
    file_groups = group_items(path)
    print_groups(file_groups)

if __name__ == "__main__":
    main()

My goal now is to learn more and more fundamentals of python/programming by adding more stuff to this code.
Examples:

  • Try/Except blocks.
  • Text Editing
  • Reading / Writing files
  • Regex function to maybe open a file and filter through "err*" text.

It would be nice if an experienced person could give me "tasks" to add to this code rather than me going ahead and asking ai "what more can i do?" or "give me more tasks".
One task f.e. could be "add a ... here and then make sure that .... is being checked" or something like that.

Does that make sense?
Would be super helpful!

tame voidBOT
#

@vestal stratus

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

vestal stratus
#

If you think its complete nonsense to stay at this program and extend it with more functionalities etc. and thats its much better to rather start a new program with a different task then it'd be nice to know where to get good, new tasks / projects that would cover the fundamentals nice and cleanly (so i can move away from asking AI)

tame voidBOT
#
Python help channel closed using Discord native close action

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.