braver wrote:
> Is there any trick to get rid of having to type the annoying,
> character-eating "self." prefix everywhere in a class? Sometimes I
> avoid OO just not to deal with its verbosity. In fact, I try to use
> Ruby anywhere speed is not crucial especially for @ prefix is better-
> lookin
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
dmitrey wrote:
> Hi all,
> I have some strings, let it be string1, string2, string3.
>
> So how could String=
> """
> string1
> string2
> string3
> """
>
> be obtained?
>
> Thank you in advance, D.
If you just want the to add newlines between the strings then you can do
the following:
String
[EMAIL PROTECTED] wrote:
> it works!
> could i cache maindict pointer in a global var or am i condemned to
> call
> PyObject* mainmod = PyImport_AddModule("__main__");
> assert(mainmod);
> PyObject* maindict = PyModule_GetDict(mainmod);
>
[EMAIL PROTECTED] wrote:
> i switched to PyImport_ImportModuleEx per your suggestion but i still
> get
>
> Traceback (most recent call last):
> File "", line 1, in ?
> NameError: name '__main__' is not defined
>
> i tried PyRun_SimpleString("__main__.foo.baz()"); :
> Traceback (most recent call
[EMAIL PROTECTED] wrote:
> suppose i have imported two modules foo and bar with
> foo=PyImport_ImportModule("foo") and bar=PyImport_ImportModule("bar")
> respectively.
>
> Now suppose I have an artitrary python expression to evaluate.
> Do I need to parse that thring and check for foo. and bar. be
[EMAIL PROTECTED] wrote:
>>From the C API (I'm using Python embedded), how can I get and set the
> value of named variables? Right now, I'm using hacks like
> PyRun_SimpleString("foobar = 12\n"), but I'd really like to access the
> named objects directly.
>
You can use the following C functions
Larry Bates wrote:
> import zipfile
> class walkZip(zipfile):
> pass
>
>
> if __name__ == "__main__":
> print "Hello World"
>
> Traceback (most recent call last):
> File "", line 192, in run_nodebug
> File "", line 2, in
> TypeError: Error when calling the metaclass bases
> modu
TheShadow wrote:
> When extending python in c/c++ after you register a module is there a
> way in c/c++ to check if they were correctly registered?
>
> Cause I'm having the problem where when I execute the the python
> script it finds the module but none of the functions.
>
Are you calling Py_In
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
Stuart wrote:
> I'm asking if there's some sort of commenting or input file or
> something to customize the output pydoc generates. Thanks.
AFAIK, there is no way to do this. However, you can edit the doc string
for your function, which can include the argument list. I believe this
is what most
[EMAIL PROTECTED] wrote:
> At the moment i can run python-string-code from C (MinGW, WinXP)
>
> But how can i register a C-function in python-RUNTIME and call this C
> function from python - without wrapper dll's or libs???
Have a look at the following documentation page on extending/embedding
p
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
[EMAIL PROTECTED] wrote:
> Hi, I have the following functions, but ' dx = abs(i2 - i1)/min(i2,
> i1)' always return 0, can you please tell me how can i convert it from
> an integer to float?
When two integers are involved in a division, the result will also be a
division. If one of the operands
Szabolcs Nagy wrote:
L=[1]
L.extend((1,))
L
> [1, 1]
Are list.extend() and list concatenation supposed to behave differently?
I always thought concatenation was just shorthand for calling extend().
However the following seems to work:
>>> L = [1]
>>> L += (2,)
>>> L
[1, 2
manstey wrote:
> Is there a neat way to write a function that can receive either a
> string or a list of strings, and then if it receives a string it
> manipulates that, otherwise it manipulates each string in the list?
The following code shows one way you can accomplish this. I don't
consider it
Svein Seldal wrote:
> I'm unable to get access to python as long as another python call is
> executing. The PyEval_AcquireThread() call blocks until the first call
> returns. I was hoping that the python system itself would release the
> GIL after some execution, but it itsnt.
>
> I am dependen
John Salerno wrote:
> Ok, back to my so-called "game." I'm just curious if I've implemented
> the subclasses properly, because it seems like an awful lot of
> repetition with the parameters. And again, if I want to add a new
> attribute later, I'd have to change a lot of things. I can't help but
Sheldon wrote:
> Can anyone give me some idea as to what this error means?
>
> "ImportError: dynamic module does not define init function "
>
> I am new at this and there is still a lot to learn.
>
> Any help is appreciated,
Take a look at the documentation for creating extension modules,
espe
Dale Strickland-Clark wrote:
> You might consider trapping calls to file() too, which is an alias for
> open().
Thanks, I didn't know about that.
> Also, I think I'd do my logging before calling the real function. It depends
> how you want to deal with exceptions.
I placed the logging after the
Hi,
My goal is to detect all (or most) file dependencies of a script (i.e.
modules, dlls, data files). Currently, after a script is finished
executing I use sys.modules to determine all module dependencies, and I
use win32process.EnumProcessModules to determine DLL dependencies. This
works rea
[EMAIL PROTECTED] wrote:
> Wouldn't importing and re-importing the same modules cause considerable
> resource bulk? Or does python cache that stuff?
If a module is already imported, then the import statement just uses the
cached module. However, you can force a full reload of the module using
th
Paul Rubin wrote:
> I like
>
> if dlg.ShowModal() == wx.ID_OK:
> db_name = dlg.GetValue()
> else:
> db_name = None
> dlg.Destroy()
> return db_name
>
> better than
>
> db_name = None
> if dlg.ShowModal() == wx.ID_OK:
> db_name = dlg.GetValue()
>
John Salerno wrote:
> Hi guys. I'm looking for a nicer, more compact way of writing this code.
> It doesn't have to be anything fancy, just something without the
> duplication and preferably only one return statement.
>
> def create_db_name(self):
> dlg = wx.TextEntryDialog(self.fram
Simon Forman wrote:
> I have not done a great deal of extension work with python, however, I
> do not believe you can simply cast an int (or pointer to int, which is
> what you say dat is declared as, unless my C is /really/ rusty) to
> PyObject*.
>
> I think you need to do something like Py_Build
Hi John
John Salerno wrote:
> how would I go about putting these variable names in a list? I know I
> can't leave them as above, but if I put them in as a string, then how do
> I later "transform" them into an actual variable for assign, such as:
>
> first_name = widget.get_text()
>
> Is there
Hi,
Is there a proper way for C code to ensure that the GIL is released? I
know about PyGILState_Ensure and PyGILState_Release, but that is to
ensure the GIL is acquired. I have some extension code that does heavy
processing and I want to release the GIL, but the code can't be sure
that the GI
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
Steven D'Aprano wrote:
> That's broken.
>
> Imagine that somewhere in main() the following is called:
>
> D = {"a": "apple", "b": "bicycle", "c": "cat"}
> print D["aardvark"]
>
> Your code now prints "That number is way too big!". That's not good.
>
> try...except blocks should, as a general r
Chris wrote:
> But sometimes you can have too many of these statements in your
> program, and it starts to get tangled and nasty looking. Is there a way
> I can modify sys.error so that when the interpreter comes accross an
> IndexError it prints "That number is way too big!" before it exits?
Hi,
placid wrote:
> is there a way to do this, wait for user input but dont block?
Hi,
The msvcrt module should do what you want. Here is a sample:
import msvcrt
chr = 0
while chr != 'q':
""" keep printing text """
if msvcrt.kbhit():
chr = msvcrt.getch()
Keep in mind that this
donkeyboy wrote:
> This is probably a really basic question, but anyway ...
>
> I'm new to both Python and OO programming. From looking at a number of
> code examples, the word "self" is used a lot when referring to classes.
> As such, what does "self" mean and/or do? I've read things that say
> i
The windows distribution of python was compiled with Visual Studio 7.1,
so you need the 7.1 runtime libraries on your computer to run python. I
haven't tried compiling an app with VS2005, but I don't see why they
would be incompatible. I've compiled a python app using VS 7.0 and it
worked fine.
Andre Meyer wrote:
> Am I missing something here? What is the preferred pythonic way of
> implementing singleton elegantly?
The "Open Issues" section of that PEP says the following:
"It's exceedingly unlikely that class decorators will be in Python 2.4"
So it might not be in the current version
[EMAIL PROTECTED] wrote:
> I want to call add from C. Could anybody please help me?
Look at the "Pure Embedding" section of the python documentation. It
contains an example program that does exactly what you want. Here is a
link to the page:
http://www.python.org/doc/ext/pure-embedding.html
-F
Schüle Daniel wrote:
> thx for quick reply :)
>
> image is local variable of imageLabel
> I would expect that in case imageLabel lives, it should
> hold alife objects bound to its local variables
>
> I am just curious *why* reference to image is not hold by imageLabel
> which on his part is hold
Schüle Daniel wrote:
> I don't understand what is the difference between commented lines
> 1 and 2
>
> with 1 uncommented and 2 commented it works as expected
> with 1 commented and 2 uncommented the picture doesn't appear
I'm not familiar with Tkinter, but it seems as thought with 2, the
"imag
[EMAIL PROTECTED] wrote:
> Hi,
> I want to pass something like this to a C function via the Python C
> API.
> mytuple = (("string_one", 1.2, 1.3), ("string_two", 1.4, 1.5), ..,
> ., )
> This tuple is dynamic in size, it needs to be 3 X N dimensions. each
> tuple in the
> tuple array is of
> Any suggestions are very welcome!
Are you allowed to use any boost libraries? If so then boost::any would
probably help. The boost::any object can contain any object type. So you
could have a single container that looked like the following:
std::map< std::string, std::vector > result;
Since
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#f564a219ffe44149
-Farshid
--
http
> When I do this I get the first 634 bytes. I tried using the:
> f = open('myfile,'rb')
> option, but now there are a few 0x0D bytes extra in myfile. 0x0D =
> Carriage return. How can I make a program that not puts in the 0x0D
> bytes in windows.
Try opening the file in 'rbU' mode. This will use
> 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
--
http://mail.python.org/mailman/listi
> A few comments (which I hope are correct, but which I hope you will read
> then mostly ignore since you probably shouldn't be designing based on
> this stuff anyway):
Thanks for the info Peter. My original question wasn't due to any
observed performance problems. I was just being curious :)
> 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
> I really don't understand why it's so important: it's not a part of the
> language definition at all, and therefore whatever behavior you see is
> simply an artifact of the implementation you observe.
I guess I should rephrase my question in the form of an example. Should
I assume that a new
> It takes far too little evidence to induce belief:
>
> >>> a = "hello"
> >>> b = "h"+"ello"
> >>> a is b
> False
> >>> c = "hello"
> >>> b is a
> False
> >>>
I don't understand the point of your last expression. Were you intending
this instead:
>>> c is a
True
However, the following c
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
When I pass an empty string to a function is a new string object created
or does python use some global pre-created object? I know python does
this with integer objects under a certain value. For instance, in the
following code is a new string object created for each function call?
func(0,'')
f
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
> Is there a simple way to get the current object's name? You would think
> __name__ would work, right? It doesn't.
className = item.__class__.__name__
> I'd like to avoid passing a reference to an object's parent in
> __init__, but is there a built in way in Python to say "You, Parent
> Object,
John Dean wrote:
> Hi
>
> Could somebody, please tell me where I can find information about embedding
> Python into a C/C++ application. The example in the docs is rather simple. I
> am looking for something a bit more complex and longer
>
Are you looking for a specific kind of example? Here is
Levi Campbell wrote:
> Hi, I'm thinking about writing a system for DJing in python, but I'm
> not sure if Python is fast enough to handle the realtime audio needed
> for DJing, could a guru shed some light on this subject and tell me if
> this is doable or if I'm out of my fscking mind?
>
What do
> Can anybody tell me how to call "f" in my C code?
Assuming you already have a handle to an instance of MyClass this should
do the trick:
PyObject *func = PyObject_GetAttrString(MyClassInst,"f");
if(func) {
PyObject *result = PyObject_CallObject(func,NULL);
if(result) {
//Do
You need to declare _expensiveObject as global inside your function.
Whenever you assign something to a variable that resides in the global
scope inside a function, you need to declare it as global at the
beginning of the function. So your function should look like this
def ExpensiveObject():
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
> Is it possible to have method names of a class generated somehow dynamically?
If you don't know the name of the method ahead of time, how do you write
the code for it? Do you use some dummy name? If so, once you have the
name determined then you could use setattr to set the method name.
Here'
> I have a dll that contains all kinds of services (input, audio, video,
> etc..), and I would like to export these to Python as separate modules.
> Now, if I call Py_InitModule with a name that's different than the dll
> name, I get an error. So what can I do?
I believe you can export differe
> The problem is that PyObject_CallObject always returns NULL. Is this the
> correct return value for simply executing a script, as there is no function
> return value involved?
The documentation for PyObject_CallObject states the following:
"Returns the result of the call on success, or NULL on
> Can C extended python modules provide any kind module destructor, so
> that whenever the module is unloaded some cleanup is run?
I've needed the same thing before but couldn't find it. AFAIK, the best
you can do is register an exit function that will be called when python
exits. Here is a sa
> 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('../')
-Farshid
--
http://ma
Fuzzyman wrote:
> Is there another way to shadow the sys module from a single namespace ?
I've never actually tried this, but try making a copy of the sys module
then replacing the stdout object with your own object. Then you can
replace "sys" of the namespace with your custom "sys" module. I gu
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
--
http://mail.pyth
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'
69 matches
Mail list logo