self.__symbol = 0 def __setattr(self, name, value): if name == "denominator" and value == 0: raise ZeroDenominatorError("denominator by zero") return super().__setattr(self, name, value) # -self def __neg__(self): a, b = self.numerator, self.denominator if self.__symbol: return Fraction(a, b) return Fraction(abs(a), abs(b)) # +self def __pos__(self): return self def __str__(self): a, b = self.numerator, self.denominator if a == 0: return "0" return "-" * abs(self.__symbol - 1) + f"{abs(a)}/{abs(b)}" def __repr__(self): __repr__ == __str__ def __add__(self, other): a, b = self.numerator, self.denominator c, d = other.numerator, other.denominator if a == 0: return Fraction(c, d) if c == 0: return Fraction(a, b) ad = a * d bc = b * c bd = b * d return Fraction(ad + bc, bd) def __sub__(self, other): a, b = self.numerator, self.denominator c, d = other.numerator, other.denominator if a == 0: return -Fraction(c, d) if c == 0: return Fraction(a, b) ad = a * d bc = b * c bd = b * d return Fraction(ad + bc, bd) def __mul__(self, other): return Fraction( self.numerator * other.numerator, self.denominator * other.denominator def __truediv__(self, other): if other.numerator == 0: raise ZeroDivisionError("division by zero") ad, bc = self.numerator * other.denominator, self.denominator * other.numerator return Fraction(ad, bc) # int(self) def __int__(self): return int(self.numerator / self.denominator) # float(self) def __float__(self): return self.numerator / self.denominator # != def __ne__(self, other) -> bool: if isinstance(other, Fraction): return str(self) != str(other) return True def __eq__(self, other): if isinstance(other, Fraction): return str(self) == str(other) return False def __lt__(self, other) -> bool: if isinstance(other, Fraction): return float(self) < float(other) raise TypeError( def __le__(self, other) -> bool: if isinstance(other, Fraction): return float(self) <= float(other) raise TypeError( f"'<=' not supported between instances of 'Fraction' and {type(other)}" def __gt__(self, other) -> bool: if isinstance(other, Fraction): return float(self) > float(other) raise TypeError( f"'>' not supported between instances of 'Fraction' and {type(other)}" def __ge__(self, other) -> bool: if isinstance(other, Fraction): return float(self) >= float(other) raise TypeError( f"'>=' not supported between instances of 'Fraction' and {type(other)}" # abs(self) def __abs__(self): a, b = self.numerator, self.denominator if self.__symbol: return Fraction(a, b) return Fraction(-a, b) # bool(self) def __bool__(self): if self.numerator == 0: return False return True
mysql客户端能创建schema的用户吗 mysql建立用户

今天搭建一个测试环境时,遇到了一个很隐蔽的问题。有必要分享一下 | user | password | host | +------+-------------------------------------------+--------------------+ | root | *81F5E21E