Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26585 > unrolled thread
| Started by | PeterSo <ojlise@gmail.com> |
|---|---|
| First post | 2012-08-05 16:46 -0700 |
| Last post | 2012-08-09 06:36 -0700 |
| Articles | 9 — 7 participants |
Back to article view | Back to comp.lang.python
Getting started with IDLE and Python - no highlighting and no execution PeterSo <ojlise@gmail.com> - 2012-08-05 16:46 -0700
Re: Getting started with IDLE and Python - no highlighting and no execution Rotwang <sg552@hotmail.co.uk> - 2012-08-06 01:09 +0100
Re: Getting started with IDLE and Python - no highlighting and no execution MRAB <python@mrabarnett.plus.com> - 2012-08-06 01:58 +0100
Re: Getting started with IDLE and Python - no highlighting and no execution Matthew Barnett <mrabarnett@mrabarnett.plus.com> - 2012-08-06 02:01 +0100
Re: Getting started with IDLE and Python - no highlighting and no execution Rotwang <sg552@hotmail.co.uk> - 2012-08-06 02:13 +0100
Re: Getting started with IDLE and Python - no highlighting and no execution PeterSo <ojlise@gmail.com> - 2012-08-05 19:17 -0700
Re: Getting started with IDLE and Python - no highlighting and no execution Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-06 01:52 +0100
Re: Getting started with IDLE and Python - no highlighting and no execution Terry Reedy <tjreedy@udel.edu> - 2012-08-05 21:32 -0400
Re: Getting started with IDLE and Python - no highlighting and no execution soloflyr@gmail.com - 2012-08-09 06:36 -0700
| From | PeterSo <ojlise@gmail.com> |
|---|---|
| Date | 2012-08-05 16:46 -0700 |
| Subject | Getting started with IDLE and Python - no highlighting and no execution |
| Message-ID | <d07282d6-1666-4230-bf46-c0942ef9a390@r7g2000yqr.googlegroups.com> |
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)
[toc] | [next] | [standalone]
| From | Rotwang <sg552@hotmail.co.uk> |
|---|---|
| Date | 2012-08-06 01:09 +0100 |
| Message-ID | <jvn1vr$ln6$1@dont-email.me> |
| In reply to | #26585 |
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
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2012-08-06 01:58 +0100 |
| Message-ID | <mailman.2991.1344214708.4697.python-list@python.org> |
| In reply to | #26586 |
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. >> # 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). >
[toc] | [prev] | [next] | [standalone]
| From | Matthew Barnett <mrabarnett@mrabarnett.plus.com> |
|---|---|
| Date | 2012-08-06 02:01 +0100 |
| Message-ID | <mailman.2993.1344214905.4697.python-list@python.org> |
| In reply to | #26586 |
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]
[toc] | [prev] | [next] | [standalone]
| From | Rotwang <sg552@hotmail.co.uk> |
|---|---|
| Date | 2012-08-06 02:13 +0100 |
| Message-ID | <jvn5n6$6so$1@dont-email.me> |
| In reply to | #26596 |
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. -- I have made a thing that superficially resembles music: http://soundcloud.com/eroneity/we-berated-our-own-crapiness
[toc] | [prev] | [next] | [standalone]
| From | PeterSo <ojlise@gmail.com> |
|---|---|
| Date | 2012-08-05 19:17 -0700 |
| Message-ID | <89c5285b-5f3a-4195-9dcb-f24a098cb670@p8g2000yqa.googlegroups.com> |
| In reply to | #26586 |
On Aug 5, 7:09 pm, Rotwang <sg...@hotmail.co.uk> 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. > > > 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 Your right, it is v 3 so print(mean(data1)) worked. Thanks. I still do not have any highlighting in the IDLE editor.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2012-08-06 01:52 +0100 |
| Message-ID | <mailman.2989.1344214255.4697.python-list@python.org> |
| In reply to | #26585 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2012-08-05 21:32 -0400 |
| Message-ID | <mailman.2997.1344216783.4697.python-list@python.org> |
| In reply to | #26585 |
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
[toc] | [prev] | [next] | [standalone]
| From | soloflyr@gmail.com |
|---|---|
| Date | 2012-08-09 06:36 -0700 |
| Message-ID | <5094008e-1df3-4b6d-9d50-6a7a4751dcf7@googlegroups.com> |
| In reply to | #26585 |
On Sunday, August 5, 2012 7:46:54 PM UTC-4, 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? > > 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) did you call you file xxx.py IDLE looks for the .py extension to identify the program as python code.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web