Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread wesley chun
e.g. can you predict the result of the following operations without trying it? a = [1, 2, 3, 4] a[1:3] = [7, 8] print a [1, 7, 8, 4] Whew! (I really wasn't positive that it shouldn't be [1, [7, 8], 4] !) good job dick! of course, you *know* i'm going to ask this... how *do*

Re: [Tutor] Is var = None in Python equivalent to Set var = Nothingin VB?

2008-06-30 Thread Kelie
wesley chun wescpy at gmail.com writes: one question i'd like to ask is, in what context is such a line part of your code? altho alan is correct in that syntactically, they're very similar, i'm wondering what you're using it for. Wesley, Thanks for your reply (also thanks to others who

Re: [Tutor] Is var = None in Python equivalent to Set var = Nothingin VB?

2008-06-30 Thread wesley chun
Thanks for your reply (also thanks to others who replied). I was trying to translate a VBA sample in this page http://tinyurl.com/3hvj3j to python. The VBA sample has a line Set objDbx = Nothing. kelie, thanks for your reply... it helps clear things up -- i didn't think i was going to

Re: [Tutor] Is var = None in Python equivalent to Set var = Nothingin VB?

2008-06-30 Thread Andre Engels
On Mon, Jun 30, 2008 at 11:26 AM, Kelie [EMAIL PROTECTED] wrote: wesley chun wescpy at gmail.com writes: one question i'd like to ask is, in what context is such a line part of your code? altho alan is correct in that syntactically, they're very similar, i'm wondering what you're using it for.

Re: [Tutor] Is var = None in Python equivalent to Set var

2008-06-30 Thread Kent Johnson
On Mon, Jun 30, 2008 at 12:53 AM, wesley chun [EMAIL PROTECTED] wrote: As I understand it there are no cases where obj==None and obj is None will give different results (which is not true for == vs is in general), so is there any practical difference? Maybe you save a handful of cycles?

[Tutor] destroying windows

2008-06-30 Thread Jim Morcombe
I want to have a program that uses Tkinter to display a window. If the user selects an option, then I want to destroy that window and then display a second window. In turn, the user can select an option to change back to the first window and I want to destroy that window and then display the

Re: [Tutor] Deleting specified files using a python program...help with code?

2008-06-30 Thread Saad Javed
Here's the working code for my problem. But i tried it to post 'No files found' in case no specified files are found. It doesn't do that. Just simply exits. dir_input = raw_input('Enter dir: ') win_trace = ['*.ini', '*.db'] for root, dirs, files in os.walk(dir_input): for trace in

Re: [Tutor] Deleting specified files using a python program...help with code?

2008-06-30 Thread Cédric Lucantis
Le Monday 30 June 2008 16:17:45 Saad Javed, vous avez écrit : Here's the working code for my problem. But i tried it to post 'No files found' in case no specified files are found. It doesn't do that. Just simply exits. dir_input = raw_input('Enter dir: ') win_trace = ['*.ini', '*.db'] for

Re: [Tutor] need help; save web data

2008-06-30 Thread W W
On Sun, Jun 29, 2008 at 2:28 PM, Kent Johnson [EMAIL PROTECTED] wrote: Note that this may be a violation of the Google Scholar terms of service; I know it is a violation to automatically collect normal Google search results, and IIRC Google takes some steps to make it difficult as well.

Re: [Tutor] destroying windows

2008-06-30 Thread Cédric Lucantis
Le Monday 30 June 2008 14:47:39 Jim Morcombe, vous avez écrit : I want to have a program that uses Tkinter to display a window. If the user selects an option, then I want to destroy that window and then display a second window. In turn, the user can select an option to change back to the first

Re: [Tutor] Is var = None in Python equivalent to Set var

2008-06-30 Thread Tony Cappellini
Message: 5 Date: Mon, 30 Jun 2008 11:49:59 +0200 From: Andre Engels [EMAIL PROTECTED] Subject: Re: [Tutor] Is var = None in Python equivalent to Set var = Nothingin VB? To: Kelie [EMAIL PROTECTED] Cc: tutor@python.org Message-ID: [EMAIL PROTECTED] Content-Type: text/plain;

[Tutor] list objects are unhashable

2008-06-30 Thread Norman Khine
Hello, I would like to count list items but am not 100% sure how to do it. Here is what I have so far: for brain in brains: x = getattr(brain, horizontal) y = getattr(brain, vertical) if x and y and (x, y) in table: table[(x, y)] +=

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Cédric Lucantis
Le Monday 30 June 2008 20:55:36 Norman Khine, vous avez écrit : Hello, I would like to count list items but am not 100% sure how to do it. Here is what I have so far: for brain in brains: x = getattr(brain, horizontal) y = getattr(brain, vertical)

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Norman Khine
Thanks, but where do i replace the x with tuple(x) Norman Cédric Lucantis wrote: Le Monday 30 June 2008 20:55:36 Norman Khine, vous avez écrit : Hello, I would like to count list items but am not 100% sure how to do it. Here is what I have so far: for brain in brains:

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Cédric Lucantis
Le Monday 30 June 2008 21:31:35, vous avez écrit : Thanks, but where do i replace the x with tuple(x) Whenever x is hashed, ie used as a key in a dictionary. You said you have: table[(x, y)] += 1 where: x = ['airlines-scheduled', 'airport-car-parking'] so you should

Re: [Tutor] destroying windows

2008-06-30 Thread Alan Gauld
Jim Morcombe [EMAIL PROTECTED] wrote If the user selects an option, then I want to destroy that window and then display a second window. In turn, the user can select an option to change back to the first window and I want to destroy that window and then display the first again. You probably

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Alan Gauld
Norman Khine [EMAIL PROTECTED] wrote but when I run this, I get the following error on the line: if x and y and (x, y) in table: TypeError: list objects are unhashable Please post the entire error. The tiny bit you posted was not overly helpful, usually the stacjk trace contains the

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Norman Khine
Hi, Sorry, but this did not work. I have done this, which returns the values I want (sort of) for brain in brains: x = getattr(brain, horizontal) if isinstance(x, list): for item in x: x = item else:

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Dick Moores
At 11:01 PM 6/29/2008, wesley chun wrote: e.g. can you predict the result of the following operations without trying it? a = [1, 2, 3, 4] a[1:3] = [7, 8] print a [1, 7, 8, 4] Whew! (I really wasn't positive that it shouldn't be [1, [7, 8], 4] !) good job dick! of course, you *know*

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Dick Moores
At 01:39 PM 6/30/2008, Dick Moores wrote: At 11:01 PM 6/29/2008, wesley chun wrote: e.g. can you predict the result of the following operations without trying it? a = [1, 2, 3, 4] a[1:3] = [7, 8] print a [1, 7, 8, 4] Whew! (I really wasn't positive that it shouldn't be [1, [7, 8],

Re: [Tutor] Deleting specified files using a python program...help with code?]

2008-06-30 Thread David
I am learning python from books and this mailing list. I used the suggestions to come up with this; #!/usr/bin/python # Filename : new_remove-file.py import os import sys import glob dir_input = raw_input('Enter dir: ') win_trace = ['*.ini', '*.db'] files_removed = 0 for root, dirs, files in

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Jerry Hill
On Mon, Jun 30, 2008 at 4:47 PM, Dick Moores [EMAIL PROTECTED] wrote: Show me a better way? You can do it with slice assignment too: a = [1, 2, 3, 4] a[1:3] = [[7, 8]] a [1, [7, 8], 4] Now, which way is better? The answer depends on context. The best way to write it is in the manner that

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Lie Ryan
 You can do it with slice assignment too: a = [1, 2, 3, 4] a[1:3] = [[7, 8]] a [1, [7, 8], 4]  Now, which way is better? The answer depends on context. The best way to write it is in the manner that it makes the most sense to someone reading your program (including you, several

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Douglas Drumond
Thanks, Ryan, for detailed explanation; I'm learning Python now, too, so I don't know exactly how stuff works. []'s Douglas On Mon, Jun 30, 2008 at 18:33, Lie Ryan [EMAIL PROTECTED] wrote: You can do it with slice assignment too: a = [1, 2, 3, 4] a[1:3] = [[7, 8]] a [1, [7, 8], 4] 

Re: [Tutor] Is var = None in Python equivalent to Set var

2008-06-30 Thread John Fouhy
On 01/07/2008, Tony Cappellini [EMAIL PROTECTED] wrote: In VB6 ( I have not worked with VB.NET), objects are set to Nothing when they go out of scope, yet there is a fair amount lot of code out there where objects are explicitly set to Nothing. This is a pretty common practice in VB land.

Re: [Tutor] Is var = None in Python equivalent to Set var

2008-06-30 Thread Tony Cappellini
This thread got a bit off track but in Python these statements are unnecessary. What happened to Explicit is better than implicit? Regarding the original poster contrasting VB with Python setting someObject = None is perfectly fine in Python, and a good analogy between the languages.

Re: [Tutor] s[len(s):len(s)] = [x] ??

2008-06-30 Thread Alan Gauld
Jerry Hill [EMAIL PROTECTED] wrote You can do it with slice assignment too: a = [1, 2, 3, 4] a[1:3] = [[7, 8]] a [1, [7, 8], 4] Now, which way is better? The answer depends on context. If, conceptually, you are removing two elements from a list, then adding a new element which is itself

Re: [Tutor] Is var = None in Python equivalent to Set var

2008-06-30 Thread Alan Gauld
John Fouhy [EMAIL PROTECTED] wrote (I don't want to criticise VB programmers because I am not one. Follow the local conventions is generally always a good rule of programming) I think this is a key point. I'm no VB expert but I do have to read it from time to time. VB programmers tend to set

Re: [Tutor] Deleting specified files using a python program...help with code?]

2008-06-30 Thread Alan Gauld
David [EMAIL PROTECTED] wrote dir_input = raw_input('Enter dir: ') win_trace = ['*.ini', '*.db'] files_removed = 0 for root, dirs, files in os.walk(dir_input): for trace in win_trace: win_trace_path = os.path.join(root, trace) for filename in glob.glob(win_trace_path):

Re: [Tutor] Deleting specified files using a python program...help with code?]

2008-06-30 Thread David
Alan Gauld wrote: David [EMAIL PROTECTED] wrote dir_input = raw_input('Enter dir: ') win_trace = ['*.ini', '*.db'] files_removed = 0 for root, dirs, files in os.walk(dir_input): for trace in win_trace: win_trace_path = os.path.join(root, trace) for filename in

Re: [Tutor] list objects are unhashable

2008-06-30 Thread Martin Walsh
Hi Norman, Norman Khine wrote: for brain in brains: x = getattr(brain, horizontal) x = string.join(x, '' ) y = getattr(brain, vertical) y = string.join(y, '' ) if x and y and (x, y) in table: table[(x,

[Tutor] String concatenation too slow

2008-06-30 Thread Shrutarshi Basu
I'm working on a program to create Lindenmayer systems. These systems depend on heavy string rewriting to form complex patterns.I've been using string concatenation to read through the string, and then create the new one based on a dictionary lookup. However it becomes very slow once the string

Re: [Tutor] String concatenation too slow

2008-06-30 Thread wesley chun
I've been using string concatenation to read through the string, and then create the new one based on a dictionary lookup. However it becomes very slow once the string gets very long (several thousand characters). [...] I was wondering if there might be a faster alternative to string

Re: [Tutor] String concatenation too slow

2008-06-30 Thread Shrutarshi Basu
My bad, should have included some code. Here's the function which does the grunt work. self.axiom is a string, where each character gets replaced by its counterpart from self.rules. output then goes back to the calling function. That's the end of one generation of the string. The next generation