Import Question ..
Skulled2003 at netscape.net
Skulled2003 at netscape.net
Mon Jul 12 09:38:33 EDT 2004
Thanks a lot for all the answers.
The 'def' and 'str' were merely example names. I am not using any of those.
Thanks for the replies again.
Vinod.
James Henderson <james at logicalprogression.net> wrote:
>On Monday 12 July 2004 1:32 pm, Peter Otten wrote:
>> Skulled2003 at netscape.net wrote:
>> > import def
>> >
>> > def dosomething(something)
>> >
>> > if something == 'firstlist':
>> > listdef = def.firstlistCommonPart
>> > elif something == 'secondlist':
>> > listdef = def.secondlistCommonPart
>> >
>> > This is quite frustrating if i have lots of definitions. So is there a
>> > way where i could get something like:
>>
>> Now 'def' is a _really_ bad name for a module - I'll use 'module' instead.
>>
>> import module
>>
>> def dosomething(something):
>> listdef = getattr(module, something + "CommonPart")
>>
>> Peter
>
>Yes, "getattr" is the answer. This came while I was replying so I'll just add
>that "str" is also a bad name for a variable (it was in the OP), since it
>masks a built in name. "def" is in fact an impossible name for a module:
>"import def" is a syntax error (as is "def.firstlistCommonPart") because
>"def" is a reserved keyword.
>
>James
>--
>James Henderson, Logical Progression Ltd
>http://www.logicalprogression.net
>http://mailmanager.sourceforge.net
>
>--
>http://mail.python.org/mailman/listinfo/python-list
>
__________________________________________________________________
Switch to Netscape Internet Service.
As low as $9.95 a month -- Sign up today at http://isp.netscape.com/register
Netscape. Just the Net You Need.
New! Netscape Toolbar for Internet Explorer
Search from anywhere on the Web and block those annoying pop-ups.
Download now at http://channels.netscape.com/ns/search/install.jsp
More information about the Python-list
mailing list