我有一些字符串要连接,结果字符串将很长.我也有一些变量要连接.
如何组合字符串和变量,以便结果是多行字符串?
以下代码抛出错误.
str = "This is a line" +
str1 +
"This is line 2" +
str2 +
"This is line 3" ;
Run Code Online (Sandbox Code Playgroud)
我也尝试过这个
str = "This is a line" \
str1 \
"This is line 2" \
str2 \
"This is line 3" ;
Run Code Online (Sandbox Code Playgroud)
请建议一种方法来做到这一点.
我创建了一个新的流浪盒使用
vagrant init ubuntu/trusty64
vagrant up
Run Code Online (Sandbox Code Playgroud)
我想在不使用“vagrant ssh”的情况下进行 ssh
盒子机的ifconfig给了我
eth0 Link encap:Ethernet HWaddr 08:00:27:ca:3e:f9
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:feca:3ef9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:254 errors:0 dropped:0 overruns:0 frame:0
TX packets:187 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:26220 (26.2 KB) TX bytes:22208 (22.2 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 …Run Code Online (Sandbox Code Playgroud) 我是角度js的新手,并试图使用指令.我想在指令的link函数中使用$ http.以下是我的代码
MyApp.directive('appItem', ['$http',function() {
return {
restrict: 'E',
scope: {
transaction: '='
},
templateUrl: 'js/directives/appItem.html' ,
link: function($scope, $http, element, attrs) {
$scope.process = function(trId) {
$http({
method: 'PATCH',
url: 'http://myapp.domain.local/api/v1/items/'+trId+'.json'
}).
then(function successCallback(response) {
console.log(response);
});
}
}
}
}]);
Run Code Online (Sandbox Code Playgroud)
但它给了我错误:
$http is not a function
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用flask框架和jinja模板打印一个数字的fibonacci系列.以下程序给我一个505内部服务器错误!但是当我在函数内部注释for循环时,它会给我正确的结果
fibonacciURL.py
from flask import Flask
from jinja2 import Environment, PackageLoader
app= Flask(__name__)
def fib(num):
if num==1 or num==0:
return num
else:
return fib(num-1)+fib(num-2)
@app.route('/fib/<number>')
def generate_fibonacci(number):
env= Environment(loader=PackageLoader('Fibonacci','templates'))
fibMap={}
#for x in range(number):
# fibMap[i]=fib(i)
for i in range(0,number):
print 'Hello'
#pass
template= env.get_template('table_template.html')
return template.render(num=3,map={1:1,2:2,3:3})
#return 'wda'
if __name__ =='__main__':
app.run(host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)
我的table_template.html是
<table>
{%for i in range(1,num)%}
<tr>
<td>{{i}}</td>
<td>{{map[i]}}</td>
</tr>
{% endfor %}
</table>
Run Code Online (Sandbox Code Playgroud)
如果没有for循环,页面将显示预期结果
python ×2
angular-http ×1
angularjs ×1
flask ×1
javascript ×1
jinja2 ×1
ssh ×1
string ×1
ubuntu ×1
vagrant ×1