欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pygame外星人入侵小游戲超詳細(xì)開發(fā)流程

 更新時間:2022年03月17日 14:19:18   作者:hacker707  
這篇文章主要介紹了利用Python編寫的外星人入侵游戲的示例代碼,文中的代碼講解詳細(xì),對我們學(xué)習(xí)Python有一定的幫助,感興趣的可以學(xué)習(xí)一下

游戲開始前的注意事項

1:游戲《外星人入侵》將包含很多文件,請在你的D盤中新建一個空文件夾,并將其命名為alien_invasion.請務(wù)必將所有文件存儲在這個文件夾中,這樣游戲才能正常運行。

2:在開始編碼前請安裝pygame庫(在pycharm終端pip install pygame即可) 如果在安裝時遇到以下情況,請更新pip版本(將以下內(nèi)容復(fù)制粘貼到下面回車即可)

《外星人入侵》游戲簡介

在游戲《外星人入侵》中,玩家控制著一艘最初出現(xiàn)在屏幕底部中央的飛船。玩家可以使用方向鍵左右移動飛船,還可以使用空格鍵進行射擊。游戲開始時,一群外星人出現(xiàn)在天空中,他們在屏幕中向下移動。玩家的任務(wù)就是射殺這些外星人。玩家將所有的外星人全部射殺,將會出現(xiàn)一群新的外星人群。他們的移動速度更快。只要有外星人撞到玩家的飛船或者屏幕底部,玩家就損失一艘飛船,。玩家損失三艘飛船后游戲結(jié)束。

開始游戲項目實戰(zhàn)開發(fā)

在D盤的alien_invasion文件夾中新建一個images文件夾,將外星人的圖像命名為alien,將飛船圖像命名為ship

alien.bmp

ship.bmp

alien_invasion.py

創(chuàng)建pygame窗口

只需運行文件alien_invasion.py即可開始游戲,其他文件內(nèi)容會被間接或直接導(dǎo)入到該文件

import sys
import pygame
from pygame.sprite import Group
from settings import Settings
from game_stats import GameSrats
from scoreboard import Scoreboard
from button import Button
from ship import Ship
from alien import Alien
import game_functions as gf


def run_game():
    # 初始化pygame,設(shè)置和屏幕對象
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("外星人入侵")

    # 創(chuàng)建play按鈕
    play_button = Button(ai_settings, screen, "play")

    # 創(chuàng)建存儲游戲統(tǒng)計信息的實例,并創(chuàng)建得分牌
    stats = GameSrats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    # 創(chuàng)建一艘飛船,一個子彈編組和一個外星人編組
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()

    # 創(chuàng)建外星人群
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # 開始游戲主循環(huán)
    while True:
        gf.cheak_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets)

        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button)


run_game()

alien.py

管理外星人類

import pygame
from pygame.sprite import Sprite


class Alien(Sprite):
    """表示單個外星人的類"""

    def __init__(self, ai_settings, screen):
        """初始化外星人并設(shè)置其初始位置"""
        super().__init__()
        self.screen = screen
        self.ai_settings = ai_settings

        # 加載外星人圖像,并設(shè)置其rect屬性
        self.image = pygame.image.load('images/alien.bmp')
        self.rect = self.image.get_rect()

        # 每個外星人最初在屏幕左上角附近
        self.rect.x = self.rect.width
        self.rect.y = self.rect.height

        # 存儲外星人的準(zhǔn)確位置
        self.x = float(self.rect.x)

    def blitme(self):
        """在指定位置繪制外星人"""
        self.screen.blit(self.image, self.rect)

    def cheak_edgs(self):
        """如果外星人位于屏幕邊緣,就返回True"""
        screen_rect = self.screen.get_rect()
        if self.rect.right >= screen_rect.right:
            return True
        elif self.rect.left <= 0:
            return True

    def update(self):
        """向左或向右移動外星人人"""
        self.x += (self.ai_settings.alien_speed_factor * self.ai_settings.fleet_direction)
        self.rect.x = self.x

bullet.py

創(chuàng)建子彈類,將子彈存儲到編組Group中

import pygame
from pygame.sprite import Sprite


class Bullet(Sprite):
    """一個對飛船發(fā)射的子彈進行管理的類"""

    def __init__(self, ai_settings, screen, ship):
        """在飛船所處位置創(chuàng)建一個子彈對象"""
        super().__init__()
        self.screen = screen

        # 在(0,0)處創(chuàng)建一個表示子彈的矩形,再設(shè)置正確的位置
        self.rect = pygame.Rect(0, 0, ai_settings.bullet_width, ai_settings.bullet_height)
        self.rect.centerx = ship.rect.centerx
        self.rect.top = ship.rect.top

        # 存儲用小數(shù)表示的子彈位置
        self.y = float(self.rect.y)

        self.color = ai_settings.bullet_color
        self.speed_factor = ai_settings.bullet_speed_factor

    def update(self):
        """向上發(fā)射子彈"""
        # 更新表示子彈的小數(shù)值
        self.y -= self.speed_factor
        # 更新表示子彈的rect的位置
        self.rect.y = self.y

    def draw_bullet(self):
        """在屏幕上繪制子彈"""
        pygame.draw.rect(self.screen, self.color, self.rect)

button.py

按鍵類,實例化按鍵,添加play按鈕

import pygame.font


class Button():

    def __init__(self, ai_settings, screen, msg):
        """初始化按鈕的屬性"""
        self.screen = screen
        self.screen_rect = screen.get_rect()

        # 設(shè)置按鈕的尺寸和其他屬性
        self.width, self.hieght = 200, 50
        self.button_color = (0, 255, 0)
        self.text_color = (255, 255, 255)
        self.font = pygame.font.SysFont(None, 48)

        # 創(chuàng)建按鈕的rect對象,并將其居中
        self.rect = pygame.Rect(0, 0, self.width, self.hieght)
        self.rect.center = self.screen_rect.center

        # 按鈕的標(biāo)志只需創(chuàng)建一次
        self.prep_msg(msg)

    def prep_msg(self, msg):
        """將msg渲染為圖像,并將其在按鈕中居中"""
        self.msg_image = self.font.render(msg, True, self.text_color, self.button_color)
        self.msg_image_rect = self.msg_image.get_rect()
        self.msg_image_rect.center = self.rect.center

    def draw_button(self):
        """繪制一個用顏色填充的按鈕,再繪制文本"""
        self.screen.fill(self.button_color, self.rect)
        self.screen.blit(self.msg_image, self.msg_image_rect)

game_functions.py

文件game_functions.py包含一系列函數(shù),需要響應(yīng)按鍵和鼠標(biāo)事件,游戲大部分工作都是由它們完成的。

import sys
from time import sleep
import pygame
from bullet import Bullet
from alien import Alien


def cheak_keydowen_events(event, ai_settings, screen, ship, bullets):
    """響應(yīng)按鍵"""
    if event.key == pygame.K_RIGHT:
        ship.moving_right = True
    elif event.key == pygame.K_LEFT:
        ship.moving_left = True
    elif event.key == pygame.K_SPACE:
        fire_bullet(ai_settings, screen, ship, bullets)
    elif event.key == pygame.K_q:
        sys.exit()


def fire_bullet(ai_settings, screen, ship, bullets):
    """如果還沒到達限制,就發(fā)射一顆子彈"""
    # 創(chuàng)建一顆子彈,并將其加入到編組bullets中
    if len(bullets) < ai_settings.bullets_allowed:
        news_bullet = Bullet(ai_settings, screen, ship)
        bullets.add(news_bullet)


def cheak_keyup_events(event, ship):
    """響應(yīng)松開"""
    if event.key == pygame.K_RIGHT:
        ship.moving_right = False
    elif event.key == pygame.K_LEFT:
        ship.moving_left = False


def cheak_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets):
    """響應(yīng)按鍵和鼠標(biāo)事件"""
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            cheak_keydowen_events(event, ai_settings, screen, ship, bullets)
        elif event.type == pygame.KEYUP:
            cheak_keyup_events(event, ship)
        elif event.type == pygame.MOUSEBUTTONDOWN:
            mouse_x, mouse_y = pygame.mouse.get_pos()
            cheak_play_button(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets, mouse_x, mouse_y)


def cheak_play_button(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets, mouse_x, mouse_y):
    """在玩家單擊play按鈕時開始新游戲"""
    bullets_clicked = play_button.rect.collidepoint(mouse_x, mouse_y)
    if bullets_clicked and not stats.game_active:
        # 重置游戲設(shè)置
        ai_settings.initialize_dynamic_settings()
        # 隱藏光標(biāo)
        pygame.mouse.set_visible(False)
        # 重置游戲統(tǒng)計信息
        stats.reset_stats()
        stats.game_active = True

        # 重置記分牌對象
        sb.prep_score()
        sb.prep_high_score()
        sb.prep_level()
        sb.prep_ships()

        # 清空外星人列表和子彈列表
        aliens.empty()
        bullets.empty()

        # 創(chuàng)建一群新的外星人,并讓飛船居中
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()


def update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, play_button):
    """更新屏幕上的圖像,并切換到新屏幕"""
    # 每次循環(huán)都重繪屏幕
    screen.fill(ai_settings.bg_color)
    # 在飛船和外星人后面重繪所有子彈
    for bullet in bullets.sprites():
        bullet.draw_bullet()
    ship.blitme()
    aliens.draw(screen)

    # 顯示得分
    sb.show_score()

    # 如果游戲處于非活動狀態(tài),就繪制play按鈕
    if not stats.game_active:
        play_button.draw_button()

    # 讓最近繪制的屏幕可見
    pygame.display.flip()


def update_bullets(ai_settings, screen, stats, sb, ship, aliens, bullets):
    """更新子彈的位置,并刪除已消失子彈"""
    # 更新子彈位置
    bullets.update()

    # 刪除已消失的子彈
    for bullet in bullets.copy():
        if bullet.rect.bottom <= 0:
            bullets.remove(bullet)
    cheak_bullets_alien_collisions(ai_settings, screen, stats, sb, ship, aliens, bullets)


def cheak_bullets_alien_collisions(ai_settings, screen, stats, sb, ship, aliens, bullets):
    """響應(yīng)子彈和外星人碰撞"""
    # 刪除發(fā)生碰撞的子彈和外星人
    collections = pygame.sprite.groupcollide(bullets, aliens, True, True)

    if collections:
        for aliens in collections.values():
            stats.score += ai_settings.alien_points * len(aliens)
            sb.prep_score()
        cheak_high_score(stats, sb)

    if len(aliens) == 0:
        # 如果整群外星人都被消滅,就提高一個等級
        # 刪除現(xiàn)有的子彈,加快游戲節(jié)奏,并創(chuàng)建一群新的外星人
        bullets.empty()
        ai_settings.increase_speed()

        # 提高等級
        stats.level += 1
        sb.prep_level()

        create_fleet(ai_settings, screen, ship, aliens)


def get_number_alien_x(ai_settings, alien_width):
    """計算每行可容納多少外星人"""
    available_space_x = ai_settings.screen_width - 2 * alien_width
    number_alien_x = int(available_space_x / (2 * alien_width))
    return number_alien_x


def get_number_rows(ai_settings, ship_height, alien_height):
    """計算屏幕可容納多少行機器人"""
    available_space_y = (ai_settings.screen_height - (3 * alien_height) - ship_height)
    number_rows = int(available_space_y / (2 * alien_height))
    return number_rows


def create_alien(ai_settings, screen, aliens, alien_number, row_number):
    # 創(chuàng)建第一行外星人并將其加入當(dāng)前行
    alien = Alien(ai_settings, screen)
    alien_width = alien.rect.width
    alien.x = alien_width + 2 * alien_width * alien_number
    alien.rect.x = alien.x
    alien.rect.y = alien.rect.height + 2 * alien.rect.height * row_number
    aliens.add(alien)


def create_fleet(ai_settings, screen, ship, aliens):
    """創(chuàng)建外星人群"""
    # 創(chuàng)建一個外星人,并計算一行可容納多少個外星人
    # 外星人間距為外星人寬度
    alien = Alien(ai_settings, screen)
    number_alien_x = get_number_alien_x(ai_settings, alien.rect.width)
    number_rows = get_number_rows(ai_settings, ship.rect.height, alien.rect.height)

    # 創(chuàng)建外星人群
    for row_number in range(number_rows):
        for alien_number in range(number_alien_x):
            create_alien(ai_settings, screen, aliens, alien_number, row_number)


def cheak_fleet_edges(ai_settings, aliens):
    """有外星人到達屏幕邊緣時采取相應(yīng)的措施"""
    for alien in aliens.sprites():
        if alien.cheak_edgs():
            change_fleet_direction(ai_settings, aliens)
            break


def change_fleet_direction(ai_settings, aliens):
    """將整群外星人下移,并改變它們的位置"""
    for alien in aliens.sprites():
        alien.rect.y += ai_settings.fleet_drop_speed
    ai_settings.fleet_direction *= -1


def ship_hit(ai_settings, screen, stats, sb, ship, aliens, bullets):
    """響應(yīng)被外星人撞到的飛船"""
    if stats.ships_left > 0:
        # 將ships_left減1
        stats.ships_left -= 1

        # 更新記分牌
        sb.prep_ships()

        # 清空外星人列表和子彈列表
        aliens.empty()
        bullets.empty()

        # 創(chuàng)建一群新的外星人,并將飛船放在屏幕底端中央
        create_fleet(ai_settings, screen, ship, aliens)
        ship.center_ship()

        # 暫停
        sleep(0.5)

    else:
        stats.game_active = False
        pygame.mouse.set_visible(True)


def cheak_aliens_bottom(ai_settings, screen, stats, sb, ship, aliens, bullets):
    """檢查是否有外星人到達了屏幕底端"""
    screen_rect = screen.get_rect()
    for alien in aliens.sprites():
        if alien.rect.bottom >= screen_rect.bottom:
            # 像飛船被撞到一樣進行處理
            ship_hit(ai_settings, screen, stats, sb, ship, aliens, bullets)
            break


def update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets):
    """檢查是否有外星人位于屏幕邊緣,并更新整群外星人的位置"""
    cheak_fleet_edges(ai_settings, aliens)
    aliens.update()

    # 檢查外星人和飛船之間的碰撞
    if pygame.sprite.spritecollideany(ship, aliens):
        ship_hit(ai_settings, screen, stats, sb, ship, aliens, bullets)

    # 檢查是否有外星人到達屏幕底端
    cheak_aliens_bottom(ai_settings, screen, stats, sb, ship, aliens, bullets)


def cheak_high_score(stats, sb):
    """檢查是否誕生了新的最高得分"""
    if stats.score > stats.high_score:
        stats.high_score = stats.score
        sb.prep_high_score()

game_stats.py

跟蹤統(tǒng)計游戲信息類

class GameSrats():
    """跟蹤游戲的統(tǒng)計信息"""

    def __init__(self, ai_settings):
        """初始化統(tǒng)計信息"""
        self.ai_settings = ai_settings
        self.reset_stats()

        # 游戲剛啟動時處于活動狀態(tài)
        self.game_active = False

        # 在任何情況下都不應(yīng)重置最高得分
        self.high_score = 0

    def reset_stats(self):
        """初始化在游戲運行期間可能變化的統(tǒng)計信息"""
        self.ships_left = self.ai_settings.ship_limit
        self.score = 0
        self.level = 1

scoreboard.py

創(chuàng)建scoerboard類,用來顯示當(dāng)前得分,最高得分,玩家等級,余下的飛船數(shù)。

import pygame.font
from pygame.sprite import Group
from ship import Ship


class Scoreboard():
    """顯示得分信息的類"""

    def __init__(self, ai_settings, screen, stats):
        """初始化顯示得分涉及的屬性"""
        self.screen = screen
        self.screen_rect = screen.get_rect()
        self.ai_settings = ai_settings
        self.stats = stats

        # 顯示得分信息時使用的字體設(shè)置
        self.text_color = (30, 30, 30)
        self.font = pygame.font.SysFont(None, 48)

        # 準(zhǔn)備包含得分的初始圖像
        self.prep_score()
        self.prep_high_score()
        self.prep_level()
        self.prep_ships()

    def prep_ships(self):
        """顯示還余下多少搜飛船"""
        self.ships = Group()
        for ship_number in range(self.stats.ships_left):
            ship = Ship(self.ai_settings, self.screen)
            ship.rect.x = 10 + ship_number * ship.rect.width
            ship.rect.y = 10
            self.ships.add(ship)

    def prep_level(self):
        """將等級轉(zhuǎn)換為渲染的圖像"""
        self.level_image = self.font.render(str(self.stats.level), True, self.text_color, self.ai_settings.bg_color)

        # 將等級放在得分下方
        self.level_rect = self.level_image.get_rect()
        self.level_rect.right = self.score_rect.right
        self.level_rect.top = self.score_rect.bottom + 10

    def prep_high_score(self):
        """將最高得分轉(zhuǎn)換為渲染的圖像"""
        high_score = int(round(self.stats.high_score, -1))
        high_score_str = str("{:,}".format(high_score))
        self.high_score_image = self.font.render(high_score_str, True, self.text_color, self.ai_settings.bg_color)

        # 將最高得分放在屏幕頂部中央
        self.high_score_rect = self.high_score_image.get_rect()
        self.high_score_rect.centerx = self.screen_rect.centerx
        self.high_score_rect.top = self.screen_rect.top

    def prep_score(self):
        """將得分轉(zhuǎn)換為一幅渲染的圖像"""
        rounded_score = int(round(self.stats.score, -1))
        score_str = "{:,}".format(rounded_score)
        self.score_image = self.font.render(score_str, True, self.text_color, self.ai_settings.bg_color)

        # 將得分放在屏幕右上角
        self.score_rect = self.score_image.get_rect()
        self.score_rect.right = self.screen_rect.right - 20
        self.score_rect.top = 20

    def show_score(self):
        """在屏幕上顯示得分"""
        self.screen.blit(self.score_image, self.score_rect)
        self.screen.blit(self.high_score_image, self.high_score_rect)
        self.screen.blit(self.level_image, self.level_rect)

        # 繪制飛船
        self.ships.draw(self.screen)

settings.py

存儲游戲所有設(shè)置類

class Settings():
    """存儲外星人入侵所有設(shè)置的類"""

    def __init__(self):
        """初始化游戲靜態(tài)設(shè)置"""
        # 屏幕設(shè)置
        self.screen_width = 1200
        self.screen_height = 800
        self.bg_color = (230, 230, 230)

        # 飛船的速度設(shè)置
        self.ship_speed_factor = 1.5
        self.ship_limit = 3

        # 子彈設(shè)置
        self.bullet_speed_factor = 10
        self.bullet_width = 10
        self.bullet_height = 15
        self.bullet_color = 60, 60, 60
        self.bullets_allowed = 3

        # 外星人設(shè)置
        self.alien_speed_factor = 1
        self.fleet_drop_speed = 5
        # fleet_direction為1表示向右移,為-1表示向左移
        self.fleet_direction = 1

        # 加快游戲節(jié)奏的速度
        self.speedup_scale = 1.1

        # 外星人點數(shù)的提高速度
        self.score_scale = 1.5

        self.initialize_dynamic_settings()

    def initialize_dynamic_settings(self):
        """初始化隨游戲進行而變化的位置"""
        self.ship_speed_factor = 1.5
        self.bullet_speed_factor = 3
        self.alien_speed_factor = 1

        # fleet_direction為1表示向右,為-1表示向左
        self.fleet_direction = 1

        # 記分
        self.alien_points = 100

    def increase_speed(self):
        """提高速度設(shè)置和外星人點數(shù)"""
        self.ship_speed_factor *= self.speedup_scale
        self.bullet_speed_factor *= self.speedup_scale
        self.alien_speed_factor *= self.speedup_scale

        self.alien_points = int(self.alien_points * self.score_scale)

ship.py

管理飛船類

import pygame
from pygame.sprite import Sprite


class Ship(Sprite):

    def __init__(self, ai_settings, screen):
        """初始化飛船,并設(shè)置其初始位置"""
        super().__init__()
        self.screen = screen
        self.ai_settings = ai_settings

        # 加載飛船圖像并獲取其外接矩形
        self.image = pygame.image.load('images/ship.bmp')
        self.rect = self.image.get_rect()
        self.screen_rect = screen.get_rect()

        # 將每艘飛船放在屏幕底部中央
        self.rect.centerx = self.screen_rect.centerx
        self.rect.bottom = self.screen_rect.bottom

        # 在飛船的屬性center中存儲小數(shù)值
        self.center = float(self.rect.centerx)

        # 移動標(biāo)志
        self.moving_right = False
        self.moving_left = False

    def center_ship(self):
        """讓飛船在屏幕上居中"""
        self.center = self.screen_rect.centerx

    def update(self):
        """根據(jù)移動標(biāo)志調(diào)整飛船的位置"""
        # 更新飛船的center值,而不是rect
        if self.moving_right and self.rect.right < self.screen_rect.right:
            self.center += self.ai_settings.ship_speed_factor
        if self.moving_left and self.rect.left > 0:
            self.center -= self.ai_settings.ship_speed_factor

        # 根據(jù)self.center更新rect對象
        self.rect.centerx = self.center

    def blitme(self):
        """在指定位置繪制飛船"""
        self.screen.blit(self.image, self.rect)

以上就是外星人入侵全部開發(fā)過程

到此這篇關(guān)于pygame外星人入侵小游戲超詳細(xì)開發(fā)流程的文章就介紹到這了,更多相關(guān)pygame 外星人入侵內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • python中f字符串f-string用法詳解

    python中f字符串f-string用法詳解

    f-string用大括號{}表示被替換字段,其中直接填入替換內(nèi)容,本文給大家介紹python中f字符串f-string用法詳解,感興趣的朋友一起看看吧
    2023-10-10
  • Linux 下 Python 實現(xiàn)按任意鍵退出的實現(xiàn)方法

    Linux 下 Python 實現(xiàn)按任意鍵退出的實現(xiàn)方法

    這篇文章主要介紹了Linux 下 Python 實現(xiàn)按任意鍵退出的實現(xiàn)方法的相關(guān)資料,本文介紹的非常詳細(xì),具有參考借鑒價值,需要的朋友可以參考下
    2016-09-09
  • 使用Python下載歌詞并嵌入歌曲文件中的實現(xiàn)代碼

    使用Python下載歌詞并嵌入歌曲文件中的實現(xiàn)代碼

    這篇文章主要介紹了使用Python下載歌詞并嵌入歌曲文件中的實現(xiàn)代碼,需要借助eyed3模塊,需要的朋友可以參考下
    2015-11-11
  • 兩個元祖T1=(''a'', ''b''),T2=(''c'', ''d'')使用匿名函數(shù)將其轉(zhuǎn)變成[{''a'': ''c''},{''b'': ''d''}]的幾種方法

    兩個元祖T1=(''a'', ''b''),T2=(''c'', ''d'')使用匿名函數(shù)將其轉(zhuǎn)變成[{''a'': '

    今天小編就為大家分享一篇關(guān)于兩個元祖T1=('a', 'b'),T2=('c', 'd')使用匿名函數(shù)將其轉(zhuǎn)變成[{'a': 'c'},{'b': 'd'}]的幾種方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • PyQt5+python3+pycharm開發(fā)環(huán)境配置教程

    PyQt5+python3+pycharm開發(fā)環(huán)境配置教程

    這篇文章主要介紹了PyQt5+python3+pycharm開發(fā)環(huán)境配置教程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-03-03
  • python的pstuil模塊使用方法總結(jié)

    python的pstuil模塊使用方法總結(jié)

    這篇文章主要介紹了python的pstuil模塊使用方法總結(jié),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-07-07
  • 簡單介紹Python中利用生成器實現(xiàn)的并發(fā)編程

    簡單介紹Python中利用生成器實現(xiàn)的并發(fā)編程

    這篇文章主要介紹了簡單介紹Python中利用生成器實現(xiàn)的并發(fā)編程,使用yield生成器函數(shù)進行多進程編程是Python學(xué)習(xí)進階當(dāng)中的重要知識,需要的朋友可以參考下
    2015-05-05
  • python3 kubernetes api的使用示例

    python3 kubernetes api的使用示例

    這篇文章主要介紹了python3 kubernetes api的使用示例,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2021-01-01
  • Python?flask?sqlalchemy的簡單使用及常用操作

    Python?flask?sqlalchemy的簡單使用及常用操作

    這篇文章主要介紹了Python?flask?sqlalchemy的簡單使用及常用操作,在python中,常用的ORM工具就是sqlalchemy了。下面就以一個簡單的flask例子來說明吧,需要的小伙伴可以參考一下
    2022-08-08
  • python中的裝飾器該如何使用

    python中的裝飾器該如何使用

    裝飾器經(jīng)常被用于有切面需求的場景,較為經(jīng)典的有插入日志、性能測試、事務(wù)處理等。裝飾器是解決這類問題的絕佳設(shè)計,有了裝飾器,我們就可以抽離出大量函數(shù)中與函數(shù)功能本身無關(guān)的雷同代碼并繼續(xù)重用。裝飾器的作用就是為已經(jīng)存在的對象添加額外的功能。
    2021-06-06

最新評論