Python : writing to a file

Peter Otten __peter__ at web.de
Sun Jan 11 11:32:34 CET 2015


Ganesh Pal wrote:

> On Sun, Jan 11, 2015 at 2:17 PM, Dave Angel <davea at davea.name> wrote:
>>
>>
>> You chopped off the output there.  It probably looked like this:
>>
>>
>> node-1# cat test_2.txt
>> Sundaynode-1#
>>
>>
>> Your output is there, right before the prompt.  Since you neglected the
>> newline in your code, that's what you'd expect, wouldn't you?
>>
>> Incidentally, in most systems that prompt would mean you're running as
>> root. Bad idea, especially when you're learning to program.
>>
> 
> I didn't get the output before the prompt ,I actually didn't chop off
> the output . below is the complete flow.
> 
> # cat get_day.py
> #!/usr/bin/python
> 
> import time
> f = open ('test_a.txt','wb+')
> DAY = time.strftime("%A")
> f.write(DAY)
> f.close()
> Throttling-1# python get_day.py
> 
> 
> node-1# cat test_a.txt   // This didn't give any result
> 
> node-1# less test_a.txt //  I can see the text here
> Sunday
> test_a.txt (END)

What does

$ echo $PS1

print? If there's a \r (carriage return) you should change it to avoid this 
confusion.




More information about the Python-list mailing list