Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception on str decode & making it work in terminal #2

Open
pholat opened this issue Jan 26, 2019 · 1 comment
Open

Exception on str decode & making it work in terminal #2

pholat opened this issue Jan 26, 2019 · 1 comment

Comments

@pholat
Copy link

pholat commented Jan 26, 2019

def _(s): return s.decode('unicode_escape');

I'm in no way python enthusiast but this line results in error:

  File "/home/pholat/.local/lib/python3.6/site-packages/ansiescapes.py", line 8, in _
    def _(s): return s.decode('unicode_escape');
AttributeError: 'str' object has no attribute 'decode'

So shouldn't it be decode?
Also to actually use to manipulate terminal with sys.stdout.buffer.write imho ESC should be:
\033[ although there is character [ added, while it's not a part of escape key :) as well as it shouldn't be ansii_escaped so that it would actually work.

@jeffsilverm
Copy link

I am having the same problem.

jeffs@jeffs-desktop:/home/jeffs/python/ansiescapes/ansiescapes-master  (development) *  $ python3 ansiescapes.py 
Traceback (most recent call last):
  File "ansiescapes.py", line 53, in <module>
    cursorLeft = _(ESC + 'G');
  File "ansiescapes.py", line 8, in _
    def _(s): return s.decode('unicode_escape');
AttributeError: 'str' object has no attribute 'decode'
jeffs@jeffs-desktop:/home/jeffs/python/ansiescapes/ansiescapes-master  (development) *  $ 

I am a python enthusiast, so I am going to investigate a little bit and see if the forks have addressed this issue.

jeffsilverm pushed a commit to jeffsilverm/code_examples that referenced this issue Dec 26, 2019
kodie/ansiescapes#2

jeffs@jeffs-desktop:/home/jeffs/python/ansiescapes/ansiescapes-master  (development) *  $ diff ansiescapes.py original_ansiescapes.py
8,17c8
< def _(s):
< # A solution to issue 2, kodie/ansiescapes#2
< # Because I don't know what the data type of s is going to be (it might
< # be a type that has a decode function such as byte array ), simple test
< # is s has a decode method.  If it does, great, call it, otherwise, just
< # return s.
<   if hasattr(s, "decode"):
<     return s.decode('unicode_escape')
<   else:
<     return s
---
> def _(s): return s.decode('unicode_escape');
jeffs@jeffs-desktop:/home/jeffs/python/ansiescapes/ansiescapes-master  (development) *  $
jeffsilverm added a commit to jeffsilverm/ansiescapes that referenced this issue Dec 26, 2019
Solve issue kodie#2 

jeffs@jeffs-desktop:/home/jeffs/python/ansiescapes/ansiescapes-master  (development) *  $ diff ansiescapes.py original_ansiescapes.py 
8,17c8
< def _(s):
< # A solution to issue 2, kodie#2
< # Because I don't know what the data type of s is going to be (it might
< # be a type that has a decode function such as byte array ), simple test
< # is s has a decode method.  If it does, great, call it, otherwise, just 
< # return s.
<   if hasattr(s, "decode"):
<     return s.decode('unicode_escape')
<   else:
<     return s
---
> def _(s): return s.decode('unicode_escape');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants