Expected type 'optional[bytes]' got 'str' instead

Chris Angelico rosuav at gmail.com
Tue Sep 13 07:26:41 EDT 2016


On Tue, Sep 13, 2016 at 9:19 PM, Daiyue Weng <daiyueweng at gmail.com> wrote:
> Could you give me an example of doing this using os.path.split and
> os.path.join?
>
> thanks

Sure, but I'm keeping this on list.

os.path.split basically does the same thing you do.

# maintaining your non-PEP-8 names
rootPath = os.path.abspath(__file__)
rootPath = os.path.split(os.path.split(rootPath)[0])[0]

os.path.join simply joins pieces together, so you could join a couple
of ".." to your path.

rootPath = os.path.abspath(os.path.join(__file__, "..", ".."))

Advantage: They don't depend on backslashes in file paths, so they'll
work on all platforms.

ChrisA



More information about the Python-list mailing list