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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:47:28+00:00 2026-06-06T07:47:28+00:00

I am writing a program that sets up a file path that I use

  • 0

I am writing a program that sets up a file path that I use to store data. The format is as follows

c://users/username/.../endingpath

When i switch computers the username is changed. Is there a way or a method that specifies what the username is for the specific computer I am working on? Or is there an even better way of making the path computer independent?

I’m running Python 2.7 on Windows 7

  • 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-06T07:47:30+00:00Added an answer on June 6, 2026 at 7:47 am

    Under Windows, there are several pre-defined environment variables that you can look at. One of those is USERNAME.

    So:

    import os
    user_name = os.getenv("USERNAME")
    

    Windows also defines environment variables for some directories. If your file should be stored in the user’s personal home directory (on Windows 7, this is: %SystemDrive%\Users\{username}) you can use USERDATA or USERPROFILE. This is better than trying to build your own path with the user name.

    @Matteo Italia pointed out that APPDATA is probably the best one to use; that is specifically a directory for applications to store their data files. This makes sense to me; I think he is right.

    So:

    import os
    appdata_dir_name = os.getenv("APPDATA")
    

    I found a list of Windows environment variables in Wikipedia:

    http://en.wikipedia.org/wiki/Environment_variable#Examples_from_Microsoft_Windows

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

Sidebar

Related Questions

I'm writing a program that's parsing an XML file to java objects using smooks.
I'm writing a program that reads huge file (3x280 GB) and does a fitting
I am writing a program that creates an image file. I want the original
Overview I am writing a Ruby program that uses data from mysql queries to
I have tried writing program that plays a sound file but have been unsuccessful
I am writing a program that gets a HTML file in Android and I
I'm writing a program that needs to watch for file system events on multiple
I'm writing a test program that use a Tab Controller with multiple tab views.
I' writing a program that stores opening hours for a store in a database
I'm writing a program that iterates a file tree and now I need it

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.