Yes, that single line of code works but it’s simpler and faster to be able to just type a short command like “list_symbols()” to list all the symbols created in terminal.


Sent from my iPhone.

On 28 Jun 2025, at 10:14, [email protected] wrote:



I have been following this discussion as I use a library of sympy (sympy.physics.mechanics) quite a bit.

Would Krishnav’s one line code not do what Stephen wants, or am I missing something?

 

Thanks!

 

 

 

From: [email protected] <[email protected]> On Behalf Of Sangyub Lee
Sent: Saturday, June 28, 2025 10:59 AM
To: sympy <[email protected]>
Subject: Re: [sympy] Listing all symbols in sympy

 

I don't understand `locals()` or `globals()` very well, but it's always good that we don't implement something directly based on functionality that we don't feel safe using. Or will you put in the effort to address those concerns anyway

Regardless, it is primarily your responsibility to prove a strong reason why we need such functionality in SymPy. We don't have a responsibility to implement something general to solve the trivial terminal problems that you face.

 

On Saturday, June 28, 2025 at 10:41:48AM UTC+2 [email protected] wrote:

What does “…locals() or globals() introspection…” mean?

 

Please prove to me that “… it lead to issues with garbage collection, introduce security vulnerabilities and create thread safety concerns”.

 

I won’t be moving beyond Python.

 

What do you mean by “…domain-specific…”!

 

 

Sent from my iPhone.



On 28 Jun 2025, at 07:26, Sangyub Lee <[email protected]> wrote:

I don't think we should add such functionality to the library. I would not use locals() or globals() introspection in library because it lead to issues with garbage collection, introduce security vulnerabilities, and create thread safety concerns.



I think you would need to move beyond Python and use a different domain-specific language or user interface to implement such functionality in a secure way. I suggest consulting with experienced software engineers or IT agencies to implement that approach.

On Wednesday, June 25, 2025 at 8:17:49PM UTC+2 [email protected] 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 <[email protected]> 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:14AM Stephen Learmonth
>> <[email protected]> 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 [email protected] 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:07PM Stephen Learmonth <[email protected]> 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 [email protected].
>>>> 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 [email protected].
>> 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 [email protected].
> 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 [email protected].

--
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 [email protected].
To view this discussion visit https://groups.google.com/d/msgid/sympy/9f2e3377-26ce-4894-8f14-2b15c4869812n%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 [email protected].
To view this discussion visit https://groups.google.com/d/msgid/sympy/0c0901dbe80d%2414fff820%243effe860%24%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 [email protected].
To view this discussion visit https://groups.google.com/d/msgid/sympy/126633FB-0907-496F-BE65-EADA8192C5FF%40gmail.com.

Reply via email to