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


Groups > comp.lang.python > #95215

Re: Importing is partially working...

Path csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'importerror:': 0.05; 'source.': 0.05; 'cc:addr:python-list': 0.09; 'stored': 0.10; 'python': 0.10; 'file,': 0.15; 'interpreter': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'function?': 0.16; 'need,': 0.16; 'work.)': 0.16; 'wrote:': 0.16; 'module,': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; '(on': 0.22; 'seems': 0.23; "haven't": 0.24; 'import': 0.24; '(most': 0.24; 'implemented': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'message-id:@mail.gmail.com': 0.27; "skip:' 10": 0.28; 'sentence': 0.29; 'there!': 0.29; 'anywhere': 0.30; 'work.': 0.30; 'code': 0.30; 'probably': 0.31; 'traceback': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'so,': 0.35; 'something': 0.35; 'but': 0.36; 'loaded': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'there,': 0.37; 'say': 0.37; 'does': 0.39; 'some': 0.40; 'your': 0.60; 'special': 0.73; 'chrisa': 0.84; 'precompiled': 0.84; 'to:none': 0.91; 'coach': 0.93; 'fun!': 0.95
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=LsX/gUaH6Mc82o6+vhkiksMrIU6y9fdZ3va/9zzkwqk=; b=Safs3vMmxTIGf2pwfNun5IErMgpgNV1m6D2pdMB/17Z/SLmJlBHosHvBH3712e7dOi 14BvQXl6WERQPX4WRJwBuIzVPtpOGj91LprAETSHh2WXLNUAtDSjEI/YPOL/sDyryDS/ XX36MlMHnL0siJq68iOoVYs4pCCRk8JL5qtgppW6nT4jKmI/ZhqUWBv0gy8ow0DXGukH TeO1jlZVY3gsGQpAuipAzbc3/D2RgQK6dPhlBcm+2ruwFE76hh0Ls6q1vvNJFP0VFc6J z33vqzE4Qt+CvHqD7pN1MV4mY5GGdHU5qGLeFufRrWeLWxnpoG5FkQ2y1y5cOyxncM4x 1CNA==
MIME-Version 1.0
X-Received by 10.50.124.97 with SMTP id mh1mr10603900igb.92.1439201475346; Mon, 10 Aug 2015 03:11:15 -0700 (PDT)
In-Reply-To <D1ED09E0.10CC86%Dwight@GoldWinde.com>
References <D1ED09E0.10CC86%Dwight@GoldWinde.com>
Date Mon, 10 Aug 2015 20:11:15 +1000
Subject Re: Importing is partially working...
From Chris Angelico <rosuav@gmail.com>
Cc Python Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.36.1439201482.3627.python-list@python.org> (permalink)
Lines 38
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1439201482 news.xs4all.nl 2898 [2001:888:2000:d::a6]:60757
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95215

Show key headers only | View raw


On Sun, Aug 9, 2015 at 3:45 PM, Dwight GoldWinde <Dwight@goldwinde.com> wrote:
> name = 'Jim'
> coach = 'Dwight'
> import importlib
> sentence = 'Hi, there, ' + name + '. My name is ' + coach + '. I will be
> your coach today.'
> from Functions.py import humprint
> humprint (sentence)
>
> Traceback (most recent call last):
>
>   File "Intro.py", line 5, in <module>
>
>     from Functions.py import humprint
>
> ImportError: No module named 'Functions.py'; 'Functions' is not a package
>
>
>
> So, it seems like it is accessing the module, but not the function?

You're almost there! But in Python, you don't import something from a
specific file - you import from a module, and the Python interpreter
is free to locate that file anywhere that it can. It might be
implemented in C, and be stored in Functions.so (on Unix-like systems)
or Functions.dll (on Windows); it might be precompiled and loaded from
Functions.pyc; it might come from a zip file, or some other form of
special import source. So all you say is:

from Functions import humprint

and Python does the rest. Yep, that's all the change you need, and
your code will most likely work. (I haven't tested it, but it'll
probably work.)

Have fun!

ChrisA

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


Thread

Re: Importing is partially working... Chris Angelico <rosuav@gmail.com> - 2015-08-10 20:11 +1000

csiph-web