Å
å¥å®‰ 王
Hi:
My Python version is 3.1.2.
I am programming embedding c with python in windows.
When I imported urllib.request in my test py file,
PyImport_ImportModule always return NULL.
But I imported re or cmd ,they work fine.
I found urllib is folder, and request seems to be submodule.
I don't know how to import it. I confirmed myutil.py and application
are in same folder.
Could you give me some advice?
Thank you.
myutil.py
import sys
import urllib.request
CRLF = '\r\n'
def addValue(oper1,oper2):
return (oper1 + oper2);
def ConnectURL(url):
try:
req = urllib.request.urlopen(url)
response = req.read()
req.close()
return (req.getcode(),req.geturl())
except BaseException as exp:
sys.stdout.write(exp)
native code:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
PyObject* pPyUtil = NULL;
PyObject* pPypfn = NULL;
PyObject* pPyArgs = NULL;
PyObject* pPyRet = NULL;
int nRet = 0;
int nValue = 0;
Py_Initialize();
PyImport_ImportModule("sys"); // ok
PyImport_ImportModule("csv"); // ok
PyImport_ImportModule("urllib"); // ok
pPyUtil = PyImport_ImportModule("myutil"); // failed ,
if(pPyUtil != NULL)
{
Py_DECREF(pPyUtil);
}
Py_Finalize();
return 0;
}
My Python version is 3.1.2.
I am programming embedding c with python in windows.
When I imported urllib.request in my test py file,
PyImport_ImportModule always return NULL.
But I imported re or cmd ,they work fine.
I found urllib is folder, and request seems to be submodule.
I don't know how to import it. I confirmed myutil.py and application
are in same folder.
Could you give me some advice?
Thank you.
myutil.py
import sys
import urllib.request
CRLF = '\r\n'
def addValue(oper1,oper2):
return (oper1 + oper2);
def ConnectURL(url):
try:
req = urllib.request.urlopen(url)
response = req.read()
req.close()
return (req.getcode(),req.geturl())
except BaseException as exp:
sys.stdout.write(exp)
native code:
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
PyObject* pPyUtil = NULL;
PyObject* pPypfn = NULL;
PyObject* pPyArgs = NULL;
PyObject* pPyRet = NULL;
int nRet = 0;
int nValue = 0;
Py_Initialize();
PyImport_ImportModule("sys"); // ok
PyImport_ImportModule("csv"); // ok
PyImport_ImportModule("urllib"); // ok
pPyUtil = PyImport_ImportModule("myutil"); // failed ,
if(pPyUtil != NULL)
{
Py_DECREF(pPyUtil);
}
Py_Finalize();
return 0;
}