Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #78797

Re: ruby instance variable in python

X-Received by 10.224.160.143 with SMTP id n15mr1931928qax.5.1412684951707; Tue, 07 Oct 2014 05:29:11 -0700 (PDT)
X-Received by 10.50.154.66 with SMTP id vm2mr33230igb.5.1412684951605; Tue, 07 Oct 2014 05:29:11 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!uq10no5632225igb.0!news-out.google.com!bc9ni15653igb.0!nntp.google.com!uq10no5632214igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Tue, 7 Oct 2014 05:29:11 -0700 (PDT)
In-Reply-To <mailman.14632.1412590002.18130.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=124.184.77.116; posting-account=5Cd8QAoAAAC6AxpkrISTgUBJ9ktgwNBm
NNTP-Posting-Host 124.184.77.116
References <mailman.14632.1412590002.18130.python-list@python.org>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <b22416b5-e3ed-4ece-aeba-65603fff1b3f@googlegroups.com> (permalink)
Subject Re: ruby instance variable in python
From flebber <flebber.crue@gmail.com>
Injection-Date Tue, 07 Oct 2014 12:29:11 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.python:78797

Show key headers only | View raw


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'

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

ruby instance variable in python roro codeath <rorocodeath@gmail.com> - 2014-10-06 18:06 +0800
  Re: ruby instance variable in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-07 05:54 +1100
  Re: ruby instance variable in python flebber <flebber.crue@gmail.com> - 2014-10-07 05:29 -0700
    Re: ruby instance variable in python Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-10-07 15:46 +0300
      Re: ruby instance variable in python flebber <flebber.crue@gmail.com> - 2014-10-07 17:59 -0700
        Re: ruby instance variable in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-08 12:32 +1100
          Re: ruby instance variable in python flebber <flebber.crue@gmail.com> - 2014-10-08 03:12 -0700

csiph-web