OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Why will node include annotation when i use 2to3/lib2to3/fix_print.py

  • Thread starter Thread starter haifu_qin
  • Start date Start date
H

haifu_qin

Guest
python file

Code:
# -*- coding: utf-8 -*-

print 'original python file'

fix_print.py

Code:
class FixPrint(fixer_base.BaseFix):

    BM_compatible = True

    PATTERN = """
              simple_stmt< any* bare='print' any* > | print_stmt
              """

    def transform(self, node, results):
        assert results
        bare_print = results.get("bare")

when i use 2to3/lib2to3/fix_print.py to transform the python file.

if i print the node,it shows

Code:
# -*- coding: utf-8 -*-

print 'original python file'

why does the node include the annotation "# -- coding: utf-8 --"

Thank you very much if you can explain this.
<p>python file</p>
<pre><code># -*- coding: utf-8 -*-

print 'original python file'
</code></pre>
<p>fix_print.py</p>
<pre><code>class FixPrint(fixer_base.BaseFix):

BM_compatible = True

PATTERN = """
simple_stmt< any* bare='print' any* > | print_stmt
"""

def transform(self, node, results):
assert results
bare_print = results.get("bare")
</code></pre>
<p>when i use 2to3/lib2to3/fix_print.py to transform the python file.</p>
<p>if i print the node,it shows</p>
<pre><code># -*- coding: utf-8 -*-

print 'original python file'
</code></pre>
<p>why does the node include the annotation "# -<em>- coding: utf-8 -</em>-"</p>
<p>Thank you very much if you can explain this.</p>
 

Latest posts

Top