Beginner python 3 unicode question


L

Laszlo Nagy

Example interactive:

$ python3
Python 3.3.1 (default, Sep 25 2013, 19:29:01)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
import uuid
import base64
base64.b32encode(uuid.uuid1().bytes)[:-6].lower() b'zsz653co6ii6hgjejqhw42ncgy'

But when I put the same thing into a source file I get this:

Traceback (most recent call last):
File "/home/gandalf/Python/Lib/shopzeus/yaaf/ui/widget.py", line 94,
in __init__
self.eid = uniqueid()
File "/home/gandalf/Python/Lib/shopzeus/yaaf/ui/__init__.py", line
34, in uniqueid
base64.b32encode(uuid.uuid1().bytes)[:-6].lower()
TypeError: Can't convert 'bytes' object to str implicitly


Why it is behaving differently on the command line? What should I do to
fix this?
 
Ad

Advertisements

L

Luuk

Example interactive:

$ python3
Python 3.3.1 (default, Sep 25 2013, 19:29:01)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
import uuid
import base64
base64.b32encode(uuid.uuid1().bytes)[:-6].lower() b'zsz653co6ii6hgjejqhw42ncgy'

But when I put the same thing into a source file I get this:

Traceback (most recent call last):
File "/home/gandalf/Python/Lib/shopzeus/yaaf/ui/widget.py", line 94,
in __init__
self.eid = uniqueid()
File "/home/gandalf/Python/Lib/shopzeus/yaaf/ui/__init__.py", line
34, in uniqueid
base64.b32encode(uuid.uuid1().bytes)[:-6].lower()
TypeError: Can't convert 'bytes' object to str implicitly


Why it is behaving differently on the command line? What should I do to
fix this?

the error is in one of the lines you did not copy here....

because this works without problems:
<<BEGIN-of script>>
#!/usr/bin/python

import uuid
import base64
print base64.b32encode(uuid.uuid1().bytes)[:-6].lower()
<<END-of script>>

But, i need to say, i'm also a beginner ;)
 
L

Laszlo Nagy

the error is in one of the lines you did not copy here....

because this works without problems:
<<BEGIN-of script>>
#!/usr/bin/python
Most probably, your /usr/bin/python program is python version 2, and not
python version 3

Try the same program with /usr/bin/python3. And also try the interactive
mode with the same program and I think you will see the same phenomenon.
 
Ad

Advertisements

L

Luuk

Most probably, your /usr/bin/python program is python version 2, and not
python version 3

Try the same program with /usr/bin/python3. And also try the interactive
mode with the same program and I think you will see the same phenomenon.

adding some '()' helped:
<<BEGIN-of script>>
#!/usr/bin/python3

import uuid
import base64
print (base64.b32encode(uuid.uuid1().bytes)[:-6].lower())
<<END-of script>>

~/temp> python3 --version
Python 3.3.0
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top