error

Nick Sarbicki nick.a.sarbicki at gmail.com
Wed Sep 2 14:44:04 EDT 2015


Where are you running the code from?

The interactive prompt? (E.g. idle, or after you type "python" at the
terminal) or from the terminal? (as in by typing "python p2.py" at the
terminal).

It looks like you're trying to load a file while in the interactive prompt
which won't work that way (it will work if you type "import p2"). When you
should be using "python p2.py" at the terminal.

- Nick

On Wed, 2 Sep 2015 19:20  <jorge.conrado at cptec.inpe.br> wrote:

> Hi,
>
>
> I have a Python version: Python 2.7.8
>
> I'm runing it on: Fedora release 21
>
>
> Yesterday I a sent a question:
>
>
> I'm starting in the Python scripts. I run this script:
>
>
> 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
>
>
> I had two answers to my question. But I could not understand them. I
> don't have expericence with Python. So I downloaded from the Web a code
> to calcluate the dew point temperature:
>
>
> import sys
> import numpy as np
>
> # approximation valid for
> # 0 degC < T < 60 degC
> # 1% < RH < 100%
> # 0 degC < Td < 50 degC
>
> # constants
> a = 17.271
> b = 237.7 # degC
>
> # sys.argv[0] is program name
> T=float(sys.argv[1])
> RH=float(sys.argv[2])
>
>
> def dewpoint_approximation(T,RH):
>
>      Td = (b * gamma(T,RH)) / (a - gamma(T,RH))
>
>      return Td
>
>
> def gamma(T,RH):
>
>      g = (a * T / (b + T)) + np.log(RH/100.0)
>
>      return g
>
>
> Td = dewpoint_approximation(T,RH)
> print 'T, RH',T,RH
> print 'Td=',Td
>
>
> Then I run it and I had the message:
>
>              p2.py
>
>
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> NameError: name 'p2' is not defined
>
>
> Like the same error that I had for my first run.
>
> Please, someone can help me. I have a commercial software and I would
> like to use Python.
>
> In advance. Thanks,
>
> Conrado
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
 - Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150902/10503c76/attachment.html>


More information about the Python-list mailing list