python - 使用一个文件运行良好但另一个文件未导入的位置访问我的目录中的文件(?)

标签 python visual-studio-code directory

我正在尝试使用 vs-code 访问目录中的文件 Maxoflist.py。我希望打印列表中的最大值,但事实并非如此。没有发生错误,并且在另一个文件 shipping.py 中定义的函数工作正常。

import shipping
import Maxoflist #imported the entire module shippinng
shipping.calc_shipping() #working good
findmaxoflist() #not working

Maxoflist.py:

def findmaxoflist():
    Items = [5,61,7,2,4,9,1]
    Max = Items[0]
    for num in Items:
        if Max < num:
            Max   = num

    print(f"Maximum Number is: {Max}")

findmaxoflist()

shipping.py:

def calc_shipping():    #working good when imported
    print("Callin the calculate shipping")

最佳答案

确保该目录中的文件没有丢失/删除或者名称拼写正确!

试试这个:

from Maxoflist import findmaxoflist

关于python - 使用一个文件运行良好但另一个文件未导入的位置访问我的目录中的文件(?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55450871/

相关文章:

Python交互模式历史和方向键

c++ - 在 Windows (MSVC) 上为 C++ 安装 VSCode

iis - dotnet 发布错误 : The process cannot access the file because it is being used by another process

batch-file - 提示用户在批处理文件中选择目录

c - 目录中文件的链接列表,最后附加

python - re.sub 将所有内容替换为列表中的最后一项

javascript - 将python的json对象转换为html表?

pipe - 如何通过管道将输出传输到 Visual Studio Code 中?

python - 如何将目录树输出为 HTML?

python - pandas 列表理解 if 语句