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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:14:01+00:00 2026-06-17T17:14:01+00:00

I have some code in a project which I’d like to reuse in another

  • 0

I have some code in a project which I’d like to reuse in another project. What do I need to do (in both folders) so that I can do this?

The directory structure is something like:

  • Foo
    • Project1
      • file1.py
      • file2.py
  • Bar
    • Project2
      • fileX.py
      • fileY.py

I want to use functions from file1.py and file2.py in fileX.py and fileY.py.

  • 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-17T17:14:02+00:00Added an answer on June 17, 2026 at 5:14 pm

    Ideally both projects will be an installable python package, replete with __init__.py and setup.py. They could then be installed with python setup.py install or similar.

    If that is not possible, don’t use execfile()! Manipulate the PYTHONPATH to add Foo so that import Project1.file1 works.

    For example, from Project2/fileX.py:

    from os import path
    import sys
    sys.path.append(path.abspath('../Foo'))
    
    from Project1.file1 import something
    

    However, the real answer is to make each a discrete installable package.

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

Sidebar

Related Questions

I have some code that does something like this (Irrelevant bits snipped): void foo(Bitmap
I have some code that looks like this in my GLKViewController subclass: -(void)touchesBegan:(NSSet *)touches
I found some code in a project which looks like that : int main(int
On a small embedded system project we have some code which we would like
I have some code in my project that saves an object to the database,
Can anyone help? I have some code that is shared between 2 projects. The
Sometimes I have seen some code or part of the project which I could
I have an idea for a hobby project which performs some code analysis and
I have some code in a project which should never be used in the
I have some code that references an outside DLL which in production will be

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.