-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidcheck.py
More file actions
33 lines (26 loc) · 768 Bytes
/
idcheck.py
File metadata and controls
33 lines (26 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
from keyword import kwlist
import string
ALPHAS = string.ascii_letters + '_'
NUMS = string.digits
def main():
print 'Welcome to the Identifier Checker v2.0'
myInput = raw_input('Identifier to test? ').strip()
if len(myInput) == 0:
print "ERROR: no identifier candidate entered"
return
if myInput in kwlist:
print "ERROR: %r is a keyword" % myInput
return
alnums = ALPHAS + NUMS
for i, c in enumerate(myInput):
if i == 0 and c not in ALPHAS:
print 'ERROR: first symbol must be alphabetic'
break
if c not in alnums:
print 'ERROR: remaining symbols must be alphanumeric'
break
else:
print "okay as an identifier"
if __name__ == '__main__':
main()