【问题标题】:Can't figure out why I can't import this one class, I feel like it should work不知道为什么我不能导入这一类,我觉得它应该可以工作
【发布时间】:2019-09-07 03:12:48
【问题描述】:

我在一个文件中创建了一个简单的类,该文件与我尝试发送它的目录位于同一目录中。但是,由于某些未知的原因,我一生都无法弄清楚为什么导入不起作用。任何帮助都会很棒。

我已经用谷歌搜索了很多,但找不到任何特定于我的东西

有问题的类(名为 location1.py 的文件)

class Location:
    def __init__(self, name, txt_display, been_there):
        self.name = name
        self.txt_display = txt_display
        self.been_there = been_there

我所有的导入(名为 mainPart1.py 的文件)

import random
from tkinter import *
from location1 import *
from PIL import ImageTk, Image

我如何测试它

temp = Loction("1a", "display poo", True)
print(temp.name)

“名称错误:名称‘位置’未定义” 我从终端得到这个,我不知道该怎么做。 我期待“1a”

【问题讨论】:

  • 阅读错误信息:你拼错了类名。

标签: python class import


【解决方案1】:

你有一个错字,应该是Location

您的代码:

temp = Loction("1a", "display poo", True)

应该是:
temp = Location("1a", "display poo", True)

【讨论】:

    猜你喜欢
    • 2018-09-24
    • 1970-01-01
    • 2022-07-26
    • 2020-04-16
    • 1970-01-01
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多