Re: reading variable names and values from a file
- To: mathgroup at smc.vnet.net
- Subject: [mg41560] Re: reading variable names and values from a file
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Mon, 26 May 2003 05:46:38 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <bamuol$11q$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi, str = "a 1\n b 2\n c 3" and Set @@@ (ImportString[str, "Table"] /. {s_String, b_} :> {ToExpression[s], b}) Regards Jens Chuck Wilkerson wrote: > > Howdy! > > I would like to read a text file that looks like the following: > > a 1 > b 2 > c 3 > ... > > and end up having assigned the value in the second column to the > variable name in the first column, i.e. > > a=1 > b=2 > c=3 > ... > > Does anyone know how to do this? I have tried (only briefly, though) > with ReadList to accomplish this task, but with no success yet. > > Thanks in advance! > > -Chuck > -- > ============================================================================= > Chuck Wilkerson cww at lanl.gov > Advanced Diagnostics and Instrumentation Group Tel 505-667-5966 > Los Alamos National Laboratory FAX 505-665-2227 > ----------------------------------------------------------------------------- > You may ask yourself, 'What is that beautiful house?' > You may ask yourself, 'Where does that highway go to?' > You may ask yourself, 'Am I right?...Am I wrong?' > And you may say to yourself, 'My God, What Have I Done!?!' -Talking Heads > ============================================================================= > (Correspondence/TSPA)