Environments in python, Python Programming

Environments in Python

Generally, Python establishes the following binding environments:

1.  builtin    : the mother of all environments: it contains the de?nitions of all sorts of basic function, like sum and list. It is the parent of all module environments.

2.  Module: each  separate ?le that  contains Python code  is called  a module and  establishes its own environment, whose  parent is      builtin

3.  Procedure calls: A Function that is described at the 'top level' of a module (that is, not nested in the de?nition of another procedure) has the module's  environment  as its parent, and  has its name  described in the module's environment.  Methods that are described under  other  procedures have  the  procedure-call environment of the  containing procedure as their parent.

We have seen two operations that cause bindings to be created:  assignments and procedure calls. Bindings  are also created when  you compute an import statement. If you compute import math then  a ?le associated with  the  math module is computed and  the  name  math is related, in the current environment, to the math  module, which  is an environment. No other values  are included to the current environment, and if you need  to show to names  in that part, you have to examine them, as in math.sqrt. If you run from math import sqrt then  the  math ?le is computed, and  the  name  sqrt is related, in the  current environment, to whatever the name  sqrt is bound in the math function. But note  that  if you  do this,  the name math is not related to anything, and  you cannot take any other  procedures in the math module unless  you import them  outside,  as well

 

Posted Date: 8/11/2012 2:44:35 AM | Location : United States







Related Discussions:- Environments in python, Assignment Help, Ask Question on Environments in python, Get Answer, Expert's Help, Environments in python Discussions

Write discussion on Environments in python
Your posts are moderated
Related Questions
draw the variation of pressure with volume of a real gas at temperatures lower than its critical temperature.also draw its surface of discontinuity

Rewrite the area.py program (shown below, or in the Creating Functions section of the tutorial) so that it has separate functions for the perimeter and area of a square, a rectangl

Programming models Just  as there  are several methods for organizing entire  software systems, there  are  different strategies for formally expressing computational processe

1 Low Level Exploits 1.1 Savegames Jimmy is becoming increasingly frustrated at the computer game hes playing. He has a save right before the levels boss but he needs either more

Models It is a new system that is considerably easier than  the system being modelled, but which saves the important points of the original machine. We might create a physical

What are squared matrices?

Print vs Return Here are two different method declarations: def f1(x): print x + 1 def f2(x): return x + 1 What happens when  we call them? >>> f1(3) 4 >>

Suppose the cover price of a book is $24.95, but bookstores get a 40% discount. Shipping costs $3 for the first copy and 75 cents for each additional copy. What is the tota

Write a program that requests a password after the author/program information is displayed. Make the password "hello". The program should then ask the user for their name: if the n

what are the issues assciated with top-down analysis