【问题标题】:Getting Permission to Write file in Windows OS在 Windows 操作系统中获得写入文件的权限
【发布时间】: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:它有效...谢谢! :)

标签: python windows file


【解决方案1】:

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

【讨论】:

  • 代码是从管理员帐户运行的,他可以访问所有目录。 (尤其是上面给定的目录)但它仍然没有被创建。
猜你喜欢
  • 1970-01-01
  • 2019-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-08
  • 2012-02-06
  • 2011-10-13
  • 2012-07-12
相关资源
最近更新 更多