简体   繁体   中英

Generate a table subset with a list

I have a set of subjects in a table, and I want delete a subset (eg, subject1 and subject2). Is there a way to fetch a subset using a list? Or do I need to have an attribute I can use to select the subset?

subject.Subject()

# *subject      sex    
# +----------+ +-----+
# subject1     F      
# subject2     M      
# subject3     M      
# subject4     M      

(subject.Subject & "subject=subject1").delete() # Delete individually 1
(subject.Subject & "subject=subject2").delete() # Delete individually 2

(subject.Subject & "sex='M'").delete() # Delete by attribute

(subject.Subject & "subject IN ('subject1','subject2')").delete() # pseudocode, by list

for s in ['1', '2']: # not ideal
    (subject.Subject & f'subject=\"subject{s}\"').delete(safemode=False) 

I now consider the following the most efficient:

(subject.Subject & "subject in ('subject1', 'subject2')").delete()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM