Nanxu Programming Guides

website·Indexed 30 days ago

https://www.nanxu.online/docs/

A collection of technical tutorials and case studies covering Python and Java development. Python content includes foundation guides, object-oriented programming, data analysis with Pandas and Matplotlib, web development with FastAPI and Streamlit, and AI application integration using DeepSeek and OpenAI APIs. Java content focuses on Spring Boot, Spring Security with JWT and Redis, and Druid connection pooling.

Tokens
73.8K
Snippets
332
Records
405
Agent score
49%

What's inside Nanxu

  1. Overview of Python Data Containers

    Python provides five primary data containers to store multiple elements of any type. Their characteristics are summarized as follows:

    ContainerSymbolOrderedDuplicates AllowedMutable
    String (str)' ' / " "YesYesNo
    List (list)[]YesYesYes
    Tuple (tuple)()YesYesNo
    Set (set){}NoNoYes
    Dictionary (dict){key: value}NoKeys must be uniqueYes
  2. Overview of Python Magic Methods

    Magic methods (also known as dunder methods) are built-in special methods in Python that are automatically triggered by the interpreter when specific conditions are met, rather than being called manually by the developer. They are characterized by starting and ending with double underscores (__).
  3. Overview of Data Analysis concepts in Python

    Data analysis is the process of extracting valuable information and patterns from large sets of unstructured data to support decision-making and solve business problems (e.g., user behavior insights, sales trend forecasting, or educational quality assessment). The core workflow typically involves three primary stages: data cleaning, statistical analysis, and data visualization.
  4. Core principle for implementing Python decorators

    The fundamental rule for creating a decorator is that the internal wrapper function's signature (parameters and return behavior) must match the signature of the original function being decorated. If the original function takes arguments or returns a value, the internal function must also handle those arguments and return that value to maintain consistency.
  5. Understand Python Iterators

    An Iterator in Python is an object that allows sequential access to elements in a data collection without exposing the underlying implementation. To be an iterator, an object must implement the iterator protocol, which consists of two methods: __iter__() and __next__(). Iterators are typically lazy-evaluated, meaning they generate data on demand, which optimizes memory usage.
  6. RESTful API Design Principles

    Follow REST (Representational State Transfer) architecture for better maintainability and semantic clarity. Key conventions include:

    • Resource-based URLs: Use nouns instead of verbs (e.g., /users/1 instead of /user/getById).
    • HTTP Verbs: Use GET (Retrieve), POST (Create), PUT (Update), and DELETE (Remove).
    • Pluralization: Use plural nouns for resource collections (e.g., /books).
    • Idempotency: GET, PUT, and DELETE should be idempotent (multiple identical requests have the same effect as one).
  7. Understand Python OOP Core Concepts

    Python supports the three primary pillars of Object-Oriented Programming (OOP):

    • Encapsulation: Hiding the internal complexity of an object and providing a public interface (e.g., calling list.reverse() without needing to know the underlying algorithm).
    • Inheritance: Allowing a child class to derive attributes and methods from a parent class to promote code reuse.
    • Polymorphism: The ability of different objects to respond to the same method call in different ways, or a single entity exhibiting different forms depending on the context.
  8. Understand the basics of Prompt Engineering

    A prompt is a command (sentence, question, or paragraph) sent to an AI Large Language Model (LLM) to generate a specific response. Prompt Engineering is the iterative process of skillfully crafting these prompts to ensure the AI's output aligns as closely as possible with the user's expectations.
  9. Scrape and save movie details to CSV using Python

    This implementation demonstrates how to extract detailed movie information (name, year, release date, genre, duration, rating, language, director, author, cast, slogan, and introduction) from TMDb and save the results into a CSV file using csv.DictWriter.
    import csv
    import requests
    from lxml import html
    
    BASE_URL = "https://www.themoviedb.org"
    
    def get_movie_info(movie_info_url):
        dict_data = {}
        movie_response = requests.get(movie_info_url)
        movie_doc = html.fromstring(movie_response.text)
    
        # Example of extracting data with fallback to empty string
        movie_name = movie_doc.xpath("//*[@id='original_header']/div[2]/section/div[1]/h2/a/text()")
        dict_data["电影名"] = movie_name[0] if movie_name else ""
        
        movie_release_date = movie_doc.xpath("//*[@id='original_header']/div[2]/section/div[1]/div/span[@class='release']/text()")
        dict_data["上映时间"] = movie_release_date[0].strip() if movie_release_date else ""
        
        # Handle lists (e.g., genres)
        movie_type_list = movie_doc.xpath("//*[@id='original_header']/div[2]/section/div[1]/div/span[@class='genres']/a/text()")
        dict_data["类型"] = "和".join(movie_type_list) if movie_type_list else ""
        
        return dict_data
    
    def save_all_movies(all_movies):
        with open("csv_data/movie_list.csv", "w", encoding="utf-8", newline="") as f:
            writer = csv.DictWriter(f, ["电影名", "年份", "上映时间", "类型", "时长", "评分", "语言", "导演", "作者", "主演", "Slogan", "简介"])
            writer.writeheader()
            writer.writerows(all_movies)
  10. Understand the difference between Shallow Copy and Deep Copy in Python

    In Python, copying is primarily relevant for mutable types (e.g., lists, dictionaries, sets).

    • Shallow Copy: Creates a new object but fills it with references to the original child objects. It only copies the first level.
    • Deep Copy: Recursively copies every object found in the original, creating entirely new copies of all nested mutable objects. It copies all levels.
    • Immutable Types: For types like strings, tuples, integers, and floats, both shallow and deep copying behave like simple assignment because the objects cannot be changed after creation.
  11. Understand the three essential elements of network programming

    Network programming enables data interaction between programs running on different computers. To establish communication, three elements are required:

    1. IP Address: A unique identifier for a device on the network.
    2. Port Number: A unique identifier for a specific program on a device.
    3. Protocol: A set of transmission rules that both parties must follow to ensure secure and correct data parsing.
  12. Understand Polymorphism in Python

    Polymorphism allows a single function or interface to handle different data types (objects) and produce different results based on the object's specific implementation. In a strict OOP sense, this typically requires:

    1. Inheritance: A subclass inheriting from a parent class.
    2. Method Overriding: The subclass providing a specific implementation of a method defined in the parent class.
    3. Parent Reference: A parent class variable holding a subclass instance.

    Because Python is a dynamically typed (weakly typed) language, it supports 'duck typing,' meaning polymorphism can be achieved even if classes do not share a common parent, as long as they implement the required methods.