googleads-python-lib icon indicating copy to clipboard operation
googleads-python-lib copied to clipboard

get_keyword_ideas pass variable

Open steponafish opened this issue 7 years ago • 1 comments

I'm trying to pass main() into another file. I'm using the sample code. I have:

import get_keyword_ideas
print(get_keyword_ideas.main())

This is the end of the code of my own get_keyword_ideas.py

if __name__ == '__main__':
  # Initialize client object.
  keywordList = []
  keywords = form_variables.keywordlist.split("\n")  
  adwords_client = adwords.AdWordsClient.LoadFromStorage('/path/to/googleads.yaml')
  main(adwords_client, int(AD_GROUP_ID) if AD_GROUP_ID.isdigit() else None)

  keywordList = main.keywordList

I'm getting this error in my other file:

Traceback (most recent call last):
  File "get_results.py", line 29, in <module>
    print(get_keyword_ideas.main())
TypeError: main() missing 1 required positional argument: 'client'

When running the script directly from the get_keyword_ideas.py file it all works with no errors. So why am I getting this error when trying to import the module to another file.

Any advice?

steponafish avatar Jan 25 '19 21:01 steponafish

Hi @steponafish thanks for the question! The simple answer is that error is generated because the main function in the get_keyword_ideas example (assuming that's what you're working from) requires at least one argument (the adwords client) to be passed in when it's invoked. So the first code block you have will generate an error because main() is invoked with no arguments.

For the rest of your question; I'm not sure I understand exactly what you're trying to do. Are you trying to import the main function from the example code and call it elsewhere? Note that that function only logs data from requests so it won't be useful. What you should do is use the code as an example to write your own scripts that actually pass around data. I don't recommend using example code directly - it's just for documentation purposes.

Hope that helps. I'm going to close this issue but feel free to reopen it if you think I misunderstood your issue.

BenRKarl avatar Mar 14 '19 17:03 BenRKarl