Refer installation of MinGW in Annexure - . . Executing C++ Program through Python . Double click on the command prompt or the run terminal.
c:\>python Python . . <default. Dec > [Msc v.
bit <Intel>] On win Type "help", "copyright", "credits" or "license" for more information >>> c:\> Figure . . In the figure . the prompt shows the "C:\>”.
See that highlighted area in the above window. To change a directory 'cd' command is used. For example to goto the directory pyprg, type the command 'cd pyprg' in the command prompt. Consider the Example pycpp.py is a Python program which will read the C++program Pali.cpp.
The “Pali.cpp” program accepts a number and display whether it is a “Palindrome or Not”. For example the entered input number is the output displayed will be “Palindrome”. The C++ program Pali is typed in notepad and saved as pali.cpp. Same way the Python program pycpp.py code is also typed in notepad and saved as pycpp.py.
. To execute our program double click the run terminal change the path to the Python folder location. The syntax to execute the Python program is Python <filename.py> -i <C++ filename without cpp extension> 12th Computer Chapter - - Importing C++ Programs in Python Where , Python keyword to execute the Python program from command- line filename.py Name of the Python program to executed - i input mode C++ filename without cpp extension name of C++ file to be compiled and executed For example type Python pycpp.py –i pali in the command prompt and press enter key. If the compilation is successful you will get the desired output.
Otherwise the error will be displayed. In the execution command, the input file doesn’t require its extension. For example, it is enough to mention just the name “pali” instead of “pali.cpp”. Note Now let us will see the execution through our example pycpp.py and pali.cpp.
These two programs are stored in the folder c:\pyprg. If the programs are not located in same folder then the complete path must be specified