Re: A small quiz

2020-01-03 Thread Alan Bawden
[email protected] (Stefan Ram) writes:
...
>   So I was looking for a predefined object from the standard
>   library that already /is/ an iterator (with no need to use
>   »iter«).
> 
>   I found exactly one such object (which can be used after a
>   »from ... import ...« statement). Can you guess what it is?

Well, there's sys.stdin.  

But I would expect beginning students to find the effect of typing
"next(sys.stdin)" to the commnd prompt to be a bit confusing...

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


Re: A small quiz

2020-01-03 Thread Peter Otten
Alan Bawden wrote:

> [email protected] (Stefan Ram) writes:
> ...
>>   So I was looking for a predefined object from the standard
>>   library that already /is/ an iterator (with no need to use
>>   »iter«).
>> 
>>   I found exactly one such object (which can be used after a
>>   »from ... import ...« statement). Can you guess what it is?
> 
> Well, there's sys.stdin.
> 
> But I would expect beginning students to find the effect of typing
> "next(sys.stdin)" to the commnd prompt to be a bit confusing...
> 

There are a lot of itertools.count() objects, e. g.

>>> from multiprocessing.pool import job_counter
>>> next(job_counter)
0
>>> next(job_counter)
1


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


Re: Python, Be Bold!

2020-01-03 Thread Barry Scott



> On 3 Jan 2020, at 02:31, Abdur-Rahmaan Janhangeer  
> wrote:
> 
> 
> 
> On Fri, 3 Jan 2020, 02:50 Barry Scott,  > wrote:
> Expect for trivial programs you cannot distribute a single file python exe 
> for windows.
> 
> You can, PyInstaller does it. You can have folder-based or single file apps
> 
> As you found zipapp is not a solution.
> 
>  Zipapp is a good candidate. Proposing to improve it

I'm at a lose to understand what the problem is that zipapp is the solution to 
that is not better served
with pip or PyInstall etc.


> 
> 
> Many stdlib modules use DLL's on Windows and you cannot run a DLL from
> inside a zip file.
> 
> PyInstaller's -F mode does it well

Then use that are be happy.


> 
> But, this proposal is not about native executables. It's about a .jar like 
> executable. As a python-specific 'executable', os is not a problem unless of 
> course you are using like curses on windows

Barry

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


Re: A small quiz

2020-01-03 Thread Greg Ewing

On 4/01/20 5:41 am, Alan Bawden wrote:

   So I was looking for a predefined object from the standard
   library that already /is/ an iterator (with no need to use
   »iter«).


Why are you so intent on introducing either next() or iter() to
beginning students? I'd have thought they were somewhat advanced
topics, to be tackled after your students are familiar with the
basics.

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


Re: Python, Be Bold!

2020-01-03 Thread Greg Ewing

On 3/01/20 3:31 pm, Abdur-Rahmaan Janhangeer wrote:


But, this proposal is not about native executables. It's about a .jar like
executable. 


You can pass a zip file with a .pyz extension to the python
interpreter and it will look for a __main__.py file and run
it.

That seems to give you all the functionality of a jar --
including the limitations (e.g. you can't bundle extension
modules or native libraries that way).

Py2exe comes with zipextimporter, which purports to be able
to load .pyd files from zip archives, but I'm not aware of an
equivalent for other platforms.

Perhaps getting zipextimporter into the standard library,
and developing versions of it for Linux and MacOS, would be
a useful improvement?

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


Re: Python, Be Bold!

2020-01-03 Thread Abdur-Rahmaan Janhangeer
On Sat, 4 Jan 2020, 02:55 Greg Ewing,  wrote:

> On 3/01/20 3:31 pm, Abdur-Rahmaan Janhangeer wrote:
>
> You can pass a zip file with a .pyz extension to the python
> interpreter and it will look for a __main__.py file and run
> it.
>
> That seems to give you all the functionality of a jar --
> including the limitations (e.g. you can't bundle extension
> modules or native libraries that way).
>

.jar provides more than just compression. It provides app info and has
signing ability

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


Re: Python, Be Bold!

2020-01-03 Thread Abdur-Rahmaan Janhangeer
On Fri, 3 Jan 2020, 23:49 Barry Scott,  wrote:

>
> I'm at a lose to understand what the problem is that zipapp is the
> solution to that is not better served
> with pip or PyInstall etc.
>

Well proposing to enhance zipapp, by adding app metadata and signing. By
pip i understand you mean pure python distribution. Well, an enhanced
zipapp's advantage would be smaller codebase and easy injection detection
among others + the improving the ability to prevent reverse engineering for
those who want it.

Comparing to native executable well, one thing is program size. You must
have the interpreter on the machine but your program is lighter. 10 python
programs does not mean inclung 10× the interpreter. The proposal also
proposes enhancement to the interpreter to make it more non-programmer
friendly. Also, you must have a dist for every different Os.

Python, Be Bold captures the spirit of it should not be a shame to have the
interpreter/VM installed on end-users machines. It also facilitates the
work of other python devs. You installed it because of one Python program,
other programs benefit from it. It also proposes enhancements to the VM to
better facilitate that.

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


heap enhancements

2020-01-03 Thread rontoto
Hi guys, the code is working, but I want know, what I can improve on this code. 
It is like implementation of the simulation of shipment clearance in the depot 
according to priority and available deliveries. How can I do it better? Can u 
show me? Thnx for your time.
Input:

24 K
13 H
25 R
1 M
-4 T0
15 G
4 C
-1 T1
-3 T2
12 Y

Code:

import sys
class MaxHeap:
def __init__(self):
self.heap =[]
def bubble_up(self, i):
while i > 0:
j = (i - 1) // 2
if self.heap[i] <= self.heap[j]:
break
self.heap[j], self.heap[i] = self.heap[i], self.heap[j]
i = j
def insert(self, k):
self.heap += [k]
self.bubble_up(len(self.heap) - 1)
def peek(self):
return self.heap[0]
def size(self):
return len(self.heap)
def is_empty(self):
return self.size() == 0
def bubble_down(self, i):
n = self.size()
while 2 * i + 1 < n:
j = 2 * i + 1
if j + 1 < n and self.heap[j] < self.heap[j + 1]:
j += 1
if self.heap[i] < self.heap[j]:
self.heap[i], self.heap[j] = self.heap[j], self.heap[i]
i = j
 
def pop(self):
element = self.heap[0]
self.heap[0] = self.heap[-1]
self.heap.pop()
self.bubble_down(0)
return element
 
y = sys.stdin.read().splitlines()
z = list()
for line in y:
row=list(map(str, line.split()))
z.append(row)
 
def checking(a):
for char in a:
if char not in "0123456789-":
return False
return True
 
for i in range (len(z)):
for j in range (len(z[i])):
d=z[i][j]
if d.isdigit() is True:
z[i][j]=int(z[i][j])
q=checking(d)
if q is True:
z[i][j]=int(z[i][j])
H=MaxHeap()
for t in range (len(z)):
if z[t][0]>0:
H.insert(z[t])
if z[t][0] < 0:
print(z[t][1],sep="",end="")
print(": ",end="")
e=z[t][0]
while e<0 and (H.is_empty()) is False:
u=H.pop()
print(u[1],end=" ")
e=e+1
print("")
print("Depo: ",end="")
while (H.is_empty()) is not True:
u_1=H.pop()
print(u_1[1],end=" ")



Output:

T0: R K H M
T1: G
T2: C
Depo: Y
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python, Be Bold!

2020-01-03 Thread Abdur-Rahmaan Janhangeer
On Sat, 4 Jan 2020, 05:10 Abdur-Rahmaan Janhangeer, 
wrote:

>
> Also, you must have a dist for every different Os.
>

*for native execs

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


Re: Python, Be Bold!

2020-01-03 Thread Chris Angelico
On Sat, Jan 4, 2020 at 12:12 PM Abdur-Rahmaan Janhangeer
 wrote:
>
> On Fri, 3 Jan 2020, 23:49 Barry Scott,  wrote:
>
> >
> > I'm at a lose to understand what the problem is that zipapp is the
> > solution to that is not better served
> > with pip or PyInstall etc.
> >
>
> Well proposing to enhance zipapp, by adding app metadata and signing. By
> pip i understand you mean pure python distribution. Well, an enhanced
> zipapp's advantage would be smaller codebase and easy injection detection
> among others + the improving the ability to prevent reverse engineering for
> those who want it.

Why do you assume pure Python? pip is fully capable of locating and
installing binary packages based on the architecture it's running on.

> Comparing to native executable well, one thing is program size. You must
> have the interpreter on the machine but your program is lighter. 10 python
> programs does not mean inclung 10× the interpreter. The proposal also
> proposes enhancement to the interpreter to make it more non-programmer
> friendly. Also, you must have a dist for every different Os.

I'm not sure what your proposal is here. Are you trying to make a
single-file executable, or are you trying to make an archive of Python
source code (like a jar), or are you trying something different again?

> Python, Be Bold captures the spirit of it should not be a shame to have the
> interpreter/VM installed on end-users machines. It also facilitates the
> work of other python devs. You installed it because of one Python program,
> other programs benefit from it. It also proposes enhancements to the VM to
> better facilitate that.

U.. so go install Python and then you can install some
Python app? Isn't that how things already are?

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


Re: heap enhancements

2020-01-03 Thread DL Neil via Python-list

On 4/01/20 2:13 PM, rontoto wrote:

Hi guys, the code is working, but I want know, what I can improve on this code. 
It is like implementation of the simulation of shipment clearance in the depot 
according to priority and available deliveries. How can I do it better? Can u 
show me? Thnx for your time.



1 add comments which document the code, explaining what each method 
accomplishes, etc


2 choose meaningful names - it is not like you're sending a telegram 
(and if you don't know what on earth I'm talking about, then this 
applies double!) and being charged by the letter.


Have you run any time-trials to establish whether the code is 'fast' or 
'slow'?


Recommended reading:
1 supporting the above, including PEP-8
2 supporting the above
3 writing program(me)s so that others can read them
4 search for "Python heap"
5 download and inspect heapq from the PSL (Python Standard Library)

There are algorithm-mavens on-list who might weigh-in at that level...
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python, Be Bold!

2020-01-03 Thread Abdur-Rahmaan Janhangeer
On Sat, 4 Jan 2020, 05:23 Chris Angelico,  wrote:

>
> I'm not sure what your proposal is here. Are you trying to make a
> single-file executable, or are you trying to make an archive of Python
> source code (like a jar), or are you trying something different again?
>

a .jar but it can be defined for greater security

U.. so go install Python and then you can install some
> Python app? Isn't that how things already are?
>

Not for the archive-based exec. It does not currently exist.

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


Re: Python, Be Bold!

2020-01-03 Thread Michael Torrie
On 2020-01-03 5:44 p.m., Abdur-Rahmaan Janhangeer wrote:
> .jar provides more than just compression. It provides app info and has
> signing ability

This is the first time you've mentioned signing ability in this very
long thread.  At this point I have no idea what point you are even
making anymore.  It's all over the place!

If you coded up something concrete to share with the list, and described
it in the form of a PEP, and then it could be debated on its merits
rather than some ever-changing feature wish list.  Your ideas may well
be good.  But they will need an implementation behind them.  Python core
developers have a lot on their hands; pie in the sky wishes are unlikely
to get on their radar.

Several people have suggested utilities to look at. I suggest you start
there and see if you can modify them to suit your needs.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python, Be Bold!

2020-01-03 Thread Abdur-Rahmaan Janhangeer
On Sat, 4 Jan 2020, 06:49 Michael Torrie,  wrote:

> On 2020-01-03 5:44 p.m., Abdur-Rahmaan Janhangeer wrote:
> > .jar provides more than just compression. It provides app info and has
> > signing ability
>
> This is the first time you've mentioned signing ability in this very
> long thread.  At this point I have no idea what point you are even
> making anymore.  It's all over the place!
>

True. Currently writing a draft.

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


Re: Python, Be Bold!

2020-01-03 Thread Abdur-Rahmaan Janhangeer
<< than some ever-changing feature wish list. >>

^^_ since the beginning it was .jar
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: heap enhancements

2020-01-03 Thread jezkator
ok, so it could be like this?

import sys
chain = sys.stdin.read().splitlines()
array_z = list()
for line in chain:
row=list(map(str, line.split()))
array_z.append(row)
#every line in input changes into 2D array

def checking(chain):
"checking if characters are numbers or not"
for char in chain:
if char not in "0123456789-":
return False
return True

class MaxHeap:
def __init__(self):
"""heap __init__ constructor"""
self.heap =[]
def bubble_up(self, i):
bubble the element up if condition is ok """
while i > 0:
j = (i - 1) // 2
if self.heap[i] <= self.heap[j]:
break
self.heap[j], self.heap[i] = self.heap[i], self.heap[j]
i = j
def insert(self, k):
"""insert element in heap"""
self.heap += [k]
self.bubble_up(len(self.heap) - 1)
def peek(self):
"""return the biggest element"""
return self.heap[0]
def size(self):
"""return quantity of elements in heap"""
return len(self.heap)
def is_empty(self):
"""is heap empty?"""
return self.size() == 0
def bubble_down(self, i):
"""bubble down the element"""
n = self.size()
while 2 * i + 1 < n:
j = 2 * i + 1
if j + 1 < n and self.heap[j] < self.heap[j + 1]:
j += 1
if self.heap[i] < self.heap[j]:
self.heap[i], self.heap[j] = self.heap[j], self.heap[i]
i = j
def pop(self):
"""delete the biggest element and change the heap"""
element = self.heap[0]
self.heap[0] = self.heap[-1]
self.heap.pop()
self.bubble_down(0)
return element

for i in range (len( array_z)):
for j in range (len( array_z[i])):
digit_z= array_z[i][j]
if digit_z.isdigit() is True:
array_z[i][j]=int( array_z[i][j])
check =checking(digit_z)
if check is True:
array_z[i][j]=int( array_z[i][j])

Heap=MaxHeap()
for a in range (len( array_z)):
if  array_z[a][0]>0:
Heap.insert( array_z[a])
if  array_z[a][0] < 0:
print( array_z[a][1]+": ",end="") #print name of delivery
index_of_package= array_z[a][0]
while index_of_package<0 and (Heap.is_empty()) is False:
delivery_package=Heap.pop()
print(delivery_package[1],end=" ") #print name of package in 
delivery
index_of_package+= 1
print("")
print("Depo: ",end="")
while (Heap.is_empty()) is False:
depo_package=Heap.pop()
print(depo_package[1],end=" ") #print name of package in depo
-- 
https://mail.python.org/mailman/listinfo/python-list