Forwarded from leotastic: I started the scripting tutorial and ....

67 views
Skip to first unread message

Edward K. Ream

unread,
Nov 6, 2012, 10:07:15 AM11/6/12
to leo-e...@googlegroups.com
Note from EKR:  I mistakenly banned this user, which trashed the message.  I've unbanned the user, and here is the message:

QQQ
I started the scripting tutorial and the first lines

for p in c.all_positions():
    indent = '.' * p.level()
    print('%s%s' % (indent,p.h))

get me this error:

"UnicodeEncodeError: 'ascii' codec can't encode character u'\xdc' in position 3: ordinal not in range(128)"
QQQ

This script only works if no headline contains non-ascii text.  Sorry about that.  Here is a script that works, assuming your text is utf-8 encoded::

    @first # -*- coding: utf-8 -*-
   
    for p in c.all_positions():
        indent = '.' * p.level()
        print('%s%s' % (indent,g.toUnicode(p.h))

On Windows, this will print "byte hash" if the encoding of your character doesn't match the encoding of the console, but that is another matter :-)

HTH.  Unicode is a complex subject.  Please feel free to ask more questions.

Edward

leotastic

unread,
Nov 7, 2012, 12:27:30 PM11/7/12
to leo-e...@googlegroups.com
Thank you for the answer, but...

i think now theres something wrong with the installation ?

I tried the new script, made a script button and get this message in the log-pane:

exception executing script

  File "C:\Dokumente und Einstellungen\******\.leo\scriptFile.py", line 13

    

   ^

SyntaxError: invalid syntax

--------------------

  line 12:


When i open the scriptFile.py it looks like this:

# -*- coding: utf-8 -*-
#@+leo-ver=5
#@+node:Skript Test
#@@first
#import leo

for p in c.all_positions():
    indent = '.' * p.level()
    print('%s%s' % (indent,g.toUnicode(p.h))
   
   
#@-leo



The problem with "import leo" i handled with copying the sub-dir leo to the python/lib/site-packages.
Reply all
Reply to author
Forward
0 new messages