0

I am running the script with python setup.py script is in this folder:

/data/jenkins/pypi/fabundle_env/fa-bundle/base

One folder above I have a Readme.Md file which content I need to reed.

import os
fname="Readme.Md"
print (os.path.join(os.path.dirname((os.path.dirname(os.path.abspath(__file__))))), fname)

def read(fname):
    return open((os.path.join(os.path.dirname((os.path.dirname(os.path.abspath(__file__))))), fname)).read()


long_description=read('Readme.Md')

Output:

 /data/jenkins/pypi/fabundle_env/fa-bundle Readme.Md
    Traceback (most recent call last):
      File "setup.py", line 22, in <module>
        long_description=read('Readme.Md'),
      File "setup.py", line 14, in read
        return open((os.path.join(os.path.dirname((os.path.dirname(os.path.abspath(__file__))))), fname)).read()
    TypeError: expected str, bytes or os.PathLike object, not tuple

For implementation purposes I have read os.path.join(os.path.dirname(__file__)) returns nothing but I had to use abspath in order to get some result.

Thanks

vel
  • 1,000
  • 1
  • 13
  • 35
  • I was about to answer the question, but it's just been closed. The problem is you're passing `fname` to `open`, it should be passed to `os.path.join`. It's easier if you split it up onto multiple lines so you don't have so many parenthesis to look at. like so `def read(fname):` `path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), fname)` `return open(path).read()` – hostingutilities.com Jul 06 '22 at 06:35
  • You can also use pathlib which is a more modern alternative. `from pathlib import Path` `def read(fname):` `path = Path('.').parent.parent / fname` `return path.read_text()` – hostingutilities.com Jul 06 '22 at 06:42

0 Answers0