« first day (4295 days earlier)      last day (653 days later) » 

12:26 AM
lmao
 
 
2 hours later…
 
4 hours later…
6:48 AM
@Kevin Coming back to this, according to the (condensed) grammar: eval handles a single expressions node plus padding. expressions is basically an optionally comma delimited sequence of if-else expressions, with the caveat that the latter can fall back to all other expressions of higher precedence.
So technically speaking, "technically speaking, a condition list" is technically speaking correct, technically speaking.
At least if you allow to wiggle your eyebrows a bit while saying "condition list".
 
 
1 hour later…
8:03 AM
@Mandarons please don't ask for help here with fresh questions on the main site as per our rules
 
Hello all, I am trying to import pandas into pycharm but I cannot install it via pip and it is not listed in project interpreter. I also have checked to add available packages but unfortunately none are listed. Python version is 3.7.4. I am working in a virtual workspace environment where my employer may limit my access. However I have been able to install other packages such as nbconvert, pyinstaller etc. Any help would be appreciated
 
How did you invoke pip?
 
through anaconda terminal
 
In the "Python Interpreter" view of the PyCharm preferences, you should see a listing of installed packages. Hit the + sign in the top-right to have PyCharm install packages for you.
 
Unfortunately when I do that a window opens that says available packages, but it says "nothing to show"
 
8:11 AM
How did you install nbconvert etc?
 
in anaconda prompt base pip install nbcconvert
When I do the same for pip install pandas I get an error (requires-python:>=3.7.1)
but my python version is 3.7.4
 
Since this is an anaconda environment, can you install it via conda?
FWIW, I would have expected pandas to be already installed for an anaconda environment.
 
Hm, How would I go about doing that?
Yes my last option is to have my employer reinstall pyCharm
 
9:05 AM
conda install pandas. One of the purposes of conda was to make installing the scientific stack easier, so you shouldn't really need to use pip
Also, as MisterMiyagi says, it would normally come with Anaconda unless you installed Miniconda
Have you actually activated the environment when you do your installations?
 
Honestly I'm not sure if I have activated the environment. How would I check this?
 
9:46 AM
what is the time complexity of adding a list to another list?
would it just be O(k) where k is the size of the list I'm adding?
 
yes
 
Note that lists overallocate only about len/8 so if the two lists are even roughly of same size, you won't get amortized behaviour.
It's likely to be O(n+m) for appending an m-size list to an n-size list.
The constant factor should be pretty good on that operation, though.
 
10:11 AM
@Paul you would see the environment name in brackets at the start of the command line
 
hmm, Python
 
 
1 hour later…
11:30 AM
hrngh, Python
 
11:57 AM
@Kevin That's an odd way to spell "praise"
 
Pow! Zip! Python
 
Holy Python, Batman!
 
12:13 PM
python-gnupg is quickly becoming my least favourite library
Pass it a private key and it just... does nothing. What do you want from me :'(
 
How hard would it be to make an MCVE that doesn't expose an important private key you own?
 
import gnupg
gpg = gnupg.GPG(gnupghome='current/directory')
privatekey = 'laksjrghbnsuvehdjrnvwjgb'
import_result = gpg.import_keys(privatekey)
print(import_result.stderr)
That's just a made up key; doesn't really matter. I'm guessing the one I have is invalid but finding what it actually expects is challenging
Ostensibly it doesn't even validate it so finding out where it's somehow rejected is tough
 
I too have experienced the frustration of not knowing what arguments I'm expected to pass to a library with unreliable documentation
 
Basically, we got an engineer on the inside to pull out an env var that we think should be the key it expects so we can try build our own process. I just need to determine whether they pulled the wrong probably-the-key-they-wanted or whether I'm just not setting something right in the library
 
I'm interested in investigating. But before I install gnupg, I need to install the GnuPG executable. But before I install the GnuPG executable, I need to install an FTP client.
 
12:25 PM
That's GPG in a nutshell.
 
Three layers of manual dependencies -- a good start if one wants to become my least favorite library
 
The key we actually got is 500 characters long. I don't know whether that alone is enough to determine whether it's one of the formats it will accept. I like the bit where it echoes the first 256 characters into its own log
 
12:38 PM
Ok, ftp client installed... Connecting to ftp://ftp.gnupg.org/gcrypt/binary/... Connection failed. Probably a corporate firewall thing.
I guess that's that.
 
Mine doesn't seem to need to connect to anything
You're using this version? There are multiple. Or maybe it is connecting to something in the background, which could be quite possible
 
Don't think I've seen except NameError: before... It kind of makes sense though
I'm pretty sure I'm using that version, yeah. I'm specifically stuck on docs.red-dove.com/python-gnupg/#deployment-requirements, where it says "Windows binaries are available here". If you're on Linux, I guess you can use apt-get instead of downloading via ftp.
 
Hmm, I guess that must have come pre-installed on my workspace container then
 
Ah, I found an HTML download link at gnupg.org/download/index.html. Downloading... Installing... Success? It ostensibly installed, but it never asked me where I wanted to install it, or told me where it decided to install it. There's no "GNU" directory in Program Files, so I'm out of guesses.
[least favorite library intensifies]
Ah, C:\Program Files (x86)\gnupg\bin looks right
 
Just what? I'm guessing what I need is somewhere around here
 
12:53 PM
OSError: Unable to run gpg (gpg) - it may not be available. Don't tell me I literally have to put the python script in the same directory as gpg.exe.
 
So python-gnupg doesn't have any docs... gnupg doesn't have any either... guess I'll try reading the openpgp specification??!
 
perhaps you have to change 'current/directory':P
 
I did change current_directory to r'C:\Program Files (x86)\gnupg\bin'... And now that I chdir to that and use gnupghome=".", I get seemingly valid output. Sigh.
 
Oo, maybe I've set that directory incorrectly, I hadn't really followed that part properly (I wasn't using 'current/directory' though :P)
 
Here is what I'm doing/seeing, if that's any help
 
5% chance that it's somehow Windows' fault for using "\" as a directory separator
Or they're doing something very silly with subprocess and it doesn't work for paths that contain a space
 
1:14 PM
If I do gpg = gnupg.GPG(verbose=True, gnupghome="C:/Program Files (x86)/gnupg/bin"), it reveals that it's trying to execute gpg --status-fd 2 --no-tty --no-verbose --fixed-list-mode --batch --with-colons --homedir "C:/Program Files (x86)/gnupg/bin" --version. So if gpg.exe isn't in PATH, it won't work.
Seems kind of silly to require you to specify the home directory, and then... Also require the home directory to be in PATH.
 
verbose=True --no-verbose 🤔
 
It prints verbose output for python-gnupg, but not for gpg.exe. Think of it as, half-verbose.
 
Lol. Well doing that does give me warnings about an unsafe directory. I don't know whether that is enough to make it unhappy to the point that it refuses my key
 
Might well be. ssh also refuses to use your keys if the permissions are too lenient
 
Google says that the no valid OpenPGP data found. message I'm seeing might be a firewall issue. And I don't control the firewall, so, I guess that's that.
(Here I tempt fate for the second time)
Ah, you don't need to do anything silly with path if you specify gpgbinary. pastebin.com/raw/67R8azH3 gives me the same result as my previous approach, but at least it doesn't use chdir any more.
I'm not sure if you've found the docstring for the GPG class, but here it is for posterity:
Initialize a GPG process wrapper.  Options are:

    gpgbinary -- full pathname for GPG binary.

    gnupghome -- full pathname to where we can find the public and
    private keyrings.  Default is whatever gpg defaults to.
    keyring -- name of alternative keyring file to use, or list of such
    keyrings. If specified, the default keyring is not used.
    options =-- a list of additional options to pass to the GPG binary.
    secret_keyring -- name of alternative secret keyring file to use, or
 
1:29 PM
There's apparently some aspect of Python 2/3 compatibility in the No OpenPGP data error but then people in that thread seem to be saying different things
"I was able to solve this issue by removing the gnupg package and installing the python-gnupg package." ... on the python-gnupg repo itself
 
import_keys ostensibly accepts both strings and byteses, but I'm skeptical of whether they've both been tested thoroughly. If it doesn't work when you pass in a string, try passing in a bytes instead. And vice versa.
string/bytes/unicode confusion is a classic source of sneaky 2.7/3.X incompatibilities
 
I did try make it a bytestring but the output is the same (or is it? Somewhere buried in its attributes it's holding secrets that it doesn't deign to reveal directly to me)
 
So this is a package that 1. doesn't work, 2. seems to do the opposite of what you tell it in command line arguments, 3. doesn't have documentation anywhere, 4. might be riddled with 2/3 bugs. Is there no way to use a different tool?
 
Sadly no. The customer decided to use this encryption on their files
 
You mean GPG? Are there no reasonable GPG packages?
 
1:37 PM
This is apparently the non-broken version out of multiple but I guess I could do another sweep
 
I guess they all end up trying to call some GPG command-line tool
So can you fix it by avoiding Python altogether? See if you can get the GPG part to work? Then fight with the bindings.
 
To their credit, they are trying to be version compatible. Better than just sitting on their laurels.
I suspect that python-gnupg would work if I fed it the correct arguments, and had the correct environment, etc. It only seems insurmountable because I'm clueless about all things gpg.
 
I think I've been looking at the wrong repo. This seems to be the one that's linked to PyPI that seemingly copied the interface of the one that comes up first in a google search. This one seems to have docs. What a mess
 
22 stars should be a red flag for "the" GNUPG wrapper
aah, this is exactly the one you weren't looking at
 
1:52 PM
C:\Users\kevin\Desktop\scripts\misc\adv\roganjosh>"C:/Program Files (x86)/gnupg/bin\gpg.exe" --list-keys
gpg: C:\\Users\\kevin\\AppData\\Roaming\\gnupg\\trustdb.gpg: trustdb created
Uhh. Can't say I expected that to happen
 
yeah, the isislovecruft/python-gnupg is called pretty-bad-protocol on PyPI
captain obvious: because PGP stands for "pretty good privacy"
 
Yeah, I saw that and found it moderately amusing/concerning
 
on the other hand its maintainer is (was?) a Tor developer
 
That looks like progress, Kevin?
 
@Kevin oh dear, you broke it
 
1:58 PM
A moderately unique file extension multiplies my google power by at least 2x
 
2:11 PM
While prying open gpg with my +2 ClueBat, I have managed to make something that may or may not be a public/secret key pair. One of them starts with "-----BEGIN PGP PUBLIC KEY BLOCK-----". That's probably the public one.
 
sounds like it, yeah
it usually has a *.pub name
 
I had to specify the filename and extension myself, so I just went with .key
 
Actually, my PGP keys also have .key ending. I was thinking of RSA and other OPENSSH keys.
 
Ok, I found the "-----BEGIN PGP PRIVATE KEY BLOCK-----" file. My apotheosis draws near.
 
2:28 PM
I think I understand the basics of encryption and decryption when the keys are already available in the gpg environment. I'm not sure how to add more keys, though.
 
Yeah, I've also had it generate keys for me so I don't think this unsafe directory thing will stop it working (I'm not sure I have the ability to change access permissions on directories, I guess I could try rule it out). But that means it should be possible to import a key
 
There's an --import command, so that's very likely. But there are twenty individual options, and I'm not sure which one means "take this plaintext that I copied from between two headers that looked like "-----BEGIN PGP PRIVATE KEY BLOCK-----", and assign it to a user object, and maybe give it a passphrase, and save it in whichever place that kind of thing usually goes"
 
odds are you can/should include the header too
 
Was just starting to think that myself but the code I'm trying to emulate pulls just that env var, doesn't concat anything to it, and I'm hoping the engineer gave me a faithful copy of what was being set. I can give it a go, though. Just gonna check if a colleage saw it in its raw form while they were pulling it out
 
2:52 PM
Arrrgh, you're right, it looks like it does need headers and I might not be able to guess at them because the customer made the key
Ok, but that's definitely sprung it into life
gpg: invalid armor header: <my_key_here>
gpg: invalid radix64 character 2D skipped [multiple times]
gpg: [don't know]: invalid packet (ctb=41)
gpg: read_block: read error: Invalid packet
gpg: no valid OpenPGP data found.
 
3:17 PM
Lol. "I bet those 2D errors are due to missing newlines in the characters" --> Just increased the number of errors two-fold
 
<facepalm> I was trying to search for that specific error rather than just looking directly. Thanks
 
3:48 PM
Let's say I have a class B(A) which implements a method foo that originally doesn't exist in A. But now A gets an update and implements a foo, too - different code, different functionality, only the same name. Now A.foo will get shadowed by B.foo in all instances of B, right?
 
Standard base64 doesn't use '-', but URL-safe substitutes '-' for '+'. See docs.python.org/3/library/base64.html
 
@rattlesnake hold on, when you mean "update", you don't mean something weird like redifining the class with existing instances lying around, right?
 
No, I mean A is imported from another library that got an update
B is in my code
 
When you say "got an update", what do you mean?
If you just mean that A has a different definition than earlier, it isn't very relevant, is it?
You're just asking that if a class A has a .foo method and a subclass B has a .foo method then the latter shadows the former.
 
3:51 PM
python -m pip install --upgrade etc.
 
OK
python code isn't aware of the concept of "updates", it just sees whatever it can import at runtime
 
Yes, it's more a code design question
Yeah, so that might lead to issues, right?
I cannot be sure what methods will be implemented in A in the future. And to avoid having issues with B.foo (or whatever I call my methods), what do I do?
 
@rattlesnake Can we assume that your code doesn't care about A.foo? So you can just ignore it, and continue to use B.foo
 
Just no inheritance at all? Keep A only as a member of B and "forward" all calls to the "parent"?
@PM2Ring Yes
 
In that case, just ignore A.foo. Unless the library gets totally redesigned so it's no longer backwards compatible, which would be evil.
 
3:55 PM
You probably already know this, but just to be safe: A().foo() will still call the foo method of the A class, even if B inherits from A and defines its own foo method.
 
@PM2Ring Now that's an interesting observation. The key does contain 10 + characters. Originally I was concerned because all the example keys have this little ending that mine doesn't have
 
So if the library that defines A gets an update, and it's calling some_a_instance.foo() all over the place, all of that will still work.
 
And given that the footer has 10 hyphens in it, I was wondering whether the parser hadn't realised that it was at the end of the encryption key itself when it slammed into the footer and was complaining about that. This gives me a good lead, thanks
 
As long as your code follows the rules of Liskov substitution you should be fine. en.wikipedia.org/wiki/Liskov_substitution_principle
 
@Kevin Really? Oh man, I think I just tested that and it didn't work?! Wait... give me a second
 
3:57 PM
On the other hand, if the library has some function that takes an A instance as an argument, and you try to call it with a B instance... That might be an issue.
Liskov will be displeased
 
class A:
    def foo(self):
        print("A")
    def bar(self):
        self.foo()

class B(A):
    def foo(self):
        print("B")

b = B()
b.foo()  # prints "B"
b.bar()  # prints "B"
 
It may be possible to update your B.foo so it can smartly distinguish between calls intended for B.foo, and calls intended for A.foo. If the parameters are very different, you might be able to distinguish them objectively.
 
That's what I meant. Originally, there is only A.bar and I add a B.foo
Now A gets an A.foo from upstream and that method is called from A.bar
Because I added my B.foo, that means A doesn't work as intended
 
Why not? Is there an A method that calls foo(), and because you've overridden foo, it doesn't do what it should?
 
Out of curiosity, what's the real use-case behind this? Why inherit from A when its interace isn't stable?
 
4:02 PM
@Aran-Fey Yes
@MisterMiyagi Could be a new feature, no? Is adding new members to a class "unstable"?
 
@roganjosh Hmmm. I guess that =2A5s is some kind of checksum. Base64 data often has a little piece of padding at the end, which ends with '='. That's because it expands 6 bits to 8 bits, so if the length of the original binary data isn't an exact multiple of 6, there's going to be a partial byte at the end.
Also, I expect the PGP protocol looks for whole lines of the form -----END PGP PRIVATE KEY BLOCK-----. So don't mess with them.
 
@rattlesnake Ok, let's call that method qux. Is this a new method that was added along with foo, or did it already exist before foo?
 
@PM2Ring it does based on those test cases have that checksum. But when I was thinking it was hyphens, I assumed the parser was expecting the checksum and when it didn't see it, ran straight into the footer and started complaining about the hyphens
 
I'm confused. ;) What are we calling qux?

1. A.bar exists
2. B is implemented with an additional feature B.foo
3. A implements A.foo, unrelated to B.foo
4. A.bar uses A.foo
5. Now B().bar doesn't work anymore, because in instances of B, foo is B.foo, not A.foo
 
Ah, ok, bar is a real thing, not just an example. Got it.
 
4:07 PM
So it's an important distinction because what I actually have might be 10 subkeys which seem to be a thing
 
Any chance you can do what Kevin said and "overload" foo?
 
A small example of what I was saying in my last message: pastebin.com/raw/rwB0ChpV. C behaves like an A when it needs to, and does its own thing otherwise.
I'm pretty sure there's a decorator or something in the stdlib somewhere, that makes this easier
 
Maybe? Probably? Seems like a lot of overhead to add that to every method? I was just wondering if I'm overlooking something obvious
Seems like that's just not something I should do. I shouldn't write a class which inherits from a class that I don't have much control over
So I'll better just keep A as a member of B and do self.a = A() and return self.a.bar() in B.bar
 
I often have similar worries when I inherit from a class that has a lot of attributes I might not know about. What if I overwrite something important? I think the "composition over inheritance" design principle is meant for devs like us.
 
Thanks :) I'll look that up
 
4:13 PM
If B does not inherit from A, and instead has an attribute pointing to an A instance, then you don't need to worry about new additions to A's interface. It can have a foo method, and B can have a foo method, and they're not going to get mixed up unless you get real silly with duck typing
 
@Kevin Exactly. That's what I meant. :) The only downside is that I have to "forward" all the useful methods from A into B
 
@Kevin Is there a nice way to do that? I.e. without having to write a bajillion boilerplate functions that all look like def foo(self, *args, **kwargs): return self.a.foo(*args, **kwargs)
... I guess you could just define a __getattr__, but that's kinda ew
 
I think you have to get boilerplatey.
If you see that your composition-based design has a ton of inheritance-like boilerplate, that might be a sign that you should stick with inheritance. Right tool for the right job.
 
What about putting it in __getattr__?
 
If tons of manual boilerplate is a red flag, I'd call __getattr__ an orange flag
 
4:18 PM
Explicit is better than implicit. If you write b_thing.a.bar() it's obvious what's going on.
 
Concept: a decorator named @dont_overshadow, which crashes your program if the decorated method sees its name in any of its parent classes.
 
@Kevin Why is this not the default behavior
 
Because not doing that is good enough, most of the time :-)
 
... because then you couldn't override any methods?
 
Well you'd just have to use the @please_override decorator
 
4:19 PM
@Aran-Fey No that's when you will need the decorator
Haha yes exactly
 
... I think .NET has something like this, actually
 
Because usually when you're using inheritance you want the child attributes & methods to over-ride the parent's.
 
A lot of non-python developers are shaking their heads right now
Cursing us for not having a virtual keyword
 
:)
 
Classes are a silly idea anyway, let's just use json
Classes, types, bah. All I really need is None and tuples.
 
4:22 PM
To turn it around, if you mostly want overriding to happen, use inheritance. Otherwise, use composition.
 
Wisdom
 
Would that really help here though? Sure, Child().bar() would still work, but there's still the problem that Child().foo() is now ambiguous. (Should it call Child.foo or Parent.foo?)
 
Rename Child.foo to Child.original_foo, lie down, try not to cry, cry
 
@Aran-Fey b.foo for B.foo, b.a.foo for A.foo
 
Oh, that's the plan? That works I guess
 
4:38 PM
Does this library actually recommend that you inherit from A? If so, they're naughty for changing the interface. If not, it's always risky inheriting from a class that you don't control that's not explicitly designed to be inherited from. ;)
 
@rattlesnake Why yes, if the class is intended for subclassing than any visible interface change is potentially a braking change – after all, that is exactly your problem. ;)
 
5:06 PM
Side note: if the third party parent doesn't call super() you might be stuck when trying to inherit from another class and the third-party class
Same issue of whether the third-party class supports inheritance
 
Eh, there are ways around that. Worst case scenario is if it calls super().__init__() with no arguments, then you need to insert a dummy class into the MRO
 
That's a pretty bad scenario
 
Fortunately that's pretty rare (:
 
 
2 hours later…
7:01 PM
Sorry, had to go out at short notice. Forgot to properly thank you both @Kevin and @AndrasDeak--СлаваУкраїні. Not sussed it yet but certainly feel a lot closer; thanks for your assistance
 
7:36 PM
Going back through the transcript I notice that Kevin had the following file path - C:\Users\kevin\Desktop\scripts\misc\adv\roganjosh. I'm gonna go on the assumption that "adv" stands for "advanced level" in the realms that Kevin pokes into, just to feel less dumb about today :P
 
8:25 PM
FYI @pedroechavarria an event for you from yesterday, may be recorded: "Data Science with Pandas" meetup.com/New-York-R-Users-Group/events/287072216
 
8:54 PM
@rattlesnake: I don't understand your premise, is this purely a hypothetical that hasn't happened? The pragmatic approach when B is only your own subclass and has no other customers is a) give your subclass's methods sufficiently unique names to minimize the chance of this ever haoppening b) monitor any package changes to A, and if the name-collision ever happens, just rename B's method...
...You could even c) join A's developer mailing-list, let them know of the method names you use in B, and get them to confirm that those are unlikely to ever be used in A
 
9:12 PM
@smci ¯\_(ツ)_/¯ I'm sorry but none of your a)-c) sound attractive to me. I don't like to take chances and the overhead doesn't seem worth it to me. I'm totally fine with using composition instead of inheritance though. So I guess that's just the right way for me, personally.
 
Noo, github seems to have packed in on me. I was surveying one of my repos and found something that made absolutely no sense (I might have let it through the door - my bad) that happened to be on line 420 and I have my puns ready to go :(
 
@rattlesnake Without more context, we can't tell if worrying about hypothetical future name-collisions is realistic or not. If your B has a method (or two) that performs nuclear actions and you don't want it to ever unintentionally be called, then give it a sufficiently unique name. This should be more than enough, even if package A's API is a chaotic soup. Yes, composition could be better instead of inheritance in this case.
 
 
2 hours later…
10:58 PM
@AndrasDeak--СлаваУкраїні I gave up trying to understand how this paranormal activity took place, but at least I've been able to prevent it from even happening one step upstream. 75% satisfactory resolution. The remaining 25% is still slightly itchy but I can't and don't have to spend more time on this, since it's a non-issue now.
 
11:11 PM
Is this thing on ... Hi everyone!
 
Hello, can I ask a question? I'm having a hard time reading information from an excel file.
 
My current place of employment does a great job making sure rooms like these are not accessible. Can't drop by as often. I was hoping to get some advice on hourly rates for basic web app programming.
 
@Eestrada hello. For reference here our our rules. Tl;dr you can ask if it's Python and not a fresh question on the main site. For code that's more than about a dozen lines of code, use a code paste service such as pastebin or github gists. For shorter snippets here's out code formatting guide to chat.
 
@Eestrada Have you tried making the font bigger? :)
 
11:17 PM
@Dodge lol
 
11:31 PM
I'm reading an excel file that has a time column in hh:mm:ss format. When creating the data frame, it reads the time column but in a decimal format. For example, it prints 0.292986111 instead of 7:01:54. How can I convert it back to hh:mm:ss?
 
@Eestrada let's take one step back: are you using pandas.read_excel() then?
 
Yes
 
OK. What is the dtype of your "decimal" column?
And when you say "convert it back", what kind of object do you exactly want to end up with? Strings?
 
dtype is object and yes, to strings
 
And what is the type of one of those values, e.g. that 0.292986111? float?
 

« first day (4295 days earlier)      last day (653 days later) »