Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-21 Thread Thomas Passin

On 1/21/2023 10:11 PM, Jach Feng wrote:

Fail on command line,

e:\Works\Python>py infix2postfix.py "-4^2+5.3*abs(-2-1)/2"
usage: infix2postfix.py [-h] [infix]
infix2postfix.py: error: unrecognized arguments: -4^2+5.3*abs(-2-1)/2

Also fail in REPL,

e:\Works\Python>py
Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import argparse
parser = argparse.ArgumentParser(description='Convert infix notation to 
postfix')
parser.parse_args("-4^2+5.3*abs(-2-1)/2")

usage: [-h]
: error: unrecognized arguments: - 4 ^ 2 + 5 . 3 * a b s ( - 2 - 1 ) / 2

Just can't figure out where is wrong!?


It just doesn't work like that.  If you download the package, there is 
only one python file, __init__.py.  This file contains one class.  It 
has a demo at the end, commented out.  If you uncomment those lines and 
run the file, you get a result printed.


These remarks are based on downloading the link for the source 
distribution from Pypi
(https://pypi.org/project/infix2postfix/).  When I installed it with 
pip, nothing seems to have gotten installed although pip went through 
the motions and claimed it was. So I just downloaded the source package.


The test expression is "-(a*b)+(c+d)-(a+b+c+d)".  The test output for 
this is "ab*-cd++ab+c+d+-".


If you substitute your expression, the result is

abs1-2-*2/3.5+2^4-

This may or may not be correct. I'm not sure but I think it's as 
intended except for reversing "3.5".  But maybe that's right, I'm not 
too sure.   Notice that this file is in its first release, version 0.0.1 
- the metadata that says it's 'Development Status :: 5 - 
Production/Stable' seems to be bogus.  So it may very well be buggy.


At any rate, if you want to use it in a program that can accept 
arguments, you will have to write that part yourself.  And the 
expression you feed it would need to be a single string, meaning it has 
to be quoted on the command line as you have done (although on Windows 
you should be using double quotes instead of single quotes).


As for argparse, it isn't doing what you want because you haven't told 
it what to do with the arguments.

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


How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-21 Thread Jach Feng
Fail on command line,

e:\Works\Python>py infix2postfix.py "-4^2+5.3*abs(-2-1)/2"
usage: infix2postfix.py [-h] [infix]
infix2postfix.py: error: unrecognized arguments: -4^2+5.3*abs(-2-1)/2

Also fail in REPL,

e:\Works\Python>py
Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import argparse
>>> parser = argparse.ArgumentParser(description='Convert infix notation to 
>>> postfix')
>>> parser.parse_args("-4^2+5.3*abs(-2-1)/2")
usage: [-h]
: error: unrecognized arguments: - 4 ^ 2 + 5 . 3 * a b s ( - 2 - 1 ) / 2

Just can't figure out where is wrong!?

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


Re: PEP-8, Line Length, And All That

2023-01-21 Thread Cameron Simpson

On 21Jan2023 01:32, Thomas Passin  wrote:
In another thread ("Improvement to imports, what is a better way ?") 
there was a lot of talk about line length, PEP-8, etc.  I realized 
that one subject did not really come up, yet it can greatly affect the 
things we were talking about.


I'm referring to the design of the functions, methods, and classes. 
When they are well designed, or more likely, refactored over and over 
again, they can lead to code that reads almost like pseudo-code.  [...]


Yeah. Personally, I summarise this as the maxim: "ergonomics matter".  
Code should be easy to use and easy to read.


I've got a heap of code I've refactored after the initial implementation 
to make it easy to use, if only to make it easier for _me_ to use to do 
more things with it.


I've also got decorators and context managers and special classes all 
aimed at making all the things easier to use and easier to _write_ 
(because some decorators (a) provide flexibility for the caller - easier 
to use and (b) implement standard boilerplate logic for common types of 
parameters, making the function/method implementation easier to write.)


And increasingly I've got docstrings with _example_ code which doubles 
as a doctest. Making it easier to understand how to easily use this 
thing.


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


Re: tree representation of Python data

2023-01-21 Thread Dino


you rock. Thank you, Stefan.

Dino

On 1/21/2023 2:41 PM, Stefan Ram wrote:

r...@zedat.fu-berlin.de (Stefan Ram) writes:

def display_( object, last ):
directory = object; result = ''; count = len( directory )
for entry in directory:
count -= 1; name = entry; indent = ''
for c in last[ 1: ]: indent += '│   ' if c else ''
indent += '├──' if count else '└──' if last else ''
result += '\n' + indent +( ' ' if indent else '' )+ name
if directory[ entry ]:
result += display_( directory[ entry ], last +[ count ])
return result


   This ultimate version has some variable names made more speaking:

def display_( directory, container_counts ):
 result = ''; count = len( directory )
 for name in directory:
 count -= 1; indent = ''
 for container_count in container_counts[ 1: ]:
 indent += '│   ' if container_count else ''
 indent += '├──' if count else '└──' if container_counts else ''
 result += '\n' + indent +( ' ' if indent else '' )+ name
 if directory[ name ]:
 result += display_\
 ( directory[ name ], container_counts +[ count ])
 return result




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


I could not install pygame no matter what

2023-01-21 Thread Robbie mezazem
70916814/error-metadata-generation-failed-cant-install-artic-module

Sent from Mail for Windows

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


Re: tree representation of Python data

2023-01-21 Thread Weatherby,Gerard
https://docs.python.org/3/library/pprint.html

From: Python-list  on 
behalf of Dino 
Date: Saturday, January 21, 2023 at 11:42 AM
To: python-list@python.org 
Subject: tree representation of Python data
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

I have a question that is a bit of a shot in the dark. I have this nice
bash utility installed:

$ tree -d unit/
unit/
├── mocks
├── plugins
│   ├── ast
│   ├── editor
│   ├── editor-autosuggest
│   ├── editor-metadata
│   ├── json-schema-validator
│   │   └── test-documents
│   └── validate-semantic
│   ├── 2and3
│   ├── bugs
│   └── oas3
└── standalone
 └── topbar-insert

I just thought that it would be great if there was a Python utility that
visualized a similar graph for nested data structures.
Of course I am aware of indent (json.dumps()) and pprint, and they are
OK options for my need. It's just that the compact, improved
visualization would be nice to have. Not so nice that I would go out of
my way to build, but nice enough to use an exising package.

Thanks

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


Re: ok, I feel stupid, but there must be a better way than this! (finding name of unique key in dict)

2023-01-21 Thread Dino



I learned new things today and I thank you all for your responses.

Please consider yourself thanked individually.

Dino

On 1/20/2023 10:29 AM, Dino wrote:


let's say I have this list of nested dicts:


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


tree representation of Python data

2023-01-21 Thread Dino


I have a question that is a bit of a shot in the dark. I have this nice 
bash utility installed:


$ tree -d unit/
unit/
├── mocks
├── plugins
│   ├── ast
│   ├── editor
│   ├── editor-autosuggest
│   ├── editor-metadata
│   ├── json-schema-validator
│   │   └── test-documents
│   └── validate-semantic
│   ├── 2and3
│   ├── bugs
│   └── oas3
└── standalone
└── topbar-insert

I just thought that it would be great if there was a Python utility that 
visualized a similar graph for nested data structures.
Of course I am aware of indent (json.dumps()) and pprint, and they are 
OK options for my need. It's just that the compact, improved 
visualization would be nice to have. Not so nice that I would go out of 
my way to build, but nice enough to use an exising package.


Thanks

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