On 31/08/12 17:42, Aaron Meurer wrote: > On Aug 31, 2012, at 5:12 AM, Juha Jeronen <[email protected]> wrote: > >> On 31.08.2012 13:03, Chris Smith wrote: >>> On Fri, Aug 31, 2012 at 3:30 PM, Juha Jeronen <[email protected]> wrote: >>>> Hi all (again), >>>> >>>> And here's a fixed version. The code I just posted returned some >>>> nonsensical >>>> results, because it didn't filter out modules and classes. >>> Another way to maybe approach this problem (getting a non-clashing >>> form of an expression sympified) is this: >>> >>> * the user must know what functions they are using: they/you give a >>> list of these and this list must agree with the representation of that >>> function's name in sympy >>> * they give an expressions >>> * let python parse this (I don't recall which does that now -- there's >>> some module for parsing python code character by character) and when >>> it identifies a variable either 1) it is a function that has already >>> been identified or it is intended as a symbol and 2a) sympy agrees or >>> 2b) sympy disagrees and wants to make it a class or anything other >>> than a symbol. > The tokenize module will split a string of valid python code into its > tokens, which you can then search for names. Or if you don't need 2.5 > support, you can use the ast module. > > If you want, you could then sympify the name and see if you get a > Symbol or not (caching the results).
Ok. Thanks for the tip. The ast module should be fine. >> Is it possible to dynamically detect in the new version whether a function >> object is evaluatable or not, and user-defined or not? At least I couldn't >> find anything obvious in the attributes... > In 0.7.2 you will be able to check if it is a subclass of > UndefinedFunction. I don't know if that works in 0.7.1 or what would > be a work around if not. Ok. Thanks. It seems 0.7.1 doesn't have an UndefinedFunction. But I suppose I can wait for 0.7.2 for this. (It's not absolutely critical, though it improves user-friendliness by catching errors early.) -J -- 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.
