我正在编写一个纯Python库,出于各种原因,我非常希望避免要求用户安装任何二进制扩展。然而,当在OSX上运行时,我还想找到用户库目录(~/Library
),这样我就可以在那里存储一些配置数据,而且我的理解是,出于非常有效、模糊但重要的原因,正确的方法不是在代码中只写~/Library
,而是通过询问OSX的目录在哪里像代码一样
[NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,
NSUserDomainMask,
YES)
objectAtIndex:0];
当然,这段代码是Objective-C,而不是Python,所以我不能直接使用它。如果它是纯C语言,我只需要使用ctypes
从Python调用它,但事实并非如此。有没有任何方法可以从Python进行此调用,而不需要在Objective-C中编写扩展模块,也不需要用户安装一些扩展模块,如PyObjC
?或者,如果我像其他人一样放弃硬代码,那么会发生什么可怕的事情吗?在
好吧,在引擎盖下面是一个普通的C语言,所以你可以用
ctypes
模块获得相同的结果:但是如果你只使用
~/Library
;,宇宙可能不会崩溃相关问题 更多 >
编程相关推荐