Hi everyone,
I am coming to you because I need help with the code below.
I'm looking to generate text files of n- lines. Each line contains n- random characters.
I also want the names of the output files to increment when the n- lines are reached.
The number of files is not defined, and the process will be killed by "ctrl+c".
For my example I chose files of 1000 lines, each containing 6 characters.
Generate a 1000 lines file, no problem.
I tried several loops in several places, but I get stuck and I can't get what I want.
The "count" variable allows me to determine the number of lines saved in the file.
The "nameFile" variable is for incrementing the filename.
I tried replacing the "while" by "if" but identical.
Thank you for your feedback.
I am coming to you because I need help with the code below.
I'm looking to generate text files of n- lines. Each line contains n- random characters.
I also want the names of the output files to increment when the n- lines are reached.
The number of files is not defined, and the process will be killed by "ctrl+c".
For my example I chose files of 1000 lines, each containing 6 characters.
Generate a 1000 lines file, no problem.
I tried several loops in several places, but I get stuck and I can't get what I want.
The "count" variable allows me to determine the number of lines saved in the file.
The "nameFile" variable is for incrementing the filename.
I tried replacing the "while" by "if" but identical.
count = 0 while True: letters_and_digits = string.ascii_letters + string.digits result_str = ''.join((random.choice(letters_and_digits) for i in range(6))) nameFile = 0 while count < 10000: with open("test%d.txt" % nameFile, "a") as f: f.write(result_str + '\n') count += 1I always come back to my code that works without being able to advance it.
Thank you for your feedback.