how to pass parameters from the class Vetrina: self.item_price, self.item_name, self.item_am, class User.Buyer

class Vitrina: def __init__(self,name,am,price): self.item_name=name self.item_am=am self.item_price=price print(self.item_name,' amount ',self.item_am,' price',self.item_price) def popolnenie(self,a,b): if self.item_name == a: self.item_am+=b print(self.item_name,' amount ',self.item_am) class User: class Buyer(): def __init__(self,addr,ballance): self.addr=addr self.ballance=ballance print('addr is ',self.addr,'your ballance is',self.ballance) def popolnenie(self,a): self.ballance += a print('your ballance is',self.ballance) def buy(self,name,am): if self.ballance>=self.item_am*self.item_price: if am<=self.item_am and name == self.item_name: ballance -= self.item_am* self.item_price print('You buy ',name ,' you ballance is',ballance,' your addr is ',self.addr) else: print('you cant buy it') else: print('your ballance very smoll to buy ',name) 
  • I understand correctly that you want the buyer to make a “familiarize with the shop window” method, where the input will be the shop window class? - Eugene Dennis
  • @EugeneDennis I need to make a product purchase method - the method takes as input the number of product units and the name. - Merk G9
  • and where is the showcase? - Eugene Dennis
  • @EugeneDennis in the showcase class stores the name of the product, its cost and quantity. All this data needs to be passed to the User.Buyer class. - Merk G9
  • The answer was given an example of transferring attributes between classes, does not suit you? - Eugene Dennis

1 answer 1

It is not entirely clear that, after all, it is really necessary to pass a class parameter to another class or a class instance parameter to an instance of another class. If, after all, you need exactly what is indicated in the question header, then such a scheme can work:

 class c1(): c1str='blahblah' def __init__(self): pass class c2(): def __init__(self): self.c2str=c1().c1str print(c2().c2str) 

Displays:

 blahblah