#ifdef like question.

Roman Yakovenko romany at actimize.com
Tue May 14 10:39:17 EDT 2002


Thanks for the help. I don't like the first version( I knew that I could implement it this way).
The reason is simple if for each class \ function I will have 3 files than I'd rather will not use
futures. So I'd like to see the second way. Even if it will be some dirty method. 
I'll pay attention to comments.

Thanks. Roman


-----Original Message-----
From: holger krekel [mailto:pyth at devel.trillke.net]
Sent: Tuesday, May 14, 2002 3:25 PM
To: Roman Yakovenko
Cc: python-list at python.org
Subject: Re: #ifdef like question.

Roman Yakovenko wrote:
> Yes it is.
(meaning he wants to have either generators or normal
 list-returning functions depending on the python-version)

well, you have two options:

(1) put the different versions in different files

(2) put both versions in one file

Most people will recommend to do it the (1) way.
This means you put your generator functions into e.g.
'funcs_generators.py' and the list-versions into
'funcs_oldway.py'
then:

    try:
        import funcs_generators as funcs
    except:
        import funcs_oldway as funcs

    for item in funcs.getsome():
        print item

where getsome could be a generator or a full-list-constructing
function.

If you want to put both versions into one file
it *is* possible but involves some tricks which
are considered 'bad style'. So i am only going
to show them if you don't want to go with the the other
method :-)

regards,

    holger


P.S: i took this posting back to python-list at python.org
as i think you didn't mean to sent private mail.





More information about the Python-list mailing list