This should be:

class MyPrinter(CCodePrinter):
    def _print_Symbol(self, expr):
        name = super(MyPrinter, self)._print_Symbol(expr)
        return 'foo_' + name


Jason
moorepants.info
+01 530-601-9791

On Tue, Nov 3, 2015 at 8:01 PM, Jason Moore <moorepa...@gmail.com> wrote:

> How about something like this:
>
> In [1]: from sympy.abc import a, b, c
>
> In [2]: from sympy.printing.ccode import CCodePrinter
>
> In [3]: class MyPrinter(CCodePrinter):
>     def _print_Symbol(self, expr):
>         name = super(CCodePrinter, self)._print_Symbol(expr)
>         return 'foo_' + name
>    ...:
>
> In [4]: MyPrinter().doprint(a)
> Out[4]: 'foo_a'
>
>
> Jason
> moorepants.info
> +01 530-601-9791
>
> On Tue, Nov 3, 2015 at 3:01 PM, Richard Brown <rgbr...@gmail.com> wrote:
>
>> Hi there
>>
>> I'm a relative python/sympy newbie, and I need a little help on a
>> problem. I'm writing a piece of code that translates a system of
>> differential equations into either C, Python, or MATLAB/Octave code that
>> can be interfaced to solvers in those languages. The models are specified
>> using .ini files, and I'm using sympy's code generators to translate the
>> model equations (which are in python syntax). So far so good.
>>
>> What I want to be able to do, is take an expression like
>>
>> prefix = 'foo'
>> str = 'x**2 - sin(x) + exp(xy)'
>>
>> and turn it into C (or MATLAB) like
>>
>> 'pow(foo_x, 2) - sin(foo_x) + exp(foo_x * foo_y)'
>>
>> I know this involves overriding the printing library somehow, but I'm
>> getting confused with where to start. Should I be overriding the __str__
>> method of atom?
>>
>> Any help would be gratefully accepted
>>
>> Richard
>>
>> --
>> 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.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sympy/d4c5d051-d835-4a63-a966-191938935a2d%40googlegroups.com
>> <https://groups.google.com/d/msgid/sympy/d4c5d051-d835-4a63-a966-191938935a2d%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAP7f1AhNDhpWxV3wV4LsOL9rRWD_JO9GzO0aEJbAV%3DcC%2Bz2k-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to