我想创建一个具有 3 个函数的 Python 类。
这是我到目前为止的代码:
class Product:
def __init__(self, x, y):
self.x = x
self.y = y
def get_x(self):
x = int(input('What is the first number?: ')
def get_y(self):
y = int(input('What is the second number?: ')
def mult_XY(self):
return x * y
Run Code Online (Sandbox Code Playgroud)
当我尝试打电话给班级时,我得到了'y' is not defined。
我尝试使用以下代码:
num = Product(x, y)
print(num.mult_XY)
Run Code Online (Sandbox Code Playgroud) 我想使用这个web scrape创建一个pandas数据框,这样我可以将数据导出到excel.有人熟悉这个吗?我在网上和网站上看到了不同的方法,但是无法通过这种方法成功复制结果.
这是迄今为止的代码:
import requests
source = requests.get("https://api.lineups.com/nba/fetch/lineups/gateway").json()
for team in source['data']:
print("\n%s players\n" % team['home_route'].capitalize())
for player in team['home_players']:
print(player['name'])
print("\n%s players\n" % team['away_route'].capitalize())
for player in team['away_players']:
print(player['name'])
Run Code Online (Sandbox Code Playgroud)
这个网站似乎很有用,但示例不同:
https://www.tutorialspoint.com/python_pandas/python_pandas_dataframe.htm
这是stackoverflow.com的另一个例子:
我是编码/抓取的新手,所以任何帮助都会非常感激.提前感谢您的时间和精力!