Dynamic character substitution.

Tim Roberts timr at probo.com
Tue Sep 27 08:14:36 CEST 2005

"John Bausano" <jbausano at vt.edu> wrote:
>Hello all,
>I've been using Ansys which is a commercial FEA package which can be 
>controlled through its own scripting language they call APDL.  Now I'm 
>trying to write some stand alone code in Python to supplement my current 
>In Ansys I can do something like this.
>*do,n,1,3                                   #loop through n
>  *dim,data%n%,1000,2                       #creates variables 
>arrays data1(1000,2), data2(1000,2)..
>  *vread,data%n%,filename%n%            #fills arrays with data 
>from filename1,.

Generally, you need to think about your problem in a slightly different
way.  Instead of thinking about creating variables called data1 and data2,
think about creating a dictionary called "data" which contains three
elements.  For example:

    data = {}
    for n in range(3):
        data[n] = read_from( 'filename%d' % n )

It IS possible to create variables on the fly, but except in very special
situations, it is almost never the right way to do things.
- Tim Roberts, timr at probo.com
  Providenza & Boekelheide, Inc.

More information about the Python-list mailing list