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

  • Home
  • SEARCH
  • 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 4237256
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:44:59+00:00 2026-05-21T02:44:59+00:00

The Goal: Access / Write to the same temp files when using a common

  • 0

The Goal:
Access / Write to the same temp files when using a common utility function called from various python modules.

Background:
I am using the python Unittest module to run sets of custom tests that interface with instrumentation via pySerial. Because I am using the unittest module, I am unable to pass required variables, such as which serial port to use, into the unittest’s test case. To get around this I am wanting to create a module that stores and returns pickled data. I have run into the issue that when I call the function get_foo() from test_case_1(), it tries to load the pickled data from the relative path based on test_case_1(), not the actual module that contains get_foo().

It is worth noting that I have contemplated using global variables, but there is a handful of data that I want to retain from run to run. Meaning that all python modules will be closed and I want to re-load the data that was stored on the previous execution.

I in SO question: Python – how to refer to relative paths of resources when working with code repository, I thought I found the solution in the first answer. To my dismay, this is not working for me in Python 2.7 (Debian)

Is there an reliable way to return the path to a specific file when called from different modules?

  • 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-05-21T02:45:00+00:00Added an answer on May 21, 2026 at 2:45 am

    Probably you know this, but here the basics first:

    ## file one: main.py, main program in your working directory
    # this code must run directly, not inside IDLE to get right directory name
    import os, mytest
    curdir=os.path.dirname(__file__) 
    print '-'*10,'program','-'*10
    print 'Program in',curdir
    print 'Module is in', mytest.curdir
    print 'Config contents in module directory:\n',mytest.config()
    input('Push Enter')
    

    The module

    ## file two: mytest.py, module somewhere in PATH or PYTHONPATH
    import os
    curdir= os.path.dirname(__file__)
    
    print "Test module directory is "+curdir
    
    ## function, not call to function
    config=open(os.path.join(curdir,'mycfg.cfg')).read
    """ Example output:
    Test module directory is D:\Python Projects
    ---------- program ----------
    Program in D:\test
    Module is in D:\Python Projects
    Config contents in module directory:
    [SECTIONTITLE]
    SETTING=12
    
    Push Enter
    """"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
My goal is to maintain a web file server separately from my main ASP.NET
my goal is to write a stored proc that can collect all field values
The goal: To create a .NET dll i can reference from inside SQL Server
My goal is to recognize simple gestures from accelerometers mounted on a sun spot.
The goal: Any language. The smallest function which will return whether a string is
My goal is to generate a directory of static html, javascript, and image files
I'm designing a Form in Access 2003. My goal is that when the user
I'm using ASM java byte code instrumentation and my goal is to measure the
Goal Java client for Yahoo's HotJobs Resumé Search REST API . Background I'm used

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.