如果给出类名和方法名,我怎样才能在静态类上调用方法呢?
例如:
鉴于System.Environment和GetFolderPath,我想Reflection用来打电话Environment.GetFolderPath().
我试图使用Python和pywin32从安全组中删除用户,但到目前为止还没有成功.但是,我可以将用户添加到安全组.
from win32com.client import GetObject
grp = GetObject("LDAP://CN=groupname,OU=groups,DC=blah,DC=local")
grp.Add("LDAP://CN=username,OU=users,DC=blah,DC=local") # successfully adds a user to the group
grp.Remove("LDAP://CN=username,OU=users,DC=blah,DC=local") # returns an error
Run Code Online (Sandbox Code Playgroud)
错误如下:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<COMObject LDAP://CN=groupname,OU=groups,DC=blah,DC=local>", line 2, in Remove
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None,
0, -2147024891), None)
Run Code Online (Sandbox Code Playgroud)
我也尝试使用GetObject添加来获取用户并以这种方式删除它,但是我得到了同样的错误.
usr = GetObject("LDAP://CN=user,OU=users,DC=blah,DC=local")
grp.Remove(usr)
Run Code Online (Sandbox Code Playgroud)
任何帮助都会非常感激,因为我在这里遇到了死胡同.
编辑
我现在也尝试使用Tim Golden的active_directory模块来尝试删除组成员.
import active_directory as ad
grp = ad.find_group("groupname")
usr = ad.find_user("username")
grp.remove(usr.path())
Run Code Online (Sandbox Code Playgroud)
但是这也行不通,我遇到了以下错误.
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\active_directory.py", …Run Code Online (Sandbox Code Playgroud) 在shell中输入以下内容时,我在Mongo DB中收到上述错误,但是我一生都看不到语法错误...
db.createUser (
... "user":"dbTest",
... "pwd":"testPass",
... "roles": [
... { "role":"readWrite", "db":"test" }
... ]
... )
Run Code Online (Sandbox Code Playgroud)
该文件已直接从控制台复制并粘贴。
我正在尝试使用$or使用MongoDB的PHP驱动程序的运算符进行查询,但是出现以下错误:
Fatal error: Uncaught MongoDB\Driver\Exception\ConnectionException: $or
must be an array in /path/to/file.php:83 Stack trace: #0 /path/to/file.php(83):
MongoDB\Driver\Manager->executeQuery('userAccou...',
Object(MongoDB\Driver\Query)) #1 {main} thrown in /path/to/file.php on line 83
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
postSub = $_POST['register']['subdomain'];
$postEmail = $_POST['register']['email'];
$filter = ['$or' => ['subdomain' => $postSub, 'email' => $postEmail]];
$query = new MongoDB\Driver\Query($filter);
$cursor = $mongo->executeQuery('DB_Name.Collection_Name', $query);
Run Code Online (Sandbox Code Playgroud) 我有一个视图,它有一个复杂的 CASE 语句来确定其中一列的值。
SELECT a.itemcode, count(*) total, b.foo
CASE
WHEN foo IN ('aab', 'aac')
THEN 1
WHEN foo IN ('qqq', 'fff')
THEN 2
WHEN foo IN ('foo', 'bar')
THEN 10 % count(*)
ELSE 9 % count(*)
END AS other_total
FROM a INNER JOIN b ON a.itemcode = b.itemcode
GROUP BY itemcode, foo
Run Code Online (Sandbox Code Playgroud)
我想添加一个检查 other_total 列的值。如果是0,我想将该值设置为1.
显然我可以用一个CASE声明来概括整个事情......
CASE ( CASE
WHEN foo IN ('aab', 'aac')
THEN 1
WHEN foo IN ('qqq', 'fff')
THEN 2
WHEN …Run Code Online (Sandbox Code Playgroud) 我想根据主字典中的属性中是否存在任何字符串数组将字典分成两部分。目前,我可以通过两个单独的字典理解(如下)来实现此目的,但是是否有一种更有效的方法可以仅通过一行/字典理解来实现此目的?
included = {k:v for k,v in users.items() if not any(x.lower() in v["name"].lower() for x in EXCLUDED_USERS)}
excluded = {k:v for k,v in users.items() if any(x.lower() in v["name"].lower() for x in EXCLUDED_USERS)}
Run Code Online (Sandbox Code Playgroud)
编辑
EXCLUDED_USERS包含模式列表。
我有一个为uni做的任务,需要让用户使用方向键来控制游戏.
到目前为止,我有以下内容,但这不起作用.我有什么明显的遗失吗?
// key bindings
// add the key bindings for up, down, left and right to the input map
gamePanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0), "down");
gamePanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,0), "up");
gamePanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT,0), "left");
gamePanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT,0), "right");
// assign actions to the key bindings in the action map
gamePanel.getActionMap().put("down", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
move("DOWN");
}
});
gamePanel.getActionMap().put("up", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
move("UP");
}
});
gamePanel.getActionMap().put("left", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
move("LEFT");
}
});
gamePanel.getActionMap().put("right", new AbstractAction()
{
public …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 FTPS 将文件上传到 FTP 站点,但是当我尝试存储文件时,它只是在文件完全传输后挂起。
global f_blocksize
global total_size
global size_written
f_blocksize = 1024
total_size = os.path.getsize(file_path)
size_written = 0
file = open(file_path, "rb")
try:
ftps = FTP_TLS("ftp.example.com")
ftps.auth()
ftps.sendcmd("USER username")
ftps.sendcmd("PASS password")
ftps.prot_p()
print(ftps.getwelcome())
try:
print("File transfer started...")
ftps.storbinary("STOR myfile.txt", file, callback=handle, blocksize=f_blocksize)
print("File transfer complete!")
except OSError as ex:
print(ftps.getresp())
except Exception as ex:
print("FTP transfer failed.")
print("%s: %s" %(type(ex), str(ex)))
def handle(block):
global size_written
global total_size
global f_blocksize
size_written = size_written + f_blocksize if size_written + f_blocksize …Run Code Online (Sandbox Code Playgroud) 我有以下正则表达式,我将其解释为与仅包含字母数字字符和连字符的字符串匹配的模式。
if (preg_match('/[A-Za-z0-9-]/', $subdomain) === false) {
// valid subdomain
}
Run Code Online (Sandbox Code Playgroud)
问题在于此正则表达式也匹配空格,这在子域名中显然是不可取的。
对于奖励积分,这是验证子域名的合适方法吗?我不确定允许使用哪些特殊字符,但我想我只允许使用连字符就可以使其简单。还有什么我需要检查的吗?例如最大长度?
如果我有两个清单
a = [2,5,1,9]
b = [4,9,5,10]
Run Code Online (Sandbox Code Playgroud)
如何找到每个元素的平均值,以便结果列表为:
[3,7,3,9.5]
Run Code Online (Sandbox Code Playgroud) python ×4
mongodb ×2
php ×2
c# ×1
dictionary ×1
ftp ×1
ftplib ×1
ftps ×1
java ×1
key-bindings ×1
python-2.7 ×1
pywin32 ×1
reflection ×1
regex ×1
sql ×1
sql-server ×1
ssl ×1
subdomain ×1
swing ×1
t-sql ×1