Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10380

PyImport_ImportModule bug in 3.1.2

From bob.wang <wangja@yeahcity.cn>
Subject PyImport_ImportModule bug in 3.1.2
Date 2011-07-27 17:46 +0800
Newsgroups comp.lang.python
Message-ID <mailman.1531.1311760049.1164.python-list@python.org> (permalink)

Show all headers | View raw


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;
}



Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

PyImport_ImportModule bug in 3.1.2 bob.wang <wangja@yeahcity.cn> - 2011-07-27 17:46 +0800

csiph-web