Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python File Path Name

Tags:

python

file

io

What is the difference between "./file_name", "../file_name" and "file_name"when used as the file path in Python?

For example, if you want to save in the file_path, is it correct that "../file_name" will save file_name inside the current directory? And "./file_name" will save it to the desktop? It's really confusing.

like image 239
Chaine Avatar asked Jul 15 '26 23:07

Chaine


1 Answers

./file_name and file_name mean the same thing - a file called file_name in the current working directory.

../file_name means a file called file_name in the in the parent directory of the current working directory.

Summary

. represents current directory whereas .. represents parent directory.

Explanation by example

if the current working directory is this/that/folder then:

  • . results in this/that/folder
  • .. results in this/that
  • ../.. results in this
  • .././../other results in this/other
like image 166
EyuelDK Avatar answered Jul 17 '26 17:07

EyuelDK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!