CPC
This part of the project documentation focuses on
an information-oriented approach. Use it as a
reference for the technical implementation of the
pact_methodology
project code.
Represents a Central Product Classification (CPC) code.
Attributes:
Name | Type | Description |
---|---|---|
code |
str
|
The CPC code. |
title |
str
|
The title of the CPC code. |
section |
str
|
The section of the CPC code. |
division |
str
|
The division of the CPC code. |
group |
str
|
The group of the CPC code. |
class_ |
str
|
The class of the CPC code. |
subclass |
str
|
The subclass of the CPC code. |
Example
cpc = CPC("0111", "Wheat") cpc.code '0111' cpc.title 'Wheat' cpc.section '0'
Source code in pact_methodology/product_footprint/cpc.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
__eq__(other)
Checks equality with another CPC object.
Example
cpc1 = CPC("0111", "Wheat") cpc2 = CPC("0111", "Wheat") cpc3 = CPC("0112", "Maize (corn)") cpc1 == cpc2 True cpc1 == cpc3 False
Source code in pact_methodology/product_footprint/cpc.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
__init__(code, title)
Initializes a CPC object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code
|
str
|
The CPC code. |
required |
title
|
str
|
The title of the CPC code. |
required |
Source code in pact_methodology/product_footprint/cpc.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
A lookup table for CPC codes.
Attributes:
Name | Type | Description |
---|---|---|
filename |
str
|
The name of the CSV file containing the CPC codes. |
cpc_codes |
dict[str, CPC]
|
A dictionary mapping CPC codes to CPC objects. |
Example
lookup = CPCCodeLookup() cpc = lookup.lookup("0111") cpc.title 'Wheat'
Source code in pact_methodology/product_footprint/cpc.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|
__init__()
Initializes a CPCCodeLookup object.
Source code in pact_methodology/product_footprint/cpc.py
73 74 75 76 77 |
|
load_cpc_codes()
Loads the CPC codes from the CSV file.
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the CSV file does not exist. |
Error
|
If there is an error reading the CSV file. |
Source code in pact_methodology/product_footprint/cpc.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
lookup(cpc_code)
Looks up a CPC code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cpc_code
|
str
|
The CPC code to look up. Must be a string of 2-5 digits. |
required |
Returns:
Type | Description |
---|---|
CPC | None
|
CPC | None: The CPC object corresponding to the CPC code, or None if not found. |
Raises:
Type | Description |
---|---|
ValueError
|
If the CPC code is not a numerical string with a maximum length of 5. |
Example
lookup = CPCCodeLookup() cpc = lookup.lookup("0111") cpc.title 'Wheat' lookup.lookup("99999") is None True
Source code in pact_methodology/product_footprint/cpc.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
|