Python has its own built-in codecs and does not use the system codecs. You
   can see the list (which does not include cp285) here:
   [1]
https://docs.python.org/3/library/codecs.html#standard-encodings
   As Python runs in PASE it will open the file tagged with whatever the PASE
   ccsid is (which defaults to 819 except in rare cases). There is currently
   no mechanism in Python to match the CCSID tag with the encoding of the
   data, though there are various command line programs you could call
   manually from within Python to do so.
     ----- Original message -----
     From: Craig Richards <craig@xxxxxxxxxxxxxxxx>
     Sent by: "OpenSource" <opensource-bounces@xxxxxxxxxxxx>
     To: IBMi Open Source Roundtable <opensource@xxxxxxxxxxxx>
     Cc:
     Subject: [IBMiOSS] Creating Stream Files with Python
     Date: Mon, Oct 1, 2018 11:13 AM
     Hi All,
     I can create streamfiles with different encodings in the IFS using
     python
     using the encoding parameter and this works fine e.g:
     f = open('asci.txt', 'w', encoding='cp819')
     This is good. And fine too. Some might say dandy.
     However if I look at the attributes of the stream file it is always
     CCSID
     819 if I am creating a new file.
     This means that using DSPF to look at the data on the IBMi will display
     the
     data incorrectly if that data is not actually written with encoding 819.
     I can modify the file manually using EDTF to change the file's CCSID and
     then it will be displayed correctly ( within the limitations of the 5250
     Client ) however I assume there is a way to set this attribute correctly
     for new files using python?
     I understand that the IBMi is fairly unique in that it has additional
     attributes on stream files that store information such as the (intended)
     ccsid but I know it is possible to set these correctly when using the
     unix
     open API to create stream files ( for example )
     Additionally I'm using an IBMi in the UK and QCCSID is set to 285, I get
     an
     error in the above code if I specify encoding='cp285' although it is
     quite
     happy to use encoding='cp037'.
     Not that I have a requirement to encoding in the IFS in 285 but I was a
     little surprised that 37 was supported but not 285 - especially given
     that
     it is a UK not US box.
     However my main question is - should I be using a different method to
     create my streamfiles if I want the endcoding of the streamfile ( the
     file
     header, not the actual data ) to be other than 819?
     I've tried using the codecs.open method but that seems to work the same
     -
     it creates the data correctly but the CCSID for the file itself is
     always
     819 for NEW files.
     Thanks kindly,
     Craig
     --
     This is the IBMi Open Source Roundtable (OpenSource) mailing list
     To post a message email: OpenSource@xxxxxxxxxxxx
     To subscribe, unsubscribe, or change list options,
     visit: [2]
https://lists.midrange.com/mailman/listinfo/opensource
     or email: OpenSource-request@xxxxxxxxxxxx
     Before posting, please take a moment to review the archives
     at [3]
https://archive.midrange.com/opensource.
References
   Visible links
   1. 
https://docs.python.org/3/library/codecs.html#standard-encodings
   2. 
https://lists.midrange.com/mailman/listinfo/opensource
   3. 
https://archive.midrange.com/opensource
As an Amazon Associate we earn from qualifying purchases.