LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 01-23-2009, 09:27 PM   #1
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 225

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:
Code:
import re, urllib2, sys, BaseHTTPServer


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

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



	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
Code:
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, 01:29 AM   #2
CroMagnon
Member
 
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:

Code:
    return foo.findall(bar)

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

Rep: Reputation: 227Reputation: 227Reputation: 227
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, 10:50 AM   #4
snowman81
Member
 
Registered: Aug 2006
Location: Michigan
Distribution: Ubuntu
Posts: 225

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.
 
  


Reply


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 04:07 PM
how to parse info from a txt file using c++ code abhisheknayak Programming 8 11-23-2007 01:33 AM
Parse Python through use of .htaccess Hal Linux - General 1 01-24-2006 12:33 AM
What is wrong with this python code ? indian Programming 5 09-22-2005 02:20 PM
easy python code JoeUser11 Programming 1 01-21-2005 01:40 AM


All times are GMT -5. The time now is 09:53 PM.

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