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

Chris Angelico rosuav at gmail.com
Thu Oct 2 11:34:29 EDT 2014


On Fri, Oct 3, 2014 at 1:29 AM, Milson Munakami <milsonmun at 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



More information about the Python-list mailing list