Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'broken': 0.04; 'third- party': 0.04; 'importing': 0.05; 'suddenly': 0.07; 'filenames': 0.09; 'function,': 0.09; 'latter': 0.09; 'namespace': 0.09; 'override': 0.09; 'recommends': 0.09; 'rewrite': 0.09; 'subset': 0.09; 'works.': 0.09; 'python': 0.11; '"but': 0.16; 'dirnames,': 0.16; 'dirpath,': 0.16; 'intended.': 0.16; 'os.walk': 0.16; 'script?': 0.16; 'similarly,': 0.16; 'symbols': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'library': 0.18; 'pointed': 0.19; 'written': 0.21; 'code,': 0.22; 'example': 0.22; 'import': 0.22; '(in': 0.22; 'header:User-Agent:1': 0.23; 'adds': 0.24; 'documented': 0.24; 'library,': 0.24; 'module,': 0.24; 'subject:problem': 0.24; 'equivalent': 0.26; 'nearly': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'code': 0.31; 'ones.': 0.31; 'releases,': 0.31; 'text': 0.33; 'third': 0.33; 'updated': 0.34; 'could': 0.34; 'but': 0.35; 'there': 0.35; 'doubt': 0.36; 'library.': 0.36; 'maintained': 0.36; "didn't": 0.36; 'thanks': 0.36; 'should': 0.36; 'example,': 0.37; 'sometimes': 0.38; 'thank': 0.38; 'form,': 0.38; 'whatever': 0.38; 'to:addr:python- list': 0.38; 'bad': 0.39; 'to:addr:python.org': 0.39; 'release': 0.40; 'manually': 0.60; 'new': 0.61; "you're": 0.61; 'you.': 0.62; 'email addr:gmail.com': 0.63; 'happen': 0.63; 'more': 0.64; 'charset:windows-1252': 0.65; 'determine': 0.67; 'received:74.208': 0.68; 'email,': 0.69; 'to,': 0.72; 'carefully': 0.74; 'other.': 0.75; 'complaint': 0.84; 'expose': 0.84; 'victor': 0.84; 'careful': 0.91; 'do:': 0.91 Date: Wed, 11 Feb 2015 10:07:06 -0500 From: Dave Angel 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: <201502110006.t1B060VZ021974@fido.openend.se> <201502110016.t1B0GVah024279@fido.openend.se> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:63fpq7CzJ48eiPAPXTC2Iayd2uFX+1w8KEKqa1FjFUU JAh1twnukevAZiboAplQfjLLxtgNZPy+ecUjxLHhOxM6p1cM4v vYNOO5dt9B1WsuKPweLDkfw6z880DJ2AeXzGgoOX0H/7K23vAr ENwZ9xhGXf8e9SJZWS0jgWoYlMtwaMHWVhIz8qiBlFkRNHXKaV X4YLfWAUvWbT2nfQVnpDi4qsfNd0wufNt1Bg0lTCTIH/lP0BnR mMymTK+ZRat+8XQUBdmK0rABFHyPbEXACOgRMSmcfsSkD84M0Q cAl2dRYFpmS4ibP1XDi79gx0mNcb07qQEgOka/ZJoWcMz2vqyq 5wvnMePvsh8ESN9ppEP8= X-UI-Out-Filterresults: notjunk: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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423667239 news.xs4all.nl 2934 [2001:888:2000:d::a6]:48084 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85532 On 02/11/2015 08:27 AM, Victor L wrote: > Laura, thanks for the answer - it works. Is there some equivalent of > "include" to expose every function in that script? > Thanks again, > -V > Please don't top-post, and please use text email, not html. Thank you. yes, as sohcahtoa82@gmail.com pointed out, you can do from mydef import * But this is nearly always bad practice. If there are only a few functions you need access to, you should do from mydef import Fatalln, func2, func42 and if there are tons of them, you do NOT want to pollute your local namespace with them, and should do: import mydef x = mydef.func2() # or whatever The assumption is that when the code is in an importable module, it'll be maintained somewhat independently of the calling script/module. For example, if you're using a third party library, it could be updated without your having to rewrite your own calling code. So what happens if the 3rd party adds a new function, and you happen to have one by the same name. If you used the import* semantics, you could suddenly have broken code, with the complaint "But I didn't change a thing." Similarly, if you import from more than one module, and use the import* form, they could conflict with each other. And the order of importing will (usually) determine which names override which ones. The time that it's reasonable to use import* is when the third-party library already recommends it. They should only do so if they have written their library to only expose a careful subset of the names declared, and documented all of them. And when they make new releases, they're careful to hide any new symbols unless carefully documented in the release notes, so you can manually check for interference. Incidentally, this is also true of the standard library. There are symbols that are importable from multiple places, and sometimes they have the same meanings, sometimes they don't. An example (in Python 2.7) of the latter is os.walk and os.path.walk When I want to use one of those functions, I spell it out: for dirpath, dirnames, filenames in os.walk(topname): That way, there's no doubt in the reader's mind which one I intended. -- DaveA