Something like sorted([i for i in globals() if isinstance(globals()[i], Symbol)])
will give you what you are looking for. In general, I'd say if you want to start over it's better to just reset the session. Also you may prefer using a Jupyter notebook to a terminal session, as it makes it easier to follow what code you have already executed, and it also supports nicer math output with SymPy. Aaron Meurer On Wed, Jun 25, 2025 at 12:17 PM <stephen.j.learmo...@gmail.com> wrote: > > My “use case” is that suppose you are executing Python code in the Mac > terminal application to test out some code and you lose track of what > variables you have created and you want to delete some or all of them to > start over. > > A function which lists all the created variables would be useful so you can > delete them all and start over. A very basic function. > > Sent from my iPhone. > > > On 25 Jun 2025, at 17:46, Aaron Meurer <asmeu...@gmail.com> wrote: > > > > What is your use-case for such a function? In most cases if you are > > writing a script you know what symbols are defined because you have > > defined them all statically somewhere, so there's no need to > > programmatically get a list of them. > > > > Aaron Meurer > > > >> On Mon, Jun 23, 2025 at 9:14 AM Stephen Learmonth > >> <stephen.j.learmo...@gmail.com> wrote: > >> > >> Thanks Krishnav, > >> > >> It would have been really useful if Sympy just had a function like > >> list_symbols() oir something from the start. > >> > >> It''s such a basic thing to want to be able to do! > >> > >> Stephen > >> > >>> On Monday, 23 June 2025 at 16:00:38 UTC+1 bajoria...@gmail.com wrote: > >>> > >>> Hi Stephen, > >>> > >>> If you want to list all sympy symbols that you have created in a Python > >>> script, one straightforward way is to use Python’s built-in globals() to > >>> scan the current namespace and check for instances of sympy.Symbol. > >>> > >>> Here's a simple example to illustrate: > >>> > >>>>>> from sympy import Symbol > >>>>>> from sympy.abc import a, b, c > >>>>>> x = Symbol('x') > >>>>>> y = Symbol('y') > >>>>>> z = 3 # this is not a SymPy symbol > >>>>>> symbols_used = [name for name, obj in globals().items() if > >>>>>> isinstance(obj, Symbol)] > >>>>>> print("Symbols used :", symbols_used) > >>> > >>> This would output: > >>> > >>> Symbols used : ['a', 'b', 'c', 'x', 'y'] > >>> > >>> But do let me know if you are looking for something more specific. Happy > >>> to help further! > >>> > >>> Best regards, > >>> > >>> Krishnav Bajoria. > >>> > >>> > >>> On Mon, Jun 23, 2025 at 8:07 PM Stephen Learmonth > >>> <stephen.j...@gmail.com> wrote: > >>>> > >>>> How do I list ALL sympy symbols created in a Python script? > >>>> > >>>> -- > >>>> 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+un...@googlegroups.com. > >>>> To view this discussion visit > >>>> https://groups.google.com/d/msgid/sympy/2f682bea-f462-4188-9873-82c9ebafe889n%40googlegroups.com. > >> > >> -- > >> 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 view this discussion visit > >> https://groups.google.com/d/msgid/sympy/c41df7a9-b27c-4e81-9fcd-85a52789b4e6n%40googlegroups.com. > > > > -- > > 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 view this discussion visit > > https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2B%2B_feNU%3D1psGQ1H7PapFHO67DtaqHKW8PiR59iZmrRDA%40mail.gmail.com. > > -- > 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 view this discussion visit > https://groups.google.com/d/msgid/sympy/09F2477A-68C5-4D47-B87C-E127DF867DF9%40gmail.com. -- 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 view this discussion visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6LiVQrnpZvUqnhBTBkA85WZzYf%3DyCvTgEiN%2BSOrwt4xow%40mail.gmail.com.