| View previous topic :: View next topic |
| Author |
Message |
montanarry
Joined: 13 May 2006 Posts: 175
|
| I have to print "hi world" to a file - how do I do it? |
| |
|
|
|
|
WarChild
Joined: 24 Feb 2006 Posts: 46
|
Ugly, Perl way:
print >> open('somefile', 'w'), 'hello'
Nice, Python way:
open('somefile', 'w').write('hello') |
| |
|
|
froomzer
Joined: 23 May 2006 Posts: 148
|
| montanarry, you have a syntax error here. you probably mean "hello world". |
| |
|
|
montanarry
Joined: 13 May 2006 Posts: 175
|
| ????? |
| |
|
|
optomeb
Joined: 19 May 2006 Posts: 113
|
| The second, because if after newline you have a space or more you'll not get rid of newline |
| |
|
|
montanarry
Joined: 13 May 2006 Posts: 175
|
Ok "hello world"
Any idfeas of printing to file |
| |
|
|
froomzer
Joined: 23 May 2006 Posts: 148
|
| F=file(path, 'w'); f.write('hello world'); f.close() |
| |
|
|
jomanda
Joined: 19 May 2006 Posts: 70 Location: Germany
|
| froomzer, what about file(path, 'w').write('hello word') |
| |
|
|
montanarry
Joined: 13 May 2006 Posts: 175
|
| froomzer, what if I want to write a few more lines to same file |
| |
|
|
ovigo22
Joined: 15 May 2006 Posts: 130
|
| montanarry, if you want the print behavour (like adding a newline): print >>f, "hello world" instead of f.write("hello world") |
| |
|
|
|