【发布时间】:2021-02-14 06:48:18
【问题描述】:
import matplotlib.pyplot as plt
import numpy as np
import plotly.graph_objects as go # run "pip install plotly==4.9.0" in your terminal to install plotly
import yfinance as yf
import numpy as np
import ast
eurusd = yf.Ticker("EURUSD=X")
usd_to_eur = 1 / (eurusd.info["ask"])
eur_to_usd = 1 * eurusd.info["ask"]
class Asset:
def __init__(self,name, ticker, amount):
self.amount = amount
self.name = name
self.ticker = ticker
self.price = yf.Ticker(self.ticker).info["regularMarketPrice"]
class Usd_asset(Asset):
def __init__(self, name, ticker, amount, buy_price):
super().__init__(name, ticker, amount)
self.buy_price = buy_price
self.buy_price_eur = [x * usd_to_eur for x in self.buy_price]
self.price_usd = yf.Ticker(self.ticker).info["regularMarketPrice"]
self.price_eur = self.price_usd * usd_to_eur
class Crypto(Asset):
def __init__(self, name, ticker, amount):
super().__init__(name, ticker, amount)
print("crypto")
class Crypto_Usd(Crypto, Usd_asset):
def __init__(self, name, ticker, amount, buy_price):
Usd_asset.__init__(self, name = name, ticker = ticker, amount = amount, buy_price = buy_price)
Crypto.__init__(self, name = name, ticker = ticker, amount = amount)
print("crypto usd")
每当我运行它时,我都会得到以下信息:
Attribute Error: Type object 'Usd_asset' has no attribute '_Crypto_Usd__init'
我在这里做错了什么?
我的目标是拥有一个继承自 Crypto 和 Usd_asset 的类。 它们又都继承自 Asset。
【问题讨论】:
-
请以文字形式分享代码。
标签: python class multiple-inheritance