21.12.2022 Views

python_para_desenvolvedores_2ed

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

322 Integração com outras linguagens

PyRun_SimpleString("import os\n"

"for f in os.listdir('.'):\n"

" if os.path.isfile(f):\n"

" print f, ':', os.path.getsize(f)\n");

// Finaliza interpretador Python

Py_Finalize();

return 0;

}

Para compilar, é preciso passar a localização das headers e libraries do Python

para o compilador C:

gcc -I/usr/include/python2.5 \

-L/usr/lib/python2.5/config \

-lpython2.5 -opy_call py_call.c

Observações:

▪ Esta API faz parte do CPython (porte do Python escrito em C).

▪ Existem ferramentas para automatizar o processo para gerar interfaces

para sistemas maiores: SWIG, Boost.Python e SIP.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!