Professional IronPython



Download 20,35 Mb.
Pdf ko'rish
bet66/453
Sana01.07.2022
Hajmi20,35 Mb.
#723045
1   ...   62   63   64   65   66   67   68   69   ...   453
46

CHAPTER 3
ImplementIng Structured language elementS
STRINgINg STATEmENTS TogETHER
A basic IronPython application begins as a series of statements, as a procedure. These statements 
perform some task at the command line or within a window, depending on which IronPython inter-
preter you use. This initial execution path is called the main function, even though there really isn’t 
a function — simply a set of statements.
A lot of people feel uncomfortable with the open feel of IronPython’s main function so they create 
something that looks a bit more like what they’re used to using, as shown in Listing 3-1.
LISTINg 3-1: 
 Creating an actual main() function
import sys
# Create a main() function that everyone can recognize.
def main(argv = None):
# Obtain the command line arguments.
if argv is None:
argv = sys.argv
# Display the command line arguments.
for ThisArg in argv:
print ThisArg
# Pause after the debug session.
raw_input(‘Press any key to continue...’)
# Call the main() function.
if __name__ == “__main__“:
main()
This code shows a few interesting structural features of IronPython, which is why it’s such a good 
example to start with. The code actually begins with a comparison of 
__name__
to 
“__main__“
. It 
turns out that 
__name__
always contains the name of the current function. Using 
__name__
makes
it possible for your application to detect its position in the execution loop.
Most programming languages provide an equivalent of the 
main()
 function 
described in Listing 3-1. Even C# and Visual Basic have a 
main()
-type function 
that creates the initial form. Whether you actually use a 
main()
 function in your 
applications depends upon how you expect other developers to interact with 
your code. The examples in this book don’t rely on a main function for the sake 
of clarity, but you might want to consider including one when developers are 
used to working with 
main()
 as part of their coding experience. Of course, you 
can call 
main()
 anything you like to match the programming language that your 
developers normally use.
548592c03.indd 46
2/24/10 12:47:28 PM
www.finebook.ir



Download 20,35 Mb.

Do'stlaringiz bilan baham:
1   ...   62   63   64   65   66   67   68   69   ...   453




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish