【发布时间】:2021-04-13 19:33:26
【问题描述】:
我正在尝试将 python 函数移至 Google Cloud Functions,但我似乎遇到了别名问题。
我有一个模块,它的 init 中有以下内容;
import tweetBot.generator, tweetBot.poster
# Add aliases when this module is imported
tweetBot.ebooksGen = tweetBot.generator.ebooksGen
tweetBot.genreGen = tweetBot.generator.genreGen
tweetBot.variantGen = tweetBot.generator.variantGen
tweetBot.postTweet = tweetBot.poster.postTweet
然后使用简单的import tweetBot 导入。
在我的本地机器上运行它,它运行良好,并且该功能绝对没有问题。输出全部正确,一切正常。
但是,当使用 Google Cloud Functions 运行此程序时,我收到以下错误;
AttributeError: module 'tweetBot' has no attribute 'genreGen'
这对我来说绝对没有意义,因为它是在导入中绝对定义的。此外,我知道这是可行的,因为它在我的本地机器上从完全相同的存储库中运行得非常好。
https://github.com/Jademalo/JadeBots/tree/gcp-functions
忽略糟糕的代码,至少它可以工作。我只是不明白为什么我在 Google Cloud 上运行它时会出现属性错误,而它在本地绝对没问题。
谢谢
编辑:用原件替换别名调用后(例如tweetBot.generator.genreGen,我仍然遇到同样的问题;
File "/workspace/JadeBots.py", line 18, in postGenreDefining
tweetText, altGenreGameDebug, altGenreExtraDebug, gameText, genreText, altPostDebug = tweetBot.generator.genreGen(gameFile, genreFile, genreExtraFile, altPostFreq, altGenreGameFreq, altGenreExtraFreq)
AttributeError: module 'tweetBot' has no attribute 'generator'
【问题讨论】:
标签: python google-cloud-platform