LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-22-2010, 01:59 PM   #1
madsovenielsen
Member
 
Registered: Aug 2009
Posts: 183

Rep: Reputation: 15
Writing files with python produces blank 0KB file


Hey all.

I am working on a little project in python. i have produced this prototype

Code:
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-

#DocC documentation prototype

sitestructure = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title></title><style type="text/css">pre {background-color: #DDFFDD;border: solid 1px #BBDDBB;padding: 10px;}.notice {background-color: #DDDDFF;border: solid 1px #BBBBFF;}b {font-size: 0.8em;}</style></head><body><h1>Documentation</h1>'

userinput = raw_input("Please specify file path: ")
input = file(userinput, "r")
source_code = input.read()

source_code = source_code.replace("<","&lt;")
source_code = source_code.replace(">","&gt;")

userinput = userinput + ".html"

sitecontent = sitestructure + "<pre>" + source_code + "</pre>" + "</body></html>"

sample_file = file(userinput, "w")
sample_file.write(sitecontent)

raw_input("Pause")
Its producing a blank file. no error messages or nothing. whats wrong ?

/mads
 
Old 06-22-2010, 03:15 PM   #2
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
try to close the output file before quitting...

Code:
sample_file.close ()
quit()
 
Old 06-22-2010, 03:38 PM   #3
madsovenielsen
Member
 
Registered: Aug 2009
Posts: 183

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by marozsas View Post
try to close the output file before quitting...

Code:
sample_file.close ()
quit()
Thanks a lot. that did the trick.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python: socket broadcast produces a broken pipe eantoranz Programming 2 04-14-2009 08:24 AM
redirect stdout to file produces blank file kissaki Linux - Software 5 01-06-2009 03:28 AM
scanner produces only gray blank bezdomny Linux - Hardware 0 08-12-2008 08:58 PM
Dosemu fullscreen produces a blank screen dgsmithsgu Linux - Software 0 02-05-2008 04:10 PM
Print Test page produces 11 blank pages zeeple Linux - Hardware 4 07-27-2007 03:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration