#Method to add a generic item to package

10 messages · Page 1 of 1 (latest)

boreal parcel
#
  • The company has a packaging process, it takes the item and adds the package to it. The packaging process returns a Packaged Element instance. A packaged element is a pair of item and package.

I am thinking to make an array of Package, and add item to it. I dont know how to execute.

ebon wrenBOT
#

This post has been reserved for your question.

Hey @boreal parcel! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

cloud parrot
boreal parcel
#

@cloud parrot appreciate the help thank you

#

however, myitem1 should be a generic not string

#

because it can be either a product or vehicle

cloud parrot
#

from typing import TypeVar, Generic

#

T = TypeVar("T")
P = TypeVar("P")

class PackagedElement(Generic[T, P]):
    def __init__(self, item: T, package: P) -> None:
        self.item = item
        self.package = package```