All Questions
16 questions
0
votes
0
answers
334
views
Porting Python2 to Python3 - Reading Bytes from a socket and using unpack() correctly
There is code here that I am trying to convert from Python2 to Python3. In this section of code, data is received from a socket. data is declared to be an empty string and then concatenated. This is ...
0
votes
1
answer
270
views
Loading Images from a LevelDB in python 2.7
I am facing a problem with python (2.7) "strings".
I am using a LevelDB and want to load an image from the database and save it to disk (e.g., as test.jpeg).
To access the db I am using the plyvel ...
4
votes
2
answers
6k
views
First character of string in Python
In Python I have got this string
string = "Ľubomír Mezovský"
I need to get only first character of it. But when I tried string[0] it returned �. When I tried string[:2] it worked well. My question is ...
8
votes
3
answers
124k
views
Python UnicodeEncodeError: 'ascii' codec can't encode character in position 0: ordinal not in range(128) [duplicate]
In Python 2.7, see the following error, when trying to cast type to ensure it matches the output schema.
UnicodeEncodeError: 'ascii' codec can't encode character in position
0: ordinal not in ...
0
votes
1
answer
107
views
Replacing sometimes causes exceptions in unicode strings
In the Python Unicode Howto, it says:
Note that the arguments to these [string] methods can be Unicode strings or
8-bit strings. 8-bit strings will be converted to Unicode before
carrying out the ...
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 ...
0
votes
1
answer
673
views
Python 2.7 String decode failed.
I expect the following code works fine, but it's failing, what is the reason?
>>> s = 'ö'
>>> s.decode('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, ...
0
votes
0
answers
17
views
What is the difference between printing a variable and just entering a variable name in the Python 2.7 REPL? [duplicate]
The specific difference I encountered was with Unicode strings. First, I initialized a Unicode string with some Unicode characters in it. I then initialized in another variable the encoded Unicode ...
2
votes
2
answers
12k
views
How to change a string to Unicode in Python 2?
I have a string like s1 = "\xed\xf3\xb4\x90".
>>> x = u"\xed\xf3\xb4\x90"
>>> print x
íó´
How could I use s1 to print this?
I have tried:
s1= "\xed\xf3\xb4\x90"
print unicode(s1)
...
0
votes
2
answers
87
views
Error in encoding string
This might be a very simple problem but i am just not able to solve it.
In my python console I do :
request.request.data.get('comment')
I get {u'price': u'21', u'unit': u'30\xd730', u'name': u'test'...
-1
votes
1
answer
689
views
how to combine non ascii char with string in python 2.7
I have a string 'My Name' and variable customerName with 'sünil' data. I want to combine both so I tried
'My Name' + customerName
but this is showing error
UnicodeDecodeError: 'ascii' codec can't ...
1
vote
2
answers
2k
views
Python, UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 1718: ordinal not in range(128)
I am trying a simple parsing of a file and get the error due to special characters:
#!/usr/bin/env python ...
2
votes
2
answers
6k
views
Python putting r before unicode string variable
For static strings, putting an r in front of the string would give the raw string (e.g. r'some \' string'). Since it is not possible to put r in front of a unicode string variable, what is the minimal ...
1
vote
1
answer
105
views
What does str.encode expect as input?
I was hoping to use unicode instead of str for all strings in my project. I am trying to use the str.encode method but can't make out from the documentation what the encode method exactly does or ...
0
votes
2
answers
107
views
How do I properly format this string in Python?
I am parsing through a folder of txt files. These text files have a Dell computer service tag on the second line. I'd like to grab the second line and eventually place it in a csv spreadsheet.
When ...