Re: python read line by line and keep indent

2020-04-18 Thread Peter Otten
Souvik Dutta wrote:

> You can actually read and write in a file simultaneously. Just replace "r"
> with "w+" if the file has not been previously made or use "r+" is the file
> has already been made.

Good advice for those who like to butcher their data ;)

Seriously, writing modified data into a new file is the cleaner and safer 
method in most cases.

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


Re: python read line by line and keep indent

2020-04-18 Thread Souvik Dutta
Okay so I was not able to say properly. You are indeed doing the same thing
that you were doing i.e. writting the modified data just, that now you
don't need to close you if file before doing any writting stuff. That is
there is a one line deduction from the whole code.

Souvik flutter dev

On Sat, Apr 18, 2020, 1:20 PM Peter Otten <[email protected]> wrote:

> Souvik Dutta wrote:
>
> > You can actually read and write in a file simultaneously. Just replace
> "r"
> > with "w+" if the file has not been previously made or use "r+" is the
> file
> > has already been made.
>
> Good advice for those who like to butcher their data ;)
>
> Seriously, writing modified data into a new file is the cleaner and safer
> method in most cases.
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Incremental PCA

2020-04-18 Thread Rahul Gupta
i wanted to implement incremental PCA.
Got this code for stack overflow but i am wondering what y = chunk.pop("y") 
does and what is this argument "y" to pop
from sklearn.decomposition import IncrementalPCA
import csv
import sys
import numpy as np
import pandas as pd

dataset = sys.argv[1]
chunksize_ = 5 * 25000
dimensions = 300

reader = pd.read_csv(dataset, sep = ',', chunksize = chunksize_)
sklearn_pca = IncrementalPCA(n_components=dimensions)
for chunk in reader:
y = chunk.pop("Y")
sklearn_pca.partial_fit(chunk)

# Computed mean per feature
mean = sklearn_pca.mean_
# and stddev
stddev = np.sqrt(sklearn_pca.var_)

Xtransformed = None
for chunk in pd.read_csv(dataset, sep = ',', chunksize = chunksize_):
y = chunk.pop("Y")
Xchunk = sklearn_pca.transform(chunk)
if Xtransformed == None:
Xtransformed = Xchunk
else:
Xtransformed = np.vstack((Xtransformed, Xchunk))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-18 Thread Souvik Dutta
I have one question here. On using print(f"{c:.32f}") where c= 2/5 instead
of getting 32 zeroes I got some random numbers. The exact thing is
0.40002220446049250313
Why do I get this and not 32 zeroes?

On Fri, 17 Apr, 2020, 6:25 pm ast,  wrote:

> Le 17/04/2020 à 13:40, Aakash Jana a écrit :
>
> > I am running python 3.8 only but my issue is I need more zeroes after my
> > result.
> > I want 2/5 = 0.40
> > But I am only getting 0.4
>
> f"{2/5:.6f}"
> '0.40'
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-18 Thread DL Neil via Python-list

On 19/04/20 1:07 AM, Souvik Dutta wrote:

I have one question here. On using print(f"{c:.32f}") where c= 2/5 instead
of getting 32 zeroes I got some random numbers. The exact thing is
0.40002220446049250313
Why do I get this and not 32 zeroes?


Approximating decimal numbers as binary values.

Do NOT try this at home! How many lines will the following code display 
on-screen?


>>> v = 0.1
>>> while v != 1.0:
... print(v)
... v += 0.1

As an exercise, try dividing 1.0 by 10.0 and then adding the result to 
itself ten times.


Back in the ?good, old days, a Computer Science course would almost 
certainly involve some "Numerical Analysis", when such issues would be 
discussed. Not sure that many institutions offer such, these days...

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


Re: Floating point problem

2020-04-18 Thread Dan Sommers
On Sun, 19 Apr 2020 01:25:00 +1200
DL Neil via Python-list  wrote:

> On 19/04/20 1:07 AM, Souvik Dutta wrote:
> > I have one question here. On using print(f"{c:.32f}") where c= 2/5 instead
> > of getting 32 zeroes I got some random numbers. The exact thing is
> > 0.40002220446049250313
> > Why do I get this and not 32 zeroes?
> 
> Approximating decimal numbers as binary values.
> 
> Do NOT try this at home! How many lines will the following code display 
> on-screen?
> 
>  >>> v = 0.1
>  >>> while v != 1.0:
> ... print(v)
> ... v += 0.1
> 
> As an exercise, try dividing 1.0 by 10.0 and then adding the result to 
> itself ten times.
> 
> Back in the ?good, old days, a Computer Science course would almost 
> certainly involve some "Numerical Analysis", when such issues would be 
> discussed. Not sure that many institutions offer such, these days...

These days, I continue to recommend _What Every Computer Scientist
Should Know About Floating-Point Arithmetic_ by David Goldberg.  The
first link that pops up in my search bubble is
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html; YMMV.

Yes, it's highly technical, but well worth the effort.

Or an extended session at the feet of the timbot, which is much harder
to come by.

Dan

-- 
“Atoms are not things.” – Werner Heisenberg
Dan Sommers, http://www.tombstonezero.net/dan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-18 Thread Souvik Dutta
I literally tried it!!! And it did not stop because I did not get any 1.0
rather I got 0.999 But why does this happen. This is a simple math
which according to normal human logic should give perfect numbers which are
not endless. Then why does a computer behave so differently?

On Sat, 18 Apr, 2020, 7:02 pm DL Neil via Python-list, <
[email protected]> wrote:

> On 19/04/20 1:07 AM, Souvik Dutta wrote:
> > I have one question here. On using print(f"{c:.32f}") where c= 2/5
> instead
> > of getting 32 zeroes I got some random numbers. The exact thing is
> > 0.40002220446049250313
> > Why do I get this and not 32 zeroes?
>
> Approximating decimal numbers as binary values.
>
> Do NOT try this at home! How many lines will the following code display
> on-screen?
>
>  >>> v = 0.1
>  >>> while v != 1.0:
> ... print(v)
> ... v += 0.1
>
> As an exercise, try dividing 1.0 by 10.0 and then adding the result to
> itself ten times.
>
> Back in the ?good, old days, a Computer Science course would almost
> certainly involve some "Numerical Analysis", when such issues would be
> discussed. Not sure that many institutions offer such, these days...
> --
> Regards =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-18 Thread Chris Angelico
On Sun, Apr 19, 2020 at 12:03 AM Souvik Dutta  wrote:
>
> I literally tried it!!! And it did not stop because I did not get any 1.0
> rather I got 0.999 But why does this happen. This is a simple math
> which according to normal human logic should give perfect numbers which are
> not endless. Then why does a computer behave so differently?
>

If you add 0.333 and 0.333 and 0.333, do you get 1.0? No, you get
0.999. But if you add 1/3 and 1/3 and 1/3, you get 1. The computer has
to round, same as you do - it doesn't have infinite precision. The
truth is that the number 0.1, to a computer, is not actually one tenth
- it's an approximation for one tenth, just as 0.333 is an
approximation for one third.

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


Re: Floating point problem

2020-04-18 Thread DL Neil via Python-list

On 19/04/20 1:51 AM, Souvik Dutta wrote:
I literally tried it!!! And it did not stop because I did not get any 
1.0 rather I got 0.999 But why does this happen. This is a 
simple math which according to normal human logic should give perfect 
numbers which are not endless. Then why does a computer behave so 
differently?


Please don't top-post - (human) conversations are normally question 
followed by answer, not the other way around!


Computers use binary, not decimal - asked and answered (see previous 
first response, below)



On Sat, 18 Apr, 2020, 7:02 pm DL Neil via Python-list, 
mailto:[email protected]>> wrote:


On 19/04/20 1:07 AM, Souvik Dutta wrote:
 > I have one question here. On using print(f"{c:.32f}") where c=
2/5 instead
 > of getting 32 zeroes I got some random numbers. The exact thing is
 > 0.40002220446049250313
 > Why do I get this and not 32 zeroes?

Approximating decimal numbers as binary values.

Do NOT try this at home! How many lines will the following code display
on-screen?

  >>> v = 0.1
  >>> while v != 1.0:
...     print(v)
...     v += 0.1

As an exercise, try dividing 1.0 by 10.0 and then adding the result to
itself ten times.

Back in the ?good, old days, a Computer Science course would almost
certainly involve some "Numerical Analysis", when such issues would be
discussed. Not sure that many institutions offer such, these days...
-- 
Regards =dn
-- 
https://mail.python.org/mailman/listinfo/python-list




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


Re: Floating point problem

2020-04-18 Thread Souvik Dutta
Hmmm sorry please forgive me. I only did that because the question was
relevant. Please forgive me. Sorry again.

Souvik flutter dev

On Sat, Apr 18, 2020, 7:52 PM DL Neil via Python-list <
[email protected]> wrote:

> On 19/04/20 1:51 AM, Souvik Dutta wrote:
> > I literally tried it!!! And it did not stop because I did not get any
> > 1.0 rather I got 0.999 But why does this happen. This is a
> > simple math which according to normal human logic should give perfect
> > numbers which are not endless. Then why does a computer behave so
> > differently?
>
> Please don't top-post - (human) conversations are normally question
> followed by answer, not the other way around!
>
> Computers use binary, not decimal - asked and answered (see previous
> first response, below)
>
>
> > On Sat, 18 Apr, 2020, 7:02 pm DL Neil via Python-list,
> > mailto:[email protected]>> wrote:
> >
> > On 19/04/20 1:07 AM, Souvik Dutta wrote:
> >  > I have one question here. On using print(f"{c:.32f}") where c=
> > 2/5 instead
> >  > of getting 32 zeroes I got some random numbers. The exact thing is
> >  > 0.40002220446049250313
> >  > Why do I get this and not 32 zeroes?
> >
> > Approximating decimal numbers as binary values.
> >
> > Do NOT try this at home! How many lines will the following code
> display
> > on-screen?
> >
> >   >>> v = 0.1
> >   >>> while v != 1.0:
> > ... print(v)
> > ... v += 0.1
> >
> > As an exercise, try dividing 1.0 by 10.0 and then adding the result
> to
> > itself ten times.
> >
> > Back in the ?good, old days, a Computer Science course would almost
> > certainly involve some "Numerical Analysis", when such issues would
> be
> > discussed. Not sure that many institutions offer such, these days...
> > --
> > Regards =dn
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
>
> --
> Regards =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-18 Thread Souvik Dutta
Hmm understood.

Souvik flutter dev

On Sat, Apr 18, 2020, 7:36 PM Chris Angelico  wrote:

> On Sun, Apr 19, 2020 at 12:03 AM Souvik Dutta 
> wrote:
> >
> > I literally tried it!!! And it did not stop because I did not get any 1.0
> > rather I got 0.999 But why does this happen. This is a simple
> math
> > which according to normal human logic should give perfect numbers which
> are
> > not endless. Then why does a computer behave so differently?
> >
>
> If you add 0.333 and 0.333 and 0.333, do you get 1.0? No, you get
> 0.999. But if you add 1/3 and 1/3 and 1/3, you get 1. The computer has
> to round, same as you do - it doesn't have infinite precision. The
> truth is that the number 0.1, to a computer, is not actually one tenth
> - it's an approximation for one tenth, just as 0.333 is an
> approximation for one third.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Farewell to Oier Echaniz Beneitez

2020-04-18 Thread M.-A. Lemburg
We received the very sad news today, that Oier Echaniz Beneitez has
passed away, after a long-term illness (not as a result of COVID-19):

https://www.europython-society.org/post/615744838396215296/farewell-to-oier-echaniz-beneitez

Oier was one of the initiators for bringing EuroPython to Bilbao in
2015 and co-chaired the conference in both 2015 and 2016, together
with Fabio.

Oier giving the EuroPython 2015 welcome speech together with Fabio
Pliger: https://www.youtube.com/watch?v=NrLKOEhnb7w

He was one of the most enthusiastic and engaged organizers of the
conference, served on the EuroPython Society board from 2015 - 2017
and founded and chaired the local Python organization in San Sebastian
(PySS, pronounced “peace”). Oier also started the pyjok.es project,
together with Alexandre Savio and Ben Nuttall, inaugurating the first
Python Jokes-as-a-Service of its kind.

https://pyjok.es/

His humour and friendly approach to everything, even when things
turned bad on him, were inspiring and created a great atmosphere for
everyone who worked with him. Oier’s love for pyntxos was famous and
I’m sure all of you who attended the EuroPython conferences in Bilbao
will never forget.

https://ep2015.europython.eu/en/events/social-event/

“Oier was an exceptionally funny guy with a wonderful sense of
humour. He was kind, caring and considerate, and worked hard for PySS
and EuroPython. I have fond, happy memories of any time I spent with
him and know he’ll be greatly missed.” — Ben Nuttall

“Oier put so much enthusiasm in everything we did, in our first quests
together and then doing all the activities of ACPySS. He was not only
an active member of the Python community but also very involved in the
local cancer research and care community. We knew his end was going to
come sooner rather than later, and these last 2 years have been quite
harsh on him. His amazing will to live was what kept him going for so
long and we are sure that the Python community motivated him to keep
on. Rest in PySS, my friend.” — Alexandre Savio


 * Our good friend: We’ll miss you! *

  May the good vibes and pyntxos always be with you.


Thank you for all the good times,
--
Your friends from the EuroPython community

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


Re: Floating point problem

2020-04-18 Thread Aakash Jana
I am really enlightened by the amount of knowledge I received from a
question that seemed so little to me. 😅

On Sat, 18 Apr 2020, 8:08 pm Souvik Dutta  Hmm understood.
>
> Souvik flutter dev
>
> On Sat, Apr 18, 2020, 7:36 PM Chris Angelico  wrote:
>
> > On Sun, Apr 19, 2020 at 12:03 AM Souvik Dutta 
> > wrote:
> > >
> > > I literally tried it!!! And it did not stop because I did not get any
> 1.0
> > > rather I got 0.999 But why does this happen. This is a simple
> > math
> > > which according to normal human logic should give perfect numbers which
> > are
> > > not endless. Then why does a computer behave so differently?
> > >
> >
> > If you add 0.333 and 0.333 and 0.333, do you get 1.0? No, you get
> > 0.999. But if you add 1/3 and 1/3 and 1/3, you get 1. The computer has
> > to round, same as you do - it doesn't have infinite precision. The
> > truth is that the number 0.1, to a computer, is not actually one tenth
> > - it's an approximation for one tenth, just as 0.333 is an
> > approximation for one third.
> >
> > ChrisA
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python read line by line and keep indent

2020-04-18 Thread MRAB

On 2020-04-18 08:59, Souvik Dutta wrote:

Okay so I was not able to say properly. You are indeed doing the same thing
that you were doing i.e. writting the modified data just, that now you
don't need to close you if file before doing any writting stuff. That is
there is a one line deduction from the whole code.

Souvik flutter dev


No. As Peter said, writing to a _new_ file is better.

Read from old, write to new, then, when you've finished, replace the old 
with the new (or rename the old as a backup and then rename the new as 
the old). That way, if anything goes wrong during processing, you'll 
still have the original.



On Sat, Apr 18, 2020, 1:20 PM Peter Otten <[email protected]> wrote:


Souvik Dutta wrote:

> You can actually read and write in a file simultaneously. Just replace
"r"
> with "w+" if the file has not been previously made or use "r+" is the
file
> has already been made.

Good advice for those who like to butcher their data ;)

Seriously, writing modified data into a new file is the cleaner and safer
method in most cases.


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


Re: python read line by line and keep indent

2020-04-18 Thread Souvik Dutta
Oh! Sorry I didn't get that earlier. 😛

On Sat, 18 Apr, 2020, 9:10 pm MRAB,  wrote:

> On 2020-04-18 08:59, Souvik Dutta wrote:
> > Okay so I was not able to say properly. You are indeed doing the same
> thing
> > that you were doing i.e. writting the modified data just, that now you
> > don't need to close you if file before doing any writting stuff. That is
> > there is a one line deduction from the whole code.
> >
> > Souvik flutter dev
> >
> No. As Peter said, writing to a _new_ file is better.
>
> Read from old, write to new, then, when you've finished, replace the old
> with the new (or rename the old as a backup and then rename the new as
> the old). That way, if anything goes wrong during processing, you'll
> still have the original.
>
> > On Sat, Apr 18, 2020, 1:20 PM Peter Otten <[email protected]> wrote:
> >
> >> Souvik Dutta wrote:
> >>
> >> > You can actually read and write in a file simultaneously. Just replace
> >> "r"
> >> > with "w+" if the file has not been previously made or use "r+" is the
> >> file
> >> > has already been made.
> >>
> >> Good advice for those who like to butcher their data ;)
> >>
> >> Seriously, writing modified data into a new file is the cleaner and
> safer
> >> method in most cases.
> >>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-18 Thread ast

Le 18/04/2020 à 15:07, Souvik Dutta a écrit :

I have one question here. On using print(f"{c:.32f}") where c= 2/5 instead
of getting 32 zeroes I got some random numbers. The exact thing is
0.40002220446049250313
Why do I get this and not 32 zeroes?





2/5 = 0.0110011001100110011001...  and repeat 1001 infinitely

It cannot be represented exactly on a 64bits float




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


Re: Incremental PCA

2020-04-18 Thread Dieter Maurer
Rahul Gupta wrote at 2020-4-18 02:56 -0700:
>i wanted to implement incremental PCA.
>Got this code for stack overflow but i am wondering what y = chunk.pop("y") 
>does and what is this argument "y" to pop

Key to answer your question is "what is the type of `chunk`.
Either use python's inspection (--> "type(chunk)") are read the
documentation of `pandas.read_csv`.

Likely, it is a `dict`, documented in the Python documentation.
for a mapping (such as a `dict`): pop removes the given key and returns
its value.

>from sklearn.decomposition import IncrementalPCA
>import csv
>import sys
>import numpy as np
>import pandas as pd
>
>dataset = sys.argv[1]
>chunksize_ = 5 * 25000
>dimensions = 300
>
>reader = pd.read_csv(dataset, sep = ',', chunksize = chunksize_)
>sklearn_pca = IncrementalPCA(n_components=dimensions)
>for chunk in reader:
>y = chunk.pop("Y")
>sklearn_pca.partial_fit(chunk)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Floating point problem

2020-04-18 Thread Grant Edwards
On 2020-04-18, Souvik Dutta  wrote:
> I literally tried it!!! And it did not stop because I did not get any 1.0
> rather I got 0.999 But why does this happen. This is a simple math
> which according to normal human logic should give perfect numbers which are
> not endless. Then why does a computer behave so differently?

Because computers _don't_do_math_.  That is a very important thing to
remember.

Computer do something that _approximates_ math... in some
situations...  if you know what you're doing.

In you're case you're doing IEEE floating point operations. Before you
use floating point, you should read the article by Goldman that has been
suggested:

https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
https://dl.acm.org/doi/10.1145/103162.103163

--
Grant

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


Issues regarding the download

2020-04-18 Thread MRIDULA GUPTA
Hi,
I am a new user and I am facing difficulty using the app. everytime I click
on the app the windows open which tell me either to modify the app or
repair it or uninstall it. I did my level best but still I am facing
problems installing it. please look into it as soon as possible.
-- 
https://mail.python.org/mailman/listinfo/python-list


Get a region from a larger data

2020-04-18 Thread J Conrado



Hi,


I have GOES16 full disk data with the dimensions (5424, 5424) and my 
latitude and longitude arrays have the same dimension.


How can I seletct a small  region of this data, using  this limits for 
lat=[-30,10] and lon = [-90,-30] for my sector. I try to select my 
region using this limits.


But, I didn't have success.


Tanks,


Conrado

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


Re: Get a region from a larger data

2020-04-18 Thread Peter Otten
J Conrado wrote:

> I have GOES16 full disk data with the dimensions (5424, 5424) and my
> latitude and longitude arrays have the same dimension.
> 
> How can I seletct a small  region of this data, using  this limits for
> lat=[-30,10] and lon = [-90,-30] for my sector. I try to select my
> region using this limits.
> 
> But, I didn't have success.

I had no idea what you may be talking about, so I used [the evil search engine].
After a couple of iterations I found

https://stackoverflow.com/questions/29135885/netcdf4-extract-for-subset-of-lat-lon

Does that help?

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


Re: Floating point problem

2020-04-18 Thread Grant Edwards
On 2020-04-18, Dennis Lee Bieber  wrote:

> At the very least, one was taught to not test for equality of two
> floating point values (which also implies one did not test for the
> negation of equality). One either tested for difference
> (greater/less than) or for a delta between values being less than
> some threshold.

>   while abs( v - 1.0) > 0.05:

Then the trick is choosing the threshold without doing a day's worth
of trial-and-error test runs.

--
Grant



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


Re: Floating point problem

2020-04-18 Thread Chris Angelico
On Sun, Apr 19, 2020 at 4:26 AM Grant Edwards  wrote:
>
> On 2020-04-18, Souvik Dutta  wrote:
> > I literally tried it!!! And it did not stop because I did not get any 1.0
> > rather I got 0.999 But why does this happen. This is a simple math
> > which according to normal human logic should give perfect numbers which are
> > not endless. Then why does a computer behave so differently?
>
> Because computers _don't_do_math_.  That is a very important thing to
> remember.
>
> Computer do something that _approximates_ math... in some
> situations...  if you know what you're doing.

That's not true in the absolute. Computers DO do math. But like
people, they can't do more than approximate to infinities. A computer
can do true math as long as it involves integers or rationals that are
small enough to fit in its memory - just like humans do.

> In you're case you're doing IEEE floating point operations. Before you
> use floating point, you should read the article by Goldman that has been
> suggested:
>
> https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
> https://dl.acm.org/doi/10.1145/103162.103163
>

IEEE floating-point is indeed a variant form of fundamental
mathematics, though, so in this specific case, you're not wrong. But
in general (and, for instance, when you use Python's int or Fraction
types), computers *can* do math.

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


Re: Helping Windows first time users

2020-04-18 Thread boB Stepp
On Wed, Apr 15, 2020 at 2:04 PM Barry Scott  wrote:
>
> I post some suggestion to improve the Python installer for Windows
> to better sign post users on the next steps.
>
> https://mail.python.org/archives/list/[email protected]/message/TKHID7PMKN5TK5QDQ2BL3G45FYAJNYJX/
>
> It also seems like we could do with drafting the text of a helpful
> reply to help the Windows first time users. This would help folks that
> reply to the Windows first time users to have a quick way to reply
> without drafting the text a reply every time.
>
> What are your thoughts on the installer changes and reply text?

I wonder if the last screen of the installer should have a checkbox,
checked by default, that launches IDLE.  IDLE would then display a
helpful text file on this first launch describing how to use IDLE, how
to find and launch it again, etc.  As well have it describe all of the
help you are advocating here as well.  It would be a minor annoyance
for experienced users to have to uncheck the box before clicking
finish, but I think it might have a good chance of getting new users
off to a reliable start.  Many other Windows program installers are
setup similarly to launch the program being installed.  This is a
little different as IDLE is not Python, but that is a minor quibble, I
think.


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


Re: Helping Windows first time users

2020-04-18 Thread Chris Angelico
On Sun, Apr 19, 2020 at 6:02 AM boB Stepp  wrote:
> I wonder if the last screen of the installer should have a checkbox,
> checked by default, that launches IDLE.  IDLE would then display a
> helpful text file on this first launch describing how to use IDLE, how
> to find and launch it again, etc.  As well have it describe all of the
> help you are advocating here as well.  It would be a minor annoyance
> for experienced users to have to uncheck the box before clicking
> finish, but I think it might have a good chance of getting new users
> off to a reliable start.  Many other Windows program installers are
> setup similarly to launch the program being installed.  This is a
> little different as IDLE is not Python, but that is a minor quibble, I
> think.

It's provided by default, it's part of the standard library, and it's
a good consistent interface for Windows users. I'd be in favour of
this. It's also not as vulnerable to the problem of "no matter how
much info you throw at people, they still won't read it".

Of course, this would mean there'd be some who still won't figure out
how to open up Idle any other way, so they'll rerun the installer just
to open up the REPL... but at least it'll work, and the rest is just
https://xkcd.com/763/ material.

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


Re: Why generate POP_TOP after an "import from?"

2020-04-18 Thread Adam Preble
On Friday, April 17, 2020 at 1:37:18 PM UTC-5, Chris Angelico wrote:
> The level is used for package-relative imports, and will basically be
> the number of leading dots (eg "from ...spam import x" will have a
> level of 3). You're absolutely right with your analysis, with one
> small clarification:

Thanks for taking that on too. I haven't set up module hierarchy yet so I'm not 
in a position to handle levels, but I have started parsing them and generating 
the opcodes. Is it sufficient to just use the number of dots as an indication 
of level?

As a side note, I suppose it's sufficient to just *peek* at the stack rather 
than pop the module and push it again. I'm guessing that's what the Python 
interpreter is doing.

> In theory, I suppose, you could replace the POP_TOP with a STORE_FAST
> into "sys", and thus get a two-way import that both grabs the module
> and also grabs something out of it. Not very often wanted, but could
> be done if you fiddle with the bytecode.

I'm trying to follow along for academic purposes. I'm guessing you mean that 
would basically optimize:

from sys import path
import sys

It would definitely be a fringe thing to do...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Why generate POP_TOP after an "import from?"

2020-04-18 Thread Adam Preble
On Saturday, April 18, 2020 at 1:15:35 PM UTC-5, Alexandre Brault wrote:
>  >>> def f():
> ... â  â  from sys import path, argv ...

So I figured it out and all but I wanted to ask about the special characters in 
that output. I've seen that a few times and never figured out what's going on 
and if I need to change how I'm reading these. Or say:

 â â â â â â â â â â â â  12 STORE_FASTâ â â â â â â â â â â â â â  1 (argv

I don't know if you're seeing all these letter a's. I'm guessing something 
goofy with Unicode spaces or something?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Issues regarding the download

2020-04-18 Thread Bob Gailer
On Apr 18, 2020 2:29 PM, "MRIDULA GUPTA" <[email protected]> wrote:
>
> Hi,
> I am a new user and I am facing difficulty using the app. everytime I
click
> on the app the windows open which tell me either to modify the app or
> repair it or uninstall it. I did my level best but still I am facing
> problems installing it. please look into it as soon as possible.

The program you downloaded is an installer. You run an installer one time,
then you find the program that was installed ( python.exe  in this case)
and run that program. Exactly how you run the program depends on the
operating system and where you chose to install the program. See the
documentation at python.org for operating system specifics.

Try this out then get back to us for more help. When responding please
reply all and tell us what operating system you are using. This list does
not accept attachments so you will have to copy and paste any text you want
to share with us.

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


Re: Why generate POP_TOP after an "import from?"

2020-04-18 Thread Chris Angelico
On Sun, Apr 19, 2020 at 7:36 AM Adam Preble  wrote:
>
> On Friday, April 17, 2020 at 1:37:18 PM UTC-5, Chris Angelico wrote:
> > The level is used for package-relative imports, and will basically be
> > the number of leading dots (eg "from ...spam import x" will have a
> > level of 3). You're absolutely right with your analysis, with one
> > small clarification:
>
> Thanks for taking that on too. I haven't set up module hierarchy yet so I'm 
> not in a position to handle levels, but I have started parsing them and 
> generating the opcodes. Is it sufficient to just use the number of dots as an 
> indication of level?
>

Correct. You can literally just put that exact line of code into a
function, disassemble it, and you'll see the level - even if you're
not in a package (which would be a run-time error only).

> As a side note, I suppose it's sufficient to just *peek* at the stack rather 
> than pop the module and push it again. I'm guessing that's what the Python 
> interpreter is doing.
>

Yep!

> > In theory, I suppose, you could replace the POP_TOP with a STORE_FAST
> > into "sys", and thus get a two-way import that both grabs the module
> > and also grabs something out of it. Not very often wanted, but could
> > be done if you fiddle with the bytecode.
>
> I'm trying to follow along for academic purposes. I'm guessing you mean that 
> would basically optimize:
>
> from sys import path
> import sys
>
> It would definitely be a fringe thing to do...

Exactly, an incredibly fringe thing to do :) But that's the effect
you'd get (at least, I believe so - haven't actually tested that).

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


Re: What variable type is returned from Open()?

2020-04-18 Thread boB Stepp
On Wed, Apr 15, 2020 at 11:27 AM Chris Angelico  wrote:
>
> On Thu, Apr 16, 2020 at 12:01 AM  wrote:

> > config_file : file = open(config_file_s, "r")
> >
> >
> > What type of variable should config_file (above) be declared as?

> It returns a file-like object. Instead of annotating, just let the
> type hinting system figure it out - you initialized it with the result
> of an open() call, so it should be able to figure that out.
>
> Python is not C, you do not need to declare all your variable types.
>
> If you actually need a way to represent "file-like object" (maybe as a
> parameter to some other function), there are tools for that in the
> typing module, but just DON'T annotate every variable. Bad idea, will
> cause you a maintenance headache and won't help anything.

I have just started playing around with type annotations and mypy.  I
have still much to learn.  I take your point about "...cause you a
maintenance headache..."  I am guessing that part of what you are
saying is that if mypy (or whatever is actually being used) can
properly infer the type of an object then there is no point in
annotating it.  Can you give guidelines or point to a good article how
to best and most efficiently use type annotation without
over-annotating?  Bear in mind that I have yet to fully grasp all of
what mypy (What I am currently using.) can correctly infer from the
code.

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


Re: Why generate POP_TOP after an "import from?"

2020-04-18 Thread Chris Angelico
On Sun, Apr 19, 2020 at 7:40 AM Adam Preble  wrote:
>
> On Saturday, April 18, 2020 at 1:15:35 PM UTC-5, Alexandre Brault wrote:
> >  >>> def f():
> > ... â  â  from sys import path, argv ...
>
> So I figured it out and all but I wanted to ask about the special characters 
> in that output. I've seen that a few times and never figured out what's going 
> on and if I need to change how I'm reading these. Or say:
>
>  â â â â â â â â â â â â  12 STORE_FASTâ â â â â â â â â â â â â â  1 (argv
>
> I don't know if you're seeing all these letter a's. I'm guessing something 
> goofy with Unicode spaces or something?
>

That looks like something got messed up between the various mailing
list and newsgroup gateways. I'm not sure exactly what happened, but
it's probably been converted into nonbreaking spaces, then encoded in
some way, and decoded incorrectly. I'm not sure WHAT the encodings in
question would be, but my best guess is that the nonbreaking spaces
were encoded UTF-8 (C2 A0), and then decoded in some eight-bit
encoding.

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


Re: Issues regarding the download

2020-04-18 Thread DL Neil via Python-list

On 18/04/20 6:20 PM, MRIDULA GUPTA wrote:

Hi,
I am a new user and I am facing difficulty using the app. everytime I click
on the app the windows open which tell me either to modify the app or
repair it or uninstall it. I did my level best but still I am facing
problems installing it. please look into it as soon as possible.



Hi, and welcome to Python.

Please be aware that the members of this Discussion List are volunteers, 
giving-up their free time to help each-other.


This question appears (and has been answered) in the list archives. (ref 
close of all messages)


The Python documentation library is your friend!
https://docs.python.org/3/index.html
Python Setup and Usage: https://docs.python.org/3/using/index.html
The Python Tutorial: https://docs.python.org/3/tutorial/index.html

There is also a Python Tutor Discussion List, which you may find 
helpful. https://mail.python.org/mailman/listinfo/tutor

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


Re: What variable type is returned from Open()?

2020-04-18 Thread Chris Angelico
On Sun, Apr 19, 2020 at 7:48 AM boB Stepp  wrote:
> Can you give guidelines or point to a good article how
> to best and most efficiently use type annotation without
> over-annotating?  Bear in mind that I have yet to fully grasp all of
> what mypy (What I am currently using.) can correctly infer from the
> code.
>

Like with most things, the best way is to start by doing as little as
you possibly can, and then work your way up from there. Try using mypy
on your code absolutely as-is, without any type hints at all. If it
seems to be quite useless, add some hints, try again. Continue until
it's able to help you with your goals. Oh, I forgot to mention. Start
with a goal. Why are you using mypy? Is it to help you detect
misspelled variable/parameter names? Is it to save you the hassle of
writing unit tests? Is it to improve IDE features (tab completion
etc)?

The one specific thing I'll say is: function signatures are usually
the lowest-hanging fruit. For equivalent effort, they'll usually give
you the best results, since you can create "knowledge boundaries" of a
sort, where the type inference doesn't need to search the entire
codebase for everything. But other than that, just explore your own
codebase to try to find where it'd be useful.

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


Springer released free ebooks (epub and pdf)

2020-04-18 Thread DL Neil via Python-list
Springer (publisher) has released a bunch of eBook versions of Python 
text-books, free to download (.PDF and/or .EPUB), in support of COVID-19 
stay-at-homes.


This sub-list features texts for all 'levels' of mastery, and published 
between 2014 and 2019/20. They tend to be 'solid' content, cf 'Dummies 
Guide' casual:

https://www.reddit.com/r/Python/comments/g2yfml/springer_released_free_ebooks_epub_and_pdf/
--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Creating a curses app that interacts with the terminal, yet reads from stdin?

2020-04-18 Thread Tim Chase
I know that vim lets me do things like

 $ ls | vim -

where it will read the data from stdin, but then take over the screen
TUI curses-style, and interact directly with the keyboard input
without being limited to input from stdin.

I've played around with something like

import sys
import curses
d = list(sys.stdin) # read/process/store it
def main(stdscr):
stdscr.clear()
for i, s in enumerate(d):
stdscr.addstr(i, 1, s.strip())
stdscr.refresh()
stdscr.getkey()
curses.wrapper(main)

but it complains when I run it with

  $ seq 10 | python myprog.py
  ...
  _curses.error: no input

I've tried adding (after the imports)

tty = open('/dev/tty', 'r+b')
curses.setupterm(fd=tty.fileno())

to coerce it, but it doesn't seem to do anything fruitful.

Any advice for how to go about replicating this vim-like behavior in
Python?

Thanks!

-tkc




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