Try using numbered_symbols().

Aaron Meurer


On Thu, May 2, 2013 at 10:49 AM, Prasoon Shukla <prasoon92.i...@gmail.com>wrote:

> I had a 2 day break between exams so I began work on the CoordSystem
> class. Hopefully, I'll be able to make a WIP PR before 15th.
>
> One problem I am facing is this: In this class, there is a *lot* of
> initialization going on. A part of that is generating non-commutative
> symbols to represent the basis elements. Since we planning to support n
> dimensional coordinate system for rectangular coordinates, I would need n
> basis elements.
> So, I basically need to do initialization n times like so:
> self.e1 = Symbol('e1') ... upto n times.
>
> Obviously this is not feasible since we don't know n.
> I can get a tuple of symbols using the symbols('e1: '+ str(n+1)) but then
> again is the problem of initializing the object properties.
>
> The only way I can think of doing this is to use the exec statement.
>
> sym_tuple = symbols('e1:' + str(n+1))
> for i in range(1, n+1):
>     cmd = 'self.e' + str(i) + ' = sym_tuple[ ' + str(i-1) + ']'
>     exec cmd
>
> But then again, I know that using exec is frowned upon in general. So, is
> there a better way to go about this?
>
>  --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sympy+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy?hl=en-US.
>
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to