我有数据结构,我在其中定义了列表。
data_items = [ {"ID":0x0202, "Name":"Country"},
{ "ID":0x2007, "Name":"Sports"}]
我想导入完整的ID'值包括' 0',例如:
'0202'
'2007'
现在打印如下:
'202'
'2007'
代码:
Input = 1
SMI = data_items[Input-1]['ID']
hex(SMI)[2:]
建议我如何进行?
答案 0 :(得分:0)
hex
删除任何前导零。如果您希望在字符串中保留4个字符的长度,请尝试执行public class Model_image {
String str_folder;
ArrayList<String> all_imagepath;
public void setStr_folder(String str_folder)
{
this.str_folder = str_folder;
}
public void setAll_imagepath(ArrayList<String> all_imagepath)
{
this.all_imagepath = all_imagepath;
}
public String getStr_folder()
{
return str_folder;
}
public ArrayList<String> getAll_imagepath()
{
return all_imagepath;
}
}
,其中它将为前导零,直到达到指定的长度。
答案 1 :(得分:-1)
试试这个:
SMI = data_items[Input-1]['ID']
SMI = str(SMI).split('0x')[1]