Re: Import variable and data
- To: mathgroup at smc.vnet.net
- Subject: [mg32745] Re: [mg32696] Import variable and data
- From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
- Date: Thu, 7 Feb 2002 05:12:29 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
All you need is to insert Evaluate on the left hand side. In[1]:= mylist={{"a","b","c","d"},{1,23,45,678}} Out[1]= {{a,b,c,d},{1,23,45,678}} In[2]:= Evaluate[ToExpression[mylist][[1]]]=mylist[[2]]; In[3]:= {a,b,c,d} Out[3]= {1,23,45,678} On Wednesday, February 6, 2002, at 05:42 PM, Mark Van De Vyver wrote: > Hi MathGroup, > > I'm having trouble with the following variable and data import: > The import file is input.txt: > > a b c d > 1 23 45 678 > > inputData=Import[input.txt,"Table"] > {{a,b,c,d},{1,23,45,678}} > > This all works OK. > Head[..] indicates the a,b,c and d are strings, which is fine, because > ToExpression[..] changes them to symbols. What I'd like to do is use > inputData to do the following: > > {a,b,c,d}={1,23,45,678} > > However, if I try > > ToExpression[ inputData[[1]] ] = inputData[[2]] > > I get an error: > > Set::write: Tag ToExpression in ToExpression[a] is Protected. > > If I then enter 'a' in Mathematica I do not get 1 returned! No matter > how I try I > can't work it so that when I enter the symbol 'a' in Mathematica I get > the value > from inputData[[2]]. > > Not sure if that makes sense? > > > > > Andrzej Kozlowski Toyama International University JAPAN http://platon.c.u-tokyo.ac.jp/andrzej/