小编won*_*der的帖子

Postgres:创建角色并使用 psql -U 角色登录

代码:

postgres=# create role hello;
CREATE ROLE
postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 hello     | Cannot login                                   | {}
 postgres  | Superuser, Create role, Create DB, Replication | {}

postgres=# ALTER ROLE hello WITH LOGIN;
ALTER ROLE
postgres=# ALTER ROLE hello WITH CREATEDB;
ALTER ROLE
postgres=# \du
                             List of roles
 Role name |                   Attributes                   | Member of
-----------+------------------------------------------------+-----------
 hello     | Create DB                                      | {}
 postgres  | Superuser, Create role, Create DB, Replication | …
Run Code Online (Sandbox Code Playgroud)

postgresql

6
推荐指数
1
解决办法
1万
查看次数

Python Scapy vs dpkt

我试图Scapy从一开始就使用Python来分析数据包.在最近的搜索中,我发现python中有另一个名为的模块dpkt.使用此模块,我可以解析数据包的各个层,创建数据包,读取.pcap文件并写入.pcap文件.我发现他们之间的区别是:

  1. 缺少实时数据包嗅探器 dpkt

  2. 某些字段需要使用struct.unpackin 解压缩dpkt.

我还缺少其他差异吗?

python scapy dpkt

3
推荐指数
1
解决办法
3927
查看次数

Python unittest继承setUp覆盖

import unittest

class A(unittest.TestCase):
    def setUp(self):
        print "Hi it's you",self._testMethodName

    def test_one(self):
        self.assertEqual(5,5)

    def tearDown(self):
        print "Bye it's you", self._testMethodName

class B(A,unittest.TestCase): 

    def setUp(self):
        print "Hi it's me", self._testMethodName

    def test_two(self):
        self.assertNotEqual(5,5)


unittest.main()
Run Code Online (Sandbox Code Playgroud)

输出 :

Hi it's you test_one
Bye it's you test_one
.Hi it's me test_one
Bye it's you test_one
.Hi it's me test_two
FBye it's you test_two

======================================================================
FAIL: test_two (__main__.B)
----------------------------------------------------------------------

Traceback (most recent call last):
  File "try_test_generators.py", line 19, in test_two
    self.assertNotEqual(5,5)
AssertionError: 5 == 5 …
Run Code Online (Sandbox Code Playgroud)

python python-unittest

3
推荐指数
1
解决办法
3714
查看次数

Python 触发文件更改事件

我有一组由应用程序创建的 100 个文件。文件不是按顺序动态更新的。使用 Python,我正在尝试读取文件。但是,我不知道哪个文件在什么时间更新。

我不想每次都遍历每个文件来检查实例中更新了哪些文件。我可以创建多个进程/线程来触发文件更新的主进程。有没有其他方式像文件更新可以通知主python进程,以便只读取那些文件??

谢谢。

python-2.7 python-multiprocessing

2
推荐指数
1
解决办法
5686
查看次数

Postgres:在特定数据库中创建函数

代码:

CREATE FUNCTION square_num(num integer)
 RETURNS INTEGER AS $$

BEGIN

 IF (num<0) THEN
 RETURN 0;
 END IF;

 RETURN num*num;

END; $$
LANGUAGE PLPGSQL;
Run Code Online (Sandbox Code Playgroud)

上面的代码在数据库postgres和模式中创建了一个函数public.如何在特定数据库及其架构中创建函数?谢谢.

sql postgresql plpgsql

2
推荐指数
1
解决办法
1462
查看次数