P
Player
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello
I am teaching myself python, and I have gotten a long way, it's quite a
decent language and the syntax is great
However I am having a few, "problems" shall we say with certain conventions
in python.
In the book I am using to teach me more of the inner working of python, and
further into python that the basic tutorials go, there is this wording
below...
[book quote]
When a file containing python code is executed, the built in variable _name_
is populated with the name of the module being executed. If the value of
_name_ is _main_, then that file is the original file that was used to
invoke the application from command line or an icon.
This is usefull, as it allows code to know the difference between when it is
invoked & when it is imported by another python program. It is also provides
a convenient place to provide one-time startup code.
[end quote]
Can someone explain this in some different wording, because I dn't know if
my understanding of what is said in that paragraph is right or not?
ALSO
Below is some example of some code, for use with python and PyGame and PyUI,
that I would like to ask a question about..
import pyui
class Application:
def _init_(self, width, height):
self.width = width
self.height = height
def run(self):
"""I am called to begin the Application or game.
"""
def run()
width = 800
height = 600
pyui.init(width, height)
app= Application(width, height)
app.run()
if _name == '_main_':
run()
Now I no that this code declares an Application class, and then invokes a
run method to create an instance of that class. Then the Application cobject
then uses the run method called to start the main loop.
Which basically created a game window of size 800 by 600.
What I don't understand is the, "self" bit of the two top functions.
Can somebody explain what the, "self" is actually for??
Thanks ina dvance
Player
- --
*************
The Imagination may be compared to Adam's dream-
he awoke and found it truth.
John Keats.
*************
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0
iQA/AwUBQU7/ty/z2sM4qf2WEQJRrQCguAtRwDQ6UfFRXDGZ63DDjWdnID0AmwX3
4K3iWiybh9BEKPh9b2h0m9Tr
=0niY
-----END PGP SIGNATURE-----
Hash: SHA1
Hello
I am teaching myself python, and I have gotten a long way, it's quite a
decent language and the syntax is great
However I am having a few, "problems" shall we say with certain conventions
in python.
In the book I am using to teach me more of the inner working of python, and
further into python that the basic tutorials go, there is this wording
below...
[book quote]
When a file containing python code is executed, the built in variable _name_
is populated with the name of the module being executed. If the value of
_name_ is _main_, then that file is the original file that was used to
invoke the application from command line or an icon.
This is usefull, as it allows code to know the difference between when it is
invoked & when it is imported by another python program. It is also provides
a convenient place to provide one-time startup code.
[end quote]
Can someone explain this in some different wording, because I dn't know if
my understanding of what is said in that paragraph is right or not?
ALSO
Below is some example of some code, for use with python and PyGame and PyUI,
that I would like to ask a question about..
import pyui
class Application:
def _init_(self, width, height):
self.width = width
self.height = height
def run(self):
"""I am called to begin the Application or game.
"""
def run()
width = 800
height = 600
pyui.init(width, height)
app= Application(width, height)
app.run()
if _name == '_main_':
run()
Now I no that this code declares an Application class, and then invokes a
run method to create an instance of that class. Then the Application cobject
then uses the run method called to start the main loop.
Which basically created a game window of size 800 by 600.
What I don't understand is the, "self" bit of the two top functions.
Can somebody explain what the, "self" is actually for??
Thanks ina dvance
Player
- --
*************
The Imagination may be compared to Adam's dream-
he awoke and found it truth.
John Keats.
*************
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0
iQA/AwUBQU7/ty/z2sM4qf2WEQJRrQCguAtRwDQ6UfFRXDGZ63DDjWdnID0AmwX3
4K3iWiybh9BEKPh9b2h0m9Tr
=0niY
-----END PGP SIGNATURE-----