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

Passing a FILE* from Python into a MinGW/SWIG module

Hi all

I understand that I can't hope to pass a FILE* from the Windows
version of Python into a SWIG module that I've built using MinGW gcc/g+
+, because apparently the FILE* structure are different and
incompatible.

Is there an official workaround for this? Presumably I need to
implement a mingw-compatible version of all the 'file' class in
Python, eg

import mingw
import myswigmodule

F1 = mingw.file("newfile.txt","rw")
F1.write("somestuff")
F1.seek(0)
F2 = mingw.tmpfile()
myswigmodule.dosomething(F1,F2)
F2.seek(0)
print F2.read()

Has anyone done this? Is there a better way that doesn't require users
of my module to adapt? Do I have to use the dreaded MSVS to compile my
SWIG module?

Cheers
JP

Mar 14 '07 #1
2 1489
John Pye <jo******@gmail.comwrote:
>Is there an official workaround for this? Presumably I need to
implement a mingw-compatible version of all the 'file' class in
Python, eg
I'm not familiar with SWIG, but why not pass Python's own file class?
Method calls on Python's file class will be dispatched to C code in
the Python interpreter and so will use the C runtime that Python was
linked with.

Ross Ridge

--
l/ // Ross Ridge -- The Great HTMU
[oo][oo] rr****@csclub.uwaterloo.ca
-()-/()/ http://www.csclub.uwaterloo.ca/~rridge/
db //
Mar 15 '07 #2

On 14 mar 2007, at 11.57, John Pye wrote:
Hi all

I understand that I can't hope to pass a FILE* from the Windows
version of Python into a SWIG module that I've built using MinGW
gcc/g+
+, because apparently the FILE* structure are different and
incompatible.

Is there an official workaround for this? Presumably I need to
implement a mingw-compatible version of all the 'file' class in
Python, eg

import mingw
import myswigmodule

F1 = mingw.file("newfile.txt","rw")
F1.write("somestuff")
F1.seek(0)
F2 = mingw.tmpfile()
myswigmodule.dosomething(F1,F2)
F2.seek(0)
print F2.read()

Has anyone done this? Is there a better way that doesn't require users
of my module to adapt? Do I have to use the dreaded MSVS to compile my
SWIG module?

Cheers
JP
Can you get the file descriptor from the FILE *, and use that?

-------------------------------------
This sig is dedicated to the advancement of Nuclear Power
Tommy Nordgren
to************@comhem.se

Mar 15 '07 #3

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

Similar topics

1
by: orion30 | last post by:
I would like to know if somebody has successfully uses SWIF using MSYS / MINGW32 / PYTHON. I tried to do it but apparently, I failed. Is there somebody who can help me and give a little...
3
by: kj.kjn | last post by:
My function func(File * des) is embedded in a module swig. I would to know how to call this function from python script and if it's necessay to declare a typemaps ? Thank you
0
by: Phil Schmidt | last post by:
I'm attempting to follow the instructions at http://sebsauvage.net/python/mingw.html, without luck. I have Python 2.3, MinGW 3.2.3, ans SWIG 1.3.19. I get an export error on "initexample" when...
13
by: Roy Smith | last post by:
I've got a C library with about 50 calls in it that I want to wrap in Python. I know I could use some tool like SWIG, but that will give me a too-literal translation; I want to make some...
1
by: Leonard J. Reder | last post by:
Hello, I have been trying to get this simple call to work with a SWIG interface. The problem is I do not know how to pass a const char * or a std::string & in python to SWIG wrapped code. I...
1
by: nimitsis | last post by:
Hello everyone I am trying to use a module , which I have create by using Swig. This module has C code with embedded Python . The relative code follows : // main.c #include "Python.h"...
0
by: abarun22 | last post by:
Hi I am facing a problem while including a C header file in the SWIG interface file. However the problem does not occur when i directly copy the contents of header file in the same place. My...
1
by: Harika | last post by:
hi everybody Iam learning python. I have to write test scripts for c files. I did using swig and python. Using python i give input to a function and gets the output and shown using python script...
2
by: mathieu | last post by:
Hi there, I have prepared binaries of a python module that I wrote. Basically the lib is written in C++ and wrapped in python using SWIG. Of course it links to the python dynamic libraries. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
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...
0
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...

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.