【发布时间】:2014-10-10 11:56:11
【问题描述】:
在 Windows 7 上使用 Python 3。
import pickle
import os.path
from tkinter import * # Import tkinter
import tkinter.messagebox
class Places:
def __init__(self, name, street, city, state, zip):
self.name = name
self.street = street
self.city = city
self.state = state
self.zip = zip
class PlacesBook:
def __init__(self):
window = Tk() # Create a window
window.title("PlacesBook") # Set title
我收到错误 builtins.NameError: name 'self' is not defined at "class PlacesBook:"
【问题讨论】:
-
你能检查一下你的缩进吗?这在 Python 中很重要。
-
我的复制和粘贴中没有显示缩进。
-
无法复制 - 运行更新的代码 (
pb = PlacesBook()) 对我来说很好。您能否提供一个minimal example 以允许其他人重现该问题? -
这可能会回答你的问题:stackoverflow.com/questions/1802971/…
标签: python python-3.x