Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16891

How do I pass a data class into the parameters of a regular class in python?

$
0
0

I want to instantiate a regular class Motion using the dataclass Points, and the regular class is supposed to have four parameters namely self, x, y, and z. However, when I pass the dataclass to the regular class,and run the test method, I get the error:

Motion.__init__() missing 2 required positional arguments: 'y' and 'z'.

How do I fix this?

Source code:

from dataclasses import dataclass@dataclass class Points:    x: int    y: int    z: intclass Motion:   def __init__(self, x:int, y:int, z:int):       self.x = x       self.y = y       self.z = z   def test(self):      print(self.x, self.y, self.z)result = Motion(Points(1,2,3))result.test()

Viewing all articles
Browse latest Browse all 16891


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>