【发布时间】:2012-12-20 17:35:45
【问题描述】:
我正在尝试在我的计算机 (Windows 7) 中的给定路径上创建一个文件,但该文件没有在给定路径上创建。它是在编译器中虚拟创建的,直到代码被执行,但它不是在 OS 上创建的。
x = str(input("Please enter the file name: "))
x = 'C:\Users\Aakash\Documents\Aakash\Aakash College\Practical\MIT Paython\\'+x
f = open('x','w')
print 'Please choose your option:'
print '1.Write'
print '2.Read'
choice = int(input('Enter the number: '))
while choice==1:
text = input('Please enter the string: ')
f.write(text)
f.write('\n')
print 'Please choose your option:'
print '1.Write'
print '2.Read'
choice = int(input('Enter the number: '))
if choice==2:
f.close()
print
f = open('x','r')
text = f.readline()
print text
while text!='':
text = f.readline()
print text
f.close()
我认为 windows 没有授予创建文件的权限。那么如何获得该权限以便在给定位置创建一个真实文件呢?
当我使用 IDLE 尝试相同的代码时它可以工作,但是当我在新文件中尝试它时(通过创建模块)它不起作用! (即模块正常运行,没有任何错误,但不创建真实文件)
注意:该文件是从管理员用户帐户运行的。他有权访问所有目录。
【问题讨论】:
-
如何创建和运行模块?
-
您正在尝试打开一个名为
x的文件。 -
martineau:它有效...谢谢! :)