[update] i added str function to write it as string and close the file to make sure it does it immediately,before i had to terminate the program so the content would be write
It's probably because you're not actually closing your file. This can cause problems. You want to use the context manager/with block when dealing with files, unless you really have a reason not to.
with open('file.txt', 'w') as f:
# Do either this
f.write(str(uuid.uuid1()))
# **OR** this.
# You can leave out the `end=''` if you want.
# That was just included so that the two of these
# commands do the same thing.
print(uuid.uuid1(), end='', file=f)
This will automatically close your file when you're done, which will ensure that it's written to disk.
You can also do this. Removes the dashes as a bonus. link to docs.
import uuid
my_id = uuid.uuid4().hex
ffba27447d8e4285b7bdb4a6ec76db5c
UPDATE: trimmed UUIDs (without the dashes) are functionally identical to full UUIDS (discussion). The dashes in full UUIDs are always in the same position (article).