Comment by David Z on Update Git submodule to latest commit on origin
@GabrielStaples Can I ask, why did you change the git pull command to include an explicit remote and branch? Does that make a difference in what the command does?
View ArticleComment by David Z on Save git output to a variable
Good point, thanks @Kildareflare! I've edited accordingly.
View ArticleComment by David Z on Are PIP packages curated? Is it safe to install them?
@Andrew (1/2) The PyPI administrators will sometimes take down malicious packages when they find out about them, especially if the malicious package seems to be taking advantage of a name similarity....
View ArticleComment by David Z on Testing class methods with pytest - error - fixture...
@Jimmy I know it's been a while, but if you're still around, would you consider posting that as an answer to better help future readers of this question?
View ArticleComment by David Z on Where to place static variables (for type definition)...
@Mattwmaster58 Which version did you get errors with? I did a quick test with every version from 3.5 to 3.11 and they all worked fine for me. (Plus, in the specific case from this answer it'd be import...
View ArticleComment by David Z on Erase whole array Python
@tcglezen That's using a different definition of "work" that was not part of the question.
View ArticleComment by David Z on Sphinx: "WARNING: py:class reference target not found"...
I don't think this is the way to go. a = bar.A and a = bar.A() are both perfectly valid Python statements to include at that point in the code, with different meanings, and you shouldn't have to change...
View ArticleComment by David Z on pip install pyqt5, it cannot go on
I found this not to be the case: I was able to run the command from ninjaphysics' answer on Linux and it completed with no problems. Maybe it depends on the pip version? (Also, I don't think the...
View ArticleComment by David Z on Finding the layers and layer sizes for each Docker image
@SherwinF Alternatively, pipe it to less -S, or save it to a file and open it in a text editor, or any of various other things one can do to work with output that's too wide for the terminal (assuming...
View ArticleComment by David Z on cp command should ignore some files
It's to match the behavior of cp -r as closely as possible. Specifically, cp -r copies regular files, directories, and links (which rsync without -l does not), but does not copy over attributes like...
View ArticleAnswer by David Z for Java color opacity
Use the Color constructor that takes a value with an alpha channel. Specifically, first you convert your color coordinates to RGB space:int rgba = Color.HSBtoRGB(H, S, B);and then add the desired...
View ArticleAnswer by David Z for How to pip install packages written in Pipfile without...
Eventually pip should be able to do this itself, at least that's what they say. Currently, that is not yet implemented.For now, a Pipfile is a TOML file, so you can use a TOML parser to extract the...
View ArticleAnswer by David Z for How can I make a public HTML folder in Ubuntu?
The other answers are on the right track with mod_userdir, but using that will give your website the base URL http://www.yourdomain.com/~username/ - for instance, a file...
View ArticleAnswer by David Z for How to ignore \n in regular expressions in python?
From the documentation:'$'Matches the end of the string or just before the newline at the end of the stringTry \Z instead.Also, any time you find yourself writing a regular expression that starts with...
View ArticleAnswer by David Z for Specify template argument by subclassing
When you write Parent<char>, the compiler effectively generates a class definition as if you had substituted char into the template text. That is, behind the scenes it's as if the parent class of...
View ArticleAnswer by David Z for jq: Find a key in a struct in an array or use default...
This jq script should do the trick:{ id, name: (first(.Tags[] | select(.Key == "Name").Value)? // "(none)")}| "\(.id) \(.name)"It works similar to your pseudocode, but it doesn't proactively defend...
View ArticleHow do I tell CMake to link in a static library in the source directory?
I have a small project with a Makefile which I'm trying to convert to CMake, mostly just to get experience with CMake. For purposes of this example, the project contains a source file (C++, though I...
View ArticleAnswer by David Z for How to calculate the time interval between two time...
Yes, definitely datetime is what you need here. Specifically, the datetime.strptime() method, which parses a string into a datetime object.from datetime import datetimes1 = '10:33:26's2 = '11:15:49' #...
View ArticleWhat is an appropriate page processing time for a web application?
I'm working on a web application, and it's getting to the point where I've got most of the necessary features and I'm starting to worry about execution speed. So I did some hunting around for...
View ArticleAnswer by David Z for How to replace an instance in __init__() with a...
You need __new__() for that. (And you also need to make it a new-style class, assuming you're using Python 2, by subclassing object.)class ClassA(object): def __new__(cls,theirnumber): if theirnumber...
View ArticleAnswer by David Z for How do I sum the first value in each tuple in a list of...
In modern versions of Python I'd suggest what SilentGhost posted (repeating here for clarity):sum(i for i, j in list_of_pairs)In an earlier version of this answer I had suggested this, which was...
View ArticleAnswer by David Z for Grouping imports together from subdirectories
Nope. The package that contains a module will not necessarily know anything about the contents of the module, so in your case accounts doesn't know anything about the User class in accounts.user. There...
View ArticleCreating Python modules from an extension with extra C data structures
I'm working on a custom Python loader that creates Python modules from a particular kind of non-Python file, let's call it a "cheese file". I'm writing my project as a C extension module because these...
View ArticleAnswer by David Z for Python: No csv.close()?
The reader is really just a parser. When you ask it for a line of data, it delegates the reading action to the underlying file object and just converts the result into a set of fields. The reader...
View ArticleAnswer by David Z for Why am I getting only 800 hashes per second?
The crypt module, like the crypt() system call that underlies it, is meant for hashing passwords, and good password hashing algorithms are designed to be slow, precisely because they want to make it...
View ArticleAnswer by David Z for How are lambdas useful?
Are you talking about lambda expressions? Likelambda x: x**2 + 2*x - 5Those things are actually quite useful. Python supports a style of programming called functional programming where you can pass...
View ArticleAnswer by David Z for Pythonic way to combine (interleave, interlace,...
There's a recipe for this in the itertools documentation (note: for Python 3):from itertools import cycle, islicedef roundrobin(*iterables):"roundrobin('ABC', 'D', 'EF') --> A D E B F C" # Recipe...
View ArticleAnswer by David Z for How to calculate the cosine similarity betwen list to...
You need to change a couple things: first, when using dot(), the last dimension of the first array needs to match the second-to-last dimension of the second array, so in your case what you probably...
View ArticleAnswer by David Z for In Python script, how do I set PYTHONPATH?
You don't set PYTHONPATH, you add entries to sys.path. It's a list of directories that should be searched for Python packages, so you can just append your directories to that...
View ArticleSelecting distinct column values in SQLAlchemy/Elixir
In a little script I'm writing using SQLAlchemy and Elixir, I need to get all the distinct values for a particular column. In ordinary SQL it'd be a simple matter ofSELECT DISTINCT `column` FROM...
View ArticleHow can I get a human-readable timezone name in Python?
In a Python project I'm working on, I'd like to be able to get a "human-readable" timezone name of the form America/New_York, corresponding to the system local timezone, to display to the user. Every...
View ArticleComment by David Z on Unable to use pipenv to install: ImportError: cannot...
This just runs a different version of pipenv (and/or uses a different version of Python). It seems that whatever version of pipenv you get when running python3 -m pipenv has a fix for this error,...
View ArticleComment by David Z on Finding process count in Linux via command line
@krzemian Sorry I didn't see this at the time! In case it's still relevant: the difference is probably coming from the wc process, which is listed in the output of ps when you have them running in...
View ArticleAnswer by David Z for mod_python publisher and pretty URLs
You would have to have an object bar.a1.a2.a3.an defined within your foo.py module. Basically, the publisher handler replaces the slashes in the URL with dots, and tries to find some Python object with...
View ArticleAnswer by David Z for How can I put an actual backslash in a string literal...
To answer your question directly, put r in front of the string.final= path + r'\xulrunner.exe '+ path + r'\application.ini'More on Python's site hereBoth string and bytes literals may optionally be...
View ArticleComment by David Z on jq pass argument as a key to new field
@somenxavier In general I would suggest asking followup questions as their own separate posts, not as comments. But since this one is quick, I'll tell you that it's because $md is part of a string, and...
View ArticleComment by David Z on Using the open() system call
Thanks! I must have missed these comments, my bad. (although it's a little surprising it took this long for someone to fix a simple typo)
View ArticleComment by David Z on distutils: How to pass a user defined parameter to...
Since distutils was removed from Python 3.12, that link is dead, but the Python 3.11 version of the page is still up, and it also exists (for now) in the setuptools documentation. The sdist source code...
View ArticleAnswer by David Z for How to execute shell script from LaTeX?
I would do something like the following (partially motivated by what Roman suggested): make your LaTeX file be\documentclass{article}\begin{document}\input{scriptoutput.tex}\end{document}and generate...
View ArticleComment by David Z on How to grow a list to fit a given capacity in Python
Ah I must have made a mistake, I'll fix it.
View Article