473,231 Members | 1,375 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,231 software developers and data experts.

Using API Calls

Is it possible to import API calls the same way you could import other .py scripts? If so, what is the code.

Thank you for your help,
Jordan
Jul 17 '07 #1
8 3026
bartonc
6,596 Expert 4TB
Is it possible to import API calls the same way you could import other .py scripts? If so, what is the code.

Thank you for your help,
Jordan
Yes. In Python 2.5 the ctypes module is included. For 2.4 you'll have to install it.
With ctypes you can call functions in DLLs on Windows and lib (or what ever they are on *nix). It's not quite as simple as import, but works VERY well and is invaluable.
Jul 17 '07 #2
Yes. In Python 2.5 the ctypes module is included. For 2.4 you'll have to install it.
With ctypes you can call functions in DLLs on Windows and lib (or what ever they are on *nix). It's not quite as simple as import, but works VERY well and is invaluable.
I was actually hoping I could have the source code.
Jul 17 '07 #3
bartonc
6,596 Expert 4TB
I was actually hoping I could have the source code.
It's a little platform dependent, and will also vary to a degree by which library you are trying to call functions from. The ctypes documentation is full of tutorial goodies.
Jul 17 '07 #4
It's a little platform dependent, and will also vary to a degree by which library you are trying to call functions from. The ctypes documentation is full of tutorial goodies.
There is no standard way to call an API?

In VB.NET it's as simple as:

Declare Function FUNCTIONNAME Lib "DLL"(PARAMETERS)

For Example

Declare Function SwapMouseButtons Lib "user32.dll"(bSwap as Integer)
Jul 17 '07 #5
bartonc
6,596 Expert 4TB
There is no standard way to call an API?

In VB.NET it's as simple as:

Declare Function FUNCTIONNAME Lib "DLL"(PARAMETERS)

For Example

Declare Function SwapMouseButtons Lib "user32.dll"(bSwap as Integer)
ctypes is the standard way to call dll functions. You can tell that by its inclusion in version 2.5.
Jul 17 '07 #6
bartonc
6,596 Expert 4TB
ctypes is the standard way to call dll functions. You can tell that by its inclusion in version 2.5.
What I should say is: As in most other programming languages, many of the features of Python live in library modules. Just because you must import (in Python) or include (in C) or what ever, doesn't mean that it is not a standard part of the language.
Expand|Select|Wrap|Line Numbers
  1. import ctypes  as C
  2. CreateFile = C.windll.Kernel32.CreateFileA
  3.  
  4.         devHandle.value = CreateFile(devicePath,
  5.                                      win32con.GENERIC_READ | win32con.GENERIC_WRITE,
  6.                                      0, # exclusive access
  7.                                      None, win32con.OPEN_EXISTING,
  8.                                      win32con.FILE_ATTRIBUTE_NORMAL, # | win32con.FILE_FLAG_OVERLAPPED,
  9.                                      None)
  10.         if devHandle.value == INVALID_HANDLE_VALUE:
  11.             raise WinError()
Jul 17 '07 #7
What I should say is: As in most other programming languages, many of the features of Python live in library modules. Just because you must import (in Python) or include (in C) or what ever, doesn't mean that it is not a standard part of the language.
Expand|Select|Wrap|Line Numbers
  1. import ctypes  as C
  2. CreateFile = C.windll.Kernel32.CreateFileA
  3.  
  4.         devHandle.value = CreateFile(devicePath,
  5.                                      win32con.GENERIC_READ | win32con.GENERIC_WRITE,
  6.                                      0, # exclusive access
  7.                                      None, win32con.OPEN_EXISTING,
  8.                                      win32con.FILE_ATTRIBUTE_NORMAL, # | win32con.FILE_FLAG_OVERLAPPED,
  9.                                      None)
  10.         if devHandle.value == INVALID_HANDLE_VALUE:
  11.             raise WinError()
Okay, thanks for the help
Jul 20 '07 #8
bartonc
6,596 Expert 4TB
Okay, thanks for the help
Of course, in the example there are non "standard" constants imported from the pythonWin package for file attributes.
Jul 20 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
18
by: Method Man | last post by:
If I don't care about the size of my executable or compile time, is there any reason why I wouldn't want to inline every function in my code to make the program run more efficient?
11
by: ryan | last post by:
Hi, I've omitted a large chunk of the code for clarity but the loop below is how I'm calling a delegate function asynchronously. After I start the each call I'm incrementing a counter and then...
3
by: Siv | last post by:
Hi, A little while ago I wrote a small program that allowed the user to view products from a database. The database holds the details of the products which can be viewed via a form and...
11
by: GVN | last post by:
Hi All, Can anyone guide me when asynchronous method calls will be benificial? Are there any disadvantages of using asynchronous calls? Thanks,
6
by: Dasn | last post by:
Hi, there. 'lines' is a large list of strings each of which is seperated by '\t' I wanna split each string into a list. For speed, using map() instead of 'for' loop. 'map(str.split, lines)'...
13
by: cj | last post by:
I'm looking at using Using to try an plug a suspected memory leak. I've already started using dispose for everything that implements it but no luck. I have several questions about Using Can I...
1
by: yasinirshad | last post by:
Hi.. how to use joins for 4 tables.. in my query i have CALLS,STATUS,USERS,MESSAGES (4 tables). Query: "SELECT CALLS.CALL_ID, REQUESTOR, USERS.USER_NAME REQUESTOR_NAME, DESCRIPTION, TYPE, SCOPE,...
21
by: omkar pangarkar | last post by:
Hi all, I have two simple hello world programs one using printf() and other using write() --prog 1-- #include<stdio.h> #include<stdlib.h> int main() { printf("Hello"); /* up to here...
0
by: =?Utf-8?B?Tm9yYmVydCBN?= | last post by:
Dear all, I have a C# application that uses "Microsoft Excel 11.0 Object Library" to access Excel documents. This worked pretty well until ... Ok I guess I installed some update for XP ore some...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.