小编Yar*_*min的帖子

Kotlin将字符串作为字符串

我无法找到如何让一个变量(或不变)的类型String,比如typeof(variable),与科特林语言.怎么做到这一点?

java kotlin

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

JavaScript中的模块和库之间的区别

我正在学习ES6模块.但我对模块和库之间的区别感到困惑.

以及模块和库与node.js包的不同之处.

javascript node.js

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

使用Openpyxl将边界应用于单元格区域

我使用的是python 2.7.10和openpyxl 2.3.2,我是一个Python新手.

我正在尝试将边框应用于Excel工作表中的指定范围的单元格(例如C3:H10).我在下面的尝试失败,并显示以下消息:

AttributeError:'Cell'对象没有属性'styles'.

如何将边框附加到单元格?任何见解都会感激不尽.

我目前的代码:

import openpyxl
from openpyxl.styles import Border, Side

def set_border(ws, cell_range):
    rows = ws.iter_rows(cell_range)
    for row in rows:
        row[0].styles.borders = Border(left=Side(border_style='thin', color="FF000000"))
        row[-1].styles.borders = Border(right=Side(border_style='thin', color="FF000000"))
    for c in rows[0]:
        c.styles.borders = Border(top=Side(border_style='thin', color="FF000000"))
    for c in rows[-1]:
        c.styles.borders = Border(bottom=Side(border_style='thin', color="FF000000"))


# Example call to set_border
wb = openpyxl.load_workbook('example.xlsx')
ws = wb.get_sheet_by_name('Sheet1')

set_border(ws, "B3:H10")
Run Code Online (Sandbox Code Playgroud)

python excel openpyxl

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

在Angular2中禁用应用程序加载/路由

我有一个angular2应用程序(RC6版本),其中一些重要的全局参数使用在启动时收集此文件的服务从配置文件加载:

@NgModule({
imports:  [ BrowserModule, FormsModule, HttpModule, AppRoutes, SomeCustomModule ],
declarations: [ AppComponent ]
providers: [
            ConfigurationService,
            {
              provide: APP_INITIALIZER,
              useFactory: (config: ConfigurationService) => () => { 
                             return config.load().then(configParams=> { return true;});      
                          },
              deps: [ConfigurationService, HttpModule],
              multi: true
            }
          ],
bootstrap:[ AppComponent ]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)

如本片段所示,我使用我称之为ConfigurationRervice的内容,它通过http调用读取配置文件并返回一些参数(作为Promise).如果一切顺利,应用程序将完美加载,并且可以在子模块等中访问这些配置参数.

问题是,如果此配置文件未按预期加载,如何停止应用程序加载子模块?(请注意,AppComponent实质上只是一个路由器插座,重定向到其他路由,由多个子模块定义).我可以"禁用"或重定向到错误页面而不是加载由请求的路由定义的模块/组件吗?

configuration angular2-router angular

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

如何在删除时将外键设置为默认值?

如何在category_id删除类别时自动将产品设置为默认值?例如1,指向第一个类别.

class Product(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    content = db.Column(db.Text(), unique=True)
    category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
    atime = db.Column(db.DateTime())

    def __init__(self, name, content, category_id):
        self.name = name
        self.content = content
        self.category_id = category_id
        self.atime = datetime.now()

    def __repr__(self):
        return '<Product %r>' % self.id

class Category(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    products = db.relationship('Product', backref='category', cascade="all, delete, delete-orphan")

    def __init__(self, *args, **kwargs):
        if len(kwargs) > 0:
            self.name = kwargs['name']

    def __repr__(self):
        return '<Category …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy

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

在Typescript中解析JSON数组

我以这种方式从远程服务器获得JSON响应:

{
  "string": [
    {
      "id": 223,
      "name": "String",
      "sug": "string",
      "description": "string",
      "jId": 530,
      "pcs": [{
        "id": 24723,
        "name": "String",
        "sug": "string"
      }]
    }, {
      "id": 247944,
      "name": "String",
      "sug": "string",
      "description": "string",
      "jlId": 531,
      "pcs": [{
        "id": 24744,
        "name": "String",
        "sug": "string"
      }]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

为了解析响应,列出"名称"和"描述",我已经写出了这个代码:

interface MyObj {
  name: string
  desc: string
}
let obj: MyObj = JSON.parse(data.toString());
Run Code Online (Sandbox Code Playgroud)

我的问题是如何在可以显示的列表中获取名称和描述.

json typescript ionic2

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

升级到 Nebular 4 已停止显示很棒的字体图标。设置包也不起作用

Angular 版本 8 升级后,Nebular 更新到版本 4。升级后,我看不到之前显示的很棒的字体图标。

我尝试浏览 nebular 的这份文档,它要求我们将 font Awesome 注册为默认包。但即使这样做也不起作用。 https://akveo.github.io/nebular/docs/guides/register-icon-pack#register-icon-pack

找不到关于此问题的足够讨论。Font Awesome 已包含在内,并且我已将其添加到我的 angular.json 文件中

constructor(private iconService: NbIconLibraries) {
    this.iconService.registerFontPack('font-aweome');
    this.iconService.setDefaultPack('font-aweome');
}
Run Code Online (Sandbox Code Playgroud)

Nebular 应该接受字体很棒的图标。

font-awesome-5 nebular angular8

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

检查字符串是否包含特定字符

我需要检查我的字符串是否包含特定字符.

我试过这个:

charFound :: Char -> String -> Bool
charFound c s = filter(\x -> x == c) s
Run Code Online (Sandbox Code Playgroud)

但它给了我:

无法将预期类型Bool与实际类型匹配[Char]

我知道那个过滤器:

返回一个由列表成员(第二个参数)构成的列表,它满足第一个参数给出的条件.

我怎么能达到目标并返回一个布尔而不是列表?

haskell

4
推荐指数
2
解决办法
9238
查看次数

带有时间戳的Ansible模板

我试图找出是否有方法在Ansible中为模板文件添加时间戳,这样每次我运行使用某个模板的Ansible playbook时,它会在目标文件中添加执行playbook的时间.

例如,我正在使用Ansible模板配置文件,我希望它在目标计算机上显示第一行的时间戳...

例如

cat something.conf_template
some config lines
Run Code Online (Sandbox Code Playgroud)

模板化后:

- template: src=/mytemplates/something.conf_template dest=/etc/something.conf owner=smth group=smth mode=0644
Run Code Online (Sandbox Code Playgroud)

内容应该是

cat something.conf
#in this comment is the timestamp, format irrelevant
some config lines
Run Code Online (Sandbox Code Playgroud)

你知道任何可以做到这一点的ansible模块吗?

ansible ansible-playbook

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

升级到Angular9问题:无法找到节点的导出名称

升级到 Angular 9 并尝试运行我的项目后,我收到此错误:

Compiling @angular/common/http : module as esm5
Compiling angular-font-awesome : module as esm5
Compiling angular-font-awesome : module as esm5
Error: Error on worker #5: Error: Failed to find exported name of node (CommonModule = (function () {
    function CommonModule() {
    }
    return CommonModule;
}())) in 'C:/Users/.../node_modules/angular-font-awesome/dist/angular-font-awesome.es5.js'.
    at Object.findExportedNameOfNode (C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\find_export.js:35:19)
    at LogicalProjectStrategy.emit (C:\Users\Ghaida\...\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\emitter.js:228:38)
    at ReferenceEmitter.emit (C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\imports\src\emitter.js:71:44)
    at Object.toR3Reference (C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\util.js:173:31)
    at NgModuleDecoratorHandler._toR3Reference (C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\ng_module.js:415:31)
    at C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\ng_module.js:196:72
    at Array.map (<anonymous>)
    at NgModuleDecoratorHandler.analyze (C:\Users\...\node_modules\@angular\compiler-cli\src\ngtsc\annotations\src\ng_module.js:196:38)

Run Code Online (Sandbox Code Playgroud)

这是运行 ng version 的结果:

Angular CLI: 9.1.0
Node: …
Run Code Online (Sandbox Code Playgroud)

npm angular-upgrade angular angular9

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