[Tutor] Working with interactive Python shell

Josep M. Fontana josep.m.fontana at gmail.com
Wed Nov 24 14:50:50 CET 2010


Thanks Evert and Steve,

Both of you are right when you say:

> You're not really showing what exactly you type. That's often more clearer than describing what you do, although in this case we can get a pretty good picture anyway.

OK, here's what I do:

>>>import test

I know the shell is importing the file because I can see the following message:

<module 'test' from 'test.py'>


The file test.py has the following contents (this is a little line of
code I constructed to see how the interactive shell worked importing
the file):

words = 'in the garden on the bank behind the tree'.split()

> How do you 'call the variable'?

Sorry, you are right.  That was a sloppy use of the term 'call'. I
meant to say "print the variable".

When I do:

>>print words

and

>>print words[3]

In principle I should get:

['in', 'the', 'garden', 'on', 'the', 'bank', 'behind', 'the', 'tree']

and

on

What I do get is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'words' is not defined

If the file has the contents that I showed above (and it does),
'words' should be defined, shouldn't it?

By the way Evert, thanks also for the tip on how to get tabs on a Mac
terminal. I didn't know that.


Josep M.


More information about the Tutor mailing list