python - 属性错误 : 'str' object has no attribute 'Sub

我正在编写一个 python 脚本来将数据从 csv 转换为 geojson,这是可行的。 我有一个日期格式的字段(“2017-07-14 17:01:00”)但是对于这个数据我只需要小时部分(仅限 17)所以我试图对其进行子串以仅获取该部分,我添加了该功能:

def substr(strtime):
    strtime = strtime.Substr(strtime, 0, 3)
    return substr(strtime)

我收到了错误消息 AttributeError: 'str' 对象没有属性 'Substr'

是否有人知道如何修复它?

最佳答案

python 中的字符串可以被视为字符数组,因此您可以像这样访问:

myStr=strtime[0:3]

关于python - 属性错误 : 'str' object has no attribute 'Substr' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50796999/

相关文章:

r - 安装旧包 R

apache-spark - Apache Spark 2.0 (PySpark) - DataFr

data-structures - 如何将文本文件读入 Erlang 中的 map ?

scala - 为什么在 Scala 中将成对列表转换为 Map 时不保留元素顺序?

domain-driven-design - 微服务架构中的编排与编排

php - 在 google drive api 的根目录中创建文件夹并将文件上传到该文件夹

image-processing - 如何使用网格分割图像并保留透明边界框

scala - 我如何处理下面udf中的空指针异常错误

react-native - 如何在 createBottomTabNavigator 中获取背景图

android-studio - 无法解析 : com. google.android.gms :p