0

I found this question that has answers that work on mac, but do they work on Windows, Linux, etc? I am referring specifically to os.path.realpath(__file__) or os.path.realpath('myPythonFile.py').

I apologize for this question being so obvious to figure out but I don't have access to non-mac computers and so can't test it myself.

Community
  • 1
  • 1
Johnny Dollard
  • 708
  • 3
  • 11
  • 26

2 Answers2

3

According to the reference docs that method should work fine for all operating systems.

Specifically from the docs:

Note Since different operating systems have different path name conventions, there are several versions of this module in the standard library. The os.path module is always the path module suitable for the operating system Python is running on, and therefore usable for local paths.

0

I think that you should try this one too

import os
import sys
f_name = os.getcwd() + sys.argv[0]
print f_name
boladjivinny
  • 1
  • 1
  • 3