[pythonvis] Re: thoughts on confusing threads - Re: How Python works ... was Re: print"Hello world."

  • From: "Charles Rivard" <wee1sman@xxxxxxxxxx>
  • To: <pythonvis@xxxxxxxxxxxxx>
  • Date: Thu, 1 May 2014 17:28:38 -0500

Not as of yet, because someone else has been using my laptop while her PC is temporarily out of commission. I will be at this evening's meeting at


www.Out-Of-Sight.com

though.  Thanks.

---
Be positive! When it comes to being defeated, if you think you're finished, you! really! are! finished! ----- Original Message ----- From: "Richard Dinger" <rrdinger@xxxxxxxxxx>
To: <pythonvis@xxxxxxxxxxxxx>
Sent: Wednesday, April 30, 2014 11:24 PM
Subject: [pythonvis] Re: thoughts on confusing threads - Re: How Python works ... was Re: print"Hello world."


I think all the jargon that we use is a primary source of bewilderment among newbies. At least the book 'How to Think like a Computer Scientist' has a glossary at the end of each chapter and attempts to explain new terms as they come up. Over time you will learn and become comfortable with the jargon.

Now, as I recall, you said you got the hello program to run. Have you gone further in one of the books and is anything confusing you?

Richard



-----Original Message----- From: Charles Rivard
Sent: Wednesday, April 30, 2014 4:20 PM
To: pythonvis@xxxxxxxxxxxxx
Subject: [pythonvis] thoughts on confusing threads - Re: How Python works ... was Re: print"Hello world."

I agree that maybe this discussion should be taken up at a later date, when
people like me actually know what's being talked about.  Right now, it's
totally confusing.  What I am doing, though, is saving these explanatory
posts for future reference.

---
Be positive! When it comes to being defeated, if you think you're finished,
you! really! are! finished!
----- Original Message ----- From: "Richard Dinger" <rrdinger@xxxxxxxxxx>
To: <pythonvis@xxxxxxxxxxxxx>
Sent: Tuesday, April 29, 2014 11:04 PM
Subject: [pythonvis] How Python works ... was Re: print"Hello world."


This sort of discussion serves mainly to confuse new programmers if they pay
any attention.  So maybe this thread should be retired.

That being said, there may still be some confusion over how the translation
process works and when errors are
discovered.  Hopefully, the following will help clarify things.

The .py file you write with your text editor is called a source code file. Something called the compiler reads and translates your python source code into what is called a byte
code representation.

syntax errors are errors in the formal rules of the programming language
(like misspelled words or missing quotes) and are discovered by the
compiler. Execution of the translation process stops when a syntax error is
discovered.

If there were no syntax or other compiler errors, the byte code is
then passed to the Python virtual machine, which executes the translated byte
code.  If an error occurs during this execution phase it is called a run
time error since it happened while the program is running. And as usual, execution is
halted when such a run time error is discovered.

Mark Lutz in 'Learning Python 3rd edition summarizes:
When you instruct Python to run your script, there are a few steps that
Python carries out before your code actually starts crunching away.
Specifically, it's first compiled to something called "byte code" and then
routed to something called a "virtual machine."

Richard
-----Original Message----- From: Octavian Rasnita
Sent: Tuesday, April 29, 2014 1:34 PM
To: pythonvis@xxxxxxxxxxxxx
Subject: [pythonvis] Re: print"Hello world."

Yep, the results are:

D:\>python z8.py
File "z8.py", line 2
pritn "Goodbye world!"
^
SyntaxError: invalid syntax
D:\>

So the program is not ran.

As I said, first the program is checked for syntax, is compiled in memory if the syntax is correct and if it has a syntax error no line is executed from
it.

Then it is ran. But just like in any program made in any other language,
there may appear runtime errors like no free space on hard disk, no memory,
divide by zero etc.
All these things can't be known at compile time. Probably a program asks to
user to type 2 numbers and then divide one with the other.
The user can type anything including 0 or strings.
If the input is not checked then there may appear runtime errors, but that doesn't mean that the program has an error, It is just poorly made because
it doesn't check the input data or it doesn't treat all the possible
exceptions etc.
(And this can happen in programs made in other languages also.)

--Octavian

----- Original Message ----- From: "James Scholes" <james@xxxxxxxxxxxxx>
To: <pythonvis@xxxxxxxxxxxxx>
Sent: Tuesday, April 29, 2014 9:14 PM
Subject: [pythonvis] Re: print"Hello world."


Richard Dinger wrote:
I was unable to replicate your example.  The first correct print
statement did not print, I only got the error traceback.

I should've realised that a syntax error would prevent the program from
running at all.  However, a traceback does not.  For example, if you run
the following code:

print "Hello world!"
print "Here comes a traceback when we try to divide by zero..."
print 20 / 0

You will see:

Hello world!
Here comes a traceback when we try to divide by zero...
Traceback (most recent call last):
 File "hello.py", line 3, in <module>
   print 20 / 0
ZeroDivisionError: integer division or modulo by zero

You cannot divide a number by zero, so your program crashes and
generates a traceback.  However, as you can see, the file is
syntactically correct, so the statements up to that point will run
without a problem.  Apologies for the error!
--
James Scholes
http://twitter.com/JamesScholes








Other related posts: