Re: Find the path of a shell command [POSTPONED]

2022-10-12 Thread Cameron Simpson

On 13Oct2022 03:25, Paulo da Silva  wrote:
There is another problem involved. The script, works fine except when 
launched by cron! Why?


Record the script output:

# record all output
exec >/tmp/script.$$.out 2>&1
# dump the envionment
env | sort
# turn on execution tracing
set -x
... rest of the script

and have a look afterwards. Cron's environment is very minimal. This 
will show you what's in it.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command [POSTPONED]

2022-10-12 Thread Paulo da Silva

Às 05:00 de 12/10/22, Paulo da Silva escreveu:

Hi!

The simple question: How do I find the full path of a shell command 
(linux), i.e. how do I obtain the corresponding of, for example,

"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well 
until it is invoked by cron! I suspect that for cron we need to specify 
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
What about other commands?



For now I will postpone this problem.
I just wrote a small script to delete a dir using rm and it works even 
under cron!
There is another problem involved. The script, works fine except when 
launched by cron! Why?

I'll have to look into this later when I have more time.
For now I solved the problem using a complementary shell script.

Thank you very much to those who responded.
Paulo


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


Re: Find the path of a shell command

2022-10-12 Thread rbowman

On 10/12/22 09:06, Chris Green wrote:

Michael F. Stemper  wrote:

On 12/10/2022 07.20, Chris Green wrote:

jak  wrote:

Il 12/10/2022 09:40, jkn ha scritto:

On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:



I'm afraid you will have to look for the command in every path listed in
the PATH environment variable.


erm, or try 'which rm' ?


You might but if you don't know where the 'rm' command is, you will have
the same difficulty in using 'which' command. Do not you think?

  From a command prompt use the bash built-in 'command' :-

  command -v rm

... and rm will just about always be in /usr/bin.


On two different versions of Ubuntu, it's in /bin.


I think you'll find it's in both /bin and /usr/bin, usually /usr/bin
is earlier in the path so /usr/bin/rm is the one that will normally be
found first.

It's only in /bin/rm in case one has a system which mounts /bin
separately and earlier in the boot sequence and rm is one of the
commands needed early on.



ls -l /bin
lrwxrwxrwx 1 root root 7 Sep 23 01:41 /bin -> usr/bin



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


Re: for -- else: what was the motivation?

2022-10-12 Thread dn




On 11/10/2022 02.13, Grant Edwards wrote:

On 2022-10-10, Chris Angelico  wrote:

On Mon, 10 Oct 2022 at 11:52, MRAB  wrote:


On 2022-10-10 00:40, dn wrote:

On Sun, 9 Oct 2022 at 15:39, Axy via Python-list
 wrote:


"shortest block first"


Have never heard this advice before. Kind-of rankled with me, as it did
for others.


I've followed that advice for several decades. I find it much easier
to read code that's organized that way -- particularly when the
difference in block sizes is large (e.g. the first block is one line,
and the second is a a hundred).


Makes sense. Keep the 'cause' and 'effect' close together. In other 
words, making it easy to look 'up' from one of the 'suites' to see the 
if-statement/condition which directs that logic-branch.



Contrarily, (see @Karsten, earlier) the preference to bundle the 
"hundred" into one or more functions, rather than present as a 'wall of 
text'. Added advantage: well-chosen function names(!) will remind the 
reader of the purposes(!) of the "hundred".


Once both suites are short[ened], visibility improves (readability), and 
the above contention goes-away. Thus the sense of the condition becomes 
the most worthy consideration.


--
Regards,
=dn
--
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-12 Thread Peter J. Holzer
On 2022-10-11 14:11:56 -0400, Thomas Passin wrote:
> To bring things back to the context of the original post, actual web
> browsers are extremely tolerant of HTML syntax errors (including incorrect
> nesting of tags) in the documents they receive.

HTML5 actually specifies exactly how to recover from errors. So since
every sequence of bytes results in a well-defined DOM tree you might
argue (a bit tongue in cheek) that there are no syntax errors in HTML5.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-12 Thread Peter J. Holzer
On 2022-10-13 11:23:40 +1100, Chris Angelico wrote:
> On Thu, 13 Oct 2022 at 11:19, Peter J. Holzer  wrote:
> > On 2022-10-11 09:47:52 +1100, Chris Angelico wrote:
> > > On Tue, 11 Oct 2022 at 09:18, Cameron Simpson  wrote:
> > > >
> > > Consider:
> > >
> > > if condition # no colon
> > > code
> > > else:
> > > code
> > >
> > > To actually "restart" parsing, you have to make a guess of some sort.
> >
> > Right. At least one of the papers on parsing I read over the last few
> > years (yeah, I really should try to find them again) argued that the
> > vast majority of syntax errors is either a missing token, a superfluous
> > token or a combination of the the two. So one strategy with good results
> > is to heuristically try to insert or delete single tokens and check
> > which results in the longest distance to the next error.
> >
> > Checking multiple possible fixes has its cost, especially since you have
> > to do that at every error. So you can argue that it is better for
> > productivity if you discover one error in 0.1 seconds than 10 errors in
> > 5 seconds.
> 
> Maybe; but what if you report 10 errors in 5 seconds, but 8 of them
> are spurious? You've reported two useful errors in a sea of noise.
> Even if it's the other way around (8 where you nailed it and correctly
> reported the error, 2 that are nonsense), is it actually helpful?

Humans are pattern-matching animals. It is quite possible that seeing a
bunch of related errors makes the fix more obvious than seeing them in
isolation.

No, I haven't done any studies on this. Yes, it is possible that all
those compiler writers who spent lots of work on error recovery over the
last 50 years (or longer) are delusional.


> > > > I grew up with C and Pascal compilers which would _happily_ produce many
> > > > complaints, usually accurate, and all manner of syntactic errors. They
> > > > didn't stop at the first syntax error.
> > >
> > > Yes, because they work with a much simpler grammar.
> >
> > I very much doubt that. Python doesn't have a particularly complicated
> > grammar, and C certainly doesn't have a particularly simple one.
> >
> > The argument that it's impossible in Python (unlike any other language),
> > because Python is oh so special doesn't hold water.
> >
> 
> Never said it's because Python is special; there are a LOT of
> languages that are at least as complicated.

And almost all of their compilers do try to recover from errors.

> But I do think that Pascal, especially, has a significantly simpler
> grammar than Python does.

Incidentally, Turbo Pascal was the one other example of a compiler which
*didn't* try to recover.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What to use for finding as many syntax errors as possible.

2022-10-12 Thread Chris Angelico
On Thu, 13 Oct 2022 at 11:23, dn  wrote:
> # add an extra character within identifier, as if 'new' identifier
> 28  assert expected_value == fyibonacci_number
> UUU
>
> # these all trivial SYNTAX errors - could have tried leaving-out a
> keyword, but ...

Just to be clear, this last one is not actually a *syntax* error -
it's a misspelled name, but contextually, that is clearly a name and
nothing else. These are much easier to report multiples of, and
typical syntax highlighters will do so.

Your other two examples were both syntactic discrepancies though.

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


Re: What to use for finding as many syntax errors as possible.

2022-10-12 Thread Chris Angelico
On Thu, 13 Oct 2022 at 11:19, Peter J. Holzer  wrote:
>
> On 2022-10-11 09:47:52 +1100, Chris Angelico wrote:
> > On Tue, 11 Oct 2022 at 09:18, Cameron Simpson  wrote:
> > >
> > Consider:
> >
> > if condition # no colon
> > code
> > else:
> > code
> >
> > To actually "restart" parsing, you have to make a guess of some sort.
>
> Right. At least one of the papers on parsing I read over the last few
> years (yeah, I really should try to find them again) argued that the
> vast majority of syntax errors is either a missing token, a superfluous
> token or a combination of the the two. So one strategy with good results
> is to heuristically try to insert or delete single tokens and check
> which results in the longest distance to the next error.
>
> Checking multiple possible fixes has its cost, especially since you have
> to do that at every error. So you can argue that it is better for
> productivity if you discover one error in 0.1 seconds than 10 errors in
> 5 seconds.

Maybe; but what if you report 10 errors in 5 seconds, but 8 of them
are spurious? You've reported two useful errors in a sea of noise.
Even if it's the other way around (8 where you nailed it and correctly
reported the error, 2 that are nonsense), is it actually helpful? Bear
in mind that, if you can discover one syntax error in 0.1 seconds, you
can do that check *the moment the user types a key* in the editor
(which is more-or-less what happens with most syntax highlighting
editors - some have a small delay to avoid being too noisy with error
reporting, but same difference). Why report false errors when you can
report errors one by one and know that they're true?

> > > I grew up with C and Pascal compilers which would _happily_ produce many
> > > complaints, usually accurate, and all manner of syntactic errors. They
> > > didn't stop at the first syntax error.
> >
> > Yes, because they work with a much simpler grammar.
>
> I very much doubt that. Python doesn't have a particularly complicated
> grammar, and C certainly doesn't have a particularly simple one.
>
> The argument that it's impossible in Python (unlike any other language),
> because Python is oh so special doesn't hold water.
>

Never said it's because Python is special; there are a LOT of
languages that are at least as complicated. Try giving multiple useful
errors when there's a syntactic problem in SQL, for instance. But I do
think that Pascal, especially, has a significantly simpler grammar
than Python does.

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


Re: What to use for finding as many syntax errors as possible.

2022-10-12 Thread dn

On 09/10/2022 23.09, Antoon Pardon wrote:
I would like a tool that tries to find as many syntax errors as possible 
in a python file. I know there is the risk of false positives when a 
tool tries to recover from a syntax error and proceeds but I would 
prefer that over the current python strategy of quiting after the first 
syntax error. I just want a tool for syntax errors. No style 
enforcements. Any recommandations? -- Antoon Pardon



Am not sure if have really understood problem being addressed, because 
it seems 'answered' - perhaps the question says more about the tool-set 
being utilised...



As someone who used to manually check and re-check code before 
submitting (first punched-cards, and later edited files) source to a 
compiler, it took some re-education to learn what to expect from a 
modern/language-intelligent IDE.


The topic was a major interest back in the days of batch-compilers. Plus 
we had other tools, eg CREF/XREF utilities which produced 
cross-references of identifier usage - and illustrated typos in 
identifiers, usage before value-assignment, etc (per request from one 
respondent).



Using an IDE which is inspecting source-code as it is being typed (or 
when an existing file is opened) will suggest what might?should be typed 
'next' (a mixed blessing IMHO!), and secondly highlights errors until 
they are noticed and dealt-with. Some, especially warnings, can be 
safely ignored - and yes, some are spurious and SHOULD be ignored!.


PyCharm* displays a number of indicators. The least intrusive appears in 
the top-right corner of the editor-tab listing, eg 8 errors, 2 warnings. 
So, apparently not 'stopping' at first error found.


Within the source-code itself, there are high-lights and under-lines (in 
and amongst the syntax highlighting presentation/theme) - which I 
suppose are easier to notice during data-entry if one is a touch-typist. 
Accordingly, not much of a context for multiple errors to be committed 
during a single coding-session, but remaining un-noticed until 'the end'.



For illustration, I took a simple tutorial* routine and deliberately 
introduced some/many of the types of error discussed within this thread. 
It would have been ideal to attach a graphic but here are some lines of 
code, under which I have attempted to represent a highlighted character 
(related to the line above) with an "H", and a (red) under-lined token 
with a "U". So, this is a feeble-attempt to show how the source is 
displayed and annotated by the IDE:


# mis-type the tuple-assignment by adding semi-colon
# which might also confuse Python into thinking of a second instruction
17 i, j = 0;, 1
  H  UH

# replace under-line/under-score with space: s/b expected_value
25 for expected value, fibonacci_number in \
   UU  

# mis-type the name of the zip built-in function
26 z ip( SERIES, fibonacci_generator() ):
   U 

# add an extra character within identifier, as if 'new' identifier
28  assert expected_value == fyibonacci_number
   UUU

# these all trivial SYNTAX errors - could have tried leaving-out a 
keyword, but ...



Assuming the problem is not noticed/handled as the text is being typed, 
and in addition to the coder reviewing the work, recognising problems, 
and dealing with them him-/her-self; the IDE offers two follow-up 
mechanisms:


1 a means to jump 'focus' from the site of one error to the next, 
whereupon a pop-up will describe the error, eg (line 28) "Unresolved 
reference 'expected_value'"; which illustrates one problem in-isolation. 
In this case, line 28 is 'at fault' despite the fact that the 'error' is 
a consequence of THE problem on line 25!


2 a "Problems" Tool Window can be displayed, which will list every error 
and warning, with pretty, colored, icons, and the same message per 
example above, together with the relevant line-number, (the first two 
entries, as-listed, are 'warnings', and the rest are described as "errors"):


Need more values to unpack:17
Statement seems to have no effect:17
# so it has picked-up both of my nefarious intentions

Statement expected, found Py:COMMA:17
# as above
# NB the "Py:COMMA" is from tokenize (per @Chris contribution(s))
'in' expected:25
# logical, but confused by the space
Unresolved reference 'value':25
# pretty-much had no chance with so many faults in one statement!
Unresolved reference 'fibonacci_number':25
# ditto
Unresolved reference 'z':26
# absolutely!
':' expected:26
# evidently re-started after the "in" and did what it could with the "z"
Unresolved reference 'expected_value':28
# it would be "resolved" but for the first error on line 25
Unresolved reference 'fyibonacci_number':28
# ahah! Apparently trying to use an identifier before declaring/defining
# in reality, just another typo
# that said, I created the issue by inserting the "y"
# if I'd mistyped the 

Re: What to use for finding as many syntax errors as possible.

2022-10-12 Thread Peter J. Holzer
On 2022-10-11 09:47:52 +1100, Chris Angelico wrote:
> On Tue, 11 Oct 2022 at 09:18, Cameron Simpson  wrote:
> >
> Consider:
> 
> if condition # no colon
> code
> else:
> code
> 
> To actually "restart" parsing, you have to make a guess of some sort.

Right. At least one of the papers on parsing I read over the last few
years (yeah, I really should try to find them again) argued that the
vast majority of syntax errors is either a missing token, a superfluous
token or a combination of the the two. So one strategy with good results
is to heuristically try to insert or delete single tokens and check
which results in the longest distance to the next error.

Checking multiple possible fixes has its cost, especially since you have
to do that at every error. So you can argue that it is better for
productivity if you discover one error in 0.1 seconds than 10 errors in
5 seconds.


> > I grew up with C and Pascal compilers which would _happily_ produce many
> > complaints, usually accurate, and all manner of syntactic errors. They
> > didn't stop at the first syntax error.
> 
> Yes, because they work with a much simpler grammar.

I very much doubt that. Python doesn't have a particularly complicated
grammar, and C certainly doesn't have a particularly simple one.

The argument that it's impossible in Python (unlike any other language),
because Python is oh so special doesn't hold water.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Joe Pfeiffer
Cameron Simpson  writes:

> On 12Oct2022 20:54, Jon Ribbens  wrote:
>>On 2022-10-12, Jon Ribbens  wrote:
>>> On 2022-10-12, Joe Pfeiffer  wrote:
 Jon Ribbens  writes:
> on Amazon Linux:
>
> $ which rm
> /usr/bin/rm
> $ sudo which rm
> /bin/rm

 Have some major Linux distributions not done usrmerge yet?  For any that
 have, /bin is a symbolic link to /usr/bin
>
> The above example may just be a different ordering in $PATH.

Sure, but the point is OP can use either /bin/rm or /usr/bin/rm on the
vast majority of systems and execute the same command.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Paulo da Silva

Às 22:38 de 12/10/22, Jon Ribbens escreveu:

On 2022-10-12, Jon Ribbens  wrote:

On 2022-10-12, Paulo da Silva  wrote:

Às 19:14 de 12/10/22, Jon Ribbens escreveu:

On 2022-10-12, Paulo da Silva  wrote:

Às 05:00 de 12/10/22, Paulo da Silva escreveu:

Hi!

The simple question: How do I find the full path of a shell command
(linux), i.e. how do I obtain the corresponding of, for example,
"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well
until it is invoked by cron! I suspect that for cron we need to specify
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
What about other commands?


Thank you all who have responded so far.
I think that the the suggestion of searching the PATH env seems the best.
Another thing that I thought of is that of the 'which', but, to avoid
the mentioned recurrent problem of not knowing where 'which' is I would
use 'type' instead. 'type' is a bash (sh?) command.


If you're using subprocess.run / subprocess.Popen then the computer is
*already* searching PATH for you.

Yes, and it works out of cron.

Your problem must be that your cron
job is being run without PATH being set, perhaps you just need to edit
your crontab to set PATH to something sensible.

I could do that, but I am using /etc/cron.* for convenience.


Or just hard-code your
program to run '/bin/rm' explicitly, which should always work (unless
you're on Windows, of course!)

It can also be in /bin, at least.


I assume you mean /usr/bin. But it doesn't matter. As already
discussed, even if 'rm' is in /usr/bin, it will be in /bin as well
(or /usr/bin and /bin will be symlinks to the same place).


A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer
searching thru PATH env. It only needs to do that once.


I cannot think of any situation in which that will help you. But if for
some reason you really want to do that, you can use the shutil.which()
function from the standard library:

 >>> import shutil
 >>> shutil.which('rm')
 '/usr/bin/rm'


Actually if I'm mentioning shutil I should probably mention
shutil.rmtree() as well, which does the same as 'rm -r', without
needing to find or run any other executables.

Except that you can't have parallel tasks, at least in an easy way.
Using Popen I just launch rm's and end the script.


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


Re: for -- else: what was the motivation?

2022-10-12 Thread Peter J. Holzer
On 2022-10-10 16:48:04 +, Robert Latest via Python-list wrote:
> Axy wrote:
> >> Also not really a justification for "shortest block first". Wanting
> >> some elaboration on that. What's the value in it?
> >
> > Well, the value is productivity. No need to save puzzles "what this 
> > hanging else belongs to?"
> 
> If you find yourself asking that question, the if-block is probably too long 
> to
> begin with.

ACK.


> > Code small things first and return early, same 

> > as taking a test: do easy and quick things first and boring and 
> > difficult ones later.
> 
> Yes, but in that case you have a very long indented "else" block,

If you return you don't have to indent the rest.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: for -- else: what was the motivation?

2022-10-12 Thread Peter J. Holzer
On 2022-10-10 10:11:10 +, Stefan Ram wrote:
>   I would not use tabs in source code as they are not
>   displayed in the same way everywhere.

Some would argue that this is a feature. Different people prefer
different indentation widths. Using a single tab character for an
indentation level allows everybody to view the file in their preferred
layout.

I have, however, found out that this requires more discipline than I and
the people I work with can muster. There is always someone who
accidentally converts some tabs to spaces, messing up indentation for
everyone else. So I require a "indent by x spaces" rule for all projects
I work on (unless the language convention have a strong preference for
tabs, like in Go).

In email I would always use spaces. Tabs are just too unreliable there.


>   Functions also come at a cost. From the Web:
   
Ah yes. Your infamous aversion against useful citations strikes again.

For those too lazy to use a search engine, the excerpt seems to be from
https://softwarebyscience.com/very-short-functions-are-a-code-smell-an-overview-of-the-science-on-function-length/

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Peter J. Holzer
On 2022-10-12 21:51:39 +0100, Paulo da Silva wrote:
> Às 19:14 de 12/10/22, Jon Ribbens escreveu:
> > If you're using subprocess.run / subprocess.Popen then the computer is
> > *already* searching PATH for you.
> Yes, and it works out of cron.
> > Your problem must be that your cron
> > job is being run without PATH being set, perhaps you just need to edit
> > your crontab to set PATH to something sensible.

The PATH in cron includes the directories with standard commands like
"rm" by default. If a cron job doesn't find rm, either
 * rm isn't where it is supposed to be, or
 * PATH has been changed.

> I could do that, but I am using /etc/cron.* for convenience.

That may be a clue. Does any of the /etc/cron.* files set PATH to weird
value?

In any case I find that when debugging such problems it is helpful to
find out what the actual environment is. A simple 

* * * * * nobody echo $PATH >> /tmp/path.$$

should do that.

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Cameron Simpson

On 12Oct2022 20:54, Jon Ribbens  wrote:

On 2022-10-12, Jon Ribbens  wrote:

On 2022-10-12, Joe Pfeiffer  wrote:

Jon Ribbens  writes:

on Amazon Linux:

$ which rm
/usr/bin/rm
$ sudo which rm
/bin/rm


Have some major Linux distributions not done usrmerge yet?  For any that
have, /bin is a symbolic link to /usr/bin


The above example may just be a different ordering in $PATH.


I have immediate access to CentOS 7, Ubuntu 20, and Amazon Linux 2,
and none of those have done that.


Sorry, in fact they have done that - I misread your comment as being
that they had symlinked the executables not the directories. This seems
quite an unwise move to me but presumably they've thought it through.


I think that modern discs are so large these days that the scenario of 
having a small critical /bin with a larger less critical /usr/bin on 
another partition are behind us except in very niche circumstances.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Cameron Simpson

On 13Oct2022 08:50, Cameron Simpson  wrote:

On 12Oct2022 15:16, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote:

rm doesn't take that long.  Why are you detaching them?


[...]
For remove filesystems, even a local to your LAN NAS, it can take quite 
a while.


Of course I meant "remote" here, not "remove".

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command (shutil.which)

2022-10-12 Thread Eryk Sun
On 10/12/22, Weatherby,Gerard  wrote:
>
> When no path is specified, the results of
> os.environ() are used,
> returning either the “PATH” value or a fallback of
> os.defpath.

The documentation is out of sync with what the code actually does.
os.defpath is hard coded in posixpath and ntpath, but shutil.which()
actually prefers to query the system's default path to use via
os.confstr(), if it's supported:

if path is None:
path = os.environ.get("PATH", None)
if path is None:
try:
path = os.confstr("CS_PATH")
except (AttributeError, ValueError):
# os.confstr() or CS_PATH is not available
path = os.defpath

As documented by POSIX, the CS_PATH string "can be used as a value of
the PATH environment variable that accesses all of the standard
utilities of POSIX.1-2017, that are provided in a manner accessible
via the exec family of functions".

https://pubs.opengroup.org/onlinepubs/9699919799/functions/confstr.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Jon Ribbens  wrote:
> On 2022-10-12, Paulo da Silva  wrote:
>> Às 19:14 de 12/10/22, Jon Ribbens escreveu:
>>> On 2022-10-12, Paulo da Silva  wrote:
 Às 05:00 de 12/10/22, Paulo da Silva escreveu:
> Hi!
>
> The simple question: How do I find the full path of a shell command
> (linux), i.e. how do I obtain the corresponding of, for example,
> "type rm" in command line?
>
> The reason:
> I have python program that launches a detached rm. It works pretty well
> until it is invoked by cron! I suspect that for cron we need to specify
> the full path.
> Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
> What about other commands?
>
 Thank you all who have responded so far.
 I think that the the suggestion of searching the PATH env seems the best.
 Another thing that I thought of is that of the 'which', but, to avoid
 the mentioned recurrent problem of not knowing where 'which' is I would
 use 'type' instead. 'type' is a bash (sh?) command.
>>> 
>>> If you're using subprocess.run / subprocess.Popen then the computer is
>>> *already* searching PATH for you.
>> Yes, and it works out of cron.
>>> Your problem must be that your cron
>>> job is being run without PATH being set, perhaps you just need to edit
>>> your crontab to set PATH to something sensible.
>> I could do that, but I am using /etc/cron.* for convenience.
>>
>>> Or just hard-code your
>>> program to run '/bin/rm' explicitly, which should always work (unless
>>> you're on Windows, of course!)
>> It can also be in /bin, at least.
>
> I assume you mean /usr/bin. But it doesn't matter. As already
> discussed, even if 'rm' is in /usr/bin, it will be in /bin as well
> (or /usr/bin and /bin will be symlinks to the same place).
>
>> A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer 
>> searching thru PATH env. It only needs to do that once.
>
> I cannot think of any situation in which that will help you. But if for
> some reason you really want to do that, you can use the shutil.which()
> function from the standard library:
>
> >>> import shutil
> >>> shutil.which('rm')
> '/usr/bin/rm'

Actually if I'm mentioning shutil I should probably mention
shutil.rmtree() as well, which does the same as 'rm -r', without
needing to find or run any other executables.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fail 3.10.8 version installation on Windows 11 21H2

2022-10-12 Thread Eryk Sun
On 10/12/22, Kirill Ratkin via Python-list  wrote:
>
> Do anyone face issue like in log below?
>
> I got last installer (3.10.8) and try to install it 'for all users' with
> downloading precompiled (pdb) files.

There was a permission problem on the Python website that prevented
downloading the 3.8.10 debug binaries and symbol files. It's fixed
now.

https://github.com/python/cpython/issues/98193
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Cameron Simpson

On 12Oct2022 15:16, Dan Sommers <2qdxy4rzwzuui...@potatochowder.com> wrote:

rm doesn't take that long.  Why are you detaching them?


For big things it takes quite a while. On slow discs it can take quite a 
while. For directory trees with many files it can take quite a while.  
For remove filesystems, even a local to your LAN NAS, it can take quite 
a while.


Certainly I've got real world modern day things right now where "quite a 
while" can be many minutes.


I've got an `rmr` script of my own whose entire function is to rename 
the target to something like `.frm.blah` and then remove `.frm.blah` in 
the background. I use it a _lot_.


Ancient anecdote. We got funky new workstations at Uni long ago. For the 
first time in my life "rm filename" came back to the command prompt with 
no perceptable delay. So fast that I first wondered if it had worked at 
all. Previously we'd been using shared minicomputers (PDPs, Vaxen).


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command (shutil.which)

2022-10-12 Thread Weatherby,Gerard
Not going to do any good if it’s not on the PATH in the first place:

https://docs.python.org/3/library/shutil.html

shutil.which(cmd, mode=os.F_OK | os.X_OK, path=None)
Return the path to an executable which would be run if the given cmd was 
called. If no cmd would be called, return None.
mode is a permission mask passed to 
os.access(), by default 
determining if the file exists and executable.
When no path is specified, the results of 
os.environ() are used, 
returning either the “PATH” value or a fallback of 
os.defpath.


From: Python-list  on 
behalf of Thomas Passin 
Date: Wednesday, October 12, 2022 at 5:39 PM
To: python-list@python.org 
Subject: Re: Find the path of a shell command
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

On 10/12/2022 12:00 AM, Paulo da Silva wrote:
> Hi!
>
> The simple question: How do I find the full path of a shell command
> (linux), i.e. how do I obtain the corresponding of, for example,
> "type rm" in command line?
>
> The reason:
> I have python program that launches a detached rm. It works pretty well
> until it is invoked by cron! I suspect that for cron we need to specify
> the full path.
> Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
> What about other commands?
>
> Thanks for any comments/responses.
> Paulo
>

Python has a command that usually does the job:

import shutil, os
executable_path = shutil.which(exename, os.X_OK)

If you know that the executable you want is on some non-standard path,
you can or them together:

executable_path = shutil.which(exename, os.X_OK)\
or shutil.which(exename, os.X_OK, other_path)

Presumably the shutil command uses which behind the scenes, but that
doesn't matter.

Now you can include this location when you run the executable from
Python.  If you need to run a system command from a batch file and not
from Python, you will either need to have the right path in effect when
the batch file is run, or manually include the full path to the file in
the batch file.

BTW, on Linux Mint, which is derived from Ubuntu and Debian, rm is at

$ which rm
/bin/rm



--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!lyWawGnR8ddR5pCSS5bC09WInoHss_eleSRXxsjbIL_ndHz2TPW246oagSmaBVekZyVjzO7zKsGqN9NpLtM$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Cameron Simpson

On 12Oct2022 17:49, Paulo da Silva  wrote:

Às 05:00 de 12/10/22, Paulo da Silva escreveu:
I think that the the suggestion of searching the PATH env seems the 
best.


I just want to note that you want to not just check for existence of the 
path, but that it is executable (permissionwise). You want to use `X_OK` 
with the `os.access` function:

https://docs.python.org/3/library/os.html#os.access

Also notice that the `shutil` module has a `which()` function:
https://docs.python.org/3/library/shutil.html#shutil.which

Another thing that I thought of is that of the 'which', but, to avoid 
the mentioned recurrent problem of not knowing where 'which' is I 
would use 'type' instead.


`which` will almost always be in `/usr/bin` (or `/bin` on some systems I 
suppose). But do you need to know where `which` is? If you're invoking 
it instead of search `$PATH`, the normal executtion stuff itself search 
`$PATH`, an will find `which` for you :-)



'type' is a bash (sh?) command.


Yeah. Bash, ksh etc have `type`. It is a builtin, shich can see if a 
command word you give it is a shell alias or function or builtin or 
externally executed command. As you'd imagine, an external executable 
like `which` has no access to the internals of your shell, and can only 
look for executables.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Thomas Passin

On 10/12/2022 12:00 AM, Paulo da Silva wrote:

Hi!

The simple question: How do I find the full path of a shell command 
(linux), i.e. how do I obtain the corresponding of, for example,

"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well 
until it is invoked by cron! I suspect that for cron we need to specify 
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
What about other commands?


Thanks for any comments/responses.
Paulo



Python has a command that usually does the job:

import shutil, os
executable_path = shutil.which(exename, os.X_OK)

If you know that the executable you want is on some non-standard path, 
you can or them together:


executable_path = shutil.which(exename, os.X_OK)\
   or shutil.which(exename, os.X_OK, other_path)

Presumably the shutil command uses which behind the scenes, but that 
doesn't matter.


Now you can include this location when you run the executable from 
Python.  If you need to run a system command from a batch file and not 
from Python, you will either need to have the right path in effect when 
the batch file is run, or manually include the full path to the file in 
the batch file.


BTW, on Linux Mint, which is derived from Ubuntu and Debian, rm is at

$ which rm
/bin/rm



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


Re: Fail 3.10.8 version installation on Windows 11 21H2

2022-10-12 Thread Thomas Passin
You probably need to install from an administrator account to install 
for all users.


On 10/12/2022 5:20 AM, Kirill Ratkin via Python-list wrote:

Hi All,


Do anyone face issue like in log below?

I got last installer (3.10.8) and try to install it 'for all users' with 
downloading precompiled (pdb) files.


And installation fails saying permission error.

Installer says downloading error in the log.


I repeated it three times with same result



Just to test I got previous version (3.10.6) and it is installed without 
any errors with same installer settings.



 begin here  part of installer log file 
---


[183C:19E4][2022-10-12T12:01:23]e000: Error 0x80070005: Failed attempt 
to download URL: 
'https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi' to: 
'C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb'
[183C:19E4][2022-10-12T12:01:23]w343: Prompt for source of package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, path: 
C:\Users\Kirill\Downloads\core_pdb.msi
[183C:19E4][2022-10-12T12:01:26]i338: Acquiring package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, download from: 
https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi
[183C:19E4][2022-10-12T12:01:26]e000: Error 0x80070005: Failed attempt 
to download URL: 
'https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi' to: 
'C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb'
[183C:19E4][2022-10-12T12:01:26]w343: Prompt for source of package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, path: 
C:\Users\Kirill\Downloads\core_pdb.msi
[183C:19E4][2022-10-12T12:01:29]i338: Acquiring package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, download from: 
https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi
[183C:19E4][2022-10-12T12:01:29]e000: Error 0x80070005: Failed attempt 
to download URL: 
'https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi' to: 
'C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb'
[183C:19E4][2022-10-12T12:01:29]w343: Prompt for source of package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, path: 
C:\Users\Kirill\Downloads\core_pdb.msi
[183C:19E4][2022-10-12T12:01:32]i338: Acquiring package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, download from: 
https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi
[183C:19E4][2022-10-12T12:01:32]e000: Error 0x80070005: Failed attempt 
to download URL: 
'https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi' to: 
'C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb'
[183C:19E4][2022-10-12T12:01:32]e000: Error 0x80070005: Failed to 
acquire payload from: 
'https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi' to working 
path: 
'C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb'
[183C:19E4][2022-10-12T12:01:32]e313: Failed to acquire payload: 
core_AllUsers_pdb to working path: 
C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb, error: 0x80070005.
[08CC:3570][2022-10-12T12:01:32]i351: Removing cached package: 
core_AllUsers, from path: C:\ProgramData\Package 
Cache\{6463E43B-54B1-4407-818D-DD90D11CDD06}v3.10.8150.0\
[183C:313C][2022-10-12T12:01:32]e000: Error 0x80070005: Cache thread 
exited unexpectedly.


 end here  part of installer log file 
---





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


Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Paulo da Silva  wrote:
> Às 19:14 de 12/10/22, Jon Ribbens escreveu:
>> On 2022-10-12, Paulo da Silva  wrote:
>>> Às 05:00 de 12/10/22, Paulo da Silva escreveu:
 Hi!

 The simple question: How do I find the full path of a shell command
 (linux), i.e. how do I obtain the corresponding of, for example,
 "type rm" in command line?

 The reason:
 I have python program that launches a detached rm. It works pretty well
 until it is invoked by cron! I suspect that for cron we need to specify
 the full path.
 Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
 What about other commands?

>>> Thank you all who have responded so far.
>>> I think that the the suggestion of searching the PATH env seems the best.
>>> Another thing that I thought of is that of the 'which', but, to avoid
>>> the mentioned recurrent problem of not knowing where 'which' is I would
>>> use 'type' instead. 'type' is a bash (sh?) command.
>> 
>> If you're using subprocess.run / subprocess.Popen then the computer is
>> *already* searching PATH for you.
> Yes, and it works out of cron.
>> Your problem must be that your cron
>> job is being run without PATH being set, perhaps you just need to edit
>> your crontab to set PATH to something sensible.
> I could do that, but I am using /etc/cron.* for convenience.
>
>> Or just hard-code your
>> program to run '/bin/rm' explicitly, which should always work (unless
>> you're on Windows, of course!)
> It can also be in /bin, at least.

I assume you mean /usr/bin. But it doesn't matter. As already
discussed, even if 'rm' is in /usr/bin, it will be in /bin as well
(or /usr/bin and /bin will be symlinks to the same place).

> A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer 
> searching thru PATH env. It only needs to do that once.

I cannot think of any situation in which that will help you. But if for
some reason you really want to do that, you can use the shutil.which()
function from the standard library:

>>> import shutil
>>> shutil.which('rm')
'/usr/bin/rm'

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


Re: Find the path of a shell command

2022-10-12 Thread Weatherby,Gerard
Some thoughts / notes:
1. On our Ubuntu-Server 20.04.3 based systems, /bin/rm and /usr/bin/rm are hard 
links to the same file.

2. Put the following in a bash script and run it from cron. Then you can see 
what your environment is. Mine has PATH=/usr/bin:/bin in it.

#!/bin/bash
env > /tmp/env$$

3. You can background Python just as well as you can a separate rm invocation.
if os.fork() == 0:
os.unlink(….)








From: Python-list  on 
behalf of Grant Edwards 
Date: Wednesday, October 12, 2022 at 5:03 PM
To: python-list@python.org 
Subject: Re: Find the path of a shell command
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

On 2022-10-12, 2qdxy4rzwzuui...@potatochowder.com 
<2qdxy4rzwzuui...@potatochowder.com> wrote:
> On 2022-10-12 at 17:43:18 +0100, Paulo da Silva 
>  wrote:
>>
>> > Probably you could use os.unlink[1] with no problem.
>>
>> No, because I need to launch several rm's that keep running after the script
>> ends.
>
> rm doesn't take that long.

Recursive ones can take a long time.

--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!ny8-fSGJEE3wk-Yq188xuT5aamgIUVI6SJQHkNaxMp11JelflHEJ2SQcYqqSC1s8pxkifVVdFyeEcbSv1ZJlqoaxuG_m$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Paulo da Silva

Às 20:09 de 12/10/22, Antoon Pardon escreveu:



Op 12/10/2022 om 18:49 schreef Paulo da Silva:

Às 05:00 de 12/10/22, Paulo da Silva escreveu:

Hi!

The simple question: How do I find the full path of a shell command 
(linux), i.e. how do I obtain the corresponding of, for example,

"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty 
well until it is invoked by cron! I suspect that for cron we need to 
specify the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
What about other commands?



Thank you all who have responded so far.
I think that the the suggestion of searching the PATH env seems the best.


I fear that won't work.

If it doesn't work in cron, that probably means, PATH is not set 
properly in your cron environment. And if PATH is not set properly, 
searching it explicitely won't work either.



It seems you are right :-( I didn't think of that!
Does 'type' bash command work? I don't know how bash 'type' works.
I need to do some tests.
Thanks
Paulo



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


Re: Find the path of a shell command

2022-10-12 Thread jak

Il 12/10/2022 20:19, MRAB ha scritto:

On 2022-10-12 06:11, jak wrote:

Il 12/10/2022 06:00, Paulo da Silva ha scritto:

Hi!

The simple question: How do I find the full path of a shell command 
(linux), i.e. how do I obtain the corresponding of, for example,

"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty 
well until it is invoked by cron! I suspect that for cron we need to 
specify the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
What about other commands?


Thanks for any comments/responses.
Paulo



I'm afraid you will have to look for the command in every path listed in
the PATH environment variable.


Isn't that what the "whereis" command does?


"whereis" does more than the OP wants. A suitable command could be
"which" but if the OP is in a context where he needs to know the path
of the command, then it will have the same problem with "whereis" or
"which". In any case they would be a few lines of Python:

import os

def which(c):
for p in os.getenv('PATH').split(os.path.pathsep):
if p and os.path.isfile(f := os.path.join(p, c)):
return f
return ''

cmd = 'explorer.exe'
cmdp = which(cmd)

if cmdp:
print("found:", cmdp)
else:
print("not found"

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


Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Jon Ribbens  wrote:
> On 2022-10-12, Joe Pfeiffer  wrote:
>> Jon Ribbens  writes:
>>
>>> On 2022-10-12, Michael F. Stemper  wrote:
 On 12/10/2022 07.20, Chris Green wrote:
> ... and rm will just about always be in /usr/bin.

 On two different versions of Ubuntu, it's in /bin.
>>>
>>> It will almost always be in /bin in any Unix or Unix-like system,
>>> because it's one of the fundamental utilities that may be vital in
>>> fixing the system when it's booted in single-user mode and /usr may
>>> not be available. Also, the Filesystem Hierarchy Standard *requires*
>>> it to be in /bin.
>>>
>>> Having said that, nothing requires it not to be elsewhere *as well*,
>>> and in Ubuntu and other Linux systems it is in /usr/bin too. And because
>>> PATH for non-root users will usually contain /usr/bin before /bin (or
>>> indeed may not contain /bin at all), 'command -v rm' or 'which rm' will
>>> usually list the version of rm that is in /usr/bin.
>>>
>>> e.g. on Amazon Linux:
>>>
>>> $ which rm
>>> /usr/bin/rm
>>> $ sudo which rm
>>> /bin/rm
>>
>> Have some major Linux distributions not done usrmerge yet?  For any that
>> have, /bin is a symbolic link to /usr/bin
>
> I have immediate access to CentOS 7, Ubuntu 20, and Amazon Linux 2,
> and none of those have done that.

Sorry, in fact they have done that - I misread your comment as being
that they had symlinked the executables not the directories. This seems
quite an unwise move to me but presumably they've thought it through.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Paulo da Silva

Às 19:14 de 12/10/22, Jon Ribbens escreveu:

On 2022-10-12, Paulo da Silva  wrote:

Às 05:00 de 12/10/22, Paulo da Silva escreveu:

Hi!

The simple question: How do I find the full path of a shell command
(linux), i.e. how do I obtain the corresponding of, for example,
"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well
until it is invoked by cron! I suspect that for cron we need to specify
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
What about other commands?


Thank you all who have responded so far.
I think that the the suggestion of searching the PATH env seems the best.
Another thing that I thought of is that of the 'which', but, to avoid
the mentioned recurrent problem of not knowing where 'which' is I would
use 'type' instead. 'type' is a bash (sh?) command.


If you're using subprocess.run / subprocess.Popen then the computer is
*already* searching PATH for you.

Yes, and it works out of cron.

Your problem must be that your cron
job is being run without PATH being set, perhaps you just need to edit
your crontab to set PATH to something sensible.

I could do that, but I am using /etc/cron.* for convenience.


Or just hard-code your
program to run '/bin/rm' explicitly, which should always work (unless
you're on Windows, of course!)

It can also be in /bin, at least.
A short idea is to just check /bin/rm and /usr/bin/rm, but I prefer 
searching thru PATH env. It only needs to do that once.



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


Re: Find the path of a shell command

2022-10-12 Thread Paulo da Silva

Às 20:16 de 12/10/22, 2qdxy4rzwzuui...@potatochowder.com escreveu:

On 2022-10-12 at 17:43:18 +0100,
Paulo da Silva  wrote:


Às 17:22 de 12/10/22, Tilmann Hentze escreveu:

Paulo da Silva  schrieb:

I have python program that launches a detached rm. It works pretty well
until it is invoked by cron! I suspect that for cron we need to specify
the full path.


Probably you could use os.unlink[1] with no problem.

No, because I need to launch several rm's that keep running after the script
ends.


rm doesn't take that long.  Why are you detaching them?


Because the use of "rm -rf" here is to remove full dirs, mostly in 
external drives, each reaching more than hundreds thousand files.




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


Re: for -- else: what was the motivation?

2022-10-12 Thread Weatherby,Gerard
As did I.

tree = ET.parse(lfile)
for child in tree.getroot():
if child.tag == 'server':
break
else:
raise ValueError(f"server tag not found in {lfile}")

I think there are other places I could be using it, but honestly I tend to 
forget it’s available.

From: Python-list  on 
behalf of Stefan Ram 
Date: Wednesday, October 12, 2022 at 2:22 PM
To: python-list@python.org 
Subject: Re: for -- else: what was the motivation?
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

Axy  writes:
>So, seriously, why they needed else if the following pieces produce same
>result? Does anyone know or remember their motivation?

  Just wrote code wherein I used "else"! This:

import locale
for name in( 'de', 'de_DE', 'deu_deu', 'deu', 'German', 'Deutsch' ):
try: locale.setlocale( locale.LC_ALL, name ); break
except locale.Error: pass
else: print( "Programm kann deutsche Schreibweise nicht einrichten." )

  .


--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!iyDac-XjNlj78G0XwNzZ-FEHyuCZIy33n3cI9MUDM_FnEdR04mSQ5Ln0OA1ETUNloyH24iY9meNHVdixLgWRYL8$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Grant Edwards
On 2022-10-12, 2qdxy4rzwzuui...@potatochowder.com 
<2qdxy4rzwzuui...@potatochowder.com> wrote:
> On 2022-10-12 at 17:43:18 +0100, Paulo da Silva 
>  wrote:
>>
>> > Probably you could use os.unlink[1] with no problem.
>>
>> No, because I need to launch several rm's that keep running after the script
>> ends.
>
> rm doesn't take that long.

Recursive ones can take a long time.

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


Re: Find the path of a shell command

2022-10-12 Thread 2QdxY4RzWzUUiLuE
On 2022-10-12 at 17:43:18 +0100,
Paulo da Silva  wrote:

> Às 17:22 de 12/10/22, Tilmann Hentze escreveu:
> > Paulo da Silva  schrieb:
> > > I have python program that launches a detached rm. It works pretty well
> > > until it is invoked by cron! I suspect that for cron we need to specify
> > > the full path.
> > 
> > Probably you could use os.unlink[1] with no problem.
> No, because I need to launch several rm's that keep running after the script
> ends.

rm doesn't take that long.  Why are you detaching them?

(I'm not debating your point about cron.)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Antoon Pardon



Op 12/10/2022 om 18:49 schreef Paulo da Silva:

Às 05:00 de 12/10/22, Paulo da Silva escreveu:

Hi!

The simple question: How do I find the full path of a shell command 
(linux), i.e. how do I obtain the corresponding of, for example,

"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty 
well until it is invoked by cron! I suspect that for cron we need to 
specify the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
What about other commands?



Thank you all who have responded so far.
I think that the the suggestion of searching the PATH env seems the best.


I fear that won't work.

If it doesn't work in cron, that probably means, PATH is not set 
properly in your cron environment. And if PATH is not set properly, 
searching it explicitely won't work either.


If rm works when evoked directly in a cron script but not via a python 
script, you may need to export the PATH in your cron script.


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


Re: Find the path of a shell command

2022-10-12 Thread jkn
On Wednesday, October 12, 2022 at 12:07:36 PM UTC+1, jak wrote:
> Il 12/10/2022 09:40, jkn ha scritto: 
> > On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote: 
> >> Il 12/10/2022 06:00, Paulo da Silva ha scritto: 
> >>> Hi! 
> >>> 
> >>> The simple question: How do I find the full path of a shell command 
> >>> (linux), i.e. how do I obtain the corresponding of, for example, 
> >>> "type rm" in command line? 
> >>> 
> >>> The reason: 
> >>> I have python program that launches a detached rm. It works pretty well 
> >>> until it is invoked by cron! I suspect that for cron we need to specify 
> >>> the full path. 
> >>> Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
> >>> What about other commands? 
> >>> 
> >>> Thanks for any comments/responses. 
> >>> Paulo 
> >>> 
> >> I'm afraid you will have to look for the command in every path listed in 
> >> the PATH environment variable. 
> > 
> > erm, or try 'which rm' ?
> You might but if you don't know where the 'rm' command is, you will have 
> the same difficulty in using 'which' Command. Do not you think?

I don't need to know where the rm command is in order to use the which command.

I *was* (knowingly and deliberately) assuming that you have a semi-reasonably
working system, and that your question meant "given command X, how do I
find where the executable X is on my system?".

Sounds like you want to make less assumptions than that. Fine. but probably
best to be clear about your assumptions up front.

J^n
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Paulo da Silva  wrote:
> Às 05:00 de 12/10/22, Paulo da Silva escreveu:
>> Hi!
>> 
>> The simple question: How do I find the full path of a shell command 
>> (linux), i.e. how do I obtain the corresponding of, for example,
>> "type rm" in command line?
>> 
>> The reason:
>> I have python program that launches a detached rm. It works pretty well 
>> until it is invoked by cron! I suspect that for cron we need to specify 
>> the full path.
>> Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
>> What about other commands?
>> 
> Thank you all who have responded so far.
> I think that the the suggestion of searching the PATH env seems the best.
> Another thing that I thought of is that of the 'which', but, to avoid 
> the mentioned recurrent problem of not knowing where 'which' is I would 
> use 'type' instead. 'type' is a bash (sh?) command.

If you're using subprocess.run / subprocess.Popen then the computer is
*already* searching PATH for you. Your problem must be that your cron
job is being run without PATH being set, perhaps you just need to edit
your crontab to set PATH to something sensible. Or just hard-code your
program to run '/bin/rm' explicitly, which should always work (unless
you're on Windows, of course!)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread MRAB

On 2022-10-12 06:11, jak wrote:

Il 12/10/2022 06:00, Paulo da Silva ha scritto:

Hi!

The simple question: How do I find the full path of a shell command 
(linux), i.e. how do I obtain the corresponding of, for example,

"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well 
until it is invoked by cron! I suspect that for cron we need to specify 
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
What about other commands?


Thanks for any comments/responses.
Paulo



I'm afraid you will have to look for the command in every path listed in
the PATH environment variable.


Isn't that what the "whereis" command does?
--
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Joe Pfeiffer  wrote:
> Jon Ribbens  writes:
>
>> On 2022-10-12, Michael F. Stemper  wrote:
>>> On 12/10/2022 07.20, Chris Green wrote:
 ... and rm will just about always be in /usr/bin.
>>>
>>> On two different versions of Ubuntu, it's in /bin.
>>
>> It will almost always be in /bin in any Unix or Unix-like system,
>> because it's one of the fundamental utilities that may be vital in
>> fixing the system when it's booted in single-user mode and /usr may
>> not be available. Also, the Filesystem Hierarchy Standard *requires*
>> it to be in /bin.
>>
>> Having said that, nothing requires it not to be elsewhere *as well*,
>> and in Ubuntu and other Linux systems it is in /usr/bin too. And because
>> PATH for non-root users will usually contain /usr/bin before /bin (or
>> indeed may not contain /bin at all), 'command -v rm' or 'which rm' will
>> usually list the version of rm that is in /usr/bin.
>>
>> e.g. on Amazon Linux:
>>
>> $ which rm
>> /usr/bin/rm
>> $ sudo which rm
>> /bin/rm
>
> Have some major Linux distributions not done usrmerge yet?  For any that
> have, /bin is a symbolic link to /usr/bin

I have immediate access to CentOS 7, Ubuntu 20, and Amazon Linux 2,
and none of those have done that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Paulo da Silva

Às 17:22 de 12/10/22, Tilmann Hentze escreveu:

Paulo da Silva  schrieb:

I have python program that launches a detached rm. It works pretty well
until it is invoked by cron! I suspect that for cron we need to specify
the full path.


Probably you could use os.unlink[1] with no problem.
No, because I need to launch several rm's that keep running after the 
script ends.



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


Re: Find the path of a shell command

2022-10-12 Thread Joe Pfeiffer
Jon Ribbens  writes:

> On 2022-10-12, Michael F. Stemper  wrote:
>> On 12/10/2022 07.20, Chris Green wrote:
>>> ... and rm will just about always be in /usr/bin.
>>
>> On two different versions of Ubuntu, it's in /bin.
>
> It will almost always be in /bin in any Unix or Unix-like system,
> because it's one of the fundamental utilities that may be vital in
> fixing the system when it's booted in single-user mode and /usr may
> not be available. Also, the Filesystem Hierarchy Standard *requires*
> it to be in /bin.
>
> Having said that, nothing requires it not to be elsewhere *as well*,
> and in Ubuntu and other Linux systems it is in /usr/bin too. And because
> PATH for non-root users will usually contain /usr/bin before /bin (or
> indeed may not contain /bin at all), 'command -v rm' or 'which rm' will
> usually list the version of rm that is in /usr/bin.
>
> e.g. on Amazon Linux:
>
> $ which rm
> /usr/bin/rm
> $ sudo which rm
> /bin/rm

Have some major Linux distributions not done usrmerge yet?  For any that
have, /bin is a symbolic link to /usr/bin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to fix Python error, The term '.../python.exe' is not recognized as the name of a cmdlet, function, script file, or operable program, in VS Code?

2022-10-12 Thread Dennis Lee Bieber
On Tue, 11 Oct 2022 16:40:31 -0700, LouisAden Capellupo
 declaimed the following:

> So basically, I get, "The term '...\python.exe' is not recognized as the 
>name of a cmdlet, function, script, file, or operable program... At line: 1 
>char: 3." It works the first way I showed with Code Runner, but the second or 
>original way doesn't work. What if I don't want to use Code Runner? Any help 
>in fixing this problem would be greatly appreciated. Sorry if certain things 
>are unclear as this is my first time using Python.
>

What happens if you change the system to use the "command" shell
INSTEAD OF PowerShell?

PowerShell may not honor the same environment variables.


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Paulo da Silva

Às 05:00 de 12/10/22, Paulo da Silva escreveu:

Hi!

The simple question: How do I find the full path of a shell command 
(linux), i.e. how do I obtain the corresponding of, for example,

"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well 
until it is invoked by cron! I suspect that for cron we need to specify 
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
What about other commands?



Thank you all who have responded so far.
I think that the the suggestion of searching the PATH env seems the best.
Another thing that I thought of is that of the 'which', but, to avoid 
the mentioned recurrent problem of not knowing where 'which' is I would 
use 'type' instead. 'type' is a bash (sh?) command.


Thanks
Paulo


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


Re: Find the path of a shell command

2022-10-12 Thread Michael F. Stemper

On 12/10/2022 07.20, Chris Green wrote:

jak  wrote:

Il 12/10/2022 09:40, jkn ha scritto:

On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:



I'm afraid you will have to look for the command in every path listed in
the PATH environment variable.


erm, or try 'which rm' ?


You might but if you don't know where the 'rm' command is, you will have
the same difficulty in using 'which' command. Do not you think?

 From a command prompt use the bash built-in 'command' :-

 command -v rm

... and rm will just about always be in /usr/bin.


On two different versions of Ubuntu, it's in /bin.

--
Michael F. Stemper
Psalm 94:3-6
--
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Chris Green
Michael F. Stemper  wrote:
> On 12/10/2022 07.20, Chris Green wrote:
> > jak  wrote:
> >> Il 12/10/2022 09:40, jkn ha scritto:
> >>> On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
> 
>  I'm afraid you will have to look for the command in every path listed in
>  the PATH environment variable.
> >>>
> >>> erm, or try 'which rm' ?
> >>
> >> You might but if you don't know where the 'rm' command is, you will have
> >> the same difficulty in using 'which' command. Do not you think?
> >  From a command prompt use the bash built-in 'command' :-
> > 
> >  command -v rm
> > 
> > ... and rm will just about always be in /usr/bin.
> 
> On two different versions of Ubuntu, it's in /bin.
> 
I think you'll find it's in both /bin and /usr/bin, usually /usr/bin
is earlier in the path so /usr/bin/rm is the one that will normally be
found first.

It's only in /bin/rm in case one has a system which mounts /bin
separately and earlier in the boot sequence and rm is one of the
commands needed early on.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread Jon Ribbens via Python-list
On 2022-10-12, Michael F. Stemper  wrote:
> On 12/10/2022 07.20, Chris Green wrote:
>> ... and rm will just about always be in /usr/bin.
>
> On two different versions of Ubuntu, it's in /bin.

It will almost always be in /bin in any Unix or Unix-like system,
because it's one of the fundamental utilities that may be vital in
fixing the system when it's booted in single-user mode and /usr may
not be available. Also, the Filesystem Hierarchy Standard *requires*
it to be in /bin.

Having said that, nothing requires it not to be elsewhere *as well*,
and in Ubuntu and other Linux systems it is in /usr/bin too. And because
PATH for non-root users will usually contain /usr/bin before /bin (or
indeed may not contain /bin at all), 'command -v rm' or 'which rm' will
usually list the version of rm that is in /usr/bin.

e.g. on Amazon Linux:

$ which rm
/usr/bin/rm
$ sudo which rm
/bin/rm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot import gdal in jupyter notebook

2022-10-12 Thread Abdul Haseeb Azizi
On Wednesday, October 12, 2022 at 9:51:22 AM UTC+2, Abdul Haseeb Azizi wrote:
> On Tuesday, October 11, 2022 at 10:29:34 PM UTC+2, MRAB wrote: 
> > On 2022-10-11 20:38, Thomas Passin wrote: 
> > > On Windows, when I tried to install gdal using pip, it needed to compile 
> > > part of it. I'm not set up with the Microsoft compiler and header 
> > > files, so that failed. If you are on Windows, you will need to look for 
> > > a binary wheel to install, or install and configure the compiler and 
> > > header files. 
> > > 
> > The PyPI page at https://pypi.org/project/GDAL/ has this: 
> > 
> > """ 
> > Conda 
> > GDAL can be quite complex to build and install, particularly on Windows 
> > and MacOS. Pre built binaries are provided for the conda system: 
> > 
> > https://docs.conda.io/en/latest/ 
> > 
> > By the conda-forge project: 
> > 
> > https://conda-forge.org/ 
> > """ 
> > 
> > > On 10/11/2022 11:53 AM, Abdul Haseeb Azizi wrote: 
> > >> Hi everyone, 
> > >> I am new to python and I am trying to utilize this code "from osgeo 
> > >> import gdal". I installed python 3.10 and also I installed anaconda3 to 
> > >> solve this matter but I could not succeed. When I run that code I get 
> > >> the following error. 
> > >> ---
> > >>  
> > >> ModuleNotFoundError Traceback (most recent call last) 
> > >> Cell In [1], line 1 
> > >> > 1 from osgeo import gdal 
> > >> 
> > >> ModuleNotFoundError: No module named 'osgeo' 
> > >> 
> > >> I also tried to create anaconda environment and enter the following 
> > >> codes: 
> > >> conda crate --name pygdal 
> > >> conda activate pygdal 
> > >> conda install -c conda-forge gdal 
> > >> 
> > >> I don't what is the problem. Any help is appreciated to solve this 
> > >> matter. 
> > >> Looking forward to hear from you. 
> > >> 
> > >> with regards 
> > >> Abdul 
> > >
> Thanks a lot for your recommendations. 
> As I mentioned before I installed conda and also created conda environment 
> using the following codes: 
> Step 1: Create conda environment 
> 
> conda create --name venv 
> 
> After creating the virtual environment, by default it will install some of 
> the packages. 
> Step 2: Installation of gdal
> conda install -c conda-forge gdal
> Step 3: Installation of ipykernel 
> 
> conda install -c anaconda ipykernel 
> 
> Step 4: Add ipykernel and run jupyternotebook 
> 
> python -m ipykernel install --user --name=venv 
> jupyter notebook 
> 
> 
> still I get the following error: 
> 
> %pip install gdal 
> 
> Requirement already satisfied: gdal in 
> c:\users\abdul\anaconda3\lib\site-packages (3.4.1) 
> Note: you may need to restart the kernel to use updated packages. 
> 
> from osgeo import gdal 
> 
> 
> --- 
> ImportError Traceback (most recent call last) 
> File ~\anaconda3\lib\site-packages\osgeo\__init__.py:29, in 
> swig_import_helper() 
> 28 try: 
> ---> 29 return importlib.import_module(mname) 
> 30 except ImportError: 
> 
> File ~\anaconda3\lib\importlib\__init__.py:127, in import_module(name, 
> package) 
> 126 level += 1 
> --> 127 return _bootstrap._gcd_import(name[level:], package, level) 
> 
> File :1030, in _gcd_import(name, package, level) 
> 
> File :1007, in _find_and_load(name, import_) 
> 
> File :986, in _find_and_load_unlocked(name, 
> import_) 
> 
> File :666, in _load_unlocked(spec) 
> 
> File :565, in module_from_spec(spec) 
> 
> File :1173, in create_module(self, 
> spec) 
> 
> File :228, in _call_with_frames_removed(f, 
> *args, **kwds) 
> 
> ImportError: DLL load failed while importing _gdal: The specified module 
> could not be found. 
> 
> During handling of the above exception, another exception occurred: 
> 
> ImportError Traceback (most recent call last) 
> Input In [1], in ()
> > 1 from osgeo import gdal
> File ~\anaconda3\lib\site-packages\osgeo\__init__.py:45, in  
> 41 raise ImportError(traceback_string + '\n' + msg) 
> 42 return importlib.import_module('_gdal') 
> ---> 45 _gdal = swig_import_helper() 
> 46 del swig_import_helper 
> 48 __version__ = _gdal.__version__ = _gdal.VersionInfo("RELEASE_NAME") 
> 
> File ~\anaconda3\lib\site-packages\osgeo\__init__.py:41, in 
> swig_import_helper() 
> 39 import traceback 
> 40 traceback_string = ''.join(traceback.format_exception(*sys.exc_info())) 
> ---> 41 raise ImportError(traceback_string + '\n' + msg) 
> 42 return importlib.import_module('_gdal') 
> 
> ImportError: Traceback (most recent call last): 
> File "C:\Users\abdul\anaconda3\lib\site-packages\osgeo\__init__.py", line 29, 
> in swig_import_helper 
> return importlib.import_module(mname) 
> File "C:\Users\abdul\anaconda3\lib\importlib\__init__.py", line 127, in 
> import_module 
> return _bootstrap._gcd_import(name[level:], package, level) 
> File "", line 1030, in _gcd_import 
> File "", line 1007, in _find_and_load 
> File "", line 986, in _find_and_load_unlocked 
> File "", 

Re: Find the path of a shell command

2022-10-12 Thread jak

Il 12/10/2022 14:20, Chris Green ha scritto:

jak  wrote:

Il 12/10/2022 09:40, jkn ha scritto:

On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:

Il 12/10/2022 06:00, Paulo da Silva ha scritto:

Hi!

The simple question: How do I find the full path of a shell command
(linux), i.e. how do I obtain the corresponding of, for example,
"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well
until it is invoked by cron! I suspect that for cron we need to specify
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
What about other commands?

Thanks for any comments/responses.
Paulo


I'm afraid you will have to look for the command in every path listed in
the PATH environment variable.


erm, or try 'which rm' ?


You might but if you don't know where the 'rm' command is, you will have
the same difficulty in using 'which' command. Do not you think?


 From a command prompt use the bash built-in 'command' :-

 command -v rm

... and rm will just about always be in /usr/bin.



ok but I didn't suggest a very complicated thing:

for p in os.getenv('PATH').split(os.path.pathsep):
if p:
if os.path.isfile(os.path.join(p, 'rm')):
print(f)

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


Re: Find the path of a shell command

2022-10-12 Thread Chris Green
jak  wrote:
> Il 12/10/2022 09:40, jkn ha scritto:
> > On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
> >> Il 12/10/2022 06:00, Paulo da Silva ha scritto:
> >>> Hi!
> >>>
> >>> The simple question: How do I find the full path of a shell command
> >>> (linux), i.e. how do I obtain the corresponding of, for example,
> >>> "type rm" in command line?
> >>>
> >>> The reason:
> >>> I have python program that launches a detached rm. It works pretty well
> >>> until it is invoked by cron! I suspect that for cron we need to specify
> >>> the full path.
> >>> Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
> >>> What about other commands?
> >>>
> >>> Thanks for any comments/responses.
> >>> Paulo
> >>>
> >> I'm afraid you will have to look for the command in every path listed in
> >> the PATH environment variable.
> > 
> > erm, or try 'which rm' ?
> 
> You might but if you don't know where the 'rm' command is, you will have
> the same difficulty in using 'which' command. Do not you think?
> 
From a command prompt use the bash built-in 'command' :-

command -v rm

... and rm will just about always be in /usr/bin.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Find the path of a shell command

2022-10-12 Thread jak

Il 12/10/2022 09:40, jkn ha scritto:

On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:

Il 12/10/2022 06:00, Paulo da Silva ha scritto:

Hi!

The simple question: How do I find the full path of a shell command
(linux), i.e. how do I obtain the corresponding of, for example,
"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well
until it is invoked by cron! I suspect that for cron we need to specify
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin?
What about other commands?

Thanks for any comments/responses.
Paulo


I'm afraid you will have to look for the command in every path listed in
the PATH environment variable.


erm, or try 'which rm' ?


You might but if you don't know where the 'rm' command is, you will have
the same difficulty in using 'which' Command. Do not you think?

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


Fail 3.10.8 version installation on Windows 11 21H2

2022-10-12 Thread Kirill Ratkin via Python-list

Hi All,


Do anyone face issue like in log below?

I got last installer (3.10.8) and try to install it 'for all users' with 
downloading precompiled (pdb) files.


And installation fails saying permission error.

Installer says downloading error in the log.


I repeated it three times with same result



Just to test I got previous version (3.10.6) and it is installed without 
any errors with same installer settings.



 begin here  part of installer log file 
---


[183C:19E4][2022-10-12T12:01:23]e000: Error 0x80070005: Failed attempt 
to download URL: 
'https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi' to: 
'C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb'
[183C:19E4][2022-10-12T12:01:23]w343: Prompt for source of package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, path: 
C:\Users\Kirill\Downloads\core_pdb.msi
[183C:19E4][2022-10-12T12:01:26]i338: Acquiring package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, download from: 
https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi
[183C:19E4][2022-10-12T12:01:26]e000: Error 0x80070005: Failed attempt 
to download URL: 
'https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi' to: 
'C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb'
[183C:19E4][2022-10-12T12:01:26]w343: Prompt for source of package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, path: 
C:\Users\Kirill\Downloads\core_pdb.msi
[183C:19E4][2022-10-12T12:01:29]i338: Acquiring package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, download from: 
https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi
[183C:19E4][2022-10-12T12:01:29]e000: Error 0x80070005: Failed attempt 
to download URL: 
'https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi' to: 
'C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb'
[183C:19E4][2022-10-12T12:01:29]w343: Prompt for source of package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, path: 
C:\Users\Kirill\Downloads\core_pdb.msi
[183C:19E4][2022-10-12T12:01:32]i338: Acquiring package: 
core_AllUsers_pdb, payload: core_AllUsers_pdb, download from: 
https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi
[183C:19E4][2022-10-12T12:01:32]e000: Error 0x80070005: Failed attempt 
to download URL: 
'https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi' to: 
'C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb'
[183C:19E4][2022-10-12T12:01:32]e000: Error 0x80070005: Failed to 
acquire payload from: 
'https://www.python.org/ftp/python/3.10.8/amd64/core_pdb.msi' to working 
path: 
'C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb'
[183C:19E4][2022-10-12T12:01:32]e313: Failed to acquire payload: 
core_AllUsers_pdb to working path: 
C:\Users\Kirill\AppData\Local\Temp\{93FCA30B-7B82-4BF0-B911-5223F0E6A053}\core_AllUsers_pdb, 
error: 0x80070005.
[08CC:3570][2022-10-12T12:01:32]i351: Removing cached package: 
core_AllUsers, from path: C:\ProgramData\Package 
Cache\{6463E43B-54B1-4407-818D-DD90D11CDD06}v3.10.8150.0\
[183C:313C][2022-10-12T12:01:32]e000: Error 0x80070005: Cache thread 
exited unexpectedly.


 end here  part of installer log file 
---



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


Re: Find the path of a shell command

2022-10-12 Thread jkn
On Wednesday, October 12, 2022 at 6:12:23 AM UTC+1, jak wrote:
> Il 12/10/2022 06:00, Paulo da Silva ha scritto: 
> > Hi! 
> > 
> > The simple question: How do I find the full path of a shell command 
> > (linux), i.e. how do I obtain the corresponding of, for example, 
> > "type rm" in command line? 
> > 
> > The reason: 
> > I have python program that launches a detached rm. It works pretty well 
> > until it is invoked by cron! I suspect that for cron we need to specify 
> > the full path. 
> > Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
> > What about other commands? 
> > 
> > Thanks for any comments/responses. 
> > Paulo 
> >
> I'm afraid you will have to look for the command in every path listed in 
> the PATH environment variable.

erm, or try 'which rm' ?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot import gdal in jupyter notebook

2022-10-12 Thread Abdul Haseeb Azizi
On Tuesday, October 11, 2022 at 10:29:34 PM UTC+2, MRAB wrote:
> On 2022-10-11 20:38, Thomas Passin wrote: 
> > On Windows, when I tried to install gdal using pip, it needed to compile 
> > part of it. I'm not set up with the Microsoft compiler and header 
> > files, so that failed. If you are on Windows, you will need to look for 
> > a binary wheel to install, or install and configure the compiler and 
> > header files. 
> >
> The PyPI page at https://pypi.org/project/GDAL/ has this: 
> 
> """ 
> Conda 
> GDAL can be quite complex to build and install, particularly on Windows 
> and MacOS. Pre built binaries are provided for the conda system: 
> 
> https://docs.conda.io/en/latest/ 
> 
> By the conda-forge project: 
> 
> https://conda-forge.org/
> """ 
> 
> > On 10/11/2022 11:53 AM, Abdul Haseeb Azizi wrote:
> >> Hi everyone, 
> >> I am new to python and I am trying to utilize this code "from osgeo import 
> >> gdal". I installed python 3.10 and also I installed anaconda3 to solve 
> >> this matter but I could not succeed. When I run that code I get the 
> >> following error. 
> >> ---
> >>  
> >> ModuleNotFoundError Traceback (most recent call last) 
> >> Cell In [1], line 1 
> >> > 1 from osgeo import gdal 
> >> 
> >> ModuleNotFoundError: No module named 'osgeo' 
> >> 
> >> I also tried to create anaconda environment and enter the following codes: 
> >> conda crate --name pygdal 
> >> conda activate pygdal 
> >> conda install -c conda-forge gdal 
> >> 
> >> I don't what is the problem. Any help is appreciated to solve this matter. 
> >> Looking forward to hear from you. 
> >> 
> >> with regards 
> >> Abdul 
> >
Thanks a lot for your recommendations.
As I mentioned before I installed conda and also created conda environment 
using the following codes:
Step 1: Create conda environment

conda create --name venv

After creating the virtual environment, by default it will install some of the 
packages.
Step 2: Installation of gdal

conda install -c conda-forge gdal

Step 3: Installation of ipykernel

conda install -c anaconda ipykernel

Step 4: Add ipykernel and run jupyternotebook

python -m ipykernel install --user --name=venv
jupyter notebook


still I get the following error:

%pip install gdal

Requirement already satisfied: gdal in 
c:\users\abdul\anaconda3\lib\site-packages (3.4.1)
Note: you may need to restart the kernel to use updated packages.

from osgeo import gdal


---
ImportError   Traceback (most recent call last)
File ~\anaconda3\lib\site-packages\osgeo\__init__.py:29, in swig_import_helper()
 28 try:
---> 29 return importlib.import_module(mname)
 30 except ImportError:

File ~\anaconda3\lib\importlib\__init__.py:127, in import_module(name, package)
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)

File :1030, in _gcd_import(name, package, level)

File :1007, in _find_and_load(name, import_)

File :986, in _find_and_load_unlocked(name, 
import_)

File :666, in _load_unlocked(spec)

File :565, in module_from_spec(spec)

File :1173, in create_module(self, spec)

File :228, in _call_with_frames_removed(f, *args, 
**kwds)

ImportError: DLL load failed while importing _gdal: The specified module could 
not be found.

During handling of the above exception, another exception occurred:

ImportError   Traceback (most recent call last)
Input In [1], in ()
> 1 from osgeo import gdal

File ~\anaconda3\lib\site-packages\osgeo\__init__.py:45, in 
 41 raise ImportError(traceback_string + '\n' + msg)
 42 return importlib.import_module('_gdal')
---> 45 _gdal = swig_import_helper()
 46 del swig_import_helper
 48 __version__ = _gdal.__version__ = _gdal.VersionInfo("RELEASE_NAME")

File ~\anaconda3\lib\site-packages\osgeo\__init__.py:41, in swig_import_helper()
 39 import traceback
 40 traceback_string = 
''.join(traceback.format_exception(*sys.exc_info()))
---> 41 raise ImportError(traceback_string + '\n' + msg)
 42 return importlib.import_module('_gdal')

ImportError: Traceback (most recent call last):
  File "C:\Users\abdul\anaconda3\lib\site-packages\osgeo\__init__.py", line 29, 
in swig_import_helper
return importlib.import_module(mname)
  File "C:\Users\abdul\anaconda3\lib\importlib\__init__.py", line 127, in 
import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1030, in _gcd_import
  File "", line 1007, in _find_and_load
  File "", line 986, in _find_and_load_unlocked
  File "", line 666, in _load_unlocked
  File "", line 565, in module_from_spec
  File "", line 1173, in create_module
  File "", line 228, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: The specified module could 
not be 

Re: Find the path of a shell command

2022-10-12 Thread jak

Il 12/10/2022 06:00, Paulo da Silva ha scritto:

Hi!

The simple question: How do I find the full path of a shell command 
(linux), i.e. how do I obtain the corresponding of, for example,

"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well 
until it is invoked by cron! I suspect that for cron we need to specify 
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
What about other commands?


Thanks for any comments/responses.
Paulo



I'm afraid you will have to look for the command in every path listed in
the PATH environment variable.

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


Find the path of a shell command

2022-10-12 Thread Paulo da Silva

Hi!

The simple question: How do I find the full path of a shell command 
(linux), i.e. how do I obtain the corresponding of, for example,

"type rm" in command line?

The reason:
I have python program that launches a detached rm. It works pretty well 
until it is invoked by cron! I suspect that for cron we need to specify 
the full path.
Of course I can hardcode /usr/bin/rm. But, is rm always in /usr/bin? 
What about other commands?


Thanks for any comments/responses.
Paulo

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


Re: flattening lists

2022-10-12 Thread Antoon Pardon




Op 11/10/2022 om 21:32 schreef SquidBits _:

Does anyone else think there should be a flatten () function, which just turns 
a multi-dimensional list into a one-dimensional list in the order it's in. e.g.

[[1,2,3],[4,5,6,7],[8,9]] becomes [1,2,3,4,5,6,7,8,9].

I have had to flatten lists quite a few times and it's quite tedious to type 
out. It feels like this should be something built in to python, anyone else 
think this way?


Depending on what you exactly mean by "flatten", it already is easy to 
flatten a list in python:


>>> lst = [[1,2,3],[4,5,6,7],[8,9]]
>>> list(itertools.chain.from_iterable(lst))
[1, 2, 3, 4, 5, 6, 7, 8, 9]

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


[Python-announce] NumPy 1.23.4 released.

2022-10-12 Thread Charles R Harris
Hi All,

On behalf of the NumPy team, I am pleased to announce the release of
NumPy 1.23.4. NumPy 1.23.4 is a maintenance release that fixes bugs
discovered after the 1.23.3 release and keeps the build infrastructure
current. The main improvements are fixes for some annotation corner cases,
a fix for a long time *nested_iters* memory leak, and a fix of complex
vector dot for very large arrays. The Python versions supported for this
release are 3.8-3.11. Wheels can be downloaded from PyPI
; source archives, release notes,
and wheel hashes are available on Github
.

Note that the mypy version needs to be 0.981+ if you test using Python
3.10.7, otherwise the typing tests will fail.


*Contributors*

A total of 8 people contributed to this release.  People with a "+" by their
names contributed a patch for the first time.

   - Bas van Beek
   - Charles Harris
   - Matthew Barber
   - Matti Picus
   - Ralf Gommers
   - Ross Barnowski
   - Sebastian Berg
   - Sicheng Zeng +



*Pull requests merged*
A total of 13 pull requests were merged for this release.

   - #22368: BUG: Add ``__array_api_version__`` to ``numpy.array_api``
   namespace
   - #22370: MAINT: update sde toolkit to 9.0, fix download link
   - #22382: BLD: use macos-11 image on azure, macos-1015 is deprecated
   - #22383: MAINT: random: remove ``get_info`` from "extending with
   Cython"...
   - #22384: BUG: Fix complex vector dot with more than NPY_CBLAS_CHUNK
   elements
   - #22387: REV: Loosen ``lookfor``'s import try/except again
   - #22388: TYP,ENH: Mark ``numpy.typing`` protocols as runtime checkable
   - #22389: TYP,MAINT: Change more overloads to play nice with pyright
   - #22390: TST,TYP: Bump mypy to 0.981
   - #22391: DOC: Update delimiter param description.
   - #22392: BUG: Memory leaks in numpy.nested_iters
   - #22413: REL: Prepare for the NumPy 1.23.4 release.
   - #22424: TST: Fix failing aarch64 wheel builds.

Cheers,

Charles Harris
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com


[Python-announce] PyCA cryptography 38.0.2 yanked

2022-10-12 Thread Alex Gaynor
Yesterday, PyCA cryptography 38.0.2 was released to PyPI. Today, we
yanked the release from PyPI due to regressions in OpenSSL that led
the OpenSSL team  to withdraw OpenSSL 3.0.6 (which PyCA cryptography's
wheels include). We expect to issue a follow up release once the
OpenSSL team has released OpenSSL 3.0.7.

cryptography includes both high level recipes and low level interfaces
to common cryptographic algorithms such as symmetric ciphers,
asymmetric algorithms, message digests, X509, key derivation
functions, and much more. We support Python 3.6+, and PyPy3.

Alex
-- 
All that is necessary for evil to succeed is for good people to do nothing.
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com