Grasshopper

algorithmic modeling for Rhino

hi I am trying to make the follow snippet work :

import os,sys
reload(sys)
sys.setdefaultencoding('UTF8')


line_number = 0
with open('C:\1.txt', encoding='utf-8') as a_file: #utf-8(linux) or cp1252(windows)
for a_line in a_file:
line_number += 1
print('{:>4} {}'.format(line_number, a_line.rstrip()))

so that it can read from multiple

also the text is in a foreign language, korean.

I tried with a txt file in english but throws the same error : 

1. Solution exception:open() got an unexpected keyword argument 'encoding'

Any ideas? A bit in a hurry. Thank you.

Views: 477

Replies to This Discussion

Hi Youngjae,

This means that open() does not have an encoding option.

https://docs.python.org/2/library/functions.html#open

Giulio
--
Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service