News for hackers. Stuff that matters.
Re:Fixing the Python subprocess interface by nas on Monday January 30, 2012 @01:19PM (#3529913)
Neat but way too magical for my taste. The code to figure out what to do in the case of 'from .. import *' is particularly ugly.

Perhaps the commands should accessible from an object you import. That's slightly more typing but more explicit and would not require ugly magic. E.g.

  from pbs import sh
  print sh.ifconfig('eth')
If it's not clear, the 'sh' object could override __getattr__ or __getattribute__ and wrap commands as necessary.
Re:Fixing the Python subprocess interface by dman on Monday January 30, 2012 @01:20PM (#3529917)
Anything that encourages a from ... import * usage is evil irrespective of its implementation.
Re:Fixing the Python subprocess interface by petsos on Monday January 30, 2012 @01:27PM (#3529945)
Why?
Re:Fixing the Python subprocess interface by andylei on Monday January 30, 2012 @01:38PM (#3529997)
makes references ambiguous to anyone but the interpreter

let's say you have

from a import foo from b import *

what does 'foo' refer to? 'b' could contain 'foo', which would overwrite your previous reference to 'a.foo'. its hard to figure out what 'foo' now refers to from inspecting the code. its better to be explicit:

from a import foo from b import bar, baz

Re:Fixing the Python subprocess interface by ulope on Monday January 30, 2012 @01:35PM (#3529991)
Because it leads to namespace pollution and hard-to-track-down bugs.

It's especially bad in this case where adding an executable in the system can suddenly shadow any built-in name (e.g. imagine someone adds a "print" or "sys" executable).

Re:Fixing the Python subprocess interface by gbog on Tuesday January 31, 2012 @08:14AM (#3533063)
Refactoring is also made much harder with import * if you have cascading modules. I have a pylint hook forbidding these before committing to our hg repo
Re:Fixing the Python subprocess interface by dman on Monday January 30, 2012 @01:34PM (#3529986)
Off the top of my head a) Nothing prevents the writer of the module you are importing from overriding symbols that you expect b) In many cases increased load times. c) Irrelevant symbols present in scope when debugging d) Makes the order of import statements important, because potentially different modules might be providing the same variable name
Re:Fixing the Python subprocess interface by rytis on Monday January 30, 2012 @01:35PM (#3529990)
because this might mess up your script by either overwriting something that's already defined, or you might accidentally overwrite something that is 'hidden' behind the '* '.

somewhat naive example:

    >>> time = 'blah'
    >>> time
    'blah'
    >>> from datetime import *
    >>> time
    <type 'datetime.time'>
    >>>
Re:Fixing the Python subprocess interface by VMG on Monday January 30, 2012 @01:34PM (#3529985)
pollution of the global name space
Re:Fixing the Python subprocess interface by tantalor on Monday January 30, 2012 @01:38PM (#3529998)
Irrelevant for shell-style scripts because they are entry points, not included from other modules.

--And its not a "global" name space, its just the namespace of your script.--

Re:Fixing the Python subprocess interface by viraptor on Monday January 30, 2012 @02:30PM (#3530251)
It's a global namespace in your script. That's what it's called, I believe and it's available via globals().
Re:Fixing the Python subprocess interface by tantalor on Monday January 30, 2012 @02:51PM (#3530354)
Aye, they are added to "current scope's global variables", thank you for correcting.
Re:Fixing the Python subprocess interface by d0mine on Monday January 30, 2012 @01:30PM (#3529962)
To avoid any magic you could use:

  ifconfig = pbs.Command("/path/to/ifconfig")