What does "from ... import ..." mean?

from sys import argv
from os.path import exists

script, from_file, to_file = argv

print "Copying from %s to %s" % (from_file, to_file)

# we could two on one line too, how?
input = open(from_file)
indata = input.read()

print "The input file is %d bytes long" % len(indata)
print "Does the output file exist? %r" % exists(to_file)
print "Ready, hit return to continue, CTRL-C to abort."

raw_input()

output = open(to_file, 'w')
output.write(indata)

print "Alright, all done."

output.close()
input.close()

On the first two lines, I have some idea of ​​what is going on, but I want me to fully understand this, since it looks like it could be important.

+6
source share
3 answers

import sys, sys sys.foo sys.bar(). , - (, django.contrib.auth.models.User). , , . from os.path import exists exists() os.path. .

os.path, from os.path import foo, bar.

from os.path import *, , . . "import foo" "from foo import" ? .

+17
from module import x

:

module, x .

+8

In terms of bone, this means

from USA import iPhone # instead of importing the whole USA for an iPhone you now will just import the iPhone into your program,

Why do you need something like this?

consider this, without instructions ... import, your code will look like this:

import USA

variableA = USA.iPhone()

with the expression from ... import looks like this:

from USA import iPhone

variableA = iPhone()
+2
source

All Articles