Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Tony

Pages: 1 ... 26 27 [28] 29 30 ... 39
406
Help and Support / Re: Returning a float array or error string
« on: September 13, 2013, 08:08:08 AM »
Hi,

great :) Yes, converting between numpy arrays or basic types (float, int, string) will be faster than using var, but unless you're returning very large arrays I don't think it's something to worry about to be honest.

best regards,
Tony

407
Help and Support / Re: Returning a float array or error string
« on: September 12, 2013, 01:54:32 PM »
Hi,

the numpy_row type expects the elements in the array to be floats, which is why I expect you're having this problem. If you check the log file you should see the exception along with the stack trace.

You could change the type to var and return a 2d array or a string depending on whether there was an error or not, i.e: something like this:

   @xl_func("int uid, int node: var") ## return type changed to var
   def py_GetNodeXYZ(uid, node):
       """Get node coordinates """
# Create empty array of c_doubles required by the API function
            XYZType = ctypes.c_double * 3
            XYZ = XYZType()
# Call API function
       ierr = St7GetNodeXYZ(uid, node, XYZ)
# If ierr <> 0 return an error string
       if ierr <> 0:
      err = py_ErrString(ierr)  # this returns an error message to err
      return err ## return a string
       else:
          return array([XYZ[0:3]])  ## return a 2d array

best regards,
Tony

408
Help and Support / Re: Using coo_matrix
« on: September 05, 2013, 09:59:33 AM »
Hi,

that's probably better asked on a scipy forum as I'm not an expert, but from a general python perspective two functions with the same name imported from different modules are different functions, and so you would have to call whichever one you want. It's possible that scipy determines the most appropriate method internally, but I don't know - you'd have to refer to the scipy docs or ask elsewhere to find that out.

Best regards,
Tony

409
Help and Support / Re: Stepping through code
« on: September 04, 2013, 08:51:17 AM »
Hi,

yes. You need a python debugger that supports connecting to a remote python process. You simply connect to your python code in Excel with the debugger as you would to debug remotely any normal python process.

One debugger than can do this is the eclipse plugin pydev. There's an example included with pyxll that shows how to attach to the remote debugger in pydev from pyxll (see 'attach_to_pydev' in http://www.pyxll.com/docs/examples/developertools.html).

If you don't want to use eclipse another alternative it winpdb (http://winpdb.org/download/ and see http://winpdb.org/docs/embedded-debugging/ for how to attach to the debugger from your python code - which you could put in a menu function).

Best regards,
Tony

410
Help and Support / Re: Using coo_matrix
« on: September 04, 2013, 08:47:00 AM »
Hi,

I'm not familiar with coo_matrix I'm afraid, but looking at the docs it seems like i and j should be vectors rather than 2d arrays? The numpy_array type is always a 2d array, even if only a single column or row is passed in. You can use the types numpy_row and numpy_column to pass 1d vectors (see http://www.pyxll.com/docs/udfs.html#using-numpy-arrays). If you want to automatically detect is a matrix only has one row or column and convert it to a vector you can use a custom type (see http://www.pyxll.com/docs/examples/customtypes.html).

You should also look at the log file as any exceptions throws will be output there, along with the stack trace. That should help you figure out what's not working.

Best regards,
Tony

411
Bugs and Suggestions / Re: 64-bit / 32 bit
« on: August 27, 2013, 01:30:03 PM »
Hi,

it's not possible to load a 32bit dll into a 64 bit process or vice versa, so there's not really much that can be done to manage these different cases other than raise an error as it does now. 32bit and 64bit processes have different paths and use different sections of the registry, so from one it's not really possible to tell that the other is installed - perhaps the error message could be extended to say to check the version of python installed matches Excel...

Your python path looks wrong to me. The python33.zip file isn't normally installed in your system folder. I would suggest uninstalling python and re-installing it completely. If you have changed the pythonpath yourself then try setting it back to how it was set by the installer.

Best regards,
Tony

412
Help and Support / Re: multiple args (was: Other decorators)
« on: July 29, 2013, 10:19:13 AM »
Hi,

the Excel C api that pyxll uses doesn't allow for this, unfortunately. You can have a function that takes multiple arguments and Excel will pass in its default value for whatever type those arguments are if you don't supply them when calling from excel - for example,

@xl_func("var a, var b_optional, var c_optional: var")
def func(a, b, c):
    return

If called as '=func(1)' then your python function will be called with b and c set to None.

There's no way to change what default value your function gets called with if no argument is supplied to Excel, as Excel always calls the function regardless of whether the user actually provided one or not.

You can pass ranges of values to a function, however, which could be a better way of writing functions that take a variable number of arguments depending on exactly what you're trying to do.

Best regards,
Tony

413
General Discussion / Re: IPython console in Excel
« on: July 29, 2013, 10:14:09 AM »
Hi Sebastian,

I think maybe you misunderstand how globals work in python. If you have a function like this:

my_global = 5
def my_function(x):
    global my_global
    my_global += x
    return my_global

Then my_global is global to the module it's defined in, not to the entire python session. For example, if you were to create a new module then it wouldn't have 'my_global' automatically visible - you have to import it from the module it's defined in.

When you work in an IPython session that has its own set of globals local to that session. If you declare a function within that session then it will see those globals, but if you import a function from another module it will not.

You simply need to import whatever globals you want from the module where your function is defined. For example, if the above code was in a module called 'my_test_code', in IPython to see 'my_global' you would need to type 'from my_test_code import my_global'.

If you want to change what is automatically in the IPython session's variables when the kernel starts you can set 'user_ns' to something other than an empty dictionary in the _start_kernel function in the code from this thread (around line 43). For example, you could change this to be 'app.kernel.user_ns = globals()' which would set the dictionary of globals you see in IPython to be the globals dict as seen from the ipython.py module - but this would still not be the same as the globals seen by your code in the other module as explained above.

See http://docs.python.org/2/library/functions.html#globals for more information about python globals (although not very much more!).

Best regards,
Tony

414
Help and Support / Re: Other decorators
« on: July 26, 2013, 09:39:52 PM »
Hi,

yes - the function the xl_func decorator is applied to needs to have the correct name, which in your case will be 'timedMethod' and not 'MergeTimeSeries' as you're expecting. You can fix your code by using the wraps decorator from the functools module, ie.

from functools import wraps

def timed(method):
    @wraps(method)
    def timedMethod(*args, **kwargs):
        ....
    return timedMethod

In the second case the decorators are applied in the wrong order. xl_func exposes the function it's applied to, which in the second case is the original function and not the result of calling timed.

Best regards,
Tony


415
General Discussion / Re: IPython console in Excel
« on: July 26, 2013, 12:44:59 PM »
Hi Sebastian,

by globals I'm guess you mean objects set at in your module - if so, you just need to import them from the module that your python functions are in, eg 'from my_module import *'

Best regards,
Tony

416
Help and Support / Re: problems with Excel 2003 and xl_func
« on: July 17, 2013, 09:42:11 AM »
Hi,

hmm that's odd then. Would you be able to send me a sample that reproduces the problem so I can take a look? You can either PM it to me, or email it to info@pyxll.com.

thanks,
Tony

417
Help and Support / Re: problems with Excel 2003 and xl_func
« on: July 17, 2013, 09:35:41 AM »
Hi,

is this using python 3? are there any special (ie non ascii) characters in your function name?

Regards,
Tony

418
Help and Support / Re: Pyxll installation problem
« on: July 16, 2013, 01:37:26 PM »
Hi,

that error is usually because you are trying to use a 32 bit python install with a 64 bit pyxll addin (or 64 bit python with 32 bit pyxll).

You need to install the correct version of python to match the version of pyxll and excel you have installed.

Best regards,
Tony

419
Help and Support / Re: installation with Excel 2013
« on: July 08, 2013, 10:14:11 AM »
Hi,

no it should work. What problem are you seeing? Do you get any error messages or anything in the log file?

One thing to try is to add the location of the pyxll addin to your trusted locations. Go into the Excel options and then into Trust Center->Trust Center Settings add the location of pyxll.xll file to the list of trusted locations (Trusted Locations -> Add new location).

Best regards,
Tony

420
Hi Dave,

are you sure it's the argument conversion that's going wrong? Could you try making your function return immediately just to double check there's not something else going on?

Best regards,
Tony

Pages: 1 ... 26 27 [28] 29 30 ... 39