0
As I identify the root of the operating system (windows: "C: ", No linux: "/"), exclusively through python commands that apply to both systems?
0
As I identify the root of the operating system (windows: "C: ", No linux: "/"), exclusively through python commands that apply to both systems?
3
Use the commands below:
>>> import os
>>> os.path.abspath(os.sep)
'/'
Results would be:
Works on Windows too?
@Andersoncarloswoss yes
I don’t think that’s what he asked for. What would be the result in windows?
@Sidon edited.
Okay, to be complete I would have to remove the scape, I mean, I would have to elaborate more, as I did in my reply. :-)
Escape is not part of the variable, it is not possible to "remove" it. It is only a visual representation, which appears when printing the repr()
of the variable. The answer is correct.
Truth, things from the windows world, I think I’ve never done anything in python in windows. :-)
0
I got the solution, gentlemen.
os.path.commonpath(os.get_exec_path())
The association of the above commands will always display the operating system root (OS), for any OS.
:D
If @sant0will’s answer works on any single, what is the advantage of your solution over his (more sleek and sleek)?
@Sidon, I’m not sure yet... I have to test, as it will have to work in network directories, and multiple drives... I will bring the result.
@Sidon, tested and works well.
@sant0will’s alternative is simpler, pythonica and works well!!! It is the best solution for this problem.
Browser other questions tagged python python-3.x
You are not signed in. Login or sign up in order to post.
If these are both values, why do you need a function for this? It would not be enough for one
if
checking if it’s Windows or Linux?– Woss
I need it captured from the operating system.
– britodfbr
that question has already been answered: https://answall.com/questions/167296/howto detect the operating system
– Adriano Gomes
@Adrianogomes he asked to return the root folder of the only one that uses the application, not just identify the system
– sant0will
I got it, gentlemen. Thank you. Here’s the solution: https://answall.com/a/337395/62736
– britodfbr