楼主: dcs2213
555 3

[编程问题求助] 如何在ado文档中插入一段python脚本? [推广有奖]

  • 1关注
  • 0粉丝

硕士生

71%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
38.1984
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
327 点
帖子
14
精华
0
在线时间
373 小时
注册时间
2016-4-7
最后登录
2025-1-16

楼主
dcs2213 发表于 2023-3-22 21:50:13 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
I am writing a Stata file named mycode.ado. The basic structure of it is as follows:

  1. program define mycode

  2.   di "I am going to print a random number get from random.org"

  3. python:

  4. import urllib.request
  5. import re

  6. api = "https://www.random.org/integers/?num=1&min=1&max=100&col=1&base=10&format=plain&rnd=new&cl=w"
  7. response = urllib.request.urlopen(api)
  8. response_text = response.read().decode('utf-8')

  9. try:
  10.     match = re.search(r"font-weight:bold;'>(.*?)\n</span>", response_text)
  11.     print(match.group(1))
  12. except Exception as e:
  13.     print('获取出错:', e)

  14. end

  15. end
复制代码
The program failed to be executed. the erro returned was "command end is unrecognized".
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:python do文档 unrecognized recognized Structure

沙发
newfei188 发表于 2023-3-24 08:31:33
不懂哈,不会用

藤椅
Raymond.K 学生认证  发表于 2023-3-24 15:16:40
Please
  1. help python
复制代码

Also, such python code cannot be indented at will.
Reference:https://www.lianxh.cn/news/290a48d428074.html

板凳
cxkking 发表于 2023-4-17 12:30:10
你可以使用 ADO 文档的「表格」功能来插入 Python 脚本,只需要新建一个表格,然后把你想插入的 Python 脚本复制并粘贴到表格中即可。在编辑表格时,可以点击右上方的椭圆形图标,来选择 Python 代码语法模式,这样便可以支持语法高亮显示,以及更好地编辑 Python 脚本。

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-9 08:13