Metaprogramming question

T

Travis Griggs

The discussion about niladic functions, made me want to follow a segue and do some reflection/introspective programming in Python. I’ve not done a lot of that yet, and it seemed like an educational (well, at least entertaining) goose chase.

If I run the following code:

import datetime
datetime.datetime.now(13, 42)

I will get an error (expected). The error I will get is:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: now() takes at most 1 argument (2 given)

So, at some point, there’s some metadata in the system attached to the builtin datetime.datetime.now method, that indicates 1 argument, tops.

So here’s my basic question. Is there anyway to programatically query that information in python code?

inspect.signature(datetime.datetime.now)

just gives a ValueError. inspect must only be good for the python code that I write, in python. Is there another way to dig out what the interpreter knows there?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top