有没有办法让arr = [5,4,3,2,1]
同时仍然使用这两个函数而不使arr
全局?我需要将多个值从y()
传递回x(
),但我不希望arr
= [5,4,3,[2,1]]
。或者我是否需要重新设计我的功能?
arr = [5,4,3]
def x():
arr.append(y())
def y():
a = 2
b = 1
newArr = [a,b]
return newArr
x()
print arr
答案 0 :(得分:4)
你使用了错误的方法:
arr.append(thing)
thing
表示"在arr
"末尾添加arr.extend(thing)
作为新项目。 thing
表示"将arr
的所有内容添加到app.controller('MainCtrl', function ($scope, $timeout, $http) {
//keep a variable for storing timeoutPromise
var timeoutPromise;
$scope.searchForUser = function () {
$scope.selectedUser = null;
$scope.selectedRepo = null;
$scope.returnedRepos = [];
$scope.returnedCommits = [];
if ($scope.user.length === 0) {
$scope.returnedUsers = null;
return;
}
//if already a timeout is in progress cancel it
if (timeoutPromise) {
$timeout.cancel(timeoutPromise);
}
//Make a fresh timeout
timeoutPromise = $timeout(searchUsers, 500)
.finally(function(){
timeoutPromise = null; //nullify it
});
};
function searchUsers() {
$http.get("https://api.github.com/search/users?q=" + $scope.user).
success(function (data, status) {
if (status === 200) {
$scope.returnedUsers = data.items;
}
}).
error(function (data, status) {
alert("something happened with quhhnnhhhh");
});
}
});
"的末尾。