Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'socket': 0.05; 'subject:text': 0.05; 'exit': 0.07; 'filename': 0.07; 'subject:file': 0.07; 'sys,': 0.07; 'try:': 0.07; 'python': 0.09; 'hostname': 0.09; 'loop.': 0.09; 'sep': 0.09; 'subject:using': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'finished': 0.15; '(another': 0.16; 'chris,': 0.16; 'code?': 0.16; 'e))': 0.16; 'situation.': 0.16; 'skip:( 60': 0.16; 'sys.exit(1)': 0.16; '{0}': 0.16; 'wed,': 0.16; 'wrote:': 0.17; 'skip:{ 20': 0.17; 'import': 0.21; 'thanks.': 0.21; 'lets': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'host': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'skip:# 10': 0.27; 'question': 0.27; 'forgive': 0.27; 'options': 0.27; 'chris': 0.28; 'dan': 0.29; "i'm": 0.29; 'file': 0.32; 'addresses': 0.32; 'print': 0.32; 'says': 0.33; 'skip:s 30': 0.33; 'docs': 0.33; 'code:': 0.33; 'tutorial': 0.33; 'another': 0.33; 'program,': 0.34; 'received:google.com': 0.34; 'text': 0.34; 'clear': 0.35; 'pm,': 0.35; 'continue': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'except': 0.36; 'but': 0.36; 'skip:{ 10': 0.36; 'option': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'skip:o 20': 0.38; 'received:209.85.214': 0.39; 'where': 0.40; 'your': 0.60; 'address': 0.60; 'stay': 0.61; 'back': 0.62; 'show': 0.63; 'here': 0.65; 'choose': 0.65; 'skip:\xd7 10': 0.69; '8bit%:100': 0.70; 'sounds': 0.71; 'subject:get': 0.81; "'while'": 0.84; 'received:209.85.214.184': 0.84; 'received:mail- ob0-f184.google.com': 0.84; 'start.': 0.84 Newsgroups: comp.lang.python Date: Wed, 19 Sep 2012 01:50:47 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.65.169.174; posting-account=_vepBgoAAAD3Jx-8VUeoi33AOFj3T9H8 References: <3359a0e7-f7bb-4b1f-b586-e83f337566b7@googlegroups.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 85.65.169.174 MIME-Version: 1.0 Subject: Re: using text file to get ip address from hostname From: Dan Katorza To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 107 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348044655 news.xs4all.nl 6926 [2001:888:2000:d::a6]:35413 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29472 =D7=91=D7=AA=D7=90=D7=A8=D7=99=D7=9A =D7=99=D7=95=D7=9D =D7=A8=D7=91=D7=99= =D7=A2=D7=99, 19 =D7=91=D7=A1=D7=A4=D7=98=D7=9E=D7=91=D7=A8 2012 11:14:29 U= TC+3, =D7=9E=D7=90=D7=AA Chris Angelico: > On Wed, Sep 19, 2012 at 5:41 PM, Dan Katorza wrote: >=20 > > >=20 > > Hello again, >=20 > > I have another question and i hope you will understand me.. >=20 > > Is there any option where you can set the program to go back to lets sa= y the top of the code? >=20 > > I mean if the program finished the operation and i want to stay in the = program and go back ro the start. >=20 > > after any operation i want the option to do it again , go back to the m= ain menu or full exit from the program, and i want it every time. >=20 > > >=20 > > i hope i'm clear :) >=20 >=20 >=20 > Yep! Look up the docs and tutorial on "control flow" and "looping >=20 > constructs". Sounds like what you want here is a 'while' loop. >=20 >=20 >=20 > ChrisA Hi Chris, this is my code: #!/usr/bin/env python #Get the IP Address import sys, socket print ("\n\n#########################################################") print ("# Get IP from Host v 1.0 #") print ("#########################################################") print ("# Choose from the options below #") print ("# 1- url , 2-File(Text file only.txt) #") print ("#########################################################\n") mchoice =3D int(raw_input("Please enter your choice> ")) while mchoice !=3D1 and mchoice !=3D2: print("{0} is not a menu option.".format(mchoice)) mchoice =3D int(raw_input("Please try again> ")) if mchoice =3D=3D 2: filename =3D raw_input("Hello, please enter file name here> ") if filename.endswith(".txt"): try: infile =3D open(filename) except EnvironmentError as e: print(e) sys.exit(1) print("\nFile {0} exists!".format(filename)) print("\nGetting IP addresses for hosts") print("\n") else: print("{0} is not a Text file.".format(filename)) sys.exit(1) for line in infile: hostname =3D line.strip() try: ip_address =3D socket.gethostbyname(hostname) except EnvironmentError as e: print("Couldn't find IP address for {0}: {1}".format(hostname, e)) continue print("IP address for {0} is {1}.".format(hostname, ip_address)) else: print ("\nFinished the operation") if mchoice =3D=3D 1: murl =3D raw_input("Enter URL here> ") try: print("Checking URL...") ip_address =3D socket.gethostbyname(murl) except EnvironmentError as d: print(d) sys.exit(1) print("Valid URL") print("\nIP address for {0} is {1}.".format(murl, ip_address)) print ("\nFinished the operation") =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D now where it says Finsihed the operation i want it to show (another search = /main menu/exit program) i know about the while loop , but forgive me i just don't have a clue how t= o use it for this situation. i don't want you to give me the code:) just the idea. i did read the section about the while loop but still i do not know how to = use it in this situation. thanks.