[Tutor] File IO

2006-08-29 Thread Amadeo Bellotti
Ok im trying to create a file that the user chooses the name of and print a varible that is a string to the text file. but for some reason whne i do this code: FILE = open(filename, "w") FILE.write(puzzleanswers) FILE.close() it doesnt write anything does anyone know how to fix it  so it works? _

[Tutor] File IO

2005-11-03 Thread Michael Haft
Hello, I tried the following code: def readSOMNETM(inputName): input = open(inputName, "r") result = [] for line in input: fields = line.split() data = fields[1] + fields[2] + fields[7] result.append(data) input.close() return result print "Here g

[Tutor] file IO tutorial

2005-07-31 Thread Rob Andrews
http://uselesspython.com/tutorials/PythonFileIOStepByStep.pdf I've written a quick step-by-step .pdf to walk through the process of creating a new text file, read from it, and append to it with Python. It doesn't cover every last thing one can do with opened files, but does point to a few other re

[Tutor] File IO flush

2008-12-08 Thread Sander Sweers
Hello All, I was playing around with the zipfile module and wrote a simple script to unzip a zip file. I then looked around on the internet and found the recipe 252508 [1] on the active state cookbook website. In this recipe the author calls flush() and then close() on a file object being written

Re: [Tutor] File IO

2006-08-29 Thread Kent Johnson
Amadeo Bellotti wrote: > Ok im trying to create a file that the user chooses the name of and print a > varible that is a string to the text file. but for some reason whne i do > this code: > > FILE = open(filename, "w") > FILE.write(puzzleanswers) > FILE.close() > > it doesnt write anything does an

Re: [Tutor] File IO

2006-08-29 Thread Amadeo Bellotti
i do and they have writing but its just not printing it at allOn 8/29/06, Kent Johnson <[EMAIL PROTECTED]> wrote: Amadeo Bellotti wrote:> Ok im trying to create a file that the user chooses the name of and print a > varible that is a string to the text file. but for some reason whne i do> this code

Re: [Tutor] File IO

2006-08-29 Thread Bob Gailer
Amadeo Bellotti wrote: > Ok im trying to create a file that the user chooses the name of and > print a varible that is a string to the text file. but for some reason > whne i do this code: > > FILE = open(filename, "w") > FILE.write(puzzleanswers) > FILE.close() > > it doesnt write anything That

Re: [Tutor] File IO

2006-08-29 Thread Amadeo Bellotti
well i made a typo and puzzleanswers was empty i fixed it and it works fine thank you guys so muchOn 8/29/06, Bob Gailer < [EMAIL PROTECTED]> wrote:Amadeo Bellotti wrote:> Ok im trying to create a file that the user chooses the name of and > print a varible that is a string to the text file. but fo

Re: [Tutor] File IO

2006-08-29 Thread Alan Gauld
>i do and they have writing but its just not printing it at all > How do you know? Where are you looking for the file? Are you sure its not a Path issue? Alan G. > On 8/29/06, Kent Johnson <[EMAIL PROTECTED]> wrote: >> >> Amadeo Bellotti wrote: >> > Ok im trying to create a file that the user

Re: [Tutor] File IO

2006-08-29 Thread Amadeo Bellotti
no no the file shows up in the same directory as the .py file and i no it works cause i read the text fileOn 8/29/06, Alan Gauld < [EMAIL PROTECTED]> wrote:>i do and they have writing but its just not printing it at all >How do you know? Where are you looking for the file?Are you sure its not a Pat

Re: [Tutor] File IO

2006-08-30 Thread Alan Gauld
>> How do you know? Where are you looking for the file? >> Are you sure its not a Path issue? > no no the file shows up in the same directory as the .py file and i > no it > works cause i read the text file OK, In that case can you show us what puzzleanswers looks like? >> > On 8/29/06, Kent Jo

Re: [Tutor] File IO

2006-08-30 Thread Amadeo Bellotti
the code is way to long but i can post the output of puzzleanswers Answer: 6 1 4 2 9 3 8 5 7 8 5 9 1 6 7 2 3 4 2 3 7 8 5 4 9 1 6 7 8 6 9 1 2 5 4 3 4 2 1 3 7 5 6 9 8 3 9 5 4 8 6 1 7 2 9 4 3 5 2 8 7 6 1 5 6 8 7 4 1 3 2 9 1 7 2 6 3 9 4 8 5 for those of you who dont know its a sudoku puzzle if you gu

[Tutor] File IO help

2005-10-26 Thread Mike Haft
Hello all, I'm new to python but so far I have to say its a really good language I've been having some trouble with File IO can anyone help? I've got the basics but my problem is that I have many files (one for each year of the last 100 years or so) that look like this: MONTH RAIN AVTE

Re: [Tutor] File IO

2005-11-03 Thread bob
At 01:34 PM 11/3/2005, Michael Haft wrote: >Hello, > I tried the following code: > >def readSOMNETM(inputName): > input = open(inputName, "r") > result = [] > for line in input: > fields = line.split() # add this; it will show you what line(s) have less than 8 f

Re: [Tutor] File IO

2005-11-03 Thread Mike Haft
I did that and got this: Here goes Enter filename: Name:LAU73M.MET Line too short Monthly Weather Data, LAU73M.MET, converted from: Line too short BAD LAUCHSTAEDT; DAILY METEOROLOGICAL DATA FOR 01/01/1973-31/12/1973 Line too short *

Re: [Tutor] File IO

2005-11-03 Thread Liam Clarke-Hutchinson
Woah, that's way simpler than mine. Liam Clarke-Hutchinson -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of bob Sent: Friday, 4 November 2005 11:01 a.m. To: [EMAIL PROTECTED]; tutor@python.org Subject: Re: [Tutor] File IO At 01:34 PM 11/3/2005, Mi

Re: [Tutor] File IO

2005-11-03 Thread Liam Clarke-Hutchinson
ur problem. In your loop, I'd recommend you check and ignore your header. either - result = [] pastHeader = False for line in input: if not pastHeader: if line.startswith("***"): pastHeader = True #Will be shortly, anyway. continu

Re: [Tutor] File IO

2005-11-03 Thread Carroll, Barry
ields[7]] > -- > Date: Thu, 3 Nov 2005 22:10:02 - (GMT) > From: "Mike Haft" <[EMAIL PROTECTED]> > Subject: Re: [Tutor] File IO > To: "bob" <[EMAIL PROTECTED]> > Cc: tutor@python.org > Message-ID: <[EMAIL PRO

Re: [Tutor] File IO

2005-11-03 Thread Kent Johnson
Michael Haft wrote: > Hello, > I tried the following code: > > def readSOMNETM(inputName): > input = open(inputName, "r") > result = [] > for line in input: > fields = line.split() > data = fields[1] + fields[2] + fields[7] > result.append(data) > input

Re: [Tutor] File IO

2005-11-03 Thread Colin J. Williams
Michael Haft wrote: >Hello, > I tried the following code: > >def readSOMNETM(inputName): >input = open(inputName, "r") >result = [] >for line in input: >fields = line.split() >data = fields[1] + fields[2] + fields[7] >result.append(data) >input.close() >

Re: [Tutor] File IO

2005-11-03 Thread bob
[snip] Colin: your replies to 2 e-mails indicate that you have either not read the e-mails or the prior responses. Please consider the work others put into replying before replying. Example: I suggested % formatting in a reply. You replied to that by saying the same thing.

Re: [Tutor] File IO flush

2008-12-08 Thread Kent Johnson
On Mon, Dec 8, 2008 at 12:15 PM, Sander Sweers <[EMAIL PROTECTED]> wrote: > Hello All, I was playing around with the zipfile module and wrote a > simple script to unzip a zip file. I then looked around on the > internet and found the recipe 252508 [1] on the active state cookbook > website. > > In

[Tutor] File IO Help again

2005-10-27 Thread Mike Haft
Apologies for not making things clearer last time. My specific problems are: why can I not get the readline() or readlines() functions to work, I'm told they are not defined whenever I try. Also the following: if line[:1] == "1": collects data from month 1, 10, 11, and 12. How do I make the re

Re: [Tutor] File IO help

2005-10-28 Thread Kent Johnson
Mike Haft wrote: > Hello all, > I'm new to python but so far I have to say its a really good language > > I've been having some trouble with File IO can anyone help? I've got the > basics but my problem is that I have many files (one for each year of the > last 100 years or so) that look l

Re: [Tutor] File IO help

2005-10-28 Thread Liam Clarke
Oops, filePaths = [os.path.join(direc, item) for item in os.listdir(direc) if not os.path.isdir(os.path.join(direc, item))] should be > filePaths = [os.path.join(dirPath, item) for item in os.listdir(dirPath) > if not os.path.isdir(os.path.join(dirPath, item))] ... __

Re: [Tutor] File IO Help again

2005-10-27 Thread Danny Yoo
On Thu, 27 Oct 2005, Mike Haft wrote: > why can I not get the readline() or readlines() functions to work, I'm > told they are not defined whenever I try. Don't paraphrase. *grin* Show us what you did in terms of the code that you ran. Also, include the literal error message and its tracebac

Re: [Tutor] File IO Help again

2005-10-27 Thread bob
At 12:18 PM 10/27/2005, Mike Haft wrote: >Apologies for not making things clearer last time. > >My specific problems are: > >why can I not get the readline() or readlines() functions to work, I'm >told they are not defined whenever I try. Mike * Oh * Mike ... and all others ... Please Post The Co

Re: [Tutor] File IO Help again

2005-10-27 Thread Adam
>if line[:1] == "1": This line won't work because you're getting the first 2 characters from the line and seeing if it's equal to a string of length one. For example in your test file if you put this line, 1      12.4    12.0    *   10 , through that bit of code it would see if "1 " == "1", which

Re: [Tutor] File IO Help again

2005-10-27 Thread bob
At 01:42 PM 10/27/2005, Adam wrote: > >if line[:1] == "1": > >This line won't work because you're getting the first 2 characters from >the line Oh? Did you test that? When I do that I get 1 character. Why? Because slicing goes UP TO the 2nd argument. >>> 'abc'[:1] 'a'

Re: [Tutor] File IO Help again

2005-10-28 Thread Liam Clarke
Heh, Cut 'im some slack there Bob, I only just figured out that line[:1] == line[0]... On 10/28/05, bob <[EMAIL PROTECTED]> wrote: > At 01:42 PM 10/27/2005, Adam wrote: > > >if line[:1] == "1": > > > >This line won't work because you're getting the first 2 characters from > >the line > > Oh? Did

[Tutor] File IO and writing lists

2005-11-04 Thread Mike Haft
"Carroll, Barry" <[EMAIL PROTECTED]> wrote: Second, your current logic is assembling the data from each line into a string. Is that what you want? I'm guessing you want to extract the three fields into a three element list. If so, you need to turn the three strings (fields[1], fields[2] and fie

[Tutor] file io: reading an int32 at the end of a file?

2005-07-06 Thread Marcus Goldfish
Hi, I have a file format that ends in a 4-byte (int32) number. I would like to read this value in python on a WinXP machine with something like: fname = 'somefile' f = open(fname, 'rb') f.seek(-4,2) offset = f.read() ... but this doesn't seem to work. The value that Python returns is: '@\x

Re: [Tutor] file io: reading an int32 at the end of a file?

2005-07-06 Thread Danny Yoo
On Wed, 6 Jul 2005, Marcus Goldfish wrote: > I have a file format that ends in a 4-byte (int32) number. I would like > to read this value in python on a WinXP machine with something like: > > fname = 'somefile' > f = open(fname, 'rb') > f.seek(-4,2) > offset = f.read() > > ... but this doesn't

Re: [Tutor] file io: reading an int32 at the end of a file?

2005-07-06 Thread Bob Gailer
At 01:12 PM 7/6/2005, Marcus Goldfish wrote: Hi, I have a file format that ends in a 4-byte (int32) number.  I would like to read this value in python on a WinXP machine with something like: fname = 'somefile' f = open(fname, 'rb') f.seek(-4,2) offset = f.read() ... but this doesn't seem to work.

Re: [Tutor] file io: reading an int32 at the end of a file?

2005-07-06 Thread Alan G
-- ... but this doesn't seem to work. The value that Python returns is: '@\x19\x01\x00' but I know from similar code in Matlab that the correct sequence is: 64 25 1 0 Can someone point out my error? -- That