Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #105732 > unrolled thread

Interpretation

Started byDennis Ngeno <dennisngeno7@gmail.com>
First post2016-03-25 09:33 -0700
Last post2016-03-27 14:49 +1100
Articles 5 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Interpretation Dennis Ngeno <dennisngeno7@gmail.com> - 2016-03-25 09:33 -0700
    Re: Interpretation "Mario R. Osorio" <nimbiotics@gmail.com> - 2016-03-26 20:22 -0700
      Re: Interpretation Ben Finney <ben+python@benfinney.id.au> - 2016-03-27 14:35 +1100
      Re: Interpretation Steven D'Aprano <steve@pearwood.info> - 2016-03-27 14:45 +1100
    Re: Interpretation Steven D'Aprano <steve@pearwood.info> - 2016-03-27 14:49 +1100

#105732 — Interpretation

FromDennis Ngeno <dennisngeno7@gmail.com>
Date2016-03-25 09:33 -0700
SubjectInterpretation
Message-ID<mailman.22.1458986332.28225.python-list@python.org>
My programs have never combile, they keep telling me , systax error even
after copy pasting

[toc] | [next] | [standalone]


#105806

From"Mario R. Osorio" <nimbiotics@gmail.com>
Date2016-03-26 20:22 -0700
Message-ID<d4bc11c2-e8b9-42f7-a3ff-11b609df1bfa@googlegroups.com>
In reply to#105732
On Saturday, March 26, 2016 at 5:59:04 AM UTC-4, Dennis Ngeno wrote:
> My programs have never combile, they keep telling me , systax error even
> after copy pasting

No pun intended, but I hope you are not typing your code like you typed your message.

OTOH, python code is not supposed to be compiled.

Another tip: If you really are copying and pasting, I'd recommend you first paste the code to the text editor of your like and MAKE SURE YOU ARE NOT MIXING SPACES AND TAB CHARACTERS FOR INDENTATION PURPOSES.

Use either, or but do not mix them, specially not on the same line. IMHO, it is best to always use spaces, but some people do prefer tabs.

[toc] | [prev] | [next] | [standalone]


#105808

FromBen Finney <ben+python@benfinney.id.au>
Date2016-03-27 14:35 +1100
Message-ID<mailman.70.1459049750.28225.python-list@python.org>
In reply to#105806
"Mario R. Osorio" <nimbiotics@gmail.com> writes:

> On Saturday, March 26, 2016 at 5:59:04 AM UTC-4, Dennis Ngeno wrote:
> > My programs have never combile, they keep telling me , systax error even
> > after copy pasting
>
> No pun intended, but I hope you are not typing your code like you
> typed your message.

Many people don't have English as a first language, or are otherwise
impaired from typing English text.

The issue is important though, Dennis: communication is at the core of
programming. You'll need to take care with what you write in your code,
and in your messages; both are communications and clear writing is very
helpful.

> OTOH, python code is not supposed to be compiled.

That's simply untrue: Python code is compiled every day on countless
machines. It is compiled to various formats, but the process is none the
less compilation.

Don't make the mistake of a narrow definition of “compile” which is
unhelpful in modern languages like Python.

> Another tip: If you really are copying and pasting, I'd recommend you
> first paste the code to the text editor of your like and MAKE SURE YOU
> ARE NOT MIXING SPACES AND TAB CHARACTERS FOR INDENTATION PURPOSES.

Dennis, you should choose a text editor that handles program code well.
A “word processor” program makes different trade-offs, altering text in
a way that is not helpful for writing program code.

For an overview of the range of programmer's text editors, see
<URL:https://wiki.python.org/moin/PythonEditors>. To start with you can
use the “IDLE” development environment that comes installed with Python.

-- 
 \      “Puritanism: The haunting fear that someone, somewhere, may be |
  `\                                         happy.” —Henry L. Mencken |
_o__)                                                                  |
Ben Finney

[toc] | [prev] | [next] | [standalone]


#105809

FromSteven D'Aprano <steve@pearwood.info>
Date2016-03-27 14:45 +1100
Message-ID<56f75759$0$1615$c3e8da3$5496439d@news.astraweb.com>
In reply to#105806
On Sun, 27 Mar 2016 02:22 pm, Mario R. Osorio wrote:

> OTOH, python code is not supposed to be compiled.

Technically, Python code is compiled, to byte-code rather than machine-code,
but still compiled.

That's what is inside the .pyc files you will often see after importing
modules. And Python even has a built-in function called "compile" that
takes source code and compiles it a code object:

py> x = compile("value = 23", "", "single")
py> type(x)
<class 'code'>
py> print(x)
<code object <module> at 0xb7993300, file "", line 1>
py> eval(x)
py> print(value)
23



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#105810

FromSteven D'Aprano <steve@pearwood.info>
Date2016-03-27 14:49 +1100
Message-ID<56f75845$0$1615$c3e8da3$5496439d@news.astraweb.com>
In reply to#105732
On Sat, 26 Mar 2016 03:33 am, Dennis Ngeno wrote:

> My programs have never combile, they keep telling me , systax error even
> after copy pasting

Dennis, if Python is complaining that you have a SyntaxError, it means you
have written something which the interpreter cannot understand. We cannot
possibly tell what you have done wrong if you don't show us what you wrote,
and what the error message says.


SyntaxError can mean many different errors, for example:


- you have misspelled a keyword (e.g. "dfe" instead of "def", "clas" instead
of "class", "ipmort" instead of "import");


- you tried to use a keyword as a variable (e.g. "class = 23");

- you have not indented a code block correctly, e.g. inconsistent
indentation in a single code block:

def function():
    print(1)  # four spaces indent
        print(2)  # eight spaces! this is inconsistent
  print(3)  # now two spaces!


or forgetting to indent a code block:

def function():
print(1)  # no indentation at all


If you mix spaces and tabs, Python can sometimes get confused about the
indentation, so you should always use *only* spaces or *only* tabs, never
both in the same block.


- you have too many, or too few, brackets and parentheses, or they are in
the wrong place, e.g.:

    def function():
        result = math.sin(1.245  # oops, forgot the closing parenthesis
        return result + 1


Errors with brackets and parentheses can be the most annoying ones, because
sometimes Python cannot tell that there is an error until the line *after*
where the error is. So in this case, it will say that there's a SyntaxError
in the last line, "return result + 1", when the real error is in the
previous line.

SyntaxError tells you that your code is written wrongly and Python doesn't
understand what you mean. You have to look at the code and fix the syntax
problem. If you show us the line of code that Python is complaining about,
and maybe the line before it, we can help.




-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web