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 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

I'm trying to write a function that can call a webmethod from a webserive
The goal is to access the nth element of a vector of strings instead
I have a project here the goal is to merge multiple Access DB's into
Goal: Produce an Excel document with information from 3 associated models that is similar
My site is powered by node & using the Express framework. My goal is
rails version rails 3.2.1 Goal: Access ActiveAdmin login page only office computer. Code: route.rb
I'd like to write a screenshot tool in Python. Right now i'm studying how
I have some shared preferences (latitude, longitude) that I want to access from a
I am developing a web service that will be invoked (using JSON) from client
I want to ask about manipulating IE via Powershell. My goal is to write

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.