fable-compiler / Fable.Python

Python bindings for Fable
https://fable.io/docs/
MIT License
135 stars 10 forks source link

Builtins.builtins.open has incorrect definition #79

Closed teknikal-wizard closed 1 year ago

teknikal-wizard commented 1 year ago

I am working through converting an ML sample to Fable Python, and I need to open a CSV file.

It seems the proper Python way to do that is to use the csv module. The csv.reader function requires a file which they load with the built in open function.

I found that function in Fable.Python.Builtins.builtins has an open function, but it has no intellisense and shows an error when I try to use it.

image

dbrattli commented 1 year ago

Yes, open is a keyword in F#. That's why you get that message. Look at line 4, 5 and 6. We cannot use that name so the open function from Python have been named ``open``. E.g try:

let result = builtins.``open``("test.txt", OpenTextMode.Write)
dbrattli commented 1 year ago

Another option is to use System.IO.ReadAllText which is supported by Python

teknikal-wizard commented 1 year ago

Ah of course! Thank you :)