Python實(shí)現(xiàn)大模型Function Calling的實(shí)戰(zhàn)指南
一、什么是 Function Calling?為什么它改變了 AI 的游戲規(guī)則?
傳統(tǒng)大模型的工作方式是這樣的:
用戶提問 → 模型思考 → 返回文本回答
模型只能"紙上談兵"——它不能查天氣、不能發(fā)郵件、不能操作數(shù)據(jù)庫(kù)、不能調(diào)用任何外部系統(tǒng)。
Function Calling 讓模型從"軍師"變成了"將軍":
用戶提問 → 模型思考 → 決定調(diào)用什么工具 → 執(zhí)行工具 → 獲取結(jié)果 → 返回最終回答
| 對(duì)比維度 | 傳統(tǒng)大模型 | 支持 Function Calling |
|---|---|---|
| 能力邊界 | 只能用訓(xùn)練數(shù)據(jù)回答 | 可以調(diào)用任意外部工具 |
| 實(shí)時(shí)性 | 知識(shí)截止日期前 | 可以獲取實(shí)時(shí)數(shù)據(jù) |
| 準(zhǔn)確性 | 數(shù)學(xué)計(jì)算容易出錯(cuò) | 可以調(diào)用計(jì)算器保證精確 |
| 交互性 | 純文本對(duì)話 | 操作數(shù)據(jù)庫(kù)、發(fā)郵件、控制設(shè)備 |
| 可擴(kuò)展性 | 固定能力 | 無(wú)限擴(kuò)展(寫什么工具就能用什么) |
一句話總結(jié):Function Calling = 讓大模型從"只會(huì)聊天"進(jìn)化為"能干實(shí)事"。
二、核心原理:大模型如何"學(xué)會(huì)"調(diào)用工具?
Function Calling 的核心流程并不復(fù)雜:
┌─────────┐ ┌─────────┐ ┌──────────┐ ┌─────────┐ │ 用戶 │ │ 大模型 │ │ 工具函數(shù) │ │ 大模型 │ │ 提問 │────?│ 判斷 │────?│ 執(zhí)行 │────?│ 總結(jié) │──? 最終回答 │ │ │ 需要工具 │ │ 并返回 │ │ 回答 │ └─────────┘ └─────────┘ └──────────┘ └─────────┘
關(guān)鍵步驟:
- 定義工具:告訴模型有哪些工具可用,每個(gè)工具接收什么參數(shù)
- 模型決策:模型根據(jù)用戶輸入,判斷是否需要調(diào)用工具,需要調(diào)用哪個(gè)
- 執(zhí)行工具:你的代碼執(zhí)行對(duì)應(yīng)函數(shù),拿到結(jié)果
- 模型總結(jié):把工具結(jié)果返回給模型,生成最終回答
注意:模型本身不執(zhí)行任何代碼,它只是輸出結(jié)構(gòu)化的 JSON 表示"我想調(diào)用這個(gè)函數(shù)",真正的執(zhí)行由你的 Python 代碼完成。
三、環(huán)境準(zhǔn)備
pip install openai python-dotenv
創(chuàng)建 .env 文件:
OPENAI_API_KEY=sk-your-key-here # 也可以用兼容 OpenAI 接口的國(guó)內(nèi)模型 # OPENAI_BASE_URL=https://api.deepseek.com
四、實(shí)戰(zhàn) 1:天氣查詢工具 —— 從最簡(jiǎn)單的例子開始
4.1 定義工具函數(shù)
# weather_tool.py
import json
from datetime import datetime
# 模擬天氣數(shù)據(jù)(實(shí)際項(xiàng)目中替換為真實(shí) API)
WEATHER_DATA = {
"北京": {"temp": 22, "weather": "晴", "humidity": 45, "wind": "北風(fēng)3級(jí)"},
"上海": {"temp": 26, "weather": "多云", "humidity": 72, "wind": "東南風(fēng)2級(jí)"},
"深圳": {"temp": 30, "weather": "陣雨", "humidity": 85, "wind": "南風(fēng)3級(jí)"},
"成都": {"temp": 20, "weather": "陰", "humidity": 68, "wind": "微風(fēng)"},
"杭州": {"temp": 24, "weather": "晴轉(zhuǎn)多云", "humidity": 60, "wind": "東風(fēng)2級(jí)"},
}
def get_weather(city: str) -> str:
"""查詢指定城市的天氣信息
Args:
city: 城市名稱,如"北京"、"上海"
Returns:
天氣信息的 JSON 字符串
"""
if city in WEATHER_DATA:
data = WEATHER_DATA[city]
return json.dumps({
"city": city,
"temp": data["temp"],
"weather": data["weather"],
"humidity": data["humidity"],
"wind": data["wind"],
"update_time": datetime.now().strftime("%Y-%m-%d %H:%M")
}, ensure_ascii=False)
return json.dumps({"error": f"未找到城市:{city}"}, ensure_ascii=False)
4.2 注冊(cè)工具到模型
# tools定義:告訴模型有哪些工具可用
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "查詢指定城市的實(shí)時(shí)天氣信息,包括溫度、天氣狀況、濕度、風(fēng)力等",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "要查詢的城市名稱,如'北京'、'上海'、'深圳'"
}
},
"required": ["city"]
}
}
}
]
4.3 核心循環(huán):調(diào)用模型 → 解析工具 → 執(zhí)行 → 再調(diào)用
# main.py
import json
from openai import OpenAI
from weather_tool import get_weather
client = OpenAI() # 自動(dòng)讀取環(huán)境變量
# 工具映射表:函數(shù)名 → 實(shí)際函數(shù)
TOOL_MAP = {
"get_weather": get_weather,
}
def chat_with_tools(user_message: str) -> str:
"""帶工具調(diào)用能力的對(duì)話"""
messages = [
{"role": "system", "content": "你是一個(gè)智能助手,可以幫用戶查詢天氣信息?;卮饡r(shí)請(qǐng)用簡(jiǎn)潔自然的語(yǔ)言。"},
{"role": "user", "content": user_message}
]
# 第一次調(diào)用:讓模型判斷是否需要工具
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
tools=tools,
tool_choice="auto" # 自動(dòng)決定是否調(diào)用工具
)
message = response.choices[0].message
# 如果模型決定不調(diào)用工具,直接返回回答
if not message.tool_calls:
return message.content
# 模型決定調(diào)用工具,逐個(gè)執(zhí)行
messages.append(message) # 把模型的工具調(diào)用記錄加入對(duì)話
for tool_call in message.tool_calls:
func_name = tool_call.function.name
func_args = json.loads(tool_call.function.arguments)
print(f" [工具調(diào)用] {func_name}({func_args})")
# 執(zhí)行對(duì)應(yīng)工具
if func_name in TOOL_MAP:
result = TOOL_MAP[func_name](**func_args)
else:
result = json.dumps({"error": f"未知工具:{func_name}"})
# 把工具結(jié)果加入對(duì)話
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": result
})
# 第二次調(diào)用:讓模型根據(jù)工具結(jié)果生成最終回答
final_response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages
)
return final_response.choices[0].message.content
# 測(cè)試
if __name__ == "__main__":
questions = [
"北京今天天氣怎么樣?",
"上海和深圳哪個(gè)城市更熱?",
"推薦一個(gè)適合出游的城市"
]
for q in questions:
print(f"\n提問:{q}")
answer = chat_with_tools(q)
print(f"回答:{answer}")
print("-" * 50)
運(yùn)行效果:
提問:北京今天天氣怎么樣?
[工具調(diào)用] get_weather({'city': '北京'})
回答:北京今天天氣晴朗,氣溫22°C,濕度45%,北風(fēng)3級(jí)。整體來(lái)說天氣不錯(cuò),
適合外出活動(dòng),建議適當(dāng)補(bǔ)水,風(fēng)力稍大注意防護(hù)。
--------------------------------------------------
提問:上海和深圳哪個(gè)城市更熱?
[工具調(diào)用] get_weather({'city': '上海'})
[工具調(diào)用] get_weather({'city': '深圳'})
回答:深圳更熱!深圳目前氣溫30°C,而上海是26°C,深圳比上海高了4度。
不過上海濕度更大(72% vs 85%),體感上深圳更悶熱一些。
--------------------------------------------------
注意第二問:模型自主判斷需要查兩個(gè)城市,并行調(diào)用了兩次工具!
五、實(shí)戰(zhàn) 2:多工具協(xié)作 —— 打造 AI 助手
真實(shí)場(chǎng)景中,我們需要多個(gè)工具協(xié)同工作。下面打造一個(gè)功能更豐富的 AI 助手。
5.1 定義多個(gè)工具
# tools.py
import json
import math
from datetime import datetime
# ========== 工具 1:數(shù)學(xué)計(jì)算器 ==========
def calculator(expression: str) -> str:
"""安全地計(jì)算數(shù)學(xué)表達(dá)式
Args:
expression: 數(shù)學(xué)表達(dá)式,如 "2 + 3 * 4" 或 "sqrt(16)"
"""
# 安全白名單:只允許數(shù)學(xué)函數(shù)和數(shù)字運(yùn)算
ALLOWED_NAMES = {
"abs": abs, "round": round, "min": min, "max": max,
"sqrt": math.sqrt, "pow": pow, "pi": math.pi, "e": math.e,
"sin": math.sin, "cos": math.cos, "tan": math.tan,
"log": math.log, "log10": math.log10, "ceil": math.ceil,
"floor": math.floor,
}
try:
result = eval(expression, {"__builtins__": {}}, ALLOWED_NAMES)
return json.dumps({"expression": expression, "result": result})
except Exception as e:
return json.dumps({"error": f"計(jì)算錯(cuò)誤:{str(e)}"})
# ========== 工具 2:時(shí)間查詢 ==========
def get_current_time(timezone_offset: int = 8) -> str:
"""獲取當(dāng)前時(shí)間
Args:
timezone_offset: 時(shí)區(qū)偏移量,默認(rèn)8(北京時(shí)間 UTC+8)
"""
from datetime import timezone, timedelta
tz = timezone(timedelta(hours=timezone_offset))
now = datetime.now(tz)
return json.dumps({
"current_time": now.strftime("%Y-%m-%d %H:%M:%S"),
"weekday": ["周一", "周二", "周三", "周四", "周五", "周六", "周日"][now.weekday()],
"timezone": f"UTC+{timezone_offset}"
}, ensure_ascii=False)
# ========== 工具 3:?jiǎn)挝粨Q算 ==========
def unit_convert(value: float, from_unit: str, to_unit: str) -> str:
"""單位換算
Args:
value: 原始值
from_unit: 原始單位(km, mile, kg, lb, celsius, fahrenheit 等)
to_unit: 目標(biāo)單位
"""
conversions = {
("km", "mile"): lambda v: v * 0.621371,
("mile", "km"): lambda v: v * 1.60934,
("kg", "lb"): lambda v: v * 2.20462,
("lb", "kg"): lambda v: v * 0.453592,
("celsius", "fahrenheit"): lambda v: v * 9/5 + 32,
("fahrenheit", "celsius"): lambda v: (v - 32) * 5/9,
("meter", "feet"): lambda v: v * 3.28084,
("feet", "meter"): lambda v: v * 0.3048,
}
key = (from_unit.lower(), to_unit.lower())
if key in conversions:
result = conversions[key](value)
return json.dumps({
"original": f"{value} {from_unit}",
"converted": f"{round(result, 4)} {to_unit}"
}, ensure_ascii=False)
return json.dumps({"error": f"不支持的轉(zhuǎn)換:{from_unit} → {to_unit}"})
5.2 注冊(cè)所有工具
# 工具定義
ALL_TOOLS = [
{
"type": "function",
"function": {
"name": "calculator",
"description": "計(jì)算數(shù)學(xué)表達(dá)式,支持加減乘除、三角函數(shù)、對(duì)數(shù)、冪運(yùn)算等。當(dāng)需要精確數(shù)值計(jì)算時(shí)使用。",
"parameters": {
"type": "object",
"properties": {
"expression": {
"type": "string",
"description": "要計(jì)算的數(shù)學(xué)表達(dá)式,如 '2**10'、'sqrt(144)'、'sin(pi/4)'"
}
},
"required": ["expression"]
}
}
},
{
"type": "function",
"function": {
"name": "get_current_time",
"description": "獲取當(dāng)前的日期和時(shí)間",
"parameters": {
"type": "object",
"properties": {
"timezone_offset": {
"type": "integer",
"description": "時(shí)區(qū)偏移量,默認(rèn)為8(北京時(shí)間)"
}
},
"required": []
}
}
},
{
"type": "function",
"function": {
"name": "unit_convert",
"description": "在不同度量單位之間進(jìn)行換算,如長(zhǎng)度、重量、溫度等",
"parameters": {
"type": "object",
"properties": {
"value": {
"type": "number",
"description": "要換算的數(shù)值"
},
"from_unit": {
"type": "string",
"description": "原始單位,如 km、mile、kg、lb、celsius、fahrenheit"
},
"to_unit": {
"type": "string",
"description": "目標(biāo)單位"
}
},
"required": ["value", "from_unit", "to_unit"]
}
}
}
]
# 工具映射
TOOL_MAP = {
"calculator": calculator,
"get_current_time": get_current_time,
"unit_convert": unit_convert,
}
5.3 通用工具調(diào)用引擎
# agent.py
import json
from openai import OpenAI
client = OpenAI()
def agent_chat(user_message: str, system_prompt: str = None, max_rounds: int = 5) -> str:
"""
通用 Function Calling 引擎
Args:
user_message: 用戶輸入
system_prompt: 系統(tǒng)提示詞
max_rounds: 最大工具調(diào)用輪數(shù)(防止死循環(huán))
Returns:
模型的最終回答
"""
messages = []
if system_prompt:
messages.append({"role": "system", "content": system_prompt})
messages.append({"role": "user", "content": user_message})
for round_num in range(max_rounds):
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
tools=ALL_TOOLS,
tool_choice="auto"
)
message = response.choices[0].message
# 沒有工具調(diào)用,返回最終回答
if not message.tool_calls:
return message.content
# 有工具調(diào)用,執(zhí)行所有工具
messages.append(message)
for tool_call in message.tool_calls:
func_name = tool_call.function.name
func_args = json.loads(tool_call.function.arguments)
print(f" ?? [調(diào)用] {func_name}({json.dumps(func_args, ensure_ascii=False)})")
if func_name in TOOL_MAP:
result = TOOL_MAP[func_name](**func_args)
else:
result = json.dumps({"error": f"未知工具:{func_name}"})
print(f" ?? [結(jié)果] {result}")
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": result
})
return "抱歉,工具調(diào)用輪數(shù)已達(dá)上限。"
# 測(cè)試
if __name__ == "__main__":
system_prompt = """你是一個(gè)全能AI助手,具備計(jì)算、時(shí)間查詢和單位換算能力。
回答問題時(shí):
1. 需要精確計(jì)算時(shí),使用計(jì)算器工具
2. 需要知道當(dāng)前時(shí)間時(shí),使用時(shí)間查詢工具
3. 需要單位換算時(shí),使用換算工具
4. 用簡(jiǎn)潔自然的中文回答"""
test_cases = [
"幫我算一下 2 的 20 次方是多少",
"100華氏度等于多少攝氏度?",
"現(xiàn)在幾點(diǎn)了?距離2026年國(guó)慶節(jié)還有多少天?",
"一個(gè)馬拉松42.195公里等于多少英里?跑完大概消耗多少卡路里(按每公里60大卡算)?",
]
for question in test_cases:
print(f"\n{'='*60}")
print(f"?? 提問:{question}")
print(f"{'='*60}")
answer = agent_chat(question, system_prompt)
print(f"\n?? 回答:{answer}")
運(yùn)行效果:
============================================================
?? 提問:100華氏度等于多少攝氏度?
============================================================
?? [調(diào)用] unit_convert({"value": 100, "from_unit": "fahrenheit", "to_unit": "celsius"})
?? [結(jié)果] {"original": "100 fahrenheit", "converted": "37.7778 celsius"}
?? 回答:100華氏度約等于 **37.78攝氏度**,接近人體正常體溫的溫度。
============================================================
六、實(shí)戰(zhàn) 3:工具編排 —— 讓 AI 自主規(guī)劃執(zhí)行鏈
復(fù)雜場(chǎng)景下,模型需要鏈?zhǔn)秸{(diào)用多個(gè)工具。看這個(gè)例子:
# chain_agent.py
import json
from openai import OpenAI
client = OpenAI()
def chain_agent(user_message: str) -> str:
"""
支持多輪工具調(diào)用的智能 Agent
模型可以在一輪中調(diào)用多個(gè)工具,
也可以在拿到結(jié)果后決定是否繼續(xù)調(diào)用更多工具。
"""
messages = [
{
"role": "system",
"content": """你是一個(gè)智能規(guī)劃助手。面對(duì)復(fù)雜問題時(shí):
1. 先分析需要哪些信息
2. 逐步調(diào)用工具獲取信息
3. 基于工具結(jié)果進(jìn)行推理和回答
你必須主動(dòng)調(diào)用工具獲取數(shù)據(jù),不要憑空猜測(cè)。"""
},
{"role": "user", "content": user_message}
]
for round_num in range(10): # 最多 10 輪工具調(diào)用
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
tools=ALL_TOOLS,
tool_choice="auto"
)
message = response.choices[0].message
if not message.tool_calls:
return message.content
messages.append(message)
print(f"\n--- 第 {round_num + 1} 輪工具調(diào)用 ---")
for tool_call in message.tool_calls:
func_name = tool_call.function.name
func_args = json.loads(tool_call.function.arguments)
result = TOOL_MAP[func_name](**func_args)
print(f" {func_name}({json.dumps(func_args, ensure_ascii=False)}) => {result}")
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"content": result
})
return "工具調(diào)用輪數(shù)已達(dá)上限"
# 測(cè)試復(fù)雜鏈?zhǔn)秸{(diào)用
if __name__ == "__main__":
result = chain_agent(
"我想做一個(gè)蛋糕。幫我算一下:如果配方需要把350華氏度的烤箱預(yù)熱,"
"那是多少攝氏度?另外幫我算一下,2.5磅面粉等于多少公斤?"
)
print(f"\n最終回答:\n{result}")
模型會(huì)自主規(guī)劃:先換算溫度,再換算重量,最后綜合回答。
七、進(jìn)階技巧
7.1 強(qiáng)制調(diào)用 / 禁止調(diào)用工具
# 強(qiáng)制模型必須調(diào)用某個(gè)工具
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
tools=tools,
tool_choice={"type": "function", "function": {"name": "get_weather"}}
)
# 禁止調(diào)用任何工具(純對(duì)話模式)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=messages,
tools=tools,
tool_choice="none"
)
7.2 并行工具調(diào)用
GPT-4o / GPT-4o-mini 支持在一輪中并行調(diào)用多個(gè)獨(dú)立工具:
# 當(dāng)用戶問"北京和上海天氣對(duì)比"時(shí),
# 模型會(huì)在一個(gè) tool_calls 中返回兩個(gè)調(diào)用:
# tool_calls[0]: get_weather({"city": "北京"})
# tool_calls[1]: get_weather({"city": "上海"})
7.3 錯(cuò)誤處理與重試
def safe_tool_call(func, **kwargs, max_retries=2):
"""帶重試的安全工具調(diào)用"""
for attempt in range(max_retries + 1):
try:
result = func(**kwargs)
return result
except Exception as e:
if attempt == max_retries:
return json.dumps({"error": f"工具執(zhí)行失敗(已重試{max_retries}次):{str(e)}"})
print(f" ?? 工具執(zhí)行失敗,正在重試({attempt + 1}/{max_retries})...")
八、性能與成本分析
| 項(xiàng)目 | 數(shù)據(jù) |
|---|---|
| 單次工具調(diào)用延遲 | 約增加 0.5-1s |
| Token 消耗 | 工具定義約 100-300 tokens/個(gè) |
| 建議單次對(duì)話工具數(shù) | 3-10 個(gè)(太多模型會(huì)混亂) |
| 推薦模型 | GPT-4o-mini(性價(jià)比最高)、GPT-4o(復(fù)雜場(chǎng)景)、DeepSeek-V3 |
成本估算(GPT-4o-mini):
- 輸入:$0.15 / 1M tokens
- 輸出:$0.6 / 1M tokens
- 一次包含 3 個(gè)工具的完整對(duì)話:約 0.1-0.3 美分
九、踩坑指南
- 工具描述是靈魂:
description寫得越清晰,模型選錯(cuò)工具的概率越低。不要寫"查詢信息",要寫"查詢指定城市的實(shí)時(shí)天氣,包括溫度、濕度、風(fēng)力" - 參數(shù)類型要準(zhǔn)確:
integer就不要寫string,模型會(huì)根據(jù)類型生成不同格式的參數(shù) - 防止注入:工具函數(shù)的參數(shù)來(lái)自模型輸出,務(wù)必做安全校驗(yàn)
- 上下文窗口:每輪工具調(diào)用都會(huì)增加消息長(zhǎng)度,注意
max_tokens限制 - 冪等性:工具函數(shù)盡量設(shè)計(jì)為冪等的(同一參數(shù)多次調(diào)用結(jié)果一致),因?yàn)槟P涂赡苤貜?fù)調(diào)用
總結(jié)
Function Calling 的工作模式:
定義工具 → 注冊(cè)給模型 → 模型自主決策 → 代碼執(zhí)行工具 → 結(jié)果返回模型 → 生成最終回答
| 能力 | 傳統(tǒng)大模型 | + Function Calling |
|---|---|---|
| 數(shù)學(xué)計(jì)算 | 容易出錯(cuò) | 精確無(wú)誤 |
| 實(shí)時(shí)信息 | 無(wú)法獲取 | 隨時(shí)查詢 |
| 外部操作 | 無(wú)能為力 | 無(wú)限擴(kuò)展 |
| 多步推理 | 靠譜度一般 | 工具鏈保障 |
Function Calling 是 AI Agent 的基石。掌握了它,你就掌握了讓大模型真正"干活"的能力。下一步可以結(jié)合 LangChain、CrewAI 等框架,構(gòu)建更復(fù)雜的多 Agent 協(xié)作系統(tǒng)。
如果覺得有用,點(diǎn)贊收藏不迷路!下期我們將深入探討 RAG 檢索增強(qiáng)生成,讓 AI 擁有你的私有知識(shí)庫(kù)。
以上就是Python實(shí)現(xiàn)大模型Function Calling的實(shí)戰(zhàn)指南的詳細(xì)內(nèi)容,更多關(guān)于Python大模型Function Calling的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
使用Python對(duì)MySQL數(shù)據(jù)操作
本文介紹Python3使用PyMySQL連接數(shù)據(jù)庫(kù),并實(shí)現(xiàn)簡(jiǎn)單的增刪改查。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-04-04
Python實(shí)現(xiàn)Linux下守護(hù)進(jìn)程的編寫方法
這篇文章主要介紹了Python實(shí)現(xiàn)Linux下守護(hù)進(jìn)程的編寫方法,比較實(shí)用的一個(gè)技巧,需要的朋友可以參考下2014-08-08
Python兩個(gè)整數(shù)相除得到浮點(diǎn)數(shù)值的方法
這篇文章主要介紹了Python兩個(gè)整數(shù)相除得到浮點(diǎn)數(shù)值的方法,本文直接給出代碼示例,需要的朋友可以參考下2015-03-03
Python+PyQt5實(shí)現(xiàn)自動(dòng)化任務(wù)管理
這篇文章主要為大家詳細(xì)介紹了如何通過PyQt5構(gòu)建圖形界面,使用Python實(shí)現(xiàn)了一個(gè)自動(dòng)化任務(wù)管理系統(tǒng),感興趣的小伙伴可以參考一下2025-04-04
使用Python爬取Json數(shù)據(jù)的示例代碼
這篇文章主要介紹了使用Python爬取Json數(shù)據(jù)的示例代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12
Python中多繼承與菱形繼承問題的解決方案與實(shí)踐
在Python這個(gè)靈活且功能強(qiáng)大的編程語(yǔ)言中,多繼承是一個(gè)既強(qiáng)大又復(fù)雜的概念,它允許一個(gè)類繼承自多個(gè)父類,從而能夠復(fù)用多個(gè)父類的屬性和方法,本文將深入解釋Python中的多繼承概念,詳細(xì)剖析菱形繼承問題,并探討Python是如何解決這一難題的,需要的朋友可以參考下2024-07-07
在Flask使用TensorFlow的幾個(gè)常見錯(cuò)誤及解決
這篇文章主要介紹了在Flask使用TensorFlow的幾個(gè)常見錯(cuò)誤及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01
如何使用Python連接?SSH?服務(wù)器并執(zhí)行命令
實(shí)際開發(fā)中,有時(shí)候經(jīng)常需要查看日志,有時(shí)候使用ssh工具打開就為了看一下錯(cuò)誤日志又比較麻煩,所以今天帶來(lái)一個(gè)簡(jiǎn)單的基于python的小工具,感興趣的朋友跟隨小編一起看看吧2023-11-11

