Hello, please have a look at following code snippet
(python 3.4.4)
class Test:
a = 1
def __init__(self):
self.a = 2
self.f = lambda : print("f from object")
self.__call__ = lambda : print("__call__ from object")
def __call__(self):
print("__call__ from cl
Hello, I tried the following:
import copy
a = 5
b = copy.copy(a)
a is b
True
I was expecting False
I am aware that it is useless to copy an integer
(or any immutable type).
I know that for small integers, there is always a
single integer object in memory, and that for larger
one's there ma
"ast" a écrit dans le message de
news:59e9b419$0$3602$426a7...@news.free.fr...
Neither works for large integers which is
even more disturbing
a = 6555443
b = copy.copy(a)
a is b
True
--
https://mail.python.org/mailman/listinfo/python-list
"Thomas Nyberg" a écrit dans le message de
news:mailman.378.1508491267.12137.python-l...@python.org...
On 10/20/2017 10:30 AM, ast wrote:
I am aware that it is useless to copy an integer
(or any immutable type).
...
any comments ?
Why is this a problem for you?
Cheers,
Thom
Hi,
I know two Python's objects which have an intrinsic
name, classes and functions.
def f():
pass
f.__name__
'f'
g = f
g.__name__
'f'
class Test:
pass
Test.__name__
'Test'
Test2 = Test
Test2.__name__
'Test'
Are there others objects with a __name__ attribute
and what is it us
Hi
Below an example of enum which defines an __init__
method.
https://docs.python.org/3.5/library/enum.html#planet
Documentation says that the value of the enum
members will be passed to this method.
But in that case __init__ waits for two arguments, mass
and radius, while enum member's va
Hello
Here is my module tmp.py:
a=0
def test():
global a
print(a)
a+=1
If I import function "test" from module "tmp" with:
from tmp import test
it works
test()
0
test()
1
But where variable "a" is located ? I can't find it anywhere
Regards
--
https://mail.python.org/
"Paul Moore" a écrit dans le message de
news:mailman.53.1510069830.2819.python-l...@python.org...
On 7 November 2017 at 15:39, ast wrote:
It's in the "tmp" module, where you defined it. But because you didn't
ask for a reference to it in your import stateme
Hello
Python's doc says about loop.call_soon(callback, *arg):
Arrange for a callback to be called as soon as possible. The callback is called
after call_soon() returns, when control returns to the event loop.
But it doesn't seem to be true; see this program:
import asyncio
async def task_fu
Hello,
According to:
https://www.python.org/dev/peps/pep-0492/#await-expression
an awaitable object is:
- A native coroutine object returned from a native coroutine function
- A generator-based coroutine object returned from a function decorated
with types.coroutine()
- An object with an __a
"ast" a écrit dans le message de
news:5a2a568c$0$3699$426a7...@news.free.fr...
I made some experiment.
It seems that the iterator shall provide None values, an other value
raises an exception: "RuntimeError: Task got bad yield: 1"
and in instruction "res
Hi
Time measurment with module timeit seems to work with some
statements but not with some other statements on my computer.
Python version 3.6.3
from timeit import Timer
Timer("'-'.join([str(i) for i in range(10)])").timeit(1)
0.179271876732912
Timer("'-'.join([str(i) for i in range(1
"Thomas Jollans" a écrit dans le message de
news:mailman.74.1513341235.14074.python-l...@python.org...
On 2017-12-15 11:36, ast wrote:
No, this is right. The calculation takes practically no time; on my
system, it takes some 10 ns. The uncertainty of the timeit result is at
l
"ast" a écrit dans le message de
news:5a33a5aa$0$10195$426a7...@news.free.fr...
Ty Peter and Steve, I would never have found that
explanation myself
--
https://mail.python.org/mailman/listinfo/python-list
"Steve D'Aprano" a écrit dans le message de
news:5a33d0fc$0$2087$b1db1813$d948b...@news.astraweb.com...
On Sat, 16 Dec 2017 12:25 am, ast wrote:
"Thomas Jollans" a écrit dans le message de
news:mailman.74.1513341235.14074.python-l...@python.org...
On 20
Hello
It seems that caracter % can't be escaped
>>>"test %d %" % 7
ValueError: incomplete format
>>>"test %d \%" % 7
ValueError: incomplete format
>>>"test %d" % 7 + "%"
'test 7%' # OK
But is there a way to escape a % ?
thx
--
https://mail.python.org/mailman/listinfo/python-list
Le 14/02/2018 à 13:46, ast a écrit :
Hello
It seems that caracter % can't be escaped
>>>"test %d %" % 7
ValueError: incomplete format
>>>"test %d \%" % 7
ValueError: incomplete format
>>>"test %d" % 7 + "%"
'
Hello
I would like to write a huge file of double precision
floats, 8 bytes each, using IEEE754 standard. Since
the file is big, it has to be done in an efficient
way.
I tried pickle module but unfortunately it writes
12 bytes per float instead of just 8.
Example:
import pickle
f = open("data
Le 21/02/2018 à 15:02, bartc a écrit :
On 21/02/2018 13:27, ast wrote:
Time efficient or space efficient?
space efficient
If the latter, how many floats are we talking about?
10^9
--
https://mail.python.org/mailman/listinfo/python-list
Le 21/02/2018 à 14:27, ast a écrit :
struct.pack() as advised works fine.
Exemple:
>>> import struct
>>> struct.pack(">d", -0.0)
b'\x80\x00\x00\x00\x00\x00\x00\x00'
before I read your answers I found a way
with pickle
>>> import pickle
>&
Le 21/02/2018 à 18:23, bartc a écrit :
On 21/02/2018 15:54, ast wrote:
Le 21/02/2018 à 15:02, bartc a écrit :
On 21/02/2018 13:27, ast wrote:
Time efficient or space efficient?
space efficient
If the latter, how many floats are we talking about?
10^9
Although it might be better
Hello
I share a very valuable table I found on
StackOverflow about file opening modes
If like me you always forget the details of
file opening mode, the following table provides
a good summary
| r r+ w w+ a a+
--|--
read
Le 22/02/2018 à 13:03, bartc a écrit :
On 22/02/2018 10:59, Steven D'Aprano wrote:
https://www.ibm.com/developerworks/community/blogs/jfp/entry/Python_Meets_Julia_Micro_Performance?lang=en
While an interesting article on speed-up techniques, that seems to miss
the point of benchmarks.
On t
Le 22/02/2018 à 19:53, Chris Angelico a écrit :
On Fri, Feb 23, 2018 at 2:15 AM, ast wrote:
Le 22/02/2018 à 13:03, bartc a écrit :
On 22/02/2018 10:59, Steven D'Aprano wrote:
for count in 1, 10, 100, 1000:
print(count, timeit("cache(maxsize=None)(fib)(20)", setu
Le 20/12/2020 à 21:00, danilob a écrit :
b = ((x[0] for x in a))
There is a useless pair of parenthesis
b = (x[0] for x in a)
b is a GENERATOR expression
first list(b) calls next method on b repetedly until b is empty.
So it provides the "content" of b
second list(b) provides nothing si
Hello
Reading PEP572 about Python 3.9 assignment expressions,
I discovered a subtle difference between any(a list)
and any(a generator)
see:
>>> lines = ["azerty", "#qsdfgh", "wxcvbn"]
>>> any((comment := line).startswith('#') for line in lines)
True
>>> comment
"#qsdfgh"
>>> any([(comment :=
Le 05/08/2021 à 11:40, Jach Feng a écrit :
I want to distinguish between numbers with/without a dot attached:
text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
re.compile(r'ch \d{1,}[.]').findall(text)
['ch 1.', 'ch 23.']
re.compile(r'ch \d{1,}[^.]').findall(text)
['ch 23', 'ch 4 ', 'ch 56 '
Le 05/08/2021 à 17:11, ast a écrit :
Le 05/08/2021 à 11:40, Jach Feng a écrit :
I want to distinguish between numbers with/without a dot attached:
text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
re.compile(r'ch \d{1,}[.]').findall(text)
['ch 1.', &
Le 05/08/2021 à 17:11, ast a écrit :
Le 05/08/2021 à 11:40, Jach Feng a écrit :
I want to distinguish between numbers with/without a dot attached:
text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
re.compile(r'ch \d{1,}[.]').findall(text)
['ch 1.', &
Le 06/08/2021 à 02:57, Jach Feng a écrit :
ast 在 2021年8月5日 星期四下午11:29:15 [UTC+8] 的信中寫道:
Le 05/08/2021 à 17:11, ast a écrit :
Le 05/08/2021 à 11:40, Jach Feng a écrit :
import regex
# regex is more powerful that re
text = 'ch 1. is\nch 23. is\nch 4 is\nch 56 is\n'
regex.finda
Hello
class NewStr(str):
def __init__(self, s):
self.l = len(s)
Normaly str is an immutable type so it can't be modified
after creation with __new__
But the previous code is working well
obj = NewStr("qwerty")
obj.l
6
I don't understand why it's working ?
(python 3.9)
--
https:/
> li = []
> li.append(li)
> li
[[...]]
>li[0][0][0][0]
[[...]]
That's funny
--
https://mail.python.org/mailman/listinfo/python-list
Hello
In this function
def get4(srcpages):
scale = 0.5
srcpages = PageMerge() + srcpages
x_increment, y_increment = (scale * i for i in srcpages.xobj_box[2:])
for i, page in enumerate(srcpages):
page.scale(scale)
page.x = x_increment if i & 1 else 0
page.y
Le 04/11/2021 à 16:41, Stefan Ram a écrit :
ast writes:
(scale * i for i in srcpages.xobj_box[2:]) is a generator, a single
object, it should not be possible to unpack it into 2 variables.
But the value of the right-hand side /always/ is a single object!
A syntax of an assignment
A curiosity:
q = lambda x: x and q([i for i in x[1:] if i < x[0]]) + [x[0]] + q([i
for i in x[1:] if i >= x[0]])
>>> q([7, 5, 9, 0])
[0, 5, 7, 9]
--
https://mail.python.org/mailman/listinfo/python-list
Hello,
It seems that symbolic links on Windows are not
well reconized by modules os or pathlib.
I have a file named json.txt on my destop. With a
drag and drop right click on it I create a link
automatically named: json.txt - Raccourci.lnk
Then:
>>> from pathlib import Path
>>> p2 = Path('C:/
Le 17/11/2021 à 13:10, Python a écrit :
ast wrote:
Hello,
It seems that symbolic links on Windows are not
well reconized by modules os or pathlib.
I have a file named json.txt on my destop. With a
drag and drop right click on it I create a link
automatically named: json.txt - Raccourci.lnk
Le 19/11/2021 à 03:51, MRAB a écrit :
On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote:
On 2021-11-18 at 23:16:32 -0300,
René Silva Valdés wrote:
Hello, I would like to report the following issue:
Working with floats i noticed that:
int(23.99/12) returns 1, and
int(
Le 19/11/2021 à 12:43, ast a écrit :
Le 19/11/2021 à 03:51, MRAB a écrit :
On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote:
On 2021-11-18 at 23:16:32 -0300,
René Silva Valdés wrote:
Hello, I would like to report the following issue:
Working with floats i noticed that:
int
Hi,
>>> a = 6
>>> b = 6
>>> a is b
True
ok, we all know that Python creates a sole instance
with small integers, but:
>>> import copy
>>> b = copy.copy(a)
>>> a is b
True
I was expecting False
--
https://mail.python.org/mailman/listinfo/python-list
Le 22/11/2021 à 16:02, Jon Ribbens a écrit :
On 2021-11-22, ast wrote:
For immutable types, copy(foo) just returns foo.
ok, thx
--
https://mail.python.org/mailman/listinfo/python-list
Le 19/11/2021 à 21:17, Chris Angelico a écrit :
On Sat, Nov 20, 2021 at 5:08 AM ast wrote:
Le 19/11/2021 à 03:51, MRAB a écrit :
On 2021-11-19 02:40, 2qdxy4rzwzuui...@potatochowder.com wrote:
On 2021-11-18 at 23:16:32 -0300,
René Silva Valdés wrote:
>>> 0.3 + 0.3 + 0.3 ==
Python 3.9.9
Hello
I have some troubles with groupby from itertools
from itertools import groupby
for k, grp in groupby("aahfffddnnb"):
print(k, list(grp))
print(k, list(grp))
a ['a', 'a']
a []
h ['h']
h []
f ['f', 'f', 'f']
f []
d ['d', 'd']
d []
s ['s', 's', 's', 's']
s []
n ['n
"Mok-Kong Shen" a écrit dans le message de
news:noo1v6$r39$1...@news.albasani.net...
Am 13.08.2016 um 03:08 schrieb Steven D'Aprano:
On Sat, 13 Aug 2016 06:44 am, Mok-Kong Shen wrote:
list2 = [1,2,3]
list1 += [4,5,6]
print(list1, list2)
[1, 2, 3, 4, 5, 6] [1, 2, 3]
Does that help?
I do
Hello
I wonder why calling a method on an integer
doesn't work ?
123.bit_length()
SyntaxError: invalid syntax
123.to_bytes(3, 'big')
SyntaxError: invalid syntax
but it works with a variable
i = 123
i.bit_length()
7
i=123
i.to_bytes(3, 'big')
b'\x00\x00{'
I am working with pyhton 3.5
"Marko Rauhamaa" a écrit dans le message de
news:87k2fefcyu@elektro.pacujo.net...
"ast" :
123.bit_length()
SyntaxError: invalid syntax
I fell into that trap myself.
CPython's lexical analyzer can't handle a dot after an integer literal
so you must ad
Hello
I made few experiments about variables visibility
for methods.
class MyClass:
a = 1
def test(self):
print(a)
obj = MyClass()
obj.test()
Traceback (most recent call last):
File "", line 1, in
obj.test()
File "", line 4, in test
print(a)
NameError: name 'a' is not def
"dieter" a écrit dans le message de
news:mailman.63.1472630594.24387.python-l...@python.org...
"ast" writes:
You are right. And it is documented this way.
Thank you
--
https://mail.python.org/mailman/listinfo/python-list
hi
Is there a web site to store python programs
in order to make them accessible for every boby ?
I know pypy, but I understood that it is for modules
only.
--
https://mail.python.org/mailman/listinfo/python-list
Hello
I noticed that searching in a set is faster than searching in a list.
from timeit import Timer
from random import randint
l = [i for i in range(100)]
s = set(l)
t1 = Timer("randint(0, 200) in l", "from __main__ import l, randint")
t2 = Timer("randint(0, 200) in s", "from __main__ import
"ast" a écrit dans le message de
news:57eb5a4a$0$3305$426a7...@news.free.fr...
Hello
I noticed that searching in a set is faster than searching in a list.
from timeit import Timer
from random import randint
l = [i for i in range(100)]
s = set(l)
t1 = Timer("randint(0, 20
"jmp" a écrit dans le message de
news:mailman.31.1474987306.2302.python-l...@python.org...
On 09/27/2016 04:01 PM, Peng Yu wrote:
Note: function are objects, and can have attributes, however I rarely see usage of these, there
could be good reasons for that.
It could be use to implemen
"Steven D'Aprano" a écrit dans le message de
news:57eb7dff$0$1598$c3e8da3$54964...@news.astraweb.com...
On Wednesday 28 September 2016 15:51, ast wrote:
Hello
I noticed that searching in a set is faster than searching in a list.
[...]
I tried a search in a tuple, it'
Hello,
In a class there are three possible types of methods,
the static methods, the class methods and the
instance methods
* Class methods are decorated, eg:
@classmethod
def func(cls, a, b):
...
I read that the decorator tranforms 'func' as a descriptor,
and when this descriptor is read, it
"Lawrence D’Oliveiro" a écrit dans le message de
news:f5314bdd-a98f-4a16-b546-bd8efe4dd...@googlegroups.com...
On Thursday, October 6, 2016 at 7:54:08 PM UTC+13, ast wrote:
But there is no decorator, why ? Is python doing the conversion
of funct2 to a descriptor itself, behind
"Steve D'Aprano" a écrit dans le message de
news:57f6673a$0$1598$c3e8da3$54964...@news.astraweb.com...
On Thu, 6 Oct 2016 08:03 pm, ast wrote:
Consider this function:
def add(a, b):
return a+b
You say that a function is always stored as
a descriptor object, so when I e
"Gregory Ewing" a écrit dans le message de
news:e5mgi9fp1b...@mid.individual.net...
Lawrence D’Oliveiro wrote:
Every function is already a descriptor.
Which you can see with a simple experiment:
>>> def f(self):
... print("self =", self)
...
I thought yesterday that every thing was cle
"Daiyue Weng" a écrit dans le message de
news:mailman.208.1475840291.30834.python-l...@python.org...
Hi, I declare two parameters for a function with default values [],
def one_function(arg, arg1=[], arg2=[]):
PyCharm warns me:
Default argument value is mutable,
what does it mean? and how
"jmp" a écrit dans le message de
news:mailman.209.1475841371.30834.python-l...@python.org...
On 10/07/2016 01:38 PM, Daiyue Weng wrote:
So the rule of thumb for default argument value is "No mutable"
Cheers,
It can be used to store some variables from one call of
a function to an other
"jmp" a écrit dans le message de
news:mailman.210.1475844513.30834.python-l...@python.org...
On 10/07/2016 02:07 PM, ast wrote:
"jmp" a écrit dans le message de
news:mailman.209.1475841371.30834.python-l...@python.org...
On 10/07/2016 01:38 PM, Daiyue Weng wrote:
"jmp" a écrit dans le message de
news:mailman.213.1475849391.30834.python-l...@python.org...
On 10/07/2016 03:45 PM, ast wrote:
"jmp" a écrit dans le message de
news:mailman.210.1475844513.30834.python-l...@python.org...
On 10/07/2016 02:07 PM, ast wrote:
"jmp&
Hello, here is the small program:
from tkinter import *
class Test:
def __init__(self):
root = Tk()
label = Label(root, text="this is a test")
label.pack()
root.mainloop()
test=Test()
I dont understand why this program works. After execution
of function __init__,
"Christian Gollwitzer" a écrit dans le message de
news:ntl6in$on5$1...@dont-email.me...
Am 12.10.16 um 13:18 schrieb ast:
Because the Test() call does never terminate. You have the mainloop inside of your constructor. As
long as this loop runs, your program exists. Try it by putt
Hi
On python doc here:
https://docs.python.org/3.4/reference/datamodel.html
it is said about __prepare__ metaclass's method:
If the metaclass has a __prepare__ attribute, it is called as
namespace = metaclass.__prepare__(name, bases, **kwds)
where the additional keyword arguments, if any,
"Peter Otten" <__pete...@web.de> a écrit dans le message de
news:mailman.34.1477663877.31204.python-l...@python.org...
ast wrote:
class T(type):
... def __new__(*args, **kw): return type.__new__(*args)
... def __prepare__(*args, **kw):
... print(kw)
..
Hi
I found this way to put a large number in
a variable.
C = int(
"28871482380507712126714295971303939919776094592797"
"22700926516024197432303799152733116328983144639225"
"94197780311092934965557841894944174093380561511397"
"4215424169339729054237110027510420801349667317"
"55152859226962916
Le 23/03/2018 à 13:43, Rustom Mody a écrit :
On Friday, March 23, 2018 at 5:46:56 PM UTC+5:30, ast wrote:
Hi
I found this way to put a large number in
a variable.
What stops you from entering the number on one single (v long) line?
It is not beautiful and not very readable. It is better
Le 23/03/2018 à 13:30, Wolfgang Maier a écrit :
On 03/23/2018 01:16 PM, ast wrote:
A very simple improvement would be to use a single
triple-quoted string. Assuming you are copy/pasting
the number from somewhere that will save a lot of your
time.
no, it seems that sone \n are inserted
Le 23/03/2018 à 13:55, Wolfgang Maier a écrit :
On 03/23/2018 01:30 PM, Wolfgang Maier wrote:
On 03/23/2018 01:16 PM, ast wrote:
n = int(
''.join("""
37107287533902102798797998220837590246510135740250
4637693767749000971264812
Le 23/03/2018 à 14:16, Antoon Pardon a écrit :
On 23-03-18 14:01, ast wrote:
Le 23/03/2018 à 13:43, Rustom Mody a écrit :
On Friday, March 23, 2018 at 5:46:56 PM UTC+5:30, ast wrote:
What meaningful information from number can you easily retrieve from
representing the number in some kind
Le 25/03/2018 à 03:47, Steven D'Aprano a écrit :
On Sun, 25 Mar 2018 00:05:56 +0100, Peter J. Holzer wrote:
The Original Poster (OP) is concerned about saving, what, a tenth of a
microsecond in total? Hardly seems worth the effort, especially if you're
going to end up with something even sl
Hi
round is supposed to provide an integer when
called without any precision argument.
here is the doc:
>>> help(round)
round(number[, ndigits]) -> number
Round a number to a given precision in decimal digits (default 0 digits).
This returns an int when called with one argument, otherwise the
Hello
I noticed that the speed of animations made
with module matplotlib.animation always seems
wrong.
Here is a small example for demonstration purpose:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
ax = fig.add_subplot(111)
tx
Le 19/06/2018 à 10:57, Peter Otten a écrit :
ast wrote:
I noticed that the speed of animations made
with module matplotlib.animation always seems
wrong.
dt = 0.1 # 100 ms
interval : number, optional
Delay between frames in milliseconds. Defaults to 200.
What's wrong ?
Le 19/06/2018 à 11:47, Peter Otten a écrit :
ast wrote:
Le 19/06/2018 à 10:57, Peter Otten a écrit :
ast wrote:
No, with dt = 100 it should last
200 * 100ms = 20.000ms = 20s
with dt = 0.1 it should last
200 * 0.1ms = 20ms = 0.02s
but your computer is probably not fast enough for
Hello
I found a smart and very concise code to
generate all permutations of a list.
I put it here if someone is interested to
figure out how it works
def permut(li, prefix=[]):
if len(li)==1:
yield prefix + li
else:
for elt in li:
li2 = li.copy()
Le 18/09/2018 à 17:01, ast a écrit :
error: permut instead of S
yield from permut(li2, prefix+[elt])
--
https://mail.python.org/mailman/listinfo/python-list
"Mark Lawrence" a écrit dans le message de
news:mailman.204.1459343690.28225.python-l...@python.org...
I believe something like this should suffice to display borders around the
radiobuttons.
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
style = ttk.Style()
style.configure('B
"ast" a écrit dans le message de
news:56fbe699$0$4548$426a7...@news.free.fr...
"Mark Lawrence" a écrit dans le message de
news:mailman.204.1459343690.28225.python-l...@python.org...
I believe something like this should suffice to display borders around the
radiobutt
hello
import tkinter as tk
import tk.ttk as ttk
Traceback (most recent call last):
File "", line 1, in
import tk.ttk as ttk
ImportError: No module named 'tk'
of course
import tkinter.ttk as ttk
works
Strange, isn't it ?
--
https://mail.python.org/mailman/listinfo/python-list
Hello
I currently migrate a GUI from tkinter to ttk and I found a problem
Here is a piece of code, with comments which explain what is
wrong.
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
BITMAP0 = """
#define zero_width 24
#define zero_height 32
static char zero_bits[] = {
"Kevin Walzer" a écrit dans le message de
news:ne1qin$7po$1...@dont-email.me...
In general, the "img.config" syntax is suitable for the classic Tk widgets, not the themed ttk
widgets. They have a very different (and very gnarly) syntax for indicating changed state. I am
not inclined to see a
Hello
I would like to know if it is advised or not to test
a function's parameters before running it, e.g
for functions stored on a public library ?
Example:
def to_base(nber, base=16, use_af=True, sep=''):
assert isinstance(nber, int) and nber >= 0
assert isinstance(base, int) and base
"Mark Lawrence" a écrit dans le message de
news:mailman.131.1459949361.32530.python-l...@python.org...
On 06/04/2016 14:07, ast wrote:
Please see
http://ftp.dev411.com/t/python/python-list/13bhcknhan/when-to-use-assert
Thanks for this paper
Running Python with the
"Chris Angelico" a écrit dans le message de
news:mailman.13.1459955565.1197.python-l...@python.org...
On Thu, Apr 7, 2016 at 12:18 AM, ast wrote:
"Mark Lawrence" a écrit dans le message de
news:mailman.131.1459949361.32530.python-l...@python.org...
On 06/04/2
a écrit dans le message de
news:52f7516c-8601-4252-ab16-bc30c59c8...@googlegroups.com...
Hi,
there may be a serious error in python's int() function:
print int(float(2.8/0.1))
yields
27
instead of 28!!
I am using Python Python 2.7.6, GCC 4.8.2 on Linux Ubuntu.
Is that known?
Best,
Marti
Hello
>>> float('Nan') == float('Nan')
False
Why ?
Regards
--
https://mail.python.org/mailman/listinfo/python-list
Le 13/02/2019 à 14:21, ast a écrit :
Hello
>>> float('Nan') == float('Nan')
False
Why ?
Regards
Thank you for answers.
If you wonder how I was trapped with it, here
is the failing program.
r = float('Nan')
while r==float('Nan'):
i
Hello
Is it normal to have 151 entries in dictionary sys.modules
just after starting IDLE or something goes wrong ?
>>> import sys
>>> len(sys.modules)
151
Most of common modules seems to be already there,
os, itertools, random
I thought that sys.modules was containing loaded modules
with
Le 24/02/2019 à 05:21, Himanshu Yadav a écrit :
fibs={0:0,1:1}
def rfib(n):
global fibs
if not fibs.get(n):
fibs[n]=rfib(n-2)+rfib(n-1)
return fibs[n]
Why it is gives error??
Nothing to do with the malfunction, but you dont need
to define fibs as globa
Hello
I noticed a quirk difference between classes and functions
>>> x=0
>>>
>>> class Test:
x = x+1
print(x)
x = x+1
print(x)
1
2
>>> print(x)
0
Previous code doesn't generate any errors.
x at the right of = in first "x = x+1" line is
the global one (x=0), then
Hello
I just uploaded a package on pypi, whose name is "arith_lib"
The strange thing is that on pypi the package is renamed "arith-lib"
The underscore is substitued with a dash
If we search for this package:
pip search arith
arith-lib (2.0.0) - A set of functions for miscellaneous arithmetic
Hello
In the following snippet, a file is opened but
without any variable referring to it.
So the file can't be closed.
[line.split(":")[0]
for line in open('/etc/passwd')
if line.strip() and not line.startswith("#")]
What do you think about this practice ?
--
https://mail.python.org/mailm
Hello
List sys.path contains all paths where python shall
look for libraries.
Eg on my system, here is the content of sys.path:
>>> import sys
>>> sys.path
['',
'C:\\Users\\jean-marc\\Desktop\\python',
'C:\\Program Files\\Python36-32\\python36.zip',
'C:\\Program Files\\Python36-32\\DLLs',
'C:\\
Hello
I read in a course that class UserList from module
collections can be used to create our own custom list
Example
>>> from collections import UserList
>>> class MyList(UserList):
... def head(self):
... return self.data[0]
... def queue(self):
... return self.data[1
Le 11/09/2019 à 12:11, Sayth Renshaw a écrit :
Hi
I want to allow as many lists as needed to be passed into a function.
But how can I determine how many lists have been passed in?
I expected this to return 3 but it only returned 1.
matrix1 = [[1, -2], [-3, 4],]
matrix2 = [[2, -1], [0, -1]]
mat
Le 14/09/2019 à 04:26, Oscar Benjamin a écrit :
I've been staring at this for a little while:
from itertools import product
class Naturals:
def __iter__(self):
i = 1
while True:
yield i
i += 1
N = Naturals()
print(iter(N))
print(product(N)) # <
Le 14/09/2019 à 03:40, Random832 a écrit :
On Fri, Sep 13, 2019, at 21:22, Hongyi Zhao wrote:
what's the differences: None and null?
null isn't really a concept that exists in Python... while None fills many of
the same roles that null does in some other languages, it is a proper object,
wit
Hello
Following syntax doesn't generate any errors:
>>> foo=0
>>> Class Foo:
foo
But class Foo seems empty
Is it equivalent to ?
>>> class Foo:
pass
--
https://mail.python.org/mailman/listinfo/python-list
Hi
It is not clear to me why the following code
generates 2 exceptions, ZeroDivisionError and
ArithmeticError. Since ZeroDivisionError is
catched, it shoud not bubble out.
Found here:
https://www.pythonsheets.com/notes/python-new-py3.html
>>> def func():
... try:
... 1 / 0
... e
1 - 100 of 255 matches
Mail list logo