Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-23-2009, 10:27 PM   #1
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 242

Rep: Reputation: 30
Python Parse Code

I tried ot take a full program and pare it down to a function within a program and I am sure something is wrong. Actually, since I am getting an error I know something is wrong. Here is the code:
import re, urllib2, sys, BaseHTTPServer

def getip():
	web_handle = urllib2.urlopen(address)

	address = parseAddress(sys.argv[1])
	website_handle = retrieveWebPage(address)
	website_text =

	foo = re.compile("(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,4})")
	bar = website_text
	ip = foo.findall(bar)
for finds in ip:
	return finds

print finds
And this is the error I am getting
File "parse_example_try1", line 18
   return finds
SyntaxError: 'return' outside function
If it is totally screwed up then I will have to try something different.
Old 01-24-2009, 02:29 AM   #2
Registered: Sep 2004
Location: New Zealand
Distribution: Debian
Posts: 900

Rep: Reputation: 33
The error explains it pretty well. You are using 'return' outside a function definition, which is pretty meaningless - return to where?

You probably want something more like this at the end:

    return foo.findall(bar)

for ip in getip():
    print ip
Old 01-24-2009, 08:31 AM   #3
Senior Member
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 231Reputation: 231Reputation: 231
Hi snowman81 - please don't take offense but I really think you should look up a basic python tutorial to get to grips with the syntax of the language. You'll always have problems blindly hacking at code without knowing it's structure.

There are loads of good works on line. Just Google "python tutorial". A good introductory one is "A Byte of Python" or "Dive into Python" which is a bit more advanced.
Old 01-24-2009, 11:50 AM   #4
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 242

Original Poster
Rep: Reputation: 30
Meh, no offense taken. I am reading up on it but I think I'm a little impatient and am biting off more than I can chew this early in my learning process.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: parse error, unexpected '/' - can anyone see the error in this code? v@ny@ Programming 8 04-03-2010 05:07 PM
how to parse info from a txt file using c++ code abhisheknayak Programming 8 11-23-2007 02:33 AM
Parse Python through use of .htaccess Hal Linux - General 1 01-24-2006 01:33 AM
What is wrong with this python code ? indian Programming 5 09-22-2005 03:20 PM
easy python code JoeUser11 Programming 1 01-21-2005 02:40 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:37 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration