Live data from Hacker News

Migrating to Python 3 with pleasure

github.com

171–180 of 181 posts

Re: Migrating to Python 3 with pleasure

#171
post #47

Earlier quoted context omitted.

Python allows the overriding of just about every operator. For Pathlib they overrode the division operator to instead perform path addition in a platform agnostic manner.

> Python allows the overriding of just about every operator. Except the boolean operators (and, or, not). For instance __and__ overrides the binary and (&), not the boolean and.

That's True, but you _can_ override __bool__.[1]

[1] https://docs.python.org/3/reference/datamodel.html#object.__...

Re: Migrating to Python 3 with pleasure

#172
If you would like to write Python 3 but need to maintain support for any particular version of Python 2, something that I can personally recommend is using the Coconut transpiler: http://coconut-lang.org/ The Coconut language is a superset of Python 3, so any valid Python 3 is valid Coconut. But the advantage of the transpiler extends beyond the language itself, in that it can target any version of Python from 2.6 onwards on the Python 2 branch and 3.2 onwards on the Python 3 branch.

It has been really useful for me in that I want the advantages of type annotations and f-strings and other python 3.5+ features but I have to support running in an environment with only 2.6 installed. So when I target a 3.5+ version, all of those features are maintained, but when I target 2.6, the transpiler does all the work in converting to running 2.6 code for me.

Re: Migrating to Python 3 with pleasure

#173

Earlier quoted context omitted.

As I said: > Not the result set, the rows of the result set. Each row is a mapping with ordered keys.

Perhaps you are confused and mean "columns"? ("Rows of the result set" is what I was referring to.) A result set has rows, which are not in a deterministic order unless an "order by" is provided. Each row has columns. The columns are in order, obviously.

Perhaps you are confused and think I'm talking about the ordering of the result set.

I said that database query result rows are made up of ordered dictionaries. I didn't mention ordering of the result set.

Happy to keep repeating this as many times as necessary.

Re: Migrating to Python 3 with pleasure

#174

Earlier quoted context omitted.

No, I mean the rows. Each row is semantically an ordered mapping.

Shouldn’t the collection of rows be a set or list, not a dictionary? That said, you disagreed with my question then went on to show my question was on point. The “rows themself” being an ordered map means you are referring to the columns, the order being set by the SELECT clause or table definition order (in case of wildcard). That said, I personally feel iterating over table columns in that way to be a “bad code sme…

> Shouldn’t the collection of rows be a set or list, not a dictionary?

I didn't mention the collection of rows, I mentioned the rows themselves.

> The “rows themself” being an ordered map means you are referring to the columns

No, it means I'm referring to the rows themselves.

The rows themselves are each ordered mappings.

Hope this helps to clarify things. Happy to keep repeating this as many times as necessary.

Re: Migrating to Python 3 with pleasure

#175

Earlier quoted context omitted.

No, I mean the rows. Each row is semantically an ordered mapping.

Shouldn’t the collection of rows be a set or list, not a dictionary? That said, you disagreed with my question then went on to show my question was on point. The “rows themself” being an ordered map means you are referring to the columns, the order being set by the SELECT clause or table definition order (in case of wildcard). That said, I personally feel iterating over table columns in that way to be a “bad code sme…

I think the confusion is your use of “columns” or “columns of the row” to refer to attribute-value pairs that make up the row.

Re: Migrating to Python 3 with pleasure

#176
post #170
post #167

Earlier quoted context omitted.

Tradition? ;) I only use python for deep learning, which is not really that intensive in terms of code. Also most of the code out there for deep learning works on both python 2 and 3. Also, your phrasing invites the question. Why on earth would I use a new feature in a turing complete language? Unless using the new feature results in tangible improvements in my code, I don't see a reason to use it.

I really like this one. “So you already have your turing complete language! What else do you need?”

That's not the point. The point is there is no reason to use an extra language feature unless it provides a tangible improvement in the code.

In fact, there are lots of reasons not to use an extra language feature that doesn't provide tangible improvements in code, including maintainability, ease of reading code, and portability in python's case.

Re: Migrating to Python 3 with pleasure

#177

Earlier quoted context omitted.

Other OSes just install a “python3” binary, I’d expect Apple to do the same.

Sure. What I'm saying is I expect python/python2 to be gone soon after that.

I’m not so sure; /System/Library/Frameworks links for Python versions have been stable for a very long time (which surprised me at first but I imagine Apple has plenty of stuff of their own that uses Python). Even though they’ve since hacked a lot of the older versions with symbolic links to 2.7, versions back to 2.3 have valid paths.

Re: Migrating to Python 3 with pleasure

#178
post #163

Earlier quoted context omitted.

Honestly the fact that they include a system Python 2 is a huge pain. You can't add packages to it, and you shouldn't add another Python 2 interpreter to the PATH. You end up having to use virtualenv which is a stupid hack.

pip takes a --user flag that installs packages to your user's account. It's essentially global unless you have multiple users on your machine.

But there is no pip.

Re: Migrating to Python 3 with pleasure

#179

Earlier quoted context omitted.

Perhaps you are confused and mean "columns"? ("Rows of the result set" is what I was referring to.) A result set has rows, which are not in a deterministic order unless an "order by" is provided. Each row has columns. The columns are in order, obviously.

Perhaps you are confused and think I'm talking about the ordering of the result set. I said that database query result rows are made up of ordered dictionaries. I didn't mention ordering of the result set. Happy to keep repeating this as many times as necessary.

ok. We're actually saying the same thing, just in different words.

Re: Migrating to Python 3 with pleasure

#180
post #21

Earlier quoted context omitted.

TypeError: expected str, bytes or os.PathLike object, not int

This probably means that you put a path to the left, not ints on both sides.

Well, I put a path and then two ints... if you don't start with a path it's obviously just going to be division.
Post reply on HN