add generate_random_string
This commit is contained in:
parent
ebac7f49fd
commit
a8479a56e3
1 changed files with 11 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
import random
|
||||||
|
import string
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
@ -35,3 +37,12 @@ def rmtree(root_dir: Path):
|
||||||
child.unlink()
|
child.unlink()
|
||||||
|
|
||||||
root_dir.rmdir()
|
root_dir.rmdir()
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_string(length: int, punctuation=False) -> str:
|
||||||
|
"""returns a random string of the given length"""
|
||||||
|
characters = string.ascii_letters + string.digits
|
||||||
|
if punctuation:
|
||||||
|
characters += string.punctuation
|
||||||
|
random_string = "".join(random.choice(characters) for _ in range(length))
|
||||||
|
return random_string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue