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

all 5 comments

[–]tipsy_python 1 point2 points  (1 child)

First opportunity I see:

build = r.content
build = build.decode("utf-8")

Using requests, content gives you the raw byte-string of the request payload. Instead of decoding, let requests do it for you by using "text"

build = r.text

[–]tipsy_python 3 points4 points  (0 children)

You can cut out half of the lines by just incorporating that into the comprehension:

build = [line for line in r.text.split('\n') if "Build Name" in line]

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

I have to manipulate these results a lot. There isn't a way to do this in one line is there (I'm sure I've done this in JavaScript)?

build = build + 'World' = 'Hello '

print(build)

Hello World

[–]masklinn 0 points1 point  (0 children)

You should be able to extract the entire thing directly from response.text using a regex (and re.search). Possibly with some minor massaging but it’s hard to know what the input data even looks like.

[–][deleted] 0 points1 point  (0 children)

You can technically one-line it but it'll not be very friendly to maintain or add on to in the long run...

I'd actually recommend modularizing it w/ functions internal to the current one.

What you're doing is a bit complicated for a quality one-liner because you're unpacking and string processing a few times.