MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Reading a file

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25563] Re: [mg25475] Reading a file
  • From: dkeith at sarif.com
  • Date: Sat, 7 Oct 2000 03:36:11 -0400 (EDT)
  • References: <8rjj98$of4@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Rod, here is another way. ReadList reads Words with Records as
sublists, then ToExpression converts the Words to numbers. The Words
cannot be the names of previously defined symbols, or they will be
evaluated to their definitions.


!! test.txt
s,1,even,21,2.1,40
p,1,even,7,2.1,3.0
d,1,even,5,2.1,3.0
f,1,even,3,2.1,3.0

ReadList["test.txt", Word, WordSeparators -> {","},
    RecordLists -> True] // ToExpression

{{s, 1, even, 21, 2.1, 40}, {p, 1, even, 7, 2.1, 3.}, {d, 1, even, 5,
2.1, 3.}, {f, 1, even, 3, 2.1, 3.}}


Regards,

David




In article <8rjj98$of4 at smc.vnet.net>,
  Matt.Johnson at autolivasp.com wrote:
>
> Rod-
>
> ReadList is tricky and I usually end up using trial and error to get
it
> right, but this seems to work for your example.
>
> In[39]:=
> !! test.txt
> s,1,even,21,2.1,40
> p,1,even,7,2.1,3.0
> d,1,even,5,2.1,3.0
> f,1,even,3,2.1,3.0
>
> In[40]:=
> ReadList["test.txt", Record, RecordLists -> True]
> Out[40]=
> {{"s,1,even,21,2.1,40"}, {"p,1,even,7,2.1,3.0"},
{"d,1,even,5,2.1,3.0"}, \
> {"f,1,even,3,2.1,3.0"}}
>
> -matt
>
> Rod <rodolphe6831 at my-deja.com> on 10/02/2000 08:26:55 PM
>
> cc:
>
> Subject: [mg25563]  [mg25475] Reading a file
>
>  I'm trying to read the following file,
>
> s,1,even,21,2.1,40
> p,1,even,7,2.1,3.0
> d,1,even,5,2.1,3.0
> f,1,even,3,2.1,3.0
>
> I want the field separator to be "," so i tried
> ReadList
> ["file",{Character,Number,Word,Number,Number,Number},WordSeparators->
> ","] but it does not seem to work. Any ideas ?
>
> --
>    __   _
>   / /  (_)__  __ ____  __
>  / /__/ / _ \/ // /\ \/ /  . . .  t h e   c h o i c e  o f   a
> /____/_/_//_/\_,_/ /_/\_\              G N U   g e n e r a t i o
n . . .
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


  • Prev by Date: Re: vector multiplication
  • Next by Date: Re: Exporting multiple page graphics
  • Previous by thread: Re: Reading a file
  • Next by thread: Extracting all the variables from a list of equations?