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
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
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())
meone else are probably
`colourise` and `colourise_patterns`. Link:
https://github.com/cameron-simpson/css/blob/26504f1df55e1bbdef00c3ff7f0cb00b2babdc01/lib/python/cs/ansi_colour.py#L96
I particularly use it to automatically colour log messages on a
terminal, example code:
https://github.com/camer
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
)
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
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(value)}')
or whatever fits your code.
Cheers,
Cameron Simpson
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
and
namedtuple.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 08Feb2024 12:21, tony.fl...@btinternet.com wrote:
I know that mappings by default support the ** operator, to unpack the
mapping into key word arguments.
Has it been considered implementing a dunder method for the **
operator so you could unpack an object into a key word argument, and
On 21Jan2024 23:39, bagra...@live.com wrote:
class NameMe(dict):
def __missing__(self, key):
return key
I would need to know more about what it might be used for. What larger
problem led you to writing a `dict` subclass with this particular
`__missing__` implementation?
--
() would accept any kind of mapping
(dicts, etc etc).
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
name)
grades.append(s.finalGrade())
if s.finalGrade()>82:
grades.append("Pass")
else:
grades.append("Fail")
print(grades)
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
/rfc2821#section-4.1.1.6
I think a lot of mail receivers don't honour this one, for exactly the
reasons above.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
URL,please visit it to confirm receipt
of this email (implying email is 'real"). You see this a lot when
signing up for things. And for plenty of things I generate a random
throw away address at mailinator.com (looking at you, every "catch up"
free online TV streaming service who
This message:
NameError: name 'Pnt' is not defined. Did you mean: 'PNT'?
is unfortunate, because you have a very similar "PNT" name in scope. But
it isn't what you want.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 19Oct2023 20:16, Bongo Ferno wrote:
A with statement makes clear that the alias is an alias and is local,
and it automatically clears the variable after the block code is used.
No it doesn't:
>>> with open('/dev/null') as f:
... print(f)
...
<_io.TextIOWrapper
s associated
with `a` and puts that in as the first argument (usually named `self`).
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
of code with many
imports you might go for module1.funcname for clarity, particularly if
funcname is generic or overlaps with another similar imported name.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 07Aug2023 08:02, Barry wrote:
On 7 Aug 2023, at 05:28, Cameron Simpson via Python-list
wrote:
Used to use a Pascal compiler once which was uncannily good at
suggesting where you'd missing a semicolon.
Was that on DEC VMS? It was a goal at DEC for its compilers to do this well
underlined code?
Is this "clairvoyant" behaviour a side-effect of the new parser or was
that a deliberate decision?
I have the vague impression the new parser enabled the improved
reporting.
Used to use a Pascal compiler once which was uncannily good at
suggesting where yo
kets) and frugal use of the meaning of what values can occur there.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 21Jun2023 10:09, Chris Angelico wrote:
On Wed, 21 Jun 2023 at 09:59, Cameron Simpson via Python-list
wrote:
I wasted some time the other evening on an API which returned a
string
or None. My own API, and the pain it caused tells me that that API
design choice isn't good (it's an automatic
-1 on None acquiring iteration or other features.
Fail early, fail often!
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 24May2023 02:18, Rob Cliffe wrote:
There doesn't seem to be any decent documentation for it anywhere.
Already mentioned in the replies, I use this:
https://tkdocs.com/shipman/index.html
quite a lot.
--
https://mail.python.org/mailman/listinfo/python-list
it is part of the stdlib.
On some platforms eg Ubuntu Linux the stdlib doesn't come in completely
unless you ask - a lot of stdlib packages are apt things you need to ask
for. On my Ubunut here tkinter comes from python3-tk. So:
$ sudo apt-get install python3-tk
Cheers,
Cameron Simpson
On 16May2023 09:26, Alan Gauld wrote:
On 15/05/2023 22:11, Grant Edwards wrote:
I got a nice warning today from the inews utility I use daily:
DeprecationWarning: 'nntplib' is deprecated and slated for removal in
Python 3.13
What should I use in place of nntplib?
I'm curious as to why
ecification:
https://datatracker.ietf.org/doc/html/rfc2047
You should reach for jak's suggested email.header suggestion _before_
parsing the subject line. Details:
https://docs.python.org/3/library/email.header.html#module-email.header
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
0] ] # spaces for clarity
makes a new dataframe with only the first column.
A dataframe can be thought of as an array of Series (one per column).
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
this index:
[1]
which is a list of ints (with just one int).
Have a look at this page:
https://pandas.pydata.org/docs/user_guide/indexing.html
If you suppply a list, it expects a list of labels. Is 1 a valid label
for your particular dataframe?
Cheers,
Cameron Simpson
--
https
of similar situations.
Because of this I usually am prepared to make a missing final component
with mkdir(), but not a potentially deep path with makedirs().
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
... not all directories made ...
2 notes on the above:
- catching Exception, not a bare except (which catches a rather broader
suit of things)
- reporting the other exception
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
e means that what happens to a name when you define the class depends
on the typeof the value bound to the name.
A plain function gets turned into an unbound instance method, but other
things are left alone.
When you went:
__enter__ = int
That's not a plain function and so "obj.__enter__" doesn't turn into a
bound method - it it just `int`.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
ll some package "foo".
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 13Apr2023 03:36, MRAB wrote:
I thought that in Java you can, in fact, concatenate a string and an
int, so I did a quick search online and it appears that you can.
I stand corrected. I could have sworn it didn't, but it has been a long
time. - Cameron Simpson
--
https://mail.python.org
time with Java, being staticly
typed).
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
s.iso14496`
package, which has a full MP4/MOV parser and a hook for getting the
metadata.
Not as convenient as ffprobe, but if you care about the innards...
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
cs/ for my modules, which are all named "cs.*" (avoids
conflict). But that's just me.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
://github.com/cameron-simpson/css/blob/0ade6d191833b87cab8826d7ecaee4d114992c45/lib/python/cs/timeseries.py#L2163
But it would be easy to give that class `__lt__` etc methods.
You're welcome to use it, or anything from the module (it's on PyPI).
Cheers,
Cameron Simpson
--
https://mail.python.org
On 30Mar2023 10:13, Cameron Simpson wrote:
I do in fact have a `TimePartition` in my timeseries module; it
presently doesn't do comparisons because I'm not comparing them - I'm
just using them as slices into the timeseries data on the whole.
https://github.com/cameron-simpson/css/blob
not sure I understand Loris' other requirements though. It might be
hard to write a general thing which was also still useful.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 27Mar2023 12:03, Cameron Simpson wrote:
On 27Mar2023 01:53, Jen Kris wrote:
But that brings up a new question. I can create a class instance with
x = BinaryConstraint(),
That makes an instance of EqualityConstraint.
Copy/paste mistake on my part. This makes an instance
ens you full control to sompletely
replace some superclass' init with a custom one. By calling
super().__init__() we're saying we not replacing that stuff, we're
running the old stuff and just doing something additional for our
subclass.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
e
".__mro__" field on the new class (EqualityConstraint). You can look at
it directly as "EqualityConstraint.__mro__".
So looking up:
self.choose_method()
looks for a "choose_method" method on the classes in
"type(self).__mro__".
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
call to `sys.exit()` is right at the bottom.
Everything else is just regularfunction returns.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
imported.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
ou read it.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 09Mar2023 17:55, aapost wrote:
On 3/9/23 16:37, Cameron Simpson wrote:
Just a note that some code formatters use a trailing comma on the last
element to make the commas fold points. Both yapf (my preference) and
black let you write a line like (and, indeed, flatten if short
enough
it on if available.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
call some module method to fetch the next user-entered line.
You call the input() built-in.
Ah. That's not overtly stated? [...reads...] Ah, there it is in the last
sentence of the opening paragraph. Not quite as in-your-face as I'd have
liked it. That paragraph could do with being a bullet li
,
)
in varying flavours of indentation depending on tuning. The point being
that if, like me, you often have a code formatter active-on-save it can
be hinted to nicely present complex tuples (or parameter lists and
imports).
It isn't magic, but can be quite effective.
Cheers,
Cameron Simpson
, expr)[-1]
to embed some debug tracing in a lambda defined expression.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
an "event", and
the GUI mainloop will process that as it happens - the event callback
will be fired (called) by the main loop itself and thus the callback
gets to do its thing in the main loop.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
to a stream (eg a TCP connection):
https://github.com/cameron-simpson/css/blob/00ab1a8a64453dc8a39578b901cfa8d1c75c3de2/lib/python/cs/packetstream.py#L624
Starting at line 640: `if Q.empty():` it optionally pauses briefly to
see if more packets are coming on the source queue. If another arrives
by design something is hanging on to a
file while it is waiting for something, then a crash occurs, they lose
a portion of what was assumed already complete...
f.flush()
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
string. You want r0.search(s).
- Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
the other quote character.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 28Feb2023 12:54, Greg Ewing wrote:
I guess this means I can't use Black. :-(
Black's treatment of quotes and docstrings is one of the largest reasons
why I won't let it touch my personal code. yapf is far better behaved,
and can be tuned as well!
Cheers,
Cameron Simpson
--
https
ng
language (eg sed vs awk vs shell vs python in loose order of problem
difficulty), but it applies also to choosing tools within a language.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
is actually working with, instead of what you
thought it was working with.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
ust something to
keep in mind.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
ed_ string, not a
pattern/regexp. So why on earth are you using regexps to do your
searching?
The `str` type has a `find(substring)` function. Just use that! It'll be
faster and the code simpler!
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
absolute path used to index a `TaggedPath` instance.
This returns `realpath(fspath)` if `self.config.physical`,
otherwise `abspath(fspath)`.
'''
return realpath(fspath) if self.config.physical else abspath(fspath)
You can stack the decorators just like deal.
Cheers,
Ca
(wink,wink)
type suggestions
There are several type checking programs for Python, with mypy probably
being the best known. I seem to recall seeing some mention of tools
which will aid inferring types from partially types programmes, usually
as an aid to completing the type annotations.
t a class attribute.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 21Feb2023 18:00, Hen Hanna wrote:
what editor do you (all) use to write Python code? (i use Vim)
vim
--
https://mail.python.org/mailman/listinfo/python-list
_paren = True
split_before_first_argument = True
split_before_logical_operator = True
split_complex_comprehension = True
use_tabs = False
So basicly PEP8 with some tweaks.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
in range(10) )
which makes a tuple from an iterable (such as a list, but anything
iterable will do). Here the iterable is the generator expression:
x for x in range(10)
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
different linters (via a script named "lint") and turn off
quite a few of the `pycodestyle` checks, `E114` included.
`pycodestyle` doesn't clean any special "authority", and exlicitly
offers ways to turn off whichever checks you find unsuitable to your
code.
Cheers,
Camer
roadly has the same purpose as this mailing list. I use both, and use
Discourse in email mode - the forum's there, but >90% of my interaction
is via email - I file it and python-list to the same "python" folder
here and lossely treat them the same.
Cheers,
Cameron Simpson
--
and what happens in a programme once the shell has invoked it for a
user.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 29Jan2023 07:12, 2qdxy4rzwzuui...@potatochowder.com
<2qdxy4rzwzuui...@potatochowder.com> wrote:
On 2023-01-29 at 16:51:20 +1100,
Cameron Simpson wrote:
They're unrelated. As others have mentioned, "--" is _extremely_
common;
almost _all_ UNIX command like programmes which
emely_ common;
almost _all_ UNIX command like programmes which handle -* style options
honour the "--" convention. _argparse_ itself honours that convention,
as does getopt etc.
The "--" convention has nothing to do with the shell.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
t;, choices=pytz.all_timezones)
[...]
It works, but when I run it with the -h option it dumps all entries in
pytz.all_timezones.
What happens if you just presupply a `help=` parameter in
`add_argument`?
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
to shoehorn argparse into behaving in a way it was not
designed for
- avoids users needing to know the standard UNIX/POSIX "--" idiom for
marking off the end of options
- supports a -h or --help leading option
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
;.
Not personally a fan of argparse myself, but then I have my own
elaborate command line framework which generally uses getopt for the
option stuff.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
saying that what
follows from here is not an argument. So the user is expected to type:
your_script -x -y -- "-4^2+5.3*abs(-2-1)/2"
where there are -x and -y options, then end of options, then an
argument, which would look like an option if there wasn't the "--"
argument.
ingle character strings which it has taken to be
individual arguments. Try this:
parser.parse_args(["-4^2+5.3*abs(-2-1)/2"])
and of course:
parser.parse_args(["--", "-4^2+5.3*abs(-2-1)/2"])
You can see this behaviour of strings as:
print(list("abc"))
or:
for s in "abc":
print("s =", repr(s))
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
I've got docstrings with _example_ code which doubles
as a doctest. Making it easier to understand how to easily use this
thing.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
can themselves
call update etc and ...
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
uot; point where
the tk gui updates widgets and polls for user actions.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
don't think you've described this. I don't know what you mean here.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 11Jan2023 19:10, Dieter Maurer wrote:
Cameron Simpson wrote at 2023-1-11 08:37 +1100:
...
There's a Discourse forum over at discuss.python.org. I use it in
"mailing list mode" and do almost all my interactions via email, exactly
as I do for python-list. [...]
I am also using
work, just not in a
separate thread.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
lder I use for python-list. My replies land on the forum as
expected (and of course also go by email to those members who have
turned that mode on).
So I'm using both the new forum and the currently mailing list still,
and broadly in exactly the same way.
Cheers,
Cameron Simpson
--
https://mail.
and one could argue that
type annotations already form a "has no effect" syntax extension to
Python, so we're already in that playground :-)
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
do that globally (eg in the root logger) it
will affect _all_ logging calls, not merely your own, and other
libraries will assume they can log at whatever level and not pollute
stdout with their logs.
Basicly, logging isn't "output".
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 19Dec2022 08:53, Cameron Simpson wrote:
I'm no expert on floating point coding for precision, but I believe
that trying to work with values "close together" in magnitude is
important because values of different scales inherently convert one of
them to the other scale (i.e. sim
imilar sized exponent part) with corresponding loss
of precision in the mantissa part. That may require you to form your
calcutations carefully.
See if you can locate a source for the jerkiness (by printing
intermediate results) and then maybe rephrase that step?
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
ing, it is needn't be utf-8).
(For the OP: `UnicodeDecodeError` doesn't necessarily mean you're
decoding Unicode data, you're decoding _into_ a Python string which is a
Unicode string.)
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
/computer-science-subject-kit/python-101
That's just from a web search, I've not used it.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
to copy and save this “logistics.py“
file?
It sounds like you're follow some tutorial? Can you provide the URL of
the tutorial you're following?
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 20Nov2022 12:36, Chris Angelico wrote:
On Sun, 20 Nov 2022 at 12:27, Cameron Simpson wrote:
But really, is there any problem which cannot be solved with a
decorator? I've even got a @decorator decorator for my decorators.
Do you have a @toomanydecorators decorator to reduce the number
problem which cannot be solved with a
decorator? I've even got a @decorator decorator for my decorators.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
want to do this? Often
this kind of response ("yes but don't!") can be a clue that you're
chasing the wrong (sorry, "suboptimal/poor") solution to a problem which
can be solved in another way.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
ing levels logging.INFO, logging.WARNING etc, and then called
logging.log() with the official level.
Then adjust the calling code to call your new function.
The alternative is to just replace every calling function which uses
my_ugly_debug() to directly call a logging.whatever() call.
Cheers,
Camer
target for complaint by a linter, whose task is to
point out dodgy looking stuff for review by the author.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
at this:
clearx = x.clear
is more valid than:
x.clear
which discards the return value of the expression.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
will it just show
up here? Or do the actual Python devs intercept it?
Nah, it'll go through.
Cheers,
Cameron Simpson
--
https://mail.python.org/mailman/listinfo/python-list
On 13Nov2022 10:08, Cameron Simpson wrote:
On 13Nov2022 07:57, Cameron Simpson wrote:
# replace fctory with a function calling factory.__func__
factory = lambda arg: factory.__func__(classmethod, arg)
It just occurred to me that you might need to grab the value
1 - 100 of 1724 matches
Mail list logo