Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:18:36+00:00 2026-06-13T13:18:36+00:00

I am automatically generating filenames and I do not want there to be an

  • 0

I am automatically generating filenames and I do not want there to be an overwrite. I am lazily using this little line of code

fd, filepath = tempfile.mkstemp(ext, prefix='odt_img_', dir=self.destPath)
os.close(fd) # just using the name and overwriting later

Later on I write to filepath, but I am not sure if mkstemp just adds some random letters or if it actually makes sure the name is unique.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:18:37+00:00Added an answer on June 13, 2026 at 1:18 pm

    tempfile.mkstemp only guarantees to create and open a new file with a name that does not exist. From the docs:

    Creates a temporary file in the most secure manner possible. There are no race conditions in the file’s creation, assuming that the platform properly implements the os.O_EXCL flag for os.open().

    and the O_EXCL flag specifies:

    Ensure that this call creates the file: if this flag is specified in conjunction with O_CREAT, and the filename already exists, then open() will fail.

    Internally, mkstemp just loops through a random sequence trying to create a file that does not exist until it succeeds or runs out of “ideas” in which case it would fail with an IOError.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are generating a newsletter automatically every 24 hours using a rake task. There's
There is some code in our system for automatically generating self-signed certificates into a
Is there any way generating automatically a jax-rs client with HttpUrlConnection or third party
I'm automatically generating a PDF-file with Platypus that has dynamic content. This means that
I`m thinking of using POCO instead of automatically generating the entities, cause i don't
Is there a good Javascript library for generating an automatically scrolling list like the
This is the code where i generating my table : foreach($list_user as $temp){ $this->table->add_row(++$i,
Any tool for automatically generating unit tests for Java code? UPDATE: Primary intended use
Is there any open source tool for automatically generating .NET wrappers for a COM
Is there a way of automatically generating a HTML-Map compatible list of coordinates of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.