小编kar*_*t18的帖子

python中的random.sample()方法有什么作用?

我用Google搜索了很多但却找不到它.我想知道random.sample()方法的用法以及它给出了什么?什么时候应该使用它和一些示例用法.

python random

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

"预计缩进块"错误?

我无法理解为什么python会出现"预期的缩进块"错误?

""" This module prints all the items within a list"""
def print_lol(the_list):
""" The following for loop iterates over every item in the list and checks whether
the list item is another list or not. in case the list item is another list it recalls the function else it prints the ist item"""

    for each_item in the_list:
        if isinstance(each_item, list):
            print_lol(each_item)
        else:
            print(each_item)
Run Code Online (Sandbox Code Playgroud)

python docstring indentation

19
推荐指数
2
解决办法
22万
查看次数

在python中的文件中写入多行

我有以下代码:

line1 = raw_input("line 1: ")
line2 = raw_input("line 2: ")
line3 = raw_input("line 3: ")
print "I'm going to write these to the file."
target.write(line1)
target.write("\n")
target.write(line2)
target.write("\n")
target.write(line3)
target.write("\n")
Run Code Online (Sandbox Code Playgroud)

这里target是文件对象,line1,line2,line3是用户输入.我想只使用一个target.write()命令来编写这个脚本.我尝试过使用以下内容:

target.write("%s \n %s \n %s \n") % (line1, line2, line3)
Run Code Online (Sandbox Code Playgroud)

但是不是将字符串放在另一个字符串中但是如果我使用以下内容:

target.write(%s "\n" %s "\n" %s "\n") % (line1, line2, line3)
Run Code Online (Sandbox Code Playgroud)

Python解释器(我使用的是Microsoft Powershell)说的语法无效.我怎么能这样做?

python

13
推荐指数
3
解决办法
7万
查看次数

C 中的 if-else if 序列

我使用以下逻辑来测试三角形是等腰、等边、不等边三角形还是直角三角形。

if (side1 == side2 || side2 == side3 || side1 == side3)
    printf("Isosceles triangle.");
else if (side1 == side2 && side2 == side3 && side3 == side1)
    printf("equilateral triangle");
Run Code Online (Sandbox Code Playgroud)

我得到边 3 3 3 的输出为等腰,但不是等边,但是当我交换首先编写等边逻辑的逻辑时,我得到等边。我不明白发生了什么事?

c turbo-c

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

安装numpy时出错

我正在尝试安装numpy我的步骤如下:在numpy提取的文件夹中打开cmd(我提取的.tar.gz文件)然后python setup.py install但是我收到如下错误: 在此输入图像描述 有这样的许多警告,并在最后错误无法找到vcvarsall.bat(我很遗憾地放一张照片,但我找不到更好的方法从cmd窗口复制文本)如果可能的话建议编译设置numpy

python numpy

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

Android:PlaybackOverlayFragment无法正常工作

我正在使用Android TV应用程序,当我开始处理项目代码时,它会引发PlaybackOverlayFragment错误,并指出它无法解析符号PlaybackOverlayFragment

public class PlaybackOverlayFragment extends android.support.v17.leanback.app.PlaybackOverlayFragment
Run Code Online (Sandbox Code Playgroud)

目前在我的gradle文件中显示为:

compile 'com.android.support:leanback-v17:27.1.1'
Run Code Online (Sandbox Code Playgroud)

最初的项目是编译sdk版本26​​,我将其升级到27,是因为它引发错误吗?

android android-tv leanback

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

对于C中的循环格式

我想知道这个程序是如何执行的,并没有抛出任何错误.

void main( ) 
{ 
    clrscr();
    int i ; 
    for ( i = 1 ; i <= 5 ; printf ( "\n%c", 65 ) ) ; 
        i++ ;
    getch(); 
} 
Run Code Online (Sandbox Code Playgroud)

循环继续打印A.for循环的格式是

for(initialize value; test counter; increment value)
{
    do this;
    and this;
    and this;
}
Run Code Online (Sandbox Code Playgroud)

我的问题是printf("\n%c",65)如何增加值?

c for-loop

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

Eclipse Kepler不会自动生成web.xml

我看到了一个教程,根据哪个web.xml在动态Web项目的WEB-INF文件夹中自动创建,它包含了所有的servlet,所有的JSP页面和HTML页面都被自动包含在内.但是,我在项目中找不到任何此类文件.IDE没有在我创建的jsp和servlet中显示任何错误.

当我自己添加web.xml文件时,服务器停止工作.

我正在使用Apache Tomcat 7.我是否遗漏了某些内容或者我没有正确地进行集成?

xml jsp servlets eclipse-wtp tomcat7

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

什么时候超级(Baseclass,self).__ init__使用

何时应该在Python中使用以下代码(假设Baseclass继承自Parent类,而Parent类在__init __()方法中启动了一些变量)

class Baseclass(Parent):
    def __init__(self, some_arg):
        self.some_arg = some_arg
        super(Baseclass, self).__init__()
Run Code Online (Sandbox Code Playgroud)

此代码是否使在Parentclass的__init__方法中定义的所有局部变量都可以在Baseclass中访问?它有什么意义?

python class super

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

malloc()可以用来定义数组的大小吗?

这里考虑以下代码示例:

int *a = malloc(sizeof(int) * n);
Run Code Online (Sandbox Code Playgroud)

这段代码可以用来定义一个包含n个整数的数组吗?

c arrays malloc pointers

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

python:单行三元运算符中列表元素的if-else

当我遇到以下代码时,我正在使用 python 标记化推文的代码。请注意,tokens_reemoticons_re是正则表达式对象。由于tokenize(s)返回一个列表,因此tokens是一个列表。我对 python 有点陌生,我不确定 if-else 是否在 list 的元素上运行。提到的三元运算符没有相同的语法。

def tokenize(s):
    return tokens_re.findall(s)

def preprocess(s, lowercase=False):
    tokens = tokenize(s)
    if lowercase:
        tokens = [token if emoticon_re.search(token) else token.lower() for token in tokens]
    return tokens
Run Code Online (Sandbox Code Playgroud)

python ternary-operator

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

如何在函数内使用while循环?

我决定修改以下while循环并在函数内使用它,以便循环可以取任何值而不是6.

i = 0
numbers = []
while i < 6:
    numbers.append(i)
    i += 1
Run Code Online (Sandbox Code Playgroud)

我创建了以下脚本,以便我可以使用变量(或更具体的参数)而不是6.

def numbers(limit):
    i = 0
    numbers = []

    while i < limit:
        numbers.append(i)
        i = i + 1
    print numbers

user_limit = raw_input("Give me a limit ")      
numbers(user_limit)
Run Code Online (Sandbox Code Playgroud)

当我没有使用它raw_input()并简单地从脚本中放入参数它工作正常但现在当我运行它(在Microsoft Powershell中)时,在询问问题后光标会不断闪烁raw_input().然后我必须按CTRL+ C才能中止它.也许这个功能不会被调用raw_input().

现在它给出了像pic中的内存错误. 在此输入图像描述

python raw-input while-loop

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

如何访问引导网格系统中的某些列?

在 bootstrap 网格系统中,有 12 列, col - *- * 类用于将一定数量的列组合在一起。但是当我想使用前 3 列然后只使用最后一列时,我该怎么做,也就是说,如何在单行类中使用某些列而不是其他列?

就像我制作页眉时,我在左侧给出标题,在页眉右侧给出某些其他文本,我假设我可以在这里有效地使用网格系统,因为我可以访问某些列。

html css frontend twitter-bootstrap

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