我在我的系统上安装了一个python模块,我希望能够看到它中有哪些函数/类/方法.
我想在每一个上调用doc函数.在ruby中,我可以执行类似ClassName.methods的操作,以获取该类上可用的所有方法的列表.python中有类似的东西吗?
例如.就像是:
from somemodule import foo
print foo.methods # or whatever is the correct method to call
Run Code Online (Sandbox Code Playgroud) 在初始连接后与postgres交互时,是否可以更改用户正在使用的postgresql角色?
数据库将在Web应用程序中使用,我希望对具有连接池的表和模式使用数据库级规则.从阅读postgresql文档看来,如果我最初作为具有超级用户角色的用户连接,我可以切换角色,但我更愿意最初以具有最小权限的用户连接并根据需要进行切换.切换时必须指定用户的密码才行(实际上我更喜欢它).
我错过了什么?
更新:我已经尝试了两个SET ROLE并且SET SESSION AUTHORIZATION按照@Milen的建议但是如果用户不是超级用户,那么两个命令似乎都不起作用:
$ psql -U test
psql (8.4.4)
Type "help" for help.
test=> \du test
List of roles
Role name | Attributes | Member of
-----------+------------+----------------
test | | {connect_only}
test=> \du test2
List of roles
Role name | Attributes | Member of
-----------+------------+----------------
test2 | | {connect_only}
test=> set role test2;
ERROR: permission denied to set role "test2"
test=> \q
Run Code Online (Sandbox Code Playgroud) 在php中声明属性时,为什么不能将属性初始化为函数?以下snippit导致Parse错误:语法错误,意外T_FUNCTION
<?php
class AssignAnonFunction {
private $someFunc = function() {
echo "Will Not work";
};
}
?>
Run Code Online (Sandbox Code Playgroud)
您可以将属性初始化为字符串,数字或其他数据类型吗?
编辑:
但我可以在__construct()方法中为属性分配一个函数.以下工作:
<?php
class AssignAnonFunctionInConstructor {
private $someFunc;
public function __construct() {
$this->someFunc = function() {
echo "Does Work";
};
}
}
?>
Run Code Online (Sandbox Code Playgroud) 我有一个数据库表,其中包含部分邮政编码.我正在尝试编写一个查询,该查询将采用邮政编码,并在表中找到与该代码匹配的行尽可能接近.在下面的示例中,邮政编码为"A1A B2E"的Gold客户将匹配第一行,而具有相同邮政编码的青铜客户将匹配第三行
CUST_TYPE | POST_CODE | SHIPPING_SURCHARGE
------------------------------------------
Gold | A1A | 0.99
Gold | A2A | 1.01
Gold | A | 3.00
Bronze | A | 1.05
Silver | A | 1.02
Bronze | B | 1.07
Run Code Online (Sandbox Code Playgroud)
在所有情况下,查询都将通过CUST_TYPE和POST_CODE列进行查询.我希望查询只返回包含与邮政编码最匹配的一行的单行.所以,如果我查询Gold和'A1AB2B',我希望返回第一行(Gold,A1A,0.99),而不是第一行和第三行
inspect ×1
module ×1
oracle ×1
php ×1
postgresql ×1
python ×1
reflection ×1
sql ×1
sql-server ×1