Click here to Skip to main content
13,410,621 members (36,039 online)
Rate this:
Please Sign up or sign in to vote.
So, I have two projects: a library and a console app. In the library, I have the following function declaration:

std::string NewApp::Testing()
	char* test[] = {"test", 0};
	PyObject* obj = Python::Py_Arg("test", "test", test);
	std::string s = PyString_AsString(obj);
	return s;

Then, in the app, I call the function:

int _tmain(int argc, _TCHAR* argv[])
	std::cout << NewApp::Testing();
	return 0;

Which all makes a call to the following Python script (which is in the same release directory as the static library):

def test(wrd):
    return wrd

Yet, for whatever reason, I get the following error every time I run the program:

AttributeError: `module` object has no attribute `test`
Cannot find function "test"

And it's driving me crazy! It knows where the file is but it can't find the function. What could be causing it?? I've gotten embedded Python to work before in another app, yet I still can't get this one to work! Any help is appreciated. Thanks.
Posted 11-Jun-13 14:54pm
Ron Beyer 11-Jun-13 20:34pm
I can't find anything on Py_Arg, are you using this api?

Are you sure you got the function arguments right? Where are you telling the argument that it should be expecting a string?
RadXPictures 11-Jun-13 22:22pm
I followed this tutorial: My code is identical, except I replaced the args[] with actual string variable names.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I can see something here:

std::string NewApp::Testing()
    char* test[] = {"test", 0};//Here you have a char* array called 'test' set to the string of characters "test", ending with the null character '0'///
    PyObject* obj = Python::Py_Arg("test", "test", test);// Here you have 3 tests in your Py_Arg, one of which is the char* array.///
    std::string s = PyString_AsString(obj); // string s now = "test", "test", "test".
    return s;

And here you 'define' "test" again:

def test(wrd):
    return wrd
Do you know what type 'wrd' is? While I'm not Python literate, this line of code is not working as you think. Are you defining a function, a variable, a list, ???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180221.1 | Last Updated 20 Jun 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100