Re: What you can do about legalese nonsense on email (was: How to split value where is comma ?)

2016-09-09 Thread Rustom Mody
On Friday, September 9, 2016 at 2:37:48 AM UTC+5:30, Ben Finney wrote:
> Joaquin Alzola writes:
> > Added by the MTA of the company not by my client.
> 
> Right. So, here are things you can do (that we cannot) about this:
> * Switch to a different mail service, one which does not add that
>   nonsense to your email.

Here is a recent action of google that has received at the moment 337,048
petitions:
https://www.change.org/p/google-inc-google-put-palestine-on-your-maps

Do you believe that Google is more ethical than Lebara?

Ok you didn't suggest to use gmail (ie google) specifically

So what do you suggest to people (like myself) who’s primary email is gmail
and are incensed with such actions??
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to extend a tuple of tuples?

2016-09-09 Thread dieter
"Frank Millman"  writes:

> Hi all
>
> This should be easy, but I cannot figure it out.
>
> Assume you have a tuple of tuples -
>
> a = ((1, 2), (3, 4))
>
> You want to add a new tuple to it, so that it becomes -
>
>((1, 2), (3, 4), (5, 6))
>
> The obvious way does not work -
>
> a += (5, 6)
>
>((1, 2), (3, 4), 5, 6)

You could use:

  a += (5, 6),

or (more clearly written):

  a += ((5, 6),)

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


Re: How to extend a tuple of tuples?

2016-09-09 Thread Rustom Mody
On Friday, September 9, 2016 at 12:18:24 PM UTC+5:30, Frank Millman wrote:
> Hi all
> 
> This should be easy, but I cannot figure it out.
> 
> Assume you have a tuple of tuples -
> 
> a = ((1, 2), (3, 4))
> 
> You want to add a new tuple to it, so that it becomes -
> 
> ((1, 2), (3, 4), (5, 6))

Your example does not add inside the inner tuples
So I am simplifying the question to

> Assume you have a tuple of tuples -
> 
> a = (1 2 3)
> 
> You want to add a new element to it, so that it becomes -
> 
> (1 2 3 4)


>>> t = (1,2,3)
>>> new = t + (4,)
>>> new
(1, 2, 3, 4)
>>> 

Slightly harder if the new addition were inbetween
>>> t = (1,2,3)
>>> t[:1]
(1,)
>>> t[1:]
(2, 3)
>>> t[:1] + (42,) + t[1:]
(1, 42, 2, 3)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What you can do about legalese nonsense on email

2016-09-09 Thread Rustom Mody
On Friday, September 9, 2016 at 6:49:52 AM UTC+5:30, Terry Reedy wrote:
> On 9/8/2016 4:52 PM, Ben Finney wrote:
> > Joaquin Alzola writes:
> >>  >> the world?
> >>
> >> Cannot do anything.
> >
> > That's not true; you can do more than we.
> >
> >> Added by the MTA of the company not by my client.
> >
> > Right. So, here are things you can do (that we cannot) about this:
> 
> Something that some 'we' could do is ask the python-list 
> manager/programmers, or more broadly, the mailman developers, to 
> recognize an 'end of message' line, such as '--end message--' and delete 
> it and anything appended thereafter.  Then Joaquin and people in a 
> similar situation could add the magic line as the end of a signature block.
> 
> -- 
> Terry Jan Reedy

Thanks Terry for a constructive thought.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to extend a tuple of tuples?

2016-09-09 Thread Ben Finney
"Frank Millman"  writes:

> Assume you have a tuple of tuples -
>
> a = ((1, 2), (3, 4))
>
> You want to add a new tuple to it, so that it becomes

As you acknowledge, the tuple ‘a’ can't become anything else. Instead,
you need to create a different value.

> The obvious way does not work -
>
> a += (5, 6)
>
>((1, 2), (3, 4), 5, 6)

Right, because a tuple is immutable.

So instead, you want a different tuple. You do that by creating it,
explicitly constructing a new sequence with the items you want::

b = tuple([
item for item in a
] + [(5, 6)])

-- 
 \“Look at it this way: Think of how stupid the average person |
  `\ is, and then realise half of 'em are stupider than that.” |
_o__)   —George Carlin, _Doin' It Again_, 1990 |
Ben Finney

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


Is it possible to process dist files before they are build via a setuptools hook?

2016-09-09 Thread Mark Summerfield
Hi,

I use setuptools (in my case with cx_Freeze) to package some of my Python 
applications.

As part of this process a build\exe.win-amd64-3.4 dir is created with all the 
necessary files, and then a separate dist\ dir is created with the 
distributable package (e.g., a .msi file).

I'd like to run UPX https://upx.github.io/ on all the .dll, .py, and .exe files 
in the build dir _before_ they are put into the distributable package.

So, I need to have some hook that lets me run a python script after the build 
dir has been populated but before the distributable is made -- is this possible?

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


Re: How to extend a tuple of tuples?

2016-09-09 Thread Jussi Piitulainen
Ben Finney writes:

> Frank Millman writes:
>
>> Assume you have a tuple of tuples -
>>
>> a = ((1, 2), (3, 4))
>>
>> You want to add a new tuple to it, so that it becomes
>
> As you acknowledge, the tuple ‘a’ can't become anything else. Instead,
> you need to create a different value.
>
>> The obvious way does not work -
>>
>> a += (5, 6)
>>
>>((1, 2), (3, 4), 5, 6)
>
> Right, because a tuple is immutable.
>
> So instead, you want a different tuple. You do that by creating it,
> explicitly constructing a new sequence with the items you want::
>
> b = tuple([
> item for item in a
> ] + [(5, 6)])

b = tuple(list(a) + [(5,6)])

b = a + tuple([(5,6)])

b = a + ((5,6),)

b = tuple(itertools.chain(iter(a), iter(((5,6), # :
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers?

2016-09-09 Thread Chi Hsuan Yen
On Fri, Sep 9, 2016 at 2:54 PM, dieter  wrote:

> Chi Hsuan Yen  writes:
> > ...
> > Thanks a lot! I just lost my direction when trying to understand how
> > certificate verification works in Python.
>
> It sets things up for "OpenSSL" and then delegates all details
> to it.
>
>
Thanks, sounds a great start point. I'll look into OpenSSL.


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


Re: How to split value where is comma ?

2016-09-09 Thread Chris Angelico
On Fri, Sep 9, 2016 at 4:20 PM, Rustom Mody  wrote:
> [Personal note: When I was a kid I thought that doctors removed fever by 
> sticking
> a thermometer into one’s mouth.
> Those who teach that programming needs to start with writing print statements
> are the same except for not having the excuse of being kids]

I agree. People should learn that print is not a statement any more,
it's a function.

And then use it. Use it often, use it early. Know what your program is doing.

Practicality beats pure functional programming?

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


Re: Suggestions to improve a code

2016-09-09 Thread Lawrence D’Oliveiro
On Wednesday, September 7, 2016 at 2:55:37 AM UTC+12, GP wrote:
>   MaxLengthOfItem_Index =f_LMax(shelves2,MaxLengthOfItem)

MaxLengthOfItem_Index = max(range(len(shelves2)), key = lambda i : 
shelves2[i]["Length"])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP 492: isn't the "await" redundant?

2016-09-09 Thread Lawrence D’Oliveiro
On Friday, August 26, 2016 at 10:08:25 PM UTC+12, Marko Rauhamaa wrote:
> Ultimately, asyncio and multithreading might well merge. It will be
> difficult for a programmer to decide in the beginning of the design
> which way to go as the programming models are almost identical.

The two will never merge, because asyncio is non-preemptive, while threading is 
preemptive. Threading is for compute performance (and this is no good in pure 
Python unless you write a C extension module), at the cost of much trickier 
programming and greater propensity to bugs, while asyncio lets you interleave 
background processing with waits for time-consuming external activities (I/O, 
including network I/O, or just waiting for the user to click a button or press 
a key), while keeping the race conditions manageable.

So you see, they have very different application areas, that only superficially 
overlap.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP 492: isn't the "await" redundant?

2016-09-09 Thread Chris Angelico
On Fri, Sep 9, 2016 at 7:23 PM, Lawrence D’Oliveiro
 wrote:
> On Friday, August 26, 2016 at 10:08:25 PM UTC+12, Marko Rauhamaa wrote:
>> Ultimately, asyncio and multithreading might well merge. It will be
>> difficult for a programmer to decide in the beginning of the design
>> which way to go as the programming models are almost identical.
>
> The two will never merge, because asyncio is non-preemptive, while threading 
> is preemptive. Threading is for compute performance (and this is no good in 
> pure Python unless you write a C extension module), at the cost of much 
> trickier programming and greater propensity to bugs, while asyncio lets you 
> interleave background processing with waits for time-consuming external 
> activities (I/O, including network I/O, or just waiting for the user to click 
> a button or press a key), while keeping the race conditions manageable.
>
> So you see, they have very different application areas, that only 
> superficially overlap.

FWIW I think it's great that they have similar coding styles. We don't
have a problem with threading and multiprocessing having very similar
APIs, do we? Yet they exist to solve distinctly different problems.

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


Re: libdivecomputer

2016-09-09 Thread Lawrence D’Oliveiro
On Wednesday, August 24, 2016 at 1:29:55 AM UTC+12, alister wrote:
> I already have an application that works fine (sub-surface) so this is 
> more of a curiosity, delving into ctypes is not something I want to try 
> just yet.

Why not? It would be a great way to learn ctypes. :)
-- 
https://mail.python.org/mailman/listinfo/python-list


ldap or active directory module

2016-09-09 Thread Robert Clove
Is it possible to find the following things using python ldap or active
directory module
I want to find if the particular group exist in my active directory also
another function to find the user in a particular group
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers?

2016-09-09 Thread Chi Hsuan Yen
On Fri, Sep 9, 2016 at 4:18 PM, Chi Hsuan Yen  wrote:

>
>
> On Fri, Sep 9, 2016 at 2:54 PM, dieter  wrote:
>
>> Chi Hsuan Yen  writes:
>> > ...
>> > Thanks a lot! I just lost my direction when trying to understand how
>> > certificate verification works in Python.
>>
>> It sets things up for "OpenSSL" and then delegates all details
>> to it.
>>
>>
> Thanks, sounds a great start point. I'll look into OpenSSL.
>
>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>
I found that OpenSSL provides an X509 callback hook that allows clients to
know why the verification process fails. Seems CPython does not use it yet.
I hope it can be added to CPython. Where should I go next, python-dev,
python-ideas or bugs.python.org? Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


import pybel in python error code

2016-09-09 Thread talari . gopiprashanth . gopi2
ValueErrorTraceback (most recent call last)
 in ()
  1 from django.conf import settings
> 2 import pybel
  3 import random, os

C:\Miniconda2\lib\site-packages\pybel.py in ()
 67 _obconv = ob.OBConversion()
 68 _builder = ob.OBBuilder()
---> 69 informats = _formatstodict(_obconv.GetSupportedInputFormat())
 70 """A dictionary of supported input formats"""
 71 outformats = _formatstodict(_obconv.GetSupportedOutputFormat())

C:\Miniconda2\lib\site-packages\pybel.py in _formatstodict(list)
 63 list = [list.get(i) for i in range(list.size())]
 64 broken = [x.replace("[Read-only]", 
"").replace("[Write-only]","").split(" -- ") for x in list]
---> 65 broken = [(x,y.strip()) for x,y in broken]
 66 return dict(broken)
 67 _obconv = ob.OBConversion()

ValueError: need more than 1 value to unpack
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers?

2016-09-09 Thread Chris Angelico
On Fri, Sep 9, 2016 at 7:47 PM, Chi Hsuan Yen  wrote:
> I found that OpenSSL provides an X509 callback hook that allows clients to
> know why the verification process fails. Seems CPython does not use it yet.
> I hope it can be added to CPython. Where should I go next, python-dev,
> python-ideas or bugs.python.org? Thanks.

Are you wanting a way to provide a custom callback from your
application, or have this as a standard feature that enhances the
error return?

Either way, I would go to python-ideas with details about what you're
hoping for. It sounds like it's not going to be overly complex, so it
might end up just going straight to the tracker, but I'd start with
-ideas.

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


Re: How to diagnose CERTIFICATE_VERIFY_FAILED on Windows for websites working in browsers?

2016-09-09 Thread Chi Hsuan Yen
On Fri, Sep 9, 2016 at 5:52 PM, Chris Angelico  wrote:

> On Fri, Sep 9, 2016 at 7:47 PM, Chi Hsuan Yen  wrote:
> > I found that OpenSSL provides an X509 callback hook that allows clients
> to
> > know why the verification process fails. Seems CPython does not use it
> yet.
> > I hope it can be added to CPython. Where should I go next, python-dev,
> > python-ideas or bugs.python.org? Thanks.
>
> Are you wanting a way to provide a custom callback from your
> application, or have this as a standard feature that enhances the
> error return?
>
> Either way, I would go to python-ideas with details about what you're
> hoping for. It sounds like it's not going to be overly complex, so it
> might end up just going straight to the tracker, but I'd start with
> -ideas.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Thanks. I'll try to organize what I want and post to python-ideas.

Best,

Yen Chi Hsuan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to extend a tuple of tuples?

2016-09-09 Thread Steve D'Aprano
On Fri, 9 Sep 2016 04:47 pm, Frank Millman wrote:

> Hi all
> 
> This should be easy, but I cannot figure it out.
> 
> Assume you have a tuple of tuples -
> 
> a = ((1, 2), (3, 4))
> 
> You want to add a new tuple to it, so that it becomes -
> 
> ((1, 2), (3, 4), (5, 6))


a = a + ((5, 6),)


You might think that you can just add (5, 6) but that doesn't work:

py> a + (5, 6)
((1, 2), (3, 4), 5, 6)


The plus operator builds a new tuple containing the contents of each of the
two tuples concatenated, so to get the result that you want you need a
tuple containing (5, 6) as the one and only item. Because that's a tuple
with one item, you need a trailing comma:

py> len( ((5, 6),) )
1
py> a + ((5, 6),)
((1, 2), (3, 4), (5, 6))





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: How to extend a tuple of tuples?

2016-09-09 Thread Frank Millman
"Frank Millman"  wrote in message news:nqtlue$unj$1...@blaine.gmane.org... 


Assume you have a tuple of tuples -



a = ((1, 2), (3, 4))



You want to add a new tuple to it, so that it becomes -



((1, 2), (3, 4), (5, 6))


Thanks all.

The one I was looking for was 


   a += (5, 6),

I understand it now - makes perfect sense.

Frank


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


Re: libdivecomputer

2016-09-09 Thread alister
On Fri, 09 Sep 2016 02:26:02 -0700, Lawrence D’Oliveiro wrote:

> On Wednesday, August 24, 2016 at 1:29:55 AM UTC+12, alister wrote:
>> I already have an application that works fine (sub-surface) so this is
>> more of a curiosity, delving into ctypes is not something I want to try
>> just yet.
> 
> Why not? It would be a great way to learn ctypes. :)


indeed it would, however I really don't wish to get bogged down in low 
level stuff any more (ok a necessary evil with my AVR programming but 
that is all very basic anyway) which is why i decided on python as my 
language of choice.



-- 
Ginsberg's Theorem:
(1) You can't win.
(2) You can't break even.
(3) You can't even quit the game.

Freeman's Commentary on Ginsberg's theorem:
Every major philosophy that attempts to make life seem
meaningful is based on the negation of one part of Ginsberg's
Theorem.  To wit:

(1) Capitalism is based on the assumption that you can win.
(2) Socialism is based on the assumption that you can break even.
(3) Mysticism is based on the assumption that you can quit the 
game.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What you can do about legalese nonsense on email (was: How to split value where is comma ?)

2016-09-09 Thread Steve D'Aprano
On Fri, 9 Sep 2016 04:59 pm, Rustom Mody wrote:

> On Friday, September 9, 2016 at 2:37:48 AM UTC+5:30, Ben Finney wrote:
>> Joaquin Alzola writes:
>> > Added by the MTA of the company not by my client.
>> 
>> Right. So, here are things you can do (that we cannot) about this:
>> * Switch to a different mail service, one which does not add that
>>   nonsense to your email.
> 
> Here is a recent action of google that has received at the moment 337,048
> petitions:
> https://www.change.org/p/google-inc-google-put-palestine-on-your-maps
> 
> Do you believe that Google is more ethical than Lebara?

Hell no!

http://img0.joyreactor.com/pics/post/comics-google-facebook-245504.jpeg

But in this specific case, Google is not entirely in the wrong re Palestine.
It *is* a disputed area, and Google cannot satisfy everyone no matter what
they do.

If you search for "Palestine" in Google Maps, you get a map which (at least
in Australia) clearly shows the West Bank and Gaza Strip as disputed
territories:

https://www.google.com.au/maps/place/Palestine/

More here:

https://www.theguardian.com/technology/2016/aug/10/google-maps-accused-remove-palestine

http://opennews.kzhu.io/map-disputes/?_ga=1.48243875.420098949.1397702661



> Ok you didn't suggest to use gmail (ie google) specifically
> 
> So what do you suggest to people (like myself) who’s primary email is
> gmail and are incensed with such actions??

Whatever you do, don't use Yahoo Mail or AOL unless there is *absolutely* no
other alternative. They are actively hostile to mailing lists and even
worse for good email practice than Gmail.

I don't know about others, but most ISPs in Australia offer at least one
email address per customer. So although there aren't many *great*
alternatives to Gmail, there are some good and so-so alternatives:


* run your own mail server (easy enough that I can do it)
* your work or school email
* your ISP email
* Outlook.Com (Hotmail)





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: nested loops in Python

2016-09-09 Thread Igor Kozin
I think you are right, it's the assignment itself which is slow.
Merged loop is only a tad quicker.

On Thursday, September 8, 2016 at 6:04:41 PM UTC+1, Christian Gollwitzer wrote:
> > Why nested loops are so slow in Python? Is it because new contexts are 
> > created?
> > For more details, see
> > http://stackoverflow.com/questions/26611043/numpy-vs-cython-nested-loop-so-slow
> > http://stackoverflow.com/questions/39371021/efficient-loop-over-numpy-array
> 
> The answers are right there, too - what are you mising? CPython is an 
> interpreter. For every seemingly simple operation like a[i]=j, a 
> function pointer is called, the variables contain polymorphic types 
> which are morphed, etc. The same thing in compiled code is a single 
> machine instruction. Speed differences of ~100x are normal between 
> compiled and interpreted code over all dynamic languages.
> 
>   Christian

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


Re: What you can do about legalese nonsense on email (was: How to split value where is comma ?)

2016-09-09 Thread D'Arcy J.M. Cain
On Thu, 08 Sep 2016 18:27:44 -0400
Random832  wrote:
> If every lawyer in the world benefits from the interpretation that
> this sort of notice is legally effective (since tomorrow it may be
> they who accidentaly send privileged information), who will argue in
> court that it's not? The reality is more complex, and it appears that
> it may only apply if the accidental recipient is a lawyer. I really

I often wonder if these automatic disclaimers actually remove any
protection that they might have if they were used judiciously.  If they
had any validity wouldn't the fact that they are attached to every
email, even ones obviously meant for the public, give someone an
argument that they don't really apply?

-- 
D'Arcy J.M. Cain
System Administrator, Vex.Net
http://www.Vex.Net/ IM:da...@vex.net
VoIP: sip:da...@vex.net
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP 492: isn't the "await" redundant?

2016-09-09 Thread Marko Rauhamaa
Chris Angelico :
> FWIW I think it's great that they have similar coding styles. We don't
> have a problem with threading and multiprocessing having very similar
> APIs, do we? Yet they exist to solve distinctly different problems.

Well, Ext4, BtrFS, XFS and ReiserFS have very similar APIs. In fact,
they exist to solve the same problems. One day, a file system might
emerge that supersedes all other file systems.

It's a similar deal between asyncio and threading. The problem space is
the same: managing concurrency with almost identical programming models.


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


Re: import pybel in python error code

2016-09-09 Thread Peter Otten
talari.gopiprashanth.go...@gmail.com wrote:

> ValueErrorTraceback (most recent call
> last)  in ()
>   1 from django.conf import settings
> > 2 import pybel
>   3 import random, os
> 
> C:\Miniconda2\lib\site-packages\pybel.py in ()
>  67 _obconv = ob.OBConversion()
>  68 _builder = ob.OBBuilder()
> ---> 69 informats = _formatstodict(_obconv.GetSupportedInputFormat())
>  70 """A dictionary of supported input formats"""
>  71 outformats = _formatstodict(_obconv.GetSupportedOutputFormat())
> 
> C:\Miniconda2\lib\site-packages\pybel.py in _formatstodict(list)
>  63 list = [list.get(i) for i in range(list.size())]
>  64 broken = [x.replace("[Read-only]",
>  "").replace("[Write-only]","").split(" -- ") for x in list]
> ---> 65 broken = [(x,y.strip()) for x,y in broken]
>  66 return dict(broken)
>  67 _obconv = ob.OBConversion()
> 
> ValueError: need more than 1 value to unpack

What does

>>> import openbabel
>>> [s for s in openbabel.OBConversion().GetSupportedInputFormat()
...  if s.count(" -- ") != 1]
[]

print on your machine? There is probably a string that doesn't contain the 
separator " -- " (note the space at the beginning and the end).


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


Re: Suggestions to improve a code

2016-09-09 Thread jmp

On 09/06/2016 04:55 PM, GP wrote:

I have a list:
shelves2 =[{'Part No': '1', 'Length': 610.0,  'Width': 50.0},
{'Part No': '2', 'Length': 2319.0, 'Width': 465.0 },
{'Part No': '3', 'Length': 5.0,'Width': 465.0}]

The length of shelf is calculated as follows:
  1. Calculate the maximum length of all items in the shelf.
  2. Calculate width of shelf = 610 (in this case).
  3. Length of shelf : maxlength of all items + length ( if it less than width 
of shelf) or width of other items such that length of shelf  is less than 
maximum allowed length.

In the above case the length is 2319+50+5 = 2374. I have the following code which generates it 
correctly but would like to know if there is a better way to write it. I would like to know some 
smarter way to write the code ( especially if the "for", "if" statements can be 
avoided).
   list_1=[]
   list_2=[]
   WidthOfShelf = max([x['Width'] for x in shelves2])
   MaxLengthOfItem =  max([x['Length'] for x in shelves2])
   f_LMax=lambda seq, m: [ii for ii in range(0, len(seq)) if seq[ii] ['Length'] 
>= m][0]
   MaxLengthOfItem_Index =f_LMax(shelves2,MaxLengthOfItem)
   current= MaxLengthOfItem

   list_1=[shelves2[MaxLengthOfItem_Index]]
   list_2 = [MaxLengthOfItem]
   del shelves2[MaxLengthOfItem_Index]
   for i in range(0,len(shelves2)):
if shelves2[i]['Length'] <= Width:
if (current + shelves2[i]['Length']) or (current + shelves2  
[i]['Width'])<= 2438.5 :
q_2= min(shelves2[i]['Length'],  shelves2[i]['Width'])
q=shelves2[i]
list_1.append(q)
list_2.append(q_2)
current += (shelves2[i]['Length'] or shelves2[i]  ['Width'])
length = sum(list_2)
   print("LENGTH:",length)




Hi,

Your code does not make any sense. Before making it smarter, you need to 
make it understandable if you want us to help you.


It's ok to write quick and dirty scripts, until you send them for others 
to review :)


Here are my advices:

1/ use meaningful names
  * list_1, list_2, q_2, q, current give no clue about what information 
they're supposed to hold

  * you can use comments instead as sometimes a short name won't do it

2/ provide code that reproduces your problem, executing the above code 
gives a NameError.

---> 30  if shelves2[i]['Length'] <= Width:
NameError: name 'Width' is not defined

3/ name different things with different names. at the end of your code 
you're printing "length", which is the sum of either length or width fields.
It's difficult to guess what you're trying to achieve. Same confusion 
about the field 'Length' of a shelf, and the length of a shelf that is 
computed elsewhere. My guess would be that a shelf has an innate length, 
and another one depending on the  shelves it's inserted into. If so, 
find 2 different names.


4/ You are iterating like a C/C++ addict. Short story: resist the urge 
to iterate over indexes.


for i in range(0,len(shelves2)):
print(shelves2[i]['Length'])

is best written

for shelf in shelves2:
   print(shelf['Length'])

long story : http://nedbatchelder.com/text/iter.html

5/ use list comprehension to create filtered list:

for shelf in [s for s in shelves2 if s['Length'] <= s['Width']]:
   ...


Hope it helps somehow.

jm

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


Re: How to extend a tuple of tuples?

2016-09-09 Thread Ned Batchelder
On Friday, September 9, 2016 at 6:13:37 AM UTC-4, Frank Millman wrote:
> "Frank Millman"  wrote in message news:nqtlue$unj$1...@blaine.gmane.org... 
> 
> > Assume you have a tuple of tuples -
> 
> > a = ((1, 2), (3, 4))
> 
> > You want to add a new tuple to it, so that it becomes -
> 
> > ((1, 2), (3, 4), (5, 6))
> 
> Thanks all.
> 
> The one I was looking for was 
> 
> a += (5, 6),
> 
> I understand it now - makes perfect sense.

I'm curious why you are using a growing tuple, instead of a list.
This seems like a much more natural use for a list.

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


Re: PEP 492: isn't the "await" redundant?

2016-09-09 Thread Chris Angelico
On Fri, Sep 9, 2016 at 9:26 PM, Marko Rauhamaa  wrote:
> Chris Angelico :
>> FWIW I think it's great that they have similar coding styles. We don't
>> have a problem with threading and multiprocessing having very similar
>> APIs, do we? Yet they exist to solve distinctly different problems.
>
> Well, Ext4, BtrFS, XFS and ReiserFS have very similar APIs. In fact,
> they exist to solve the same problems. One day, a file system might
> emerge that supersedes all other file systems.
>
> It's a similar deal between asyncio and threading. The problem space is
> the same: managing concurrency with almost identical programming models.

C, Python, Ruby, and COBOL exist to solve the same problems, and have
very similar APIs - write your code in a text file, then run it
through some parser so it executes. Are we some day going to eliminate
all programming languages bar one? I doubt it. And I don't want to.

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


Re: How to extend a tuple of tuples?

2016-09-09 Thread Frank Millman
"Ned Batchelder"  wrote in message 
news:44e067ce-f499-4ca8-87bd-94b18dfc0...@googlegroups.com...


On Friday, September 9, 2016 at 6:13:37 AM UTC-4, Frank Millman wrote:

> "Frank Millman"  wrote in message news:nqtlue$unj$1...@blaine.gmane.org...
>
> The one I was looking for was
>
> a += (5, 6),
>
> I understand it now - makes perfect sense.

I'm curious why you are using a growing tuple, instead of a list.
This seems like a much more natural use for a list.



The short answer is that I am using it as a dictionary key.

However, from The Zen of Python -
   If the implementation is hard to explain, it's a bad idea.

Let's see if I can explain.

I am building a series of JOINs for a SQL statement. Some of them can be 
nested - table A is joined from table B is joined from table C. In other 
parts of the same SQL statement, table A could be joined from table D which 
is joined from table E.


For each potential candidate, I need to check if I have already built the 
JOIN. If so, just use it. If not, build it, and update a dictionary to 
indicate that it has been built.


The key to the dictionary is the path to the joined table, which could be 
several levels deep. I build up a tuple to represent the path. Each table 
needs two pieces of information to identify it, so I use a tuple for each 
identifier.


The value portion of the dictionary is simply the alias generated for the 
joined table. I use the alias in the body of the SQL statement.


I don't know if that explains it very well. I can supply more info if anyone 
is curious, or wishes to suggest a better approach.


Frank


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


Re: How to extend a tuple of tuples?

2016-09-09 Thread Chris Angelico
On Fri, Sep 9, 2016 at 10:21 PM, Frank Millman  wrote:
> I am building a series of JOINs for a SQL statement. Some of them can be
> nested - table A is joined from table B is joined from table C. In other
> parts of the same SQL statement, table A could be joined from table D which
> is joined from table E.
>
> For each potential candidate, I need to check if I have already built the
> JOIN. If so, just use it. If not, build it, and update a dictionary to
> indicate that it has been built.
>
> The key to the dictionary is the path to the joined table, which could be
> several levels deep. I build up a tuple to represent the path. Each table
> needs two pieces of information to identify it, so I use a tuple for each
> identifier.
>
> The value portion of the dictionary is simply the alias generated for the
> joined table. I use the alias in the body of the SQL statement.

Sounds fair enough. A tuple is a pretty reasonable way to do this.

The other approach would be to craft the aliases directly, as strings.
For instance, your first example could be JOIN_A_B_C, and your second
JOIN_A_D_E. (Sort the table names alphabetically before "_".join()ing
them if you want order to be insignificant.) Obviously this won't do
if it runs the risk of crashing into length limits in your SQL engine,
but if you find tuples too annoying, this is an equally valid way of
crafting the keys for your dictionary.

Overall, this sounds like one of those horrendously messy pieces of
code that exists because... it's dealing with a horrendously messy
situation. Which, sad to say, happens all too often in real-world
code, much as we'd love to pretend it doesn't in examples on mailing
lists :|

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


Re: PEP 492: isn't the "await" redundant?

2016-09-09 Thread Steve D'Aprano
On Fri, 9 Sep 2016 07:28 pm, Chris Angelico wrote:

> We don't
> have a problem with threading and multiprocessing having very similar
> APIs, do we? Yet they exist to solve distinctly different problems.

Surely not?

I would think that threading and multiprocessing are two distinct
implementations of the same problem: how to run two or more chunks of code
at the same time.

In CPython we usually say "use threads for I/O bound tasks, processes for
CPU bound tasks" but that's only because of the GIL. One doesn't need such
a distinction in Jython or IronPython.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


Re: PEP 492: isn't the "await" redundant?

2016-09-09 Thread Chris Angelico
On Fri, Sep 9, 2016 at 10:27 PM, Steve D'Aprano
 wrote:
> On Fri, 9 Sep 2016 07:28 pm, Chris Angelico wrote:
>
>> We don't
>> have a problem with threading and multiprocessing having very similar
>> APIs, do we? Yet they exist to solve distinctly different problems.
>
> Surely not?
>
> I would think that threading and multiprocessing are two distinct
> implementations of the same problem: how to run two or more chunks of code
> at the same time.
>
> In CPython we usually say "use threads for I/O bound tasks, processes for
> CPU bound tasks" but that's only because of the GIL. One doesn't need such
> a distinction in Jython or IronPython.

You also want to use processes if you need the ability to kill one of
them externally, or track resource usage separately, or have
independence of other process-wide features such as current working
directory. So there are some problems (eg multi-user services) where
the additional isolation is important.

In contrast, you want to use threads if you need the ability to
quickly and easily share mutable data, or if you want all resource
usage to be lumped together - eg if you're not really doing several
separate jobs, but are doing one single conceptual job.

>From a systems administration POV, threads logically belong together,
but processes are distinct beasts that communicate through
clearly-defined IPC. There are times when you want one, and times when
you want the other. The GIL just pulls a specific category of problem
out of the hands of threads and into the hands of processes, due to
its inability to spread Python code across CPU cores; but it didn't
create the distinction. If a future version of CPython eliminates the
GIL and allows threads to concurrently run CPU-heavy code, there will
still be a need for multiprocessing.

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


Re: How to extend a tuple of tuples?

2016-09-09 Thread Rustom Mody
On Friday, September 9, 2016 at 5:58:16 PM UTC+5:30, Chris Angelico wrote:
> On Fri, Sep 9, 2016 at 10:21 PM, Frank Millman wrote:
> > I am building a series of JOINs for a SQL statement. Some of them can be
> > nested - table A is joined from table B is joined from table C. In other
> > parts of the same SQL statement, table A could be joined from table D which
> > is joined from table E.
> >
> > For each potential candidate, I need to check if I have already built the
> > JOIN. If so, just use it. If not, build it, and update a dictionary to
> > indicate that it has been built.
> >
> > The key to the dictionary is the path to the joined table, which could be
> > several levels deep. I build up a tuple to represent the path. Each table
> > needs two pieces of information to identify it, so I use a tuple for each
> > identifier.
> >
> > The value portion of the dictionary is simply the alias generated for the
> > joined table. I use the alias in the body of the SQL statement.
> 
> Sounds fair enough. A tuple is a pretty reasonable way to do this.
> 
> The other approach would be to craft the aliases directly, as strings.
> For instance, your first example could be JOIN_A_B_C, and your second
> JOIN_A_D_E. (Sort the table names alphabetically before "_".join()ing
> them if you want order to be insignificant.) 

If the requirement is to have ('A', 'B') == ('B', 'A')
the correct data structure to use is set(['A','B'])
In this case frozenset for immutability or allowed-for-dict-key requirements

[Disclaimer: Ive never used it like this so dont know rough edges; just 
talking ‘theoretically’!!]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What you can do about legalese nonsense on email

2016-09-09 Thread jmp

On 09/08/2016 10:52 PM, Ben Finney wrote:

Joaquin Alzola  writes:




That's not true; you can do more than we.


Added by the MTA of the company not by my client.


Right. So, here are things you can do (that we cannot) about this:

* Complain, with reasoned explanation, to the management responsible for
   deciding whether that nonsense continues to be added to every message.

   If they haven't heard the complaint before, they will no longer have
   that excuse. If they have heard the complaint before, yours will add
   to the weight of evidence that this is not wanted.

* Switch to a different mail service, one which does not add that
   nonsense to your email.

   Yes, this is inconvenient for you. But it's impossible for us to do on
   your behalf, so you are in a position of more power than us.

* Complain again to the management responsible for the ongoing decision
   to place nonsense on your email, that you have been forced to use a
   different mail system in order not to appear contemptuous of the
   communities in which you participate.

   If you are participating for reasons of benefit to the organisation,
   point out that their ongoing decision is making that more difficult
   for their employees.

These are all powers you have; please don't feel that you can do
nothing.



I've been there, I feel the pain of both sides.
Complaining won't do much, companies are not democracies, people are 
right because their title says so, not because they actually are.


I personally had to switch to a usenet client instead of a mail client 
(I think so). I'm using thunderbird for that purpose configured with 
news.gmane.org


The good news is that you don't need yet another fake email address.

jm

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


Where to store finalized python programs

2016-09-09 Thread ast

hi

Is there a web site to store python programs
in order to make them accessible for every boby ?

I know pypy, but I understood that it is for modules
only.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Where to store finalized python programs

2016-09-09 Thread Chris Angelico
On Fri, Sep 9, 2016 at 11:32 PM, ast  wrote:
> hi
>
> Is there a web site to store python programs
> in order to make them accessible for every boby ?
>
> I know pypy, but I understood that it is for modules
> only.

I would recommend source code hosting sites - gitlab.com, github.com,
bitbucket.org, launchpad.net, etc. Most of them have some kind of
zero-dollar plan for open source projects. Make sure you have a good
README, so people know how to use your program, and then basically all
you do is push from source control (git, Mercurial, Bazaar, etc)
straight to the remote hosting site. (You DO use source control,
right? If not, start using it *now*.)

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


Re: What you can do about legalese nonsense on email (was: How to split value where is comma ?)

2016-09-09 Thread Grant Edwards
On 2016-09-08, Random832  wrote:
> On Thu, Sep 8, 2016, at 18:13, Grant Edwards wrote:
>> After all, that boilerplate just makes the corporation look stupid and
>> incompetent.  Any email that leaves the corporate network must be
>> assumed to be visible to world+dog.  Anybody who thinks differently is
>> deluded and should not be allowed access to information that is
>> "confidential and subject to privledge".
>
> If every lawyer in the world benefits from the interpretation that this
> sort of notice is legally effective (since tomorrow it may be they who
> accidentaly send privileged information), who will argue in court that
> it's not?

Anybody who benefits from it not being effective -- like the NYT
reporter who broke a front page story based on a misdirected email
(described in the article to which you linked).

-- 
Grant Edwards   grant.b.edwardsYow! Is this sexual
  at   intercourse yet??  Is it,
  gmail.comhuh, is it??

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


Re: Where to store finalized python programs

2016-09-09 Thread Python

Le 09/09/2016 à 15:32, ast a écrit :

hi

Is there a web site to store python programs
in order to make them accessible for every boby ?

I know pypy, but I understood that it is for modules
only.


Not only, it is for programs too, for instance:

pip install weboob


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


Mysterious Logging Handlers

2016-09-09 Thread Josh English
I have a Python script that imports a utility script. Both scripts use logging, 
but the logs don't work as advertised. I'm getting logging output from the 
utility script but none from the main file. Worse, the format of the utility 
script's logs don't match anything I define.

The utility script is called xlreader.py. It has the following lines:

-- begin snippet --
import logging
XLOGGER = logging.getLogger('XLREADER')
-- end snippet --

And it calls XLOGGER.debug(), XLOGGER.error() and XLOGGER.info() but it never 
defines a handler.


The main script imports xlreader but does not reference XLOGGER. It defines its 
own logger:

-- begin snippet --
import logging
import xlreader

LOG = logging.getLogger('SHIPPING')
FORMAT = '%(asctime)-15s %(name)s %(level)-8s %(message)s'
logging.basicConfig(format=FORMAT,level=logging.DEBUG)
handler = logging.StreamHandler()
formatter = logging.Formatter(FORMAT)
handler.setFormatter(formatter)
LOG.addHandler(handler)
-- end snippet --

I added the logging.basicConfig line but it didn't have any effect. I created 
the second handler separately.

When I run the scriptI get logging information from only xlreader, not from the 
main script:

DEBUG:XLREADER:Creating Excel Reader

This format isn't defined anywhere. T

Even more mysterious, after I run the file (in an IDE so I have a REPL 
afterwards), I have:

>>> XLOGGER
>>> 

>>> XLOGGER.handlers
>>> []

>>> XLOGGER.debug('test')
>>> DEBUG:XLREADER:test

>>> LOG.handlers
>>> [, ]

>>> [h.formatter._fmt for h in LOG.handlers]
>>> ['%(asctime)-15s %(name)s %(level)-8s %(message)s',
 '%(asctime)-15s %(name)s %(level)-8s %(message)s']

How can I track where this formatting is coming from?

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


Re: ldap or active directory module

2016-09-09 Thread Shyam Parimal Katti
Sure, have you tried it and failed?

I remember using this: https://www.python-ldap.org/docs.html  year back and
was able to do many operations including lookups.

On Fri, Sep 9, 2016 at 5:41 AM, Robert Clove  wrote:

> Is it possible to find the following things using python ldap or active
> directory module
> I want to find if the particular group exist in my active directory also
> another function to find the user in a particular group
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Mysterious Logging Handlers

2016-09-09 Thread John Gordon
In <247db0ab-efe7-484b-a418-dd219f68a...@googlegroups.com> Josh English 
 writes:

> When I run the scriptI get logging information from only xlreader, not
> from the main script:

> DEBUG:XLREADER:Creating Excel Reader

> This format isn't defined anywhere.

That is the default logging format; it's used when you haven't supplied any
format of your own.  The snippet of xlreader.py does not define any format,
so it seems like that's where it's coming from.

(This seems pretty straightforward; am I missing something?)

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Mysterious Logging Handlers

2016-09-09 Thread Peter Otten
Josh English wrote:

> I have a Python script that imports a utility script. Both scripts use
> logging, but the logs don't work as advertised. I'm getting logging output
> from the utility script but none from the main file. Worse, the format of
> the utility script's logs don't match anything I define.
> 
> The utility script is called xlreader.py. It has the following lines:
> 
> -- begin snippet --
> import logging
> XLOGGER = logging.getLogger('XLREADER')
> -- end snippet --
> 
> And it calls XLOGGER.debug(), XLOGGER.error() and XLOGGER.info() but it
> never defines a handler.
> 
> 
> The main script imports xlreader but does not reference XLOGGER. It
> defines its own logger:
> 
> -- begin snippet --
> import logging
> import xlreader
> 
> LOG = logging.getLogger('SHIPPING')
> FORMAT = '%(asctime)-15s %(name)s %(level)-8s %(message)s'

That should be either levelname or levelno in the format string.

> logging.basicConfig(format=FORMAT,level=logging.DEBUG)
> handler = logging.StreamHandler()
> formatter = logging.Formatter(FORMAT)
> handler.setFormatter(formatter)
> LOG.addHandler(handler)
> -- end snippet --
> 
> I added the logging.basicConfig line but it didn't have any effect. 

That means there are already handlers configured for the root logger, for 
example because basicConfig() has been called before.

> I
> created the second handler separately.
> 
> When I run the scriptI get logging information from only xlreader, not
> from the main script:
> 
> DEBUG:XLREADER:Creating Excel Reader
> 
> This format isn't defined anywhere. T
> 
> Even more mysterious, after I run the file (in an IDE so I have a REPL
> afterwards), I have:

Don't run your code in an IDE. The interaction between your and their code 
can make debugging harder than necessary.

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


Re: ldap or active directory module

2016-09-09 Thread John Gordon
In  Robert Clove 
 writes:

> I want to find if the particular group exist in my active directory

Search on the group's DN, specifying SCOPE_BASE as the search scope.  If
you get a result, then the group exists, otherwise it doesn't.

> also another function to find the user in a particular group

Do the same search as above, returning the "member" attribute.  Get
the search result and then inspect the list of returned members.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Is it possible to process dist files before they are build via a setuptools hook?

2016-09-09 Thread Lawrence D’Oliveiro
On Friday, September 9, 2016 at 7:52:32 PM UTC+12, Mark Summerfield wrote:
> So, I need to have some hook that lets me run a python script after the build
> dir has been populated but before the distributable is made -- is this
> possible?

You can subclass distutils.command.build with your own custom version that does 
whatever additional steps you require. Here 
 is one example.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP 492: isn't the "await" redundant?

2016-09-09 Thread Lawrence D’Oliveiro
On Saturday, September 10, 2016 at 12:39:04 AM UTC+12, Chris Angelico wrote:
> In contrast, you want to use threads if you need the ability to
> quickly and easily share mutable data, or if you want all resource
> usage to be lumped together - eg if you're not really doing several
> separate jobs, but are doing one single conceptual job.

Multiple processes are usually preferable to multiple threads. The 
default-shared-nothing memory model is less bug-prone than 
default-shared-everything.

Think of every time you use “&” and “|” in a shell command line: you are 
creating multiple processes, and yet they are doing a “single conceptual job”.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP suggestion: Uniform way to indicate Python language version

2016-09-09 Thread Lawrence D’Oliveiro
On Tuesday, August 23, 2016 at 2:30:10 AM UTC+12, Random832 wrote:
> Receiving a SyntaxError or whatever other exception, which provides no
> suggestion about how to actually fix the issue (install a later version
> of python / run with "python3" instead of "python"), is a bad user
> experience.

When people say “user experience”, that immediately brings to mind the kinds of 
long-winded messages that Microsoft Windows might put out, that nobody pays 
attention to, because in trying to be “friendly” and “approachable” they become 
effectively meaningless.

At least the SyntaxError exception, with traceback, will give you some details 
about what went wrong. The “user” having the “experience” doesn’t need to 
understand the message to be able to copy and paste it into a bug report, and 
the developer(s) will then have some information to at least make a start on 
figuring out the problem.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PEP suggestion: Uniform way to indicate Python language version

2016-09-09 Thread Steve D'Aprano
On Tue, 23 Aug 2016 12:29 am, Random832 wrote:

> Receiving a SyntaxError or whatever other exception, which provides no
> suggestion about how to actually fix the issue (install a later version
> of python / run with "python3" instead of "python"), is a bad user
> experience.

Er wot?

If I run the following code in Python 3.4:

x:int = spam.method(?) - 1

how is the 3.4 interpreter supposed to know when the x:int and the (?)
syntax were introduced? I can tell you when x:int is introduced (Python
3.6) but I have no idea when (?) will be introduced, or what it will mean.


> It will continue to be a bad user experience when people are 
> using features that only work on python 5.0 and later and other people
> are trying to run their scripts under python 4.0, 

Suppose that version 4.5 introduces |: syntax and version 4.8 removes it
again because it was a terrible idea. And 4.9 introduces unless
expressions. I write this:

x = spam |: eggs unless ValueError then cheese

What syntax error should Python 4.0 give?




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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


python3 regex?

2016-09-09 Thread dkoleary
Hey;

Long term perl ahderent finally making the leap to python.  From my reading, 
python, for the most part, uses perl regex.. except, I can't seem to make it 
work...

I have a txt file from which I can grab specific titles via a perl one-liner:

$ perl -ne 'print if (m{^("?)[1-9]*\.})' tables
1. ${title1}
2. ${title2}
"3. ${title3}",,,
4. one more title
5. nuther title
6. and so on...,,
...
25. last title

I can't seem to get the same titles to appear using python:


$ python -V
Python 3.5.2
$ python
Python 3.5.2 (default, Jul  5 2016, 12:43:10) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import re
>>> with open('tables','rt') as f:
data = f.read()

printing data results in the output I would expect..

Trying to compile a regex and display the results does not show the same 
results I get from perl.  

>>> regex = r'^("?)[1-9]*\.'
>>> re.search(regex, data)
>>>

>>> p = re.compile(r'^("?)[1-9]*\.')
>>> p
re.compile('^("?)[1-9]*\\.')
>>> p.findall(data)

I've tried any number of options shown on the net all with the same result.  
Can someone point out what I'm messing up?

Thanks

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


Re: python3 regex?

2016-09-09 Thread Lawrence D’Oliveiro
On Saturday, September 10, 2016 at 3:12:17 PM UTC+12, Doug OLeary wrote:
> $ perl -ne 'print if (m{^("?)[1-9]*\.})' tables

Perl has this feature of being able to use alternate delimiter symbols for the 
pattern; Python does not.

> >>> regex = r'^("?)[1-9]*\.'

Try putting a backslash in front of the “"”:

regex = r'^(\"?)[1-9]*\.'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to extend a tuple of tuples?

2016-09-09 Thread Lawrence D’Oliveiro
On Saturday, September 10, 2016 at 12:21:48 AM UTC+12, Frank Millman wrote:
> The short answer is that I am using it as a dictionary key.

Another option is, if it takes several steps to construct the tuple, to build 
it incrementally as a list and then cast it to a tuple.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to set paramiko to use ssh version 1?

2016-09-09 Thread Lawrence D’Oliveiro
On Thursday, September 1, 2016 at 3:26:26 PM UTC+12, meInvent bbird wrote:
> how to set paramiko to use ssh version 1?

Be polite, but firm. Tell it “paramiko, this is ssh version 1, use it”. Then, 
when it responds “but SSHv1 is an obsolete stinking pile of crap that nobody in 
their right mind should be using any more”, make it quite clear: “I’m the 
human, you’re the machine, *you* are supposed to serve *me*, not point out how 
stupid I am”.

Then pull the plug. That will shut it up.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pymssql

2016-09-09 Thread Miki Tebeka
> for row in cus:
>print(row.budget_code)
> 
> 
> NameError: name 'budget_code' is not defined
You'll need to use a DictCursor to be able to access rows by name and not 
position (which IMO is the preferred way).

cus = conn.cursor(pymysql.cursors.DictCursor)
cus.execute("SELECT * FROM glbud ") 
for row in cus:
print(row['budget_code'])
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python3 regex?

2016-09-09 Thread Christian Gollwitzer

Am 10.09.16 um 05:12 schrieb dkole...@olearycomputers.com:

Hey;

Long term perl ahderent finally making the leap to python.  From my reading, 
python, for the most part, uses perl regex.. except, I can't seem to make it 
work...

I have a txt file from which I can grab specific titles via a perl one-liner:

$ perl -ne 'print if (m{^("?)[1-9]*\.})' tables
1. ${title1}
2. ${title2}
"3. ${title3}",,,
4. one more title
5. nuther title
6. and so on...,,
...
25. last title

I can't seem to get the same titles to appear using python:


$ python -V
Python 3.5.2
$ python
Python 3.5.2 (default, Jul  5 2016, 12:43:10)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

import os
import re
with open('tables','rt') as f:

data = f.read()

printing data results in the output I would expect..

Trying to compile a regex and display the results does not show the same 
results I get from perl.


regex = r'^("?)[1-9]*\.'
re.search(regex, data)




p = re.compile(r'^("?)[1-9]*\.')
p

re.compile('^("?)[1-9]*\\.')

p.findall(data)


I've tried any number of options shown on the net all with the same result.
Can someone point out what I'm messing up?


I think the difference is the anchor ^. In perl, you apply the regex to 
each line, whereas in Python you apply it to the whole file. You would 
either need to switch the re to multiline mode

https://docs.python.org/2/library/re.html#re.MULTILINE

or do it in a loop, the same way that perl does it implicitly:

for line in f:
print(re.findall(line).group(0))

(untested)

Christian

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


How do I automatically download files from a pop up dialog using selenium-python?

2016-09-09 Thread John
Please help.  Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python3 regex?

2016-09-09 Thread Jussi Piitulainen
dkole...@olearycomputers.com writes:

> Hey;
>
> Long term perl ahderent finally making the leap to python.  From my
> reading, python, for the most part, uses perl regex.. except, I can't
> seem to make it work...
>
> I have a txt file from which I can grab specific titles via a perl
> one-liner:
>
> $ perl -ne 'print if (m{^("?)[1-9]*\.})' tables
> 1. ${title1}
> 2. ${title2}
> "3. ${title3}",,,
> 4. one more title
> 5. nuther title
> 6. and so on...,,
> ...
> 25. last title
>
> I can't seem to get the same titles to appear using python:
>
>
> $ python -V
> Python 3.5.2
> $ python
> Python 3.5.2 (default, Jul  5 2016, 12:43:10) 
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
 import os
 import re
 with open('tables','rt') as f:
>   data = f.read()
>
> printing data results in the output I would expect..
>
> Trying to compile a regex and display the results does not show the
> same results I get from perl.
>
 regex = r'^("?)[1-9]*\.'
 re.search(regex, data)

>
 p = re.compile(r'^("?)[1-9]*\.')
 p
> re.compile('^("?)[1-9]*\\.')
 p.findall(data)
>
> I've tried any number of options shown on the net all with the same
> result.  Can someone point out what I'm messing up?

You need to compile (or use) your regex in multiline mode for the anchor
to match the beginnings of lines. But it's probably better to process
each line separately, as you do in Perl, so skip this point.

You have a capturing group in your regex, so findall returns what that
group matched. Typically that is an empty string (no doublequote). But
your capturing group seems unintended, so maybe skip this point.

Without that group, findall would return what the whole pattern matched,
which is still not the whole line. It's surely better to process each
line separately, as you do in Perl. So skip this point, too.

Then you don't even need the anchor. Instead, use re.match to match at
the start of the string. (The newer re.fullmatch attempts to match the
whole string.)

import re
p = re.compile('"?[1-9]*\.')
with open('tables', 'rt') as f:
for line in f:
if p.match(line):
print(line, end = '')

Note that 'rt' is the default mode, and you won't catch line 10 with
your regex.

More importantly, note that you can iterate over the lines from f
directly. There's also a method, f.readlines, to read the lines into a
list, if you need them all at once, but that's not what you do in Perl
either.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python3 regex?

2016-09-09 Thread Jussi Piitulainen
Jussi Piitulainen writes:
> dkole...@olearycomputers.com writes:

>> [- -]

> import re
> p = re.compile('"?[1-9]*\.')

That should be a raw string:

   r'"?[1-9]*\.'

Sorry about that. I wish Python would complain.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What you can do about legalese nonsense on email (was: How to split value where is comma ?)

2016-09-09 Thread Steve D'Aprano
On Fri, 9 Sep 2016 08:13 am, Grant Edwards wrote:

> After all, that boilerplate just makes the corporation look stupid and
> incompetent.  

I wish that were true.

Unfortunately, in the corporate world, it *doesn't* make them look stupid
and incompetent. It makes them look conventional, careful, diligent and
responsible, and depending on how it is worded, perhaps even a little
scary:

"We say that we care about the confidentiality of what we do. Don't
mess with us, because we have a lawyer and aren't afraid to use it!"

To a certain type of mindset, failure to include that boilerplate would look
stupid and incompetent. Even if it is a legal bluff, it may discourage some
people from misusing the email or forwarding it on, a bit like the legal
equivalent of fake security cameras that look like the real thing but don't
actually work.

And I doubt it is being driven by lawyers, who surely know how dubious this
is. Its not lawyers who insist on adding restraint of trade and non-compete
clauses that they know won't stand up in court, and I doubt it is lawyers
insisting on this boiler plate. But then lawyers will also know that
there's no (legal) harm done by including the message: within fairly broad
limits, they can *say* anything they like.

"If you are not the intended recipient, stop reading immediately and
seek medical attention. If you read this email without approval, you
will suffer a severe and irreversible brain embolism."

And besides, I wouldn't be *entirely* sure that it is nothing but a bluff,
particularly when wealthy corporations are involved. Privacy and
confidentiality are intangibles where the result can depend on all sorts of
factors, such as how deep the pockets of the plaintiff are, and whether the
government of the day wants to defend or attack freedom of speech and/or
privacy. Or even outright legal fraud, which is how we got corporations
considered to be legal persons.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

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