草庐IT

offline_str

全部标签

c++ - string.c_str() 是常量吗?

这个问题在这里已经有了答案:CanIgetanon-constCstringbackfromaC++string?(14个回答)关闭5年前。我在一个库中有一个函数,它接收char*并修改数据。我试图给它c_str()但c++文档说它返回一个constchar*。除了新建一个char数组并将其复制到其中之外,我还能做什么? 最佳答案 您可以使用&str[0]或&*str.begin()只要:您使用resize()显式预分配函数所需的所有空间;函数不会尝试超过预先分配的缓冲区大小(您应该传递str.size()作为缓冲区大小的参数);当

c++ - 字符串和 const char* 和 .c_str()?

我遇到了一个奇怪的问题,我想知道它为什么会这样。我有一个类,其中有一个返回std::string的成员函数。我的目标是将这个string转换为constchar*,所以我做了以下constchar*c;c=robot.pose_Str().c_str();//isthissafe??????udp_slave.sendData(c);问题是我在大师方面得到了一个奇怪的角色。但是,如果我执行以下操作constchar*c;std::stringdata(robot.pose_Str());c=data.c_str();udp_slave.sendData(c);我得到了我所期望的。我的问

python - 有没有办法在 python 中自动生成 __str__() 实现?

厌倦了为我的类手动实现字符串表示,我想知道是否有一种Python的方法可以自动执行此操作。我想要一个涵盖类的所有属性和类名的输出。这是一个例子:classFoo(object):attribute_1=Noneattribute_2=Nonedef__init__(self,value_1,value_2):self.attribute_1=value_1self.attribute_2=value_2导致:bar=Foo("baz","ping")print(str(bar))#desired:Foo(attribute_1=baz,attribute_2=ping)在使用Proje

python - 按包含 str 过滤 Pandas 数据帧行

我有一个包含很多行的pythonpandas数据框df。从这些行中,我想切出并仅使用“body”列中包含“ball”一词的行。为此,我可以这样做:df[df['body'].str.contains('ball')]问题是,我希望它不区分大小写,这意味着如果出现Ball或bAll这个词,我也会想要它们。进行不区分大小写搜索的一种方法是将字符串转换为小写,然后以这种方式进行搜索。我想知道如何去做。我试过了df[df['body'].str.lower().contains('ball')]但这不起作用。我不确定我是否应该在这个或类似的东西上使用lambda函数。

python - 为什么我会得到 "Unorderable types: int() < str()"或 "' <' not supported between instances of ' int' 和 'str' "?

这个问题在这里已经有了答案:HowcanIreadinputsasnumbers?(10个回答)I'mgettingaTypeError.HowdoIfixit?(2个回答)关闭2个月前。我有这个代码:defmain():print("LetmeRetireFinancialCalculator")deposit=input("Pleaseinputannualdepositindollars:$")rate=input("Pleaseinputannualrateinpercentage:%")time=input("Howmanyyearsuntilretirement?")x=0

python - 在 Pandas 数据框上使用 str.contains

这个问题在这里已经有了答案:FilterpandasDataFramebysubstringcriteria(17个回答)关闭3年前。这个pandaspython代码生成错误信息,"TypeError:badoperandtypeforunary~:'float'"我不知道为什么,因为我正在尝试操作str对象df_Anomalous_Vendor_Reasons[~df_Anomalous_Vendor_Reasons['V'].str.contains("File*|registry*")]#sorts,leavingonlycaseswherereasonisNOTFileorRe

python - Pandas 数据框 str.contains() AND 操作

我有一个三行的df(PandasDataframe):some_col_name"appleisdelicious""bananaisdelicious""appleandbananabotharedelicious"函数df.col_name.str.contains("apple|banana")将捕获所有行:"appleisdelicious","bananaisdelicious","appleandbananabotharedelicious".如何将AND运算符应用于str.contains()方法,以便它只抓取包含“apple”和“banana”的字符串?"applean

Python 和 JSON - TypeError 列表索引必须是整数而不是 str

我正在学习使用Python和API(特别是这个世界杯API,http://www.kimonolabs.com/worldcup/explorer)JSON数据如下所示:[{"firstName":"NicolasAlexisJulio","lastName":"N'KoulouN'Doubena","nickname":"N.N'Koulou","assists":0,"clubId":"5AF524A1-830C-4D75-8C54-2D0BA1F9BE33","teamId":"DF25ABB8-37EB-4C2A-8B6C-BDA53BF5A74D","id":"D9AD1E6

python - Matplotlib编译错误: TypeError: unorderable types: str() < int()

这个问题在这里已经有了答案:ubuntu14.04,pipcannotupgradematplotllib(9个回答)关闭7年前.我正在尝试使用pythonsetup.pybuild在python3.4上添加matplotlib-1.4.2。根据文档,它在python3.4上受支持。我收到以下错误消息:IMPORTANTWARNING:pkg-configisnotinstalled.matplotlibmaynotbeabletofindsomeofitsdependencies=====================================================

python - 类型错误 : str does not support buffer interface

这个问题在这里已经有了答案:TypeError:'str'doesnotsupportthebufferinterface(7个回答)PythonSocketSendBufferVs.Str(2个回答)关闭6年前.我正在尝试在python中制作一个简单的客户端和服务器消息传递程序,但我不断收到错误“TypeError:'str'doesnotsupportthebufferinterface”,甚至不知道这是什么意思。我在很大程度上是python的初学者,也是网络的完全初学者。我假设由于某种原因我无法发送字符串数据?如果是这种情况,我将如何发送字符串?作为引用,我从中获得的大部分示例代