是否可以在像Ramaze这样的Web框架中使用ActionMailer,还是需要使用Rails?
在列出 Active Directory 中的所有用户时,我遇到了一些困难。我到达了该组,但不幸的是,我无法检索到所有用户。我正在寻找用户全名、用户名、董事会。我的代码是:
package client;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import javax.naming.ldap.LdapContext;
import javax.naming.ldap.*;
import java.util.Enumeration;
import javax.naming.NamingEnumeration;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import javax.naming.directory.*;
public class AD1 {
public AD1() {
super();
}
public static String usersContainer = "cn=XX,ou=XX,ou=Groups,dc=XX,dc=XX,dc=XXX";
public static void main(String[] args) {
try {
LdapContext ctx = null;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.SECURITY_AUTHENTICATION, "Simple");
//it can be <domain\\userid> something that you use for windows login
//it …Run Code Online (Sandbox Code Playgroud) import java.io.IOException;
import java.util.Scanner;
public class Chapter_3_Self_Test {
public static void main (String args []) throws IOException {
Scanner sc = new Scanner (System.in);
char a;
for (int counter = 0; a == '.'; counter++) {
a = (char) System.in.read();
}
System.out.println(counter);
}
}
Run Code Online (Sandbox Code Playgroud)
我是Java的初学者.当我运行此代码时,我收到错误消息,计数器无法解析为变量.我该如何解决?我尝试将计数器转换为字符串,但这没有做任何事情.
我无法在我的 CSS 中覆盖父级的宽度。本质上,我有一个父级和一个子级 div,例如:
.parent{ width: 768px; background-color: red; }
.child{ background-color:blue; }Run Code Online (Sandbox Code Playgroud)
<div class="parent">
<div class="child">
//content
</div>
</div>Run Code Online (Sandbox Code Playgroud)
很多元素仍然使用 768px 宽度的 parent 参数,但是我希望这个特定的子元素扩展屏幕的整个宽度 - 我尝试过 left: 0, right: 0,清除浮动并将宽度设置为汽车。如果可以,我也想避免使用 !important。
有什么建议 ?
我想要的准确表示如下所示:
_____
|par. |
_|_____|_
| child |
| |
|_________|
| |
|_____|
Run Code Online (Sandbox Code Playgroud) 算法问题:
假设我想确定一个值是否在十几倍的范围内(例如2) - 所以,8-12,18-22,28-32等.
我目前的解决方案是将范围添加到值,mod乘以10,然后重新减去范围 - 从而留下-2到8的东西 - 然后检查绝对值是否小于所需范围.
value = 38
range = 2
cycle = 10
tweaked_mod = ((value + range) % cycle) - range
# tweaked_mod = -2
within_range = (abs(tweaked_mod) <= range)
# within_range = True
Run Code Online (Sandbox Code Playgroud)
与:
value = 37
range = 2
cycle = 10
tweaked_mod = ((value + range) % cycle) - range
# tweaked_mod = 7
within_range = (abs(tweaked_mod) <= range)
# within_range = False
Run Code Online (Sandbox Code Playgroud)
它有效,但很尴尬.
我在这里错过了一个更直观/简洁的算法吗?
I knew that python's __getattr__ is triggered when visiting a non-existing attribute.
但是在下面的示例中,在 c1's 中__init__,我创建了一个名为 name 的 self 属性。访问它时,两种访问方式都触发__getattr__并因此打印“无”。
这对我来说很奇怪。我想我的理解或我的代码有问题吗?
$ cat n.py
class c1(object):
def __init__(s):
print 'init c1'
s.name='abc'
def __getattr__(s,name):
print "__getattr__:"+name
return None
def __setattr__(s,name,value):
print "__setattr__:"+value
def __get__(s,inst,owner):
print "__get__"
class d:
def __init__(s):
s.c=c1()
c=c1()
print c.name
o=d()
print o.c.name
$ python n.py
init c1
__setattr__:abc
__getattr__:name
None
init c1
__setattr__:abc
__getattr__:name
None
Run Code Online (Sandbox Code Playgroud)
你可以看到我已经s.name='abc'在里面定义了__init__,但是在调用它时无法识别。