I posted that link earlier today. Summary of reactions: MooingRawr thought it was a prank, Withnail thought it was about time, I thought it's a step in the right direction.
Was there a good justification for not subclassing dict and adding __getattr__ == __getitem__? I feel like I read that it wasn't a good idea somewhere.
I find it more conveniant to access dict keys as obj.foo instead of obj['foo'], so I wrote this snippet:
class AttributeDict(dict):
def __getattr__(self, attr):
return self[attr]
def __setattr__(self, attr, value):
self[attr] = value
However, I assume there must be some...
overshadowing would be a violation of the Liskov substitution principle, and thus probably be bad OO design. Even if you promise to be super careful about it.
def frobnicate_object(obj):
"Duck typing is great! Give me an object with a foo param, that's it!"
try:
print(obj.foo)
except AttributeError:
print("You're missing a foo!")
It doesn't break dict LSP, it breaks object LSP
Just have them do types.SimpleNamespace(**input_dict)
@AnonInternational in that link you posted here they teach passing values to SQL queries using string formatting. That's very dangerous. You should pretty much never do that.
Silly noob question: I know that sudo pip install is unsafe and why, but my impression is that virtualenvs work locally in that they work inside a given subdirectory. Would pip install --user let me install stuff globally-as-far-as-my-user-is-concerned?
pip install --user should be the default , but in true python packaging style - they have been talking about it for 3 years instead of doing it. github.com/pypa/pip/issues/1668
@AndrasDeak their custom C proxy code had an error, whereby it would, like in heartbleed, copy random data outside the intended buffer from the cache into output...
We fetched a few live samples, and we observed encryption keys, cookies, passwords, chunks of POST data and even HTTPS requests for other major cloudflare-hosted sites from other users. Once we understood what we were seeing and the implications, we immediately stopped and contacted cloudflare security.
oops
@AnttiHaapala a friend told me that pirate bay uses it too
@SylentNyte if you're looking at the ratio of two integers, your most precise chance is if a[2]%b[2]==0. Otherwise floats have a method called is_integer which tells you if its value is integer. But considering floating point arithmetic, you should generally not rely on this
so my initial thought was to see if i can convert it to an int, as an int cant have decimal places so it will throw an error and i will catch it, i solved this by doing a[2] % b[2]
1. if it's longer than a few lines, consider using a pastebin or something similar 2. if you post it here: multiline messages enable a "fixed font" button on the right --> (or, ctrl+k does the same) that preserves indentation
with open(inputFilename,'r') as in_f, open(outputFilename,'w') as out_f:
lines = 0
for line in in_f:
if lines == 0:
lines+=1
else:
column = line.split(',')
print "{}\t{}\t{}".format(str(column[0]),str(column[1]),str(column[2]))
out_f.write('{}\t{}\t{}'.format(
str(column[0]),
str(column[1]),
str(column[2]))
Ok, so this gives me a "Syntax error" and it only happens when I'm trying to write
Yeah, you need to learn first. I was forced to learn it when I started using an hpc cluster, but it turned out to be an amazingly profitable investment
you might be better off with Eclipse. I don't use it (vim for me) but I know people who have large python software projects in it. Atom and Sublime are good if you use a Mac.
PEP428 says that pathlib used to be a 3rd party module, that might be a reason why os is not pathlib-aware... (?)
Hmm, PEP519 suggests that path objects are the future. So will os be changed/deprecated?
Abstract
This PEP proposes a protocol for classes which represent a file system path to be able to provide a str or bytes representation. Changes to Python's standard library are also proposed to utilize this protocol where appropriate to facilitate the use of path objects where historically only str and/or bytes file system paths are accepted. The goal is to facilitate the migration of users towards rich path objects while providing an easy way to work with code expecting str or bytes .
I guess they failed to change this part of Python's standard library to facilitate the use of path objects
hmm, my python 3.5 won't even accept a Path inside os.walk
(right, found the "3.6" part of the PEP :P)
@wim can't you try something with os.PathLike?
though I guess if it worked for something like that it would also work for a pathlib.Path
OK, here goes nothing, I'll try to install 3.6 inside a virtualenv
From that pep: "The various path-manipulation functions of os.path [9] will be updated to accept path objects. For polymorphic functions that accept both bytes and strings, they will be updated to simply use os.fspath() ."