Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59646 > unrolled thread
| Started by | Laszlo Nagy <gandalf@shopzeus.com> |
|---|---|
| First post | 2013-11-16 20:12 +0100 |
| Last post | 2013-11-16 22:10 +0100 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.python
Beginner python 3 unicode question Laszlo Nagy <gandalf@shopzeus.com> - 2013-11-16 20:12 +0100
Re: Beginner python 3 unicode question Luuk <luuk@invalid.lan> - 2013-11-16 20:35 +0100
Re: Beginner python 3 unicode question Laszlo Nagy <gandalf@shopzeus.com> - 2013-11-16 21:57 +0100
Re: Beginner python 3 unicode question Luuk <luuk@invalid.lan> - 2013-11-16 22:10 +0100
| From | Laszlo Nagy <gandalf@shopzeus.com> |
|---|---|
| Date | 2013-11-16 20:12 +0100 |
| Subject | Beginner python 3 unicode question |
| Message-ID | <mailman.2730.1384629174.18130.python-list@python.org> |
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?
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
[toc] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2013-11-16 20:35 +0100 |
| Message-ID | <o1ukla-h8g.ln1@luuk.invalid.lan> |
| In reply to | #59646 |
On 16-11-2013 20:12, Laszlo Nagy wrote: > 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 ;)
[toc] | [prev] | [next] | [standalone]
| From | Laszlo Nagy <gandalf@shopzeus.com> |
|---|---|
| Date | 2013-11-16 21:57 +0100 |
| Message-ID | <mailman.2734.1384635478.18130.python-list@python.org> |
| In reply to | #59649 |
> 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. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
[toc] | [prev] | [next] | [standalone]
| From | Luuk <luuk@invalid.lan> |
|---|---|
| Date | 2013-11-16 22:10 +0100 |
| Message-ID | <3j3lla-1eh.ln1@luuk.invalid.lan> |
| In reply to | #59654 |
On 16-11-2013 21:57, Laszlo Nagy wrote: > >> 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. > 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web