You can download this code by clicking the button below.
This code is now available for download.
Generates a random string of a specified length.
Technology Stack : random, string
Code Type : Function
Code Difficulty : Intermediate
import os
import random
import string
import json
import sys
import time
import re
def generate_random_string(length):
letters = string.ascii_letters
return ''.join(random.choice(letters) for i in range(length))
def read_file(file_path):
with open(file_path, 'r') as file:
return file.read()
def save_to_file(file_path, content):
with open(file_path, 'w') as file:
file.write(content)
def count_lines_in_file(file_path):
return sum(1 for line in open(file_path))
def list_files_in_directory(directory_path):
return os.listdir(directory_path)
def is_directory_empty(directory_path):
return not os.listdir(directory_path)
def sleep_for(seconds):
time.sleep(seconds)
def regex_search(text, pattern):
return re.search(pattern, text)
def json_load(file_path):
with open(file_path, 'r') as file:
return json.load(file)
def json_dump(data, file_path):
with open(file_path, 'w') as file:
json.dump(data, file)