Tag: python 3.x

你如何使用python3 c api为命令行驱动的应用程序?

我已经使用自定义构建作为virtualenv的替代品已经有一段时间了,而且它很棒。 它需要更长的时间才能构建,但实际上它可以工作,并且它永远不会搞砸。 部分内容在一个简单的python包装器中,它将一些特定的文件夹添加到库路径中,我发现它非常有用。 它的代码是微不足道的: #include #include #include int main(int argc, char *argv[]) { /* Setup */ Py_SetProgramName(argv[0]); Py_Initialize(); PySys_SetArgv(argc, argv); /* Add local path */ PyObject *sys = PyImport_ImportModule(“sys”); PyObject *path = PyObject_GetAttrString(sys, “path”); /* Custom path */ char *cwd = nrealpath(argv[0]); char *libdir = nstrpath(cwd, “python_lib”, NULL); PyList_Append(path, PyString_FromString(libdir)); free(cwd); free(libdir); /* Run the […]

为什么这个ctypes代码不能与Python 3.3一起使用,但是可以与Python 2.7一起使用?

所以我正在尝试使用ctypes模块创建一个Python 3.3程序来更改Windows桌面背景。 我在Python 2.7中测试了以下代码,它运行得很好。 但它只适用于Python 3.3! 我正在使用Windows 7.这是代码: import ctypes SPI_SETDESKTOPWALLPAPER=20 ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKTOPWALLPAPER, 0,”C:/Users/Public/Pictures/Sample Pictures/Penguins.jpg”, 3)