examining an initial, pristine python3 shell session

R

Robert P. J. Day

still working my way through "dive into python 3" and i've already
been asked to give a newbie tutorial on it -- blind leading the blind,
as it were. that should be hilarious.

i'll be using python 3 and it occurred to me that it would be
educational (at least for me :) to display what an initial p3 shell
session looks like before doing any imports whatsoever. as in, i run
"python3" on my fedora box and, at the ">>>" prompt, i want to show
what's already there for the new user.

from what little i know so far, i'd start with:

to display the name of the current scope(?). backing up a bit, i
could run either of:
dir() ['__builtins__', '__doc__', '__name__', '__package__']
globals()

then i might go a bit further to examine some of *those* objects. i
admit it might seem a bit dry, but i think it would be handy to have a
handle on what a clean shell session looks like before starting to
import things, then seeing how that importing changes the session
before getting down to actual programming.

what other useful commands might i run immediately after starting a
session whose output would be informative? i can certainly poke at
some of those objects to see them in more detail. i'm just curious
what others might recommend. thanks.

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
========================================================================
 
A

Alf P. Steinbach

* Robert P. J. Day:
still working my way through "dive into python 3" and i've already
been asked to give a newbie tutorial on it -- blind leading the blind,
as it were. that should be hilarious.

i'll be using python 3 and it occurred to me that it would be
educational (at least for me :) to display what an initial p3 shell
session looks like before doing any imports whatsoever. as in, i run
"python3" on my fedora box and, at the ">>>" prompt, i want to show
what's already there for the new user.

from what little i know so far, i'd start with:
'__main__'

to display the name of the current scope(?). backing up a bit, i
could run either of:
dir() ['__builtins__', '__doc__', '__name__', '__package__']
globals()
{'__builtins__': <module 'builtins' (built-in)>, '__name__':
'__main__', '__doc__': None, '__package__': None}

then i might go a bit further to examine some of *those* objects. i
admit it might seem a bit dry, but i think it would be handy to have a
handle on what a clean shell session looks like before starting to
import things, then seeing how that importing changes the session
before getting down to actual programming.

what other useful commands might i run immediately after starting a
session whose output would be informative? i can certainly poke at
some of those objects to see them in more detail. i'm just curious
what others might recommend. thanks.

That depends on what you mean by "newbie".

If it's someone who knows a little bit of programming but is new to Python, then
'help' would definitely be about the first thing I'd show her.

But if it's someone who doesn't even know anything about programming, then I'd
recommend (blatant plug) <url: http://tinyurl.com/programmingbookP3> -- its
first two chapters are constructed around complete, concrete examples. However,
you would have to adapt just the *sense* of the first chapter, which is only
about tool usage, to *nix, since it's written for Windows. I'd not dive into
'help' for the someone who doesn't know anything because it gets technical
pretty fast, and because she will get back to that on her own when it's time.

Whatever you do, and whatever the background of the newbie, do introduce turtle
graphics right away.

The ch 2 of the above reference contains some t.g. examples that you might use
(initial silly figures, graphs of functions, recursive figures). It doesn't go
into the turtle module objects. But if objects are what you want to show right
away, then I think the turtle module is great also for that, because those
objects are simple and can be easily explored.


Cheers & hth.,

- Alf
 
A

Alf P. Steinbach

* Alf P. Steinbach:
* Robert P. J. Day:
still working my way through "dive into python 3" and i've already
been asked to give a newbie tutorial on it -- blind leading the blind,
as it were. that should be hilarious.

i'll be using python 3 and it occurred to me that it would be
educational (at least for me :) to display what an initial p3 shell
session looks like before doing any imports whatsoever. as in, i run
"python3" on my fedora box and, at the ">>>" prompt, i want to show
what's already there for the new user.

from what little i know so far, i'd start with:
'__main__'

to display the name of the current scope(?). backing up a bit, i
could run either of:
['__builtins__', '__doc__', '__name__', '__package__']
globals()
{'__builtins__': <module 'builtins' (built-in)>, '__name__':
'__main__', '__doc__': None, '__package__': None}

then i might go a bit further to examine some of *those* objects. i
admit it might seem a bit dry, but i think it would be handy to have a
handle on what a clean shell session looks like before starting to
import things, then seeing how that importing changes the session
before getting down to actual programming.

what other useful commands might i run immediately after starting a
session whose output would be informative? i can certainly poke at
some of those objects to see them in more detail. i'm just curious
what others might recommend. thanks.

That depends on what you mean by "newbie".

If it's someone who knows a little bit of programming but is new to
Python, then 'help' would definitely be about the first thing I'd show her.

He he... Try "help antigravity". :)
 
R

Robert P. J. Day

* Robert P. J. Day:

... snip ...
That depends on what you mean by "newbie".

If it's someone who knows a little bit of programming but is new to
Python, then 'help' would definitely be about the first thing I'd
show her.

But if it's someone who doesn't even know anything about
programming, then I'd recommend (blatant plug) <url:
http://tinyurl.com/programmingbookP3> -- its first two chapters are
constructed around complete, concrete examples. However, you would
have to adapt just the *sense* of the first chapter, which is only
about tool usage, to *nix, since it's written for Windows. I'd not
dive into 'help' for the someone who doesn't know anything because
it gets technical pretty fast, and because she will get back to that
on her own when it's time.

Whatever you do, and whatever the background of the newbie, do
introduce turtle graphics right away.

ah, thank you, i appreciate that reference. i'm expecting the small
audience to be relatively tech-savvy with OO dev experience, and i'm
betting that some of them will be wondering right off the very first
thing *i* was wondering -- when i start that python3 shell and get
dumped into it, what am i looking at? which is why i wanted to
collect a few commands to give the attendees at least a vague idea of
what was already there.

i've collected the following to start with:
dir() ['__builtins__', '__doc__', '__name__', '__package__']
globals()
.... stuff ...

then move on to examine *those* things:
<class 'module'>

zoom in a bit further and pick on specific examples:
.... lots of output ...

and so on. as i said, i know it looks dry but i figure i can take 5
minutes or so just to lay out the terrain and what a shell session
looks like before you do *anything* with it. and i'm betting most of
my audience will appreciate getting that high-level view before
launching into some programming. they'll just want to know the
initial session setup before they start importing stuff into it.

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
========================================================================
 
L

Lie Ryan

then i might go a bit further to examine some of *those* objects. i
admit it might seem a bit dry, but i think it would be handy to have a
handle on what a clean shell session looks like before starting to
import things, then seeing how that importing changes the session
before getting down to actual programming.

I would recommend to teach these introspection capabilities *after* some
basic programming. If you tell them these dir(), globals(), __name__,
etc before even getting into basic python, your precious newbies would
sit there thinking "what the hell is he talking about?"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top