##I'm sorry to stir up such a well discussed topic yet again, but namespaces
are a point of confusion to me...
I took the effort of organizing my Python code (scripting a cad program
calles Rhino) in well defined classes, which would be a terrific thing if I
didn't got stuck in namespace issues.
I have a module that launches the application I'm scripting via win32com;
rhino.load
from rhino import load
RS = load.RS
So the application, with all its methods are now available through the RS
(RhinoScript) object
from rhino import SRF # is where things get stuck
The RS object is the application scripted via COM, where all its method
reside.
In my module, SRF, I'm not importing anything, though it refers to the RS
object all the time.
Such as:
class srfBase:
'''Base class inherited by the srf* classes, binding general Rhino
surface functionality to a particular
surface generation method'''
def __init__(self):
self.id = 'self.id srfBase'
pass
def isBrep(self):
return RS.IsBrep(self.id)
def isPointInSurface(self, coord):
return RS.IsPointInSurface(self.id, coord)
How do I make the RS object available to the imported SRF module, such that
my module code and program code both refer to RS as the application object
being scripted?
Cheers,
Jelle. 3 1527
One way is to pass the RS object when you instantiate
an instance of srfBase, something like:
class srfBase:
'''Base class inherited by the srf* classes, binding general Rhino
surface functionality to a particular
surface generation method'''
def __init__(self, RS):
self.id = 'self.id srfBase'
self.RS=RS
return
def isBrep(self):
return self.RS.IsBrep(self.id)
def isPointInSurface(self, coord):
return self.RS.IsPointInSurface(self.id, coord)
This is how most of wxWindows seems to do things.
-Larry Bates
Jelle Feringa / EZCT Architecture & Design Research wrote: ##I'm sorry to stir up such a well discussed topic yet again, but namespaces are a point of confusion to me...
I took the effort of organizing my Python code (scripting a cad program calles Rhino) in well defined classes, which would be a terrific thing if I didn't got stuck in namespace issues.
I have a module that launches the application I'm scripting via win32com; rhino.load
from rhino import load RS = load.RS
So the application, with all its methods are now available through the RS (RhinoScript) object
from rhino import SRF # is where things get stuck
The RS object is the application scripted via COM, where all its method reside. In my module, SRF, I'm not importing anything, though it refers to the RS object all the time. Such as:
class srfBase: '''Base class inherited by the srf* classes, binding general Rhino surface functionality to a particular surface generation method''' def __init__(self): self.id = 'self.id srfBase' pass def isBrep(self): return RS.IsBrep(self.id) def isPointInSurface(self, coord): return RS.IsPointInSurface(self.id, coord)
How do I make the RS object available to the imported SRF module, such that my module code and program code both refer to RS as the application object being scripted?
Cheers,
Jelle.
Dear Steve & Larry,
Both your methods worked flawless, thanks to both of you!
I have to say Larry's way wins on style points, doens't it?
What an awefull thing to get stuck on something that simple, what a
gorgeous solution, thanks so much!
-Jelle
Ooops, Larry, forgive me being to overhauled here:
Actually self.RS = RS does not make the RS object available in the
module, Steve's method does however.
-Jelle This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andy Jewell |
last post by:
Does anyone know of a way to dynamically reload all the imported modules of a
client module?
I'm writing a program that I have broken down into quite a few submodules, and
the 'configuration'...
|
by: Dan Williams |
last post by:
Hi people
I've just joined the Python list and although I'm sure my question must be
asked fairly frequently, I have been unable to find an answer after two days
of searching. For the record, my...
|
by: Bart |
last post by:
Hi all
I don't understand globals between multiple modules in a python program. I
really don't. I've narrowed it down to the following two very simple
programs a.py and b.py. When I run a.py I...
|
by: qwweeeit |
last post by:
The pythonic way of programming requires, as far as I know, to spread a
big application in plenty of more manageable scripts, using import or
from ... import to connect the various modules.
In...
|
by: Ben R. |
last post by:
Hello,
I’m in the process of reading "Inside Microsft .NET IL Assembler" by Serge
Lidin to gain a better understanding of my .NET code at a lower (IL) level.
There is one concept that I am...
|
by: Alex |
last post by:
Hi, this is my first mail to the list so please correct me if Ive done
anything wrong.
What Im trying to figure out is a good way to organise my code. One
class per .py file is a system I like,...
|
by: Neil Cerutti |
last post by:
The Glk API (which I'm implementing in native Python code)
defines 120 or so constants that users must use. The constants
already have fairly long names, e.g., gestalt_Version,
evtype_Timer,...
|
by: Zytan |
last post by:
I've read the docs on this, but one thing was left unclear. It seems
as though a Module does not have to be fully qualified. Is this the
case? I have source that apparently shows this.
Are...
|
by: deltaquattro |
last post by:
Hi,
I'm currently learning C++ and I would like to ask you the difference
between Fortran 95 modules and C++ namespaces. To me they look the
same, except for the scope operator :: in C++, which...
|
by: Fabrizio Pollastri |
last post by:
Hi,
just an import problem:
a program imports two modules, modA and modB, each module do not known anything
about the other module (i.e. no cross imports in them), both modules needs to
refer...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |