Mailing List Archive

1 2  View All
Re: Use of a variable in parent loop [ In reply to ]
On Sun, Sep 27, 2020 at 9:41 PM Manfred Lotz <ml_news@posteo.de> wrote:
>
> On Sun, 27 Sep 2020 15:18:44 +0800
> Stephane Tougard <stephane@sdf.org> wrote:
>
> > On 2020-09-27, 2QdxY4RzWzUUiLuE@potatochowder.com
> > <2QdxY4RzWzUUiLuE@potatochowder.com> wrote:
> > > As ChrisA noted, Python almost always Just Works without
> > > declarations. If you find yourself with a lot of global and/or
> > > nonlocal statements, perhaps you're [still] thinking in another
> > > language.
> >
> >
> > I don't really agree with that, trying to use an undeclared
> > object/variable/whatever :
> >
> > Python 3.7.7 (default, Aug 22 2020, 17:07:43)
> > [GCC 7.4.0] on netbsd9
> > Type "help", "copyright", "credits" or "license" for more information.
> > >>> print(name)
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in <module>
> > NameError: name 'name' is not defined
> > >>>
> >
> > You can say it's not the "declaration" the issue, it's the
> > "definition", that's just a matter of vocabulary and it does not
> > answer the question.
> >
> > In many non declarative language, if I do print($var), it just prints
> > and undefined value with returning an error.
> >
> >
>
> It is very good that you try out things. Nevertheless, it is also good
> to read. In other words the combination of reading and trying out
> things is the best way to make progress.
>
> Here some pointers
>
> pass
>
> - http://localhost:2015/tutorial/controlflow.html#pass-statements
>

Looks like you're linking to a local copy of the documentation. Here's
the same page from the official docs:

https://docs.python.org/3/tutorial/controlflow.html#pass-statements

(It'll be the same information, modulo version differences, but this
one should be available everywhere.)

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 27/09/20 10:27 pm, Stephane Tougard wrote:
> That's not a question of editor, that's a question of having a clear way
> to mark the end of a block, I guess the Emacs maintener found this way
> and I think it's a great idea.

I doubt whether the authors of the Emacs python-mode had this way
of using "pass" in mind. More likely they're just trying to be helpful
and save you from having to manually unindent in a few rare situations.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-27, Avi Gross <avigross@verizon.net> wrote:
> But when someone insists Python needs to
> change to meet their preconception, I get less sympathetic.

To clarify my question, I never asked that Python changes for me, I
asked if there was any way to change Python's behavior by using a module
or a configuration for example.

As "use strict;" in Perl or JS who changes the behavior of the language.

That's kind of difference between Perl and Python (or C and GO) is that
each Mongiste has its own style and uses Perl the way it fits for his
needs, while Pythonist has to write Python as it has been defined (this
rule is much stronger with GO).

To be frank, I don't really care the rules and supposed best practices,
I use a language the way it fits me. So I'll pass on the advices like
"we never use this like this" without more reason that "we just don't do
it" or "it's not expected to be done this way".

Anyway, thanks for your help.

--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-27, Grant Edwards <grant.b.edwards@gmail.com> wrote:
> Maybe you need to choose different editors and tools.

In my world, humans don't adapt to tools but human adapt tools to their
needs.

> A guy I worked for many years ago used to write BASIC programs in C by
> using a bizarre set of pre-processor macros. While it provided his
> employees with plenty of amusement, he could never get the programs to
> work right...

It's normal, he was an ass. When I manage a team, I don't enforce tools
or language, I ask them to work the best way they can to get the things
done. If they want to write C in Perl (as I often do), I'm happy. If
they prefer Ruby (that I never learnt), or Lisp ... as long as it works
and they are able to maintain it, I'm happy as well.

Nothing is more enjoyable than a platform running a variety of languages
and technologies, working all together.

And FYI, I've done this way since 25 years and I count a few good
success in my career. Practically, my way of doing things works is at least
as well as any.

--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On Mon, 28 Sep 2020 05:20:20 +0800
Stephane Tougard <stephane@sdf.org> wrote:

> On 2020-09-27, Manfred Lotz <ml_news@posteo.de> wrote:
> > - http://localhost:2015/tutorial/controlflow.html#pass-statements
> ...
> > (In comparison to guys like ChrisA and StefanR and others here I am
> > also a Python beginner)
>
> To give me a pointer on your localhost, I could guess.

Don't understand this sentence.

--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-27, Terry Reedy <tjreedy@udel.edu> wrote:
> emacs with python-mode has been and likely still is used by some
> experienced python programmers. I have never seen anyone but a rank

Yes, since I discovered that an empty has almost the same effect than a
pass to end a block.

> The 'pass' line does not mark the end of the if block.

Yes, I know, I discovered that yesterday. Reading the documentation, it
should not anyway.

The way Emacs understands it is misleading.

> Python only has a temporary overlap mechnism:

That's the only answer I was expecting instead of all this arguing as if
I said any blasphem because I asked how can we change the behavior of
the language.

--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-27, MRAB <python@mrabarnett.plus.com> wrote:
>> If a extremist Pythonist takes over my code some day, he'll have to
>> search and delete hundreds of useless pass. I laugh already thinking
>> about it.
> He could write some code to do it.

I would do it in Perl, LOL.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-27, Chris Angelico <rosuav@gmail.com> wrote:
> Or maybe Emacs *isn't* breaking it, and it's just an autoindentation
> thing. I don't know.

From the discussion I read about this feature, it considers that 'pass' is
use to write an empty def()

def();
pass

So it's logic for it to indent one level up after a 'pass' because the people
who made it did not see any other usage to 'pass' than that.

if True:
pass
print("It's true")

The 'pass' is totally useless by itself, it can be replaced by a comment.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-27, Cameron Simpson <cs@cskk.id.au> wrote:
>>In many non declarative language, if I do print($var), it just prints
>>and undefined value with returning an error.
>
> And that way lie MANY MANY bugs not detected until an undefined value
> actually causes an issue, if that ever happens. In some languages

Totally agree, it's not an acceptable behavior.

I would not do some Perl without 'use strict'
--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-28 03:53, Stephane Tougard via Python-list wrote:
> On 2020-09-27, Chris Angelico <rosuav@gmail.com> wrote:
>> Or maybe Emacs *isn't* breaking it, and it's just an autoindentation
>> thing. I don't know.
>
> From the discussion I read about this feature, it considers that 'pass' is
> use to write an empty def()
>
> def();
> pass
>
> So it's logic for it to indent one level up after a 'pass' because the people
> who made it did not see any other usage to 'pass' than that.
>
> if True:
> pass
> print("It's true")
>
> The 'pass' is totally useless by itself, it can be replaced by a comment.
>
It's used where the language requires a statement.

In, say, C, you would use empty braces:

while (process_next_item()) {
/* Do nothing. */
}

In Python that would be:

while process_next_item():
# Do nothing.
pass
--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On Mon, Sep 28, 2020 at 12:31 PM Stephane Tougard via Python-list
<python-list@python.org> wrote:
> To be frank, I don't really care the rules and supposed best practices,
> I use a language the way it fits me. So I'll pass on the advices like
> "we never use this like this" without more reason that "we just don't do
> it" or "it's not expected to be done this way".

If you're going to ignore advice on how to use Python well and just
use it your own way, that's fine, but don't expect python-list to help
you do things your own way. :) Also, please don't try to collaborate
with anyone unless you're prepared to follow best prac.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 28Sep2020 13:43, Chris Angelico <rosuav@gmail.com> wrote:
>On Mon, Sep 28, 2020 at 12:31 PM Stephane Tougard via Python-list
><python-list@python.org> wrote:
>> To be frank, I don't really care the rules and supposed best practices,
>> I use a language the way it fits me. So I'll pass on the advices like
>> "we never use this like this" without more reason that "we just don't do
>> it" or "it's not expected to be done this way".
>
>If you're going to ignore advice on how to use Python well and just
>use it your own way, that's fine, but don't expect python-list to help
>you do things your own way. :) Also, please don't try to collaborate
>with anyone unless you're prepared to follow best prac.

Chris: that's not what Stephane said. Stephane passes on advice
unsupported by reasons.

That said, Stephane: I don't believe in "best practice" as _the_ best
practice, but I certainly believe there's "bad practice".

Cheers,
Cameron Simpson <cs@cskk.id.au>
--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 28/09/2020 12:56 pm, Stephane Tougard via Python-list wrote:
> On 2020-09-27, Cameron Simpson <cs@cskk.id.au> wrote:
>>> In many non declarative language, if I do print($var), it just prints
>>> and undefined value with returning an error.
>> And that way lie MANY MANY bugs not detected until an undefined value
>> actually causes an issue, if that ever happens. In some languages
> Totally agree, it's not an acceptable behavior.
>
> I would not do some Perl without 'use strict'

I came to Python from Pascal, Perl and PHP. For a while my code was full
of constructs which came from those languages. As time passed and I
lurked on mailing lists I began to see the power of Python. It is
incredibly flexible. You can write code the way you used to or you can
gradually try to write more "Pythonically". The real beauty of Python in
my opinion is genuine OO. And the community.

Perl can be extremely terse, much more so than Python but that is where
the "write-only" criticism comes from. Perl's terseness can only work
for throwaway code.[1] Python is - or can be - quite terse but if
written Pythonically is almost self-documenting. You, or anyone else can
read it in coming years.

Cheers

Mike

[1] If you live with Perl non-stop I agree Perl code can be read in
future. But it requires allocation of serious brain-space for me at
least to come back to it.

--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-28, MRAB <python@mrabarnett.plus.com> wrote:
> It's used where the language requires a statement.
>
> In, say, C, you would use empty braces:
>
> while (process_next_item()) {
> /* Do nothing. */
> }

If I want to express nothing in C, I put nothing and it works fine.

#include <stdio.h>

int main(int argc, char * argv[])
{
if(1 == 1)
;
printf("Hello\n");
return 0;
}

> while process_next_item():
> # Do nothing.
> pass

while p():
# do nothing
continue

--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-28, Manfred Lotz <ml_news@posteo.de> wrote:
> On Mon, 28 Sep 2020 05:20:20 +0800
> Stephane Tougard <stephane@sdf.org> wrote:
>
>> On 2020-09-27, Manfred Lotz <ml_news@posteo.de> wrote:
>> > - http://localhost:2015/tutorial/controlflow.html#pass-statements
>> ...
>> > (In comparison to guys like ChrisA and StefanR and others here I am
>> > also a Python beginner)
>>
>> To give me a pointer on your localhost, I could guess.
>
> Don't understand this sentence.

The URL you gave is pointing to your localhost, your own computer if you
prefer.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-28, Cameron Simpson <cs@cskk.id.au> wrote:
> That said, Stephane: I don't believe in "best practice" as _the_ best
> practice, but I certainly believe there's "bad practice".

I kind of disagree with that, what I mean that there is no bad practice
to get the work done. There may be bad practice to write a code that you
intend to share or as part of a bigger project. Still, that depends how
you deliver your code.

For example, in Perl I sometime make extensive usage of goto(), through
this is usually considered bad practice I've read several documents who
stated otherwise.

Using goto() may make the code much simpler to understand when you
encounter a lot of error cases in a code.

The try: except: of Python, as I understand it, is never more than a
goto() in disguise (at least, that's the way I use goto() in Perl).

--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-28, Mike Dewhirst <miked@dewhirst.com.au> wrote:
> [1] If you live with Perl non-stop I agree Perl code can be read in
> future. But it requires allocation of serious brain-space for me at
> least to come back to it.

Let's be franc, I can read my own Perl code (very C-ish) without any
issue. I live with it since 20 years.

But I've seen some Perl code that is total gebbiresh to me, still doing
the job correctly.


--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
Am 28.09.20 um 07:38 schrieb Stephane Tougard:
> On 2020-09-28, MRAB <python@mrabarnett.plus.com> wrote:
>> It's used where the language requires a statement.
>>
>> In, say, C, you would use empty braces:
>>
>> while (process_next_item()) {
>> /* Do nothing. */
>> }
>
> If I want to express nothing in C, I put nothing and it works fine.
>
> #include <stdio.h>
>
> int main(int argc, char * argv[])
> {
> if(1 == 1)
> ;

No. You put ";", that's not nothing.

Christian
--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On Mon, 28 Sep 2020 13:39:08 +0800
Stephane Tougard <stephane@sdf.org> wrote:

> On 2020-09-28, Manfred Lotz <ml_news@posteo.de> wrote:
> > On Mon, 28 Sep 2020 05:20:20 +0800
> > Stephane Tougard <stephane@sdf.org> wrote:
> >
> >> On 2020-09-27, Manfred Lotz <ml_news@posteo.de> wrote:
> >> > -
> >> > http://localhost:2015/tutorial/controlflow.html#pass-statements
> >> >
> >> ...
> >> > (In comparison to guys like ChrisA and StefanR and others here I
> >> > am also a Python beginner)
> >>
> >> To give me a pointer on your localhost, I could guess.
> >
> > Don't understand this sentence.
>
> The URL you gave is pointing to your localhost, your own computer if
> you prefer.

It is amazing that I just didn't see it. I am a bad at spotting things.
Sigh.

Anyway:
https://docs.python.org/3/tutorial/controlflow.html#pass-statements


--
Manfred

--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-27, Terry Reedy <tjreedy@udel.edu> wrote:
> On 9/26/2020 3:36 PM, Stephane Tougard via Python-list wrote:
>> On 2020-09-26, Terry Reedy <tjreedy@udel.edu> wrote:
>>> Noise. Only 'pass' when there is no other code.
>>
>> Why ?
>>
>> I use pass and continue each time to break a if or a for because emacs
>> understands it and do not break the indentation.

Huh? What is emacs doing to "break the indentation"?

>> Is there any other instruction to end a if than pass and ensure Emacs
>> does not break the indentation during a copy paste or an indent-region ?
>
> Emacs should come with python.el or python-mode.el defining a
> python-mode. Are you using it? I presume it understands python block
> structure without extra passes.

It works for me.

> emacs with python-mode has been and likely still is used by some
> experienced python programmers.

I've been usnig emacs in python-mode for almost 20 years. I've never
had any problems with.

--
Grant

--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On 2020-09-27, Stephane Tougard via Python-list <python-list@python.org> wrote:

> However, I discovered that Emacs interprets as well an empty line or a
> comment as a breaking point of a block, it's not as good as the use of
> pass because I still have to indent up manually, but at least the
> indent-region does not break it.

I don't understand what you expect emacs 'indent-region' to do.

With token-delimited languages, it will re-do the indentation of a
block with respect to the first selected line. That's possible
because for C et al. indentation can be deduced from keywords and
block delimiters.

That's simply not possible with Python because indentation _is_ the
delimiters. Expecting Python to know how your code is supposed to be
indented would be like entering a block of C code with no curly braces
and then expecting emacs to know where to insert them so that the code
does what you want.

You can increase/decrease indentation by selecting a block and hitting
C-c < or C-c >.

--
Grant



--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
On Sun, Sep 27, 2020 at 03:18:44PM +0800, Stephane Tougard via Python-list wrote:
> On 2020-09-27, 2QdxY4RzWzUUiLuE@potatochowder.com <2QdxY4RzWzUUiLuE@potatochowder.com> wrote:
> > As ChrisA noted, Python almost always Just Works without declarations.
> > If you find yourself with a lot of global and/or nonlocal statements,
> > perhaps you're [still] thinking in another language.
>
>
> I don't really agree with that, trying to use an undeclared
> object/variable/whatever :
>
> Python 3.7.7 (default, Aug 22 2020, 17:07:43)
> [GCC 7.4.0] on netbsd9
> Type "help", "copyright", "credits" or "license" for more information.
> >>> print(name)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NameError: name 'name' is not defined
> >>>
>
> You can say it's not the "declaration" the issue, it's the "definition",
> that's just a matter of vocabulary and it does not answer the question.

No it's not... those two words mean different things, and the
difference actually matters. If you use strict in perl you need BOTH
(at least, if you want your variable to actually have a value):

my $foo;
$foo = 1;

The declaration and definition serve different purposes. You can
combine them into one statement for syntactic convenience, much as you
can in C/C++, but nevertheless both functions still exist and are
explicitly expressed.

In Python, you almost always only need the definition.

--
https://mail.python.org/mailman/listinfo/python-list
Re: Use of a variable in parent loop [ In reply to ]
Stephane Tougard <stephane@sdf.org> writes:

> ...
> It's normal, he was an ass. When I manage a team, I don't enforce tools
> or language, I ask them to work the best way they can to get the things
> done. If they want to write C in Perl (as I often do), I'm happy. If
> they prefer Ruby (that I never learnt), or Lisp ... as long as it works
> and they are able to maintain it, I'm happy as well.
>
> Nothing is more enjoyable than a platform running a variety of languages
> and technologies, working all together.
>
> And FYI, I've done this way since 25 years and I count a few good
> success in my career. Practically, my way of doing things works is at least
> as well as any.

Maybe you seems like lisp or emacs lisp just i think, not serious...

Sincerely, Byung-Hee from South Korea

--
^????? _????_ ?????_^))//
--
https://mail.python.org/mailman/listinfo/python-list

1 2  View All