Initially there is a string

>>> string = '50.6,383,149,1.9,786, 4 -4, [Ne]3s²3p², DIA,5.43' 

which was broken into a leaf by separator ","

 >>> print(re.split(r',', string)) ['50.6', '383', '149', '1.9', '786', ' 4 -4', ' [Ne]3s\xc2\xb23p\xc2\xb2', ' DIA', '5.43'] 

The element [Ne] 3s²3p² has been translated into byte code '[Ne] 3s \ xc2 \ xb23p \ xc2 \ xb2'.

It can be successfully printed in human form.

 >>> print('[Ne]3s\xc2\xb23p\xc2\xb2'.decode('utf-8')) [Ne]3s²3p² 

But is it possible to translate it into a human-readable form and enter it back into the list?

    1 answer 1

    You do not have a bytecode (the contents of *.pyc files), but simply a textual representation of an object of type str in Python, returned by the repr() function.

    You see it, because by default, when printing a list in Python, repr() is called for each list item.

    If you want a different result, format the list returned by the re.split() function yourself, for example, to print each list item on a separate line:

     for элемент in ваш_список: print(элемент) 

    Additionally, the result hints that you are using Python 2. In this case, either add from __future__ import unicode_literals at the very top from __future__ import unicode_literals or explicitly use the u"" prefix to create a Unicode line (from a constant in the source code) instead of using bytes, otherwise you can skip get when typing .

    • Added an explanation to the question, and tried the solution proposed by you, it gives an error - while1pass
    • one
      @ while1pass: I answered the question of how he stood by you. Now you have another question — do not change the question if it makes invalid the already published answers. Ask a separate question with a problem that you already really have (if the input is in a file, you should say so in the question — how to read Unicode from a file is different from how to create a Unicode line in the source code using a string constant such as u'abc' ). Show only the code that you really use (of course, for the question it needs to be reduced ) - jfs
    • new question created here - while1pass