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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:released': 0.07; 'global,': 0.09; 'subject:set': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'def': 0.12; 'itself.': 0.14; '"create': 0.16; 'declaration': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'it."': 0.16; 'nodes': 0.16; 'subject: \n ': 0.16; 'subject:variable': 0.16; 'there!': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'trying': 0.19; 'cc:addr:python.org': 0.22; 'instead.': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'sets': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'everywhere': 0.31; 'subject:other': 0.31; 'subject:that': 0.31; 'though.': 0.31; 'class': 0.32; 'fri,': 0.33; 'subject:the': 0.34; 'received:google.com': 0.35; 'add': 0.35; 'subject:can': 0.39; 'sure': 0.39; "you're": 0.61; 'more': 0.64; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=8mPza9F2uBhZMtm7cqsX9SJ7rtJB0Kf/o9iVEiDxh1k=; b=I9sIJVjCYBoDWYz/Ko2Rf/7xqOXWPCf/r9JQ8appOWWYAXf4T+YKbJgkfUnweDHWzm sWHUax6CL+Syjz9TLLdzJxU8SNhFBs7LA+qdhjVfr7Y3P1KczHjUc0qNof/5tutTiddA MJRqwxu+itnoD49aHgZOFl06eSzqJMRM3ydF97J2wEbYfWMq/44kj45YEwzQHhLuKD+G yH/yXyKwcucbrsPIUeE342oGitBDAAoRmFf5IACs6x2eV7XaiULraKYdozRZWWhWGQdH QUgqAZI+T4lznZTqli21BgA8tj1AJAEKbzz1vyTZsUg66HKDNp31OuKx4dcBM5ABGOcU CG7A==
MIME-Version 1.0
X-Received by 10.51.17.2 with SMTP id ga2mr5984639igd.2.1412264069083; Thu, 02 Oct 2014 08:34:29 -0700 (PDT)
In-Reply-To <3bb9f56c-eff3-472e-8239-58b58cdb16be@googlegroups.com>
References <3bb9f56c-eff3-472e-8239-58b58cdb16be@googlegroups.com>
Date Fri, 3 Oct 2014 01:34:29 +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>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14555.1412264077.18130.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412264077 news.xs4all.nl 2956 [2001:888:2000:d::a6]:34627
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 3836
X-Received-Body-CRC 438381475
Xref csiph.com comp.lang.python:78612

Show key headers only | 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