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

2010-07-17 Thread Alan Gauld
"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" would be fine. But how to get it to execute ctime()? Create a function? def myNow(): return ctime()[11:20] Or am I missing somethin

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

2010-07-17 Thread Luke Paireepinart
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 the scenes, like calling the now() function on each access. A muc

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

2010-07-17 Thread Luke Paireepinart
Sorry the iPhone email client is terrible. It sent the previous email before I was done writing it. Anyway, the timeit module is available whenever you want to profile something and determine how long it takes to run. Sent from my iPhone On Jul 17, 2010, at 1:32 AM, "Richard D. Moores" wrote:

[Tutor] Strange sqlite3 behavior

2010-07-17 Thread Lang Hurst
I just had the weirdest issue with sqlite3. I was trying to update a field to "Active". I have a little database of students and sometimes they get sent to juvi, or just check out for a couple of months and show back up. Anyway, I wanted to just have a field that had either "Active" or "Inac

Re: [Tutor] Strange sqlite3 behavior

2010-07-17 Thread Tim Golden
On 17/07/2010 8:10 AM, Lang Hurst wrote: I just had the weirdest issue with sqlite3. I was trying to update a field to "Active". I have a little database of students and sometimes they get sent to juvi, or just check out for a couple of months and show back up. Anyway, I wanted to just have a

Re: [Tutor] append, list and variables

2010-07-17 Thread pk
Dnia 17-07-2010 o 02:57:46 Steven D'Aprano napisał(a): On Sat, 17 Jul 2010 05:44:07 am pk wrote: In general, the shorter and more descriptive a variable name is, the better. That's a generalisation that is contradictory. Short works against descriptive. Compare: Well, yes I agree. I've

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" would be fine. But how to get it to execute ctime()? > > Create a function? >

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 Hugo Arts
On Sat, Jul 17, 2010 at 2:01 PM, Richard D. Moores wrote: > 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

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

2010-07-17 Thread bob gailer
On 7/17/2010 8:01 AM, Richard D. Moores wrote: 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 memo

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

2010-07-17 Thread Mark Lawrence
On 17/07/2010 13:01, Richard D. Moores wrote: 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 memor

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

2010-07-17 Thread bob gailer
On 7/17/2010 9:01 AM, Mark Lawrence wrote: [snip] As an alternative to the suggestions given so far, why not open the file for write in binary mode, i.e. use 'wb' instead of 'w', and don't bother converting to strings? Then when reading the file use 'rb' instead of 'r'. You can only write

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

2010-07-17 Thread Hugo Arts
On Sat, Jul 17, 2010 at 3:34 PM, bob gailer wrote: > > You can only write strings to files. See 6.9 in the documentation: > file.write(str) Write a string to the file b mode only affects how line ends > are handled. See 2. Built-in Functions: > > The default is to use text mode, which may convert

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 Alan Gauld
"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 write many shorter lines, because the end result I seek is one long string. But am I correct? Others have ans

Re: [Tutor] Strange sqlite3 behavior

2010-07-17 Thread Lang Hurst
On 07/17/2010 02:04 AM, Tim Golden wrote: On 17/07/2010 8:10 AM, Lang Hurst wrote: I just had the weirdest issue with sqlite3. I was trying to update a field to "Active". I have a little database of students and sometimes they get sent to juvi, or just check out for a couple of months and show

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

2010-07-17 Thread Dave Angel
Richard D. Moores wrote: 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

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 write many shorter lines, because the end result I se

[Tutor] Return error message for my script in Blender

2010-07-17 Thread Andrew Martin
I am new to Blender and Python (2.6 on vista) and was trying to follow a tutorial in the book Blender 2.49 Scripting by Michel Anders. I was trying to write a script that would create a user interface where the user could select various aspect of an insect and the code would create a polygonal bug.

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 Hugo Arts
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. > > I don't think so. Look again at my function, randIntOfGivenLength(). > Try a for l

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

2010-07-17 Thread ALAN GAULD
> 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 when we only had 16K RAM etc! was to use buffers and pages.

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. >> >> I don't think so. Look

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 gets rid of the digit ex

Re: [Tutor] Return error message for my script in Blender

2010-07-17 Thread bob gailer
On 7/17/2010 5:11 PM, Andrew Martin wrote: I am new to Blender and Python (2.6 on vista) and was trying to follow a tutorial in the book Blender 2.49 Scripting by Michel Anders. I was trying to write a script that would create a user interface where the user could select various aspect of an in

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 Hugo Arts
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 look: http://docs.python.org/py3k/library/io.html#io.IOBase.tell read and seek are in there as well. There

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

2010-07-17 Thread Steven D'Aprano
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('rand_digits.txt', 'w') for i in xrange(10**9): f.write(random_dig

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 look: > > http://docs.python.org/py3k/library/io.

Re: [Tutor] Return error message for my script in Blender

2010-07-17 Thread Steven D'Aprano
On Sun, 18 Jul 2010 07:11:19 am Andrew Martin wrote: > I am new to Blender and Python (2.6 on vista) and was trying to > follow a tutorial in the book Blender 2.49 Scripting by Michel > Anders. I was trying to write a script that would create a user > interface where the user could select various a

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-17 Thread Luke Paireepinart
On Jul 17, 2010, at 7:19 PM, "Richard D. Moores" wrote: > I don't fully understand your "you always have two [chunks] in memory > at once". Does that take care of the overlap I think I need? I don't > want you or anyone to give me the the whole answer, but could you > clarify a bit about keeping

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

2010-07-17 Thread Alan Gauld
"Richard D. Moores" wrote I don't fully understand your "you always have two [chunks] in memory at once". Does that take care of the overlap I think I need? I don't want you or anyone to give me the the whole answer, but could you clarify a bit about keeping 2 chunks in memory? Luke gave a g