sharing vars with different functions

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Oct 29 07:31:05 EDT 2007


scripteaze at gmail.com 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)





More information about the Python-list mailing list