473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Small changes in side library

Hi, all!

May be this question have been already discussed, but I found nothing
closer :-/
I have the side library which provides wide set of different
functions, but I'm going to replace some of them with mine and
provided such 'modified' library thought my project.

The following way works well for my purpose:

------- mylib.py -------
import sidelib

import os, sys, ....

def func():
.....
sidelib.func = func
.......
?!?!?!?!
--------------------------

But this cause to write mylib.sidelib.func() to function call, is it
any way to 'map' definitions from sidelib to mylib (possible at point
marked ?!?!?!?!) such that constructions like mylib.func() will be
provided and client code don't see difference between changed and
original library in syntax way?

One my idea was to do from sidelib import * and then modify globals()
dictionary, but this isn't good too because mylib imports many other
modules and they all mapped into it's namespace (like mylib.os,
mylib.sys).

Thanks for attention!

Sep 23 '07 #1
3 1022
En Sat, 22 Sep 2007 22:07:27 -0300, ma************@gmail.com
<ma************@gmail.comescribi�:
I have the side library which provides wide set of different
functions, but I'm going to replace some of them with mine and
provided such 'modified' library thought my project.

The following way works well for my purpose:

------- mylib.py -------
import sidelib

import os, sys, ....

def func():
.....
sidelib.func = func
......
?!?!?!?!
--------------------------

But this cause to write mylib.sidelib.func() to function call, is it
any way to 'map' definitions from sidelib to mylib (possible at point
marked ?!?!?!?!) such that constructions like mylib.func() will be
provided and client code don't see difference between changed and
original library in syntax way?
Your code already works as you like:
import sidelib
sidelib.func()
and you get the modified function.

You don't have to say mylib.sidelib.func - in fact, mylib.sidelib is the
same module object as sidelib
But you have to ensure that the replacing code (mylib.py) runs *before*
anyone tries to import something from sidelib.
One my idea was to do from sidelib import * and then modify globals()
dictionary, but this isn't good too because mylib imports many other
modules and they all mapped into it's namespace (like mylib.os,
mylib.sys).
As you said, a bad idea.

--
Gabriel Genellina

Sep 23 '07 #2
On Sep 24, 1:16 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sat, 22 Sep 2007 22:07:27 -0300, maxim.gavri...@gmail.com
<maxim.gavri...@gmail.comescribi?:
I have the side library which provides wide set of different
functions, but I'm going to replace some of them with mine and
provided such 'modified' library thought my project.
The following way works well for my purpose:
------- mylib.py -------
import sidelib
import os, sys, ....
def func():
.....
sidelib.func = func
......
?!?!?!?!
--------------------------
But this cause to write mylib.sidelib.func() to function call, is it
any way to 'map' definitions from sidelib to mylib (possible at point
marked ?!?!?!?!) such that constructions like mylib.func() will be
provided and client code don't see difference between changed and
original library in syntax way?

Your code already works as you like:
import sidelib
sidelib.func()
and you get the modified function.

You don't have to say mylib.sidelib.func - in fact, mylib.sidelib is the
same module object as sidelib
But you have to ensure that the replacing code (mylib.py) runs *before*
anyone tries to import something from sidelib.
One my idea was to do from sidelib import * and then modify globals()
dictionary, but this isn't good too because mylib imports many other
modules and they all mapped into it's namespace (like mylib.os,
mylib.sys).

As you said, a bad idea.

--
Gabriel Genellina
Thank you for reply!
I make a mistake in my problem description, because I'm going not only
use my own functions (it'll be simple import library question), but
also using side library many functions (with only a few one replaced
by me). For now I'm stay at the following solution:
----- mylib.py -----
import sidelib
from sidelib import *

_sidelib_set = set(dir(sidelib))
_mylib_set = set(['replacedfunc1', 'replacedfunc2', ....]) # all
exports
__all__ = list(_sidelib_set.union(_mylib_set))

.....implementations of _mylib_set functions....
--------------------

Seems it's pretty good for my task, mylib seems fully the same as the
sidelib one.

Thanks for you attention, anyway!

Sep 24 '07 #3
On Sep 24, 10:26 pm, Vircom <maxim.gavri...@gmail.comwrote:
On Sep 24, 1:16 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Sat, 22 Sep 2007 22:07:27 -0300, maxim.gavri...@gmail.com
<maxim.gavri...@gmail.comescribi?:
I have the side library which provides wide set of different
functions, but I'm going to replace some of them with mine and
provided such 'modified' library thought my project.
The following way works well for my purpose:
------- mylib.py -------
import sidelib
import os, sys, ....
def func():
.....
sidelib.func = func
......
?!?!?!?!
--------------------------
But this cause to write mylib.sidelib.func() to function call, is it
any way to 'map' definitions from sidelib to mylib (possible at point
marked ?!?!?!?!) such that constructions like mylib.func() will be
provided and client code don't see difference between changed and
original library in syntax way?
Your code already works as you like:
import sidelib
sidelib.func()
and you get the modified function.
You don't have to say mylib.sidelib.func - in fact, mylib.sidelib is the
same module object as sidelib
But you have to ensure that the replacing code (mylib.py) runs *before*
anyone tries to import something from sidelib.
One my idea was to do from sidelib import * and then modify globals()
dictionary, but this isn't good too because mylib imports many other
modules and they all mapped into it's namespace (like mylib.os,
mylib.sys).
As you said, a bad idea.
--
Gabriel Genellina

Thank you for reply!
I make a mistake in my problem description, because I'm going not only
use my own functions (it'll be simple import library question), but
also using side library many functions (with only a few one replaced
by me). For now I'm stay at the following solution:
----- mylib.py -----
import sidelib
from sidelib import *

_sidelib_set = set(dir(sidelib))
_mylib_set = set(['replacedfunc1', 'replacedfunc2', ....]) # all
exports
__all__ = list(_sidelib_set.union(_mylib_set))

....implementations of _mylib_set functions....
--------------------

Seems it's pretty good for my task, mylib seems fully the same as the
sidelib one.

Thanks for you attention, anyway!
Sorry, I'm misunderstand your propose by first reading. Importing
sidelib after my changes are really the best idea. I'm changingmy
project this way.

Thank you!!!

Sep 24 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Marcel Brekelmans | last post by:
Hi, This is my situation: My ISP doesn't allow me the execute server-code. So, no ASP or otherwise.As a small compensation, they run some CGI scripts that we can use. With one of these...
4
by: Glenn Owens | last post by:
I have a DataGrid web control which I've dynamically populated with template columns to be used for bulk-editting. Generally, all of the columns are textbox and/or dropdownlist child controls. ...
6
by: lanem | last post by:
I have a page that shows some data in a datagrid. All rows are updateable and then the changes are saved by hitting the "Save Changes" button. It is not a row by row save. All edits are made and...
9
by: UJ | last post by:
I have a page where the user can make changes to some DB stuff. It's not saved until they hit the save button. I'd like to have it so that if they attempt to navigate somewhere else, I give them a...
21
by: Viken Karaguesian | last post by:
Hello all, I'm having a weird design issue with IE. The bottom borders on two of my div's stop 1px or 2px short of the right side of the div. In Mozzilla and Opera, these borders go completely...
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
4
by: RobertTheProgrammer | last post by:
Hi folks, Although I'm an experienced programmer, I'm new to ASP and relatively new to web programming, so I hope you'll be patient with my questions. I'm working on a project using ASP.NET and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.