Re: Serializing pydantic enums
Most Python objects aren't serializable into JSON. Pydantic isn't special in this sense. What can you do about this? -- Well, if this is a one-of situation, then, maybe just do it by hand? If this is a recurring problem: json.dumps() takes a cls argument that will be used to do the serialization. Extend json.JSONEncoder and implement the encode() method for the encoder class you are passing. I believe that the official docs have some information about this too. On Tue, May 28, 2024 at 2:50 PM Larry Martell via Python-list wrote: > > Just getting started with pydantic. I have this example code: > > class FinishReason(Enum): > stop = 'stop' > > class Choice(BaseModel): > finish_reason: FinishReason = Field(...) > > > But I cannot serialize this: > > json.dumps(Choice(finish_reason=FinishReason.stop).dict()) > *** TypeError: Object of type FinishReason is not JSON serializable > > > I get the object not the value: > > (Pdb) Choice(finish_reason=FinishReason.stop) > Choice(finish_reason=) > > > Also tried it with .value, same result. > > What am I missing here? > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Serializing pydantic enums
Just getting started with pydantic. I have this example code: class FinishReason(Enum): stop = 'stop' class Choice(BaseModel): finish_reason: FinishReason = Field(...) But I cannot serialize this: json.dumps(Choice(finish_reason=FinishReason.stop).dict()) *** TypeError: Object of type FinishReason is not JSON serializable I get the object not the value: (Pdb) Choice(finish_reason=FinishReason.stop) Choice(finish_reason=) Also tried it with .value, same result. What am I missing here? -- https://mail.python.org/mailman/listinfo/python-list
Re: Weird Stuff (Markdown, syntax highlighting and Python)
On 5/26/2024 2:28 AM, Gilmeh Serda via Python-list wrote: The web claims (I think on all pages I've read about Markdown and Python) that this code should work, with some very minor variants on the topic: ```python import os with open(os.path.join('/home/user/apath', 'somefile')) as f: print(f.read()) ``` There are different flavors of Markdown, so that might be a factor so far as details of the block are concerned. What do you mean by it not "working"? What do you see and what did you expect to see? What did you see different when you used the next example? How did you generate the output HTML file? However, that is not the case. At least not for me (using Python 3.12.3). If instead I type it: #!python import os with open(os.path.join('/home/user/apath', 'somefile')) as f: print(f.read()) As an indented block (four spaces) and a shebang, THEN it works. You even get line numbers by default. N.b. if you don't know, you also need to generate a css file using pygments to make this work. Not until I started to read the markdown source code and its docs pages, the coin dropped. I'm posting this for other Markdown newbies that otherwise probably would spend hours trying to make it work. Speaking of Markdown. Does anybody out there have any idea how to turn on table borders, adjust them (color/width/etc.) and such things? Currently I have to add HTML to do so, which works, but isn't very nice. I'd hate to spend an additional day or two, hunting for this info. References: https://pypi.org/project/Markdown/ https://python-markdown.github.io/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Any marginally usable programming language approaches an ill defined barely usable re-implementation of half of Common-Lisp
On 2024-05-27 at 12:37:01 -0700, HenHanna via Python-list wrote: > > On 5/27/2024 7:18 AM, Cor wrote: > > Some entity, AKA "B. Pym" , > > wrote this mindboggling stuff: > > (selectively-snipped-or-not-p) > > > > > On 12/16/2023, c...@clsnet.nl wrote: > > > > > > > Any marginally usable programming language approaches an ill > > > > defined barely usable re-implementation of half of common-lisp > > > > > > The good news is, it's not Lisp that sucks, but Common Lisp. > > > --- Paul Graham > > > > Just to set the record straight; > > This is not My line. > > I quoted it but don't know who the originator of that remark is. https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule -- https://mail.python.org/mailman/listinfo/python-list
Re: Weird Stuff (Markdown, syntax highlighting and Python)
With reference to another reply here, the "Weird stuff" came from reading the question, finding it unclear, and only later realising that whereas most people write Markdown-formatted documents for later processing, or perhaps docstrings in Markdown-format for collection by documentation systems; here, the objective appears to be using Python to generate Markdown. How much have you used Markdown to any serious degree, before attempting this feat? On 26/05/24 18:28, Gilmeh Serda via Python-list wrote: The web claims (I think on all pages I've read about Markdown and Python) that this code should work, with some very minor variants on the topic: There are so many "variants", the problem is not "minor"! Markdown users learn to use their tool (again, see @Grant's question) and work within the implementation of that "variant". Like any other non-standardised tool, the users of some particular 'version' often fail to realise that others using different versions may not enjoy the same experience. Plus-one for standardisation! At the end of the message, the web.refs reveal use of a package which is based upon a variant of Markdown that is 20-years old(!), albeit with some updates to suit yet another variant. Neither variant-author famous for collaboration. The phrase YMMV springs to mind... Some ten years ago, an effort was made to standardise Markup, and it ended-up being called CommonMark. Why is it not called "Standard Markdown" one might ask? Because the fellow who 'invented' Markdown objected. This very objection has likely led directly to your confusions, because the particular PyPi package is based upon that original definition... Whereas, Markdown 3.6 is the most-recently updated Markdown search-hit on PyPi today, have you tried any of the others (which, ironically, may offer more recent and/or more standardised coverage)? This has worked in all of the Markdown processors I have used or tried-out: The (?reasonable) 'common-core', offers single back-ticks for code, triple back-ticks for a code-block, and the latter with or without a language specification which *usually* kicks-in syntax highlighting. ```python import os with open(os.path.join('/home/user/apath', 'somefile')) as f: print(f.read()) ``` However, that is not the case. At least not for me (using Python 3.12.3). It's not Python 3 that is the problem. It is the "Markdown 3.6" package! If instead I type it: I've not seen the hash-bang combination in-the-wild (but YMMV!) #!python import os with open(os.path.join('/home/user/apath', 'somefile')) as f: print(f.read()) As an indented block (four spaces) and a shebang, THEN it works. You even get line numbers by default. An indented-block is NOT necessarily the same as a code-block - just as "code" is not necessarily "Python". Line numbers are great - although if a code snippet is extracted from the middle of some example code-file, the original line-numbers won't line-up with Markdown's... N.b. if you don't know, you also need to generate a css file using pygments to make this work. That's not what the package's docs suggest: https://python-markdown.github.io/extensions/fenced_code_blocks/ Not until I started to read the markdown source code and its docs pages, the coin dropped. I'm posting this for other Markdown newbies that otherwise probably would spend hours trying to make it work. Speaking of Markdown. Does anybody out there have any idea how to turn on table borders, adjust them (color/width/etc.) and such things? Currently I have to add HTML to do so, which works, but isn't very nice. I'd hate to spend an additional day or two, hunting for this info. Again, heavily dependent upon the tool in-use. For example, most SSGs and doc-tools (which accept Markdown) have a .css or theming-system which enables 'decorations'. References: https://pypi.org/project/Markdown/ https://python-markdown.github.io/ Further reading: https://en.wikipedia.org/wiki/Markdown https://commonmark.org https://pypi.org/search/?q=markdown -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list
Any marginally usable programming language approaches an ill defined barely usable re-implementation of half of Common-Lisp
On 5/27/2024 7:18 AM, Cor wrote: Some entity, AKA "B. Pym" , wrote this mindboggling stuff: (selectively-snipped-or-not-p) On 12/16/2023, c...@clsnet.nl wrote: Any marginally usable programming language approaches an ill defined barely usable re-implementation of half of common-lisp The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham Just to set the record straight; This is not My line. I quoted it but don't know who the originator of that remark is. Cor a few years ago... when i started learning Python... it was so exciting... Every day i thought... --- THis is Lisp in a thin-disguise ... SO Everyone gets it now. Everyone is a Lisper now. -- https://mail.python.org/mailman/listinfo/python-list
Re: Weird Stuff (Markdown, syntax highlighting and Python)
On 2024-05-26, Gilmeh Serda via Python-list wrote: > The web claims (I think on all pages I've read about Markdown and Python) > that this code should work, with some very minor variants on the topic: > > ```python > > import os > > with open(os.path.join('/home/user/apath', 'somefile')) as f: > print(f.read()) > ``` > > However, that is not the case. For me, that block formats as expected using Python markdown. What do you mean by "this code should work [...] that is not the case"? What markdown rendering engine are you using? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Can't trap paramiko runtime trace-back error
When running the code below , I get error as enumerated below. Why am I not able to trap this paramiko runtime traceback in try-except block ? Exception (client): Error reading SSH protocol banner Traceback (most recent call last): File "/home/uzi/.local/lib/python3.8/site-packages/paramiko/transport.py", line 2327, in _check_banner buf = self.packetizer.readline(timeout) File "/home/uzi/.local/lib/python3.8/site-packages/paramiko/packet.py", line 381, in readline buf += self._read_timeout(timeout) File "/home/uzi/.local/lib/python3.8/site-packages/paramiko/packet.py", line 626, in _read_timeout raise socket.timeout() socket.timeout During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/uzi/.local/lib/python3.8/site-packages/paramiko/transport.py", line 2143, in run self._check_banner() File "/home/uzi/.local/lib/python3.8/site-packages/paramiko/transport.py", line 2331, in _check_banner raise SSHException( paramiko.ssh_exception.SSHException: Error reading SSH protocol banner SSH error: No existing session importparamiko importtime defexecute(): try: # Define the server and credentials ip='p.q.r.s' un, up, po='name', "passwd", 22 bto, sto=60, 60 ssh_client=paramiko.SSHClient() ssh_client.load_system_host_keys() ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh_client.connect(hostname=ip, port=po, username=un, password=up, banner_timeout=bto, timeout=sto) shell=ssh_client.invoke_shell() defsend_command(command, wait_time=1): shell.send(command+'\n') time.sleep(wait_time) # Give the command some time to execute whilenotshell.recv_ready(): time.sleep(0.1) returnshell.recv(8192).decode() output=send_command('date') print("Output:\n", output) delssh_client exceptparamiko.SSHExceptionase: print(f"SSH error: {e}") exceptExceptionase: print(f"Error: {e}") finally: # Close the SSH client connection delssh_client execute() -- Warm Regards, Vinode Singh Ujlain | https://www.linkedin.com/in/ujlain/ -------- -- https://mail.python.org/mailman/listinfo/python-list
Re: Cprod -- (writing this: itertools.product([0, 1], repeat=N )
dn wrote: On 22/05/24 07:14, HenHanna via Python-list wrote: How can i write this function Cprod (Cartesian Product) simply? (writing this out: itertools.product([0, 1], repeat=N ) The value can be a list or a Tuple. cprod([0, 1], 1) => ((0) (1)) cprod([0, 1], 2) => ((0,0) (0,1) (1,0) (1,1)) This works: def cprod(x, c): if c==1: return [[i] for i in x] Sub= cprod(x, c-1) return [i for F in x for i in [[F]+R for R in Sub]] -- Is there another way to write [F]+R ??? Other ways to improve it? https://python.readthedocs.io/en/stable/library/itertools.html#itertools.product Regards, =dn Thank you... That code looks elegant... I'll study it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Cprod -- (writing this: itertools.product([0, 1], repeat=N )
On 22/05/24 07:14, HenHanna via Python-list wrote: How can i write this function Cprod (Cartesian Product) simply? (writing this out: itertools.product([0, 1], repeat=N ) The value can be a list or a Tuple. cprod([0, 1], 1) => ((0) (1)) cprod([0, 1], 2) => ((0,0) (0,1) (1,0) (1,1)) This works: def cprod(x, c): if c==1: return [[i] for i in x] Sub= cprod(x, c-1) return [i for F in x for i in [[F]+R for R in Sub]] -- Is there another way to write [F]+R ??? Other ways to improve it? https://python.readthedocs.io/en/stable/library/itertools.html#itertools.product -- Regards, =dn -- https://mail.python.org/mailman/listinfo/python-list
Cprod -- (writing this: itertools.product([0, 1], repeat=N )
How can i write this function Cprod (Cartesian Product) simply? (writing this out: itertools.product([0, 1], repeat=N ) The value can be a list or a Tuple. cprod([0, 1], 1) => ((0) (1)) cprod([0, 1], 2) => ((0,0) (0,1) (1,0) (1,1)) This works: def cprod(x, c): if c==1: return [[i] for i in x] Sub= cprod(x, c-1) return [i for F in x for i in [[F]+R for R in Sub]] -- Is there another way to write [F]+R ??? Other ways to improve it? -- https://mail.python.org/mailman/listinfo/python-list
Re: pip and venvs on Debian
Op 20/05/2024 om 23:48 schreef Akkana Peck via Python-list: Every so often I need to regenerate it (like when Debian updates the system Python version) but that's easy to do: I don't try to duplicate what's installed there, I just delete the old venv, create a new one and then pip install packages as needed. I know this isn't the usual pythonista model of "you should have a zillion different venvs, one for each program you use, and never use system Python packages", but it works well for me: my pip installed packages are all in a predictable place, and I get security updates for all the software Debian *does* package. That's my biggest beef with pip, the lack of an easy way to update everything at once, and it's the reason I prefer Debian packages when available. If you have a requirements.txt file with all packages you want, I think you can do pip -install --upgrade -r requirements.txt to update them all. That only works if you don't specify exact versions in the requirements.txt file, so don't use the output of pip freeze to generate that requirements file. Just create it yourself: it's a simple text file with one package per line. Also I prefer not to include dependencies in it for use cases like this (it's another story for packaging, where it can be useful or requirements.txt to mirror your exact environment with dependencies and specific versions). Having such a requirements.txt file also makes it easier to install all the packages again after you re-create your venv. -- "I love science, and it pains me to think that to so many are terrified of the subject or feel that choosing science means you cannot also choose compassion, or the arts, or be awed by nature. Science is not meant to cure us of mystery, but to reinvent and reinvigorate it." -- Robert Sapolsky -- https://mail.python.org/mailman/listinfo/python-list
pip and venvs on Debian (was: Terminal Emulator)
Alan Gauld via Python-list writes: > On 18/05/2024 19:12, Piergiorgio Sartor via Python-list wrote: > > >> So venvs make managing all that pretty convenient. Dunno why everybody's > >> so down on venvs... > > Not so much down on them, they are just one extra step that's > mostly not needed(in my use case) Years ago, I used to have trouble with pip install --user on Debian -- sometimes things would end up under .local, sometimes in other places that I've forgotten. So I reluctantly started using venvs. And you know, they work fine. I have one master venv that I created with python3 -m venv --system-site-packages ~/pythonenv/envname and I activate that automatically when I log in, so when I need to install anything that Debian doesn't package, I just pip install it (no --user or --break-system-packages needed) and it installs to that venv. Every so often I need to regenerate it (like when Debian updates the system Python version) but that's easy to do: I don't try to duplicate what's installed there, I just delete the old venv, create a new one and then pip install packages as needed. I have a few special venvs (without --system-site-packages) for specific purposes, but most of the time I'm just using my default venv and it's all pretty transparent and automatic. I know this isn't the usual pythonista model of "you should have a zillion different venvs, one for each program you use, and never use system Python packages", but it works well for me: my pip installed packages are all in a predictable place, and I get security updates for all the software Debian *does* package. That's my biggest beef with pip, the lack of an easy way to update everything at once, and it's the reason I prefer Debian packages when available. ...Akkana -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 20/05/2024 10:58, Peter J. Holzer wrote: On 2024-05-20 00:26:03 +0200, Roel Schroeven via Python-list wrote: Skip Montanaro via Python-list schreef op 20/05/2024 om 0:08: Modern debian (ubuntu) and fedora block users installing using pip. Even if you're telling it to install in ~/.local? I could see not allowing to run it as root. I assumed pip install --user would work, but no. I tried it (on Debian 12 (bookworm)): $ pip install --user docopt error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, it may be easiest to use pipx install xyz, which will manage a virtual environment for you. Make sure you have pipx installed. See /usr/share/doc/python3.11/README.venv for more information. note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification. Exactly the same output for sudo pip install. This message (quoted in all its glory) is too long to be useful. The important bit is at the end: You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. (I admit I didn't see this the first time I got this message) python3 -m pip install --user --break-system-packages does indeed install into ~/.local/lib/python3.XX/site-packages. This inconvenient, but otoh I have accidentally installed packages into ~/.local in the past, so maybe it's good to make that more explicit. hp Perhaps an alias like so: $ alias 'pip install'='pip install --user --break-system-packages' Would work here? Someone please advise if that is a good idea. -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
I'm on Manjaro Of course, I'm not here to tell you how to use your computer, and it's great that you're using Linux, but I'd suggest that you look into installing Arch Linux proper. Arch Linux isn't as difficult as people make it out to be (I'd argue that anyone who's had to deal with the Calamares installer has seen worse), and it's hugely rewarding as it gives you a fundamental overview of how your system operates and what makes it tick, since you need to install it yourself manually. Plus, Manjaro holds back packages by about a month or so, sometimes more, which breaks AUR packages, which are designed around Arch Linux's packages, which are newer. On top of this, the Manjaro team just can't be trusted with basic things like not having their SSL certs expire on their website (this has happened half a dozen times in the past, which is embarassing, given that things like certbot make installing a certificate the easiest thing in the world). Again, I'm not some power hungry elitist Arch Linux shill or whatever, it's your computer, use it how you want, these are just my suggestions. Don't say I didn't warn you though :) -- https://mail.python.org/mailman/listinfo/python-list
Re: venvs vs. package management
There are several independent problems here: 1. Very short release cycle. This is independent of the Python venv module but is indirectly influenced by Python's own release cycle. Package maintainers don't have time for proper testing, they are encouraged to release a bunch of new (and poorly tested) versions, and they never get a break. So, when you install the latest, there will be something else broken. There's never a window to properly test anything. 2. Python made a very short-sighted decision about how imports work. Python doesn't have a concept of "application", and therefore there's no way to specify dependencies per application (and imports import anything that's available, not versioned). That's why every Python application ends up carrying its own Python, with the version of its own dependencies around. Python's venv module is just an acknowledgement of this design flaw. I.e. the proper solution would've been a concept of application and per-application dependency specification, but instead we got this thing that doesn't really work (esp. when native modules and shared libraries are considered), but it "works" often enough to be useful. 3. The Python community grew to be very similar to what PHP 4 was, where there were several "poisonous" examples, which were very popular on the Web, which popularized a way of working with MySQL databases that was very conducive to SQL injections. Python has spread very bad ideas about project management. Similar to how PHP came up with mysql_real_escape() and mysql_this_time_promise_for_real_escape() and so on functions, Python came up with bad solutions to the problems that had to be fixed by removing bad functionality (or, perhaps, education). So, for example, it's very common to use requirements.txt, which is generated by running pip freeze (both practices are bad ideas). Then PyPA came up with a bunch of bad ideas in response to problems like this, eg. pyproject.toml. In an absurd way very much mirroring the situation between makefiles and makefiles generated by autotools, today Python developers are very afraid of doing simple things when it comes to project infrastructure (it absolutely has to be a lot of configuration fed into another configuration, processed by a bunch of programs to generate even more configuration...) And most Python programmers don't really know how the essential components of all of this infrastructure work. They rely on a popular / established pattern of insane multi-step configuration generation to do simple things. And the tradition thus developed is so strong, that it became really cultish. This, of course, negatively contributes to the overall quality of Python packages and tools to work with them. Unfortunately, the landscape of Python today is very diverse. There's no universally good solution to package management because it's broken in the place where nobody is allowed to fix it. Commercial and non-commercial bodies alike rely on people with a lot of experience and knowledge of particular Python gotchas to get things done. (Hey, that's me!) And in different cases, the answer to the problem will be different. Sometimes venv is good enough. Other times you may want a container or a vm image. Yet in a different situation you may want a PyPA or conda package... and there's more. On Sun, May 19, 2024 at 4:05 PM Piergiorgio Sartor via Python-list wrote: > > On 19/05/2024 08.49, Peter J. Holzer wrote: > [...] > > That's what package management on Linux is for. Sure, it means that you > > won't have the newest version of anything and some packages not at all, > > but you don't have to care about dependencies. Or updates. > > Well, that doesn't work as well. > Distributions do not pack everything, this > also depending on licenses. > > Sometimes, or often, you need to use the > *latest* version of something, due to some > bugfix or similar. > > The distribution does not always keep up > to date everything, so you're stuck. > > The only solution is a venv, with all > needed packages for the given task. > > Typical problem with PyTorch / TensorFlow. > > In case of trouble, the first answer is: > "Check with the latest (nightly) release". > > Which means installing something *outside* > the Linux distribution support. > And this impossible, because this will pull > in dependencies like crazy, which are not > (yet) in the Linux distribution path. > > Saying it differently, the latest greatest > update is not a wish, it's a must... > > So, long story short, the only solution I > know are venvs... > > Of course, other solutions are welcome! > > bye, > > -- > > piergiorgio > > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-20 00:26:03 +0200, Roel Schroeven via Python-list wrote: > Skip Montanaro via Python-list schreef op 20/05/2024 om 0:08: > > > Modern debian (ubuntu) and fedora block users installing using pip. > > > > Even if you're telling it to install in ~/.local? I could see not allowing > > to run it as root. > > I assumed pip install --user would work, but no. I tried it (on Debian 12 > (bookworm)): > > > $ pip install --user docopt > > error: externally-managed-environment > > > > × This environment is externally managed > > ╰─> To install Python packages system-wide, try apt install > > python3-xyz, where xyz is the package you are trying to > > install. > > > > If you wish to install a non-Debian-packaged Python package, > > create a virtual environment using python3 -m venv path/to/venv. > > Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make > > sure you have python3-full installed. > > > > If you wish to install a non-Debian packaged Python application, > > it may be easiest to use pipx install xyz, which will manage a > > virtual environment for you. Make sure you have pipx installed. > > > > See /usr/share/doc/python3.11/README.venv for more information. > > > > note: If you believe this is a mistake, please contact your Python > > installation or OS distribution provider. You can override this, at the > > risk of breaking your Python installation or OS, by passing > > --break-system-packages. > > hint: See PEP 668 for the detailed specification. > > Exactly the same output for sudo pip install. This message (quoted in all its glory) is too long to be useful. The important bit is at the end: > > You can override this, at the risk of breaking your Python > > installation or OS, by passing --break-system-packages. (I admit I didn't see this the first time I got this message) python3 -m pip install --user --break-system-packages does indeed install into ~/.local/lib/python3.XX/site-packages. This inconvenient, but otoh I have accidentally installed packages into ~/.local in the past, so maybe it's good to make that more explicit. 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: Terminal Emulator (Posting On Python-List Prohibited)
On 5/19/2024 6:00 PM, Karsten Hilbert via Python-list wrote: Am Sun, May 19, 2024 at 10:45:09PM +0100 schrieb Barry via Python-list: On 18 May 2024, at 16:27, Peter J. Holzer via Python-list wrote: I don't think Linux users have to deal with venvs Modern debian (ubuntu) and fedora block users installing using pip. You must use a venv to pip install packages from pypi now. Which makes one wonder how one is supposed to package Python applications requiring modules not yet packaged by Debian. I confess, I sometimes install those packages using pip's self-warning option "--break-system-packages". Naturally I only install them with --user. Another option besides venvs is to install a different version of Python from python.org, not by using the system installer. For example, if your system version is, say, 3.8.10 (as it is on my Mint VM), install 3.11.9 and make sure you always launch pip with python3.11 -m pip I have done this on some VMs, and use the system's Python on some others. Happily none of my Linux VMs are critical for anything. I can blow them away and recreate them without worry. -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 5/19/2024 6:34 PM, Grant Edwards via Python-list wrote: On 2024-05-19, Barry via Python-list wrote: On 18 May 2024, at 16:27, Peter J. Holzer via Python-list wrote: I don't think Linux users have to deal with venvs Modern debian (ubuntu) and fedora block users installing using pip. You can't even use pip to do "user" installs? Nope, often not. The error messages I've gotten do tell you to use the "--break-system-packages" flag if you really, really want to install the package. So python3 -m pip install --user --break-system-packages [--upgrade] Or install an additional version of Python that isn't managed by the system. Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 5/19/2024 6:08 PM, Skip Montanaro via Python-list wrote: Modern debian (ubuntu) and fedora block users installing using pip. Even if you're telling it to install in ~/.local? I could see not allowing to run it as root. I honestly haven't tried. Maybe I should... 樂 I have an old laptop running XUbuntu 22.04 which I generally only use to compile the most recent branches on GitHub (main, 3.12, & 3.13 at the moment). On some (maybe all) of my Linux VMs, pip - the one installed for the system - won't install something even with --user unless you use the --break-system-packages flag. -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-19, Barry via Python-list wrote: > > >> On 18 May 2024, at 16:27, Peter J. Holzer via Python-list >> wrote: >> >> I don't think Linux users have to deal with venvs > > Modern debian (ubuntu) and fedora block users installing using pip. You can't even use pip to do "user" installs? -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-19, Gilmeh Serda via Python-list wrote: > On Sun, 19 May 2024 08:32:46 +0100, Alan Gauld wrote: > >> I've honestly never experienced this "nightmare". >> I install stuff and it just works. > > Hear! Hear! Me too! And all that. > > I'm on Manjaro, which is a tad finicky about other people touching its > Python since it's used for lots of things. I install things for myself > only. > > Was there a reason they chose the name Pip? I always assumed it was in honor of the PIP (Peripheral Interchange Program?) utility that was used to copy files around on CP/M and DEC's PDP-11 OSes. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
Skip Montanaro via Python-list schreef op 20/05/2024 om 0:08: Modern debian (ubuntu) and fedora block users installing using pip. > Even if you're telling it to install in ~/.local? I could see not allowing to run it as root. I assumed pip install --user would work, but no. I tried it (on Debian 12 (bookworm)): $ pip install --user docopt error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, it may be easiest to use pipx install xyz, which will manage a virtual environment for you. Make sure you have pipx installed. See /usr/share/doc/python3.11/README.venv for more information. note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification. Exactly the same output for sudo pip install. For easy reference here's a link to that PEP 668: https://peps.python.org/pep-0668/ Which links to the "Externally Managed Environments" on the PyPA specs page: https://packaging.python.org/en/latest/specifications/externally-managed-environments/#externally-managed-environments -- "If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed." -― Onbekend (dikwijls toegeschreven aan Mark Twain, waarschijnlijk onterecht) -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
Modern debian (ubuntu) and fedora block users installing using pip. > Even if you're telling it to install in ~/.local? I could see not allowing to run it as root. I honestly haven't tried. Maybe I should... 樂 I have an old laptop running XUbuntu 22.04 which I generally only use to compile the most recent branches on GitHub (main, 3.12, & 3.13 at the moment). Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
Am Sun, May 19, 2024 at 10:45:09PM +0100 schrieb Barry via Python-list: > > On 18 May 2024, at 16:27, Peter J. Holzer via Python-list > > wrote: > > > > I don't think Linux users have to deal with venvs > > Modern debian (ubuntu) and fedora block users installing using pip. > You must use a venv to pip install packages from pypi now. Which makes one wonder how one is supposed to package Python applications requiring modules not yet packaged by Debian. Karsten -- GPG 40BE 5B0E C98E 1713 AFA6 5BC0 3BEA AC80 7D4F C89B -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
> On 18 May 2024, at 16:27, Peter J. Holzer via Python-list > wrote: > > I don't think Linux users have to deal with venvs Modern debian (ubuntu) and fedora block users installing using pip. You must use a venv to pip install packages from pypi now. This is implemented in python and pip and enabled by the distros. There are ways to turn off the blocking, but it’s strongly discouraged by the distros. Barry -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-19 at 18:13:23 +, Gilmeh Serda via Python-list wrote: > Was there a reason they chose the name Pip? Package Installer for Python https://pip.pypa.io/en/stable/index.html -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-19 19:13, Gilmeh Serda via Python-list wrote: On Sun, 19 May 2024 08:32:46 +0100, Alan Gauld wrote: I've honestly never experienced this "nightmare". I install stuff and it just works. Hear! Hear! Me too! And all that. I'm on Manjaro, which is a tad finicky about other people touching its Python since it's used for lots of things. I install things for myself only. Was there a reason they chose the name Pip? [snip] From https://pip.pypa.io/en/stable/: "pip is the package installer for Python." It's an acronym. -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-19 at 18:13:23 +, Gilmeh Serda via Python-list wrote: > Was there a reason they chose the name Pip? Package Installer for Python https://pip.pypa.io/en/stable/index.html Every time I see PIP, I think Peripheral Interchange Program, but I'm old. -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 5/19/2024 3:32 AM, Alan Gauld via Python-list wrote: On 18/05/2024 19:12, Piergiorgio Sartor via Python-list wrote: [snip] The dependency nightmare created by python, pip and all the rest cannot be resolved otherwise. I've honestly never experienced this "nightmare". I install stuff and it just works. One way it can bite even you is if you have a program installed whose requirements claim it needs a certain library of version no higher than X, and you already already have a later version of that library installed since one of your other programs requires it. Pip won't install the new program because of this conflict. In reality, you may know the the new program would work fine with the version of the library you installed, but the packagers of the new program didn't realize they should have updated their requirements. With venvs, you can have separate environments for each. Of course this doesn't help if you need both packages in the same environment... -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-19, Alan Gauld via Python-list wrote: >> The dependency nightmare created by python, pip >> and all the rest cannot be resolved otherwise. > > I've honestly never experienced this "nightmare". > I install stuff and it just works. Same here. I occasonlly use pip to install something that isn't packaged for Gentoo, but it doesn't seem to cause problems — let alone nightmares. I also occasionally package something myself. -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: venvs vs. package management
On 19/05/2024 08.49, Peter J. Holzer wrote: [...] That's what package management on Linux is for. Sure, it means that you won't have the newest version of anything and some packages not at all, but you don't have to care about dependencies. Or updates. Well, that doesn't work as well. Distributions do not pack everything, this also depending on licenses. Sometimes, or often, you need to use the *latest* version of something, due to some bugfix or similar. The distribution does not always keep up to date everything, so you're stuck. The only solution is a venv, with all needed packages for the given task. Typical problem with PyTorch / TensorFlow. In case of trouble, the first answer is: "Check with the latest (nightly) release". Which means installing something *outside* the Linux distribution support. And this impossible, because this will pull in dependencies like crazy, which are not (yet) in the Linux distribution path. Saying it differently, the latest greatest update is not a wish, it's a must... So, long story short, the only solution I know are venvs... Of course, other solutions are welcome! bye, -- piergiorgio -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 18/05/2024 19:12, Piergiorgio Sartor via Python-list wrote: >> So venvs make managing all that pretty convenient. Dunno why everybody's >> so down on venvs... Not so much down on them, they are just one extra step that's mostly not needed(in my use case) > Only people which are *not* using python... :-) > > In my experience, venvs is the only possible > way to use python properly. Well, I've been using Python since 1998 on Linux, Windows and MacOS and have yet to find a use for a venv. I've played with them when they first came out but haven't actually found a scenario where I've thought "I need a venv for that!" But then I'm a sole user, I have 3 or 4 projects going but only me working on them. I only have 2 Python versions at any time and the OS handles that just fine without any venvs. > The dependency nightmare created by python, pip > and all the rest cannot be resolved otherwise. I've honestly never experienced this "nightmare". I install stuff and it just works. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list
venvs vs. package management (was: Terminal Emulator (Posting On Python-List Prohibited))
On 2024-05-18 20:12:33 +0200, Piergiorgio Sartor via Python-list wrote: > On 18/05/2024 20.04, Mats Wichmann wrote: > > So venvs make managing all that pretty convenient. Dunno why everybody's > > so down on venvs... > > Only people which are *not* using python... :-) > > In my experience, venvs is the only possible > way to use python properly. That's very much depends on what you mean by properly. Personally, I use venvs a lot. But most of the reasons have more to do with team culture than technical constraints. In a different situation (e.g. if all our developers used Linux and preferrably the same version) I could see myself using venvs much less or maybe not at all. > The dependency nightmare created by python, pip and all the rest > cannot be resolved otherwise. That's what package management on Linux is for. Sure, it means that you won't have the newest version of anything and some packages not at all, but you don't have to care about dependencies. Or updates. (Missing packages can be a problem: Is there a script to automatically generate .deb packages from PyPI? I haven't looked recently ...) > It seems backward compatibility is a taboo... I have recently written a script which checks out the newest version of the project, creates a fresh venv using a requirements.txt without version numbers and runs the test suite. If there is any action required (either because a test fails or because there is a newer version of any dependent package) it will create a ticket in redmine. Oh, and this script runs on a staging server which has the same Linux distribution (and hence the same Python version) as the production server. Seems to work, but that is only necessary because we are using venvs. If we relied on the distro's package management that would basically be a non-issue. 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: Terminal Emulator (Posting On Python-List Prohibited)
On 18/05/2024 20.04, Mats Wichmann wrote: [...] So venvs make managing all that pretty convenient. Dunno why everybody's so down on venvs... Only people which are *not* using python... :-) In my experience, venvs is the only possible way to use python properly. The dependency nightmare created by python, pip and all the rest cannot be resolved otherwise. It seems backward compatibility is a taboo... bye, -- piergiorgio -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator
On 14/05/2024 19.44, Gordinator wrote: I wish to write a terminal emulator in Python. I am a fairly competent Python user, and I wish to try a new project idea. What references can I use when writing my terminal emulator? I wish for it to be a true terminal emulator as well, not just a Tk text widget or something like that. If you have any advice, please do let me know! I would start writing down what this "terminal emulator" should do. Then, collect information about what module / library can support the features. bye, -- piergiorgio -- https://mail.python.org/mailman/listinfo/python-list
Re: PyCon
Two interesting ones: - Norwegian library: https://fosstodon.org/@osdotsystem/112459312723574625 - One about if Ai will take our jobs, using py to find out and she concludes it will On Sat, 18 May 2024, 14:15 Chris Angelico via Python-list, < python-list@python.org> wrote: > On Sun, 19 May 2024 at 04:10, Abdur-Rahmaan Janhangeer via Python-list > wrote: > > > > Yes, this year's pretty exciting, great keynotes, great lightnings, great > > location, great even sponsor talks (thought they would be pumping a lot > of > > marketing, but the ones i went were pretty awesome technically) > > > > Organization side pretty smooth as well > > I missed out on the first day's lightning talks session due to > conflict with work, and it didn't seem to have been recorded. What did > I miss? > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-18, Mats Wichmann via Python-list wrote: > Distros have do offer a good selection of packaged Python bits, yes, but > only for the version of Python that's "native" to that distro release. > If you need to test other versions of Python, you're mostly on your own. For a few years I needed both 2.x and 3.x installed, but my distro (Gentoo) handled that fine (I think most others do also). Gentoo also allows multiple minor versions to be installed (currently I have 3.11 and 3.12 on this machine). But, since Gentoo is a source-based meta-distro, when I install a Python package, the package manager knows how to install it for all installed Python versions that are supported by the package. I can't think of why I would need a venv unless I needed to test something with a Python version that isn't available for Gentoo. That said, there are currently 7 versions available (2.7.18, 3.8.19, 3.9.19, 3.10.14, 3.11.9, 3.12.3, 3.13.0). 3.13 isn't marked stable yet in the Gentoo package database, and I apparently have some Python app/package installed that doesn't yet support 3.12, so I've currently got both 3.12 and 3.11. -- https://mail.python.org/mailman/listinfo/python-list
Re: PyCon
On Sun, 19 May 2024 at 04:10, Abdur-Rahmaan Janhangeer via Python-list wrote: > > Yes, this year's pretty exciting, great keynotes, great lightnings, great > location, great even sponsor talks (thought they would be pumping a lot of > marketing, but the ones i went were pretty awesome technically) > > Organization side pretty smooth as well I missed out on the first day's lightning talks session due to conflict with work, and it didn't seem to have been recorded. What did I miss? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: PyCon
Yes, this year's pretty exciting, great keynotes, great lightnings, great location, great even sponsor talks (thought they would be pumping a lot of marketing, but the ones i went were pretty awesome technically) Organization side pretty smooth as well On Fri, 17 May 2024, 20:58 Larry Martell via Python-list, < python-list@python.org> wrote: > I’m at PyCon in Pittsburgh and I’m haven’t an amazing time! > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 5/18/24 10:48, Grant Edwards via Python-list wrote: On 2024-05-18, Peter J. Holzer via Python-list wrote: On 2024-05-16 19:46:07 +0100, Gordinator via Python-list wrote: To be fair, the problem is the fact that they use Windows (but I guess Linux users have to deal with venvs, so we're even. I don't think Linux users have to deal with venvs any more than Windows users. Maybe even less because many distributions come with a decent set of Python packages. I've been using Python on Linux almost daily for 25 years, same here, but: and I've yet to use a venv... Distros have do offer a good selection of packaged Python bits, yes, but only for the version of Python that's "native" to that distro release. If you need to test other versions of Python, you're mostly on your own. Just as an example, for a particular project I had one test machine running Fedora 38 until just a couple weeks ago, with Python 3.11 as "native" with a full suite of packages, but I needed to test 3.12 and then the 3.13 pre-releases, as well as occasionally sanity-check the "oldest supported Python for this project", which turned out to be 3.6. I could build all those Pythons myself and install them to a location I can "python3.xx -m pip install" to, but Fedora is nice enough to package up a whole bunch of past and future Python versions, so why? And Fedora really discourages doing installs via pip to a system-packaged Python. So venvs make managing all that pretty convenient. Dunno why everybody's so down on venvs... -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-18, Peter J. Holzer via Python-list wrote: > On 2024-05-16 19:46:07 +0100, Gordinator via Python-list wrote: > >> To be fair, the problem is the fact that they use Windows (but I >> guess Linux users have to deal with venvs, so we're even. > > I don't think Linux users have to deal with venvs any more than > Windows users. Maybe even less because many distributions come with > a decent set of Python packages. I've been using Python on Linux almost daily for 25 years, and I've yet to use a venv... -- Grant -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 2024-05-16 19:46:07 +0100, Gordinator via Python-list wrote: > To be fair, the problem is the fact that they use Windows (but I guess Linux > users have to deal with venvs, so we're even. I don't think Linux users have to deal with venvs any more than Windows users. Maybe even less because many distributions come with a decent set of Python packages. 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: Terminal Emulator
On 2024-05-14 22:37:17 +0200, Mirko via Python-list wrote: > Am 14.05.24 um 19:44 schrieb Gordinator via Python-list: > > I wish to write a terminal emulator in Python. I am a fairly competent > > Python user, and I wish to try a new project idea. What references can I > > use when writing my terminal emulator? I wish for it to be a true > > terminal emulator as well, not just a Tk text widget or something like > > that. > > > > If you have any advice, please do let me know! > > > Not sure, what you mean with: > > > true terminal emulator as well, not just a Tk text widget or > > something like that > If you want to write a GUI terminal, than that *is* a terminal emulator and > *has* a text widget as its visible core. If you want to write something like > getty which runs on the virtual terminals (Ctrl+Alt+F*) than that is a > terminal (not a terminal emulator). Getty isn't a terminal (unless there is another program of the same name). It's a small program to set up a serial communication line. Basically it waits for the modem to connect, sets the relevant parameters (bit rate, byte width, parity, ...) and then hands over to login. Of course in the case of a linux console there is no modem and no serial line involved, so it doesn't have much to do. (Of course this raises the question whether the Linux console is a terminal or a terminal emulator ...) 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: Terminal Emulator
On 2024-05-14 16:03:33 -0400, Grant Edwards via Python-list wrote: > On 2024-05-14, Alan Gauld via Python-list wrote: > > On 14/05/2024 18:44, Gordinator via Python-list wrote: > > > >> I wish to write a terminal emulator in Python. I am a fairly > >> competent Python user, and I wish to try a new project idea. What > >> references can I use when writing my terminal emulator? I wish for > >> it to be a true terminal emulator as well, not just a Tk text > >> widget or something like that. > > > > The first thing is to decide which terminal. > > If you want to make life easier, make it a superset of a terminal that > already exists in the terminfo database. > > Going with some sort of ANSI terminal will probably provide > operability even with dumb apps which ignore $TERM and just spit out > basic ANSI escape sequences. And if you want to go for a superset, xterm might be one of the more useful: https://www.xfree86.org/current/ctlseqs.html > If you really want to break trail, you could invent your own control > sequences, which means you'll have to write terminfo and/or termcap > entries as well as the terminal emulator. Right. A saner model than ANSI and its supersets might be a good idea conceptionally. But I'd expect quite a few programs to break. > > A VT100 is very different from a 3270. And even a VT330 is quite > > different from a VT100 although sharing a common subset of control > > codes. And if you start looking at graphical terminals things get > > even more interesting! > > "Intersting" is putting it mildly... Yup. Also there aren't many programs which use, e.g. xterm's pixel-graphics capabilities. OTOH, there is something like domterm[1], which can (theoretically) display anything a browser can display. hp [1] https://domterm.org/index.html -- _ | 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: PyCon
On Sat, 18 May 2024 at 21:44, Skip Montanaro via Python-list wrote: > > > > > > I’m at PyCon in Pittsburgh and I’m haven’t an amazing time! > > > > s/haven’t/having/ > > > > No need to explain/correct. We understand you are excited. Many of us have > been in the same state before. ;-) > We're fluent in autocorrupt :) If you're connecting to the online parts of PyCon, I'll see you there - I'm about to hang out in the lightning talks! Geography's a bit of a barrier for me, but thanks to livestreams, I can participate too! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: PyCon
> > > I’m at PyCon in Pittsburgh and I’m haven’t an amazing time! > > s/haven’t/having/ > No need to explain/correct. We understand you are excited. Many of us have been in the same state before. ;-) Enjoy, Skip > -- https://mail.python.org/mailman/listinfo/python-list
Re: PyCon
LOn Fri, May 17, 2024 at 8:57 PM Larry Martell wrote: > I’m at PyCon in Pittsburgh and I’m haven’t an amazing time! s/haven’t/having/ -- https://mail.python.org/mailman/listinfo/python-list
PyCon
I’m at PyCon in Pittsburgh and I’m haven’t an amazing time! -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 16/05/2024 01:12, Lawrence D'Oliveiro wrote: On 15 May 2024 10:31:25 GMT, Stefan Ram wrote: We need somethin like a portable curses module (plus colorama) and it has got to work on both Windoze and Linux straight out of the box in standard Python. Something else for Windows Python users to complain that they cannot get to install properly? To be fair, the problem is the fact that they use Windows (but I guess Linux users have to deal with venvs, so we're even. -- https://mail.python.org/mailman/listinfo/python-list
Re: Version of NymPy
Let me try to answer this properly, instead of "simply". The "problematic" part of your question is "with my Anaconda distribution". Anaconda distribution comes with the conda program that manages installed packages. A single Anaconda distribution may have multiple NumPy versions installed at the same time, although only one will be available to the Python process (note that this means that sub-processes created in this Python process won't necessarily have the same version of NumPy!). To make matters worse, it's common for Anaconda users to use pip to install packages. Now, Anaconda has a concept of virtual environments independent of Python's venv module. In order to create such environments it can be configured to either link (usually hard-link) installed packages into the dedicated directory, or to copy these packages into the said directory. This will become important once you inevitably ask the follow-up question: "why do I have this version of NumPy?". Unfortunately, you also need to consider setuptools. The traditional setup.py install command may install multiple versions of the same package into the same directory. Even worse, "pip install -e", the glorified "setup.py develop", complicates things even further by adding the "installed" package to the pth file, which can, again, create ambiguities as to the resolution of the package location. On top of this, there's an environment variable: PYTHONPATH that can be set to add an arbitrary number of source directories for Python to look up package location. So, suppose you ran: python -c "import numpy; numpy.__version__" and then ran a Jupyter notebook and discovered that the version of NumPy in that notebook is not the one you just saw in the previous output... What went wrong? You then may try: conda info numpy and get yet another answer. And then you run pip show numpy And the answer is still different! Of course, it's not necessary that all these answers are different. And, in most circumstances they are going to be consistent... but they don't have to be! Below is the list of typical problems I encountered in my attempts to resolve similar problems for Python users. Of course, this list is not exhaustive. 1. If the version in the Jupyter notebook differs from the one in the environment in which the Jupyter server was started, you need to look for the Jupyter kernel definition. There are many ways in which the Jupyter kernel definition may alter the module lookup locations, but the most common one is that using Python from the active virtual environment isn't the default for the default Jupyter kernel. 2. If installed modules in conda environments are hard-linked, and at some point pip or setuptools were used to install extra packages, you might have "botched" unrelated environments by overwriting files through hard-links without you even knowing that. 3. conda will happily install outdated versions of conda into virtual environments it creates. The format of conda virtual environments changed over time, and older versions of conda are unaware of the new format, while newer versions are unaware of the old format. If you happen to run the conda command from the wrong environment you may get unexpected results (especially if both the new and the old version of conda have created environments with the same name!) To avoid this, you'd want to deactivate all conda environments activated so far until you are at least in the base environment. 4. Usually, some diagnostic information can be gleaned from printing the value of PYTHONPATH environment variable, sys.paths list (inside Python), sys.sysconfig.get_path('platlib') (and looking into this directory for duplicate packages with different version or for the pth files.) If you discover anomalies, try to figure out if you had to use pip to install packages (this may indirectly mean using setuptools). Similarly, running "conda build" may indirectly result in running setuptools commands. Also, some popular tools like to do bad things to packages and virtual environments: pytest and tox come to mind. pytest can manipulate module lookup locations (and you will need to dissect its configuration to figure this out). tox, afaik, is unaware of conda virtual environments, and will try to create venv-style virtual environments, which will have all the same problems as using pip in conda environments does. 5. Final warning: no matter how ridiculous this is: the current directory in Python is added to the module lookup path, and it *precedes* every other lookup location. If, accidentally, you placed a numpy.py in the current directory of your Python process -- that is going to be the numpy module you import. To make this even worse, this behavior used to depend on whether you start Python with PDB active or not (with PDB, the current working directory wasn't added to the path, and module imports
Re: Terminal Emulator
We need somethin like a portable curses module (plus colorama) Agreed, getting curses to work on Windows is SUCH a pain, and I don't think I've ever done it. Naturally, as a Linux user, I don't find much need to do it anyway. Colorama would also be cool in the standard library as well. I have worked on projects in the past where only the standard library could be used, so I 100% agree with this. But that's something for the PSF to talk about. Maybe someone could write a PEP for this. -- https://mail.python.org/mailman/listinfo/python-list
Re: Version of NymPy
On 2024-05-15 19:42, Popov, Dmitry Yu via Python-list wrote: What would be the easiest way to learn which version of NumPy I have with my Anaconda distribution? Import numpy and print its '__version__' attribute. -- https://mail.python.org/mailman/listinfo/python-list
Re: Version of NymPy
Thank you. From: Larry Martell Sent: Wednesday, May 15, 2024 1:55 PM To: Popov, Dmitry Yu Cc: Popov, Dmitry Yu via Python-list Subject: Re: Version of NymPy On Wed, May 15, 2024 at 2: 43 PM Popov, Dmitry Yu via Python-list wrote: > > What would be the easiest way to learn which version of NumPy I have with my Anaconda distribution? >>> import numpy >>> ZjQcmQRYFpfptBannerStart This Message Is From an External Sender This message came from outside your organization. ZjQcmQRYFpfptBannerEnd On Wed, May 15, 2024 at 2:43 PM Popov, Dmitry Yu via Python-list wrote: > > What would be the easiest way to learn which version of NumPy I have with my > Anaconda distribution? >>> import numpy >>> numpy.__version__ '1.24.4' -- https://mail.python.org/mailman/listinfo/python-list
Re: Version of NymPy
On Wed, May 15, 2024 at 2:43 PM Popov, Dmitry Yu via Python-list wrote: > > What would be the easiest way to learn which version of NumPy I have with my > Anaconda distribution? >>> import numpy >>> numpy.__version__ '1.24.4' -- https://mail.python.org/mailman/listinfo/python-list
Version of NymPy
What would be the easiest way to learn which version of NumPy I have with my Anaconda distribution? -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator
On 14May2024 18:44, Gordinator wrote: I wish to write a terminal emulator in Python. I am a fairly competent Python user, and I wish to try a new project idea. What references can I use when writing my terminal emulator? I wish for it to be a true terminal emulator as well, not just a Tk text widget or something like that. Start with the `pty` module. -- https://mail.python.org/mailman/listinfo/python-list
RE: Terminal Emulator
The topic was to re-invent the wheel yet again and create a terminal emulator. I hesitate to say this but one approach is to consider the curses module as described by our very own Alan Gauld in a book: https://www.amazon.com/Programming-curses-Python-Alan-Gauld-ebook/dp/B091B85 B77 The topic is how to make a terminal emulator and as Alan mentions, each kind of terminal may accept various kinds of escape sequences. There are files available the are normally used by curses to get a description of sorts of the capabilities and details of a terminal like a VT100 that curses can use to decide what stream of bytes to send to update a screen. You might be able to use something similar, or better, to see what your terminal emulator should emulate. And, it may even be possible for you to emulate lots of terminals with the same basic code. -Original Message- From: Python-list On Behalf Of Alan Gauld via Python-list Sent: Tuesday, May 14, 2024 3:07 PM To: Gordinator ; python-list@python.org Subject: Re: Terminal Emulator On 14/05/2024 18:44, Gordinator via Python-list wrote: > I wish to write a terminal emulator in Python. I am a fairly competent > Python user, and I wish to try a new project idea. What references can I > use when writing my terminal emulator? I wish for it to be a true > terminal emulator as well, not just a Tk text widget or something like that. The first thing is to decide which terminal. A VT100 is very different from a 3270. And even a VT330 is quite different from a VT100 although sharing a common subset of control codes. And if you start looking at graphical terminals things get even more interesting! The other thing to consider is whether it will be a standalone app or a GUI component. If the latter do you want to expose your own API or clone the manufacturers? Or both?! Or you could make it an object that can be used both in GUIs and in "robotic" or "batch" mode. So many options. Most of the specs are available online and there must be dozens of terminal emulators around written in C so you should have plenty of sample code to study. Good luck! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator
Am 14.05.24 um 19:44 schrieb Gordinator via Python-list: I wish to write a terminal emulator in Python. I am a fairly competent Python user, and I wish to try a new project idea. What references can I use when writing my terminal emulator? I wish for it to be a true terminal emulator as well, not just a Tk text widget or something like that. If you have any advice, please do let me know! Not sure, what you mean with: true terminal emulator as well, not just a Tk text widget or something like that If you want to write a GUI terminal, than that *is* a terminal emulator and *has* a text widget as its visible core. If you want to write something like getty which runs on the virtual terminals (Ctrl+Alt+F*) than that is a terminal (not a terminal emulator). In both cases, you write something that gets input from the keyboard, processes it and shows the result. How that processing is done, depends on the terminal standard, like DEC VT{100, 102, 220, 320, etc}. For a start, you might want to look at Terminator, which is a terminal emulator written in Python, Gtk and libvte (which does all the low level stuff). -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator
On 2024-05-14, Alan Gauld via Python-list wrote: > On 14/05/2024 18:44, Gordinator via Python-list wrote: > >> I wish to write a terminal emulator in Python. I am a fairly >> competent Python user, and I wish to try a new project idea. What >> references can I use when writing my terminal emulator? I wish for >> it to be a true terminal emulator as well, not just a Tk text >> widget or something like that. > > The first thing is to decide which terminal. If you want to make life easier, make it a superset of a terminal that already exists in the terminfo database. Going with some sort of ANSI terminal will probably provide operability even with dumb apps which ignore $TERM and just spit out basic ANSI escape sequences. If you really want to break trail, you could invent your own control sequences, which means you'll have to write terminfo and/or termcap entries as well as the terminal emulator. > A VT100 is very different from a 3270. And even a VT330 is quite > different from a VT100 although sharing a common subset of control > codes. And if you start looking at graphical terminals things get > even more interesting! "Intersting" is putting it mildly... -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator
On 2024-05-14, Alan Gauld via Python-list wrote: > On 14/05/2024 18:44, Gordinator via Python-list wrote: > >> I wish to write a terminal emulator in Python. I am a fairly >> competent Python user, and I wish to try a new project idea. What >> references can I use when writing my terminal emulator? I wish for >> it to be a true terminal emulator as well, not just a Tk text >> widget or something like that. > > The first thing is to decide which terminal. You also need to decide if you're going to support real serial ports or just ptys. -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator
On 14/05/2024 18:44, Gordinator via Python-list wrote: > I wish to write a terminal emulator in Python. I am a fairly competent > Python user, and I wish to try a new project idea. What references can I > use when writing my terminal emulator? I wish for it to be a true > terminal emulator as well, not just a Tk text widget or something like that. The first thing is to decide which terminal. A VT100 is very different from a 3270. And even a VT330 is quite different from a VT100 although sharing a common subset of control codes. And if you start looking at graphical terminals things get even more interesting! The other thing to consider is whether it will be a standalone app or a GUI component. If the latter do you want to expose your own API or clone the manufacturers? Or both?! Or you could make it an object that can be used both in GUIs and in "robotic" or "batch" mode. So many options. Most of the specs are available online and there must be dozens of terminal emulators around written in C so you should have plenty of sample code to study. Good luck! -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos -- https://mail.python.org/mailman/listinfo/python-list
Terminal Emulator
I wish to write a terminal emulator in Python. I am a fairly competent Python user, and I wish to try a new project idea. What references can I use when writing my terminal emulator? I wish for it to be a true terminal emulator as well, not just a Tk text widget or something like that. If you have any advice, please do let me know! -- https://mail.python.org/mailman/listinfo/python-list
Re: help
On 5/12/2024 7:56 PM, Enrder via Python-list wrote: good tader I need help to install the bcml, and is that after installing the python and I go to the command prompt and put ''pip install bcml'' to install it tells me "pip" is not recognized as an internal or external command, program or executable batch file. I have tried everything, uninstalling and installing, restoring it, activating and deactivating all the checkboxes that appear in the options section, I searched the internet and the same thing keeps happening to me. If you can help me, I would appreciate it very much. Launch pip using the following command. If you don't run python using the name "python" then use the name you usually use (e.g., "py", "python3", etc.) - python -m pip install bcml This command causes Python to load and run its own copy of pip. So the fact that the operating system can't find it doesn't matter. You should always run pip this way, especially if you end up with several different versions of Python on the same computer. -- https://mail.python.org/mailman/listinfo/python-list
help
good tader I need help to install the bcml, and is that after installing the python and I go to the command prompt and put ''pip install bcml'' to install it tells me "pip" is not recognized as an internal or external command, program or executable batch file. I have tried everything, uninstalling and installing, restoring it, activating and deactivating all the checkboxes that appear in the options section, I searched the internet and the same thing keeps happening to me. If you can help me, I would appreciate it very much. Translated with DeepL.com (free version) Enviado desde [1]Correo para Windows References Visible links 1. https://go.microsoft.com/fwlink/?LinkId=550986 -- https://mail.python.org/mailman/listinfo/python-list
Re: Issues with uninstalling python versions on windows server
On 5/10/24 03:39, Tripura Seersha via Python-list wrote: Hi Barry, Automation is using the system account using which the installation is failing with exit code 3. This account has the administrative privileges. Please help me with this issue. Thanks, Seersha You probably have a better chance of finding the attention of people who know about the details either on the Python Discuss board (discuss.python.org), or by filing an issue - after first checking someone else isn't wrestling with the same problem you are - there are a number of uninstall-related issues open (https://github.com/python/cpython/issues) In particular, I see that this part of your issue: > I have observed that uninstallation is working only with the account/login using which the python version is installed seems to be a known problem, where the user who initiated the install has the uninstall registered to their account - see https://github.com/python/cpython/issues/69353 -- https://mail.python.org/mailman/listinfo/python-list
Re: Issues with uninstalling python versions on windows server
Hi Barry, Automation is using the system account using which the installation is failing with exit code 3. This account has the administrative privileges. Please help me with this issue. Thanks, Seersha From: Python-list on behalf of Tripura Seersha via Python-list Sent: 07 May 2024 12:06 To: Barry Cc: python-list@python.org Subject: Re: Issues with uninstalling python versions on windows server Hi Barry, Yes, the install was for specific user. As suggested by you, when I installed a version for all users, I was able to uninstall from the account used for automation successfully. Thank you for the help on this issue. However, for installation the account being used in automation has administrative access for the system and yet fails with exit code 3. Installation is working only when we provide a specific user account in automation. Can you please suggest a resolution for this issue. Also, with the approach of using msiexec.exe to uninstall different components of python version, though all the components are uninstalled successfully(executables, core interpreter, test suite, standard library, etc. ) but still an entry for this version shows in the control panel with the options: Modify, repair and uninstall. I am unable to identify which component has still remained as a part of the installer. Please help me with this issue. Thanks, Tripura From: Barry Sent: 03 May 2024 22:34 To: Tripura Seersha Cc: python-list@python.org Subject: Re: Issues with uninstalling python versions on windows server > On 3 May 2024, at 17:43, Tripura Seersha via Python-list > wrote: > > Hi Team, > > I am working on an automation related to uninstalling and installing python > versions on different windows servers. > > I have observed that uninstallation is working only with the account/login > using which the python version is installed. But for automation, we are not > aware which account is being used for installation on different machines. I would guess that this is because you installed for the user not for all-users. If true fix your install to do it for all-users and you should be able to uninstall as any user. But this will require admin privs for both install and uninstall. As assume you can find out how to bet the admin priv required for your automation. Barry > > Also, with the approach of using msiexec.exe to uninstall different > components of python version, though all the components are uninstalled > successfully but still an entry for this version shows in the control panel > with the options: Modify, repair and uninstall. I am unable to identify which > component has still remained as a part of the installer. > > Could you please help me resolve these issues. > > Thanks, > Tripura > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
[RELEASE] Python 3.13.0 beta 1 released
After a little bit of excitement discovering new bugs during the release, *it’s done*: 3.13.0 beta 1 is released, the 3.13 branch has been created, and features for 3.13 are frozen! The main branch is now 3.14.0a0. https://www.python.org/downloads/release/python-3130b1/ *This is a beta preview of Python 3.13* Python 3.13 is still in development. This release, 3.13.0b1, is the first of four beta release previews of 3.13. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release. We *strongly encourage* maintainers of third-party Python projects to *test with 3.13* during the beta phase and report issues found to the Python bug tracker <https://github.com/python/cpython/issues> as soon as possible. While the release is planned to be feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (Tuesday 2024-07-30). Our goal is to have no ABI changes after beta 4 and as few code changes as possible after 3.13.0rc1, the first release candidate. To achieve that, it will be *extremely important* to get as much exposure for 3.13 as possible during the beta phase. Please keep in mind that this is a preview release and its use is *not* recommended for production environments. <https://discuss.python.org/t/python-3-13-0b1-now-available/52891#major-new-features-of-the-313-series-compared-to-312-1>Major new features of the 3.13 series, compared to 3.12 Some of the new major new features and changes in Python 3.13 are: <https://discuss.python.org/t/python-3-13-0b1-now-available/52891#new-features-2>New features - A new and improved interactive interpreter <https://docs.python.org/3.13/whatsnew/3.13.html#a-better-interactive-interpreter>, based on PyPy <https://pypy.org>’s, featuring multi-line editing and color support, as well as colorized exception tracebacks <https://docs.python.org/3.13/whatsnew/3.13.html#improved-error-messages> . - An *experimental* free-threaded build mode <https://docs.python.org/3.13/whatsnew/3.13.html#free-threaded-cpython>, which disables the Global Interpreter Lock, allowing threads to run more concurrently. - A preliminary, *experimental* JIT <https://docs.python.org/3.13/whatsnew/3.13.html#experimental-jit-compiler>, providing the ground work for significant performance improvements. - The (cyclic) garbage collector is now incremental <https://docs.python.org/3.13/whatsnew/3.13.html#incremental-garbage-collection>, which should mean shorter pauses for collection in programs with a lot of objects. - A modified version of mimalloc <https://github.com/microsoft/mimalloc> is now included, optional but enabled by default if supported by the platform, and required for the free-threaded build mode. - Docstrings now have their leading indentation stripped <https://docs.python.org/3.13/whatsnew/3.13.html#other-language-changes>, reducing memory use and the size of .pyc files. (Most tools handling docstrings already strip leading indentation.) - The dbm module <https://docs.python.org/3.13/library/dbm.html> has a new dbm.sqlite3 backend <https://docs.python.org/3.13/whatsnew/3.13.html#dbm> that is used by default when creating new files. <https://discuss.python.org/t/python-3-13-0b1-now-available/52891#typing-3> Typing - Support for type defaults in type parameters <https://peps.python.org/pep-0696/>. - A new type narrowing annotation <https://peps.python.org/pep-0742/>, typing.TypeIs. - A new annotation for read-only items in TypeDicts <https://peps.python.org/pep-0705/>. <https://discuss.python.org/t/python-3-13-0b1-now-available/52891#removals-and-new-deprecations-4>Removals and new deprecations - PEP 594 (Removing dead batteries from the standard library) <https://peps.python.org/pep-0594/> scheduled removals of many deprecated modules: aifc, audioop, chunk, cgi, cgitb, crypt, imghdr, mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau, telnetlib, uu, xdrlib, lib2to3. - Many other removals <https://docs.python.org/3.13/whatsnew/3.13.html#removed> of deprecated classes, functions and methods in various standard library modules. - C API removals <https://docs.python.org/3.13/whatsnew/3.13.html#id10> and deprecations <https://docs.python.org/3.13/whatsnew/3.13.html#id9>. (Some removals present in alpha 1 were reverted in alpha 2, as the removals were deemed too disruptive at this time.) - New deprecations <https://docs.python.org/3.13/whatsnew/3.13.html#deprecated>, most of which are scheduled for removal from Python 3.15 or 3.16. (Hey, *fellow core developer,* if
Re: Use of statement 'global' in scripts.
Thank you! From: Python-list on behalf of Greg Ewing via Python-list Sent: Wednesday, May 8, 2024 3:56 AM To: python-list@python.org Subject: Re: Use of statement 'global' in scripts. On 8/05/24 1: 32 pm, Popov, Dmitry Yu wrote: > The statement 'global', indicating variables living in the global scope, is very suitable to be used in modules. I'm wondering whether in scripts, running at the top-level invocation of the interpreter, ZjQcmQRYFpfptBannerStart This Message Is From an External Sender This message came from outside your organization. ZjQcmQRYFpfptBannerEnd On 8/05/24 1:32 pm, Popov, Dmitry Yu wrote: > The statement 'global', indicating variables living in the global scope, is > very suitable to be used in modules. I'm wondering whether in scripts, > running at the top-level invocation of the interpreter, statement 'global' is > used exactly the same way as in modules? The 'global' statement declares a name to be module-level, so there's no reason to use it at the top level of either a script or a module, since everything there is module-level anyway. You only need it if you want to assign to a module-level name from within a function, e.g. spam = 17 def f(): global spam spam = 42 f() # spam is now 42 A script is a module, so everything that applies to modules also applies to scripts. -- Greg -- https://urldefense.us/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!G_uCfscf7eWS!airWCCS1QeLAhk0AfN3VxhuV9MZkx8YBhs5Vjf89K2WZPjhCUkXt9culFzwlX1_ON0G17lukcR79-kWAsA$ -- https://mail.python.org/mailman/listinfo/python-list
Re: Use of statement 'global' in scripts.
On 8/05/24 1:32 pm, Popov, Dmitry Yu wrote: The statement 'global', indicating variables living in the global scope, is very suitable to be used in modules. I'm wondering whether in scripts, running at the top-level invocation of the interpreter, statement 'global' is used exactly the same way as in modules? The 'global' statement declares a name to be module-level, so there's no reason to use it at the top level of either a script or a module, since everything there is module-level anyway. You only need it if you want to assign to a module-level name from within a function, e.g. spam = 17 def f(): global spam spam = 42 f() # spam is now 42 A script is a module, so everything that applies to modules also applies to scripts. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
Use of statement 'global' in scripts.
Dear Sirs. The statement 'global', indicating variables living in the global scope, is very suitable to be used in modules. I'm wondering whether in scripts, running at the top-level invocation of the interpreter, statement 'global' is used exactly the same way as in modules? If there are any differences, I would really appreciate any comments on this. Regards, Dmitry Popov Lemont, IL USA -- https://mail.python.org/mailman/listinfo/python-list
Re: Issues with uninstalling python versions on windows server
Hi Barry, Yes, the install was for specific user. As suggested by you, when I installed a version for all users, I was able to uninstall from the account used for automation successfully. Thank you for the help on this issue. However, for installation the account being used in automation has administrative access for the system and yet fails with exit code 3. Installation is working only when we provide a specific user account in automation. Can you please suggest a resolution for this issue. Also, with the approach of using msiexec.exe to uninstall different components of python version, though all the components are uninstalled successfully(executables, core interpreter, test suite, standard library, etc. ) but still an entry for this version shows in the control panel with the options: Modify, repair and uninstall. I am unable to identify which component has still remained as a part of the installer. Please help me with this issue. Thanks, Tripura From: Barry Sent: 03 May 2024 22:34 To: Tripura Seersha Cc: python-list@python.org Subject: Re: Issues with uninstalling python versions on windows server > On 3 May 2024, at 17:43, Tripura Seersha via Python-list > wrote: > > Hi Team, > > I am working on an automation related to uninstalling and installing python > versions on different windows servers. > > I have observed that uninstallation is working only with the account/login > using which the python version is installed. But for automation, we are not > aware which account is being used for installation on different machines. I would guess that this is because you installed for the user not for all-users. If true fix your install to do it for all-users and you should be able to uninstall as any user. But this will require admin privs for both install and uninstall. As assume you can find out how to bet the admin priv required for your automation. Barry > > Also, with the approach of using msiexec.exe to uninstall different > components of python version, though all the components are uninstalled > successfully but still an entry for this version shows in the control panel > with the options: Modify, repair and uninstall. I am unable to identify which > component has still remained as a part of the installer. > > Could you please help me resolve these issues. > > Thanks, > Tripura > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Dialogs
On Tue, 7 May 2024 at 03:42, jak via Python-list wrote: > > Loris Bennett ha scritto: > > r...@zedat.fu-berlin.de (Stefan Ram) writes: > > > >>Me (indented by 2) and the chatbot (flush left). Lines lengths > 72! > > > > Is there a name for this kind of indentation, i.e. the stuff you are > > writing not being flush left? It is sort of contrary to > > what I think of as "normal" indentation. You seem to use it in all your > > postings, too, which hurts my brain, but I guess that's my problem :-) > > > > [snip (40 lines)] > > > > It's not just your problem. When the texts are particularly long and > complex, I happen to use Google-Translator. It makes bad translations if > the lines are interrupted by the newline, so I wrote a tool dedicated to > Stefan and to all those who indent like him. This tool takes the text > from the clipboard, removes all the superfluous spaces, combines all the > lines in one and puts the result back into the clipboard. :-D > Fun fact: His posts are completely irrelevant to people who follow the mailing list. Due to a dispute over permissions, his posts are blocked at the gateway. So all of us folks who use the mailing list never need to see the wonky indentation. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: how to discover what values produced an exception?
On Tue, 7 May 2024 at 03:38, Alan Bawden via Python-list wrote: > A good error message shouldn't withhold any information that can > _easily_ be included. Debugging is more art than science, so there is > no real way to predict what information might prove useful in solving > the crime. I emphasized "easily" because of course you have to draw the > line somewhere. Emphasis on "easily" is correct here. How easy is it to report the value of something that could be arbitrarily large? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Dialogs
Loris Bennett ha scritto: r...@zedat.fu-berlin.de (Stefan Ram) writes: Me (indented by 2) and the chatbot (flush left). Lines lengths > 72! Is there a name for this kind of indentation, i.e. the stuff you are writing not being flush left? It is sort of contrary to what I think of as "normal" indentation. You seem to use it in all your postings, too, which hurts my brain, but I guess that's my problem :-) [snip (40 lines)] It's not just your problem. When the texts are particularly long and complex, I happen to use Google-Translator. It makes bad translations if the lines are interrupted by the newline, so I wrote a tool dedicated to Stefan and to all those who indent like him. This tool takes the text from the clipboard, removes all the superfluous spaces, combines all the lines in one and puts the result back into the clipboard. :-D -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Dialogs
Stefan Ram ha scritto: r...@zedat.fu-berlin.de (Stefan Ram) wrote or quoted: translation services are gonna interpret line breaks as I just beefed up my posting program to replace "gonna". Now I won't come across like some street thug, but rather as a respectable member of human society! # replace complete words replacements =\ { rb'kind of': b'kind of', rb'trying to': b'trying to', rb'got to': b'got to', rb'gonna': b'going to', } lines =\ [ re.sub( rb"\b(" + b"|".join( replacements.keys() ) + rb")\b", lambda x: replacements[ x.group() ], line ) if len( line )and line[ 0 ]not in b'>|' else line for line in lines ] I present to you the brutality to which your posts are subjected: for(d = s = pCLipb; *s != TEXT('\0'); s++) { if(d == pCLipb) { if(*s != TEXT(' ') && *s != TEXT('\n') && *s != TEXT('\r')) *d++ = *s; } else if(*s == TEXT(' ') || *s == TEXT('\n') || *s == TEXT('\r')) { if(d[-1] != TEXT(' ')) *d++ = TEXT(' '); } else *d++ = *s; } *d = TEXT('\0'); -- https://mail.python.org/mailman/listinfo/python-list
Re: how to discover what values produced an exception?
From a practical perspective: not all values are printable (especially if printing a value results in an error: then you'd lose the original error, so, going crazy with printing of errors is usually not such a hot idea). But, if you want the values: you'd have to examine the stack, extract the values from the local variables etc. It's easier to do this interactively (unless you are in a multithreaded environment, where pdb is broken). But, you could also try to find this information automatically (by unwinding the stack to the place that generated the error, examining the local variables etc.) It's tedious and prone to errors. So, if you really want to do this automatically for every error that's going to be quite a bit of work. On Fri, May 3, 2024 at 6:58 PM Johanne Fairchild via Python-list wrote: > > How to discover what values produced an exception? Or perhaps---why > doesn't the Python traceback show the values involved in the TypeError? > For instance: > > --8<>8--- > >>> (0,0) < 4 > Traceback (most recent call last): > File "", line 1, in > TypeError: '<' not supported between instances of 'tuple' and 'int' > --8<>8--- > > It could have said something like: > > --8<>8--- > TypeError: '<' not supported between instances of 'tuple' and 'int' > in (0,0) < 4. > --8<>8--- > > We would know which were the values that caused the problem, which would > be very helpful. > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: how to discover what values produced an exception?
Thomas Passin writes: On 5/3/2024 9:56 AM, Johanne Fairchild via Python-list wrote: > How to discover what values produced an exception? Or perhaps---why > doesn't the Python traceback show the values involved in the TypeError? > For instance: > > --8<>8--- >>>> (0,0) < 4 > Traceback (most recent call last): >File "", line 1, in > TypeError: '<' not supported between instances of 'tuple' and 'int' > --8<>8--- > > It could have said something like: > > --8<>8--- > TypeError: '<' not supported between instances of 'tuple' and 'int' >in (0,0) < 4. > --8<>8--- > > We would know which were the values that caused the problem, which would > be very helpful. In this example it would not help at all to know the actual values. Knowing that you are trying to compare incomparable types is enough. In general, it absolutely can help. The programmer can sometimes recognize where a value of unexpected type came from just by looking at it, allowing her to quickly deduce just what went wrong without further investigation. A good error message shouldn't withhold any information that can _easily_ be included. Debugging is more art than science, so there is no real way to predict what information might prove useful in solving the crime. I emphasized "easily" because of course you have to draw the line somewhere. The fact that Python error messages often fail to mention the actual objects that caused the error has always annoyed me. I've always presumed that for some reason it just wasn't easy to do. And it's never been more than a minor annoyance to me. So the OP is not wrong for wishing for this. Other programming languages do it. Other Python programmers miss it. - Alan -- https://mail.python.org/mailman/listinfo/python-list
Re: Issues with uninstalling python versions on windows server
On 5/3/24 05:55, Tripura Seersha via Python-list wrote: Hi Team, I am working on an automation related to uninstalling and installing python versions on different windows servers. I have observed that uninstallation is working only with the account/login using which the python version is installed. But for automation, we are not aware which account is being used for installation on different machines. If you want to automate things properly, you need to control installation as well as uninstallation - if things are just installed via some random user account it's hard to see how you can expect later steps without that knowledge to work out. There's a fair bit of control available; if you haven't already, take a look here: https://docs.python.org/3/using/windows.html#installing-without-ui -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Dialogs
On 2024-05-02 16:34:38 +0200, Loris Bennett via Python-list wrote: > r...@zedat.fu-berlin.de (Stefan Ram) writes: > > Me (indented by 2) and the chatbot (flush left). Lines lengths > 72! > > Is there a name for this kind of indentation, i.e. the stuff you are > writing not being flush left? Ramism. > It is sort of contrary to what I think of as "normal" indentation. Stefan is well known for doing everything contrary to normal convention. 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: how to discover what values produced an exception?
On 2024-05-03 at 10:56:39 -0300, Johanne Fairchild via Python-list wrote: > How to discover what values produced an exception? Or perhaps---why > doesn't the Python traceback show the values involved in the TypeError? > For instance: > > --8<>8--- > >>> (0,0) < 4 > Traceback (most recent call last): > File "", line 1, in > TypeError: '<' not supported between instances of 'tuple' and 'int' > --8<>8--- > > It could have said something like: > > --8<>8--- > TypeError: '<' not supported between instances of 'tuple' and 'int' > in (0,0) < 4. > --8<>8--- > > We would know which were the values that caused the problem, which would > be very helpful. I'm not disagreeing that knowing the values could be useful in many cases. In the general case, though, it's not practical. Consider a function like this: def f(x, y): return g(x) < h(y) The printed values of x, y, g(x), and h(y) could all be millions of (or more) glyphs. Worse, one or more of those values could contain circular lists or similar structures. And h or g could have changed x or y. In summary, printing run-time values isn't always safe or useful. At least printing the types is safe. In the face of ambiguity, refuse to guess. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to discover what values produced an exception?
Johanne Fairchild wrote at 2024-5-3 10:56 -0300: >How to discover what values produced an exception? Or perhaps---why >doesn't the Python traceback show the values involved in the TypeError? >For instance: > >--8<>8--- >>>> (0,0) < 4 >Traceback (most recent call last): > File "", line 1, in >TypeError: '<' not supported between instances of 'tuple' and 'int' >--8<>8--- > >It could have said something like: > >--8<>8--- >TypeError: '<' not supported between instances of 'tuple' and 'int' > in (0,0) < 4. >--8<>8--- > >We would know which were the values that caused the problem, which would >be very helpful. Typically, the traceback informs you about the source code line where the exception has been raised. When the source line contains literals, you see the values. If not, then only in special (speak: rather simple) cases the knowledge of the values will help much. Usually, a more thorough analysis is required to find out the bug location and how to fix the bug. -- https://mail.python.org/mailman/listinfo/python-list
Re: how to discover what values produced an exception?
On 5/3/2024 9:56 AM, Johanne Fairchild via Python-list wrote: How to discover what values produced an exception? Or perhaps---why doesn't the Python traceback show the values involved in the TypeError? For instance: --8<>8--- (0,0) < 4 Traceback (most recent call last): File "", line 1, in TypeError: '<' not supported between instances of 'tuple' and 'int' --8<>8--- It could have said something like: --8<>8--- TypeError: '<' not supported between instances of 'tuple' and 'int' in (0,0) < 4. --8<>8--- We would know which were the values that caused the problem, which would be very helpful. In this example it would not help at all to know the actual values. Knowing that you are trying to compare incomparable types is enough. -- https://mail.python.org/mailman/listinfo/python-list
Re: Issues with uninstalling python versions on windows server
> On 3 May 2024, at 17:43, Tripura Seersha via Python-list > wrote: > > Hi Team, > > I am working on an automation related to uninstalling and installing python > versions on different windows servers. > > I have observed that uninstallation is working only with the account/login > using which the python version is installed. But for automation, we are not > aware which account is being used for installation on different machines. I would guess that this is because you installed for the user not for all-users. If true fix your install to do it for all-users and you should be able to uninstall as any user. But this will require admin privs for both install and uninstall. As assume you can find out how to bet the admin priv required for your automation. Barry > > Also, with the approach of using msiexec.exe to uninstall different > components of python version, though all the components are uninstalled > successfully but still an entry for this version shows in the control panel > with the options: Modify, repair and uninstall. I am unable to identify which > component has still remained as a part of the installer. > > Could you please help me resolve these issues. > > Thanks, > Tripura > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
how to discover what values produced an exception?
How to discover what values produced an exception? Or perhaps---why doesn't the Python traceback show the values involved in the TypeError? For instance: --8<>8--- >>> (0,0) < 4 Traceback (most recent call last): File "", line 1, in TypeError: '<' not supported between instances of 'tuple' and 'int' --8<>8--- It could have said something like: --8<>8--- TypeError: '<' not supported between instances of 'tuple' and 'int' in (0,0) < 4. --8<>8--- We would know which were the values that caused the problem, which would be very helpful. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Dialogs (Posting On Python-List Prohibited)
Lawrence D'Oliveiro writes: > Assume you have an expression "s.replace('a','b').replace('c','d'). > replace('e','f').replace('g','h')". Its value is a string which > is the value of s, but with "a" replaced by "b", "c" replaced by > "d", "e" replaced by "f" and "g" replaced by "h". How to modify > this expression, so that "a", "c", "e", and "g", respectively, > are replaced only if they are words (but not parts of words)? import re replacements = (("a", "b"), ("c", "d"), ("e", "f"), ("g", "h")) text = "this be a test g eg" "".join \ ( repl.get(s, s) for repl in (dict(replacements),) for s in re.split("\\b(" + "|".join(re.escape(s[0]) for s in replacements) + ")\\b", text) ) How about just: repl = { "a" : "b", "c" : "d", "e" : "f", "g" : "h", } "".join(repl.get(s, s) for s in re.split(r"\b", text)) - Alan -- https://mail.python.org/mailman/listinfo/python-list
Re: Python Dialogs
r...@zedat.fu-berlin.de (Stefan Ram) writes: > Me (indented by 2) and the chatbot (flush left). Lines lengths > 72! Is there a name for this kind of indentation, i.e. the stuff you are writing not being flush left? It is sort of contrary to what I think of as "normal" indentation. You seem to use it in all your postings, too, which hurts my brain, but I guess that's my problem :-) [snip (40 lines)] -- This signature is currently under constuction. -- https://mail.python.org/mailman/listinfo/python-list
Issues with uninstalling python versions on windows server
Hi Team, I am working on an automation related to uninstalling and installing python versions on different windows servers. I have observed that uninstallation is working only with the account/login using which the python version is installed. But for automation, we are not aware which account is being used for installation on different machines. Also, with the approach of using msiexec.exe to uninstall different components of python version, though all the components are uninstalled successfully but still an entry for this version shows in the control panel with the options: Modify, repair and uninstall. I am unable to identify which component has still remained as a part of the installer. Could you please help me resolve these issues. Thanks, Tripura -- https://mail.python.org/mailman/listinfo/python-list
Re: UTF_16 question
Richard Damon ha scritto: On Apr 29, 2024, at 12:23 PM, jak via Python-list wrote: Hi everyone, one thing that I do not understand is happening to me: I have some text files with different characteristics, among these there are that they have an UTF_32_le coding, utf_32be, utf_16_le, utf_16_be all of them without BOM. With those utf_32_xx I have no problem but with the UTF_16_xx I have. If I have an utf_16_le coded file and I read it with encoding='utf_16_le' I have no problem I read it, with encoding='utf_16_be' I can read it without any error even if the data I receive have the inverted bytes. The same thing happens with the utf_16_be codified file, I read it, both with encoding='utf_16_be' and with 'utf_16_le' without errors but in the last case the bytes are inverted. What did I not understand? What am I doing wrong? thanks in advance -- https://mail.python.org/mailman/listinfo/python-list That is why the BOM was created. A lot of files can be “correctly” read as either UTF-16-LE or UTF-1-BE encoded, as most of the 16 bit codes are valid, so unless the wrong encoding happens to hit something that is invalid (most likely something looking like a Surrogage Pair without a match), there isn’t an error in reading the file. The BOM character was specifically designed to be an invalid code if read by the wrong encoding (if you ignore the possibility of the file having a NUL right after the BOM) If you know the files likely contains a lot of “ASCII” characters, then you might be able to detect that you got it wrong, due to seeing a lot of 0xXX00 characters and few 0x00XX characters, but that doesn’t create an “error” normally. Thanks to you too for the reply. I was actually looking for a way to distinguish "utf16le" texts from "utf16be" ones. Unfortunately, whoever created this log file archive thought that the BOM was not important and so omitted it. Now they want to switch to "utf8 " and also save the previous. Fortunately I can be sure that the text of the log files is in some European language, so after converting the file to "utf8" I make sure that most of the bytes are less than the value 0x7F and if not I reconvert them by replacing "utf16 " "le" with "be" or vice versa. The strategy seems to be working. In the future, by writing files in "utf8" they will no longer have problems like this. -- https://mail.python.org/mailman/listinfo/python-list
Re: UTF_16 question
> On Apr 29, 2024, at 12:23 PM, jak via Python-list > wrote: > > Hi everyone, > one thing that I do not understand is happening to me: I have some text > files with different characteristics, among these there are that they > have an UTF_32_le coding, utf_32be, utf_16_le, utf_16_be all of them > without BOM. With those utf_32_xx I have no problem but with the > UTF_16_xx I have. If I have an utf_16_le coded file and I read it with > encoding='utf_16_le' I have no problem I read it, with > encoding='utf_16_be' I can read it without any error even if the data I > receive have the inverted bytes. The same thing happens with the > utf_16_be codified file, I read it, both with encoding='utf_16_be' and > with 'utf_16_le' without errors but in the last case the bytes are > inverted. What did I not understand? What am I doing wrong? > > thanks in advance > > -- > https://mail.python.org/mailman/listinfo/python-list That is why the BOM was created. A lot of files can be “correctly” read as either UTF-16-LE or UTF-1-BE encoded, as most of the 16 bit codes are valid, so unless the wrong encoding happens to hit something that is invalid (most likely something looking like a Surrogage Pair without a match), there isn’t an error in reading the file. The BOM character was specifically designed to be an invalid code if read by the wrong encoding (if you ignore the possibility of the file having a NUL right after the BOM) If you know the files likely contains a lot of “ASCII” characters, then you might be able to detect that you got it wrong, due to seeing a lot of 0xXX00 characters and few 0x00XX characters, but that doesn’t create an “error” normally. -- https://mail.python.org/mailman/listinfo/python-list
Re: UTF_16 question
Stefan Ram ha scritto: jak wrote or quoted: I read it, both with encoding='utf_16_be' and with 'utf_16_le' without errors but in the last case the bytes are inverted. I think the order of the octets (bytes) is exactly the difference between these two encodings, so your observation isn't really surprising. The computer can't report an error here since it can't infer the correct encoding from the file data. It's like that koan: "A bit has the value 1. What does that mean?". Understood. They are just 2 bytes and there is no difference between them. Thank you. -- https://mail.python.org/mailman/listinfo/python-list
UTF_16 question
Hi everyone, one thing that I do not understand is happening to me: I have some text files with different characteristics, among these there are that they have an UTF_32_le coding, utf_32be, utf_16_le, utf_16_be all of them without BOM. With those utf_32_xx I have no problem but with the UTF_16_xx I have. If I have an utf_16_le coded file and I read it with encoding='utf_16_le' I have no problem I read it, with encoding='utf_16_be' I can read it without any error even if the data I receive have the inverted bytes. The same thing happens with the utf_16_be codified file, I read it, both with encoding='utf_16_be' and with 'utf_16_le' without errors but in the last case the bytes are inverted. What did I not understand? What am I doing wrong? thanks in advance -- https://mail.python.org/mailman/listinfo/python-list
Changing path to python in pip.exe, ipython.exe, etc
I am building a python work environment where - i build python from sources - install pip with the wheel bundled with python - then install things with pip, like Jupyter That environment is then deployed on various machines, at various installation folders. One issue I encounter, is the path to python in scripts like pip, ipython, jupyter, etc is the original path where python is installed. On linux, i can just do some sed in the problematic scripts. On windows however, those scripts are python embedded in an EXE. Probably generated by the same tool, as they all have a similar size and a structure of an exe that contains a compressed __main__.py that launch the relevant python module for the command. What is the tool that creates those executables, and is there a way to regenerate them from the python that has been deployed somewhere else, so they point to the correct final path to python on that machine? Since pip is able to create ipython.exe with path to my python embedded for example, i assume i already have all i need in my python installation to regenerate them? -- https://mail.python.org/mailman/listinfo/python-list
ANN: Python Meeting Düsseldorf - 17.04.2024
/This announcement is in German since it targets a local user group//meeting in Düsseldorf, Germany/ Ankündigung Python Meeting Düsseldorf - April 2024 <https://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2024-04-17> Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosphäre. *17.04.2024, 18:00 Uhr* Raum 1, 2.OG im Bürgerhaus Stadtteilzentrum Bilk <http://www.duesseldorf.de/jugendamt/fam/famfoe/bueh/ac/index.shtml> Düsseldorfer Arcaden <http://www.duesseldorf-arcaden.de/anfahrt.html>, Bachstr. 145, 40217 Düsseldorf <http://maps.google.com/maps?q=51.209169,6.775339=c=51.209353,6.775272=11,177.96,,0,0.79=51.209412,6.77577=UTF8=m=0=0NGUHHHEpGGMCcqpf3Gmbw=17> Programm Bereits angemeldete Vorträge: * Marc-André Lemburg: /*Advanced parsing structured data* with Python's new match statement / * Jens Diemer: /Anbindung von *Tinkerforge* in Home Assistant / * Charlie Clark: /Eine kleine *Datenanalyse */ * Detlef Lannert: /Überblick über *CLI-Frameworks*/ Weitere Vorträge können gerne noch angemeldet werden. Bei Interesse, bitte unter i...@pyddf.de melden. Startzeit und Ort Wir treffen uns um 18:00 Uhr im Bürgerhaus in den Düsseldorfer Arcaden. Das Bürgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der Düsseldorfer Arcaden. Über dem Eingang steht ein großes "Schwimm’ in Bilk" Logo. Hinter der Tür direkt links zu den zwei Aufzügen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. >>> Eingang in Google Street View <http://bit.ly/11sCfiw> *⚠️ Wichtig*: Bitte nur dann anmelden, wenn ihr absolut sicher seid, dass ihr auch kommt. Angesichts der begrenzten Anzahl Plätze, haben wir kein Verständnis für kurzfristige Absagen oder No-Shows. Einleitung Das Python Meeting Düsseldorf <http://pyddf.de/> ist eine regelmäßige Veranstaltung in Düsseldorf, die sich an Python Begeisterte aus der Region wendet. Einen guten Überblick über die Vorträge bietet unser PyDDF YouTube-Kanal <http://www.youtube.com/pyddf/>, auf dem wir Videos der Vorträge nach den Meetings veröffentlichen. Veranstaltet wird das Meeting von der eGenix.com GmbH <https://www.egenix.com/>, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research <http://www.clark-consulting.eu/>, Düsseldorf: Format Das Python Meeting Düsseldorf <http://pyddf.de/> nutzt eine Mischung aus (Lightning) Talks und offener Diskussion. Vorträge können vorher angemeldet werden, oder auch spontan während des Treffens eingebracht werden. Ein Beamer mit HDMI und FullHD Auflösung steht zur Verfügung. (Lightning) Talk Anmeldung bitte formlos per EMail an i...@pyddf.de <mailto:i...@pyddf.de?subject=AnmeldungLightningTalkPythonMeetingDsseldorf> Kostenbeteiligung Das Python Meeting Düsseldorf <http://pyddf.de/> wird von Python Nutzern für Python Nutzer veranstaltet. Da Tagungsraum, Beamer, Internet und Getränke Kosten produzieren, bitten wir die Teilnehmer um einen Beitrag in Höhe von EUR 10,00 inkl. 19% Mwst. Schüler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir möchten alle Teilnehmer bitten, den Betrag in bar mitzubringen. Anmeldung Da wir nur 25 Personen in dem angemieteten Raum empfangen können, möchten wir bitten, sich vorher anzumelden. *Meeting Anmeldung* bitte per Meetup <https://www.meetup.com/Python-Meeting-Dusseldorf/> Weitere Informationen Weitere Informationen finden Sie auf der Webseite des Meetings: https://pyddf.de/ Viel Spaß ! -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Experts (#1, Apr 15 2024) Python Projects, Coaching and Support ...https://www.egenix.com/ Python Product Development ...https://consulting.egenix.com/ ::: We implement business ideas - efficiently in both time and costs ::: eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 https://www.egenix.com/company/contact/ https://www.malemburg.com/ -- https://mail.python.org/mailman/listinfo/python-list
Re: help: pandas and 2d table
]" are the first and second column, respectively, of that DataFrame. These then are zipped to get the desired form as a list of pairs. And this is a technique very similar to reverse engineering. Thanks for the explanation and examples. All this is really clear and I was able to follow it easily because I have already written a version of this code in C without any kind of external library that uses the .CSV version of the table as data ( 234 code lines :^/ ). -- https://mail.python.org/mailman/listinfo/python-list
Re: help: pandas and 2d table
Stefan Ram ha scritto: df = df.where( df == 'zz' ).stack().reset_index() result ={ 'zz': list( zip( df.iloc[ :, 0 ], df.iloc[ :, 1 ]))} Since I don't know Pandas, I will need a month at least to understand these 2 lines of code. Thanks again. -- https://mail.python.org/mailman/listinfo/python-list
Custom importer and errors
Hi folks! I'd like to split my package tree into several IDE projects and build a custom importer to import 'top.child1.child2' from the directory /top.child1.child2/__init__.py so basically replacing the dots with slashes and having the package content lying directly in the project folder. I have come up with this: === usercustomize.py === 1 import sys 2 from importlib.machinery import ModuleSpec 3 from pathlib import Path 4 5 Loader = type(__spec__.loader) 6 7 class IdeHelper: 8 @classmethod 9 def find_spec(cls, name, path, target=None): 10 for dirname in sys.path: 11 dirobj = Path(dirname) 12 if dirobj.name == name: 13 break 14 else: 15 return None 16 origin = str(dirobj.joinpath('__init__.py').absolute()) 17 ret = ModuleSpec(name, Loader(name, origin), origin=origin) 18 return ret 19 20 sys.meta_path.append(IdeHelper) which I'm on the right direction with. Unfortunately, I'm getting errors while importing a subpackage. With 'import top.child1' the error is ModuleNotFoundError: No module named 'top.child1'; 'top' is not a package whereas with 'from top import child1' the error changes to ImportError: cannot import name 'child1' from 'top' (unknown location) How can I make this work? Best wishes, Fabiano -- https://mail.python.org/mailman/listinfo/python-list
Re: help: pandas and 2d table
On Sat, Apr 13, 2024 at 1:10 PM Mats Wichmann via Python-list < python-list@python.org> wrote: > On 4/13/24 07:00, jak via Python-list wrote: > > doesn't Pandas have a "where" method that can do this kind of thing? Or > doesn't it match what you are looking for? Pretty sure numpy does, but > that's a lot to bring in if you don't need the rest of numpy. > > pandas.DataFrame.where — pandas 2.2.2 documentation (pydata.org) <https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.where.html#pandas.DataFrame.where> -- https://mail.python.org/mailman/listinfo/python-list
Re: help: pandas and 2d table
On 4/13/24 07:00, jak via Python-list wrote: Stefan Ram ha scritto: jak wrote or quoted: Would you show me the path, please? I was not able to read xls here, so I used csv instead; Warning: the script will overwrite file "file_20240412201813_tmp_DML.csv"! import pandas as pd with open( 'file_20240412201813_tmp_DML.csv', 'w' )as out: print( '''obj,foo1,foo2,foo3,foo4,foo5,foo6 foo1,aa,ab,zz,ad,ae,af foo2,ba,bb,bc,bd,zz,bf foo3,ca,zz,cc,cd,ce,zz foo4,da,db,dc,dd,de,df foo5,ea,eb,ec,zz,ee,ef foo6,fa,fb,fc,fd,fe,ff''', file=out ) df = pd.read_csv( 'file_20240412201813_tmp_DML.csv' ) result = {} for rownum, row in df.iterrows(): iterator = row.items() _, rowname = next( iterator ) for colname, value in iterator: if value not in result: result[ value ]= [] result[ value ].append( ( rowname, colname )) print( result ) In reality what I wanted to achieve was this: what = 'zz' result = {what: []} for rownum, row in df.iterrows(): iterator = row.items() _, rowname = next(iterator) for colname, value in iterator: if value == what: result[what] += [(rowname, colname)] print(result) In any case, thank you again for pointing me in the right direction. I had lost myself looking for a pandas method that would do this in a single shot or almost. doesn't Pandas have a "where" method that can do this kind of thing? Or doesn't it match what you are looking for? Pretty sure numpy does, but that's a lot to bring in if you don't need the rest of numpy. -- https://mail.python.org/mailman/listinfo/python-list
Re: help: pandas and 2d table
Stefan Ram ha scritto: jak wrote or quoted: Would you show me the path, please? I was not able to read xls here, so I used csv instead; Warning: the script will overwrite file "file_20240412201813_tmp_DML.csv"! import pandas as pd with open( 'file_20240412201813_tmp_DML.csv', 'w' )as out: print( '''obj,foo1,foo2,foo3,foo4,foo5,foo6 foo1,aa,ab,zz,ad,ae,af foo2,ba,bb,bc,bd,zz,bf foo3,ca,zz,cc,cd,ce,zz foo4,da,db,dc,dd,de,df foo5,ea,eb,ec,zz,ee,ef foo6,fa,fb,fc,fd,fe,ff''', file=out ) df = pd.read_csv( 'file_20240412201813_tmp_DML.csv' ) result = {} for rownum, row in df.iterrows(): iterator = row.items() _, rowname = next( iterator ) for colname, value in iterator: if value not in result: result[ value ]= [] result[ value ].append( ( rowname, colname )) print( result ) In reality what I wanted to achieve was this: what = 'zz' result = {what: []} for rownum, row in df.iterrows(): iterator = row.items() _, rowname = next(iterator) for colname, value in iterator: if value == what: result[what] += [(rowname, colname)] print(result) In any case, thank you again for pointing me in the right direction. I had lost myself looking for a pandas method that would do this in a single shot or almost. -- https://mail.python.org/mailman/listinfo/python-list