Re: CLI parsing—with `--help` text—`--foo bar`, how to give additional parameters to `bar`?

2020-10-16 Thread Mats Wichmann
On 10/15/20 5:09 PM, Samuel Marks wrote:
> Yes it’s my module, and I’ve been using argparse
> https://github.com/SamuelMarks/ml-params
> 
> No library I’ve found provides a solution to CLI argument parsing for my
> use-case.
> 
> So I’ll write one. But what should it look like, syntactically and
> semantically?

Jumping back to an earlier point in the thread...

There are an astonishing number of "argument parsers" for the Python
universe, but if none of them do what you want it's certainly not
illegal to write your own.  Reinventing the wheel is ok if existing
wheels don't work right on your vehicle - but do take the time check.
getopt, optparse, and argparse from the standard library have all
adopted some of the relatively well specified POSIX argument syntax.
Python has a heritage in the POSIX-y world, but not all systems
(Windows!) follow that model anyway. All have some quirks (I find
optparse and argparse irritating for some of the choices they've made).

If you haven't seen it, Dan Bader and his crew at the excellent
RealPython have a comparsion of some of them:

https://realpython.com/comparing-python-command-line-parsing-libraries-argparse-docopt-click

The thing is, if your situation is that you've looked at existing
implementations and don't like them, then it's hard to ask us here as a
group what a replacement should look like - by not liking what you've
seen you must have some model in your mind of what would look more sane
that you're comparing against, and we can't mind-read!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Cameron Simpson
On 16Oct2020 22:07, Albert-Jan Roskam  wrote:
>   I was using datetime.now().isoformat('T', 'seconds')
>   Not 100% sure, but the strings seemed to be 2hrs off. Could it be that
>   this Linux server was using the wrong time zone?

Maybe. This is why timezones are such a nightmare, and programmes 
working with datetime as their primary structure are fragile (hmm, is 
this _naive_ (untimezoned) datetime in local time? What _is_ local time? Was 
the naive datetime obtained correctly?  etc).

Hence the common recommendation to work in seconds since an epoch (on 
UNIX that epoch is midnight 01 January 1970 GMT). Then timezones are 
just when presenting to a human.

But also, on UNIX and UNIX-like (Linux) the timezone is an aspect of 
your environment; setting the $TZ environment various suitably will 
display times according to your preference.  The system default for when 
$TZ is not set is usually in the /etc/timezone file, but you can set $TZ 
for yourself and have your own localtimes generally displayed.

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


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread sjeik_appie
   On 16 Oct 2020 12:50, Eryk Sun  wrote:

 On 10/16/20, Steve  wrote:
 > -Original Message-
 > From: Python-list 
 On
 > Behalf Of Frank Millman
 > Sent: Friday, October 16, 2020 4:34 AM
 > To: python-list@python.org
 > Subject: Re: How do I get datetime to stop showing seconds?
 >
 > On 2020-10-16 9:42 AM, Steve wrote:
 >> d2 =  datetime.datetime.now() #Time Right now
 >> 

   I was using datetime.now().isoformat('T', 'seconds')
   Not 100% sure, but the strings seemed to be 2hrs off. Could it be that
   this Linux server was using the wrong time zone?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Cousin Stanley
Steve wrote:

> d2 =  datetime.datetime.now() #Time Right now
> 
> Show this: 2020-10-16 02:53
> and not this: 2020-10-16 02:53:48.585865
> 
> 
> ==
> Footnote:
> If you double major in psychology and reverse psychology, to they cancel
> each other out?
> 
> --

py> 
py> import datetime as dt
py> 
py> d = dt.datetime.now().strftime( '%Y-%m-%d  %H:%M' )
py> 
py> print( '\n  ' , d )

   2020-10-16  07:22


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Eryk Sun
On 10/16/20, Steve  wrote:
> -Original Message-
> From: Python-list  On
> Behalf Of Frank Millman
> Sent: Friday, October 16, 2020 4:34 AM
> To: python-list@python.org
> Subject: Re: How do I get datetime to stop showing seconds?
>
> On 2020-10-16 9:42 AM, Steve wrote:
>> d2 =  datetime.datetime.now() #Time Right now
>>
>> Show this: 2020-10-16 02:53
>> and not this: 2020-10-16 02:53:48.585865
>
>  >>>
>  >>> str(d2)
> '2020-10-16 10:29:38.423371'
>  >>>
>  >>> d2.strftime('%Y-%m-%d %H:%M')
> '2020-10-16 10:29'

datetime also supports the __format__ protocol [1]. For example:

>>> d2 = datetime(2020, 10, 16, 10, 29, 38, 423371)

>>> format(d2, '%Y-%m-%d %H:%M')
'2020-10-16 10:29'

>>> f'{d2:%Y-%m-%d %H:%M}'
'2020-10-16 10:29'

[1] https://docs.python.org/3/library/datetime.html#datetime.datetime.__format__
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: How do I get datetime to stop showing seconds?

2020-10-16 Thread Steve
Right on target, 
Many Thanks


FootNote:
If money does not grow on trees, then why do banks have branches?

-Original Message-
From: Python-list  On
Behalf Of Frank Millman
Sent: Friday, October 16, 2020 4:34 AM
To: python-list@python.org
Subject: Re: How do I get datetime to stop showing seconds?

On 2020-10-16 9:42 AM, Steve wrote:
> d2 =  datetime.datetime.now() #Time Right now
> 
> Show this: 2020-10-16 02:53
> and not this: 2020-10-16 02:53:48.585865
> 

 >>>
 >>> str(d2)
'2020-10-16 10:29:38.423371'
 >>>
 >>> d2.strftime('%Y-%m-%d %H:%M')
'2020-10-16 10:29'
 >>>


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

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


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Marco Sulla
Another way is:

'{:%Y-%m-%d %H:%M}'.format(d2)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I get datetime to stop showing seconds?

2020-10-16 Thread Frank Millman

On 2020-10-16 9:42 AM, Steve wrote:

d2 =  datetime.datetime.now() #Time Right now

Show this: 2020-10-16 02:53
and not this: 2020-10-16 02:53:48.585865



>>>
>>> str(d2)
'2020-10-16 10:29:38.423371'
>>>
>>> d2.strftime('%Y-%m-%d %H:%M')
'2020-10-16 10:29'
>>>


Frank Millman

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


Re: CLI parsing—with `--help` text—`--foo bar`, how to give additional parameters to `bar`?

2020-10-16 Thread Samuel Marks
Yeah, but the risk with config files is you need a website—and/or full JSON
schema output—to figure out what’s needed.

(Although I should mention that with my doctrans project you can generate a
config class—and class method—from/to your argparse parser; enabling the
config file scenario rather cleanly)

Also there is a project which takes your CLI and turns it into a GUI
(Gooey).

At some future point doctrans will be “complete”, and then you can provide
inputs via:
- CLI arguments
- Config file
- RPC*
- REST*

*TODO, will also optionally generate ORM classes for persistence

On Fri, 16 Oct 2020 at 6:08 pm, Karen Shaeffer 
wrote:

> Passing a lot of command line parameters is very error prone. Opening a
> file and specifying flags is much more user friendly, because you have any
> necessary help documented right there. In my eyes, the command line is only
> useful for simple scripts.
>
> Karen
>
> > On Oct 15, 2020, at 11:44 PM, Karen Shaeffer 
> wrote:
> >
> > In my work, for complex ML modeling code, I never pass anything through
> the command line. I implement absl.flags in each module, specifying all the
> defaults. At runtime I instantiate the flags as  class variables of a
> ModelConfiguration class that gets passed into the model class. Absl
> supports all I need for this scheme. Of course, for a package, I can have a
> configuration module for all these configuration classes.
> >
> > This scheme is easy to maintain. It can be dynamically customized at run
> time. It’s very easy to document and maintain and to use. In one project, I
> even supported console inputs that dynamically managed configurations of
> pipelines. Nothing was ever passed in on command lines. I wonder why you
> need to play on the command line.
> >
> > And yea, I’ve written a command line parsing function in C a long time
> ago. I thought that really cool at the time. I wouldn’t want to do it now.
> >
> > Karen.
> >
> >> On Oct 15, 2020, at 9:58 PM, Samuel Marks 
> wrote:
> >>
> >> Yeah I've played with custom actions before
> >>
> https://github.com/offscale/argparse-utils/tree/master/argparse_utils/actions
> >>
> >> But this would only help in one phase, the important phase of
> >> providing help text will need to be provided out-of-argparse and
> >> thrown in
> >>
> >> (like my trivial absl alternative, exposing a function which takes an
> >> argparse instance and returns an argparse instance)
> >>
> >> The only hack remaining is that I have to pass through `sys.argv` at
> >> least once before giving it to argparse. I wonder if there's a way to
> >> not need to explicitly go through it at all…
> >>
> https://github.com/SamuelMarks/ml-params/blob/d1fb184/ml_params/__main__.py#L89
> >>
> >> [I didn't know `getopt` was exposed otherwise I'd use that  >> sometimes do in C>, but there has to be a solution just using
> >> argparse?]
> >>
> >> Samuel Marks
> >> Charity  | consultancy
> >>  | open-source  |
> >> LinkedIn 
> >>
> >>
> >> Samuel Marks
> >> Charity | consultancy | open-source | LinkedIn
> >>
> >>
> >> On Fri, Oct 16, 2020 at 3:47 PM Dieter Maurer 
> wrote:
> >>>
> >>> Samuel Marks wrote at 2020-10-16 10:09 +1100:
>  Yes it’s my module, and I’ve been using argparse
>  https://github.com/SamuelMarks/ml-params
> 
>  No library I’ve found provides a solution to CLI argument parsing for
> my
>  use-case.
> >>>
> >>> Do you know that with `argparse` you can specify how many arguments an
> option
> >>> expects? Thus, it should be quite easily possible to
> >>> have --opt   ...
> >>> Do you know that you can define new `Action`s for `argparse`?
> >>> This way, you could properly process `--opt ,, ...`.
> >> --
> >> https://mail.python.org/mailman/listinfo/python-list
> >
>
> --
Samuel Marks
Charity  | consultancy
 | open-source
 | LinkedIn <
https://linkedin.com/in/samuelmarks>
-- 
https://mail.python.org/mailman/listinfo/python-list


How do I get datetime to stop showing seconds?

2020-10-16 Thread Steve
d2 =  datetime.datetime.now() #Time Right now

Show this: 2020-10-16 02:53
and not this: 2020-10-16 02:53:48.585865


==
Footnote:
If you double major in psychology and reverse psychology, to they cancel
each other out?

-- 

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