Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function returning None
#1
Hi,

I'm working my way through an example in a book. However, it is return an unexpected value. Wonder if someone could help point out what/where I did wrong.

baseUrl ="http://pythonscraping.com" 
source = "www.pythonscraping.com/sites/default/files/lrg_0.jpg"

def getAbsoluteURL(baseUrl, source):
	if source.startswith("http://www."):
		url = "http://"+source[11:]
	elif source.startswith("http://"):
		url = source
	elif source.startswith("www."):
		url = source[4:]
		url = "http://"+source
	else:
		url = baseUrl+"/"+source
	if baseUrl not in url:
		return None
	return url
When I run the following code:
fileUrl = getAbsoluteURL(baseUrl, source)
print(fileUrl)
I got the value None. I thought that the second elif statement would evaluate to True, in which the url returned would be "http://pythonscraping.com/sites/default/files/lrg_0.jpg" as opposed to None.
I tried to trace where it went wrong by only defining the function as:
def getAbsoluteURL(baseUrl, source):
	if source.startswith("http://www."):
		url = "http://"+source[11:]
	elif source.startswith("http://"):
		url = source
	elif source.startswith("www."):
		url = source[4:]
		url = "http://"+source
However, the return value still is None.
Reply


Messages In This Thread
function returning None - by tkj80 - Oct-03-2016, 11:16 PM
RE: function returning None - by metulburr - Oct-03-2016, 11:21 PM
RE: function returning None - by wavic - Oct-04-2016, 12:30 AM
RE: function returning None - by tkj80 - Oct-06-2016, 02:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why my function is returning None? PauloDAS 6 1,989 Jul-17-2022, 11:17 PM
Last Post: Skaperen
  Pausing and returning to function? wallgraffiti 1 2,237 Apr-29-2021, 05:30 PM
Last Post: bowlofred
  Why is the function returning None for a * b instead of number? omm 10 4,582 Nov-05-2020, 01:17 PM
Last Post: omm
  Having hard time understanding the function self-returning itself twice jagasrik 2 2,622 Aug-15-2020, 08:50 PM
Last Post: deanhystad
  Returning Value from Function with Trackbars vicpylon 3 2,188 May-24-2020, 11:28 PM
Last Post: bowlofred
  Nested Recursive Function not Returning Etotheitau 2 2,421 May-09-2020, 06:09 PM
Last Post: Etotheitau
  Function not returning correct value ActualNoob 3 2,824 Jan-11-2019, 12:35 AM
Last Post: stullis
  Function not returning expected value Euqinu 4 3,659 Sep-10-2018, 12:48 PM
Last Post: Euqinu
  Recursive function not returning expected output...(Python speech recog module) bigmit37 4 6,082 Jan-10-2017, 02:13 PM
Last Post: bigmit37

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020