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
program on damped lcr cicuit

Write an algorithm for the sum of the given series 1,-1/2,1/4,-1/8.....

Write a Python program to accomplish the following. Use modular design. Include at least 3 functions: one that returns zero values, one that returns one value, and one that retu

Bank transfer What  if we  have  two  values,  representing bank  accounts, and  need  to transfer an  amount of money  amt between them?  Consider that a bank account is show

Tuples  and strings Python has two different more list-like data  types  that are very important to understand.A tuple  is a structure that  is like a list, but  is not  mutab

Python has  a built-in list data  structure that  is easy  to use  and  incredibly convenient.  So, for that point, you can say >>> y = [1, 2, 3] >>> y[0] 1 >>> y[2]

Worked example 1   Let's examine what  happens when  we compute the following Python code:   def p(x, y): z = x*x - y return z + 1/z   >>> p(1.0, 2.0) -2.0

For and While   If we want  to do some operation or set of operations various  times, we can handle the process  in several  different types.  The most straightforward types

Booleans   Before we talk about  conditionals, we require  to clarify the Boolean  data  type.  It has two values False and True. Typical statement that have Boolean values

Environments in Python Generally, Python establishes the following binding environments: 1.  builtin     : the mother of all environments: it contains the de?nitions of