[Tutor] (no subject)

spir denis.spir at free.fr
Sat Nov 1 18:09:21 CET 2008


otu at iptech-ghana.com a écrit :
> Dear Friends,
> I have just started learning python programming. I have no previous
> programming knowledge.
Welcome! I'm an amateur, too. Some words to add to Kent's answer.
> I am presently using Python 2.6 windows version.
> I am struggling with how to enable executable files. I copied the ff
> program on idlle non-interactice and run it.
>
> the_world_is_flat =1
> if the_world_is_flat:
> 	print"Be careful not to fall off"
>
>
You can alternatively write:

the_world_is_flat = True
The reason for this is that "the world is flat" is a logical assertion which may be either true or false. Right? More logical assertions of that kind: "end of file reached", "searched pattern found", "invalid syntax",... For both historical and practical reasons, python represents logical values (called booleans or bools) as integers. This can be considered an internal, background, feature, that can safely be forgotten 99% of the time. Their meaning always remains logical. Writing True or False instead of 1 or 0 then makes your code more legible. This is no necessity, just a common recommendation.
Another point of view about logical variables is that they are like closed questions ("is the world flat?"), which answer/value can be yes or no. Some languages allow that. Ruby also identifies logical variables with a '?'.

>
> The result came out on the interactive window. I saved this as
> "example.py" on the desktop. The python icon appears on the the desktop
> alright.  When I attempt to run it by double clicking the icon, only a
> black DOS window flashes.  I know I am doing something seriously wrong.
> What is it?
You do it all right. The tricky problem is what Kent explained. If you 
are under windows and rename your program with a .pyw extension, it will 
run slightly differently, so that you won't even see the DOS window 
flash. This is rather for GUI programs.
Anyway, when you run a program inside Idle, it really runs! For 
instance, if you create a file, you can check it after execution. So 
that you may not need to execute your programs from outside the editor. 
It's a very practicle advantage. You just have to know that they will 
run "normally", with no change, on any machine with python installed.

> Regards,
> Bennedy.
>
> _
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>




More information about the Tutor mailing list