Re: why sqrt is not a built-in function?

2021-01-16 Thread Michael F. Stemper

On 15/01/2021 17.17, dn wrote:

On 16/01/2021 11.40, Michael F. Stemper wrote:

On 15/01/2021 16.01, Chris Angelico wrote:

On Sat, Jan 16, 2021 at 8:56 AM Michael F. Stemper
 wrote:

On 15/01/2021 15.26, Stefan Ram wrote:

"Michael F. Stemper"  writes:

On 15/01/2021 14.01, Stefan Ram wrote:



__import__( "math" ).sqrt( 4 )

I had no idea that syntax existed, and find it completely at odds
with The Zen of Python. I'm torn between forgetting that I ever saw
it and using it for some evilly-obfuscated code.


     When one collects snippets of Python code that are intended
     to be inserted into programs, a snippet usually would have
     to consist of two parts: One part to be inserted at the top
     of the program, into the imports section, and then the actual
     snippet.
     "__import__" allows to write snippets that can be inserted
     as they are without the need to do insertions at two different
     places. (Possibly with a tool to later normalize the insertions
     to the usual style.)


I'm not sure how that works. In Python, you can just put the imports
where you want them - why would the __import__ function be needed?


import is 'syntactic sugar' for __import__().


And any high-level language is, from a certain point of view, syntactic
sugar for entering the machine-language instructions using the toggle
switches on the front panel. The way that Turing meant for us to do it.


More seriously, it's like creating a class object by

 MyClass = type('MyClass', (), {})

whereas it's far easier (for most of us) to use

 class MyClass( etc )


As well as far easier to comprehend and maintain.


I have no idea what PEP-8 has to say on the subject. However, my coding
style *generally* puts all of the imports up front, right after the
prologue (program description, revision history, uzw).


This is indeed received-wisdom.

However it does not disallow (yuk: double-negative!) coding an import
statement elsewhere, eg a routine which is only executed during some
invocations, but not others.


Hence the emphasized "generally". For instance, one of my programs has
an option to plot its results. If that option is selected, matplotlib is
imported -- way at the end, after all of the number-crunching.

I think that we're in agreement here.


What you may like to consider about "prolog[ue]s" is whether they belong
'in' the code (plenty of arguments 'for') or within the VCS (plenty of
arguments here too)...

eg1: how easy is it to establish when a particular decision/code-change
was made (more than one week ago)? - particularly if changes were
subsequent made 'on top of' that change?

eg2: is it a good idea to use 'Python constants' to display the
program(me) name and (perhaps) a version number on the
terminal/application window?


Such as "%prog"? Or "sys.argv[0]"? Quite useful for help text and
diagnostic messages, with no need to hard-code the program name
into the program. Which would cause confusion if a user wanted to
rename/alias the program.

--
Michael F. Stemper
What happens if you play John Cage's "4'33" at a slower tempo?
--
https://mail.python.org/mailman/listinfo/python-list


Issues with running python in Command prompt

2021-01-16 Thread mohsen shooshtari
hello,
Thanks in advance for your consideration. I install python3.8 and then
install Pycharm but when I call python in Command prompt, followed by
( 'python'
is not recognized as an internal or external command, operable program or
batch file.

what should I do to fix this problem?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: HEKLP

2021-01-16 Thread Grant Edwards
Perhaps once you get your 'K' key fixed it'll work better.

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


Re: Exploring terminfo

2021-01-16 Thread Alan Gauld via Python-list
On 15/01/2021 21:41, Dennis Lee Bieber wrote:
> On Fri, 15 Jan 2021 13:19:26 +, Alan Gauld via Python-list
>  declaimed the following:
> 
>> So the native C functions work as expected.
>> Why does the Python wrapper not?
> 
>   Are you running Python from a plain command shell, or from some sort of
> IDE?

Heh Dennis, you should know I'm strictly a vim and bash man ;-)

-- 
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: Issues with running python in Command prompt

2021-01-16 Thread OmPs
On Sat, 16 Jan 2021, 23:51 mohsen shooshtari, 
wrote:

> hello,
> Thanks in advance for your consideration. I install python3.8 and then
> install Pycharm but when I call python in Command prompt, followed by
> ( 'python'
> is not recognized as an internal or external command, operable program or
> batch file.
>

You need to set the path in your batch file so the batch file knows where
To look for python package. Search in google for setting up path in
baychfile in windows.


> what should I do to fix this problem?
> --
> https://mail.python.org/mailman/listinfo/python-list



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


Re: Issues with running python in Command prompt

2021-01-16 Thread Mats Wichmann

On 1/16/21 8:30 AM, mohsen shooshtari wrote:

hello,
Thanks in advance for your consideration. I install python3.8 and then
install Pycharm but when I call python in Command prompt, followed by
( 'python'
is not recognized as an internal or external command, operable program or
batch file.

what should I do to fix this problem?



Make sure you've read this page.  There turn out to be a number of 
permutations depending on what you installed and how you installed it:


https://docs.python.org/3/using/windows.html
--
https://mail.python.org/mailman/listinfo/python-list


Re: A beginning beginner's question about input, output and . . .

2021-01-16 Thread DonK
On Tue, 12 Jan 2021 09:26:18 +1100, Chris Angelico 
wrote:

>On Tue, Jan 12, 2021 at 7:41 AM DonK  wrote:
>> Hi, I'm thinking about learning Python but I'm 74 years old and will
>> very likely not ever have a programming job again. I used to program
>> in Visual Basic, C\C++, Delphi, etc. and some obscure "mainframe"
>> languages.
>
>BTW, from my experience, there's very very few languages so obscure
>that not one person on this list has heard of them :)
>
>For example, I've used REXX, which is an IBM language found on some of
>the mainframes and also on OS/2, and I'm not the only person here who
>has.
>
>ChrisA

Hi Chris,

The mainframe language that I mentioned was/is? called KwikBasic. I
don't remember if it was all one word or not. It's not to be confused
with Microsoft's QuickBasic.

KwikBasic ran on the Unix OS and was, hands down, the worst
programming experience I've ever had. It was a Y2k fix for the
reservation system of a large Fortune 500 real estate "timeshare"
company. I probably shouldn't say that their name was Trendswest.

The update had to be completed by the end of October 1998 because they
would start taking reservations for 2000 in Nov, 1998. They hired me
to manage the "reservation" part of their Y2k update in the Summer.
(YES! It was late.)

It turned out that KwikBasic was VERY much like the other versions of
basic that I had used. Including MSDOS's QuickBasic and PDS. The two
nutty things about it were that it had only 2 data types, if I
remember corectly they were called number and string.

The worst thing was that there was just one directory that contained
2,702 source files (I'll never forget that number) with names like
217h9436. There was no index to tell you what 217h9436 was, what it
did, what part of the business it pertained to . . . nothing. There
was also no notation in the files. You just had to open each one of
them, read their code to find out what they did.

Also, we had Windows computers on our desks with MS Office installed
but the nearest computer that could run Kwikbasic was their UNIX
mainframe in the main buildings about .25 to .50 miles away. We were
supposed to write code at our desk with Windows Notepad and then, on
Fridays,  the IT manager would take our code over to compile it and
would let us know of any error codes. They said they were going to buy
some expensive workstation for our office, that would run RedHat,
which they were told would then run Kwikbasic. IDunno!

It would have been impossible to do the job as the IT mgr (Mike W.)
envisioned it but I was able to write some simple MS Office code that
searched all the source code files, in just a minute or 2, for any
reference to "Date" functions. As I recall, there weren't that many.

Anyway, Mike W. was a fool that spent all day, every day, screaming
about, mostly, politics. I wound up quitting iafter less than 2 weeks.

Thanks for replying and sorry for the long message.

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


Re: A beginning beginner's question about input, output and . . .

2021-01-16 Thread DonK
On Mon, 11 Jan 2021 21:56:48 -0800, Paul Rubin
 wrote:

>DonK  writes:
>> My problem is that I don't understand how Python programs are
>> used. (i.e user input and output) Is Python mainly used for backends?
>> I've seen some Python gui frameworks like Tkinter, PyQt, etc
>
>I would say at least for me, the i/o to my python programs tends to be
>be either files or network sockets.  I've written some fairly complex
>tkinter apps in the past, but these days, desktop GUI's almost seem like
>a 1990s thing.  If you want an interactive program, either it's a mobile
>app (Python is not so great at that, though see kivy.org) or a web app
>(so the user interacts with it through a browser).
>
>> So, what do you folks use Python for?
>
>Pretty much everything unless a) it's someone else's application written
>in another language so I have to use the other language; b) I need raw
>performance (C, C++) or some other specialized feature; or c) I want to
>get more practice with some other language (quite a few).
>
>> if the titlebar contains certain strings
>
>Yeah this sounds like a Windows thing.  I don't have any idea what it
>takes to make those Windows calls in Python since I'm mostly a Un*x
>programmer.

Yes, Windows. Iterating open windows with the Window's API is easy the
hard (very hard) part is sending keystrokes to those windows to Save
them. It's very tricky because the timing is critical. 

You have to use one of those "spy" utilities to get the name and
classid for the controls that you want to send a command to, then use
the Window's API functions SendMessage or PostMessage to send the
message directly to the control or just put it in the message que.
 
Like sending an "s" to the File menu to (S)ave. It's more complicated
than you would think and it doesn't work very well. It's like pushing
on a string. 


>
>> I know that Python is a very popular language so I'm sorry if it
>> sounds like I'm being critical. I really don't know enough about it to
>> be critical.
>
>If you're familiar with Javascript or Visual Basic, my impression is
>that Python is at about the same level, but with a (for me) subjectively
>cleaner style.  It doesn't have a static type system or a lot of
>boilerplate, so it's easy to bang out small scripts; but the compiler
>doesn't supply much long range error checking, so you have to be pretty
>devoted to test automation if you're doing anything sizeable.  There is
>now a syntax for optional type annotations in Python, and a tool called
>mypy for checking types based on the annotations.  The Python compiler
>itself ignores the annotations.  I've been using them and like them.


Hi Paul,

I doubt that I'll be doing anything sizeable, mostly just a little
learning and entertainment with an occasional small utility once in a
while. But, who knows?

For example, I've found a need to parse text documents quite a number
of times over the years. Basic/VB is great at doing that. How's
Python?


Thanks,

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


Re: A beginning beginner's question about input, output and . . .

2021-01-16 Thread 2QdxY4RzWzUUiLuE
On 2021-01-16 at 15:42:44 -0500,
DonK  wrote:

> Yes, Windows. Iterating open windows with the Window's API is easy the
> hard (very hard) part is sending keystrokes to those windows to Save
> them. It's very tricky because the timing is critical. 
> 
> You have to use one of those "spy" utilities to get the name and
> classid for the controls that you want to send a command to, then use
> the Window's API functions SendMessage or PostMessage to send the
> message directly to the control or just put it in the message que.
>  
> Like sending an "s" to the File menu to (S)ave. It's more complicated
> than you would think and it doesn't work very well. It's like pushing
> on a string. 

Then don't do that?  ;-)

I'm no Windows expert (nor even a user), but do those applications have
a scripting interface?  (DDE?  OLE?  COM?  Do those letters ring a bell?
The right bell?  Are those technologies current?)  What you're trying to
do sounds like working *against* those applications rather than with
them.

> For example, I've found a need to parse text documents quite a number
> of times over the years. Basic/VB is great at doing that. How's
> Python?

Python can do that.  Can you expand on "parse" and "text documents"?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A beginning beginner's question about input, output and . . .

2021-01-16 Thread DonK
On Tue, 12 Jan 2021 10:16:47 +0400, Abdur-Rahmaan Janhangeer
 wrote:

>Greetings,
>
>Web with Python is really easy to get started with, here
>is a simple endpoint with a framework called Flask
>
>from flask import Flask
>app = Flask(__name__)
>
>@app.route('/')
>def hello_world():
>   return 'Hello World’
>
>if __name__ == '__main__':
>   app.run()
>
>As for Tkinter, it's really annoying.
>PyQt5 and others are a lot better.
>PyQt5 follows the Cpp function namings
>
>Kind Regards,
>
>Abdur-Rahmaan Janhangeer

Someone else also suggested a web interface for i/o. If I get that far
it seems like it will be something I'll need to take a look at.

A lot of my early programming was command line BASIC apps running on
MSDOS. Even some pretty BIG stuff. So, going back to that after 40+
years seems a little weird. :-)

I looked at some Youtube videos about creating mobile apps with Java
but that just didn't do it for me. As far as I've seen there isn't
really a way to do the small "ad hoc" type of utilities on a
smartphone that you can do on a desktop machine.

Don't get me wrong, I love my smartphone.  

Thanks, 

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


Re: A beginning beginner's question about input, output and . . .

2021-01-16 Thread DonK
On Sat, 16 Jan 2021 14:56:37 -0600, 2qdxy4rzwzuui...@potatochowder.com
wrote:

>On 2021-01-16 at 15:42:44 -0500,
>DonK  wrote:
>
>> Yes, Windows. Iterating open windows with the Window's API is easy the
>> hard (very hard) part is sending keystrokes to those windows to Save
>> them. It's very tricky because the timing is critical. 
>> 
>> You have to use one of those "spy" utilities to get the name and
>> classid for the controls that you want to send a command to, then use
>> the Window's API functions SendMessage or PostMessage to send the
>> message directly to the control or just put it in the message que.
>>  
>> Like sending an "s" to the File menu to (S)ave. It's more complicated
>> than you would think and it doesn't work very well. It's like pushing
>> on a string. 
>
>Then don't do that?  ;-)
>
>I'm no Windows expert (nor even a user), but do those applications have
>a scripting interface?  (DDE?  OLE?  COM?  Do those letters ring a bell?
>The right bell?  Are those technologies current?)  What you're trying to
>do sounds like working *against* those applications rather than with
>them.

No! I've used the interfaces that you mentioned (OLE and COM in
particular) but that was for apps that I, or my colleagues, wrote (for
an employer) "to expose their guts" many years ago. I've found few
general use Windows apps that support any form of scripting. MS Office
apps, famously, support OLE. Or they used to. My copy of Office is
2007 so I don't know about the newer versions. I think most of those
technologies might have died a long time ago but I could be entirely
wrong. Does Python use those methods to control Excel, etc??

There was a Windows Usenet app, that I was interested in, around 10,
maybe 20 years ago that exposed a Pascal language like interface but
there was no documentation and no support. I believe it only lasted a
short time. I'm pretty sure that it's name started with a "D". It
doesn't matter.

I tried the method that I described above with the Forte Agent
newsreader back in the dial-up days because people in one of the
programming newsgroups wanted to be able to upload/dowanload
(unattended) in the middle of the night. It might have been possible
to get it to work reliably but I gave up on it.

>
>> For example, I've found a need to parse text documents quite a number
>> of times over the years. Basic/VB is great at doing that. How's
>> Python?

>
>Python can do that.  Can you expand on "parse" and "text documents"?

There's nothing that I have any particular need for at the moment but
it is something that I've done a number of times over the years. I
think it's a common need?? 

I've used Pascal and BASIC\VB for string parsing and BASIC\VB is much
better. VB has all the string handling functions that you need built
in but, for example, Pascal has some but you have to create others to
be useful. Since I'm just beginning with Python I have no knowledge or
criticism of how Python does this but I'm sure that it can.

Since I've retired I've written parsers for my bank records, medical
records and other personally useful things. I would categorize them as
trivial but useful.  i.e utility means useful

When I was working, in the 1999-2001 range, I wrote a parser in VB
that unscrambled corrupted "batch files" for credit card processing so
that vendors didn't have to spend hours rebuilding them by hand. Some
of those files had over 700 credit card transactions in them. That's
one example.

I'm looking forward to learning some Python, mostly for fun, but I'm
sure that it will also be useful.


Thank you

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


Re: Exploring terminfo

2021-01-16 Thread Greg Ewing

On 16/01/21 4:17 pm, Chris Angelico wrote:

But somewhere along the way, you're finding that there's a problem,
which implies that SOMETHING is calling on C stdio. That thing,
surely, should be the thing responsible for flushing?


The C library using stdio has no way of knowing that something
else (e.g. Python) is bypassing stdio. That's an unusual thing
to do in the C world, so you can't really blame the authors
of the library for failing to anticipate it.

It's also unreasonable to expect a C library to flush after
every write, as that would defeat the purpose of stdio buffering.

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


Python not Running

2021-01-16 Thread Logan Cranford
I downloaded Python but when I try to run Idle it says it is not found and
I should try to redownload it. When I try to do that all that comes up is a
page that says modify, repair or uninstall. I have repaired several times
but it still gives me the same message. Can anyone  help me with this?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exploring terminfo

2021-01-16 Thread Chris Angelico
On Sun, Jan 17, 2021 at 10:36 AM Greg Ewing  wrote:
>
> On 16/01/21 4:17 pm, Chris Angelico wrote:
> > But somewhere along the way, you're finding that there's a problem,
> > which implies that SOMETHING is calling on C stdio. That thing,
> > surely, should be the thing responsible for flushing?
>
> The C library using stdio has no way of knowing that something
> else (e.g. Python) is bypassing stdio. That's an unusual thing
> to do in the C world, so you can't really blame the authors
> of the library for failing to anticipate it.
>
> It's also unreasonable to expect a C library to flush after
> every write, as that would defeat the purpose of stdio buffering.
>

This is true. However, at some point, the boundary is crossed from
Python into the C library. Something, at that point, knows. It's very
common to have a flush option available, so it should be used.

It's extremely uncommon for Python to call into C code that (a) uses C
stdio, (b) shares the file handle with something else (eg
stdout/stderr), and (c) doesn't have an option to flush its output.
And when that happens, I would consider it a bug, not just because of
the shared handle - if you're piping the output into something else,
you might need to force it to flush its buffer.

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


Re: Exploring terminfo

2021-01-16 Thread Greg Ewing

On 17/01/21 12:40 pm, Chris Angelico wrote:

This is true. However, at some point, the boundary is crossed from
Python into the C library. Something, at that point, knows. It's very
common to have a flush option available, so it should be used.


I'm wondering whether the problem in this particular case stems
from trying to use parts of curses without initialising it
properly. I expect that initialising curses would put stdout
into some kind of unbuffered mode, and the rest of it assumes
that this has been done.

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


Re: Exploring terminfo

2021-01-16 Thread Chris Angelico
On Sun, Jan 17, 2021 at 11:06 AM Greg Ewing  wrote:
>
> On 17/01/21 12:40 pm, Chris Angelico wrote:
> > This is true. However, at some point, the boundary is crossed from
> > Python into the C library. Something, at that point, knows. It's very
> > common to have a flush option available, so it should be used.
>
> I'm wondering whether the problem in this particular case stems
> from trying to use parts of curses without initialising it
> properly. I expect that initialising curses would put stdout
> into some kind of unbuffered mode, and the rest of it assumes
> that this has been done.
>

I'm not familiar with the curses module, but that sounds extremely plausible.

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


Re: count consecutive elements

2021-01-16 Thread Dan Stromberg
On Thu, Jan 14, 2021 at 2:01 PM Wolfram Hinderer via Python-list <
python-list@python.org> wrote:

> Am 13.01.2021 um 22:20 schrieb Bischoop:
> > I want to  to display a number or an alphabet which appears mostly
> > consecutive in a given string or numbers or both
> > Examples
> > s= ' aabskaaabad'
> > output: c
> > # c appears 4 consecutive times
> >   8bbakebaoa
> > output: b
> > #b appears 2 consecutive times
> >
> >
> You can let itertools.groupy find the groups.
>
> max((len(tuple(group)), key) for key, group in itertools.groupby(s))
> # (4, 'c')
>

Does anyone else find the documentation on itertools.groupby kind of
lacking?

I think it makes sense now that I've played around with it though.

Here's a revised solution:
  def get_longest(string: str) -> typing.Tuple[int, typing.List[str]]:
  """Get the longest run of a single consecutive character."""
  if not string:
  return (0, [])
  grouped = itertools.groupby(string)
  grouped_with_lengths = [(len(list(value)), key) for key, value in
grouped]
  max_count_and_letter = max(grouped_with_lengths)
  max_count = max_count_and_letter[0]
  result = (max_count, sorted(list_ for count, list_ in
grouped_with_lengths if count == max_count))
  return result
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exploring terminfo

2021-01-16 Thread Eryk Sun
On 1/16/21, Greg Ewing  wrote:
> On 17/01/21 12:40 pm, Chris Angelico wrote:
>> This is true. However, at some point, the boundary is crossed from
>> Python into the C library. Something, at that point, knows. It's very
>> common to have a flush option available, so it should be used.
>
> I'm wondering whether the problem in this particular case stems
> from trying to use parts of curses without initialising it
> properly. I expect that initialising curses would put stdout
> into some kind of unbuffered mode, and the rest of it assumes
> that this has been done.

The buffering mode cannot be changed for an in-use stream: "setvbuf()
... may be used only after opening a stream and before any other
operations have been performed on it". So it would have to open a new
stream, which can only be done legitimately by device or file name via
C freopen(). Code that overwrites the FILE record (e.g. *stdout =
*stream) is not legitimate and cross-platform.

You can force the interpreter to change stdout to unbuffered mode at
startup via `-u` or the PYTHONUNBUFFERED environment variable. In
Linux, there's also the `stdbuf` command (e.g. stdbuf -o0 python
), which uses an LD_PRELOAD hook to inject a shared library that
calls setvbuf() at process startup. There's no analog to that in
Windows for various reasons.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A beginning beginner's question about input, output and . . .

2021-01-16 Thread 2QdxY4RzWzUUiLuE
On 2021-01-16 at 17:46:13 -0500,
DonK  wrote:

> On Sat, 16 Jan 2021 14:56:37 -0600, 2qdxy4rzwzuui...@potatochowder.com
> wrote:
> 
> >On 2021-01-16 at 15:42:44 -0500,
> >DonK  wrote:

> >> For example, I've found a need to parse text documents quite a number
> >> of times over the years. Basic/VB is great at doing that. How's
> >> Python?
> 
> >
> >Python can do that.  Can you expand on "parse" and "text documents"?
> 
> There's nothing that I have any particular need for at the moment but
> it is something that I've done a number of times over the years. I
> think it's a common need?? 

Indeed.  :-)  In my experience, "parse" and "text documents" often mean
different things to different people.

> I've used Pascal and BASIC\VB for string parsing and BASIC\VB is much
> better. VB has all the string handling functions that you need built
> in but, for example, Pascal has some but you have to create others to
> be useful. Since I'm just beginning with Python I have no knowledge or
> criticism of how Python does this but I'm sure that it can.
> 
> Since I've retired I've written parsers for my bank records, medical
> records and other personally useful things. I would categorize them as
> trivial but useful.  i.e utility means useful
> 
> When I was working, in the 1999-2001 range, I wrote a parser in VB
> that unscrambled corrupted "batch files" for credit card processing so
> that vendors didn't have to spend hours rebuilding them by hand. Some
> of those files had over 700 credit card transactions in them. That's
> one example.

Sounds like you're parsing files composed of lines of plain text where
each line represents some kind of record (as opposed to parsing a
document containing programming code as a precursor to generating an
executable, or looking through a word processing document for something
important).

A bare minimum skeleton might look something like this:

with open(filename) as f:
for line in f.readlines():
handle_one_line(f)

Python has a capable string type for handling text; see
.

Or look into the fileinput module for a convenient way to run through a
collection of files and/or standard input.

> I'm looking forward to learning some Python, mostly for fun, but I'm
> sure that it will also be useful.

Absolutely!  :-)

Happy Hacking!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python not Running

2021-01-16 Thread Terry Reedy

On 1/16/2021 3:55 PM, Logan Cranford wrote:

I downloaded Python but when I try to run Idle it says it is not found and


From where? try how? what is 'it'?
Read the section of
https://docs.python.org/3/using/index.html
appropriate for your system, likely Windows.


I should try to redownload it. When I try to do that all that comes up is a
page that says modify, repair or uninstall. I have repaired several times


This sounds like you are rerunning the python installer, not python 
itself.  Doing the latter depends on how you installed.  Read the doc.



but it still gives me the same message. Can anyone  help me with this?

You can also read answers to similar posts at
https://mail.python.org/pipermail/python-list/


--
Terry Jan Reedy

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


Using plotly and getting "This site can't be reached"

2021-01-16 Thread Chuck Untulis
The Chrome browser on the machine shows "127.0.0.1 refused to connect" for
various urls of the form 127.0.0.1:x where x are numbers like
64981, 65029,... About once in 20-40 attempts, the graphs appear.

I ran the same code on a different machine and it created the plots in the
Chrome browser every time. I ran a different Python plotly program on both
machines with similar results.

Everything else I navigate to in Chrome works as expected.

No errors are reported by the plotly code shown below. I also ran the code
in Visual Studio Code with the same results.

I would like to see the information sent to the browser but I have not
figured out how to do that yet.

Any help would be appreciated.

=
import pandas as pd

df = pd.DataFrame({
  "Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
  "Contestant": ["Alex", "Alex", "Alex", "Jordan", "Jordan", "Jordan"],
  "Number Eaten": [2, 1, 3, 1, 3, 2],
})

import plotly.express as px

fig = px.bar(df, x="Fruit", y="Number Eaten", color="Contestant", barmode=
"group")

#print(""PLOT 1")
# fig.show()

import plotly.graph_objects as go

fig = go.Figure()
for contestant, group in df.groupby("Contestant"):
fig.add_trace(go.Bar(x=group["Fruit"], y=group["Number Eaten"], name
=contestant,
  hovertemplate="Contestant=%sFruit=%%{x}Number Eaten=%%{y}
"% contestant))
fig.update_layout(legend_title_text = "Contestant")
fig.update_xaxes(title_text="Fruit")
fig.update_yaxes(title_text="Number Eaten")
print("PLOT 2")
fig.show()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A beginning beginner's question about input, output and . . .

2021-01-16 Thread Terry Reedy

On 1/16/2021 9:17 PM, 2qdxy4rzwzuui...@potatochowder.com wrote:


A bare minimum skeleton might look something like this:

 with open(filename) as f:
 for line in f.readlines():
 handle_one_line(f)


f.readlines() reads the entire file into a list of lines (strings).  If 
you do not need that,

for line in f:
is sufficient for iterating thru the file line by line.

--
Terry Jan Reedy

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