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


Groups > comp.lang.python > #95886

Re: error

Path csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <lac@openend.se>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'filenames': 0.07; 'line:': 0.07; 'nicely': 0.07; 'cc:addr:python-list': 0.09; 'instance.': 0.09; 'received:openend.se': 0.09; 'received:theraft.openend.se': 0.09; 'python': 0.10; 'subject:error': 0.11; 'cc:addr:lac': 0.16; 'cc:addr:openend.se': 0.16; 'from:addr:lac': 0.16; 'from:addr:openend.se': 0.16; 'from:name:laura creighton': 0.16; 'message-id:@fido.openend.se': 0.16; 'naming': 0.16; 'numpy': 0.16; 'received:fido': 0.16; 'received:fido.openend.se': 0.16; 'renaming': 0.16; 'directory.': 0.18; 'laura': 0.18; 'versions': 0.20; 'cc:addr:python.org': 0.20; 'cc:2**1': 0.22; '"",': 0.22; 'fine,': 0.22; 'defined': 0.23; 'import': 0.24; '(most': 0.24; 'looks': 0.29; 'equivalent.': 0.29; 'finds': 0.29; 'received:se': 0.29; 'thinks': 0.29; 'cc:no real name:2**1': 0.29; 'rules': 0.31; 'file': 0.34; 'something': 0.35; 'should': 0.36; 'loaded': 0.36; 'modules': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'charset:us- ascii': 0.37; 'wanted': 0.37; 'things': 0.38; 'files': 0.38; 'goes': 0.39; 'called': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'header:Message-Id:1': 0.61; 'home': 0.67; 'header:In-reply-to:1': 0.84
To jorge.conrado@cptec.inpe.br
cc python-list@python.org, lac@openend.se
From Laura Creighton <lac@openend.se>
Subject Re: error
In-reply-to <3ffa1cef71ad34dd0fece7e983ecb987@cptec.inpe.br>
References <3ffa1cef71ad34dd0fece7e983ecb987@cptec.inpe.br>
Comments In-reply-to jorge.conrado@cptec.inpe.br message dated "Wed, 02 Sep 2015 15:18:43 -0300."
MIME-Version 1.0
Content-Type text/plain; charset="us-ascii"
Content-ID <6867.1441219331.1@fido>
Date Wed, 02 Sep 2015 20:42:11 +0200
X-Greylist Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (theraft.openend.se [89.233.217.130]); Wed, 02 Sep 2015 20:42:18 +0200 (CEST)
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.28.1441219359.8327.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1441219359 news.xs4all.nl 23815 [2001:888:2000:d::a6]:33147
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:95886

Show key headers only | View raw


>import numpy as np
>
>import netCDF4
>
>f = netCDF4.Dataset('uwnd.mon.ltm.nc','r')
>
>
>f.variables
>
>
>and I had the message:
>
>
>netcdf4.py
>Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
>NameError: name 'netcdf4' is not defined

You have a file called netcdf4.py
It contains the line:
import netCDF4

python comes along, reads
"import netCDF4"
and goes looking for something named netCDF4 or netCdf4 or netcdf4
or NETDCF4 or NeTcDf4  -- the rules of your file system say that
filenames are case-insensitive ... so all the above are equivalent.
The first place it looks is your home directory.  Then it looks in
your PYTHONPATH.  Then it looks in the system modules you nicely
loaded for it.

Unfortunately for you, it finds the file netcdf4.py in your home
directory and thinks that is the one you wanted to import.

BANG.

Solution -- stop naming your python files as lower-cased versions
of things you want to import.  Renaming it to mynetcdf4.py should
work fine, for instance.

Laura

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


Thread

Re: error Laura Creighton <lac@openend.se> - 2015-09-02 20:42 +0200

csiph-web