Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement query in python

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to implement the query in python, which is very detailed and has certain reference value. Friends who are interested must finish reading it!

Query

1) query the parameters of the function

When we want to know which parameters a function will accept, we can use the following method to query.

Import inspectprint (inspect.getargspec (func))

2) query the properties of objects

In addition to using dir () to query the properties of an object, we can use the following built-in (built-in) function to confirm whether an object has a property:

Hasattr (obj, attr_name) # attr_name is a string

For example:

A = [1, 2, 3] print (hasattr (a)

2) query the class and class name to which the object belongs

A = [1, 2, 3] print a.__class__print a.classic classrooms. Naming names _

3) query parent class

We can use the _ _ base__ attribute to query the parent class of a class:

Cls.__base__

For example:

Print (list.__base__) above is all the contents of the article "how to query in python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report