當前位置:編程學習大全網 - 編程軟體 - Python 程序報:NameError: name 'sys' is not defined

Python 程序報:NameError: name 'sys' is not defined

在代碼最前面加入壹行代碼:import?sys。

出錯是因為沒有導入sys這個模塊。

修改後的代碼變為:

import?sys

import pygame

pygame.init()

screen = pygame.display.set_mode([640,480])

while True:

for event in pygame.event.get():

if event.type == pygame.QUIT:

sys.exit()

擴展資料:

Python編程常見問題

問題壹,出現“name ‘name’ is not defined”報錯

解決:"name"兩端是雙下劃線"_",不是只有壹個""。

問題二,出現“name 'messagebox' is not defined”報錯

解決:“ ” 內為某個數據庫的子module。

在代碼中加上語句:from tkinter import messagebox,默認情況下子module不會自動import。

問題三,出現“name 'reload' is not defined.”報錯。

解決:對於 Python 2.X添加代碼行:

import sys

reload(sys)

sys.setdefaultencoding("utf-8")

對於 Python 3.3添加代碼行:

import imp

imp.reload(sys)

參考資料:

百度百科-Python

  • 上一篇:如何在VB6.0中編寫SQL語句
  • 下一篇:寶馬x1扶手後面的插口怎麽用
  • copyright 2024編程學習大全網