python读取sql文件-python读取sql文件python函数每日一讲 - dir()函数

dir()函数

中文说明:

你可以使用内建的dir函数来列出模块定义的标识符。标识符有函数、类和变量。

当你为dir()提供一个模块名的时候,它返回模块定义的名称列表。如果不提供参数,它返回当前模块中定义的名称列表。

首先,我们来看一下在输入的sys模块上使用dir。我们看到它包含一个庞大的属性列表。

接下来,我们不给dir函数传递参数而使用它——默认地,它返回当前模块的属性列表。注意,输入的模块同样是列表的一部分。

为了观察dir的作用,我们定义一个新的变量a并且给它赋一个值,然后检验dir,我们观察到在列表中增加了以上相同的值。我们使用del语句删除当前模块中的变量/属性,这个变化再一次反映在dir的输出中。

关于del的一点注释——这个语句在运行后被用来 删除 一个变量/名称。在这个例子中,del a,你将无法再使用变量a——它就好像从来没有存在过一样。

‍‍版本:

各版本中都支持该函数,python3中仍可用。

代码示例:>>> import struct

>>> dir()   # show the names in the module namespace

["__builtins__", "__doc__", "__name__", "struct"]

>>> dir(struct)   # show the names in the struct module

["Struct", "__builtins__", "__doc__", "__file__", "__name__",

"__package__", "_clearcache", "calcsize", "error", "pack", "pack_into",

"unpack", "unpack_from"]

>>> class Shape(object):

def __dir__(self):

return ["area", "perimeter", "location"]

>>> s = Shape()

>>> dir(s)

["area", "perimeter", "location"]

002pc.com认为此文章对《python读取sql文件python函数每日一讲 - dir()函数》说的很在理,第二电脑网为你提供最佳的Python基础教程,python教程。

英文说明:

dir([object])

Without arguments, return the list of names in the current local scope. With an argument, attempt to return a list of valid attributes for that object.

If the object has a method named __dir__(), this method will be called and must return the list of attributes. This allows objects that implement a custom __getattr__() or __getattribute__() function to customize the way dir() reports their attributes.

If the object does not provide __dir__(), the function tries its best to gather information from the object’s __dict__ attribute, if defined, and from its type object. The resulting list is not necessarily complete, and may be inaccurate when the object has a custom __getattr__().

The default dir() mechanism behaves differently with different types of objects, as it attempts to produce the most relevant, rather than complete, information:

If the object is a module object, the list contains the names of the module’s attributes.

If the object is a type or class object, the list contains the names of its attributes, and recursively of the attributes of its bases.

Otherwise, the list contains the object’s attributes’ names, the names of its class’s attributes, and recursively of the attributes of its class’s base classes.

更多:python读取sql文件python函数每日一讲 - dir()函数

https://www.002pc.comhttps://www.002pc.com/python/3628.html

你可能感兴趣的函数,python,dir,一讲,每日

org.apache.subversion.javahl.ClientException: Attempted to lock an already-locked dir

1、错误描述org.apache.subversion.javahl.ClientException: Attempted to lock an already-locked dir

svn: Commit

数据库读写分离mysqlMySQL函数一览_MySQL函数全部汇总

前言MySQL提供了众多功能强大、方便易用的函数,使用这些函数,可以极大地提高用户对于数据库的管理效率,从而更加灵活地满足不同用户的需求。本文将MySQL的函数分类并汇总,以便以

php执行效率扩展php构造函数实例讲解

PHP官网定义:复制代码 代码如下:构造函数是类中的一个特殊函数,当使用 new 操作符创建一个类的实例时,构造函数将会自动调用。当函数与类同名时,这个函数将成为构造函数。如果一

cxml phpPHP构造函数与析构函数用法示例

本文实例讲述了PHP构造函数与析构函数用法。分享给大家供大家参考,具体如下:

在实例化一个新对象时,构造方法和析构方法都会被自动调用,若有继承则会使用父类的对应方法。

析构

php oa系统开发教程PHP匿名函数可以干什么用

匿名函数(Anonymous functions),也叫闭包函数(closures),允许临时创建一个没有指定名称的函数。

mysql 读写分离配置MySQL日期函数与日期转换格式化函数大全

Mysql作为一款开元的免费关系型数据库,用户基础非常庞大,本文列出了MYSQL常用日期函数与日期转换格式化函数

1、DAYOFWEEK(date)

SELECT DAYOFWEEK("2016

mysql 查出数据一对多python使用unittest测试接口步奏详解

这次给大家带来python使用unittest测试接口步奏详解,python使用unittest测试接口的注意事项有哪些,下面就是实战案例,一起来看一下。

mysql 两个结果集相加函数日期mysql获取当天日期

题记:写这篇博客要主是加深自己对函数日期的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢。mysql 中可以应用每日一道理 002pc.com认为此文章对《mysql 两

js文件显示在一行怎么格式化显示javascript AutoScroller 函数类

002pc.com从javascript AutoScroller 函数类分析来看,对javascript AutoScroller 函数类的结果。

0踩

0 赞

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值