radon-project / radon

The Radon Programming Language
https://radon-project.github.io
GNU General Public License v3.0
21 stars 2 forks source link

Built-in class `File` is not working. #157

Closed Almas-Ali closed 1 month ago

Almas-Ali commented 1 month ago

Describe the bug Could not open a file. No such file or directory!

Screenshots or Code snippets Check the examples/files.rn file.

Radiation (most recent call last):
  File examples/files.rn, line 2, in <program>
RuntimeError: Could not open file examples/files.rn: [Errno 2] No such file or directory: 'examples/files.rn'

f = File("examples/files.rn")
         ^^^^^^^^^^^^^^^^^^^
Vardan2009 commented 1 month ago

It works for me...?

>>> f = File("examples/files.rn")
<core.builtin_classes.base_classes.BuiltInInstance object at ...>
>>> f.read()
"
f = File("examples/files.rn")
contents = f.read()
f.close()

print(contents)

"
>>>
Almas-Ali commented 1 month ago

Run the file not in REPL. ./radon.py -s examples/files.rn

Vardan2009 commented 1 month ago

That's because the file is already in ./examples, when it tries to get examples/files.rn, it actually tries to get ./examples/examples/files.rn relative to the root of the radon folder

angelcaru commented 1 month ago

So we need a separate import_cwd for imports. That's the only reason we change directory in the first place

Vardan2009 commented 1 month ago

So import_cwd will import from the command line's cwd?

angelcaru commented 1 month ago

No, import_cwd would cd into the directory where the script is while leaving the process cwd unaltered