python库存管理系统
时间: 2023-10-29 11:56:37 浏览: 242
Python库存管理系统是一个用于管理库存信息的系统。它包括了增加产品信息、产品信息报表、增加货架位置、货架位置报表、商品入库管理、商品出库管理、商品库存信息报表等功能菜单选项。[1]
这个系统的实现主要包括了数据管理模块data.py和用户界面交互模块ui.py。data.py负责数据的管理,通过使用Python标准库中的json模块的loads()函数和dumps()函数,实现从JSON文件读取数据和转储数据到JSON文件的功能。
其中,商品库存信息报表功能可以通过调用ui模块中的report_items()函数实现,它可以显示库存信息列表。
在主模块main.py中,导入data和ui模块,并定义了一个main()函数。在这个函数中,首先调用data.init()函数从磁盘的JSON格式文件中读取数据。然后,在一个无限循环中,调用ui.prompt_for_action()函数显示功能菜单,并根据用户的选择调用相应模块的功能实现。
这是一个简单而实用的Python库存管理系统,可以帮助用户轻松管理和跟踪库存信息。
相关问题
Python库存管理系统
### 如何使用Python实现库存管理系统
#### 创建项目结构
创建一个新的目录用于保存整个项目的文件,在该目录下建立 `inventory_system.py` 文件来编写核心逻辑[^1]。
#### 设计功能模块
为了简化说明,这里定义几个基本的功能函数:添加商品(add),修改商品(modify),展示所有商品(show)以及删除商品(delete)[^4]。这些操作可以通过字典或者列表数据结构临时存储商品信息;对于更复杂的应用场景,则建议采用关系型数据库配合ORM框架(如SQLAlchemy),以便更好地管理和维护大量数据[^3]。
#### 编写主程序入口
下面是一个简单的命令行界面CLI(Command Line Interface)版本的库存管理系统的示例代码:
```python
from typing import Dict, List
class InventorySystem:
def __init__(self):
self.products: Dict[str, dict] = {}
def add(self, product_id: str, name: str, quantity: int, price: float):
"""Add a new product to the inventory."""
if product_id not in self.products:
self.products[product_id] = {"name": name, "quantity": quantity, "price": price}
print(f"Product '{name}' added successfully.")
else:
print("Error: Product ID already exists.")
def modify(self, product_id: str, **kwargs):
"""Modify an existing product's details."""
if product_id in self.products:
for key, value in kwargs.items():
if key in ["name", "quantity", "price"]:
self.products[product_id][key] = value
print(f"Product '{product_id}' updated successfully.")
else:
print("Error: No such product found.")
def show(self):
"""Display all products currently stored in the system."""
if not self.products:
print("No items available.")
else:
for pid, info in self.products.items():
print(f"ID:{pid}, Name:{info['name']}, Quantity:{info['quantity']}, Price:${info['price']}")
def delete(self, product_id: str):
"""Remove a specific item by its unique identifier (product id)."""
removed_item = self.products.pop(product_id, None)
if removed_item is None:
print("Error: No such product found.")
else:
print(f"Product '{removed_item['name']}' has been deleted.")
if __name__ == "__main__":
inv_sys = InventorySystem()
while True:
action = input("\nChoose your operation:\n"
"[A]dd\n[M]odify\n[S]how All\n[D]elete\n[E]xit\n").upper()
match action:
case 'A':
try:
prod_id = input("Enter Product ID:")
name = input("Enter Product Name:")
qty = int(input("Enter Quantity:"))
prc = float(input("Enter Unit Price($):"))
inv_sys.add(prod_id, name, qty, prc)
except ValueError as e:
print(e)
case 'M':
try:
prod_id = input("Which Product do you want to change? Enter ID:")
field_to_update = input("What would you like to update?(name/quantity/price)")
new_value = input("New Value:")
inv_sys.modify(prod_id, **{field_to_update:new_value})
except Exception as ex:
print(ex)
case 'S':
inv_sys.show()
case 'D':
try:
prod_id = input("Which Product should be removed? Enter ID:")
inv_sys.delete(prod_id)
except KeyError as ke:
print(ke)
case 'E':
break
case _ :
print("Invalid choice! Please select again.")
```
此脚本提供了一个简易的商品增删改查接口,并通过循环读取用户的输入来进行相应的处理。
一个python库存管理系统的示例
好的,这是一个简单的 Python 库存管理系统示例:
```python
class Product:
def __init__(self, name, price, quantity):
self.name = name
self.price = price
self.quantity = quantity
class Inventory:
def __init__(self):
self.products = []
def add_product(self, product):
self.products.append(product)
def remove_product(self, product):
self.products.remove(product)
def total_value(self):
return sum([product.price * product.quantity for product in self.products])
inventory = Inventory()
p1 = Product("T-shirt", 20, 10)
p2 = Product("Pants", 30, 5)
inventory.add_product(p1)
inventory.add_product(p2)
print(inventory.total_value())
```
这个示例中,我们定义了两个类 `Product` 和 `Inventory`。`Product` 表示一个商品,包括名称、价格和数量;`Inventory` 表示存货,包括所有的商品。这个库存管理系统实现了一些基本功能,包括添加、移除商品、计算总价值等。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)