Re: on GNU EMACS's python-mode, loading entire buffer

2022-09-29 Thread Stephen Berman
On Sun, 04 Sep 2022 16:47:07 -0300 Meredith Montgomery  
wrote:

> Meredith Montgomery  writes:
>
>> Meredith Montgomery  writes:
>>
>> [...]
>>
>>> I would also be interested in a command that restarts the REPL afresh
>>> and reloads my buffer --- sort of like keyboard's [F5] of the IDLE.
>>
>> A partial solution for this is the following procedure.
>>
>> (defun python-revert-and-send-buffer-to-repl ()
>>   "Revert current buffer and sends it to the Python REPL."
>>   (interactive)
>>   (revert-buffer "ignore-auto-no" "no-confirm")
>>   (python-shell-send-buffer))
>>
>> We can map this to the F5-key and that improves things.  But a restart
>> of the REPL would be the ideal.  (Sometimes we really want to start
>> afresh.  Sometimes.  Most often we don't want that.)
>
> It's not easy to restart the REPL.  You can send "quit()" to it and
> invoke run-python again interactively by typing out one command after
> another, but if you write a procedure such as this one below, it doesn't
> work: it gives me the impression that there's a timing issue, that is,
> perhaps the procedure is too fast and something happens before it
> should.
>
> (defun python-save-send-buffer-to-repl ()
>   (interactive)
>   (save-buffer)
>   (python-shell-send-string "quit()")
>   (run-python)
>   (python-shell-send-buffer)
>   (python-shell-switch-to-shell))

It does seem like a timing issue.  This works for me:

(defun python-save-send-buffer-to-repl ()
  (interactive)
  (save-buffer)
  (python-shell-send-string "quit()")
  (sit-for 0.1)
  (run-python)
  (python-shell-send-buffer)
  (python-shell-switch-to-shell))

But if I decrease the wait to 0.05 it doesn't work.

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


Re: Trying to read from a text file to generate a graph

2021-07-29 Thread Stephen Berman
[Resending to the list only, since I couldn't post it without subscribing.]

On Wed, 28 Jul 2021 11:58:21 -0400 "Steve"  wrote:

> I forgot about the no-file rule...
>
>> On 28Jul2021 02:55, Steve  wrote:
>> I am going though a struggle with this and just don't see where it
>> fails.  I am using the Dual Bar Graph.py program from
>> https://matplotlib.org/stable/gallery/index.html website.  The file
>> from the web site works so that shows that all my installations are
>> complete.
>>
>> My program, LibreGraphics 05.py program runs but the graph is all
>> smutched up.  I am pulling data from the EXCEL-FILE.txt into the
>> program, selecting three values for each line and creating three
>> variables formatted as is shown in the original demo file.
>>
>> When you run the program, choose 112 when prompted. You will see the
>> values of the variables I want to pass to the graph section of the
>> code.  If the values are hardcoded, the graphs look good.  When the
>> variables generated by my section of the code, it does not.

The problem is due to the values of Sensors, TestStrips and SampleNumber
being strings; what you want is for them to be lists, as in the
assignments you commented out.  And since the data from the file is read
in as strings, you have to cast the elements of the Sensors and
TestStrips lists to integers, since you want the numerical values.  The
following code does the job:

Sensors = []
TestStrips = []
SampleNumber = []

x = 1
SensorNumber = input("Enter senaor number: ")
with open("_EXCEL-FILE.txt", 'r') as infile:
for lineEQN in infile:
if (lineEQN[0:1]== "."):
SN = lineEQN[44:48].strip()
if (SensorNumber == SN):
SN = x
SampleNumber.append(SN)

sv = lineEQN[25:29].strip()
Sensors.append(int(sv))

tv = lineEQN[32:37].strip()
TestStrips.append(int(tv))

x += 1

labels = SampleNumber

Add the rest of your code from the second half to make the desired bar
chart.

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