我对这段代码有问题,但不知道为什么...
import inspect
inspect.getsource(min)
Run Code Online (Sandbox Code Playgroud)
错误是:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
inspect.getsource(min)
File "C:\Python33\lib\inspect.py", line 726, in getsource
lines, lnum = getsourcelines(object)
File "C:\Python33\lib\inspect.py", line 715, in getsourcelines
lines, lnum = findsource(object)
File "C:\Python33\lib\inspect.py", line 551, in findsource
file = getfile(object)
File "C:\Python33\lib\inspect.py", line 435, in getfile
'function, traceback, frame, or code object'.format(object))
TypeError: <built-in function min> is not a module, class, method, function, traceback, frame,or code object
Run Code Online (Sandbox Code Playgroud) 这是一个程序,找到一个字符串中最长的单词,但我有一个问题.编译器说我不能比较一个指向整数的指针!但我比较一个字符串指针的char指针
#include <string.h>
#include <string>
#include <iostream>
using namespace std;
string longest(char * a)
{
int count=0;
int finalcount=0;
string longs="";
string longest;
int lena=strlen(a);
for(int i=0;i<lena;i++)
{
if(*a==" ")
{
if(count>=finalcount)
{
finalcount=count;
longest=longs;
}
count=0;
longs="";
}
else{*a++;count++;longs+=*a;}
}
return longest;
}
int main()
{
char a[]="which is the longest";
cout<<longest(a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)