ected behavior or a
bug in the 2to3 script?
-farshid
--
http://mail.python.org/mailman/listinfo/python-list
looking at your code in the future. So use it at your own risk!
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362305
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
J. Clifford Dyer wrote:
> I think you mean '\n'.join([string1,string2,string3])
>
> You actually do want the \ to do its thing in this case.
Yeah, my brain must still be asleep. Thanks for waking it up :)
--
http://mail.python.org/mailman/listinfo/python-list
newlines between the strings then you can do
the following:
String = '\\n'.join([string1,string2,string3])
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
ing_the_interpreter.html
>
> btw what kind of object is returned in case i use Py_file_input
> in PyRun_String?
>
Yes, you can keep a reference to maindict if you wish, but make sure you
increment the reference count since PyModule_GetDict() returns a
borrowed reference.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
portModuleEx()
function. You can use the PyImport_AddModule() function as before, but
you must explicitly add the module to the __main__ module. Here is some
code:
PyObject *mainmod = PyImport_AddModule("__main__");
PyObject *foo = PyImport_ImportModule("foo");
Py_INCREF(foo); //
t;__main__");
PyObject* maindict = PyModule_GetDict(mainmod);
foo = PyImport_ImportModuleEx("foo", maindict , maindict , NULL);
bar = PyImport_ImportModuleEx("bar", maindict , maindict , NULL);
Once the modules are imported into the __main__ scope, you should be
able to use PyRun_SimpleString() to evaluate expressions.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
, if you wanted to get the value of an integer in the __main__
module named "foobar", you would do the following:
PyObject *m = PyImport_AddModule("__main__");
PyObject *v = PyObject_GetAttrString(m,"foobar");
int foobar = PyInt_AsLong(v);
Py_DECREF(v);
You will probably
t;", line 2, in
> TypeError: Error when calling the metaclass bases
> module.__init__() takes at most 2 arguments (3 given)
In your code 'zipfile' is a module, not a class, so you cannot inherit
from it. I believe this is what you are trying to accomplish:
class walkZip(zipfile.ZipFile):
pass
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
, it would be easier to tell what the problem is.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
Stefan Bellon wrote:
> Thanks for your hints ...
>
> The interesting part is "Call python code". In my example this is done
> with PyRun_SimpleString which does not return if an exception is not
> handled but raised "out of" the interpreter. So I am unsure of what you
> mean with "Call python code
Stefan Bellon wrote:
> Hi all!
>
> I am embedding Python into a GUI application in a way that the GUI is
> scriptable using Python.
>
> Now I have come to a problem that when the user puts a "sys.exit(0)"
> into his script to end the script, not only the script is terminated,
> but also the GUI a
beginner wrote:
> I did and it did not seem to work. I ended up doing the following.
> Verbose, isn't it?
> If I do d=PyFloat_AsDouble(oDiscount); in the third "if", I get an
> error. Maybe I missed something obvious.
That's strange. I just tried the following code:
fprintf(stdout,"True = %lf\n",
beginner wrote:
> This works with PyFloat only. It does not work with integers.
Did you try it out? I have used it on ints, bools, and objects that
implement the __float__ method. It does not work on strings though.
--
http://mail.python.org/mailman/listinfo/python-list
beginner wrote:
> I know obj is a number, but I do not know the exact type. How can I
> convert it to double without writing a giant switch() that exhausts
> every single type of number?
Try using the PyFloat_AsDouble(...) function, it should be able to
convert an object to a double, as long as t
is
is what most of Python's built-in functions do.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
tending/embedding
python. I believe it does exactly what you want.
http://www.python.org/doc/ext/extending-with-embedding.html
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
Farshid Lashkari wrote:
> When two integers are involved in a division, the result will also be a
> division.
My bad, I meant the result will also be an *integer*
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
one of the operands is a float, then the result will be a
float instead. So try casting one of the values to a float before
performing the division:
dx = float(abs(i2 - i1))/min(i2, i1)
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
t;>> L = [1]
>>> L += (2,)
>>> L
[1, 2]
It seems like the '+' operator for lists should accept any iterable for
the right side argument to be consistent with extend() and the '+='
operator.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
27;t
consider it bad programming style to allow your functions to accept
multiple data types.
def MyFunction(val):
if isinstance(val,basestring):
val = [val]
for s in val:
#Process string
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
g call at the beginning of your application:
PyEval_InitThreads()
From my experience, calling PyGILState_Ensure() was enough. I didn't
need to call any extra threading functions. But make sure that every
call to PyGILState_Ensure() is matched with a call to PyGILState_Release()
-Far
kw):
Character.__init__(self, *args, **kw)
self.health += 2
self.strength += 1
This way, if you add a new parameter to the base class, you won't need
to update all the derived classes.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
for creating extension modules,
especially the following page:
http://docs.python.org/ext/methodTable.html
"The initialization function must be named initname(), where name is the
name of the module, and should be the only non-static item defined in
the module file"
-Farshid
--
http:
aced the logging after the call to the real function so that files
that don't exist will not be logged. However, I'm already checking for
file existence during the post process of the script running, so I guess
it doesn't really make too much of a difference.
Thanks for the help.
will still fall through my checks,
especially file opens from C extensions, which is fine. I just want to
be able to detect the most common use cases. Any other suggestions are
appreciated.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
odule using
the following syntax:
reload(mymodule)
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
D_OK:
> db_name = dlg.GetValue()
> dlg.Destroy()
> return db_name
>
> but I suppose it's a matter of preference.
Yeah, I think the second way is usually used by people who are more
accustomed to programming in C, since they need to initialize variables.
Yo
s should work:
def create_db_name(self):
dlg = wx.TextEntryDialog(self.frame, 'Enter a database name:',
'Create New Database')
db_name = None
if dlg.ShowModal() == wx.ID_OK:
db_name = dlg.GetValue()
dlg.Destroy()
return db_name
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
do something like Py_BuildValue("i", 123), but see
> http://docs.python.org/ext/buildValue.html for more info.
Simon is correct. You need to create a python object from your unsigned
int. Try the following instead:
PyTuple_SET_ITEM(toRet, i, PyInt_FromLong(dat[i]) );
-Farshid
--
http://m
get.get_text()
print first_name
If you want these variables to be assigned to an object then you can use
setattr():
name = 'first_name'
setattr(obj,name,widget.get_text())
print obj.first_name
Hope this helps
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
t the GIL is already acquired. All I can think of so far is the
following:
PyGILState_STATE state = PyGILState_Ensure();
Py_BEGIN_ALLOW_THREADS
//do processing
Py_END_ALLOW_THREADS
PyGILState_Release(state)
Is there a better way?
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
Digital Logic wrote:
> Am I checking for the slice object incorrectly? That's the only thing
> I can think of.
Yes. The slice object is the "i" variable in your code, not the "data"
variable.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
e OP said he wanted to print out that error message
whenever the interpreter came across any IndexError. So I gave him what
he wanted. I guess he needs to be more careful what he wishes for ;)
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
; before it exits?
Hi,
Try placing the try/except block around the main function of your program:
if __name__ == '__main__':
try:
main()
except IndexError:
sys.exit("That number is way too big!")
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
r = msvcrt.getch()
Keep in mind that this will only work on windows.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
ling "self"s in all over
> the place to see if that helps, but without much of an idea of what it
> really achieves.
>
> Thanks in advance!!
>
Hi,
Take a look at the following FAQ on the python homepage:
http://www.python.org/infogami-faq/general/why-must-self-be-us
it
worked fine.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
it might not be in the current version of python.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
mbedding.html
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
l also become garbage collected at the end of the
constructor. Are you sure this is the case?
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
t seems as thought with 2, the
"image" variable is garbage collected after the constructor of Main is
called. With 1, you save a reference to the image, so it does not get
garbage collected.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
tuple = PyTuple_GetItem(args,i);
if(!PyArg_ParseTuple(tuple,"sff",...) {
//handle error
Py_RETURN_NONE;
}
}
}
Also, you need to INCREF Py_None before you return it. Or you can use
the macro used in the sample code above.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
t;
Since you know the type, you would use boost::any_cast to convert it to
that type. You can find information about it here:
http://www.boost.org/doc/html/any.html
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
You don't need to pass the object along with the method. The method is
bound to the object. Simply call the method by itself:
def ObjApply(method):
method()
class Test:
def test1 (self): print "Hello"
def test2 (self):
ObjApply(self.test1)
ta = Test ()
ta
I asked a similar question a few weeks ago. I think the answers I got
will also answer your question as well. Here's a link to the thread:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/2f6f1d399ba94a7b/f564a219ffe44149?lnk=st&rnum=1&hl=en#f564a219ffe44
e in 'rbU' mode. This will use universal newline mode
and convert all carriage returns to line feeds.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
> I am working on a script to get parts of raw data out of a file, and
> the data I read has to be the data written in the file without CR or
> LF.
So you just want to remove all the linefeeds? This should work then:
data = data.replace('\n','')
-Farshid
--
h
just being curious :)
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
> It just boils down to either a LOAD_CONST vs. a LOAD_NAME - either way
> the string isn't duplicated.
Great, that's exactly what I wanted to know. Thanks Steve!
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
stated, is it not important at all?
Thanks,
Farshid
--
http://mail.python.org/mailman/listinfo/python-list
't understand the point of your last expression. Were you intending
this instead:
>>> c is a
True
However, the following commands add to my confusion:
>> a = 'wtf?'
>> b = 'wtf?'
>> a is b
False
So how are string literals ca
Gregory PiƱero wrote:
> Let's say I have a module named "Excellent Module.py"
ExcellentModule = __import__('Excellent Module')
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
This leads me to believe that python does reuse existing strings, but
once the variables are removed, does the item still exist in the cache?
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
Sounds like the popen2 module should suffice. Take a look at the
documentation for the module here:
http://www.python.org/doc/lib/module-popen2.html
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
hon to say "You, Parent
> Object, do ...stuff!"
Use the super() function to access an attribute of a parent clas
class C(B):
def meth(self, arg):
super(C, self).meth(arg)
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
f example? Here is a link to a two
part tutorial on Code Project that might help you out:
http://www.codeproject.com/cpp/embedpython_1.asp
http://www.codeproject.com/cpp/embedpython_2.asp
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
f my fscking mind?
>
What do you mean by DJing? Queueing and playing audio files? If so,
python should work fine. Check out the PyMedia library for
playing/mixing audio with python.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
result) {
//Do something with result
Py_DECREF(result);
}
Py_DECREF(func);
}
Have a look in the "Python/C API Reference Manual" for more information.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
():
global _expensiveObject
if not(_expensiveObject):
_expensiveObject = "A VERY Expensive object"
return _expensiveObject
The documentation will no doubtedly explain it better than I have
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
It's definitely possible, here's a small example. There are probably
better ways to do it, but I'll let you figure that out ;)
class ErrorHandler:
def __init__(self,method):
self.method = method
self.errorHook = None
def onError(sel
hod name.
Here's a simple example:
class MyClass:
def DummyMethodName(self): pass
setattr(MyClass,'NewMethodName',MyClass.DummyMethodName)
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
video
import input
I've never actually tried this, but I don't see why it wouldn't work.
Let me know how it goes.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
ss, or NULL on failure".
So it seems like the call is failing. My guess would be that modules are
not callable objects. Also, this seems somewhat redundant since your
module is effectively executed when you import it using the
PyImport_Import function.
-Farshid
--
http://mail.python.o
exits. Here is a sample code snippet:
//Called when python exits
void CleanupModule(void)
{
//Perform cleanup here
}
Then in your init function add the following code:
//Register function to be called when python exits
Py_AtExit(CleanupModule);
-Farshid
--
http://mail.python.org/mailman
> How can I modify the python search-path from within the script, thus it
> contains the doc directory?
Hi,
The sys.path variable is a list of strings that contains the current
module search path. You can add your own path to this list:
import sys
sys.path.append('../')
-
s of namespace
namespace.sys = mysys
This seems like it should work, however I don't know if copying the
entire dictionary of one module to another is a safe thing to do.
-Farshid
--
http://mail.python.org/mailman/listinfo/python-list
Grazie!
Paolino wrote:
> Farshid Lashkari wrote:
>
>> Hi,
>>
>> I have an object and I want to check if it is a bound or unbound
>> method, or neither. I tried using the types module, but it seems as
>> though types.UnboundMethodType and types.MethodType are
Hi,
I have an object and I want to check if it is a bound or unbound method,
or neither. I tried using the types module, but it seems as though
types.UnboundMethodType and types.MethodType are equal. How else can I
determine this? BTW, I'm using Python 2.3
Thanks,
Farshid
--
This will get the name of an objects class
obj.__class__.__name__
This will return a tuple of its base classes
obj.__class__.__bases__
Christopher J. Bottaro wrote:
> I actually want all the parent classes too. So if D derives off C derives
> off B derives off A, I ultimately want a tuple ('D'
70 matches
Mail list logo