Re: When should I use "parent=None" in __ini__ and "parent" in super()

2022-09-01 Thread Randy Johnson
Those are contradictory for what you are trying to accomplish unless it is a 
Parent - Child relationship  (MainWindow - Window):

When you super() an object, it enherits all the properties from its parent 
object.

Source: 
https://www.w3schools.com/python/python_inheritance.asp

If what you want is 2 windows, you can define 2 instances of both Classes and 
run both at the end. 

```

class User1(object):
def __init__(self, fname, age, parent=None):
self.fname = fname
self.age = int(age)

# Calling the return function that prints the details
self.return_user()

def return_user(self):
print(self.fname)
print(self.age)


class User2(object):

def __init__(self, lname, height, parent=None):

self.lname = lname
self.height = float(height)
self.return_user()

def return_user(self):
print(self.lname)
print(self.height, "CM")
print((self.height / 2.54), "IN")


User1("Hugh", 21)
User2("Janus", 175.26)
```
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to make a variable's late binding crosses the module boundary?

2022-09-01 Thread Jach Feng
ery...@gmail.com 在 2022年9月2日 星期五凌晨12:41:46 [UTC+8] 的信中寫道:
> On 8/31/22, Jach Feng  wrote: 
> > 
> > I found that using "from test import *" in test2.py makes test2's relation 
> > to "test" almost like the function's relation to the module where it is 
> > defined. You can refer to all the variables of the module
> Note that in general, if __all__ doesn't exist to explicitly define 
> the contents of a star import, then it imports everything except names 
> that begin with an underscore.
Thank you for pointing out these important difference:-)

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


Re: Local variable definition in Python list comprehension

2022-09-01 Thread Avi Gross
Dumb question. Your y is purely a function of x. So create an f(x) where
you want your y. It probably can even be anonymous inline. I mean your
return values of (x, y) would be (x, f(x)) ...

On Thu, Sep 1, 2022, 5:04 PM Chris Angelico  wrote:

> On Fri, 2 Sept 2022 at 06:55, James Tsai  wrote:
> >
> > 在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> > > On 9/1/22, James Tsai  wrote:
> > > >
> > > > I find it very useful if I am allowed to define new local variables
> in a
> > > > list comprehension. For example, I wish to have something like
> > > > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> > > > [(x, y) for x in range(10) with y := x ** 2 if x + y < 80].
> > > >
> > > > For now this functionality can be achieved by writing
> > > > [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].
> > > You can assign a local variable in the `if` expression. For example:
> > >
> > > >>> [(x, y) for x in range(10) if x + (y := x**2) < 30]
> > > [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16)]
> >
> > Yeah this works great but like [(x, y) for x in range(10) for y in
> [x**2]] I written before, is kind of a hack. And if initially I do not need
> an "if" condition in the list comprehension, this becomes less convenient.
> I still can write
> > >>> [(x, y) for x in range(10) if (y := x**2) or True]
> >
> > But I wonder if Python could have a specific syntax to support this.
> >
>
> But why would you need to assign to y in that example? If you're using
> it more than once, you can use :=, and if you aren't, you don't need
> to. But do be aware that := does not create a comprehension-local name
> binding, but a nonlocal instead.
>
> > No but very often when I have written a neat list/dict/set
> comprehension, I find it very necessary
> > to define local variable(s) to make it more clear and concise. Otherwise
> I have to break it down
> > to several incrementally indented lines of for loops, if statements, and
> variable assignments,
> > which I think look less nice.
>
> Well, if it's outgrown a list comp, write it on multiple lines. Like I
> said, not everything has to be a one-liner.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-01 Thread Cameron Simpson
On 02Sep2022 07:01, Chris Angelico  wrote:
>On Fri, 2 Sept 2022 at 06:55, James Tsai  wrote:
>> No but very often when I have written a neat list/dict/set 
>> comprehension, I find it very necessary
>> to define local variable(s) to make it more clear and concise. Otherwise I 
>> have to break it down
>> to several incrementally indented lines of for loops, if statements, and 
>> variable assignments,
>> which I think look less nice.
>
>Well, if it's outgrown a list comp, write it on multiple lines. Like I
>said, not everything has to be a one-liner.

True, but a comprehension can be more expressive than a less 
"functional" expression (series of statements).

James, can you provide (a) a real world example where you needed to 
write a series of statements or loops and (b) a corresponding example of 
how you would have preferred to have written that code, possibly 
inventing some syntax or misusing ":=" as if it workeed they way you'd 
like it to work?

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


Re: Local variable definition in Python list comprehension

2022-09-01 Thread Peter J. Holzer
On 2022-09-01 13:33:16 -0700, James Tsai wrote:
> 在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> > On 9/1/22, James Tsai  wrote: 
> > > 
> > > I find it very useful if I am allowed to define new local variables in a 
> > > list comprehension. For example, I wish to have something like 
> > > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or 
> > > [(x, y) for x in range(10) with y := x ** 2 if x + y < 80]. 
> > > 
> > > For now this functionality can be achieved by writing 
> > > [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].
> > You can assign a local variable in the `if` expression. For example: 
> > 
> > >>> [(x, y) for x in range(10) if x + (y := x**2) < 30] 
> > [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16)]
> 
> Yeah this works great but like [(x, y) for x in range(10) for y in
> [x**2]] I written before, is kind of a hack. And if initially I do not
> need an "if" condition in the list comprehension, this becomes less
> convenient. I still can write 
> >>> [(x, y) for x in range(10) if (y := x**2) or True]

In that case 
[(x, x**2) for x in range(10)]
seems to be somewhat more readable.

I would also say that
[(x, x**2) for x in range(10) if x + x**2 < 80]
doesn't really seem worse than any of the variants with y in it.
(Yes, I get that your real duplicated expression is probably a bit more
complex than `x**2`, but by the time a temporary variable really
improves readability it's probably a good time to split that across
multiple lines, too.)

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-01 Thread Chris Angelico
On Fri, 2 Sept 2022 at 06:55, James Tsai  wrote:
>
> 在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> > On 9/1/22, James Tsai  wrote:
> > >
> > > I find it very useful if I am allowed to define new local variables in a
> > > list comprehension. For example, I wish to have something like
> > > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> > > [(x, y) for x in range(10) with y := x ** 2 if x + y < 80].
> > >
> > > For now this functionality can be achieved by writing
> > > [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].
> > You can assign a local variable in the `if` expression. For example:
> >
> > >>> [(x, y) for x in range(10) if x + (y := x**2) < 30]
> > [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16)]
>
> Yeah this works great but like [(x, y) for x in range(10) for y in [x**2]] I 
> written before, is kind of a hack. And if initially I do not need an "if" 
> condition in the list comprehension, this becomes less convenient. I still 
> can write
> >>> [(x, y) for x in range(10) if (y := x**2) or True]
>
> But I wonder if Python could have a specific syntax to support this.
>

But why would you need to assign to y in that example? If you're using
it more than once, you can use :=, and if you aren't, you don't need
to. But do be aware that := does not create a comprehension-local name
binding, but a nonlocal instead.

> No but very often when I have written a neat list/dict/set comprehension, I 
> find it very necessary
> to define local variable(s) to make it more clear and concise. Otherwise I 
> have to break it down
> to several incrementally indented lines of for loops, if statements, and 
> variable assignments,
> which I think look less nice.

Well, if it's outgrown a list comp, write it on multiple lines. Like I
said, not everything has to be a one-liner.

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


Re: Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
在 2022年9月1日星期四 UTC+2 18:16:03, 写道:
> On Fri, 2 Sept 2022 at 02:10, James Tsai  wrote: 
> > 
> > Hello, 
> > 
> > I find it very useful if I am allowed to define new local variables in a 
> > list comprehension. For example, I wish to have something like 
> > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or 
> > [(x, y) for x in range(10) with y := x ** 2 if x + y < 80]. 
> > 
> > For now this functionality can be achieved by writing 
> > [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80]. 
> > 
> > Is it worthwhile to add a new feature like this in Python? If so, how can I 
> > propose this to PEP?
> Not everything has to be a one-liner. 
> 
> ChrisA

No but very often when I have written a neat list/dict/set comprehension, I 
find it very necessary to define local variable(s) to make it more clear and 
concise. Otherwise I have to break it down to several incrementally indented 
lines of for loops, if statements, and variable assignments, which I think look 
less nice.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> On 9/1/22, James Tsai  wrote: 
> > 
> > I find it very useful if I am allowed to define new local variables in a 
> > list comprehension. For example, I wish to have something like 
> > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or 
> > [(x, y) for x in range(10) with y := x ** 2 if x + y < 80]. 
> > 
> > For now this functionality can be achieved by writing 
> > [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].
> You can assign a local variable in the `if` expression. For example: 
> 
> >>> [(x, y) for x in range(10) if x + (y := x**2) < 30] 
> [(0, 0), (1, 1), (2, 4), (3, 9), (4, 16)]

Yeah this works great but like [(x, y) for x in range(10) for y in [x**2]] I 
written before, is kind of a hack. And if initially I do not need an "if" 
condition in the list comprehension, this becomes less convenient. I still can 
write 
>>> [(x, y) for x in range(10) if (y := x**2) or True]

But I wonder if Python could have a specific syntax to support this.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
在 2022年9月1日星期四 UTC+2 16:15:17, 写道:
> James Tsai  writes: 
> 
> > I find it very useful if I am allowed to define new local variables in 
> > a list comprehension. For example, I wish to have something like 
> > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or 
> > [(x, y) for x in range(10) with y := x ** 2 if x + y < 80]. 
> > 
> > For now this functionality can be achieved by writing 
> > [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].
> x and y are, to a first approximation, new local variables defined in a 
> list comprehension. I think you need to restate what it is you want.
> > Is it worthwhile to add a new feature like this in Python? If so, how 
> > can I propose this to PEP?
> To make any sort of case you'd need to give an example that does not 
> have a clearer way to write it already. Your working version is, to me, 
> clearer that the ones you want to be able to write. 
> 
> -- 
> Ben.

By local variable definition I mean binding a variable to a single value, so it 
doesn't include giving an iterable that a variable can take values iteratively, 
e.g. 'for x in range(10)'. Does it not worth introducing a specific syntax to 
do this, instead of creating a new list ad hoc to define the variable like 'for 
y in [1]'?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to make a variable's late binding crosses the module boundary?

2022-09-01 Thread Eryk Sun
On 8/31/22, Jach Feng  wrote:
>
> I found that using "from test import *" in test2.py makes test2's relation
> to "test" almost like the function's relation to the module where it is
> defined. You can refer to all the variables of the module

Note that in general, if __all__ doesn't exist to explicitly define
the contents of a star import, then it imports everything except names
that begin with an underscore.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-01 Thread Eryk Sun
On 9/1/22, James Tsai  wrote:
>
> I find it very useful if I am allowed to define new local variables in a
> list comprehension. For example, I wish to have something like
> [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> [(x, y) for x in range(10) with y := x ** 2 if x + y < 80].
>
> For now this functionality can be achieved by writing
> [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].

You can assign a local variable in the `if` expression. For example:

>>> [(x, y) for x in range(10) if x + (y := x**2) < 30]
[(0, 0), (1, 1), (2, 4), (3, 9), (4, 16)]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Local variable definition in Python list comprehension

2022-09-01 Thread Chris Angelico
On Fri, 2 Sept 2022 at 02:10, James Tsai  wrote:
>
> Hello,
>
> I find it very useful if I am allowed to define new local variables in a list 
> comprehension. For example, I wish to have something like
> [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> [(x, y) for x in range(10) with y := x ** 2 if x + y < 80].
>
> For now this functionality can be achieved by writing
> [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].
>
> Is it worthwhile to add a new feature like this in Python? If so, how can I 
> propose this to PEP?

Not everything has to be a one-liner.

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


Re: Local variable definition in Python list comprehension

2022-09-01 Thread Ben Bacarisse
James Tsai  writes:

> I find it very useful if I am allowed to define new local variables in
> a list comprehension. For example, I wish to have something like
> [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> [(x, y) for x in range(10) with y := x ** 2 if x + y < 80].
>
> For now this functionality can be achieved by writing
> [(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].

x and y are, to a first approximation, new local variables defined in a
list comprehension.  I think you need to restate what it is you want.

> Is it worthwhile to add a new feature like this in Python? If so, how
> can I propose this to PEP?

To make any sort of case you'd need to give an example that does not
have a clearer way to write it already.  Your working version is, to me,
clearer that the ones you want to be able to write.

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


Re: How to make a variable's late binding crosses the module boundary?

2022-09-01 Thread Jach Feng
Mark Bourne 在 2022年9月1日 星期四凌晨2:43:40 [UTC+8] 的信中寫道:
> Jach Feng wrote: 
> > Mark Bourne 在 2022年8月29日 星期一下午6:40:59 [UTC+8] 的信中寫道: 
> >> Jach Feng wrote: 
> >>> Chris Angelico 在 2022年8月29日 星期一下午1:58:58 [UTC+8] 的信中寫道: 
>  On Mon, 29 Aug 2022 at 15:54, Jach Feng  wrote: 
> > 
> > Richard Damon 在 2022年8月29日 星期一上午10:47:08 [UTC+8] 的信中寫道: 
> >> On 8/27/22 7:42 AM, Mark Bourne wrote: 
> >>> Jach Feng wrote: 
>  I have two files: test.py and test2.py 
>  --test.py-- 
>  x = 2 
>  def foo(): 
>  print(x) 
>  foo() 
>  
>  x = 3 
>  foo() 
>  
>  --test2.py-- 
>  from test import * 
>  x = 4 
>  foo() 
>  
>  - 
>  Run test.py under Winows8.1, I get the expected result: 
>  e:\MyDocument>py test.py 
>  2 
>  3 
>  
>  But when run test2.py, the result is not my expected 2,3,4:-( 
>  e:\MyDocument>py test2.py 
>  2 
>  3 
>  3 
>  
>  What to do? 
> >>> 
> >>> `from test import *` does not link the names in `test2` to those in 
> >>> `test`. It just binds objects bound to names in `test` to the same 
> >>> names in `test2`. A bit like doing: 
> >>> 
> >>> import test 
> >>> x = test.x 
> >>> foo = test.foo 
> >>> del test 
> >>> 
> >>> Subsequently assigning a different object to `x` in one module does 
> >>> not affect the object assigned to `x` in the other module. So `x = 4` 
> >>> in `test2.py` does not affect the object assigned to `x` in `test.py` 
> >>> - that's still `3`. If you want to do that, you need to import `test` 
> >>> and assign to `test.x`, for example: 
> >>> 
> >>> import test 
> >>> test.x = 4 
> >>> test.foo() 
> >>> 
> >> Yes, fundamental issue is that the statement 
> >> 
> >> from x import y 
> >> 
> >> makes a binding in this module to the object CURRECTLY bound to x.y to 
> >> the name y, but if x.y gets rebound, this module does not track the 
> >> changes. 
> >> 
> >> You can mutate the object x.y and see the changes, but not rebind it. 
> >> 
> >> If you need to see rebindings, you can't use the "from x import y" 
> >> form, 
> >> or at a minimum do it as: 
> >> 
> >> 
> >> import x 
> >> 
> >> from x import y 
> >> 
> >> then later to get rebindings to x.y do a 
> >> 
> >> y = x.y 
> >> 
> >> to rebind to the current x.y object. 
> >> 
> >> -- 
> >> Richard Damon 
> > Yes, an extra "import x" will solve my problem too! Sometimes I am 
> > wondering why "from x import y" hides x? hum...can't figure out the 
> > reason:-) 
> > 
>  "from x import y" doesn't hide x - it just grabs y. Python does what 
>  you tell it to. :) 
>  
>  ChrisA 
> >>> But I had heard people say that "from x import y" did import the whole x 
> >>> module into memory, just as "import x" did, not "grabs y" only. Is this 
> >>> correct? 
> >> `from x import y` does import the whole module x into memory, and adds 
> >> it to `sys.modules`. But it only binds the name `y` in the namespace of 
> >> module doing the import (and it binds it to the value of `x.y` at the 
> >> time the import is done - it doesn't magically keep them in sync if one 
> >> or the other is later reassigned). 
> >> 
> >> The point about the whole module being imported is that you don't save 
> >> any memory by using `from x import y` to avoid importing some very large 
> >> object `z` from `x`. Those other large objects might be needed by 
> >> functions which have been imported (e.g. your `foo` function still needs 
> >> `x` even if you haven't imported `x` - so it still needs to be loaded 
> >> into memory) or might be imported and used by other modules importing 
> >> `x`, so they still have to be loaded when any part of `x` is imported - 
> >> they just don't have to be bound to names in the importing module's 
> >> namespace. 
> >> 
> >> As Richard mentioned, if `x.y` is a mutable object (such as a list) you 
> >> can still mutate that object (e.g. add/remove items) and those changes 
> >> will be seen in both modules. That's because both are still bound to 
> >> the same object and you're mutating that existing object. If you assign 
> >> a new list to either, that won't be seen by the other. 
> >> 
> >> -- 
> >> Mark. 
> > When using dot notation to change variable, no matter if 'x.y' is a mutable 
> > or immutable object, the change 
> > will be seen in both modules except those early bindings. 
> > 
> > --Jach
> Yes, sorry, I'd used `x.y` as a way of referring to the variable `y` in 
> module `x` as opposed to `y` in the current module. It doesn't help 
> that I added the second paragraph and didn't notice that the third was 
> then out of context. 
> 
> If you use `import x` and 

Local variable definition in Python list comprehension

2022-09-01 Thread James Tsai
Hello,

I find it very useful if I am allowed to define new local variables in a list 
comprehension. For example, I wish to have something like
[(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
[(x, y) for x in range(10) with y := x ** 2 if x + y < 80].

For now this functionality can be achieved by writing
[(x, y) for x in range(10) for y in [x ** 2] if x + y < 80].

Is it worthwhile to add a new feature like this in Python? If so, how can I 
propose this to PEP?
-- 
https://mail.python.org/mailman/listinfo/python-list


[Python-announce] ANN: pvlib-0.9.2 released

2022-09-01 Thread Dr. Mark Alexander Mikofski PhD
Dear Pythonistas and solar power enthusiasts,

The maintainers are happy to announce a new release of pvlib python:
software for simulating performance of photovoltaic solar energy systems.

*See what's new for v0.9.2:*
** *https://pvlib-python.readthedocs.io/en/stable/whatsnew.html

*Releases are available from PyPI and the conda-forge channel:*
* https://pypi.org/project/pvlib/
* https://anaconda.org/conda-forge/pvlib
* https://anaconda.org/conda-forge/pvlib-python

*Note: you can now install from conda-forge using either "pvlib" or
"pvlib-python"*

*Read the Documentation:*
* https://pvlib-python.readthedocs.io/en/stable/index.html

*Report issues & contribute:*
* https://github.com/pvlib/pvlib-python

*Highlights:*
* Albedo can be entered as a column in weather DataFrame when running a
model chain. This can be used to enter a time series instead of just
monthly values.
* A new function calc_surface_orientation() returns tracker surface tilt
and azimuth when given tracker rotation and axis tilt.
* There's a new example in the gallery to calculate backside irradiance
using pvfactors.
* Dropped support for Python-3.6 and increased required pandas to v0.25.0
* A new build system that conforms to PEP 517 & PEP518
* There were several new contributors.

*Thank you for using pvlib python!*

-- 
Mark Mikofski, PhD (2005)
*Fiat Lux*
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com