Fable.Python icon indicating copy to clipboard operation
Fable.Python copied to clipboard

allow TextIOWrapper to be enumerated

Open joprice opened this issue 1 year ago • 0 comments

Could TextIOWrapper be made to be an enumerable of string? I am able to do this with a cast, which generates a call to get_enumerator that happens to call iter() on the object and work:

use result = builtins.``open`` ("test.txt", OpenTextMode.Read)
for (line: string) in !!result do
  let line = line.Trim()
  builtins.print $"'{line}'"

I can also use readline directly for a typesafe verison, but as a side note, I also noticed that it requires a parameter, where as the parameter should be optional:

use result = builtins.``open`` ("test.txt", OpenTextMode.Read)
let mutable line = result.readline (-1)
line <- line.Trim()
while line <> "" do
  line <- line.Trim()
  builtins.print $"'{line}'"
  line <- result.readline (-1)

joprice avatar Jul 22 '24 15:07 joprice