Newbie: Installing packages on windows
Hi, I'm reading the python tutorials on docs.python.org, but I'm still not sure how install a package. I have downloaded pylint in zip form from www.logilab.org, but I'm unsure what to do with it. The file I wish to test (i.e. the file I have writen myself) is located in C:\Python25\ Hope you can help, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Python Wrapper for C# Com Object
Hi, I wish to write a Python wrapper for my C# COM object but am unsure where to start. I have a dll and a tlb file, and I can use this object in C via the following code - // ConsolApp.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "windows.h" #include "stdio.h" #import "C:\Documents and Settings\X\Mina dokument\Visual Studio 2005\Projects\X_COMObject\X_COMObject\bin\Debug\X_COMObject.tlb" using namespace X_COMObject; int _tmain(int argc, _TCHAR* argv[]) { CoInitialize(NULL); X_COMObject::XCOM_InterfacePtr p(__uuidof(X_COMObject::XCOM_Class)); XCOM_Interface *X_com_ptr ; X_com_ptr = p ; X_com_ptr->SetID(10); int x = X_com_ptr->GetID(); printf("%d",x); getchar(); return 0; } Can anyone offer me some tips as to how to do this in Python? Thanks very much for your help, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Wrapper for C# Com Object
[EMAIL PROTECTED] skrev: > Hi, > > I wish to write a Python wrapper for my C# COM object but am unsure > where to start. I have a dll and a tlb file, and I can use this object > in C via the following code - > > // ConsolApp.cpp : Defines the entry point for the console application. > // > #include "stdafx.h" > #include "windows.h" > #include "stdio.h" > #import "C:\Documents and Settings\X\Mina dokument\Visual Studio > 2005\Projects\X_COMObject\X_COMObject\bin\Debug\X_COMObject.tlb" > using namespace X_COMObject; > > int _tmain(int argc, _TCHAR* argv[]) > { > CoInitialize(NULL); > > X_COMObject::XCOM_InterfacePtr p(__uuidof(X_COMObject::XCOM_Class)); > XCOM_Interface *X_com_ptr ; > X_com_ptr = p ; > X_com_ptr->SetID(10); > int x = X_com_ptr->GetID(); > printf("%d",x); > getchar(); > > return 0; > } > > Can anyone offer me some tips as to how to do this in Python? > > Thanks very much for your help, > > Barry. This is what I've done so far, but I know I'm not doing this correctly. Can anyone help me out? #import pythoncom #pythoncom.CoInitialize() from comtypes.client import GetModule, CreateObject module = GetModule("C:\\Documents and Settings\\X\\Mina dokument\\Visual Studio 2005\\Projects\\X_COMObject\\X_COMObject\\bin\\Debug\\X_COMObject.tlb") dir(module) interface = module.XCOM_Interface() dir(interface) interface.SetID() #pythoncom.CoUnitialize() Traceback (most recent call last): File "C:/Python25/test.py", line 14, in interface.SetID() TypeError: Expected a COM this pointer as first argument -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Wrapper for C# Com Object
[EMAIL PROTECTED] skrev: > [EMAIL PROTECTED] skrev: > > > Hi, > > > > I wish to write a Python wrapper for my C# COM object but am unsure > > where to start. I have a dll and a tlb file, and I can use this object > > in C via the following code - > > > > // ConsolApp.cpp : Defines the entry point for the console application. > > // > > #include "stdafx.h" > > #include "windows.h" > > #include "stdio.h" > > #import "C:\Documents and Settings\X\Mina dokument\Visual Studio > > 2005\Projects\X_COMObject\X_COMObject\bin\Debug\X_COMObject.tlb" > > using namespace X_COMObject; > > > > int _tmain(int argc, _TCHAR* argv[]) > > { > > CoInitialize(NULL); > > > > X_COMObject::XCOM_InterfacePtr p(__uuidof(X_COMObject::XCOM_Class)); > > XCOM_Interface *X_com_ptr ; > > X_com_ptr = p ; > > X_com_ptr->SetID(10); > > int x = X_com_ptr->GetID(); > > printf("%d",x); > > getchar(); > > > > return 0; > > } > > > > Can anyone offer me some tips as to how to do this in Python? > > > > Thanks very much for your help, > > > > Barry. > > This is what I've done so far, but I know I'm not doing this correctly. > Can anyone help me out? > > #import pythoncom > #pythoncom.CoInitialize() > > from comtypes.client import GetModule, CreateObject > > module = GetModule("C:\\Documents and Settings\\X\\Mina > dokument\\Visual Studio > 2005\\Projects\\X_COMObject\\X_COMObject\\bin\\Debug\\X_COMObject.tlb") > > dir(module) > > interface = module.XCOM_Interface() > > dir(interface) > > interface.SetID() > > #pythoncom.CoUnitialize() > > > Traceback (most recent call last): > File "C:/Python25/test.py", line 14, in > interface.SetID() > TypeError: Expected a COM this pointer as first argument Can anyone help me with this? Thanks, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Wrapper for C# Com Object
Thomas Heller skrev: > [EMAIL PROTECTED] schrieb: > > [EMAIL PROTECTED] skrev: > > > >> Hi, > >> > >> I wish to write a Python wrapper for my C# COM object but am unsure > >> where to start. I have a dll and a tlb file, and I can use this object > >> in C via the following code - > >> > >> // ConsolApp.cpp : Defines the entry point for the console application. > >> // > >> #include "stdafx.h" > >> #include "windows.h" > >> #include "stdio.h" > >> #import "C:\Documents and Settings\X\Mina dokument\Visual Studio > >> 2005\Projects\X_COMObject\X_COMObject\bin\Debug\X_COMObject.tlb" > >> using namespace X_COMObject; > >> > >> int _tmain(int argc, _TCHAR* argv[]) > >> { > >>CoInitialize(NULL); > >> > >>X_COMObject::XCOM_InterfacePtr p(__uuidof(X_COMObject::XCOM_Class)); > >>XCOM_Interface *X_com_ptr ; > >>X_com_ptr = p ; > >>X_com_ptr->SetID(10); > >>int x = X_com_ptr->GetID(); > >>printf("%d",x); > >>getchar(); > >> > >>return 0; > >> } > >> > >> Can anyone offer me some tips as to how to do this in Python? > >> > >> Thanks very much for your help, > >> > >> Barry. > > > > This is what I've done so far, but I know I'm not doing this correctly. > > Can anyone help me out? > > > > #import pythoncom > > #pythoncom.CoInitialize() > > The above is unneeded if you use comtypes as below (and is unneeded > when using pythoncom, as well). > > > from comtypes.client import GetModule, CreateObject > > > > module = GetModule("C:\\Documents and Settings\\X\\Mina > > dokument\\Visual Studio > > 2005\\Projects\\X_COMObject\\X_COMObject\\bin\\Debug\\X_COMObject.tlb") > > > You don't intantiate the interface, you have to instantiate the COM object. > Something like > > CreateObject("XCOM_Class") > > but of course you have to use the correct argument in the call - the progid > of the COM object. > Alternatively you can use the CoClass from the typelibrary, look into the > generated module in the comtypes\gen directory for a class derived from > comtypes.CoClass. > > InternetExplorer, for example, can be started in these ways: > > # using the progid: > ie = CreateObject("InternetExplorer.Application") > > # using the clsid: > ie = CreateObject("{0002DF01---C000-0046}") > > > # using the coclass from the generated module: > mod = GetModule("shdocvw.dll") > ie = CreateObject(mod.InternetExplorer) > > Thomas Thanks very much for your help. I tried running the following code - import win32com.client scanObj = win32com.client.Dispatch("X_COMObject") but im getting the following error - Traceback (most recent call last): File "C:\Python22\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Python25\test.py", line 20, in ? scanObj = win32com.client.Dispatch("Scania_COMObject") File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python22\Lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python22\Lib\site-packages\win32com\client\dynamic.py", line 78, in _GetGoodDispatch IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) com_error: (-2147221005, 'Invalid Class String', None, None) I ran my C++ code again and it works fine. I also checked COM Browser and my X_COMObject is present and I'm spelling it right. Any ideas what the problem migth be? Thanks again, Barry. -- http://mail.python.org/mailman/listinfo/python-list
A simple array in Python
Hi, I have the following enum - class State: Fire = 0 Water = 1 Earth = 2 And I want a variable which holds a value for each of these states, something like - myState1[State.Fire] = 10 myState1[State.Earth] = 4 myState2[State.Fire] = 20 myState2[State.Earth] = 24 How do I do this? Thanks Barry. -- http://mail.python.org/mailman/listinfo/python-list
Establishing if an Object is Defined
Hi, The following code works - one = 1 if one == 1: ok = 1 print ok but this does not, without exception - one = 2 if one == 1: ok = 1 print ok How do I establish before printing ok if it actually exists so as to avoid this exception? Thanks for your help, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Why do I have to call del explicitly for com objects?
Hi, I'm creating objects in my python script belonging to a COM object which I dispatch using win32com.client.DispatchEx. Hence, dllhost.dll is the concerned process. The problem is that the objects destructor within the com object is not called if the object lives past a certain number of seconds. For example, this function will not call the destructor concerned with obj unless the sleep is commented out. def fnction: obj = comobj.createACertainObject() obj.doStuff() sleep(10) obj.doMoreStuff() #del obj It seems to me that the GC forgets about obj after a certain amount of time. I can force the destructor to be called using del obj at the end of my function, but why do I have to call this explicitly? Thanks for your help, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why do I have to call del explicitly for com objects?
Gabriel Genellina skrev: > <[EMAIL PROTECTED]> escribió en el mensaje > news:[EMAIL PROTECTED] > > > I'm creating objects in my python script belonging to a COM object > > which I dispatch using win32com.client.DispatchEx. Hence, dllhost.dll > > is the concerned process. The problem is that the objects destructor > > within the com object is not called if the object lives past a certain > > number of seconds. For example, this function will not call the > > destructor concerned with obj unless the sleep is commented out. > > > > def fnction: > > obj = comobj.createACertainObject() > > obj.doStuff() > > sleep(10) > > obj.doMoreStuff() > > #del obj > > I don't understand the case. > del does not invoke a destructor, just decrements the object's reference > count. When the rc reaches zero, the object is a candidate for GC. That is, > "some time in the future", the GC would destroy it (unless it's part of a > circular reference chain...) > So, *inside* your function, there is a reference held by the local variable > obj. It is decremented automatically when you exit the function (and obj > gets out of scope) or if you explicitely use del. > You can use sys.getrefcount() to see how many references an object has. (The > output is +1 because getrefcount() has a temporary reference to the object > too). > > py> x="Hello World" > py> sys.getrefcount(x) > 2 > > See how many references your obj have. After calling doStuff or doMoreStuff, > you can have more references if those functions store `self` somewhere, or > pass it to another method that does so. > > > It seems to me that the GC forgets about obj after a certain amount of > > time. I can force the destructor to be called using del obj at the end > > of my function, but why do I have to call this explicitly? > If del obj works at the end, exiting the function should work too. Both ways > you decrement the rc. There is something *more* in here. > > -- > Gabriel Genellina Thanks for the reply. I tried using a longer sleep before the del but the destructor wasn't called this time. I guess del is not the issue here what so ever. As far as I can see, the garbage collector forgets about my object after a certain period of time. The fix i'm using now is to use Destruct functions in my CoM object which I call explicitly. def fnction: obj = comobj.createACertainObject() obj.doStuff() sleep(10) obj.doMoreStuff() obj.Destruct() I'd still love to know what the issue is here. Thanks, Barry. -- http://mail.python.org/mailman/listinfo/python-list
COM makepy util finds multiple versions of my COM object
Hi, I have a problem where an earlier version of my Com object is being used by makepy for early binding. In makepy I see - MyCom (1.0) MyCom (1.0) MyCom (2.0) I created version 2 of my Com object hoping that this would solve the problem but makepy is still using an earlier version. I can solve the problem by editing the registry, but this problem now exists on a number of computers... Any ideas as to how I might solve this one? I'm using build 210 of pythonwin. Thanks for your help, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Getting a class name from within main
Hi, Lets say I have the following class - class MyClass: def __init__(self): print (__name__.split("."))[-1] if __name__ == '__main__': MyClassName = "MyClass" I can print the name of the class from within the class scope as seen above in the init, but is there any way of printing it from within the main without creating an object of the MyClass type. I need to assign the name of the class within my script, to a variable in main. Thanks, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Building Python Pagage for Newer Python Version
Hi, I have just downloaded the source for PyXML-0.8.4, which I would like to build for Python 2.5. How exactly do I go about doing this? Thanks for your help, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Finding a tuple in a tuple
Hi, Lists say I have the following tuple - t1 = ("ONE","THREE","SIX") and then the following tuples - t2 = ("ONE","TWO","THREE") t3 = ("TWO","FOUR","FIVE","SIX") t4 = ("TWO",) t5 = ("TWO","FIVE") What I want to do is return true if any member of tuple t1 is found in the remaining tuples. Therefore - 2) ("ONE","TWO","THREE") : TRUE 3) ("TWO","FOUR","FIVE","SIX") : TRUE 4) ("TWO",) FALSE 5) ("TWO","FIVE") How do I do this? Cheers, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Finding non ascii characters in a set of files
Hi, I'm updating my program to Python 2.5, but I keep running into encoding problems. I have no ecodings defined at the start of any of my scripts. What I'd like to do is scan a directory and list all the files in it that contain a non ascii character. How would I go about doing this? Thanks, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Copy a module build to another machine
Hi, I have downloaded the source for PyXML-0.8.4, which has no binaries available for Python 2.5. Therefore I built it myself doing something like this - python2.5 setup.py build python2.5 setup.py install having installed cygwin (with gcc). Now lets say I'd like to install PyXML-0.8.4 on a number of other machines running the same os, what files would I need to copy, and to where, in order to install PyXML with just the line - python2.5 setup.py install In other words, I don't want to have to install cygwin on all these machines and build for each machine. Instead I want to create a simple install. Thanks for your help, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Building a dictionary from a tuple of variable length
Hi, I have the following tuple - t = ("one","two") And I can build a dictionary from it as follows - d = dict(zip(t,(False,False))) But what if my tuple was - t = ("one","two","three") then I'd have to use - d = dict(zip(t,(False,False,False))) Therefore, how do I build the tuple of Falses to reflect the length of my t tuple? Thanks for your help, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Dictionary of Dictionaries
Hi, I have the following - messagesReceived = dict.fromkeys(("one","two"), {}) messagesReceived['one']['123'] = 1 messagesReceived['two']['121'] = 2 messagesReceived['two']['124'] = 4 This gives: {'two': {'121': 2, '123': 1, '124': 4}, 'one': {'121': 2, '123': 1, '124': 4}} but I expected - {'one': {'121': 2, }, 'two': {'123': 1, '124': 4}} What am I doing wrong? Thanks, Barry. -- http://mail.python.org/mailman/listinfo/python-list
Re: Dictionary of Dictionaries
On 5 Mar, 11:45, "Amit Khemka" <[EMAIL PROTECTED]> wrote: > On 5 Mar 2007 02:22:24 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > Hi, > > > I have the following - > > > messagesReceived = dict.fromkeys(("one","two"), {}) > > This will create a dictionary "messagesReceived", with all the keys > referring to *same instance* of the (empty) dictionary. > ( try: messagesReceived = dict( [(k,{}) for k in ('one', 'two') ] ) ) > > > > > messagesReceived['one']['123'] = 1 > > messagesReceived['two']['121'] = 2 > > messagesReceived['two']['124'] = 4 > > > This gives: > > > {'two': {'121': 2, '123': 1, '124': 4}, 'one': {'121': > > 2, '123': 1, '124': 4}} > > And hence the results ! > > HTH, > > -- > > Amit Khemka -- onyomo.com > Home Page:www.cse.iitd.ernet.in/~csd00377 > Endless the world's turn, endless the sun's Spinning, Endless the quest; > I turn again, back to my own beginning, And here, find rest. Thanks for your help! -- http://mail.python.org/mailman/listinfo/python-list