#1
  1. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13

    Question About os.system argument


    I see that the return value of os.system its an indicator to as if the command inside os.system() returned successfully.

    So i guess ill be needing somethign like this:

    Code:
    htmltemp = '/home/nikos/www/data/private/htmltemp' 
    
    if htmlpage.endswith('.html'): 
            f = open( "/home/nikos/www/" + htmlpage ) 
            htmldata = f.read() 
    elif htmlpage.endswith('.py'): 
            os.system( 'python metrites.py > %s' ) % htmltemp 
            f = open( htmltemp ) 
            htmldata = f.read() 
    
    template = htmldata + counter
    ==============

    which i just tried and now iam receiving this:

    <type 'exceptions.TypeError'>: unsupported operand type(s) for %: 'int' and 'str'

    I'am very close to the solution now i cna feel it but please help a bit!
    What is now proved was once only imagined!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    138
    Rep Power
    2
    Originally Posted by Nik
    I see that the return value of os.system its an indicator to as if the
    Code:
    [...]
            os.system( 'python metrites.py > %s' ) % htmltemp 
    [...]
    ==============

    which i just tried and now iam receiving this:

    <type 'exceptions.TypeError'>: unsupported operand type(s) for %: 'int' and 'str'
    You want to put 'htmltemp' within the os.system() call. Otherwise, os.system() returns a return value (int) which python then tries to concatenate with htmltemp (string).
    Code:
    [...]
            os.system( 'python metrites.py > %s' % htmltemp )
    [...]
    Also, please post the entire stack trace when you get an error.
  4. #3
  5. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13
    Thank you! i can beleive it was a matter of aprenthesis!

    Now instead of receiving proper html output i receive this:

    Go to http://superhost.gr please and click the 1st image you see on the top.
    Instead for the pelatologio.py html output to appear + counter string

    i see weird formatting, if you want please take a look.
    What is now proved was once only imagined!
  6. #4
  7. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13
    I have fixed this!
    Still ahve allok and you will see that in both of my images they appear in the firstpage of superhost.gr

    the output of .py files appear fine except of that ehen a visitor click on my first 2 image links he also sees as first line this:

    print ( "Content-type: text/html; charset=utf-8\n" )

    this is because the above code is a header and its contained to every cgi .py file that i generate html ouput from via os.system()

    Can this be somehow eliminated?
    What is now proved was once only imagined!
  8. #5
  9. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13
    But those are *.py's script output! but the webpage application works ok! i just need to eliminate the line print ( "Content-type: text/html; charset=utf-8\n" )

    Its because that line doesn;t actully run but instead its printed as normal text that makes these pages not valid html pages.
    What is now proved was once only imagined!
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,997
    Rep Power
    481
    I didn't see funny formatting at the web page.
    I think you fixed it before I looked.
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2003
    Location
    Thessaloniki
    Posts
    1,285
    Rep Power
    13
    Apart from appearing ugly its not causing any more trouble(other than some issues that i have fixed), so i will just do:

    Code:
            os.system( 'python %s > %s' % (htmlpage, temp) ) 
            f = open( temp ) 
            htmldata = f.read() 
            htmldata = htmldata.replace( 'Content-type: text/html; charset=utf-8', '' )

    But i wonder by runnign this system.os() command and saving its html output to a temp file no vaild html data is being produced.

    So is it really correct?

    Can i somehow make the .py code run as a .py script?
    What is now proved was once only imagined!

IMN logo majestic logo threadwatch logo seochat tools logo