最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Python解析五大主流文檔從PDF到EPUB的全攻略

 更新時間:2026年01月16日 09:32:12   作者:司南錘  
在日常的數(shù)據(jù)處理、內(nèi)容分析和知識管理工作中,我們經(jīng)常需要從各種格式的文檔中提取信息,今天,我將為大家詳細介紹如何用Python解析五種最常見的文檔格式:PDF、Markdown、TXT、DOC和EPUB,需要的朋友可以參考下

為什么需要文檔解析?

文檔解析是將結(jié)構(gòu)化或半結(jié)構(gòu)化的文檔內(nèi)容轉(zhuǎn)換為機器可讀格式的過程。這對于以下場景至關(guān)重要:

  • 知識管理:構(gòu)建企業(yè)內(nèi)部的知識庫系統(tǒng)
  • 數(shù)據(jù)分析:從報告中提取數(shù)據(jù)進行分析
  • 內(nèi)容遷移:將內(nèi)容從一種格式轉(zhuǎn)換為另一種格式
  • AI訓(xùn)練:為機器學(xué)習(xí)模型準(zhǔn)備訓(xùn)練數(shù)據(jù)

一、PDF解析:最復(fù)雜的挑戰(zhàn)

PDF(Portable Document Format)是最常見但也最復(fù)雜的文檔格式之一。由于它最初設(shè)計用于保持格式一致性而非方便內(nèi)容提取,解析PDF一直是文檔處理中的難題。

1.1 PyMuPDF:速度與功能的平衡

PyMuPDF(在代碼中導(dǎo)入為fitz)是目前功能最全面、速度最快的PDF解析庫之一。

import fitz  # PyMuPDF

# 打開PDF文件
doc = fitz.open('example.pdf')

# 提取所有文本
all_text = ""
for page in doc:
    all_text += page.get_text()

# 提取頁面中的圖像
for page_num in range(len(doc)):
    page = doc.load_page(page_num)
    image_list = page.get_images()
    
    for img_index, img in enumerate(image_list):
        xref = img[0]
        pix = fitz.Pixmap(doc, xref)
        if pix.n - pix.alpha > 3:  # 檢查是否為RGB圖像
            pix = fitz.Pixmap(fitz.csRGB, pix)
        pix.save(f"page_{page_num}_img_{img_index}.png")

# 提取帶格式的文本(保留位置信息)
for page in doc:
    blocks = page.get_text("dict")["blocks"]
    for block in blocks:
        if "lines" in block:  # 文本塊
            for line in block["lines"]:
                for span in line["spans"]:
                    print(f"文本: {span['text']}")
                    print(f"字體: {span['font']}")
                    print(f"大小: {span['size']}")
                    print(f"位置: {span['bbox']}")

doc.close()

PyMuPDF的優(yōu)勢

  • 解析速度極快,處理大型文件時優(yōu)勢明顯
  • 提供精確的文本位置信息
  • 支持圖像、矢量圖形提取
  • 可以進行簡單的PDF編輯操作

1.2 pdfplumber:表格提取專家

如果你的PDF中包含大量表格,pdfplumber可能是更好的選擇。

import pdfplumber

with pdfplumber.open('example.pdf') as pdf:
    # 提取第一頁的文本
    first_page = pdf.pages[0]
    text = first_page.extract_text()
    print(text)
    
    # 提取表格
    tables = first_page.extract_tables()
    for table in tables:
        for row in table:
            print(row)
    
    # 可視化文本位置(調(diào)試用)
    im = first_page.to_image()
    im.debug_tablefinder().show()

pdfplumber的特點

  • 專門優(yōu)化的表格檢測算法
  • 提供詳細的文本位置、字體信息
  • 可視化工具幫助調(diào)試解析問題

1.3 Unstructured:智能解析的未來

Unstructured是一個新興但功能強大的庫,特別擅長將非結(jié)構(gòu)化文檔轉(zhuǎn)換為結(jié)構(gòu)化數(shù)據(jù)。

from unstructured.partition.pdf import partition_pdf

# 解析PDF并自動識別元素類型
elements = partition_pdf(
    filename="example.pdf",
    strategy="auto",  # 自動選擇解析策略
    infer_table_structure=True,  # 推斷表格結(jié)構(gòu)
    include_page_breaks=True  # 包含分頁符
)

# 查看識別出的元素類型
for element in elements:
    print(f"類型: {type(element).__name__}")
    print(f"文本: {str(element)[:100]}...")
    print("-" * 50)
    
    # 不同類型的元素有不同的屬性
    if hasattr(element, 'category'):
        print(f"分類: {element.category}")

Unstructured的核心優(yōu)勢

  • 自動識別文檔結(jié)構(gòu)(標(biāo)題、正文、列表、表格等)
  • 特別適合掃描文檔和復(fù)雜布局
  • 輸出可以直接用于AI應(yīng)用和知識庫

1.4 中文PDF處理注意事項

處理中文PDF時需要特別注意編碼問題:

import fitz

def extract_chinese_pdf(pdf_path):
    doc = fitz.open(pdf_path)
    
    # 方法1:嘗試直接提取
    text = ""
    for page in doc:
        text += page.get_text()
    
    # 如果提取的中文是亂碼,嘗試指定編碼
    if "亂碼" in text or len(text.strip()) < 10:
        print("檢測到可能的編碼問題,嘗試其他方法...")
        
        # 方法2:使用OCR(需要安裝額外的依賴)
        # 這里展示思路,實際需要安裝pytesseract和Pillow
        # import pytesseract
        # from PIL import Image
        # 
        # for page_num in range(len(doc)):
        #     pix = doc[page_num].get_pixmap()
        #     img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
        #     text += pytesseract.image_to_string(img, lang='chi_sim')
    
    return text

二、Markdown解析:輕量級標(biāo)記語言

Markdown是一種輕量級標(biāo)記語言,解析相對簡單但應(yīng)用廣泛。

2.1 markdown:經(jīng)典之選

import markdown

# 基本使用:將Markdown轉(zhuǎn)換為HTML
md_text = """
# 標(biāo)題一

這是一個段落,包含**加粗**和*斜體*文本。

- 列表項1
- 列表項2

[這是一個鏈接](https://example.com)
"""

html_output = markdown.markdown(md_text)
print(html_output)

# 使用擴展功能
html_with_extensions = markdown.markdown(
    md_text,
    extensions=[
        'toc',           # 目錄生成
        'tables',        # 表格支持
        'fenced_code',   # 代碼塊
        'footnotes'      # 腳注
    ]
)

# 解析為AST(抽象語法樹)
from markdown.extensions import Extension
from markdown.treeprocessors import Treeprocessor

class LinkCollector(Treeprocessor):
    def run(self, root):
        links = []
        for element in root.iter():
            if element.tag == 'a':
                links.append(element.get('href'))
        return links

class MyExtension(Extension):
    def extendMarkdown(self, md):
        md.treeprocessors.register(LinkCollector(md), 'linkcollector', 15)

md = markdown.Markdown(extensions=[MyExtension()])
result = md.convert(md_text)
print(f"找到的鏈接: {md.treeprocessors['linkcollector'].run(md.parser.root)}")

2.2 markdown-it-py:現(xiàn)代解析器

from markdown_it import MarkdownIt
from markdown_it.tree import SyntaxTreeNode

# 創(chuàng)建解析器實例
md = MarkdownIt()

# 解析Markdown
tokens = md.parse(md_text)

# 遍歷語法標(biāo)記
for token in tokens:
    if token.type == 'heading_open' and token.tag == 'h1':
        print("找到一個一級標(biāo)題")
    elif token.type == 'inline':
        print(f"文本內(nèi)容: {token.content}")

# 轉(zhuǎn)換為語法樹
tree = SyntaxTreeNode(tokens)
for node in tree.walk():
    if node.type == 'heading' and node.tag == 'h1':
        print(f"標(biāo)題: {node.children[0].content}")

選擇建議

  • 對于大多數(shù)項目,經(jīng)典的markdown庫足夠使用
  • 如果需要嚴(yán)格的CommonMark兼容性或更高性能,選擇markdown-it-py
  • 需要操作語法樹時,兩者都提供相應(yīng)功能

三、TXT文件:最簡單的格式

純文本文件是最容易處理的格式,但也有一些注意事項。

# 基礎(chǔ)讀取
def read_txt_basic(filepath):
    with open(filepath, 'r', encoding='utf-8') as f:
        content = f.read()
    return content

# 處理大文件(逐行讀?。?
def process_large_txt(filepath):
    with open(filepath, 'r', encoding='utf-8') as f:
        for line_number, line in enumerate(f, 1):
            # 處理每一行
            processed_line = line.strip()
            if processed_line:  # 跳過空行
                print(f"行 {line_number}: {processed_line[:50]}...")

# 自動檢測編碼
import chardet

def read_txt_with_encoding_detection(filepath):
    with open(filepath, 'rb') as f:
        raw_data = f.read()
        result = chardet.detect(raw_data)
        encoding = result['encoding']
        confidence = result['confidence']
        
        print(f"檢測到編碼: {encoding} (置信度: {confidence})")
        
        try:
            return raw_data.decode(encoding)
        except UnicodeDecodeError:
            # 如果檢測失敗,嘗試常見編碼
            for enc in ['utf-8', 'gbk', 'gb2312', 'latin-1']:
                try:
                    return raw_data.decode(enc)
                except UnicodeDecodeError:
                    continue
            raise

# 使用Pandas處理結(jié)構(gòu)化文本數(shù)據(jù)
import pandas as pd

def process_tabular_txt(filepath):
    # 讀取CSV/TSV文件
    try:
        # 嘗試用逗號分隔
        df = pd.read_csv(filepath, encoding='utf-8')
    except:
        try:
            # 嘗試用制表符分隔
            df = pd.read_csv(filepath, sep='\t', encoding='utf-8')
        except:
            # 嘗試自動檢測分隔符
            with open(filepath, 'r') as f:
                first_line = f.readline()
            
            if ',' in first_line:
                df = pd.read_csv(filepath, sep=',', encoding='utf-8')
            elif '\t' in first_line:
                df = pd.read_csv(filepath, sep='\t', encoding='utf-8')
            else:
                df = pd.read_csv(filepath, delim_whitespace=True, encoding='utf-8')
    
    # 數(shù)據(jù)分析示例
    print(f"數(shù)據(jù)形狀: {df.shape}")
    print(f"列名: {df.columns.tolist()}")
    print(f"前5行:\n{df.head()}")
    
    return df

四、DOC/DOCX文件:微軟Word文檔

對于現(xiàn)代的.docx文件,python-docx是事實上的標(biāo)準(zhǔn)庫。

from docx import Document
from docx.document import Document as DocDocument

def read_docx(filepath):
    # 打開文檔
    doc = Document(filepath)
    
    # 提取所有段落
    full_text = []
    for paragraph in doc.paragraphs:
        if paragraph.text.strip():  # 跳過空段落
            full_text.append(paragraph.text)
            print(f"段落: {paragraph.text[:50]}...")
    
    # 提取表格數(shù)據(jù)
    tables_data = []
    for table in doc.tables:
        table_data = []
        for row in table.rows:
            row_data = [cell.text for cell in row.cells]
            table_data.append(row_data)
        tables_data.append(table_data)
        print(f"表格找到,有{len(table.rows)}行{len(table.columns)}列")
    
    # 提取樣式信息
    styled_elements = []
    for paragraph in doc.paragraphs:
        style_info = {
            'text': paragraph.text,
            'style': paragraph.style.name,
            'runs': []
        }
        
        # 獲取運行級別的格式
        for run in paragraph.runs:
            run_info = {
                'text': run.text,
                'bold': run.bold,
                'italic': run.italic,
                'underline': run.underline,
                'font_name': run.font.name,
                'font_size': run.font.size
            }
            style_info['runs'].append(run_info)
        
        if style_info['runs']:
            styled_elements.append(style_info)
    
    # 處理列表
    lists = []
    for paragraph in doc.paragraphs:
        if paragraph.style.name.startswith('List'):
            lists.append({
                'text': paragraph.text,
                'style': paragraph.style.name,
                'level': get_list_level(paragraph.style.name)
            })
    
    return {
        'full_text': '\n'.join(full_text),
        'tables': tables_data,
        'styled_elements': styled_elements,
        'lists': lists
    }

def get_list_level(style_name):
    """獲取列表縮進級別"""
    if '1' in style_name:
        return 1
    elif '2' in style_name:
        return 2
    elif '3' in style_name:
        return 3
    else:
        return 0

# 處理舊版.doc文件(需要額外的庫)
def read_doc_file(filepath):
    # 注意:python-docx只能處理.docx文件
    # 處理.doc文件需要安裝antiword或使用其他方法
    
    # 方法1:使用LibreOffice轉(zhuǎn)換(需要系統(tǒng)安裝LibreOffice)
    # import subprocess
    # subprocess.run(['libreoffice', '--headless', '--convert-to', 'docx', filepath])
    
    # 方法2:使用pywin32(僅Windows)
    # import win32com.client
    # word = win32com.client.Dispatch("Word.Application")
    # doc = word.Documents.Open(filepath)
    # text = doc.Content.Text
    # doc.Close()
    # word.Quit()
    
    print("處理.doc文件需要額外的工具")
    return None

五、EPUB文件:電子書格式

EPUB是一種基于HTML的電子書格式,可以使用EbookLib進行解析。

from ebooklib import epub
import html2text

def read_epub(filepath):
    # 打開EPUB文件
    book = epub.read_epub(filepath)
    
    # 獲取書籍元數(shù)據(jù)
    metadata = {
        'title': book.get_metadata('DC', 'title'),
        'creator': book.get_metadata('DC', 'creator'),
        'publisher': book.get_metadata('DC', 'publisher'),
        'date': book.get_metadata('DC', 'date'),
        'language': book.get_metadata('DC', 'language'),
        'identifier': book.get_metadata('DC', 'identifier')
    }
    
    print(f"書名: {metadata['title']}")
    print(f"作者: {metadata['creator']}")
    
    # 提取所有文本內(nèi)容
    h = html2text.HTML2Text()
    h.ignore_links = False
    h.ignore_images = False
    
    full_text = []
    toc_items = []
    
    # 處理目錄
    for item in book.toc:
        if isinstance(item, tuple):
            # 處理嵌套目錄項
            section, subsections = item
            toc_items.append({
                'title': section.title,
                'href': section.href
            })
        else:
            toc_items.append({
                'title': item.title,
                'href': item.href
            })
    
    # 按章節(jié)讀取內(nèi)容
    for item in book.get_items():
        if item.get_type() == ebooklib.ITEM_DOCUMENT:
            # 獲取章節(jié)內(nèi)容(HTML格式)
            content = item.get_content().decode('utf-8')
            
            # 轉(zhuǎn)換為純文本
            text_content = h.handle(content)
            
            # 清理文本
            cleaned_text = clean_epub_text(text_content)
            
            if cleaned_text.strip():
                full_text.append({
                    'title': item.get_name(),
                    'content': cleaned_text,
                    'raw_html': content[:500] + '...'  # 保存部分HTML供參考
                })
    
    # 按目錄順序組織內(nèi)容
    organized_content = organize_by_toc(full_text, toc_items)
    
    return {
        'metadata': metadata,
        'toc': toc_items,
        'content': organized_content,
        'full_text': '\n\n'.join([item['content'] for item in full_text])
    }

def clean_epub_text(text):
    """清理EPUB文本中的多余空白和標(biāo)記"""
    lines = text.split('\n')
    cleaned_lines = []
    
    for line in lines:
        line = line.strip()
        if line and not line.startswith('#' * 4):  # 跳過HTML2Text的標(biāo)題標(biāo)記
            cleaned_lines.append(line)
    
    return '\n'.join(cleaned_lines)

def organize_by_toc(content_items, toc):
    """根據(jù)目錄組織內(nèi)容"""
    organized = []
    
    for toc_item in toc:
        # 查找對應(yīng)章節(jié)
        for content_item in content_items:
            if toc_item['href'] in content_item['title']:
                organized.append({
                    'toc_title': toc_item['title'],
                    'content_title': content_item['title'],
                    'content': content_item['content']
                })
                break
    
    return organized

六、實戰(zhàn):構(gòu)建統(tǒng)一文檔解析器

在實際項目中,我們經(jīng)常需要處理多種格式的文檔。下面是一個統(tǒng)一的文檔解析器示例:

class UniversalDocumentParser:
    def __init__(self):
        self.supported_formats = {
            '.pdf': self._parse_pdf,
            '.md': self._parse_markdown,
            '.txt': self._parse_text,
            '.docx': self._parse_docx,
            '.epub': self._parse_epub
        }
    
    def parse(self, filepath):
        import os
        
        # 獲取文件擴展名
        _, ext = os.path.splitext(filepath)
        ext = ext.lower()
        
        # 檢查是否支持該格式
        if ext not in self.supported_formats:
            raise ValueError(f"不支持的文件格式: {ext}")
        
        # 調(diào)用對應(yīng)的解析函數(shù)
        return self.supported_formats[ext](filepath)
    
    def _parse_pdf(self, filepath):
        """解析PDF文件"""
        # 根據(jù)需求選擇合適的PDF解析器
        try:
            # 首先嘗試使用PyMuPDF(速度快)
            import fitz
            doc = fitz.open(filepath)
            text = ""
            for page in doc:
                text += page.get_text() + "\n"
            doc.close()
            return {'format': 'pdf', 'content': text, 'parser': 'PyMuPDF'}
        except ImportError:
            # 回退到其他解析器
            try:
                import pdfplumber
                with pdfplumber.open(filepath) as pdf:
                    text = ""
                    for page in pdf.pages:
                        text += page.extract_text() + "\n"
                return {'format': 'pdf', 'content': text, 'parser': 'pdfplumber'}
            except ImportError:
                raise ImportError("請安裝PyMuPDF或pdfplumber以解析PDF文件")
    
    def _parse_markdown(self, filepath):
        """解析Markdown文件"""
        import markdown
        with open(filepath, 'r', encoding='utf-8') as f:
            content = f.read()
        
        # 轉(zhuǎn)換為HTML
        html = markdown.markdown(content)
        
        return {
            'format': 'markdown',
            'raw_content': content,
            'html_content': html
        }
    
    def _parse_text(self, filepath):
        """解析純文本文件"""
        # 自動檢測編碼
        import chardet
        
        with open(filepath, 'rb') as f:
            raw_data = f.read()
            result = chardet.detect(raw_data)
            encoding = result['encoding']
        
        with open(filepath, 'r', encoding=encoding) as f:
            content = f.read()
        
        return {
            'format': 'text',
            'encoding': encoding,
            'content': content
        }
    
    def _parse_docx(self, filepath):
        """解析DOCX文件"""
        from docx import Document
        
        doc = Document(filepath)
        paragraphs = [p.text for p in doc.paragraphs if p.text.strip()]
        
        # 提取表格
        tables = []
        for table in doc.tables:
            table_data = []
            for row in table.rows:
                table_data.append([cell.text for cell in row.cells])
            tables.append(table_data)
        
        return {
            'format': 'docx',
            'paragraphs': paragraphs,
            'tables': tables,
            'full_text': '\n'.join(paragraphs)
        }
    
    def _parse_epub(self, filepath):
        """解析EPUB文件"""
        import ebooklib
        from ebooklib import epub
        import html2text
        
        book = epub.read_epub(filepath)
        h = html2text.HTML2Text()
        h.ignore_links = True
        
        # 提取所有文本內(nèi)容
        text_parts = []
        for item in book.get_items():
            if item.get_type() == ebooklib.ITEM_DOCUMENT:
                content = item.get_content().decode('utf-8')
                text = h.handle(content)
                if text.strip():
                    text_parts.append(text)
        
        full_text = '\n\n'.join(text_parts)
        
        # 提取元數(shù)據(jù)
        metadata = {}
        for key in ['title', 'creator', 'publisher', 'date']:
            meta = book.get_metadata('DC', key)
            if meta:
                metadata[key] = meta[0][0]
        
        return {
            'format': 'epub',
            'metadata': metadata,
            'content': full_text
        }

# 使用示例
parser = UniversalDocumentParser()

# 解析各種格式的文件
formats_to_test = ['document.pdf', 'notes.md', 'data.txt', 'report.docx', 'book.epub']

for file in formats_to_test:
    try:
        result = parser.parse(file)
        print(f"成功解析 {file}: {result['format']} 格式")
        print(f"內(nèi)容預(yù)覽: {result.get('content', result.get('full_text', ''))[:100]}...")
        print("-" * 50)
    except FileNotFoundError:
        print(f"文件不存在: {file}")
    except Exception as e:
        print(f"解析 {file} 時出錯: {e}")

七、性能優(yōu)化與最佳實踐

7.1 大文件處理策略

class EfficientDocumentProcessor:
    def __init__(self, chunk_size=1000):
        self.chunk_size = chunk_size  # 每次處理的塊大小
    
    def process_large_pdf(self, filepath, callback=None):
        """流式處理大型PDF文件"""
        import fitz
        
        doc = fitz.open(filepath)
        total_pages = len(doc)
        
        for page_num in range(total_pages):
            page = doc.load_page(page_num)
            text = page.get_text()
            
            # 分塊處理文本
            chunks = self._split_into_chunks(text)
            
            for chunk in chunks:
                if callback:
                    callback(chunk, page_num + 1)
                else:
                    yield chunk, page_num + 1
        
        doc.close()
    
    def _split_into_chunks(self, text, chunk_size=None):
        """將文本分割為指定大小的塊"""
        if chunk_size is None:
            chunk_size = self.chunk_size
        
        chunks = []
        words = text.split()
        
        current_chunk = []
        current_size = 0
        
        for word in words:
            word_size = len(word) + 1  # 加1是空格
            
            if current_size + word_size > chunk_size and current_chunk:
                chunks.append(' '.join(current_chunk))
                current_chunk = [word]
                current_size = word_size
            else:
                current_chunk.append(word)
                current_size += word_size
        
        if current_chunk:
            chunks.append(' '.join(current_chunk))
        
        return chunks

7.2 錯誤處理與日志記錄

import logging
from functools import wraps

# 配置日志
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)

def document_parser_error_handler(func):
    """文檔解析器的錯誤處理裝飾器"""
    @wraps(func)
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except FileNotFoundError as e:
            logger.error(f"文件未找到: {e.filename}")
            raise
        except PermissionError as e:
            logger.error(f"權(quán)限不足: {e.filename}")
            raise
        except UnicodeDecodeError as e:
            logger.error(f"編碼錯誤: {e.reason}")
            # 嘗試其他編碼
            return handle_encoding_error(*args, **kwargs)
        except Exception as e:
            logger.exception(f"解析文檔時發(fā)生未知錯誤: {e}")
            raise
    return wrapper

@document_parser_error_handler
def safe_document_parse(filepath, parser_func):
    """安全的文檔解析函數(shù)"""
    return parser_func(filepath)

八、總結(jié)與選擇建議

通過本文的介紹,你應(yīng)該對Python解析各種文檔格式有了全面的了解。以下是針對不同場景的選擇建議:

PDF解析

  • PyMuPDF:通用場景首選,速度快,功能全面
  • pdfplumber:表格提取需求多的場景
  • Unstructured:需要智能結(jié)構(gòu)化的AI應(yīng)用場景

Markdown解析

  • markdown:大多數(shù)項目的選擇
  • markdown-it-py:需要嚴(yán)格標(biāo)準(zhǔn)兼容或更高性能的場景

TXT文件

  • Python內(nèi)置函數(shù):簡單文本讀取
  • Pandas:結(jié)構(gòu)化文本數(shù)據(jù)分析

DOC/DOCX文件

  • python-docx:唯一選擇,功能完善

EPUB文件

  • EbookLib:專業(yè)處理EPUB格式

以上就是使用Python解析五大主流文檔從PDF到EPUB的全攻略的詳細內(nèi)容,更多關(guān)于Python解析主流文檔的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • PyTorch中常見損失函數(shù)的使用詳解

    PyTorch中常見損失函數(shù)的使用詳解

    損失函數(shù),又叫目標(biāo)函數(shù),是指計算機標(biāo)簽值和預(yù)測值直接差異的函數(shù),本文為大家整理了PyTorch中常見損失函數(shù)的簡單解釋和使用,希望對大家有所幫助
    2023-06-06
  • Django應(yīng)用程序中如何發(fā)送電子郵件詳解

    Django應(yīng)用程序中如何發(fā)送電子郵件詳解

    我們常常會用到一些發(fā)送郵件的功能,比如有人提交了應(yīng)聘的表單,可以向HR的郵箱發(fā)郵件,這樣,HR不看網(wǎng)站就可以知道有人在網(wǎng)站上提交了應(yīng)聘信息。下面這篇文章就介紹了在Django應(yīng)用程序中如何發(fā)送電子郵件的相關(guān)資料,需要的朋友可以參考借鑒。
    2017-02-02
  • 教你如何在Pygame 中移動你的游戲角色

    教你如何在Pygame 中移動你的游戲角色

    Pygame是一組跨平臺的 Python 模塊,專為編寫視頻游戲而設(shè)計,您可以使用 pygame 創(chuàng)建不同類型的游戲,包括街機游戲、平臺游戲等等,今天通過本文給大家介紹Pygame移動游戲角色的實現(xiàn)過程,一起看看吧
    2021-09-09
  • 淺談Python之Django(三)

    淺談Python之Django(三)

    這篇文章主要介紹了Python3中的Django,小編覺得這篇文章寫的還不錯,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧,希望能夠給你帶來幫助
    2021-10-10
  • Python json模塊使用實例

    Python json模塊使用實例

    這篇文章主要介紹了Python json模塊使用實例,本文給出多個使用代碼實例,需要的朋友可以參考下
    2015-04-04
  • 詳解如何使用python創(chuàng)建和結(jié)束線程

    詳解如何使用python創(chuàng)建和結(jié)束線程

    線程的創(chuàng)建和結(jié)束是多線程編程中的核心概念之一,在本文中,我們將學(xué)習(xí)如何使用 Python 創(chuàng)建線程,并探討如何優(yōu)雅地結(jié)束線程,需要的朋友可以參考下
    2024-04-04
  • Python變量、數(shù)據(jù)類型、數(shù)據(jù)類型轉(zhuǎn)換相關(guān)函數(shù)用法實例詳解

    Python變量、數(shù)據(jù)類型、數(shù)據(jù)類型轉(zhuǎn)換相關(guān)函數(shù)用法實例詳解

    這篇文章主要介紹了Python變量、數(shù)據(jù)類型、數(shù)據(jù)類型轉(zhuǎn)換相關(guān)函數(shù)用法,結(jié)合實例形式詳細分析了Python變量類型、基本用法、變量類型轉(zhuǎn)換相關(guān)函數(shù)與使用技巧,需要的朋友可以參考下
    2020-01-01
  • Python字符串格式化format()方法運用實例

    Python字符串格式化format()方法運用實例

    這篇文章主要給大家介紹了關(guān)于Python字符串格式化format()方法運用實例的相關(guān)資料,字符串格式化是Python編程中十分常用的部分,它可以幫助我們將更具可讀性的數(shù)據(jù)輸出到控制臺或?qū)懭胛募?需要的朋友可以參考下
    2023-08-08
  • Django中多對多關(guān)系三種定義方式

    Django中多對多關(guān)系三種定義方式

    Django 中的多對多關(guān)系可以通過三種方式定義,它們在使用便捷性和可擴展性上各有差異,下面就來介紹一下如何實現(xiàn),感興趣的可以了解一下
    2025-06-06
  • 如何將寫好的.py/.java程序變成.exe文件詳解

    如何將寫好的.py/.java程序變成.exe文件詳解

    有時候我們需要將自己寫的代碼打包成exe文件,給別人使用需要怎么辦呢,下面這篇文章主要給大家介紹了關(guān)于如何將寫好的.py/.java程序變成.exe文件的相關(guān)資料,需要的朋友可以參考下
    2023-01-01

最新評論

虹口区| 大连市| 体育| 保康县| 西贡区| 西吉县| 印江| 榆中县| 深州市| 洪湖市| 丰顺县| 云梦县| 平利县| 丹棱县| 罗江县| 五峰| 襄汾县| 正镶白旗| 双牌县| 成安县| 常宁市| 唐山市| 阳泉市| 南汇区| 会宁县| 阜平县| 壤塘县| 淄博市| 若尔盖县| 丰宁| 富蕴县| 定远县| 东海县| 铜梁县| 互助| 东乌珠穆沁旗| 诸城市| 历史| 织金县| 日土县| 宝兴县|