Re: Python app on a Mac

2022-04-15 Thread Dan Stromberg
On Fri, Apr 15, 2022 at 11:43 AM Alan Gauld  wrote:

> I've just migrated from a Linux PC to a Mac mini running Monterey.
>
I'm using a Mac for work lately.  I miss Linux.  I feel like MacOS isn't
nearly as good at multimonitor setups as Cinnamon.

Does anyone know how to launch a Python program from the
> desktop without a Terminal window (or at least with an
> iconified one!) Does it require Applescript or somesuch?
>

You could try appify:
https://stromberg.dnsalias.org/~strombrg/mactools/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python app on a Mac

2022-04-15 Thread Greg Ewing

On 15/04/22 10:51 pm, Alan Gauld wrote:

Does anyone know how to launch a Python program from the
desktop without a Terminal window (or at least with an
iconified one!) Does it require Applescript or somesuch?


The easiest and most reliable way is probably to use Automator
with a Run Shell Script action, and save it as type Application.

The command should be something like

/path/to/desired/python /path/to/my/python_file.py

Note that the current directory will probably be the user's home
directory, so it's best to use full pathnames for everything.

--
Greg



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


Re: Python app on a Mac

2022-04-15 Thread Alan Gauld


On 15/04/2022 19:53, MRAB wrote:

>> When I start the program I get a Terminal window as well
>> as the GUI. On Windows I'd run it with pythonw and in Linux
>> ...
>> Does anyone know how to launch a Python program from the
>> desktop without a Terminal window (or at least with an
>> iconified one!) Does it require Applescript or somesuch?
>>
> There's an answer here:
>
> https://stackoverflow.com/questions/50792048/running-a-python-script-without-opening-terminal

Yes, I've already done all that. The script runs and the GUI
displays but so does a Terminal in the background. The SO answer
does mention you can get the Terminal to close when the
script terminates whhich would be better than now. However,
another answer mentions something called Automator, which
I'll need to Google...

Thanks for the pointer though.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos

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


Re: No shortcut Icon on Desktop

2022-04-15 Thread Mirko via Python-list
Am 15.04.2022 um 18:53 schrieb Mats Wichmann:
> On 4/15/22 08:59, Grant Edwards wrote:
> 
>> Of course it's easy to add. But, we're talking about people who have
>> no idea how to do that. They have no clue how to "navigate to the
>> install directory". They don't even realize anything _was_ installed.
> 
> 
> I dunno, it's a pretty WIndows-y thing, 
> But anyway...

Yes, it is a pretty "Windows-y thing". How do Windows software
installers work? What do they do? They add shortcuts to the desktop.
 I do not use Windows for myself since many years, but it is hard
for me to remember any software that did not add those shortcuts.

> right-click + create shortcut.

Right-click on what and where? On something called "IDLE" (has what
to do with python?). Right click on "python.exe" which gives some
wired texty DOS-window (or how that thing is called) where one can
do what?

Don't get me wrong. I do not ask those questions. Myself, I'm
perfectly able to compile Python from source on pretty much any
system you throw me at. But we are talking about people who are new
to programming.

AFAIK, almost every Windows tool/application/utility does add those
desktop shortcuts/icons/links. Newcomers expect, want and need some
editor or IDE or "app". Just put a "Python" folder on the desktop
with an "IDLE Python Editor" on the desktop and done.

How hard is it do add that functionality to the Windows installer?
Because I just can't see any reason not to do it.

What is there to lose in trying/doing that? What dire consequences
does that might have?

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


Re: No shortcut Icon on Desktop

2022-04-15 Thread Grant Edwards
On 2022-04-15, Mats Wichmann  wrote:

> I'd add - not naming the installer something Windows' memory of recent
> files retains as being Python itself - could be as simple as including
> the word "setup" in the name.

Oh yes, that's been suggested many, many times also. :)

I always name all my installers something that ends in -setup.exe or
-setup.ini. I always used to build .exe installers, but have more
recently been trending towards .ini's.

But the end of the basename alway ends in -setup.

--
Grant



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


Re: Proposal: Syntax for attribute initialisation in __init__ methods

2022-04-15 Thread Ethan Furman

On 4/15/22 04:19, Sam Ezeh wrote:

Elsewhere, the idea of supporting new syntax to automatically initialise
attributes provided as arguments to __init__ methods was raised.


[...]

Good post!  You'll want to send this to python-ideas at some point (that's where most new python features are 
discussed).  This particular desire has come up in the past, so you'll need to do some more research (i.e. find the 
previous threads on python-ideas) so you can answer objections already raised, or find new data supporting/refuting 
previous arguments.


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


Re: Proposal: Syntax for attribute initialisation in __init__ methods

2022-04-15 Thread dn
On 15/04/2022 23.19, Sam Ezeh wrote:
...

Kudos for doing the research!


> Some related implementations are attrs, dataclasses and the use of a
> decorator. And there's potentially a point to be raised that the results
> from the first query indicate that the @dataclasse decorator is not being
> used enough. One advantage this proposal offers is control over the
> arguments that the __init__ function takes.
> 
> A downside to using a decorator is that it might become difficult to accept
> arguments that don't need to be assigned to anything.
> 
> I gave the example of the following code (unlike the above, this is not
> taken from existing python source code). In this example, a decorator can't
> assign all of the arguments to attributes or else it would produce code
> that does something different.
...


I will support anything which reduces 'boiler-plate' or 'make busy' work!

Perhaps I'm missing the point, but what functionality or advantage(s)
does this give, over data-classes?

Maybe Dataclasses are not being used as much as one might hope, but they
are relatively new, and many Python-Masters simply carry-on constructing
classes the way they have for years...

If data-classes give the impression of being 'syntactic sugar', there's
no particular need to use them - and certainly no rule or demand.

There are constructs where one might find it easier not to use them.

@dataclass does allow init=False.

There is an argument which says that all data-attributes should be
'created' inside an __init__() or __post_init__(), rather than
'somewhere', 'later'.
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: code confusion

2022-04-15 Thread Avi Gross via Python-list

As usual, without very clear and precise instructions and parameters, the 
answers may not quite fit.
It looks like you are asked two and only two questions.
The first is asking how many numbers you want. 
Before continuing, you need to make sure that is a valid number as many answer 
will throw an exception.
The next line, complex as it is, asks for one long answer and does not check 
anything and breaks rapidly unless you use just normal integer representation. 
Yes, it ignores any entry after the "i"th but if you want valid entries, you 
might want to evaluate them in a loop perhaps one at a time and keep going till 
you have 'i" valid ones.
I do suggest you not use the variable name of "i" for many reasons as modern 
languages allow more meaningful names like, well, "n"!
I understand using i, j, k in some nested loops but here I would haveused 
something like howMany and verified the number was an integer larger than 0.
As for getting the second largest number, there is nothing wrong with 
determining it the hard way. Of course for some people, it is more intuitive to 
sort the uniqued data and simply choose the 2nd entry from the end. Some python 
modules allow you tosee the ranks of various entries and you can simply choose 
the one of second rank. 
But if this is HW, you are being asked to do things the old-fashioned way! LOL!



-Original Message-
From: Dennis Lee Bieber 
To: python-list@python.org
Sent: Fri, Apr 15, 2022 2:31 pm
Subject: Re: code confusion

On Fri, 15 Apr 2022 08:41:20 +0100, Tola Oj 
declaimed the following:

>i = int(input())

    Obtain a single /integer/ from stdin -- note: any extraneous characters
on the input line will result in a failure to convert from textual
representation to internal/binary integer

>lis = list(map(int,input().strip().split()))[:i]

    Obtain a line from stdin containing space separated /integer/
representations. Split the line at the spaces. Convert each "word" to
internal/binary integer. Keep up to at most "i" integers. Note that the
position of the [:i] could be at 
            ... .split()[:i]
The difference being that the provided code is converting all "words" on
the input into integers and then keeping the first "i"; putting the [:i]
after .split() means only the first "i" words are kept, and hence only that
many need to be converted to integer.

>z = max(lis)

    Determine largest value in the list of integers

>while max(lis) == z:
>lis.remove(max(lis))

    WHILE the largest value in the (current) list matches the initially
determined maximum value... remove that value from the list.

    Rather than repeat "max(lis)" in the .remove() invocation, just pass it
"z" (the WHILE has already confirmed that the maximum "z" is found in the
list, so why recompute the maximum).

    Note: Python indentation is significant -- the above .remove() line
needs to be indented. Presuming your code was properly indented please find
a posting client that doesn't reformat leading indentation.

>
>print (max(lis))
>

    Display the new list maximum value after removing all instances of the
initial maximum value.

>this is an answer to a question from the discussion chat in hackerrank. i
>didn't know the answer so i found an answer that fitted well to the
>question, however i struggle to understand the use of some of the methods
>and functions the person has used. my major questions are: 1. what does
>"[:i]" mean

    Learn the contents of the Library Reference Manual -- you don't need to
memorize it all, but should at least know the major groupings...

https://docs.python.org/3/library/stdtypes.html#common-sequence-operations


>                                                        2. is there
>another i could write this code using if statement?

    There are many ways to rewrite that...

UNTESTED

i = int(input("How many integers are to be considered?"))
ls = [int(wd) for wd in input(
                "enter space separated integers"
                ).split()[:i]]
maximum = max(ls)
while maximum in ls:
    ls.remove(maximum)
print(ls)

    Remove the first line, and the [:i], and the code will happily process
for however many integers are provided on the input line.

    The while/remove loop can be replaced with

ls = [itm for itm in ls if itm != maximum]

which only requires one pass through the list; while/remove has to scan the
list to see if maximum is in it, then has to scan it a second time to for
the .remove() to find where in the list it is found.

    Or...

for _ in range(ls.count(maximum)):
    ls.remove(maximum)

where _ is a "junk/temp" value that we don't care about -- we only want to
loop once for EACH maximum value

    Or...

while maximum in ls:
    del ls[ls.index(maximum)]



-- 
    Wulfraed                Dennis Lee Bieber        AF6VN
    wlfr...@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: is there somebody that have experince with python and canopen

2022-04-15 Thread alister via Python-list
On Fri, 15 Apr 2022 10:18:33 -0700 (PDT), luca72.b...@gmail.com wrote:

> We are searching for someone that can develop a python program for use
> servomotor for automotive.

What location & what is the salary?
(although based on the method of recruitment I doubt that you will get 
many takers)



-- 
MS and Y2K: Windows 95, 98, ... and back again to 01

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


Re: Functionality like local static in C

2022-04-15 Thread Chris Angelico
On Sat, 16 Apr 2022 at 04:51, Python  wrote:
>
> Cecil Westerhof wrote:
> > In C when you declare a variable static in a function, the variable
> > retains its value between function calls.
> > The first time the function is called it has the default value (0 for
> > an int).
> > But when the function changes the value in a call (for example to 43),
> > the next time the function is called the variable does not have the
> > default value, but the value it had when the function returned.
> > Does python has something like that?
>
> Sort of, one way is to have a argument with a default value
> which is mutable. Hint: don't do that.
>

Why do you anonymously suggest a thing and also suggest not doing it?
The default argument technique has been mentioned already as a
perfectly valid way to do this.

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


Re: Python app on a Mac

2022-04-15 Thread MRAB

On 2022-04-15 11:51, Alan Gauld wrote:

I've just migrated from a Linux PC to a Mac mini running Monterey.

I have a Python GUI(Tkinter) app that I wrote on Linux
and have managed to get working on MacOS except

When I start the program I get a Terminal window as well
as the GUI. On Windows I'd run it with pythonw and in Linux
I just created a desktop launcher to avoid that. But there
is no pythonw on MacOS nor a simple way I can find to
launch apps from the desktop.

Does anyone know how to launch a Python program from the
desktop without a Terminal window (or at least with an
iconified one!) Does it require Applescript or somesuch?


There's an answer here:

https://stackoverflow.com/questions/50792048/running-a-python-script-without-opening-terminal
--
https://mail.python.org/mailman/listinfo/python-list


is there somebody that have experince with python and canopen

2022-04-15 Thread luca72.b...@gmail.com
We are searching for someone that can develop a python program for use 
servomotor for automotive.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functionality like local static in C

2022-04-15 Thread Python

Cecil Westerhof wrote:

In C when you declare a variable static in a function, the variable
retains its value between function calls.
The first time the function is called it has the default value (0 for
an int).
But when the function changes the value in a call (for example to 43),
the next time the function is called the variable does not have the
default value, but the value it had when the function returned.
Does python has something like that?


Sort of, one way is to have a argument with a default value
which is mutable. Hint: don't do that.


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


Re: code confusion

2022-04-15 Thread Dennis Lee Bieber
On Fri, 15 Apr 2022 08:41:20 +0100, Tola Oj 
declaimed the following:

>i = int(input())

Obtain a single /integer/ from stdin -- note: any extraneous characters
on the input line will result in a failure to convert from textual
representation to internal/binary integer

>lis = list(map(int,input().strip().split()))[:i]

Obtain a line from stdin containing space separated /integer/
representations. Split the line at the spaces. Convert each "word" to
internal/binary integer. Keep up to at most "i" integers. Note that the
position of the [:i] could be at 
... .split()[:i]
The difference being that the provided code is converting all "words" on
the input into integers and then keeping the first "i"; putting the [:i]
after .split() means only the first "i" words are kept, and hence only that
many need to be converted to integer.

>z = max(lis)

Determine largest value in the list of integers

>while max(lis) == z:
>lis.remove(max(lis))

WHILE the largest value in the (current) list matches the initially
determined maximum value... remove that value from the list.

Rather than repeat "max(lis)" in the .remove() invocation, just pass it
"z" (the WHILE has already confirmed that the maximum "z" is found in the
list, so why recompute the maximum).

Note: Python indentation is significant -- the above .remove() line
needs to be indented. Presuming your code was properly indented please find
a posting client that doesn't reformat leading indentation.

>
>print (max(lis))
>

Display the new list maximum value after removing all instances of the
initial maximum value.

>this is an answer to a question from the discussion chat in hackerrank. i
>didn't know the answer so i found an answer that fitted well to the
>question, however i struggle to understand the use of some of the methods
>and functions the person has used. my major questions are: 1. what does
>"[:i]" mean

Learn the contents of the Library Reference Manual -- you don't need to
memorize it all, but should at least know the major groupings...

https://docs.python.org/3/library/stdtypes.html#common-sequence-operations


> 2. is there
>another i could write this code using if statement?

There are many ways to rewrite that...

UNTESTED

i = int(input("How many integers are to be considered?"))
ls = [int(wd) for wd in input(
"enter space separated integers"
).split()[:i]]
maximum = max(ls)
while maximum in ls:
ls.remove(maximum)
print(ls)

Remove the first line, and the [:i], and the code will happily process
for however many integers are provided on the input line.

The while/remove loop can be replaced with

ls = [itm for itm in ls if itm != maximum]

which only requires one pass through the list; while/remove has to scan the
list to see if maximum is in it, then has to scan it a second time to for
the .remove() to find where in the list it is found.

Or...

for _ in range(ls.count(maximum)):
ls.remove(maximum)

where _ is a "junk/temp" value that we don't care about -- we only want to
loop once for EACH maximum value

Or...

while maximum in ls:
del ls[ls.index(maximum)]



-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Functionality like local static in C

2022-04-15 Thread Cecil Westerhof via Python-list
Thanks for the multiple answers. I was pleasantly surprised.
I have something to think about. :-D

In principle I selected a solution for the problem for which I asked
it, but I first have to finish some other stuff. I hope to find time
to implement it next week.

Everyone a good weekend and Eastern.

Cecil Westerhof  writes:
> In C when you declare a variable static in a function, the variable
> retains its value between function calls.
> The first time the function is called it has the default value (0 for
> an int).
> But when the function changes the value in a call (for example to 43),
> the next time the function is called the variable does not have the
> default value, but the value it had when the function returned.
> Does python has something like that?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: No shortcut Icon on Desktop

2022-04-15 Thread Christian Gollwitzer

Am 15.04.22 um 02:49 schrieb Mats Wichmann:

On 4/14/22 18:06, Grant Edwards wrote:

On 2022-04-14, Richard Damon  wrote:


I think the issue is that the 'python' interpreter/compiler isn't the
sort of program that makes sense to make a desktop icon for, as it is a
command line utility.


Yes, it is a command line utility. Why does that mean you shouldn't
have a desktop shortcut for it?

I start up a python REPL prompt in a terminal often enough that were I
a windows users, I would probably want a desktop shortcut for it.

It would at least let people know that something got installed and
show them what a Python is. If they don't want/use that shortcut, it's
trivial to delete it.


easy to add - it's a windows thing, not a python thing.  you can
navigate to the install directory and create a shortcut and drag that
out of that directiory in explorer and drop it on the desktop.  or you
can navigate through the start menu, and when you get to the thing you
want, pick open folder and then you can create a shortcut and drag off
to the desktop.


Yes, you *can* do that of course and it is not a Python thing - but the 
point is, that typical Windows installers create these shortcuts during 
the installation process for you - typically there is a pre-selected 
checkbox "Create desktop icons" or similar. I agree with Grant that this 
is what users expect from the installer.


Christian

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


Python app on a Mac

2022-04-15 Thread Alan Gauld
I've just migrated from a Linux PC to a Mac mini running Monterey.

I have a Python GUI(Tkinter) app that I wrote on Linux 
and have managed to get working on MacOS except

When I start the program I get a Terminal window as well
as the GUI. On Windows I'd run it with pythonw and in Linux
I just created a desktop launcher to avoid that. But there
is no pythonw on MacOS nor a simple way I can find to
launch apps from the desktop.

Does anyone know how to launch a Python program from the
desktop without a Terminal window (or at least with an
iconified one!) Does it require Applescript or somesuch?

Alan G.

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


Re: No shortcut Icon on Desktop

2022-04-15 Thread Mats Wichmann
On 4/15/22 08:59, Grant Edwards wrote:

> Of course it's easy to add. But, we're talking about people who have
> no idea how to do that. They have no clue how to "navigate to the
> install directory". They don't even realize anything _was_ installed.


I dunno, it's a pretty WIndows-y thing, right-click + create shortcut.
But anyway...

> The problem is that people run the installer, don't see a desktop
> icon, and think nothing has been installed. Or they think the
> installer "is python", and run it over and over again trying to "run
> Python". Then they post the exact same plea for help that has been
> posted coutless times.
> 
> If the installer, by default, created an IDLE desktop shortcut and a
> cmd.exe shortcut that ran Python, I believe it would eliminate most of
> those problems.

I'd add - not naming the installer something Windows' memory of recent
files retains as being Python itself - could be as simple as including
the word "setup" in the name.

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


Re: No shortcut Icon on Desktop

2022-04-15 Thread Grant Edwards
On 2022-04-15, Mats Wichmann  wrote:
> On 4/14/22 18:06, Grant Edwards wrote:
>> On 2022-04-14, Richard Damon  wrote:
>> 
>>> I think the issue is that the 'python' interpreter/compiler isn't the 
>>> sort of program that makes sense to make a desktop icon for, as it is a 
>>> command line utility.
>> 
>> Yes, it is a command line utility. Why does that mean you shouldn't
>> have a desktop shortcut for it?
>> 
>> I start up a python REPL prompt in a terminal often enough that were I
>> a windows users, I would probably want a desktop shortcut for it.
>> 
>> It would at least let people know that something got installed and
>> show them what a Python is. If they don't want/use that shortcut, it's
>> trivial to delete it.
>
> easy to add - it's a windows thing, not a python thing.  you can
> navigate to the install directory and create a shortcut and drag
> that out of that directiory in explorer and drop it on the desktop.

Of course it's easy to add. But, we're talking about people who have
no idea how to do that. They have no clue how to "navigate to the
install directory". They don't even realize anything _was_ installed.

The problem is that people run the installer, don't see a desktop
icon, and think nothing has been installed. Or they think the
installer "is python", and run it over and over again trying to "run
Python". Then they post the exact same plea for help that has been
posted coutless times.

If the installer, by default, created an IDLE desktop shortcut and a
cmd.exe shortcut that ran Python, I believe it would eliminate most of
those problems.

--
Grant



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


Proposal: Syntax for attribute initialisation in __init__ methods

2022-04-15 Thread Sam Ezeh
Elsewhere, the idea of supporting new syntax to automatically initialise
attributes provided as arguments to __init__ methods was raised.

Very often, __init__ functions will take arguments only to assign them as
attributes of self. This proposal would remove the need to additionally
write `self.argument = argument` when doing this.

I'm specifically looking at statements of the form `self.argument =
argument`.

I ran a query on the source code of the top 20 most downloaded PyPi
packages (source:
https://github.com/dignissimus/presearch/blob/master/queries/attribute_initialisation.py)
and found the following statistics. I found that 19% of classes that define
__init__ and have at least one argument that isn't `self` assign all of
those non-self arguments as attributes with the same name in the function
definition.
I also found that 33% of __init__ functions that have more than one
non-self argument assign at least one of their arguments as attributes with
the same name, that 27% of __init__ functions that have at least two
non-self arguments assign at least 2 of them as attributes with the same
name and that 28% of __init__ functions that had 3 or more non-self
arguments assigned at least 3 of their arguments as attributes with the
same name.

```
[sam@samtop]: ~/Documents/git/presearch>$ presearch -f
queries/attribute_initialisation.py sources/
Running queries...
Out of 1526 classes defining __init__, there were 290 (19.0%) classes whose
__init__ functions assigned all non-self arguments as attributes.
Out of 1526 __init__ functions with at least one non-self argument, there
were 497 (32.57%) __init__ functions that assigned one or more non-self
arguments as attributes.
Out of 834 __init__ functions with at least two non-self arguments, there
were 221 (26.5%) __init__ functions that assigned two or more non-self
arguments as attributes.
Out of 490 __init__ functions with at least three non-self arguments, there
were 139 (28.37%) __init__ functions that assigned three or more non-self
arguments as attributes.
[sam@samtop]: ~/Documents/git/presearch>$

```

With the new syntax, the following snippet taking from the pyyaml source
code (pyyaml is the 12th most downloaded package this month on PyPi)

```
def __init__(self, default_style=None, default_flow_style=False,
sort_keys=True):
self.default_style = default_style
self.sort_keys = sort_keys
self.default_flow_style = default_flow_style
self.represented_objects = {}
self.object_keeper = []
self.alias_key = None
```

Can be re-written as follows

```
def __init__(self, @default_style=None, @default_flow_style=False,
@sort_keys=True):
self.represented_objects = {}
self.object_keeper = []
self.alias_key = None
```

And from numpy, the following code

```
def __init__(self, mbfunc, fillx=0, filly=0):
"""
abfunc(fillx, filly) must be defined.

abfunc(x, filly) = x for all x to enable reduce.

"""
super().__init__(mbfunc)
self.fillx = fillx
self.filly = filly
ufunc_domain[mbfunc] = None
ufunc_fills[mbfunc] = (fillx, filly)
```

Can be written like this

```
def __init__(self, mbfunc, @fillx=0, @filly=0):
"""
abfunc(fillx, filly) must be defined.

abfunc(x, filly) = x for all x to enable reduce.

"""
super().__init__(mbfunc)
ufunc_domain[mbfunc] = None
ufunc_fills[mbfunc] = (fillx, filly)
```

Some related implementations are attrs, dataclasses and the use of a
decorator. And there's potentially a point to be raised that the results
from the first query indicate that the @dataclasse decorator is not being
used enough. One advantage this proposal offers is control over the
arguments that the __init__ function takes.

A downside to using a decorator is that it might become difficult to accept
arguments that don't need to be assigned to anything.

I gave the example of the following code (unlike the above, this is not
taken from existing python source code). In this example, a decorator can't
assign all of the arguments to attributes or else it would produce code
that does something different.

```
class ExampleClass:
def __init__(self, example, argument, word):
self.example = example
self.argument = argument
do_something(word)
```

In response, the following was given

```
class ExampleClass:
@make_attr("example")
@make_attr("argument")
def __init__(self, example, argument, word):
do_something(word)
```

And this could potentially be written like this

```
class ExampleClass:
@make_attr("example", "argument")
def __init__(self, example, argument, word):
do_something(word)
```

However, having to rewrite the argument name might defeat the purpose of
having a decorator.

As an idea, I thought about the case of when an __init__ method only
contains arguments that will become attributes. From the cryptography
library, there's the following 

Re: code confusion

2022-04-15 Thread dn
On 15/04/2022 19.41, Tola Oj wrote:
> i = int(input())
> lis = list(map(int,input().strip().split()))[:i]
> z = max(lis)
> while max(lis) == z:
> lis.remove(max(lis))
> 
> print (max(lis))
> 
> this is an answer to a question from the discussion chat in hackerrank. i
> didn't know the answer so i found an answer that fitted well to the
> question, however i struggle to understand the use of some of the methods
> and functions the person has used. my major questions are: 1. what does
> "[:i]" mean
>  2. is there
> another i could write this code using if statement?
> thank you


It is taking a slice from the list:
https://docs.python.org/3/glossary.html#term-slice

More explanation:
https://docs.python.org/3/tutorial/introduction.html?highlight=slice

-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: code confusion

2022-04-15 Thread Chris Angelico
On Fri, 15 Apr 2022 at 17:42, Tola Oj  wrote:
>
> i = int(input())
> lis = list(map(int,input().strip().split()))[:i]
> z = max(lis)
> while max(lis) == z:
> lis.remove(max(lis))
>
> print (max(lis))
>
> this is an answer to a question from the discussion chat in hackerrank. i
> didn't know the answer so i found an answer that fitted well to the
> question, however i struggle to understand the use of some of the methods
> and functions the person has used. my major questions are: 1. what does
> "[:i]" mean
>  2. is there
> another i could write this code using if statement?

If you don't understand the code, don't submit it :) You should create
your own code for hackerrank.

I'll just give very very broad hints:

1) It's slicing. Play around with it in the interactive interpreter
and see what it does with different inputs.

2) Yes. You can always write code with an if statement. What are you
actually trying to accomplish though?

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


code confusion

2022-04-15 Thread Tola Oj
i = int(input())
lis = list(map(int,input().strip().split()))[:i]
z = max(lis)
while max(lis) == z:
lis.remove(max(lis))

print (max(lis))

this is an answer to a question from the discussion chat in hackerrank. i
didn't know the answer so i found an answer that fitted well to the
question, however i struggle to understand the use of some of the methods
and functions the person has used. my major questions are: 1. what does
"[:i]" mean
 2. is there
another i could write this code using if statement?
thank you
-- 
https://mail.python.org/mailman/listinfo/python-list