# This is a comment
127.0.0.1 localhost
192.168.2.253 pyschools # python server
Examples
>>> gethostname('127.0.0.1')
'localhost'
>>> gethostname('192.168.2.253')
'pyschools'
>>> gethostname('192.168.2.254') # Returns 'Unknown host' if ip address is not found.
'Unknown host'
代码: 全选
# Write a function that reads the /etc/hosts and return the hostname, given the ip address.
def gethostname(ip_address):
for line in open("/etc/hosts"):
line = line.rstrip()
if ip_address in line:
return line.split(' ')[-1]
break
else:
return "Unknown host"
官方给出的解释是
费了老大劲,还是不知道哪里出错。What does it mean when I failed the Private Test Cases?
Private test cases are hidden test cases created to prevent the users from hardcoding the answers to the visible test cases. If you fail the private test cases, look at the samples for some clues that you may miss. For example, there may be a missing '\n' or ' ' (space) which is not apparent between the Returned and Expected results.