Python redirect/write output to file? -
i want write output write output in file, got "none" words synonyms.
note: when not writing in file output works fine note: output appears on screen whether writing file or not, "none" in file, theres anyway fix it. [im using python v2.7 mac version]
file=open("input.txt","w") #opening file xxx in diacritics: print xxx synsets = wn.get_synsetids_from_word(xxx) or [] s in synsets: file.write(str(wn._items[s].describe()))
i tried simplify question , rewrite code independent test should able run , modify if problem code.
test = "is real life? fantasy? caught in test slide..." open('test.txt', 'w') f: word in test.split(): f.write(word) # test.txt output: isthisareallife?isthisfantasy?caughtinatestslide...
a side note sounds want append rather truncate, not sure, take @ this.
the commonly-used values of mode 'r' reading, 'w' writing (truncating file if exists), , 'a' appending (which on unix systems means writes append end of file regardless of current seek position). if mode omitted, defaults 'r'. default use text mode, may convert '\n' characters platform-specific representation on writing , on reading. thus, when opening binary file, should append 'b' mode value open file in binary mode, improve portability. (appending 'b' useful on systems don’t treat binary , text files differently, serves documentation.) see below more possible values of mode.
Comments
Post a Comment