• Welcome to Valhalla Legends Archive.
 

Multiple questions concerning Python

Started by topaz, May 15, 2006, 04:31 AM

Previous topic - Next topic

topaz



1. What, if there is, the equivalent of SendMessage() in Python?
2. How do you make calls to DLLs written in C++ and, if possible, VB6?
3. What library is used for socket work? (hard to phrase... see: mswinsck.dll from VB6)
4. Are optimizations automatically done by the interpreter?
RLY...?

MyndFyre

I'm pretty sure I can answer question 2 for you, but don't take it as canon.

C++ DLLs are specialized DLLs -- linkers have to do special work to import them.  This is because, to avoid overlap in function names, they're mangled in a very specific way.  You most likely can't import C++ DLLs unless they expose COM through ATL, which leads me to my response about VB6.  Unless Python provides a way to access COM, you're out of luck with VB6, since VB6 doesn't compile traditional PE DLLs.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Yegg

Quote from: Topaz on May 15, 2006, 04:31 AM
1. What, if there is, the equivalent of SendMessage() in Python?

Well, Python can interface with the Windows API.

Quote from: Topaz on May 15, 2006, 04:31 AM
2. How do you make calls to DLLs written in C++ and, if possible, VB6?

http://starship.python.net/crew/theller/ctypes/

Quote from: Topaz on May 15, 2006, 04:31 AM
3. What library is used for socket work? (hard to phrase... see: mswinsck.dll from VB6)

Python has it's own socket library which is very easy to use.

Quote from: Topaz on May 15, 2006, 04:31 AM
4. Are optimizations automatically done by the interpreter?

I believe so, I'm no Python expert.

MyndFyre

Quote from: Yegg on May 15, 2006, 02:39 PM
http://starship.python.net/crew/theller/ctypes/
He said C++.  Meaning, he wants to use C++ classes.  C DLLs and C++ DLLs are very different.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Yegg

Quote from: MyndFyre[vL] on May 15, 2006, 03:06 PM
Quote from: Yegg on May 15, 2006, 02:39 PM
http://starship.python.net/crew/theller/ctypes/
He said C++.  Meaning, he wants to use C++ classes.  C DLLs and C++ DLLs are very different.

I havn't used ctypes in quite some time, but does it not support both types of DLLs? Also, what makes the two DLLs different?

topaz

Quote from: Yegg on May 15, 2006, 02:39 PM
Quote from: Topaz on May 15, 2006, 04:31 AM
1. What, if there is, the equivalent of SendMessage() in Python?

Well, Python can interface with the Windows API.

Quote from: Topaz on May 15, 2006, 04:31 AM
2. How do you make calls to DLLs written in C++ and, if possible, VB6?

http://starship.python.net/crew/theller/ctypes/

Quote from: Topaz on May 15, 2006, 04:31 AM
3. What library is used for socket work? (hard to phrase... see: mswinsck.dll from VB6)

Python has it's own socket library which is very easy to use.

Quote from: Topaz on May 15, 2006, 04:31 AM
4. Are optimizations automatically done by the interpreter?

I believe so, I'm no Python expert.


Would you like to specify, instead of just giving yes or no answers?
RLY...?

Banana fanna fo fanna

1. If you've downloaded the win32 extensions for Python (and I'm sure you have, they're usually installed automatically, http://starship.python.net/crew/mhammond/):

import win32api
win32api.SendMessage(...)
import win32con # for constants


2. You'll probably want to use ActiveX. See http://www.python.org/windows/win32com/QuickStartClientCom.html . You also might want to wrap a C library around it and use ctypes, which is included in Python 2.5, and available at the link above.

3. Most people just use the built-in socket library ("import socket") and maybe non-blocking I/O ("import select"). If you want to access HTTP URLs, "import urllib2", or if you want to serve up web pages, "import SimpleHTTPServer". If you're looking for a hardcore (and I mean hardcore) networking framework built on Python, see www.twistedmatrix.com.

4. Yeah. If you need any more, Psyco is your man (http://psyco.sourceforge.net/). All you have to do is:

import psyco
psyco.full()

topaz

RLY...?

topaz

#8
I'll continue to add questions as I run into problems:


5. What is / how would I use arg? I've seen it around, but I can't find any documentation on it (checked MSDN, Google - just code involving it, no explanations).
RLY...?

FrOzeN

#9
Quote from: Topaz on May 18, 2006, 01:00 AM
5. What is / how would I use arg? I've seen it around, but I can't find any documentation on it (checked MSDN, Google - just code involving it, no explanations).
Not sure if this is what you ment, but I'll take a stab.

If you mean 'arg' as-in 'argc/argv', eg:
int main(int argc, char *argv[]);
Then argc is an integer containing the amount of arguements (determined by spaces) that are in the command line, and argv[] would be a character array with each part.

Eg, If you did ran the program like "yourprogram.exe Hello Something -c -bla"
argc would be 4, argv[0] would be "Hello", argv[1] = "Something", argv[2] = "-c" and argv[4] = "-bla".

[EDIT] Eh, that was C++. Anyway 'arg' essentially stands for "Command Line Arguments". This will explain it better for Python.
~ FrOzeN

Banana fanna fo fanna


rabbit

Quote from: FrOzeN on May 18, 2006, 01:44 AM
Quote from: Topaz on May 18, 2006, 01:00 AM
5. What is / how would I use arg? I've seen it around, but I can't find any documentation on it (checked MSDN, Google - just code involving it, no explanations).
Not sure if this is what you ment, but I'll take a stab.

If you mean 'arg' as-in 'argc/argv', eg:
int main(int argc, char *argv[]);
Then argc is an integer containing the amount of arguements (determined by spaces) that are in the command line, and argv[] would be a character array with each part.

Eg, If you did ran the program like "yourprogram.exe Hello Something -c -bla"
argc would be 4, argv[0] would be "Hello", argv[1] = "Something", argv[2] = "-c" and argv[4] = "-bla".

[EDIT] Eh, that was C++. Anyway 'arg' essentially stands for "Command Line Arguments". This will explain it better for Python.
You're almost correct.  In C/++, argv[0] is always how the program name.  IE: if you did 'yourprogram.exe Hello Stuff', argv[0] would be "yourprogram.exe", but if you did 'yourprogram Goodbye Moo', argv[0] would be "yourprogram".
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

topaz

RLY...?

Kp

Quote from: rabbit on May 18, 2006, 01:33 PMYou're almost correct.  In C/++, argv[0] is always how the program name.  IE: if you did 'yourprogram.exe Hello Stuff', argv[0] would be "yourprogram.exe", but if you did 'yourprogram Goodbye Moo', argv[0] would be "yourprogram".

You too, are almost correct. :)  argv[0] is chosen by the calling application, just as all other argv[] values are.  It's traditional for shells to place the program's name in argv[0], but they're not required to do so.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

rabbit

Windows does it, and based on what's been said, that's the primary platform, so that's what I went with.
Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.