ruby instance variable in python

flebber flebber.crue at gmail.com
Tue Oct 7 14:29:11 CEST 2014


On Monday, 6 October 2014 21:07:24 UTC+11, roro codeath  wrote:
> in ruby:
> 
> 
> module M
> def ins_var
> @ins_var ||= nil
> end
> 
> 
> def m
> @ins_var = 'val'
> end
> 
> 
> def m2
> m
> ins_var # => 'val'
> end
> end
> 
> 
> in py:
> 
> 
> # m.py
> 
> 
> # how to def ins_var
> 
> 
> def m:
>     # how to set ins_var
> 
> 
> def m2:
>     m()
>     # how to get ins var

I took || to be a ternary. So I assumed your code just sets ins_var to nil and then  is called in module m and supplied a val. Could be wrong.

if ins_var is None:
    ins_var = 'val'



More information about the Python-list mailing list