Sure. The first creates an object, os
, that contains all the names in the os
module. E.g. os.getuid
The latter puts the name (or with *
, all names into the current namespace,
e.g. getuid
. So, if you have your own function
called getuid
, they would conflict. But if you don't,
you save yourself three characters of typing, but you sacrifice a
bit of clarity. (Someone reading your code won't necessarily know
that getuid
is the one from the os
module and not your home-grown function that happens to have the same name.
Usually, clarity is more important than brevity, but there are occasions when programmers go the other way. Here, we are tearing down the wall between two files.
d = {} x = d.get('apple')A. Your program prints an error message
Let's try it! We'll copy the code into a Python REPL and see what it does.
Glad to. When we invoke the curs.execute(sql,data)
method:
javac
but on a single
method.
curs
)
After that, whenever we want the data, or part of the data, we can
get it from the cursor by using curs.fetchone()
or curs.fetchall()
.
Interesting! This is essentially a kind of pre-fetching (or pre-computation) and caching.
There are lots of occasions in which this would be a great idea, saving the need to get the data multiple times from the database and avoiding delay on the first (well, sorta).
But, if the database changes, the cached data would be out of date.