如何使用 python 在 Mac 云驱动器中创建文件
how to create a file in Mac cloud drive using python
我正在尝试使用 python 代码在我的云驱动器中创建一个文件。当我在这个位置创建文件时/Users/agauravdeep/Library/Mobile Documents/com~apple~CloudDocs/Untitled.rtf
“使用任何应用程序,它都可以工作,但通过代码,即使在通过超级用户尝试后,我到目前为止也不成功(虽然没有错误)。
代码非常简单
# -*- coding: utf-8 -*-
#!/usr/bin/python
from os.path import expanduser
def createBugsFileInitiallyIfNotPresent():
global bugsFileLocation
bugsFileLocation = expanduser("~")+"/Library/Mobile Documents/com~apple~CloudDocs/abc.txt"
if(os.path.isfile(bugsFileLocation)):
f = open(bugsFileLocation, 'w+')
f.write(" dddd ")
这有效
另外,vi ~/Library/Mobile\ Documents/com~apple~CloudDocs/abcd.txt 但是当我在路径周围加上引号时它不起作用。
任何建议都会很有帮助。
您正在检查文件是否存在,但您说要创建它。如果您打算创建一个新文件,请删除 if 语句:
from os.path import expanduser
def createBugsFileInitiallyIfNotPresent():
global bugsFileLocation
bugsFileLocation = expanduser("~")+"/Library/Mobile Documents/com~apple~CloudDocs/abc.txt"
f = open(bugsFileLocation, 'w+')
f.write(" dddd ")
我正在尝试使用 python 代码在我的云驱动器中创建一个文件。当我在这个位置创建文件时/Users/agauravdeep/Library/Mobile Documents/com~apple~CloudDocs/Untitled.rtf “使用任何应用程序,它都可以工作,但通过代码,即使在通过超级用户尝试后,我到目前为止也不成功(虽然没有错误)。
代码非常简单
# -*- coding: utf-8 -*-
#!/usr/bin/python
from os.path import expanduser
def createBugsFileInitiallyIfNotPresent():
global bugsFileLocation
bugsFileLocation = expanduser("~")+"/Library/Mobile Documents/com~apple~CloudDocs/abc.txt"
if(os.path.isfile(bugsFileLocation)):
f = open(bugsFileLocation, 'w+')
f.write(" dddd ")
这有效 另外,vi ~/Library/Mobile\ Documents/com~apple~CloudDocs/abcd.txt 但是当我在路径周围加上引号时它不起作用。
任何建议都会很有帮助。
您正在检查文件是否存在,但您说要创建它。如果您打算创建一个新文件,请删除 if 语句:
from os.path import expanduser
def createBugsFileInitiallyIfNotPresent():
global bugsFileLocation
bugsFileLocation = expanduser("~")+"/Library/Mobile Documents/com~apple~CloudDocs/abc.txt"
f = open(bugsFileLocation, 'w+')
f.write(" dddd ")