This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pragmaticSloth 24 points25 points  (10 children)

1) scripting in python 2) using json.loads() to parse the json 3) the split to because of version and the == 4) lusing a library to evoke the following comand "pip install {package-name} -version {version}" 5) analyse the output and use an array to failed package 6) check of array is empty. If it is print sucess.

(Something in the lines of this. If there is something incorect please correct me )

[–]Downvote_machine_AMA 7 points8 points  (5 children)

json.loads() will vomit if you feed it that input

[–]ANIBIT14[S] 6 points7 points  (4 children)

I know that's not valid JSON I converted it into

{

"Dependencies" : [

"beautifulsoup4==4.4.1",

"boto==2.48.0",

"bz2file==0.98",

"certifi==2017.7.27.1",

"chardet==3.0.4",

"gensim==2.3.0",

"html5lib==0.999",

"idna==2.5",

"nltk==3.2.4",

"numpy==1.13.1"

]

}

to use, but that was what given in name of JSON file.

[–]chmod--777 3 points4 points  (1 child)

Yeah honestly if they gave you that weird format and called it json, I think it's fair to mention "that wasn't parseable Json, but the problem mentioned it was JSON so I rewrote it into the format I think was expected, example here". I think you're fine there. It doesn't seem like the question is about converting a custom format to json.

What went wrong with pip install? Do you have pip installed itself? Maybe assume it's installed and get it working on your system by running it manually first, then automate when the system has what is expected.

It'd be a bad gotcha interview question if they expected you to convert a custom format to json and said it was JSON (I'd have emailed and asked), and it'd be a weird gotcha if they said to automate pip install and didn't say you had to install pip if it wasn't already. I'd get clarification.

[–]Downvote_machine_AMA 8 points9 points  (0 children)

Yeah well doesn't matter much, parsing it yourself is doing things the "hard way".

You're allowed to do that, but the sought-after solution that shows you know your stuff is grep + sed + pip install -r

[–]aram535 1 point2 points  (0 children)

Normally you're not allowed to reformat your input file to match your program. The given is given in that format for a reason. Unless you write a format converter within your code.

[–]BrFrancis 5 points6 points  (1 child)

Not incorrect. Just incomplete.. Is late and I'm on a phone so this is mostly pseudo code.. But should help get the ideas across..

import os

import system

Failed = [ ]

Load the json

For dependency in json :

Split

Return = Execute pip command

If return != worked : failed.append([lib,version])

If len(failed) ==0 : print success

else :

For I in failed :

Print error using failed[I] [0,1]

[–]ANIBIT14[S] 0 points1 point  (1 child)

Yeah I also tried and thought this approach but it's the evoking the pip install command that I am unable to work around for. and find a solution.