All Questions
14 questions
0
votes
1
answer
704
views
How to validate that a string is a valid UTF-8 string in python 2.7
I have the following string -
"\xed\xad\x80\xed\xb1\x93"
When using this string to execute queries in the PostgreSQL DB, it raises the following error -
DataError: invalid byte sequence ...
0
votes
2
answers
98
views
How to make `format` function in python 2 to work with `unicode` type objects with UTF-8 encoding?
I have huge code base with lots of format functions. I want to pass unicode type objects as arguments like:
# -*- coding: UTF-8 -*-
x = u"ñö"
print isinstance(x,unicode)#prints "True"
y = "Hello {0}"...
0
votes
0
answers
57
views
Does str type use ASCII encoder/decoder?
On Python 2 REPL:
>>> sys.stdin.encoding
'UTF-8'
So my understanding is, on giving the below expression on stdin
>>> stringLiteral = 'abc'
the interpreter reads the expression ...
2
votes
3
answers
2k
views
Recover UTF-8 encoding in string
I'm working on my python script to extract multiple strings from a .csv file but I can't recover the Spanish characters (like á, é, í) after I open the file and read the lines.
This is my code so far:
...
7
votes
4
answers
26k
views
UTF-8 string in python 2 and 3
The following code works in Python 3:
people = [u'Nicholas Gyeney', u'Andr\xe9']
writers = ", ".join(people)
print(writers)
print("Writers: {}".format(writers))
And produces the following output:
...
1
vote
0
answers
2k
views
Convert utf-8 string to bytes and back in Python 2.7
I have a program which takes a string, makes a list with its byte representation, and then converts the list back to a string. This is really easy if the string contains only ASCII characters:
def ...
-2
votes
2
answers
503
views
String encoding of win32print results
I have a non-literal string that is programmatically obtained from the title of a printed document online.
When I try to commit it to MongoDB, I get:
bson.errors.InvalidStringData: strings in ...
5
votes
1
answer
2k
views
Concatenate left-to-right and right-to-left languages (arabic, etc.)
I need to process some language files. Most of them are in left-to-right languages, but some are in right-to-left languages. Processing the right-to-left languages ir problematic.
I have read a ...
0
votes
1
answer
2k
views
removing the question mark in python output
I'm trying to remove last character with [:-1] from the words that aren't written in latin alphabet (header has # -*- coding: utf-8 -*- set) and removed character gets replaced with ? in terminal ...
0
votes
1
answer
219
views
Python 2.7 : Removal of accents from an <str> - Still won't work
I am receiving str datas trough a websocket connection, and trying to remove accents (as well as lowering the text / turning ' ' into '-' ..)
And I, even with the hundreds of questions having being ...
2
votes
1
answer
100
views
Regex on Python prints Garbage when use char class
Python 2.7
I am processing a utf-8 encoded file (greek) and seems that regex has some issues.
Regex seems to work fine when i do not use char class. When i do :
text = re.sub('αυ','kk',text,...
1
vote
1
answer
145
views
Convert Python's internal str to print equivalent
Currently I have:
>> class_name = 'AEROSPC\xc2\xa01A'
>> print(class)
>> AEROSPC 1A
>> 'AEROSPC 1A' == class_name
>> False
How can I convert class_name into '...
1
vote
2
answers
403
views
How do I convert a bitstring to an utf-8 string?
I use the bitstring module. What is the easiest way to convert a bitstring to an utf-8 string?
0
votes
1
answer
134
views
Cannot save utf-8 encoded stuff in string
I am querying the Twitter API and receive utf-8 encoded answers. Now I want to save these answers in a string with the format() function. This is what I have so far (and I have tried a lot of ...