samedi 28 décembre 2019

How to loop print output and write each result to csv?

I have written the following code to generate a random 12 number string:

import uuid

def my_random_string(string_length=12):
    """Returns a random string of length string_length."""
    random = str(uuid.uuid4()) # Convert UUID format to a Python string.
    random = random.upper() # Make all characters uppercase.
    random = random.replace("-","") # Remove the UUID '-'.
    return random[0:string_length] # Return the random string.

print(my_random_string(12)) # For example, D9E50Cd

How can I loop it and save each string output to a .csv file?




Aucun commentaire:

Enregistrer un commentaire