Re: Problem : Generator

2019-02-16 Thread Prahallad Achar
Woww.. This solves the problem..
Thank you very much

On Sat, 16 Feb 2019, 12:54 Avi Gross  Just want to point out you can make any function into a generator by having
> a yield statement like this:
>
> >>> def previous(listing):
> while listing: yield listing.pop()
>
>
> >>> for num in previous([1,2,3,4]): print(num)
>
> 4
> 3
> 2
> 1
>
> The above is an EXAMPLE, not a particularly great way to do this. The point
> is if you have an iterable you want to do reversed, you could do it without
> an explicit reversal. Variations on the above that do not alter the list
> would be to use an index based on the length of the list and count backward
> as you return what is at that index.
>
> -Original Message-
> From: Python-list  On
> Behalf Of dieter
> Sent: Saturday, February 16, 2019 1:47 AM
> To: python-list@python.org
> Subject: Re: Problem : Generator
>
> Prahallad Achar  writes:
>
> > I get list object instead gen  obj
>
> If you have a list "l" and want a generator, you can use
>( x for x in l)
> or simpler "iter(l)" - which gives you an interator over "l".
>
> An "iterator" is slightly more general than a generator (every generator is
> also an iterator).
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem : Generator

2019-02-16 Thread Prahallad Achar
Yupee.. Thanks for the knowledge sharing.

Regards
Prahallad

On Sat, 16 Feb 2019, 12:18 dieter  Prahallad Achar  writes:
>
> > I get list object instead gen  obj
>
> If you have a list "l" and want a generator, you can use
>( x for x in l)
> or simpler "iter(l)" - which gives you an interator over "l".
>
> An "iterator" is slightly more general than a generator
> (every generator is also an iterator).
>
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: more pythonic way

2019-02-16 Thread Barry



On 11 Feb 2019, at 20:00, Felix Lazaro Carbonell  wrote:

>> The most pythonic way is to do this:
>> 
>> def find_monthly_expenses(month=datetime.date.today().month,
> year=datetime.date.today().year):
>>...

This has subtle bugs. 
The default is calculated at import time and not at function call time.
Also the defaults for month and year are not calculated at the same moment in 
time.

Import at 23:59:59.99 on 31 december 2018 and you might get
month as 12 and year as 2019.

Run this example to see the problem:

import datetime
import time

def test_defaults(prefix, now=datetime.datetime.now()):
print( prefix, now )

test_defaults('one')
time.sleep( 1 )
test_defaults('two')
time.sleep( 1 )
test_defaults('three', datetime.datetime.now())

Which outputs:

one 2019-02-16 08:30:54.819466
two 2019-02-16 08:30:54.819466
three 2019-02-16 08:30:56.821453

Notice that the time for 'one' and 'two' is the same.
Only the overridden default chanse.

Barry

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


Re: more pythonic way

2019-02-16 Thread Grant Edwards
On 2019-02-16, Barry  wrote:
> On 11 Feb 2019, at 20:00, Felix Lazaro Carbonell  wrote:
>
>>> The most pythonic way is to do this:
>>> 
>>> def find_monthly_expenses(month=datetime.date.today().month,
>> year=datetime.date.today().year):
>>>...
>
> This has subtle bugs. 
> The default is calculated at import time and not at function call time.

Indeed.  That was the entire point of that posting: it was an example
of a not-uncommon misunderstanding about when intializer values are
determined.  Unfortunately the subsequent remark about initializers
not working that way has been lost in the shuffle.

> Also the defaults for month and year are not calculated at the same
> moment in time.

Yep.  The race condition between the evaluation of the two initializer
expressions is a bit more subtle than the fact that the evaluations
only happen once at compile time.

-- 
Grant


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


Why this curl command works in shell but NOT when I do subprocess.getoutput(["curl", .....]) ??

2019-02-16 Thread Christian Seberino
Why this curl command works in shell but NOT when I use subprocess as in 
below?.


UL_URL = "https://auphonic.com/api/simple/productions.json";

ul_output = subprocess.getoutput(["curl",
  "-X",
  "POST",
  UL_URL,
  "-u",
  "seberino:XXX",
  "-F",
  "input_file=@" + sys.argv[1],
  "-F",
  "denoise=true",
  "-F",
  "action=start"])

There is some difference in how shell versus Python process the info.

Thanks,

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


Re: Why this curl command works in shell but NOT when I do subprocess.getoutput(["curl", .....]) ??

2019-02-16 Thread Christian Seberino
Nevermind...appears to get arguments like this you need to use subprocess.run 
rather than subprocess.getoutput (with capture_output = True).

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


[RELEASE] Python 2.7.16 release candidate 1

2019-02-16 Thread Benjamin Peterson
I'm pleased to announce the immediate availability of Python 2.7.16 release 
candidate 1. This is a prerelease for yet another bug fix release in the Python 
2.7.x series. It includes over 100 fixes over Python 2.7.15. See the changelog 
at


https://raw.githubusercontent.com/python/cpython/baacaac06f93dd624c9d7b3bac0e13fbe34f2d8c/Misc/NEWS.d/2.7.16rc1.rst

for full details.

Downloads are at:

https://www.python.org/downloads/release/python-2716rc1/

Please test your software against the new release and report any issues to

https://bugs.python.org/

If all goes according to plan, Python 2.7.16 final will be released on March 2.

All the best,
Benjamin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [RELEASE] Python 2.7.16 release candidate 1

2019-02-16 Thread Shakti Kumar
On Sun, 17 Feb 2019 at 6:44 AM Benjamin Peterson 
wrote:

> I'm pleased to announce the immediate availability of Python 2.7.16
> release candidate 1. This is a prerelease for yet another bug fix release
> in the Python 2.7.x series. It includes over 100 fixes over Python 2.7.15.
> See the changelog at


> https://raw.githubusercontent.com/python/cpython/baacaac06f93dd624c9d7b3bac0e13fbe34f2d8c/Misc/NEWS.d/2.7.16rc1.rst

(Clipped for brevity)

>
> 
> If all goes according to plan, Python 2.7.16 final will be released on
> March 2.


> Just a small doubt (out of curiosity), python 2.7 is nearing end of
support right?
-- 
Sent from Shakti’s iPhone
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [RELEASE] Python 2.7.16 release candidate 1

2019-02-16 Thread MRAB

On 2019-02-17 02:23, Shakti Kumar wrote:

On Sun, 17 Feb 2019 at 6:44 AM Benjamin Peterson 
wrote:


I'm pleased to announce the immediate availability of Python 2.7.16
release candidate 1. This is a prerelease for yet another bug fix release
in the Python 2.7.x series. It includes over 100 fixes over Python 2.7.15.
See the changelog at




https://raw.githubusercontent.com/python/cpython/baacaac06f93dd624c9d7b3bac0e13fbe34f2d8c/Misc/NEWS.d/2.7.16rc1.rst


(Clipped for brevity)




If all goes according to plan, Python 2.7.16 final will be released on
March 2.




Just a small doubt (out of curiosity), python 2.7 is nearing end of

support right?

Support by the Python Software Foundation for Python 2.7 will end on 1 
January 2020.

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


flask problem

2019-02-16 Thread jaybraun2 . 0
I have used flask before with no problem.  Now I am getting very mysterious 
results, which I have reduced to a very small test case.

Here is a flask server, in Python 3, which waits for a message on port 8002 
(the port is open):


from flask import Flask, Response
import json
app = Flask(__name__)
@app.route('/jay', methods=['PUT'])
def analyze():
print("hello")
resp = Response(json.dumps({'status':'Good'}),  status=200,  
mimetype='application/json')
return resp
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=8002)


And here is the simple client:


import requests
r = requests.put('http://13.57.96.64:8002/jay', data='{ "test": "Jay" }', 
headers={"Content-Type": "application/json"}, verify=False)
print(r)

I bring up the server, and as expected, it outputs:

 * Running on http://0.0.0.0:8002/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 292-073-960

and waits.  Then I run the client and see:



So the connection is fine.  But the server does not print to the terminal.  (In 
my actual application, it needs to do much more, but does nothing.)  Without 
the server running, the client fails to make a connection, as expected.  So the 
only effect of the server is to create the REST endpoint -- but it does not 
execute the logic that a message is supposed to trigger.

Hopefully, another pair of eyes will see the problem.  Thanks.

Jay

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


Re: [RELEASE] Python 2.7.16 release candidate 1

2019-02-16 Thread Terry Reedy

On 2/16/2019 8:10 PM, Benjamin Peterson wrote:

I'm pleased to announce the immediate availability of Python 2.7.16 release 
candidate 1. This is a prerelease for yet another bug fix release in the Python 
2.7.x series. It includes over 100 fixes over Python 2.7.15. See the changelog 
at

 
https://raw.githubusercontent.com/python/cpython/baacaac06f93dd624c9d7b3bac0e13fbe34f2d8c/Misc/NEWS.d/2.7.16rc1.rst

for full details.

Downloads are at:

 https://www.python.org/downloads/release/python-2716rc1/

Please test your software against the new release


Something changed in either Windows or the Windows installer.  Since I 
just upgraded to 1809, I suspect the former.  As a result, I got this 
unfriendly message.

"
Windows Defender SmartScreen prevented an unrecognized app from 
starting. Running this app might put your PC at risk.


App:
python-2.7.16rc1.amd64.msi
"

Open an issue?

--
Terry Jan Reedy

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