Re: Pandas cat.categories.isin list, is this a bug?

2018-05-17 Thread zljubisic
Hi Matt,

> (Including python-list again, for lack of a reason not to. This
> conversation is still relevant and appropriate for the general Python
> mailing list -- I just meant that the pydata list likely has many more
> Pandas users/experts, so you're more likely to get a better answer,
> faster, from a more specialized group.)

OK, for now we will stay here, but in the future I will use pydata as you have 
suggested.

> Selecting all rows that have categories is a bit simpler than what you
> are doing -- your issue is that you are working with the *set of
> distinct categories*, and not the actual vector of categories
> corresponding to your data.

Yes, now I got it thanks to your explanation. 
df.CRM_assetID.cat.categories means unique categories of the CRM_assetID field.
Now I am using df_cat[df_cat.CRM_assetID.isin({'V1254748', 'V805722', 
'V1105400'})].shape to select all rows that have relevant categories.
Thanks for the set instead of list as well. Very good tip.
Everything works as it should now. 

Matt, you were more than helpful.
Thank you very very much.

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


Re: object types, mutable or not?

2018-05-17 Thread Gregory Ewing

I don't think it's very helpful to anyone to say that "everything
is an object", because "everything" is far too vague a term.
(It's not even close to being true -- there are plenty of concepts
in Python that are not objects.)

I think I would say something like "All data that a Python program
can manipulate comes in the form of things we call objects."
Then go on to give some examples of different kinds of objects --
integer objects, string objects, list objects, etc. And that
variables in Python don't contain objects, they just refer to
objects. Draw some diagrams with boxes and arrows.

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


Re: what does := means simply?

2018-05-17 Thread Abdur-Rahmaan Janhangeer
thank you very much @steve

i guess it will make py fly more than ever !

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ

On Thu, 17 May 2018, 07:57 Steven D'Aprano, <
steve+comp.lang.pyt...@pearwood.info> wrote:

> On Thu, 17 May 2018 05:33:38 +0400, Abdur-Rahmaan Janhangeer wrote:
>
> > what does := proposes to do?
>
> Simply, it proposes to add a new operator := for assignment (or binding)
> as an expression, as an addition to the = assignment operator which
> operates only as a statement. The syntax is:
>
> name := expression
>
> and the meaning is:
>
> 1. evaluate 
>
> 2. assign that value to 
>
> 3. return that same value as the result
>
>
> A simple example (not necessarily a GOOD example, but a SIMPLE one):
>
> print(x := 100, x+1, x*2, x**3)
>
> will print:
>
> 100 101 200 100
>
> Today, we would write that as:
>
> x = 100
> print(x, x+1, x*2, x**3)
>
>
> A better example might be:
>
>
> if mo := re.search(pattern1, text):
> print(mo.group(0))
> elif mo := re.match(pattern2, text):
> print(mo.group(3))
> elif mo := re.search(pattern3, text):
> print(mo.group(2))
>
>
>
> which today would need to be written as:
>
>
> mo = re.search(pattern, text)
> if mo:
> print(mo.group(0))
> else:
> mo = re.match(pattern2, text)
> if mo:
> print(mo.group(3))
> else:
> mo := re.search(pattern3, text)
> if mo:
> print(mo.group(2))
>
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why does list's .remove() does not return an object?

2018-05-17 Thread Abdur-Rahmaan Janhangeer
if then a more convenient way might be found to naturally remove and return
the list

maybe it was not included as one might want to remove the list only

x = [1]
x.remove(1)

as opposed to

x = [1]
x.remove(1)
new_list = x

i was looking for like

x = [1]
x.remove(1).return()

ps. list is was demo illustrative var

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ

On Thu, 17 May 2018, 07:01 Ned Batchelder,  wrote:

> On 5/16/18 10:41 PM, Abdur-Rahmaan Janhangeer wrote:
> > why is x = list.remove(elem) not return the list?
> >
> >
> Methods in Python usually do one of two things: 1) mutate the object and
> return None; or 2) leave the object alone and return a new object.  This
> helps make it clear which methods mutate and which don't.  Since .remove
> mutates the list, it returns None.
>
> --Ned.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: syntax oddities

2018-05-17 Thread Abdur-Rahmaan Janhangeer
just a remark that people help and discuss on more issues unrelated to
python

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ

On Thu, 17 May 2018, 07:45 Steven D'Aprano, <
steve+comp.lang.pyt...@pearwood.info> wrote:

> On Thu, 17 May 2018 05:25:44 +0400, Abdur-Rahmaan Janhangeer wrote:
>
> > weird, still not much traffic on this thread
>
> How many ways would you like us to answer the question?
>
> It is a FAQ:
>
> https://docs.python.org/3/faq/design.html
>
> Here's an older version:
>
>
> http://www.effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm
>
>
>
>
> --
> Steve
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: syntax oddities

2018-05-17 Thread Gregory Ewing

On Tue, 15 May 2018, 23:15 Tobiah,  wrote:


Why is it getattr(object, item) rather then object.getattr(item)?


It's part of the design philosophy of Python that the
namespace of a new user-defined class should as far as
possible start off as a "blank slate", not cluttered
up with a bunch of predefined names. So, very general
things like getattr() that apply to any object are
implemented as functions that operate on an object,
rather than methods.

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


Re: object types, mutable or not?

2018-05-17 Thread Anders Wegge Keller
På Wed, 16 May 2018 14:48:27 +0100
Paul Moore  skrev:

> C++ called that an "rvalue". And then went on to define things that
> could go on the left hand side of an assignment as "lvalues". And now
> we have two confusing concepts to explain - see what happens when you
> let a standards committee define your language? :-)

 I'm not sure the C++ committee has to bear the responsibility for those
terms. They are pretty well defined in the C world, so I think you need to
point the finger of accusation at either Brian or Dennis. 

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


Re: object types, mutable or not?

2018-05-17 Thread Chris Angelico
On Thu, May 17, 2018 at 7:16 PM, Anders Wegge Keller  wrote:
> På Wed, 16 May 2018 14:48:27 +0100
> Paul Moore  skrev:
>
>> C++ called that an "rvalue". And then went on to define things that
>> could go on the left hand side of an assignment as "lvalues". And now
>> we have two confusing concepts to explain - see what happens when you
>> let a standards committee define your language? :-)
>
>  I'm not sure the C++ committee has to bear the responsibility for those
> terms. They are pretty well defined in the C world, so I think you need to
> point the finger of accusation at either Brian or Dennis.
>

Let's be fair and blame one of them for each.

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


Re: why does list's .remove() does not return an object?

2018-05-17 Thread Jach Fong

Abdur-Rahmaan Janhangeer at 2018/5/17 PM 04:23 wrote:

if then a more convenient way might be found to naturally remove and return
the list

maybe it was not included as one might want to remove the list only

x = [1]
x.remove(1)

as opposed to

x = [1]
x.remove(1)
new_list = x


IMO, this way is more flexible on its usage and avoid
a redundant copy.

--Jach



i was looking for like

x = [1]
x.remove(1).return()

ps. list is was demo illustrative var

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ

On Thu, 17 May 2018, 07:01 Ned Batchelder,  wrote:


On 5/16/18 10:41 PM, Abdur-Rahmaan Janhangeer wrote:

why is x = list.remove(elem) not return the list?



Methods in Python usually do one of two things: 1) mutate the object and
return None; or 2) leave the object alone and return a new object.  This
helps make it clear which methods mutate and which don't.  Since .remove
mutates the list, it returns None.

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



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

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


Re: Python - requests - forms - web scraping - how to deal with multi stage forms

2018-05-17 Thread GMX

https://stackoverflow.com/questions/50383210/python-requests-how-to-post-few-stages-forms
 
-- 
https://mail.python.org/mailman/listinfo/python-list 


Hi, 

Your post will get more traction on the email list if you try to post the 
actual question on the list against posting a url to an external website for 
your question. 

Coming back to the question. I think what you want to do is implement some 
client side processing using Javascript or one of it’s frameworks and implement 
the parts. Once everything is done you can submit it to the python server. 

Hope that helps. 



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


About: from sklearn import linear_model ModuleNotFoundError: No module named sklearn

2018-05-17 Thread Jpn Jha
Dear Team
Please attached  Python_PyCharm  Interpreter doc and zoom it .

The screen shots are explanatory.

Could you please  guide me step  wise  to resolve the Issue.
I am  completely new to Python.

Thanks
Regards

Jai Prakash
7975839735
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what does := means simply?

2018-05-17 Thread bartc

On 17/05/2018 04:54, Steven D'Aprano wrote:

On Thu, 17 May 2018 05:33:38 +0400, Abdur-Rahmaan Janhangeer wrote:


what does := proposes to do?



A simple example (not necessarily a GOOD example, but a SIMPLE one):

print(x := 100, x+1, x*2, x**3)


It's also not a good example because it assumes left-to-right evaluation 
order of the arguments. Even if Python guarantees that, it might be a 
problem if the code is ever ported anywhere else.


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


Re: what does := means simply?

2018-05-17 Thread Paul Moore
On 17 May 2018 at 12:58, bartc  wrote:
> On 17/05/2018 04:54, Steven D'Aprano wrote:
>>
>> On Thu, 17 May 2018 05:33:38 +0400, Abdur-Rahmaan Janhangeer wrote:
>>
>>> what does := proposes to do?
>
>> A simple example (not necessarily a GOOD example, but a SIMPLE one):
>>
>> print(x := 100, x+1, x*2, x**3)
>
>
> It's also not a good example because it assumes left-to-right evaluation
> order of the arguments. Even if Python guarantees that, it might be a
> problem if the code is ever ported anywhere else.

It's a good example, because it makes it clear that the benefits of :=
are at least in some cases, somewhat dependent on the fact that Python
evaluates arguments left to right :-)

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


Re: what does := means simply?

2018-05-17 Thread Serhiy Storchaka

17.05.18 15:07, Paul Moore пише:

It's a good example, because it makes it clear that the benefits of :=
are at least in some cases, somewhat dependent on the fact that Python
evaluates arguments left to right :-)


Unless it evaluates them in other order.

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


Re: what does := means simply?

2018-05-17 Thread Antoon Pardon
On 17-05-18 03:44, Chris Angelico wrote:
> On Thu, May 17, 2018 at 11:33 AM, Abdur-Rahmaan Janhangeer
>  wrote:
>> what does := proposes to do?
>>
>> pep572
>>
> If you read the PEP, you'll find an answer to your question.
>
> https://www.python.org/dev/peps/pep-0572/
>
> ChrisA

Just wondering, but in discussing this PEP has one considered
making the ';' into an expression too, with the value being
the value of the last expression?

I just ask because sometimes I have a loop that now often is written
as follows:

while True:
a = prepare_a()
b = prepare_b()
if not condition(a, b):
break
Do other stuff

Now with the := assignment it seems I will be able to write it like this:

while [a := prepare_a(), b := prepare_b(), condition(a, b)][-1]:
Do other stuff.


But IMO it would be nicer if it could be written as:

while a := prepare_a(); b := prepare_b(); condition(a, b):
Do other stuff

-- 
Antoon Pardon

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


Re: syntax oddities

2018-05-17 Thread Grant Edwards
On 2018-05-17, Abdur-Rahmaan Janhangeer  wrote:

> just a remark that people help and discuss on more issues unrelated to
> python
[...]
> On Thu, 17 May 2018, 07:45 Steven D'Aprano, <
> steve+comp.lang.pyt...@pearwood.info> wrote:
>> On Thu, 17 May 2018 05:25:44 +0400, Abdur-Rahmaan Janhangeer wrote:
>>

And one such popular issue is how top-posting is evil.

-- 
Grant Edwards   grant.b.edwardsYow! Catsup and Mustard all
  at   over the place!  It's the
  gmail.comHuman Hamburger!

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


Re: what does := means simply?

2018-05-17 Thread Steven D'Aprano
On Thu, 17 May 2018 12:58:43 +0100, bartc wrote:

> On 17/05/2018 04:54, Steven D'Aprano wrote:
>> On Thu, 17 May 2018 05:33:38 +0400, Abdur-Rahmaan Janhangeer wrote:
>> 
>>> what does := proposes to do?
> 
>> A simple example (not necessarily a GOOD example, but a SIMPLE one):
>> 
>> print(x := 100, x+1, x*2, x**3)
> 
> It's also not a good example because it assumes left-to-right evaluation
> order of the arguments. Even if Python guarantees that, it might be a
> problem if the code is ever ported anywhere else.

Seriously? You think we have a responsibility to write examples which 
will work with arbitrary languages with arbitrarily different evaluation 
order?

Okay, let's be clear:

- if the language has different evaluation order, it might not work;

- if the language has different syntax, it might not work;

- if the language has not variables or names, it might not work;

- if the language uses something other than decimal for numeric
  literals, it might not work;

- if the language doesn't use + * and ** for addition, multiplication
  and exponentiation, it might not work;

- if the language has no print, it might not work;

- if the language doesn't use ( ) for function calls, it might
  not work;

- or if the print function does something else, say, erases your 
  hard disk, you probably don't want to run that example;

- or if the language has no I/O, or no functions, it might not 
  do what you expect either;

- and if the language doesn't actually have a working interpreter
  or compiler for any existing computer, you may have trouble
  getting the code to run.


Did I miss any other problems?


-- 
Steve

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


Re: what does := means simply?

2018-05-17 Thread Steven D'Aprano
On Thu, 17 May 2018 14:56:32 +0200, Antoon Pardon wrote:

> On 17-05-18 03:44, Chris Angelico wrote:

>> https://www.python.org/dev/peps/pep-0572/

> Just wondering, but in discussing this PEP has one considered making the
> ';' into an expression too, with the value being the value of the last
> expression?

I'm not going to answer for Chris, the PEP author, but if I were the PEP 
author I'd say "No, but you can write your own competing PEP".



-- 
Steve

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


Re: Python - requests - forms - web scraping - how to deal with multi stage forms

2018-05-17 Thread Grant Edwards
On 2018-05-17, kret...@gmail.com  wrote:

> https://stackoverflow.com/questions/50383210/python-requests-how-to-post-few-stages-forms

Your point?

-- 
Grant Edwards   grant.b.edwardsYow! I had pancake makeup
  at   for brunch!
  gmail.com

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


Re: what does := means simply?

2018-05-17 Thread Marko Rauhamaa
Antoon Pardon :

> On 17-05-18 03:44, Chris Angelico wrote:
> I just ask because sometimes I have a loop that now often is written
> as follows:
>
> while True:
> a = prepare_a()
> b = prepare_b()
> if not condition(a, b):
> break
> Do other stuff
>
> Now with the := assignment it seems I will be able to write it like this:
>
> while [a := prepare_a(), b := prepare_b(), condition(a, b)][-1]:
> Do other stuff.
>
>
> But IMO it would be nicer if it could be written as:
>
> while a := prepare_a(); b := prepare_b(); condition(a, b):
> Do other stuff

I know you must be joking but...

   while condition(a := prepare_a(), b := prepare_b()):
   Do other stuff.


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


Re: what does := means simply?

2018-05-17 Thread Steven D'Aprano
On Thu, 17 May 2018 15:54:27 +0300, Serhiy Storchaka wrote:

> 17.05.18 15:07, Paul Moore пише:
>> It's a good example, because it makes it clear that the benefits of :=
>> are at least in some cases, somewhat dependent on the fact that Python
>> evaluates arguments left to right :-)
> 
> Unless it evaluates them in other order.

I don't think it does though, does it?

I know there are a few expressions that evaluate out of left-to-right 
order. But I think positional arguments are always evaluated left-to-
right.


-- 
Steve

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


Re: what does := means simply?

2018-05-17 Thread Chris Angelico
On Thu, May 17, 2018 at 11:34 PM, Steven D'Aprano
 wrote:
> On Thu, 17 May 2018 14:56:32 +0200, Antoon Pardon wrote:
>
>> On 17-05-18 03:44, Chris Angelico wrote:
>
>>> https://www.python.org/dev/peps/pep-0572/
>
>> Just wondering, but in discussing this PEP has one considered making the
>> ';' into an expression too, with the value being the value of the last
>> expression?
>
> I'm not going to answer for Chris, the PEP author, but if I were the PEP
> author I'd say "No, but you can write your own competing PEP".
>

Yep. Or just "you're welcome to propose an unrelated feature".

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


Re: what does := means simply?

2018-05-17 Thread Chris Angelico
On Thu, May 17, 2018 at 9:58 PM, bartc  wrote:
> On 17/05/2018 04:54, Steven D'Aprano wrote:
>>
>> On Thu, 17 May 2018 05:33:38 +0400, Abdur-Rahmaan Janhangeer wrote:
>>
>>> what does := proposes to do?
>
>
>> A simple example (not necessarily a GOOD example, but a SIMPLE one):
>>
>> print(x := 100, x+1, x*2, x**3)
>
>
> It's also not a good example because it assumes left-to-right evaluation
> order of the arguments. Even if Python guarantees that, it might be a
> problem if the code is ever ported anywhere else.
>

Python DOES guarantee it, and nobody cares about your personal toy
language other than you. :)

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


Request for comments: use-cases for delayed evaluation

2018-05-17 Thread Steven D'Aprano
Suppose Python had a mechanism to delay the evaluation of expressions 
until needed. What would you use it for?

Python already does this on an ad hoc basis. For example, the "and" and 
"or" operators are special:

 and 

If the expression on the left is falsey, the expression on the right is 
ignored and not evaluated. Similarly for "or":

 or 

only evaluates the expression on the right if the one on the left is 
falsey.

Similarly for ternary if.

But apart from these few ad hoc examples of short-circuiting behaviour, 
we don't really have an convenient way to do the same in our code. But 
what if we did? I can think of four places where I would like to delay 
the evaluation of expressions:

1. Late binding of function parameter defaults.

Given a function with defaults:

def function(arg=DEFAULT)

Python's standard behaviour is to evaluate DEFAULT *once*, then always 
return the same value. Sometimes we want the default to be re-evaluated 
each time the function is called without an argument.


2. Printing of individual expressions, not just their value, within a 
line of code.

Sometimes I have a line of code where I'm not sure if a particular sub-
expression is correct. Of course I can refactor the code, but a 
lightweight solution would be to just insert a print:

result = spam + eggs + print(EXPRESSION) +  cheese

Alas, this doesn't work: print doesn't return anything useful (it returns 
None), and the expression is evaluated before print can see it. But a 
simple helper function could solve this problem:

# pseudo-code
def debugprint(EXPRESSION):
value = (evaluate EXPRESSION)
print(EXPRESSION AS A STRING, value)
return value



3. Assertions, similar to the "assert" statement, which don't evaluate 
the (potentially expensive) expression unless a flag is switched on:

# pseudo-code
def myassert(EXPRESSION, flag=None):
if flag is None:
flag = DEBUGGING
if flag and not (evaluate EXPRESSION):
s = EXPRESSION as a string
raise AssertionError('assertion "%s" failed' % s)



4. Similarly, delaying the evaluation of expressions for logging:

log.debug(str(sum(primes_below(10**10)))

has to calculate a huge number of prime numbers, and sum them, even if 
the log level is above DEBUG and the result won't be logged.


Of course I realise that every one of these have work-arounds or 
alternate solutions, some of which work quite well, some of which not so 
well. That's not my question.

My question is, if we had a way to delay the evaluation of expressions, 
what if anything would you use it for?

Use-cases beyond the four above are especially welcome.



-- 
Steve

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


Re: what does := means simply?

2018-05-17 Thread Tobiah

On 05/16/2018 08:54 PM, Steven D'Aprano wrote:

On Thu, 17 May 2018 05:33:38 +0400, Abdur-Rahmaan Janhangeer wrote:


what does := proposes to do?


Simply, it proposes to add a new operator := for assignment (or binding)
as an expression, as an addition to the = assignment operator which
operates only as a statement. The syntax is:

 name := expression

and the meaning is:

1. evaluate 

2. assign that value to 

3. return that same value as the result


Well, that would be a welcome addition!


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


Re: syntax oddities

2018-05-17 Thread Tobiah

Top posting is awesome for the reader plowing through
a thread in order.  In that case the cruft at the bottom
is only for occasional reference.

Ok, I yield!  I know the bottom-posting party has congress
right now.

On 05/17/2018 06:29 AM, Grant Edwards wrote:

On 2018-05-17, Abdur-Rahmaan Janhangeer  wrote:


just a remark that people help and discuss on more issues unrelated to
python

[...]

On Thu, 17 May 2018, 07:45 Steven D'Aprano, <
steve+comp.lang.pyt...@pearwood.info> wrote:

On Thu, 17 May 2018 05:25:44 +0400, Abdur-Rahmaan Janhangeer wrote:



And one such popular issue is how top-posting is evil.



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


Re: syntax oddities

2018-05-17 Thread Paul
Top posting saves a huge amount of useless scrolling time.  Is it frowned
upon on this list?

On Thu, May 17, 2018, 7:26 AM Tobiah  wrote:

> Top posting is awesome for the reader plowing through
> a thread in order.  In that case the cruft at the bottom
> is only for occasional reference.
>
> Ok, I yield!  I know the bottom-posting party has congress
> right now.
>
> On 05/17/2018 06:29 AM, Grant Edwards wrote:
> > On 2018-05-17, Abdur-Rahmaan Janhangeer  wrote:
> >
> >> just a remark that people help and discuss on more issues unrelated to
> >> python
> > [...]
> >> On Thu, 17 May 2018, 07:45 Steven D'Aprano, <
> >> steve+comp.lang.pyt...@pearwood.info> wrote:
> >>> On Thu, 17 May 2018 05:25:44 +0400, Abdur-Rahmaan Janhangeer wrote:
> >>>
> >
> > And one such popular issue is how top-posting is evil.
> >
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what does := means simply?

2018-05-17 Thread bartc

On 17/05/2018 14:32, Steven D'Aprano wrote:

On Thu, 17 May 2018 12:58:43 +0100, bartc wrote:


On 17/05/2018 04:54, Steven D'Aprano wrote:

On Thu, 17 May 2018 05:33:38 +0400, Abdur-Rahmaan Janhangeer wrote:


what does := proposes to do?



A simple example (not necessarily a GOOD example, but a SIMPLE one):

print(x := 100, x+1, x*2, x**3)


It's also not a good example because it assumes left-to-right evaluation
order of the arguments. Even if Python guarantees that, it might be a
problem if the code is ever ported anywhere else.


Seriously? You think we have a responsibility to write examples which
will work with arbitrary languages with arbitrarily different evaluation
order?

Okay, let's be clear:

- if the language has different evaluation order, it might not work;


That's right. The rest of your list either doesn't matter so much or is 
only remotely likely.


Doing a certain amount of restructuring of an algorithm expressed in one 
language in order to port it to another is expected. But relying on 
evaluation order is bad form. Suppose this bit of code was imported from 
elsewhere where evaluation was right to left?


Anyway, try this:

def showarg(x): print(x)

def dummy(*args,**kwargs): pass

dummy(a=showarg(1),*[showarg(2),showarg(3)])

This displays 2,3,1 showing that evaluation is not left to right.


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


Re: syntax oddities

2018-05-17 Thread Chris Angelico
On Fri, May 18, 2018 at 12:31 AM, Paul  wrote:
> Top posting saves a huge amount of useless scrolling time.  Is it frowned
> upon on this list?

Trimming your replies saves even more. Yes, it is.

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


Re: syntax oddities

2018-05-17 Thread Paul
 wrote:

> > Is it frowned
> > upon on this list?
>
> Trimming your replies saves even more. Yes, it is.
>
> ChrisA
> -
>

kk.
Thanks
 Paul

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


Re: what does := means simply?

2018-05-17 Thread bartc

On 17/05/2018 15:03, Chris Angelico wrote:

On Thu, May 17, 2018 at 9:58 PM, bartc  wrote:

On 17/05/2018 04:54, Steven D'Aprano wrote:


On Thu, 17 May 2018 05:33:38 +0400, Abdur-Rahmaan Janhangeer wrote:


what does := proposes to do?




A simple example (not necessarily a GOOD example, but a SIMPLE one):

print(x := 100, x+1, x*2, x**3)



It's also not a good example because it assumes left-to-right evaluation
order of the arguments. Even if Python guarantees that, it might be a
problem if the code is ever ported anywhere else.



Python DOES guarantee it, and nobody cares about your personal toy
language other than you. :)


As I said, it's poor form.

Of course, full-on Python code is pretty much impossible to port 
anywhere else anyway.


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


Re: what does := means simply?

2018-05-17 Thread Marko Rauhamaa
bartc :
> Anyway, try this:
>
> def showarg(x): print(x)
>
> def dummy(*args,**kwargs): pass
>
> dummy(a=showarg(1),*[showarg(2),showarg(3)])
>
> This displays 2,3,1 showing that evaluation is not left to right.

Nice one!


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


Re: why does list's .remove() does not return an object?

2018-05-17 Thread Ned Batchelder

On 5/17/18 4:23 AM, Abdur-Rahmaan Janhangeer wrote:
if then a more convenient way might be found to naturally remove and 
return the list


maybe it was not included as one might want to remove the list only

x = [1]
x.remove(1)

as opposed to

x = [1]
x.remove(1)
new_list = x

i was looking for like

x = [1]
x.remove(1).return()


I don't understand what this would return? x? You already have x. Is it 
meant to make a copy? x has been mutated, so I don't understand the 
benefit of making a copy of the 1-less x.  Can you elaborate on the 
problem you are trying to solve?


--Ned.

(PS: bottom-posting (adding your response below the text you are 
responding to) will make the conversation easier to follow...)




ps. list is was demo illustrative var

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ

On Thu, 17 May 2018, 07:01 Ned Batchelder, > wrote:


On 5/16/18 10:41 PM, Abdur-Rahmaan Janhangeer wrote:
> why is x = list.remove(elem) not return the list?
>
>
Methods in Python usually do one of two things: 1) mutate the
object and
return None; or 2) leave the object alone and return a new
object.  This
helps make it clear which methods mutate and which don't. Since
.remove
mutates the list, it returns None.

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




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


Re: syntax oddities

2018-05-17 Thread Rich Shepard

On Fri, 18 May 2018, Chris Angelico wrote:


Top posting saves a huge amount of useless scrolling time.  Is it frowned
upon on this list?


Trimming your replies saves even more. Yes, it is.


  Allow me to add an additional reason for trimming and responding beneath
each quoted section: it puts the response in the proper context.

  People who top-post require the reader to scroll up and down to fit the
response to the original message. Might as well just send a response without
the original message and elimiate all scrolling ... as well as the context
of the thread.

  When we respond to a received message (mail list or direct) we want the
reader to understand what we write. Trimming away all but the pieces to
which we respond makes communication more clear and, we hope, more
effective.

Regards,

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


Re: what does := means simply?

2018-05-17 Thread Chris Angelico
On Fri, May 18, 2018 at 12:30 AM, bartc  wrote:
> Anyway, try this:
>
> def showarg(x): print(x)
>
> def dummy(*args,**kwargs): pass
>
> dummy(a=showarg(1),*[showarg(2),showarg(3)])
>
> This displays 2,3,1 showing that evaluation is not left to right.
>

Keyword args are evaluated after positional args. It's a bad idea to
put positional after keyword; you risk mis-identifying your args:

>>> def dummy(a, b, c): pass
...
>>> dummy(a=showarg(1),*[showarg(2),showarg(3)])
2
3
1
Traceback (most recent call last):
  File "", line 1, in 
TypeError: dummy() got multiple values for argument 'a'

Evaluation is not always left to right, but it is always well-defined.

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


Re: why does list's .remove() does not return an object?

2018-05-17 Thread Abdur-Rahmaan Janhangeer
On Thu, 17 May 2018, 18:55 Ned Batchelder,  wrote:

> On 5/17/18 4:23 AM, Abdur-Rahmaan Janhangeer wrote:
>
> if then a more convenient way might be found to naturally remove and
> return the list
>
> maybe it was not included as one might want to remove the list only
>
> x = [1]
> x.remove(1)
>
> as opposed to
>
> x = [1]
> x.remove(1)
> new_list = x
>
> i was looking for like
>
> x = [1]
> x.remove(1).return()
>
>
> I don't understand what this would return? x? You already have x.  Is it
> meant to make a copy? x has been mutated, so I don't understand the benefit
> of making a copy of the 1-less x.  Can you elaborate on the problem you are
> trying to solve?
>
> --Ned.
>
>
assignment to another var

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


Re: what does := means simply?

2018-05-17 Thread Ian Kelly
On Thu, May 17, 2018 at 9:06 AM, Chris Angelico  wrote:
> On Fri, May 18, 2018 at 12:30 AM, bartc  wrote:
>> Anyway, try this:
>>
>> def showarg(x): print(x)
>>
>> def dummy(*args,**kwargs): pass
>>
>> dummy(a=showarg(1),*[showarg(2),showarg(3)])
>>
>> This displays 2,3,1 showing that evaluation is not left to right.
>>
>
> Keyword args are evaluated after positional args. It's a bad idea to
> put positional after keyword; you risk mis-identifying your args:
>
 def dummy(a, b, c): pass
> ...
 dummy(a=showarg(1),*[showarg(2),showarg(3)])
> 2
> 3
> 1
> Traceback (most recent call last):
>   File "", line 1, in 
> TypeError: dummy() got multiple values for argument 'a'
>
> Evaluation is not always left to right, but it is always well-defined.

I wasn't actually aware it was allowed to place keyword args before
positional args; this must be relatively new in Python 3.

This raises a new issue for me w.r.t. PEP 572. The spelling of :=
makes it unlikely to accidentally use in place of ==, but what about
:= and = confusion? For example, say I mean to write this:

foo(a := 42, b, c)

but accidentally write this instead:

foo(a = 42, b, c)

Hopefully for many functions this would just be a TypeError
("unexpected keyword argument"). At the same time, it's a fairly
common practice to pass a variable to a function that happens to have
the same name as the argument being passed. Has there been any
discussion of whether this is likely to be a source of confusion?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what does := means simply?

2018-05-17 Thread Chris Angelico
On Fri, May 18, 2018 at 1:27 AM, Ian Kelly  wrote:
> This raises a new issue for me w.r.t. PEP 572. The spelling of :=
> makes it unlikely to accidentally use in place of ==, but what about
> := and = confusion? For example, say I mean to write this:
>
> foo(a := 42, b, c)
>
> but accidentally write this instead:
>
> foo(a = 42, b, c)
>
> Hopefully for many functions this would just be a TypeError
> ("unexpected keyword argument"). At the same time, it's a fairly
> common practice to pass a variable to a function that happens to have
> the same name as the argument being passed. Has there been any
> discussion of whether this is likely to be a source of confusion?

There has been. The value of it is too great to disallow it, and most
style guides would recommend writing the keyword argument with no
spaces around the equals sign, so there's a bit of a chance to catch
the bug that way. But you're right that it is a potential bug.

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


Re: why does list's .remove() does not return an object?

2018-05-17 Thread Alexandre Brault

On 2018-05-17 11:26 AM, Abdur-Rahmaan Janhangeer wrote:
> I don't understand what this would return? x? You already have x.  Is it
> meant to make a copy? x has been mutated, so I don't understand the benefit
> of making a copy of the 1-less x.  Can you elaborate on the problem you are
> trying to solve?
>
> --Ned.
>
>
> assignment to another var
>
You already have access to the list before removal, the list after
removal and the element to be removed.

Do need a copy of the list before removing x?
>>> old_list = list[:]
>>> list.remove(x)

Do you need the list after removing x?
>>> list.remove(x)  # list is the modified list

Do you need x?
>>> list.remove(x)  # x is x

What else would need to be assigned to another var?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why does list's .remove() does not return an object?

2018-05-17 Thread Abdur-Rahmaan Janhangeer
x = [0,1]
x.remove(0)
new_list = x

instead i want in one go

x = [0,1]
new_list = x.remove(0) # here a way for it to return the modified list by
adding a .return() maybe ?

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ

On Thu, 17 May 2018, 19:54 Alexandre Brault,  wrote:

>
> On 2018-05-17 11:26 AM, Abdur-Rahmaan Janhangeer wrote:
> > I don't understand what this would return? x? You already have x.  Is it
> > meant to make a copy? x has been mutated, so I don't understand the
> benefit
> > of making a copy of the 1-less x.  Can you elaborate on the problem you
> are
> > trying to solve?
> >
> > --Ned.
> >
> >
> > assignment to another var
> >
> You already have access to the list before removal, the list after
> removal and the element to be removed.
>
> Do need a copy of the list before removing x?
> >>> old_list = list[:]
> >>> list.remove(x)
>
> Do you need the list after removing x?
> >>> list.remove(x)  # list is the modified list
>
> Do you need x?
> >>> list.remove(x)  # x is x
>
> What else would need to be assigned to another var?
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Request for comments: use-cases for delayed evaluation

2018-05-17 Thread Dan Strohl via Python-list


I could easily see using all of the examples;  I run into this pretty regularly.

What about something like the following (which, honestly is really a 
combination of other examples).

If I have a function that has multiple parameters, each of which might be 
expensive, but it might break out earlier depending on how each one is 
evaluated... for example:

(pretending that "$" is a flag that says "evaluate later", and $(arg) is how 
you say "evaluate now")

def combine_unless_none(*$args, sep=', '):
""" if any arg evaluates to None, return '', otherwise join"""
for arg in args:
tmp_arg = $(arg)
If tmp_arg is None:
return "
return sep.join(args)

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


Re: why does list's .remove() does not return an object?

2018-05-17 Thread Ned Batchelder

On 5/17/18 11:57 AM, Abdur-Rahmaan Janhangeer wrote:

x = [0,1]
x.remove(0)
new_list = x

instead i want in one go

x = [0,1]
new_list = x.remove(0) # here a way for it to return the modified list by
adding a .return() maybe ?


There isn't a way to do that in one line.  I often find myself splitting 
long statements into more, shorter, statements to express myself more 
clearly.


I don't know if you have a real piece of code in mind, so I don't know 
if you can tell us:  why is it useful to have another variable referring 
to the same list?


--Ned.


Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ

On Thu, 17 May 2018, 19:54 Alexandre Brault,  wrote:


On 2018-05-17 11:26 AM, Abdur-Rahmaan Janhangeer wrote:

I don't understand what this would return? x? You already have x.  Is it
meant to make a copy? x has been mutated, so I don't understand the

benefit

of making a copy of the 1-less x.  Can you elaborate on the problem you

are

trying to solve?

--Ned.


assignment to another var


You already have access to the list before removal, the list after
removal and the element to be removed.

Do need a copy of the list before removing x?

old_list = list[:]
list.remove(x)

Do you need the list after removing x?

list.remove(x)  # list is the modified list

Do you need x?

list.remove(x)  # x is x

What else would need to be assigned to another var?
--
https://mail.python.org/mailman/listinfo/python-list



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


RE: why does list's .remove() does not return an object?

2018-05-17 Thread Dan Strohl via Python-list
On 2018-05-17 11:26 AM, Abdur-Rahmaan Janhangeer wrote:
> I don't understand what this would return? x? You already have x.  Is 
> it meant to make a copy? x has been mutated, so I don't understand the 
> benefit of making a copy of the 1-less x.  Can you elaborate on the 
> problem you are trying to solve?
>
> --Ned.
>
>
> assignment to another var
>

Though I don’t know what the OP was specifically looking for I could see a 
benefit to returning the item deleted.

So, lets take as an example I have an object like:

class ListItem(object):
def __init__(self, key, data):
self.key = key
self.data = data
def __eq__(other):
return other == self.key

and I do something like:

i1 = ListItem('hello', 'foobar')
l2 = ListItem('goodby', 'snafu')

l = [i1, i2]

So, lets say I have a need where I want to do something like a remove, but I 
also want to be able to get the .data variable from the object I am removing, 
it would be nice to be able to simply do

x = l.remove('hello')
print(x.data)

Yes, I could do a index/pop to get this, or I could keep a separate dict of the 
objects as well for lookups, or a number of other techniques, but it would be 
easier to simply get it back during the remove().

Dan Strohl

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


Re: why does list's .remove() does not return an object?

2018-05-17 Thread Ned Batchelder

On 5/17/18 12:28 PM, Dan Strohl via Python-list wrote:

On 2018-05-17 11:26 AM, Abdur-Rahmaan Janhangeer wrote:

I don't understand what this would return? x? You already have x.  Is
it meant to make a copy? x has been mutated, so I don't understand the
benefit of making a copy of the 1-less x.  Can you elaborate on the
problem you are trying to solve?

--Ned.


assignment to another var


Though I don’t know what the OP was specifically looking for I could see a 
benefit to returning the item deleted.


Notice that this is not the thing the OP wanted returned.  I believe 
they are looking to return the list, not the item.


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


Re: what does := means simply?

2018-05-17 Thread Steven D'Aprano
On Thu, 17 May 2018 15:50:17 +0100, bartc wrote:

> On 17/05/2018 15:03, Chris Angelico wrote:
>> On Thu, May 17, 2018 at 9:58 PM, bartc  wrote:
>>> On 17/05/2018 04:54, Steven D'Aprano wrote:

 On Thu, 17 May 2018 05:33:38 +0400, Abdur-Rahmaan Janhangeer wrote:

> what does := proposes to do?
>>>
>>>
 A simple example (not necessarily a GOOD example, but a SIMPLE one):

 print(x := 100, x+1, x*2, x**3)
>>>
>>>
>>> It's also not a good example because it assumes left-to-right
>>> evaluation order of the arguments. Even if Python guarantees that, it
>>> might be a problem if the code is ever ported anywhere else.
>>>
>>>
>> Python DOES guarantee it, and nobody cares about your personal toy
>> language other than you. :)
> 
> As I said, it's poor form.

"... to rely on a language's guaranteed features, because, well, for no 
reason really."


> Of course, full-on Python code is pretty much impossible to port
> anywhere else anyway.

*rolls eyes*

You know what "Turing Complete" means, don't you? Either:

- Python is the only Turing Complete programming language in the universe;

- Python is the only programming language in the universe which is
  strictly more powerful than a Turing Machine; or

- you're talking nonsense on stilts.


I know where I'd put my money.


Of course it may sometimes be tricky to mechanically port certain Python 
programs to languages which are less powerful (in the Blub sense). But 
this is nothing new: mechanically porting from one language to another is 
always fraught with problems, unless the languages are designed for that 
(e.g. Coffeescript and Javascript).

Any pair of languages will have code that is hard to port from one to the 
other without jumping through hoops. Try porting C code with lots of 
dynamic memory allocations and pointer accesses to COBOL, or Scheme code 
using continuations to Python, or Hyperscript text chunking code to 
Fortran.

But hard does not mean "pretty much impossible".




-- 
Steve

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


Re: what does := means simply?

2018-05-17 Thread Steven D'Aprano
On Thu, 17 May 2018 17:50:22 +0300, Marko Rauhamaa wrote:

> bartc :
>> Anyway, try this:
>>
>> def showarg(x): print(x)
>>
>> def dummy(*args,**kwargs): pass
>>
>> dummy(a=showarg(1),*[showarg(2),showarg(3)])
>>
>> This displays 2,3,1 showing that evaluation is not left to right.
> 
> Nice one!

I'm fairly sure that both you and Bart know full well I was talking about 
positional arguments. My example used only positional arguments, and my 
reply to Serhiy explicitly referenced positional arguments.

But don't bother responding to what I *actually* said, it's much more fun 
to attack a strawman, right?

And besides, Bart's "showarg" function is a waste of space: it could be 
simply replaced by print.

py> dummy(a=print(1), *[print(2), print(3)])
2
3
1

You want some more examples of non-left to right evaluation order?

Comprehensions.

Ternary if.

Are there any others? Could be. So what? The existence of odd corner 
cases in the language doesn't invalidate my example that doesn't go 
anywhere near those odd corners.


-- 
Steve

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


Re: what does := means simply?

2018-05-17 Thread Steven D'Aprano
On Thu, 17 May 2018 15:50:17 +0100, bartc wrote:

> Of course, full-on Python code is pretty much impossible to port
> anywhere else anyway.

Oh, I forgot to mention... given that Python is frequently used to 
prototype applications before the production-ready application is written 
in C, C++ or Java, the idea that Python code (whether "full on" or 
otherwise) cannot be ported is especially silly.


-- 
Steve

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


Re: object types, mutable or not?

2018-05-17 Thread Ben Bacarisse
Anders Wegge Keller  writes:

> På Wed, 16 May 2018 14:48:27 +0100
> Paul Moore  skrev:
>
>> C++ called that an "rvalue". And then went on to define things that
>> could go on the left hand side of an assignment as "lvalues". And now
>> we have two confusing concepts to explain - see what happens when you
>> let a standards committee define your language? :-)
>
>  I'm not sure the C++ committee has to bear the responsibility for those
> terms. They are pretty well defined in the C world, so I think you need to
> point the finger of accusation at either Brian or Dennis.

The terms are much older than that.  The first BCPL (1967) reference
manual uses the terms, and I don't think Martin Richards invented them.

(And C++ has added glvalue and prvalue to lvalue and rvalue.)

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


Re: what does := means simply?

2018-05-17 Thread Chris Angelico
On Fri, May 18, 2018 at 3:34 AM, Steven D'Aprano
 wrote:
> On Thu, 17 May 2018 15:50:17 +0100, bartc wrote:
>
>> Of course, full-on Python code is pretty much impossible to port
>> anywhere else anyway.
>
> Oh, I forgot to mention... given that Python is frequently used to
> prototype applications before the production-ready application is written
> in C, C++ or Java, the idea that Python code (whether "full on" or
> otherwise) cannot be ported is especially silly.
>

I'm morbidly curious as to what "half-on Python code" would look like.

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


Package DLL or SO in wheel

2018-05-17 Thread Chris Nyland
Hello,

We have several internal modules we have developed that are used mostly to
read different types of data files. Most of the time the different data
file formats come with some sort of DLL or SO files that gives a standard
interface to read the files. Our design pattern is to create a python
library that uses ctypes to interface with the shared library.

To be clear we are not building the shared libraries these are usually
provided by another group or distributed by a  third party.

So the issue is I want to bundle these share libraries with the module into
a wheel or sdist package to server off our local PyPiServer. I have combed
though the documentation on the setup.py and setuptools and I cannot figure
out a simple way to do this. Currently we are just adding them as datafiles
but this means that the wheels are not named with a particular platform and
thus we need to bundle all the different possible shared libraries with it.

Additionally using the data files method always puts the share library in
the same directory as the Python source while this works I wasn't certain
if there is a more appropriate place for the libraries in the Python
installation.

So in summary:
1. How do I create a setup.py to bundle the appropriate share library into
a wheel for a given platform and name the wheel properly.
2. Where is the most appropriate spot to stick these shared libraries?

Most of our work is done in Windows but we have some modules that we use on
Linux as well. We have both 32 and 64 bit environments. We are currently
using Python 3.6.

Thanks

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


Re: what does := means simply?

2018-05-17 Thread Steven D'Aprano
On Fri, 18 May 2018 03:44:25 +1000, Chris Angelico wrote:

> I'm morbidly curious as to what "half-on Python code" would look like.

Writing Java in Python. Or C in Python. Or Lisp in Python. Or ...


-- 
Steve

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


Re: what does := means simply?

2018-05-17 Thread Chris Angelico
On Fri, May 18, 2018 at 3:48 AM, Steven D'Aprano
 wrote:
> On Fri, 18 May 2018 03:44:25 +1000, Chris Angelico wrote:
>
>> I'm morbidly curious as to what "half-on Python code" would look like.
>
> Writing Java in Python. Or C in Python. Or Lisp in Python. Or ...
>

Ah. I was wondering if this was more like "Python code written when
the programmer's brain was half-on" (which, for many, is any time
prior to the third cup of coffee).

Actually, probably not all that different, come to think of it.

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


Re: why does list's .remove() does not return an object?

2018-05-17 Thread David Stanek
On 17-May-2018 12:37, Ned Batchelder wrote:
> On 5/17/18 12:28 PM, Dan Strohl via Python-list wrote:
> > On 2018-05-17 11:26 AM, Abdur-Rahmaan Janhangeer wrote:
> > > I don't understand what this would return? x? You already have x.  Is
> > > it meant to make a copy? x has been mutated, so I don't understand the
> > > benefit of making a copy of the 1-less x.  Can you elaborate on the
> > > problem you are trying to solve?
> > >
> > > --Ned.
> > >
> > >
> > > assignment to another var
> > >
> > Though I don’t know what the OP was specifically looking for I could see a 
> > benefit to returning the item deleted.
>
> Notice that this is not the thing the OP wanted returned.  I believe they
> are looking to return the list, not the item.
>

I'm guessing that they want to be able to do some sort of method
chaining like:

  the_list.remove(x).remove(y)

Although the clarifying example was contrived and confusing. A more
concrete example would be greatly appreciated.

-- 
david stanek
web: https://dstanek.com
twitter: https://twitter.com/dstanek
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why does list's .remove() does not return an object?

2018-05-17 Thread Tobiah

On 05/17/2018 09:25 AM, Ned Batchelder wrote:

On 5/17/18 11:57 AM, Abdur-Rahmaan Janhangeer wrote:

x = [0,1]
x.remove(0)
new_list = x


Just call the original list 'new_list' to begin with.

  new_list = [0, 1]
  new_list.remove(0)


There you are!
--
https://mail.python.org/mailman/listinfo/python-list


ANN: Wing Python IDE 6.0.12 released

2018-05-17 Thread Wingware

Hi,

We've just released Wing 6.0.12 , 
which adds wxPython 4 as a supported matplotlib backend, fixes remote 
development with Python 3.7, improves PEP287 docstring formatting 
errors, correctly updates the Source Assistant for remote files, fixes 
display glitches in the Remote Hosts dialog, adds minor updates of the 
French localization, and makes about 20 other improvements.  For 
details, see https://wingware.com/pub/wingide/6.0.12/CHANGELOG.txt


Download Now 

About Wing

Wing is a family of cross-platform 
 Python IDEs with 
powerful integrated editing, debugging, unit testing, and project 
management features. Wing runs on Windows, Linux, and OS X, and can be 
used to develop any kind of Python code for web, desktop, embedded 
scripting, and other applications.


Wing 101  and Wing Personal 
 omit some features and 
are free to download and use without a license. Wing Pro 
 requires purchasing 
 or upgrading 
 a license, or obtaining a 30-day 
trial at startup.


Version 6 introduces many new features, including improved 
multi-selection, much easier remote development 
, debugging from the Python 
Shell, recursive debugging, PEP 484 and 526 type hinting, support for 
Python 3.6 and 3.7, Vagrant , 
Jupyter , and Django 
 1.10+, easier Raspberry Pi 
 development, optimized 
debugger, OS X full screen mode, One Dark color palette, Russian 
localization (thanks to Alexandr Dragukin), expanded free product line, 
and much more. For details, see What's New in Wing Version 6 
.


Wing 6 works with Python versions 2.5 through 2.7 and 3.2 through 3.7, 
including also Anaconda, ActivePython, EPD, Stackless, and others 
derived from the CPython implementation.


For more product information, please visit wingware.com 



Upgrading

You can try Wing 6 without removing older versions. Wing 6 will read and 
convert your old preferences, settings, and projects. Projects should be 
saved to a new name since previous versions of Wing cannot read Wing 6 
projects.


See also Migrating from Older Versions 
 and Upgrading 
.


Links

Release notice: https://wingware.com/news/2018-05-15
Downloads and Free Trial: https://wingware.com/downloads
Buy: https://wingware.com/store/purchase
Upgrade: https://wingware.com/store/upgrade

Questions?  Don't hesitate to email us at supp...@wingware.com.

Thanks,

--

Stephan Deibel
Wingware | Python IDE

The Intelligent Development Environment for Python Programmers

wingware.com

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


logging date format with milliseconds and timezone

2018-05-17 Thread Skip Montanaro
It seems that the logging.Formatter class uses two formats by default to
format a time, default_time_format (%Y-%m-%d %H:%M:%S) and
default_msec_format (%s,%03d). The former is a format string for
time.strftime (and thus can't represent fractions of a second). The latter
accomplishes that, but expanding %s with the output of (I believe)
time.strftime and %03d with the milliseconds in the current time. Users can
pass a datefmt arg to logging.basicConfig, or override the aforementioned
default_*_format attributes. Is there some way to format the timestamp with
both fractions of a second and timezone in a way similar to
datetime.strftime? In particular, I'd be happy with this format:
%Y-%m-%dT%H:%M:%S.%f%z. Maybe there is some magic flag to tell the system
I'm want to use datetime.strftime instead of time.strftime?

Thx,

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


Aw: Re: why does list's .remove() does not return an object?

2018-05-17 Thread Karsten Hilbert
> On 5/17/18 11:57 AM, Abdur-Rahmaan Janhangeer wrote:
> > x = [0,1]
> > x.remove(0)
> > new_list = x
> >
> > instead i want in one go
> >
> > x = [0,1]
> > new_list = x.remove(0) # here a way for it to return the modified list by
> > adding a .return() maybe ?
> 
> There isn't a way to do that in one line.

   new_list = list(x.remove(0))
   new_list = x.remove(0)[:]

?

No one said x can't be modified, only that new_list is
to contain the modified list after one line of code :)

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


Re: Re: why does list's .remove() does not return an object?

2018-05-17 Thread Ian Kelly
On Thu, May 17, 2018 at 3:27 PM, Karsten Hilbert
 wrote:
>> On 5/17/18 11:57 AM, Abdur-Rahmaan Janhangeer wrote:
>> > x = [0,1]
>> > x.remove(0)
>> > new_list = x
>> >
>> > instead i want in one go
>> >
>> > x = [0,1]
>> > new_list = x.remove(0) # here a way for it to return the modified list by
>> > adding a .return() maybe ?
>>
>> There isn't a way to do that in one line.
>
>new_list = list(x.remove(0))
>new_list = x.remove(0)[:]
>
> ?
>
> No one said x can't be modified, only that new_list is
> to contain the modified list after one line of code :)

Did you actually run either of those?
-- 
https://mail.python.org/mailman/listinfo/python-list


Aw: Re: why does list's .remove() does not return an object?

2018-05-17 Thread Karsten Hilbert
>new_list = list(x.remove(0))
>new_list = x.remove(0)[:]

Please disregard :)

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


file download using django and javascript

2018-05-17 Thread Xristos Xristoou


i have create a django app with REST JSON API and i fill html table in web page 
from my JSON.

here some examples

javascript snippets :

var field22=document.getElementById('f22');
field22.innerHTML=e.target.feature.properties.id;

var field23=document.getElementById('f23');
field23.innerHTML=e.target.feature.properties.file_1;

html :

 

  
  id :
  
   
   file :
  
   

i have parse my JSON in table with success but in the file field now i have a 
simple text from image path.

Now i want in this path to have some hyperlink(or button) for download this 
file.

any idea how to do this because i stack ?i dont know how to connection 
javasscript with my download or how to download this file using javascript

django app code

models.py:

class MyModel(models.Model):
file_1 = models.FileField(upload_to='documents/',blank=True, null=True)

simple test django donwload :

def download(request, id):
product_file=MyModel.objects.get(pk=id)
f = StringIO()
zip = zipfile.ZipFile(f, 'w')
product_file_url = product_file.file_1.url
file_url = settings.MEDIA_ROOT + product_file_url[6:]
filename = product_file_url[6:].split('/')[-1]
zip.write(file_url,filename)
zip.close()
response = HttpResponse(f.getvalue(), content_type="application/zip")
response['Content-Disposition'] = 'attachment; filename=file-download.zip'
return response

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


Re: syntax oddities

2018-05-17 Thread Chris Angelico
On Fri, May 18, 2018 at 8:31 AM, Dennis Lee Bieber
 wrote:
> On Thu, 17 May 2018 07:18:32 -0700, Tobiah  declaimed the
> following:
>
>>Top posting is awesome for the reader plowing through
>>a thread in order.  In that case the cruft at the bottom
>>is only for occasional reference.
>>
>
> That concept is meaningful only email between two parties, where the
> quoted material is a "courtesy copy" for content the other party likely
> provided a week earlier (snail mail).

And I'm not sure it's of value there either. If I emailed someone a
week ago and s/he responds today, proper quote trimming is of great
value, just as it is with newsgroups/mailing lists. The only time it
wouldn't much matter is if we're going back and forth with extreme
rapidity, and then you may as well bottom-post because it makes little
difference.

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


Re: syntax oddities

2018-05-17 Thread Paul
>
>
> That concept is meaningful only email between two parties, where
> the
> quoted material is a "courtesy copy" for content the other party likely
> provided a week earlier (snail mail).
>
> But mailing lists/newsgroups are the equivalent of a bulletin board
> open to anyone walking past. Bottom posting (or better, trim and
> intersperse) allows someone who has no prior knowledge of the message chain
> to read it from top-down, picking up the relevant points as they go...
> Rather than having to flip through a stack of pages looking for information
> being referenced by the top-most sheet of paper.
>
>
> --
> Wulfraed Dennis Lee Bieber


I've been using email for thirty years, including thousands of group emails
at many tech companies, and no one has ever suggested, let alone insisted
on, bottom posting.  If someone's late to a thread they can read from it
the bottom up. But, for everyone who has been  keeping up, not having to
scroll is a big advantage.
   I'm not suggesting that the convention on this list be changed, but it's
by no means the only option which makes sense.
  Paul C.

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


Re: syntax oddities

2018-05-17 Thread Chris Angelico
On Fri, May 18, 2018 at 8:44 AM, Paul  wrote:
>>
>>
>> That concept is meaningful only email between two parties, where
>> the
>> quoted material is a "courtesy copy" for content the other party likely
>> provided a week earlier (snail mail).
>>
>> But mailing lists/newsgroups are the equivalent of a bulletin board
>> open to anyone walking past. Bottom posting (or better, trim and
>> intersperse) allows someone who has no prior knowledge of the message chain
>> to read it from top-down, picking up the relevant points as they go...
>> Rather than having to flip through a stack of pages looking for information
>> being referenced by the top-most sheet of paper.
>>
>>
>> --
>> Wulfraed Dennis Lee Bieber
>
>
> I've been using email for thirty years, including thousands of group emails
> at many tech companies, and no one has ever suggested, let alone insisted
> on, bottom posting.  If someone's late to a thread they can read from it
> the bottom up.

Remind me which direction text is usually written in English?

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


Re: object types, mutable or not?

2018-05-17 Thread Mike McClain
On Thu, May 17, 2018 at 07:28:44PM +1000, Chris Angelico wrote:
> On Thu, May 17, 2018 at 7:16 PM, Anders Wegge Keller  wrote:
> > P?? Wed, 16 May 2018 14:48:27 +0100
> > Paul Moore  skrev:
> >
> >> C++ called that an "rvalue". And then went on to define things that
> >> could go on the left hand side of an assignment as "lvalues". And now
> >> we have two confusing concepts to explain - see what happens when you
> >> let a standards committee define your language? :-)
> >
> >  I'm not sure the C++ committee has to bear the responsibility for those
> > terms. They are pretty well defined in the C world, so I think you need to
> > point the finger of accusation at either Brian or Dennis.
> >
>
> Let's be fair and blame one of them for each.
>

Let's be fair and make that accolades.
We stand on their shoulders.

I like telling a computer what to do.
Don't you?

Enjoy,
Mike
--
Once you can accept the universe as matter expanding into nothing
that is something, wearing stripes with plaid comes easy.
- Albert Einstein
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: syntax oddities

2018-05-17 Thread Steven D'Aprano
On Fri, 18 May 2018 08:38:31 +1000, Chris Angelico wrote:

> On Fri, May 18, 2018 at 8:31 AM, Dennis Lee Bieber
>  wrote:
>> On Thu, 17 May 2018 07:18:32 -0700, Tobiah  declaimed
>> the following:
>>
>>>Top posting is awesome for the reader plowing through a thread in
>>>order.  In that case the cruft at the bottom is only for occasional
>>>reference.
>>>
>>>
>> That concept is meaningful only email between two parties,
>> where the
>> quoted material is a "courtesy copy" for content the other party likely
>> provided a week earlier (snail mail).
> 
> And I'm not sure it's of value there either. If I emailed someone a week
> ago and s/he responds today, proper quote trimming is of great value,
> just as it is with newsgroups/mailing lists. The only time it wouldn't
> much matter is if we're going back and forth with extreme rapidity, and
> then you may as well bottom-post because it makes little difference.

Bottom-posting is infinitely more evil than top-posting.

The next time I have to scroll past fifteen pages of quoted text twelve 
layers deep, only to read "Me too!!!1!" or "LOL!!!" as the sole addition 
to the conversation, I'm going to go all Jack Nicholson in The Shining.

What we want is *inline* posting, which follows the *trimmed* posting. If 
there happens to be only a single quoted section left untrimmed (as in 
this email) it may superficially look like bottom-posting, but it isn't.

Top-posting is good for real-time rapid-fire conversations between two 
parties where the context is self-evident and you will never, ever need 
to look through the archives again.

But bottom-posting without trimming combines the worst of both strategies.


-- 
Steve

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


Re: what does := means simply?

2018-05-17 Thread bartc

On 17/05/2018 18:19, Steven D'Aprano wrote:

On Thu, 17 May 2018 15:50:17 +0100, bartc wrote:



Of course, full-on Python code is pretty much impossible to port
anywhere else anyway.


*rolls eyes*



Any pair of languages will have code that is hard to port from one to the
other without jumping through hoops. Try porting C code with lots of
dynamic memory allocations and pointer accesses to COBOL, or Scheme code
using continuations to Python, or Hyperscript text chunking code to
Fortran.

But hard does not mean "pretty much impossible".



Normally you'd use the source code as a start point. In the case of 
Python, that means Python source code. But you will quickly run into 
problems because you will often see 'import lib' and be unable to find 
lib.py anywhere.


That's one problem. Others might involve how to deal with something like 
__globals__ which doesn't have an equivalent in the target language. And 
we haven't started on features that are specific to Python.


But most non-esoteric languages will have functions, variables, 
assignments, expressions, loops and so on. The basics. Algorithms 
expressed using those will be simplest to port.


When I was looking at benchmarks involving multiple languages and wanted 
to port one to a new language, I usually ended up working from Pascal or 
Lua because they tended not to use advanced features that made the job 
harder.


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


Re: what does := means simply?

2018-05-17 Thread Steven D'Aprano
On Fri, 18 May 2018 02:17:39 +0100, bartc wrote:

> Normally you'd use the source code as a start point. In the case of
> Python, that means Python source code. But you will quickly run into
> problems because you will often see 'import lib' and be unable to find
> lib.py anywhere.

Seriously? There's a finite number of file extensions to look for:

.py .pyc .pyo .pyw .dll .so

pretty much is the lot, except on some obscure platforms which few people 
use.

To successful port anything but the most trivial code, you actually have 
to understand *both* languages -- including the syntax, semantics, built-
in language features, AND libraries.


> That's one problem. Others might involve how to deal with something like
> __globals__ which doesn't have an equivalent in the target language. And
> we haven't started on features that are specific to Python.

How about features which are specific to C, or Scheme, or Forth, or APL, 
or bash, or Fortran, or Intercal, or Java, or Javascript, or Ruby, or 
Smalltalk, or Rust, or Go, or any of hundreds of other languages?

Since every language has features that some other languages don't have, 
is it your position that it is impossible to port code from any language 
to any other?

If you want to *really* see code that is hard to port, you should try 
porting an Inform 7 program to another language. Any other language.



-- 
Steve

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


Re: why does list's .remove() does not return an object?

2018-05-17 Thread Abdur-Rahmaan Janhangeer
ah there's no return question then

that precisely returned the discussion to the first answer

Abdur-Rahmaan Janhangeer
https://github.com/Abdur-rahmaanJ

On Thu, 17 May 2018, 23:35 Tobiah,  wrote:

> On 05/17/2018 09:25 AM, Ned Batchelder wrote:
> > On 5/17/18 11:57 AM, Abdur-Rahmaan Janhangeer wrote:
> >> x = [0,1]
> >> x.remove(0)
> >> new_list = x
>
> Just call the original list 'new_list' to begin with.
>
>new_list = [0, 1]
>new_list.remove(0)
>
>
> There you are!
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what does := means simply?

2018-05-17 Thread Ian Kelly
On Thu, May 17, 2018, 7:50 PM Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:

>
> If you want to *really* see code that is hard to port, you should try
> porting an Inform 7 program to another language. Any other language.
>

How about Z-code?

*ducks*

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


Re: what does := means simply?

2018-05-17 Thread Ben Finney
Steven D'Aprano  writes:

> If you want to *really* see code that is hard to port, you should try
> porting an Inform 7 program to another language. Any other language.

Does porting Inform 7 code to Inform 6 count? They are very different
languages :-)

-- 
 \  “Puritanism: The haunting fear that someone, somewhere, may be |
  `\ happy.” —Henry L. Mencken |
_o__)  |
Ben Finney

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


Re: what does := means simply?

2018-05-17 Thread Bob van der Poel
On Thu, May 17, 2018, 8:45 PM Ben Finney, 
wrote:

> Steven D'Aprano  writes:
>
> > If you want to *really* see code that is hard to port, you should try
> > porting an Inform 7 program to another language. Any other language.
>
> Does porting Inform 7 code to Inform 6 count? They are very different
> languages :-)
>
>
My least favorite remains APL.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request for comments: use-cases for delayed evaluation

2018-05-17 Thread dieter
Steven D'Aprano  writes:

> Suppose Python had a mechanism to delay the evaluation of expressions 
> until needed. What would you use it for?

Delayed evaluation is some form of "lazy evaluation": evaluate an
expression (only) at the time, it is needed (maybe for the first time).

The avocates of "lazy evaluation" bring forward that it gives you
a convenient new modularization facility: you can separate the description
for the construction of (potentially huge or even infinite) data structures
from the algorithms operating on those structures. The "lazy evaluation"
ensures that the structure is "unfolded" only so far as a concrete
algorithm requires it.

An example could be a game. Lazy evaluation would allow to describe
once and for all how to compute the tree of game states reachable from
a given game state (usually a huge, maybe even an infinite tree).
Various algorithms for the selection of the next game move could
all work on tree (and would be some form of tree search).

With lazy evaluation, Python might become more attractive in
areas where conceptually huge data structures can be involved: games,
articial intelligence, proving systems, ...

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


Re: Package DLL or SO in wheel

2018-05-17 Thread dieter
Chris Nyland  writes:
> We have several internal modules we have developed that are used mostly to
> read different types of data files. Most of the time the different data
> file formats come with some sort of DLL or SO files that gives a standard
> interface to read the files. Our design pattern is to create a python
> library that uses ctypes to interface with the shared library.
>
> To be clear we are not building the shared libraries these are usually
> provided by another group or distributed by a  third party.
>
> So the issue is I want to bundle these share libraries with the module into
> a wheel or sdist package to server off our local PyPiServer.

I am not yet familiar with the newer "wheel" concept but
with "older" technology you could approach it as follows.

I am using "setuptools", thus I use this for the presentation below.
But "setuptools" is based on the standard "distutils" package
and this has the same facilities.

With "setuptools", you describe how to handle (especially install)
a distribution by providing describing arguments to a "setup"
function. The "ext_modules" parameter is responsible to
describe extensions, i.e. things corresponding to shared objects/DLLs.
The value of "ext_modules" is a sequence of "setuptools.Extension"
instances.

The standard "setuptools.Extension" class can handle C/C++
compilation (and various other generation types). It
supports standard parameters decribing sources, macros, includes,
libraries -- things typically involved in C/C++ compilation).
For your case, you would need your own "Extension" class: as
source it would use the precreated shared object[s]; as additional
parameter, it would have the target platform supported by those
shared object[s]. On installation, it would check for platform compatibility
and then put the shared object[s] at the correct place.

If I would need to implement such an "Extension" class, I would
look at the implementation of "setuptools.Extension" (likely,
I would also have to look at its base "distutils.Extension")
and derive my "Extention" by simplification (the shared object[s]
are already build and available; they need just get installed).


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


Re: syntax oddities

2018-05-17 Thread Lele Gaifax
Chris Angelico  writes:

> Remind me which direction text is usually written in English?

This applies to italian as well, accordingly to one my signatures, that
roughly corresponds to the following:

  Because it is contrary to the normal sense of reading
  > What's wrong with top-posting?
  >> The answers that precede the questions
  >>> What's the most boring thing in e-mails?

:-)

ciao, lele.
-- 
nickname: Lele Gaifax | Perché è contrario al normale senso di lettura
real: Emanuele Gaifas | > Cosa c'è di male nel rispondere in cima?
l...@metapensiero.it  | >> Le risposte che precedono le domande
  | >>> Qual'è la cosa più noiosa nelle e-mail?

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