hello everyone,

I am new to python so I need help about .pyd file
I have a xxx.pyd file which is basically a merge of many .h5 data files.
I have to use this xxx.pyd files(merge of simulations files) and compare it with one experiment data file which is also a .h5
i am using a linux machine.
So, my question are
what exactly is .pyd files?is it an executable file?
how i can use it for my purpose?

can someone help?
thanx in advance

Extension .pyd is used for C compiled library files for Python.

Member Avatar for leegeorg07

basically what bumsfield said is right but i like to think of them as the dll's of the python world

basically what bumsfield said is right but i like to think of them as the dll's of the python world

Well they actually really are dlls. It's just that the routines inside are built on the python C API.

To use them, just import them like any other module.

Member Avatar for leegeorg07

oh cool!

Extension .pyd is used for C compiled library files for Python.

Files with extension .pyd are library files for Python and are accessed with the import statement. I would recommend not to use this extension for private files that are not specifically structured Python library files.

Thanx guys for your help.
I could not solve my problem yet but i made some progress.
I am sorry for my terrible programming skills :))
So again, I have something to ask with the hope that i problem will be solved with the help of you guys.
I have a python script named mesharray.py (see below)
and a filename.pyd(a merge of simulations data files) both are in the same folder
I want to this .pyd file to compare it my experimental data file
I came to know from a friend who couldn't make it more clear. that the following python script can be used to manipulate individual simulations file merged in filename.pyd

import cPickle
fil = open('filename.pyd','rb')
I = cPickle.load(fil)
Print I[0.9]

and its give me for I less than( or equal to) 1

<mesharray.mesharray object at 0xa3318ac>

for any value above 1, I get error

Traceback (most recent call last):
  File "new file.py", line 5, in <module>
    print I[1.1]
  File "mesharray.py", line 61, in __getitem__
    item = self.mapitem(item)
  File "mesharray.py", line 135, in mapitem
    indexlist[i]=mapping(x,value)
  File "mesharray.py", line 144, in nearest
    raise IndexError, 'Value out of bounds.'

but i dont unstand what exactly its doing?
can someone explain?
I have attached the mesharray.py file below

thanx in advance!!

import warnings
import numpy

class mesharray(object):

    def __len__(self):
        return self.data.__len__()

    def __iter__(self):
        return self.data.__iter__()

    def __init__(self,data,*args,**dict):
        self.data=data
        self.meshmap={}
        self.meshdict={}
        for arg in args:
            name,data,pos,write = arg
            self.setmesh(name,data,pos,write)
        for key,value in dict.iteritems():
            if key=='mapping':
                self.mapping = getattr(self,value)
            else:
                raise ValueEror, 'Argument not understood.'

    def __call__(self,**dict):

        mapping = self.mapping

        indexlist=[]

        for i in range(self.data.ndim):
            indexlist+=[slice(None, None, None)]

        meshmap  = self.meshmap
        meshdict = self.meshdict

        for key, value in dict.iteritems():

            if not meshdict.has_key(key):
                raise KeyError, 'Key %s not found in meshict.' % key

            pos = meshdict[key]
            x=getattr(self,key)

            if type(value)!=slice:
                indexlist[pos]=mapping(x,value)

            elif type(value)==slice:
                start = mapping(x,value.start)
                stop  = mapping(x,value.stop)
                step  = value.step
                indexlist[pos]=slice(start,stop,step)

        indextuple=tuple(indexlist)

        return self.data[indextuple]


    def __getitem__(self, item):

        item = self.mapitem(item)

        return self.data[item]


    def __setitem__(self,item,value):

        item = self.mapitem(item)

        self.data[item]=value


    def setmesh(self,name,data,pos,write):

        if type(name)!= str:
            raise TypeError, 'Mesh name must be a string.'

        if type(data) != numpy.ndarray:
            raise TypeError, 'Mesh data must be of type numpy.ndarray.'

        if len(numpy.shape(data)) != 1:
            raise ValueError, 'Mesh must be one-dimensional.'

        if type(pos)!= int:
            raise TypeError, 'Mesh position must be of type int.'

        ndim = self.data.ndim

        if pos >  ndim - 1 or pos < -ndim :
            raise ValueError, 'Mesh position out of array dimensions.'

        if pos < 0:
            pos = pos + ndim

        setattr(self,name,data)

        self.meshdict[name]=pos
        if write:
            self.meshmap[pos]=name


    def mapitem(self,item):

        mapping = self.mapping

        if type(item) != tuple:
            item = (item,)

        indexlist = list(item)

        meshmap=self.meshmap

        for i, value in enumerate(indexlist):

            if not meshmap.has_key(i):
                continue

            if meshmap[i]==None:
                continue

            x=getattr(self,meshmap[i])

            if type(value) == numpy.ndarray:
                indexlist[i]=value

            elif type(value) == slice:
                start = mapping(x,value.start)
                stop  = mapping(x,value.stop)
                if stop != None:
                    stop = stop + 1
                step  = value.step
                indexlist[i]=slice(start,stop,step)

            else:
                indexlist[i]=mapping(x,value)

        return tuple(indexlist)


    def nearest(self,x,x0):
        if x0==None:
            return None
        if x0<x[0] or x0>x[-1]:
            raise IndexError, 'Value out of bounds.'
        if x0==-numpy.inf:
            return 0
        if x0==numpy.inf:
            return -1
        i = x.searchsorted(x0)
        if abs(x[i]-x0) <= abs(x[i-1]-x0):
            return i
        else:
            return i-1


    mapping = nearest


# data=empty((10,20,30))
# meshx=arange(1,11)
# meshy=arange(1,21)
# mesht=arange(1,21)**2
# meshz=arange(1,31)
# l=mesharray(data,('meshx',meshx,0,1),('kappar',meshy,1,0),('zeta',mesht,1,1))

# for x in l:
#   print x

# data = array((-10,-1,0,1,10))
# mesh = array((-inf,-1,0,1,inf))
# a=mesharray(data,('mesh',mesh,0,1))
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.