문제

For example, if I have following code:

#people( sin, name, height,weight,eyecolor, haircolor,addr,gender,birthday )
sin = input("sin ---->")  
gender = input("gender ---->")

I need check whether 'sin' is an integer or say, a 'INT' in oracle data type.

And whether gender is f or m.

How can I do this? Is there any different way from:

while gender != 'f' or gender != 'm':
    gender = input("gender ---->")

The two attributes above will be insert into my database by SQL statement

I am using cx_Oracle

도움이 되었습니까?

해결책

Can you use isinstance()?

isinstance(sin, int) will eval to true or false. isinstance(object_instance, object_type) might work for the other objects you want to evaluate as well.

Your checking of 'f' or 'm' is a bit different since you're comparing data rather than type. Not sure if you can get around that way of checking data.

Hope that helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top