我想创建一个angular.io应用程序,但其余的API应从不同的服务器端口提供.
来自localhost:4200的Angular内容,来自node express服务器的数据在localhost:3000上独立启动.但是当我注入并使用'http'时,如何配置要使用的端口?
我试图mat-tooltip从角度材料2 应用一些css更改,并在文档中找到,matTooltipClass然后可以在css文件中进行选择以进行更改.但是,我无法让它工作.
component.html:
<mat-cell
*matCellDef="let productInfo"
matTooltip="{{productInfo.description}}"
matTooltipClass="tooltip">
{{ productInfo.description}}
</mat-cell>
Run Code Online (Sandbox Code Playgroud)
component.scss:
.tooltip {
background-color: red;
color: blue;
font-size: 20px;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Google App Engine环境并使用Python进行编程.我正在创建一个函数,它基本上生成一个随机数字/字母字符串,然后存储到memcache.
def generate_random_string():
# return a random 6-digit long string
def check_and_store_to_memcache():
randomstring = generate_random_string()
#check against memcache
#if ok, then store key value with another value
#if not ok, run generate_random_string() again and check again.
Run Code Online (Sandbox Code Playgroud)
创建两个函数而不是一个大函数会影响性能吗?我更喜欢两个,因为它更符合我的想法,但如果这是"最佳实践",请不要介意将它们结合起来.
我正在寻找一种干净的方法,将变量组合成一个带有预定义分隔符的单个字符串.问题是有时这些变量中的一些不会总是存在或者可以设置为None.我不能让分隔符字符串重复.问题示例:
# This works because I have all strings
str('-').join(('productX', 'deployment-package', '1.2.3.4'))
# 'productX-deployment-package-1.2.3.4'
# But I have more args that might be None / or not exist like and that breaks
str('-').join(('productX', 'deployment-package', '1.2.3.4', idontexist, alsonotexist))
str('-').join(('productX', 'deployment-package', '1.2.3.4', None, None, None))
# If I set the other missing variables to empty strings, I get duplicated joiners
str('-').join(('productX', 'deployment-package', '1.2.3.4', '', '', ''))
# 'productX-deployment-package-1.2.3.4---'
Run Code Online (Sandbox Code Playgroud)
有一个很好的干净方法吗?
我不明白代码的问题是什么,它非常简单,所以这很简单.
x = input("Give starting number: ")
y = input("Give ending number: ")
for i in range(x,y):
print(i)
Run Code Online (Sandbox Code Playgroud)
它给了我一个错误
Traceback (most recent call last):
File "C:/Python33/harj4.py", line 6, in <module>
for i in range(x,y):
TypeError: 'str' object cannot be interpreted as an integer
Run Code Online (Sandbox Code Playgroud)
例如,如果x为3且y为14,我希望它打印
Give starting number: 4
Give ending number: 13
4
5
6
7
8
9
10
11
12
13
Run Code Online (Sandbox Code Playgroud)
问题是什么?
我想在我的纯python + tkinter应用程序中添加一个控制终端小部件,类似于Blender中提供的python解释器.它应该在相同的上下文(进程)中运行,以便用户可以添加功能并控制当前从控件小部件运行的应用程序.理想情况下,我还希望它"劫持"当前应用程序的stdout和stderr,以便在运行的应用程序中报告任何问题或调试信息.
这是我到目前为止所提出的.唯一的问题是它没有响应命令,并且当用户关闭窗口时线程不会停止.
import Tkinter as tk
import sys
import code
from threading import *
class Console(tk.Frame):
def __init__(self,parent=None):
tk.Frame.__init__(self, parent)
self.parent = parent
sys.stdout = self
sys.stderr = self
self.createWidgets()
self.consoleThread = ConsoleThread()
self.after(100,self.consoleThread.start)
def write(self,string):
self.ttyText.insert('end', string)
self.ttyText.see('end')
def createWidgets(self):
self.ttyText = tk.Text(self.parent, wrap='word')
self.ttyText.grid(row=0,column=0,sticky=tk.N+tk.S+tk.E+tk.W)
class ConsoleThread(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
vars = globals().copy()
vars.update(locals())
shell = code.InteractiveConsole(vars)
shell.interact()
if __name__ == '__main__':
root = tk.Tk()
root.config(background="red")
main_window = Console(root)
main_window.mainloop()
try:
if root.winfo_exists():
root.destroy()
except: …Run Code Online (Sandbox Code Playgroud) 我有一个自定义的Ng2组件,我正在使用模型驱动的方法.
<form [ngFormModel]="myForm" class="layout vertical relative">
<my-custom-comp ngControl="currentValue"></my-custom-comp>
</form>
Run Code Online (Sandbox Code Playgroud)
因此,在我的自定义组件中,我拥有我需要的所有逻辑,但是我找不到一种方法来获取对ngControl的引用,以将其设置为有效或无效的自定义组件.
我在Angular 1.x上找到了一些项目,用户可以通过按Enter键将焦点移动到下一个控件.
'use strict';
app.directive('setTabEnter', function () {
var includeTags = ['INPUT', 'SELECT'];
function link(scope, element, attrs) {
element.on('keydown', function (e) {
if (e.keyCode == 13 && includeTags.indexOf(e.target.tagName) != -1) {
var focusable = element[0].querySelectorAll('input,select,button,textarea');
var currentIndex = Array.prototype.indexOf.call(focusable, e.target)
var nextIndex = currentIndex == focusable.length - 1 ? 0 : currentIndex + 1;
if (nextIndex >= 0 && nextIndex < focusable.length)
focusable[nextIndex].focus();
return false;
}
});
}
return {
restrict: 'A',
link: link
};
});
Run Code Online (Sandbox Code Playgroud)
但这对Angular 2不起作用.如何在Angular 2中的Enter keypress上设置焦点到下一个控件?
我有一个数据帧
test = spark.createDataFrame([('bn', 12452, 221), ('mb', 14521, 330),('bn',2,220),('mb',14520,331)],['x','y','z'])
test.show()
Run Code Online (Sandbox Code Playgroud)
我需要根据条件计算行数:
test.groupBy("x").agg(count(col("y")>12453),count(col("z")>230)).show()
Run Code Online (Sandbox Code Playgroud)
这使
+---+------------------+----------------+
| x|count((y > 12453))|count((z > 230))|
+---+------------------+----------------+
| bn| 2| 2|
| mb| 2| 2|
+---+------------------+----------------+
Run Code Online (Sandbox Code Playgroud)
对于某些条件,它只是行的计数而不是行的计数.
import itertools
def _yield_sample():
it = iter(itertools.combinations('ABCD', 2))
it2 = iter(itertools.combinations('EFGH', 3))
itc = itertools.chain(it,it2)
for x in itc:
yield x
def main():
for x in _yield_sample():
print x
Run Code Online (Sandbox Code Playgroud)
这适用于打印组合.
>>>
('A', 'B')
('A', 'C')
('A', 'D')
...
Run Code Online (Sandbox Code Playgroud)
但是这个:
def __position_combination(_count = [2,3,4,5]):
its = []
for ct in _count:
it = iter(itertools.combinations('ABCDEFG', ct))
its.append(it)
itc = itertools.chain(its)
for x in itc:
yield x
def main():
for x in __position_combination():
print x
Run Code Online (Sandbox Code Playgroud)
不会,它会打印出来
>>>
<itertools.combinations object at 0x02179210>
<itertools.combinations object …Run Code Online (Sandbox Code Playgroud) python ×5
angular ×4
chain ×1
count ×1
css ×1
embed ×1
forms ×1
function ×1
html ×1
interpreter ×1
javascript ×1
performance ×1
pyspark ×1
tkinter ×1
types ×1
typescript ×1