is-empty

What is the best way to check if a tuple has any empty/None values in Python?

喜你入骨 提交于 2019-12-03 22:27:22
What is the best/most efficient way to check if all tuple values? Do I need to iterate over all tuple items and check or is there some even better way? For example: t1 = (1, 2, 'abc') t2 = ('', 2, 3) t3 = (0.0, 3, 5) t4 = (4, 3, None) Checking these tuples, every tuple except t1 , should return True, meaning there is so called empty value. P.S. there is this question: Test if tuple contains only None values with Python , but is it only about None values It's very easy: not all(t1) returns False only if all values in t1 are non-empty/nonzero and not None . all short-circuits, so it only has to

AngularJS - controller doesn't get data from service when using $http

﹥>﹥吖頭↗ 提交于 2019-12-03 17:16:51
I have simple web app where I like to load some data from json. At the moment the data is hardcoded within my service and everything is working. When I change my service to load the same data from an external json file the controller renders the view before it gets some data. That's what it looks like now: function() { var tripsService = function() { var trips = [{ .... SOME DATA }]; this.getTrips = function() { return trips; }; }; angular.module('customersApp').service('tripsService', tripsService); }()); Using $http.get : function() { var tripsService = function() { var trips = []; this

How to check if a multi-dimensional array only contains empty values?

两盒软妹~` 提交于 2019-12-03 14:07:14
问题 I looked around and can't quite find the answer for this, so I'm wondering if I contain an array such as this.. $array['foo']['bar'][1] = ''; $array['foo']['bar'][2] = ''; $array['foo']['bar'][3] = ''; $array['foo']['bar'][4] = ''; How can I check if all the values are empty? I tried doing the following: if (empty($array['foo']['bar'])) { // Array empty } But as expected that didn't work. How can I do this? 回答1: If you wanted to check to see if all of the values where populated you can use if

How to check if a multi-dimensional array only contains empty values?

这一生的挚爱 提交于 2019-12-03 04:03:52
I looked around and can't quite find the answer for this, so I'm wondering if I contain an array such as this.. $array['foo']['bar'][1] = ''; $array['foo']['bar'][2] = ''; $array['foo']['bar'][3] = ''; $array['foo']['bar'][4] = ''; How can I check if all the values are empty? I tried doing the following: if (empty($array['foo']['bar'])) { // Array empty } But as expected that didn't work. How can I do this? If you wanted to check to see if all of the values where populated you can use if(call_user_func_array("isset", $array['foo']['bar'])) For what you want to do though you could use array

What is the best way to test for an empty string in Go?

随声附和 提交于 2019-12-02 14:12:59
Which method is best (more idomatic) for testing non-empty strings (in Go)? if len(mystring) > 0 { } Or: if mystring != "" { } Or something else? Both styles are used within the Go's standard libraries. if len(s) > 0 { ... } can be found in the strconv package: http://golang.org/src/pkg/strconv/atoi.go if s != "" { ... } can be found in the encoding/json package: http://golang.org/src/pkg/encoding/json/encode.go Both are idiomatic and are clear enough. It is more a matter of personal taste and about clarity. Russ Cox writes in a golang-nuts thread : The one that makes the code clear. If I'm

Javascript: Checking if an object has no properties or if a map/associative-array is empty [duplicate]

旧时模样 提交于 2019-11-30 04:16:46
Possible Duplicate: How do I test for an empty Javascript object from JSON? Is there an easy way to check if an object has no properties, in Javascript? Or in other words, an easy way to check if a map/associative array is empty? For example, let's say you had the following: var nothingHere = {}; var somethingHere = {foo: "bar"}; Is there an easy way to tell which one is "empty"? The only thing I can think of is something like this: function isEmpty(map) { var empty = true; for(var key in map) { empty = false; break; } return empty; } Is there a better way (like a native property/function or

PHP: What is the best and easiest way to check if directory is empty or not [closed]

主宰稳场 提交于 2019-11-30 01:51:26
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 6 years ago . I got a root directory with 100s of dynamically generated folders. As time goes some of these folders will need to be extirpated from system on the condition that this(ese) directories(s) must be empty. What would be the best shortest, easiest and/or most effective way to

execute Ant task if TWO conditions are met

家住魔仙堡 提交于 2019-11-29 13:37:50
The above ant script implements if dir_is_empty then git-clone else git-fetch using Ant-1.7.1 core statements: <target name="update" depends="git.clone, git.fetch" /> <target name="check.dir"> <fileset dir="${dir}" id="fileset"/> <pathconvert refid="fileset" property="dir.contains-files" setonempty="false"/> </target> <target name="git.clone" depends="check.dir" unless="dir.contains-files"> <exec executable="git"> <arg value="clone"/> <arg value="${repo}"/> <arg value="${dir}"/> </exec> </target> <target name="git.fetch" depends="check.dir" if="dir.contains-files" > <exec executable="git" dir=

How to check if a date cell in Excel is empty?

别来无恙 提交于 2019-11-29 13:36:33
If feels like this should be really easy but I dont get it to work without retrieving the value of the cell again. To start with, I have 2 date cells: Dim agreedDate As Date Dim completedDate As Date THIS WORKS .. (but looks messy) agreedDate = Worksheets("Data").Cells(Counter, 7).Value completedDate = Worksheets("Data").Cells(Counter, 9).Value If (IsEmpty(Worksheets("Data").Cells(Counter, 7).Value) = True) Or (IsEmpty(Worksheets("Data").Cells(Counter, 9).Value) = True) Then [.. do stuff] End If THIS DOES NOT WORK - WHY NOT?! agreedDate = Worksheets("Data").Cells(Counter, 7).Value

Check if an Edit Text that only accepts number is not empty and the number is equal or less than 100

自闭症网瘾萝莉.ら 提交于 2019-11-29 12:47:05
I'm building an application for receiving grades and I want to make sure that the Edit Texts are not empty and the values are less or equal to 100 I wrote this line but it crashes the application if(Integer.parseInt(editText.gettext().toString()) > 100 || editText.getText().toString().trim().length() == 0) { //Error message for example } and this is the logCat 09-04 18:21:06.331 8649-8649/com.example.nima.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.nima.myapplication, PID: 8649 java.lang.IllegalStateException: Could not execute method of the activity at android