« first day (1919 days earlier)      last day (3030 days later) » 

12:08 AM
Anyone interested in wasting some time on reviewing a PR on GH?
 
12:18 AM
Ok I'll just spam it - github.com/anybrew/anybrew/pull/1
 
DSM
12:29 AM
No time to read it, but double underscore prefixes are only used to bypass name mangling. No point in using them so often.
 
Is it against some commonly accepted paradigm? I have no idea - my background is languages where exposing internals is considered a sin :D
 
DSM
If you really want to indicate that something is private and not meant to be touched, convention is to use a single underscore prefix. It doesn't do anything (well, except for some import stuff), but everybody recognizes it. Double underscore prefixes don't make things private either, they just name mangle to make it a little harder to do for inheritance purposes, and it uglifies your code immensely.
 
12:45 AM
Okay, point taken! Thanks!
 
 
2 hours later…
2:39 AM
@Matiss I recall many instances of users being quite confused by the name-mangling invoked by double-underscores. If I recall correctly, PEP 8 used to discourage using it, but now it is ambivalent. I would suggest that you know what it does but otherwise avoid it, unless it solves some problem very elegantly (and don't go looking for it).
 
Hello
I'm new here in chat.
 
Welcome, be sure to read the room rules to avoid avoidable avoidables.
@Matiss and let me point out that you can still have name collisions if you subclass an object of the same name, so it doesn't guarantee against name collisions.
 
3:32 AM
@OneRaynyDay OpenCV 3 now supports Python 3
 
 
2 hours later…
user559633
5:06 AM
@RobertGrant woof. reed.co.uk/average-salary if this is to be believed, it seems as if "recruitment" vastly out-pays engineering, with engineering being below sales and marketing.
 
7:20 AM
@Matiss In Python we have a saying: "We're all consenting adults here". So rather than the language making it impossible for private attributes to be accessed directly we just use the leading underscore to indicate that an attribute is private and that you should only touch it directly if you know exactly what you're doing.
 
@PM2Ring terrible but yeah
 
Why is it terrible? It means that Python classes can be a lot less verbose than their Java equivalents.
 
@PM2Ring one word more verboseness is not an issue.
underscores before members is a hack and all hacks are bad
 
I prefer to see the leading underscore as a mere naming convention rather than as a hack.
 
anyways, it's not a big deal.
 
7:33 AM
As for verbosity, it's not just the lack of a private keyword. Python's attitude means that we don't normally write getter or setter methods in Python: we just access the attributes directly. But if you do need special behaviour when getting or setting attributes, then Python lets you write getters & setters that do their job invisibly, so the caller can still treat them as simple attribute accesses.
 
user559633
@khajvah how is it terrible? why would you want a dynamic language to nanny you?
 
@PM2Ring How is accessing it directly different than just making it pubic in C++ or Java?
@tristan normally, I wouldn't want a dynamic language :)
but I like Python
 
@khajvah It isn't. :)
I can understand that you find Python's lack of privacy concerning, but please try to see it as a feature rather than as a flaw. Guido left privacy out of Python as an intentional part of the language design, not because he was too lazy to implement it, or because he wanted to reduce the overheads that would be incurred.
rbrb
 
user559633
7:56 AM
@khajvah you want a language that assumes you know what you're doing, but also makes you protect yourself from yourself?
 
user559633
if you wouldn't want a language that's dynamic and not enforcing of privacy, i'm not really sure why you'd like python
 
user559633
first one wasn't meant to be rude -- i'm just not sure why you'd like python if you don't like what's basically why people use it
 
8:12 AM
> you want a language that assumes you know what you're doing
that's a bad assumption, although private/public keyword is not a big deal as I said.
dynamic nature of it caused many time consuming debugging(maybe I am doing something wrong).
@tristan I used to complain a lot but I can complain about every language, so I just chose to take it :D
 
There's no harm in making constructive criticism of a language. Who knows, it may lead you to create your own language that behaves how you want it to. And if other people feel the same way they'll use your language too.
OTOH, complaining about aspects of Python that most of its user consider to be positive features is probably not very fruitful in a Python chat room. :)
 
yeah, I understand
 
8:36 AM
Is there a standard lib function that efficiently converts a string to \x escape sequences? The following is pretty simple, but I guess it'd be faster if the conversion loop happened at C speed.
''.join([r'\x%02x' % ord(u) for u in some_string])
A less readable option:
s = iter(some_string.encode('hex'))
a = ''.join([r'\x%s%s'%t for t in zip(s,s)])
 
8:52 AM
cbg
@PM2Ring all of them?
@PM2Ring sure there is a codec
also you're not talking about string, you're talking about bytes
>>> 'asfdölöä'.encode('string_escape')
'asfd\\xc3\\xb6l\\xc3\\xb6\\xc3\\xa4'
does not encode all of them of course, but why'd you want that?
 
user559633
@khajvah there's inference and hungarian notation and writing your code in such a way that will lead to appropriate flows of types
 
@khajvah I am one who agrees with you that the lack of privacy is not only a good thing :D
 
user559633
that's the path to getters and setters
 
user559633
which is the path to dealing with friend functions
 
9:31 AM
@AnttiHaapala Nice. Sorry for my Python2isms. ;) I don't need it to escape everything, but I kinda do need it to escape things like forward slashes. I thought it might be a useful way to handle this U&L question
 
9:53 AM
I am getting ImportError: cannot import name 'util' from django.forms. is this an old-new django compatibility issue?
it seems it is
 
10:19 AM
1
Q: python magic can't identify unicode filename

Pruthvi RajIn my small project I had to identify the type of files in the directory. So I went with python-magic module and did the following: from Tkinter import Tk from tkFileDialog import askdirectory def getDirInput(): root = Tk() root.withdraw() return askdirectory() di = getDirInput() pr...

 
@PM2Ring just no...
 
libmagic seems to fail to identify type of a file with unicode filename, any ideas guys?
 
@vaultah okay I didn't know we shouldn't , I'll refrain from now on, just wanted to see if anyone here knows an answer :). Sorry
 
@AnttiHaapala Yeah, I guess it's a bit kludgey.
 
10:22 AM
regex is quoted with re.quote
well but that is replacement
for that just use perl :D
 
hello :)
 
hello bob :)
 
using sublimetext2, got this eof when reading line problem, installed Sublimerepl, restarted teh whole thing but the error persists
 
0
A: Is there a way to prevent sed from interpreting the replacement string?

Antti HaapalaYou can use Perl instead of sed with -p (assume loop over input) and -e (give program on command line). With Perl you can access environment variables without interpolating these in shell. Note that the variable needs to be exported: export VAR='hi/' perl -p -e 's/KEYWORD/$ENV{VAR}/g' somefile ...

@PM2Ring ^
 
fname = raw_input('Enter file name: ')
EOFError: EOF when reading a line
 
10:30 AM
@hmmmbob you do not have a console / stdin
(what environment are you using)
 
@AnttiHaapala I don't know perl, but that looks good. Hopefully the OP will agree...
 
@PM2Ring perl was originally a single-box replacement for sed/awk etc.
 
environment, i am using python 2.7 installed via anaconda on windows 10
 
doens't explain it yet
how do you run that program
@PM2Ring see also a2p, s2p
 
control B ?
 
If this program is invoked with the name s2p it will act as a sed-to-Perl translator. After option processing (all other arguments are ignored), a Perl program is printed on standard output, which will process the input stream (as read from all arguments) in the way defined by the sed script and the option setting used for the translation.
 
@AnttiHaapala Wow! I had no idea that those commands existed. But it's nice to see that I have them installed. :)
 
@vaultah dv, cv
and notably, if the syntax error were fixed, that code would also "work"
 
11:22 AM
antti you have any suggestion for my problem ?
 
Hey, I'm wondering if some advice in a certain question is actually good....
stackoverflow.com/questions/674304/pythons-use-of-new-and-init < I have a problem very similar to this (also a class-scope-dictionary-variable, to which objects are added during __init__(self, name, **kwargs), I then need to make sure I don't add -or create- the "same (=same name)" object twice.
The question remarks that using __new()__ is NOT the right tool, instead a factory method/pattern should be used. Is that really the case for python? I've used factory methods a lot in JAVA but not seen them in python yet?
 
Hmm maybe I should make my own specific question for above..
 
11:37 AM
Is it possible to get python to use all my CPU cores?
I launch 8 threads using ThreadPoolExecutor yet my CPU usage doesn't exceed one core.
 
@Rishav Multiple python runs each run on a separate process (and can thus be divided as your OS wants) - but python by itself is single threaded - except of course for specific libraries (threading)
 
Oh, it seems ProcessPoolExecutor does this.
 
@paul23 It might be worth a question if you can't find what you want in the existing questions about __new__; OTOH, it might get closed as "primarily opinion-based".
My personal opinion: I think that's a suitable job for __new__, although I'd be inclined to use a simple factory function to handle it, since I don't like messing with __new__ unless I'm deriving from a built-in type.
Also, there may be a way to do it with metaclass, but that's not my forte.
 
11:53 AM
@PM2Ring Hmm just reading an official python blog - __new__() may return an existing object, and then __init__() is called again upon that existing object.. Sounds exactly what I wish to do. I'm already using a metaclass to actually make the class iterable, so I might also overload __call__() - which can prevent __new__() and __init__()` altogether and directly modify the variables in the existing object.
I wonder however how many people will get terribly confused (myself included) by doing that latter option though.
It's btw an extension to the code written here: stackoverflow.com/questions/34832334/…
 
When anyone sees that you're overriding __new__ they will (or should) know to proceed with caution! :)
 
@PM2Ring yes, but now talking about overwriting __call__() - which is called before creation. (But adds another layer/indirection)
See third method here for an example of the use of __call__(): stackoverflow.com/questions/6760685/…
 
@paul23 Yeah, ok. Note that's defining __call__ on a class that derives from type rather than object, i.e., it's a metaclass. Defining __call__ on a normal class is relatively innocuous: it just allows you to call a method on an (initialized) instance of your class.
 
12:21 PM
@PM2Ring yea got that, just trying to get myself familiarized with these newfound powers.
 
:)
Remember Kernighan's maxim: "Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" — The Elements of Programming Style , 2nd edition, chapter 2.
4
 
I'm always afraid that someday in python I accidentally discover and execute: for i in nuclear_arsenal: launch_missile(i)
 
@tristan hm well that makes no sense
 
There's a classic website written by a guy who was sick of people doing dumb things with pointers in C. His solution: train programmers on an OS that detonates a nuke if your program segfaults. :) Unfortunately, I can no longer find the site. :(
 
I think it was destroyed in a nuclear explosion
 
1:08 PM
cbg
the problem with C is that 90 % of C programmers cannot program in C
 
@AnttiHaapala Hi, I used to use C...
 
I used to think of myself as a reasonably competent C programmer, but I'm a bit rusty these days. Most of my C coding was done on the Amiga, but I tried to stick with ANSI/ISO C unless I was doing stuff with Amiga system calls. It used to annoy me reading C code that was needlessly littered with Microsoft crap.
FWIW, my ancient Amiga C CLI code tends to compile fine on Linux with minimal or no changes required.
 
i love comp.lang.c faq :D
 
1:25 PM
@PM2Ring that's cool
 
Although I rarely write in C these days I still have K&R 2 within arm's reach, as well as P.J. Plauger's The C Standard Library.
Thanks, Robert. It does feel nice when stuff like that happens. :)
 
though
 
I've done a tiny bit of GUI C programming on Linux: I wrote a moderately simple Mandelbrot generator. It uses X windows directly, rather than a sane GUI library. But my program doesn't have a proper GUI - just a window for showing the Mandelbrot image or the help text; all user input is via hotkeys and mouse clicks on the image itself. I got the relevant X windows code by cargo-culting a simple example program, and by poring over the relevant sections of the X windows docs.
 
C programming language is C11 now
 
Good point, Antti. My C skills are definitely antiquated.
 
1:37 PM
Oh lol I feel strange now...
(Ab)using exceptions to create recursive lookup. Well true to the pythonic EAFP..
def __getitem__(cls, item):
    try:
        v = cls._registry[item]
        return v
    except KeyError:
        for subcls in cls.__subclasses__():
            try:
                v = subcls.__getitem__(item)
                return v
            except KeyError:
                pass
        raise
 
Note that try:...except is faster than the equivalent if only when the exception isn't raised, otherwise it's much slower. So if you expect the KeyError to be raised less than (say) 5% of the time the above code is ok, otherwise you probably should rewrite it.
 
1:57 PM
@PM2Ring Hmm I tried testing before using: (cls._registry.__contains__(item) or any(c.__contains__(item) for c in cls.__subclasses__())), but profiler shows that much slower (25%)
 
Ok
 
Even for something that is only found at a depth of "3 layers" (and it "raises" 5 times before finding the item).
 
2:47 PM
Hm I seem to be breaking my d3
 
rhubarb
 
3:04 PM
@Rob Good...goooooooood...
 
:)
And by the transitive relation, fear leads to suffering
 
I would not believe that this kind of things is happening in 2016.
 
lol
 
omg, nobody else is able to write a python script from scratch, we're doomed!
No worries, people, it's all in a day's work for Python script writer man.
 
We have the source code! Oh- no. They base64 encoded it.
 
3:16 PM
I wonder how often they actually review each other (his co-workers, not even talking about higher layers); that this became a problem.
 
Likely not a software company.
 
Well in ANY field I've worked with I've yet to see a point where not at least 2 people (can) do the same thing, working together.
I'm loving the explanation on the obfuscator posted btw.
"This open source obfuscator hopes to obfuscate python scripts and make the scripts unreadable / hard to decipher, since you can somehow retrieve the source code from de-compiling the Python bytecode."
 
"Somehow" -- I have no idea why or how, but I just found that this is done, don't understand it though...
 
well, that happens
I looked at what that "obfuscator" does, and really it took 23 seconds to come to the same conclusion as the answer.
 
3:31 PM
Not my forte
 
So, it's not even an obfuscator...
 
3:54 PM
well
of course it is
it obfuscated it well enough for the asker
but very bad at it :d
a good obfuscator would make my head ache.
it would rewrite the source into something incomprehensible
 
@AnttiHaapala Actually a simple randomizing of the "wordlist", with special cases for build-in-words would make it magnitudes better.
 
the main problem is usually the moment of unpacking it, in case if it's needed.
 
 
1 hour later…
5:32 PM
@paul23 but it doesn't work for python :D
 
5:47 PM
Just read all the feedback from earlier today, thanks guys.
 
 
1 hour later…
7:09 PM
@PM2Ring that bash question was very strange
 
My refactoring of my d3 code failed. Revert to previous version :(
 
 
2 hours later…
9:35 PM
Just seen Hateful Eight. Really good stuff. Not the best Tarantino film but well worth a watch.
 
10:06 PM
so which one is the best?
 
10:24 PM
I have a question regarding the Pelican static site generator, not sure if that's okay here, but I'll ask anyway: I want to do something like {% if lang == 'nl' %} in the index.html template, but how would I go about this?
 
10:57 PM
I spent a lot of time today and yesterday working on a friend's spreadsheet parser. It was pretty cool. Did you know that the pandas DataFrame has a to_json method and the regular JSON parser doesn't know to use it, but you can subclass the JSON parser with a single method and make it work?
 

« first day (1919 days earlier)      last day (3030 days later) »