top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is import and use of it in python?

+2 votes
376 views
What is import and use of it in python?
posted Dec 19, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
 
Best answer

(A module in python can be a file or directory. If it is a directory, it must have a __init__.py file module inside of it, so that the python interpreter recognizes it as a python module.)
Python code in one module gains access to the code in another module by the process of importing it. It is similar to #include in C at least in theory. But the it works is totally different. Just like in java importing a module in python (whether a library module or any other user defined module) makes the code within that module accessible to current module scope. Even if u import the module multiple times it is imported only once.. While importing a module the python path is searched for the module . If it is not present in it, the import statement combines two operations; it searches for the named module, then it binds the results of that search to a name in the local scope. The full path of the module is then is then appended to python path. You can take a look at all directory modules currently accessible by printing the sys.path.

import sys
print sys.path

answer Dec 20, 2014 by Prakash
Similar Questions
0 votes

I want to know how relative imports (in Python) are different than import. I have found lots of examples on internet explaining about the relative import but I want to know about the basic aspects of relative import that make it different than import.

+1 vote

I remember to avoiding to confusing compiler for header, use

// in my include file
#define MYHEADER_H
// and in others code use:
#ifndef MYHEADER_H
#include blahblah

Unfortunately, I prevent to same error, double import to python, but I don't know how to solve, Please help.

0 votes

Im required to import ha certain dll called 'NHunspell.dll' which is used for Spell Checking purposes. I am using Python for the software. Although I checked out several websites to properly use ctypes, I have been unable to load the dll properly.

When I use this code.

 from ctypes import *
 hunspell = cdll.LoadLibrary['Hunspellx64.dll']

I get an error

 hunspell = cdll.LoadLibrary['Hunspellx64.dll']
 TypeError: 'instancemethod' object has no attribute '__getitem__'

I guess it might a problem with the structure of the dll. But I have no idea how to import the dll properly.

...