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
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:
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
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
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
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
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
> exec compile("code", "filename", "exec")
Thanks for the tip!
Works great!
BranoZ
--
http://mail.python.org/mailman/listinfo/python-list
> 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
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
> > 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,
11 matches
Mail list logo