0

I have the following list in Python

["trovare", "mostrare", "convincere", "spiegare", "vedere"]

Is there a way to create a group of empty txt files in a specific folder on my desktop that would look like this:

trovare.txt, mostrare.txt, convincere.txt, spiegare.txt, vedere.txt

3 Answers 3

2

Path.touch() can be used to create empty files.

Try this:

from pathlib import Path

filenames = ["trovare", "mostrare", "convincere", "spiegare", "vedere"]
folder_path = '~/desktop/'

for filename in filenames:
    Path(folder_path + filename + '.txt').touch()

Replace the folder_path with the path to the folder that should contain the files

Sign up to request clarification or add additional context in comments.

Comments

1

Yes, that is possible.

import os

path = '/your_folder_path'
filenames = ["trovare", "mostrare", "convincere", "spiegare", "vedere"]

for filename in filenames:
    with open(os.path.join(path, filename+'.txt'), 'w')

Comments

0

Try this:

for fn in ["trovare", "mostrare", "convincere", "spiegare", "vedere"]:
    open(fn + '.txt', 'w').close()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.