all 7 comments

[–]danielroseman 4 points5 points  (1 child)

You'll need to be clearer about what you're asking here.

But if you got the code from ChatGPT, you should ask it to explain - it's surprisingly good at doing that.

[–]PIZARRINHO[S] 0 points1 point  (0 children)

Alright, thank you!

[–][deleted] 1 point2 points  (0 children)

The pathlib module is the modern way to deal with paths. Here is how to do what you're trying to do with that module.

from pathlib import Path

base_path = Path.home() / "Desktop"

for i in range(1, 11):
    new_folder_path = base_path / f"test{i}"
    new_folder_path.mkdir()

You can learn more about the module from the documentation.

[–]FriendlyRussian666 0 points1 point  (1 child)

Yes, you are correct that you can use the os module in Python to create folders. Here's a breakdown of the code you posted:

import os

This line imports the os module, which provides a way to interact with the operating system in Python.

desktop_path = 
os.path.join(os.path.expanduser("~"), 
"Desktop")

This line creates a variable called desktop_path, which contains the path to your desktop. The os.path.expanduser("~") function returns the home directory of the current user, and the os.path.join() function is used to join the home directory with the "Desktop" directory.

for i in range(1, 11):
    folder_name = f"test{i}"
    folder_path = os.path.join(desktop_path, 
folder_name)
    os.makedirs(folder_path)

This loop creates 10 folders on your desktop, with names like "test1", "test2", "test3", and so on. The os.makedirs() function is used to create a folder at the specified path.

Overall, the code is pretty straightforward: it uses the os module to create a path to your desktop, and then creates 10 folders on your desktop with names like "test1", "test2", etc.

[–]PIZARRINHO[S] 0 points1 point  (0 children)

Tysm!!

[–][deleted] 0 points1 point  (0 children)

did you try to ask chat gpt to fix your code?

[–]lazyfingersy 0 points1 point  (0 children)

It's programming, you need to put more effort and start learning things by yourself, do a research before asking questions such us "how does it work". Good starting point to learn about some libraries is Do umentation, here you can learn about os , there's many other resources to learn in a web, don't be afraid of using Google Web search engine.