Re: importing two modules with the same name
El Pitonero wrote: > #- Main.py: your program > import imp > # load the third party module into sys.modules > imp.load_source('A', '', open('C:\\A.py')) > # load and execute your changes Thanks a bunch for the hint. The imp module did take care of the job, but just to mention load_source seems to be deprecated, so I used fp, mpath, desc = imp.find_module('optparse',a) s_opt = imp.load_module('std_optparse', fp, mpath, desc) again, thanks for the help! Cheers, Francisco -- http://mail.python.org/mailman/listinfo/python-list
Re: importing two modules with the same name
Tim Jarman wrote: > But if your foo is under your control, why not do everyone a favour and call > it something else? His case is a canonical example of a patch. Often you'd like to choose the "patch" approach because: (1) the third-party may eventually incorporate the changes themselves, hence you may want to minimize changes to the name of the module in your code, so one day in the future you may simply remove the patch, or (2) you are testing out several ideas, at any point you may want to change to a different patch, or simply roll back to the original module, or (3) your product is shipped to different clients, each one of them requires a different twist of the shared module, or (4) your program and your data files are versioned, and your program structure needs cumulative patches in order to be able to work with all previous data file versions. These types of needs are rather common. -- http://mail.python.org/mailman/listinfo/python-list
Re: importing two modules with the same name
Francisco Borges wrote: > There are 2 "foo" named modules, 'std foo' and 'my foo'. I want to be > able to import 'my foo' and then from within my foo, import 'std > foo'. Anyone can help?? In other words, you would like to make a "patch" on third-party code. There are many ways to do it. Here is just one possible approach. #- A.py: third-party module x = 3 def f(): return 'A.f(): x=%d' % x #- B.py: your modifications to the module def f(): return 'B.f(): x=%d' % x #- Main.py: your program import imp # load the third party module into sys.modules imp.load_source('A', '', open('C:\\A.py')) # load and execute your changes imp.load_source('A', '', open('C:\\B.py')) # import now from memory (sys.modules) import A print A.f() -- http://mail.python.org/mailman/listinfo/python-list
Re: importing two modules with the same name
Francisco Borges wrote: > Hello, > > This is not stricly necessary but it would be nice if I could get it > done. Here is what I want to do: > > There are 2 "foo" named modules, 'std foo' and 'my foo'. I want to be > able to import 'my foo' and then from within my foo, import 'std > foo'. Anyone can help?? > If I had to do this, I'd use packages: import foo # the standard module - presumably already on sys.path import my.foo# my module which lives in its own little world Remember to qualify names correctly, and/or do something like: import foo as std_foo But if your foo is under your control, why not do everyone a favour and call it something else? -- Website: www DOT jarmania FULLSTOP com -- http://mail.python.org/mailman/listinfo/python-list
Re: importing two modules with the same name
Francisco Borges <[EMAIL PROTECTED]> writes: > I could simply copy optparse's code and hack it or I could simply import > it and overload some methods, which is what I think would be a cleaner > solution. So why aren't you willing to give your optparse module a different name? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
importing two modules with the same name
Hello, This is not stricly necessary but it would be nice if I could get it done. Here is what I want to do: There are 2 "foo" named modules, 'std foo' and 'my foo'. I want to be able to import 'my foo' and then from within my foo, import 'std foo'. Anyone can help?? - Before you start calling me stupid... the reason I would like that is that: I have a module that produces shell completion code from optparse objects for zsh, tcsh and (sort of) bash. But to use it, I have to directly modify the python code. Which I don't want that since I want to be able to generate completion automatically for code which is not mine in an easy manner. So a shell script sets the PYTHONPATH in a way that "my optparse" is loaded, but to build the option parser I want to then import the original optparse module from my optparse.py file. I could simply copy optparse's code and hack it or I could simply import it and overload some methods, which is what I think would be a cleaner solution. Cheers, -- Francisco. Groningen, Nederlands. __o `\<, _(*)/(*)_ -- http://mail.python.org/mailman/listinfo/python-list