我真的很喜欢python做这样的事情的能力:
if __name__ == '__main__':
#setup testing code here
#or setup a call a function with parameters and human format the output
#etc...
Run Code Online (Sandbox Code Playgroud)
这很好,因为我可以将Python脚本文件视为可以从命令行调用的东西,但它仍然可以轻松地将其函数和类导入到单独的python脚本文件中,而不会触发默认的"从命令行运行"行为".
Powershell有类似的设施,我可以利用吗?如果不是,我应该如何组织我的函数文件库,这样我可以在开发它时轻松执行其中的一些?
我正在使用 python requests-oauthlib 包连接到 Microsoft Graph。我正在使用 OAuth 2.0 客户端凭据流程。
下面的简化代码工作得很好:
from oauthlib.oauth2 import BackendApplicationClient
from requests_oauthlib import OAuth2Session
client = BackendApplicationClient(client_id='myclientid')
token_url = "https://login.microsoftonline.com/mydomain.onmicrosoft.com/oauth2/v2.0/token"
msgraph = OAuth2Session(client=client)
msgraph.fetch_token(
token_url = token_url,
client_secret = 'myclientsecret',
scope='https://graph.microsoft.com/.default')
response = msgraph.get(
url="https://graph.microsoft.com/v1.0/users/user@mydomain.com/messages")
Run Code Online (Sandbox Code Playgroud)
虽然这有效,但在这种情况下,承载访问令牌的有效期仅为 1 小时。requests-oauthlib 包支持刷新令牌,但它似乎仅限于带有单独刷新令牌的令牌类型。与 Microsoft Graph 一起使用的客户端凭据流仅发出 access_token。
所以我的问题是:
我了解 Polars 系列可以导出到 Python 列表。但是,有什么方法可以将 Polars Dataframe 转换为 Python 列表吗?
此外,如果 Polars 数据框中只有一列,如何将其转换为 Polars 系列?
我尝试使用 pandas 命令但没有成功。我还查了Polars官方网站,看有没有相关的内置功能,但没有看到。