Re: degrees and radians.

2016-09-08 Thread Lawrence D’Oliveiro
On Tuesday, May 7, 2002 at 9:15:50 AM UTC+12, Fernando Pérez wrote:
> Plus, if you really need those conversions, it's less typing and more 
> efficient (no function call) to simply use a multiplicative constant...

This I have found to be the best idea. In Qahirah 
 I provided “deg” and “circle” constants, used 
like this:

ldo@hypatia:~> python3 -ic "import math, qahirah as qah"
>>> math.sin(45 * qah.deg)
0.7071067811865475
>>> math.atan(1) / qah.deg
45.0
>>> math.cos(qah.circle / 4)
6.123233995736766e-17

I think these provide greater flexibility than having to have explicit 
conversion functions.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: easy way to return a list of absolute file or directory path within a directory

2016-09-08 Thread iMath
On Wednesday, September 7, 2016 at 4:00:31 PM UTC+8, Steven D'Aprano wrote:
> On Wednesday 07 September 2016 17:08, iMath wrote:
> 
> > Any easier solutions on returning a list of absolute file or directory path
> > within a directory? Mine is
> > 
> > list(map(lambda entry: os.path.join(directory,entry),os.listdir(directory)))
> 
> 
> Use a list comprehension:
> 
> 
> [os.path.join(directory,entry) for entry in os.listdir(directory)]
> 
> 
> 
> -- 
> Steven
> 
> git gets easier once you get the basic idea that branches are homeomorphic 
> endofunctors mapping submanifolds of a Hilbert space.

yes, a  list comprehension does make the code more readable 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to split value where is comma ?

2016-09-08 Thread Robin Becker

On 08/09/2016 03:54, D'Arcy J.M. Cain wrote:

On Wed, 7 Sep 2016 16:04:40 +
Joaquin Alzola  wrote:

..

This email is confidential and may be subject to privilege. If you
are not the intended recipient, please do not copy or disclose its
content but contact the sender immediately upon receipt.


Do you realize how stupid it is to put this on a message sent all around
the world?



I have worked places where they put stuff like this at the bottom of emails sent 
to the person sitting next to them :)

-raising entropy-ly yrs-
Robin Becker

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


nested loops in Python

2016-09-08 Thread Igor Kozin
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
Thanks! 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: nested loops in Python

2016-09-08 Thread Chris Angelico
On Thu, Sep 8, 2016 at 8:20 PM, Igor Kozin  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
> Thanks!

Have you actually measured the loops and found them to be visibly slow?

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


Re: Does This Scare You?

2016-09-08 Thread eryk sun
On Thu, Sep 8, 2016 at 1:30 AM, Lawrence D’Oliveiro
 wrote:
> On Monday, August 22, 2016 at 4:18:39 PM UTC+12, eryk sun wrote:
>> It would help to consult a reverse-engineered implementation of
>> RtlGetFullPathName_Ustr  and RtlIsDosDeviceName_Ustr. I'll check the
>> ReactOS source code.
>
> 
> might also be useful (found from
> ).

I posted a comment there about a month and a half ago with a couple of
corrections. But at the time I wasn't concerned about the section on
legacy DOS device names. The author only tested on 8.1 and 10, so the
description of DOS device behavior is incomplete -- especially
concerning the way Windows Vista/7 handle CON, CONIN$, and CONOUT$.
For example, "CONOUT$" gets redirected to the console, but not
"C:\Temp\CONOUT$" or "\\.\CONOUT$" even though the last two path
strings start with "C" and "\", which satisfies the speed hack used by
BaseIsThisAConsoleName. The difference is that, prior to Windows 8,
RtlIsDosDeviceName_U doesn't look for "CONIN$" or "CONOUT$", yet
BaseIsThisAConsoleName relies on RtlIsDosDeviceName_U to find the
offset to the device name. Thus it can only redirect an exact match
for "CONIN$" and "CONOUT$".
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Alexander N. Moibenko
Yes, of course I did not write posixmodule.c, it is a part of the python 
2.7 distribution and I have no idea how to not use it and I believe I 
have no control over it, unless I go inside of python distribution and 
modify it. Is this what you are recommending?



On 09/07/2016 05:36 PM, Ben Finney wrote:

"Alexander N. Moibenko"  writes:


/opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the
use of `tempnam' is dangerous, better use `mkstemp'
collect2: ld returned 1 exit status

How this can be fixed?

The clearest answer is already there in the warning message. Replace
your use of ‘tempnam’ with ‘mkstemp’.

If you don't know what that means because you didn't write the code,
then this is for whoever is maintaining that code. Read it, learn what
it does, find (or write) its unit tests to make sue you don't break
anything; then, change that usage as suggested.



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


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Alexander N. Moibenko
In fact I tried issuing commands manually, but they did not give me any 
hint more than I already had.


In python 2.6 this all works with the same libc, of course (because I 
tried to compile on the same machine).


Thanks anyway.



On 09/08/2016 01:22 AM, dieter wrote:

"Alexander N. Moibenko"  writes:

when I build a binary with python 2.6 it builds without any problem.
When I build with python 2.7 the build fails after warnings like:
/opt/python/Python-2.7.12/Modules/posixmodule.o: In function
`posix_tempnam':
/opt/python/Python-2.7.12/./Modules/posixmodule.c:7578: warning: the
use of `tempnam' is dangerous, better use `mkstemp'
collect2: ld returned 1 exit status

How this can be fixed?

I doubt that the (compiler) warning is responsible for the (linker) failure.

When I am faced with problems like this (usually during extension building;
I have never encountered a problem during a Python built), I try
to find out what (OS level) commands are executed by the build machinery
and then issue them manually on the command line: the build machinery
often hides error details revealed by executing the commands
directly on the command line.


What I can imagine is that your (OS level installed) C libraries (i.e. "libc"
and friends) no longer contain a "tempnam", letting the linker fail.
Thus, maybe, the compiler still warns about "tempnam" but the linker
already considers it as an error.



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


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Chris Angelico
On Fri, Sep 9, 2016 at 12:48 AM, Alexander N. Moibenko
 wrote:
> In fact I tried issuing commands manually, but they did not give me any hint
> more than I already had.
>
> In python 2.6 this all works with the same libc, of course (because I tried
> to compile on the same machine).
>

Can you provide some more information about the machine you're trying
to compile this on?

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


Re: How to split value where is comma ?

2016-09-08 Thread John Gordon
In  Joaquin Alzola 
 writes:

> Use the split

> a.split(",")
> for x in a:
> print(x)

This won't work.  split() returns a list of split elements but the
original string remains unchanged.

You want something like this instead:

newlist = a.split(",")
for x in newlist:
print(x)

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

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


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Alexander N. Moibenko

Yes this Linux Red Hat 6.

[enstore@dmsen02 enstore-log]$ cat /etc/redhat-release
Scientific Linux Fermi release 6.5 (Ramsey)
Please note that the same set of modules buils with python 2.6.3 and 
fails with python 2.7 ( I mean any pyhon 2.7 release).



On 09/08/2016 09:51 AM, Chris Angelico wrote:

On Fri, Sep 9, 2016 at 12:48 AM, Alexander N. Moibenko
 wrote:

In fact I tried issuing commands manually, but they did not give me any hint
more than I already had.

In python 2.6 this all works with the same libc, of course (because I tried
to compile on the same machine).


Can you provide some more information about the machine you're trying
to compile this on?

ChrisA


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


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Rustom Mody
On Thursday, September 8, 2016 at 8:57:23 PM UTC+5:30, Alexander N. Moibenko 
wrote:
> Yes this Linux Red Hat 6.
> 
> [enstore@dmsen02 enstore-log]$ cat /etc/redhat-release
> Scientific Linux Fermi release 6.5 (Ramsey)
> Please note that the same set of modules buils with python 2.6.3 and 
> fails with python 2.7 ( I mean any pyhon 2.7 release).
> 
> 
> On 09/08/2016 09:51 AM, Chris Angelico wrote:
> > On Fri, Sep 9, 2016 at 12:48 AM, Alexander N. Moibenko
> > moibenko wrote:
> >> In fact I tried issuing commands manually, but they did not give me any 
> >> hint
> >> more than I already had.
> >>
> >> In python 2.6 this all works with the same libc, of course (because I tried
> >> to compile on the same machine).
> >>
> > Can you provide some more information about the machine you're trying
> > to compile this on?
> >
> > ChrisA

Cant make out much
I suspect gcc gets inconsistent (with itself) across widely disparate versions
When I give [ubuntu 16.4]
$ gcc -v
I get
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2) 
(along with a lot of other stuff!)

What does your gcc say?
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-09-08 Thread Chi Hsuan Yen
Hi Python enthusiasts,

I'm working on youtube-dl, a handy tool for downloading videos from various
websites. There are occasional bug reports with SSL error
CERTIFICATE_VERIFY_FAILED when people are trying to download videos from
youtube.com [1] or dailymotion.com [2]. The issue about youtube.com turned
out to be expired intermediate CA certificates. Some users report that
there's one or more expired "Google Internet Authority G2" certificate on
their machines. Apparently OpenSSL verifies the whole certificate chain and
report an error as soon as it finds an invalid certificate in the chain. My
questions is: how to tell from several possible causes to
CERTIFICATE_VERIFY_FAILED? Currently both expired self signed certificate
leads to CERTIFICATE_VERIFY_FAILED. Thanks for any help or advice.

Best,

Yen Chi Hsuan

[1] https://github.com/rg3/youtube-dl/issues/7309
[2] https://github.com/rg3/youtube-dl/issues/10574
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Alexander N. Moibenko



On 09/08/2016 11:06 AM, Rustom Mody wrote:

On Thursday, September 8, 2016 at 8:57:23 PM UTC+5:30, Alexander N. Moibenko 
wrote:

Yes this Linux Red Hat 6.

[enstore@dmsen02 enstore-log]$ cat /etc/redhat-release
Scientific Linux Fermi release 6.5 (Ramsey)
Please note that the same set of modules buils with python 2.6.3 and
fails with python 2.7 ( I mean any pyhon 2.7 release).


On 09/08/2016 09:51 AM, Chris Angelico wrote:

On Fri, Sep 9, 2016 at 12:48 AM, Alexander N. Moibenko
moibenko wrote:

In fact I tried issuing commands manually, but they did not give me any hint
more than I already had.

In python 2.6 this all works with the same libc, of course (because I tried
to compile on the same machine).


Can you provide some more information about the machine you're trying
to compile this on?

ChrisA

Cant make out much
I suspect gcc gets inconsistent (with itself) across widely disparate versions
When I give [ubuntu 16.4]
$ gcc -v
I get
gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.2)
(along with a lot of other stuff!)

What does your gcc say?

gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
--
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Chris Angelico
On Fri, Sep 9, 2016 at 1:12 AM, Alexander N. Moibenko  wrote:
> Yes this Linux Red Hat 6.
>
> [enstore@dmsen02 enstore-log]$ cat /etc/redhat-release
> Scientific Linux Fermi release 6.5 (Ramsey)
> Please note that the same set of modules buils with python 2.6.3 and fails
> with python 2.7 ( I mean any pyhon 2.7 release).

I still don't think the compiler warnings have anything to do with
this. After you run 'make' and it fails at the ld step, can you rerun
make and post the output, please? It should skip all the compilation
and go straight to the link stage, so (a) it should be a manageable
amount of text, and (b) it most likely won't say anything about
tempnam.

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


Re: nested loops in Python

2016-09-08 Thread Christian Gollwitzer

Am 08.09.16 um 12:20 schrieb Igor Kozin:

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: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Chris Angelico
On Fri, Sep 9, 2016 at 2:50 AM, Alexander N. Moibenko  wrote:
> The output is long so, I am replying to you only:

Not too long, fortunately. Replying back to the list with a trimmed version.

> make[1]: Entering directory `/opt/enstore/src/ENCPBIN_TEMP'

(Curious path name.)

> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function
> `_PyTime_DoubleToTimet':
> /opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:108:
> multiple definition of `_PyTime_DoubleToTimet'
> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:108:
> first defined here
> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function
> `inittime':
> /opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:851:
> multiple definition of `inittime'
> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:851:
> first defined here
> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function
> `_PyTime_FloatTime':
> /opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:1062:
> multiple definition of `_PyTime_FloatTime'
> /opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:1062:
> first defined here

This is interesting. Very interesting. Firstly, I thought you were
trying to compile 2.7.12. Do you possibly have multiple versions of
the source, and they're treading on each other's toes?

Do you still get these errors if you create a brand new empty
directory, extract the 2.7.12 sources to it, and run a clean build?
Particularly notable if you get 2.7.9 paths when you try to build
2.7.12, but still of interest if you're getting these
multiple-definition errors on a clean build.

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


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread Alexander N. Moibenko



On 09/08/2016 12:19 PM, Chris Angelico wrote:

On Fri, Sep 9, 2016 at 2:50 AM, Alexander N. Moibenko  wrote:

The output is long so, I am replying to you only:

Not too long, fortunately. Replying back to the list with a trimmed version.


make[1]: Entering directory `/opt/enstore/src/ENCPBIN_TEMP'

(Curious path name.)


/opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function
`_PyTime_DoubleToTimet':
/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:108:
multiple definition of `_PyTime_DoubleToTimet'
/opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:108:
first defined here
/opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function
`inittime':
/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:851:
multiple definition of `inittime'
/opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:851:
first defined here
/opt/enstore/Python/Python-2.7.9/Modules/timemodule.o: In function
`_PyTime_FloatTime':
/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:1062:
multiple definition of `_PyTime_FloatTime'
/opt/enstore/Python/Python-2.7.9/Modules/timemodule.o:/opt/python/python-enstore-2.7.9/Python-2.7.9/./Modules/timemodule.c:1062:
first defined here

This is interesting. Very interesting. Firstly, I thought you were
trying to compile 2.7.12. Do you possibly have multiple versions of
the source, and they're treading on each other's toes?
I tried 2.7.9 and 2.7.12. I do have multiple versions, but they do not 
mix up because I set environment appropriately.

On this particular machine I have only my own 2.7.9


Do you still get these errors if you create a brand new empty
directory, extract the 2.7.12 sources to it, and run a clean build?

This is what I usually do, in this case too.

Particularly notable if you get 2.7.9 paths when you try to build
2.7.12, but still of interest if you're getting these
multiple-definition errors on a clean build.

This is not the case.


ChrisA


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


Re: How to split value where is comma ?

2016-09-08 Thread Larry Hudson via Python-list

On 09/08/2016 07:57 AM, John Gordon wrote:

In  Joaquin Alzola 
 writes:


Use the split



a.split(",")
for x in a:
print(x)


This won't work.  split() returns a list of split elements but the
original string remains unchanged.

You want something like this instead:

newlist = a.split(",")
for x in newlist:
print(x)



Even easier...

for x in a.split(','):
print(x)

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


RE: How to split value where is comma ?

2016-09-08 Thread Joaquin Alzola


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


Need some suggestions in grouping of items

2016-09-08 Thread GP

I have a list of items:
ShelvesToPack = [{'ShelfLength': 2278.0, 'ShelfWidth': 356.0, 'ShelfArea': 
759152.0, 'ItemNames': 1},
{'ShelfLength': 1220.0, 'ShelfWidth': 610.0, 'ShelfArea':   372100.0, 
'ItemNames': 2},
{'ShelfLength': 2310.0, 'ShelfWidth': 762.0, 'ShelfArea': 1760220.0, 
'ItemNames': 3},
{'ShelfLength': 610.0, 'ShelfWidth': 610.0,   'ShelfArea': 1450435.0, 
'ItemNames': 4}]

I have a certain criteria and I  want to group the items based on those.
I need the program that tells how many minimum number of groups one can have 
and how the items are grouped. I would like to form groups of these items such 
that (sum of shelflength (of itmes) <= max length or sum of  shelfwidth (of 
items) <= max width) and sum of ShelfArea (of items) <= Max Area. In this case, 
if we look at the logic we can have all the items packed in minimum 2 groups - 
item 1 and 3 will form one group and item 2 & 4 will form other group. I would 
like to have the answer in the format:
[[{'ShelfLength': 2278.0, 'ShelfWidth': 356.0, 'ShelfArea':759152.0, 
'ItemNames': 1} ,
 {'ShelfLength': 2310.0, 'ShelfWidth':762.0, 'ShelfArea': 1760220.0, 
'ItemNames': 3}],
[{'ShelfLength': 1220.0, 'ShelfWidth': 610.0, 'ShelfArea':   372100.0, 
'ItemNames': 2},
 , {'ShelfLength': 610.0, 'ShelfWidth': 610.0,   'ShelfArea':   1450435.0, 
'ItemNames': 4}]]

I have written a code but it does only one grouping ( need some help why it 
doesnot for the remaining items and what corrections need to be done) . 

ShelvesToPack_sorted=sorted(ShelvesToPack, key = itemgetter('ShelfWidth'), 
reverse = True)
AreaOfObject= 2972897.28
current_width = 0
current_length = 0
current_area =0
shelf =[]
shelves=[]
if len(ShelvesToPack_sorted) > 0: 
   for item in ShelvesToPack_sorted:
if (current_width + item['ShelfWidth'] <= 1219.2  or  
current_length + item['ShelfLength']  <= 2438.5) and  current_area + 
item['ShelfArea'] <= AreaOfObject:
shelf.append(item)
current_width += item['ShelfWidth']
current_length +=  item['ShelfLength']
current_area += item['ShelfArea']
del item

if shelf: 
shelves.append(shelf)

print(shelves)

This produces only one grouping and does not group the remaining items. 
[[{'ShelfLength': 2310.0, 'ItemNames': 3, 'ShelfArea': 1760220.0, 'ShelfWidth': 
762.0}, {'ShelfLength': 2278.0, 'ItemNames': 1, 'ShelfArea': 759152.0, 
'ShelfWidth': 356.0}]]

Can anyone please suggest?
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2016-09-08 Thread Ben Finney
Joaquin Alzola  writes:

>  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:

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

-- 
 \  “Isn't it enough to see that a garden is beautiful without |
  `\  having to believe that there are fairies at the bottom of it |
_o__) too?” —Douglas Adams |
Ben Finney

-- 
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-08 Thread Joaquin Alzola
Hi Ben

Thanks for the advice.

> * Complain

Basically what all comes down is to complain. I wonder if in a company of 
80,000 people I will manage to change that behaviour.
This email is confidential and may be subject to privilege. If you are not the 
intended recipient, please do not copy or disclose its content but contact the 
sender immediately upon receipt.
-- 
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-08 Thread Chris Angelico
On Fri, Sep 9, 2016 at 7:17 AM, Joaquin Alzola
 wrote:
> Hi Ben
>
> Thanks for the advice.
>
>> * Complain
>
> Basically what all comes down is to complain. I wonder if in a company of 
> 80,000 people I will manage to change that behaviour.
> This email is confidential and may be subject to privilege. If you are not 
> the intended recipient, please do not copy or disclose its content but 
> contact the sender immediately upon receipt.
>

You are one out of eighty thousand. I am zero out of eighty thousand.
Short of suing the company or something of that nature, I have no
chance of affecting it. You _do_ have a chance, exactly as per Ben's
advice.

There is one option among Ben's suggestions that doesn't amount to "complain":

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

This amounts to "subvert". Now, if it's dead simple for you to remove
the disclaimer, the ball lands in the court of those wanting it on all
outgoing emails: they can either complain at you for omitting it, or
decide that it's not worth it. Again, this is a marked improvement;
and if you're bothered by the difficulty of changing a large and
bureaucratic organization, it's probably the easiest solution.

ChrisA

This email is overconfident and may be subject to grammar. If you are
not the intended sender, please do not confuse yourself for me but
contact the recipient immediately to report that you have lost your
marbles.
-- 
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-08 Thread Lew Pitcher
On Thursday September 8 2016 17:17, in comp.lang.python, "Joaquin Alzola"
 wrote:

> Hi Ben
> 
> Thanks for the advice.
> 
>> * Complain
> 
> Basically what all comes down is to complain. I wonder if in a company of
> 80,000 people I will manage to change that behaviour.

Why don't you, at least, include a "signature" line at the end of /your/ text.
That way, the automatically-added "confidentiality clause" will end up
appended to the signature. Since many news readers discard or suppress
display of the signature, the "confidentiality clause" won't be as much of an
issue.

> This email is 
> confidential and may be subject to privilege. If you are not the intended
> recipient, please do not copy or disclose its content but contact the sender
> immediately upon receipt.

A signature begins with a line consisting only of two hyphens followed by a
space. Any lines that follow that line are considered to be part of the
signature.

-- 
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request

-- 
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-08 Thread Grant Edwards
On 2016-09-08, Joaquin Alzola  wrote:

> Basically what all comes down is to complain. I wonder if in a
> company of 80,000 people I will manage to change that behaviour.

Perhaps others have complained. If enough people complain, maybe
they'll do something.

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

But, I'm sure there's a lawyer somewhere who's trying to cover his
ass regardless of how foolish it looks...

> This email is confidential and may be subject to privilege. If you
> are not the intended recipient, please do not copy or disclose its
> content but contact the sender immediately upon receipt.

-- 
Grant Edwards   grant.b.edwardsYow! I'm pretending that
  at   we're all watching PHIL
  gmail.comSILVERS instead of RICARDO
   MONTALBAN!

-- 
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-08 Thread Random832
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? The reality is more complex, and it appears that it may only
apply if the accidental recipient is a lawyer. I really can't say for
sure, since _I'm_ not a lawyer, but posted without further comment:

http://apps.americanbar.org/litigation/committees/technology/articles/winter2013-0213-do-email-disclaimers-really-work.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What you can do about legalese nonsense on email

2016-09-08 Thread Ben Finney
Chris Angelico  writes:

> On Fri, Sep 9, 2016 at 7:17 AM, Joaquin Alzola
>  wrote:
> > Hi Ben
> >
> > Thanks for the advice.

You're welcome, I hope it leads to positive change.

> > Basically what all comes down is to complain. I wonder if in a
> > company of 80,000 people I will manage to change that behaviour.

That's a good thing to wonder! But wondering will never get the answer
to this one: you'll have to *do* it, in a way that allows that change to
occur.

It is far more certain that if you don't use that power, you will not
effect positive change.

> You are one out of eighty thousand. I am zero out of eighty thousand.
> Short of suing the company or something of that nature, I have no
> chance of affecting it. You _do_ have a chance, exactly as per Ben's
> advice.

With tens of thousands of people all subject to the same stupid rule,
you have even more of a change: You have many more opportunities to find
people who can also complain about the same thing in the same forum.

Surely you are far from alone in realising how this exhibits arrant
incompetence on the internet, and that your employer would do well to
drop this mindless policy.

So if you know you have many people in the same situation, join forces
with them. That is another thing that we cannot do, and you can.

You have far more power in this than you may feel; and realising that
you *can* act is an imortant step to getting the positive change
effected.

-- 
 \ “You don't need a book of any description to help you have some |
  `\kind of moral awareness.” —Dr. Francesca Stavrakoloulou, bible |
_o__)  scholar, 2011-05-08 |
Ben Finney

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


Re: Need some suggestions in grouping of items

2016-09-08 Thread MRAB

On 2016-09-08 21:50, GP wrote:


I have a list of items:
ShelvesToPack = [{'ShelfLength': 2278.0, 'ShelfWidth': 356.0, 'ShelfArea': 
759152.0, 'ItemNames': 1},
{'ShelfLength': 1220.0, 'ShelfWidth': 610.0, 'ShelfArea':   372100.0, 
'ItemNames': 2},
{'ShelfLength': 2310.0, 'ShelfWidth': 762.0, 'ShelfArea': 1760220.0, 
'ItemNames': 3},
{'ShelfLength': 610.0, 'ShelfWidth': 610.0,   'ShelfArea': 1450435.0, 
'ItemNames': 4}]

I have a certain criteria and I  want to group the items based on those.
I need the program that tells how many minimum number of groups one can have and how the 
items are grouped. I would like to form groups of these items such that (sum of shelflength 
(of itmes) <= max length or sum of  shelfwidth (of items) <= max width) and sum of 
ShelfArea (of items) <= Max Area. In this case, if we look at the logic we can have all 
the items packed in minimum 2 groups - item 1 and 3 will form one group and item 2 & 4 
will form other group. I would like to have the answer in the format:
[[{'ShelfLength': 2278.0, 'ShelfWidth': 356.0, 'ShelfArea':759152.0, 
'ItemNames': 1} ,
 {'ShelfLength': 2310.0, 'ShelfWidth':762.0, 'ShelfArea': 1760220.0, 
'ItemNames': 3}],
[{'ShelfLength': 1220.0, 'ShelfWidth': 610.0, 'ShelfArea':   372100.0, 
'ItemNames': 2},
 , {'ShelfLength': 610.0, 'ShelfWidth': 610.0,   'ShelfArea':   1450435.0, 
'ItemNames': 4}]]

I have written a code but it does only one grouping ( need some help why it 
doesnot for the remaining items and what corrections need to be done) .

ShelvesToPack_sorted=sorted(ShelvesToPack, key = itemgetter('ShelfWidth'), 
reverse = True)
AreaOfObject= 2972897.28
current_width = 0
current_length = 0
current_area =0
shelf =[]
shelves=[]
if len(ShelvesToPack_sorted) > 0:
   for item in ShelvesToPack_sorted:
if (current_width + item['ShelfWidth'] <= 1219.2  or  current_length + 
item['ShelfLength']  <= 2438.5) and  current_area + item['ShelfArea'] <= 
AreaOfObject:
shelf.append(item)
current_width += item['ShelfWidth']
current_length +=  item['ShelfLength']
current_area += item['ShelfArea']
del item

if shelf:
shelves.append(shelf)

print(shelves)

This produces only one grouping and does not group the remaining items.
[[{'ShelfLength': 2310.0, 'ItemNames': 3, 'ShelfArea': 1760220.0, 'ShelfWidth': 
762.0}, {'ShelfLength': 2278.0, 'ItemNames': 1, 'ShelfArea': 759152.0, 
'ShelfWidth': 356.0}]]

Can anyone please suggest?


The easy way to do it is, in pseudocode:

shelves = []

while list_of_items:
shelf = []
# Also initialise width, length and area.
doesnt_fit = []

for item in list_of_items:
if item fits:
shelf.append(item)
# Also adjust width, length and area.
else:
doesnt_fit.append(item)

shelves.append(shelf)
list_of_items = doesnt_fit

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


pymssql

2016-09-08 Thread sum abiut
Hi,
i have used pymssql to connet to windows database but i want to be able
iterate and  only print out some specific fields.

here is what i did

conn=pymssql.connect(server,username,password,database)
cus=conn.cursor()
cus.execute("SELECT * FROM glbud ")

for row in cus:
   print(row)
this works perfect, but when i try to iterate through and only print out
specific fields i got the error NameError: name 'budget_code' is not defined


for row in cus:
   print(row.budget_code)


NameError: name 'budget_code' is not defined

the column name is budget_code, in mssql server 2008


any idea what i am doing wrong? please advise
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What you can do about legalese nonsense on email

2016-09-08 Thread Terry Reedy

On 9/8/2016 4: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:


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

--
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-08 Thread Chris Angelico
On Fri, Sep 9, 2016 at 11:05 AM, Dennis Lee Bieber
 wrote:
> I suspect, like the last two companies I've worked for -- corporate IT
> policy is to block any access to non-corporate email systems. (Heck, my
> current company is so paranoid that it adds "EXT:" to the subject of
> incoming emails that did not originate from another employee!
>
> I haven't checked to see if GMAIL on a Samsung tablet can get through
> if using the corporate "guest" WiFi system. Pretty sure if I tether to my
> Blackberry phone it would work.

The most common way to access Gmail is HTTP, so it would be difficult
to mess with the emails as they go through. (You could block it, I
guess, but it'd have to be some sort of IP address blacklist - you
can't just say "no access to port 25 or 110".) And yes, if you tether
to your phone, you should get past the problems. That might be a
_little_ inconvenient though.

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


Re: C Python extension to export an Function

2016-09-08 Thread Lawrence D’Oliveiro
On Friday, September 2, 2016 at 3:59:21 AM UTC+12, Stefan Behnel wrote:
> Manually written C-API code is simply too difficult to maintain, and also
> too difficult to get right in the first place. There are just too many ways
> to introduce reference leaks, crashes and long standing unnoticed bugs
> (believe me, I know what I'm talking about).

There are ways to keep that manageable, using structured-programming techniques.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pymssql

2016-09-08 Thread Lawrence D’Oliveiro
On Friday, September 9, 2016 at 12:48:50 PM UTC+12, sum abiut wrote:
> cus.execute("SELECT * FROM glbud ")

Never use “select *”, except for testing.

> for row in cus:
>print(row)
> this works perfect, but when i try to iterate through and only print out
> specific fields i got the error NameError: name 'budget_code' is not defined

Possibly because you are getting back a tuple? Are you expecting some other 
object type?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What you can do about legalese nonsense on email

2016-09-08 Thread Ben Finney
Terry Reedy  writes:

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

No, that would be mangling messages in transit, to reverse someone
else's mangling of messages in transit.

That kind of arms race is foolish to enter in the first place. I would
not agree to that policy.

-- 
 \ “I went to a fancy French restaurant called ‘Déjà Vu’. The head |
  `\  waiter said, ‘Don't I know you?’” —Steven Wright |
_o__)  |
Ben Finney

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


Re: pymssql

2016-09-08 Thread sum abiut
ok did some changes:

conn=pymssql.connect(server,username,password,database)
 cus=conn.cursor(
cus.execute("SELECT budget_code,budget_description,rate_type FROM glbud")
for row in cus:
print(row)


the above code display the selected column


but when i iterate and try to print the fields, its not displaying anything
and its not giving any error.

conn=pymssql.connect(server,username,password,database)
 cus=conn.cursor(
cus.execute("SELECT budget_code,budget_description,rate_type FROM glbud")
for row in cus:
print(row.budget_code,row.budget_description,row.rate_type)


the above code it doesn't print out anything and it doesn't give me any
error.

any assistance will be very much appreciated.




On Fri, Sep 9, 2016 at 1:38 PM, Lawrence D’Oliveiro 
wrote:

> On Friday, September 9, 2016 at 12:48:50 PM UTC+12, sum abiut wrote:
> > cus.execute("SELECT * FROM glbud ")
>
> Never use “select *”, except for testing.
>
> > for row in cus:
> >print(row)
> > this works perfect, but when i try to iterate through and only print out
> > specific fields i got the error NameError: name 'budget_code' is not
> defined
>
> Possibly because you are getting back a tuple? Are you expecting some
> other object type?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
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-08 Thread Jussi Piitulainen
Grant Edwards writes:

> On 2016-09-08, Joaquin Alzola  wrote:
>
>> Basically what all comes down is to complain. I wonder if in a
>> company of 80,000 people I will manage to change that behaviour.
>
> Perhaps others have complained. If enough people complain, maybe
> they'll do something.
>
> 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".

I read Lebara's "Vision" and "Mission" and I remember that whenever
Lebara says anything, they end it with that rude disclaimer. I don't
want to get in touch with Lebara. That's how stupid it is.

> But, I'm sure there's a lawyer somewhere who's trying to cover his
> ass regardless of how foolish it looks...

As if Lebara's real mission is to cover their lawyers' asses.

>> This email is confidential and may be subject to privilege. If you
>> are not the intended recipient, please do not copy or disclose its
>> content but contact the sender immediately upon receipt.

Spammers should use a disclaimer like that. Then people would not dare
to delete the spam without first confirming to the spammer that they
read their spam. Or not.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fwd: Fwd: Python freeze fails with warning: the use of `tempnam' is dangerous, better use `mkstemp'

2016-09-08 Thread dieter
"Alexander N. Moibenko"  writes:
> In fact I tried issuing commands manually, but they did not give me
> any hint more than I already had.

When I remember right, then "gcc" has an option to show details
about the calling of the phase commands ("gcc" is a coordinating
programm delegating the real work to subcommands ("cpp", "cc1", "ld", ...)).


Key to your problem seems to understand why "ld/collect2" fails.
Usually, you should get a clear error message corresponding to this
failure (e.g. "symbol  undefined"). Getting only
"collect2 exited with error code 1" is unusual.

I would approach the problem by isolating the "collect2/ld" command
and then try hard to determine what the command is doing and why it
fails (e.g. by "strace"ing it).


"collect2" is usually used for "C++" programs (collecting code
for the initialization of static C++ objects). Maybe, the difference
between Python 2.7 and earlier Python versions is that it includes C++
parts - and maybe, "collect2" has some (still not understood) problems
in your environment.

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


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

2016-09-08 Thread dieter
Chi Hsuan Yen  writes:
> ...
> Apparently OpenSSL verifies the whole certificate chain and
> report an error as soon as it finds an invalid certificate in the chain.

As it must, if you require verification.

When I remember right, you can disable the verification altogether
(though you should not for security reasons).

> My
> questions is: how to tell from several possible causes to
> CERTIFICATE_VERIFY_FAILED? Currently both expired self signed certificate
> leads to CERTIFICATE_VERIFY_FAILED. Thanks for any help or advice.

I would try to find (or write) a utility that follows the certificate
chain and provides details information about its state.

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


Re: How to split value where is comma ?

2016-09-08 Thread Rustom Mody
On Friday, September 9, 2016 at 1:36:24 AM UTC+5:30, Larry Hudson wrote:
> On 09/08/2016 07:57 AM, John Gordon wrote:
> > In  Joaquin Alzola writes:
> >
> >> Use the split
> >
> >> a.split(",")
> >> for x in a:
> >> print(x)
> >
> > This won't work.  split() returns a list of split elements but the
> > original string remains unchanged.
> >
> > You want something like this instead:
> >
> > newlist = a.split(",")
> > for x in newlist:
> > print(x)
> >
> 
> Even easier...
> 
> for x in a.split(','):
>  print(x)

In all probability, what is required is just: a.split(','); no for, no print

And unfortunately none of the answers (that I see) describe the spectrum of
what one may really want
 a.split(',')
 set(a.split(','))

Less likely (in this case) but important for a learner to be aware of:
 Counter(a.split(',')

And if the original 'a' looked something like
>>> a="p:1,q:2,r:42"

then you probably want something like:

>>> {k:v for item in a.split(',') for k,v in [item.split(':')]}
{'q': '2', 'p': '1', 'r': '42'}
>>>
In all cases the print is irrelevant and unnecessary

And if we insist on interpreting the OP request for replacing comma by newline
(almost always a misconceived request), one can do:


>>> a="p,q,r"
>>> str(a.replace(',','\n'))
'p\nq\nr'

Sure one can go one step further and do:
>>> print str(a.replace(',','\n'))
p
q
r

But this is almost always not what the requester wants (even if he thinks it is)

[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]

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


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

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

> Chi Hsuan Yen  writes:
> > ...
> > Apparently OpenSSL verifies the whole certificate chain and
> > report an error as soon as it finds an invalid certificate in the chain.
>
> As it must, if you require verification.
>
> When I remember right, you can disable the verification altogether
> (though you should not for security reasons).
>
>
Yeah we have a CLI option for that, and fortunately (or unfortunately?) it
works fine.

> My
> > questions is: how to tell from several possible causes to
> > CERTIFICATE_VERIFY_FAILED? Currently both expired self signed certificate
> > leads to CERTIFICATE_VERIFY_FAILED. Thanks for any help or advice.
>
> I would try to find (or write) a utility that follows the certificate
> chain and provides details information about its state.
>
>
Thanks a lot! I just lost my direction when trying to understand how
certificate verification works in Python.


> --
> 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-08 Thread Rustom Mody
On Friday, September 9, 2016 at 11:51:25 AM UTC+5:30, Rustom Mody wrote:
> And if the original 'a' looked something like
> >>> a="p:1,q:2,r:42"
> 
> then you probably want something like:
> 
> >>> {k:v for item in a.split(',') for k,v in [item.split(':')]}
> {'q': '2', 'p': '1', 'r': '42'}
> >>>

Well if the a did look like
>>> a="a:1,b:2,c:42"

what we would need is likely to be
>>> {k:int(v) for item in a.split(',') for k,v in [item.split(':')]}
{'a': 1, 'c': 42, 'b': 2}

Likely, but not necessary -- eg we would not want leading zeroes in a 
phone number to disappear
-- 
https://mail.python.org/mailman/listinfo/python-list


How to extend a tuple of tuples?

2016-09-08 Thread Frank Millman

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)

I have discovered that there is something new in python 3.5 that does work -

a = (*a, (5, 6))

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

But how would you have done it before? I know you can convert the outer 
tuple to a list, add the new tuple, and convert it back again. Is that the 
only solution?


BTW, I do know that tuples are immutable, and that all of the above 
operations create a new tuple.


Frank Millman


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


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

2016-09-08 Thread dieter
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.

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