On Thu, Oct 24, 2019 at 1:13 AM Greg Ewing <greg.ew...@canterbury.ac.nz>
wrote:

> Christopher Barker wrote:
> > I've always wondered
> > how disruptive it would be to add a char type
>
> I'm not sure if it would help much. Usually the problem with
> strings being sequences of strings lies in the fact that they're
> sequences at all. Code that operates generically on nested sequences
> often has to special-case strings so that it can treat them as
> atomic values. Having them be sequences of something else
> wouldn't change that.
>

wouldn't it? once you got to an object that couldn't be iterated, you'd
know you had an atomic value. And this is why I was thinking that chars had
less functionality, it would work. This is really common code for me that I
need to type check:

for filename in sequence_of_filenames:
    open(filename)

if a char could not be used as a filename, then I'd get a similar error if
a single string was passed in as if a list of numbers was passed in, say.

That is, a string is a sequence of chars, not a sequence of strings. and a
char can not be used as a string in many contexts.

If I were to advocate changing anything in that area, it would
> be to make strings not be sequences. They would support slicing,
> but not indexing single characters, and would not be directly
> iterable.


you are right -- that would be a great solution to the above problem. And I
can't think of many real uses for iterating strings where you don't know
that you want the chars, so .chars() iterator, or maybe str.iter_chars()
would be fine.

Something tells me that I've had uses for char in other contexts, but I
can't think of them now, so maybe not :-)

But again -- too disruptive, we've lived with this for a LONG time.

-CHB



> If you really wanted to iterate over characters, there
> could be a method such as s.chars() giving a sequence view.
> But that would be a disruptive enough change for so little
> benefit that I don't expect it to ever happen.
>
> --
> Greg
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/LUR6URJANVGIVJCWQMIUEM7XASTLV47B/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/DG57PO6KFDSKZ4ZQMK7R7VNYHWYRQELN/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to