Skip to content

Instantly share code, notes, and snippets.

@pepoluan
Created March 24, 2025 05:15
Show Gist options
  • Save pepoluan/135956344c70c8834053c58c40b7e8de to your computer and use it in GitHub Desktop.
Save pepoluan/135956344c70c8834053c58c40b7e8de to your computer and use it in GitHub Desktop.
Create a filename that does not exist
import random
import string
fromt pathlib import Path
def file_that_does_not_exist() -> Path:
def _randname() -> str:
return "".join(
random.choice(string.ascii_lowercase)
for _ in range(8)
)
while (fp := Path(_randname())).exists():
pass
return fp
print(f"This file does not exist: '{file_that_does_not_exist()}'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment