Paul Walker on 20 Feb 2014 07:58:28 -0800


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Python Syntax Question


See also Philly PUG group & list!


On Thu, Feb 20, 2014 at 10:13 AM, Will <staticphantom@gmail.com> wrote:
Short answer is scoping of variables. 

"import sys" means that to add a new path to sys one must use "syst.path.append(<location>)" 

"from sys import *" means that to add a new path is now "path.append". 

I would recommend avoiding the use of "from sys import *", you may import specific features from a script file (classes, globals, etc..) 

-Will C


On Thu, Feb 20, 2014 at 10:12 AM, <gary@duzan.org> wrote:
=> I'm confused a little about importing modules in python.
=>
=> In some cases, you add a statement like:
=>
=> "import sys"
=>
=>
=> But in other cases, the syntax is:
=>
=> "from sys import *"

   In the former case, you reference the module elements as sys.foo,
whereas in the latter case you just reference foo. The latter is
probably slightly faster per reference, but you should only use it on
modules which are designed for it. Otherwise, it can overwrite your own
variables or replace names imported from other modules. To be explicit,
you are better off using:

"from sys import foo, bar"

where foo and bar are the particular items of interest. If you aren't sure
all the names you will want, just use the first style.

                                  Gary Duzan


p.s. PhillyPUG is an active Python Users Group if you are really
interested. The meetings are scheduled on Meetup.

___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug


___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug


___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug