怎么建立一个python文件_如何创建一个py文件

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.

第三个参数是需要整型的。你是不是少写了什么。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值