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 million of >>> what? Obviously not bytes, >> >> I meant what the context implied

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] Help with Hangman program

2010-07-19 Thread Alan Gauld
"John Palmer" wrote I have the program working nearly as I want it to be. The only problem is, that when the user is prompted to enter its chosen word, (I am using a raw input) and the word is typed in, it shows in the line above, Take a look at the getpass module. HTH, -- Alan Gauld Au

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

2010-07-19 Thread Alan Gauld
"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 unusual but basically means substitute the next argument but treat it as part of the format string. So: "%0*d" % (2,8) # becom

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 unusual but basically means substitute the next > argument but treat i

Re: [Tutor] Contents of Tutor digest, help with Hangman program

2010-07-19 Thread John Palmer
Hi Alan thanks for the help. I did try the getpass module, I think I used: getpass.getpass() This actually prompted the user to enter a password, which isn't really what I want. Unless there's something i'm missing with this module? I'll take another look anyway. On 19 July 2010 11:00, wrote

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

2010-07-19 Thread Peter Otten
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.time() - s Note that this

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 Peter Otten
Richard D. Moores wrote: > 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 = []

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

2010-07-19 Thread ALAN GAULD
> 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 indicates that the string should be padded with zeros to the

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] Contents of Tutor digest, help with Hangman program

2010-07-19 Thread Steven D'Aprano
On Mon, 19 Jul 2010 09:37:25 pm John Palmer wrote: > Hi Alan thanks for the help. I did try the getpass module, I think I > used: > > getpass.getpass() > > This actually prompted the user to enter a password, which isn't > really what I want. Unless there's something i'm missing with this > module?

Re: [Tutor] Contents of Tutor digest, help with Hangman program

2010-07-19 Thread bob gailer
On 7/19/2010 7:37 AM, John Palmer wrote: Hi Alan thanks for the help. I did try the getpass module, I think I used: getpass.getpass() This actually prompted the user to enter a password, which isn't really what I want. Unless there's something i'm missing with this module? I'll take another

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

2010-07-19 Thread Steven D'Aprano
On Tue, 20 Jul 2010 12:48:13 am Richard D. Moores wrote: > 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

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

2010-07-19 Thread bob gailer
On 7/19/2010 10:48 AM, Richard D. Moores wrote: I've been unable to find any mention of that use of the asterisk in the 3.1 docs http://docs.python.org/py3k/library/stdtypes.html#old-string-formatting -- Bob Gailer 919-636-4239 Chapel Hill NC

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

2010-07-19 Thread bob gailer
[snip] I did not read the documentation with enough understanding. I withdraw the use of sample. Sigh! -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.pyth

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 > interpolation operator. > > http://docs.pyt

[Tutor] searching for multiple strings in line.starswith()

2010-07-19 Thread Bala subramanian
Friends, I have to extract the line from a file that does not contain a set of strings in the start of the line, i wrote the following code. for index, line in enumerate(myvar.split('\n')): if line.startswith('') not in ['#Cluster','#Centroid','#End']: line=line.split() print l

Re: [Tutor] Contents of Tutor digest, Help with hangman

2010-07-19 Thread John Palmer
; really what I want. Unless there's something i'm missing with this > > module? I'll take another look anyway. > > Tell the function what prompt to use: > > >>> import getpass > >>> s = getpass.getpass("Please enter your secret word:

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

2010-07-19 Thread ALAN GAULD
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 4. :-) Alan Gauld Author of the Learn To Program website

[Tutor] System Window

2010-07-19 Thread Jacob Bender
I was wondering if there was a way to program a new window using Tkinter so that a one-billion digit number could fit, instead of in the system window, which dumps numbers once they fill up the screen. I know that it would take me days to read all of the numbers, but that is not my intention. Thank

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 ALAN GAULD
Wikipedia is a little more helpful but not Python oriented: http://en.wikipedia.org/wiki/Printf#printf_format_placeholders Alan Gauld Author of the Learn To Program website http://www.alan-g.me.uk/ - Original Message > From: Richard D. Moores > To: ALAN GAULD > Cc: tutor@python.o

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

2010-07-19 Thread Alan Gauld
"Richard D. Moores" wrote The formatting operations described here are obsolete and may go away in future versions of Python. Use the new String Formatting in new code. I hope that use of '*' does disappear. It's the most confusing thing I've recently tried to get my mind around! But knowi

Re: [Tutor] Contents of Tutor digest, help with Hangman program

2010-07-19 Thread Alan Gauld
"John Palmer" wrote Please trim your messages and not post the entire digest. Hi Alan thanks for the help. I did try the getpass module, I think I used: getpass.getpass() This actually prompted the user to enter a password, which isn't really what I want. Unless there's something i'm mis

Re: [Tutor] Contents of Tutor digest, Help with hangman

2010-07-19 Thread Timo
Subject: Re: [Tutor] Contents of Tutor digest, help with Hangman program Message-ID: <4c4467c7.1060...@gmail.com <mailto:4c4467c7.1060...@gmail.com>> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed" On 7/19/2010 7:37 AM, John

Re: [Tutor] searching for multiple strings in line.starswith()

2010-07-19 Thread Alan Gauld
"Bala subramanian" wrote I have to extract the line from a file that does not contain a set of strings in the start of the line, i wrote the following code. for index, line in enumerate(myvar.split('\n')): if line.startswith('') not in ['#Cluster','#Centroid','#End']: line.startswith()

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

Re: [Tutor] Help with hangman

2010-07-19 Thread Alan Gauld
"John Palmer" wrote Modifying the subject... And I repeat, please don't send the whole digest, delete the excess irrelevant stuff! (see below!) Thanks a lot for the help guys, but when I use the getpass.getpass(Enter your word here, I get a different response to what you get. This is what h

Re: [Tutor] System Window

2010-07-19 Thread Alan Gauld
"Jacob Bender" wrote I was wondering if there was a way to program a new window using Tkinter so that a one-billion digit number could fit, instead of in the system window, which dumps numbers once they fill up the screen. I know that it would take me days to read all of the numbers, but tha

Re: [Tutor] searching for multiple strings in line.starswith()

2010-07-19 Thread Luke Paireepinart
You are using Line.startswith incorrectly, read the docs on it and see if you can figure out your problem an key us know. Pay attention to the parameters it takes and the values it returns. Sent from my iPhone On Jul 19, 2010, at 11:18 AM, Bala subramanian wrote: > Friends, > I have to extra

Re: [Tutor] searching for multiple strings in line.starswith()

2010-07-19 Thread Joel Goldstick
On Mon, Jul 19, 2010 at 2:07 PM, Luke Paireepinart wrote: > You are using Line.startswith incorrectly, read the docs on it and see if > you can figure out your problem an key us know. Pay attention to the > parameters it takes and the values it returns. > > Sent from my iPhone > > On Jul 19, 2010,

Re: [Tutor] Contents of Tutor digest, Help with hangman

2010-07-19 Thread Wayne Werner
On Mon, Jul 19, 2010 at 11:20 AM, John Palmer wrote: > Thanks a lot for the help guys, but when I use the getpass.getpass(Enter > your word here, I get a different response to what you get. This is what > happen with mine: > > >>> import getpass > >>> s = getpass.getpass("Enter your word here: ")

Re: [Tutor] Contents of Tutor digest, Help with hangman

2010-07-19 Thread John Palmer
Right thanks for all the help guys, finally got it working. It was because as previously suggested, I was using Idle instead of the terminal. Again thanks for all the help John ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscriptio

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

2010-07-19 Thread Steven D'Aprano
On Tue, 20 Jul 2010 03:07:47 am Richard D. Moores wrote: > 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/li

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

2010-07-19 Thread Steven D'Aprano
On Tue, 20 Jul 2010 09:53:25 am Steven D'Aprano wrote: > This is how you would do it with the asterisk: you need a > meta-template to make a template. Doh! I meant *without* the asterisk. > >>> meta = "(a) %%05d | (b) %%0%dd" > >>> template = meta % 5 > >>> template % (42, 42) > > '(a) 00042 | (

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

2010-07-19 Thread Steven D'Aprano
On Tue, 20 Jul 2010 01:42:51 am Richard D. Moores wrote: > The formatting operations described here are obsolete and may go away > in future versions of Python. Use the new String Formatting in new > code. > > I hope that use of '*' does disappear. It's the most confusing thing > I've recently tri

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

2010-07-19 Thread David Hutto
On Mon, Jul 19, 2010 at 8:57 PM, Steven D'Aprano wrote: > On Tue, 20 Jul 2010 01:42:51 am Richard D. Moores wrote: > >> The formatting operations described here are obsolete and may go away >> in future versions of Python. Use the new String Formatting in new >> code. >> >> I hope that use of '*'

[Tutor] SQLite database locked problem

2010-07-19 Thread Che M
I'm using an SQLite3 database (with Python 2.5) and every so often the application crashes or hangs because somewhere there is this error, or something like it: OperationalError: database is locked. This is probably because I am viewing and sometimes changing the database through SQLite Data

Re: [Tutor] SQLite database locked problem

2010-07-19 Thread Christian Witts
On 20/07/2010 06:48, Che M wrote: I'm using an SQLite3 database (with Python 2.5) and every so often the application crashes or hangs because somewhere there is this error, or something like it: OperationalError: database is locked. This is probably because I am viewing and sometimes changin