如何使用python在macclouddrive中创建文件

2024-10-01 02:34:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试用python代码在我的云驱动器中创建一个文件。当我在这个位置创建文件“/Users/agauravdeep/Library/Mobile Documents/com~apple~CloudDocs/无标题.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/wen dang.txt但当我在路径上加上引号时,它就不起作用了。在

任何建议都会很有帮助。在


Tags: 文件path代码txtcomappleoslibrary
1条回答
网友
1楼 · 发布于 2024-10-01 02:34:50

您正在检查文件是否存在,但您表示要创建它。如果计划创建新文件,请删除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 ")

相关问题 更多 >