[Tutor] References in loops

2005-02-11 Thread Matt Dimmic
In Python, one bug that often bites me is this: (example A) aList = [1,2,3] for i in aList: i += 1 print aList --> [1,2,3] This goes against my intuition, which is that aList == [2,3,4], probably because so much in Python is passed by reference and not by value. Of course I can always use ran

[Tutor] elementtree, lists, and dictionaries

2005-02-11 Thread Luis N
Hi, This code works, but I don't like it much: def authenticateAuthor(author, password): authorxml = 'author.xml' path = os.path.join(xml, authorxml) try: if not os.path.exists(path): authorfile = False else: authorfile = True tree = E.ElementTree(file=path

Re: [Tutor] default argument frustration

2005-02-11 Thread Karl Pflästerer
On 11 Feb 2005, [EMAIL PROTECTED] wrote: >> FOR THE LOVE OF MIKE can someone tell me even one reason why this >> isn't a misfeature?!?! > Its the only sane way to implement default arguments. The whole > point of function definitions is that they provide a single concise > interface. The funct

Re: ****SPAM(11.2)**** [Tutor] Larger program organization

2005-02-11 Thread Danny Yoo
> >way we ASP.NET at my company, and I'm having some trouble finding a good > >way to organize all the code. > > My take on doing that in Python: > > Organize things into modules. Especially with an eye to potential reuse. > Look at the module index in the docs to see how most of the "standard" >

Re: [Tutor] Idle needles

2005-02-11 Thread Danny Yoo
On Fri, 11 Feb 2005, Lobster wrote: > The tutorials I am accessing with Firefox and there seems to be a > conflict in which the Idle editor is trying to (or reported as accessing > the Net but does not (according to the literature and warning) Hello! IDLE does use network connections to talk t

Re: [Tutor] Negative IF conditions

2005-02-11 Thread Bob Gailer
At 01:38 PM 2/11/2005, Kent Johnson wrote: Mark Brown wrote: Hi, I'm a newbie and was wondering which of these IF conditions is better structure: 1. if not os.path.exists('filename'): I prefer the above. 2. if os.path.exists('filename') == False: They both work so if one preferred over the o

Re: [Tutor] Negative IF conditions

2005-02-11 Thread Kent Johnson
Bob Gailer wrote: At 01:38 PM 2/11/2005, Kent Johnson wrote: Note that in Python in general, 'not x' and 'x == False' are not equivalent; 'not x' will be true for many more values than just False. For example not 0 not 0.0 not [] not {} are all True. Oops. 0 and 0.0 do == False. Uh, right. Than

Re: [Tutor] Negative IF conditions

2005-02-11 Thread Bob Gailer
At 01:38 PM 2/11/2005, Kent Johnson wrote: Mark Brown wrote: Hi, I'm a newbie and was wondering which of these IF conditions is better structure: 1. if not os.path.exists('filename'): I prefer the above. 2. if os.path.exists('filename') == False: They both work so if one preferred over the o

Re: [Tutor] Negative IF conditions

2005-02-11 Thread Kent Johnson
Mark Brown wrote: Hi, I'm a newbie and was wondering which of these IF conditions is better structure: 1. if not os.path.exists('filename'): I prefer the above. 2. if os.path.exists('filename') == False: They both work so if one preferred over the other? Note that in Python in general, 'not

[Tutor] Re: Negative IF conditions

2005-02-11 Thread Andrei
Mark Brown wrote: I'm a newbie and was wondering which of these IF conditions is better structure: 1. if not os.path.exists('filename'): 2. if os.path.exists('filename') == False: I prefer the "if not" variety. Yours, Andrei ___ Tutor maillist -

Re: ****SPAM(11.2)**** [Tutor] Larger program organization

2005-02-11 Thread Bob Gailer
At 10:39 AM 2/11/2005, Ryan Davis wrote: I'm starting to make a code-generation suite in python, customized to the way we ASP.NET at my company, and I'm having some trouble finding a good way to organize all the code.  My take on doing that in Python: Organize things into modules. Especially wit

[Tutor] Idle needles

2005-02-11 Thread Lobster
Hi Just started with Idle and Python :-) The tutorials I am accessing with Firefox and there seems to be a conflict in which the Idle editor is trying to (or reported as accessing the Net but does not (according to the literature and warning) More seriously I can not run Idle and Firefox together

Re: [Tutor] Negative IF conditions

2005-02-11 Thread Bob Gailer
At 08:52 AM 2/11/2005, Mark Brown wrote: Hi, I'm a newbie and was wondering which of these IF conditions is better structure: if not os.path.exists('filename'): IMHO the above is preferable to the below. It is much more "intuitive". if os.path.exists('filename') == False: Bob Gailer mailto:[EM

Re: [Tutor] Data storage, SQL?

2005-02-11 Thread Alan Gauld
> I don't know any good on-line resources for learning SQL I like http://www.sqlcourse.com/ Its got a live SQL prompt so you can practice with their database and see the results. It seems fairly clearly written too. Caveat: I'#ve only gone through a few of the pages to check it out, I haven'

Re: [Tutor] Simple question on creating a filter

2005-02-11 Thread Danny Yoo
On Fri, 11 Feb 2005, Smith, Jeff wrote: > I'm sorry to both with such a simple question but I've looked in the > normal places and don't see the quick and dirty answer I know must > exist. > > I want to write a simple line selection filter that could be used like: > > filter < file > > I get the

Re: [Tutor] Data storage, SQL?

2005-02-11 Thread Bill Kranec
I also recommend learning SQL. It is not very hard to learn, and sometimes it may be advantageous to do data manipulation directly in the database, rather than with Python. As far as databases go, I would recommend Firebird, as I have found that it has a good number of features, is free, and

Re: [Tutor] help with refactoring needed -- which approach ismorePythonic?

2005-02-11 Thread Kent Johnson
Alan Gauld wrote: (And to pick up on someone else's question this is why you should put in a __del__ to tidy up the Node list when Body is destructed - otherwise you get circular references which can cause memory leaks by confusing the garbage collector! CPython has been able to GC cycles since ver

Re: [Tutor] Negative IF conditions

2005-02-11 Thread Alan Gauld
> I'm a newbie and was wondering which of these IF conditions is better structure: > 1.. if not os.path.exists('filename'): > 2.. if os.path.exists('filename') == False: Which one reads easiest? I'd say the first one personally. But both are OK. Alan G. _

Re: [Tutor] help with refactoring needed -- which approach ismorePythonic?

2005-02-11 Thread Alan Gauld
> My Example Body > Node List >Node the first >Node the second > > Is there any way to make methods of the Node class access attributes > of `parents' of instances? I would like a Node instance such as Node > the first above to be aware just what it is a node of and what its > s

Re: [Tutor] Re: Might be a silly question!

2005-02-11 Thread Alan Gauld
> I have been reading code written before me (mind you it's C++) and the > authors seemed to follow what ever style they wished to that day. And that's C++ style, it has no single standard approach... > that's the nature of the beast. How very true. Alan G.

Re: [Tutor] Might be a silly question!

2005-02-11 Thread Alan Gauld
> Can and if you can how do you set a variable as a constant? Only by resorting to tricks involving classes and properties. There is a cookbook recipe if I recall correctly. Vanilla Python doesn't have the concept of constants other than as a naming convention (all uppercase). Its part of the

Re: [Tutor] Simple question on creating a filter

2005-02-11 Thread Alan Gauld
> In Perl I would do: > > while (<>) > { > print if line meets selection criteria; > } You may want to check out the fileinput module. It takes care of multiple files being passed as input and such like too. > for line in sys.stdin: > if line meets selection criteria: > print line >for line

Re: [Tutor] default argument frustration

2005-02-11 Thread Alan Gauld
> > FOR THE LOVE OF MIKE can someone tell me even one reason why this > isn't a misfeature?!?! > :-) Its the only sane way to implement default arguments. The whole point of function definitions is that they provide a single concise interface. The function should return the same result each

Re: [Tutor] Data storage, SQL?

2005-02-11 Thread Alan Gauld
> I'm looking to create a prog that will store disparate bits of info > all linked together, i.e. address details for a person, transaction > records, specific themes, and the ability to search by certain > criteria, so I'm pretty sure I want a database. Sounds a lot like it! > Can anyone recomme

[Tutor] Larger program organization

2005-02-11 Thread Ryan Davis
I'm starting to make a code-generation suite in python, customized to the way we ASP.NET at my company, and I'm having some trouble finding a good way to organize all the code.  I keep writing it, but it feels more and more spaghetti-ish every day.   I'm going to look at the other stuff i

Re: [Tutor] help with refactoring needed -- which approach is morePythonic?

2005-02-11 Thread Kent Johnson
Brian van den Broek wrote: Alan Gauld said unto the world upon 2005-02-10 02:58: Pseudo code: class Body: def __init__(self,content): self.contents = contents self.nodes = [] def parse(self): for line in self.contents:

Re: [Tutor] help with refactoring needed -- which approach is morePythonic?

2005-02-11 Thread Jeremy Jones
Brian van den Broek wrote: Alan Gauld said unto the world upon 2005-02-10 02:58: Pseudo code: class Body: def __init__(self,content): self.contents = contents self.nodes = [] def parse(self): for line in self.contents:

Re: [Tutor] help with refactoring needed -- which approach is morePythonic?

2005-02-11 Thread Brian van den Broek
Alan Gauld said unto the world upon 2005-02-10 02:58: Pseudo code: class Body: def __init__(self,content): self.contents = contents self.nodes = [] def parse(self): for line in self.contents: if line == NodeStartTag:

Re: [Tutor] Negative IF conditions

2005-02-11 Thread Jeremy Jones
Mark Brown wrote: Hi, I'm a newbie and was wondering which of these IF conditions is better structure: if not os.path.exists('filename'): if os.path.exists('filename') == False: My preference would be the first (if not os.path.exists).  os.path.exists returns a boolean (I

[Tutor] Negative IF conditions

2005-02-11 Thread Mark Brown
Hi, I'm a newbie and was wondering which of these IF conditions is better structure: if not os.path.exists('filename'): if os.path.exists('filename') == False: They both work so if one preferred over the other? Thanks Mark Brown ___ Tutor ma

[Tutor] Re: Might be a silly question!

2005-02-11 Thread Jeffrey Maitland
Thanks that's what I thought. Wasn't 100% sure that is what prompted me to ask the question in here. As for the CAPS thing for constants, I generally try and practice (to the best of my knowledge) proper programming consepts/styles/standards. However I have been reading code written before me

Re: [Tutor] Might be a silly question!

2005-02-11 Thread Bill Mill
Jeff, On Fri, 11 Feb 2005 10:03:30 -0500, Jeffrey Maitland <[EMAIL PROTECTED]> wrote: > > Hello all, > > I am drawing a blank right now and can't seem to find anything on it and I > am sure this issue has been addressed before, so here is the question. > > Can and if you can how do you set a va

RE: [Tutor] Simple question on creating a filter

2005-02-11 Thread Smith, Jeff
Good catch Bill, I was using assoc and ftype to allow me to run my filter.py directly as a command and using: filter < file Unfortunately, Windows doesn't handle this properly and I had to do C:\Python24\python filter.py < file To get it to work. Thanks, Jeff P.S. In retrospect, I've had the

[Tutor] Might be a silly question!

2005-02-11 Thread Jeffrey Maitland
Hello all, I am drawing a blank right now and can't seem to find anything on it and I am sure this issue has been addressed before, so here is the question. Can and if you can how do you set a variable as a constant? Example of what I mean: (this is loose and not python since variable type

Re: [Tutor] Simple question on creating a filter

2005-02-11 Thread Bill Mill
On Fri, 11 Feb 2005 09:28:35 -0500, Smith, Jeff <[EMAIL PROTECTED]> wrote: > I'm sorry to both with such a simple question but I've looked in the > normal places and don't see the quick and dirty answer I know must > exist. > No worries; that's what this list is for. > I want to write a simple l

[Tutor] Simple question on creating a filter

2005-02-11 Thread Smith, Jeff
I'm sorry to both with such a simple question but I've looked in the normal places and don't see the quick and dirty answer I know must exist. I want to write a simple line selection filter that could be used like: filter < file In Perl I would do: while (<>) { print if line meets selec

Re: [Tutor] Data storage, SQL?

2005-02-11 Thread Kent Johnson
Kent Johnson wrote: I don't know any good on-line resources for learning SQL The Wikipedia entry for SQL has links to quite a few tutorials: http://en.wikipedia.org/wiki/Sql Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listi

Re: [Tutor] default argument frustration

2005-02-11 Thread Kent Johnson
Brian van den Broek wrote: At first, I ended up with every single node being a copy of the first one processed. A bit of weeping later, I realized that this is from the feature [?] of Python that default arguments are evaluated just once. (Note the comment added above.) FOR THE LOVE OF MIKE ca

Re: [Tutor] Data storage, SQL?

2005-02-11 Thread Kent Johnson
Kent Johnson wrote: SQL is a standardized language for giving commands to databases. Most (all?) industrial-strength databases use SQL as their command language. (DB-API is actually a wrapper around SQL - it standardizes the API to issue a SQL command and read the results.) SQL is kind of a str

[Tutor] Database

2005-02-11 Thread Matt Williams
I would recommend KirbyBase as a quick starter - it's nice and simple, and outputs text files, so you can always check things manually. http://www.netpromi.com/kirbybase.html Matt ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/

Re: [Tutor] Data storage, SQL?

2005-02-11 Thread Kent Johnson
Liam Clarke wrote: Hi, I'm looking to create a prog that will store disparate bits of info all linked together, i.e. address details for a person, transaction records, specific themes, and the ability to search by certain criteria, so I'm pretty sure I want a database. Can anyone recommend a usef

[Tutor] default argument frustration

2005-02-11 Thread Brian van den Broek
Alan Gauld said unto the world upon 2005-02-10 02:58: class Node: def __init__(self,lines=[]): # here's the zowie BvdB self.lines = lines def append(self,item): self.lines.append(item) def parse(self): #