小编n0p*_*0pe的帖子

关于"动态"变量的Java快速问题

假设我有一个从配置文件中读取信息的应用程序.让我们说每次在配置文件中遇到单词"Hello"时,我希望能够创建一个String类型的变量并将其命名为Hello0,Hello1,Hello2等等......

我知道这样的动态变量在编程中是不可能的(大部分).但是会有某种解决方法吗?就像让用户决定要拥有多少变量一样?

java variables configuration

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

获取String并从String中表示的类中创建对象

场景:

  • 我有两个名为ListLayout和GridLayout的类,它们都实现了CustomLayout.
  • 用户输入表示他们希望使用的布局的String(例如"ListLayout")

如何根据用户输入的字符串创建ListLayout对象?我需要等同于这样做:

CustomLayout layout = new ListLayout();
Run Code Online (Sandbox Code Playgroud)

理想情况下,我需要找到一个解决方案,它允许我检查输入的String是否对应于在实际创建对象之前实现CustomLayout的预定义类(因为如果它不存在则会抛出错误而我不检查预先).

这真让我思考......提前感谢您的帮助

java string class object instantiation

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

如何让Chrome尊重我的字段名称,而不是尝试自动完成

我的主页上有两种不同的表单:一种用于登录,另一种用于注册.从代码中可以看出,表单具有不同名称的输入:

<h3> Log In </h3>
<form action="/login/" method="POST" class="form-vertical" style="padding-top: 5px">
  <input id="id_login_username" type="text" name="login_username" maxlength="25" />
  <input type="password" name="login_password" id="id_login_password" /><br>
  <button type="submit" class="btn btn-info">Login</button>
</form>

<h3> Sign Up <small>(It's free!)</small></h3>
<form action="/register/" method="POST" class="form-vertical" style="padding-top: 5px">
  <input id="id_register_username" type="text" name="register_username" maxlength="25" />
  <input type="text" name="register_email" id="id_register_email" />
  <input type="password" name="register_password" id="id_register_password" />
  <input type="password" name="register_password2" id="id_register_password2" /><br>
  <button type="submit" class="btn">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)

哪个在Chrome中渲染:

在此输入图像描述

是什么导致这个?我该如何解决?

forms django google-chrome autocomplete

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

Python缩进混淆,使用4个空格选项卡

我有这个小脚本:

filters = []
pipes = []

check_environment()
config()
fix_syslog()
make_fifo()

def check_environment():
    # check python
    # check for syslog
    # check for mknod
    # check for root privileges

def config():
    accepted_filters = ['auth', 'authpriv', 'daemon', 'cron', 'ftp', 'lpr', \
    'kern', 'mail', 'news', 'syslog', 'user', 'uucp', 'local0', 'local1'    \
    'local2', 'local3', 'local4', 'local5', 'local6', 'local7']

    accepted_priorities = ['Emergency', 'Alert', 'Critical', 'Error',       \
    'Warning', 'Notice', 'Info', 'Debug']


    print "Entered configuration mode. Type 'help' for more information"
    loop = true

    while loop: …
Run Code Online (Sandbox Code Playgroud)

python indentation

0
推荐指数
1
解决办法
423
查看次数

将jQuery/HTML缩小是一个好主意吗?

在我的网站上缩小jQuery甚至HTML是一个好主意吗?我怎么能这样做,仍然有一个很好的结构可以使用?

html security obfuscation jquery

0
推荐指数
1
解决办法
1431
查看次数

如果我使用render_to_response,是否需要HttpRequest对象?

Django告诉我,我的登录视图没有返回一个HttpResponse对象:

The view accounts.views.login didn't return an HttpResponse object.
Run Code Online (Sandbox Code Playgroud)

但是,我render_to_response()到处都在使用,如果没有得到回复,视图就无法完成解析.这是代码:

def login(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                if user.is_active:
                    auth_login(request, user)
                    render_to_response('list.html')
                else:
                    error = "It seems your account has been disabled."
                    render_to_response('list.html', {'error': error})
            else:
                error = "Bad login information. Give it another go."
                render_to_response('list.html', {'error': error})
        else:
            error = "Bad login information. Give it another go."
            render_to_response('list.html', …
Run Code Online (Sandbox Code Playgroud)

python authentication django http

0
推荐指数
1
解决办法
118
查看次数

无法删除我的自定义类的堆实例(C++)

这是我得到的:

class MyClass {
    int holder;
public:
    MyClass() {
        holder = 5;
    }
};
Run Code Online (Sandbox Code Playgroud)
template<class T>
class First {
    std::vector<T> items;
public:
    First() {
        T* tmp;
        for (int i = 0; i < 20; i++) {
            tmp = new T();
            items.push_back(*tmp);
        }
    };
    ~First() {
        for (int i = 0; i < 20; i++) {
            delete items.at(i);
        }
    };
};
Run Code Online (Sandbox Code Playgroud)
class Second {
    std::vector<std::deque<First<MyClass>>> items;
public:
    Second() {
        std::deque<First<MyClass>>* tmp;
        for (int i = 0; i < 10; i++) { …
Run Code Online (Sandbox Code Playgroud)

c++ heap templates destructor

0
推荐指数
1
解决办法
2538
查看次数

如果它们不包含静态数据,我是否需要为派生类实现自己的析构函数?

比方说我有:

class Base {
public:
    virtual ~Base() = 0;
}

class Derived: public Base {
public:
    ~Derived();
}
Run Code Online (Sandbox Code Playgroud)

在我的代码中,我需要Derived通过Base指针删除类,如下所示:

delete[] pt_base;
Run Code Online (Sandbox Code Playgroud)

但是,在实现的析构函数中,我实际上没有任何东西可以破坏.但我仍然需要它们通过基类删除?

如果没有大量浪费的代码和空的析构函数,实现我想要的最佳方法是什么?

c++ polymorphism destructor virtual-destructor

0
推荐指数
1
解决办法
858
查看次数

eval()与if() - 是否存在性能差异?

我的问题专门针对Perl,但我希望对大多数语言都有所启发.

使用eval()函数和if()语句之间是否存在实际差异(性能方面和效率方面)?

eval(-e /path/to/file) or die "file doesn't exist";
if (! -e /path/to/file) { die "file doesn't exist"; }
Run Code Online (Sandbox Code Playgroud)

perl performance if-statement eval

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

为什么我可以将65535 + 1转换为C++中的有效int?

我有一个非常简单的程序:

int main()
{
  char* num = new char[5];
  sprintf(num, "65536");
  std::cout << "atoi(num): " << atoi(num) << "\n";
}
Run Code Online (Sandbox Code Playgroud)

无符号INT的最大大小为65535.为什么运行时该程序不会溢出atoi(65536)

c++ integer overflow

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