Quantcast
Channel: User David Z - Stack Overflow
Browsing all 49 articles
Browse latest View live
↧

Answer 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 Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

Answer 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 Article


How 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 Article

Answer 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 Article

Image may be NSFW.
Clik here to view.

What 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 Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

Creating 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer 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 Article


Answer 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 Article

Selecting 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 Article

How 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 Article
Browsing all 49 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>