获得在Windows操作系统中写入文件的权限

时间:2012-12-20 17:35:45

标签: python windows file

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

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

1 个答案:

答案 0 :(得分:0)

正在运行代码的用户必须具有对手头目录的写入权限。