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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:40:24+00:00 2026-06-05T21:40:24+00:00

Currently working with the following package structure: /package __init__.py final.py /write __init__.py write.py /data

  • 0

Currently working with the following package structure:

/package
    __init__.py
    final.py
    /write
        __init__.py
        write.py
    /data
        backup.txt
        backup1.txt
        backup2.txt

final.py imports write.py, which should be able to go back one directory and write a series of backup .txt files to /data.

final.py should be able to go into /data during another call and access the backup files, hence the need to save the information in /data.

  1. I’m not sure this should be the correct hierarchy for a package file? How would /write create text files in a directory branch separate from itself without using absolute file paths in case the whole project file is moved, say onto a server.

  2. Would it be wrong (once the backup.txt files are created) to add a retrieve.py to /data which returns the .txt files in some sort of data structure and make /data a package, or (2) should final.py directly enter /data and retrieve the text files.

  • 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-05T21:40:25+00:00Added an answer on June 5, 2026 at 9:40 pm
    1. IMO you shouldn’t be writing into your packages. Set your code up so that you are writing to a data directory that is potentially outside your package. Numerous code deployment strategies assume that your code will be in a directory that is not normally writable. (E.g. if it is packaged for common linux distributions, the code will go into /usr/lib/python…/yourpackage/ and the data will be written to /var/lib/yourpackage, or something similar.)
    2. Put your retrieve.py outside of …/data, possibly in a …/read directory, or alongside final.py, depending on the organization you need.

    To write to an arbitrary location, just pass the full path to open. For example, assume that you store the path to your data directory in a constant:

    DATA_PATH = '/var/lib/mypackage'
    
    def backup():
        f = open(os.path.join(DATA_PATH, 'backup.txt'), 'w')
        f.write('some backup data...')
        f.close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working with the following pseudo code block to fix a regex
I'm currently working on a database with the following requirements: There are accounts of
I'm currently working on incorporating an authorization feature for Twitter following the approach described
I`m currently working on a script, and I have the following situation. function somnicefunction()
I am currently working on a simulator and encountered the following error during debug
I am currently working on Problem 62 I have tried the following code to
I'm currently working on an SSIS package to load mainframe logs from multiple server/file
I'm currently working on a big JavaScript project for which we want to define
I am currently working on a while loop that should get the following information
I before I started the game I'm currently working on, I built the following

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.