Why is this?

2005-08-10 Thread Jiri Barton
Hi everyone,

I have a problem with initialization.
>>> a, b = [[]]*2
>>> a.append(1)
>>> b
[1]

Why is this? Why does not this behave like the below:

>>> a, b = [[], []]
>>> a.append(1)
>>> b
[]

And, just to add to my confusion:

>>> [[]]*2
[[], []]
>>> [[], []] == [[]]*2
True

Thanks in advance for the explanation.
jbar


BTW, if it matters...
Python 2.4.1 (#2, Mar 30 2005, 20:41:35)
[GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why is this?

2005-08-10 Thread Jiri Barton
Yes, now it is clear!

As always, I should have RTFM, the operator* is not just a syntactic sugar
and thus does not make copies. You know, my actual scenario was with four
variables at the time:

a, b, c, d = [], [], [], []

so I was even more tempted to use the previous and wrong approach:-)

Thank you for your explanation. No more errors in my code from now on (oh
well,...)

jbar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: escape single and double quotes

2005-03-24 Thread Jiri Barton
Hey there,

str.replace('"', '\\"').replace("'", "\\'")

HTH,  jbar
-- 
http://mail.python.org/mailman/listinfo/python-list


Distributing closed source modules

2005-03-24 Thread Jiri Barton
Hi,

I'd like to be able to distribute some python modules of my system (plugins)
without the source. So far, I have done this by including only the *.pyc
files. However, I have recently found they are platform dependent and
python version dependent.

This approach has been very convenient because I don't have to mess up with
__import__ and the like - which seem to be kind of a pain when inter-module
dependencies are introduced.

Can some one point me in another direction of protecting the code? I know
and this whole thing just does not sound right to me either but I am forced
to do so.

TIA,  jbar
-- 
http://mail.python.org/mailman/listinfo/python-list


unicode in multi-line strings

2008-09-18 Thread Jiri Barton

Hello,

I have a problem with international characters in multi-line strings.


Works: '''á'''

Works: '''
a'''

Does not work: '''
á'''


By does not work I mean the infamous

'ascii' codec can't encode character u'\xe1' in position 4: ordinal not 
in range(128)


I'm using Ubuntu 8.04 with Python 2.5. It does not work in terminal, 
from scripts, or from scripts with the encoding specified at the top. 
Making the string unicode (u''' ... ''') does not change anything.


It could be an interpreter issue but I didn't know where else I should 
turn for help.


Thank you!
Jiri


--
http://mail.python.org/mailman/listinfo/python-list