Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 7th, 2013, 09:31 AM
Nik's Avatar
Nik Nik is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: Thessaloniki
Posts: 1,095 Nik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 22 h 44 m 18 sec
Reputation Power: 11
Send a message via Google Talk to Nik
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!

Reply With Quote
  #2  
Old March 7th, 2013, 09:46 AM
partoj partoj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 138 partoj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 59 m 48 sec
Reputation Power: 1
Quote:
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.

Reply With Quote
  #3  
Old March 7th, 2013, 10:00 AM
Nik's Avatar
Nik Nik is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: Thessaloniki
Posts: 1,095 Nik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 22 h 44 m 18 sec
Reputation Power: 11
Send a message via Google Talk to Nik
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.

Reply With Quote
  #4  
Old March 7th, 2013, 10:23 AM
Nik's Avatar
Nik Nik is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: Thessaloniki
Posts: 1,095 Nik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 22 h 44 m 18 sec
Reputation Power: 11
Send a message via Google Talk to Nik
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?

Reply With Quote
  #5  
Old March 7th, 2013, 11:48 AM
Nik's Avatar
Nik Nik is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: Thessaloniki
Posts: 1,095 Nik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 22 h 44 m 18 sec
Reputation Power: 11
Send a message via Google Talk to Nik
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.

Reply With Quote
  #6  
Old March 7th, 2013, 04:59 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,458 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 4 Days 6 h 26 m 43 sec
Reputation Power: 403
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!

Reply With Quote
  #7  
Old March 7th, 2013, 06:57 PM
Nik's Avatar
Nik Nik is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2003
Location: Thessaloniki
Posts: 1,095 Nik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 22 h 44 m 18 sec
Reputation Power: 11
Send a message via Google Talk to Nik
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > About os.system argument

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap