convert

Java: how to convert a List<?> to a Map<String,?> [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: This question already has an answer here: Java: How to convert List to Map 16 answers I would like to find a way to take the object specific routine below and abstract it into a method that you can pass a class, list, and fieldname to get back a Map. If I could get a general pointer on the pattern used or , etc that could get me started in the right direction. Map < String , Role > mapped_roles = new HashMap < String , Role >(); List < Role > p_roles = ( List < Role >) c . list (); for ( Role el : p_roles ) { mapped_roles . put (

In python, how to convert a hex ascii string to raw internal binary string?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In python, how to convert a hex ASCII string to binary string? Example: 01000001B8000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435362021222324 Needs to be converted to a binary string. ( 0A need to be converted to 1010 , not to ASCII bit 1000001 which is 65 ) edit : Changed "raw binary" in question to "raw internal binary" string for better clarity. 回答1: import base64 data = base64.b16decode("01000001B8000102030405") 回答2: Is this what you're searching for? hex_string = '0A' '{0:b}'

convert String to MD5

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Ok I am trying to write a basic converter of a string to md5 hash code but when I run my program I keep getting an error that say's: Traceback (most recent call last): File "C:\Users\Shane\Documents\Amer CISC\lab4.py", line 30, in <module> assertEqual (computeMD5hash("The quick brown fox jumps over the lazy dog"),("9e107d9d372bb6826bd81d3542a419d6")) File "C:\Users\Shane\Documents\Amer CISC\lab4.py", line 27, in computeMD5hash m.update(string) TypeError: Unicode-objects must be encoded before hashing My code looks like this: def

How to convert SimpleXMLObject into PHP Array?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Consider the following code: $string = '<device> <id>1234</id> <label>118</label> <username>root</username> <password>helloWorld</password> <hardware> <memory>4GB RAM</memory> <storage_drives> <storage_drive_1>2TB SATA 7,200RPM</storage_drive_1> <storage_drive_2>1TB SATA 7,200RPM</storage_drive_2> <storage_drive_3>Not Applicable</storage_drive_3> <storage_drive_4>Not Applicable</storage_drive_4> </storage_drives> </hardware> </device>'; $xml = new SimpleXMLElement($string); $deviceDetails = Array(); foreach($xml as $element){ $tag = $element

convert csv to netcdf

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to convert a .csv file to a netCDF4 via Python but I am having trouble figuring out how I can store information from a .csv table format into a netCDF. My main concern is how do we declare the variables from the columns into a workable netCDF4 format? Everything I have found is normally extracting information from a netCDF4 to a .csv or ASCII. I have provided the sample data, sample code, and my errors for declaring the appropriate arrays. Any help would be much appreciated. The sample table is below: Station Name Country Code

Python: convert 2 ints to 32 float

匿名 (未验证) 提交于 2019-12-03 02:19:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I combine 2 ints to a single 32bit IEEE floating point ? (each of the 2 ints represent 16 bit) And in the opposite direction: How can I transform a python float into 2 16 bit ints? (I need this because of modbus protocol - where 2x16 bit registers are treated as single 32 floating point number) 回答1: This code takes the 16 bits integers i1 and i2 and convert them to the floating point number 3.14, and vice versa. from struct import * # Two integers to a floating point i1 = 0xC3F5 i2 = 0x4840 f = unpack('f',pack('>HH',i1,i2))[0] #

Convert QUrl with percent encoding into string

匿名 (未验证) 提交于 2019-12-03 02:18:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I use a URL entered by the user as text to initialize a QUrl object. Later I want to convert the QUrl back into a string for displaying it and to check it using regular expression. This works fine as long as the user does not enter any percent encoded URLs. Why doesn't the following example code work? qDebug() << QUrl("http://test.com/query?q=%2B%2Be%3Axyz%2Fen").toDisplayString(QUrl::FullyDecoded); It simply doesn't decode any of the percent-encoded characters. It should print "http://test.com/query?q=++e:xyz/en" but it actually prints

How to convert Linux 32-bit gcc inline assembly to 64-bit code? [closed]

匿名 (未验证) 提交于 2019-12-03 02:18:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm attempting to convert RR0D Rasta Ring 0 Debugger from 32-bit mode to 64-bit mode (long mode) in Linux, using gcc. I'm familiar with x86 32-bit assembly (in MS-DOS environment) but I'm a beginner in x86 64-bit assembly and in Linux assembly programming in general. This project is for production use (I need a working non-source debugger), but I also attempt to learn how to do the 32-bit to 64-bit conversion. If possible, I attempt to find a universal way to do 32-bit to 64-bit conversion that could be done on any 32-bit program using

pandas convert strings to float for multiple columns in dataframe

匿名 (未验证) 提交于 2019-12-03 02:18:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm new to pandas and trying to figure out how to convert multiple columns which are formatted as strings to float64's. Currently I'm doing the below, but it seems like apply() or applymap() should be able to accomplish this task even more efficiently...unfortunately I'm a bit too much of a rookie to figure out how. Currently the values are percentages formatted as strings like '15.5%' for column in ['field1', 'field2', 'field3']: data[column] = data[column].str.rstrip('%').astype('float64') / 100 回答1: Starting in 0.11.1 (coming out this

sql server convert date to string MM/DD/YYYY

匿名 (未验证) 提交于 2019-12-03 02:18:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using SQL Server 2008. I have the following: select convert(varchar(20),fmdate) from Sery How do I convert the date to string such that it show as MM/DD/YYYY 回答1: That task should be done by the next layer up in your software stack. SQL is a data repository, not a presentation system You can do it with CONVERT(VARCHAR(10), fmdate(), 101) But you shouldn't 回答2: select convert(varchar(10), fmdate, 101) from sery 101 is a style argument. Rest of 'em can be found here. T-SQL Cast / Convert date to string 回答3: select convert(varchar(10),