我收到了错误
app/hero-detail.component.ts(44,29): error TS2339: Property 'includes' does not exist on type '[]'.
app/hero.service.ts(25,25): error TS1122: A tuple type element list cannot be empty.
Run Code Online (Sandbox Code Playgroud)
代码将无法编译和运行,此错误已启用npm start.
hero.service.ts:
import { Injectable } from '@angular/core';
import { Hero, HeroIds } from './hero';
import { HEROES } from './mock-heroes';
@Injectable()
export class HeroService {
getHeroes(): Promise<Hero[]> {
return Promise.resolve(HEROES);
}
getHero(id: number): Promise<Hero> {
return this.getHeroes()
.then(heroes => heroes.find(hero => hero.id === id));
}
getHeroesSlowly(): Promise<Hero[]> {
return new Promise(resolve => { …Run Code Online (Sandbox Code Playgroud) 我在https://bitbucket.org/codyc54321/anthony-project-react有一个仓库
我的主页显示了链接,当您单击链接时,反应路由器就可以工作。但组件的文本没有显示,如 <div>Login page</div>、<div>Homepage</div>等。
索引.js:
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, Link, IndexRoute, browserHistory } from 'react-router';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import reducers from './reducers';
import Nav from './Nav';
import Home from './components/Home';
import Login from './components/Login';
import SignupMain from './components/SignupMain';
const createStoreWithMiddleware = applyMiddleware()(createStore);
ReactDOM.render(
(
<Provider store={createStoreWithMiddleware(reducers)}>
<Router history={browserHistory}>
<Route path="/" component={Nav}>
<IndexRoute component={Home}/>
<Route path='/login' component={Login}/>
<Route path='/signup-main' …Run Code Online (Sandbox Code Playgroud) 我可以在 shell 中导入 BASE_DIR 如下:
In [3]: from scriptcitymirror.settings import BASE_DIR
In [4]: BASE_DIR
Out[4]: '/home/cchilders/projects/django_practice/scriptcity_public'
Run Code Online (Sandbox Code Playgroud)
但是在为我编写应用程序的脚本中,我无法导入完全相同的内容:
#!/usr/bin/env python
import os, subprocess, sys, re, requests, time
from scriptcitymirror.settings import BASE_DIR
Run Code Online (Sandbox Code Playgroud)
爆炸为:
cchilders@cody_pc:~/projects/django_practice/scriptcity_public$ robots/app_writer.py
Traceback (most recent call last):
File "robots/app_writer.py", line 4, in <module>
from scriptcitymirror.settings import BASE_DIR
ImportError: No module named scriptcitymirror.settings
Run Code Online (Sandbox Code Playgroud)
我惊呆了。另外,我通常在主目录(带有 settings.py 的目录中的 urls.py 文件)中执行此操作的方法不起作用:
from django.conf import settings
settings.configure()
print settings.MEDIA_URL
Run Code Online (Sandbox Code Playgroud)
现在我丑陋的解决方法是调用CWD=os.getcwd()并要求脚本从主项目路径运行。我的文件夹如下图所示。如何在 django 项目中的任何地方正确获取 BASE_DIR?(但在这里,我想在不是应用程序的“机器人”中使用它们。在制作测试应用程序后导入也不起作用)。谢谢
我正在尝试构建一个ETL机器进行测试.
class TestETLMachine(object):
API_URL = 'https://9g9xhayrh5.execute-api.us-west-2.amazonaws.com/test/data'
@staticmethod
def get_email_data(cls):
headers = {'accept': 'application/json'}
r = requests.get(cls.API_URL, headers=headers)
email_objects_as_list_of_dicts = json.loads(r.content)['data']
return email_objects_as_list_of_dicts
@staticmethod
def get_distinct_emails(cls):
email_data = cls.get_email_data()
print email_data
Run Code Online (Sandbox Code Playgroud)
因为get_distinct_emails我想打电话TestETLMachine.get_email_data()让它知道我指的是这堂课.这个对象是一个静态机器,意味着它总是做同样的事情,并且使它的实例是毫无意义的并且看起来很糟糕.当我get_email_data现在试着打电话给我时,cls我已经不能了:
In [9]: TestETLMachine.get_email_data()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-9-cf48fc1a9c1d> in <module>()
----> 1 TestETLMachine.get_email_data()
TypeError: get_email_data() takes exactly 1 argument (0 given)
Run Code Online (Sandbox Code Playgroud)
如何在下一个类方法中调用这些类方法并使用其他类方法?萨拉马特
我想解压缩像:
one, two, three, four = unpack(this_dict)
Run Code Online (Sandbox Code Playgroud)
哪里
this_dict = {'one': 1, 'two': 2, 'three': 3, 'four': 4}
Run Code Online (Sandbox Code Playgroud)
我唯一的问题是unpack需要知道它将分配给哪些名字.你是如何在python中做到这一点的?谢谢
我在 Go 之旅的解释器中有以下内容:
package main
import "fmt"
var someString = "one two three four "
var words = strings.Fields(someString)
var length = len(words)
fmt.Println(words, length)
Run Code Online (Sandbox Code Playgroud)
我明白了
tmp/sandbox216066597/main.go:11: syntax error: non-declaration statement outside function body
Run Code Online (Sandbox Code Playgroud)
我最近通过在任何函数之外使用var而不是:=短语法来纠正它,但错误与以前相同。
我想知道如何在 python 中初始化一个对象,只使用命名的 args,如果可能的话。

如果self.name = name 和self.age = age 的顺序互换,则错误在于初始化age。我将这些作为关键字参数提供给对象,那为什么还不够呢?我看到一个类深入 python 实例化,使用显式命名的关键字参数和它们的默认值(文件名=无),所以我认为 **kwargs 也可以工作。谢谢
在//header[.//span[contains(text(), 'part_title')]]//label[contains(@class, 'start')],.点.//是什么意思?谢谢
python ×4
javascript ×2
python-3.x ×2
angular ×1
class ×1
constructor ×1
django ×1
go ×1
html ×1
object ×1
python-2.7 ×1
react-router ×1
reactjs ×1
scripting ×1
xml ×1
xpath ×1