Y
Y
Yevgeni2018-03-28 18:02:25
Python
Yevgeni, 2018-03-28 18:02:25

How to properly import from .py to .py?

Hello.

I'm having trouble importing a .py file. To be more specific, attributes are not inherited from me.

The file I am trying to import is:

import tweepy

def api():
    consumer_key = 'айзабей'
    consumer_secret = 'айзабей'
    access_token = 'айзабей'
    access_token_secret = 'айзабей'
    
    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    api = tweepy.API(auth)
    
    return api


The file I'm trying to import into :
from flask import Flask, render_template
from tweepy_credentials import api
app = Flask(__name__)

@app.route('/')
def index():
    public_tweets = api.home_timeline(count=10)
    return render_template('index.html',public_tweets=public_tweets)

if __name__ == '__main__':
    app.run(debug=True)


at the output I have AttributeError: 'function' object has no attribute 'home_timeline'

in other words, the reference to the api object is empty :( HELP!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-03-28
@Yevgeni

public_tweets = api().home_timeline(count=10)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question