Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get string constants for punctuation characters in Python

How can I access Python's string constants ?

I need to get a list of punctuation marks which Python docs say are in string.punctuation

This won't work

''.punctuation
''.get_value("punctuation")

Is what I'm trying even possible?

like image 762
Joel Blum Avatar asked Oct 27 '25 01:10

Joel Blum


2 Answers

string in string.punctuation isn't referring to type str, but to a string module:

In [32]: import string

In [33]: string.punctuation
Out[33]: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
like image 136
root Avatar answered Oct 28 '25 13:10

root


Like so:

>>> import string
>>> string
<module 'string' from '/usr/lib/python2.7/string.pyc'>
>>> string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
like image 44
Udo Klein Avatar answered Oct 28 '25 13:10

Udo Klein