Python self.update() 使用詳細(xì)
什么是self.update()
self.update() 并不是 Python 的內(nèi)置關(guān)鍵字,而是在不同上下文中的方法調(diào)用:
| 場景 | self 代表 | update() 作用 |
|---|---|---|
| 字典操作 | 字典實(shí)例 | 合并/更新鍵值對 |
| 集合操作 | 集合實(shí)例 | 添加多個(gè)元素 |
| 自定義類 | 類的實(shí)例 | 自定義更新邏輯 |
| GUI 開發(fā) | 窗口/控件對象 | 刷新界面顯示 |
理解 self 是關(guān)鍵:self 代表類的實(shí)例對象本身,通過 self.method() 可以調(diào)用對象的方法。
字典中的update()方法
字典的 update() 是最常用的場景,用于批量更新或合并字典。
1. 基礎(chǔ)用法
class ConfigManager:
"""配置管理器類 - 演示字典 update()"""
def __init__(self):
# 初始化默認(rèn)配置
self.config = {
'host': 'localhost',
'port': 8080,
'debug': False,
'timeout': 30
}
print("初始配置:", self.config)
def update_config(self, new_settings):
"""
使用 self.config.update() 更新配置
new_settings: 新的配置項(xiàng)字典
"""
# 使用 update() 合并字典
self.config.update(new_settings)
print("更新后配置:", self.config)
def update_single(self, key, value):
"""更新單個(gè)配置項(xiàng)"""
self.config.update({key: value})
# 或者直接用: self.config[key] = value
# 使用示例
manager = ConfigManager()
# 輸出: 初始配置: {'host': 'localhost', 'port': 8080, 'debug': False, 'timeout': 30}
# 批量更新多個(gè)配置
manager.update_config({
'port': 9090,
'debug': True,
'new_option': 'enabled'
})
# 輸出: 更新后配置: {'host': 'localhost', 'port': 9090, 'debug': True,
# 'timeout': 30, 'new_option': 'enabled'}2. update() 的多種參數(shù)形式
class DictUpdateDemo:
"""演示 update() 的各種用法"""
def __init__(self):
self.data = {'a': 1, 'b': 2}
print(f"初始: {self.data}")
def update_with_dict(self):
"""方式1:傳入字典"""
self.data.update({'c': 3, 'd': 4})
print(f"傳入字典: {self.data}")
# {'a': 1, 'b': 2, 'c': 3, 'd': 4}
def update_with_kwargs(self):
"""方式2:關(guān)鍵字參數(shù)(key=value)"""
self.data.update(e=5, f=6)
print(f"關(guān)鍵字參數(shù): {self.data}")
# {'a': 1, 'b': 2, 'e': 5, 'f': 6}
def update_with_iterable(self):
"""方式3:傳入可迭代對象(鍵值對列表)"""
self.data.update([('g', 7), ('h', 8)])
print(f"可迭代對象: {self.data}")
# {'a': 1, 'b': 2, 'g': 7, 'h': 8}
def update_mixed(self):
"""方式4:混合使用"""
self.data.update({'i': 9}, j=10)
print(f"混合使用: {self.data}")
# 分別測試
demo = DictUpdateDemo()
demo.update_with_dict()
demo.update_with_kwargs()
demo.update_with_iterable()
demo.update_mixed()3. 覆蓋更新與條件更新
class SmartUpdater:
"""智能更新 - 處理沖突和條件更新"""
def __init__(self):
self.user_info = {
'name': '張三',
'age': 25,
'email': 'zhangsan@example.com'
}
def safe_update(self, new_data, overwrite=True):
"""
安全更新:可選擇是否覆蓋現(xiàn)有值
overwrite=True: 新值覆蓋舊值(默認(rèn))
overwrite=False: 只添加不存在的鍵
"""
if overwrite:
# 標(biāo)準(zhǔn) update:新值覆蓋舊值
self.user_info.update(new_data)
else:
# 只更新不存在的鍵
for key, value in new_data.items():
if key not in self.user_info:
self.user_info.update({key: value})
return self.user_info
def selective_update(self, new_data, allowed_keys=None):
"""
選擇性更新:只允許更新指定字段
allowed_keys: 允許更新的鍵列表,None 表示全部允許
"""
if allowed_keys is None:
self.user_info.update(new_data)
else:
# 過濾只允許更新的鍵
filtered = {k: v for k, v in new_data.items() if k in allowed_keys}
self.user_info.update(filtered)
return self.user_info
# 使用示例
updater = SmartUpdater()
# 測試安全更新
print(updater.safe_update({'age': 26, 'city': '北京'}, overwrite=False))
# age 不會(huì)被覆蓋,city 被添加
# 測試選擇性更新(只允許更新 email,不允許更新 name)
print(updater.selective_update(
{'name': '李四', 'email': 'lisi@example.com'},
allowed_keys=['email']
))
# 只有 email 被更新集合中的update()方法
集合的 update() 用于批量添加元素,類似于列表的 extend()。
class TagManager:
"""標(biāo)簽管理器 - 演示集合 update()"""
def __init__(self):
self.tags = {'python', 'programming'}
print(f"初始標(biāo)簽: {self.tags}")
def add_tags(self, new_tags):
"""
使用 self.tags.update() 添加多個(gè)標(biāo)簽
new_tags: 可以是集合、列表、元組或字符串
"""
# update() 會(huì)將可迭代對象的每個(gè)元素加入集合
self.tags.update(new_tags)
print(f"添加后: {self.tags}")
def merge_from_other(self, other_manager):
"""合并另一個(gè)標(biāo)簽管理器的標(biāo)簽"""
if isinstance(other_manager, TagManager):
self.tags.update(other_manager.tags)
print(f"合并后: {self.tags}")
# 使用示例
tag_mgr = TagManager()
# 傳入列表
tag_mgr.add_tags(['web', 'django', 'python']) # python 已存在,不會(huì)重復(fù)
# 傳入集合
tag_mgr.add_tags({'database', 'sql'})
# 傳入字符串(注意:字符串會(huì)被拆分成單個(gè)字符?。?
tag_mgr.add_tags('ai') # 添加 'a', 'i' 兩個(gè)字符,可能不是預(yù)期結(jié)果
# 正確做法:傳入單元素列表
tag_mgr.add_tags(['ai']) # 添加 'ai' 作為一個(gè)標(biāo)簽
# 合并另一個(gè)管理器
other = TagManager()
other.add_tags(['machine-learning', 'tensorflow'])
tag_mgr.merge_from_other(other)重要區(qū)別:
class SetVsListUpdate:
"""對比 update() 的不同行為"""
def __init__(self):
self.my_set = set()
self.my_list = []
self.my_dict = {}
def demonstrate(self):
# 集合 update() - 添加元素
self.my_set.update([1, 2, 3])
print(f"集合: {self.my_set}") # {1, 2, 3}
self.my_set.update([3, 4, 5]) # 3 已存在,不會(huì)重復(fù)
print(f"集合(去重): {self.my_set}") # {1, 2, 3, 4, 5}
# 列表沒有 update() 方法,用 extend()
self.my_list.extend([1, 2, 3])
print(f"列表: {self.my_list}") # [1, 2, 3]
# 字典 update() - 更新鍵值對
self.my_dict.update({'a': 1, 'b': 2})
print(f"字典: {self.my_dict}") # {'a': 1, 'b': 2}
demo = SetVsListUpdate()
demo.demonstrate()類中的自定義update()方法
在實(shí)際項(xiàng)目中,我們經(jīng)常需要為自定義類實(shí)現(xiàn) update() 方法,用于更新對象狀態(tài)。
1. 基礎(chǔ)自定義 update()
class Student:
"""學(xué)生類 - 自定義 update() 方法"""
def __init__(self, name, age, grade):
self.name = name
self.age = age
self.grade = grade
self.courses = []
self.scores = {}
def update(self, **kwargs):
"""
自定義 update 方法:批量更新學(xué)生信息
kwargs: 支持更新 name, age, grade, courses, scores
"""
allowed_fields = {'name', 'age', 'grade', 'courses', 'scores'}
for key, value in kwargs.items():
if key in allowed_fields:
# 使用 setattr 動(dòng)態(tài)設(shè)置屬性
setattr(self, key, value)
print(f"更新 {key}: {value}")
else:
print(f"警告: 未知字段 '{key}',已忽略")
def add_course(self, course, score=None):
"""添加課程"""
if course not in self.courses:
self.courses.append(course)
if score is not None:
self.scores[course] = score
def __repr__(self):
return (f"Student(name='{self.name}', age={self.age}, "
f"grade='{self.grade}', courses={self.courses}, "
f"scores={self.scores})")
# 使用示例
student = Student("小明", 15, "初三")
print(student)
# Student(name='小明', age=15, grade='初三', courses=[], scores={})
# 使用自定義 update()
student.update(
age=16,
grade="高一",
courses=["數(shù)學(xué)", "物理"],
scores={"數(shù)學(xué)": 95, "物理": 88}
)
print(student)2. 帶驗(yàn)證的 update()
class BankAccount:
"""銀行賬戶類 - 帶驗(yàn)證的 update()"""
def __init__(self, account_id, owner, balance=0):
self.account_id = account_id
self.owner = owner
self._balance = balance # 受保護(hù)屬性
self.status = "active"
self.transaction_history = []
@property
def balance(self):
"""只讀屬性:余額"""
return self._balance
def update(self, **kwargs):
"""
更新賬戶信息,帶數(shù)據(jù)驗(yàn)證
允許更新:owner, status
不允許直接更新:balance(必須通過 deposit/withdraw)
"""
updatable_fields = {
'owner': self._validate_owner,
'status': self._validate_status
}
for key, value in kwargs.items():
if key in updatable_fields:
# 調(diào)用驗(yàn)證函數(shù)
validated_value = updatable_fields[key](value)
setattr(self, key, validated_value)
self._log_transaction(f"UPDATE_{key}", value)
elif key == 'balance':
raise ValueError("不能直接修改余額,請使用 deposit() 或 withdraw()")
else:
raise AttributeError(f"不能更新未知屬性 '{key}'")
def _validate_owner(self, name):
"""驗(yàn)證戶主姓名"""
if not isinstance(name, str) or len(name) < 2:
raise ValueError("戶主姓名必須是至少2個(gè)字符的字符串")
return name
def _validate_status(self, status):
"""驗(yàn)證賬戶狀態(tài)"""
valid_statuses = {'active', 'frozen', 'closed'}
if status not in valid_statuses:
raise ValueError(f"狀態(tài)必須是 {valid_statuses} 之一")
return status
def _log_transaction(self, action, amount):
"""記錄交易日志"""
from datetime import datetime
self.transaction_history.append({
'time': datetime.now().isoformat(),
'action': action,
'value': amount
})
def deposit(self, amount):
"""存款"""
if amount <= 0:
raise ValueError("存款金額必須大于0")
self._balance += amount
self._log_transaction("DEPOSIT", amount)
def withdraw(self, amount):
"""取款"""
if amount <= 0:
raise ValueError("取款金額必須大于0")
if amount > self._balance:
raise ValueError("余額不足")
self._balance -= amount
self._log_transaction("WITHDRAW", amount)
# 使用示例
account = BankAccount("10086", "張三", 1000)
# 正常更新
account.update(owner="張三豐", status="active")
print(f"戶主: {account.owner}, 狀態(tài): {account.status}")
# 錯(cuò)誤更新(會(huì)被攔截)
try:
account.update(balance=9999) # 報(bào)錯(cuò)!
except ValueError as e:
print(f"錯(cuò)誤: {e}")
try:
account.update(status="invalid") # 報(bào)錯(cuò)!
except ValueError as e:
print(f"錯(cuò)誤: {e}")
# 正常存取款
account.deposit(500)
account.withdraw(200)
print(f"當(dāng)前余額: {account.balance}")
print(f"交易記錄: {account.transaction_history}")3. 級聯(lián)更新(更新關(guān)聯(lián)對象)
class Department:
"""部門類"""
def __init__(self, name):
self.name = name
self.employees = []
def add_employee(self, employee):
self.employees.append(employee)
employee.department = self
def update(self, **kwargs):
"""更新部門信息,同時(shí)通知所有員工"""
old_name = self.name
if 'name' in kwargs:
self.name = kwargs['name']
# 級聯(lián)更新:通知所有員工部門名稱變更
for emp in self.employees:
emp.update(department_name=self.name)
print(f"部門名從 '{old_name}' 更新為 '{self.name}'")
if 'budget' in kwargs:
self.budget = kwargs['budget']
print(f"部門預(yù)算更新為: {kwargs['budget']}")
class Employee:
"""員工類"""
def __init__(self, name, emp_id):
self.name = name
self.emp_id = emp_id
self.department = None
self.info = {
'position': '員工',
'salary': 5000,
'department_name': None
}
def update(self, **kwargs):
"""更新員工信息"""
# 更新基本信息字典
self.info.update(kwargs)
# 處理特殊邏輯
if 'salary' in kwargs:
print(f"{self.name} 的薪資調(diào)整為: {kwargs['salary']}")
if 'department_name' in kwargs:
print(f"{self.name} 的部門變更為: {kwargs['department_name']}")
# 使用示例
dept = Department("技術(shù)部")
emp1 = Employee("張三", "E001")
emp2 = Employee("李四", "E002")
dept.add_employee(emp1)
dept.add_employee(emp2)
# 更新部門名,會(huì)自動(dòng)通知所有員工
dept.update(name="研發(fā)部")GUI 編程中的update()方法
在 Tkinter 等 GUI 庫中,update() 用于強(qiáng)制刷新界面。
import tkinter as tk
from tkinter import ttk
import time
class ProgressApp:
"""演示 GUI 中的 update()"""
def __init__(self, root):
self.root = root
self.root.title("進(jìn)度條示例")
self.root.geometry("400x200")
# 創(chuàng)建界面組件
self.label = tk.Label(root, text="準(zhǔn)備開始...", font=("Arial", 14))
self.label.pack(pady=20)
self.progress = ttk.Progressbar(root, length=300, mode='determinate')
self.progress.pack(pady=20)
self.btn = tk.Button(root, text="開始任務(wù)", command=self.start_task)
self.btn.pack(pady=20)
self.counter = 0
def start_task(self):
"""模擬耗時(shí)任務(wù),使用 update() 刷新界面"""
self.btn.config(state='disabled')
for i in range(101):
# 更新進(jìn)度條
self.progress['value'] = i
self.label.config(text=f"進(jìn)度: {i}%")
# 關(guān)鍵:調(diào)用 update() 強(qiáng)制刷新界面
# 否則界面會(huì)卡死,直到循環(huán)結(jié)束才一次性顯示
self.root.update()
# 模擬耗時(shí)操作
time.sleep(0.05)
self.label.config(text="任務(wù)完成!")
self.btn.config(state='normal')
def update_status(self, message):
"""
自定義 update 方法:更新狀態(tài)標(biāo)簽
注意:這里我們自定義方法名避免與 tkinter 的 update() 沖突
"""
self.label.config(text=message)
self.root.update_idletasks() # 更輕量級的刷新
# 運(yùn)行應(yīng)用
if __name__ == "__main__":
root = tk.Tk()
app = ProgressApp(root)
root.mainloop()GUI 中 update() 的注意事項(xiàng)
class GUITips:
"""GUI update() 使用技巧"""
def __init__(self, root):
self.root = root
def method1_update(self):
"""
update() - 處理所有掛起的事件
會(huì)立即處理所有事件(包括按鈕點(diǎn)擊等)
可能導(dǎo)致遞歸問題
"""
self.root.update()
def method2_update_idletasks(self):
"""
update_idletasks() - 只處理"空閑"任務(wù)
更安全,只更新界面顯示,不處理用戶輸入事件
推薦用于進(jìn)度更新
"""
self.root.update_idletasks()
def method3_after(self):
"""
after() - 更好的替代方案
將任務(wù)放入事件隊(duì)列,不阻塞主線程
"""
self.root.after(100, self.do_something) # 100ms后執(zhí)行
def do_something(self):
pass實(shí)際應(yīng)用案例
案例1:配置管理系統(tǒng)(綜合應(yīng)用)
import json
import os
from datetime import datetime
class AppConfig:
"""應(yīng)用配置管理類 - 綜合使用 update()"""
CONFIG_FILE = "app_config.json"
def __init__(self):
self._config = {
'version': '1.0.0',
'last_updated': None,
'settings': {
'theme': 'light',
'language': 'zh-CN',
'notifications': True
},
'user_preferences': {}
}
self._observers = [] # 觀察者列表
self.load()
def update(self, section=None, **kwargs):
"""
智能更新配置
section: 要更新的配置節(jié),None 表示根級別
kwargs: 要更新的鍵值對
"""
target = self._config.get(section, {}) if section else self._config
# 記錄變更
changes = {}
for key, value in kwargs.items():
old_value = target.get(key)
if old_value != value:
changes[key] = {'old': old_value, 'new': value}
target[key] = value
if changes:
self._config['last_updated'] = datetime.now().isoformat()
self._notify_observers(section, changes)
self.save()
print(f"配置已更新: {changes}")
return len(changes) > 0
def batch_update(self, updates_dict):
"""
批量更新多個(gè)配置節(jié)
updates_dict: {
'settings': {'theme': 'dark'},
'user_preferences': {'font_size': 14}
}
"""
for section, values in updates_dict.items():
self.update(section, **values)
def add_observer(self, callback):
"""添加配置變更觀察者"""
self._observers.append(callback)
def _notify_observers(self, section, changes):
"""通知所有觀察者"""
for callback in self._observers:
try:
callback(section, changes)
except Exception as e:
print(f"通知觀察者失敗: {e}")
def save(self):
"""保存到文件"""
with open(self.CONFIG_FILE, 'w', encoding='utf-8') as f:
json.dump(self._config, f, ensure_ascii=False, indent=2)
def load(self):
"""從文件加載"""
if os.path.exists(self.CONFIG_FILE):
with open(self.CONFIG_FILE, 'r', encoding='utf-8') as f:
loaded = json.load(f)
# 使用 update 合并配置(保留默認(rèn)值)
self._config.update(loaded)
def get(self, key, default=None, section=None):
"""獲取配置值"""
target = self._config.get(section, {}) if section else self._config
return target.get(key, default)
def __repr__(self):
return f"AppConfig({json.dumps(self._config, ensure_ascii=False, indent=2)})"
# 使用示例
def on_config_changed(section, changes):
"""配置變更回調(diào)函數(shù)"""
print(f"[觀察者] 節(jié) '{section}' 發(fā)生變更: {changes}")
config = AppConfig()
config.add_observer(on_config_changed)
# 更新單個(gè)配置
config.update(section='settings', theme='dark')
# 批量更新
config.batch_update({
'settings': {'language': 'en-US'},
'user_preferences': {'sidebar_collapsed': True}
})
print(config.get('theme', section='settings'))案例2:數(shù)據(jù)同步系統(tǒng)
class DataSynchronizer:
"""數(shù)據(jù)同步器 - 使用 update() 合并數(shù)據(jù)"""
def __init__(self):
self.local_data = {}
self.remote_data = {}
self.sync_log = []
def fetch_remote(self, data):
"""模擬獲取遠(yuǎn)程數(shù)據(jù)"""
self.remote_data = data
def sync(self, conflict_strategy='remote_wins'):
"""
同步本地和遠(yuǎn)程數(shù)據(jù)
conflict_strategy:
- 'remote_wins': 遠(yuǎn)程數(shù)據(jù)優(yōu)先(默認(rèn))
- 'local_wins': 本地?cái)?shù)據(jù)優(yōu)先
- 'merge': 嘗試合并
"""
if not self.remote_data:
print("沒有遠(yuǎn)程數(shù)據(jù)需要同步")
return
conflicts = []
for key, remote_value in self.remote_data.items():
if key in self.local_data:
local_value = self.local_data[key]
if local_value != remote_value:
conflicts.append({
'key': key,
'local': local_value,
'remote': remote_value
})
# 根據(jù)策略解決沖突
if conflict_strategy == 'remote_wins':
self.local_data.update({key: remote_value})
elif conflict_strategy == 'local_wins':
pass # 保留本地,不更新
elif conflict_strategy == 'merge':
if isinstance(local_value, dict) and isinstance(remote_value, dict):
# 遞歸合并字典
local_value.update(remote_value)
else:
self.local_data.update({key: remote_value})
else:
# 新增數(shù)據(jù)
self.local_data.update({key: remote_value})
# 記錄同步日志
self.sync_log.append({
'timestamp': datetime.now().isoformat(),
'conflicts_resolved': len(conflicts),
'strategy': conflict_strategy
})
print(f"同步完成,解決沖突: {len(conflicts)}")
return conflicts
# 使用示例
syncer = DataSynchronizer()
syncer.local_data = {
'user': {'name': '張三', 'age': 25},
'settings': {'theme': 'light'}
}
syncer.fetch_remote({
'user': {'name': '張三', 'age': 26, 'email': 'zhangsan@example.com'},
'settings': {'theme': 'dark', 'notifications': True}
})
conflicts = syncer.sync(conflict_strategy='merge')
print(f"本地?cái)?shù)據(jù): {syncer.local_data}")常見錯(cuò)誤與解決方案
1.NoneType錯(cuò)誤
class CommonMistakes:
"""常見錯(cuò)誤示例"""
def mistake1_none_check(self):
"""錯(cuò)誤:不檢查 find() 返回 None"""
import xml.etree.ElementTree as ET
root = ET.fromstring('<root><item>1</item></root>')
element = root.find('nonexistent') # 返回 None
# ? 錯(cuò)誤:直接調(diào)用 update()
# element.update({'a': 1}) # AttributeError: 'NoneType'
# ? 正確:先檢查
if element is not None:
element.update({'a': 1})
else:
print("元素未找到")
def mistake2_dict_vs_list(self):
"""錯(cuò)誤:混淆字典和列表"""
self.data = []
# ? 錯(cuò)誤:列表沒有 update()
# self.data.update([1, 2, 3]) # AttributeError
# ? 正確:列表用 extend()
self.data.extend([1, 2, 3])
# 或者如果是字典
self.data = {}
self.data.update({'a': 1}) # ? 正確
def mistake3_immutable_types(self):
"""錯(cuò)誤:嘗試更新不可變類型"""
self.tuple_data = (1, 2, 3)
# ? 錯(cuò)誤:元組沒有 update()
# self.tuple_data.update((4, 5))
# ? 正確:轉(zhuǎn)換為集合或列表
self.set_data = set(self.tuple_data)
self.set_data.update({4, 5})2. 參數(shù)類型錯(cuò)誤
def correct_usage():
"""update() 的正確參數(shù)類型"""
d = {}
# ? 正確:字典
d.update({'a': 1, 'b': 2})
# ? 正確:關(guān)鍵字參數(shù)
d.update(c=3, d=4)
# ? 正確:可迭代對象(鍵值對)
d.update([('e', 5), ('f', 6)])
# ? 正確:另一個(gè)字典對象
other = {'g': 7}
d.update(other)
# ? 錯(cuò)誤:單獨(dú)的值
# d.update('key', 'value') # TypeError
# ? 錯(cuò)誤:單個(gè)列表
# d.update(['a', 'b']) # ValueError: need more than 1 value to unpack3. 修改字典時(shí)的迭代問題
def safe_iteration_update(self):
"""安全地在迭代時(shí)更新字典"""
self.data = {'a': 1, 'b': 2, 'c': 3}
# ? 錯(cuò)誤:運(yùn)行時(shí)修改字典大小
# for key in self.data:
# if self.data[key] < 2:
# self.data.update({key + '_new': self.data[key] * 2})
# ? 正確:先收集要更新的項(xiàng)
to_update = {}
for key, value in self.data.items():
if value < 2:
to_update[key + '_new'] = value * 2
self.data.update(to_update)
# ? 或者:創(chuàng)建新字典
new_items = {k + '_copy': v for k, v in self.data.items()}
self.data.update(new_items)總結(jié)對比表
| 使用場景 | 調(diào)用方式 | 作用 | 返回值 |
|---|---|---|---|
| 字典更新 | dict.update(other) | 合并鍵值對 | None |
| 集合更新 | set.update(iterable) | 添加多個(gè)元素 | None |
| 自定義類 | self.update(**kwargs) | 更新對象狀態(tài) | 自定義 |
| GUI 刷新 | widget.update() | 強(qiáng)制重繪界面 | None |
核心要點(diǎn):
- self.update() 中的 self 代表實(shí)例本身
- 字典 update() 會(huì)覆蓋已有鍵,添加新鍵
- 集合 update() 具有去重特性
- 自定義 update() 應(yīng)做好參數(shù)驗(yàn)證
- GUI 中優(yōu)先使用 update_idletasks() 避免事件遞歸
通過本教程的學(xué)習(xí),您應(yīng)該能夠在各種場景下正確使用 self.update() 方法,并根據(jù)需求自定義更新邏輯。
到此這篇關(guān)于Python self.update() 使用詳細(xì)的文章就介紹到這了,更多相關(guān)Python self.update()內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python爬蟲小技巧之偽造隨機(jī)的User-Agent
這篇文章主要給大家介紹了關(guān)于Python爬蟲小技巧之偽造隨機(jī)的User-Agent的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09
Windows 安裝 Anaconda3+PyCharm的方法步驟
這篇文章主要介紹了Windows 安裝 Anaconda3+PyCharm的方法步驟,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-06-06
python打包為linux可執(zhí)行文件的詳細(xì)圖文教程
這篇文章主要給大家介紹了關(guān)于python打包為linux可執(zhí)行文件的詳細(xì)圖文教程,本文介紹的方法可以輕松地將Python代碼變成獨(dú)立的可執(zhí)行文件,需要的朋友可以參考下2024-02-02
python 求一個(gè)列表中所有元素的乘積實(shí)例
今天小編就為大家分享一篇python 求一個(gè)列表中所有元素的乘積實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-06-06
python爬取企查查企業(yè)信息之selenium自動(dòng)模擬登錄企查查
這篇文章主要介紹了python爬取企查查企業(yè)信息之自動(dòng)模擬登錄企查查以及selenium獲取headers,selenium獲取cookie,需要的朋友可以參考下2021-04-04
python PaddleSpeech實(shí)現(xiàn)嬰兒啼哭識別
這篇文章主要為大家介紹了python PaddleSpeech實(shí)現(xiàn)嬰兒啼哭識別操作詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08

