Re: ignoring keywords on func. call

2005-04-06 Thread Brano Zarnovican
> > Q: Can you call 'f' with keywords that will be > > ignored, without changing 'f's definition ? > > no. OK. Thank you for an answer. > what's the use case? I have extended the dict class, so that my __getitem__ accepts an optional parameter class MyTree(dict): def __getitem__(self, key,

ignoring keywords on func. call

2005-04-06 Thread Brano Zarnovican
Hi ! If I define 'f' like this def f(a): print a then, the call with keywords f(1, optional=2) fails. I have to change 'f' to def f(a, **kwrds): print a to ignore optional parameters. BUT.. Q: Can you call 'f' with keywords that will be ignored, without changing 'f's definition ? I

Re: embedded python example: PyString_FromString doesnt work?

2005-03-25 Thread Brano Zarnovican
> wierd. does: http://www.python.org/doc/2.3.­2/ext/pure-embedding.html work > for you ? Yes. It does. > ./test_String script1.py multiply 4 5 Don't run it with the ".py" suffix. The argv[1] is a module name, not a filename.. Even if you do, it may not find the module. Depending of what you ha

Re: execfile() on file subclass or string

2005-03-24 Thread Brano Zarnovican
> exec compile("code", "filename", "exec") Thanks for the tip! Works great! BranoZ -- http://mail.python.org/mailman/listinfo/python-list

Re: exec src in {}, {} strangeness

2005-03-24 Thread Brano Zarnovican
As Greg pointed.. g = {} exec open('t.py').read() in g, g is what you want. But you can write it also this way: exec open('t.py').read() in {} because if you specify only globals, the same dictionary is also used for locals. (locals() is used as a default only if you don't specify globals) OR

Re: embedded python example: PyString_FromString doesnt work?

2005-03-24 Thread Brano Zarnovican
Hi David ! I cannot see anything wrong on your code. So, I'm posting my working example. Hint: try to determine, why it is returning NULL (the PyErr_Print() call) BranoZ #include int main(int argc, char *argv[]) { PyObject *s; int ret; if (argc < 2) return -1; Py_In

execfile() on file subclass or string

2005-03-24 Thread Brano Zarnovican
Hi ! I have a python script represented by a string. I need to execute it in a context. 'exec' does the job, but doesn't display the filename in tracebacks. 'execfile' is displaying the filename but it can only exec a script in a filesystem. I have tried: - to give exec a filename, like: exec

Embeding Py: failed to instantiate a class

2005-03-22 Thread Brano Zarnovican
Hi ! I need to import a module and create an instance of a class from that module (in C). import mod o = mod.klass() (mod.klass is a subclass of tuple) When I receive a class object from the module.. module = PyImport_ImportModule("mod") cls = PyObject_GetAttrString(module, "klass") ..it fail

Embeding Py: failed to instantiate a class

2005-03-21 Thread Brano Zarnovican
Hi ! I need to import a module and create an instance of a class from that module (in C). import mod o = mod.klass() (mod.klass is a subclass of tuple) When I receive a class object from the module.. module = PyImport_ImportModule("mod") cls = PyObject_GetAttrString(module, "klass") ..it fail

Re: looking for way to include many times some .py code from another python code

2005-03-08 Thread Brano Zarnovican
On Tuesday 08 March 2005 12:41, Martin MOKREJŠ wrote: > cat somefile.py > a = 222 > b = 111 > c = 9 > > cat anotherfile.py > > def a(): > include somefile > postprocess(a) What about : def a(): exec open('somefile.py') postprocess(a) You can even use the optional dictionary parameter:

curses & disable readline & replace stdin

2005-03-04 Thread Brano Zarnovican
Hi ! I'd like to init curses and still have working Python interactive command line. I found that you can replace stdin/stdout/stderr like this: #!/usr/bin/python -i import curses import sys import atexit # this doesn't help, anyway #del sys.modules['readline'] # global variable (curses window