[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Python curses



On Tue 10 Jan 2023 at 09:01:17 (-0500), paulf@quillandmouse.com wrote:
> On Tue, 10 Jan 2023 08:34:05 -0500 Greg Wooledge <greg@wooledge.org> wrote:
> > On Tue, Jan 10, 2023 at 08:24:11AM -0500, paulf@quillandmouse.com wrote:
> > > What you wrote triggered something. I'd been following the Python
> > > curses docs, which tell you to write, for example, "A_REVERSE". And
> > > Python was throwing exceptions. But based on what you wrote, I
> > > substituted "curses.A_REVERSE", which works.
> > > 
> > > Problem solved... for now.

Exactly: just for now.

> > I'm a Python novice, but I believe what you're seeing is the
> > difference between
> 
> No, here's what happened. I was going along, and I used "A_REVERSE" in
> my code, according to the online docs. Exception, didn't recognize the
> name. That didn't make sense; this attribute is basic to curses. So I
> started investigated versions of Python, ncurses, Python curses, etc.
> 
> But as it turns out, instead of typing "A_REVERSE", I should have
> ignored the docs and typed "curses.A_REVERSE". That worked, and
> obviated the whole versioning problem.

You keep mentioning "the docs" without saying which docs, so a
reference might be helpful. I'm finding that most online docs
I hit by googling   python curses docs   use examples that:

  import curses

thereby only importing the module's name into the local namespace,
or else import just a selection of attributes into the local
namespace, as in:

  from curses import wrapper

To fully answer your question, we need to see how your docs had
imported curses before using its attributes without qualification.

It's difficult to conceive of doing much python programming without
understanding the distinction being made here by Greg and tomas.
You should read "The import statement" section in the Python
Language Reference:
file:///usr/share/doc/python3/html/reference/simple_stmts.html#the-import-statement

BTW in the many years I used python seriously as part of my job,
I never used "from mod import *" except where I'd written the
module concerned, and had total control over the few, unique,
attribute names that it defined.

Cheers,
David.


Reply to: