473,837 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Output File

Is there a limit on the size of the file Python will read then output. I am
reading a file of 433 lines and when I output the same file it only will
output 421 lines. The last line is cut off also. This is the code I am using
as a test.

input = open(r'C:\Docum ents and Settings\Owner\ Desktop\somefil e.html','r')
L = input.readlines ()
input.close

output = open(r'C:\Docum ents and
Settings\Owner\ Desktop\somefil e_test.html','w ')
for t in range(len(L)):
output.writelin es(L[t])
output.close

Also is there a way to test for EOF in Python?
Thanks
S
Jul 18 '05 #1
2 1878
Samantha wrote:
input = open(r'C:\Docum ents and Settings\Owner\ Desktop\somefil e.html','r')
L = input.readlines ()
input.close

output = open(r'C:\Docum ents and
Settings\Owner\ Desktop\somefil e_test.html','w ')
for t in range(len(L)):
output.writelin es(L[t])
output.close
I think you want to do [1]:

input = open(r'somefile .html', 'r')
lst = input.readlines ()
input.close() # note the () -- this is a method call

output = open(r'somefile _test.html', 'w')
output.writelin es(lst) # not in a for-loop
output.close() # note the () -- this is a method call

If you really want to use a for-loop, the code should look like:

for line in L:
output.write(li ne)

If you call writelines when you only want to write one line, you're
going to get odd behavior -- Python's going to interpret each character
in your line as a "line" itself.
Also is there a way to test for EOF in Python?


file.read() or file.readline() will return '' if you have reached the
end of the file.

STeVe

[1] In fact, what you really probably want to do is to take advantage of
the fact that a file is an iterator. You can write:

input = open(r'somefile .html', 'r')
output = open(r'somefile _test.html', 'w')
output.writelin es(input)

And the lines of somefile.html will be written to somefile_test.h tml.
You might also look at the shutil module.
Jul 18 '05 #2
Thanks Steve. Appreciate it!
S
"Steven Bethard" <st************ @gmail.com> wrote in message
news:67******** ************@co mcast.com...
Samantha wrote:
input = open(r'C:\Docum ents and
Settings\Owner\ Desktop\somefil e.html','r')
L = input.readlines ()
input.close

output = open(r'C:\Docum ents and
Settings\Owner\ Desktop\somefil e_test.html','w ')
for t in range(len(L)):
output.writelin es(L[t])
output.close


I think you want to do [1]:

input = open(r'somefile .html', 'r')
lst = input.readlines ()
input.close() # note the () -- this is a method call

output = open(r'somefile _test.html', 'w')
output.writelin es(lst) # not in a for-loop
output.close() # note the () -- this is a method call

If you really want to use a for-loop, the code should look like:

for line in L:
output.write(li ne)

If you call writelines when you only want to write one line, you're going
to get odd behavior -- Python's going to interpret each character in your
line as a "line" itself.
Also is there a way to test for EOF in Python?


file.read() or file.readline() will return '' if you have reached the end
of the file.

STeVe

[1] In fact, what you really probably want to do is to take advantage of
the fact that a file is an iterator. You can write:

input = open(r'somefile .html', 'r')
output = open(r'somefile _test.html', 'w')
output.writelin es(input)

And the lines of somefile.html will be written to somefile_test.h tml. You
might also look at the shutil module.

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
6999
by: Chuck Amadi | last post by:
Sorry to bovver you again (again) here's script. I still can't see why the get_payload() doesn't produce the plain text message body of an emails in the testwwws users mailbox. As you can see I have tried a few things but no joy what am I missing. Is the another snippet in relation to get_payload to access the body contents print and process to a file. Cheers
4
2711
by: Richard Tierney | last post by:
To create help output (the response to "myprog --help", for example) I currently create a big .h file, which includes a single string, such as: static char *help_text = "\ myprog: my program\n\ loads and\n\ loads of\n\ painfully manually\n\ formatted and\n\
10
8182
by: tram | last post by:
How do we pass on the step1 output file to step2 of the same job? I would like to know the current job's output file programmetically, instead of hard coding it. Any idaes would be appreciated. Thanks
1
4362
by: Andrew | last post by:
I'm adding this as it to me a while to figure out all the pieces to be able to do this without using Microsoft.Office.Interop which caused me problems on the web-server. Streaming is the easy part, but I couldn't initially work out how to manipulate the page setup to change page margins and orientation, that's why I was looking at Microsoft.Office.Interop. But with Microsoft.Office.Interop I couldn't fiure out how to stream HTML...
3
6118
by: John Williams | last post by:
I'm writing a stagenography program to experiment with how it works. The algorithm I'm using appears to be producing the correct result...however I'm struggling with the file input. I never learned file input/output very well (I self taught all the programming I know...and my c++ book was not good) and so I'm not sure what's wrong with this. The problem is the function void encodemsg(fstream *img, fstream *msg, fstream *out, char key) ...
3
4668
by: undshan | last post by:
I am writing a code that needs to open a file, create an output file, run through my function, prints the results to the output file, and closes them within a loop. Here is my code: #include <stdlib.h> #include <stdio.h> #include <math.h> #include <string.h> #include "util.h" //Main Loop
1
3616
by: yohan610 | last post by:
i have to read the binary data of a file, then encrypt them according to a supplied algorithm...and then the obtained output has to be written to an output file...everything works ok, and there are no errors... but when i print out the binary data from the input file it seems to be the same whtever the file, and then after encrypting and wirting the data to the output file, the output file has a size of 0KB and nothing in it..pls help as soon...
0
1819
by: jebbyleezer | last post by:
Hello, I have source code that builds correctly, however, after the program terminates the output file produced is empty. Here is my source code: import java.io.*; import java.util.Scanner; public class project { public static void main( String args ) {
14
12838
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in case it's a question, i want to popup a messageBox or something, and bring back to the batch file the result (Yes\No question). I know how to excute the batch file and get all the Standard output at the end, but i don't know who can i read it line by...
5
3336
by: amit.uttam | last post by:
Hey everyone, I've recently jumped big time into python and I'm working on a software program for testing automation. I had a question about proper logging of output. What I would like is: 1. a function syslog (to log output to log file only) 2. a function stdout (to log output to stdout only) 3. a function sslog (to log output to both log and stdout)
0
9851
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10902
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10583
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10286
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7824
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7013
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5680
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4481
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.