小编sta*_*ion的帖子

Javascript将小写转换为大写

以下htmla和javascript代码有什么问题

formToConvert.html

<html>
    <head>
        <title>ExampleToConvert</title>
        <script type = "text/javascript" src = "con.js"></script>
    </head>
    <body> 
        <form id ="myform">
            <input type = "text" id = "field1" value = "Enter text Here"/><br/>
            <input type ="submit" value = "submit" onclick = "convert()"/>
        </form>
    </body> 
</html>
Run Code Online (Sandbox Code Playgroud)

con.js

function convert() 
{
    var str ;
    str = document.getElementById("field1");
    document.writeln(str.toUpperCase());
}
Run Code Online (Sandbox Code Playgroud)

为什么上面的代码没有给我想要的结果呢?

html javascript

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

如何删除mongodb中列表中的重复值

我有一个mongodb系列.当我做.

db.bill.find({})
Run Code Online (Sandbox Code Playgroud)

我明白了

{ 
    "_id" : ObjectId("55695ea145e8a960bef8b87a"),
    "name" : "ABC. Net", 
    "code" : "1-98tfv",
    "abbreviation" : "ABC",
    "bill_codes" : [  190215,  44124,  190215,  147708 ],
    "customer_name" : "abc"
}
Run Code Online (Sandbox Code Playgroud)

我需要一个操作来从bill_codes中删除重复的值.最后它应该是

{ 
    "_id" : ObjectId("55695ea145e8a960bef8b87a"),
    "name" : "ABC. Net", 
    "code" : "1-98tfv",
    "abbreviation" : "ABC",
    "bill_codes" : [  190215,  44124,  147708 ],
    "customer_name" : "abc"
}
Run Code Online (Sandbox Code Playgroud)

如何在mongodb中实现这一目标.

mongodb pymongo mongodb-query aggregation-framework

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

GCC中的unordered_map错误

这个unordered_map概念是什么时候内置到g ++中的?

因为以下代码引发错误.

#include<iostream>
#include<unordered_map>
#include<stdio.h>

using namespace std;

std::unordered_map<std::int,int> mirror;

mirror['A'] = 'A';
mirror['B'] = '#';
mirror['E'] = 3;

int main(void)
{
    std::cout<<mirror['A'];
    std::cout<<mirror['B'];
    std::cout<<mirror['C'];
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我正在编译代码如下:

g++ -c hashexample.cpp
g++ -o result hashExample.o
./result
Run Code Online (Sandbox Code Playgroud)

我得到的错误是这样的:

inavalid类型int [char [用于aaray下标

有什么办法解决这个问题?

c++ linux gcc

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

为什么在枚举中找不到以下属性?

我使用的是Python 2.7.5,我安装了Enum as

pip install Enum

我已经写出以下代码来测试Enum.

from enum import Enum
class Color(Enum):
  red = 'Hello'
  blue = 'Trello'
  green = 'Yello'

for name, attr in Color.__members__.items():
  print(attr.value)
Run Code Online (Sandbox Code Playgroud)

这引起了我的错误说法.

AttributeError: type object 'Color' has no attribute '__members__'.

为什么python无法获得__members__

python enums

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

如何在Python dict中平均相同键的值

我有以下Python词典列表。

[{"country": "IE", "values": ["Server1-17.6650", "Server3-78.6064", "Server2-3.7286"]}, {"country": "CA", "values": ["Server1-100.0000"]}, {"country": "DE", "values": ["Server2-100.0000"]}, {"country": "JP", "values": ["Server2-100.0000"]}, {"country": "IT", "values": ["Server1-100.0000"]}, {"country": "US", "values": ["Server1-6.3158", "Server3-15.7895", "Server2-77.8947", "Server1-5.5556", "Server3-2.7778", "Server2-91.6667", "Server1-12.6145", "Server3-86.8043", "Server2-0.5811"]}, {"country": "CZ", "values": ["Server1-100.0000"]}, {"country": None, "values": ["Server1-100.0000", "Server2-100.0000", "Server2-100.0000", "Server1-100.0000"]}, {"country": "A", "values": ["Server2-100.0000"]}, {"country": "IL", "values": ["Server1-100.0000"]}, {"country": "BR", "values": ["Server2-100.0000"]}, {"country": "KP", "values": ["Server1-100.0000"]}, {"country": "SG", "values": ["Server1-79.2000", "Server2-20.8000"]}, {"country": "ES", "values": ["Server1-100.0000"]}]
Run Code Online (Sandbox Code Playgroud)

现在,对于values服务器名称在列表中重复的每个服务器名称,我必须对-服务器之后的值求平均值。本质上,对于上面的列表,最终输出变为。

[{"country": "IE", "values": ["Server1-17.6650", …
Run Code Online (Sandbox Code Playgroud)

python dictionary data-structures

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

区分覆盖和重载

我在python中有两个类

  1. 通常醉酒

通常的drunk类继承自drunk,并为其move方法提供了一个新的实现,如下所示

class Drunk:
    def __init__(self,name):
        self.name = name

    def move(self,field,cp,dist=1):
        if field.getDrunk().name!= self.name:
            raise ValueError('Drunk not in the field!')
        for i in range(dist):   
            #pt = CompassPt(random.choice(CompassPt.possibles))
            field.move(cp,1)


class UsualDrunk(Drunk):
    def move(self,field,dist=1):
        cp = random.choice(CompassPt.possibles)
        Drunk.move(self,field,CompassPt(cp),dist)
Run Code Online (Sandbox Code Playgroud)

现在通常的醉酒类有两个名为move但具有不同参数的方法.

那么在这种情况下它是覆盖还是超载?

python

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

C前处理问题

我有一个程序来查找数字的倒数,但主程序是用C语言编写的,reciprocal函数是用c ++编写的.接下来我有一个头文件reciprocal.hpp,它有一些条件编译代码,使reciprocal函数成为一个extern函数.Can有人请解释一下reciprocal.hpp程序中有什么.

main.c中

#include<stdio.h>
#include<stdlib.h>

int main(int argc,char **argv)
{
int i;
i = atoi(argv[1]);
printf("\nThe reciprocal of %d is %f\n",i,reciprocal(i));
return 0;
}
Run Code Online (Sandbox Code Playgroud)

reciprocal.cpp

#include<cassert>
#include "reciprocal.hpp"

double reciprocal(int i)
{
assert( i != 0);
return 1.0/i;
}
Run Code Online (Sandbox Code Playgroud)

reciprocal.hpp

#ifdef __cplusplus
extern "C"
{
#endif

extern double reciprocal(int i);

#ifdef __cplusplus
}
#endif
Run Code Online (Sandbox Code Playgroud)

我不明白发生了什么reciprocal.hpp.请帮助!!

c++

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

如何在java中从用户读取数组?

什么是以下C代码的Java等价物.

for(i = 0;i<n;i++)
scanf("%d",&a[i])

其中i是先前定义的整数,a是一个数组

java

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

Junit测试用例不能按预期工作

我有以下jUnit测试用例来测试取幂

@Test
public void testExponentiation() {
    AssertSame("Not valid!",32.0,this.myObject.expo(2,5))
}
Run Code Online (Sandbox Code Playgroud)

我的世博会功能是

public double expo(int n1,int n2) {
    return Math.pow(n1,n2);
}
Run Code Online (Sandbox Code Playgroud)

这不能按预期工作,但AssertSame适用于Integer原始类型.可以解释为什么?

java junit

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

从数组中获取逗号分隔的字符串

我在JS中有以下JSON.

{
   "url":"http://example.com/main.aspx",
   "report_template_id":"1",
   "interval_secs":"86400",
   "analysis_type":"lite",
   "email":"rokumar@example.com",
   "alerts":["num_domains", "med_load_time", "avg_load_time", "tot_req"]
}
Run Code Online (Sandbox Code Playgroud)

我希望删除警报列表并用逗号分隔值替换,如下所示.

{
   "url":"http://example.com/main.aspx",
    "report_template_id":"1",
    "interval_secs":"86400",
    "analysis_type":"lite",
    "email":"rokumar@example.com",
    "alerts":"num_domains,med_load_time,avg_load_time,tot_req"
}
Run Code Online (Sandbox Code Playgroud)

javascript jquery json

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