Python Programming

Discussion in 'Mac Programming' started by FDomin16, Apr 7, 2013.

  1. FDomin16 macrumors newbie

    Apr 7, 2013
    Fremont, Ca
    I'm new to programming and I decided to begin with Python. I downloaded Python 3.3 and I'm using the book "Python Programming: An Introduction to Computer Science 2nd edition". In the book there is an exercise to make a module file. I wrote the file in IDLE and I saved it as in my documents. After I open a new IDLE and I try to import the file it comes up with this:

    >>> import chaos
    Traceback (most recent call last):
    File "<pyshell#0>", line 1, in <module>
    import chaos
    File "./", line 1
    Python 3.3.1 (v3.3.1:d9893d13c628, Apr 6 2013, 10:32:10)
    SyntaxError: invalid syntax

    As I said before, I am new to programming and I don't know what to do.
  2. ytk macrumors regular

    Jul 8, 2010
  3. stueee123 macrumors member

    Nov 24, 2011
    What I always did when i used IDLE was to first save it as a .py file like you did, and then just double click it in Finder and select "Run"

    Why are you trying to import it? just run it
  4. estorstenson macrumors member

    Jan 30, 2013
    It's been years since I used idle, but my guess is that it saved that line you see (above the ^ character) when you saved the session to a file and that line (and possibly others) are not valid python syntax.

    Open the file you created inside a plain text editor (not something like word) and remove or comment any line that wasn't part of what you were supposed to type in the previous exercise. Once you save it, then it should work just fine.

    If you have text that gets printed out by your program, you might want to use instead of double clicking to run the script. As a programmer, it is always good to learn to use the terminal. It can be found /Applications/Utilities/ As a profession developer, I have it set to stay inside my dock (and it opens up after I restart). I spend roughly 50% of my work day inside the terminal.

Share This Page