Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53704
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.023 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'definitions': 0.07; 'sys': 0.07; "'a'": 0.09; 'def': 0.12; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'special.': 0.16; 'throw': 0.16; 'wrote:': 0.18; 'module': 0.19; 'thu,': 0.19; 'work,': 0.20; 'import': 0.22; 'saying': 0.22; 'print': 0.22; 'error': 0.23; "aren't": 0.24; 'lets': 0.24; 'second': 0.26; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'once,': 0.31; 'sep': 0.31; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'method': 0.36; 'e.g.': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'name': 0.63; 'such': 0.63; 'more': 0.64; 'wish': 0.70; 'want:': 0.84; 'can!': 0.91; '2013': 0.98 |
| 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:to :content-type; bh=cl4l0Tk4iPQQReJ205JC5/M36bG5W9Q2q1nDg8Y8lso=; b=uhCwaYRvrW3pcpOOZ2mQR2TIaIUEpyHqxoVp4fTefIHk2dKJSlflELm6zd/nu0apJr WyuCcH01jXwIj/iysKuQF2pN5Aa2s4xDkNxaNYLeHRbUqE/RrgWZQ7baJNBpqDI/9Fzr M1Rh+ypD1z5szeLwpuOIy/9rS7unr5s/r44OdauNr865+c78RQUIyGcYNgQn9bGPRIxV w+Q8+HWjT1YSszYHh4NU1THeGj7lF9ZKJt02ztVUSy4gZCzV6nXQCpI9tNfOsW14kUeb kImrWpb25yEnrII9Upjg1OsOSQSwnTztKODXP7d49sX3dK9uz8DpeyGQMs+7/MyAyILY 4iPg== |
| MIME-Version | 1.0 |
| X-Received | by 10.52.165.237 with SMTP id zb13mr2529939vdb.28.1378385435739; Thu, 05 Sep 2013 05:50:35 -0700 (PDT) |
| In-Reply-To | <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> |
| References | <28b859f6-f14b-49d2-9e14-5d3febd33441@googlegroups.com> |
| Date | Thu, 5 Sep 2013 22:50:35 +1000 |
| Subject | Re: Importing Definitions |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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.91.1378385806.5461.python-list@python.org> (permalink) |
| Lines | 31 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1378385806 news.xs4all.nl 16004 [2001:888:2000:d::a6]:39842 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:53704 |
Show key headers only | View raw
On Thu, Sep 5, 2013 at 10:39 PM, Azureaus <lo0446@my.bristol.ac.uk> wrote: > Lets say I have some definitions in a module1.py e.g. > > import sys > A,B,C,D,E = range(5) > def method1(): > more code > end > > Then a second module module2.py where I wish to use these definitions > import module1.py > print A > > This will throw an error saying "global name 'A' is not defined." > > Now I know if there was a method I wanted to reference I could do something like this in module2. > from module1 import method1 > > which would mean from that point on I could just reference it as method1 rather than module1.method1, is there such a way I could do this with definitions?? You can! Any name will work, functions aren't special. from module1 import method1, A, B, C, D, E If you want all of them at once, you may want: from module1 import * but this can make your code confusing. ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Importing Definitions Azureaus <lo0446@my.bristol.ac.uk> - 2013-09-05 05:39 -0700
Re: Importing Definitions Chris Angelico <rosuav@gmail.com> - 2013-09-05 22:50 +1000
Re: Importing Definitions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-09-05 17:28 +0000
Re: Importing Definitions Skip Montanaro <skip@pobox.com> - 2013-09-05 13:06 -0500
Re: Importing Definitions Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-09-06 11:05 +0100
Re: Importing Definitions Peter Otten <__peter__@web.de> - 2013-09-05 15:00 +0200
Re: Importing Definitions Ethan Furman <ethan@stoneleaf.us> - 2013-09-05 05:56 -0700
Re: Importing Definitions Azureaus <lo0446@my.bristol.ac.uk> - 2013-09-06 02:10 -0700
csiph-web