Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6384319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:45:41+00:00 2026-05-25T02:45:41+00:00

I recently wrote a rather ugly looking one-liner, and was wondering if it is

  • 0

I recently wrote a rather ugly looking one-liner, and was wondering if it is better python style to break it up into multiple lines, or leave it as a commented one-liner. I looked in PEP 8, but it did not mention anything about this

This is the code I wrote:

def getlink(url):
    return(urllib.urlopen(url).readlines()[425].split('"')[7])
    # Fetch the page at "url", read the 426th line, split it along
    # quotes, and return the 8th quote delimited section

But would something like this be better style?:

 def getlink(url):
    url_file = urllib.urlopen(url)
    url_data = url_file.readlines()
    line = url_data[425]
    line = line.split('"')
    return line[7]

Or perhaps something in between?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:45:41+00:00Added an answer on May 25, 2026 at 2:45 am

    My vote would be based on readability. I find your one-liner quicker to digest than the multi-line example.

    One-liners are great as long as it fits in one eye-ful, and collectively they perform one distinct task.

    Personally, I would write that as:

    def getlink(url):
        content = urllib.urlopen(url).readlines()  
        return content[425].split('"')[7]  
    

    (Now, venturing into downvote realm…)

    Your block of comments is great for someone unfamiliar with Python, but arguably, they reduce readability by increasing the information to digest. A pythonista reading the code would quickly understand your one-liner, and yet may then proceed to read the comments just in case there are caveats or edge cases to be warned of.

    I’m not saying comments are evil, just that verbose comments can have a negative effect on readability. E.g. the classic : x+=1 # increment x by 1

    Naturally, this is down to the purpose and audience of the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently wrote a custom Debugger Visualizer for Visual Studio 2008 for one of
I recently found out about C# extension methods and wrote this one: /// <summary>
I have a rather confusing issue. I've recently picked up some code I wrote
I've recently wrote a rather large custom configuration group. I'm curious if it is
I wrote one sample function to understand behavior of std::chrono::duration which recently introduced as
I've recently started learning Python and wrote a little script that informs me when
I have recently stated trying to use the newer style of classes in Python
I recently wrote a texting program (texting through email, rather), and I'd like to
So I accidentally wrote a Haskell answer to a Scala question recently. Being rather
I recently wrote a parser in Python using Ply (it's a python reimplementation of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.