【发布时间】:2020-11-20 19:02:38
【问题描述】:
我有一个项目目录,用于提取和处理 twitter 数据,其中包含用于我所有配置的配置模块
twitter_data
|
|--config
| |--configAuth.py -> a class file for configuring an api object
| |--accessKeys.py -> a file for processing access keys for configuration
| |--__init__.py -> used for global API
| |--access_keys.txt
|
|--dataScraping
|--searchUsers.py -> test file to see if twitter API works
|--__init__.py
这是 searchUsers.py 的内容
import tweepy
from config import api
from config.configAuth import configAuth
def configTweepy(keys):
return configAuth(keys).getApi()
def getUserList(keyWord):
return api.search_users(keyWord)
users = getUserList('rock music')
for user in users: print(user.screen_name)
当我运行它时,我遇到了这个错误
Traceback (most recent call last):
File "searchUsers.py", line 7, in <module>
from config import api
ModuleNotFoundError: No module named 'config'
我尝试使用 sys.append 路径方法,但我需要它只处理 twitter_data 目录中的文件,而不必指定完整路径,因为 accessKeys.py 依赖于 access_keys.txt 文件。
有修复吗?
【问题讨论】:
标签: python tweepy python-module