Tamilnadu Samacheer Kalvi 12th Computer Science Notes Chapter 14 Importing C++ Programs in Python Notes
Scripting language Vs Other programming language:
A scripting language requires an interpreter while a programming language requires a compiler.
Compiler Vs Interpreter:
Compiler | Interpreter |
Scans the entire program and translates it as a whole into machine code. | Translates program one statement at a time. |
It takes large amount of time to analyze the source code | It takes less amount of time to analyze the source code |
The overall execution time is comparatively faster. | The overall execution time is slower. |
Programming language like C, C++ use compilers | Programming language like Python, Ruby use interpreters. |
Python Vs C++
PYTHON | C++ |
Python is typically an “interpreted” language | C++ is typically a “compiled” language |
Python is a dynamic- typed language | C++ is compiled statically typed language |
Data type is not required while declaring variable | Data type is required while declaring variable |
It can act both as scripting and general purpose language | It is a general purpose language |
Applications of Scripting Language :
- To automate certain tasks in a program
- Extracting information from a data set
- Less code intensive as compared to traditional programming language.
- can bring new functions to applications and glue complex systems together
Module:
Modules refer to a file containing Python statements and definitions.
Modular programming:
- Modular programming is a software design technique to split your code into separate parts.
- These parts are called modules. The focus for this separation should have modules with no or just few dependencies upon other modules.
Wrapping:
Importing C++ program in a Python program is called wrapping up of C++ in Python.
Importing C++ Files in Python:
- Importing C++ program in a Python program is called wrapping up of C++ in Python.
- Wrapping or creating Python interfaces for C++ programs are done in many ways.
The commonly used interfaces are
- Python-C-API (API-Application Programming Interface for interfacing with C programs)
- Ctypes (for interfacing with c programs)
- SWIG (Simplified Wrapper Interface Generator- Both C and C++)
- Cython (Cython is both a Python-like language for writing C-extensions)
- Boost. Python (a framework for interfacing Python and C++)
- MinGW (Minimalist GNU for Windows)
g++:
g++ is a program that calls GCC (GNU C Compiler) and automatically links the required C++ library files to the object code.
MinGW Interface:
MinGW refers to a set of runtime header files, used in compiling and linking the code of C, C++ and FORTRAN to be run on Windows Operating System.
Importing modules in Python:
Python’s sys Module:
sys module provides access to some variables used by the interpreter and to functions that interact strongly with the interpreter.
Python’s OS Module:
- The OS module in Python provides a way of using operating system dependent functionality.
- The functions that the OS module allows you to interface with the Windows operating system where Python is running on.
Python getopt module:
- The getopt module of Python helps you to parse (split) command-line options and arguments.
- This module provides two functions to enable command-line argument parsing.
_name_ :
name is one such special variable which by default stores the name of the file