A wild guess would be that the print line line is not properly indented,
if I replace spaces with _ it should look like

for line in lines:
____print line
myfile.close()

as python uses spaces/tabs to structure code, copy paste errors like
that are pretty common.

All the best

Sean

Graeme Denny wrote:
> 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
>>
> 
> > 
> 


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to