simple print is not working..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lahirister@gmail.com

    #1

    simple print is not working..

    What is wrong with this script?

    #!/usr/bin/python
    fsfile = open('/tmp/fs_info.al', 'r')
    for line in fsfiles.readlin es():
    print line
    fsfile.close()


    #./get_fs_info.py
    File "./get_fs_info.py" , line 4
    print line
    ^
    SyntaxError: invalid syntax


    Any ideas?

    Thanks
    AL

  • lahirister@gmail.com

    #2
    Re: simple print is not working..


    lahiris...@gmai l.com wrote:

    Sorry typo: Script is like this:

    #!/usr/bin/python
    fsfile = open('/tmp/fs_info.al', 'r')
    for line in fsfile.readline s():
    print line
    fsfile.close()

    *not* fsfiles as I typed in original post.
    [color=blue]
    > What is wrong with this script?
    >
    > #!/usr/bin/python
    > fsfile = open('/tmp/fs_info.al', 'r')
    > for line in fsfiles.readlin es():
    > print line
    > fsfile.close()
    >
    >
    > #./get_fs_info.py
    > File "./get_fs_info.py" , line 4
    > print line
    > ^
    > SyntaxError: invalid syntax
    >
    >
    > Any ideas?
    >
    > Thanks
    > AL[/color]

    Comment

    • Carl J. Van Arsdall

      #3
      Re: simple print is not working..

      lahirister@gmai l.com wrote:[color=blue]
      > What is wrong with this script?
      >
      > #!/usr/bin/python
      > fsfile = open('/tmp/fs_info.al', 'r')
      > for line in fsfiles.readlin es():
      > print line
      > fsfile.close()
      >
      >
      >[/color]
      Did you cut and paste that code? I see a couple typos

      First, on the line

      for line in fsfiles.readlin es():

      There's an extra s in fsfile

      Secondly, the line:

      print line

      should have an indentation to denote that its the block of code that the
      for loop will execute on.

      ..c



      --

      Carl J. Van Arsdall
      cvanarsdall@mvi sta.com
      Build and Release
      MontaVista Software

      Comment

      • Paul Osman

        #4
        Re: simple print is not working..

        On 24-May-06, at 3:41 PM, lahirister@gmai l.com wrote:
        [color=blue]
        > What is wrong with this script?
        >
        > #!/usr/bin/python
        > fsfile = open('/tmp/fs_info.al', 'r')
        > for line in fsfiles.readlin es():
        > print line
        > fsfile.close()
        >
        >
        > #./get_fs_info.py
        > File "./get_fs_info.py" , line 4
        > print line
        > ^
        > SyntaxError: invalid syntax
        >
        >
        > Any ideas?
        >
        > Thanks
        > AL[/color]

        Well first, you have to indent properly :) Assuming you did that and
        the copy & paste just removed it, you're also creating a variable
        called fsfile, then trying to call the readlines() method on an
        object called fsfiles... that'll cause a problem.

        Cheers,

        --
        Paul Osman

        Comment

        Working...