使用Python 2.5.2(r252:60911,2008年9月30日,15:42:03)我尝试使用
type(x)
Run Code Online (Sandbox Code Playgroud)
传入此字符串'2014-02-06 00:00:00'时收到以下错误
TypeError:'str'对象不可调用
为什么它不返回str?
c ++中的以下结构是否可行且推荐?
class IColour{}
class Grey: public IColour {}
class DarkGrey: public IColour {}
class IMaterial {}
class Rock: public Material, public Grey {}
class Basalt : public Rock, public DarkGrey {}
Run Code Online (Sandbox Code Playgroud)
有没有办法覆盖派生类中基类的继承?也就是说,是否有可能在玄武岩中用DarkGrey覆盖Gray的继承?
我隐约记得python允许类似的东西
def foo( x ):
....
f = foo( 5 )
Run Code Online (Sandbox Code Playgroud)
在c ++中是这样的,所以如果我有一个成员函数
class C {
void foo( int x ) { ... }
so that I can define a pointer or variable that would effectively point at foo( 5 )
Run Code Online (Sandbox Code Playgroud)
我想这样做的原因是因为我有很多听众需要订阅回调并保留被调用的信息
class C {
map<int, ptrSender> m_sender;
void subscribe() {
for (const auto& p : m_sender) {
p .second->register( Callback( this, &C::onCall ) )
}
Run Code Online (Sandbox Code Playgroud)
我的问题是onCall没有返回哪个发送回叫,但我需要这些信息.所以,而不是做这样的事情
void subscribe() {
m_sender[0]->register( Callback( this, onCall_0 ) );
m_sender[1]->register( Callback( this, onCall_1 …Run Code Online (Sandbox Code Playgroud) 假设我有一个字典
d:flip(100 200 400 800 1600; 1 3 4 6 10)
Run Code Online (Sandbox Code Playgroud)
如何创建一个返回大于x的最小键值的查找函数?给出一张桌子
tbl:flip `sym`val!(`a`b`c`d; 50 280 1200 1800)
Run Code Online (Sandbox Code Playgroud)
我想做点什么
{[x] : update new:fun[x[`val]] from x} each tbl
Run Code Online (Sandbox Code Playgroud)
最终在这样的桌子
tbl:flip `sym`val`new!(`a`b`c`d; 50 280 1200 1800; 1 4 10 0N)
sym val new
a 50 1
b 280 4
c 1200 10
d 1800
Run Code Online (Sandbox Code Playgroud) def parseCommand():
args = None
if len (sys.argv) < 2:
print('no command entered')
return
command = sys.argv[1]
print ('command executed: %s' %command)
if len(sys.argv) == 3:
args = sys.argv[2]
if len(sys.argv) > 3:
args = sys.argv[2:]
commandList = {
'fA' : fA(),
'fB' : fB(),
}
if args == None:
return commandList[command]
else:
return commandList[command](args)
if __name__ == "__main__":
parseCommand()
Run Code Online (Sandbox Code Playgroud)
我从linux运行这个脚本.但是,当我运行python scriptname.py fA或python scriptname.py fB时,脚本似乎只是从上到下运行,执行这两个函数当我将其更改为
if __name__ == "__main__":
fA()
Run Code Online (Sandbox Code Playgroud)
要么
if __name__ == "__main__":
fB()
Run Code Online (Sandbox Code Playgroud)
并运行python scriptname.py frtom linux它只执行我调用的函数. …
我在这里找到了一个建议,通过自我更新批量类属性.dict .upadte所以我试过了
class test(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def update(self, **kwargs):
self.__dict__.update(kwargs)
d = {'a':1,'b':2,'c':3}
c = test(d)
Run Code Online (Sandbox Code Playgroud)
而且
c = test()
c.update(d)
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误
TypeError: __init__() takes exactly 1 argument (2 given)
Run Code Online (Sandbox Code Playgroud)
谁能告诉我为什么这不起作用?干杯C.
看完说明后,我很困惑
import datetime
d = datetime.date.today()
print datetime.timedelta(hours = 9)
print d
d += datetime.timedelta(hours = 9)
print datetime.datetime.strftime(d, '%m/%d/%Y %H:%M:%S')
Run Code Online (Sandbox Code Playgroud)
正在印刷
9:00:00
2014-08-05
08/05/2014 00:00:00
Run Code Online (Sandbox Code Playgroud)
我只是看不出我在这里犯了什么错误.我错过了什么?
我有一个类以下.h
class Book; //forward declaration of Book
class Reader
{
public:
Reader();
void SetBook( Book );
private:
Book book_; // Error Reader::book_ uses undefined class Book
}
Run Code Online (Sandbox Code Playgroud)
和.cpp包含
#include "book.h"
void Reader::SetBook( Book book ) { this->book_ = book; }
// Error C2440 cannot convert from Book to int
Run Code Online (Sandbox Code Playgroud)
我不明白为什么这个前瞻性声明不起作用.此外,它不会为声明中使用的"Book"类型引发错误
void SetBook (Book )
Run Code Online (Sandbox Code Playgroud)
有什么问题的建议,这里?
我有一个向量 vec 包含对象 Order (不是指向对象的指针)
现在我需要在容器中找到某个对象并对其进行操作
for ( auto it = vec.begin(); it != vec.end(); ++it ) {
Order *p_o = it; // ERROR HERE
if ( p_o->id_ == id ) { p_o->size_ -= reduce_amount; }
}
error: C2440: 'initializing': cannot convert from 'std::_Vector_iterator<std::_Vector_val<std::_Simple_types<Order>>>' to 'Order *'
Run Code Online (Sandbox Code Playgroud)
如何获取迭代器保存的对象的地址
我都尝试过
it.pointer
it.reference
Run Code Online (Sandbox Code Playgroud)
但这会产生
C:\CPP\Simulator\Venue\venue.cpp:88: error: C2274: 'function-style cast': illegal as right side of '.' operator
Run Code Online (Sandbox Code Playgroud) 我试图在功能更新中使用一些lambdas.简单的例子就是
parse "update cfoo:foo'[c] from t"
!
`t
falseb
,`cfoo!,((`func;`foo);`c)
Run Code Online (Sandbox Code Playgroud)
那个解析树中的`func是什么?我需要在下面更换它?
![`t;();0b;(enlist `cfoo)!enlist ((`func;`foo);`c)]
Run Code Online (Sandbox Code Playgroud)