Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'output': 0.04; 'subject:text': 0.05; 'subject:file': 0.07; 'python': 0.09; 'already.': 0.09; 'hostname': 0.09; 'iterate': 0.09; 'received :mail-vc0-f174.google.com': 0.09; 'sep': 0.09; 'subject:using': 0.09; 'file,': 0.15; "(you're": 0.16; '2.7.3': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable:': 0.16; 'looping': 0.16; 'screen,': 0.16; 'wrote:': 0.17; 'thu,': 0.17; 'issue.': 0.20; 'file.': 0.20; 'file:': 0.22; "haven't": 0.23; 'header:In-Reply-To:1': 0.25; 'expand': 0.26; 'am,': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'lines': 0.28; 'all.': 0.28; 'pointer.': 0.29; 'received:209.85.220.174': 0.29; "i'm": 0.29; 'basic': 0.30; 'url:python': 0.32; 'file': 0.32; 'could': 0.32; 'docs': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'open': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'url:org': 0.36; 'url:library': 0.36; "i'll": 0.36; 'address.': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'takes': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'address': 0.60; 'most': 0.61; 'worth': 0.63; 'else.': 0.65; 'want,': 0.65; 'enjoy': 0.67; 'fact,': 0.69; 'subject:get': 0.81; 'addresses;': 0.84; 'done:': 0.84; 'presumably': 0.84; 'reading,': 0.84; 'url:functions': 0.84; 'url:reference': 0.84; 'you;': 0.84; 'url:tutorial': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=tLqgYAZzlqcdiXYiYWIvujLTJi28ML3Z7HvxzQ0iGEs=; b=P3x5Nnxlywx9w6jtOhUzEjXHu4287VSjiKMskM1kUcLLEyX/gfud+BOyJ41qRVa04W wd/JmQOyLR5toRs/3QoxiwVaMWF5tYQYJCBKS7zpD2O5Gb8+fwoNg834vW0/DjzzXyX5 TZQc4BM6Vy0nViznMTpOwk5MHQDPP7WXXhBXvDgWImf8UDJ4NHjqi/q01eGdW/hydqlA /MeZhT5ZkHuLpT2IdY0hJGFRhvGvpQyOxquCRmvHzz8oIEm7bUAyDwNOLGtn2oBcQamu vKDj/V5E0WbhoMBpFYtpYgTSby6ER0OclhwX3/9rjDTV6fICvl8SRYbbHiEqaQGnMBRL zZzA== MIME-Version: 1.0 In-Reply-To: References: Date: Thu, 13 Sep 2012 00:35:30 +1000 Subject: Re: using text file to get ip address from hostname From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1347460533 news.xs4all.nl 6954 [2001:888:2000:d::a6]:34724 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28970 On Thu, Sep 13, 2012 at 12:24 AM, wrote: > i'm new to Python and i searched the web and could not find an answer for my issue. > > i need to get an ip address from list of hostnames which are in a textfile. This is sounding like homework, so I'll just give you a basic pointer. You have there something that successfully resolves one hostname to an IP address. Now you want to expand that to reading an entire file of them and resolving them all. Presumably you need to produce a list of IP addresses; check the question as to whether you need to create a file, or output to the screen, or something else. What you want, here, is to open a file and iterate over it. The most convenient way would be to have one hostname per line and iterate over the lines of the file. Check out these pages in the Python docs (you're using Python 2 so I'm going with Python 2.7.3 documentation): Opening a file: http://docs.python.org/library/functions.html#open Ensuring that it'll be closed when you're done: http://docs.python.org/reference/compound_stmts.html#the-with-statement Looping over an iterable: http://docs.python.org/tutorial/controlflow.html#for-statements See where that takes you; in fact, all of http://docs.python.org/tutorial/ is worth reading, if you haven't already. Have fun, enjoy Python! ChrisA