× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.