Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4560

Re: Why do directly imported variables behave differently than those attached to imported module?

From harrismh777 <harrismh777@charter.net>
Newsgroups comp.lang.python
Subject Re: Why do directly imported variables behave differently than those attached to imported module?
References <d8d1d20e-2edd-49e5-917c-f338ef35006f@l18g2000yql.googlegroups.com>
Message-ID <vTWvp.23964$vC5.14171@newsfe01.iad> (permalink)
Date 2011-05-03 12:24 -0500

Show all headers | View raw


Dun Peal wrote:
>      # module foo.py
>      var = 0
>
>      def set():
>          global var
>          var = 1

My two cents to add in addition to the correct accounts of [ Daniel, 
Chris, Mel] is that you might have a misunderstanding of var, generally.

Python has no variables--- in the way you think of them in other 
languages. Python only has references.

Var is not 'set' in the classical sense of the word...

var is a 'reference' (think C pointer, sort-of) to an object...   '0' 
and '1' are objects of type int and

var=0   means create a reference to object  int('0') called var.

a=b=0   a is a reference to object '0'
         b is a reference to object '0'

         a does not reference b

This rest of the discussion has to do with name spaces:

See:

http://docs.python.org/release/3.0.1/reference/datamodel.html?highlight=namespaces



Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Why do directly imported variables behave differently than those attached to imported module? Dun Peal <dunpealer@gmail.com> - 2011-05-03 09:31 -0700
  Re: Why do directly imported variables behave differently than those attached to imported module? Chris Rebert <clp2@rebertia.com> - 2011-05-03 09:57 -0700
  Re: Why do directly imported variables behave differently than those attached to imported module? Daniel Kluev <dan.kluev@gmail.com> - 2011-05-04 03:57 +1100
  Re: Why do directly imported variables behave differently than those attached to imported module? Mel <mwilson@the-wire.com> - 2011-05-03 13:00 -0400
  Re: Why do directly imported variables behave differently than those attached to imported module? Terry Reedy <tjreedy@udel.edu> - 2011-05-03 13:13 -0400
  Re: Why do directly imported variables behave differently than those attached to imported module? harrismh777 <harrismh777@charter.net> - 2011-05-03 12:24 -0500
    Re: Why do directly imported variables behave differently than those attached to imported module? Dun Peal <dunpealer@gmail.com> - 2011-05-03 11:51 -0700
      Re: Why do directly imported variables behave differently than those attached to imported module? Dun Peal <dunpealer@gmail.com> - 2011-05-03 12:23 -0700
        Re: Why do directly imported variables behave differently than those attached to imported module? Daniel Kluev <dan.kluev@gmail.com> - 2011-05-04 06:55 +1100
  Re: Why do directly imported variables behave differently than those attached to imported module? Chris Angelico <rosuav@gmail.com> - 2011-05-04 07:47 +1000
    Re: Why do directly imported variables behave differently than those attached to imported module? Duncan Booth <duncan.booth@invalid.invalid> - 2011-05-04 08:44 +0000
  Re: Why do directly imported variables behave differently than those attached to imported module? Chris Rebert <clp2@rebertia.com> - 2011-05-03 15:11 -0700

csiph-web