我有一个错误
TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'
Run Code Online (Sandbox Code Playgroud)
我的代码如下
import os
import cv2
import random
from pathlib import Path
path = Path(__file__).parent
path = "../img_folder"
for f in path.iterdir():
print(f)
f = str(f)
img=cv2.imread(f)
line = random.randint(0, 50)
img[3, 3, :] = line
cv2.imwrite(path + "/" + "photo.png", img)
Run Code Online (Sandbox Code Playgroud)
回溯说代码cv2.imwrite~是错误的。我真的无法理解为什么这是错误的。是这种类型的路径错误吗?还是我使用这种方法是错误的?我应该如何解决这个问题?
我想知道是否有人能够帮助在Java中String的现有密钥中添加另一个值HashMap?
我知道您可以使用该this.put("String", "String")方法添加键值对.但是,它会覆盖现有值,而我希望使用相同的密钥存储和配对多个值?
谢谢你的帮助.
我目前正在尝试编写一个脚本,将文档插入 MongoDb 并返回每个元素的存储位置。非常简单感谢insert_many(),但是如果在插入时出现错误,则会出现我的问题。
我将无法获得刚刚插入的 ID。
from pymongo import MongoClient
client = MongoClient(...)
db = client.test
r = db.test.insert_many([{'foo': 1}, {'foo': 2}, {'foo': 3}])
r.inserted_ids
#: [ObjectId('56b2a592dfcce9001a6efff8'),
#: ObjectId('56b2a592dfcce9001a6efff9'),
#: ObjectId('56b2a592dfcce9001a6efffa')]
list(db.test.find())
#: [{'_id': ObjectId('56b2a592dfcce9001a6efff8'), 'foo': 1},
#: {'_id': ObjectId('56b2a592dfcce9001a6efff9'), 'foo': 2},
#: {'_id': ObjectId('56b2a592dfcce9001a6efffa'), 'foo': 3}]
# This is dead stupid, but forcing an error by re-using the ObjectId we just generated
r2 = db.test.insert_many([{'foo': 4}, {'_id': r.inserted_ids[0], 'foo': 6}, {'foo': 7}])
#: ---------------------------------------------------------------------------
#: BulkWriteError Traceback (most …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的字典:
{
'key1':
{
'a': 'key1',
'b': 'val1',
'c': 'val2'
},
'key2':
{
'a': 'key2',
'b': 'val3',
'c': 'val4'
},
'key3':
{
'a': 'key3',
'b': 'val5',
'c': 'val6'
}
}
Run Code Online (Sandbox Code Playgroud)
我试图根据键“a”删除嵌套字典中的元素以获得如下输出:
{
'key1':
{
'b': 'val1',
'c': 'val2'
},
'key2':
{
'b': 'val3',
'c': 'val4'
},
'key3':
{
'b': 'val5',
'c': 'val6'
}
}
Run Code Online (Sandbox Code Playgroud)
我为它编写了以下代码段:
for k in dict_to_be_deleted:
del k["a"]
Run Code Online (Sandbox Code Playgroud)
我不断收到密钥错误:找不到 k。我也尝试了以下方法:
for i in dict_to_be_deleted:
for k,v in i.items():
if "a" in k:
del i[k]
Run Code Online (Sandbox Code Playgroud)
我得到
Attribute Error: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 BeautifulSoup 从 SeekingAlpha 中抓取每家公司的收入。但是,该站点似乎正在检测到正在使用网络抓取工具?我收到“HTTP 错误 403:禁止”
我试图抓取的页面是:https : //seekingalpha.com/symbol/AMAT/earnings
有谁知道可以做些什么来绕过这个?
为什么我们不必function b
在下面的代码中传递参数?是因为我们使用的是Array类型的map方法吗?或者在JavaScript中我们可以在其他任何地方使用这样的函数吗?
有人能给出一个非常干净的解释吗?
码:
/* we have an array a*/
const a = ['a', 'b', 'c'];
/*we define a function called b to process a single element*/
const b = function(x){do something here};
/*I noticed that if we want to use function b to take care with the
elements in array a. we just need to do the following.*/
a.map(b);
Run Code Online (Sandbox Code Playgroud) 我有一个2维numpy数组和一个字典,它将在数组第一列中找到的值映射到其他值.例如:
>>> x = np.array([[14, 4], [18, 2], [15, 7]])
>>> d = {5: 0, 7: 2, 14: 3, 15: 12, 16: 10, 18: 30}
Run Code Online (Sandbox Code Playgroud)
尽管第一列中的所有值都在d,x但不保证所有键都x在d.我想要做的是将第一列中的值替换x为相关值d.就像是:
>>> x[:, 0] = d[x[:, 0]]
Run Code Online (Sandbox Code Playgroud)
所以新的数组将是:
>>> x
array([[3, 4], [30, 2], [12, 7]])
Run Code Online (Sandbox Code Playgroud)
当然,这不起作用,因为我基本上只是将整个数组传递到想要键的字典中.我提出的最好的是使用for循环:
>>> for i in range(x.shape[0]):
... x[i, 1] = d[x[i, 1]]
Run Code Online (Sandbox Code Playgroud)
这当然是非常不合理的,可能效率不高.我的问题是,做这样的事情有一种"笨拙的方式"吗?
我们的CI中有一个奇怪的依赖,它要求我们的git repo有一个node_modules目录(但显然不是它中的包).
由于git不跟踪空目录,我们实现它的方式是有一个.gitignore内部:
node_modules/
.gitignore
Run Code Online (Sandbox Code Playgroud)
使用以下配置
*
!.gitignore
Run Code Online (Sandbox Code Playgroud)
这有效,直到我们使用重新安装我们的模块yarn install,这将清除目录中的所有内容,包括我们的.gitignore文件,搞乱了存储库.
我们还可以添加以下内容:
node_modules/
.empty
.gitignore
Run Code Online (Sandbox Code Playgroud)
用.gitignore:
/node_modules/*
!/node_modules/.empty
Run Code Online (Sandbox Code Playgroud)
但yarn install仍将删除该文件,以及任何跟踪node_modules目录.
我们的问题是,我们缺少哪些可以:
node_modules/gityarn install我知道实际的答案是修复我们的CI,但这对我们来说有点超出了我们的范围.
import pypyodbc as pyodbc
model_name = 'test'
model_name1 = Master_Cursor.execute("select col1,col2,col3 from tablename where col3 like '%s' order by col3" %(model_name)).fetchall()
Run Code Online (Sandbox Code Playgroud)
上面的代码返回一条匹配的记录model_name = test。我如何取回其他记录model_name=123test123,abctestabc,ABCtestABC等?
基本上是在寻找
select col1,col2,col3 from tablename where col3 like '%test%'.
Run Code Online (Sandbox Code Playgroud) 我是新来的火花。当我尝试在客户端模式下使用 3 个执行程序运行 spark-submit 时,我希望在执行时显示 3 个 java 进程(因为有 3 个执行程序)ps -ef
$SPARK_HOME/bin/spark-submit --num-executors 3 --class AverageCalculation --master local[1] /home/customer/SimpleETL/target/SimpleETL-0.1.jar hdfs://node1:9000/home/customer/SimpleETL/standard_input.csv
Run Code Online (Sandbox Code Playgroud)
但是,我没有看到 3 个 Java 进程。我的理解是每个 executor 进程都是一个 java 进程。请指教。谢谢。
假设我有以下 typedef:
interface Node {
id: ID!
}
type Foo implements Node {
id: ID!
quantity: Int
}
type Bar implements Node {
id: ID!
name: String
}
Run Code Online (Sandbox Code Playgroud)
我发出的每一个ID,我都想以同样的方式处理。目前我需要一些解析器,如:
interface Node {
id: ID!
}
type Foo implements Node {
id: ID!
quantity: Int
}
type Bar implements Node {
id: ID!
name: String
}
Run Code Online (Sandbox Code Playgroud)
使用许多类型实现Node,这会导致大量代码重复,开发人员很容易忘记编码 id 的正确方法,或者忘记将它们全部编码。
有没有办法做这样的事情?
{
// ...
Foo: {
id: (root) => encodeId(root.id, root.type),
// ...
},
Bar: {
id: (root) => encodeId(root.id, …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用正则表达式来验证输入。它应该接受 8 位并且只接受 8 位数字(没有空格字母等)。例如:
88884444, 55551234
Run Code Online (Sandbox Code Playgroud)
我试过了,但如果我输入超过 8 位数字,它似乎可以接受(如果我在之后添加字母,它也可以接受)谢谢
r'^[0-9]{8,8}'
Run Code Online (Sandbox Code Playgroud) python ×6
python-3.x ×3
arrays ×2
dictionary ×2
node.js ×2
apache-spark ×1
apollostack ×1
git ×1
graphql ×1
hashmap ×1
java ×1
javascript ×1
key ×1
mongodb ×1
nested ×1
numpy ×1
opencv ×1
pymongo ×1
pypyodbc ×1
regex ×1
web-scraping ×1
yarnpkg ×1