小编Man*_*Pal的帖子

UnsupportedOperation:无法执行非零当前相对搜索:Python

下面是我的代码,我正在使用:

with open(r'C:\Users\Manish\Desktop\File5.txt', 'r') as f:
     fo = f.read(20)
     print(fo)
     f.seek(20,1)
     fo = f.read(20)
     print(fo)
Run Code Online (Sandbox Code Playgroud)

但它没有从当前位置获取下一行,而是反复向我显示错误。我的代码问题出在哪里?

python python-3.x

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

运算符不存在:json @> 未知

我有下表,我想要其 userid='user-1' 和 gridname='RT' 的布局名称

| userid |                                                                              defaultdata |
|--------|------------------------------------------------------------------------------------------|
| user-1 | [{"gridname":"RT", "layoutname":"layout-1"},{"gridname":"RT2", "layoutname":"layout-2"}] |
| user-2 | [{"gridname":"RT", "layoutname":"layout-3"},{"gridname":"RT2", "layoutname":"layout-2"}] |
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经尝试过这个。

 SELECT userid, obj.value->>'gridname' AS gridname
 FROM   col.userdefault t
 JOIN   lateral jsonb_array_elements(t.defaultdata::jsonb) obj(value) ON 
 obj.value->>'_gridname' = 'RT'
 WHERE  defaultdata @> '[{"_gridname":"RT"}]';
Run Code Online (Sandbox Code Playgroud)

但不工作并收到以下错误:

ERROR:  operator does not exist: json @> unknown
LINE 4: WHERE  defaultdata @> '[{"_gridname":"RT"}]::jsonb';
                           ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts. …
Run Code Online (Sandbox Code Playgroud)

postgresql

5
推荐指数
1
解决办法
6649
查看次数

如何在Python中的字符串前后添加字符?

我有两个变量,一个是字符串,另一个是列表。

string_val = 'CreateTime:1557770979668  {"schema":{"type":"string","optional":false},"payload":"{\"subscriptionId\":\"//blp/mktdata/BLOOMBERG IDENTIFIER?fields=LAST_PRICE\",\"MarketDataEvents\":{\"LAST_PRICE\":50.84}}"}'
list_val = ["25746UCY3 Corp","BBG00JM9XLN6 Equity","CFM0987JKM Pro"]
Run Code Online (Sandbox Code Playgroud)

在所需的输出中,您可以观察到插入了list_val元素而不是“ BLOOMBERG IDENTIFIER”。我尝试了下面的代码,但没有成功。

for i in range(0,len(list_val)):
    print(len(list_val))
    expect_val = string_val.split('mktdata/',0)[1]  + list_val[i] + string_val.split('?fields',0)[-1]
    print(expect_val)
Run Code Online (Sandbox Code Playgroud)

所需的输出:

CreateTime:1557770979668    {"schema":{"type":"string","optional":false},"payload":"{\"subscriptionId\":\"//blp/mktdata/25746UCY3 Corp?fields=LAST_PRICE\",\"MarketDataEvents\":{\"LAST_PRICE\":50.84}}"}
CreateTime:1557770979668    {"schema":{"type":"string","optional":false},"payload":"{\"subscriptionId\":\"//blp/mktdata/BBG00JM9XLN6 Equity?fields=LAST_PRICE\",\"MarketDataEvents\":{\"LAST_PRICE\":50.84}}"}
CreateTime:1557770979668    {"schema":{"type":"string","optional":false},"payload":"{\"subscriptionId\":\"//blp/mktdata/CFM0987JKM Pro?fields=LAST_PRICE\",\"MarketDataEvents\":{\"LAST_PRICE\":50.84}}"}
Run Code Online (Sandbox Code Playgroud)

请提出建议,我该如何实现?

python

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

标签 统计

python ×2

postgresql ×1

python-3.x ×1