Need help with Py_BuildValue()
#1
Py_BuildValue can return a tuple (array) when the format string is eg "(ss)" and a known number of values, the problem i am having is i do not know the total number of values that will be returned.

so i loop thru and create the format string and also fill a CStdStringArray.

this works, although there may be a simpler way.

what doesn't work is the return.
PHP Code:
return Py_BuildValue((char*)fmtstring.c_str(), values); 

so:
question 1: how would i build the return statement.
question 2. can this be done with less code by just using self->pAddon->GetDeps()

any help would be appreciated.

here is the part of the function:

PHP Code:
else if (strcmpi(id"dependencies") == 0)
    {
      
PyXBMCGUILock();
      
CStdString fmtstring;
      
CStdStringArray values;
      for (
ADDON::ADDONDEPS::iterator itr self->pAddon->GetDeps().begin(); itr != self->pAddon->GetDeps().end(); ++itr)
      {
        
fmtstring.append("(sss)");
        
CStdString id = (*itr).first;
        
values.push_back(id);
        
CLog::Log(LOGNOTICE"DEPEND: %s",id.c_str());
        
        
CStdString min = (*itr).second.first.str;
        
values.push_back(min);
        
CLog::Log(LOGNOTICE"MIN: %s"min.c_str());
        
        
CStdString max = (*itr).second.second.str;
        
values.push_back(max);
        
CLog::Log(LOGNOTICE"MAX: %s"max.c_str());
      }
      
      
fmtstring.Format("(%s)"fmtstring.c_str());
      
PyXBMCGUIUnlock();
      
CLog::Log(LOGNOTICE"FORMAT STRING: %s"fmtstring.c_str());
      for (
CStdStringArray::iterator itr values.begin(); itr != values.end(); ++itr)
      {
        
CStdString value = *itr;
        
CLog::Log(LOGNOTICE"VALUE: %s"value.c_str());
      }
      return 
Py_BuildValue((char*)fmtstring.c_str(), values);
    } 

this is for a module for python and the new addons. the function is getAddonInfo(), where it returns all the usable values of an addon. eg name, version, id, "dependencies"...
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#2
i can't use py Py_BuildValue

http://effbot.org/pyfaq/how-do-i-use-py-...length.htm
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#3
Any luck with that bit that you link to? It looks like exactly what you need?
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#4
Yes, it was exactly what i needed.

works good, just had to add a couple thing to the dll export.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply

Logout Mark Read Team Forum Stats Members Help
Need help with Py_BuildValue()0