This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author quevedo
Recipients
Date 2003-02-08.23:50:22
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Hello world.




Well, let's see. When you open a file with "write-only" 
permission, then you write some in and after that you 
print the text contained in the file, you get your code (or 
almost all) and some other characters by output (See 1 
). 




- 1:




a) Code:


#!/usr/bin/python


file = open("test.txt", "w")


file.write("We love Python")


text = file.read()


print text




b) Output:


ÿÿ    


pen("test.txt", "w")


file.write("We love Python")


text = file.read()


print text


ext




ufferTypes   tuples	   TupleTypes   lists   
ListTypes   dicts   DictTypes   DictionaryTypes   
_fs   FunctionTypes


   LambdaTypes	   func_codes   CodeTypes   
RuntimeErrors   gs


   GeneratorTypes   _Cs	   ClassTypes   _ms   
UnboundMethodTypes   _xs   InstanceTypes


   MethodTypes   lens   BuiltinFunctionTypes   
appends   BuiltinMethodTypes


   ModuleTypes   files   FileTypes   xranges


   XRangeTypes	   TypeErrors   exc_infos   tbs


   TracebackTypes   tb_frames	   FrameTypes   
AttributeErrors   slices	   SliceTypes   Ellipsiss   
EllipsisTypes   __dict__s


   DictProxyType((   s   IntTypes   tbs   
BuiltinFunctionTypes   BooleanTypes   _Cs   
UnboundMethodTypes


   StringTypes   BuiltinMethodTypes	   FloatTypes   
DictionaryTypes   TypeTypes


   DictProxyTypes   _fs


   GeneratorTypes   InstanceTypes


   ObjectTypes   DictTypes   FileTypes   syss   
EllipsisTypes   Strý%  Lÿh HNh  ListTypes


   MethodTypes	   TupleTypes


   ModuleTypes	   FrameTypes   LongTypes


   BufferTypes


   TracebackTypes   gs   CodeTypes	   
ClassTypes   _xs   UnicodeTypes	   SliceTypes   
ComplexTypes


   LambdaTypes   FunctionTypes


   XRangeTypes   NoneType(    (    s   
C:\PYTHON23\lib\types.pys   ?   sr   
	





			



    s   |  
i i ?  Sd  S(   N(   s   selfs   datas


   itervalues(   s   self(    (    s   C




---------------------------------------------------




But if you try this without writing to the file you get just 
an error (See 2).




- 2:




a) Code:


#!/usr/bin/python


file = open("test.txt", "w")


text = file.read()


print text




b) Output:


Traceback (most recent call last):


  File "tralara.py", line 3, in ?


    text = file.read()


IOError: [Errno 9] Bad file descriptor




------------------------------------------------




It's stupid, I know. Why somenone would want to read a 
file after writing to it ? Don't know, I've discovered this 
by error ;)




Tested in Python 2.3 Beta (Win32).




Happy coding friends.


History
Date User Action Args
2007-08-23 14:10:55adminlinkissue683160 messages
2007-08-23 14:10:55admincreate