Coder Social home page Coder Social logo

Comments (13)

serhiy-storchaka avatar serhiy-storchaka commented on September 27, 2024 2

You can use string.printable.replace(' ', '') or set(string.printable) - {' '}. This can be easily modified to exclude other undesirable characters (for example I, l and 1 can be confused with each other, '' can be confused with " or ``).

string.printable is a historical artifact. Today it is superseded by the str.isprintable() methods combined with additional conditions. Every applications has its own conditions. Adding yet one string constant in the string module which differs only by a character from other string constant will likely confuse people.

from cpython.

encukou avatar encukou commented on September 27, 2024 1

If we add something for convenience, it should be both convenient and correct for many users.

While I haven't done the research, use cases I can think of are better served with a slightly different set -- for example, exclude quotes or the backslash, exclude O/0 and l/I/1 for readability, or not limit the set to ASCII. For toy examples, digits + ascii_letters are fine.

from cpython.

RustoMCSpit avatar RustoMCSpit commented on September 27, 2024

this is a good first issue i suppose for people looking to make a PR

from cpython.

RustoMCSpit avatar RustoMCSpit commented on September 27, 2024

Adding yet one string constant in the string module which differs only by a character from other string constant will likely confuse people.

i doubt anyone will be confused by a string constant. even if there are workarounds, it's just prettier and quicker to have another constant, helps the read-ability yk.

from cpython.

pochmann3 avatar pochmann3 commented on September 27, 2024

differs only by a character

By six. Also ASCII 9 to 13.

from cpython.

serhiy-storchaka avatar serhiy-storchaka commented on September 27, 2024

How would you name the new constant? string.printable_without_space? Or more accurately string.ascii_printable_without_whitespace?

from cpython.

RustoMCSpit avatar RustoMCSpit commented on September 27, 2024

How would you name the new constant? string.printable_without_space? Or more accurately string.ascii_printable_without_whitespace?

string.visible

from cpython.

nineteendo avatar nineteendo commented on September 27, 2024

Is there a problem with this?

from string import ascii_letters, digits, punctuation

visible = digits + ascii_letters + punctuation

from cpython.

RustoMCSpit avatar RustoMCSpit commented on September 27, 2024

Is there a problem with this?

from string import ascii_letters, digits, punctuation

visible = digits + ascii_letters + punctuation

no, but it's less efficient than just having a visible constant which would be useful for a lot of use cases. it's sorta like asking 'why have ascii when you can just add lower and upper ascii?'

from cpython.

nineteendo avatar nineteendo commented on September 27, 2024

For reference here are the constants of the original version:

cpython/Lib/string.py

Lines 6 to 12 in c636014

whitespace = ' \t\n'
lowercase = 'abcdefghijklmnopqrstuvwxyz'
uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
letters = lowercase + uppercase
digits = '0123456789'
hexdigits = digits + 'abcdef' + 'ABCDEF'
octdigits = '01234567'

Only punctuation & printable have been added since with the latter being the concatenation of all other strings.

from cpython.

RustoMCSpit avatar RustoMCSpit commented on September 27, 2024

i still think visible is such a logical addition when someone needs all visible symbols fast. id hardly see it as bloat? i fully axknowledge what im suggestinf is just an efficiency / readability optimisation and there are work arounds but i see little reason why not to add it as a constant

from cpython.

encukou avatar encukou commented on September 27, 2024

i see little reason why not to add it as a constant

The opposite question is relevant: what is the reason to add it? Where would it be useful?
It's easy to add, but that's not a very good reason to add it.

from cpython.

RustoMCSpit avatar RustoMCSpit commented on September 27, 2024

i see little reason why not to add it as a constant

The opposite question is relevant: what is the reason to add it? Where would it be useful? It's easy to add, but that's not a very good reason to add it.

already answered. tl;dr: convenience.

from cpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.