Last active
December 16, 2015 20:59
-
-
Save xkyii/5496043 to your computer and use it in GitHub Desktop.
Python + C++相关
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get_pyfiles.cpp : 定义控制台应用程序的入口点。 | |
// | |
#include <Python.h> | |
#include <Windows.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
int main(int argc, char* argv[]) | |
{ | |
// 得到当前可执行文件所在的目录 | |
char szPath[MAX_PATH]; | |
char szCmd[MAX_PATH]; | |
::GetModuleFileNameA(NULL, szPath, sizeof(szPath)); | |
char* p = strrchr(szPath, '\\'); | |
if (p == NULL) | |
{ | |
printf("Get module file name error!\n"); | |
return -1; | |
} | |
*p = 0; | |
// 设定运行时的PATH | |
sprintf_s(szCmd, "PATH=%s\\dlls;%%PATH%%", szPath); | |
_putenv(szCmd); | |
printf(szCmd); | |
Py_NoSiteFlag = 1; | |
Py_Initialize(); | |
PyRun_SimpleString("import main"); | |
getchar(); | |
return 0; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf-8 -*- | |
import sys | |
def main(): | |
print(sys.path) | |
print('hello') | |
if __name__ == '__main__': | |
main() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment