representation

Is the semantic of the data integral part of REST?

北城余情 提交于 2019-12-08 04:58:52
问题 This is a follow up on a question asking for an explanation of REST. As you can see from the comments to my answer, we've had a small argument with Darrel Miller on the best media representation of the resources. We've had a further email discussion that resulted in this question. The main difference between Darrel's and mine understanding of REST is whether the semantic of the data is part of the REST API. Darrel believes (my interpretation of his words :-)) that the semantic of the data is

Malformed String error - Python - converting string repr. of dictionary

大憨熊 提交于 2019-12-08 04:23:44
问题 When I do ast.literal_eval() , I get ValueError: malformed string for the line below z = ast.literal_eval(a) . Why is this not working? (Pls. note - "something" in the line below has 4 or more namedtuples) for thing in something: a = thing._asdict() z = ast.literal_eval(a) print z If I do a simple print a , I get OrderedDict([('a', 0.0), ('b', 0.0), ('c', 0.0), ('d', 100.0)]) Without ast.literal_eval(a) , when I try to use "a" as a dictionary, it raises AttributeError: 'str' object has no

Hint for lookup table set bit count algorithm

末鹿安然 提交于 2019-12-07 14:42:13
问题 I am looking at solution for the set bit count problem (given a binary number, how to efficiently count how many bits are set). Here, http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetNaive, I have found some methods. What about the lookup table method? I dont understand what properties of binary representation / number make it work. static const unsigned char BitsSetTable256[256] = { # define B2(n) n, n+1, n+1, n+2 # define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2) # define B6(n)

Hint for lookup table set bit count algorithm

落爺英雄遲暮 提交于 2019-12-05 21:25:52
I am looking at solution for the set bit count problem (given a binary number, how to efficiently count how many bits are set). Here, http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetNaive , I have found some methods. What about the lookup table method? I dont understand what properties of binary representation / number make it work. static const unsigned char BitsSetTable256[256] = { # define B2(n) n, n+1, n+1, n+2 # define B4(n) B2(n), B2(n+1), B2(n+1), B2(n+2) # define B6(n) B4(n), B4(n+1), B4(n+1), B4(n+2) B6(0), B6(1), B6(1), B6(2) }; unsigned int v; // count the number of

Changing internal representation in runtime

孤街浪徒 提交于 2019-12-05 07:37:14
问题 UPDATE The main questions remain the ones under the example, but I guess it boils down to : **If you have a type where 99% of the values could be represented in one fast, powerfull type, and only 1% in a very heavy type, (say int vs. BigInteger) How to represent it?? ** A school we learned a lot about internal representations, but never how to change it at runtime. I mean : suppose you have a class representing a decimal, but you use an integer to represent it internal, until you actually

UnicodeDecodeError: 'ascii' codec can't decode

独自空忆成欢 提交于 2019-12-05 05:20:20
I'm reading a file that contains Romanian words in Python with file.readline(). I've got problem with many characters because of encoding. Example : >>> a = "aberație" #type 'str' >>> a -> 'abera\xc8\x9bie' >>> print sys.stdin.encoding UTF-8 I've tried encode() with utf-8, cp500 etc, but it doesn't work. I can't find which is the right Character encoding I have to use ? thanks in advance. Edit: The aim is to store the word from file in a dictionnary, and when printing it, to obtain aberație and not 'abera\xc8\x9bie' Claudiu What are you trying to do? This is a set of bytes: BYTES = 'abera\xc8

Converting a hex-string representation to actual bytes in Python

我们两清 提交于 2019-12-04 12:07:31
问题 i need to load the third column of this text file as a hex string http://www.netmite.com/android/mydroid/1.6/external/skia/emoji/gmojiraw.txt >>> open('gmojiraw.txt').read().split('\n')[0].split('\t')[2] '\\xF3\\xBE\\x80\\x80' how do i open the file so that i can get the third column as hex string: '\xF3\xBE\x80\x80' i also tried binary mode and hex mode, with no success. 回答1: You can: Remove the \x -es Use .decode('hex') on the resulting string Code: >>> '\\xF3\\xBE\\x80\\x80'.replace('\\x',

C# binary constants representation

一世执手 提交于 2019-12-04 11:04:39
问题 I am really stumped on this one. In C# there is a hexadecimal constants representation format as below : int a = 0xAF2323F5; is there a binary constants representation format? 回答1: As of C#7 you can represent a binary literal value in code: private static void BinaryLiteralsFeature() { var employeeNumber = 0b00100010; //binary equivalent of whole number 34. Underlying data type defaults to System.Int32 Console.WriteLine(employeeNumber); //prints 34 on console. long

Transient REST Representations

扶醉桌前 提交于 2019-12-04 10:09:44
Let's say I have a RESTful, hypertext-driven service that models an ice cream store. To help manage my store better, I want to be able to display a daily report listing quantity and dollar value of each kind of ice cream sold. It seems like this reporting capability could be exposed as a resource called DailyReport. A DailyReport can be generated quickly, and there doesn't seem to be any advantage to actually storing reports on the server. I only want a DailyReport for some days, other days I don't care about getting a DailyReport. Furthermore, storing DailyReports on the server would

Biggest number in computer ever

六月ゝ 毕业季﹏ 提交于 2019-12-04 07:41:43
问题 Just asked by my 5 year old kid: what is the biggest number in the computer? We are not talking about max number for a specific data types, but the biggest number that a computer can represent. Infinity is not allowed. UPDATE my kid always wants to print as well, so lets say the computer needs to print this number and the kid to know that its a big number. Of course, in practice we won't print because theres not enough trees. 回答1: This question is actually a very interesting one which