Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Posts tagged python
I have a nested python list structure, generated by a happily executed tolist() method on a more than 2 dimensional ndarray. How can I get back my numpy ndarray from the list?
To have a successful "training session", these should cooperate. I.e. model generates an output from the input data, the loss function says, how bad or good is it, and then the optimizer tunes...
Here I am trying to install a pip package. While installation, pip tries to compile something. With meson. Meson calls cmake. Cmake fails on a missing dependency. Then, meson fails on the fail...
My impression is that the regexps behave a little bit odd: >>> import re >>> r=re.compile("test") >>> r.match("test") <re.Match object; span=(0, 4), match='test'&g...
MWE import pandas as pd import numpy as np import matplotlib.pyplot as plt df = pd.DataFrame(np.random.rand(9, 4), columns=['a', 'b', 'c', 'd']) df.plot.bar(table=True) # don't want plot, ...
I've just started playing around with pygame and have written a small game in it, of which I'd like a review. Note that I'm not only a complete beginner in pygame, but I also have very little exper...
I'm trying to create an expandable/collapsible horizontal visualization of interlinked documents using a tree diagram that looks very similar this, where the documents spread outward from a single ...
I have Box drive on Windows. I use it as a regular folder on the computer. I can store images there. When I store a small number of images (on the order of a couple hundreds) and I do not wait lon...
A while back, I made this post about reading specified sections in a text file formatted a particular way. I've since updated the format for that file to include links at the start of arbitrary li...
I see on this PyTorch model Helsinki-NLP/opus-mt-fr-en (HuggingFace), which is an encoder-decoder model for machine translation: "bos_token_id": 0, "eos_token_id": 0, in its config.json. ...
Note: I originally posted this on Stack Overflow on Stack Exchange here however I am posting the same question here as I might be able to get a answer more quickly here. Project Euler+ #250 on H...
How can I save a plot in a file in PyCharm without changing the code? I used plt.show(), so that the plot shows like this: But how can I save a plot in a file without changing the code? I don'...
Running import onnxruntime as ort from datasets import load_dataset yields the error: (env-312) dernoncourt@pc:~/test$ python SE--test_importpb.py Traceback (most recent call last): File...
I can't run a Python file in PyCharm: why? The run icon is greyed out: I went to Run → Edit Configurations… to make sure the correct Python interpreter is selected. Debug, coverage, and profile...
I converted the PyTorch model Helsinki-NLP/opus-mt-fr-en (HuggingFace), which is an encoder-decoder model for machine translation, to ONNX using this script: import os from optimum.onnxruntime im...
I'm writing a function which reads specified sections in a text file formatted a particular way, but I'm having a hard time figuring out how to locate the last line number. Here's an example of the...
This question is about the general case of subprocess-exited-with-error. It's intended to help you understand the situation if you get an error like this, and there are some common workarounds - ...
I follow Azure's tutorial on fine-tuning GPT. I'm stuck at the deployment phase. Code: # Deploy fine-tuned model import json import requests token = '[redacted]' subscription = '[redacted...
Why is spacy word vectors showing unexpected similar words? Here is the code I am using: import spacy import numpy as np nlp=spacy.load('en_core_web_md') with open ('data/us.txt') as f: ...
I am trying to capture the content outside square brackets in groups, using this regex: (.*)\[.*?\](.*) And it works perfectly for a simple string like this: testing_[_is_]_done This is the...
I'm building a Flask application with user login functionality using Flask-WTF for form handling and Flask-Login for user authentication. However, I am unable to log in successfully. The page does ...
I want to make multiple comparisons at once, of the same type, in a Python program. For example, to check whether all of a certain group of strings are in a longer test string; or whether a specifi...
This question is adapted from a question I just helped fix up on Stack Overflow. I'm giving a different motivating example which I think will make it clearer what the requirements are and why a n...
I am trying to install the Spacy library in VSCode in a folder with a virtual environment. The output appearing in the terminal is excessively long; I will share it with a pastebin later. My versio...
I used to have some testing code for mocking a simple directory structure when working with pathlib. I recently tried to run these tests to learn that some of the internals in pathlib have changed ...
When printing Markdown text to the terminal, how can I get a bit more formatting so it looks nicer? I realize that this is a bit of a contradiction, since terminals generally use only one font. Bu...
Pytest uses fixtures. Their docs explain what fixtures do: https://docs.pytest.org/en/stable/explanation/fixtures.html But what actually is a fixture? Is there a definition for it? Is this a term ...
I'm trying to implement pytest for one of my Python Flask projects. The application is instanciated like this in appname.py def create_app(): app = Flask(__name__) app.config.from_pyfil...
I had understood that Python is supposed to come "batteries included", and that the "batteries" specifically include: the tkinter standard library, a simple GUI framework a simple IDE cal...
Suppose you have a situation where text is coming 1 word at a time, and you want to quickly show it to the user. "Quickly" is not in the sense of a performance constraint, but rather we don't want ...
What are some legitimate use cases for raising a NotImplementedError exception in Python? How can it help express a code author's intentions to aid code maintenance and/or further development of co...
My (non-Windows) operating system came with Python, but that Python didn't include Pip. I followed instructions to install Pip for the included Python, using my system's package manager. But now w...
I have already learned how to tell the Python interpreter to run my code, but the standard approach feels a little unsatisfactory. I want the user experience to be that my program starts with the a...
I tried installing Python on an old computer running Windows 8[1]. I know for a fact that there was never any previous installation of Python on the machine. The installation appeared to be success...
In Python 3.12, I noticed that some libraries seem to be missing or "deprecated": >>> import asynchat Traceback (most recent call last): File "<stdin>", line 1, in <module>...
I installed Matplotlib and tried a simple demo, but I got a warning message and no plot showed up: >>> import matplotlib.pyplot as plt >>> plt.plot([1,2,3],[4,5,6]) [<matplo...
I understand the benefits of virtual environments in general, and specifically I want to use a virtual environment so that I'll have access to Pip without exposing the system Python (i.e., included...
I already know that the pip command might not correspond to the same Python that python runs. But in my case, it seems not to exist at all. I can't even run it as a Python module: $ python -m pip ...
Suppose I have some code in a file myscript.py like: def my_function(): print("Test") What steps do I need to take in order to make my_function run? That is to say: how do I get Python to ...
I tried installing package-installation-test[1] using Pip, and it appeared to be successful. But I can't use it as advertised, either by itself or by importing it from my code: Failed attempts ...
Recently, Python updated from 3.11 to 3.12 and now all my libraries are gone. Actually they're in the old 3.11 site-packages, but now that python points to 3.12 those are not active. Every time I r...
In many other programming languages, the execution of code starts in a specifically named function (such as main) which is expected to have a specific signature, which allows that function to recei...
I've seen many examples of Python scripts that include a line that says: if __name__ == '__main__': Sometimes the following block contains a bunch of code, but other times it just makes a singl...
I have multiple installations of Python on my machine. I already know how to choose one to use to run for my code - and therefore, I could also solve the problem for third-party application code. ...
Several times now, I've seen advice in tutorials, setup/install instructions for Python-based projects, etc. to use a virtual environment to keep things organized and make it simpler to manage the ...
I have multiple installations of Python on my machine. When I run Python, what determines which installation is used? How can I control this?
I know that I can make Python code run starting from the script, but this still requires the user to have Python installed (and will still rely on configuring the system so that it can find Python ...
I found a strange expression in some Python code: from library import HOME_DIRECTORY file = HOME_DIRECTORY / "file.json" It seems to be dividing a string by another string in order to do som...
How do I trim a sorted list in Python, so that I only keep the elements greater than a certain value? For example, if I have this list: l = [1, 3, 5, 6, 7, 8] How can I efficiently get a list of...
Is there some sane way to allow Python to import from subfolders in projects that don't have a package? I have many Python programs that I implemented as Python files inside a directory, without a...