Home Why does "RED1.Status (0)" not work in "test.py"?
Reply: 0

Why does "RED1.Status (0)" not work in "test.py"?

user9059041
1#
user9059041 Published in 2017-12-06 00:25:32Z

Why does "RED1.Status (0)" not work in "test.py"?

The output I got is:

name:RED 1  color:RED  status:0 

name:RED 1  color:RED  status:1 

Error message:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 3, in <module>
  NameError: name 'RED1' is not defined

My code:

#include <stdio.h>
#include <iostream>
using namespace std;

#include <string.h>
#include <python2.7/Python.h>

class LED{
  public:
    string name;
    string color;

    int Status(int st){
      if (st == 0) printf("name:%s  color:%s  status:%d \n", name.c_str(), color.c_str(), 0);
      if (st == 1) printf("name:%s  color:%s  status:%d \n", name.c_str(), color.c_str(), 1);
      return (0);
    }                             
};

int main(int argc, char *argv[]){
  LED RED1;
  RED1.name = "RED 1";
  RED1.color = "RED";

  RED1.Status(0);
  RED1.Status(1);

  Py_Initialize();

  PyRun_SimpleString("exec(open('test.py').read())");

  Py_Finalize();    
  return 0;
}

*

//test.py
#!/usr/bin/python
print "Python"
RED1.Status(0)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296737 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO