小编Nic*_*ick的帖子

通过Excel / VBA运行Python脚本

多年来,我一直在寻找解决此问题的方法。我有一些需要定期更新的python脚本,并且希望能够使用宏来完成此操作。现在,我双击文件,它们通过Shell执行而没有问题。

Sub RunPyScript()

Dim Ret_Val As Variant
Dim command As String

command = Chr(34) & "C:\Users\Jon Doe\python.exe" & Chr(34) & " " & Chr(34) & "C:\Users\Jon Doe\" & "\Roto.py" & Chr(34)
Ret_Val = Shell(command, vbNormalFocus)

End Sub
Run Code Online (Sandbox Code Playgroud)

当我尝试运行上面的宏时,看起来它的运行方式与我双击时的运行方式相同,但是Shell在执行脚本之前退出(我认为这是问题所在,不是肯定的)。如果有人可以帮助我,我将非常感激。

python excel vba

3
推荐指数
1
解决办法
1564
查看次数

在 python 请求中处理井号 (#)

我正在使用请求来编译自定义 URL,并且一个参数包含一个井号。谁能解释如何在不编码井号的情况下传递参数?

这将返回正确的 CSV 文件

results_url = 'https://baseballsavant.mlb.com/statcast_search/csv?all=true&hfPT=&hfAB=&hfBBT=&hfPR=&hfZ=&stadium=&hfBBL=&hfNewZones=&hfGT=R%7C&hfC=&hfSea=2019%7C&hfSit=&player_type=batter&hfOuts=&opponent=&pitcher_throws=&batter_stands=&hfSA=&game_date_gt=&game_date_lt=&hfInfield=&team=&position=&hfOutfield=&hfRO=&home_road=&hfFlag=&hfPull=&metric_1=&hfInn=&min_pitches=0&min_results=0&group_by=name&sort_col=pitches&player_event_sort=h_launch_speed&sort_order=desc&min_abs=0&type=#results'
results = requests.get(results_url, timeout=30).content
results_df = pd.read_csv(io.StringIO(results.decode('utf-8')))
Run Code Online (Sandbox Code Playgroud)

这不

URL = 'https://baseballsavant.mlb.com/statcast_search/csv?'

def _get_statcast(params):

     _get = get(URL, params=params, timeout=30)
     _get.raise_for_status()
     return _get.content
Run Code Online (Sandbox Code Playgroud)

问题似乎是,当通过请求传递 '#results' 时,'#' 被忽略后会导致下载错误的 CSV。如果有人对解决此问题的其他方式有任何想法,我将不胜感激。

EDIT2:也在python论坛上问过这个https://python-forum.io/Thread-Handling-pound-sign-within-custom-URL?pid=75946#pid75946

python python-requests

1
推荐指数
1
解决办法
1759
查看次数

标签 统计

python ×2

excel ×1

python-requests ×1

vba ×1