-4

i want to writ file bomber with python and i want to when user press "/" the while break.

i wanted to when i run my python file my program create billions file for me. but i received this Error:OSError: [Errno 22] Invalid argument: 'testiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.txt' this is my code:

import keyboard

fname = "test"
num = 0
while True:
    fname = fname + "i"
    num = num + 1
    fhand = open(fname + ".txt" , "w")
    if keyboard.is_pressed("/"):   
            print("/")                
            break                           
  • 2
    The max name length exceeded. – Petəíŕd The Linux Wizard Aug 15 '23 at 11:15
  • 3
    What, exactly, are you trying to achieve with this? – DarkKnight Aug 15 '23 at 14:30
  • This loop will encounter issues once the filename exceeds 255 characters, as most operating systems have a limit for filename lengths. Appending 'i' to the end of the filename isn't a robust method for generating unique filenames. You might want to consider a different approach. Check out [this StackOverflow post](https://stackoverflow.com/questions/10501247/best-way-to-generate-random-file-names-in-python) for some suggestions on generating random filenames in Python. – daniellalasa Aug 20 '23 at 18:15

0 Answers0