Python raw_input with forced TLD?

怎甘沉沦 提交于 2019-12-13 15:17:26

问题


I am working on a program that checks hostnames of specific sites, and I want to be able to insure that when asked for the hostname (with raw_input) it ends in a TLD (.com, .net, .org). I am not exactly sure how to do this in Python.

In bash I have:

local TLD=(com info org net)    
for entry in ${TLD[@]}; do
   blah blah    
done

What is the equivalent in Python?


回答1:


endswith(suffix[, start[, end]]) will do the trick. Documentation

Please also note that suffix can be a tuple of suffices!

TLD = ('.com', '.info', '.org', '.net')
if raw_input("Please enter a hostname").endswith(TLD):
    # blah blah


来源:https://stackoverflow.com/questions/16819129/python-raw-input-with-forced-tld

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!