• LCrawford (unregistered)

    print str_int("Frist")

    "NameError: global name 'profit' is not defined"

  • Warren (unregistered)

    "According to the book, this method turns a string into a float, which is why it’s called str_int."

    A throwaway line but I enjoyed it.

  • John (unregistered)

    Was the code lifted from the answer here? https://stackoverflow.com/questions/25598134/how-to-get-percentage-of-sales

  • Little Bobby Tables (unregistered)

    Come on then, what book is this? We need to know specifically whose profits not to contribute to the increase of.

  • (nodebb)

    Somebody, somehow manage to write a book which is a bigger WTF than the topic it covers - Python.

  • Sole Purpose of VIsit (unregistered)
    1. Collect string

    2. ?

    3. Profit!

  • BurnBadBooks (unregistered)

    I did a google search for:

    "def str_int(s):"

    I guess it was the second hit.

  • leus (unregistered)

    That google search is first result for me. This book is also written in Word, using Cambria as the main font. Not the most professional operation there.

  • (nodebb)

    TRWTF is of course the obligatory communist profit bashing. The problem with a bad book is not the profit motive, because guess what, most good books are written for profit, too. In a world where profit is prohibited, books on all subjects are way, way worse.

  • Kitihounel (unregistered)

    The TRWTF is people who buy books to learn Python. The official tutorial is very good. And the documentation of the library is excellent, with lot of example and recommendations. And the best books I found on Python are all FREE... No need for money to learn Python.

  • TheDaveG (unregistered)

    And in the next episode...

    Will this snippet will find it's way into their code base?

  • RLB (unregistered) in reply to tahir_ahmadov

    @tahir_ahmadov: congratulations, by pushing the point to the extreme you have, as usual for people like you, missed it completely.

  • (nodebb)

    Surely we want this article to come up when somebody Googles the book because they're considering buying it? It's Data Science Fundamentals for Python and MongoDB, by David Paper. Here's a link to the function: https://books.google.co.uk/books?id=L3haDwAAQBAJ&pg=PA59&lpg=PA59&dq=%22def+str_int(s):%22&source=bl&ots=bNCqxH6f1R&sig=hm0x9j6XfwDvm-ngKOS7QVU5zHQ&hl=en&sa=X&ved=2ahUKEwj5meXd9tPeAhUDGuwKHcqzApEQ6AEwAHoECAcQAQ#v=onepage&q=%22def%20str_int(s)%3A%22&f=false

    By the way, it won't crash when called in the program shown in the book, because profit is a global variable that's created by the time the function is called, contra what the submitter says. That doesn't mean the code isn't shit, though; the function doesn't do what its name suggests, or what the prose claims, and it totally ignores the argument passed to it in favour of working on a global.

  • Greg (unregistered) in reply to leus

    TRWTF is that the book containing this code had a technical reviewer. Added bonus: the author has also written a book about web programming with PHP.

  • bvs23bkv33 (unregistered)

    strtod!

  • William F (unregistered)

    Five stars on Amazon! I trust that way more than some rando with sour grapes on a weird website.

  • (nodebb)

    So I am thinking that this book was not selected to help the company's less experienced employees.

  • Paul Neumann (unregistered)

    I'm not certain why the author would want global profit. My goals are to keep profit privately and as narrowly scoped as possible.

  • Marco (unregistered)

    Available on Amazon in case anybody wants it: https://www.amazon.com/Data-Science-Fundamentals-Python-MongoDB/dp/1484235967

  • (nodebb) in reply to William F

    Five stars on Amazon! I trust that way more than some rando with sour grapes on a weird website.

    Obligatory XKCD.

    https://xkcd.com/937/

  • Zach (unregistered) in reply to Paul Neumann

    ˊ 'F'¯'''''L '[``…'¾`` ``` ``` ``` ``` '[```…ʹ[ ``` ``` ``` #````ˆ[```` ``` ``` ``` `` '#'[ #…`````'F` ` ` ƒ¯```````'[__ ``` `` ƒ¯````````ʹ¯¯¯¯''''''''''''¯¯¯¯¯¯™[ gµµµµµµµµµµµµµµ_µ™`````````````````````````'# '₫₫₫₫₫₫₫₫₫₫₫₫₫F¯…` ²q[¯ ` ` ʹ₫₫₫₫₫₫₫₫₫₫₫₫¾````````````````````````````ʹ} … ` ›₫₫₫₫₫₫₫₫₫₫₫₫#`````````````````````````__µr… ` ` ³₫₫₫₫₫₫₫₫₫₫₫₫₫…`````````````````````````¯[ … ` ` `₫₫₫₫₫₫₫₫₫₫₫₫$``````````````````````````_F … ` ` `]₫₫₫₫₫₫₫₫₫₫₫#````````````````````````ʹ''''[… … ` ` `'₫₫₫₫₫₫₫F''''']₫#___ '# … …₫₫₫₫₫₫₫bµ₫₫₫₫$¯''''¹uuuuuɷuɷuɷuɷuɷuɷµ#¯ …'''''''™''''™'''™''''™™ … … … … .

  • (nodebb) in reply to William F

    I just added a 1-star review with a link to here. Oh, well, guess my secret identity is blown. Curses. (no, not the VT-100 kind)

  • Eric Gregory (github)

    TRWTF is storing what appears to be a money value as floating point.

  • Sole Purpose of Visit (unregistered) in reply to Greg

    Forgive me, O Lord, but I don't really see a Web programmer in PHP as a "technical reviwer." Not for Python. Not for anything, really. Although, to be fair, we may be missing the point here. Perhaps the "technical reviewer" was the source of this code, written in PHP and piped through a PHP/Python converter? That would actually explain a lot ...

  • (nodebb)

    There was a book called "Let us C" which was (still is?) popular in a part of the globe. From its perspective, the language C as is implemented by the Turbo C 2.0 version running on DOS is the C standard. AFAIR, it has claims like "in C, the type int is 2 bytes".

  • AJ (unregistered)

    The problem with these kinds of books, and I will sympathise with the author here a little bit - the book is not "Python by a Programmer" it is "Python by a Data Scientist".

    Having seen the kind of code that Data Scientists regularly produce, that isn't actually too bad. Compared to the usual trash they usually put out this is almost worthy of a Nobel Prize.

  • OJM (unregistered) in reply to AJ

    I am a "data scientist". The goal of the work is to produce scientific analysis, coding is just a tool for that. My arcane knowledge (I know the meaning of words "typing", "scope", and "documentation") allows me to spot horrible things in my coworkers' outputs.

    I have never seen anything in there as frightening as the snippet here. The author of that snippet knows about functions and about string formatting, yet they clearly did not test the function (not as in "automated unit testing", as in "code output is incorrect, let's check intermediary outputs") or remark that the input value was ignored or whatever.

    Yeah, most scientists do not know how to code. But they do not know the tools to code really badly, either. Also, they would never entertain the idea of writing a book about the subject.

  • Moi Oci (unregistered) in reply to Cabbage

    I thought that within a python function, all variables are local unless the 'global' keyword is used. Thus the 'profit' variable here would be local to the function (and undefined) and would not reference the global 'profit'.

  • (nodebb) in reply to Moi Oci

    Assignments intrinsically create local variables unless you specify otherwise. But if you don't assign to it, you can read the global variable with no trouble at all.

  • Daniel Amdurer (google)

    The code looks like they'd spent so long getting it to work that they hadn't realised that it's still shit. The variable profit is passed in as s, as well as being global, so the str_int function works. Still doesn't explain why it's not str_float - probably because it once returned an int.

  • Klaus (unregistered)

    Doesn‘t python have a float() building to begin with?

  • peevee (unregistered)

    It is a very obvious copy-paste, first from the function which turns strings to ints (hence the name of the function), and then from the function which turns floats into strings.

  • AdamAlexander2020 (github)
    Comment held for moderation.
  • best payroll service for small business oklahoma city ok (unregistered)

    Please continue to post such an enlightening and informative blog. Therefore, people like us will be motivated in real life. Also, I would like to add some more details I have found on the website https://www.boulangercpa.com/dedicated-payroll-services-oklahoma-city-ok

  • best payroll service for small business oklahoma city ok (unregistered)

    Please continue to post such an enlightening and informative blog. Therefore, people like us will be motivated in real life. Also, I would like to add some more details I have found on the website https://www.boulangercpa.com/dedicated-payroll-services-oklahoma-city-ok

  • best payroll service for small business oklahoma city ok (unregistered)

    Please continue to post such an enlightening and informative blog. Therefore, people like us will be motivated in real life. Also, I would like to add some more details I have found on the website https://www.boulangercpa.com/dedicated-payroll-services-oklahoma-city-ok

Leave a comment on “A Profitable Education”

Log In or post as a guest

Replying to comment #:

« Return to Article