Re: Raw string statement (proposal)

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 08:09:51 +0300, Mikhail V wrote:

> On Fri, May 25, 2018 at 1:15 PM, bartc  wrote:
[...]
>> One problem here is how to deal with embedded non-printable characters:
>> CR, LF and TAB might become part of the normal source text, but how
>> about anything else? Or would you only allow text that might appear in
>> a text file where those characters would also cause issues?
> 
> This syntax does not imply anything about text. From the editor's POV
> it's just the same as it is now - you can insert anything in a .py file.
> So it does not add new cases to current state of affairs in this regard.
> But maybe I'm not completely understand your question.

Here is a string assigned to name `s` using Python's current syntax:

s = "some\ncharacters\0abc\x01\ndef\uFF0A\nhere"

How do you represent that assignment using your syntax?


And another example:

s = """this is some text
x = 'a'
y = 'b'"""
t = 'c'

How do we write that piece of code using your syntax?



>> Another thing that might come up: suppose you do come up with a
>> workable scheme, and have a source file PROG1.PY which contains such
>> raw strings.
>>
>> Would it then be possible to create a source file PROG2.PY which
>> contains PROG1.PY as a raw string? That is, without changing the text
>> from PROG1.PY at all.
> 
> Should be fine, with only difference that you must indent the PROG1.PY
> if it will be placed inside an indented suite.

Bart said WITHOUT CHANGING THE TEXT. Indenting it is changing the text.


> I was thinking about this
> nuance - I've added a special case for this in addition to the ? flag.

Oh good, another cryptic magical flag that changes the meaning of the 
syntax. Just what I was hoping for.



-- 
Steve

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


Re: Enums: making a single enum

2018-05-26 Thread Steven D'Aprano
On Fri, 25 May 2018 23:07:47 -0600, Ian Kelly wrote:

> On Fri, May 25, 2018 at 11:00 PM, Chris Angelico 
> wrote:
>> On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano
>>  wrote:
[...]
>>> Is there a better way of handling a three-state flag like this?
>>>
>>>
>> Does it need to have a value of 2? If not:
>>
>> # Tri-state logic
>> Maybe = object()
> 
> The enum has a nice __str__ though.

Yes, that's why I wanted to use enum.

Also because apparently Enums are the future and nobody uses object() any 
more :-)

Actually I don't really need all the features of Enums, I might just 
define my own class:


class Maybe:
 def __repr__(self):
 return "Maybe"

Maybe = Maybe()



I wish there was a simpler way to define symbols with identity but no 
state or behaviour...



-- 
Steve

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


Re: Enums: making a single enum

2018-05-26 Thread Chris Angelico
On Sat, May 26, 2018 at 6:00 PM, Steven D'Aprano
 wrote:
> Actually I don't really need all the features of Enums, I might just
> define my own class:
>
>
> class Maybe:
>  def __repr__(self):
>  return "Maybe"
>
> Maybe = Maybe()
>
>
>
> I wish there was a simpler way to define symbols with identity but no
> state or behaviour...

You DO have behaviour though - the repr is a behaviour of that object.
So what you have there (reusing the name for the instance) seems
decent to me.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Enums: making a single enum

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 18:14:08 +1000, Chris Angelico wrote:

> On Sat, May 26, 2018 at 6:00 PM, Steven D'Aprano
>  wrote:
>> Actually I don't really need all the features of Enums, I might just
>> define my own class:
>>
>>
>> class Maybe:
>>  def __repr__(self):
>>  return "Maybe"
>>
>> Maybe = Maybe()
>>
>>
>>
>> I wish there was a simpler way to define symbols with identity but no
>> state or behaviour...
> 
> You DO have behaviour though - the repr is a behaviour of that object.
> So what you have there (reusing the name for the instance) seems decent
> to me.

I *just knew* some clever Dick (or clever Chris in this case...) would 
point out that repr is behaviour. Technically you are correct (the best 
kind of correct...) but in a practical sense we don't really count having 
a repr as behaviour. All objects ought to have a repr: calling print(obj) 
or displaying the object in the REPL shouldn't raise an exception. Even 
None has a repr :-)

I want an easy way to make new objects like None and NotImplemented 
without having to explicitly define a class first. Some languages make 
that real easy (although the semantics might not be quite identical):

Ruby:Maybe
Javascript  Symbol("Maybe")
Julia   :Maybe or Symbol("Maybe")
Scala   'Maybe
Elixir  :Maybe
Erland  maybe or 'Maybe'


Elixir and Erland call them atoms; Erland also requires them to begin 
with a lowercase letter, otherwise they must be surrounded by single 
quotes.


Hey-Chris-you-want-to-collaborate-on-a-PEP-for-this-ly y'rs,


-- 
Steve

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


Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Steven D'Aprano
Here is my code:



 cut here %< 

import weakref
d = weakref.WeakValueDictionary()

class Spam:
pass

class Eggs:
__slots__ = ['spanish_inquisition']

d['a'] = Spam()  # Okay.
d['b'] = Eggs()  # Nobody will expect what happens next!

 cut here %< 


and the result I get is:


Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/local/lib/python3.5/weakref.py", line 158, in __setitem__
self.data[key] = KeyedRef(value, self._remove, key)
  File "/usr/local/lib/python3.5/weakref.py", line 306, in __new__
self = ref.__new__(type, ob, callback)
TypeError: cannot create weak reference to 'Eggs' object



Why does weakref hate my Eggs class?


-- 
Steve

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


Re: Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Christian Heimes
On 2018-05-26 11:17, Steven D'Aprano wrote:
> Here is my code:
> 
> 
> 
>  cut here %< 
> 
> import weakref
> d = weakref.WeakValueDictionary()
> 
> class Spam:
> pass
> 
> class Eggs:
> __slots__ = ['spanish_inquisition']
> 
> d['a'] = Spam()  # Okay.
> d['b'] = Eggs()  # Nobody will expect what happens next!
> 
>  cut here %< 
> 
> 
> and the result I get is:
> 
> 
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/local/lib/python3.5/weakref.py", line 158, in __setitem__
> self.data[key] = KeyedRef(value, self._remove, key)
>   File "/usr/local/lib/python3.5/weakref.py", line 306, in __new__
> self = ref.__new__(type, ob, callback)
> TypeError: cannot create weak reference to 'Eggs' object
> 
> 
> 
> Why does weakref hate my Eggs class?

Weakref needs some place to store reference information. It works if you
add "__weakref__" to your slots:

class Eggs:
 __slots__ = ['spanish_inquisition', '__weakref__']

Christian

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


Re: Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Gregory Ewing

Steven D'Aprano wrote:

TypeError: cannot create weak reference to 'Eggs' object

Why does weakref hate my Eggs class?


Classes with __slots__ aren't automatically given a __weakref__ slot,
to save memory I suppose.

But you can give it one explicitly:

>>> class Eggs:
...   __slots__ = ['spanish_inquisition', '__weakref__']
...
>>> e = Eggs()
>>> d['b'] = e
>>>

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Computations on pandas dataframes

2018-05-26 Thread Peter Otten
junkaccoun...@outlook.com wrote:

> Hi,
> 
> Python newbie here. I need help with the following two tasks I need to
> accomplish using Python:
> 
> 
> 
> Creating a matrix of rolling variances
> 
> I have a pandas data frame of six columns, I would like to iteratively
> compute the variance along each column. Since I am a newbie, I don't
> really understand the niceties of the language and common usage patterns.
> What is the common Python idiom for achieving the following?

Knowledge of the language doesn't help much here; pandas and numpy are a 
world of its own. One rule I apply as an amateur: when you have to resort 
Python loops it gets slow ;)

> vars = []
> for i in range(1, 10):
> v = (data.iloc[range(0, i+1)].var()).values
> if len(vars) == 0:
> vars = v
> else:
> vars = np.vstack((vars, v))
> 
> Also, when I run this code, it takes a long time to execute. Can anyone
> suggest how to improve the running time?

I think I would forego pandas and use numpy

a = np.random.random((N, M))
vars = np.empty((N-1, M))
for i in range(1, N):
vars[i-1] = a[:i+1].var(axis=0, ddof=1)

While it doesn't avoid the loop it may not need to copy as much data as your 
version.

> Pandas dataframe: sum of exponentially weighted correlation matrices per
> row
> 
> Consider the following dataframe:
> 
> df = pd.DataFrame(np.random.random((200,3)))
> df['date'] = pd.date_range('2000-1-1', periods=200, freq='D')
> df = df.set_index(['date'])
> 
> 
> date 0 1 2 3 4 5
> 2000-01-01 0.101782 0.111237 0.177719 0.229994 0.298786 0.747169
> 2000-01-02 0.348568 0.916997 0.527036 0.998144 0.544261 0.824907
> 2000-01-03 0.095015 0.480519 0.493345 0.632072 0.965326 0.244732
> 2000-01-04 0.502706 0.014287 0.045354 0.461621 0.359125 0.489150
> 2000-01-05 0.559364 0.337121 0.763715 0.460163 0.515309 0.732979
> 2000-01-06 0.488153 0.149655 0.015616 0.658693 0.864032 0.425497
> 2000-01-07 0.266161 0.392923 0.606358 0.286874 0.160191 0.573436
> 2000-01-08 0.786785 0.770826 0.202838 0.259263 0.732071 0.546918
> 2000-01-09 0.739847 0.886894 0.094900 0.257210 0.264688 0.005631
> 2000-01-10 0.615846 0.347249 0.516575 0.886096 0.347741 0.259998
> 
> Now, I want to treat each row as a vector and perform a multiplication
> like this:
> 
> [[0.101782]] [[0.101782 0.111237 0.177719 0.229994 0.298786 0.747169]]
> [[0.111237]]
> [[0.177719]]
> [[0.229994]]
> [[0.298786]]
> [[0.747169]]
> 
> For the i-th row, let's call this X_i. Now I have a parameter alpha and I
> want to multiply X_i with alpha^i and sum across all the i's. In the real
> world, I can have thousands of rows so I need to do this with reasonably
> good performance.

Again I'd use numpy directly. If I understand your second problem correctly

a = np.np.random.random((200, 3))
alpha = .5
b = alpha ** np.arange(200)
c = b * a ** 2
print(c.sum(axis=0))

If I got it wrong -- could you provide a complete (small!) example with the 
intermediate results?

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


Re: Enums: making a single enum

2018-05-26 Thread Serhiy Storchaka

26.05.18 08:07, Ian Kelly пише:

On Fri, May 25, 2018 at 11:00 PM, Chris Angelico  wrote:

On Sat, May 26, 2018 at 2:46 PM, Steven D'Aprano
 wrote:

Am I silly for wanting to make a single enum?

I have a three-state flag, True, False or Maybe. Is is confusing or bad
practice to make a single enum for the Maybe case?


from enum import Enum
class State(Enum):
 Maybe = 2

Maybe = State.Maybe
del State

Is there a better way of handling a three-state flag like this?



Does it need to have a value of 2? If not:

# Tri-state logic
Maybe = object()


The enum has a nice __str__ though.


Not very nice. It contains a reference to non-existing class State. The 
repr contains also the unrelevant here value of 2.


If you need just an identifiable singleton and don't bother about the 
exact representation, then a list can be enough:


Maybe = ['Maybe']

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


Re: Enums: making a single enum

2018-05-26 Thread Marko Rauhamaa
Ian Kelly :
> On Fri, May 25, 2018 at 11:00 PM, Chris Angelico  wrote:
>> # Tri-state logic
>> Maybe = object()
>
> The enum has a nice __str__ though.

I use strings for enums:

class X:
   HERE = "HERE"
   THERE = "THERE"
   EVERYWHERE = "EVERYWHERE"

   def __init__(self):
   self.location = self.HERE

   def move_there(self):
   assert self.location is not self.EVERYWHERE
   self.location = self.THERE


1. Why self.THERE instead of X.THERE?

   X.THERE would work. It would even be preferable if the enums were
   used in a published API. However, in general I don't like to sprinkle
   the name of a class around its implementation.

2. Whe "is not" instead of "!="?

   The enums are defined as strings only as a matter of printing
   convenience. They are treated as arbitrary sentinel objects whose
   only functional property is their identity. Or course, such sentinel
   objects must not be used in contexts where ordinary strings would be
   possible values.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Some Issues on Tagging Text

2018-05-26 Thread subhabangalore
On Saturday, May 26, 2018 at 3:54:37 AM UTC+5:30, Cameron Simpson wrote:
> On 25May2018 04:23, Subhabrata Banerjee  wrote:
> >On Friday, May 25, 2018 at 3:59:57 AM UTC+5:30, Cameron Simpson wrote:
> >> On 24May2018 03:13, wrote:
> >> >I have a text as,
> >> >
> >> >"Hawaii volcano generates toxic gas plume called laze PAHOA: The eruption 
> >> >of Kilauea volcano in Hawaii sparked new safety warnings about toxic gas 
> >> >on the Big Island's southern coastline after lava began flowing into the 
> >> >ocean and setting off a chemical reaction. Lava haze is made of dense 
> >> >white clouds of steam, toxic gas and tiny shards of volcanic glass. Janet 
> >> >Babb, a geologist with the Hawaiian Volcano Observatory, says the plume 
> >> >"looks innocuous, but it's not." "Just like if you drop a glass on your 
> >> >kitchen floor, there's some large pieces and there are some very, very 
> >> >tiny pieces," Babb said. "These little tiny pieces are the ones that can 
> >> >get wafted up in that steam plume." Scientists call the glass Limu O 
> >> >Pele, or Pele's seaweed, named after the Hawaiian goddess of volcano and 
> >> >fire"
> >> >
> >> >and I want to see its tagged output as,
> >> >
> >> >"Hawaii/TAG volcano generates toxic gas plume called laze PAHOA/TAG: The 
> >> >eruption of Kilauea/TAG volcano/TAG in Hawaii/TAG sparked new safety 
> >> >warnings about toxic gas on the Big Island's southern coastline after 
> >> >lava began flowing into the ocean and setting off a chemical reaction. 
> >> >Lava haze is made of dense white clouds of steam, toxic gas and tiny 
> >> >shards of volcanic glass. Janet/TAG Babb/TAG, a geologist with the 
> >> >Hawaiian/TAG Volcano/TAG Observatory/TAG, says the plume "looks 
> >> >innocuous, but it's not." "Just like if you drop a glass on your kitchen 
> >> >floor, there's some large pieces and there are some very, very tiny 
> >> >pieces," Babb/TAG said. "These little tiny pieces are the ones that can 
> >> >get wafted up in that steam plume." Scientists call the glass Limu/TAG 
> >> >O/TAG Pele/TAG, or Pele's seaweed, named after the Hawaiian goddess of 
> >> >volcano and fire"
> >> >
> >> >To do this I generally try to take a list at the back end as,
> >> >
> >> >Hawaii
> >> >PAHOA
> [...]
> >> >and do a simple code as follows,
> >> >
> >> >def tag_text():
> >> >corpus=open("/python27/volcanotxt.txt","r").read().split()
> >> >wordlist=open("/python27/taglist.txt","r").read().split()
> [...]
> >> >list1=[]
> >> >for word in corpus:
> >> >if word in wordlist:
> >> >word_new=word+"/TAG"
> >> >list1.append(word_new)
> >> >else:
> >> >list1.append(word)
> >> >lst1=list1
> >> >tagged_text=" ".join(lst1)
> >> >print tagged_text
> >> >
> >> >get the results and hand repair unwanted tags Hawaiian/TAG goddess of 
> >> >volcano/TAG.
> >> >I am looking for a better approach of coding so that I need not spend 
> >> >time on
> >> >hand repairing.
> >>
> >> It isn't entirely clear to me why these two taggings are unwanted. 
> >> Intuitively,
> >> they seem to be either because "Hawaiian goddess" is a compound term where 
> >> you
> >> don't want "Hawaiian" to get a tag, or because "Hawaiian" has already 
> >> received
> >> a tag earlier in the list. Or are there other criteria.
> >>
> >> If you want to solve this problem with a programme you must first clearly
> >> define what makes an unwanted tag "unwanted". [...]
> >
> >By unwanted I did not mean anything so intricate.
> >Unwanted meant things I did not want.
> 
> That much was clear, but you need to specify in your own mind _precisely_ 
> what 
> makes some things unwanted and others wanted. Without concrete criteria you 
> can't write code to implement those criteria.
> 
> I'm not saying "you need to imagine code to match these things": you're 
> clearly 
> capable of doing that. I'm saying you need to have well defined concepts of 
> what makes something unwanted (or, if that is easier to define, wanted).  You 
> can do that iteratively: start with your basic concept and see how well it 
> works. When those concepts don't give you the outcome you desire, consider a 
> specific example which isn't working and try to figure out what additional 
> criterion would let you distinguish it from a working example.
> 
> >For example,
> >if my target phrases included terms like,
> >government of Mexico,
> >
> >now in my list I would have words with their tags as,
> >government
> >of
> >Mexico
> >
> >If I put these words in list it would tag
> >government/TAG of/TAG Mexico
> >
> >but would also tag all the "of" which may be
> >anywhere like haze is made of/TAG dense white,
> >clouds of/TAG steam, etc.
> >
> >Cleaning these unwanted places become a daunting task
> >to me.
> 
> Richard Damon has pointed out that you seem to want phrases instead of just 
> words.
> 
> >I have been experimenting around
> >wordlist=["Kilauea volcano","Kilauea/TAG 
> >volcano/TAG"),("H

Re: Enums: making a single enum

2018-05-26 Thread Peter Otten
Steven D'Aprano wrote:

> Am I silly for wanting to make a single enum?
> 
> I have a three-state flag, True, False or Maybe. Is is confusing or bad
> practice to make a single enum for the Maybe case?
> 
> 
> from enum import Enum
> class State(Enum):
> Maybe = 2
> 
> Maybe = State.Maybe
> del State

> Is there a better way of handling a three-state flag like this?

I think all three states should be created equal. Would a full-blown

>>> class State(enum.IntEnum):
... false = False
... true = True
... maybe = 2
... 
>>> State.maybe

>>> bool(State.false)
False
>>> State.true == True
True
>>> list(State)
[, , ]
>>> State(True)


complicate your actual code?

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


Re: why do I get syntax error on if : break

2018-05-26 Thread Grant Edwards
On 2018-05-25, asa32s...@gmail.com  wrote:

> here is the code, i keep getting an error, "break outside loop".

You get the "break outside loop" error because you're using the break
statement when you are not inside a loop.

> if it is false just exit function

You use the 'return' statement to exit a function.

> def d(idx):
> if type(idx) != int:
> break
>
> d('k')


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


Re: Enums: making a single enum

2018-05-26 Thread Chris Angelico
On Sat, May 26, 2018 at 6:50 PM, Steven D'Aprano
 wrote:
> On Sat, 26 May 2018 18:14:08 +1000, Chris Angelico wrote:
>
>> On Sat, May 26, 2018 at 6:00 PM, Steven D'Aprano
>>  wrote:
>>> Actually I don't really need all the features of Enums, I might just
>>> define my own class:
>>>
>>>
>>> class Maybe:
>>>  def __repr__(self):
>>>  return "Maybe"
>>>
>>> Maybe = Maybe()
>>>
>>>
>>>
>>> I wish there was a simpler way to define symbols with identity but no
>>> state or behaviour...
>>
>> You DO have behaviour though - the repr is a behaviour of that object.
>> So what you have there (reusing the name for the instance) seems decent
>> to me.
>
> I *just knew* some clever Dick (or clever Chris in this case...) would
> point out that repr is behaviour. Technically you are correct (the best
> kind of correct...) but in a practical sense we don't really count having
> a repr as behaviour. All objects ought to have a repr: calling print(obj)
> or displaying the object in the REPL shouldn't raise an exception. Even
> None has a repr :-)

Sure, but the default repr is one behaviour, and a customized repr is
different behaviour. You do get a repr even without creating a class,
but you don't want that one, you want something more custom.

> I want an easy way to make new objects like None and NotImplemented
> without having to explicitly define a class first. Some languages make
> that real easy (although the semantics might not be quite identical):
>
> Ruby:Maybe
> Javascript  Symbol("Maybe")
> Julia   :Maybe or Symbol("Maybe")
> Scala   'Maybe
> Elixir  :Maybe
> Erland  maybe or 'Maybe'
>
>
> Elixir and Erland call them atoms; Erland also requires them to begin
> with a lowercase letter, otherwise they must be surrounded by single
> quotes.
>
>
> Hey-Chris-you-want-to-collaborate-on-a-PEP-for-this-ly y'rs,

Sure. Basically it'd be a builtin that, whenever instantiated, returns
a new object (guaranteed to be unique) identified by the given string.
Pretty simple and straight-forward. In fact, I wouldn't even start a
PEP yet. Toss it out onto -ideas and see who's interested!

class Symbol: # or Atom:
__slots__ = ("label",)
def __init__(self, label):
self.label = label
def __repr__(self):
return f"Symbol({self.label!r})"

Seems pretty non-controversial, which means it's almost guaranteed to
reach 100+ posts debating what the name should be.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List replication operator

2018-05-26 Thread Peter Otten
Steven D'Aprano wrote:

> On Fri, 25 May 2018 09:28:01 +0200, Peter Otten wrote:
> 
>> Yet another arcanum to learn for beginners with little return. If you
>> cannot refrain from tinkering with the language at least concentrate on
>> the features with broad application. Thank you.
> 
> Broader than multi-dimensional arrays? There are a bazillion uses for
> them. How many do you need before it is "broad application"?
> 
> https://www.google.com/search?q=multidimensional+arrays

Sorry, I don't see how your suggestion helps with multidimensional arrays 
which aren't even part of Python's stdlib.

In practice newbies will be told to replace

bins = [[]] * N

with 

bins = [[]] ** N

just as they are now told to replace it with

bins = [[] for dummy in range(N)]

Someone showing up with

0]*10]*10]*10]*10

should certainly be informed about numpy.

> https://www.google.com/search?q=what+are+some+uses+for+multidimensional
> +arrays
> 
> "My programming language doesn't support arithmetic, because I only
> provide features with broad application. Arithmetic is only useful for
> manipulating numbers."
> 
> 
> Beginners already learn list * operator, and get *extremely emotional*

I don't think there is a significant correlation between getting emotional 
and being right*.

> when it doesn't copy lists like they expect:
> 
> https://bugs.python.org/issue33636
> 
> This is a frequent, recurring pain point. Experienced programmers forget
> how confusing the behaviour of * is because they're so used to the
> execution model. They forget that writing a list comp is not even close
> to obvious, not only for beginners but even some experienced Python
> programmers.

It may be unexpected, just as

animal = Animal()

dog = animal
dog.noise = "woof"

cat = animal
cat.noise = "miaou"

or

def augmented(item, items=[]):
items.append(item)
return items

a = augmented(10)
b = augmented(20)
assert a == [10]
assert b == [20]

is if your mental model operates with values rather than references.


(*) Perhaps we should try to repeat the success of

from __future__ import braces

with

from __future__ import value_semantics


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


Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-26 Thread Paul St George

Thank you.
You are very right. The show() method is intended for debugging purposes 
and is useful for that, but what method should I be using and is PIL the 
best imaging library for my purposes? I do not want to manipulate 
images, I only want to show images (full screen) on an external display. 
I want to use Python to control the timing of the images.


And, out of curiosity, as I will probably use a different method - how 
do I find out what commands can be used as parameters for show()? I read 
the docs at 
, 
but I am none the wiser.



On 26/05/2018 01:02, boB Stepp wrote:

On Fri, May 25, 2018 at 6:04 AM, Paul St George  wrote:

I am using the Python Imaging Library (PIL), Python 2 and Raspberry Pi 3 B+

My code is simply:

 from PIL import Image

 im = Image.open(‘somepic.jpg’)
 im.show() # display image


But the show() method looks for the default viewer (probably xv). How do I
change this (in the code, or in some settings) to a different viewer (of my
choice)?

In the PIL docs for show() at
https://pillow.readthedocs.io/en/5.1.x/reference/Image.html#PIL.Image.Image.show
it says:


Image.show(title=None, command=None)

Displays this image. This method is mainly intended for debugging purposes.

On Unix platforms, this method saves the image to a temporary PPM
file, and calls either the xv utility or the display utility,
depending on which one can be found.

On macOS, this method saves the image to a temporary BMP file, and
opens it with the native Preview application.

On Windows, it saves the image to a temporary BMP file, and uses the
standard BMP display utility to show it (usually Paint).

Parameters:

title – Optional title to use for the image window, where possible.
command – command used to show the image


I have not had occasion to use PIL, but perhaps this command parameter
can be used to do what you want?  If not then perhaps you can write
your own function to load your image into your favorite image viewer.




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


Re: Raw string statement (proposal)

2018-05-26 Thread Mikhail V
On Sat, May 26, 2018 at 10:55 AM, Steven D'Aprano
 wrote:
> On Sat, 26 May 2018 08:09:51 +0300, Mikhail V wrote:
>
>> On Fri, May 25, 2018 at 1:15 PM, bartc  wrote:
> [...]
>>> One problem here is how to deal with embedded non-printable characters:
>>> CR, LF and TAB might become part of the normal source text, but how
>>> about anything else? Or would you only allow text that might appear in
>>> a text file where those characters would also cause issues?
>>
>> This syntax does not imply anything about text. From the editor's POV
>> it's just the same as it is now - you can insert anything in a .py file.
>> So it does not add new cases to current state of affairs in this regard.
>> But maybe I'm not completely understand your question.
>
> Here is a string assigned to name `s` using Python's current syntax:
>
> s = "some\ncharacters\0abc\x01\ndef\uFF0A\nhere"
>
> How do you represent that assignment using your syntax?

Hope its not mandatory to decipher your random example.
If for example I'd want to work with a lot of non-presentable
characters, I'd use a more human-oriented notation than this ^.
And that is exactly where raw strings are needed.

So I'd make a readable notation where I can present a character
by its ordinal enclosed in some tag for example {10}. Then just
write a function which collapses those depending on further needs:

data >>| abc{10}def
data = f(data)

And the notation itself can be chosen depending on my needs.
Hope you get the point.

>
>
> And another example:
>
> s = """this is some text
> x = 'a'
> y = 'b'"""
> t = 'c'
>
> How do we write that piece of code using your syntax?

That's too easy - maybe you can try it yourself?
I am not trying to imply anything, but I don't see how
this example can cause problems - just put the TQS in a block.


>>> Would it then be possible to create a source file PROG2.PY which
>>> contains PROG1.PY as a raw string? That is, without changing the text
>>> from PROG1.PY at all.
>>
>> Should be fine, with only difference that you must indent the PROG1.PY
>> if it will be placed inside an indented suite.
>
> Bart said WITHOUT CHANGING THE TEXT. Indenting it is changing the text.

I know. So you've decided to share that you also understood this?
Good, I'm glad that you understand :-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Enums: making a single enum

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 23:54:51 +1000, Chris Angelico wrote:

> Seems pretty non-controversial, which means it's almost guaranteed to
> reach 100+ posts debating what the name should be.

Including:

* 27 posts declaring that using such singleton symbols is completely
  un-Pythonic and is sure to doom Python to irrelevancy;

* 13 posts stating that whether it is spelled "Symbol(name)" or 
  "Atom(name)" it will be completely confusing;

* 4 posts proposing spelling it "~~name!" instead;

* 25 posts agreeing that the functionality is important, but
  should only be allowed inside functions whose name starts 
  with a vowel;

* 11 posts insisting it should only be functions starting
  with a consonant;

* 3 posts saying it shouldn't be allowed in functions at all,
  only in module-level try...except statements, and only so
  long as there are no list comprehensions used in the module;

* 18 posts demanding a complete list of every use-case for the
  feature and why using object()/strings/enums/ints isn't
  sufficient;

* 7 posts stating that the author would personally use it if it
  were a built-in, and they wouldn't bother installing a third-
  party package from PyPI for it, but nevertheless it should be
  put on PyPI first to see if there is any community interest;

* 12 posts cherry-picking programming languages invented between
  August 2003 and May 2015 by people whose name starts with "B",
  proving categorically that the modern trend is to avoid this
  feature;

* and 17 posts discussing the history of Forth and Intercal.


Good thing I didn't propose a short-hand syntax for it as well :-)




-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: Raw string statement (proposal)

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 18:22:15 +0300, Mikhail V wrote:

>> Here is a string assigned to name `s` using Python's current syntax:
>>
>> s = "some\ncharacters\0abc\x01\ndef\uFF0A\nhere"
>>
>> How do you represent that assignment using your syntax?
> 
> Hope its not mandatory to decipher your random example. If for example
> I'd want to work with a lot of non-presentable characters, I'd use a
> more human-oriented notation than this ^. And that is exactly where raw
> strings are needed.
> 
> So I'd make a readable notation where I can present a character by its
> ordinal enclosed in some tag for example {10}. Then just write a
> function which collapses those depending on further needs:
> 
> data >>| abc{10}def
> data = f(data)
> 
> And the notation itself can be chosen depending on my needs. Hope you
> get the point.

Loud and clear: your syntax has no way of representing the string s.

Okay, let's take a simpler example. You want to use {65290} to represent 
the Unicode code point \uFF0A. Fair enough. Everyone else in the world 
uses hexadecimal for this purpose, but whatever.

But isn't {65290} just another way of spelling an escape code? Isn't your 
syntax supposed to eliminate the need for escape codes?

So if I had:

result = function("Mikhail's syntax for \uFF0A is {65290}")

your syntax would become:

temp = >>| Mikhail's syntax for {65290} is {65290}
result = function(f(temp))

where f is your (as yet non-existent?) function for collapsing the {} 
codes to characters.

Can you see the problem yet? How does your collapse function f() 
distinguish between the escape code {65290} and the literal string 
{65290}?

And we've gone from a single string literal, which is an expression that 
can be used anywhere, to a statement that cannot be used in expressions.



>> And another example:
>>
>> s = """this is some text
>> x = 'a'
>> y = 'b'"""
>> t = 'c'
>>
>> How do we write that piece of code using your syntax?
> 
> That's too easy - maybe you can try it yourself? I am not trying to
> imply anything, but I don't see how this example can cause problems -
> just put the TQS in a block.

I don't know what TQS is supposed to mean.

I'll give it a try, and see if I understand your syntax. The idea is to 
avoid needing to put BEGIN END delimiters such as quotation marks around 
the string, right?


s = >>>
this is some text
x = 'a'
y = 'b'
t = 'c'


Am I close?

How is the interpreter supposed to know that the final line is not part 
of the string, but a line of actual Python code?

[...]
>> Bart said WITHOUT CHANGING THE TEXT. Indenting it is changing the text.
> 
> I know. So you've decided to share that you also understood this? Good,
> I'm glad that you understand :-)

I believe that the whole point of your proposal to avoid needing to 
change the text in any way when you paste it into your source code. If 
that's not the point, then what is the point?


-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: Re: The PIL show() method looks for the default viewer. How do I change this to a different viewer (of my choice)?

2018-05-26 Thread Peter Otten
Paul St George wrote:

> Thank you.
> You are very right. The show() method is intended for debugging purposes
> and is useful for that, but what method should I be using and is PIL the
> best imaging library for my purposes? I do not want to manipulate
> images, I only want to show images (full screen) on an external display.
> I want to use Python to control the timing of the images.
> 
> And, out of curiosity, as I will probably use a different method - how
> do I find out what commands can be used as parameters for show()? I read
> the docs at
>  #PIL.Image.Image.show>,
> but I am none the wiser.

If you look into the source code

https://github.com/python-pillow/Pillow/blob/master/src/PIL/Image.py#L1967

after a few indirections

show --> _show --> _showxv --> ImageShow.show

you will end up in the file

https://github.com/python-pillow/Pillow/blob/master/src/PIL/ImageShow.py

which is short enough to read completely ;)

At first glance it looks like the command argument is silently discarded, so 
here's plan B:

It turns out that you can register() Viewer instances, and the pre-
registered viewers for unixoids -- and thus probably the Pi are 
DisplayViewer and XVViewer.

Using these as a template I came up with the following simple viewer that 
shows an image with firefox:

#!/usr/bin/env python3
import os
import sys

from PIL import Image, ImageShow


class Firefox(ImageShow.UnixViewer):

# store the image in a format understood by the browser
format = "jpeg"

def get_command_ex(self, file, **options):
return ("firefox",) * 2

def show_file(self, file, **options):
quote = ImageShow.quote

command, executable = self.get_command_ex(file, **options)

# firefox returns immediately, so let's sleep a few seconds
# to give it time to actually open the image file
command = "(%s %s; sleep 10; rm -f %s)&" % (
command, quote("file://" + file), quote(file)
)
os.system(command)
return 1


# the -1 means our viewer will be inserted before the others
# and thus become the default
ImageShow.register(Firefox(), -1)


if __name__ == "__main__":
try:
file = sys.argv[1]
except IndexError:
print("Please provide an image file", file=sys.stderr)
else:
image = Image.open(file)
image.show()


Here's another, even simpler one:

class Gwenview(ImageShow.UnixViewer):
def get_command_ex(self, file, **options):
return ("gwenview",) * 2


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


Re: Enums: making a single enum

2018-05-26 Thread Ethan Furman

On 05/26/2018 01:00 AM, Steven D'Aprano wrote:


I wish there was a simpler way to define symbols with identity but no
state or behaviour...


Check out the Constant class in aenum.  You still might want to customize the 
repr, though.

--
~Ethan~

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


Re: Raw string statement (proposal)

2018-05-26 Thread Mikhail V
On Sat, May 26, 2018 at 7:10 PM, Steven D'Aprano
 wrote:
> On Sat, 26 May 2018 18:22:15 +0300, Mikhail V wrote:
>
>>> Here is a string assigned to name `s` using Python's current syntax:
>>>
>>> s = "some\ncharacters\0abc\x01\ndef\uFF0A\nhere"
>>>
>>> How do you represent that assignment using your syntax?
>>
>> Hope its not mandatory to decipher your random example. If for example
>> I'd want to work with a lot of non-presentable characters, I'd use a
>> more human-oriented notation than this ^. And that is exactly where raw
>> strings are needed.
>>
>> So I'd make a readable notation where I can present a character by its
>> ordinal enclosed in some tag for example {10}. Then just write a
>> function which collapses those depending on further needs:
>>
>> data >>| abc{10}def
>> data = f(data)
>>
>> And the notation itself can be chosen depending on my needs. Hope you
>> get the point.
>
> Loud and clear: your syntax has no way of representing the string s.

Just 5 lines before it is - you did not notice.


> temp = >>| Mikhail's syntax for {65290} is {65290}
> Can you see the problem yet? How does your collapse function f()
> distinguish between the escape code {65290} and the literal string
> {65290}?

Look, there is no any problem here. You can choose
whatever YOU want to write "{" and "}". e.g. I'd pick {<} {>}.

temp = >>| Mikhail's syntax for {65290} is {<}65290{>}


I just show you that syntax allows you not only input TEXT
without any manipulations, but also it allows to solve any task related
to custom presentation - in this case you want work with
ordinals for example. And you may end up with a scheme which
reads way better than your cryptic example.

This motivation is covered in documentation, but maybe
not good enough? anyway you're welcome to make suggestion for
the documentation.

I'll also ask you a question  -
Which such non-text codes you may need to
generate C code? Python code? HTML code?


>
> And we've gone from a single string literal, which is an expression that
> can be used anywhere, to a statement that cannot be used in expressions.

Ok show me your suggestion for a raw string definition for expressions
(no modifications to source text and no usage of invisible control chars).

> I don't know what TQS is supposed to mean.
Triple Quoted String



> s = >>>
> this is some text
> x = 'a'
> y = 'b'
> t = 'c'
>
>
> Am I close?

Yes very close, just shift it with a char of your choice, e.g. 1 space:
s >>> !" "
 this is some text
 x = 'a'
 y = 'b'
t = 'c'

or use a tag of your choice (no shifting needed in this case):

s >>> ?"#your favorite closing tag"
this is some text
x = 'a'
y = 'b'
#your favorite closing tag
t = 'c'

There can be other suggestions for symbols, etc.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Raw string statement (proposal)

2018-05-26 Thread Chris Angelico
On Sun, May 27, 2018 at 5:13 AM, Mikhail V  wrote:
> On Sat, May 26, 2018 at 7:10 PM, Steven D'Aprano

>> temp = >>| Mikhail's syntax for {65290} is {65290}
>> Can you see the problem yet? How does your collapse function f()
>> distinguish between the escape code {65290} and the literal string
>> {65290}?
>
> Look, there is no any problem here. You can choose
> whatever YOU want to write "{" and "}". e.g. I'd pick {<} {>}.
>
> temp = >>| Mikhail's syntax for {65290} is {<}65290{>}

Whatever notation you pick, you need some way to represent it
literally. Don't you see? All you're doing is dodging the issue by
making your literal syntax more and more complicated.

> I just show you that syntax allows you not only input TEXT
> without any manipulations, but also it allows to solve any task related
> to custom presentation - in this case you want work with
> ordinals for example. And you may end up with a scheme which
> reads way better than your cryptic example.

How about a simple notation that bases everything on a single typable
character like REVERSE SOLIDUS?

> I'll also ask you a question  -
> Which such non-text codes you may need to
> generate C code? Python code? HTML code?

What do you mean?

>> And we've gone from a single string literal, which is an expression that
>> can be used anywhere, to a statement that cannot be used in expressions.
>
> Ok show me your suggestion for a raw string definition for expressions
> (no modifications to source text and no usage of invisible control chars).

Ahh but "no modifications to source text" was YOUR rule, not ours.
Most of us are perfectly happy for string literals to be spelled with
quotes around them and a straight-forward system of escapes.

Or if we want NO modifications whatsoever, then we use another very
standard way of delimiting the contents: put it in a separate file and
then read that in. Oh wow, look at that, we can just put what we like
and it doesn't break anything!

I'm done. Argue with brick walls for the rest of eternity if you like.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Some Issues on Tagging Text

2018-05-26 Thread Cameron Simpson

On 26May2018 04:02, Subhabrata Banerjee  wrote:

On Saturday, May 26, 2018 at 3:54:37 AM UTC+5:30, Cameron Simpson wrote:

It sounds like you want a more general purpose parser, and that depends upon
your purposes. If you're coding to learn the basics of breaking up text, what
you're doing is fine and I'd stick with it. But if you're just after the
outcome (tags), you could use other libraries to break up the text.

For example, the Natural Language ToolKit (NLTK) will do structured parsing of
text and return you a syntax tree, and it has many other facilities. Doco:

  http://www.nltk.org/

PyPI module:

  https://pypi.org/project/nltk/

which you can install with the command:

  pip install --user nltk

That would get you a tree structure of the corpus, which you could process more
meaningfully. For example, you could traverse the tree and tag higher level
nodes as you came across them, possibly then _not_ traversing their inner
nodes. The effect of that would be that if you hit the grammatic node:

  government of Mexico

you might tags that node with "ORGANISATION", and choose not to descend inside
it, thus avoiding tagging "government" and "of" and so forth because you have a
high level tags. Nodes not specially recognised you're keep descending into,
tagging smaller things.

Cheers,
Cameron Simpson


Dear Sir,

Thank you for your kind and valuable suggestions. Thank you for your kind time 
too.
I know NLTK and machine learning. I am of belief if I may use language properly 
we need machine learning-the least.


I have similar beliefs: not that machine learning is not useful, but that it 
has a tendency to produce black boxes in terms of the results it produces 
because its categorisation rules are not overt, rather they tend to be side 
effects of weights in a graph.


So one might end up with a useful tool, but not understand how or why it works.


So, I am trying to design a tagger without the help of machine learning, by 
simple Python coding. I have thus removed standard Parts of Speech(PoS) or 
Named Entity (NE) tagging scheme.
I am trying to design a basic model if required may be implemented on any one 
of these problems.
Detecting longer phrase is slightly a problem now I am thinking to employ 
re.search(pattern,text). If this part is done I do not need machine learning. 
Maintaining so much data is a cumbersome issue in machine learning.


NLTK is not machine learning (I believe). It can parse the corpus for you, 
emitting grammatical structures. So that would aid you in recognising words, 
phrases, nouns, verbs and so forth. With that structure you can then make 
better decisions about what to tag and how.


Using the re module is a very hazard prone way of parsing text. It can be 
useful for finding fairly fixed text, particularly in machine generated text, 
but it is terrible for prose.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Raw string statement (proposal)

2018-05-26 Thread Mikhail V
On Sat, May 26, 2018 at 10:21 PM, Chris Angelico  wrote:

>
> I'm done. Argue with brick walls for the rest of eternity if you like.

I see you like me, but I can reciprocate your feelings.


>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


'_' and '__'

2018-05-26 Thread Mike McClain
In their discussion of 'List replication operator'
Steven D'Aprano and Ben Finney used these '_' and '__'.
Steve said, "[[] for _ in range(5)]".
Ben said, "[ [] for __ in range(5) ]".

These aren't listed separately in the index, where might I find
written discussion of these?
Thanks,
Mike
--
"There are three kinds of men. The ones who learn by reading. The
few who learn by observation. The rest of them have to pee on the
electric fence for themselves." --- Will Rogers
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: '_' and '__'

2018-05-26 Thread Thomas Jollans
On 27/05/18 01:19, Mike McClain wrote:
> In their discussion of 'List replication operator'
> Steven D'Aprano and Ben Finney used these '_' and '__'.
> Steve said, "[[] for _ in range(5)]".
> Ben said, "[ [] for __ in range(5) ]".
> 
> These aren't listed separately in the index, where might I find
> written discussion of these?

There's nothing special about _, it's just a possible name of a
variable, albeit a very short and entirely uninformative one. Normally,
it's not something you'd actually want to name a variable, of course.

As such, _ has become an idiomatic name for dummy variables, i.e.
something you use when syntax requires you to give a variable name, but
you don't actually want one (probably because you're throwing the
variable away). This mostly happens in generator expressions/list
comprehensions.

-- Thomas
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: '_' and '__'

2018-05-26 Thread Chris Angelico
On Sun, May 27, 2018 at 9:40 AM, Thomas Jollans  wrote:
> On 27/05/18 01:19, Mike McClain wrote:
>> In their discussion of 'List replication operator'
>> Steven D'Aprano and Ben Finney used these '_' and '__'.
>> Steve said, "[[] for _ in range(5)]".
>> Ben said, "[ [] for __ in range(5) ]".
>>
>> These aren't listed separately in the index, where might I find
>> written discussion of these?
>
> There's nothing special about _, it's just a possible name of a
> variable, albeit a very short and entirely uninformative one. Normally,
> it's not something you'd actually want to name a variable, of course.
>
> As such, _ has become an idiomatic name for dummy variables, i.e.
> something you use when syntax requires you to give a variable name, but
> you don't actually want one (probably because you're throwing the
> variable away). This mostly happens in generator expressions/list
> comprehensions.

Yes, and also in stand-alone 'for' loops where you don't care about
the iteration variable:

for _ in range(3): datafile.skipline()

The only actual significance of this name is that the interactive
interpreter will stash the result of the previous expression in that
variable.

>>> 6 * 7
42
>>> _ + 1
43

Other than that, it is simply an ordinary name, but one that has some
conventions attached to it.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: '_' and '__'

2018-05-26 Thread Cameron Simpson

On 27May2018 09:46, Chris Angelico  wrote:

On Sun, May 27, 2018 at 9:40 AM, Thomas Jollans  wrote:

There's nothing special about _, it's just a possible name of a
variable, albeit a very short and entirely uninformative one. Normally,
it's not something you'd actually want to name a variable, of course.

As such, _ has become an idiomatic name for dummy variables, i.e.
something you use when syntax requires you to give a variable name, but
you don't actually want one (probably because you're throwing the
variable away). This mostly happens in generator expressions/list
comprehensions.


Yes, and also in stand-alone 'for' loops where you don't care about
the iteration variable:

for _ in range(3): datafile.skipline()

The only actual significance of this name is that the interactive
interpreter will stash the result of the previous expression in that
variable.


6 * 7

42

_ + 1

43

Other than that, it is simply an ordinary name, but one that has some
conventions attached to it.


Also, various lint tools know that the name "_" is used in this way, and don't 
complain that a variable is assigned to and not used if its name is "_".


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: '_' and '__'

2018-05-26 Thread Ben Finney
Mike McClain  writes:

> Steven D'Aprano and Ben Finney used these '_' and '__'.
> Steve said, "[[] for _ in range(5)]".
> Ben said, "[ [] for __ in range(5) ]".
>
> These aren't listed separately in the index

That's right, the names ‘_’ and ‘__’ have no special meaning in
Python-the-language so they don't appear in the index.

Steven and I both used those respective names to communicate “never
going to use this value but the syntax requires a name here”.

> where might I find written discussion of these?

I find Nick Coghlan's answer on StackOverflow
https://stackoverflow.com/questions/5893163/what-is-the-purpose-of-the-single-underscore-variable-in-python/5893946#5893946>
to be especially helpful.

Nick also explains that, because the name ‘_’ has too many conventional
meanings already, the name ‘__’ is better for “don't need this value but
I am required to specify a name”.

-- 
 \ “The double standard that exempts religious activities from |
  `\   almost all standards of accountability should be dismantled |
_o__)   once and for all.” —Daniel Dennett, 2010-01-12 |
Ben Finney

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


Re: Why cannot I use __slots__ and weakrefs together?

2018-05-26 Thread Steven D'Aprano
On Sat, 26 May 2018 11:53:42 +0200, Christian Heimes wrote:

>> Why does weakref hate my Eggs class?
> 
> Weakref needs some place to store reference information. It works if you
> add "__weakref__" to your slots:
> 
> class Eggs:
>  __slots__ = ['spanish_inquisition', '__weakref__']


Thanks!






-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson

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


Re: List replication operator

2018-05-26 Thread Steven D'Aprano
On Fri, 25 May 2018 09:58:19 -0700, Rob Gaddi wrote:

> I agree that it's non-obvious, but I disagree with your diagnosis.

A further data point:

"I was not properly appreciating that that these 
repeated objects were the *same identical* objects 
that were in the pre-replicated list."

https://mail.python.org/pipermail/tutor/2018-May/113080.html



-- 
Steve

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


Re: List replication operator

2018-05-26 Thread Alan Bawden
If the behaviour of * on a sequence is confusing, then isn't the following
behaviour also confusing for exactly the same reason?

   >>> a = [[]]
   >>> b = a + a
   >>> b
   [[], []]
   >>> b[0].append(5)
   >>> b
   [[5], [5]]

And if so, shouldn't there also be a concatenation operator that performs
a copy of some kind on its operands?

-- 
Alan Bawden
-- 
https://mail.python.org/mailman/listinfo/python-list