erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.68k stars 55 forks source link

`__file__` is not defined #510

Closed mtshiba closed 5 months ago

mtshiba commented 5 months ago

From: #508

print! __file__
$ erg test.er    
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "test.er", line -1, in <module>
NameError: name '__file__' is not defined. Did you mean: '__name__'?

Erg does not create files (on Unix) when executing Python bytecode. That is, __file__ is not set. Even if the compiler creates the file, it will be created in the temporary directory, so it won't work as intended anyway. The compiler must embed the contents of this variable at compile time.


Originally posted by @toddlerer in https://github.com/erg-lang/erg/issues/508#issuecomment-2088396573