Re: Current thinking on required options

2021-04-19 Thread Bill Campbell
On Mon, Apr 19, 2021, Loris Bennett wrote:
>Hi,
>
>I have various small programs which tend to have an interface like the
>following example:
>
>  usage: grocli [-h] [-o {check,add,delete}] [-u USERS [USERS ...]] [-g GROUP]

I would do this with the action is first argument.

Usage: grocli check|add|delete [-u USERS ...]

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ 6641 E. Mercer Way
Mobile: (206) 947-5591  PO Box 820
Fax:(206) 232-9186  Mercer Island, WA 98040-0820

Force always attracts men of low morality.  -- Albert Einstein
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to remove "" from starting of a string if provided by the user

2020-08-11 Thread Bill Campbell
On Tue, Aug 11, 2020, Ganesh Pal wrote:
>The possible value of stat['server2'] can be either (a)
>"'/fileno_100.txt'" or (b) '/fileno_100.txt' .

def stripquotes(s):
'''Strip leading single or double quotes to any depth'''
import re
pat = re.compile(r'^([\'"])(.*)(\1)$')
slast = None
while slast != s:
slast = s
s = pat.cub(r'\2', s)
return s
# end stripquotes(s)

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ 6641 E. Mercer Way
Mobile: (206) 947-5591  PO Box 820
Fax:(206) 232-9186  Mercer Island, WA 98040-0820

Democracy is the theory that the common people know what they
want and deserve to get it good and hard. == H.L. Mencken
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Missing python curses functions?

2020-05-19 Thread Bill Campbell
On Tue, May 19, 2020, Alan Gauld via Python-list wrote:
>During my Covid19 lock-down I thought I'd spend my time translating
>the "Linux Curses Programming HOWTO" document into Pythonic curses.
>
>One of the functions discussed that does not appear to have
>a Python equivalent is attr_get() which gets the current
>attributes.

I haven't looked for it.

...
>Is anyone other than me still even using Python curses? :-)

Raises hand.

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ 6641 E. Mercer Way
Mobile: (206) 947-5591  PO Box 820
Fax:(206) 232-9186  Mercer Island, WA 98040-0820

Democracy Is Mob Rule with Income Taxes
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: OT: ALGOL 60 at 60

2020-05-16 Thread Bill Campbell
On Sun, May 17, 2020, DL Neil via Python-list wrote:
>ALGOL 60 at 60: The greatest computer language you've never used and
>grandaddy of the programming family tree
>Back to the time when tape was king
>By Richard Speed 15 May 2020 at 09:47
>https://www.theregister.co.uk/2020/05/15/algol_60_at_60/

Boy does that bring back some memories :-).

ALGOL was the third programming language I learned after FORTRAN
and Assembly on the Bendix G-20 in early 1966.

I first learned ALGOL on G.E. time sharing, where input was paper
tape, although it didn't require loading the compilers from tape
so I never hat that pleasure.  I loved the block structure of ALGOL,
and started indenting FORTRAN so that the program logic stood out
even if FORTRAN didn't understand it.

...
>ALGOL was almost 'the machine language' for the Burroughs B6700 series (and
>similar) but concurring with the article, we regarded it as somewhat academic
>and majored in FORTRAN, COBOL, or both. (as distinct from those who defined
>ComSc as compiler writing, for whom ALGOL was a brilliant tool!)

I really got into ALGOL on a time sharing system using the
Burroughs B-5500 where ALGOL was the system's native language,
there was no Assembly Language per-se.  The OS MCP, (Master
Control Progam) was written entirely in ALGOL.  The FORTRAN
compiler generated ALGOL source, and I learned a lot looking at
the ALGOL output of the FORTRAN program.

Many of the programming methods I use today have their roots in
doing a lot of scientific programming in ALGOL on the B-5500,
then in BPL (Burroughs Programming Language) on Burroughs Medium
Systems, B-2500->B-4500.

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ 6641 E. Mercer Way
Mobile: (206) 947-5591  PO Box 820
Fax:(206) 232-9186  Mercer Island, WA 98040-0820

In free governments the rulers are the servants, and the people their
superiors & sovereigns." -- Benjamin Franklin
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Vim settings for Python (was: tab replace to space 4)

2019-12-07 Thread Bill Campbell
On Sat, Dec 07, 2019, Peter J. Holzer wrote:

>As an aside, to prevent vim from inserting tabs in the first place, set
>expandtab
>sw=4
>and maybe also
>ts=4

Inserting a comment in the file like this makes thing easy.

# vim: expandtab sw=4 ts=4 nows wm=0

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ 6641 E. Mercer Way
Mobile: (206) 947-5591  PO Box 820
Fax:(206) 232-9186  Mercer Island, WA 98040-0820

Political language... is designed to make lies sound truthful and
murder respectable, and to give an appearance of solidity to pure
wind. -- George Orwell
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Convert Windows paths to Linux style paths

2019-03-12 Thread Bill Campbell
On Tue, Mar 12, 2019, Malcolm Greene wrote:

>Looking for best practice technique for converting Windows style paths to
>Linux paths. Is there an os function or pathlib method that I'm missing or
>is it some combination of replacing Windows path separators with Linux path
>separators plus some other platform specific logic?

See os.path.join

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ 6641 E. Mercer Way
Mobile: (206) 947-5591  PO Box 820
Fax:(206) 232-9186  Mercer Island, WA 98040-0820

The very concept of objective truth is fading out of the world.  Lies will
pass into history.  -- George Orwell
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: preferences file

2019-01-27 Thread Bill Campbell
On Thu, Jan 24, 2019, Dave wrote:
>I'm doing a small application and want to add user preferences.  Did some
>googling to see if there are standard Python ways/tools, but it seems not so
>much.  My specific questions are:
>
>1. Best practices for a user preference file/system?

Generally I put them in the user's $HOME or $HOME/etc directory
with appropriate permissions unless working in a virtual
environement.
>2. File format favored and why - ini, JSON, etc?

I like ini for most user configuration files as the format is
simple, easy to read, and handled nicely with the ConfigParser
libraries.

>3. File location?  I'm using Ubuntu and I believe that the correct location
>would be home/.config/ .  What about Mac and Windows?

See above.  Same for Mac.  I don't do Windows.

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ 6641 E. Mercer Way
Mobile: (206) 947-5591  PO Box 820
Fax:(206) 232-9186  Mercer Island, WA 98040-0820

The budget should be balanced, the Treasury should be refilled, public
debt should be reduced, the arrogance of officialdom should be
tempered and controlled, and the assistance to foreign lands should be
curtailed lest Rome become bankrupt. People must again learn to work,
instead of living on public assistance. -- Cicero - 55 BC
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Unable to get the gateway IP of wlan interface using python code

2018-11-12 Thread Bill Campbell
On Tue, Nov 13, 2018, srinivasan wrote:
>Dear Python Experts,
>
>*First method:*
>
>I need to get the IP address basically the gateway IP in my setup I get it
>as "192.168.178.1" when I run the below standalone python code.
>
>
>*def get_gateway_ip(self):*
>*"""*
>*Get the IP address to the WIFI module from the AP*
>*"""*
>
>*cmd = 'ip route show 0.0.0.0/0 <http://0.0.0.0/0> dev wlp1s0 | cut
>-d\  -f3'*
>*f = os.popen(cmd)*
>*return str(f.read().strip())*

This command should get the gateway IP.

Linux: cmd = "ip route list | awk '/^default/{print $3}'"

or perhaps

Linux: cmd = "netstat -rn | awk '/^0.0.0.0/{print $2}'"

OSX: cmd = "netstat -rn | awk '/^default/{print $2}'"

I don't have a freebsd system available to test this, but I think
this pattern should work:

re.compile(r'^(default|0\.0\.0\.0)\s+(\S+)')

Bill
-- 
INTERNET:   b...@celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www2.celestial.com/ PO Box 820; 6641 E. Mercer Way
Mobile: (206) 947-5591  Mercer Island, WA 98040-0820
Fax:(206) 232-9186  Skype: jwccsllc

On the free market, everyone earns according to his productive
value in satisfying consumer desires. Under statist distribution,
everyone earns in proportion to the amount he can plunder from
the producers. -- Murray N. Rothbard
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] Spaces and tabs messing up code

2008-01-08 Thread Bill Campbell
On Tue, Jan 08, 2008, [EMAIL PROTECTED] wrote:

   my friend uses vim

   and i use xemacs

   so our shared python code is a mix of tabs and spaces and it is hard
   for him to edit it in vim

   any idea on how to make it clean

   convert it all to 4 spaces?

Do that, and in his ~/.vimrc file, add a line ``set expandtab''

(Friends don't let friends use emacs :-).

Bill
--
INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 236-1676

Giving money and power to government is like giving whiskey and car keys to
teenage boys -- P.J. O'Rourke
-- 
http://mail.python.org/mailman/listinfo/python-list