Re: Is there a way to implement the ** operator on a custom object

2024-02-09 Thread Cameron Simpson via Python-list
s dict, int, str and namedtuple. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: A question about import

2024-02-16 Thread Cameron Simpson via Python-list
rect use in the script you would import it there too: import datetime import A Note that the datetime module is only actually loaded once. The import binds the name into your local namespace like any other variable. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Can one output something other than 'nan' for not a number values?

2024-02-16 Thread Cameron Simpson via Python-list
way with any sort of formatting string or other sort of cleverness? The simplest thing is probably just a function writing it how you want it: def float_s(f): if isnan(f): return "-" return str(f) and then use eg: print(f'value is {float_s(valu

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-05 Thread Cameron Simpson via Python-list
;l1 =", l1) print("outside, x =", x, "l1 =", l1) f1() print("outside after f1, x =", x, "l1 =", l1) f2() print("outside after f2, x =", x, "l1 =", l1) Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference

2024-03-07 Thread Cameron Simpson via Python-list
On 06Mar2024 15:12, Jacob Kruger wrote: So, this does not make sense to me in terms of the following snippet from the official python docs page: https://docs.python.org/3/faq/programming.html "In Python, variables that are only referenced inside a function are implicitly global. If a variable

Re: How to Add ANSI Color to User Response

2024-04-11 Thread Cameron Simpson via Python-list
little module of my own, `cs.ansi_colour`, which you can get from PyPI using `pip`. The two most useful items in it for someone else are probably `colourise` and `colourise_patterns`. Link: https://github.com/cameron-simpson/css/blob/26504f1df55e1bbdef00c3ff7f0cb00b2babdc01/lib/python/cs/ansi

Re: First two bytes of 'stdout' are lost

2024-04-11 Thread Cameron Simpson via Python-list
On 11Apr2024 14:42, Olivier B. wrote: I am trying to use StringIO to capture stdout, in code that looks like this: import sys from io import StringIO old_stdout = sys.stdout sys.stdout = mystdout = StringIO() print( "patate") mystdout.seek(0) sys.stdout = old_stdout print(mystdout.read()) Well

Re: Terminal Emulator

2024-05-14 Thread Cameron Simpson via Python-list
On 14May2024 18:44, Gordinator wrote: I wish to write a terminal emulator in Python. I am a fairly competent Python user, and I wish to try a new project idea. What references can I use when writing my terminal emulator? I wish for it to be a true terminal emulator as well, not just a Tk text

Re: Flubbed it in the second interation through the string: range error... HOW?

2024-05-28 Thread Cameron Simpson via Python-list
On 29May2024 01:14, Thomas Passin wrote: Also, it's 2024 ... time to start using f-strings (because they are more readable than str.format()) By which Thomas means stuff like this: print(f'if block {name[index]} and index {index}') Notice the leading "f'". Personally I wouldn't even go t

Re: Fwd: IDLE: clearing the screen

2024-06-04 Thread Cameron Simpson via Python-list
On 04Jun2024 22:43, Rob Cliffe wrote: import os def cls(): x=os.system("cls") Now whenever you type cls() it will clear the screen and show the prompt at the top of the screen. (The reason for the "x=" is: os.system returns a result, in this case 0.  When you evaluate an expression in the IDE

Re: Suggested python feature: allowing except in context maneger

2024-06-13 Thread Cameron Simpson via Python-list
pport, and doing stuff like merging an `except` with a `wtih` is bound to introduce some weird corner case, complicating its semantics. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Anonymous email users

2024-06-14 Thread Cameron Simpson via Python-list
On 14Jun2024 18:00, avi.e.gr...@gmail.com wrote: I notice that in some recent discussions, we have users who cannot be replied to directly as their email addresses are not valid ones, and I believe on purpose. Examples in the thread I was going to reply to are: henh

Re: Suggested python feature: allowing except in context maneger

2024-06-14 Thread Cameron Simpson via Python-list
On 14Jun2024 09:07, Yair Eshel wrote: Cameron, I'm not really sure I got your point. I've used the "file not found" exception as an example for a behavior typical on context managers. This could be a failure to connect to DB, or threads. It also applies to any kind o

Re: Best use of "open" context manager

2024-07-06 Thread Cameron Simpson via Python-list
On 06Jul2024 11:49, Rob Cliffe wrote: try:     f = open(FileName) as f:     FileLines = f.readlines() except FileNotFoundError:     print(f"File {FileName} not found")     sys.exit() # I forgot to put "f.close()" here -:) for ln in File Lines:         print("I do a lot of processing here")      

Re: Best use of "open" context manager

2024-07-07 Thread Cameron Simpson via Python-list
On 07Jul2024 22:22, Rob Cliffe wrote: Remember, the `open()` call returns a file object _which can be used as a context manager_. It is separate from the `with` itself. Did you test this?     f = open(FileName) as f: is not legal syntax. No. You're right, remove the "as f:". it's legal, but

Re: Best use of "open" context manager

2024-07-07 Thread Cameron Simpson via Python-list
On 07Jul2024 22:22, Rob Cliffe wrote: it's legal, but doesn't work (trying to access the file after "with f" raises the same     ValueError: I/O operation on closed file. Just to this: of course. The with closes the file. But my version runs the with after the try/except. -- https://mail.py

Re: Help needed - - running into issues with python and its tools

2024-08-03 Thread Cameron Simpson via Python-list
On 03Aug2024 16:34, o1bigtenor wrote: So please - - - how do I set up a venv so that I can install and run python 3.12 (and other needed programs related to 3.12) inside? Maybe this github comment will help with this: https://github.com/orgs/micropython/discussions/10255#discussioncomment-444

Re: python3 package import difference?

2024-08-07 Thread Cameron Simpson via Python-list
from dbi import * ModuleNotFoundError: No module named 'dbi' Python 3 imports are absolute (they start from the top of the package tree and you have no `dbi` at the top). You want a relative import i.e.: from .dbi import * Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: python3 package import difference?

2024-08-08 Thread Cameron Simpson via Python-list
On 08Aug2024 21:55, Gilmeh Serda wrote: I guess in a sense Py2 was smarter figuring out what whent where and where it came from. Or it was a bad hack that has been removed. No, Python 2 offered less control. -- https://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] How to stop a specific thread in Python 2.7?

2024-10-03 Thread Cameron Simpson via Python-list
reexisting Event may be supplied. Return a 2-tuple of `(T,E)`. ''' if E is None: E = Event() T = Thread(target=target, args=[E, *a], kwargs=kw) return T, E Something along those lines. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Best Practice Virtual Environment

2024-10-05 Thread Cameron Simpson via Python-list
Just make a shared virtualenv, eg in /usr/local or /opt somewhere. Have the script commence with: #!/path/to/the/shred/venv/bin/python and make it readable and executable. Problem solved. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Printing UTF-8 mail to terminal

2024-11-01 Thread Cameron Simpson via Python-list
On 01Nov2024 08:11, Loris Bennett wrote: Cameron Simpson writes: If you're using the Python email module to parse (or construct) the message as a `Message` object I'd expect that to happen automatically. I am using email.message.EmailMessage Noted. That seems like the correct a

Re: Printing UTF-8 mail to terminal

2024-11-01 Thread Cameron Simpson via Python-list
On 01Nov2024 10:10, Loris Bennett wrote: as expected. The non-UTF-8 text occurs when I do mail = EmailMessage() mail.set_content(body, cte="quoted-printable") ... if args.verbose: print(mail) which is presumably also correct. The question is: What conversion is necessary in order t

Re: TkInter Scrolled Listbox class?

2024-11-04 Thread Cameron Simpson via Python-list
def config(self, *a, **kw): return self.Listbox.config(*a, **kw) and so forth for the various listbox methods you want to proxy to the listbox itself. You could pass scroll specific methods to the scrollbar as well. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/p

Re: Printing UTF-8 mail to terminal

2024-11-05 Thread Cameron Simpson via Python-list
further encoded as quoted printable to avoid ambiguity about the meaning of bytes/octets which have their high bit set. BTW, doesn't this: for k in mail.keys(): print(f"{k}: {mail.get(k)}") print the quoted printable (i.e. not decoded) form of subject lines? Chee

Re: Two python issues

2024-11-05 Thread Cameron Simpson via Python-list
error should be given. There are many many circumstances where we replace a subsequence with a different subsequence of different length. Outlawing such a thing would remove and extremely useful feature. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Printing UTF-8 mail to terminal

2024-11-01 Thread Cameron Simpson via Python-list
On 31Oct2024 21:53, alan.ga...@yahoo.co.uk wrote: On 31/10/2024 20:50, Cameron Simpson via Python-list wrote: If you're just dealing with this directly, use the `quopri` stdlib module: https://docs.python.org/3/library/quopri.html One of the things I love about this list are these l

Re: FileNotFoundError thrown due to file name in file, rather than file itself

2024-11-11 Thread Cameron Simpson via Python-list
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

Re: Printing UTF-8 mail to terminal

2024-10-31 Thread Cameron Simpson via Python-list
n.org/3/library/quopri.html Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How to stop a specific thread in Python 2.7?

2024-09-25 Thread Cameron Simpson via Python-list
if it becomes set. You just need a per-thred vent instead of a single Event for all the threads. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: How to stop a specific thread in Python 2.7?

2024-09-25 Thread Cameron Simpson via Python-list
On 25Sep2024 22:56, marc nicole wrote: How to create a per-thread event in Python 2.7? Every time you make a Thread, make an Event. Pass it to the thread worker function and keep it to hand for your use outside the thread. -- https://mail.python.org/mailman/listinfo/python-list

Re: Bug in 3.12.5

2024-09-20 Thread Cameron Simpson via Python-list
On 20Sep2024 12:52, Martin Nilsson wrote: The attached program doesn’t work in 3.12.5, but in 3.9 it worked. This mailing list discards attachments. Please include your code inline in the message text. Thanks, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list

Re: Python List is Not Dead

2024-12-26 Thread Cameron Simpson via Python-list
On 25Dec2024 14:52, Abdur-Rahmaan Janhangeer wrote: I have been following discussions on Discourse (discuss.python.org) these last times. I think that it definitely lacks some of the joys of the mailing list: FYI, it has a very good "mailing list" mode. I use it that was >90% of the time, a

Re: Python List is Not Dead

2024-12-29 Thread Cameron Simpson via Python-list
On 29Dec2024 07:16, Kevin M. Wilson wrote: Excuse please, my failure. As I have not been following this discussion, why is the subject "Python List Is NOT Dead" a subject for discussion? Has the list been moving towards closing? No, the list's still around. But there was a significant migrat

<    20   21   22   23   24   25