Open toddlerer opened 5 months ago
Although not directly related to this PR, I enhanced the type definitions of os.path
and added a method called Str.from
that does the same thing as Python's self[nth:]
.
So, mylib.{d.er, py}
should no longer be necessary from the next release, which will be released next week.
@mtshiba
Thank you for your prompt response. I tried replacing mylib.{d.er, py}
with the latest commit on the main branch, and I was able to replace almost everything. However, I couldn't replace the parts using __file__
, and it seems that __file__
is not available when running with erg run
. (It worked when I transpiled with erg transpile
and then ran the Python file.)
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__'?
In this case, I am using it to obtain the directory of the currently executing file and set it as the current directory.
os = pyimport "os"
cwd = os.path.dirname! __file__
os.chdir! cwd
@mtshiba Thank you for your prompt response. I tried replacing
mylib.{d.er, py}
with the latest commit on the main branch, and I was able to replace almost everything. However, I couldn't replace the parts using__file__
, and it seems that__file__
is not available when running witherg run
. (It worked when I transpiled witherg transpile
and then ran the Python file.)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__'?
In this case, I am using it to obtain the directory of the currently executing file and set it as the current directory.
os = pyimport "os" cwd = os.path.dirname! __file__ os.chdir! cwd
I believe this bug has been fixed in the main branch.
I encountered a bug that seemed to be caused by non-intuitive behavior of default arguments when using a recursive function in Python, so I fixed it by switching to a for loop.
@mtshiba