Re: Usenet Gateway

2018-05-24 Thread Gregory Ewing

Ned Batchelder wrote:

On 5/23/18 12:03 PM, Gene Heskett wrote:


Brain damaged by facebook, AOL, M$, Google, yahoo yadda yadda into
thinking that webmail and forums are the only game in town?

Please avoid accusing others of being brain damaged, even if it was 
meant in a humorous context. :(


I think he meant "brainwashed".

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


Re: how to get INDEX count, or last number of Index

2018-05-24 Thread bartc

On 24/05/2018 03:37, Terry Reedy wrote:

On 5/23/2018 8:46 PM, bartc wrote:

On 24/05/2018 00:44, Terry Reedy wrote:

On 5/23/2018 5:56 PM, Rob Gaddi wrote:

On 05/23/2018 02:51 PM, asa32s...@gmail.com wrote:

s = "kitti"

0,1,2,3,4
k,i,t,t,i

how do i retrieve '4'. i know i can do a len(s)-1,


Use -1, which is the same as len(s)-1 but faster.


This illustrates one problem with having a example sequence of values 
being identical to the indices of those values.


I would have used 10,20,30,40,50 so there could be no such mix-up.

Because I assumed here that the OP wanted the index of the last value, 
the '4' they said they wanted, not the last value itself which would 
be 'i'.


And actually, the subject line seems to confirm that.

In that case, using a '-1' index won't work.


You snipped the code that shows that -1 does work to fetch the last 
character.




I'm sure it does.

But it's not clear whether the OP wants the last character, or the index 
of the last character. The subject line suggests the latter.


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


Some Issues on Tagging Text

2018-05-24 Thread subhabangalore
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
Kilauea 
volcano 
Janet 
Babb
Hawaiian 
Volcano 
Observatory
Babb 
Limu 
O 
Pele

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.

Here, corpus i.e., the volcanoxt is the untagged text given in the first and 
the wordlist, i.e., taglist
is list of words given just above the code. 

I am using Python2.7.15 on MS-Windows 7.

If any one may kindly suggest a solution.

Thanks in advance. 





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


Re: Usenet Gateway

2018-05-24 Thread Michael Torrie
On 05/23/2018 12:03 PM, Grant Edwards wrote:
> Yes.  NNTP and NNTP clients were designed from the ground up to deal
> with ongoing discussions shared by large groups of people posting lots
> of messages, and they're _very_ good at.
> 
> Email was designed for one person sending one message to another.
> 
> Over the years, people have cobbled together bits and pieces and
> features to try to make it work for shared discussions. As a result,
> mailing lists mostly work (especially for low-volume "groups") and are
> pretty decent compared to "web forums" and other such wastes of
> electrons.

I agree web forums really suck for any kind of multi-user conversation.

But mailing lists only working for low-volume groups?  That's news to
me.  But maybe I'm not a typical email user.
> But IMO email pales in comparison to NNTP when there are more than a
> few messages per day per group.

This is not my experience at all.  I used to use Usenet back in the day,
but for nearly the last two decades I've just used mailing lists,
procmail or other kinds of server-side filtering (including GMail's
filters) and a good IMAP email client like Thunderbird.  I read several
high-volume mailing lists this way and it works great. Each mailing list
goes into its own IMAP folder. The result is identical to Usenet in
functionality for me.  In fact, Thunderbird can work with Usenet and
IMAP all at the same time and you'd be hard pressed to see any difference.

GMail's web interface and mailing lists... ugh.  "Conversations" is not
threading no matter what Google calls it!

TL;DR version: with IMAP and server-side filtering of messages into
folders, the experience with email and mailing lists is very good
indeed.  Mailing lists every bit as well as Usenet given a good e-mail
client.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Usenet Gateway

2018-05-24 Thread Michael Torrie
Comparing to IMAP and Thunderbird:

On 05/23/2018 04:39 PM, Chris Green wrote:
> Well from other comments here it seems I'm not alone but anyway:-
> 
> Proper threading etc. is built in

check.

> 
> It's automatically archived and one can search back through
> threads for old postings, this is by design not an add on.

point conceded, although I've never used this feature when I was on Usenet.

> Kill files and other similar filtering abilities are part of the
> user interface

true, but I can get the same job done with thunderbird and my normal
email filtering that I do.

> Automatic handling of new messages and a means to say "I've read
> everything here".

Yes I can mark an entire thread as "read" in IMAP.

> 
> I'm sure there's more


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


Re: Usenet Gateway

2018-05-24 Thread Steven D'Aprano
On Thu, 24 May 2018 05:44:26 -0600, Michael Torrie wrote:

> I agree web forums really suck for any kind of multi-user conversation.

Oh good. Because the Python core-devs are talking about moving to 
Github's web interface instead of email. Because Github is the future :-)

https://circleci.com/blog/its-the-future/

https://hackernoon.com/its-the-future-again-cd038b72dd0b


[...]
> GMail's web interface and mailing lists... ugh.  "Conversations" is not
> threading no matter what Google calls it!


Indeed. Gmail conversations are really good, right up to the moment when 
they're not and you want real threading, and then you're screwed 
seventeen ways to Sunday.

I especially love the way occasionally Gmail will decide that an email 
you sent to Joe Blogs with subject line "Let's go fishing!" and an email 
you sent to Peter Parker with subject line "Where's the beef?" belong to 
the same conversation, and as far as I can tell there's no way to 
convince it otherwise.



-- 
Steve

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


Re: Usenet Gateway

2018-05-24 Thread Chris Green
Michael Torrie  wrote:
> Comparing to IMAP and Thunderbird:
> 
> On 05/23/2018 04:39 PM, Chris Green wrote:
> > Well from other comments here it seems I'm not alone but anyway:-
> > 
> > Proper threading etc. is built in
> 
> check.
> 
> > 
> > It's automatically archived and one can search back through
> > threads for old postings, this is by design not an add on.
> 
> point conceded, although I've never used this feature when I was on Usenet.
> 
> > Kill files and other similar filtering abilities are part of the
> > user interface
> 
> true, but I can get the same job done with thunderbird and my normal
> email filtering that I do.  

Possibly, but it's easier with most NNTP clients.  I use both mailing
lists (mutt) and Usenet (tin) and if I have the choice (as with
Python) then I always go for Usenet/tin.

> 
> > Automatic handling of new messages and a means to say "I've read
> > everything here".
> 
> Yes I can mark an entire thread as "read" in IMAP.
> 
A *thread* yes, but not a whole list.  I.e. if you read this using
mail/IMAP you can mark a thread read but you can't mark *all* Python
list messages read in one go can you?   With tin/Usenet I look at the
list of new subjects in the Python group, I may investigate a couple
of threads, then I just hit 'C' and all of the Python group is marked
as read.


-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Usenet Gateway

2018-05-24 Thread Grant Edwards
On 2018-05-24, Michael Torrie  wrote:
> On 05/23/2018 12:03 PM, Grant Edwards wrote:

>> But IMO email pales in comparison to NNTP when there are more than a
>> few messages per day per group.
>
> This is not my experience at all.  I used to use Usenet back in the day,
> but for nearly the last two decades I've just used mailing lists,
> procmail or other kinds of server-side filtering (including GMail's
> filters)

That's sort of my point: with NNTP, you don't _need_ procmail and
three kinds of filtering in addition to your IMAP client.

> and a good IMAP email client like Thunderbird.  I read several
> high-volume mailing lists this way and it works great. Each mailing
> list goes into its own IMAP folder. The result is identical to
> Usenet in functionality for me.  In fact, Thunderbird can work with
> Usenet and IMAP all at the same time and you'd be hard pressed to
> see any difference.

But you had to jump through hoops with procmail and server/client side
filtering to get there.

-- 
Grant Edwards   grant.b.edwardsYow! I'm not available
  at   for comment..
  gmail.com

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


Re: Usenet Gateway

2018-05-24 Thread José María Mateos
On Thu, May 24, 2018, at 09:10, Chris Green wrote:
> > Yes I can mark an entire thread as "read" in IMAP.
> > 
> A *thread* yes, but not a whole list.  I.e. if you read this using
> mail/IMAP you can mark a thread read but you can't mark *all* Python
> list messages read in one go can you?   With tin/Usenet I look at the
> list of new subjects in the Python group, I may investigate a couple
> of threads, then I just hit 'C' and all of the Python group is marked
> as read.

Yes, you can, at least with mutt. I have a handy alias (ESC + m) that 
accomplish precisely that.

Cheers,

-- 
José María (Chema) Mateos
https://rinzewind.org/blog-es || https://rinzewind.org/blog-en
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Usenet Gateway

2018-05-24 Thread Chris Green
José María Mateos  wrote:
> On Thu, May 24, 2018, at 09:10, Chris Green wrote:
> > > Yes I can mark an entire thread as "read" in IMAP.
> > > 
> > A *thread* yes, but not a whole list.  I.e. if you read this using
> > mail/IMAP you can mark a thread read but you can't mark *all* Python
> > list messages read in one go can you?   With tin/Usenet I look at the
> > list of new subjects in the Python group, I may investigate a couple
> > of threads, then I just hit 'C' and all of the Python group is marked
> > as read.
> 
> Yes, you can, at least with mutt. I have a handy alias (ESC + m) that 
> accomplish precisely that.
> 
OK, but you had to add that, it's built in with every NNTP client I've
ever come across.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Scripts not downloading Version 3.6.5

2018-05-24 Thread Chester Davies via Python-list
Hi! 

Yesterday I downloaded the latest version of Python, after some fiddling around 
with some command line, getting Python to open files etc, it wasn't able to 
find various pillows, so after a while, I decided to call it a night. I went to 
finish it off today, and discovered my computer had updated Windows, and so 
decided to uninstall everything and start from scratch. Upon redownloading 
Python 3.6.5, and moving to where I want it, I cannot use any of the functions 
required, mainly pip.exe. Upon looking in the scripts folder, it is completely 
empty. I have since tried to reinstall to no avail, and also attempted to do 
various repairs from the installer. How can I rectify this please?

Kind regards,

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


Scripts not downloading Version 3.6.5

2018-05-24 Thread Chester Davies via Python-list
Hi! 

Yesterday I downloaded the latest version of Python, after some fiddling around 
with some command line, getting Python to open files etc, it wasn't able to 
find various pillows, so after a while, I decided to call it a night. I went to 
finish it off today, and discovered my computer had updated Windows, and so 
decided to uninstall everything and start from scratch. Upon redownloading 
Python 3.6.5, and moving to where I want it, I cannot use any of the functions 
required, mainly pip.exe. Upon looking in the scripts folder, it is completely 
empty. I have since tried to reinstall to no avail, and also attempted to do 
various repairs from the installer. How can I rectify this please?

Kind regards,

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


List replication operator

2018-05-24 Thread Steven D'Aprano
Python has a sequence replication operator:

py> [1, 2]*3
[1, 2, 1, 2, 1, 2]


Unfortunately, it is prone to a common "gotcha":

py> x = [[]]*5  # make a multi-dimensional list
py> x
[[], [], [], [], []]
py> x[0].append(1)
py> x
[[1], [1], [1], [1], [1]]


The reason for this behaviour is that * does not copy the original list's 
items, it simply replicates the references to the items. So we end up 
with a new list containing five references to the same inner list.


This is not a bug and changing the behaviour is not an option.

But what do people think about proposing a new list replication with copy 
operator?

[[]]**5

would return a new list consisting of five shallow copies of the inner 
list.


Thoughts?



-- 
Steve

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


Re: List replication operator

2018-05-24 Thread Rob Gaddi

On 05/24/2018 11:17 AM, Steven D'Aprano wrote:

Python has a sequence replication operator:

py> [1, 2]*3
[1, 2, 1, 2, 1, 2]


Unfortunately, it is prone to a common "gotcha":

py> x = [[]]*5  # make a multi-dimensional list
py> x
[[], [], [], [], []]
py> x[0].append(1)
py> x
[[1], [1], [1], [1], [1]]


The reason for this behaviour is that * does not copy the original list's
items, it simply replicates the references to the items. So we end up
with a new list containing five references to the same inner list.


This is not a bug and changing the behaviour is not an option.

But what do people think about proposing a new list replication with copy
operator?

 [[]]**5

would return a new list consisting of five shallow copies of the inner
list.


Thoughts?





I think the same people making that mistake now would still do so 
because they didn't know they needed the special operator.


[[] for _ in range(5)] works just as well without adding more syntax.

--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.
--
https://mail.python.org/mailman/listinfo/python-list


Re: List replication operator

2018-05-24 Thread Ned Batchelder

On 5/24/18 2:17 PM, Steven D'Aprano wrote:

Python has a sequence replication operator:

py> [1, 2]*3
[1, 2, 1, 2, 1, 2]


Unfortunately, it is prone to a common "gotcha":

py> x = [[]]*5  # make a multi-dimensional list
py> x
[[], [], [], [], []]
py> x[0].append(1)
py> x
[[1], [1], [1], [1], [1]]


The reason for this behaviour is that * does not copy the original list's
items, it simply replicates the references to the items. So we end up
with a new list containing five references to the same inner list.


This is not a bug and changing the behaviour is not an option.

But what do people think about proposing a new list replication with copy
operator?

 [[]]**5

would return a new list consisting of five shallow copies of the inner
list.


"shallow" will be the next problem.  Do we also need this?:

    [[[]]]***5 # j/k

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


Re: List replication operator

2018-05-24 Thread MRAB

On 2018-05-24 20:12, Ned Batchelder wrote:

On 5/24/18 2:17 PM, Steven D'Aprano wrote:

Python has a sequence replication operator:

py> [1, 2]*3
[1, 2, 1, 2, 1, 2]


Unfortunately, it is prone to a common "gotcha":

py> x = [[]]*5  # make a multi-dimensional list
py> x
[[], [], [], [], []]
py> x[0].append(1)
py> x
[[1], [1], [1], [1], [1]]


The reason for this behaviour is that * does not copy the original list's
items, it simply replicates the references to the items. So we end up
with a new list containing five references to the same inner list.


This is not a bug and changing the behaviour is not an option.

But what do people think about proposing a new list replication with copy
operator?

 [[]]**5

would return a new list consisting of five shallow copies of the inner
list.


Why "**"? Why not "@"?

[[]] @ 5


"shallow" will be the next problem.  Do we also need this?:

      [[[]]]***5 # j/k

I suppose the choice should be limited to 2 options: shallow copy and 
deep copy.

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


Re: Some Issues on Tagging Text

2018-05-24 Thread Cameron Simpson

First up, thank you for a well described problem! Remarks inline below.

On 24May2018 03:13, Subhabrata Banerjee  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
Kilauea
volcano
Janet
Babb
Hawaiian
Volcano
Observatory
Babb
Limu
O
Pele

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()


You might want use this to compose "wordlist":

wordlist=set(open("/python27/taglist.txt","r").read().split())

because it will make your "if word in wordlist" test O(1) instead of O(n), 
which will matter later if your wordlist grows.



   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".


For example, "Hawaiian" is an adjective, and therefore will always be part of a 
compound term.


Can you clarify what makes these taggings you mention "unwanted"?

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


Re: List replication operator

2018-05-24 Thread Cameron Simpson

On 24May2018 18:17, Steven D'Aprano  
wrote:

Python has a sequence replication operator:

py> [1, 2]*3
[1, 2, 1, 2, 1, 2]

Unfortunately, it is prone to a common "gotcha":

py> x = [[]]*5  # make a multi-dimensional list
py> x
[[], [], [], [], []]
py> x[0].append(1)
py> x
[[1], [1], [1], [1], [1]]

The reason for this behaviour is that * does not copy the original list's
items, it simply replicates the references to the items. So we end up
with a new list containing five references to the same inner list.

This is not a bug and changing the behaviour is not an option.

But what do people think about proposing a new list replication with copy
operator?

   [[]]**5

would return a new list consisting of five shallow copies of the inner
list.


I think I'm against it.

Shallow copies are just as easy to get wrong, for much the same reason that * 
can produce a surprise.


So to me this introduces a new operator without much benefit, and possibly 
negative side effects (bcause it makes makes choosing an approach to sequence 
replication harder: which form should I use, per case)? The * is faster while 
the ** is safer... in very limited contexts.


I would rather there were just one model of this replication, and the model we 
have is simple and direct, with exactly the same pitfalls and benefits as 
Python's function parameter default values. So people already need this issue 
in mind to work in the language.


I'm also against the "**" spelling I find, for much the same reasons that 
people oppose allowing "=" and "==" in the same syntactic location: they're 
easy to get wrong through typing inaccuracy.


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


convert a string to a variable

2018-05-24 Thread bruceg113355
I am trying to convert a string to a variable.

I got cases 1 & 2 to work, but not cases 3 & 4.

The print statement in cases 3 & 4 reports the following:
builtins.AttributeError: type object 'animal' has no attribute 'tiger'

I am stuck on creating variables that can be accessed as follows.
  animal.tiger
  self.animal.tiger

Any suggestions?

Thanks,
Bruce


# Tested on Python 3.6.5

# Case 1: This works
indata = 'animal_tiger'
vars()[indata] = "Tigers, big and strong!"
print (animal_tiger)


# Case 2: This works
class animal():
def create (self, indata):
vars(self)[indata] = "Tigers, big and strong!"
print (self.animal_tiger)

tmp = animal()
tmp.create('animal_tiger')


#

# Case 3: This does not work
indata = 'animal.tiger'
vars()[indata] = "Tigers, big and strong!"
print (animal.tiger)


#Case 4: This does not work
class animal():
def create (self, indata):
vars(self)[indata] = "Tigers, big and strong!"
print (self.animal.tiger)

tmp = animal()
tmp.create('animal.tiger')











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


Re: List replication operator

2018-05-24 Thread Paul
How would one make a multi-dimensional list now, with truly-separate sub
lists?  Is there just no way to do it with the replication operator? IE,
would I just have to do
  X = [[], [], [], [], []]

or perhaps write a function to insert new sub lists into a list, or...?

 Thanks

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


Re: List replication operator

2018-05-24 Thread Ben Finney
Paul  writes:

> How would one make a multi-dimensional list now, with truly-separate sub
> lists?  Is there just no way to do it with the replication operator? IE,
> would I just have to do
>   X = [[], [], [], [], []]

The expressions in a comprehension are evaluated each time through. So
this is another way to get that result:

foo = [ [] for __ in range(5) ]

-- 
 \ “We now have access to so much information that we can find |
  `\  support for any prejudice or opinion.” —David Suzuki, 2008-06-27 |
_o__)  |
Ben Finney

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


Re: List replication operator

2018-05-24 Thread MRAB

On 2018-05-25 00:05, Paul wrote:

How would one make a multi-dimensional list now, with truly-separate sub
lists?  Is there just no way to do it with the replication operator? IE,
would I just have to do
   X = [[], [], [], [], []]

or perhaps write a function to insert new sub lists into a list, or...?


For a list of 5 separate lists:

X = [[] for _ in range(5)]
--
https://mail.python.org/mailman/listinfo/python-list


cleaner version of variable, new line

2018-05-24 Thread asa32sd23
hi just seeing if there is a cleaner way to write this. 
 
s1= "kitti"
s2= 'kitti'
i= 3
print(s1+ "\n" + "="*i + "^" + "\n" +s2)

> 
kitti
===^
kitti
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Scripts not downloading Version 3.6.5

2018-05-24 Thread Terry Reedy

On 5/24/2018 11:31 AM, Chester Davies via Python-list wrote:

Hi!

Yesterday I downloaded the latest version of Python, after some fiddling around 
with some command line, getting Python to open files etc, it wasn't able to 
find various pillows, so after a while, I decided to call it a night. I went to 
finish it off today, and discovered my computer had updated Windows, and so 
decided to uninstall everything and start from scratch. Upon redownloading 
Python 3.6.5, and moving to where I want it, I cannot use any of the functions 
required, mainly pip.exe. Upon looking in the scripts folder, it is completely 
empty. I have since tried to reinstall to no avail, and also attempted to do 
various repairs from the installer. How can I rectify this please?


Run python -m ensurepip --upgrade
See https://docs.python.org/3/library/ensurepip.html#module-ensurepip
There should have been an option to do this with 'repair', but anyway...

--
Terry Jan Reedy

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


Re: List replication operator

2018-05-24 Thread Steven D'Aprano
On Thu, 24 May 2018 11:24:41 -0700, Rob Gaddi wrote:

> On 05/24/2018 11:17 AM, Steven D'Aprano wrote:
[...]
>> But what do people think about proposing a new list replication with
>> copy operator?
>> 
>>  [[]]**5
>> 
>> would return a new list consisting of five shallow copies of the inner
>> list.
>> 
>> 
>> Thoughts?
>> 
>> 
>> 
>> 
> I think the same people making that mistake now would still do so
> because they didn't know they needed the special operator.

People aren't born knowing that * is usable with lists, so the fact that 
they won't be born knowing about ** either is not a point against it.

Wherever newbies are learning about * will soon teach them to use ** for 
multi-dimensional lists as well.

> [[] for _ in range(5)] works just as well without adding more syntax.

This doesn't add more syntax. ** is already valid syntax. It is just 
adding a new method to sequences.

For newbies, using a list comp is not obvious or easily discoverable.


-- 
Steve

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


Re: Usenet Gateway

2018-05-24 Thread Michael Torrie
On 05/24/2018 07:10 AM, Chris Green wrote:
> A *thread* yes, but not a whole list.  I.e. if you read this using 
> mail/IMAP you can mark a thread read but you can't mark *all* Python 
> list messages read in one go can you?   With tin/Usenet I look at
> the list of new subjects in the Python group, I may investigate a
> couple of threads, then I just hit 'C' and all of the Python group is
> marked as read.

Sure can.  Just right click on the folder that holds all the python
mailing list messages and click "mark folder read."

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


Re: Usenet Gateway

2018-05-24 Thread Michael Torrie
On 05/24/2018 07:01 AM, Steven D'Aprano wrote:
> On Thu, 24 May 2018 05:44:26 -0600, Michael Torrie wrote:
> 
>> I agree web forums really suck for any kind of multi-user conversation.
> 
> Oh good. Because the Python core-devs are talking about moving to 
> Github's web interface instead of email. Because Github is the future :-)
> 
> https://circleci.com/blog/its-the-future/
> 
> https://hackernoon.com/its-the-future-again-cd038b72dd0b

That's great news. Sigh.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Usenet Gateway

2018-05-24 Thread Michael Torrie
On 05/24/2018 08:20 AM, Grant Edwards wrote:
> But you had to jump through hoops with procmail and server/client side
> filtering to get there.

True, but it takes maybe 30 seconds for each new list I sign up for, and
then it's out of sight, out of mind.  I already do a ton of filtering on
my inbox anyway to move family messages to their own folder, etc.  Hate
to say it, but GMail actually makes it pretty fast and easy to set up
the rule.  Mostly one-click automatic "filter messages like this one."

I agree NNTP is designed for all of this.  I used to spend a lot of time
on Usenet years ago when every uni had its own NNTP server.  And
thunderbird, my preferred client, can use NNTP.  But the mailing list
works and has, for me, almost no spam, so there's no real incentive for
me to change.

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


Re: cleaner version of variable, new line

2018-05-24 Thread MRAB

On 2018-05-25 01:50, asa32s...@gmail.com wrote:

hi just seeing if there is a cleaner way to write this.
  
s1= "kitti"

s2= 'kitti'
i= 3
print(s1+ "\n" + "="*i + "^" + "\n" +s2)




kitti
===^
kitti


When printing, I'd probably just go for something clear and simple:

print(s1)
print("=" * i + "^")
print(s2)

There's no need to cram it all onto one line.
--
https://mail.python.org/mailman/listinfo/python-list


why do I get syntax error on if : break

2018-05-24 Thread asa32sd23
here is the code, i keep getting an error, "break outside loop". if it is false 
just exit function


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

d('k')
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: cleaner version of variable, new line

2018-05-24 Thread Steven D'Aprano
On Thu, 24 May 2018 17:50:53 -0700, asa32sd23 wrote:

> hi just seeing if there is a cleaner way to write this.
>  
> s1= "kitti"
> s2= 'kitti'
> i= 3
> print(s1+ "\n" + "="*i + "^" + "\n" +s2)


s = "kitti"
i = 3
print(s, "="*i + "^", s, sep='\n')





-- 
Steve

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


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

2018-05-24 Thread boB Stepp
On Thu, May 24, 2018 at 9:12 PM,   wrote:
> here is the code, i keep getting an error, "break outside loop". if it is 
> false just exit function
>
>
> def d(idx):
> if type(idx) != int:
> break
>
> d('k')

"break" (and "continue") are only meaningful inside for or while
loops.  You do not have one of these inside your function.  See
https://docs.python.org/3/reference/simple_stmts.html#break

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


Re: List replication operator

2018-05-24 Thread Steven D'Aprano
On Thu, 24 May 2018 15:12:09 -0400, Ned Batchelder wrote:

> On 5/24/18 2:17 PM, Steven D'Aprano wrote:
[...]
>> But what do people think about proposing a new list replication with
>> copy operator?
>>
>>  [[]]**5
>>
>> would return a new list consisting of five shallow copies of the inner
>> list.
>>
> "shallow" will be the next problem.  Do we also need this?:
> 
>      [[[]]]***5 # j/k

You might be right: on further thought, I think I want deep copies, not 
shallow.

Originally I thought that deep copies was an YAGNI. Have you *ever* seen 
anyone complain that * didn't make a deep copy of the list contents? I 
never have. But then I realised that if this works, people will surely 
try to use it to make three-dimensional lists as well as two, and for 
that we need deep copies.


-- 
Steve

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


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

2018-05-24 Thread Steven D'Aprano
On Thu, 24 May 2018 19:12:33 -0700, asa32sd23 wrote:

> here is the code, i keep getting an error, "break outside loop". if it
> is false just exit function

break doesn't exit the function, it exits the loop. There is no loop to 
exit, so it is an error.

Believe the compiler when it tells you there is a syntax error with your 
code. The compiler is always correct.



-- 
Steve

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


Re: List replication operator

2018-05-24 Thread Steven D'Aprano
On Fri, 25 May 2018 08:02:38 +1000, Cameron Simpson wrote:

> I'm also against the "**" spelling I find, for much the same reasons
> that people oppose allowing "=" and "==" in the same syntactic location:
> they're easy to get wrong through typing inaccuracy.

Do you often write

   y = 2**x

when you meant 2*x?

In any case, I'm not wedded to the ** spelling, MRAB's suggestion of @ 
would work for me too.


-- 
Steve

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


Re: List replication operator

2018-05-24 Thread Steven D'Aprano
On Thu, 24 May 2018 16:05:32 -0700, Paul wrote:

> How would one make a multi-dimensional list now, with truly-separate sub
> lists?  Is there just no way to do it with the replication operator?

Correct. Let's say you want to make a 1-D list with three items 
initialised to zero. This works brilliantly:

py> [0]*3
[0, 0, 0]

This seems like it ought to create a 3x3 2-D list:

py> y = [[0]*3]*3
py> y
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]


but alas, it's a trap:

py> y[0][0] = 1
py> y
[[1, 0, 0], [1, 0, 0], [1, 0, 0]]


The current recommended solution is:

py> y = [[0]*3 for _ in range(3)]
py> y[0][0] = 1
py> y
[[1, 0, 0], [0, 0, 0], [0, 0, 0]]


To get a three-dimensional 3x3x3 list is even more work:

py> z = [[[0]*3 for _ in range(3)] for _ in range(3)]
py> z[0][0][0] = 1
py> z[1][1][1] = 2
py> z[2][2][2] = 3
py> z
[[[1, 0, 0], [0, 0, 0], [0, 0, 0]], 
 [[0, 0, 0], [0, 2, 0], [0, 0, 0]],
 [[0, 0, 0], [0, 0, 0], [0, 0, 3]]]



With my suggestion, we get:

x = [0]**3  # one-dimensional
y = [[0]**3]**3  # two-dimensional
z = [[[0]**3]**3]**3  # three-dimensional

Or there's MRAB's suggestion of using @ instead.

The one-dimensional case can be optimized by using regular * replication 
instead of ** duplication, but that's an optimization for immutable 
objects.


Here's a subclass that implements a simple version of this for testing:

class ML(list):
def __pow__(self, other):
import copy
L = []
for i in range(other):
L.extend(copy.deepcopy(obj) for obj in self)
return ML(L)


And in use to generate a 3-D list:

py> z = ML([ML([ML([0])**3])**3])**3
py> z[0][0][0] = 1
py> z[1][1][1] = 2
py> z[2][2][2] = 3
py> z
[[[1, 0, 0], [0, 0, 0], [0, 0, 0]],
 [[0, 0, 0], [0, 2, 0], [0, 0, 0]],
 [[0, 0, 0], [0, 0, 0], [0, 0, 3]]]


The repeated calls to ML() are ugly and are only there because the [] 
syntax creates ordinary lists, not my subclass.


-- 
Steve

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


Re: cleaner version of variable, new line

2018-05-24 Thread asa32sd23
On Thursday, May 24, 2018 at 8:51:07 PM UTC-4, asa3...@gmail.com wrote:
> hi just seeing if there is a cleaner way to write this. 
>  
> s1= "kitti"
> s2= 'kitti'
> i= 3
> print(s1+ "\n" + "="*i + "^" + "\n" +s2)
> 
> > 
> kitti
> ===^
> kitti

more legible that way... thks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List replication operator

2018-05-24 Thread Paul
how often would people here have needed this new operator, if it had
existed?
-- 
https://mail.python.org/mailman/listinfo/python-list


Raw string statement (proposal)

2018-05-24 Thread Mikhail V
Hi.
I've put some thoughts together, and
need some feedback on this proposal.
Main question is:  Is it convincing?
Is there any flaw?
My own opinion - there IS something to chase.
Still the justification for such syntax is hard.



Raw string statement
--

Issue
-

Vast majority of tasks include operations with text in
various grades of complexity. It is relevant even by
simple ubiquitous tasks, like for example defining file paths.
String literals are interpreted - i.e. special character "\" may
change the contents of a string.
Python raw string r"" has the least amount of such cases :
namely the inclusion of the quote character requires escaping.
There is still no string type which is totally uninterpreted.
As a result, any text piece that contains a quote must
be *edited* before it can be used in sources.

This may seem a minor problem, but if we count all
cases, then the cumulative long-term impact may be significant.
Also this problem may become more acute in cases related to:
- development of text/code generators
- and, in general, all text processing with a lot of
  literal data definition
- proofreading

Such applications may *require* a lot of embedded text definitions and
this may even lead to frustration by proofreading of 'escaped' pieces
and it adds necessity for keeping track of changes in these pieces.
Using external resources for these tasks could help, but it may lead to
even worse experience because of spread definitions
and increased maintenance times.

The most common solution in existing syntax - triple quoted
strings and raw strings has some additional issues:

- Data is parsed including indents. This may be a benefit for some
cases (e.g. start lines always without any indent) but it also may
become confusing for the readers when not aligned with
containing block. So-called "de-denting" is also needed.

- Triple quotes cause visual ambiguity in some edge-cases,
e.g. when a string starts or ends with a quote. Also in many fonts
a pair of single quotes is visually identical to one double quote.


Proposal
---

Current proposal suggests adding syntax for the "raw text" statement.
This should enable the possibility to define text pieces in source
code without the need for interpreted characters.
Thereby it should solve the mentioned issues.
Additionally it should solve some issues with visual appearance.


Specification
-

Raw string statement has the following form:

name >>> "condition_string"
... text ...

in example:

data >>> "  "
  begin
  end
#rest

will parse the block by comparing each next
line part with the string "  " (2 spaces here).
This will return: "  begin\n  end"

-- Additional option: parse and remove:

data >>> !"  "
  begin
  end
#rest

Will parse by the same rule but also remove
the string from the result: "begin\nend"

- Additional option: parse *until* condition:

data >>> ?"#eof"
begin
end
#eof

Will parse up to character sequence "#eof" (if it is on the
same level) and returns: "begin\nend".
The benefit of last option - the data can be put at zero
level. It may be also prefered due to explicit terminator.


General rules:

- parsing is aware of the indent of containing
  block, i.e. no de-dention needed.
- single line assignment may be allowed with
  some restrictions.

Difficulties:

- change of core parsing rules
- backward compatibility broken
- syntax highlighting may not work
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: List replication operator

2018-05-24 Thread Cameron Simpson

On 25May2018 02:25, Steven D'Aprano  
wrote:

On Thu, 24 May 2018 15:12:09 -0400, Ned Batchelder wrote:

On 5/24/18 2:17 PM, Steven D'Aprano wrote:

[...]

But what do people think about proposing a new list replication with
copy operator?

 [[]]**5

would return a new list consisting of five shallow copies of the inner
list.


"shallow" will be the next problem.  Do we also need this?:

     [[[]]]***5 # j/k


You might be right: on further thought, I think I want deep copies, not
shallow.

Originally I thought that deep copies was an YAGNI. Have you *ever* seen
anyone complain that * didn't make a deep copy of the list contents? I
never have. But then I realised that if this works, people will surely
try to use it to make three-dimensional lists as well as two, and for
that we need deep copies.


In the deep copy scenario I am far far less opposed - _that_ is practically 
exponential memory use, and so the "**" is much more apt :-)


I think I'm basicly against a shallow copy and not against a deep copy, because 
the shallow copy only pushes the issue out one layer.


So, how to various forms of multidimensional lists play out as code?

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


Re: List replication operator

2018-05-24 Thread Cameron Simpson

On 25May2018 02:32, Steven D'Aprano  
wrote:

On Fri, 25 May 2018 08:02:38 +1000, Cameron Simpson wrote:


I'm also against the "**" spelling I find, for much the same reasons
that people oppose allowing "=" and "==" in the same syntactic location:
they're easy to get wrong through typing inaccuracy.


Do you often write

  y = 2**x

when you meant 2*x?


Well, no, but in that context they mean very different things. Your * vs ** 
mean very similar things.



In any case, I'm not wedded to the ** spelling, MRAB's suggestion of @
would work for me too.


Hmm, perhaps.

I rarely use the * list replicator myself (though I used it just the other day 
to prefill a list with None). What's your commonest use case? And also, what's 
you're commonest use case which is prone the the issue a shallow copy would 
help with?


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


Re: convert a string to a variable

2018-05-24 Thread dieter
bruceg113...@gmail.com writes:

> I am trying to convert a string to a variable.
>
> I got cases 1 & 2 to work, but not cases 3 & 4.
>
> The print statement in cases 3 & 4 reports the following:
> builtins.AttributeError: type object 'animal' has no attribute 'tiger'
> 
> I am stuck on creating variables that can be accessed as follows.
>   animal.tiger
>   self.animal.tiger
>
> Any suggestions?
> ...
> # Case 3: This does not work
> indata = 'animal.tiger'
> vars()[indata] = "Tigers, big and strong!"
> print (animal.tiger)

In the expression "animal.tiger", the "variable" is "animal",
not "animal.tiger". It is evaluated as follows:
determine the object bound to "animal", access its attribute "tiger".
Your error message tells you that the first step (object bound
to "animal") has been successful, but the result lacks the
attribute "tiger".

> #Case 4: This does not work
> class animal():
> def create (self, indata):
> vars(self)[indata] = "Tigers, big and strong!"

Here you want to define the attribute "tiger" (I think),
not "animal.tiger". Note that the "." in a Python expression
(not a string) separates two individual steps: determine
an object corresponding to the leftside to the "."; access
the attribute corresponding to the name following the ".".
> print (self.animal.tiger)
>
> tmp = animal()
> tmp.create('animal.tiger')

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


Re: List replication operator

2018-05-24 Thread Stefan Behnel
Steven D'Aprano schrieb am 25.05.2018 um 04:25:
> On Thu, 24 May 2018 15:12:09 -0400, Ned Batchelder wrote:
> 
>> On 5/24/18 2:17 PM, Steven D'Aprano wrote:
> [...]
>>> But what do people think about proposing a new list replication with
>>> copy operator?
>>>
>>>  [[]]**5
>>>
>>> would return a new list consisting of five shallow copies of the inner
>>> list.
>>>
>> "shallow" will be the next problem.  Do we also need this?:
>>
>>      [[[]]]***5 # j/k
> 
> You might be right: on further thought, I think I want deep copies, not 
> shallow.

But how would that protocol work then? What would happen with a data
structure like this:

[( 1, [1, 2, 3] )] ** 3

? Would it also deep copy the tuple, or ignore it? What about other,
non-builtin sequence types? The '**' operator cannot just recursively call
'**' on the items in the list, because they may not support it. Or they may
support it, but not in the expected way.

And limiting this to lists of lists seems rather arbitrary. What about
subtypes of lists?

Calling "copy.deepcopy()" internally instead of a recursive '**' doesn't
seem safe either, because it also wouldn't know where to stop.

Stefan

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


Re: List replication operator

2018-05-24 Thread Steven D'Aprano
On Fri, 25 May 2018 08:11:52 +0200, Stefan Behnel wrote:

> Steven D'Aprano schrieb am 25.05.2018 um 04:25:
[...]

>> You might be right: on further thought, I think I want deep copies, not
>> shallow.
> 
> But how would that protocol work then? What would happen with a data
> structure like this:
> 
> [( 1, [1, 2, 3] )] ** 3
> 
> ? Would it also deep copy the tuple, or ignore it? 

It would deep-copy the items. It would do whatever copy.deepcopy() does, 
which is deep-copy the object *all the way down*.


> What about other, non-builtin sequence types?

I've concentrated on lists because that's usually the sequence type used. 
Adding ** (or @ if you prefer) could be made part of the sequence API if 
needed, but I'd be happy to start with lists and see if there is a demand 
to add it to other objects as well.


> The '**' operator cannot just recursively
> call '**' on the items in the list, because they may not support it. Or
> they may support it, but not in the expected way.

Nobody is talking about calling ** recursively.

I gave a simple implementation. No recursion is needed, except inside 
deepcopy, which is already a solved problem.


> And limiting this to lists of lists seems rather arbitrary. What about
> subtypes of lists?

Perhaps you have heard of inheritance? If lists support this, their 
subclasses will automatically support it too, unless you override the 
relevant methods.


> Calling "copy.deepcopy()" internally instead of a recursive '**' doesn't
> seem safe either, because it also wouldn't know where to stop.

Of course it does. It stops when it has copied everything, all the way 
down. That's what it does.



-- 
Steve

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


Re: List replication operator

2018-05-24 Thread Steven D'Aprano
On Fri, 25 May 2018 15:30:36 +1000, Cameron Simpson wrote:

> So, how to various forms of multidimensional lists play out as code?

With my suggestion, we get:

x = [0]**3  # one-dimensional
y = [[0]**3]**3  # two-dimensional
z = [[[0]**3]**3]**3  # three-dimensional

Or there's MRAB's suggestion of using @ instead of the ** operator.

The one-dimensional case can be optimized by using regular * replication
instead of ** duplication, but that's an optimization for immutable
objects. Its pretty much harmless to write ** instead of * for the common 
case of a list filled with immutable ints or None.



Here's a subclass that implements a simple version of this for testing:

class ML(list):
def __pow__(self, other):
import copy
L = []
for i in range(other):
L.extend(copy.deepcopy(obj) for obj in self)
return ML(L)


And in use to generate a 3-D list:

py> z = ML([ML([ML([0])**3])**3])**3
py> z[0][0][0] = 1
py> z[1][1][1] = 2
py> z[2][2][2] = 3
py> z
[[[1, 0, 0], [0, 0, 0], [0, 0, 0]],
 [[0, 0, 0], [0, 2, 0], [0, 0, 0]],
 [[0, 0, 0], [0, 0, 0], [0, 0, 3]]]


The repeated calls to ML() are ugly and are only there because the []
syntax creates ordinary lists, not my subclass.



-- 
Steve

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


Re: List replication operator

2018-05-24 Thread Steven D'Aprano
On Fri, 25 May 2018 02:45:38 +, Paul wrote:

> how often would people here have needed this new operator, if it had
> existed?

It is common enough that it is a FAQ on the Python website.

The list * operator isn't the most heavily used operator, but it does get 
used a bit. It comes up quite frequently in tutorials, Stackoverflow, etc.

https://www.google.com/search?q=python+multidimensional+list




-- 
Steve

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