On Fri, Jan 6, 2012 at 12:09 PM, Kevin Hunter <[email protected]> wrote:
> Hullo Sympy Group,
>
> I'm wrapping some Sympy variables into a group via a class object.  The
> object is attached to another object, and from here, I'm able to collect the
> name of the group (via __setattr__).  Thus, I can have constructs like this:
>
> -----
> M.X = Var()        # Var is the wrapper class that holds a group variables.
> M.X[1,2,'a'] = 1   # automatically create variable
> -----
>
> That automatically creates the variable 'X[1,2,a]' via the Var.__getitem__.
>  To get the name with commas, I have to do this within the __getitem__
> function:
>
> -----
> 1. self.m_varsInUse += 1
> 2. vname = '%s[%d]' % ( self.m_name, self.m_varsInUse )
> 3. var = symbols( vname, **assumptions )
> 4. var.name = '%s(%s)' % (self.m_name, str(index).replace(' ', ''))
> -----
>
> Lines 1 and 2 guarantee a new variable, so that Sympy doesn't returned a
> cached copy of an already created variable, and line 4 puts in a name that
> potentially has commas.  What I'd like to be able to do is forgo lines one
> and two, like something akin to this:
>
> -----
> vname = '%s(%s)' % (self.m_name, str(index).replace(' ', ''))
> var = symbols( vname, **assumptions )
> -----
>
> This seems to return names like 'X[1', '2', and 'a]'.  I'd hazard splitting
> based on commas is correct behavior, but I'm wondering if there's something
> I can pass to the constructor that says "No, the commas are part of the
> name."
>
> Thanks,
>
> Kevin
>

Maybe I'm misunderstanding what you're doing, but if you just want
exactly one Symbol, why don't you just do var = Symbol(vname,
**assumptions)?

Aaron Meurer

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to