[Tutor] sharing a small script someone may find of use
dn
PythonList at DancesWithMice.info
Sat Aug 13 15:29:19 EDT 2022
On 14/08/2022 02.22, Peter Otten wrote:
> On 13/08/2022 02:53, Nathan Smith wrote:
>> Use case: This script can be used to identify which modules are holding
>> things up at the import stage and give you a rough estimate as to how
>> long your imports are taking for a program during start up.
> You are treating Python code as text and inspect it with standard string
> processing methods.
>
> There is an alternative, though. The ast module allows you to convert
> code into a tree of objects that you can search for Import nodes.
> This may look a bit harder in the beginning, but it already knows about
> docstrings and comments, and can even be used to modify the original
> source in ways that go beyond an editor's search-and-replace capabilities.
FYI:
Hamilton Python Meetup (New Zealand Python Users' Group)
Monday, September 12, 2022 at 7:00 PM to 9:00 PM NZST (0700~0900 UTC)
Lawrence D'Oliveiro will introduce the *"ast" module* (part of the
standard library) for abstract syntax trees, which can be used for
parsing Python files and retrieve information like doc strings, imports,
functions. etc.
Under traffic light setting Orange, the meeting will be a mix of
in-person (requirements: mask, social distancing) and virtual. Under
Red, it will be virtual only.
The in-person meeting part will take place in MS4.G.02:
https://www.waikato.ac.nz/contacts/map/?MS4
The URL for the virtual meeting part will be made available to those who
RSVP.
https://www.meetup.com/nzpug-hamilton/events/283776844/
NB I am not one of the group's organisers, but meetings are usually
recorded. More info from PeterR (via the Meetup page).
The time-zone 'works' for late-owls on the US West Coast, folk all
around the Pacific Rim, and covering the day all the way west around the
globe to Europeans and Brits enjoying their breakfast.
"traffic light setting Orange...red" are levels of COVID-response, and
irrelevant to those of us 'beaming-in' virtually.
--
Regards,
=dn
More information about the Tutor
mailing list