I'm new to Python, but have a long background in Perl, Ksh &c, C, and others.

"""One of the different things about Python is the import statement. How do you tell where a function or class name should be imported from? Some are obvious, like sys and math, but others aren't. Is there some sort of a directory that maps functionName to WhereItComesFrom?"""

Recommended Answers

All 3 Replies

Well, you can use the index of the python documentation https://docs.python.org/3/genindex-all.html

It could be your beginner's project: write a command line tool which tells you from which module you can import symbols.

Can be as simple as ...

import pip
print(pip)

Perfect!!!! The "magic string" there is 'in module'.

And, of course, I just noticed that the chapter headings there are WhereItComesFrom? ("6.2. re — Regular expression operations" - so 'import re')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.