- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
print str_int("Frist")
"NameError: global name 'profit' is not defined"
Admin
"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.
Admin
Was the code lifted from the answer here? https://stackoverflow.com/questions/25598134/how-to-get-percentage-of-sales
Admin
Come on then, what book is this? We need to know specifically whose profits not to contribute to the increase of.
Admin
Somebody, somehow manage to write a book which is a bigger WTF than the topic it covers - Python.
Admin
Collect string
?
Profit!
Admin
I did a google search for:
"def str_int(s):"
I guess it was the second hit.
Admin
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.
Admin
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.
Admin
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.
Admin
And in the next episode...
Will this snippet will find it's way into their code base?
Admin
@tahir_ahmadov: congratulations, by pushing the point to the extreme you have, as usual for people like you, missed it completely.
Admin
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.Admin
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.
Admin
strtod!
Admin
Five stars on Amazon! I trust that way more than some rando with sour grapes on a weird website.
Admin
So I am thinking that this book was not selected to help the company's less experienced employees.
Admin
I'm not certain why the author would want global profit. My goals are to keep profit privately and as narrowly scoped as possible.
Admin
Available on Amazon in case anybody wants it: https://www.amazon.com/Data-Science-Fundamentals-Python-MongoDB/dp/1484235967
Admin
Obligatory XKCD.
https://xkcd.com/937/
Admin
ˊ
'F'¯'''''L
'[``…'¾`` ``` ``` ``` ```
'[```…ʹ[
``` ``` ```
#````ˆ[```` ``` ``` ``` ``
'#
…
'[…
#…`````'F
` ` `
ƒ¯```````'[__
``` ``
ƒ¯````````ʹ¯¯¯¯''''''''''''¯¯¯¯¯¯™[
gµµµµµµµµµµµµµµ_µ™`````````````````````````'#
'₫₫₫₫₫₫₫₫₫₫₫₫₫F¯…` ²q[¯ ` ` ʹ₫₫₫₫₫₫₫₫₫₫₫₫¾````````````````````````````ʹ} … ` ›₫₫₫₫₫₫₫₫₫₫₫₫#`````````````````````````__µr… ` ` ³₫₫₫₫₫₫₫₫₫₫₫₫₫…`````````````````````````¯[ … ` ` `₫₫₫₫₫₫₫₫₫₫₫₫$``````````````````````````_F … ` ` `]₫₫₫₫₫₫₫₫₫₫₫#````````````````````````ʹ''''[… … ` ` `'₫₫₫₫₫₫₫F''''']₫#___
'# ……₫₫₫₫₫₫₫bµ₫₫₫₫$¯''''¹uuuuuɷuɷuɷuɷuɷuɷµ#¯
…'''''''™''''™'''™''''™™ … …
… …
…
…
……
.
Admin
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)
Admin
TRWTF is storing what appears to be a money value as floating point.
Admin
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 ...
Admin
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".
Admin
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.
Admin
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.
Admin
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'.
Admin
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.
Admin
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 ass
, as well as being global, so thestr_int
function works. Still doesn't explain why it's notstr_float
- probably because it once returned an int.Admin
Doesn‘t python have a float() building to begin with?
Admin
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.
Admin
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
Admin
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
Admin
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