I
I
InternetMaster2021-10-23 00:11:06
linux
InternetMaster, 2021-10-23 00:11:06

How to get Linux (Ubuntu) working category?

Question: I made python code on windows, worked with the os library, as soon as I put the script on a server running ubuntu, it os.path.abspath(os.getcwd())started giving out not the full path like /home/papka/file , but just /file . How to get the full path to the folder in which the script is running?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
antares4045, 2021-10-23
@antares4045

os.getcwd() -- this is the path to the place from which the command to run the script was given,
which may not be the same as the path to the script
, I usually use os.path.dirname(__file__) -- it hasn't let me down in any os yet

G
Griboks, 2021-10-23
@Griboks

from pathlib import Path

Path.cwd().absolute()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question