1. Where is math.py (socket.py, regex.py, etc.) source file?
Answer: If you can’t find a source file for a module, it may be a built-in or dynamically loaded module implemented in C, C++ or other compiled language. In such case you will not have the source file or it may be something like mathmodule.c, somewhere in a C source directory (not on the Python Path).
There are three kinds of modules in Python:
1 .Modules is written in Python (.py);
2. Modules are written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc);
3. Modules are written in C and linked with the interpreter; to get a list of these, type;
4. Import sys print sys.builtin_module_names;
2. How do I find undefined g++ symbols __builtin_new or __pure_virtual?
Answer: To dynamically load g++ extension modules, you must follow the below.:
2. Re-link it using g++ (change LINKCC in the python Modules Makefile)
3. Link your extension module using g++ (e.g., “g++ -shared -o mymodule.so mymodule.o”).
3. Explain Control flow statements?
Answer: By default, python program execution starts from the first line, execute each and every statement only once and transactions the program if the last statement of the program execution is over.
Control flow statements are used to disturb the normal flow of the execution of the program.
4. What is File Handling?
Answer: File handling helps in following:
1. File is a named location on the disk, which stores the data in permanent manner.
2.Python language provides various functions and methods to provide the communication between python programs and files.
3.Python programs can open the file, perform the read or write operations on the file and close the file
4. We can open the files by calling open function of built-in-modules
5. At the time of opening the file, we have to specify the mode of the file
6. Mode of the file indicates for what purpose the file is going to be opened(r,w,a,b)
5. What is Abnormal Termination?
Answer: The concept of terminating the program in the middle of its execution without executing the last statement of the main module is known as an abnormal termination
Abnormal termination is an undesirable situation in programming languages.
6. Explain OS Module?
Answer: OS Module is a predefined module and which provides various functions and methods to perform the operating system related activities, such as creating the files, removing the files, creating the directories removing the directories, executing the operating system related commands, etc.
7. What is Hierarchical Inheritance?
Answer: The concept of inheriting the properties from one class into multiple classes separately is known as hierarchical inheritance.
8. What is Try Block?
Answer: A block which is preceded by the try keyword is known as a try block
//statements that may cause an exception
The statements which cause to runtime errors and other statements which depends on the execution of runtime errors statements are recommended to represent in a try block
While executing try block statement if any exception is raised then immediately try block identifies that exception, receive that exception and forward that exception to except block without executing remaining statements to try block.
9. Explain Modules Search Path?
Answer: By default python interpreter search for the imported modules in the following locations:
– Current directory (main module location)
– Environment variable path
– Installation-dependent directory
– If the imported module is not found in any one of the above locations. Then python interpreter gives error.
10. Why don’t my signal handlers work ?
Answer: The most common problem is that the signal handler is declared with the wrong argument list. It is called as:
handler (signum, frame)
So it should be declared with two arguments:
def handler(signum, frame):
11. How to execute a loop ten times ?
Answer: Lets see the solution..
while i < 10:
12. What is the structure of a for loop ?
Answer: for in : … The ellipsis represents a code block to be executed, once for each item in the sequence. Within the block, the item is available as the current item from the entire list.
13. What is the structure of a while loop?
Answer: while : … The ellipsis represents a code block to be executed. until the condition becomes false. The condition is an expression that is considered true unless it evaluates to o, null or false.
14. Differentiate between append() and extend() methods.?
Answer: append() and extend() methods are the methods of list. These methods a re used to add the elements at the end of the list.
1. append(element) method– adds the given element at the end of the list which has called this method.
2. extend(another-list) method– adds the elements of another-list at the end of the list which is called the extend method.