>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
> 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
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
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):
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
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
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
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):
> ...
(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( [], '
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.
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://
> 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
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',
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
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
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
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
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
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
>> 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.
_
> 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
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
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
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
> >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,
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
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
> 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
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
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
> 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
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
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
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
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
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
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'
37 matches
Mail list logo