Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > alternatives to making blocks like { } or other ??

Reply
Thread Tools

alternatives to making blocks like { } or other ??

 
 
CYBER
Guest
Posts: n/a
 
      05-18-2004
Hello

Is there any other way under python to create blocks ??

instead of

def sth(x):
return x



could i use something else like

def sth(x):
{
return x
}


???
 
Reply With Quote
 
 
 
 
Larry Bates
Guest
Posts: n/a
 
      05-18-2004
Blocks in Python are defined not with {} but rather
with indention. You indent to start a block and
stop indenting when you wish to end it. Seems odd
at first, but turns out to be excellent way to
handle blocks (and to properly format you code).

HTH, Larry Bates

"CYBER" <usenet@zly_adres.com> wrote in message
news:c8do0u$9fb$(E-Mail Removed)...
> Hello
>
> Is there any other way under python to create blocks ??
>
> instead of
>
> def sth(x):
> return x
>
>
>
> could i use something else like
>
> def sth(x):
> {
> return x
> }
>
>
> ???



 
Reply With Quote
 
 
 
 
Paul McGuire
Guest
Posts: n/a
 
      05-18-2004
"Larry Bates" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Blocks in Python are defined not with {} but rather
> with indention. You indent to start a block and
> stop indenting when you wish to end it. Seems odd
> at first, but turns out to be excellent way to
> handle blocks (and to properly format you code).
>
> HTH, Larry Bates
>
> "CYBER" <usenet@zly_adres.com> wrote in message
> news:c8do0u$9fb$(E-Mail Removed)...
> > Hello
> >
> > Is there any other way under python to create blocks ??
> >
> > instead of
> >
> > def sth(x):
> > return x
> >
> >
> >
> > could i use something else like
> >
> > def sth(x):
> > {
> > return x
> > }
> >
> >
> > ???

>
>

.... and no religious wars on where the braces are supposed to go, HOORAY!!!

And I'll second Larry's comment - it takes about 10-20 minutes to get used
to, but then you just focus on indentation, and it seems *very* natural -
liberating, even!

-- Paul


 
Reply With Quote
 
Timo Virkkala
Guest
Posts: n/a
 
      05-18-2004
CYBER wrote:
> Is there any other way under python to create blocks ??
> instead of
> def sth(x):
> return x
> could i use something else like
> def sth(x):
> {
> return x
> }


Not without changing the language a lot. But just try the normal way for a
couple of days, you'll get used to it in no time.

--
Timo Virkkala
 
Reply With Quote
 
Russell Blau
Guest
Posts: n/a
 
      05-18-2004
"Timo Virkkala" <(E-Mail Removed)> wrote in message
news:Z1vqc.592$(E-Mail Removed)...
> CYBER wrote:
> > Is there any other way under python to create blocks ??
> > instead of
> > def sth(x):
> > return x
> > could i use something else like
> > def sth(x):
> > {
> > return x
> > }

>
> Not without changing the language a lot. But just try the normal way for a
> couple of days, you'll get used to it in no time.


Or you could try this, which works almost exactly as well:

def sth(x):
#
return x
#

<g,d&r>


--
I don't actually read my hotmail account, but you can replace hotmail with
excite if you really want to reach me.


 
Reply With Quote
 
Christopher Koppler
Guest
Posts: n/a
 
      05-18-2004
On Tue, 18 May 2004 21:27:17 +0200, CYBER <usenet@zly_adres.com>
wrote:

>Hello
>
>Is there any other way under python to create blocks ??
>
>instead of
>
>def sth(x):
> return x
>
>
>
>could i use something else like
>
>def sth(x):
>{
> return x
>}
>
>
>???



Of course there is another way!

Just use # in front of your favourite block separator.

I'm too lazy now to search the archives on who first suggested this,
but it works:

def something(x):
#{
return x
#}

However, as with any and all block separators, this can lead to holy
wars - is the above the 'one true way', or is it one of the following?
All are valid Python...

def something_else(x):
#{
return x
#}

def something_or_other(x):
#{
return x
#}

def something_completely_different(x): #(
return x
#}





--
Christopher
 
Reply With Quote
 
CYBER
Guest
Posts: n/a
 
      05-18-2004
> Of course there is another way!
>
> Just use # in front of your favourite block separator.
>
> I'm too lazy now to search the archives on who first suggested this,
> but it works:
>
> def something(x):
> #{
> return x
> #}
>
>


Thank you.

 
Reply With Quote
 
Chad Thompson
Guest
Posts: n/a
 
      05-19-2004

"CYBER" <usenet@zly_adres.com> wrote in message
news:c8do0u$9fb$(E-Mail Removed)...
> Hello
>
> Is there any other way under python to create blocks ??
>
> instead of
>
> def sth(x):
> return x
>
>
>
> could i use something else like
>
> def sth(x):
> {
> return x
> }
>
>
> ???


http://www.python.org/doc/Humor.html#parsing


 
Reply With Quote
 
Christopher Koppler
Guest
Posts: n/a
 
      05-19-2004
On Wed, 19 May 2004 01:46:02 GMT, "Chad Thompson" <(E-Mail Removed)>
wrote:

>
>"CYBER" <usenet@zly_adres.com> wrote in message
>news:c8do0u$9fb$(E-Mail Removed)...
>> Hello
>>
>> Is there any other way under python to create blocks ??
>>
>> instead of
>>
>> def sth(x):
>> return x
>>
>>
>>
>> could i use something else like
>>
>> def sth(x):
>> {
>> return x
>> }
>>
>>
>> ???

>
>http://www.python.org/doc/Humor.html#parsing
>


Ah yes, that was the link, I'd completely forgotten about the Python
humour page!

Oh, and CYBER: my post was *meant* ironic, but Python is flexible
enough that it can be taken at face value - so glad to have been of
help

--
Christopher
 
Reply With Quote
 
Grant Edwards
Guest
Posts: n/a
 
      05-19-2004
On 2004-05-18, Paul McGuire <(E-Mail Removed)._bogus_.com> wrote:

>>> could i use something else like
>>>
>>> def sth(x):
>>> {
>>> return x
>>> }


> ... and no religious wars on where the braces are supposed to
> go, HOORAY!!!


But as religious wars go, the great Python "tab" debate ranks
right up there.

> And I'll second Larry's comment - it takes about 10-20 minutes
> to get used to, but then you just focus on indentation, and it
> seems *very* natural - liberating, even!


Especially if you've got an editor with a "python mode".

--
Grant Edwards grante Yow! I guess we can live
at on his POT FARM in HADES!!
visi.com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Building Blocks" are "Application Blocks" Arjen ASP .Net 3 02-27-2005 01:06 AM
procs/blocks - blocks with procs, blocks with blocks? matt Ruby 1 08-06-2004 01:33 AM
alternatives to making blocks like { } or other ?? Michael Chermside Python 1 05-19-2004 04:41 PM
alternatives to making blocks like { } or other ?? Michael Chermside Python 0 05-19-2004 01:08 PM



Advertisments