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: 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 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: In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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.