Seeking Assistance with Python's IDLE for Blind Users
Dear Python Users Group, I am currently learning Python. I am blind and use the JAWS screen reader to assist me. I am trying to use Python's IDLE editor but find it quite challenging. When I move my cursor to a line of code, it reads out the letters or words from the line above, which makes it very difficult to edit the code accurately. I am reaching out to see if anyone knows how to configure IDLE to call out the letters or words that the cursor is actually on. Additionally, I have searched extensively online but have not been able to find any documentation specifically designed for blind users on how to effectively use Python's IDLE. Any guidance or resources you could provide would be greatly appreciated. Thank you for your assistance. Best regards, Jeff -- https://mail.python.org/mailman/listinfo/python-list
Re: FileNotFoundError thrown due to file name in file, rather than file itself
On 11Nov2024 18:24, [email protected] wrote: Loris Bennett wrote at 2024-11-11 15:05 +0100: I have the following in my program: try: logging.config.fileConfig(args.config_file) config = configparser.ConfigParser() config.read(args.config_file) if args.verbose: print(f"Configuration file: {args.config_file}") except FileNotFoundError: print(f"Error: configuration file {args.config_file} not found. Exiting.") Do not replace full error information (including a traceback) with your own reduced error message. If you omit your "try ... except FileNotFoundError` (or start the `except` clause with a `raise`), you will learn where in the code the exception has been raised and likely as well what was not found (Python is quite good with such error details). Actually, file-not-found is pretty well defined - the except action itself is fine in that regard. [...] 2. In terms of generating a helpful error message, how should one distinguish between the config file not existing and the log file not existing? Generally you should put a try/except around the smallest possible piece of code. So: config = configparser.ConfigParser() try: config.read(args.config_file) except FileNotFoundError as e: print(f"Error: configuration file {args.config_file} not found: {e}") This way you know that the config file was missing. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: FileNotFoundError thrown due to file name in file, rather than file itself
On 12/11/24 10:17, Cameron Simpson via Python-list wrote: On 11Nov2024 18:24, [email protected] wrote: Loris Bennett wrote at 2024-11-11 15:05 +0100: I have the following in my program: try: logging.config.fileConfig(args.config_file) config = configparser.ConfigParser() config.read(args.config_file) if args.verbose: print(f"Configuration file: {args.config_file}") except FileNotFoundError: print(f"Error: configuration file {args.config_file} not found. Exiting.") My questions are: 1. Should I be surprised by this behaviour? No. Python has behaved as-programmed. 2. In terms of generating a helpful error message, how should one distinguish between the config file not existing and the log file not existing? Generally you should put a try/except around the smallest possible piece of code. So: config = configparser.ConfigParser() try: config.read(args.config_file) except FileNotFoundError as e: print(f"Error: configuration file {args.config_file} not found: {e}") This way you know that the config file was missing. Augmenting @Cameron's excellent advice: please research "Separation of Concerns", eg https://en.wikipedia.org/wiki/Separation_of_concerns (which overlaps with one interpretation of SOLID's "Single Responsibility Principle" and the *nix philosophy of "do one thing, and do it well"). If you were to explain the code-snippet in English (or ...) it has several parts/concerns: - configure the log - instantiate ConfigParser() - read the env.file - advise verbosity-setting - handle file-error - (and, but not appearing) terminate execution A block of code (see indentation for rough definition of "block") should achieve one thing ("concern"). Thus, the advice to separate-out the file-read and attendant defensive-coding. This anticipates the problem (2) of distinguishing the subject of any one error/stack-trace from any others - and, arguably, makes the code easier to read. -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list
Re: FileNotFoundError thrown due to file name in file, rather than file itself
On Tue, 12 Nov 2024 at 01:59, Loris Bennett via Python-list wrote: > 2. In terms of generating a helpful error message, how should one >distinguish between the config file not existing and the log file not >existing? By looking at the exception's attributes rather than assuming and hard-coding the path in your message? Or, even better, just let the exception bubble. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Seeking Assistance with Python's IDLE for Blind Users
Dear Jeff, writes: > Dear Python Users Group, > > > > I am currently learning Python. I am blind and use the JAWS screen reader to > assist me. I am trying to use Python's IDLE editor but find it quite > challenging. When I move my cursor to a line of code, it reads out the > letters or words from the line above, which makes it very difficult to edit > the code accurately. > > > > I am reaching out to see if anyone knows how to configure IDLE to call out > the letters or words that the cursor is actually on. Additionally, I have > searched extensively online but have not been able to find any documentation > specifically designed for blind users on how to effectively use Python's > IDLE. > > > > Any guidance or resources you could provide would be greatly appreciated. > > > > Thank you for your assistance. > > > > Best regards, > > Jeff > I can't make any suggestions regarding IDLE as I don't use it. I also have the impression that most people, rather than IDLE, use some other form of IDE or editor. So it might be worth looking for more generally programming environments with appropriate support. I personally use Emacs for many activities, including programming in Python. On various Emacs-related mailing lists I have come across blind and visually impaired people, most of whom I assume are using Emacsspeak https://emacspeak.sourceforge.net/ which has been around for 30 years, so that may be worth having a look at. Cheers, Loris -- This signature is currently under constuction. -- https://mail.python.org/mailman/listinfo/python-list
SOLVED: Tkinter button-motion event behaves differently under Windows and Linux
I'm posting this in case anyone else encounters the same problem, and
to ask for suggestions, if any, about a better way to do it.
I'm implementing a method for dragging embedded widgets on a Text
widget. When the left mouse button is held down over an embedded widget
and the mouse is dragged across other widgets embedded in the same
parent, the original widget moves to the new positions until the button
is released.
Here's some minimal code:
---
from tkinter import *
text = Text(Tk())
text.pack()
def drag(e):
print(e.widget)
target = e.widget.winfo_containing(e.x_root, e.y_root)
if target and target not in (text, e.widget):
if text.compare(target, '>', e.widget):
target = f'{target} + 1 char'
text.window_create(target, window=e.widget)
for n in ('1', '2', '3'):
l=Label(text, text=n, width=10)
#l.bind('', lambda e:e.widget.grab_set())
l.bind('', drag)
#l.bind('', lambda e:e.widget.grab_release())
text.window_create(END, window=l)
mainloop()
---
This works as intended for me on Windows (11). The print statement
always shows the name of the first selected widget while the button is
held down, regardless of where the mouse is dragged to.
But on Linux (Debian testing with Gnome), for me the above code only
moves the widget to the first new position it is dragged to, any
further dragging is ineffective, and the print statement shows the
names of the subsequently-traversed widgets.
There is a further issue in the real code (not shown here) also on
Linux only, where if the cursor traverses any other widgets bound to
'', they are also triggered, which is not intended.
Just a guess, but it seems that on Linux, the focus switches to
whatever widget is under the cursor even during dragging, so any
bindings on the originally-clicked widget are no longer triggered,
whereas Windows maintains focus on the originally-clicked widget during
dragging until the button is released.
If that's the case (and I never thought I'd say this), I think Windows
is right! But for all I know it might be the window manager or
something else.
I eventually figured out that the commented lines calling grab_set and
grab_release solved the issue for me on Linux.
I haven't found this documented anywhere and I'm interested to know if
anyone can cast any light on it.
Thanks
--
https://mail.python.org/mailman/listinfo/python-list
FileNotFoundError thrown due to file name in file, rather than file itself
Hi,
I have the following in my program:
try:
logging.config.fileConfig(args.config_file)
config = configparser.ConfigParser()
config.read(args.config_file)
if args.verbose:
print(f"Configuration file: {args.config_file}")
except FileNotFoundError:
print(f"Error: configuration file {args.config_file} not found.
Exiting.")
sys.exit(0)
and when I ran the program I got the error
Error: configuration file /usr/local/etc/sc_mailer not found. Exiting.
However, this file *does* exist and *can* be read. By checking the
'filename' attribute of the exception I discovered that the problem was
the log file defined *in* the config file, namely
[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=defaultFormatter
args=('/var/log/my_prog.log', 'a')
This log file did not exist. The exception is thrown by
logging.config.fileConfig(args.config_file)
My questions are:
1. Should I be surprised by this behaviour?
2. In terms of generating a helpful error message, how should one
distinguish between the config file not existing and the log file not
existing?
Cheers,
Loris
--
This signature is currently under constuction.
--
https://mail.python.org/mailman/listinfo/python-list
Re: FileNotFoundError thrown due to file name in file, rather than file itself
Poor error reporting is a very common problem in programming. Python
is not anything special in this case. Of course, it would've been
better if the error reported what file wasn't found. But, usually
these problems are stacking, like in your code. Unfortunately, it's
your duty, as the language user, to anticipate those problems and act
accordingly. Now you've learned that the one file you believe that
could be the source for the error isn't the only one--well, adjust
your code to differentiate between those two (and potentially other?)
cases. There's very little else you can do beside that.
NB. On the system level, the error has no information about what file
wasn't found. It simply returns some numeric value (the famous
ENOENT) in case when the system call to open a file fails. Python
could've been more helpful by figuring out what path caused the
problem and printing that in the error message, but it doesn't...
That's why I, myself, never use the vanilla FileNotFoundError, I
always re-rise it with a customized version that incorporates the
information about the missing file in the error message.
NB2. It's always a bad idea to print logs to files. Any sysadmin /
ops / infra person worth their salt will tell you that. The only
place the logs should go to is the standard error. There are true and
tried tools that can pick up logs from that point on, and do with them
whatever your heart desires. That is, of course, unless you are
creating system tools for universal log management (in which case, I'd
question the choice of Python as a suitable language for such a task).
Unfortunately, even though this has been common knowledge for decades,
it's still elusive in the world of application development :|
On Mon, Nov 11, 2024 at 4:00 PM Loris Bennett via Python-list
wrote:
>
> Hi,
>
> I have the following in my program:
>
> try:
> logging.config.fileConfig(args.config_file)
> config = configparser.ConfigParser()
> config.read(args.config_file)
> if args.verbose:
> print(f"Configuration file: {args.config_file}")
> except FileNotFoundError:
> print(f"Error: configuration file {args.config_file} not found.
> Exiting.")
> sys.exit(0)
>
> and when I ran the program I got the error
>
> Error: configuration file /usr/local/etc/sc_mailer not found. Exiting.
>
> However, this file *does* exist and *can* be read. By checking the
> 'filename' attribute of the exception I discovered that the problem was
> the log file defined *in* the config file, namely
>
> [handler_fileHandler]
> class=FileHandler
> level=DEBUG
> formatter=defaultFormatter
> args=('/var/log/my_prog.log', 'a')
>
> This log file did not exist. The exception is thrown by
>
> logging.config.fileConfig(args.config_file)
>
> My questions are:
>
> 1. Should I be surprised by this behaviour?
> 2. In terms of generating a helpful error message, how should one
>distinguish between the config file not existing and the log file not
>existing?
>
> Cheers,
>
> Loris
>
> --
> This signature is currently under constuction.
> --
> https://mail.python.org/mailman/listinfo/python-list
--
https://mail.python.org/mailman/listinfo/python-list
Re: FileNotFoundError thrown due to file name in file, rather than file itself
Loris Bennett wrote at 2024-11-11 15:05 +0100:
>I have the following in my program:
>try:
>logging.config.fileConfig(args.config_file)
>config = configparser.ConfigParser()
>config.read(args.config_file)
>if args.verbose:
>print(f"Configuration file: {args.config_file}")
>except FileNotFoundError:
>print(f"Error: configuration file {args.config_file} not found.
> Exiting.")
Do not replace full error information (including a traceback)
with your own reduced error message.
If you omit your "try ... except FileNotFoundError`
(or start the `except` clause with a `raise`), you
will learn where in the code the exception has been raised
and likely as well what was not found (Python is quite good
with such error details).
> ...
>My questions are:
>
>1. Should I be surprised by this behaviour?
Your code contains a major weakness (see above); thus surprises
are not unlikely.
>2. In terms of generating a helpful error message, how should one
> distinguish between the config file not existing and the log file not
> existing?
You look at the error information provided by Python
(and its library) rather than hiding it.
--
https://mail.python.org/mailman/listinfo/python-list
