2019-08-16 回答
你的open函数不对啊。感觉象是你不小心重载了open函数。导致open不再是打开文件用的那个open. 感觉你象是用了一个python的扩展库,它的open函数用的很象是c语言的open. 而不是python标准的。
>>> f=open("d:/1.txt",'w')
>>> f.write('ddd')
>>> f.close()
>>>我试过了没有什么问题。
你需要把原代码完整的打出来
顺便说一下。不要使用中文目录。要全英文目录,目录中也不准有空格。如果你老师就这么教你的,说明他没有用过老版本的python。也很少用其它英文软件。
你再运行help(open)试试看
>>> help(open)
help on built-in function open in module __builtin__:
open(...)
open(name[, mode[, buffering]]) -> file object
open a file using the file() type, returns a file object. this is the
preferred way to open a file. see file.__doc__ for further information.
>>>
>>> print file.__doc__
file(name[, mode[, buffering]]) -> file object
open a file. the mode can be 'r', 'w' or 'a' for reading (default),
writing or appending. the file will be created if it doesn't exist
when opened for writing or appending; it will be truncated when
opened for writing. add a 'b' to the mode for binary files.
add a '+' to the mode to allow simultaneous reading and writing.
if the buffering argument is given, 0 means unbuffered, 1 means line
buffered, and larger numbers specify the buffer size. the preferred way
to open a file is with the builtin open() function.
add a 'u' to mode to open the file for input with universal newline
support. any line ending in the input file will be seen as a '\n'
in python. also, a file so opened gains the attribute 'newlines';
the value for this attribute is one of none (no newline read yet),
'\r', '\n', '\r\n' or a tuple containing all the newline types seen.
'u' cannot be combined with 'w' or '+' mode.
第三个参数是需要整型的。你是不是少写了什么。