Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting started with IDLE and Python - no highlighting and no execution

117 views
Skip to first unread message

PeterSo

unread,
Aug 5, 2012, 7:46:54 PM8/5/12
to
I am just starting to learn Python, and I like to use the editor
instead of the interactive shell. So I wrote the following little
program in IDLE

# calculating the mean

data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11]

def mean(data):
return sum(data)/len(data)

mean(data1)


There is no syntax highlighting and when I ran it F5, I got the
following in the shell window.


>>> ================================ RESTART
================================
>>>
>>>


Any ideas?
If I added print mean(data1), it gave me a invalid syntax

# calculating the mean

data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11]
data2=[1,2,3,4,5]

def mean(data):
return sum(data)/len(data)

mean(data1)
print mean(data1)

Rotwang

unread,
Aug 5, 2012, 8:09:30 PM8/5/12
to
On 06/08/2012 00:46, PeterSo wrote:
> I am just starting to learn Python, and I like to use the editor
> instead of the interactive shell. So I wrote the following little
> program in IDLE
>
> # calculating the mean
>
> data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11]
>
> def mean(data):
> return sum(data)/len(data)
>
> mean(data1)
>
>
> There is no syntax highlighting and when I ran it F5, I got the
> following in the shell window.
>
>
> >>> ================================ RESTART
> ================================
>>>>
>>>>
>
>
> Any ideas?

I don't know what editor you're using or how it works, but I'm guessing
that pressing f5 runs what you've written as a script, right? In that
case the interpreter doesn't automatically print the result of
expressions in the same way that the interactive interpreter does; you
didn't tell it to print anything, so it didn't.


> If I added print mean(data1), it gave me a invalid syntax
>
> # calculating the mean
>
> data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11]
> data2=[1,2,3,4,5]
>
> def mean(data):
> return sum(data)/len(data)
>
> mean(data1)
> print mean(data1)

If you're using Python 3.x, you'll need to replace

print mean(data1)

with

print(mean(data1))

since the print statement has been replaced with the print function in
Python 3.

If you're instead using Python 2.x then I don't know what the problem
is, but in that case your mean() function won't work properly - the
forward slash operator between a pair of ints gives you floor division
by default, so you should instead have it return something like
float(sum(data))/len(data).


--
I have made a thing that superficially resembles music:

http://soundcloud.com/eroneity/we-berated-our-own-crapiness

Mark Lawrence

unread,
Aug 5, 2012, 8:52:30 PM8/5/12
to pytho...@python.org
On 06/08/2012 00:46, PeterSo wrote:
> I am just starting to learn Python, and I like to use the editor
> instead of the interactive shell. So I wrote the following little
> program in IDLE
>

[snip]

I can't comment on IDLE as I've never used it, but you're doing yourself
a big disservice if you don't use the interactive shell. Trying code
snippets at the interactive prompt is one of the big benefits of using
Python, ignore it at your peril :)

--
Cheers.

Mark Lawrence.

MRAB

unread,
Aug 5, 2012, 8:58:28 PM8/5/12
to pytho...@python.org
On 06/08/2012 01:09, Rotwang wrote:
> On 06/08/2012 00:46, PeterSo wrote:
>> I am just starting to learn Python, and I like to use the editor
>> instead of the interactive shell. So I wrote the following little
>> program in IDLE
>>
>> # calculating the mean
>>
>> data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11]
>>
>> def mean(data):
>> return sum(data)/len(data)
>>
>> mean(data1)
>>
>>
>> There is no syntax highlighting and when I ran it F5, I got the
>> following in the shell window.
>>
>>
>> >>> ================================ RESTART
>> ================================
>>>>>
>>>>>
>>
>>
>> Any ideas?
>
> I don't know what editor you're using or how it works, but I'm guessing
> that pressing f5 runs what you've written as a script, right? In that
> case the interpreter doesn't automatically print the result of
> expressions in the same way that the interactive interpreter does; you
> didn't tell it to print anything, so it didn't.
>
It looks like it's IDLE.
>
>> If I added print mean(data1), it gave me a invalid syntax
>>
Which suggests to me that it's Python 3.

Matthew Barnett

unread,
Aug 5, 2012, 9:01:47 PM8/5/12
to pytho...@python.org
On 06/08/2012 01:58, MRAB wrote:
> On 06/08/2012 01:09, Rotwang wrote:
>> On 06/08/2012 00:46, PeterSo wrote:
>>> I am just starting to learn Python, and I like to use the editor
>>> instead of the interactive shell. So I wrote the following little
>>> program in IDLE
>>>
>>> # calculating the mean
>>>
>>> data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11]
>>>
>>> def mean(data):
>>> return sum(data)/len(data)
>>>
>>> mean(data1)
>>>
>>>
>>> There is no syntax highlighting and when I ran it F5, I got the
>>> following in the shell window.
>>>
>>>
>>> >>> ================================ RESTART
>>> ================================
>>>>>>
>>>>>>
>>>
>>>
>>> Any ideas?
>>
>> I don't know what editor you're using or how it works, but I'm guessing
>> that pressing f5 runs what you've written as a script, right? In that
>> case the interpreter doesn't automatically print the result of
>> expressions in the same way that the interactive interpreter does; you
>> didn't tell it to print anything, so it didn't.
>>
> It looks like it's IDLE.

Actually, he does say that it's IDLE at the start.
[snip]

Rotwang

unread,
Aug 5, 2012, 9:13:10 PM8/5/12
to
On 06/08/2012 02:01, Matthew Barnett wrote:
> On 06/08/2012 01:58, MRAB wrote:
>> On 06/08/2012 01:09, Rotwang wrote:
>>> On 06/08/2012 00:46, PeterSo wrote:
>>>> I am just starting to learn Python, and I like to use the editor
>>>> instead of the interactive shell. So I wrote the following little
>>>> program in IDLE
>>>>
>>>> [...]
>>>>
>>> I don't know what editor you're using or how it works, but I'm guessing
>>> that pressing f5 runs what you've written as a script, right? In that
>>> case the interpreter doesn't automatically print the result of
>>> expressions in the same way that the interactive interpreter does; you
>>> didn't tell it to print anything, so it didn't.
>>>
>> It looks like it's IDLE.
>
> Actually, he does say that it's IDLE at the start.
> [snip]

Doh! Not sure how I missed that, sorry.

Terry Reedy

unread,
Aug 5, 2012, 9:32:36 PM8/5/12
to pytho...@python.org
On 8/5/2012 7:46 PM, PeterSo wrote:
> I am just starting to learn Python, and I like to use the editor
> instead of the interactive shell. So I wrote the following little
> program in IDLE
>
> # calculating the mean
>
> data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11]
>
> def mean(data):
> return sum(data)/len(data)
>
> mean(data1)
>
>
> There is no syntax highlighting

If properly installed and working, IDLE does syntax highliting if and
only if you name the file with a .py, .pyw, .pyo extension. I have a
'play around' directory with a tem.py file that is always in the recent
files lists. I use it for short shippets that are two long to directly
type into the shell.

--
Terry Jan Reedy

PeterSo

unread,
Aug 5, 2012, 10:17:54 PM8/5/12
to
Your right, it is v 3 so print(mean(data1)) worked.
Thanks.
I still do not have any highlighting in the IDLE editor.

solo...@gmail.com

unread,
Aug 9, 2012, 9:36:34 AM8/9/12
to
did you call you file xxx.py IDLE looks for the .py extension to identify the program as python code.
0 new messages