Note that there are some explanatory texts on larger screens.

plurals
  1. POonly last line writing from large string to file in python
    primarykey
    data
    text
    <p>I have a rather large string that I want to write to a python file object. Currently, when I try to write this string only the LAST row gets written to the file. I've tested to ensure that the variable holding the large string is infact <code>&lt;type 'str'&gt;</code>. Here is the sample content:</p> <pre><code>"0008788014065251","Rush Running - Bentonville","1030643167","5,788.00","11.55","5.77" "0008788014065271","Rush Running - Fayetteville","1030643159","1,577.00","3.16","1.58" "0008788014108297","Snow Ball Express","2423373737","11.00","0.04","0.02" "0008788014108354","Snow Ball Express","2423378892","1,421.00","5.69","2.84" "0008788014108374","Snow Ball Express","2423378959","59.00","0.24","0.12" "0008788014110860","Sound Master","2423477231","135.00","0.54","0.27" "0008788014074301","The Baby's Room","1030669816","6,912.00","13.82","6.91" "0008788014110760","The Reserve","2423470822","715.00","2.86","1.43" "0008788014077339","Tool Town LLC","1171354079","438.00","0.88","0.44" </code></pre> <p>I want to write this to a file but everytime I do a <code>file.write()</code> I get only the last row. I'm using this simple file open and write procedure:</p> <pre><code>#link is a url to a csv file export = urllib2.urlopen( link ) content = export.read() with open("somefile.csv", "w") as file: try: file.write( content ) except Exception, e: raise e </code></pre> <p>I read that I should be iterating over <code>content</code> with a <code>for</code> loop; but, since <code>content</code> is a string and not a list/tuple, the <code>for</code> loop will explode to each letter and write the letter on a separate row.</p> <p>Any ideas how to write this type of content to a file?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload