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
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]

Write an algorithm for a program that shows the use of all 6 math functions. Write, test, and debug the program using Python. SAMPLE OUTPUT (not including author/program infor

Basics of python-introduction Python is designed for easy interaction between a user and the system. It goes with  an inter­ active function  known as  a shell or listener.  T

Normalize a vector Let's imagine we want  to normalize a vector  of three  variables;  that  is to compute a new  vector  of three values,  such that its size  is 1. Here is o

Imagine a "particle" located on the centre square of a two-dimensional grid of dimensions 11 by 75. The particle can only move one square at a time, either up, down, left, or right

Task This problem creates a list containing names. The list of names will be printed, sorted, printed again in the new sorted order, written to a new output file, and searched. Ca

Procedures as First-class objects In Python, unlike  many  other  languages, methods are behave in much  the same way as num­ bers:  they  can be stored as values  of variable


Assume you have a truck which has to travel across a desert from the base camp at position 0 (left) to the target camp at position 4 (right). The intermediate positions 1,2, and 3

Non-local references in procedures There  is an important subtlety in the  way  names  are handled in the  environment created by a function call. When  a value  that  is not