In Python the canonical way to open a file for reading and guarantee closing if 
it was opened at all is this (which also ensures the encoding is what you want):
    
    
    with open(filename, encoding="utf-8") as file:
        process(file) # user-defined function
    

Is this the canonical way to open and ensure the closing of a file in Nim?:
    
    
    var fh : File
    if open(fh, filename):
      try:
        process(fh) # user-defined function
      finally:
        close(fh)
    

In Nim there doesn't appear to be any way to specify the encoding (and while 
most of my files are utf-8, some are latin1), so how would I specify latin1?

Thanks.

Reply via email to