Code: Select all
with open(oldfile, 'r', encoding='utf-8') as infile:
Code: Select all
with open(oldfile, 'r', encoding='utf-8') as infile:
Code: Select all
- Meta:
AuthorAndLicense: !!python/str '(c) 2019 Uwe Stöhr (CC-BY 3.0)'
CardName: PA6-Generic
- General:
Name: !!python/unicode 'Polyamide 6'
Code: Select all
$ file *.FCMat
ABS.FCMat: ASCII text
ABS-Generic.FCMat: ASCII text
Acrylic-Glass-Generic.FCMat: UTF-8 Unicode text
CalculiX-Steel.FCMat: ASCII text
Concrete-Generic.FCMat: ASCII text
Glass-Generic.FCMat: UTF-8 Unicode text
None.FCMat: ASCII text
PA6-Generic.FCMat: UTF-8 Unicode text
PET-Generic.FCMat: UTF-8 Unicode text
PLA.FCMat: ASCII text
PLA-Generic.FCMat: UTF-8 Unicode text
PP-Generic.FCMat: UTF-8 Unicode text
PTFE-Generic.FCMat: UTF-8 Unicode text
PVC-Generic.FCMat: UTF-8 Unicode text
Steel-Generic.FCMat: ASCII text
TEMPLATE.FCMat: ASCII text
Wood-Generic.FCMat: ASCII text
The encoding is OK. I'm digging into ascii/utf-8/python2-3 and yaml. If file contains only ascii characters it's a valid utf-8 file as well. I tried quite a few combinations, yet python2/yaml exports strings like "szkło" (unicode/utf-8) as !!python/str and I have no idea why. But I learned a lotbernd wrote: ↑Fri Mar 01, 2019 7:47 pm strange because the cards are all written by your bash scripts on my linux debian machine. I wonder why they have different encoding ...
I am not sure about when Python 2 support will be dropped in FreeCAD I do not thing in 0.19 already. But I would like to switch in 0.19 to this yaml cards.
Code: Select all
>>> y = yaml.load("""\n - szkło\n - test\n """) ; print(yaml.dump(y))
["szk\u0142o", test]
>>> with open('y', 'w') as f:
... yaml.dump(y, f, default_flow_style=False, allow_unicode=True)
Code: Select all
$ cat y
- szkło
- test
Code: Select all
$ file y
y: UTF-8 Unicode text
Code: Select all
pythonopen = open
Code: Select all
unicode = str
Code: Select all
>>> with open('x-fc.yml') as f:
... x = yaml.load(f)
...
>>> with open('x-fc.yml', 'w') as f:
... yaml.dump(x, f, default_flow_style=False, allow_unicode=True)
To start a disscusion, a topic in developer part of the forum makes sence IMHO.PrzemoF wrote: ↑Sat Mar 02, 2019 10:42 pm Side note: we currently redefine python "open" and other build-in functions. Should we instead change it to fc_open across FreeCAD code? Renaming build-in functions is very confusing thing. I'm aware I'm asking for a huge thing, but unless there is a good reason to do it (C++/python hooks?) I'd avoid it even if it means changing it in the whole FreeCAD code.