Re: [Tutor] Alan's responce frustrated beginner

2005-09-29 Thread Alan G
>I want to save this file, import it and make the changes, eggs = >toast, spam > = jelly and change the values if needed. > > def firstpart(): > for n in range(0, 55): > if n % 3 == 0 or n % 7 == 0 or n % 11 == 0: > print 'eggs,', > else: > print 'spam,', There are

Re: [Tutor] Flattening multi-dimentional list

2005-09-29 Thread Alan G
> I have this list wich is made of tuples. I wish I could "flatten" > this list, that is, to extract each element in the tuples and > build a new flat list with it. Recursion is often used for this, there is an example function in my tutorial topic on recursion (using nested lists rather than

Re: [Tutor] Flattening multi-dimentional list

2005-09-29 Thread Pujo Aji
Hi,   Use this:def _flatten(seq,myhasil): for isi in seq: if type(isi) != str: try: _flatten(isi,myhasil) except: myhasil.append(isi) else: myhasil.append(isi) def flatten(seq): '''code to flatten tupple''' hasil = [] _flatten(seq,hasil) return

[Tutor] New-style classes

2005-09-29 Thread Jan Eden
Hi, after updating a program to use new-style classes, I am a bit confused. My setup looks like this (simplified): #Show.py import Data class Base(object): ... class Page(Data.Page, Base): ... class Author(Data.Author, Base): ... #Data.py class Base: ... class Page(Base):

Re: [Tutor] Prevent "Coder's Remorse"?

2005-09-29 Thread Kent Johnson
Kent Johnson wrote: > I'm curious about why you want to do this, it is kind of a strange > requirement. But anyway, here is a class that subclasses dict and > presents the interface you want to client code. It doesn't actually > update all instances when you add or delete a key; it keeps a list of

Re: [Tutor] Prevent "Coder's Remorse"?

2005-09-29 Thread Kent Johnson
Ron Phillips wrote: > Maybe I should explain why I thought I wanted this object. I am trying > to read, edit, and write shapefiles (actually, a shapefile is a > collection of 3-6 files having the same filename, but different > extensions. It's a legacy format that still gets a lot of use in > geogr

[Tutor] Generalising system processes

2005-09-29 Thread Peter Jessop
Good day. Is there a library in Python that generalises the display of processes in the system. I am looking for a consistent way of seeing processess, (a python equivalent of ps(unix) or tasklist (windows). I have googled but the only suggestion I have found was to install ps on Windows. Thanks

Re: [Tutor] New-style classes

2005-09-29 Thread Kent Johnson
Jan Eden wrote: > Hi, > > after updating a program to use new-style classes, I am a bit confused. My > setup looks like this (simplified): > > #Show.py > > import Data > > class Base(object): > ... > > class Page(Data.Page, Base): > ... > > class Author(Data.Author, Base): > ...

Re: [Tutor] Problem with BeautifulSoup

2005-09-29 Thread Kent Johnson
(resending to the whole list) Bernard Lebel wrote: > Hi Kent, > > Thanks a lot for that answer. I have had a look at the BS code, and I > have to admit I'm a bit at a loss: how would you add several nestable > tag names in that list? > > I tried > NESTABLE_TAGS = BeautifulSoup.buildTagMap( [], '

[Tutor] Installing ActiveState Python vs2003

2005-09-29 Thread Mohammad Moghimi
Hi When I tried  to install activestate python(.net implementation of python) to my visual studio 2003. It gives me this error message: The Visual Python Installer found an installation of Python 2.

Re: [Tutor] New-style classes

2005-09-29 Thread Jan Eden
Hi Kent, Kent Johnson wrote on 29.09.2005: >>Data.Base has no base classes, so it is not based on a built-in >>type: How can it be a new-style class? > >Data.Base is not a new-style class, but the classes in Show are. And >properties may appear to work in old-style classes. This document >http://

Re: [Tutor] Generalising system processes

2005-09-29 Thread R. Alan Monroe
> Is there a library in Python that generalises the display of processes > in the system. > I am looking for a consistent way of seeing processess, (a python > equivalent of ps(unix) or tasklist (windows). > I have googled but the only suggestion I have found was to install ps > on Windows. On Wi

Re: [Tutor] Flattening multi-dimentional list

2005-09-29 Thread Bernard Lebel
Thanks for the examples and references everyone. I should clarify though that I was simply looking for a *built-in* feature rather than a function or a list-comprehension. I know these last two works and I currently use a list comprehension. # Example: >>> flatten( [ 1, 3, 4, ('allo', 'bonjour',

Re: [Tutor] New-style classes

2005-09-29 Thread Kent Johnson
Jan Eden wrote: > My actual code looks like this: > > class Base: > def GetOwnType(self): > try: return self._own_type > except: return self.child_type > > def SetOwnType(self, value): > self._own_type = value > > own_type = property(GetOwnType, Se

[Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Jay Loden
I've not been able to find an answer to this conundrum anywhere: My current website is done in PHP with a setup something like this: ::PHP TEMPLATE CODE:: include('file.htm') ::PHP TEMPLATE CODE:: This way, I can have PHP embedded in my htm files and it will be processed as part of the scri

Re: [Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Adam Cripps
On 9/29/05, Jay Loden <[EMAIL PROTECTED]> wrote: > I've not been able to find an answer to this conundrum anywhere: > > My current website is done in PHP with a setup something like this: > > ::PHP TEMPLATE CODE:: > > include('file.htm') > > ::PHP TEMPLATE CODE:: > > This way, I can have PHP embedd

Re: [Tutor] call a def/class by reference

2005-09-29 Thread DS
bob wrote: > At 04:29 PM 9/28/2005, DS wrote: > >> What I'm hoping to avoid is an >> explicit reference to any of the called functions within the program. >> By doing it that way, it would avoid a maintenance problem of having to >> remember to put a reference for every new function in the calling

Re: [Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Christopher Arndt
Jay Loden schrieb: > I can't figure out how one would approach this in Python (i'm using > mod_python). There's no equivalent to the "include" function from PHP. I > can't use import because then Python would try to parse the HTML from the > imported file. I've looked at stuff like cheetah and P

Re: [Tutor] FW: Frustrated Beginner

2005-09-29 Thread Daniel Watkins
Rosalee Dubberly wrote: > ## Now I am trying to modify the function to replace eggs with toast > and spam with jelly. I have spent days and nothing works. Can you send > me in the right direction?? The obvious answer (that has already been mentioned) is to simply replace the words in the actual p

Re: [Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Alan G
>> can't use import because then Python would try to parse the HTML >> from the >> imported file. > > I thought PHP also parsed any html rendered through an included > file? It does but PHP 'understands' HTML - or more specifically ignores it! Alan G. _

Re: [Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Alan G
> My current website is done in PHP with a setup something like this: > > ::PHP TEMPLATE CODE:: > > include('file.htm') > > ::PHP TEMPLATE CODE:: > > This way, I can have PHP embedded in my htm files and it will be > processed as > part of the script. OK, But PHP uses server side scripting like J

Re: [Tutor] call a def/class by reference

2005-09-29 Thread bob
At 08:23 AM 9/29/2005, DS wrote: >bob wrote: > > > At 04:29 PM 9/28/2005, DS wrote: > > > >> What I'm hoping to avoid is an > >> explicit reference to any of the called functions within the program. > >> By doing it that way, it would avoid a maintenance problem of having to > >> remember to put a

Re: [Tutor] stopping threads?

2005-09-29 Thread Michael Sparks
On Thursday 29 September 2005 07:27, Pierre Barbier de Reuille wrote: > IMO, it is better to explicitely call the base class ... I think it is > more readable. But I don't know if there is any drawback for any > solution... A drawback of NOT using super is that you're potetially setting yourself y

Re: [Tutor] call a def/class by reference

2005-09-29 Thread DS
bob wrote: > At 08:23 AM 9/29/2005, DS wrote: > >> bob wrote: >> >> > At 04:29 PM 9/28/2005, DS wrote: >> > >> >> What I'm hoping to avoid is an >> >> explicit reference to any of the called functions within the program. >> >> By doing it that way, it would avoid a maintenance problem of >> having

Re: [Tutor] call a def/class by reference

2005-09-29 Thread Danny Yoo
> >From what I've read so far, globals are actively discouraged. A class > seems like the best approach. > > I'm actually pretty surprised that there isn't a built-in facility with > Python for referencing functions like this. In reading Python in a > Nutshell, prior to asking my questions here,

Re: [Tutor] call a def/class by reference

2005-09-29 Thread DS
Danny Yoo wrote: >>>From what I've read so far, globals are actively discouraged. A class >>seems like the best approach. >> >>I'm actually pretty surprised that there isn't a built-in facility with >>Python for referencing functions like this. In reading Python in a >>Nutshell, prior to asking

Re: [Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Jay Loden
Alan, thanks for your responses, they're quite helpful. I suspect the real problem I'm having is simply trying to switch modes of thinking to CGI style or mod_python style instead of the PHP style embedded code. The whole point of this exercise for me was to decide which language I prefer for

Re: [Tutor] call a def/class by reference

2005-09-29 Thread Alan G
> I'm actually pretty surprised that there isn't a built-in facility > with > Python for referencing functions like this. I'm not. In fact its pretty unusual in any language to try to map from function name to function directly. Dictionaries are the universal solution for this, I can only think o

Re: [Tutor] call a def/class by reference

2005-09-29 Thread DS
Alan G wrote: >> I'm actually pretty surprised that there isn't a built-in facility with >> Python for referencing functions like this. > > > I'm not. In fact its pretty unusual in any language to try to map > from function name to function directly. Dictionaries are the > universal solution for t

Re: [Tutor] call a def/class by reference

2005-09-29 Thread Michael Sparks
On Thursday 29 September 2005 22:26, Alan G wrote: > string -> function mapping directly. > > Its not usually a very useful thing to do This is precisely how shared libraries under linux and IIRC DLLs in windows work. cf dlopen, dysym in C. > how would the typical user know what the function na

Re: [Tutor] call a def/class by reference

2005-09-29 Thread Danny Yoo
> Thanks so much to all of you that have answered my questions, including > Liam.Clarke-Hutchinson, whom I didn't acknowledge directly with an > email. I hope I'm not asking too many questions. Hi ds, You're doing perfectly fine. *grin* We got to see a lot of different approaches to that class

Re: [Tutor] Why won't it enter the quiz? (off topic)

2005-09-29 Thread Jacob S.
Wow! What an argument... A couple of comments on the code > {code} > > import random > > def add(a,b): >answer = a+b >guess = float(raw_input(a," + ",b," = ")) This is easier IMHO, but the same guess = float(raw_input("%s+%s="%(a,b))) >return answer, guess > > num1 = random.choice(ra

Re: [Tutor] Python equiv to PHP "include" ?

2005-09-29 Thread Kent Johnson
Jay Loden wrote: > Alan, thanks for your responses, they're quite helpful. I suspect the real > problem I'm having is simply trying to switch modes of thinking to CGI style > or mod_python style instead of the PHP style embedded code. There are quite a few template engines for Python that allow

Re: [Tutor] Quick way to find the data type

2005-09-29 Thread Jacob S.
I don't believe that eval() *would* work quite as intended either. For example: eval('a random string') SyntaxError and McGuire's method othermethod('a random string') 'a random string' Another example eval('file') othermethod('file') 'file' That is, of course, if I understood the McGuire

Re: [Tutor] script question

2005-09-29 Thread Jacob S.
Why are you importing string?   1) You don't seem to use it anywhere 2) Use string methods instead   Jacob - Original Message - From: Chris Hallman To: tutor@python.org Sent: Wednesday, September 28, 2005 7:35 AM Subject: Re: [Tutor] script quest

[Tutor] Book recommendations?

2005-09-29 Thread Andrew P
I was just thinking about Jon Bentley's Programming Pearls, and how much I really liked it.  Nothing has really changed since 1986, and all the pseudo code translated nicely into Python.  It was by far the most fun I've had reading any book about programming.  Especially solving problems he present

Re: [Tutor] Installing ActiveState Python vs2003

2005-09-29 Thread Andrei
Mohammad Moghimi gmail.com> writes: > When I tried to install activestate python(.net implementation of python) to my visual studio 2003. > It gives me this error message: > > The Visual Python Installer found an installation of Python 2.4, > but it also requires the win32 extensions. > > what'