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. Bytes. Look back in this thread to
>> see my description of my laptop's problems.
>
> But you stored those in a list and then joined the list which meant you
> actually at one point had two copies of the data, one in the list and
> one in the string - that's >1.6billion bytes.
>
> And these tests suggest you only get about 2billion bytes of memory
> to use which maybe explains why you were pushed to the limit at
> 800million.

Ah. Maybe it does. Thanks, Alan.

Following Dave Angel's info about the swap file, I took a look at my
64-bit Vista paging file size. The custom setting was 5944 MB. Without
really thinking that it would help, I changed the size to 8000 MB and
rebooted. I then tried my searching script
() on the 1 billion random
digits file, changing script lines 32 and 48 appropriately. As before,
this froze my laptop and I had to do an abrupt, forced shutdown. Don't
want to do too many of those.

Now, I don't really care about what a billion random digits might
contain. The first billion digits of pi, maybe -- but the most I have
so far is 100 million. If I can get gmpy to give me 900 million more,
then I'll try to figure out how to do your trick of getting one or two
small chunks at a time for searching. I do want to learn that stuff
(tell, seek, etc.), but I need to follow along in a good elementary
book first, I think.

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-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.time() - s
>
> 1 million in ~1.25 seconds
>
> Therefore 1 billion in ~21 minutes. 3 ghz processor 2 g ram.
>
> Changing length up or down seems to increase time.

Putting "cycles" where you have "n",  I used

import random, time
s = time.time()
cycles = 100
d = "0123456789"*100
f = open("/p31working/Data/1billion_digits_rand_num_Gailor.txt", "w")
for i in range(cycles):
l = []
l.extend(random.sample(d, 1000))
f.write(''.join(l))
f.close()
print(time.time() - s)

to get 1 billion random digits into a file in 932 seconds (15.6
minutes).  , which uses Steve
D'Aprano's random_digits function, took 201 seconds (3.35 minutes).

Still, I understand yours, and not his (the return line). I'd never
noticed random.sample() before, nor tried out extend() on a list.  So
thanks, Bob.

Dick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
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-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)   # becomes same as "%02d"

'08'

"%0*d" % (7,8)   # becomes same as "%07d"

'008'

So for the return statement with n = 4 it would give 


"%04d" % x

where x is a random number from range(1).
That becomes

0

where  is the random number


The same thing can be done in two steps with:

fmt = "%0%dd" % n   # eg. gives "%04d"  if n is 4
return fmt % randrange()

But the asterisk is neater (and faster) but can become hard to 
read, and debug, if over-used - like if there are many arguments 
in a single string!


HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
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-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 it as part of the format string. So:
>
 "%0*d" % (2,8)   # becomes same as "%02d"
>
> '08'

 "%0*d" % (7,8)   # becomes same as "%07d"
>
> '008'
>
> So for the return statement with n = 4 it would give
> "%04d" % x
>
> where x is a random number from range(1).
> That becomes
>
> 0
>
> where  is the random number

Just tried it with 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?

>
>
> The same thing can be done in two steps with:
>
> fmt = "%0%dd" % n   # eg. gives "%04d"  if n is 4
> return fmt % randrange()
>
> But the asterisk is neater (and faster) but can become hard to read, and
> debug, if over-used - like if there are many arguments in a single string!
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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:

> Send Tutor mailing list submissions to
>tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>tutor-requ...@python.org
>
> You can reach the person managing the list at
>tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>   1. Re: A file containing a string of 1 billion random digits.
>  (Richard D. Moores)
>   2. Re: Help with Hangman program (Alan Gauld)
>
>
> --
>
> Message: 1
> Date: Mon, 19 Jul 2010 02:17:48 -0700
> From: "Richard D. Moores" 
> To: bob gailer 
> Cc: tutor@python.org
> Subject: Re: [Tutor] A file containing a string of 1 billion random
>digits.
> Message-ID:
>
> Content-Type: text/plain; charset=UTF-8
>
> 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.time() - s
> >
> > 1 million in ~1.25 seconds
> >
> > Therefore 1 billion in ~21 minutes. 3 ghz processor 2 g ram.
> >
> > Changing length up or down seems to increase time.
>
> Putting "cycles" where you have "n",  I used
>
> import random, time
> s = time.time()
> cycles = 100
> d = "0123456789"*100
> f = open("/p31working/Data/1billion_digits_rand_num_Gailor.txt", "w")
> for i in range(cycles):
>l = []
>l.extend(random.sample(d, 1000))
>f.write(''.join(l))
> f.close()
> print(time.time() - s)
>
> to get 1 billion random digits into a file in 932 seconds (15.6
> minutes).  , which uses Steve
> D'Aprano's random_digits function, took 201 seconds (3.35 minutes).
>
> Still, I understand yours, and not his (the return line). I'd never
> noticed random.sample() before, nor tried out extend() on a list.  So
> thanks, Bob.
>
> Dick
>
>
> --
>
> Message: 2
> Date: Mon, 19 Jul 2010 10:20:58 +0100
> From: "Alan Gauld" 
> To: tutor@python.org
> Subject: Re: [Tutor] Help with Hangman program
> Message-ID: 
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>reply-type=original
>
>
> "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
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
>
>
>
> --
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> End of Tutor Digest, Vol 77, Issue 68
> *
>
___
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-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 is not random. E. g. the start sequence "0"*101 should have a 
likelyhood of 1/10**101 but is impossible to generate with your setup.

Peter

___
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-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, 1000))
>>    f.write(''.join(l))
>> f.close()
>> print time.time() - s
>
> Note that this is not random. E. g. the start sequence "0"*101 should have a
> likelyhood of 1/10**101 but is impossible to generate with your setup.
I not sure exactly what you mean, because I don't fully understand
that '*' (despite Alan's patient explanation), but if you run

import random
cycles = 10
d = "0123456789"*10
for i in range(cycles):
   l = []
   l.extend(random.sample(d, 100))
   s = (''.join(l))
   if s[:4] == '0101':
       print(s)

You'll see a bunch of strings that begin with "0101"

Or if you run

import random
cycles = 50
d = "0123456789"*10
for i in range(cycles):
   l = []
   l.extend(random.sample(d, 100))
   s = (''.join(l))
   if s[:1] == '0':
       print(s)

You'll see some that begin with '0'.

Am I on the right track?

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-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 = []
>>> l.extend(random.sample(d, 1000))
>>> f.write(''.join(l))
>>> f.close()
>>> print time.time() - s
>>
>> Note that this is not random. E. g. the start sequence "0"*101 should
>> have a likelyhood of 1/10**101 but is impossible to generate with your
>> setup.
> I not sure exactly what you mean, because I don't fully understand
> that '*' (despite Alan's patient explanation), but if you run
> 
> import random
> cycles = 10
> d = "0123456789"*10
> for i in range(cycles):
> l = []
> l.extend(random.sample(d, 100))
> s = (''.join(l))
> if s[:4] == '0101':
> print(s)
> 
> You'll see a bunch of strings that begin with "0101"
> 
> Or if you run
> 
> import random
> cycles = 50
> d = "0123456789"*10
> for i in range(cycles):
> l = []
> l.extend(random.sample(d, 100))
> s = (''.join(l))
> if s[:1] == '0':
> print(s)
> 
> You'll see some that begin with '0'.
> 
> Am I on the right track?

No. If you fire up your python interpreter you can do

>>> "0"*10
'00'

i. e. "0"*101 is a sequence of 101 zeros. Because a sample can pick every 
item in the population only once and there are only 100 zeros, at most 100 
of them can be drawn, and the more are drawn the less likely it becomes that 
another one is drawn. The simplest demo is probably

random.sample([0, 1], 2)

Possible returns are [0, 1] and [1, 0], but for true randomness you want [1, 
1] and [0, 0], too. The more often the items are repeated the less 
pronounced that bias becomes, e. g.

random.sample([0, 1, 0, 1], 2)

can produce all combinations, but [0, 1] is twice as likely as [0, 0] 
because once the first 0 is drawn there is only one 0 left, but two 1s.
Here's a demonstration:

>>> from collections import defaultdict
>>> d = defaultdict(int)
>>> for i in range(1000):
... d[tuple(random.sample([0, 1]*2, 2))] += 1
...
>>> dict(d)
{(0, 1): 333, (1, 0): 308, (0, 0): 174, (1, 1): 185}

Peter

___
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-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 length specified. The format string 
documentation gives all the details but while zero 
padding is fairly common the asterisk is less so, that's 
why I explained it but not the zero...I assumed it was 
the asterisk that was confusing you...

HTH,

Alan G.

___
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-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 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-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 indicates that the string should be padded
> with zeros to the length specified. The format string
> documentation gives all the details

I've been unable to find any mention of that use of the asterisk in
the 3.1 docs, in

http://docs.python.org/py3k/library/string.html#formatspec

or

http://docs.python.org/py3k/library/string.html#formatstrings

Suggestion?

Dick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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? I'll take another look anyway.

Tell the function what prompt to use:

>>> import getpass
>>> s = getpass.getpass("Please enter your secret word: ")
Please enter your secret word:
>>> 
>>> print s
anti-disestablishmentarianism



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 look anyway.


Reading the documentation (15.7 in Python 3):

The getpass module provides two functions:

getpass.getpass(/prompt='Password: '/, /stream=None/)¶ 



   Prompt the user for a password without echoing. The user is prompted
   using the string /prompt/, which defaults to 'Password: '.

HTH

--
Bob Gailer
919-636-4239
Chapel Hill NC

___
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-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 23, 2 zeros are prefixed, etc.
> >> Correct?
> >
> > Yes, the zero indicates that the string should be padded
> > with zeros to the length specified. The format string
> > documentation gives all the details
>
> I've been unable to find any mention of that use of the asterisk in
> the 3.1 docs, in
>
> http://docs.python.org/py3k/library/string.html#formatspec
>
> or
>
> http://docs.python.org/py3k/library/string.html#formatstrings
>
> Suggestion?

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.python.org/py3k/library/stdtypes.html#old-string-formatting-operations


You can get the same result with the format mini-language. See the 
example "Nested arguments and more complex examples" just before the 
section on Template Strings here:

http://docs.python.org/py3k/library/string.html#format-specification-mini-language




-- 
Steven D'Aprano
___
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-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

___
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-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.python.org/mailman/listinfo/tutor


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.python.org/py3k/library/stdtypes.html#old-string-formatting-operations

Yes. I now see the asterisk use in 4. But also:

Note

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! Before that, maybe, was the
Trinity..

> You can get the same result with the format mini-language. See the
> example "Nested arguments and more complex examples" just before the
> section on Template Strings here:
>
> http://docs.python.org/py3k/library/string.html#format-specification-mini-language

OK, I'll try to sink my teeth into this. I just found that Learning
Python, 4th ed. has a discussion of all of this beginning at p.181 in
the book, or p.233 in the PDF.

Thanks, Steve.

Dick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[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 line

The code works without error but it seems that the condition is not applied.
What is the correct way of searching for multiple strings at the start of a
line.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2010-07-19 Thread John Palmer
are drawn the less likely it becomes
> that
> another one is drawn. The simplest demo is probably
>
> random.sample([0, 1], 2)
>
> Possible returns are [0, 1] and [1, 0], but for true randomness you want
> [1,
> 1] and [0, 0], too. The more often the items are repeated the less
> pronounced that bias becomes, e. g.
>
> random.sample([0, 1, 0, 1], 2)
>
> can produce all combinations, but [0, 1] is twice as likely as [0, 0]
> because once the first 0 is drawn there is only one 0 left, but two 1s.
> Here's a demonstration:
>
> >>> from collections import defaultdict
> >>> d = defaultdict(int)
> >>> for i in range(1000):
> ... d[tuple(random.sample([0, 1]*2, 2))] += 1
> ...
> >>> dict(d)
> {(0, 1): 333, (1, 0): 308, (0, 0): 174, (1, 1): 185}
>
> Peter
>
>
>
> --
>
> Message: 2
> Date: Mon, 19 Jul 2010 07:14:18 -0700 (PDT)
> From: ALAN GAULD 
> To: "Richard D. Moores" 
> Cc: tutor@python.org
> Subject: Re: [Tutor] A file containing a string of 1 billion random
>digits.
> Message-ID: <94846.12586...@web86706.mail.ird.yahoo.com>
> Content-Type: text/plain; charset=utf-8
>
>
>
> > 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 length specified. The format string
> documentation gives all the details but while zero
> padding is fairly common the asterisk is less so, that's
> why I explained it but not the zero...I assumed it was
> the asterisk that was confusing you...
>
> HTH,
>
> Alan G.
>
>
>
> --
>
> Message: 3
> Date: Mon, 19 Jul 2010 07:14:13 -0700
> From: "Richard D. Moores" 
> To: Peter Otten <__pete...@web.de>
> Cc: tutor@python.org
> Subject: Re: [Tutor] A file containing a string of 1 billion random
>digits.
> Message-ID:
>
> Content-Type: text/plain; charset=UTF-8
>
> 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
>
>
> --
>
> Message: 4
> Date: Mon, 19 Jul 2010 07:48:13 -0700
> From: "Richard D. Moores" 
> To: ALAN GAULD 
> Cc: tutor@python.org
> Subject: Re: [Tutor] A file containing a string of 1 billion random
>digits.
> Message-ID:
>
> Content-Type: text/plain; charset=UTF-8
>
> 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 indicates that the string should be padded
> > with zeros to the length specified. The format string
> > documentation gives all the details
>
> I've been unable to find any mention of that use of the asterisk in
> the 3.1 docs, in
>
> http://docs.python.org/py3k/library/string.html#formatspec
>
> or
>
> http://docs.python.org/py3k/library/string.html#formatstrings
>
> Suggestion?
>
> Dick
>
>
> --
>
> Message: 5
> Date: Tue, 20 Jul 2010 00:54:57 +1000
> From: Steven D'Aprano 
> To: tutor@python.org
> Subject: Re: [Tutor] Contents of Tutor digest, help with Hangman
>program
> Message-ID: <201007200054.57927.st...@pearwood.info>
> Content-Type: text/plain;  charset="utf-8"
>
> 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? I'll take another look anyway.
>
> Tell the function what prompt to use:
>
> >>> import getpass
> >>> s = getpass.getpass("Please enter your secret word: ")
> Please enter your secret word:
> >>>
> >>> print s
> anti-disestab

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
http://www.alan-g.me.uk/




- Original Message 
> From: Richard D. Moores 
> To: ALAN GAULD 
> Cc: tutor@python.org
> Sent: Monday, 19 July, 2010 15:48:13
> Subject: Re: [Tutor] A file containing a string of 1 billion random digits.
> 
> On Mon, Jul 19, 2010 at 07:14, ALAN GAULD <
> ymailto="mailto:alan.ga...@btinternet.com"; 
> href="mailto:alan.ga...@btinternet.com";>alan.ga...@btinternet.com> 
> 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 indicates that the string should be 
> padded
> with zeros to the length specified. The format string
> 
> documentation gives all the details

I've been unable to find any mention 
> of that use of the asterisk in
the 3.1 docs, in


> href="http://docs.python.org/py3k/library/string.html#formatspec"; 
> target=_blank 
> >http://docs.python.org/py3k/library/string.html#formatspec

or


> href="http://docs.python.org/py3k/library/string.html#formatstrings"; 
> target=_blank 
> >http://docs.python.org/py3k/library/string.html#formatstrings

Suggestion?

Dick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[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. Thanks!
___
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-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 4.

"4. Minimum field width (optional). If specified as an '*' (asterisk),
the actual width is read from the next element of the tuple in values,
and the object to convert comes after the minimum field width and
optional precision."

Now that just screams for about a dozen well-designed illustrative
examples, don't you think?

Thanks, Alan.
___
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-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.org
> Sent: Monday, 19 July, 2010 18:07:47
> Subject: Re: [Tutor] A file containing a string of 1 billion random digits.
> 
> On Mon, Jul 19, 2010 at 09:58, ALAN GAULD <
> ymailto="mailto:alan.ga...@btinternet.com"; 
> href="mailto:alan.ga...@btinternet.com";>alan.ga...@btinternet.com> 
> 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:
>
> 
> href="http://docs.python.org/library/stdtypes.html#string-formatting-operations";
>  
> target=_blank 
> >http://docs.python.org/library/stdtypes.html#string-formatting-operations
>
> 
> Read item number 4.

"4. Minimum field width (optional). If specified as 
> an '*' (asterisk),
the actual width is read from the next element of the 
> tuple in values,
and the object to convert comes after the minimum field 
> width and
optional precision."

Now that just screams for about a dozen 
> well-designed illustrative
examples, don't you think?

Thanks, 
> Alan.
___
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-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 knowing C's printf style formatting is almost a necessary skill
for a programmer because they are used in lots of lamguages
not just Python. So you would only need to learn them later is all! 
:-)


Note: This is one reason I decided to stick with the % format strings
in my v3 tutor - I'nm aiming to teach generic skills and % formatting
is much more generic than the new Python style formatting. (And
much less verbose!)


Before that, maybe, was the Trinity..


Nah, that still wins - a divine mystery :-)

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 missing with this module?


like raw_input you can supply a prompt to getpass()


import getpass as gp
gp.getpass()

Password:
'gghg'

gp.getpass("Number?")

Number?
'hjggjkh'




HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2010-07-19 Thread Timo
Message: 5
Date: Tue, 20 Jul 2010 00:54:57 +1000
From: Steven D'Aprano mailto:st...@pearwood.info>>
To: tutor@python.org <mailto:tutor@python.org>
Subject: Re: [Tutor] Contents of Tutor digest, help with Hangman
   program
Message-ID: <201007200054.57927.st...@pearwood.info
<mailto:201007200054.57927.st...@pearwood.info>>
Content-Type: text/plain;  charset="utf-8"

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? I'll take another look anyway.

Tell the function what prompt to use:

>>> import getpass
>>> s = getpass.getpass("Please enter your secret word: ")
Please enter your secret word:
>>>
>>> print s
anti-disestablishmentarianism



--
Steven D'Aprano


--

Message: 6
Date: Mon, 19 Jul 2010 10:57:11 -0400
From: bob gailer mailto:bgai...@gmail.com>>
To: John Palmer mailto:speederpyt...@gmail.com>>
Cc: tutor@python.org <mailto:tutor@python.org>
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 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 look anyway.

Reading the documentation (15.7 in Python 3):

The getpass module provides two functions:

getpass.getpass(/prompt='Password: '/, /stream=None/)?

<http://docs.python.org/py3k/library/getpass.html?highlight=getpass#getpass.getpass>

   Prompt the user for a password without echoing. The user is
prompted
   using the string /prompt/, which defaults to 'Password: '.

HTH

--
Bob Gailer
919-636-4239
Chapel Hill NC

-- next part --
An HTML attachment was scrubbed...
URL:

<http://mail.python.org/pipermail/tutor/attachments/20100719/20256873/attachment-0001.html>

--

Message: 7
Date: Tue, 20 Jul 2010 01:01:58 +1000
From: Steven D'Aprano mailto:st...@pearwood.info>>
To: tutor@python.org <mailto:tutor@python.org>
Subject: Re: [Tutor] A file containing a string of 1 billion random
   digits.
Message-ID: <201007200101.58268.st...@pearwood.info
<mailto:201007200101.58268.st...@pearwood.info>>
Content-Type: text/plain;  charset="iso-8859-1"

On Tue, 20 Jul 2010 12:48:13 am Richard D. Moores wrote:
> On Mon, Jul 19, 2010 at 07:14, ALAN GAULD
mailto:alan.ga...@btinternet.com>>
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 indicates that the string should be padded
> > with zeros to the length specified. The format string
> > documentation gives all the details
>
> I've been unable to find any mention of that use of the asterisk in
> the 3.1 docs, in
>
> http://docs.python.org/py3k/library/string.html#formatspec
>
> or
>
> http://docs.python.org/py3k/library/string.html#formatstrings
>
> Suggestion?

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.python.org/py3k/library/stdtypes.html#old-string-formatting-operations


You can get the same result with the format mini-language. See the
example "Nested arguments and more complex examples" just before the
section on Template Strings here:


http://docs.python.org/py3k/library/string.html#format-specification-mini-language




--
Steven D'Aprano


--

___
Tutor maillist  - Tutor@python.org <mailto:Tutor@python.org>
http://mail.python.org/mailman/listinfo/tutor


End of Tutor Digest, Vol 77, Issue 70
*



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
   


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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() returns a boolean result - True or False
Neither of these is in your list so the if test always passes.

You need to apply startwith to each item in your list.
You could use a list comprehension/generator expression
- or find another approach, maybe using slicing?

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




___
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-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,digits):
"""
Return any real number n to d significant digits.
"""
return '%.*g' % (digits, n)

n = -12.22345**.978
digits = 5
x = sig_digits(n, digits)
print(x)

OUTPUT: -11.568

Dick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

happen with mine:


import getpass
s = getpass.getpass("Enter your word here: ")

Warning: Password input may be echoed.
Please enter your secret word: hangman

I'm guessing that its something to do with the "Warning: Password 
may be

echoed" line. In the documentation it says:

"If echo free input is unavailable getpass() falls back to printing 
a

warning message to stream and reading
from sys.stdin and issuing a GetPassWarning."


What OS and terminal are you using?
It may be possible to enable echo free input...


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 that is not my intention. 
Thanks!


Yes there are several ways. But for the reasons you state none of them
make much sense!

You could try one or more text widgets. Or a giant label (or 
labels)...


You could use a scolled widget from the Tix module.

You could probably even create a scrolling drop down list...

Alan G 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 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 line
> 
> The code works without error but it seems that the condition is not applied. 
> What is the correct way of searching for multiple strings at the start of a 
> line.
> 
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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, at 11:18 AM, Bala subramanian 
> wrote:
>
> > 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 line
> >
> > The code works without error but it seems that the condition is not
> applied. What is the correct way of searching for multiple strings at the
> start of a line.
> >
> > ___
> > Tutor maillist  -  Tutor@python.org
> > To unsubscribe or change subscription options:
> > http://mail.python.org/mailman/listinfo/tutor
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

I recently used this code:

split_line = line.split(' ', 1)

which takes the text from the start up to the first space.

then something like:

if split_line not in [...etc]
print split_line
# or if you want the original line print line





-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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: ")
> Warning: Password input may be echoed.
> Please enter your secret word: hangman
>
> >>> s
> 'hangman'
> >>>
>
>
> I'm guessing that its something to do with the "Warning: Password may be
> echoed" line. In the documentation it says:
>
> "If echo free input is unavailable getpass() falls back to printing a
> warning message to stream and reading
> from sys.stdin and issuing a GetPassWarning."
> 


What terminal emulator are you using? Whatever it is, apparently it doesn't
offer the ability to turn off echoing - or at least it doesn't report such
things. Though AFAIK, xterm, Eterm, and gnome-terminal all are fine with
that.

-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 subscription options:
http://mail.python.org/mailman/listinfo/tutor


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/library/stdtypes.html#string-formatting-oper
> >ations
> >
> > Read item number 4.
>
> "4. Minimum field width (optional). If specified as an '*'
> (asterisk), the actual width is read from the next element of the
> tuple in values, and the object to convert comes after the minimum
> field width and optional precision."
>
> Now that just screams for about a dozen well-designed illustrative
> examples, don't you think?

Surely it only needs one?

(a) Field width known when you write the template, compared to (b) it 
being unknown when you write the template:

>>> template = "(a) %05d | (b) %0*d"
>>> template % (42, 5, 42)
'(a) 00042 | (b) 00042'


This is how you would do it with the asterisk: you need a meta-template 
to make a template.

>>> meta = "(a) %%05d | (b) %%0%dd"
>>> template = meta % 5
>>> template % (42, 42)
'(a) 00042 | (b) 00042'




-- 
Steven D'Aprano
___
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-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 | (b) 00042'



-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[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 tried to get my mind around! 

If you think that's confusing, you should try reading up on Monads.

http://en.wikipedia.org/wiki/Monad_(functional_programming)


> Before that, maybe, was the Trinity..

[Note: the following may be offensive to some Christians, in which case, 
remember that nobody has the right to not be offended, and nobody is 
forcing you to read on.]

The Trinity is simple to understand once you realise one thing -- 
despite all the obfuscatory pseudo-justifications for it, it is not 
meant to be understood, it's meant to be believed. It is a Mystery, 
something beyond human understanding. Not merely a small-m mystery, 
something which is possible to understand in principle, if we only knew 
enough. As Tertullian said (in a related but slightly different 
context):

"It is certain because it is impossible". 

Or, to paraphrase, "I believe it because it is absurd".

Like many religious beliefs (e.g. transubstantiation and dietary 
restrictions), belief in the Trinity is a shibboleth. Belief in the 
Trinity distinguishes Us ("true Christians") from Them (heretics and 
pagans[1]). The more ridiculous and crazy the belief, the more 
effective it is as a shibboleth. Anyone can believe that the son and 
the father are different people, because that's just ordinary 
common-sense[2]. But to believe that the son and the father are one and 
the same while being different *at the same time* makes no sense. It 
is, as Tertullian would almost certainly have admitted, absurd and 
ridiculous and totally crazy. Tertullian would have believed it 
*because* it was unbelievable.

It really is frightening to realise that, essentially, the Chewbacca 
Defence has held such a grip on human society for so many centuries.

http://en.wikipedia.org/wiki/Chewbacca_defense




[1] Actually many pagans also believe in trinities. But they believe in 
the *wrong* trinity: the three-as-one nature of Brahma/Vishnu/Shiva,  
Ra/Horus/Osiris, Ceres/Liber/Libera, or (two-in-one) Apollo/Bacchus is 
mere pagan superstition, while the three-as-one nature of 
Father/Son/Spirit is self-evidently true, at least according to those 
Christian sects which believe in a trinity.

[2] So rare that it ought to count as a superpower.


-- 
Steven D'Aprano
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 '*' does disappear. It's the most confusing thing
>> I've recently tried to get my mind around!
>
> If you think that's confusing, you should try reading up on Monads.
>
> http://en.wikipedia.org/wiki/Monad_(functional_programming)
>
>
>> Before that, maybe, was the Trinity..
>
> [Note: the following may be offensive to some Christians, in which case,
> remember that nobody has the right to not be offended, and nobody is
> forcing you to read on.]
>
> The Trinity is simple to understand once you realise one thing --
> despite all the obfuscatory pseudo-justifications for it, it is not
> meant to be understood, it's meant to be believed.

It is meant to be understood, and it is understood, yet man has
attachments to an 'earthly' realm, which leads to a hinderance in the
principles given to guide them...to be all Zen about it.




It is a Mystery,
> something beyond human understanding. Not merely a small-m mystery,
> something which is possible to understand in principle, if we only knew
> enough. As Tertullian said (in a related but slightly different
> context):
>
> "It is certain because it is impossible".
>
> Or, to paraphrase, "I believe it because it is absurd".
>
> Like many religious beliefs (e.g. transubstantiation and dietary
> restrictions), belief in the Trinity is a shibboleth. Belief in the
> Trinity distinguishes Us ("true Christians") from Them (heretics and
> pagans[1]). The more ridiculous and crazy the belief, the more
> effective it is as a shibboleth. Anyone can believe that the son and
> the father are different people, because that's just ordinary
> common-sense[2]. But to believe that the son and the father are one and
> the same while being different *at the same time* makes no sense.

Think of the parent child windows, while one is the master the slave
has limitations, but still can display the 'words' of the parent.

 It
> is, as Tertullian would almost certainly have admitted, absurd and
> ridiculous and totally crazy. Tertullian would have believed it
> *because* it was unbelievable.

Debate 101 can cause men to take strange stances in order to perfect
their arguments.


>
> It really is frightening to realise that, essentially, the Chewbacca
> Defence has held such a grip on human society for so many centuries.

Haven't read it yet, but will get to it eventually.
>
> http://en.wikipedia.org/wiki/Chewbacca_defense
>
>
>
>
> [1] Actually many pagans also believe in trinities. But they believe in
> the *wrong* trinity: the three-as-one nature of Brahma/Vishnu/Shiva,
> Ra/Horus/Osiris, Ceres/Liber/Libera, or (two-in-one) Apollo/Bacchus is
> mere pagan superstition,
Who can really say what is and what isn't, if your stance above is
that [It] is undefinable and a mystery to man.

 while the three-as-one nature of
> Father/Son/Spirit is self-evidently true, at least according to those
> Christian sects which believe in a trinity.
>
> [2] So rare that it ought to count as a superpower.

Anyone can believe that the son and
> the father are different people, because that's just ordinary
> common-sense[2]

How does this relate?

>
>
> --
> Steven D'Aprano
> ___
> Tutor maillist  -  tu...@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[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 Database Browser while working on my app, and occasionally the 
app tries to access the db when the Database Browser is writing to it or 
something like that.

I'd like to a) know how to reproduce the error (haven't seen it in a while, but 
want to be sure  know when it may happen for users and b) prevent it from being 
a problem in the running app.  

Any suggestions welcome.  Thank you,
Che
  
_
Hotmail is redefining busy with tools for the New Busy. Get more from your 
inbox.
http://www.windowslive.com/campaign/thenewbusy?ocid=PID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_2___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 changing the 
database through SQLite Database Browser while working on my app, and 
occasionally the app tries to access the db when the Database Browser 
is writing to it or something like that.


I'd like to a) know how to reproduce the error (haven't seen it in a 
while, but want to be sure  know when it may happen for users and b) 
prevent it from being a problem in the running app.


Any suggestions welcome.  Thank you,
Che


Hotmail is redefining busy with tools for the New Busy. Get more from 
your inbox. See how. 
 




___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
   


SQLite is technically thread safe, but a write operation locks the 
entire database [1]:

- Any resultset being step()'d through uses a shared read-only lock.
- Any insert/update being executed requires an exclusive write lock.

[1] http://www.sqlite.org/lockingv3.html

--
Kind Regards,
Christian Witts


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor