-2

我正在尝试在我的计算机(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 的同一段代码时有效,但是当我在新文件中尝试它时(通过创建模块)它不起作用!(即模块正常运行,没有任何错误,但不创建真实文件)

注意:该文件是从管理员用户帐户运行的。他有权访问所有目录。

4

1 回答 1

0

运行代码的用户必须对手头的目录具有写访问权。

于 2012-12-20T17:36:49.253 回答