如何正确导入我创建的python模块?

时间:2019-04-22 18:51:45

标签: python-3.x

我的主python文件和模块python文件都在同一目录中。当我尝试通过在模块文件中调用类来定义新变量时,VSCode告诉我该变量未定义。

module.py

class Shirt:

    def __init__(self, shirt_color, shirt_size, shirt_style, shirt_price):
        self.color = shirt_color
        self.size = shirt_size
        self.style = shirt_style
        self.price = shirt_price

    def change_price(self, new_price):

        self.price = new_price

    def discount(self, discount):

        return self.price * (1 - discount)

shirt.py

import os
import shirt_module

new_shirt = Shirt('red', 'S', 'short-sleeved', 15)

VSCode表示shirt.py文件中的变量Shirt是未定义的。有谁知道为什么会这样?

0 个答案:

没有答案
相关问题