我在python 3.3.4中使用"decode"方法遇到了一些问题.这是我的代码:
for lines in open('file','r'):
decodedLine = lines.decode('ISO-8859-1')
line = decodedLine.split('\t')
Run Code Online (Sandbox Code Playgroud)
但是我无法解决这个问题:
AttributeError: 'str' object has no attribute 'decode'
Run Code Online (Sandbox Code Playgroud)
你有什么想法?谢谢
在我的程序中,我必须在两个活动之间传递自定义对象.单击第一个活动中列表视图的项目后,第二个活动开始.第一个活动的OnItemClick中的代码是:
public void onItemClick(AdapterView<?> arg0, View v,
int position, long arg3) {
Intent userProfileIntent = new Intent(v.getContext(),
UserProfileActivity.class);
Bundle bundle = new Bundle();
bundle.putSerializable("contact", new ContactSerializer(
sortContacts.get(position)));
userProfileIntent.putExtras(bundle);
v.getContext().startActivity(userProfileIntent);
}
Run Code Online (Sandbox Code Playgroud)
第二项活动的代码是:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userprofile_layout);
ContactSerializer serializer = (ContactSerializer) getIntent()
.getSerializableExtra("contact");
CustomObj contact = serializer.getContact();
Run Code Online (Sandbox Code Playgroud)
并且可序列化对象的代码是:
public class ContactSerializer implements Serializable {
private CustomObj contact;
public ContactSerializer(CustomObj contact) {
this.contact = contact;
}
public CustomObj getContact() {
return contact;
}
Run Code Online (Sandbox Code Playgroud)
}
我的LogCat是:
07-10 13:07:57.777: E/AndroidRuntime(1333): FATAL EXCEPTION: …Run Code Online (Sandbox Code Playgroud)