[英]Python calling a function from another file - error
I am attempting to call a function from another file called 'run_ES_15M_Trend_Identifier': 我正在尝试从另一个名为“ run_ES_15M_Trend_Identifier”的文件调用函数:
import sys
import os
sys.path.append(os.path.abspath(r"C:\Users\cost9\OneDrive\Documents\PYTHON\Daily Tasks\Individual Trading\ES"))
from ES_15M_Trend_Identifier import run_ES_15M_Trend_Identifier
So the above function comes from the ES_15M_Trend_Identifier py file. 因此,以上函数来自ES_15M_Trend_Identifier py文件。 I just ran that file from its own directory and it works perfect - modifies the dataframe, sends to csv. 我只是从其自己的目录中运行了该文件,它的工作原理非常完美-修改了数据框,然后发送到csv。 So the error isn't coming from the function itself. 因此,错误并非来自函数本身。 Instead I get the error: 相反,我得到了错误:
ImportError: cannot import name run_ES_15M_Trend_Identifier
I realize there might be something circular about this process from other SO posts, but I'm not sure how to fix it. 我意识到其他SO帖子可能对此过程进行了一些通报,但是我不确定如何解决它。
edit: I've also tried: 编辑:我也尝试过:
from ES_15M_Trend_Identifier import *
run_ES_15M_Trend_Identifier()
which gives the error: 给出错误:
NameError: name 'run_ES_15M_Trend_Identifier' is not defined
edit: Here's the function, which works when I run it in its own file: 编辑:这是函数,当我在其自己的文件中运行该函数时可以使用:
def run_ES_15M_Trend_Identifier():
# Do stuff to pandas dataframe, including some for loops that fill out additional columns - this function works on the original file
path_to_csv = "C:\\Users\\cost9\\OneDrive\\Documents\\PYTHON\\Daily Tasks\\Individual Trading\\ES\CSV\\15M\\Trend_Identifier\\ES_15M_Summary.csv"
ES_15M_Summary_Reduced.to_csv(path_or_buf = path_to_csv)
Is both files are in the same directory? 两个文件都在同一个目录中吗? if not put both files in the same folder! 如果没有将两个文件放在同一个文件夹中!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.