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 7918193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:25:23+00:00 2026-06-03T15:25:23+00:00

In Python, what is a good, or the best way to generate some random

  • 0

In Python, what is a good, or the best way to generate some random text to prepend to a file(name) that I’m saving to a server, just to make sure it does not overwrite. Thank you!

  • 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-03T15:25:24+00:00Added an answer on June 3, 2026 at 3:25 pm

    Python has facilities to generate temporary file names, see http://docs.python.org/library/tempfile.html. For instance:

    In [4]: import tempfile
    

    Each call to tempfile.NamedTemporaryFile() results in a different temp file, and its name can be accessed with the .name attribute, e.g.:

    In [5]: tf = tempfile.NamedTemporaryFile()
    In [6]: tf.name
    Out[6]: 'c:\\blabla\\locals~1\\temp\\tmptecp3i'
    
    In [7]: tf = tempfile.NamedTemporaryFile()
    In [8]: tf.name
    Out[8]: 'c:\\blabla\\locals~1\\temp\\tmpr8vvme'
    

    Once you have the unique filename it can be used like any regular file. Note: By default the file will be deleted when it is
    closed. However, if the delete parameter is False, the file is not
    automatically deleted.

    Full parameter set:

    tempfile.NamedTemporaryFile([mode='w+b'[, bufsize=-1[, suffix=''[, prefix='tmp'[, dir=None[, delete=True]]]]]])
    

    it is also possible to specify the prefix for the temporary file (as one of the various parameters that can be supplied during the file creation):

    In [9]: tf = tempfile.NamedTemporaryFile(prefix="zz")
    In [10]: tf.name
    Out[10]: 'c:\\blabla\\locals~1\\temp\\zzrc3pzk'
    

    Additional examples for working with temporary files can be found here

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

Sidebar

Related Questions

What is the best way to make a browser=based chat server with a python
Is there a good way in C# to mimic the following python syntax: mydict
What is a good way to format a python decimal like this way? 1.00
Given an arbitrary python object, what's the best way to determine whether it is
What is a good solution for communication via message broker that supports both (C)Python
I have an IIS 6.0 web server that I currently use to serve some
I have a file that has over 200 lines in this format: name old_id
I wonder if there is a good way to bind local variables in python.
I need to add some extra text to an existing PDF using Python, what
What is the best way to pass List via form in python (cgi). ListStr

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.