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


Groups > comp.lang.python > #85484

Re: function inclusion problem

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <torriem+gmail@torriefamily.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '"my': 0.09; 'alias': 0.09; 'clean.': 0.09; 'referenced': 0.09; 'bit.': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'imports': 0.16; 'nameerror:': 0.16; 'namespace.': 0.16; 'numpy': 0.16; 'preserving': 0.16; 'separated': 0.16; 'symbols': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'module': 0.19; 'import': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; 'subject:problem': 0.24; 'fine': 0.24; 'this:': 0.26; 'defined': 0.27; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'code': 0.31; 'but': 0.35; 'possible': 0.36; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'helps': 0.61; 'save': 0.62; 'email addr:gmail.com': 0.63; 'name': 0.63; 'charset:windows-1252': 0.65; 'frequently': 0.68; 'idiom': 0.84
X-Virus-Scanned amavisd-new at torriefamily.org
Date Tue, 10 Feb 2015 17:00:14 -0700
From Michael Torrie <torriem@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: function inclusion problem
References <d7871507-2677-4fef-9462-d429217e7ad3@googlegroups.com>
In-Reply-To <d7871507-2677-4fef-9462-d429217e7ad3@googlegroups.com>
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 7bit
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.18632.1423612827.18130.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1423612827 news.xs4all.nl 2930 [2001:888:2000:d::a6]:33600
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:85484

Show key headers only | View raw


On 02/10/2015 04:38 PM, vlyamtsev@gmail.com wrote:
> I defined function Fatalln in "mydef.py" and it works fine if i call it from "mydef.py", but when i try to call it from "test.py" in the same folder:
> import mydef
> ...
> Fatalln "my test"
> i have NameError: name 'Fatalln' is not defined
> I also tried include('mydef.py') with the same result...
> What is the right syntax?

Almost.

Try this:

mydef.Fatalln()

Unless you import the symbols from your mydef module into your program
they have to referenced by the module name.  This is a good thing and it
helps keep your code separated and clean.  It is possible to import
individual symbols from a module like this:

from mydef import Fatalln

Avoid the temptation to import *all* symbols from a module into the
current program's namespace.  Better to type out the extra bit.
Alternatively you can alias imports like this

import somemodule.submodule as foo

Frequently this idiom is used when working with numpy to save a bit of
time, while preserving the separate namespaces.

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


Thread

function inclusion problem vlyamtsev@gmail.com - 2015-02-10 15:38 -0800
  Re: function inclusion problem sohcahtoa82@gmail.com - 2015-02-10 15:55 -0800
  Re: function inclusion problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-11 10:57 +1100
  Re: function inclusion problem Michael Torrie <torriem@gmail.com> - 2015-02-10 17:00 -0700
  Re: function inclusion problem sohcahtoa82@gmail.com - 2015-02-10 16:02 -0800
  Re: function inclusion problem Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-10 17:02 -0700
  Re: function inclusion problem Laura Creighton <lac@openend.se> - 2015-02-11 01:06 +0100
  Re: function inclusion problem Laura Creighton <lac@openend.se> - 2015-02-11 01:16 +0100
  Re: function inclusion problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-02-10 20:52 -0500
  Re: function inclusion problem Victor L <vlyamtsev@gmail.com> - 2015-02-11 08:27 -0500
  Re: function inclusion problem Dave Angel <d@davea.name> - 2015-02-11 10:07 -0500
  Re: function inclusion problem Tim Chase <python.list@tim.thechases.com> - 2015-02-11 09:22 -0600
  Re: function inclusion problem Chris Angelico <rosuav@gmail.com> - 2015-02-12 02:37 +1100
  Re: function inclusion problem blue <catalinfest@gmail.com> - 2015-02-27 12:11 -0800

csiph-web