on perhaps unloading modules?

Chris Angelico rosuav at gmail.com
Sat Aug 21 14:43:16 EDT 2021


On Sun, Aug 22, 2021 at 4:37 AM Hope Rouselle <hrouselle at jevedi.com> wrote:
>
> Greg Ewing <greg.ewing at canterbury.ac.nz> writes:
>
> > On 21/08/21 1:36 pm, Hope Rouselle wrote:
> >> I wish I could restrict their syntax too, though, but I fear that's
> >> not possible.  For instance, it would be very useful if I could
> >> remove loops.
> >
> > Actually you could, using ast.parse to get an AST and then walk
> > it looking for things you don't want to allow.
>
> Very interesting!  Thanks very much.  That would let me block them,
> though the ideal would be a certain python.exe binary that simply blows
> a helpful syntax error when they use something the course doesn't allow.
> But surely the course could provide students with a certain module or
> procedure which would validate their work.  (Don't turn in unless you
> pass these verifications.)
>
> > You could also play around with giving them a custom set of
> > builtins and restricting what they can import. Just be aware
> > that such things are not foolproof, and a sufficiently smart
> > student could find ways around them. (Although if they know
> > that much they probably deserve to pass the course anyway!)
>
> So true!  If they can get around such verifications, they should present
> their work at an extra-curricular sessions.

Agreed... if they do it knowingly. On the other hand, if they just
turn in code copied blindly from Stack Overflow...

ChrisA


More information about the Python-list mailing list