Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Spyder在使用正确数量的参数从另一个包/模块调用方法时引发错误_Python_Spyder - Fatal编程技术网

Python Spyder在使用正确数量的参数从另一个包/模块调用方法时引发错误

Python Spyder在使用正确数量的参数从另一个包/模块调用方法时引发错误,python,spyder,Python,Spyder,当前每次我尝试运行此命令时: start_1 = Random.randint(0, 25) 我得到: TypeError: randint() missing 1 required positional argument: 'b' 但是定义和代码完成仅表明两个参数。是的,我是随机输入的 按照要求,整个代码: # -*- coding: utf-8 -*- """ Created on Fri May 19 22:01:54 2017 @author: """ from r

当前每次我尝试运行此命令时:

       start_1 = Random.randint(0, 25)
我得到:

TypeError: randint() missing 1 required positional argument: 'b'
但是定义和代码完成仅表明两个参数。是的,我是随机输入的

按照要求,整个代码:

# -*- coding: utf-8 -*-
"""
Created on Fri May 19 22:01:54 2017

@author: 
"""
from random import Random

Random.randint(0, 25)

这是整个计划吗?如果不是,你能给我们整个计划吗?另外,试着做:
start_1=random.randint(randint(0,25))

您应该只导入
random

import random

print(random.randint(1,20))

Random
with capital
R
是类-因此您需要实例化它:

当然,最后两行可以替换为

Random().randint(0, 25)             # creating object of class Random just for this purpose
为什么
…在(不正确的)使用中缺少位置参数:“b”

函数
randint()
在类
Random
中以标准方式定义为

def randint(self, a, b):
因此它需要
3
参数,而您只提供了
2

(参数
self
是一个特殊(隐藏)参数-在正确使用的情况下,它将被调用对象本身自动替换)

更舒适的可能性是

import random
random.randint(0, 25)

as
randint
random
模块中定义为

randint = Random().randint          # Create temporary object and get its method

在我自己的计算机上尝试此操作时,我没有任何问题,您能否发布更多详细信息/代码以进一步诊断此问题?显示完整代码和完整错误回溯,否则我们将一直处于黑暗状态。我已提供了完整的代码。只需说
import random
,然后像这样继续
random.randint(0,25)
谢谢,请参阅修正案。此外,如果这不起作用,我认为您导入了错误的内容。据我记忆所及,我认为这是随机导入的randint。非常感谢。这似乎奏效了。我不明白为什么第二次随机提供是可用的。当我查看源代码时,该方法使用了两个参数(当然还有自参数)。如果不是的话,它应该工作得很好。我对python非常陌生(显然;)。我假设一个类的所有方法在python中都是静态的——spyder为我提供了“Random”上的代码完成。当我使用了OP实现之前,它已经在C和C++中,所以使用起来更容易——IDE通常可以清楚地知道什么是静态方法。
from random import randint
randint(0, 25)
randint = Random().randint          # Create temporary object and get its method