小编Sal*_*anz的帖子

在清洁架构中设计实体的最佳实践是什么?

我正在尝试使用 Kotlin 实现干净的架构。该过程的流程将是:

usecase --> get rowresult from DB --> map rowresult to entity --> entity used by the usecase to check business rules

代码示例:

UserTable
------------------
id (varchar)
email (varchar)
password (varchar)
gender (varchar)
phone (varchar)
anotherAttribute1
anotherAttribute2
.
anotherAttributeN
Run Code Online (Sandbox Code Playgroud)
class UserEntity {
    val id: String,
    val email: String,
    val password: String,
    //Business rules
    fun isUserAllowedToLogin(): Boolean {
        //validate password
    }
}

interface UserDataStore {
    fun getUser(email: String): User
}

class UserDataStoreImplementation {
    fun getUser(email: String): User {
        //query …
Run Code Online (Sandbox Code Playgroud)

architecture software-design clean-architecture

2
推荐指数
1
解决办法
1128
查看次数

在特殊字符前面添加空格

如果这些特殊字符粘在一个单词上,如何在Python中创建RE以在这些特殊字符前面添加空格,?!

这是输入字符串:

myString= 'I like him, but is he good? Maybe he is good , smart, and strong.'
Run Code Online (Sandbox Code Playgroud)

所需的输出(如果特殊字符不粘在单词上,则不会被修改):

modifiedString= 'I like him , but is he good ? Maybe he is good , smart , and strong.'
Run Code Online (Sandbox Code Playgroud)

我已经尝试过这个回复:

modifiedString= re.sub('\w,' , ' ,' ,myString)
Run Code Online (Sandbox Code Playgroud)

但它给出了错误的结果。它删除逗号之前的最后一个字符,这是结果示例:

modifiedString = 'I like hi , but is he good? Maybe he is goo , smar , and strong.'
Run Code Online (Sandbox Code Playgroud)

有什么建议可以解决这个问题吗?

python regex string

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