あうぇくろ writes:
tpr=composite(type,print)
print(tpr('a')==tpr(1))
Why does tpr('a')==tpr(1) return True?
Because tpr always returns the value None.
--
https://mail.python.org/mailman/listinfo/python-list
Karsten Hilbert writes:
Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more
information.
>>> tex = '\sout{'
>>> tex
'\\sout{'
>>>
Am I missing something ?
Python 3.10.5 (v3.10.5:f37715, Jul 10 2022, 00:26:17) [GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x,_,z = [1,2,3]
Works as expected.
Now I didn't expect the following to work (but Python sometimes
surprises me!), so I tried:
>>
Thomas Passin writes:
On 5/3/2024 9:56 AM, Johanne Fairchild via Python-list wrote:
> How to discover what values produced an exception? Or perhaps---why
> doesn't the Python traceback show the values involved in the TypeError?
> For instance:
>
> --8<--
Lawrence D'Oliveiro writes:
> Assume you have an expression "s.replace('a','b').replace('c','d').
> replace('e','f').replace('g','h')". Its value is a string which
> is the value of s, but with "a" replaced by "b", "c" replaced by
> "d", "e" replaced by "f" and "g" replaced by "h". Ho
Chris Angelico writes:
> 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
jak writes:
Oscar Benjamin ha scritto:
...
If we now use the function being discussed:
powers_of_2_in(n)
(63, 1)
we can see that the bit_count() method had to do 63 iterations to count
the bits
I certainly hope that the bit_count method doesn't count bits by
iterating
jak writes:
Alan Bawden ha scritto:
> Julieta Shem writes:
>
> How would you write this procedure?
> def powers_of_2_in(n):
> ...
>
> def powers_of_2_in(n):
> return (n ^ (n - 1)).bit_count() - 1
>
Great solutio
Julieta Shem writes:
How would you write this procedure?
def powers_of_2_in(n):
...
def powers_of_2_in(n):
return (n ^ (n - 1)).bit_count() - 1
--
https://mail.python.org/mailman/listinfo/python-list
Chris Angelico writes:
On Thu, 2 Nov 2023 at 15:20, AVI GROSS via Python-list
wrote:
> Yes, it would be nice if there was a syntax for sending a test
> message sort of like an ACK that is not delivered to the recipient
> but merely results in some status being sent back such as
Guenther Sohler writes:
Hi Python community,
I have a got an example list like
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
T T
and i eventually want to insert items in the given locations
(A shall go between 2 and 3, B shall go between 6 and 7)
Right now i just use ind
jose isaias cabrera writes:
On Thu, Mar 2, 2023 at 2:38 PM Mats Wichmann wrote:
This re is a bit different than the one I am used. So, I am trying to match
everything after 'pn=':
import re
s = "pm=jose pn=2017"
m0 = r"pn=(.+)"
r0 = re.compile(m0)
s0 = r0.match(s)
>>
Cecil Westerhof writes:
Alan Bawden writes:
> Cecil Westerhof writes:
>
>Yes, I try to select a random element, but it has also to be removed,
>because an element should not be used more as once.
>
> Instead of using pop to do that why
g to have it destroyed by this process:
seq = list(seq)
n = len(seq)
while n:
i = randrange(n)
yield seq[i]
n -= 1
if i < n:
seq[i] = seq[n]
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
e
_same_ dictionary every time. Your original code that used a `for' loop
is actually much clearer.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
ng for is usually called "argmax" and
"argmin" (see ). These don't exist in
the standard Python library as far as I can tell, but numpy does have
"argmax" and "argmin" routines.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
Marco Sulla writes:
On Mon, 9 May 2022 at 19:53, Chris Angelico wrote:
...
Nevertheless, tail is a fundamental tool in *nix. It's fast and
reliable. Also the tail command can't handle different encodings?
It definitely can't. It works for UTF-8, and all the ASCII compatible
single
And I missed one that was just published last month:
https://datatracker.ietf.org/doc/html/rfc9171
Unlike RFC 5050, this version of the protocol actually claims to be a
"Proposed Standard".
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
ps://en.wikipedia.org/wiki/Delay-tolerant_networking
https://datatracker.ietf.org/doc/html/rfc4838
https://datatracker.ietf.org/doc/html/rfc5050
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
David Lowry-Duda writes:
...
For the same reason that the following code doesn't do what some people
might expect it to:
```python
def add_to(elem, inlist=[]):
inlist.append(elem)
return inlist
list1 = add_to(1)
list2 = add_to(2)
print(list1) # prints [1
w the target
to be as general as possible!
I'm guessing that about 70% of you will think that this is a horrible
idea, 10% of you will find it compelling, and the remaining 20% will
find themselves conflicted. You can count me in that last category...
--
Alan Bawden
--
https://mail.python.o
Chris Angelico writes:
>>> sys.version
'3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]'
>>> def chk(x):
... if not(0 < x < 10): raise Exception
...
>>> dis.dis(chk)
2 0 LOAD_CONST 1 (0)
2 LOAD_FAST
Sibylle Koczian writes:
Am 20.03.2021 um 09:34 schrieb Alan Bawden:
>
> When you write that code to capitalize your book titles, you should be
> calling .title() rather than .upper() if you are doing it right.
>
But that's exactly what he's doing,
t;> '\u01f1'.lower()
'\u01f3'
This is the "dz" character.
>>> '\u01f1'.title()
'\u01f2'
This is the "Dz" character.
When you write that code to capitalize your book titles, you should be
calling .title() rather than .upper() if you are doing it right.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
tween append and extend. I suspect that the
heart of your confusion actually has nothing to do with generators.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
jak writes:
Il 02/01/2021 01:07, Alan Bawden ha scritto:
> jak writes:
>
> Il 01/01/2021 06:23, Alan Bawden ha scritto:
> > jak writes:
> >
> > Running the command:
> >
> > $ cat bible.txt &g
jak writes:
Il 01/01/2021 06:23, Alan Bawden ha scritto:
> jak writes:
>
> Running the command:
>
> $ cat bible.txt > cmdpipe & cat bible.txt > cmdpipe & cat bible.txt >
cmdpipe
>
> the three texts do not mix
>
n {PIPE_BUF} bytes may have data interleaved, on
arbitrary boundaries, with writes by other processes, whether or not
the O_NONBLOCK flag of the file status flags is set.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
like:
class Main:
value = []
def add(self, x):
self.value += [x]
and be suprised by the resulting behavior.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
al.alex...@gmail.com writes:
> Just for the records and to have a fully working bidirectional solution:
>
> >>> ip
> '10.44.32.0'
> >>> struct.unpack('L', socket.inet_aton(ip))[0]
> 2108426
> >>> socket.inet_ntoa(struct.pack(' '10.44.32.0'
> >>>
>
> Good luck ;-)
This will not work as expected
in Python3.8 to test the data type, e.g.
> is_floate(var)
> is_string(var)
> etc. ?
You should probably be using isinstance(), as in:
isinstance(var, float)
isinstance(var, str)
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
rly an error. Kahan doesn't think much of signalling NaNs,
writing that they "exist mainly for political reasons and are rarely used".
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
.« statement). Can you guess what it is?
Well, there's sys.stdin.
But I would expect beginning students to find the effect of typing
"next(sys.stdin)" to the commnd prompt to be a bit confusing...
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
x27; in the process.
In fact, I have been known to add `if __name__' to my colleagues' Python
scripts, just so that I can safely `pydoc' them.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
Chris Angelico writes:
> On Mon, Sep 2, 2019 at 12:36 PM Alan Bawden wrote:
...
> > > > a,b = 2,3 and [a,b] = [2,3]
...
> > It looks to me like they generate identical code. The first one calls the
> > construction of a tuple, where the second one calls for the cons
iler optimized the tuple
away, but failed to optimize the list away!
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
. `type.mro' tells you something
about the _implementation_ of `int' and `float' that you _usually_ shouldn't
concern yourself with. Stick to `isinstance' and `issubclass' and
everthing looks pretty kosher.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
storage here. Depending on how much physical
memory you have, you much actually be swapping before you're done.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
Alan Bawden writes:
> r...@zedat.fu-berlin.de (Stefan Ram) writes:
> > for i in range( len( list )- 1, 0, -1 ):
> > if list[ i ]is None: del list[ i ]
>
> list = [x for x in list if x is not None]
Except 'list' is a bad name to use...
--
Alan Bawden
--
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> for i in range( len( list )- 1, 0, -1 ):
> if list[ i ]is None: del list[ i ]
list = [x for x in list if x is not None]
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
D'Arcy Cain writes:
> On 2019-06-10 15:46, Alan Bawden wrote:
> > D'Arcy Cain writes:
> >> with open("file","w+") as fd:
> >
> > That makes the window smaller, but it doesn't actually eliminate it. Look
> > at the generate
quot;,"w+") as fd:
That makes the window smaller, but it doesn't actually eliminate it. Look
at the generated byte code. In both cases the call to open() is over and
the open file is created _before_ the SETUP_WITH instruction is executed.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
8:24:23)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> isinstance(True, int)
True
>>> type(True) == int
False
>>> type(True)
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
r...@zedat.fu-berlin.de (Stefan Ram) writes:
> Alan Bawden writes:
> >The Java compiler has no way to know whether a variable references an
> >object with a finalize() method that has side effects
>
> java.lang.Object#finalize() is deprecated since Java 9.
And we
Gregory Ewing writes:
> Alan Bawden wrote:
> > the Java Language
> > Specification contains the following language:
> >Optimizing transformations of a program can be designed that reduce
> >the number of objects that are reachable to be less than those wh
tation.
I suspect that given the history of Python, pretty much everybody has
always assumed that a Python implementation will not delete local variables
early. But I agree with you that the Python Language Reference does not
appear to address this question anywhere!
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
table of contents disappears off the top.
It's a reasonable request, but this probably isn't the most effective place
to make it.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
SyntaxError: invalid syntax
3.6> not [1,2,3] == (not True)
True
3.6> not [] == (not True)
True
3.6> (not []) == (not True)
False
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
Chris Angelico writes:
> On Mon, Oct 15, 2018 at 9:56 AM Alan Bawden wrote:
> > In my experience this is a very common way to assume that tabs will be
> > interpreted. Virtually every source-code file I have encountered since the
> > mid 1970s (for any programming languag
e encountered since the
mid 1970s (for any programming language or operating system) has assumed
either this convention or, slightly less often, its 4-column variant.
It's surprising that you've never encountered it.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
an f'{x}{y}{z}'. Apparently the overhead of making just _one_
temporary intermediate string is enough to tip the balance. I'm a bit
surprised that it doesn't take a few more than that. Although I imagine
that that balance might tip at a different point in future releases of
Python (I tested using 3.6.6).
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
uldn't there also be a concatenation operator that performs
a copy of some kind on its operands?
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
Gene Heskett writes:
> You are stating an opinion, but no facts to back it up, so describe your
> environment that makes you write that, please.
If he describes his environment and why he likes it, will that be a
"fact"? Or will you dismiss that as just another "opinion"?
You asked:
> can so
signal.SIG_DFL)
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
Cameron Simpson writes:
> On 22Feb2016 12:34, Alan Bawden wrote:
I have deleted the part of discussion where it seems that we must simply
agree to disagree. You think mktemp() is _way_ more dangerous that I
do.
>>> In fact your use case isn't safe, because _another_ task us
Cameron Simpson writes:
> On 16Feb2016 19:24, Alan Bawden wrote:
>>So in the FIFO case, I might write something like the following:
>>
>>def make_temp_fifo(mode=0o600):
>>while True:
>>path = tempfile.mktemp()
>>try:
me I
should use mkstemp() instead. (As if that would be of any use in the
situation above!) It looks like anxiety that some people might use
mktemp() in a stupid way has caused an over-reaction. Let the
documentation warn about the problem and point to prepackaged solutions
in the common cases of
Chris Angelico writes:
> On Thu, Nov 26, 2015 at 1:08 PM, Alan Bawden wrote:
>> (Note that nothing in the documentation I can find actually _guarantees_
>> that a Python implementation will only have one unique empty tuple, but
>> I wouldn't be suprised if the follow
(Note that nothing in the documentation I can find actually _guarantees_
that a Python implementation will only have one unique empty tuple, but
I wouldn't be suprised if the following is nonetheless true in all
current implementations:
>>> tuple([]) is tuple([])
True
)
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
Alan Bawden writes:
> ... Score one for untyped languages.
Drat. I should have writted "dynamically typed languages".
The language has changed. When I was a novice Lisp hacker, we were
comfortable saying that Lisp was "untyped". But nowadays we always say
that Lis
t for some other Java datatypes
(e.g., Buffer) it is a real problem. Score one for untyped languages.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
ot have to worry that .write()
might perform an incomplete write where it previously did not.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
Maybe there is some design document for Python 3 IO that I should read
that would explain the rationale for all this?
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
lly defined. Consider:
>>> a = float('nan')
>>> x = [1, a, 9]
>>> y = [1, a, 9.0]
>>> x == y
True
So is there some equality predicate where corresponding elements of x
and y are equal?
>>> map(operator.eq, x, y)
[True, False, True
Marko Rauhamaa writes:
> Case in point, if everything is a reference, how come:
>
>>>> "hello".__str__()
>'hello'
>>>> 1.__str__()
>SyntaxError: invalid syntax
>>> (1).__str__()
'1'
>>>
you to do better. After all modern Python
classes didn't start using their current ordering until Python 2.3.
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
ade use of this ability, so
don't ask me if it was good for anything, but it was definitely there...
--
Alan Bawden
--
https://mail.python.org/mailman/listinfo/python-list
Since the event being generated is commonly called a "keystroke", and since
my dictionary defines the noun "stroke" as being: "the act of striking", a
good verb to choose for the action itself would seem to be "strike":
strike('a')
--
http://mail.python.org/mailman/listinfo/python-list
68 matches
Mail list logo