0

Let's say that I wanted to create my own library to be used in Python. How would I code a key press? How do I establish that without referencing the Python library of "keyboard"? I would love to be able to view the "keyboard" library that I import, in order to see how that library was created.

Thanks!

  • 3
    Do `import keyboard; print(keyboard.__file__)`, then open that file in the text editor of your choice. Alternatively, find the code on github. – Aran-Fey Sep 29 '19 at 20:42
  • 3
    https://github.com/boppreh/keyboard? I just looked it up on https://pypi.org/ and followed the links to the source code. – jonrsharpe Sep 29 '19 at 20:44
  • @Aran-Fey, in place of `_file_`, am I putting something like `_init_ or _main_`, or do you literally mean `_file_`? Because when I run that, I am getting: `AttributeError: module 'keyboard' has no attribute '_file_'` – the-wastelander Sep 29 '19 at 22:38
  • @jonrsharpe Thank you for the link. That was what I was looking for, I think. I'm still new to all of this so that's a lot of source code to look through. – the-wastelander Sep 30 '19 at 01:24
  • I mean `__file__` with 2 underscores on each side. – Aran-Fey Sep 30 '19 at 05:36

1 Answers1

0

You can check out the inspect module.

Also possibly duplicate of this: How can I get the source code of a Python function?

Cosmos Zhu
  • 128
  • 1
  • 10