我试图在PyQt5小部件中显示一些unicode字母,如:
data['image']
其中UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bc' in position 8: ordinal not in range(128)
是从yaml配置文件读取的unicode字符串。
然而,当使用python2运行时,我收到以下错误:
@IgnoreExtraProperties
public class Product {
public String uid;
public String seller;
public String name;
public String description;
public String city;
public double price = 0.0;
public List<Uri> images = new ArrayList<>();
public Product () {
}
public Product(String uid, String seller, String name, String description, String city, double price, List<Uri> images) {
this.uid = uid;
this.seller = seller;
this.name = name;
this.description = description;
this.city = city;
this.price = price;
this.images = images;
}
// [START post_to_map]
@Exclude
public Map<String, Object> toMap() {
HashMap<String, Object> result = new HashMap<>();
result.put("uid", uid);
result.put("seller", seller);
result.put("name", name);
result.put("description", description);
result.put("city", city);
result.put("price", price);
result.put("images", images);
return result;
}
}
如果使用python3运行相同的程序,它可以正常工作。
我的问题是,有没有办法让代码可以从python2和python3运行?