小编Sox*_*arm的帖子

'module'对象不可调用 - 在另一个文件中调用方法

我有一个公平的java背景,试图学习python.我遇到了一个问题,了解如何在不同的文件中访问其他类的方法.我一直在获取模块对象不可调用.

我做了一个简单的函数来查找一个文件中列表中的最大和最小整数,并希望在另一个文件中的另一个类中访问这些函数.

任何帮助表示赞赏,谢谢.

class findTheRange():

    def findLargest(self, _list):
        candidate = _list[0]
        for i in _list:
            if i > candidate:
                candidate = i
        return candidate

    def findSmallest(self, _list):
        candidate = _list[0]
        for i in _list:
            if i < candidate:
                candidate = i
        return candidate
Run Code Online (Sandbox Code Playgroud)
 import random
 import findTheRange

 class Driver():
      numberOne = random.randint(0, 100)
      numberTwo = random.randint(0,100)
      numberThree = random.randint(0,100)
      numberFour = random.randint(0,100)
      numberFive = random.randint(0,100)
      randomList = [numberOne, numberTwo, numberThree, numberFour, numberFive]
      operator = findTheRange()
      largestInList = findTheRange.findLargest(operator, randomList)
      smallestInList …
Run Code Online (Sandbox Code Playgroud)

python import module

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

C++ cout操作数错误,输入错误ostream,string

我只是在学习c ++的基础知识,而且我在使用cout时遇到了一些问题.我写了一些简单的测试来打印hello world,一个简单的加法器函数,以及一个翻转字符串顺序的函数.一切都运行良好,除了我的字符串函数,给出了我的错误.我会喜欢解释,谢谢.

错误:没有运算符"<<"匹配这些操作数,操作数类型是std:ostream << std:string

#include <iostream>

using namespace std;

int adder(int a, int b)
{
    return a + b;
}

int addOneToInput(int a)
{
return a + 1;
}

string flipStringOrder(string s)
{
string temp = "";
for (int i = 0; i < s.length; i ++)
{
    char charTemp = (s.at(s.length() - i -1));
    temp += charTemp;
}
return temp;
}


void main(){
cout << "Hello World" << endl;
int x = 5;
int y = 3; …
Run Code Online (Sandbox Code Playgroud)

c++ types cout

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

c ++从另一个文件访问函数

我正在学习c ++,并且在如何与不同的文件和/或类共享方法时遇到一些麻烦.

如果我创建一个名为increment(int a)的函数{a ++; 返回;}

并在a.cpp中定义如何在main.cpp中调用它?任何帮助表示赞赏,谢谢.

c++ private public sharing

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

c ++简单的增量程序无法正确打印?什么?

我过去几天一直在学习c ++,我开始遇到这个简单的问题,我的控制台无法正确打印,前几天我让它使用更复杂的程序,现在我甚至无法让它工作,请帮忙吗?

#include <iostream>

using namespace std;

int main()
{
    int variable = 1;
    cout << "hello world" << endl;
    cout << variable << endl;
    variable = increment(variable);
    cout << variable << endl;
    system("pause");
}

int increment(int a)
{
    a++;
    return a;
}
Run Code Online (Sandbox Code Playgroud)

当我运行该程序时,控制台打印

"你好,世界"

1

"按任意按钮继续"

为什么不修改变量打印?我已经尝试了一些设置,似乎在变量打印一次之后它将无法再次打印,这里发生了什么?

c++ cout

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

标签 统计

c++ ×3

cout ×2

import ×1

module ×1

private ×1

public ×1

python ×1

sharing ×1

types ×1