小编Ril*_*hes的帖子

python-asyncio TypeError:object dict不能在'await'表达式中使用

我正在使用第三方模块从API检索数据.我只是想异步等待模块返回有时需要几秒钟的数据并冻结我的应用程序.但是,当我尝试等待对该模块的调用时,我收到TypeError:

TypeError: object dict can't be used in 'await' expression

import thirdPartyAPIwrapper

async def getData():
    retrienveData = await thirdPartyAPIWrapper.data()
    return await retrieveData

def main():
    loop = asncio.get_event_loop()
    data = loop.run_until_complete(getData())
    loop.close
    return data
Run Code Online (Sandbox Code Playgroud)

为什么我不等待类型('dict')?有没有解决的办法?如果与asyncio的异步/等待不能与不返回协程的第三方模块一起工作那么我的其他选择是什么?

python python-asyncio

13
推荐指数
3
解决办法
2万
查看次数

通过插入/正常模式切换VIM中的绝对编号和相对编号

我在vim中使用相对行号设置.我希望vim在我处于插入模式时自动切换到绝对行号,并在正常模式下返回到相对.目前我在我的vimrc中尝试过这段代码

  autocmd InsertEnter * :set number                                                                                                                                                                                                      
  autocmd InsertLeave * :set relativenumber 
Run Code Online (Sandbox Code Playgroud)

不幸的是,这只能让我成为那里的一部分.这在我第一次离开插入模式时切换相对数字,但在再次进入插入模式时将不再返回绝对数字.

vim

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

pug 模板中的外部样式表不会加载

我无法弄清楚如何让样式表加载到 pug 中。我已经尝试了所有我能想到的方法。并在谷歌上广泛搜索。这似乎是一个很愚蠢的问题,但我已经浪费了很多时间试图弄清楚。

我的文件结构如下

/main
    server.js
    package.json
    /views
        layout.pug
        main.pug
    /public
        style.css
Run Code Online (Sandbox Code Playgroud)

在以下所有示例中,我都尝试通过以下方式引用该文件:

  • href="../public/style.css"
  • href="./public/style.css"
  • href="/public/style.css"
  • href="public/style.css"

  • href="/style.css"

我试过了:


1) main.pug 中的链接元素

    //- daytime page
    extends layout.pug
    block styles
        link(rel="stylesheet" type="text/css" href="../public/style.css")
Run Code Online (Sandbox Code Playgroud)

2)在layout.pug中使用include

//- layout
doctype
html
  head
    meta(charset='UTF-8')
    block title
      title country
    block styles
  body
    style.
      include ../public/day.css
Run Code Online (Sandbox Code Playgroud)

以及在标题内


3) 在 layout.pug 中使用

//- layout
doctype
html
  head
    meta(charset='UTF-8')
    block title
      title country
    block styles
      link(rel="stylesheet" type="text/css" href="../public/style.css")
body
Run Code Online (Sandbox Code Playgroud)

检查源

当我检查包含 pug 元素的 pug 文件的来源时。浏览器显示链接已在父级内部正确呈现。

firefox检查元素截图

当我直接将它写入 …

javascript css pugjs pug

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

在 tkinter 的 Tk.after() 方法中使用 async/await 关键字

我正在使用 Python3.5 和 Tkinter 创建一个加密货币交换 API 客户端。我有几个显示,我想每 10 秒异步更新一次。我可以Tk.after()在这个例子中使用像每 10 秒更新一次显示

def updateLoans():
    offers = dd.loanOffers()
    demands = dd.loanDemands()
    w.LoanOfferView.delete(1.0, END)
    w.LoanDemandView.delete(1.0, END)
    w.LoanOfferView.insert(END, offers)
    w.LoanDemandView.insert(END, demands)
    print('loans refreshed')

    root.after(10000, updateLoans)
Run Code Online (Sandbox Code Playgroud)

为了使该after方法每 10 秒持续更新一次,该函数updateLoans()需要作为可调用对象传递到after()函数内部。

现在难倒我的部分,当我使这个函数与 python 的新 async 和 await 关键字异步时

async def updateLoans():
    offers = await dd.loanOffers()
    demands = await dd.loanDemands()
    w.LoanOfferView.delete(1.0, END)
    w.LoanDemandView.delete(1.0, END)
    w.LoanOfferView.insert(END, offers)
    w.LoanDemandView.insert(END, demands)
    print('loans refreshed')

    root.after(10000, updateLoans)
Run Code Online (Sandbox Code Playgroud)

这里的问题是我不能在after方法的参数中等待可调用对象。所以我收到运行时警告。RuntimeWarning: coroutine 'updateLoans' was never …

python tkinter python-3.x python-asyncio python-3.5

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

ngIf 导致错误:条件表达式需要在表达式末尾添加所有 3 个表达式

我正在尝试在表单组中写入表单控件特定的验证错误消息。我在网上找到了几个教程和示例(例如这个),概述了一个看似简单的 *ngIf div,如果在控件上检测到错误,则显示错误消息。

问题是,当我尝试这样做时,我收到这个奇怪的错误

NG5002: Parser Error: Conditional expression port?.errors?['required'] requires all 3 expressions at the end of the expression

我在此页面上还有其他几个可以正常工作的 *ngIf 条件。这是我的相关代码

                <form-field labelText="Port" [hasError]="port?.invalid && (port?.dirty || key?.touched)" [isRequired]="true">
                    <input id="port" formControlName="port" type="password">
                    <ul *ngIf="port?.invalid && (port?.touched || key?.dirty)">
                        <li *ngIf="port?.errors?['required']">Port is Required</li>
                        <li *ngIf="port?.errors?['pattern']">Invalid Port Number</li>
                    </ul>
                </form-field>

Run Code Online (Sandbox Code Playgroud)
    ngOnInit() {
        this.store.dispatch(SettingsActions.enterMaintenance());
        this.detailsForm = new FormGroup({
            id: new FormControl(''),
            name: new FormControl('', Validators.required),
            productName: new FormControl('', Validators.required),
            number: new FormControl('', Validators.required),
            isSamlAuthRequired: new FormControl(Boolean),
            iAdapterSetting: new …
Run Code Online (Sandbox Code Playgroud)

angular-ng-if angular-validation angular

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

尝试在 linux mint 上构建 mariadb connector-c 时出错。怎么修?

我正在尝试在新安装的 linux mint 上构建 mariadb++(mariadb 连接器/c)。我的流程是这样的:

$ git clone https://github.com/MariaDB/mariadb-connector-c.git
$ mkdir build && cd build
$ cmake ../mariadb-connector-c/ -DCMAKE_INSTALL_PREFIX=/usr
Run Code Online (Sandbox Code Playgroud)

这一切运行良好,问题发生在我调用make.

$ make
Run Code Online (Sandbox Code Playgroud)

输出:

Scanning dependencies of target client_ed25519
[  0%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ed25519.c.o
[  1%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/fe_0.c.o
[  2%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/fe_isnegative.c.o
[  2%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/fe_sub.c.o
[  3%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/ge_p1p1_to_p2.c.o
[  4%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/ge_p3_to_cached.c.o
[  4%] Building C object CMakeFiles/client_ed25519.dir/plugins/auth/ref10/open.c.o
In file included from /home/riley/mariadb-connector-c/plugins/auth/ref10/crypto_hash_sha512.h:2:0,
                 from /home/riley/mariadb-connector-c/plugins/auth/ref10/open.c:3: …
Run Code Online (Sandbox Code Playgroud)

linux mariadb linux-mint mariadb-connector-c

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

在python中将整数转换为它的相反数

我想知道 python 中是否有一些内置函数可以将整数的符号更改为相反的符号。

我正在寻找的示例:

num = 1
num2 = -2

# where flip() is a hypothetical function

flip(num)
flip(num2)

print(num)
print(num2)

>>> -1
>>> 2
Run Code Online (Sandbox Code Playgroud)

我知道如何创建自己的函数来做到这一点,但似乎可能有一个内置的或一些快捷的方法来实现它。

python

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