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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:44:03+00:00 2026-06-03T23:44:03+00:00

Suppose I have the following directory structure: workspace/ __init__.py ys_manage/ __init__.py manage.py ys_utils/ __init__.py

  • 0

Suppose I have the following directory structure:

workspace/
  __init__.py
  ys_manage/
    __init__.py
    manage.py
  ys_utils/
    __init__.py
    project_dicts.py

Now, suppose I need access to project_dicts.py in manage.py. Also, my $PATH includes /home/rico/workspace/ys_manage.

I need to be able to run manage.py from any directory on my machine and still be able to access project_dicts.py.

My $PYTHONPATH only has /home/rico/workspace.

If I include the following in manage.py I can run the file from ~/workspace/ys_manage but not anywhere else.

import sys
sys.path.append('..')
from ys_utils import project_dicts

It appears that the '..' gives a relative path to where the directory where the file is run, not where the file is located. Is this correct?

I wanted to try and use ys_manage/__init__.py to import project_dicts.py so that it would be available in manage.py universally. Is this a good idea?

I’ve never used __init__.py for anything other than a “package creator”. That is, I’ve never used it for initialization purposes. Perhaps I’m doing it wrong.

Contents of ys_manage/__init__.py:

import sys
sys.path.append('..')
from ys_utils import project_dicts

Should I include something in manage.py to look for this import?

When I try and run manage.py I get the following error:

NameError: global name 'project_dicts' is not defined

As a secondary question, do I need to have workspace/__init__.py? I’d really rather not have it because ys_manage and ys_utils (and about a dozen other packages) are all under revision control and used by several other developers…workspace is not.

  • 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-03T23:44:05+00:00Added an answer on June 3, 2026 at 11:44 pm

    Try this instead of sys.path.append('..'):

    sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
    

    (you’ll need to import both sys and os).

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

Sidebar

Related Questions

Suppose I have a directory structure like the following /a/b/testB.xml /a/c/testC.xml /a/testD.xml and I
Suppose I have the following (desired) folder structure: *CommonProject *Project#1 ----> CommonProject(link) *Project#2 ---->
For instance, I suppose I have a directory that contains the following folders foo_bar
Suppose I have the following directory layout in a Maven project: src/ |-- main
I have this flex project.And the below mentioned is my directory structure (List1).Now if
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose we have the following table data: ID parent stage submitted 1 1 1
Suppose I have the following HTML: <form id=myform> <input type='checkbox' name='foo[]'/> Check 1<br/> <input
Suppose I have the following: A region defined by minimum and maximum latitude and
Suppose I have the following: using(var ctx = DataContextFactory.Create(0)) { ... Some code ...

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.