Just guessing here, but try typing each line into the interpreter in
series (i mean, one at a time, dont paste multiple lines in).
The interpreter session should look something like this (plus some output):
>>> myfile = open("testtherest.rtf", "r")
>>> lines = myfile.readlines()
>>> for line in lines:
print line
>>> myfile.close()
>From the code you pasted, it looks to me like the myfile.close() line
was pasted in alongside the for loop, while the interpreter expects a
single block of code, not two.
Hope that makes sense, I'm kinda tired, been staring at code solidly
since 9 this morning :-D (and figured out my django admin problems!
yay)
2008/6/28 Graeme Denny <[EMAIL PROTECTED]>:
> thats what i had. and when i tried to run it it give me a syntax error.
>
>>>> myfile = open("/testtherest.rtf", "r")
>>>> lines = myfile.readlines()
>>>> for line in lines:
> print line
> myfile.close()
>
>
> On Sat, Jun 28, 2008 at 6:29 PM, Daniel Kersten <[EMAIL PROTECTED]> wrote:
>>
>> Do you still get a syntax error? Feel free to paste it here and
>> someone will help, if you cannot figure it out.
>>
>> Dan.
>>
>> 2008/6/28 Graeme Denny <[EMAIL PROTECTED]>:
>> > thanks for the reply,
>> > i was trying out with a few documents that i have and keep getting
>> > invalid
>> > syntax. when i try and run the script.
>> >
>> >
>> > On Sat, Jun 28, 2008 at 4:06 PM, Sean O'Donnell <[EMAIL PROTECTED]>
>> > wrote:
>> >>
>> >> Hi Graeme, The code should be the same as on a linux or windows machine
>> >> (except the path would look different on windows).
>> >>
>> >>
>> >> So the following snippet opens a text file,
>> >> reads all of the lines in it into a list
>> >> prints each line
>> >> and then closes the file, the "r" bit on the first line means open the
>> >> file for reading
>> >>
>> >> myfile = open("./myfile.txt", "r")
>> >> lines = myfile.readlines()
>> >> for line in lines:
>> >> print line
>> >> myfile.close()
>> >>
>> >> To write to a file
>> >>
>> >> myfile = open"./mynewfile.txt","w")
>> >> myfile.write("hello world")
>> >> myfile.close()
>> >>
>> >> The "w" bit means for writing this time,
>> >> and after running that you should have a new
>> >> file with the words "hello world" in it.
>> >> The .write method does not put a newline character at the end,
>> >> so if you dont put a \n in there calling it again will keep writing
>> >> on the same line. remember to call .close() at the end, or you
>> >> wont see the changes in the file when the program ends
>> >>
>> >> All the best
>> >>
>> >> Sean
>> >>
>> >>
>> >>
>> >> [EMAIL PROTECTED] wrote:
>> >> > I am extremely new to the Python language and have found many
>> >> > websites
>> >> > doing tutorials, but I am having trouble just opening a simple file.
>> >> > I
>> >> > am working the python on a Mac and all the tutorials I seem to get
>> >> > relate to PC.
>> >> >
>> >> > could somebody give me the layout that the line would take to open a
>> >> > file, just a text file, for the mac.
>> >> >
>> >> > apologies for the basicness of this request for everyone.
>> >> >
>> >> > Graeme
>> >> > >
>> >>
>> >>
>> >>
>> >
>> >
>> > >
>> >
>>
>>
>>
>> --
>> Daniel Kersten.
>> Leveraging dynamic paradigms since the synergies of 1985.
>>
>>
>
>
> >
>
--
Daniel Kersten.
Leveraging dynamic paradigms since the synergies of 1985.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Python Ireland" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.ie/group/pythonireland?hl=en
-~----------~----~----~----~------~----~------~--~---