Re: [Tutor] Fwd: : Turtle
I tested with 2.6 and it works. >/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 >"/Users/Hershel/PycharmProjects/Project 1/practicefornotturtle.py" >Traceback (most recent call last): > File "/Users/Hershel/PycharmProjects/Project 1/practicefornotturtle.py", > line 2, in > turtle.pendown() >AttributeError: 'module' object has no attribute 'pendown' Cannot access the documentation of the 2.5 to check if the pendown() is there. This email is confidential and may be subject to privilege. If you are not the intended recipient, please do not copy or disclose its content but contact the sender immediately upon receipt. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: : Turtle
On Thu, Jun 23, 2016 at 02:13:56PM -0700, Hershel Millman wrote: > What I typed was: > > import turtle > turtle.pendown() What do you get if you print turtle.__file__? > (And pendown was highlighted in pycharm, indicating that it was not a valid > command.) > > The error message I received was: > > /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 Look at the version number: you are running Python 2.5. Now look at the result you got earlier: > >> /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/turtle.py Look at the version number: you are running Python 2.6. So you have AT LEAST two different Python versions on your computer. That's fine, I have *nine* versions on mine. But it does mean you have to be a little more careful to ensure you are using the right one. My *guess* is that your Mac has pre-installed version 2.5 with the operating system, and you have installed version 2.6 next to it, and now you sometimes get 2.5 and sometimes 2.6 depending on which icon you double-click. Or something like that. Or maybe PyCharm let's you pick a different version, and you haven't noticed. You can check the version from inside Python: import sys print sys.version My prediction is: * when you run Python 2.6, turtle will work fine, including the pendown command (but remember to use round brackets/parentheses): turtle.pendown() # okay in 2.6 * when you run Python 2.5, turtle will import, but there is no turtle.pendown command. Instead, it is called turtle.down. Documentation for 2.5: https://docs.python.org/release/2.5.4/lib/module-turtle.html Documentation for 2.6: https://docs.python.org/release/2.6/library/turtle.html -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: : Turtle
On 23/06/16 22:13, Hershel Millman wrote: > What I typed was: > > import turtle > turtle.pendown() > > (And pendown was highlighted in pycharm, indicating that it was not a valid > command.) Don't use pycharm. We need to eliminate as many variables as possible. Start python in a Terminal and just type the commands into the raw Python interpreter. Send a paste of the transcript. I expect to see something like: agauld@ubuntu:~$ python2 Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import turtle >>> turtle.__file__ '/usr/lib/python2.7/lib-tk/turtle.pyc' >>> turtle.pendown >>> turtle.pendown() >>> Can you reproduce that on your Mac? (Except maybe with an error message somewhere along the line?) > /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 > "/Users/Hershel/PycharmProjects/Project 1/practicefornotturtle.py" > Traceback (most recent call last): > File "/Users/Hershel/PycharmProjects/Project 1/practicefornotturtle.py", > line 2, in > turtle.pendown() > AttributeError: 'module' object has no attribute 'pendown' I notice that this says you are using Python 2.5 but your last message suggested the module was in 2.6. I don't think that should make a difference for the turtle module but it might be significant... Lets see your transcript first. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: : Turtle
What I typed was: import turtle turtle.pendown() (And pendown was highlighted in pycharm, indicating that it was not a valid command.) The error message I received was: /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5 "/Users/Hershel/PycharmProjects/Project 1/practicefornotturtle.py" Traceback (most recent call last): File "/Users/Hershel/PycharmProjects/Project 1/practicefornotturtle.py", line 2, in turtle.pendown() AttributeError: 'module' object has no attribute 'pendown' Process finished with exit code 1 Thank you, Hershel Begin forwarded message: > From: Alan Gauld via Tutor > Date: June 23, 2016 12:12:39 AM MST > To: tutor@python.org > Subject: Re: [Tutor] : Turtle > Reply-To: Alan Gauld > > On 23/06/16 01:52, Hershel Millman wrote: >> I found the turtle module on my computer. >> > import turtle > print(turtle.__file__) >> /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/turtle.py > > That's the right turtle module do not rename it. > I entered "import turtle" instead of "from turtle import * ", but it looks as if it did not import the pendown command. Why is that? > > If that's the module you are importing it should work. > > What happens if you try: > import turtle turtle.pendown() > > Do you still get the error? > > If so can you cut n paste the entire session, including the initial > python startup message and the error message, into a mail for us? > > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Turtle
On Sat, Jun 18, 2016 at 08:46:53PM -0700, Hershel Millman wrote: > > I followed your instruction and typed "import turtle" into the terminal on > > my mac, and nothing happened. If you're talking about the Python prompt, that's good. That means turtle is installed. Importing a module either succeeds, or gives a traceback. Compare the difference between these two imports: py> import turtle py> import octopus Traceback (most recent call last): File "", line 1, in ImportError: No module named 'octopus' [...] > > In pycharm, when I enter the following, it replies with the > > following error message: > > > > from turtle import * > > > > def drawSquare(size=100): > >turtle.pendown() [...] > > Traceback (most recent call last): > > File "/Users/Hershel/PycharmProjects/Project 1/practicefornotturtle.py", > > line 14, in > >drawSquare(50) > > File "/Users/Hershel/PycharmProjects/Project 1/practicefornotturtle.py", > > line 4, in drawSquare > >turtle.pendown() > > NameError: global name 'turtle' is not defined This is the difference between plain "import" and "from ... import". Here is a simplified example that hopefully will be clear: py> import math py> math.pi 3.141592653589793 py> pi Traceback (most recent call last): File "", line 1, in NameError: name 'pi' is not defined With a regular import, the math module is loaded and made available using the module name. To see inside the module, you have to use the dot operator (it's not really an operator, but I'll call it that) to get access to functions and variables inside the math module. Hence you must say "math.pi". If you say "pi" on its own, Python looks for a variable called pi, doesn't find one, and complains. If I quit out of Python and start again, in a fresh session: py> from math import pi py> math.pi Traceback (most recent call last): File "", line 1, in NameError: name 'math' is not defined py> pi 3.141592653589793 "from ... import" works the opposite way. It still loads the math module, but this time it DOESN'T make it available under that name, so "math.pi" fails. Instead, it cretaes a new variable called pi, set to math.pi. Finally: from math import * doesn't just import pi, but ALL the functions and variables from the math module. That is generally not a good idea. There are very occasional times were it is useful, but in general you should only import what you need: from math import pi, sin, cos or import the entire module: import math -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Fwd: Turtle
On 19/06/16 04:46, Hershel Millman wrote: >> In pycharm, when I enter the following, it replies with the following error >> message: >> >> from turtle import * >> Change that to import turtle and it should work. >> def drawSquare(size=100): >>turtle.pendown() >>turtle.forward(size) >>turtle.left(90) >>turtle.forward(size) >>turtle.left(90) >>turtle.forward(size) >>turtle.left(90) >>turtle.forward(size) >>turtle.left(90) >> >> drawSquare(50) >> >> input () -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: Turtle
Begin forwarded message: > From: Hershel Millman > Date: June 18, 2016 2:39:21 PM MST > To: Steven D'Aprano > Subject: Re: [Tutor] Turtle > > Steven, > > I followed your instruction and typed "import turtle" into the terminal on my > mac, and nothing happened. > > When I entered the following, a new window was created in which the turtle > behaved exactly like it was supposed to. > > for i in range(4): > ...turtle.right(90) > ...turtle.forward(200) > > In pycharm, when I enter the following, it replies with the following error > message: > > from turtle import * > > def drawSquare(size=100): >turtle.pendown() >turtle.forward(size) >turtle.left(90) >turtle.forward(size) >turtle.left(90) >turtle.forward(size) >turtle.left(90) >turtle.forward(size) >turtle.left(90) > > drawSquare(50) > > input () > > Traceback (most recent call last): > File "/Users/Hershel/PycharmProjects/Project 1/practicefornotturtle.py", > line 14, in >drawSquare(50) > File "/Users/Hershel/PycharmProjects/Project 1/practicefornotturtle.py", > line 4, in drawSquare >turtle.pendown() > NameError: global name 'turtle' is not defined > > Process finished with exit code 1 > > Thank you, > > Hershel > > On Jun 18, 2016, at 2:00 AM, Steven D'Aprano wrote: > >> On Fri, Jun 17, 2016 at 11:25:40PM -0700, Hershel Millman wrote: >>> Hello tutors, >>> >>> I have been learning basic python on my Macintosh computer and >>> everything I have tried so far has worked, except when I tried to use >>> the turtle module. I then used my Linux computer and the turtle module >>> still did not work. >> >> What does "did not work" mean? >> >> Did you get an error message? Blue Screen Of Death? Computer caught >> fire? >> >> I see later on that you are running PyCharm. Let's try this with the >> default Python interpreter. Open a terminal window. You should see a >> prompt ending with a dollar sign $ e.g. on my computer I see: >> >> [steve@ando ~]$ >> >> Type the command "python" without quotes, and hit Enter. You should get >> a message about the version of Python you are running, and a >>> prompt. >> This is the Python interpreter. Now enter: >> >> import turtle >> >> What happens? Do you get an error? >> >> If not, what happens if you enter these lines? >> >> turtle.shape('turtle') >> for i in range(4): >> turtle.right(90) >> turtle.forward(200) >> >> (Hit the TAB key at the beginning of the last two lines to get the >> indent. When you have finished typing, you will need to enter one extra >> time to have Python run the code.) >> >> Describe what happens. Do you get an error? If you do, copy and paste >> the ENTIRE error message, starting with the line "Traceback". >> >> >> >>> I tried to use the command line and type "sudo dnf >>> install turtle", "sudo pip install turtle", and it told me "no package >>> turtle available". >> >> That's because turtle is part of the standard library. It's already >> installed. If you run: >> >> locate turtle.py >> >> from your Linux or Mac OS X shell (not from Python!) you should see a >> list of at least one turtle.py files. >> >> >>> I tried to install Python-tk and python3-tk, and I >>> was told that no packages by those names were available. I also tried >>> reinstalling python 2 and python 3, to no avail. >> >> Reinstalling Python should be the *last* resort, not the first, or >> second. >> >> >> >> -- >> Steve >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor