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


Groups > comp.lang.python > #78612

Re: How to set the global variable so that it can be accessed and released inside other methods

References <3bb9f56c-eff3-472e-8239-58b58cdb16be@googlegroups.com>
Date 2014-10-03 01:34 +1000
Subject Re: How to set the global variable so that it can be accessed and released inside other methods
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.14555.1412264077.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Oct 3, 2014 at 1:29 AM, Milson Munakami <milsonmun@gmail.com> wrote:
>         #I am trying to set net variable to global
>         global net
>
>         def CreateNet(self):
>                 "Create an empty network and add nodes to it."
>                 net = Mininet( controller=RemoteController )

You're almost there! All you have to do is move that global
declaration into CreateNet itself. That's the only place where it's
assigned to.

I'm not sure why you have a class that sets up a global, though. It
would be much more normal to use "self.net" everywhere instead.

ChrisA

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


Thread

How to set the global variable so that it can be accessed and released inside other methods Milson Munakami <milsonmun@gmail.com> - 2014-10-02 08:29 -0700
  Re: How to set the global variable so that it can be accessed and released inside other methods Chris Angelico <rosuav@gmail.com> - 2014-10-03 01:34 +1000
  Re: How to set the global variable so that it can be accessed and released inside other methods Milson Munakami <milsonmun@gmail.com> - 2014-10-03 14:43 -0700
    Re: How to set the global variable so that it can be accessed and released inside other methods Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-03 22:55 +0100

csiph-web