convert

Convert Bytes to Floating Point Numbers in Python

匿名 (未验证) 提交于 2019-12-03 08:39:56
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a binary file that I have to parse and I'm using Python. Is there a way to take 4 bytes and convert it to a single precision floating point number? 回答1: >>> import struct >>> struct.pack('f', 3.141592654) b'\xdb\x0fI@' >>> struct.unpack('f', b'\xdb\x0fI@') (3.1415927410125732,) >>> struct.pack('4f', 1.0, 2.0, 3.0, 4.0) '\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@' 回答2: You'll want the struct package. 文章来源: Convert Bytes to Floating Point Numbers in Python

How do I convert C# characters to their hexadecimal code representation

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: What I need to do is convert a C# character to an escaped unicode string: So, 'A' - > "\x0041". Is there a better way to do this than: char ch = 'A'; string strOut = String.Format("\\x{0}", Convert.ToUInt16(ch).ToString("x4")); 回答1: Cast and use composite formatting : char ch = 'A'; string strOut = String.Format(@"\x{0:x4}", (ushort)ch); 文章来源: How do I convert C# characters to their hexadecimal code representation

MongoDB: can't convert from BSON type EOO to Date

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I' trying to use aggregation framework (with ruby) and project the date like this: db['requests'].aggregate([ {"$project" => { _id: 0, method: '$method', user: '$user', year: {'$year' => '$timestamp'} }}]) the document is like this one: { _id: ObjectId("5177d7d7df26358289da7dfd"), timestamp: ISODate("2013-04-12T03:58:05+00:00"), method: "POST", status: "200", inputsize: "874", outputsize: "4981", user: "131" } but i get the following error: Mongo::OperationFailure: Database command 'aggregate' failed: (errmsg: 'exception: can't convert from

How to convert a string to a list in Python?

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How do you convert a string into a list? Say the string is like text = "a,b,c" . After the conversion, text == ['a', 'b', 'c'] and hopefully text[0] == 'a' , text[1] == 'b' ? 回答1: Like this: >>> text = 'a,b,c' >>> text = text.split(',') >>> text [ 'a', 'b', 'c' ] Alternatively, you can use eval() if you trust the string to be safe: >>> text = 'a,b,c' >>> text = eval('[' + text + ']') 回答2: Just to add on to the existing answers: hopefully, you'll encounter something more like this in the future: >>> word = 'abc' >>> L = list(word) >>> L ['a',

How to convert List to a JSON Object using GSON?

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a List which I need to convert into JSON Object using GSON. My JSON Object has JSON Array in it. public class DataResponse { private List<ClientResponse> apps; // getters and setters public static class ClientResponse { private double mean; private double deviation; private int code; private String pack; private int version; // getters and setters } } Below is my code in which I need to convert my List to JSON Object which has JSON Array in it - public void marshal(Object response) { List<DataResponse.ClientResponse> clientResponse =

How to convert multi-dimensional array into single array using php?

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: After implementing database queries, I am getting the multi-dimensional array below. Two Dimensional Array Array ( [0] => Array ( [t1] => test1 ) [1] => Array ( [t2] => test2 ) [2] => Array ( [t3] => test3 ) [3] => Array ( [t4] => test4 ) [4] => Array ( [t5] => test5 ) ) but I want to convert it to a single dimensional array, like the format below. One Dimensional Array Array ( t1 => test1 t2 => test2 t3 => test3 t4 => test4 t5 => test5 ) Please help me to do so 回答1: I think you can use array_reduce() function. For example: $multi= array(0 =

How do i convert NSAttributedString into HTML string?

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: As the title tells,now i can simple convert HTML into NSAttributedString with initWithHTML:documentAttributes: , but what i want to do here is reverse. Is there any 3rd party library to achieve this? @implementation NSAttributedString(HTML) -(NSString *)htmlForAttributedString{ NSArray * exclude = [NSArray arrayWithObjects:@"doctype", @"html", @"head", @"body", @"xml", nil ]; NSDictionary * htmlAtt = [NSDictionary dictionaryWithObjectsAndKeys:NSHTMLTextDocumentType, NSDocumentTypeDocumentAttribute, exclude,

convert string to hex in python

匿名 (未验证) 提交于 2019-12-03 08:36:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a script that calls a function that takes a hexadecimal number for an argument. The argument needs to the 0x prefix. The data source is a database table and is stored as a string, so it is returned '0x77'. I am looking for a way to take the string from the database and use it as an argument in hex form with the 0x prefix. This works: addr = 0x77 value = class.function(addr) The database entry has to be a string, as most of the other records do not have hexadecimal values in this column, but the values could be changed to make it

What is the best way to convert a SymPy matrix to a numpy array/matrix

匿名 (未验证) 提交于 2019-12-03 08:35:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am not sure if the approach I've been using in sympy to convert a MutableDenseMatrix to a numpy.array or numpy.matrix is a good current practice. I have a symbolic matrix like: g = sympy.Matrix( [[ x, 2*x, 3*x, 4*x, 5*x, 6*x, 7*x, 8*x, 9*x, 10*x] [x**2, x**3, x**4, x**5, x**6, x**7, x**8, x**9, x**10, x**11]] ) and I am converting to a numpy.array doing: g_func = lambda val: numpy.array( g.subs( {x:val} ).tolist(), dtype=float ) where I get an array for a given value of x . Is there a better built-in solution in SymPy to do that? Thank you

How to Convert NSString into CGPoint in iPhone

匿名 (未验证) 提交于 2019-12-03 08:35:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am getting the values from UITextfield into NSString , need to convert the values of NSString into CGPoint, Suppose if i enter 6,5 into textfield it should covert it into CGPoint. 回答1: See CGPointFromString (documentation in link). The string has to be in the format {x,y} so you would need to add those to the user input yourself: CGPoint myPoint = CGPointFromString ([ NSString stringWithFormat :@ "{%@}" , textField . text ]); Will return CGPointZero if the string is invalid. 转载请标明出处: How to Convert NSString into CGPoint in iPhone