0

My Project Euler setup is a PyDev project that I work on from two different computers (one is a Mac, the other is Windows 7). The file structure of the project looks like this:

PROJECT_LOC/
  unsolved/
    The .py files for the problems I haven't solved
  solved/
    Problems_001_025/
      .py files for problems 1-25
  ... etc ...
  texts/
    Any input files provided by Project Euler (e.g., Problem 22)

Every file is named in the pattern Problem###.py or Problem###.txt.

Once I solve a problem, I move it from unsolved to the correct directory in solved, which is where my difficulty comes in:

Given a problem with input, say Problem022.py:

for line in open("../texts/Problem022.txt"):
    # read file in
# code to solve the problem

Since I solved Problem 22 a while back, I moved it from PROJECT_LOC/unsolved/ to PROJECT_LOC/solved/Problems_001_025/. Now, (not surprisingly) when I try to run it again, it gives me a no such file error.

So, without changing my file structure, is there a way for me to access the input text files from wherever I am in the project directory?

I was thinking I could do something like open(${PROJECT_LOC}/texts), but I have no idea how to get the PROJECT_LOC from Eclipse at run time, and have it work on both Windows and OS X. I played with what this person did in his question, but couldn't get it to work for me.

Community
  • 1
  • 1
Matthew Denaburg
  • 163
  • 1
  • 15

1 Answers1

1

I figured it out...

I added an environment variable to the interpreter with the value ${PROJECT_LOC:texts}/ in my Eclipse preferences. I can now use os.environ["PROJECT_EULER_TEXT_FILES"] to pull the location of the input.

Matthew Denaburg
  • 163
  • 1
  • 15