opening a file from textwrangler

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aphymans
    New Member
    • Mar 2010
    • 4

    opening a file from textwrangler

    Hi everyone:

    So, I'm really new to python and I cannot figure out how to open my file using TextWranger. For example, I have a file called fun.py with this information in it:

    import turtle

    turtle.forward( 100)

    raw_input()

    and everytime I call the file in the terminal using ~/Desktop (the file is on my desktop) and then call python fun.py, I get this message:

    >>> python fun.py
    File "<stdin>", line 1
    python fun.py
    ^
    SyntaxError: invalid syntax
    >>>
    what's the matter with my syntax? I'm very confused and frustrated. Thanks!!
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    It works fine at the command prompt. What is "TextWrange r"?

    Comment

    • Glenton
      Recognized Expert Contributor
      • Nov 2008
      • 391

      #3
      TextWrangler is an IDE.

      I'm guessing you're using linux of some flavour? Try putting #!/usr/bin/env python as the first line of your text file. This is good practice for all python scripts.

      Although I use geany, and it doesn't seem to need this, it typically is needed if you run from terminal.

      Let us know how it goes...

      Comment

      • aphymans
        New Member
        • Mar 2010
        • 4

        #4
        it still doesn't work. i used my same format and it worked perfectly on another computer, and it used to work on mine, but now it just doesn't work and i keep getting that message.

        Comment

        • Glenton
          Recognized Expert Contributor
          • Nov 2008
          • 391

          #5
          You're going to have to give us some more clues, I'm afraid.

          I suspect there's relatively few textwranglers here (I've never used it either), but I also suspect that it's not the problem.

          I just tried the following:
          -I saved the file to fun.py on my Desktop,
          -opened a terminal
          -typed cd Desktop,
          -typed python fun.py
          and it worked fine.

          So let's try this systematically:
          1. What's your operating system?
          2. Is python installed on this machine?
          3. What happens if you just type "python" at the terminal?
          4. What happens if you type "ls" or "dir" at the terminal in Desktop?

          Comment

          • aphymans
            New Member
            • Mar 2010
            • 4

            #6
            I have OS 10.5.6

            yes, I have python

            If I type python this comes up:
            Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
            [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
            Type "help", "copyright" , "credits" or "license" for more information.
            >>>

            when I type Is:
            -bash: Is: command not found

            when I type dir:
            >>> dir
            <built-in function dir>
            >>>

            Comment

            • Glenton
              Recognized Expert Contributor
              • Nov 2008
              • 391

              #7
              Okay. Sorry, I meant you to type "ls" or "dir" at the command prompt, not in the python command line (which is where you were after you typed python). You can exit the python command line by typing exit(), or just restarting your command prompt.

              Let us know what the dir command gives in this condition.

              Good luck!

              Comment

              • aphymans
                New Member
                • Mar 2010
                • 4

                #8
                okay, so for some weird reason i did the exact same thing i have been doing and python finally worked! im so happy. thank you so much for all your help, glenton.

                Comment

                Working...