[英]How to look up functions of a library in python?
我剛剛安裝了這個抓取 twitter 數據的庫: https : //github.com/kennethreitz/twitter-scraper
我想找出庫的函數和方法,以便我可以開始與庫進行交互。 我在這個主題上環顧了 StackOverflow 並嘗試了以下操作:
pydoc twitter_scraper
幫助(twitter_scraper)
目錄(twitter_scraper)
導入的檢查和運行函數 = inspect.getmembers(module, inspect.isfunction)
在我嘗試過的四件事中,到目前為止,我只從檢查選項中獲得了輸出。 我也不確定(不包括檢查)這些代碼應該放在終端還是臨時文件中。
在這方面還是很新的。 非常感謝大家閱讀!
好問題! 嘗試理解(完全理解)一個新庫有幾種選擇。 在您的特定情況下, twitter-scraper ,唯一的功能是get-tweets()
並且整個庫不到 80 行。
對於一般情況,按有用性降序排列。
pydoc module_name
在安裝模塊時起作用。 ``help(module_name) works in an interactive Python session after you have done an
導入 module_name works in an interactive Python session after you have done an
. These both work from the "docstrings" or strategically placed comments in the source code. This is also what
. These both work from the "docstrings" or strategically placed comments in the source code. This is also what
. These both work from the "docstrings" or strategically placed comments in the source code. This is also what
module_name?` 在 iPython 中所做的。dir(module_name)
也需要導入。 它列出了模塊的所有入口點,包括許多奇怪的“dunder”或雙下划線,您通常不會調用或更改。此外,您詢問了可以在腳本中使用的內容:
import os
print("Welcome, human.")
print("dir() is a function, returning a list.")
print("This has no output")
a_list = dir(os)
print("but this does", dir(os))
print("The help() command uses pydoc to print to stdout")
help(os)
print("This program is gratified to be of use.")
這個庫似乎缺乏適當的文檔,但 GitHub 頁面提供了一些使用示例來幫助您入門。
>>> from twitter_scraper import get_tweets >>> for tweet in get_tweets('kennethreitz', pages=1): >>> print(tweet['text']) PS your API is a user interface s3monkey just hit 100 github stars! Thanks, y'all! I'm not sure what this /dev/fd/5 business is, but it's driving me up the wall. …
要獲取更多信息,只需查看https://github.com/kennethreitz/twitter-scraper/blob/master/twitter_scraper.py上的源代碼。 似乎唯一的函數是get_tweets
,查看源代碼,它接受兩個參數,用戶名和頁數(可選,默認為 25)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.