Re: [Tutor] question about function inside of function

2010-01-09 Thread Richard D. Moores
On Sat, Jan 9, 2010 at 07:28, Alan Gauld wrote: > > "Richard D. Moores" wrote >> >> to be put in a function. For convenience sake, I've put this new >> function inside the one that calls it. >> >> Question 1: Is this bad practice? It works fin

[Tutor] winsound.Beep(500,500) "Failed to beep"

2010-06-12 Thread Richard D. Moores
>>> import winsound >>> winsound.Beep(500,500) Traceback (most recent call last): File "", line 1, in RuntimeError: Failed to beep >>> Vista, Python 3.1 Any ideas? Dick Moores ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscrip

[Tutor] split struggle

2010-06-22 Thread Richard D. Moores
Please see my Python 3.1 code pasted at . This does what I want, which is to do one of: 1. print all the elements of the list, lst. 2. print "Done" when "" is entered. 3. print the elements of lst whose indexes are entered. (sorry if all this is obvious) Now,

Re: [Tutor] split struggle

2010-06-22 Thread Richard D. Moores
On Tue, Jun 22, 2010 at 15:09, Alan Gauld wrote: > > "Richard D. Moores" wrote > >> This does what I want, which is to do one of: >> 1. print all the elements of the list, lst. >> 2. print "Done" when "" is entered. >> 3. print the e

Re: [Tutor] split struggle

2010-06-22 Thread Richard D. Moores
On Tue, Jun 22, 2010 at 15:09, Alan Gauld wrote: > > "Richard D. Moores" wrote > >> This does what I want, which is to do one of: >> 1. print all the elements of the list, lst. >> 2. print "Done" when "" is entered. >> 3. print the e

[Tutor] Use flag to exit?

2010-06-23 Thread Richard D. Moores
I've read (I can't remember where) that for every prime p there there are positive integers a and b such that p = a + b and such that 2**a*3**b is either 1 greater than or 1 less than another (much larger) prime. I don't know if this has been proven or not, but I've tested it on all primes 3 < p <=

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Wed, Jun 23, 2010 at 23:47, Eike Welk wrote: > On Thursday June 24 2010 07:31:47 Richard D. Moores wrote: > I hope I didn't break your algorithm; I'm typing this directly into the email > program. I did what you said (<http://tutoree7.pastebin.com/JiFS0b0K>), and get

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Wed, Jun 23, 2010 at 22:31, Richard D. Moores wrote: > I've read (I can't remember where) that for every prime p there there > are positive integers a and b such that p = a + b and such that > 2**a*3**b is either 1 greater than or 1 less than another (much > larger) prime

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 02:33, Eike Welk wrote: > On Thursday June 24 2010 09:16:05 Richard D. Moores wrote: > >> I did what you said (<http://tutoree7.pastebin.com/JiFS0b0K>), and get >> "invalid syntax" for the comma in line 40. > > Are you using Pytho

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 03:36, Eike Welk wrote: > On Thursday June 24 2010 12:15:25 Richard D. Moores wrote: >> OK. See <http://tutoree7.pastebin.com/v4T98iRL>. What now? > > Ah... my bad. Line 8 must be changed to: >        self.big_p = big_p Yes! Perfect! Now, Eike, i

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 04:55, Eike Welk wrote: > On Thursday June 24 2010 12:51:26 Richard D. Moores wrote: >> On Thu, Jun 24, 2010 at 03:36, Eike Welk wrote: >> > On Thursday June 24 2010 12:15:25 Richard D. Moores wrote: >> Yes! Perfect! Now, Eike, if I only unders

[Tutor] Line wrapping in IDLE possible? Horizontal scroll bar?

2010-06-24 Thread Richard D. Moores
I use IDLE v3.1.1 occasionally on Vista. There doesn't seem to be a way to configure it to wrap long lines (they do wrap in the IDLE shell). Or is there? Also, when there's an unwrapped long line that extends past the right edge of the window frame, the only way to see the line's tail is to place

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 05:27, Richard D. Moores wrote: > On Thu, Jun 24, 2010 at 04:55, Eike Welk wrote: >> Looking at my solution now, I think it is too complicated for your relatively >> simple use-case. I think a better solution would be to put the nested for >> loop

Re: [Tutor] Line wrapping in IDLE possible? Horizontal scroll bar?

2010-06-24 Thread Richard D. Moores
>     in \ >     ('neat', 'ha') \ >     : \ >     print \ >     i > neat > ha > >>> > you can abuse it as much as you like > On Thu, Jun 24, 2010 at 10:00 AM, Richard D. Moores > wrote: >> >> I use IDLE v3.1.1 occasionally o

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 10:13, Alan Gauld wrote: > > "Richard D. Moores" wrote > >> How can I prevent >> >> Traceback (most recent call last): >>  File "C:/P31Working/prime_to_biggest_prime_tutor3.py", line 45, in >> >>   sys.exit

Re: [Tutor] Use flag to exit?

2010-06-24 Thread Richard D. Moores
On Thu, Jun 24, 2010 at 17:06, Alan Gauld wrote: > > "Richard D. Moores" wrote > >> I think I much prefer accomplishing an exit by a function return, as I >> do in <http://tutoree7.pastebin.com/QtAAtATd>, but if I wanted to use >> sys.exit() in a scrip

Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-25 Thread Richard D. Moores
On Fri, Jun 25, 2010 at 09:48, Emile van Sebille wrote: > On 6/25/2010 9:08 AM Steve Willoughby said... >> >> On 25-Jun-10 08:23, Emile van Sebille wrote: >>> >>> On 6/25/2010 1:33 AM ALAN GAULD said... > > Copy and pasting is a PITA. Why would you want to copy and paste? >>> >>>

Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-25 Thread Richard D. Moores
On Fri, Jun 25, 2010 at 23:08, Dave Angel wrote: > Do you activate Quick-Edit mode in your DOS box?  Once you have that on, > it's not much of a pain to copy and paste, as long as what you're copying > fits a rectangle. Yes, it's on. I agree that copying is easy, but if I can't use Ctrl+V, pastin

[Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Richard D. Moores
Sorry about the OT, but I'm really nervous about the possibility of screwing up my laptop by upgrading the OS from Vista to 7, and can't think of a better place than Tutors to ask for advice. I bought this Toshiba Satellite last October. It came with the right to receive the upgrade CD for Windows

Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-26 Thread Richard D. Moores
On Fri, Jun 25, 2010 at 23:42, Dave Angel wrote: > Richard D. Moores wrote: >> >> On Fri, Jun 25, 2010 at 23:08, Dave Angel wrote: >> >>> >>> Do you activate Quick-Edit mode in your DOS box?  Once you have that on, >>> it's not much of a p

Re: [Tutor] Use flag to exit? (OT - PEP 8 Gripe)

2010-06-26 Thread Richard D. Moores
On Sat, Jun 26, 2010 at 01:21, Alan Gauld wrote: > > "Richard D. Moores" wrote >>> >>> left-drag over the desired text. >>> Right click to copy to clipboard >>> Right click again to paste into current cursor position >> >> Hey,

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Richard D. Moores
On Sat, Jun 26, 2010 at 03:10, Steven D'Aprano wrote: > On Sat, 26 Jun 2010 05:00:16 pm Richard D. Moores wrote: >> Sorry about the OT, but I'm really nervous about the possibility of >> screwing up my laptop by upgrading the OS from Vista to 7, and can't >> th

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Richard D. Moores
On Sat, Jun 26, 2010 at 11:55, Sithembewena Lloyd Dube wrote: > Richard, I think you may go ahead without trepidation. I am not a Windows > fan at all, I prefer Ubuntu. But I started using Win. 7 at work about a > month ago, and I have to say it hasn't given me cause to grumble. > > Of course, a m

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Richard D. Moores
On Sat, Jun 26, 2010 at 13:39, Sithembewena Lloyd Dube wrote: > Hi Dick, > > In that case, perhaps you could externally back up all your important stuff > and then format your hard disk. That way, any drivers etc intended for > Windows Vista will be wiped off, and you can then perform a clean > in

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-26 Thread Richard D. Moores
On Sat, Jun 26, 2010 at 15:04, Marc Tompkins wrote: > On Sat, Jun 26, 2010 at 2:30 PM, Richard D. Moores > wrote: >> >> On Sat, Jun 26, 2010 at 13:39, Sithembewena Lloyd Dube >> wrote: >> > Hi Dick, >> > >> > In that case, perhaps you cou

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-27 Thread Richard D. Moores
On Sun, Jun 27, 2010 at 07:41, Alan Gauld wrote: > "Marc Tompkins" wrote > I will miss OE. I actually quite like it, its simple but has all the bits > I need for both email and newrgroups. I tried thunderbird and use it > on my Linux box but on windows I usually revert to OE. > > And its lots be

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-27 Thread Richard D. Moores
On Sun, Jun 27, 2010 at 16:25, Steven D'Aprano wrote: > On Mon, 28 Jun 2010 03:07:47 am Richard D. Moores wrote: >> A "feature" very important to me >> is that with Gmail, my mail is just always THERE, with no need to >> download it > > You see yo

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-28 Thread Richard D. Moores
On Mon, Jun 28, 2010 at 17:32, Steven D'Aprano wrote: > On Mon, 28 Jun 2010 10:52:03 am Richard D. Moores wrote: >> On Sun, Jun 27, 2010 at 16:25, Steven D'Aprano > wrote: >> > On Mon, 28 Jun 2010 03:07:47 am Richard D. Moores wrote: >> >> A "

Re: [Tutor] OT: need computer advice from wise Tutors

2010-06-29 Thread Richard D. Moores
On Tue, Jun 29, 2010 at 01:06, Alan Gauld wrote: > "Richard D. Moores" wrote > >>> You log into Gmail and your browser downloads the Gmail page; >> >> Yes, of course. But I'm always logged into Gmail. > > But it is still continually downloading

[Tutor] puzzled by Python 3's print()

2010-07-01 Thread Richard D. Moores
>>> x = 2034 >>> x/2 1017.0 >>> print(x/2) 1e+15 I was expecting, in fact needing, 117 or 117.0 1e+15 is unsatisfactory. Am I forced to use the decimal module? Dick Moores ___ Tutor maillist - T

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Richard D. Moores
On Thu, Jul 1, 2010 at 04:57, Steven D'Aprano wrote: > On Thu, 1 Jul 2010 06:26:21 pm Richard D. Moores wrote: >> >>> x = 2034 >> >>> x/2 >> 1017.0 >> >> >>> print(x/2) >> 1e+15 >> >>

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Richard D. Moores
On Thu, Jul 1, 2010 at 09:25, Mark Lawrence wrote: > Take a look at section 7.1.3 here. > > http://docs.python.org/py3k/library/string.html#string-formatting > > This is the recommended way to format strings in Python 3. Thanks, Mark. Looks good, if cryptic. I don't have time to dig into it now

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Richard D. Moores
On Thu, Jul 1, 2010 at 12:18, Eike Welk wrote: > Therefore you should probably use the integer division operator: "//" >>> x = 200033 >>> x//2 100016 I can live with THAT error! Thanks, Eike! But I will press on with Mark

Re: [Tutor] puzzled by Python 3's print()

2010-07-01 Thread Richard D. Moores
On Thu, Jul 1, 2010 at 16:18, Steven D'Aprano wrote: > On Fri, 2 Jul 2010 05:18:00 am Eike Welk wrote: > >> As you are using long integers (and you were previously writing about >> prime numbers) the precision of floating point numbers might not be >> enough for your purposes. > > It certainly won

Re: [Tutor] (no subject)

2010-07-01 Thread Richard D. Moores
On Wed, Jun 30, 2010 at 12:33, Alan Gauld wrote: > > "Aaron Chambers" wrote in message > news:aanlktinh0ptfxhsbqrwiujml8nmuzcdcpqxscirhc...@mail.gmail.com... >> >> I'm new to Python, and wanted to start messing around with it, but the >> computer I'm using is running Windows 7, so is there a vers

Re: [Tutor] (no subject)

2010-07-02 Thread Richard D. Moores
On Fri, Jul 2, 2010 at 05:01, Malcolm Greene wrote: > Hi Richard, > > I've used Activestate's Python setups in the past with success. > > But I recently had a problem with their setups running under Windows 7 > (64-bit). I can't remember the specific problem, but after much head > scratching and f

Re: [Tutor] Help with exercises from learning to program python wikibooks

2010-07-04 Thread Richard D. Moores
On Sun, Jul 4, 2010 at 07:39, Zubin Mithra wrote: > The Python tutorial for both 2.x and 3.0 is really good. > Python 2.x - http://docs.python.org/tutorial/ > Python 3.0 - http://docs.python.org/release/3.0.1/tutorial/ The 3.0 link is broken. Try Dick Moo

[Tutor] "x and y" means "if x is false, then x, else y"??

2010-07-05 Thread Richard D. Moores
See . I am quite familiar with the meaning of "x and y" in Python, and how it is evaluated -- first x, and only if x is False, then evaluate y. But I just can't read "if x is false, then x, else y" that way. In fact,

Re: [Tutor] "x and y" means "if x is false, then x, else y"??

2010-07-05 Thread Richard D. Moores
On Mon, Jul 5, 2010 at 00:55, Steve Willoughby wrote: > On 05-Jul-10 00:27, Richard D. Moores wrote: >> >> >> See<http://docs.python.org/py3k/library/stdtypes.html#boolean-operations-and-or-not>. >> I am quite familiar with the meaning of "x and y" in Py

Re: [Tutor] "x and y" means "if x is false, then x, else y"??

2010-07-05 Thread Richard D. Moores
On Mon, Jul 5, 2010 at 04:09, Stefan Behnel wrote: > Richard D. Moores, 05.07.2010 11:37: >> >> I keep getting hung up over the meaning of "the return >> value" of an expression. I am of course familiar with values returned >> by a function, but don't

Re: [Tutor] "x and y" means "if x is false, then x, else y"??

2010-07-05 Thread Richard D. Moores
On Mon, Jul 5, 2010 at 04:54, Walter Prins wrote: > > > On 5 July 2010 08:27, Richard D. Moores wrote: >> >> See >> <http://docs.python.org/py3k/library/stdtypes.html#boolean-operations-and-or-not>. >> I am quite familiar with the meaning of "x

[Tutor] Does DreamPie work well?

2010-07-07 Thread Richard D. Moores
Thanks, Dick Moores ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

[Tutor] now = ctime()[11:20]

2010-07-16 Thread Richard D. Moores
Please see Foolishly, without thinking it through, I expected the 2 prints to show different times. I understood right away why they were identical, but then I began to wonder how to create an "alias" for "ctime()[11:20]" so I wouldn't have to keep typing or

Re: [Tutor] now = ctime()[11:20]

2010-07-17 Thread Richard D. Moores
On Sat, Jul 17, 2010 at 00:03, Alan Gauld wrote: > > "Richard D. Moores" wrote >> >> but then I began to wonder how to create an "alias" for >> "ctime()[11:20]" so I wouldn't have to keep typing or pasting it. >> "now"

Re: [Tutor] now = ctime()[11:20]

2010-07-17 Thread Richard D. Moores
On Sat, Jul 17, 2010 at 00:08, Luke Paireepinart wrote: > If you are asking how to get a variable to call a function each time it's > accessed... Well that's kind of a weird request. I know you can create > properties in a class that act like variables but you can do whatever you > want behind

[Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Richard D. Moores
That's the goal of the latest version of my script at . The best I've been able to do so far is a file with 800 million digits. But it seems the writing of 800 million digits is the limit for the amount of memory my laptop has (4 GB). So my question is, how c

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Richard D. Moores
Thanks, guys. See . It made the 1billion digits file in 213 seconds! And my laptop didn't begin to choke. You made my day! I'll consider all the binary info later. Dick ___ Tutor maillist - Tutor@python.org To un

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Richard D. Moores
On Sat, Jul 17, 2010 at 11:06, Alan Gauld wrote: > > "Richard D. Moores" wrote > >> amount of memory my laptop has (4 GB). So my question is, how can I do >> this differently? I'm pretty brand new to opening and writing files. >> Here, I can't wri

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Richard D. Moores
On Sat, Jul 17, 2010 at 13:56, Dave Angel wrote: > Your code is both far more complex than it need be, and inaccurate in the > stated goal of producing random digits. Dave, please see the code I posted in this thread more recently, . > There's no need to t

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Richard D. Moores
On Sat, Jul 17, 2010 at 15:07, Hugo Arts wrote: > On Sat, Jul 17, 2010 at 11:48 PM, Richard D. Moores > wrote: >> On Sat, Jul 17, 2010 at 13:56, Dave Angel wrote: >>> Your concern over a leading zero applies equally to two leading zeroes, or >>> three, or whatever

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Richard D. Moores
On Sat, Jul 17, 2010 at 15:39, Richard D. Moores wrote: > On Sat, Jul 17, 2010 at 15:07, Hugo Arts wrote: >> P.S.: I just thought of this: how about generating numbers that are >> one digit too long, and removing the first digit instead of adding an >> extra one? It just

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Richard D. Moores
On Sat, Jul 17, 2010 at 15:36, ALAN GAULD wrote: >> Now that you see what I want to do with 1 billion random > digits, >> please give me your suggestion(s). As I mentioned > before, >> I'm very new to reading from and writing to files. > > The way old text editors used to do this - in the days whe

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Richard D. Moores
Alan, I should have added that file.seek and file.read don't show in the 3.x docs either. Dick ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Richard D. Moores
On Sat, Jul 17, 2010 at 17:39, Hugo Arts wrote: > On Sun, Jul 18, 2010 at 2:24 AM, Richard D. Moores wrote: >> Alan, >> >> I should have added that file.seek and file.read don't show in the 3.x >> docs either. >> > > You just need to know where to l

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-17 Thread Richard D. Moores
On Sat, Jul 17, 2010 at 18:01, Steven D'Aprano wrote: > Do you care about speed? If this is a script that just needs to run > once, it seems to me that the simplest, easiest to read solution is: > > import random > def random_digit(): >    return "0123456789"[random.randrange(10)] > > f = open('ra

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-18 Thread Richard D. Moores
On Sat, Jul 17, 2010 at 18:01, Steven D'Aprano wrote: > Having generated the digits, it might be useful to look for deviations > from randomness. There should be approximately equal numbers of each > digit (100,000,000 each of 0, 1, 2, ..., 9), of each digraph > (10,000,000 each of 00, 01, 02, ..

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-18 Thread Richard D. Moores
On Sun, Jul 18, 2010 at 02:26, Steven D'Aprano wrote: > On Sun, 18 Jul 2010 06:49:39 pm Richard D. Moores wrote: > >> I might try >> trigraphs where the 2nd digit is 2 more than the first, and the third >> 2 more than the 2nd. E.g. '024', '135', &#

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-18 Thread Richard D. Moores
On Sun, Jul 18, 2010 at 05:49, Steven D'Aprano wrote: > On Sun, 18 Jul 2010 08:30:05 pm Richard D. Moores wrote: > >> > Taking the string '555', you should get two digraphs: 55_ and _55. >> >> That seems wrong to me. When I search on '99' a

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-19 Thread Richard D. Moores
On Sun, Jul 18, 2010 at 16:11, Alan Gauld wrote: > "Richard D. Moores" wrote > >>>> I earlier reported that my laptop couldn't handle even 800 million. >>> >>> What do you mean, "couldn't handle"? Couldn't handle 800 m

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-19 Thread Richard D. Moores
On Sun, Jul 18, 2010 at 11:07, bob gailer wrote: > Check this out: > > import random, time > s = time.time() > cycles = 1000 > d = "0123456789"*100 > f = open("numbers.txt", "w") > for i in xrange(n): > l = [] > l.extend(random.sample(d, 1000)) > f.write(''.join(l)) > f.close() > print time.ti

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-19 Thread Richard D. Moores
On Mon, Jul 19, 2010 at 03:59, Alan Gauld wrote: > "Richard D. Moores" wrote >> >> Still, I understand yours, and not his (the return line). > > return "%0*d" % (n, random.randrange(10**n)) > > "%0*d" > > The asterisk is quite unusu

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-19 Thread Richard D. Moores
On Mon, Jul 19, 2010 at 04:51, Peter Otten <__pete...@web.de> wrote: > bob gailer wrote: > >> Check this out: >> >> import random, time >> s = time.time() >> cycles = 1000 >> d = "0123456789"*100 >> f = open("numbers.txt", "w") >> for i in xrange(n): >>    l = [] >>    l.extend(random.sample(d, 100

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-19 Thread Richard D. Moores
On Mon, Jul 19, 2010 at 06:45, Peter Otten <__pete...@web.de> wrote: > No. If you fire up your python interpreter you can do > "0"*10 > '00' Ah, you're absolutely right. Sorry, I misunderstood you and your '*'. Good catch. Dick ___ Tutor m

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-19 Thread Richard D. Moores
On Mon, Jul 19, 2010 at 07:14, ALAN GAULD wrote: > > >> 4 and executed many times. Seems the 0 in 0 is >> there when a is a 3-digit number such as 123. >> In that case a zero is prefixed to 123 to produce >> 0123. Or if just 23, 2 zeros are prefixed, etc. >> Correct? > > Yes, the zero ind

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-19 Thread Richard D. Moores
On Mon, Jul 19, 2010 at 08:01, Steven D'Aprano wrote: > On Tue, 20 Jul 2010 12:48:13 am Richard D. Moores wrote: > You're looking in the wrong place. This is not part of format strings, > as it doesn't use the str.format() method. It uses the % string > inter

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-19 Thread Richard D. Moores
On Mon, Jul 19, 2010 at 09:58, ALAN GAULD wrote: > Heres what I did: > Search Google for "Python format strings" and from the first link click > on String Formatting operations in the contents pane: > > http://docs.python.org/library/stdtypes.html#string-formatting-operations > > Read item number

Re: [Tutor] A file containing a string of 1 billion random digits.

2010-07-19 Thread Richard D. Moores
On Mon, Jul 19, 2010 at 10:18, ALAN GAULD wrote: > Wikipedia is a little more helpful but not Python oriented: > > http://en.wikipedia.org/wiki/Printf#printf_format_placeholders Yes, that's helpful. Say, I found a use for that asterisk in this little function I just wrote: def sig_digits(n,digit

[Tutor] need help with msvcrt.getch()

2010-07-27 Thread Richard D. Moores
Python 3.1 on Vista. Please see . I'm trying to recall what I used to know, thus this simple script. But 'y' or 'q' do nothing. What's wrong? Thanks, Dick Moores ___ Tutor maillist - Tutor@python.org To unsubsc

Re: [Tutor] need help with msvcrt.getch()

2010-07-27 Thread Richard D. Moores
On Tue, Jul 27, 2010 at 07:36, Tim Golden wrote: > On 27/07/2010 15:22, Richard D. Moores wrote: > >> Python 3.1 on Vista. >> >> Please see<http://tutoree7.pastebin.com/f3TaxDBc>. >> >> I'm trying to recall what I used to know, thus this simple scr

Re: [Tutor] need help with msvcrt.getch()

2010-07-27 Thread Richard D. Moores
On Tue, Jul 27, 2010 at 07:51, Nick Raptis wrote: > On 07/27/2010 05:22 PM, Richard D. Moores wrote: > >> Python 3.1 on Vista. >> >> Please see <http://tutoree7.pastebin.com/f3TaxDBc>. >> >> I'm trying to recall what I used to know, thus this simp

Re: [Tutor] need help with msvcrt.getch()

2010-07-27 Thread Richard D. Moores
On Tue, Jul 27, 2010 at 09:09, Alan Gauld wrote: > > "Richard D. Moores" wrote > > > Please see <http://tutoree7.pastebin.com/f3TaxDBc>. >> >> I'm trying to recall what I used to know, thus this simple script. But 'y' >> or &

Re: [Tutor] need help with msvcrt.getch()

2010-07-27 Thread Richard D. Moores
On Tue, Jul 27, 2010 at 07:51, Nick Raptis wrote: > On 07/27/2010 05:22 PM, Richard D. Moores wrote: > >> Python 3.1 on Vista. >> >> Please see <http://tutoree7.pastebin.com/f3TaxDBc>. >> >> I'm trying to recall what I used to know, thus this simp

[Tutor] problem with simple script

2010-07-28 Thread Richard D. Moores
I have a practical need for a script that will give me a random int in the closed interval [n, m]. Please see . This works fine when I enter both n and m as, for example, "23, 56", or even "56, 23". But often the closed interval is [1, m], so I'd like to not

Re: [Tutor] problem with simple script

2010-07-28 Thread Richard D. Moores
On Wed, Jul 28, 2010 at 04:51, Richard D. Moores wrote: > I have a practical need for a script that will give me a random int in the > closed interval [n, m]. Please see <http://tutoree7.pastebin.com/xeCjE7bV>. > > This works fine when I enter both n and m as, for example, "

Re: [Tutor] problem with simple script

2010-07-29 Thread Richard D. Moores
On Wed, Jul 28, 2010 at 08:35, Richard D. Moores wrote: > Now I'll dig into all the help I received. I see an *args in Steven's > detailed reply. That'll take some reviewing to understand. Here's my slight revision of Steven's script (see my note, lines 9-14) -- r

Re: [Tutor] A better way for greatest common divisor

2010-07-29 Thread Richard D. Moores
On Thu, Jul 29, 2010 at 19:10, James Mills wrote: > On Fri, Jul 30, 2010 at 11:47 AM, David Hutto wrote: >> This is basically to get feedback, on a better way to show the >> greatest common divisor in fraction, in order to reduce it fully, than >> the one I've come up with. I'm sure there are bet

Re: [Tutor] A better way for greatest common divisor

2010-07-30 Thread Richard D. Moores
On Thu, Jul 29, 2010 at 18:47, David Hutto wrote: > This is basically to get feedback, on a better way to show the > greatest common divisor in fraction, in order to reduce it fully, than > the one I've come up with. I'm sure there are better ways, so if you > have simpler method, or critique of w

Re: [Tutor] A better way for greatest common divisor

2010-07-30 Thread Richard D. Moores
On Fri, Jul 30, 2010 at 17:43, David Hutto wrote: > This is the url: > http://python.pastebin.com/fP3jjqGj This is a slight revision, with my suggested changes highlighted: Dick Moores ___ Tutor maillist - Tutor@

Re: [Tutor] problem with simple script

2010-07-31 Thread Richard D. Moores
On Thu, Jul 29, 2010 at 12:22, Richard D. Moores wrote: > On Wed, Jul 28, 2010 at 08:35, Richard D. Moores wrote: > > Here's my slight revision of Steven's script (see my note, lines 9-14) > -- revised only because I wanted it to handle the case where the user > (me) en

Re: [Tutor] A better way for greatest common divisor

2010-07-31 Thread Richard D. Moores
>> On Sat, 31 Jul 2010 01:03:27 pm David Hutto wrote: > There is a difference between defining a function as a singular > activity needed to be performed, and a function that serves as a tool, > that asks for input and output, as well as serves several > utilizations, e.g., it not only accepts the

Re: [Tutor] problem with simple script

2010-08-01 Thread Richard D. Moores
I apologize for the confusion. --Dick) On Wed, Jul 28, 2010 at 08:35, Richard D. Moores wrote: > Now I'll dig into all the help I received. I see an *args in Steven's > detailed reply. That'll take some reviewing to understand. Here's my slight revision of St

[Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Richard D. Moores
is a work in progress. If I could get the script to tell whether or not the pickle files already existed, I could radically revise it (yeah, functions and all :) ). So how to find if a file exists? Vista, Python 3.1 Thanks, Dick Moores

Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Richard D. Moores
On Sun, Aug 1, 2010 at 11:33, wrote: > Richard, > > Look at the os.path.isfile function. > > Malcolm Thanks, Malcolm. That makes a tremendous difference. If anyone's curious, they see what use I've made of os.path.isfile(path): Dick > _

Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Richard D. Moores
On Sun, Aug 1, 2010 at 13:37, Steven D'Aprano wrote: > On Mon, 2 Aug 2010 04:29:39 am Richard D. Moores wrote: >> <http://tutoree7.pastebin.com/0AkVmRVJ> is a work in progress. If I >> could get the script to tell whether or not the pickle files already >> exis

Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Richard D. Moores
On Sun, Aug 1, 2010 at 15:00, Richard D. Moores wrote: > On Sun, Aug 1, 2010 at 14:44, Daniel Sarmiento wrote: >> >> Without knowing what your code does, I think it will be something like: >> >> try: >>     F_unused = open(path1, 'rb') >>

Re: [Tutor] How to get script to detect whether a file exists?

2010-08-01 Thread Richard D. Moores
On Sun, Aug 1, 2010 at 16:01, Hugo Arts wrote: > On Mon, Aug 2, 2010 at 12:53 AM, Richard D. Moores wrote: >> On Sun, Aug 1, 2010 at 15:00, Richard D. Moores wrote: >>> On Sun, Aug 1, 2010 at 14:44, Daniel Sarmiento >>> wrote: >>>> >> >>>

Re: [Tutor] How to get script to detect whether a file exists?

2010-08-02 Thread Richard D. Moores
On Sun, Aug 1, 2010 at 17:38, Hugo Arts wrote: > On Mon, Aug 2, 2010 at 2:26 AM, Richard D. Moores wrote: >> >> Well, I'd like to try. Could you give me, say, an outline of what >> might be a good way? Actually, before I changed to the error catching, >> I trie

Re: [Tutor] How to get script to detect whether a file exists?

2010-08-02 Thread Richard D. Moores
On Mon, Aug 2, 2010 at 14:28, Hugo Arts wrote: > On Mon, Aug 2, 2010 at 8:58 PM, Richard D. Moores wrote: >> >> OK, here's my attempt: <http://tutoree7.pastebin.com/3YNJLkYc>.  Better? >> > > Much better. But why is that F in the argument list of both fun

Re: [Tutor] sys.exit help

2010-08-02 Thread Richard D. Moores
On Mon, Aug 2, 2010 at 13:48, Evert Rol wrote: > (replying to the full list; hope that was intended.) > I was wondering how can I change sys.exit so if you use command line to run the program. it prompts a message asking if the user wants to exit instead of automatically just exit

Re: [Tutor] How to get script to detect whether a file exists?

2010-08-02 Thread Richard D. Moores
On Mon, Aug 2, 2010 at 15:43, Hugo Arts wrote: > On Tue, Aug 3, 2010 at 12:42 AM, Richard D. Moores wrote: >> On Mon, Aug 2, 2010 at 14:28, Hugo Arts wrote: >>> On Mon, Aug 2, 2010 at 8:58 PM, Richard D. Moores >>> wrote: >>>> >>>> OK, here&#

Re: [Tutor] How to get script to detect whether a file exists?

2010-08-02 Thread Richard D. Moores
On Mon, Aug 2, 2010 at 16:55, Alan Gauld wrote: > "Richard D. Moores" wrote > >> By golly, you're right! Your point led to changes in 4 lines, the ones >> highlighted: <http://tutoree7.pastebin.com/xDUfUAET> > > Its a Good Thing(TM) to keep your i

Re: [Tutor] How to get script to detect whether a file exists?

2010-08-02 Thread Richard D. Moores
On Mon, Aug 2, 2010 at 16:57, Steven D'Aprano wrote: >  # File *probably* doesn't exist. Consider better error checking. Steve, before I dig into your detailed reply, please tell me what you meant by " # File *probably* doesn't exist. Consider better error checking.". Context was def load(path)

Re: [Tutor] How to get script to detect whether a file exists?

2010-08-03 Thread Richard D. Moores
On Tue, Aug 3, 2010 at 08:04, Steven D'Aprano wrote: > On Tue, 3 Aug 2010 10:52:27 am Richard D. Moores wrote: >> On Mon, Aug 2, 2010 at 16:57, Steven D'Aprano > wrote: >> >  # File *probably* doesn't exist. Consider better error checking. >> >&

[Tutor] Seek suggestions for script for looking up extensions using C:\>assoc

2010-08-06 Thread Richard D. Moores
Python 3.1; Windows Vista. I just ran C:\>assoc and was amazed to see 658 associations roll by. Here's the top of the list: .001=jZip.file .386=vxdfile .3g2=QuickTime.3g2 .3gp=QuickTime.3gp .3gp2=QuickTime.3gp2 .3gpp=QuickTime.3gpp .7Z=jZip.file .aa=NeroShowTime.Files9.aa .aac=QuickTime.aac .ac3=

Re: [Tutor] Seek suggestions for script for looking up extensions usingC:\>assoc

2010-08-06 Thread Richard D. Moores
On Fri, Aug 6, 2010 at 07:56, wrote: > > You wouldn't gain much with a Pyton script. You can specify the extension > with "assoc". > > Try "assoc .zip". > > But if you want to try it anyway, look at the "popen2" module (depreciated) > or the "subprocess" module to extract the data and assign it t

[Tutor] os.urandom()

2010-08-07 Thread Richard D. Moores
using Vista, Python 3.1: >>> import os >>> os.urandom(6) b'\xd1\xfc\xb0\x14\xeaL' So what is this output? What in ascii? What in hex? Do those questions even make sense? I've tried 2 things to get at it: >>> import bina

Re: [Tutor] os.urandom()

2010-08-07 Thread Richard D. Moores
On Sat, Aug 7, 2010 at 15:26, Alan Gauld wrote: > Python is telling you its bytes with the b at the front. > The \x tells you they are hex values. > > (*)The fact its 5 is odd since you seem to pass 6 as an argument! > When I try it I get 6 bytes back. Yes, the number of bytes seems to <= 6, or

Re: [Tutor] os.urandom()

2010-08-07 Thread Richard D. Moores
On Sat, Aug 7, 2010 at 15:01, Dominik Danter wrote: > You could try something like binascii.hexlify(os.urandom(6)) to create hex. >>> os.urandom(6) b'f\xc8rnr\xea' >>> binascii.hexlify(b'f\xc8rnr\xea') b'66c8726e72ea' >>> os.urandom(6) b'D\xe9?\xda\xd80' >>> binascii.hexlify(b'D\xe9?\xda\xd80')

Re: [Tutor] os.urandom()

2010-08-07 Thread Richard D. Moores
On Sat, Aug 7, 2010 at 16:34, bob gailer wrote: > [chr(x) for x in os.urandom(6))] Correcting this to [chr(x) for x in os.urandom(6)], most of the time I get an error: >>> [chr(x) for x in os.urandom(6)] Traceback (most recent call last): File "", line 1, in File "C:\Python31\lib\encodings

Re: [Tutor] os.urandom()

2010-08-07 Thread Richard D. Moores
On Sat, Aug 7, 2010 at 17:00, Alan Gauld wrote: > > "Richard D. Moores" wrote > >> Yes, the number of bytes seems to <= 6, or is it?: >>>>> >>>>> os.urandom(6) >> >> b'\xf1\x1c\x15\x83\x14\x0e' > > ok > &

  1   2   3   4   >