Python: How to identify the root of the operating system?

0

How do I identify the root of the operating system (windows: "C: \", in linux: "/"), exclusively through python commands that apply to both systems?     

asked by anonymous 18.10.2018 / 20:47

2 answers

2

Use the commands below:

>>> import os
>>> os.path.abspath(os.sep)
'/'

Results would be:

  • Linux returns "/"
  • Windows returns "C: \\" (or whatever the current disk is)
18.10.2018 / 20:58
0

I got the solution, gentlemen.

os.path.commonpath(os.get_exec_path())

The combination of the above commands will always display the operating system root (OS) for any OS.

: D

    
18.10.2018 / 22:12