One way:
sage: f = open("mydatafile.txt") sage: l1 = f.readline() sage: ls1 = l1.split(" ") sage: l1; ls1 "'b' 'breadth of member' 250\n" ["'b'", "'breadth of member'", '250\n'] sage: eval(ls1[2]) 250 where mydatafile.txt is in $SAGEROOT and consists of these lines: 'b' 'breadth of member' 250 'D' 'overall depth of member' 550 and each item is separated by 2 spaces. On Sun, Dec 28, 2008 at 8:36 PM, H. S. Rai <hardeep....@gmail.com> wrote: > > What is the easiest way to read data from file. file function mention > of size, I want to read variable wise, like: > > f.read(myInteger1, myFloat1, myString1) > > My data file will be: > 'b' 'breadth of member' 250 > 'D' 'overall depth of member' 550 > > Each line having three entries: <variable name>,<Description>,<Default vaule> > > These may be separated by comma, tab or space. If I am able to read > and have list like: > > varList[ [ 'b', 'breadth of member', 250 ] , [ 'D', 'overall depth of > member', 550 ] ] > > then that will serve my purpose. > > With regards, > > -- > H.S.Rai > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---