Inconsistency in python system attribute "__file__" on different linux distros

I am dealing with weird problem. Consider this simple code:

print("***" + os.path.dirname(__file__) + "###")

now when I run this code on my laptop, where I have Fedora 23 OS, the output is:


running the same code on Ubuntu 15.10:

can anybody explain me why? Am I missing something?


You probably don't want to purely rely on the __file__ attribute, but you ensure you have a full path abspath:


__file__ is defined by the argument given to Python that tells it what your file is. For example, let's say you are in a folder called Here. You could say python ../Here/, and __file__ would be ../Here/ If you ran the same file with just python, __file__ is When you run the Python file in the same directory without using either an absolute path or a weird relative path, the file will not have any directories mentioned. That means that os.dirname(__file__) will be blank. If you want, you can get the absolute path with os.path.abspath().

Need Your Help

document.ready() function not working

javascript jquery

I am working for selecting the text from a text box to the clipboard with the help of zclip. But the document.ready() is not working. It is not even showing the alert.

Why isn't this print method working?

objective-c printf nslog

It works when I use NSLog, but not printf. I want to use printf because then all the elements in setA will be displayed in one line.