You can download this code by clicking the button below.
This code is now available for download.
This function first gets the current time, then generates a random string as the filename, creates a file, writes two arguments to the file, and finally returns the filename and the current time.
Technology Stack : datetime, string, random, os, sys
Code Type : File operation
Code Difficulty : Intermediate
import random
import string
import math
import datetime
import os
import sys
import json
import re
def generate_random_string(length=10):
letters = string.ascii_letters
return ''.join(random.choice(letters) for i in range(length))
def xxx(arg1, arg2):
current_time = datetime.datetime.now()
filename = generate_random_string(10) + '.txt'
with open(filename, 'w') as file:
file.write(arg1)
file.write(arg2)
return filename, current_time