[Python-bugs-list] [ python-Bugs-683160 ] Reading while writing-only permissions
SourceForge.net
noreply@sourceforge.net
Sat, 08 Feb 2003 19:20:11 -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: Windows
>Group: 3rd Party
>Status: Closed
>Resolution: Wont Fix
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: Tim Peters (tim_one)
Date: 2003-02-08 22:20
Message:
Logged In: YES
user_id=31435
Figures <wink>. I tried this C program on Win98SE, using
Microsoft's MSVC 6:
#include <stdio.h>
#include <stdlib.h>
void main()
{
char buf[1000];
size_t n;
FILE *f = fopen("temp.txt", "w");
fprintf(f, "%s\n", "Hello, world!");
memset(buf, ' ', sizeof(buf));
n = fread(buf, 1, sizeof(buf), f);
printf("read %d chars, ferror is %d, feof is %d\n",
n, ferror(f), feof(f));
}
It didn't complain. The output was
read 1000 chars, ferror is 0, feof is 0
Since the OS doesn't complain, there's really nothing
Python can do about it short of writing our own file
implementation, and that's a huge project.
When I boosted the buf size in the above to 10000, it said
it read 4082 characters, suggesting it's just reading
whatever bits were left on the disk and sucked into its
internal buffer. File temp.txt was 4097 bytes when the
program ended.
Since Python isn't doing any of this, I'm closing this as
Windows, 3rdParty, and WontFix. BTW, I use Win98SE
too at home, but I don't expect it to act like a real
operating system <wink>.
----------------------------------------------------------------------
Comment By: Pablo de la Rosa (quevedo)
Date: 2003-02-08 20:06
Message:
Logged In: YES
user_id=707875
Windows 98 Second Edition ;)
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2003-02-08 19:47
Message:
Logged In: YES
user_id=31435
Python doesn't implement files, the operating system and
platform C libraries do that. If the same thing happens in a
C program, there's no hope. Which version of Windows
were you running (their file implementations aren't the
same, especially not 95/98/ME vs NT/2000/XP)?
----------------------------------------------------------------------
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