On 09/23/2014 07:48 AM, Steven D'Aprano wrote:
alas, the CUTOVER point is likely to be machine-dependent. Take it as a
given that inserting a fixed CUTOVER point into the source code (say,
``CUTOVER = 123456``) is not likely to be very effective, and dynamically
calculating it at import time is
On 24Sep2014 00:48, Steven D'Aprano
wrote:
I have a certain calculation which can be performed two radically different
ways. With the first algorithm, let's call it SHORT, performance is very
fast for small values of the argument, but terrible for large values. For
the second algorithm, LARGE,
Steven D'Aprano writes:
> ...
> *If* Python was a different language, I would spawn two threads, one using
> SHORT and the other using LARGE, then which ever completes first, I'd just
> kill the other. Alas, this won't work because (1) the GIL
The GIL does not prevent this scenario. The two threa
wn two threads, one using
>> SHORT and the other using LARGE, then which ever completes first, I'd just
>> kill the other. Alas, this won't work because (1) the GIL and (2) you
>> cannot forcibly kill threads, only ask them to die and hope they listen.
>>
>
seeking other ideas for dynamically swapping between the two
algorithms, based on runtime information. Any thoughts?
(1) I can't tell in advance how many loops I will make.
(2) Both SHORT and LARGE get slower as the size of their argument increases.
This is unavoidable due to the nature of th
seeking other ideas for dynamically swapping between the two
algorithms, based on runtime information. Any thoughts?
(1) I can't tell in advance how many loops I will make.
(2) Both SHORT and LARGE get slower as the size of their argument increases.
This is unavoidable due to the nature of the pr
t
kill the other. Alas, this won't work because (1) the GIL and (2) you
cannot forcibly kill threads, only ask them to die and hope they listen.
I am seeking other ideas for dynamically swapping between the two
algorithms, based on runtime information. Any thoughts?
(1) I can't tell in a
On Wed, Sep 24, 2014 at 12:48 AM, Steven D'Aprano
wrote:
> (3) SHORT starts off relatively speedy, significantly faster than LARGE for
> the first few tens of thousands of loops. I'm not talking about trivial
> micro-optimizations here, I'm talking about the difference between 0.1
> second for SHO
ng
SHORT and the other using LARGE, then which ever completes first, I'd just
kill the other. Alas, this won't work because (1) the GIL and (2) you
cannot forcibly kill threads, only ask them to die and hope they listen.
I am seeking other ideas for dynamically swapping between the two
al
ocking to processes owned by
> root or with the CAP_IPC_LOCK capability.
The "man" and "help" ref's are much appreciated. It's narrowed my
search space.
> Also, locking a specific region of memory won't necessarily help if the
> program code and stack are
o lock memory is controlled via
resource limits (see "man 2 setrlimit", "help ulimit" and "man 5
limits.conf"). Earlier versions limit memory locking to processes owned by
root or with the CAP_IPC_LOCK capability.
Also, locking a specific region of memory won't nec
Jon Clements writes:
> Is there a cross-platform way using Python to guarantee that an object
> will never be swapped/paged to disk? I'll be honest and say I'm really
> not sure if this is a particular language question or rather specific
> to an OS.
>
> Under linux it appears I could create a r
Hi all,
Is there a cross-platform way using Python to guarantee that an object
will never be swapped/paged to disk? I'll be honest and say I'm really
not sure if this is a particular language question or rather specific
to an OS.
Under linux it appears I could create a ramfs and mmap a file under
On Wed, 17 Mar 2010 13:34:51 +0100, Peter Otten wrote:
> Hatem Oraby wrote:
>
>> Hello, I want to swap the content of two dictionaries, the obvious way
>> to do it is:
>> a = {1:"I'am A"}
>> b = {2:"I'm B"}
>> temp = a
>> a = b
>> b = temp
>
> That can be simplified to
>
> a, b = b, a
>
> and
Hatem Oraby, 17.03.2010 12:26:
However, consider the case in which the dictionary we are referencing lives
in another module:
#external.py
#
#a = {1:"I'am A}
import external
temp = external.a
external.a = b
b = temp
Looks like the interface of your module is broken. It shouldn't export the
tw
"b": 2}
>>> b = {"b": 3, "c": 4}
>>> t = a.copy()
>>> a.clear()
>>> a.update(b)
>>> b.clear()
>>> b.update(t)
>>> a
{'c': 4, 'b': 3}
>>> b
{'a': 1, 'b': 2}
>
Hello, I want to swap the content of two dictionaries, the obvious way to do
it is:
a = {1:"I'am A"}
b = {2:"I'm B"}
temp = a
a = b
b = temp
However, consider the case in which the dictionary we are referencing lives
in another module:
#external.py
#
#a = {1:"I'am A}
import external
temp = extern
Peter Otten wrote:
Terry Reedy wrote:
If the names of superclasses is resolved when classes are instantiated,
the patching is easy. If, as I would suspect, the names are resolved
when the classes are created, before the module becomes available to the
importing code, then much more careful a
Wow, thank you all. Lots of ideas and things to try! I wish I knew
which one is going to work best. The module I'm trying to (monkey!)
patch is pxdom, and as it is a bit long (5700 lines of code in one
file!) I'm not quite sure if the simplest patching method will work or
the more complicated o
Terry Reedy wrote:
> Steven D'Aprano wrote:
>> On Sat, 16 May 2009 09:55:39 -0700, Emanuele D'Arrigo wrote:
>>
>>> Hi everybody,
>>>
>>> let's assume I have a module with loads of classes inheriting from one
>>> class, from the same module, i.e.:
>> [...]
>>> Now, let's also assume that myFile.py
Try this:
class Base(object):
pass
class C(Base):
pass
class NewBase(object):
pass
C.__bases__ = (NewBase,)
help(C)
--
http://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano wrote:
On Sat, 16 May 2009 09:55:39 -0700, Emanuele D'Arrigo wrote:
Hi everybody,
let's assume I have a module with loads of classes inheriting from one
class, from the same module, i.e.:
[...]
Now, let's also assume that myFile.py cannot be changed or it's
impractical to do
On Sat, 16 May 2009 09:55:39 -0700, Emanuele D'Arrigo wrote:
> Hi everybody,
>
> let's assume I have a module with loads of classes inheriting from one
> class, from the same module, i.e.:
[...]
> Now, let's also assume that myFile.py cannot be changed or it's
> impractical to do so. Is there a w
"Emanuele D'Arrigo" writes:
> On May 16, 8:17 pm, Arnaud Delobelle wrote:
>> # Insert Wedge into each subclass of modfoo.Base
>> for subclass in modfoo.Base.__subclasses__():
>> if subclass.__module__ != 'modfoo': continue
>> attrs = dict(item for item in subclass.__dict__.items()
>>
On May 16, 8:17 pm, Arnaud Delobelle wrote:
> # Insert Wedge into each subclass of modfoo.Base
> for subclass in modfoo.Base.__subclasses__():
> if subclass.__module__ != 'modfoo': continue
> attrs = dict(item for item in subclass.__dict__.items()
> if item[0][:2] !=
"Emanuele D'Arrigo" writes:
> Hi everybody,
>
> let's assume I have a module with loads of classes inheriting from one
> class, from the same module, i.e.:
>
> ## myFile.py
> class SuperClass(object)
> class SubClass1(SuperClass)
> class SubClass2(SuperClass)
> class SubClass3(SuperClass)
>
> In
Hi everybody,
let's assume I have a module with loads of classes inheriting from one
class, from the same module, i.e.:
## myFile.py
class SuperClass(object)
class SubClass1(SuperClass)
class SubClass2(SuperClass)
class SubClass3(SuperClass)
In a separate file I also have:
## myOtherFile.py
cla
samwyse wrote:
On Apr 15, 8:13 am, Aaron Brady wrote:
On Apr 15, 6:57 am, samwyse wrote:
Here's my idea: generate all possible pairs:
import itertools
players = [chr(c) for c in xrange(ord('a'),ord('z')+1)]
all_pairs = list(itertools.combinations(players,2))
partition the list:
def choos
On Apr 15, 11:29 am, samwyse wrote:
> On Apr 15, 8:56 am, Aaron Brady wrote:
>
>
>
> > The randomizing solution isn't quite suitable for 16 teams. With 5
> > teams/1 court, and 5 teams/2 courts, 6 teams/2 courts, the solution
> > comes within seconds. For 7 teams/3 courts, the solution takes a
On Apr 15, 8:56 am, Aaron Brady wrote:
>
> The randomizing solution isn't quite suitable for 16 teams. With 5
> teams/1 court, and 5 teams/2 courts, 6 teams/2 courts, the solution
> comes within seconds. For 7 teams/3 courts, the solution takes a few
> minutes.
7 teams/3 courts is the same as 8
On Apr 15, 8:13 am, Aaron Brady wrote:
> On Apr 15, 6:57 am, samwyse wrote:
>
> > Here's my idea: generate all possible pairs:
>
> > >>> import itertools
> > >>> players = [chr(c) for c in xrange(ord('a'),ord('z')+1)]
> > >>> all_pairs = list(itertools.combinations(players,2))
>
> > partition th
On Apr 14, 9:45 pm, Ross wrote:
> On Apr 14, 7:18 pm, Aaron Brady wrote:
>
>
>
> > On Apr 14, 7:01 pm, Aaron Brady wrote:
>
> > > On Apr 14, 12:37 pm, Ross wrote:
>
> > > > On Apr 14, 10:34 am, Ross wrote:
>
> > > > > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote:
>
> > > > > > In arti
On Apr 15, 6:57 am, samwyse wrote:
> On Apr 14, 7:01 pm, Aaron Brady wrote:
>
> > Here is an idea. Create a list of all possible pairs, using
> > itertools.combinations. You'll notice everyone gets equal play time
> > and equal time against each other on a pair-by-pair basis. Then, call
> > ra
On Apr 14, 7:01 pm, Aaron Brady wrote:
> Here is an idea. Create a list of all possible pairs, using
> itertools.combinations. You'll notice everyone gets equal play time
> and equal time against each other on a pair-by-pair basis. Then, call
> random.shuffle until one player isn't playing on t
On Apr 14, 9:45 pm, Ross wrote:
> On Apr 14, 7:18 pm, Aaron Brady wrote:
>
>
>
> > On Apr 14, 7:01 pm, Aaron Brady wrote:
>
> > > On Apr 14, 12:37 pm, Ross wrote:
>
> > > > On Apr 14, 10:34 am, Ross wrote:
>
> > > > > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote:
>
> > > > > > In arti
On Apr 14, 7:18 pm, Aaron Brady wrote:
> On Apr 14, 7:01 pm, Aaron Brady wrote:
>
>
>
> > On Apr 14, 12:37 pm, Ross wrote:
>
> > > On Apr 14, 10:34 am, Ross wrote:
>
> > > > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote:
>
> > > > > In article
> > > > > ,
>
> > > > > Ross wrote:
> >
On Apr 14, 7:01 pm, Aaron Brady wrote:
> On Apr 14, 12:37 pm, Ross wrote:
>
>
>
> > On Apr 14, 10:34 am, Ross wrote:
>
> > > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote:
>
> > > > In article
> > > > ,
>
> > > > Ross wrote:
> > > > >On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) w
On Apr 14, 12:37 pm, Ross wrote:
> On Apr 14, 10:34 am, Ross wrote:
>
>
>
> > On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote:
>
> > > In article
> > > ,
>
> > > Ross wrote:
> > > >On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote:
> > > >> In article
> > > >> > > >com>,
> > > >>
On Apr 14, 10:34 am, Ross wrote:
> On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote:
>
>
>
> > In article
> > ,
>
> > Ross wrote:
> > >On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote:
> > >> In article
> > >> > >com>,
> > >> Ross =A0 wrote:
>
> > >>>I'm sorry...my example was pro
On Apr 14, 5:57 am, a...@pythoncraft.com (Aahz) wrote:
> In article ,
>
>
>
> Ross wrote:
> >On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote:
> >> In article >com>,
> >> Ross =A0 wrote:
>
> >>>I'm sorry...my example was probably a bad one. A better example of
> >>>output I would like wou
In article ,
Ross wrote:
>On Apr 13, 9:08=A0am, a...@pythoncraft.com (Aahz) wrote:
>> In article com>,
>> Ross =A0 wrote:
>>>
>>>I'm sorry...my example was probably a bad one. A better example of
>>>output I would like would be something like [[1,2],[3,4],[5,6]] and
>>>then for the leftovers list
On Apr 13, 11:52 pm, Aaron Brady wrote:
> On Apr 13, 10:04 am, Ross wrote:
>
>
>
> > On Apr 11, 1:10 pm, a...@pythoncraft.com (Aahz) wrote:
>
> > > In article
> > > <4fd78ac3-ba83-456b-b768-3a0043548...@f19g2000vbf.googlegroups.com>,
>
> > > Ross wrote:
>
> > > >I'm trying to design an iterato
On Apr 13, 10:04 am, Ross wrote:
> On Apr 11, 1:10 pm, a...@pythoncraft.com (Aahz) wrote:
>
>
>
> > In article
> > <4fd78ac3-ba83-456b-b768-3a0043548...@f19g2000vbf.googlegroups.com>,
>
> > Ross wrote:
>
> > >I'm trying to design an iterator that produces two lists. The first
> > >list will be
On Apr 13, 9:08 am, a...@pythoncraft.com (Aahz) wrote:
> In article ,
>
> Ross wrote:
>
> >I'm sorry...my example was probably a bad one. A better example of
> >output I would like would be something like [[1,2],[3,4],[5,6]] and
> >then for the leftovers list [7,8,9,10 etc]. What I'm trying to do
In article ,
Ross wrote:
>
>I'm sorry...my example was probably a bad one. A better example of
>output I would like would be something like [[1,2],[3,4],[5,6]] and
>then for the leftovers list [7,8,9,10 etc]. What I'm trying to do is
>produce some sort of round robin algorithm for tennis that is
On Apr 11, 1:10 pm, a...@pythoncraft.com (Aahz) wrote:
> In article
> <4fd78ac3-ba83-456b-b768-3a0043548...@f19g2000vbf.googlegroups.com>,
>
> Ross wrote:
>
> >I'm trying to design an iterator that produces two lists. The first
> >list will be a list of unique pairings and the second will be a l
In article <4fd78ac3-ba83-456b-b768-3a0043548...@f19g2000vbf.googlegroups.com>,
Ross wrote:
>
>I'm trying to design an iterator that produces two lists. The first
>list will be a list of unique pairings and the second will be a list
>of items that weren't used in the first list. After each round,
Ross writes:
> Can you guys suggest an approach to this problem...I'm trying to teach
> myself python so an outline of how to approach this would probably be
> more helpful to me than an explicit solution. I'll cry mercy if I
> can't figure it out after your hints.
Look at the "set" datatype. Th
I'm trying to design an iterator that produces two lists. The first
list will be a list of unique pairings and the second will be a list
of items that weren't used in the first list. After each round, the
items that weren't used in the round before will get put back in and
the second list will be p
On 2009-01-31, Aahz wrote:
>>But could the swapping be done using less extra memory than this? What
>>is the minimum amount of extra memory required to exchange two 32-bit
>>quantities? What would be the pseudocode that achieves this minimum?
>
> This looks like a homewo
In article ,
Eric Kang wrote:
>
>In python, I set:
>
>x=1
>y=3
>
>z = x
>x = y
>y = z
>
>
>This gave me 3 1, which are the values of x and y swapped.
>The following would have given me the same result:
>x, y = y, x
>
>
>
>But could the swappi
> Grant Edwards wrote:
> > On 2009-01-30, MRAB wrote:
> >
> >>> What is the minimum amount of extra memory required to exchange two
> >>> 32-bit quantities? What would be the pseudocode that achieves this
> >>> minimum?
> >> x ^= y
> >> y ^= x
> >> x ^= y
> >>
> >> This is really only of use when
Steven D'Aprano schrieb:
> Ints in Python are *objects*, not 32-bit quantities. An int is 12 bytes
> (96 bits) in size; a long will use as much memory as needed. If your
> application needs to optimize a swap of two ints, then Python is probably
> going to be much too memory-intensive for you.
Grant Edwards wrote:
> On 2009-01-30, MRAB wrote:
>
>>> What is the minimum amount of extra memory required to exchange two
>>> 32-bit quantities? What would be the pseudocode that achieves this
>>> minimum?
>> x ^= y
>> y ^= x
>> x ^= y
>>
>> This is really only of use when working in assembly l
On Thu, 29 Jan 2009 21:23:48 -0800, Kottiyath wrote:
> Is it possible to swap two floats without a variable?
In Python? Sure.
f = 1.23
g = 2.87
f, g = g, f
This idiom is independent of the types of the objects:
x = "hello world"
y = [1, 2.0, None, "xyz", {}]
x, y = y, x
In other languages?
= z
>
> >> This gave me 3 1, which are the values of x and y swapped. The
> >> following would have given me the same result: x, y = y, x
>
> >> But could the swapping be done using less extra memory than this? What
> >> is the minimum amount of extra memory
On 2009-01-30, MRAB wrote:
>> What is the minimum amount of extra memory required to exchange two
>> 32-bit quantities? What would be the pseudocode that achieves this
>> minimum?
>
> x ^= y
> y ^= x
> x ^= y
>
> This is really only of use when working in assembly language.
And rarely then. ;)
= z
>
> >> This gave me 3 1, which are the values of x and y swapped. The
> >> following would have given me the same result: x, y = y, x
>
> >> But could the swapping be done using less extra memory than this? What
> >> is the minimum amount of extra memory
e
>> following would have given me the same result: x, y = y, x
>>
>> But could the swapping be done using less extra memory than this? What
>> is the minimum amount of extra memory required to exchange two 32-bit
>> quantities? What would be the pseudocode that achieve
On Thu, 29 Jan 2009 16:29:11 -0800, Eric Kang wrote:
> In python, I set:
>
> x=1
> y=3
>
> z = x
> x = y
> y = z
>
>
> This gave me 3 1, which are the values of x and y swapped. The following
> would have given me the same result: x, y = y, x
Yes.
&g
On Jan 30, 12:29 am, Eric Kang wrote:
> In python, I set:
>
> x=1
> y=3
>
> z = x
> x = y
> y = z
>
> This gave me 3 1, which are the values of x and y swapped.
> The following would have given me the same result:
> x, y = y, x
>
> But could the swapping
Eric Kang wrote:
In python, I set:
x=1
y=3
z = x
x = y
y = z
This gave me 3 1, which are the values of x and y swapped.
The following would have given me the same result:
x, y = y, x
But could the swapping be done using less extra memory than this?
What is the minimum amount of extra memory
In python, I set:
x=1
y=3
z = x
x = y
y = z
This gave me 3 1, which are the values of x and y swapped.
The following would have given me the same result:
x, y = y, x
But could the swapping be done using less extra memory than this? What is the
minimum amount of extra memory required to
En Sat, 18 Aug 2007 02:58:23 -0300, Beema shafreen
<[EMAIL PROTECTED]> escribi�:
> result:
> klp5bub1
>
> apn1apn2
>
> but i have do the same for the revere ,to check the result like this for
> eg:
> apn2apn1
> what is the concept to do this
I don't understand exactly what you want
hi everbody,
i have a file with data:
fhl1fkh2
dfp1chk1
mal3alp14
mal3moe1
mal3spi1
mal3bub1
mal3bub3
mal3mph1
mal3mad3
hob1nak1
i have written code to check the redudant pairs
my code:
data = []
data1 = []
fh = open('sheet1','r')
for line in fh:
if
>;
Sent: Wednesday, August 23, 2006 12:19 PM
Subject: Re: swapping numeric items in a list
> At Wednesday 23/8/2006 15:32, Jiang Nutao wrote:
>
>>This is what I got in the debugger:
>>
>>(Pdb) aa=array('b', [126, 55, 71, 112])
>>(Pdb) aa
>>array(
At Wednesday 23/8/2006 15:32, Jiang Nutao wrote:
This is what I got in the debugger:
(Pdb) aa=array('b', [126, 55, 71, 112])
(Pdb) aa
array('b', [126, 55, 71, 112])
(Pdb) aa.byteswap()
(Pdb) aa
array('b', [126, 55, 71, 112])
Oh, sorry, to swap by two bytes "H" was the right typecode. But your
Jiang Nutao wrote:
> array.byteswap() won't work for me easily. I tried this before my 1st post.
> I defined
>
> aa = array('H', [0x12, 0x34, 0x56, 0x78])
>
> Then did byteswap aa.byteswap(). The result was
>
> array('H', [0x1200, 0x3400, 0x5600, 0x7800])
>
> You can see it byteswappe
]>
To: "Jiang Nutao" <[EMAIL PROTECTED]>
Cc:
Sent: Wednesday, August 23, 2006 11:28 AM
Subject: Re: swapping numeric items in a list
> At Wednesday 23/8/2006 14:44, Jiang Nutao wrote:
>
>>array.byteswap() won't work for me easily. I tried this before my 1st
>&g
At Wednesday 23/8/2006 14:44, Jiang Nutao wrote:
array.byteswap() won't work for me easily. I tried this before my 1st post.
I defined
aa = array('H', [0x12, 0x34, 0x56, 0x78])
Then did byteswap aa.byteswap(). The result was
array('H', [0x1200, 0x3400, 0x5600, 0x7800])
You can see it
Thank you all guys for the help. Guess I'm gonna pick bearophile's way. It's
fast, neat, and easy to read.
array.byteswap() won't work for me easily. I tried this before my 1st post.
I defined
aa = array('H', [0x12, 0x34, 0x56, 0x78])
Then did byteswap aa.byteswap(). The result was
ar
Jiang Nutao wrote:
> Hi,
>
> I simplify my problem like below
>
> To convert list
> aa = [0x12, 0x34, 0x56, 0x78]
> into
> [0x34, 0x12, 0x78, 0x56]
>
> How to do it fast? My real list is huge.
Mark Rintsch's suggestion appears best if applicable, but just to cite yet
other
ways to do
In <[EMAIL PROTECTED]>, Jiang Nutao
wrote:
> To convert list
> aa = [0x12, 0x34, 0x56, 0x78]
> into
> [0x34, 0x12, 0x78, 0x56]
>
> How to do it fast? My real list is huge.
Use the `array` module and the `array.byteswap()` method.
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.py
Jiang Nutao:
> To convert list
> aa = [0x12, 0x34, 0x56, 0x78]
> into
> [0x34, 0x12, 0x78, 0x56]
> How to do it fast? My real list is huge.
Note that:
>>> a = range(6)
>>> a
[0, 1, 2, 3, 4, 5]
>>> a[::2]
[0, 2, 4]
>>> a[1::2]
[1, 3, 5]
So you can do:
>>> a[::2], a[1::2] = a[1::2], a[::2
Jiang Nutao wrote:
> Hi,
>
> I simplify my problem like below
>
> To convert list
> aa = [0x12, 0x34, 0x56, 0x78]
> into
> [0x34, 0x12, 0x78, 0x56]
>
> How to do it fast? My real list is huge.
>
> Thanks a lot.
> Jason
Here's simple and probably fast enough way (but it won't work right on
for i in xrange(0, len(your_list), 2):
your_list[i], your_list[i + 1] = your_list[i + 1], your_list[i]
Jiang Nutao wrote:
> Hi,
>
> I simplify my problem like below
>
> To convert list
> aa = [0x12, 0x34, 0x56, 0x78]
> into
> [0x34, 0x12, 0x78, 0x56]
>
> How to do it fast? My real li
Hi,
I simplify my problem like below
To convert list
aa = [0x12, 0x34, 0x56, 0x78]
into
[0x34, 0x12, 0x78, 0x56]
How to do it fast? My real list is huge.
Thanks a lot.
Jason
--
http://mail.python.org/mailman/listinfo/python-list
77 matches
Mail list logo