enumeration

Get all functions of an object in JavaScript

不问归期 提交于 2019-11-30 15:09:55
问题 For example, Math.mymfunc = function (x) { return x+1; } will be treated as a property and when I write for(var p in Math.__proto__) console.log(p) it will be shown. But the rest of Math functions will not. How can I get all functions of a Math object? 回答1: Object.getOwnPropertyNames(Math); is what you are after. This logs all of the properties provided you are dealing with an EcmaScript 5 compliant browser. var objs = Object.getOwnPropertyNames(Math); for(var i in objs ){ console.log(objs[i]

Get all functions of an object in JavaScript

家住魔仙堡 提交于 2019-11-30 13:48:01
For example, Math.mymfunc = function (x) { return x+1; } will be treated as a property and when I write for(var p in Math.__proto__) console.log(p) it will be shown. But the rest of Math functions will not. How can I get all functions of a Math object? Lime Object.getOwnPropertyNames(Math); is what you are after. This logs all of the properties provided you are dealing with an EcmaScript 5 compliant browser. var objs = Object.getOwnPropertyNames(Math); for(var i in objs ){ console.log(objs[i]); } var functionNames = []; Object.getOwnPropertyNames(obj).forEach(function(property) { if(typeof obj

How to read a properties file in java in the original order [duplicate]

六眼飞鱼酱① 提交于 2019-11-30 12:25:22
问题 This question already has answers here : Pulling values from a Java Properties file in order? (15 answers) Closed 5 years ago . I need to read a properties file and generate a Properties class in Java. I do so by using: Properties props = new Properties(); props.load(new FileInputStream(args[0])); for (Enumeration e = props.propertyNames(); e.hasMoreElements();) { } However, the properties returned by props.propertyName is not in the order of the original properties file. I understand that

Is there a way to iterate through all enum values? [duplicate]

人走茶凉 提交于 2019-11-30 10:52:09
Possible Duplicate: C#: How to enumerate an enum? The subject says all. I want to use that to add the values of an enum in a combobox. Thanks vIceBerg string[] names = Enum.GetNames (typeof(MyEnum)); Then just populate the dropdown withe the array I know others have already answered with a correct answer, however, if you're wanting to use the enumerations in a combo box, you may want to go the extra yard and associate strings to the enum so that you can provide more detail in the displayed string (such as spaces between words or display strings using casing that doesn't match your coding

How do I convert an integer to an enumerated type?

五迷三道 提交于 2019-11-30 08:04:37
I know how to convert an enumerated type to an integer. type TMyType = (mtFirst, mtSecond, mtThird); var ordValue:integer; enumValue:TMyType; ... ordValue:= Ord(mtSecond); // result is 1 But how do I do the inverse operation and convert an integer to an enumerated type? ain As Ken answered, you just cast it. But to make sure you have correct value you can use code like: if (ordValue >= Ord(Low(TMyType))) and (ordValue <= Ord(High(TMyType))) then enunValue := TMyType(ordValue) else raise Exception.Create('ordValue out of TMyType range'); You can cast the integer by typecasting it to the

Enumeration of combinations of N balls in A boxes?

独自空忆成欢 提交于 2019-11-30 07:43:21
I want to enumerate all possible combinations of N balls in A boxes. example: I have 8 balls to deal in 3 boxes : box_1 box_2 box_3 case-1 8 0 0 case-2 0 8 0 case-3 0 0 8 case-4 7 1 0 case-5 7 0 1 case-6 6 2 0 ... My first problem is that I need A loops to perform this but I want that A and N to be user's inputs. So how to do without writing all possible number of loops users could need? a and N will be value between 2 and ~800, so it will be strongly demanding in computation time so. How to optimize that algorithm? I would be grateful if you answer me using python language. thanks for all

Dictionary enumeration in C#

此生再无相见时 提交于 2019-11-30 06:02:58
How do I enumerate a dictionary? Suppose I use foreach() for dictionay enumeration. I can't update a key/value pair inside foreach() . So I want some other method. To enumerate a dictionary you either enumerate the values within it: Dictionary<int, string> dic; foreach(string s in dic.Values) { Console.WriteLine(s); } or the KeyValuePairs foreach(KeyValuePair<int, string> kvp in dic) { Console.WriteLine("Key : " + kvp.Key.ToString() + ", Value : " + kvp.Value); } or the keys foreach(int key in dic.Keys) { Console.WriteLine(key.ToString()); } If you wish to update the items within the

multi-column factorize in pandas

六月ゝ 毕业季﹏ 提交于 2019-11-30 05:09:35
The pandas factorize function assigns each unique value in a series to a sequential, 0-based index, and calculates which index each series entry belongs to. I'd like to accomplish the equivalent of pandas.factorize on multiple columns: import pandas as pd df = pd.DataFrame({'x': [1, 1, 2, 2, 1, 1], 'y':[1, 2, 2, 2, 2, 1]}) pd.factorize(df)[0] # would like [0, 1, 2, 2, 1, 0] That is, I want to determine each unique tuple of values in several columns of a data frame, assign a sequential index to each, and compute which index each row in the data frame belongs to. Factorize only works on single

How do I import a COM object namespace/enumeration in Python?

☆樱花仙子☆ 提交于 2019-11-30 04:15:35
I'm relatively new to programming/python, so I'd appreciate any help I can get. I want to save an excel file as a specific format using Excel through COM. Here is the code: import win32com.client as win32 def excel(): app = 'Excel' x1 = win32.gencache.EnsureDispatch('%s.Application' % app) ss = x1.Workbooks.Add() sh = ss.ActiveSheet x1.Visible = True sh.Cells(1,1).Value = 'test write' ss.SaveAs(Filename="temp.xls", FileFormat=56) x1.Application.Quit() if __name__=='__main__': excel() My question is how do I specify the FileFormat if I don't explicitly know the code for it? Browsing through the

Do C++ enums Start at 0?

南楼画角 提交于 2019-11-30 04:12:17
If I have an enum that does not assign numbers to the enumerations, will it's ordinal value be 0? For example: enum enumeration { ZERO, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE }; I've been able to find a post citing that the C99 standard requires a 0 ordinal number . But I know C++ ignores several things in the C99 standard. And I've also been able to find a post witnessing the compiler using an ordinal value of 1 , something I also seem recall seeing, though I can't say how long ago that was. I would really like to see an answer that confirms this for C++, but I'd also like to