forum.vmspython.org Forum Index forum.vmspython.org
Forum system
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Text file I/O

 
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS
View previous topic :: View next topic  
Author Message
JeremyBegg



Joined: 02 Feb 2010
Posts: 30
Location: Adelaide, South Australia

PostPosted: Thu Sep 27, 2012 9:26 am    Post subject: Text file I/O Reply with quote

Hi,

My user who is moving from Python 2.3 (VMS 7.2-2) to Python 2.7.3 (IA64 V8.4) has found another problem. I don't understand enough Python to give him a quick answer so I am hoping someone in this forum can. Here's what he has to say.

Python 2.3
Code:
HO2$ create a.a
123
456
789
 Exit
HO2$ python
Python 2.3 (#0, Aug 26 2003, 03:17:24) [DECC] on OpenVMS
Type "help", "copyright", "credits" or "license" for more information.
>>> import binascii
>>> binascii.hexlify(open('a.a','rU').read())
'3132330a3435360a3738390a'                             this is correct
>>> binascii.hexlify(open('a.a','r').read())
'3132330a3435360a3738390a'                             this is correct
>>> binascii.hexlify(open('a.a','rb').read())
'313233343536373839'                                   this is wrong (does not include line lengths, [pack byte])
>>>  Exit


Note that the file a.a will be a VarCR file since that's what the CREATE command does by default.

Under Python 2.7.3 on OpenVMS IA64 V8.4 the results are somewhat different ...
Code:

HO3$ create a.a
123
456
789
 Exit
HO3$ python
Python 2.7.3+ (default, Apr 20 2012, 20:06:26) [DECC] on OpenVMS
Type "help", "copyright", "credits" or "license" for more information.
>>> import binascii
>>> binascii.hexlify(open('a.a','rU').read())
'030031323300030034353600030037383900'         this is wrong (not interpreting line separators as \n) = A BUG
>>> binascii.hexlify(open('a.a','r').read())
'3132330a3435360a3738390a'                     this is “correct”
>>> binascii.hexlify(open('a.a','rb').read())
'030031323300030034353600030037383900'         this is correct (line length and pack bytes but not end-of-file marker)
>>>  Exit


He thinks the behaviour is a bug, but I suspect it might be a feature which can be configure using a DEC C RTL logical name. I just don't know which one!

Thanks,
Jeremy Begg
Back to top
View user's profile Send private message Visit poster's website
jfp



Joined: 12 Jul 2004
Posts: 632

PostPosted: Wed Oct 03, 2012 2:04 pm    Post subject: Reply with quote

Hello Jeremy,

this is not a bug, but a feature of Python 2.7.

2.5 on OpenVMS, when a file is opened, in universal mode ('U') it just open it in text mode.

But this can't work on 2.7 because use this more extensively.

So, 2.7 open the file in binary mode and try to find line terminator.

So with streamlf or streamcr file this will work, but with vfc file this doesn't work.

This is why binary and universal mode, on OpenVMS, return the same result for a vfc file, this is a restriction of the CRTL.


JF
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group