some questions unanswered - new programmer ...

Roman Suzi rnd at onego.ru
Sat Aug 4 15:22:41 EDT 2001


On Sat, 4 Aug 2001, whats_really_hot wrote:

>still I have some unanswered questions because of my stupidity or book's
>incapability of explaining everything in an understanding manner. So, now I
>begin a series of query-posts (which I hope that they won't be many, because
>then I will be proved stupid enough to be flammed).
>
>My first questions are:
>
>1. The interactive command line is really a module with the name "__main__".

No. Any top-level program is __main__. It just happened that
with command-line you type a program and it happens to be toplevel.
I think you can read Python Language Reference (chapter 8):

     * 8. Top-level components
          + 8.1 Complete Python programs
          + 8.2 File input
          + 8.3 Interactive input
          + 8.4 Expression input

to get understanding of this.

>The command dir() also, return the names of the current namespace of the
>respective active module. Among these (i.e. names) is always the "__name__"
>name, which is the name of the current module. So, why when I type dir() in
>the interactive command line "__name__" is returned in spite of  "__main__",


>>> __name__
'__main__'

There is nothing wrong. "__main__" is a value of __name__ of current
module. dir() gives you names


>>> help('dir')
Help on built-in function dir:

dir(...)
    dir([object]) -> list of strings

    Return an alphabetized list of names comprising (some of) the
attributes
    of the given object.  Without an argument, the names in the current
scope
    are listed.  With an instance argument, only the instance attributes
are
    returned.  With a class argument, attributes of the base class are not
    returned.  For other types or arguments, this may list members or
methods.

>which is indeed the name of the current module, i.e. the interactive command
>line?
>2. What does the command "cat" do? I suspect that it begins the creation of
>a new module, right?

In what context? cat is UNIX command

NAME
       cat - concatenate files and print on the standard output


So

$ cat <<EOMODULE > module.py
> print 2*2
> EOMODULE

indeed creates a module ;-) if you are using UNIX. Let see what is
inside the file module.py:

$ cat module.py
print 2*2
$ man cat
...

>Thanks for ur time and attention, because I admit that this is a huge post.
>Anyway, I look forward to ur answers and prepare for my impending questions
>in other posts.

Probably you have not seen huge posts...

Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Saturday, August 04, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Experience: a name everyone gives to his mistakes." _/





More information about the Python-list mailing list