Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to get the string module constants ASCII and numeric character sets in Python

2 Answers

0 votes
import string   
import inspect     
  
def is_string(value):         
    return isinstance(value, str)     
    
for constant_name, value in inspect.getmembers(string, is_string):         
    if constant_name.startswith('_'):             
        continue         
    print('%s = %r\n' % (constant_name, value))



'''
run

ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

digits = '0123456789'

hexdigits = '0123456789abcdefABCDEF'

octdigits = '01234567'

printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'

punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'

whitespace = ' \t\n\r\x0b\x0c'

'''

 



answered Apr 26, 2019 by avibootz
0 votes
import string   
import inspect     
  
def is_string(value):         
    return isinstance(value, str)     
    
for constant_name, value in inspect.getmembers(string, is_string):         
    if constant_name.startswith('_'):             
        print('%s = %r\n' % (constant_name, value))



'''
run

__cached__ = '/usr/lib/python3.6/__pycache__/string.cpython-36.pyc'

__doc__ = 'A collection of string constants.\n\nPublic module variables:\n\nwhitespace -- a string containing all ASCII whitespace\nascii_lowercase -- a string containing all ASCII lowercase letters\nascii_uppercase -- a string containing all ASCII uppercase letters\nascii_letters -- a string containing all ASCII letters\ndigits -- a string containing all ASCII decimal digits\nhexdigits -- a string containing all ASCII hexadecimal digits\noctdigits -- a string containing all ASCII octal digits\npunctuation -- a string containing all ASCII punctuation characters\nprintable -- a string containing all ASCII characters considered printable\n\n'

__file__ = '/usr/lib/python3.6/string.py'

__name__ = 'string'

__package__ = ''

'''

 



answered Apr 26, 2019 by avibootz

Related questions

...