[Tutor] odd bug

2007-07-19 Thread elis aeris
I ran the code attached at the end of the email, it' supposed to out put a string of characters, yet I got only this ### 2.4.3.3.8.5. definition check: 3 ### now, it's proper output, however, this part got run only once, when it's supposed to run multiple times to produce more portio

Re: [Tutor] about importing a module

2007-07-19 Thread shawn bright
change the name of the module, simple. thanks shawn On 7/19/07, Tiger12506 <[EMAIL PROTECTED]> wrote: If the module has been imported before your code is run, it will be the library module (very important if working in IDLE which importants many modules, for example). But if it has not been imp

Re: [Tutor] python: how do I create a list of definitions?

2007-07-19 Thread Luke Paireepinart
> >> You can observe this in the following situation: >> >>> y = x = 2243 >> >>> y >> 2243 >> > > I think this is a special case of assignment. Try > y = (x = 2243) > and you will see that (x = 2243) is not an expression. > Oh. Thanks for pointing that out. I wondered why I couldn't "pr

Re: [Tutor] python: how do I create a list of definitions?

2007-07-19 Thread Kent Johnson
Luke Paireepinart wrote: >> if x = 2243: > this will always evaluate to true. No, it is a syntax error. > x is being assigned the value of 2243. 2243 is being returned by the > assignment. No, assignment is a statement, not an expression; that's why it is a syntax error. > You can observe t

Re: [Tutor] python: how do I create a list of definitions?

2007-07-19 Thread Eric Brunson
Luke Paireepinart wrote: > elis aeris wrote: > >> like, I am doing string substitution: >> >> >> if x = 2243: >> > this will always evaluate to true. > Good eye, I missed that completely... However, that will actually throw an exception. >>> if x = 1: File "", line 1 if x = 1:

Re: [Tutor] python: how do I create a list of definitions?

2007-07-19 Thread Luke Paireepinart
elis aeris wrote: > like, I am doing string substitution: > > > if x = 2243: this will always evaluate to true. x is being assigned the value of 2243. 2243 is being returned by the assignment. You can observe this in the following situation: >>> y = x = 2243 >>> y 2243 As you can see, (x = 22

Re: [Tutor] python: how do I create a list of definitions?

2007-07-19 Thread Eric Brunson
Tiger12506 wrote: >> I don't understand dict >> > > Think of dict as a dictionary. Literally. You have a word, you look up it's > definition in the dictionary. A dictionary is made up of key, value pairs. > So for your example: > > a_dict = {2243 : 'e', >2234 : 'p', >

Re: [Tutor] python: how do I create a list of definitions?

2007-07-19 Thread Tiger12506
> I don't understand dict Think of dict as a dictionary. Literally. You have a word, you look up it's definition in the dictionary. A dictionary is made up of key, value pairs. So for your example: a_dict = {2243 : 'e', 2234 : 'p', 2235 : 'lol', 'how

[Tutor] Decorators (was: Style question with classes and modules

2007-07-19 Thread Terry Carroll
On Thu, 19 Jul 2007, Kent Johnson wrote: > Here is my gentle introduction: > http://personalpages.tds.net/~kent37/kk/1.html Thanks. I see the concept, but I think the part that makes it so hard for me to really get is nicely summarized in your tutorial: Good beginner examples of real-wo

Re: [Tutor] Generators

2007-07-19 Thread Kent Johnson
Doug Glenn wrote: > Greetings all, > > Please forgive my instrusion with some simple questions. I don't have > any formal training in programming so I have to get some guidance to > some terminology from time to time. What is a generator and what is its > purpose? If you are that new to prog

[Tutor] Generators

2007-07-19 Thread Doug Glenn
Greetings all, Please forgive my instrusion with some simple questions. I don't have any formal training in programming so I have to get some guidance to some terminology from time to time. What is a generator and what is its purpose? I am planning on building a DVD catalog utility for Linux i

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Kent Johnson
Terry Carroll wrote: > On Thu, 19 Jul 2007, Kent Johnson wrote: > >> This is such a common optimization that Raymond Hettinger (the king of >> speed :-) wrote a decorator to do it automatically: > > Some day I'm going to have to figure out decorators. Well, that particular decorator is hairy, b

Re: [Tutor] python: how do I create a list of definitions?

2007-07-19 Thread elis aeris
oh, just to have some numerals translated into the later. array[n][0] = "this" array[n][1] = "= to this" On 7/20/07, Eric Brunson <[EMAIL PROTECTED]> wrote: elis aeris wrote: > like, I am doing string substitution: > > > if x = 2243: > string = string + "e" > if x = 2234: >string

Re: [Tutor] python: how do I create a list of definitions?

2007-07-19 Thread elis aeris
I don't understand dict On 7/20/07, Eric Brunson <[EMAIL PROTECTED]> wrote: elis aeris wrote: > like, I am doing string substitution: > > > if x = 2243: > string = string + "e" > if x = 2234: >string = string + "p" If I'm following correctly... How about using a dict: list = { 1: '

Re: [Tutor] python: how do I create a list of definitions?

2007-07-19 Thread Eric Brunson
elis aeris wrote: > like, I am doing string substitution: > > > if x = 2243: > string = string + "e" > if x = 2234: >string = string + "p" If I'm following correctly... How about using a dict: list = { 1: 'a', 2: 'b', 3: 'c', 2342: 'p', 4234: 'e' } if x in list: string += list[x]

[Tutor] python: how do I create a list of definitions?

2007-07-19 Thread elis aeris
like, I am doing string substitution: if x = 2243: string = string + "e" if x = 2234: string = string + "p" and so forth. how do I create this: list = [ (2342,p) (4234,e) and so forth, ] so I can use it like this: for a in range(10): If x

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Terry Carroll
On Thu, 19 Jul 2007, Kent Johnson wrote: > This is such a common optimization that Raymond Hettinger (the king of > speed :-) wrote a decorator to do it automatically: Some day I'm going to have to figure out decorators. ___ Tutor maillist - Tutor@p

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Kent Johnson
Terry Carroll wrote: > On Thu, 19 Jul 2007, Kent Johnson wrote: > >> Attribute lookup seems to have gotten better since Beazley wrote; here >> is a test program that uses three ways to access math.sqrt - module >> attribute, global name, local name. Note that in the third version, all >> three nam

Re: [Tutor] about importing a module

2007-07-19 Thread Tiger12506
If the module has been imported before your code is run, it will be the library module (very important if working in IDLE which importants many modules, for example). But if it has not been imported before, the module in the current directory is imported first. You can check if a module has been

Re: [Tutor] about importing a module

2007-07-19 Thread Tiger12506
I'm pretty sure that the one in the current directory gets imported first. However, it is much simpler to just change the name of the module in the current directory. JS > hello there, > > if i have a module that is in the same directory as the file that imports > it, > but that module has the

Re: [Tutor] reading random line from a file

2007-07-19 Thread Tiger12506
> I think the best strategy for this problem would be to build an index of > the offset of the start of each line, and then randomly select from this > list. > that makes each line equally probable, and you can set up your class so > that the index is only built on the first call to the function. >

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Terry Carroll
On Thu, 19 Jul 2007, Kent Johnson wrote: > Attribute lookup seems to have gotten better since Beazley wrote; here > is a test program that uses three ways to access math.sqrt - module > attribute, global name, local name. Note that in the third version, all > three names (sqrt, d, i) are local: .

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Kent Johnson
Tino Dai wrote: > Why do you expect a speedup? > > > In the Python Reference by David Beazley on p. 40, he substituted > import math > with from math import sqrt and he switched out d = d + math.sqrt(i) with > sqrt(i). He said that that change made the program run twice as fast. > So the

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Tino Dai
On 7/19/07, Eric Brunson <[EMAIL PROTECTED]> wrote: Tino Dai wrote: > On 7/19/07, *Kent Johnson* <[EMAIL PROTECTED] > > wrote: > > > The two advantages that I can see are, I don't need to type as > much, and > > there would be a speed up in the execution of

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Eric Brunson
Tino Dai wrote: > On 7/19/07, *Kent Johnson* <[EMAIL PROTECTED] > > wrote: > > > The two advantages that I can see are, I don't need to type as > much, and > > there would be a speed up in the execution of code. > > Why do you expect a speedup? > > > In th

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Tino Dai
For what purpose would you do this? For one thing: sheer laziness ;). But seriously, I though that if I abstracted all of those classes, it would be easier to maintain in the future. That is the real reason behind my wanting refactor that piece of code. -Tino

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Tino Dai
On 7/19/07, Kent Johnson <[EMAIL PROTECTED]> wrote: > The two advantages that I can see are, I don't need to type as much, and > there would be a speed up in the execution of code. Why do you expect a speedup? In the Python Reference by David Beazley on p. 40, he substituted import math wi

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Kent Johnson
Tino Dai wrote: > Hi there Everybody, > >I have style question with importing of modules and classes. > Presently, I have several files importing several modules. > > #apacheModule > import dbBase > import dbCommon > import miscBase > > My question is there any advantage to me wrapping

Re: [Tutor] Style question with classes and modules

2007-07-19 Thread Luke Paireepinart
Tino Dai wrote: > Hi there Everybody, > >I have style question with importing of modules and classes. > Presently, I have several files importing several modules. > > #apacheModule > import dbBase > import dbCommon > import miscBase > > My question is there any advantage to me wrapping the

Re: [Tutor] reading random line from a file

2007-07-19 Thread Luke Paireepinart
bhaaluu wrote: > Greetings, > Thanks for including the complete source code! > It really helps to have something that works to look at. > I modified an earlier version of this to run on my > computer (GNU/Linux; Python 2.4.3). > I think the best strategy for this problem would be to build an ind

Re: [Tutor] about importing a module

2007-07-19 Thread Kent Johnson
shawn bright wrote: > hello there, > > if i have a module that is in the same directory as the file that > imports it, > but that module has the same name as a module in my python path, which one > gets imported ? The local one. sys.path has the list of directories that are searched for imports

[Tutor] Style question with classes and modules

2007-07-19 Thread Tino Dai
Hi there Everybody, I have style question with importing of modules and classes. Presently, I have several files importing several modules. #apacheModule import dbBase import dbCommon import miscBase My question is there any advantage to me wrapping them in a single file (wrapper), and th

[Tutor] about importing a module

2007-07-19 Thread shawn bright
hello there, if i have a module that is in the same directory as the file that imports it, but that module has the same name as a module in my python path, which one gets imported ? i ask because i want to do some work on the module, but dont want to mess with my stable one in site-packages. so

Re: [Tutor] File parse

2007-07-19 Thread Tino Dai
On 7/18/07, Tiger12506 <[EMAIL PROTECTED]> wrote: >I sent a sample of the file "testin.txt" in the last email. Here are the > lines themsevles: Oh! Sorry. I didn't look in the attachments - I expected the lines in the email. My mistake. Try this ~~ :-P ## import

Re: [Tutor] reading random line from a file

2007-07-19 Thread bhaaluu
Greetings, Thanks for including the complete source code! It really helps to have something that works to look at. I modified an earlier version of this to run on my computer (GNU/Linux; Python 2.4.3). The os.module() stuff is new for me, so I played around with it... here's my modified file just i

Re: [Tutor] IDLE Usage - was Interpreter Restarts

2007-07-19 Thread jim stockford
here's a link to the very brief vi get-started web page: http://www.sf-lug.com/How2vi.html On Jul 17, 2007, at 11:01 AM, Sara Johnson wrote: > Sure, sounds good.  Should I assume that 'any' Unix version allows Vim? >   > Thanks, > Sara > > - Original Message > From: jim stockford <[EMA

Re: [Tutor] reading random line from a file

2007-07-19 Thread Aditya Lal
Sorry, I did not see the other thread in which this approach has already been covered. The point Kent has raised about going into infinite loop with file having single line is very true. Following is the corrected version (for completeness sake) - import os,random def getrandfromMem(filename) :

Re: [Tutor] reading random line from a file

2007-07-19 Thread Aditya Lal
An alternative approach (I found the Yorick's code to be too slow for large # of calls) : We can use file size to pick a random point in the file. We can read and ignore text till next new line. This will avoid outputting partial lines. Return the next line (which I guess is still random :)). In

Re: [Tutor] IDLE Usage - was Interpreter Restarts

2007-07-19 Thread sarliz73
Unfortunately, it's the Olympic style leaps now, the baby steps later. But I definitely agree with the process. I do have some information to plow through for now. Thanks to all! Sara > > I'd also recommend that you find and install a Windows version of whatever > editor (whether vi, vim o