Re: Use of a variable in parent loop

2020-09-26 Thread Joel Goldstick
On Sat, Sep 26, 2020 at 2:01 AM Stephane Tougard via Python-list
 wrote:
>
>
> Hello All,
>
> I've been working with Perl a long time and recently started to use
> Python. I've been surprised by one behavior of Python.
>
> In Perl:
>
> ===PERL===
> #!/usr/pkg/bin/perl
>
> use strict;
>
> if(4 == 4)
> {
> my $name = "Stephane";
> print("$name\n"
> }
> print("Out $name\n");
> =
>
> This code will trigger an error because $name is declared inside the if
> and is not usable outside of the block code. That looks logic to me.
>
> ===PYTHON===
> #!/usr/local/bin/python
> if 4 == 4:
> name = "Stephane"
> print(name)
> pass
>
> print("Out {}".format(name))
> 
>
> The exact same code in Python works fine, the variable name is used
> outside of the if block even it has been declared inside.
>
> This does not look right to me. Can we change this behavior or is there
> any point to keep it this way ?
> --
> https://mail.python.org/mailman/listinfo/python-list


It looks like perl creates a local namespace inside the code suite of
the if statement.  Python namespace is function based.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-26 Thread Chris Angelico
On Sat, Sep 26, 2020 at 4:01 PM Stephane Tougard via Python-list
 wrote:
>
>
> Hello All,
>
> I've been working with Perl a long time and recently started to use
> Python. I've been surprised by one behavior of Python.
>
> In Perl:
>
> ===PERL===
> #!/usr/pkg/bin/perl
>
> use strict;
>
> if(4 == 4)
> {
> my $name = "Stephane";
> print("$name\n"
> }
> print("Out $name\n");
> =
>
> This code will trigger an error because $name is declared inside the if
> and is not usable outside of the block code. That looks logic to me.
>
> ===PYTHON===
> #!/usr/local/bin/python
> if 4 == 4:
> name = "Stephane"
> print(name)
> pass
>
> print("Out {}".format(name))
> 
>
> The exact same code in Python works fine, the variable name is used
> outside of the if block even it has been declared inside.
>
> This does not look right to me. Can we change this behavior or is there
> any point to keep it this way ?

Just to get this part out of the way: No, that behaviour won't change. :)

The distinction is that, in Python, you didn't declare the variable at
all. It's not like C where you have to declare everything, and the
place it's declared defines the scope; in Python, variables generally
*aren't* declared, and there are a small number of cases where you
declare that something's a global when it would otherwise be local.
But for the most part, Python's default rules handle the situations
admirably.

Most variables are either global (if you assign something outside of
any function) or local (inside a function). There's no concept of
scoping a variable to just a single 'if' statement, so you don't have
to worry about it disappearing prematurely.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-26 Thread Terry Reedy

On 9/26/2020 12:43 AM, Stephane Tougard via Python-list wrote:

[Example of Perl block scoping.]


===PYTHON===
#!/usr/local/bin/python
if 4 == 4:


if True:  # Only usefel in Python if you might might to switch to False.


 name = "Stephane"
 print(name)
 pass


Noise.  Only 'pass' when there is no other code.


print("Out {}".format(name))


The exact same code in Python works fine, the variable name is used
outside of the if block even it has been declared inside.


'name' is bound to a object, not declared
The only declarations are 'global' and 'nonlocal'.

Python only creates new scopes for class and function definitions.  At 
least for CPython, comprehensions are implicit function definitions.



This does not look right to me.


Because you are accustomed to block scoping.

 Can we change this behavior

No.


or is there any point to keep it this way ?


Aside from not breaking most every existing Python program?  If block 
scoped, one would have to add an otherwise useless fake declaration 
before the block to use the name outside the block.  Python tries to 
avoid boilerplate code.


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: celery multi celery.exceptions.TimeoutError: The operation timed out

2020-09-26 Thread iMath
在 2020年9月21日星期一 UTC+8 下午8:02:44, 写道:
> Op 21-09-2020 om 12:14 schreef iMath:
> > Asked 3 days ago at 
> > https://stackoverflow.com/questions/63951696/celery-multi-celery-exceptions-timeouterror-the-operation-timed-out
> >  
> > 
> > But nobody helped yet, anyone ? 
> >
> Did you see 
> https://stackoverflow.com/questions/9769496/celery-received-unregistered-task-of-type-run-example
>  
> ? 
> 
> The error says "Received unregistered task of type 'proj.tasks.add'", so 
> it looks very much like your registry is not correct/complete. 
> 
> Vriendelijke groeten/Kind regards, 
> 
> Menno Hölscher

None of the answers helped .
Finally ,I switched to https://github.com/jarekwg/django-apscheduler I found it 
is elegant and easy to use
-- 
https://mail.python.org/mailman/listinfo/python-list


pipenv picks up bad paths and crashes

2020-09-26 Thread Rhett Prince
pipenv is a bad program 

 

it conflicts with anaconda. 

I removed anaconda and it still crashes. 

 

also, I repaired my python 3.8  installation 

uninstalled and reinstalled pipenv  

and it still picks up paths from anaconda 

anaconda sucks too. 

 

see below 

 

 

 

 

Administrator@rcplt MINGW64 /c/dev_env

$ ls

a.txt  dd.py  notes.txt  pipenv_help.txt

 

Administrator@rcplt MINGW64 /c/dev_env

$ pip uninstall pipenv

Found existing installation: pipenv 2020.8.13

Uninstalling pipenv-2020.8.13:

  Would remove:

c:\program files
(x86)\python38-32\lib\site-packages\pipenv-2020.8.13.dist-i

nfo\*

c:\program files (x86)\python38-32\lib\site-packages\pipenv\*

c:\program files (x86)\python38-32\scripts\pipenv-resolver.exe

c:\program files (x86)\python38-32\scripts\pipenv.exe

Proceed (y/n)? y

  Successfully uninstalled pipenv-2020.8.13

 

Administrator@rcplt MINGW64 /c/dev_env

$ pip install pipenv

Collecting pipenv

  Using cached pipenv-2020.8.13-py2.py3-none-any.whl (3.9 MB)

Requirement already satisfied: virtualenv-clone>=0.2.5 in c:\program files
(x86)

\python38-32\lib\site-packages (from pipenv) (0.5.4)

Requirement already satisfied: setuptools>=36.2.1 in c:\program files
(x86)\pyth

on38-32\lib\site-packages (from pipenv) (41.2.0)

Requirement already satisfied: virtualenv in c:\program files
(x86)\python38-32\

lib\site-packages (from pipenv) (20.0.31)

Requirement already satisfied: pip>=18.0 in c:\program files
(x86)\python38-32\l

ib\site-packages (from pipenv) (20.2.3)

Requirement already satisfied: certifi in c:\program files
(x86)\python38-32\lib

\site-packages (from pipenv) (2020.6.20)

Requirement already satisfied: distlib<1,>=0.3.1 in c:\program files
(x86)\pytho

n38-32\lib\site-packages (from virtualenv->pipenv) (0.3.1)

Requirement already satisfied: six<2,>=1.9.0 in c:\program files
(x86)\python38-

32\lib\site-packages (from virtualenv->pipenv) (1.15.0)

Requirement already satisfied: appdirs<2,>=1.4.3 in c:\program files
(x86)\pytho

n38-32\lib\site-packages (from virtualenv->pipenv) (1.4.4)

Requirement already satisfied: filelock<4,>=3.0.0 in c:\program files
(x86)\pyth

on38-32\lib\site-packages (from virtualenv->pipenv) (3.0.12)

Installing collected packages: pipenv

Successfully installed pipenv-2020.8.13

 

Administrator@rcplt MINGW64 /c/dev_env

$ ls

a.txt  dd.py  notes.txt  pipenv_help.txt

 

Administrator@rcplt MINGW64 /c/dev_env

$ pipenv install pytz

Traceback (most recent call last):

  File "C:\Program Files
(x86)\Python38-32\Lib\site-packages\pipenv\vendor\pytho

nfinder\models\python.py", line 618, in parse_executable

result_version = get_python_version(path)

  File "C:\Program Files
(x86)\Python38-32\Lib\site-packages\pipenv\vendor\pytho

nfinder\utils.py", line 105, in get_python_version

c = subprocess.Popen(version_cmd, **subprocess_kwargs)

  File "c:\program files (x86)\python38-32\lib\subprocess.py", line 854, in
__in

it__

self._execute_child(args, executable, preexec_fn, close_fds,

  File "c:\program files (x86)\python38-32\lib\subprocess.py", line 1307, in
_ex

ecute_child

hp, ht, pid, tid = _winapi.CreateProcess(executable, args,

FileNotFoundError: [WinError 2] The system cannot find the file specified

 

During handling of the above exception, another exception occurred:

 

Traceback (most recent call last):

  File "c:\program files (x86)\python38-32\lib\runpy.py", line 194, in
_run_modu

le_as_main

return _run_code(code, main_globals, None,

  File "c:\program files (x86)\python38-32\lib\runpy.py", line 87, in
_run_code

exec(code, run_globals)

  File "C:\Program Files (x86)\Python38-32\Scripts\pipenv.exe\__main__.py",
line

7, in 

  File "C:\Program Files
(x86)\Python38-32\Lib\site-packages\pipenv\vendor\click

\core.py", line 829, in __call__

return self.main(*args, **kwargs)

  File "C:\Program Files
(x86)\Python38-32\Lib\site-packages\pipenv\vendor\click

\core.py", line 782, in main

rv = self.invoke(ctx)

  File "C:\Program Files
(x86)\Python38-32\Lib\site-packages\pipenv\vendor\click

\core.py", line 1259, in invoke

return _process_result(sub_ctx.command.invoke(sub_ctx))

  File "C:\Program Files
(x86)\Python38-32\Lib\site-packages\pipenv\vendor\click

\core.py", line 1066, in invoke

return ctx.invoke(self.callback, **ctx.params)

  File "C:\Program Files
(x86)\Python38-32\Lib\site-packages\pipenv\vendor\click

\core.py", line 610, in invoke

return callback(*args, **kwargs)

  File "C:\Program Files
(x86)\Python38-32\Lib\site-packages\pipenv\vendor\click

\decorators.py", line 73, in new_func

return ctx.invoke(f, obj, *args, **kwargs)

  File "C:\Program Files
(x86)\Python38-32\Lib\site-packages\pipenv\vendor\click

\core.py", line 610, in invoke

return callback(*args, **kwargs)

  File "C:\Program Files
(x86)\Python38-32\Lib\site-packages\pipenv\vendor\click

\decorators.py", line 21, in new_func

return f(get_current_context(), *ar

Re: Use of a variable in parent loop

2020-09-26 Thread Stephane Tougard via Python-list
On 2020-09-26, Terry Reedy  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.

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 ?

> Aside from not breaking most every existing Python program?  If block 
> scoped, one would have to add an otherwise useless fake declaration 
> before the block to use the name outside the block.  Python tries to 
> avoid boilerplate code.

I'm not talking about a general change in Python as a language, I'm
talking about a module who would enforce a block namespace as it works with
C or Perl (and many).

In Perl, use strict will break any non-strict code. So each is free to
chose between strict and not strict.

Anyway, there's no perfect language, the point is to know it. It's just
confusing I still have to declare or not declare an object depending on
the action I have with it. 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Use of a variable in parent loop

2020-09-26 Thread 2QdxY4RzWzUUiLuE
On 2020-09-27 at 03:36:48 +0800,
Stephane Tougard via Python-list  wrote:

> Anyway, there's no perfect language, the point is to know it ...

Yes.

> ... It's just confusing I still have to declare or not declare an
> object depending on the action I have with it.

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.
-- 
https://mail.python.org/mailman/listinfo/python-list


check dependencies of a pypi package

2020-09-26 Thread kamaraju kusumanchi
How can I check the dependencies of a pypi package without installing it?

For example, looking at the pandas 1.1.2 package in
https://pypi.org/project/pandas/1.1.2/, is there a way to determine
the numpy version it depends upon without installing the package?

thanks
raju
-- 
Kamaraju S Kusumanchi | http://raju.shoutwiki.com/wiki/Blog
-- 
https://mail.python.org/mailman/listinfo/python-list