[Python-bugs-list] [ python-Bugs-683160 ] Reading while writing-only permissions
SourceForge.net
noreply@sourceforge.net
Sat, 08 Feb 2003 16:31:28 -0800
Bugs item #683160, was opened at 2003-02-08 18:50
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=683160&group_id=5470
Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Pablo de la Rosa (quevedo)
>Assigned to: Tim Peters (tim_one)
Summary: Reading while writing-only permissions
Initial Comment:
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.
----------------------------------------------------------------------
>Comment By: Neal Norwitz (nnorwitz)
Date: 2003-02-08 19:31
Message:
Logged In: YES
user_id=33168
I cannot reproduce on Linux, I'm guessing this is a windows bug.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=683160&group_id=5470