Search This Blog

Subscribe to this blog

Follow by Email

Python : Importing modules

In python 3, I was not able to figure out what is the
difference between the commands, 'import math' and 'from math import *'. Here is
what I discovered about that.

When you import a module by the command import, eg: - 'import
math', then what happens is , though it imports the module we must specify the
module name first to access the functions inside it. Eg: - math.sqrt()

If we do 'from math import *', what happens is all the
functions in the math module gets loaded in the main workspace. That is when you use the '*'. We can specifically type the name of the functions just required. The functions
can be accessed by just their name. Eg: - sqrt() without the name of the
module.

There are pros and cons for these methods. In the second method,
if the variables or functions defined in the main, matches with the name of the
function inside the importing module, it may cause unexpected behaviour. At
some cases this is called contaminating the namespace. That is one cons. Because
you must be clear that you want to perform the method square root (sqrt) inside
the module 'math'.

Comments

Post a Comment

Popular Posts

This is a short, application of equations of motion. The problem statement and the approach to solution is discussed. A police inspector in a jeep is chasing a pickpocket in a straight line. The jeep has a maximum uniform speed v. the pickpocket rides on a motor cycle of a waiting friend when the jeep is at a distance d away, and motor cycle starts with constant acceleration a. What should be the speed of police to caught pickpocket?

Imagine that the pickpocket is caught at a time t after motor cycle starts. The distance travelled by the motor cycle during this interval is

Step1: Selection of material The structural designers should know well about the characteristics of the materials available in market. In the market so many materials are available. From those, first you have to select correct one. It means, the selected material should have the following properties, •Good material properties such as toughness, yield properties…etc. •Cost •Availability •Easiness for handling •Weight to strength ratio. •Good assembling property such as weldability…etc. For the purpose, the materials can be divided as ductile, plastic and rigid material. Ductile material means, it will regains its original shape after removal load. But the deformation will be permanent for plastic material. And rigid material will not deform for the applied load. But actually, these materials are not exists. Which means, in real, no material is absolutely elastic, plastic and rigid. But we will assign the names if the deformations, and behaviour are within certain limits. Structural members are…