Python Forum
how to test if something is a sequence?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to test if something is a sequence?
#11
(Jul-11-2024, 12:06 AM)Skaperen Wrote: what will that do if obj is a set? my thinking of a set is that it is iterable but it is not a sequence.
>>> from collections.abc import Iterable, Sequence
>>> isinstance(set(), Iterable)
True
>>> isinstance(set(), Sequence)
False
>>> 
What is a sequence in your view? Is it snippsat's definition or is it the interface of collections.abc.Sequence or do you have your own definition?

Another question is what do you want to do with this? For what purpose do you test if something is a sequence in your code?
« We can solve any problem by introducing an extra level of indirection »
Reply
#12
that is what my thought is for how a set relates to Iterable and Sequence.

the goal involves argument testing in a wrapper script. i also need to test if it is mutable (there go str and bytes).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 4,288 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  How to write test cases for a init function by Unit test in python? binhduonggttn 2 4,207 Feb-24-2020, 12:06 PM
Last Post: Larz60+
  How to write test cases by Unit test for database configuration file? binhduonggttn 0 3,171 Feb-18-2020, 08:03 AM
Last Post: binhduonggttn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020