Re: [Tutor] MemoryError

2004-12-08 Thread Jeff Shannon
rror (cannot concatenate 'str' and 'int' objects). ;) But yes, rebinding codeSt to a new string should allow the old string to be destroyed (if there are no other references to it). Hope that this helps. Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] MemoryError

2004-12-08 Thread Jeff Shannon
#x27;re running or not. I'd have *thought*, however, that if it *is* present, you'd get a syntax error rather than a memory error, so it's probably not there but you should check it anyhow. :) Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - [EMAIL PROTECTED] http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Please help matching elements from two lists and printing them

2004-12-09 Thread Jeff Shannon
les are all of reasonable size to fit into memory. Your code makes this same assumption, too, of course. This assumption should be valid for up to a few tens of thousands (maybe even hundreds of thousands, depending on your hardware) of items. If you have more than this, then your best bet wou

Re: [Tutor] MemoryError

2004-12-09 Thread Jeff Shannon
's exactly what html parsers *do*, well, the conclusions seems obvious (to me at least). ;) There are lots of html parsing tools available in Python (though I've never needed one myself). I've heard lots of good things about BeautifulSoup... Jeff Shannon Technician/Programmer Credit Interna

Re: [Tutor] Difference between for i in range(len(object)) and for i in object

2004-12-09 Thread Jeff Shannon
get error because append method does not work on list. No -- look carefully at the tracebacks, and you'll see that nowhere does it complain about append(), nor does it give the line numbers in which the append() takes place. It complains about split(), and tells you exactly which l

Re: [Tutor] Problem with python2.4.

2004-12-09 Thread Jeff Shannon
perations. I'd check whether XP's built-in firewall is enabled, and if so, check whether it might be blocking connections to loopback / localhost / 127.0.0.1 (all of these indicate the same thing). Jeff Shannon Technician/Programmer Credit International ___

Re: [Tutor] check_range

2004-12-14 Thread Jeff Shannon
Jeff Shannon wrote: if myrange in range(10,90): # "in" is the key word here return True else return False This is, however, the correct solution. :) Or I *should* say, rather, that this is *a* correct solution, in that it will yield the expected answer. Kent Johnson'

Re: [Tutor] am I missing another simpler structure?

2004-12-16 Thread Jeff Shannon
ults of each test, only about whether I should continue afterwards or not. In this case, I'm weighing the cost of multiple returns against the cost of multiple nestings or of using flag variables, and I find multiple returns to be the lowest-cost option. Jeff Shann

Re: [Tutor] Python structure advice ?

2004-12-17 Thread Jeff Shannon
of data to operate on, or many such sets, is mostly irrelevant (though classes are even more valuable when there *are* many sets of data). Defining a class isn't so much a statement that "I want lots of things like this", as it is a declaration of modularity -- "This stuff a

Re: [Tutor] About Perl's Integer module

2004-12-17 Thread Jeff Shannon
sitename will consistently produce the same four characters. Now, here's a 'batteries-included' function that does much the same thing (though it'll be different characters). .>> def complex2(domain): ... import md5 ... digest =

Re: [Tutor] check_range

2004-12-14 Thread Jeff Shannon
e else return False This is, however, the correct solution. :) Presuming again, of course, that myrange is an integer -- but be aware that user input normally comes in the form of strings, so it will be necessary, at some point, to create an integer from that string using int(). Jeff Shannon Te

Re: [Tutor] Comments appreciated

2004-12-21 Thread Jeff Shannon
home directory to getting the home directory for whoever the current user is. You can refine main() further, too -- for instance, instead of setting an empty flag, you could just call can() as soon as you find the -e option. Jeff Shannon Technician/Programmer Credit International

Re: [Tutor] O.T.

2004-12-29 Thread Jeff Shannon
server with desktop PCs, though, I've been able to use Python for a few projects, and I often use it for interactively exploring data files and doing sysadmin-type work. Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist

Re: [Tutor] How to put my functions in an array

2004-12-29 Thread Jeff Shannon
. import func_module # ... for ... func = getattr(func_module, verb) # ... Once again, you should probably wrap that in a try/except block (this time looking for AttributeErrors). Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] My best GUI app so far.

2005-01-11 Thread Jeff Shannon
n exactly the same way that lambda does. A function object (whether named with def, or lambda) like this, which captures a variable's current state, is called a closure. Closures are indispensible for GUI callbacks like this, and many pe

Re: [Tutor] class instance with identity crisis

2005-01-12 Thread Jeff Shannon
er a Damson or a Prune, and which forwards method calls / attribute accesses to its contained object. Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How to create a key-value pairs with alternative elements in a list ... please help.

2005-01-12 Thread Jeff Shannon
= a[1::2] (Note that this is untested, as I don't have a recent version of Python handy at the moment; I'm on 2.2 here, which doesn't have extended slices.) Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - T

Re: [Tutor] Regular expression re.search() object . Please help

2005-01-13 Thread Jeff Shannon
probe_pairs.append(line) openfile.close() Either way, lines that start with 'Name=' get thrown away, and all other lines get kept. Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Re: communication between java and python?

2005-01-13 Thread Jeff Shannon
ess to the file-like pipe objects is probably buffered. You'll want to call pipe.flush() after writing to it, or the child process won't actually see what you've written. Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Regular expression re.search() object . Please help

2005-01-14 Thread Jeff Shannon
ld (IIRC this works since 2.2, which is what I usually use), I'm just in the habit of using readlines(). I suppose that, in a case like this where the filesize is not insignificant, it *would* be worthwhile to take advantage of the file iterator to avoid having that fairly large l

Re: [Tutor] file-like object

2005-01-14 Thread Jeff Shannon
ually, I'd have avoided saving the intermediary state and simply done all the list processing at once: self.list = [line+'\n' for line in self.macro.split('\n')] Either way, though, I'm creating a new list rather than modifying the old list in-place, which avoids

Re: [Tutor] Re: glob or filter help

2005-01-24 Thread Jeff Shannon
ame', '.txt') >>> I've also added a second clause to ensure that returned files are not links, as per the rest of the O.P.'s spec. Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Syntax Check

2005-01-27 Thread Jeff Shannon
import process and modify the target module before the Python parser gets it, which should enable you to avoid the SyntaxError problems. (Of course, I've never messed around with hooking __import__(), so I could just be talking out of my ...) Jeff Shannon Technic

Re: [Tutor] Better structure?

2005-02-01 Thread Jeff Shannon
x27; >>> Note that in the second case, I've included a space in the lstrip() parameter. lstrip() is essentially saying "remove all leading characters until you find a character that's not in this sequence" -- a space counts as a character. (Took m

Re: [Tutor] Better structure?

2005-02-01 Thread Jeff Shannon
the most common case, and I'm not sure that your expectation is necessarily more generally useful than the current behavior. Especially given that your behavior is the one that's easier to hand-code if it's desired. Jeff Shannon Te

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread Jeff Shannon
e as devastating as some might lead you to believe. ;) It certainly won't prevent you from using Python for functional programming... (And personally, I suspect that if lambdas *are* removed, they will be replaced with a different construct that will fill the same needs in a

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread Jeff Shannon
lenty more awful languages around that didn't happen to be "rescued" from oblivion by an accident of history...) Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread Jeff Shannon
hat the supposed advantages of anonymity come across as little more than handwaving assertions to me, no matter how sincerely they're intended. (I've just started to read through SICP, to pick up some lisp/scheme, in hopes of understanding the ap

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-03 Thread Jeff Shannon
Max Noel wrote: On Feb 3, 2005, at 23:41, Jeff Shannon wrote: (But then, at my job I'm stuck using a horrible Frankenstein's monster of a proprietary language on a daily basis, so I can't help but believe that there's plenty more awful languages around that didn't ha

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-04 Thread Jeff Shannon
Occassionally it improves readability, but more often it obscures and obfuscates. Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-07 Thread Jeff Shannon
automatically add the newline that print does (which is why I've specified it in the above sample). Indeed, print can do all sorts of odd things with whitespace, leaving sys.stdout.write() as the best way to have real control over your output a

Re: [Tutor] Are you allowed to shoot camels? [kinda OT]

2005-02-08 Thread Jeff Shannon
of saying "I want a switch, how can I implement that in Python?", I've taken the approach of "The end result I want is ***; what tools does Python offer to achieve that?" This conceptual shift is, IMHO, *the* most important mental hurdle in learning a [second/third/n-th] language. Jeff Shannon Technician/Programmer Credit International ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] dictionary dispatch for object instance attributes question

2005-02-15 Thread Jeff Shannon
step: .n = Node(**tags) You could also put all of the splitting into fields in a method, and when __init__ gets a single string as its argument simply pass it to that method and update with the results... --Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Queued threads

2005-02-16 Thread Jeff Shannon
is finished, and then return. If the thread is already finished when it's called, it returns immediately. Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] dictionary dispatch for object instance attributes question

2005-02-16 Thread Jeff Shannon
On Tue, 15 Feb 2005 23:48:31 -0500, Brian van den Broek <[EMAIL PROTECTED]> wrote: > Jeff Shannon said unto the world upon 2005-02-15 21:20: > > On Tue, 15 Feb 2005 17:19:37 -0500, Brian van den Broek > > <[EMAIL PROTECTED]> wrote: > > > > For starters, I&#x

Re: [Tutor] Help needed with script to batch-create shapefiles

2005-02-16 Thread Jeff Shannon
y the following bare except statement. That means that you'll run (what I presume to be) your error-handling code even when you successfully convert every member of fcs... Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Active Python

2005-02-17 Thread Jeff Shannon
ernal searches would be. But I suppose that there's room for reasonable people to disagree, here. :) Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] SubClassing

2005-02-27 Thread Jeff Shannon
is way: class Child(Parent): def __init__(self, new, *args, **kwargs): Parent.__init__(self, *args, **kwargs) self.new = new This way, the Child class doesn't need to know or care about what parameters get passed on to Parent; it uses the ones it needs, and passes all t

Re: [Tutor] Re: How do you share a method (function) among several objects?

2005-02-27 Thread Jeff Shannon
where it could be simplified by delegating to a Cells instance, too... Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] sys.argv[1: ] help

2005-02-27 Thread Jeff Shannon
se you'll have to research that independently. I know that you can use the "assoc" command to associate the .py extension with the Python.File filetype, but I'm not sure how to create filetypes or change actions that are taken upon filetypes if it's different from

Re: [Tutor] Criticism / Suggestions

2005-03-01 Thread Jeff Shannon
;s probably better to have Tournament and Round be independent classes, but have Tournament instances hold a list of Rounds (which may be passed in during initialization, or may be added later). This is called "composition", and is just as important (or perhaps more important) of an idea as in

Re: [Tutor] Linked List

2005-03-06 Thread Jeff Shannon
e, but when you add items to it, you also specify a priority for them. Then, when you retrieve an item from the queue, what you get is not necessarily the first-inserted item, but rather the item with highest priority. You might want to check the Cookbook to see if there's a priority queue recipe

Re: [Tutor] 2d list matrix 7 x 75 problem

2005-03-06 Thread Jeff Shannon
creating new references to the same list. > Oh PS > > Is there a more elegant solution to > > if string == 'sun' or string == 'mon' or string == 'tue' or string == > 'wed' or string == 'thu' or string == 'fri' or string == 'sat': Try: if string in ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']: (Or perhaps look into using the datetime module, depending on how detailed your needs are.) Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] unhashable objects (unrelated to previous topic)

2005-03-27 Thread Jeff Shannon
a single object will not hash the same at different points in its life, or objects which are equal will not hash identically.) Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] If elif not working in comparison

2005-03-28 Thread Jeff Shannon
a *lot* of repeated operations, e.g. a loop with many (i.e. hundreds to thousands of) iterations. Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Launching a file browser

2005-03-30 Thread Jeff Shannon
hould work the same as the rest of your GUI. Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Float precision untrustworthy~~~

2005-03-30 Thread Jeff Shannon
g why you're not getting an equality, you were wondering whether your machine had frozen? There's always a trade-off. It's important to be aware of the weaknesses of the tools that you use, but *every* tool has weaknesses, and it doesn't make sense to discard a tool just because you've learned what those weaknesses are. Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Launching a file browser

2005-04-01 Thread Jeff Shannon
exe"), which launches a separate program in an independent process. However, if you're trying to get the results of the file selection back into your own app, you need to do the file browsing within your own process (or explicitly use some form of inter

Re: [Tutor] random import errors?

2005-04-01 Thread Jeff Shannon
ect that this is probably related to either permissions or environment variables. Jeff Shannon ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

[Tutor] odd behavior within __init__

2005-04-15 Thread Jeff Shannon
e, but we won't get into that. You *don't* want to do this.) In this case, I agree that a factory is your best bet. Jeff Shannon > > class Node: > ... > def __init__(self, cargo=None, prev=None, next=None, nod=False): > """x.__