Re: sharing vars with different functions
On Mon, 29 Oct 2007 09:03:14 +, [EMAIL PROTECTED] wrote: Im tryin to call a var thats sitting in a function, example: class someclass(object): somevar = open(blah, 'r').readlines() Thats a class variable. Is that really what you want!? def something(): for line in somevar: print line --- i guess im not graspng the whole global or local var topic.. There is no real global here. One is (somewhat) local to the class the other local to the function. Any examples?? def something(lines): for line in lines: print lines And the call it with the object. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
sharing vars with different functions
Im tryin to call a var thats sitting in a function, example: class someclass(object): somevar = open(blah, 'r').readlines() def something(): for line in somevar: print line --- i guess im not graspng the whole global or local var topic.. Any examples?? -- http://mail.python.org/mailman/listinfo/python-list
Re: sharing vars with different functions
I hate gmail, always forgetting to set the right recipient... -- Forwarded message -- From: Martin Marcher [EMAIL PROTECTED] Date: 29.10.2007 10:11 Subject: Re: sharing vars with different functions To: [EMAIL PROTECTED] [EMAIL PROTECTED] 2007/10/29, [EMAIL PROTECTED] [EMAIL PROTECTED]: Im tryin to call a var thats sitting in a function, example: i guess im not graspng the whole global or local var topic.. does this help? class Foo(object): ... somevar = [a, b] ... def __init__(self): ... self.another_var = [c, d] ... Foo.somevar ['a', 'b'] f = Foo() f.somevar ['a', 'b'] f.another_var ['c', 'd'] Foo.somevar = New Value f.somevar 'New Value' Foo.another_var Traceback (most recent call last): File stdin, line 1, in module AttributeError: type object 'Foo' has no attribute 'another_var' -- http://noneisyours.marcher.name http://feeds.feedburner.com/NoneIsYours -- http://noneisyours.marcher.name http://feeds.feedburner.com/NoneIsYours -- http://mail.python.org/mailman/listinfo/python-list
Re: sharing vars with different functions
[EMAIL PROTECTED] a écrit : Im tryin to call s/call/access/ a var thats sitting s/sitting/defined/ in a function, example: In this example, s/function/class/ class someclass(object): pep08 : should be SomeClass(object): somevar = open(blah, 'r').readlines() Doing IO in the body of a class statement is IMHO a *very* bad idea. def something(): for line in somevar: print line --- i guess im not graspng the whole global or local var topic.. Seems there are a couple other points you're net yet grasping. Anyway, in this case, you should pass the iterable object to your function: def something(iterable): for line in iterable: print line something(someclass.somevar) -- http://mail.python.org/mailman/listinfo/python-list