Skip to content
Minute Campus.

Almost rightLesson 031 min

This code calls a function that does not exist

AI-written code can call a function that looks right but does not exist. Here the code calls json.parse, which sounds like Python but belongs to JavaScript, so Python reports that the json module has no attribute parse. A model predicts code that looks likely, and a likely name is not a real one. In Python the function is loads.

Remember

Look up any function you have not used before, and run the code.

Transcript

The lesson, word for word.

Read it at your own pace, or search the page for a term.

This code calls a function that does not exist. Can you spot it in three seconds? The job is to read some settings stored as JSON text. So the code calls json dot parse. It reads well. It sounds like something Python would have. It does not. Run it, and Python says the json module has no attribute called parse. Why would an AI assistant write that? Because it predicts code that looks likely, and JavaScript really does have a function with that name. A likely name is not the same as a real one. In Python, the real function is called loads. The rule: if you have not used a function before, look it up in the official documentation before you trust it. It takes ten seconds. And run the code. A function that does not exist fails the first time it is called, which is the cheapest moment to find out.

Questions? Comment on the lesson on YouTube

New lessons every day.

Follow Minute Campus where you already scroll.