Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Python Objects and Methods Question

  • 20-04-2014 9:33pm
    #1
    Closed Accounts Posts: 2,338 ✭✭✭


    Hi,
    Assume you have code such as follows:
    import mechanize
     def viewSite(url):
       b = mechanize.Browser()
       page = b.open(url)
       source_code = page.read()
       print source_code
    viewSite(‘http://www.boards.ie/’)
    

    I don't understand why I have to create the page and source_code objects to get at the open()and read() methods.

    b.open(url) works on its own obviously.
    Why doesn't b.read work on it's own without using the page object

    More importantly, if I'm using a random module for the first time, how would I know to create the page and source_code objects to use the read method as above?
    I had a look at the Mechanize Pydoc and read is buried away here.
    I would never have found it if I hadn't got the above example code from a tutorial.

    I'm hoping some guidance will allow me to use more modules without reading tutorials on them first.


Comments

  • Registered Users, Registered Users 2 Posts: 7,157 ✭✭✭srsly78


    Many filesystem apis do it this way, you call open, then read. Seems like the author of your library tried to mimic this convention. Call it "tradition".

    You will usually have to read tutorials/documentation to use new bits of software, get used to it.


  • Closed Accounts Posts: 2,338 ✭✭✭aphex™


    srsly78 wrote: »
    You will usually have to read tutorials/documentation to use new bits of software, get used to it.

    I'm happy to read module documentation, tutorials are harder to find are on random people's blogs/websites/books.

    I would never have found read() on the opening page of the module documentation here.

    Is there any other way to access read()?


  • Registered Users, Registered Users 2 Posts: 7,157 ✭✭✭srsly78


    Try to find the real manual, not autogenerated documentation. Autogenerated stuff tends to be a bit verbose and confusing. If there are no tutorials or good documentation, then it's not a very good software library!


Advertisement