I guess I get to solve my own thread (thanks again to the Natural Language Toolkit's online tutorial). The function repr() appears to give me what I need:
[code=Python]
line = u'\u0144'
line_utf = line.encode('ut f8')
print 'line = ', line_utf
print 'line repr = ', repr(line_utf)
[/code]
Output:
line = Å„
line repr = '\xc5\x84'
It's the...
User Profile
Collapse
-
If you want to count all members of the list without specifying which one to count, you could use this reasonably standard count method (this is from the Natural Language Toolkit's online Python tutorial: http://nltk.org/doc/en/programming.htm l)
[code=Python]
alist = [1,2,3,4,4,4]
count = {}
for thing in alist: # iterates though each member of your list
if thing not in count: # checks...Leave a comment:
-
newbie: how do I test a byte string?
How do I test a byte string in Python? I want to manually convert (no libraries or functions) a UTF-8 string into UTF-16.
My basic solution is to read from the stream some number of UTF-8 bytes, convert them into codepoints, then convert those codepoints into UTF-16 bytes. I want to code this myself, but I don't understand how to test the actual byte sequence.
Let's say I use the following code to ensure I have a UTF-8... -
-
help for newbie -- using find() for exact match
I'm trying to modify a find/replace script which iterates through a file A and makes replacements defined in a csv file B. My original goal was to change any line in file A containing a search string (in whole or as a substring) defined in file B. File B contains both the search string and the string it should be changed into.
Example file A
whippy
slippy
ippy
slippy
snoob
flop
bloppy...
No activity results to display
Show More
Leave a comment: