Re: [Tutor] How to test function using random.randint()?

2016-03-20 Thread boB Stepp
On Sun, Mar 20, 2016 at 8:44 PM, Ben Finney wrote: > boB Stepp writes: >> Can I not use: >> >> if rng is None: >> rng = random.Random() > > That will work. > > It unfortunately creates a new random.Random instance every time that > line is executed, making the function waste a lot of time.

Re: [Tutor] How to test function using random.randint()?

2016-03-20 Thread Ben Finney
boB Stepp writes: > On Sun, Mar 20, 2016 at 8:19 PM, Ben Finney > wrote: > > if rng is None: > > rng = random._inst > > > > which is the default RNG instance in the module. > > Can I not use: > > if rng is None: > rng = random.Random() That will work. It unfortunately creates

Re: [Tutor] How to test function using random.randint()?

2016-03-20 Thread boB Stepp
On Sun, Mar 20, 2016 at 8:19 PM, Ben Finney wrote: > > Steven D'Aprano writes: > > > On Mon, Mar 21, 2016 at 12:18:01AM +1100, Ben Finney wrote: > > > No, I meant what I wrote. The ‘rng’ parameter is expected to be > > > bound to a RNG. If the caller has not specified a custom RNG > > > instance,

Re: [Tutor] How to test function using random.randint()?

2016-03-20 Thread Ben Finney
Steven D'Aprano writes: > On Mon, Mar 21, 2016 at 12:18:01AM +1100, Ben Finney wrote: > > No, I meant what I wrote. The ‘rng’ parameter is expected to be > > bound to a RNG. If the caller has not specified a custom RNG > > instance, we bind ‘rng’ to the standard RNG instance found at > > ‘random.

Re: [Tutor] __str__ vs. sys.displayhook

2016-03-20 Thread Steven D'Aprano
On Sun, Mar 20, 2016 at 07:57:55PM +, Albert-Jan Roskam wrote: > > The intention is that repr() returns the "string representation" of the > > object ("what does it look like?") while str() "converts this object to > > a string". They are usually the same, but not always: > > > > py> from frac

Re: [Tutor] __str__ vs. sys.displayhook

2016-03-20 Thread Albert-Jan Roskam
> Date: Mon, 21 Mar 2016 02:50:17 +1100 > From: st...@pearwood.info > To: tutor@python.org > Subject: Re: [Tutor] __str__ vs. sys.displayhook > > On Sun, Mar 20, 2016 at 01:53:04PM +, Albert-Jan Roskam wrote: >> Hi, >> >> The other day I was playing with

Re: [Tutor] __str__ vs. sys.displayhook

2016-03-20 Thread Steven D'Aprano
On Sun, Mar 20, 2016 at 01:53:04PM +, Albert-Jan Roskam wrote: > Hi, > > The other day I was playing with this to make a convenient string version of > a named tuple: > > >>> from collections import namedtuple as nt > >>> Record = nt("Record", "x y z") > >>> Record.__str__ = lambda self: "|

Re: [Tutor] How to test function using random.randint()?

2016-03-20 Thread Steven D'Aprano
On Mon, Mar 21, 2016 at 12:18:01AM +1100, Ben Finney wrote: > boB Stepp writes: > > > On Sat, Mar 19, 2016 at 8:03 AM, Steven D'Aprano > > wrote: > > > On Sat, Mar 19, 2016 at 04:05:58PM +1100, Ben Finney wrote: > > >> if rng is None: > > >> rng = random.random > > > > > > T

[Tutor] __str__ vs. sys.displayhook

2016-03-20 Thread Albert-Jan Roskam
Hi, The other day I was playing with this to make a convenient string version of a named tuple: >>> from collections import namedtuple as nt >>> Record = nt("Record", "x y z") >>> Record.__str__ = lambda self: "| %s |" % " | ".join([item + ": " + >>> str(getattr(self, item)) for item in self._f

Re: [Tutor] Advice on multi-dimensional data storage

2016-03-20 Thread Oscar Benjamin
On 16 March 2016 at 13:21, Steven D'Aprano wrote: > On Wed, Mar 16, 2016 at 08:36:59AM +, Matt Williams wrote: >> Dear Tutors, >> >> I am looking for some advice. I have some data that has three dimensions to >> it. I would like to store it such that one could manipulate (query/ update/ >> etc

Re: [Tutor] How to test function using random.randint()?

2016-03-20 Thread Ben Finney
boB Stepp writes: > On Sat, Mar 19, 2016 at 8:03 AM, Steven D'Aprano wrote: > > On Sat, Mar 19, 2016 at 04:05:58PM +1100, Ben Finney wrote: > >> if rng is None: > >> rng = random.random > > > > Typo: you want rng = random.randint. No, I meant what I wrote. The ‘rng’ paramete

Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-20 Thread Albert-Jan Roskam
< snip lots of useful info > Hi all, Thanks a lot for all your replies. I am whole lot wiser now :) Best wishes, Albert-Jan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription optio

[Tutor] how to transform the data as below?

2016-03-20 Thread Yeh
Hi, I got messages from a MCU by using codes below: import socket import time port = s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) s.bind(("",port)) print('waiting on port:', port) while True:     data, addr = s.recvfrom(1024)     print("DATA:", data, addr)     time.sleep(100) The me

[Tutor] (SIP installation problem) Best way to install Python 3 onto Windows 10

2016-03-20 Thread CMG Thrissur
On Wednesday 16 March 2016 03:15 AM, Alan Gauld wrote: On 15/03/16 21:31, Ken G. wrote: Having acquired a new laptop yesterday with Windows 10 installed and up-to-date, what would be the best way to install the latest version of Python 3? Personally I always install ActiveState Python on Windo

Re: [Tutor] (SIP installation problem) Best way to install Python 3 onto Windows 10

2016-03-20 Thread eryk sun
On Wed, Mar 16, 2016 at 12:56 PM, Alan Gauld wrote: > On 16/03/16 12:46, CMG Thrissur wrote: > >> I tried to install activestate on win 10 but due to my ignorance or >> lack of knowlege i could n't get to install pyqt or sip. i tried it >> through pip. PyQt can't be easily installed from source

Re: [Tutor] how to transform the data as below?

2016-03-20 Thread Peter Otten
Yeh wrote: > Hi, > > I got messages from a MCU by using codes below: > > import socket > import time > > port = > s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) > s.bind(("",port)) > print('waiting on port:', port) > while True: > data, addr = s.recvfrom(1024) > print("DATA:", data, a