2

I have a program that reads in several subfolders of files.

I had previously written code that had :

path = 'C:/Users/Me/etc/etc/'

And then I would open several files by saying

file1 = path + str('file1.txt')

How do I change the code so that it can be used by others? I am using Jupyter notebook and so __file __ and sys(argv[0]) don't seem to be working.

I have looked at these:

  1. How to get an absolute file path in Python
  2. How do I get the parent directory in Python?
Chid
  • 45
  • 1
  • 8

1 Answers1

0

Use get current working directory,

def join_current_dir(file):
    """Join filepath with current file directory"""
    cwd = os.getcwd()
    return os.path.join(cwd, file)
foxyblue
  • 2,859
  • 2
  • 21
  • 29
Napitupulu Jon
  • 7,713
  • 3
  • 22
  • 23