14495

function1 from other file fail when that function1 is calling another function2 inside function1

Question:

Code in FileB.py works fine, but fail at one point when I am calling it from other file. I found that it's stops working when calling function "search_response" in the code below.

FileA.py

from FileB import * search = "stackoverflow" searchF(search)

FileB.py

from apiclient.discovery import build from apiclient.errors import HttpError from oauth2client.tools import argparser search = "Google" def searchF(search): DEVELOPER_KEY = "REPLACE_ME" YOUTUBE_API_SERVICE_NAME = "youtube" YOUTUBE_API_VERSION = "v3"

<strong>print "searchF started" - works</strong>

def youtube_search(options): youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY) search_response = youtube.search().list( q=options.q, type="video", part="id,snippet", maxResults=options.max_results ).execute()

<strong>print "search_response executed" doesn't work</strong>

search_videos = [] for search_result in search_response.get("items", []): search_videos.append(search_result["id"]["videoId"]) video_ids = ",".join(search_videos) video_response = youtube.videos().list( id=video_ids, part='snippet, contentDetails' ).execute() videos = [] for video_result in video_response.get("items", []): videos.append("%s, (%s,%s)" % (video_result["snippet"]["title"], video_result["contentDetails"], video_result["contentDetails"])) find = "licensedContent': True" result = ', '.join(videos) print find in result if __name__ == "__main__": print "__main__" argparser.add_argument("--q", help="Search term", default=search) argparser.add_argument("--max-results", help="Max results", default=25) args = argparser.parse_args() try: youtube_search(args) except HttpError, e: print "An HTTP error %d occurred:\n%s" % (e.resp.status, e.content)

Answer1:

I changed if __name__ == "__main__": to if 1: and it's kinda works. But I am assume it's a horrible solution.

Recommend

  • Add a video to a playlist using resumable upload
  • Fixing relative links in PHP
  • Having issues with creating Tile Sets in Xcode 8. Anyone have any success?
  • getting error “There was a issue with network [400]” while playing You tube video
  • Ios swift - storing uiimage in document directory and path in core data
  • youtube video insert “onBehalfOfContentOwner” parameter value
  • google-maps-sdk-ios - arm 7/iphone 5 issues for Google Maps 1.4.3 for iOS
  • Watir::Exception::MissingWayOfFindingObjectException: invalid attribute: :css
  • Google Places API - Get more than 10 photos from Details Response?
  • jQuery: replace() or wrap() http://name.tld/request_url?parameter with …?
  • Problem in Loading xml from specified url using javascript in FF & Google Chrome
  • How to get google-services.json from Developer console?
  • Making Cross Site Asynchronous HTTP Post from GWT Client
  • Connecting Google Cloud SQL with Wordpress on Google Compute Engine
  • Cassandra NoClassDefFoundError: com/google/common/util/concurrent/AsyncFunction
  • Cannot page through all results using nextPageToken on YouTube search API v3
  • WARNING:root:Some characters could not be decoded, and were replaced with REPLACEMENT CHARACTER. Wit
  • How to create two column output from a single column
  • Faster Way To Simultaneously Iterate Over Rolling Window Of Two Or More Numpy Arrays?
  • mave 3.2 not able to access local nexus instance return 502 code
  • google maps autocomplete bounces back already cleared text …odd…odd…odd
  • Google Maps api v3 get start and end coordinates of a street
  • Django foreign key drop down
  • Clear fused location provider's location for testing
  • Update Google Maps traffic layer without page reloading
  • Trying to get the char code of ENTER key
  • Android Studio 1.3 RC3. Google Play services out of date. Requires 7571000 but found 6774470
  • android google indoor map
  • Android Google Maps API v2 start navigation
  • Insert new calendar with SyncAdapter- Calendar API Android
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • Grails calculated field in SQL
  • Seeking advice on Jetty HttpClient Hang
  • swift auto completion not working in Xcode6-Beta
  • How to add date and time under each post in guestbook in google app engine
  • JSON with duplicate key names losing information when parsed
  • Google cloud sdk not working when python points python3
  • Return words with double consecutive letters
  • using HTMLImports.whenReady not working in chrome
  • Android Heatmap on canvas or ImageView