[EMAIL PROTECTED] writes:

On Tue, 12 Nov 2002, at 10:08pm, [EMAIL PROTECTED] wrote:
Python hacker
'Hello, world.'
Transcript of my shell session:
$ cat > hw.py
'Hello, world.'
^D
$ python hw.py $
What did I do wrong?

Omigosh. I must have been too cryptic. What was "wrong" was $.
No one said $.
A Python hacker seldom needs to resort to a shell. :)
Seriously, earlier posts were correct. When Python evaluates
an expression at the interactive prompt, and your interactive
expression doesn't say what to do with the result (e.g.,
no = sign or no "print") Python assumes the "print". As you
develop a program you do a lot of that kind of inspection -
it's only a savings of typing "print" each time, but it adds up.
A typically "Pythonic" streamlining.
print 2+2
4
2+2
4
There is nothing special about the case of a string expression.
Python does the same for any kind of object.
somefile = open('spam.eggs', 'w')
somefile
<open file 'spam.eggs', mode 'w' at 0x10103758>
print somefile
<open file 'spam.eggs', mode 'w' at 0x10103758>
In a running program you don't usually want that behavior. For
instance, an expression might be something whose returned value
you don't need. An example might be an expresssion which is only
a call to a function.
somefile.close()          # Close the file
                          # Ahhh.   Silence..
print somefile.close()    # Same, AND print what's returned
None                          #  ..which is the empty ojbect, None

[My example is knowingly a little contrived; please forgive.
There's more to the way the empty object behaves. This example
is intended to show the flavor of Python's design.]
Extra credit, what will the following do (if you've just stepped
through the statements above)?
print somefile
_______________________________________________
gnhlug-discuss mailing list
[EMAIL PROTECTED]
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss


Reply via email to