Gnocl Cookbook‎ > ‎

Saving List Contents to Disk

The Gtk List widget provides a lot of functionality for the display (and editing) of most sorts of data. Getting the data out of the tables as a list is straight forward too.  Data is inserted into the list on a row basis and how it should be retrieved. The following simple function shows how each row it iterated and the data pulled out of each cell. The contents are then appended to a list which is written to disk.

#---------------
# save table data to disk
#---------------
proc save { lst fname } {
   
    set fp [open $fname "w"]
   
    for {set row 0} {$row < [$lst rows]} {incr row} {
        set str ""
        for {set col 0} {$col < [$lst columns]} {incr col} {   
            lappend str [$lst get $row $col ]        ;# get value from single cel, ie row, col
        }
        puts $fp [list $str]
    }
   
    close $fp
}

The attached script contains a working implementation.




ċ
test-list-save.tcl
(1k)
William Giddings,
8 Oct 2011, 07:25
Comments