What is the difference between encode/decode?

I've never been sure that I understand the difference between str/unicode decode and encode.

I know that str().decode() is for when you have a string of bytes that you know has a certain character encoding, given that encoding name it will return a unicode string.

I know that unicode().encode() converts unicode chars into a string of bytes according to a given encoding name.

But I don't understand what str().encode() and unicode().decode() are for. Can anyone explain, and possibly also correct anything else I've gotten wrong above?

EDIT:

Several answers give info on what .encode does on a string, but no-one seems to know what .decode does for unicode.

Score: 181
Tags: python, string, unicode, character-encoding, python-2.x
Views: 107217
Date posted: 1/15/2009

CATALINA_OPTS vs JAVA_OPTS - What is the difference?

I was trying to find out the difference between Apache Tomcat variables - CATALINA_OPTS and JAVA_OPTS in SO and surprised to see that there is no question/answer posted here yet. So I thought of sharing it here (with answer) after finding out the difference. Check the answer/difference below.

NOTE: At the time of this posting, we're running Apache Tomcat v6.0.10 with JDK 6u32 on CentOS5 64-bit arch.

Score: 110
Tags: java, tomcat, jvm, tomcat6
Views: 72864
Date posted: 6/27/2012

CLR and CLI - What is the difference?

I want to know what exactly is the difference between CLR & CLI? From whatever I have read so far, it seems to indicate that CLI is a subset of CLR. But isn't everything in the CLR mandatory? What exactly may be left out of CLR to create a CLI?

Score: 52
Tags: .net, clr, command-line-interface
Views: 36998
Date posted: 1/26/2009

a vs a:link, What is the difference?

What is the differences between a {...} and a:link{...}?

Are there different usages, and benefits between them?

Score: 31
Tags: css, css-selectors, anchor, pseudo-class
Views: 7540
Date posted: 12/17/2009

Android preferences - what is the difference?

What is the difference, when I get preferences as:

PreferenceManager.getDefaultSharedPreferences(getBaseContext());

and

getPreferences(Context.MODE_PRIVATE);
Score: 12
Tags: android, android-preferences, android-sharedpreferences
Views: 5825
Date posted: 4/13/2011


2


© 2021 Search Overflow
Contributions licensed under cc by-sa