Python windows interactive.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • notejam

    #1

    Python windows interactive.

    I am trying to get started with a interactive version of Python for
    windows and need some help.
    I have played with the tutorial, and now want to write a program.

    In basic language, I could write something like
    10 print "hello"
    20 print "Jim"

    and if I run it I would get
    hello
    Jim

    How do I do sometihing simple like that in python?
    How do I enter line numbers, or if none, what do I do.
    Can the interpreter load a text file with my program in it?
    How do I list a program or the parts of a program I am interested in
    looking at?

    How do I run a python program?

  • robfalck

    #2
    Re: Python windows interactive.

    edit a plain text file, just type one line


    print "hello, world"


    Now save that one-line text file as "hello.py". From the command line,
    in the same directory, type:

    python hello.py


    And it should run your script. Python doesnt require line numbers.

    Happy coding.

    Comment

    • abcd

      #3
      Re: Python windows interactive.

      How do I do sometihing simple like that in python?

      print "hello"
      print "Jim"
      How do I enter line numbers, or if none, what do I do.
      no line numbers needed
      Can the interpreter load a text file with my program in it?
      read in a text file:
      data = open("something .txt").read()
      How do I list a program or the parts of a program I am interested in
      looking at?
      say you want to know what you can do with a list....
      x = [1,2,3,4,5]

      dir(x)
      help(x)
      help(x.append)
      >
      How do I run a python program?
      create a file, type some code. then to at the end of the file (put
      this)...

      if __name__ == "__main__":
      # call your functions here

      this will let you run it from command line like this:
      c:python foo.py

      Comment

      • Paul McGuire

        #4
        Re: Python windows interactive.

        "notejam" <notejam@sbcglo bal.netwrote in message
        news:1162241672 .682830.189240@ b28g2000cwb.goo glegroups.com.. .
        >I am trying to get started with a interactive version of Python for
        windows and need some help.
        I have played with the tutorial, and now want to write a program.
        >
        In basic language, I could write something like
        10 print "hello"
        20 print "Jim"
        >
        and if I run it I would get
        hello
        Jim
        >
        How do I do sometihing simple like that in python?
        How do I enter line numbers, or if none, what do I do.
        Can the interpreter load a text file with my program in it?
        How do I list a program or the parts of a program I am interested in
        looking at?
        >
        How do I run a python program?
        >
        Hmmm, exactly how much have you "played with the tutorial"? I think if you
        go back and play some more, you will answer many of these questions for
        yourself.

        In fact, you should find Python to be quite friendly to your past
        experience. For example, if you take your basic language example, remove
        the line numbers (Python doesn't use them, and many modern Basics don't
        either), and just enter the same print statements at the Python command
        line, you should get the exact same output.

        Python editing doesn't require a specialized development environment (the
        way VisualBasic does, for example). Python programs are simply text files,
        usually saved with a .py extension, that you create, view, print, list, etc.
        using any plain text editor. (Note: Windows WordPad does not fall in this
        category - like a slimmed-down version of Word, WordPad inserts many special
        binary characters for text formatting, which is not at all Python-friendly.)

        If you use a simple text editor like notepad, enter those same two lines
        above (remember, without the line numbers) in a text file, name it
        "HelloJimThisIs YourFirstPython Program.py", then open a console window, set
        your working directory to the same directory where you saved
        HelloJimThisIsY ourFirstPythonP rogram.py, and enter at the command line:
        "python HelloJimThisIsY ourFirstPythonP rogram.py" (leave off the quotes, they
        are just there in this message to show you what to type), you should get the
        same output. And voila! you have run your Python program.

        I've left out a lot, because there is quite a bit of meat in the tutorials
        already available. Also, there are more tutorials than just the official
        one, google about a bit and you should find quite a bit of entry-level
        material.

        Lastly, before posting again, please review the Python FAQ's at
        http://www.python.org/doc/faq/. Don't be another one to exclaim "Shoot! I
        wish I'd checked the FAQ's before posting that newbie question that everyone
        is tired of hearing again and again!"

        Best of luck to you in your new Python adventure!
        -- Paul


        Comment

        • Larry Bates

          #5
          Re: Python windows interactive.

          notejam wrote:
          I am trying to get started with a interactive version of Python for
          windows and need some help.
          I have played with the tutorial, and now want to write a program.
          >
          In basic language, I could write something like
          10 print "hello"
          20 print "Jim"
          >
          and if I run it I would get
          hello
          Jim
          >
          How do I do sometihing simple like that in python?
          How do I enter line numbers, or if none, what do I do.
          Can the interpreter load a text file with my program in it?
          How do I list a program or the parts of a program I am interested in
          looking at?
          >
          How do I run a python program?
          >
          Start with the tutorial here:

          Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax an...


          Your program in python would be:

          print "hello"
          print "jim"

          You don't have line numbers in Python

          Yes the interpreter can load a text file with your program.
          A good "beginners" version of Python for windows is:



          It has an easy to use interpreter window with both your
          program and interactive prompt open on the screen.

          To run a program you click run icon. To run outside the
          interpreter you type python programname.py

          -Larry

          Comment

          • notejam

            #6
            Re: Python windows interactive.

            Thanks everyone for the help. I got a simple two line program to work
            from a text file.
            Can not figure out how to write more than one line in interpreter mode.
            Is that all interpreter is good for, testing one liners? I have it
            run the program everytime I hit return, and can not figure out how to
            enter multiple lines of code. I can do multiple lines in text file, so
            no problem, but I am jsut wondering can a program with 2 or more lines
            be wrote from the interpreter mode?





            Larry Bates wrote:
            notejam wrote:
            I am trying to get started with a interactive version of Python for
            windows and need some help.
            I have played with the tutorial, and now want to write a program.

            In basic language, I could write something like
            10 print "hello"
            20 print "Jim"

            and if I run it I would get
            hello
            Jim

            How do I do sometihing simple like that in python?
            How do I enter line numbers, or if none, what do I do.
            Can the interpreter load a text file with my program in it?
            How do I list a program or the parts of a program I am interested in
            looking at?

            How do I run a python program?
            Start with the tutorial here:
            >
            Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax an...

            >
            Your program in python would be:
            >
            print "hello"
            print "jim"
            >
            You don't have line numbers in Python
            >
            Yes the interpreter can load a text file with your program.
            A good "beginners" version of Python for windows is:
            >

            >
            It has an easy to use interpreter window with both your
            program and interactive prompt open on the screen.
            >
            To run a program you click run icon. To run outside the
            interpreter you type python programname.py
            >
            -Larry

            Comment

            • BartlebyScrivener

              #7
              Re: Python windows interactive.

              Try this, assuming you're in IDLE.



              You can enter as many lines as you want in the interpreter. Then press
              ENTER twice to get the result.

              Or try here if you're looking for some tutorials.

              Critically-acclaimed novelist Richard Dooling is the author of five novels, along with two nonfiction works.


              rd

              Comment

              • Gabriel Genellina

                #8
                Re: Python windows interactive.

                At Monday 30/10/2006 21:15, notejam wrote:
                >Thanks everyone for the help. I got a simple two line program to work
                >from a text file.
                >Can not figure out how to write more than one line in interpreter mode.
                Is that all interpreter is good for, testing one liners? I have it
                >run the program everytime I hit return, and can not figure out how to
                >enter multiple lines of code. I can do multiple lines in text file, so
                >no problem, but I am jsut wondering can a program with 2 or more lines
                >be wrote from the interpreter mode?
                The command-line interpreter (python.exe), in interactive mode, is
                just for testing purposes: one or two lines or code.
                You could write your program in a file (using notepad by example),
                save it with filename.py, and run it using: python filename.py
                There are some integrated environments for working in python. IDLE
                already comes with your Python installation. For Windows you can get
                PythonWin <http://sourceforge.net/projects/pywin32/>


                --
                Gabriel Genellina
                Softlab SRL

                _______________ _______________ _______________ _____
                Correo Yahoo!
                Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
                ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar

                Comment

                • Steve Holden

                  #9
                  Re: Python windows interactive.

                  notejam wrote:
                  Thanks everyone for the help. I got a simple two line program to work
                  from a text file.
                  Can not figure out how to write more than one line in interpreter mode.
                  Is that all interpreter is good for, testing one liners? I have it
                  run the program everytime I hit return, and can not figure out how to
                  enter multiple lines of code. I can do multiple lines in text file, so
                  no problem, but I am jsut wondering can a program with 2 or more lines
                  be wrote from the interpreter mode?
                  >
                  The interactive interpreter is mostly for experimentation , but of course
                  its advantage is that you can test out complex functionality imported
                  from modules and packages. Want to know what's on the Google home page?
                  >>import urllib
                  >>f = urllib.urlopen( "http://www.google.com" )
                  >>data = f.read()
                  >>print data
                  <html><head><me ta http-equiv="content-type" content="text/html;
                  charset=ISO-8859
                  -1"><title>Googl e</title><style><!--
                  body,td,a,p,.h{ font-family:arial,sa ns-serif}
                  ..h{font-size:20px}
                  ..q{color:#00c}
                  --></style>
                  <script>
                  <!--
                  function sf(){document.f .q.focus();}
                  // -->
                  </script>
                  </head><body bgcolor=#ffffff text=#000000 link=#0000cc vlink=#551a8b
                  alink=#ff0000 onload=sf() topmargin=3 marginheight=3> <center><div
                  align=right nowrap style="padding-bottom:4px" width=100%><fon t size=-1...
                  <font size=-2>&copy;2006 Google</font></p></center></body>
                  </html>
                  >>>
                  You can also define funcitons and classes, and write multi-line
                  statements interactively once you learn the conventions, but once
                  functionality "hardens" into something of five lines or more that you
                  want to experiment with you will find it's usually easier to edit a
                  script or program in a text file and run it. This is even more the case
                  when you start to use "test-driven development", something we shoudl all
                  aspire to.

                  regards
                  Steve
                  --
                  Steve Holden +44 150 684 7255 +1 800 494 3119
                  Holden Web LLC/Ltd http://www.holdenweb.com
                  Skype: holdenweb http://holdenweb.blogspot.com
                  Recent Ramblings http://del.icio.us/steve.holden

                  Comment

                  • Hendrik van Rooyen

                    #10
                    Re: Python windows interactive.


                    "notejam" <notejam@sbcglo bal.netTop posted:
                    Thanks everyone for the help. I got a simple two line program to work
                    from a text file.
                    Can not figure out how to write more than one line in interpreter mode.
                    Is that all interpreter is good for, testing one liners? I have it
                    run the program everytime I hit return, and can not figure out how to
                    enter multiple lines of code. I can do multiple lines in text file, so
                    no problem, but I am jsut wondering can a program with 2 or more lines
                    be wrote from the interpreter mode?
                    the interactive interpreter remembers the stuff you type.

                    so you can assign values to variables, and refer to them later.
                    you can define functions and call them later

                    that is enough to start with.

                    try it - you will like it...

                    - Hendrik



                    Comment

                    • Fredrik Lundh

                      #11
                      Re: Python windows interactive.

                      notejam wrote:
                      Can not figure out how to write more than one line in interpreter mode.
                      press return between the lines. if you get a "..." prompt, keep adding
                      more lines to the current statement. press return an extra time to end
                      the multiline-statement.
                      Is that all interpreter is good for, testing one liners? I have it
                      run the program everytime I hit return
                      no, it executes the *current statement* when you press return. a
                      program consists usually consists of many statements.
                      and can not figure out how to enter multiple lines of code.
                      if you'd entered a statement that actually consisted of multiple lines,
                      you'd noticed (try entering an "if"-statement, for example).
                      I am jsut wondering can a program with 2 or more lines
                      be wrote from the interpreter mode?
                      Type "help", "copyright" , "credits" or "license" for more information.
                      >>import urllib
                      >>def gettitle(url):
                      .... f = urllib.urlopen( url)
                      .... s = f.read()
                      .... i = s.find("<title> ")
                      .... j = s.find("</title>", i)
                      .... return s[i+7:j]
                      ....
                      >>gettitle("htt p://www.python.org" )
                      'Python Programming Language -- Official Website'
                      >>gettitle("htt p://www.cnn.com")
                      'CNN.com - Breaking News, U.S., World, Weather, Entertainment &amp;
                      Video News'
                      >>sites = ["http://news.bbc.co.uk" , "http://reddit.com",
                      .... "http://www.fbi.gov"
                      .... ]
                      >>for site in sites:
                      .... print gettitle(site)
                      ....
                      BBC NEWS | News Front Page
                      reddit.com: what&#39;s new online
                      Federal Bureau of Investigation - Home Page
                      >>>
                      etc.

                      </F>

                      Comment

                      Working...