python datetime
Hi, How to determine a date is just the 7th day after today ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep the 7th day is 5 Oct,is there simple way to do this work? I wish I explained clear Bests, -- http://mail.python.org/mailman/listinfo/python-list
Re: python datetime
Thank you,the timedelta class is awesome. On Tue, Sep 14, 2010 at 3:50 PM, Michael Ricordeau < [email protected]> wrote: > > # Determine diff days between two dates > import datetime > now = datetime.date(2010, 9, 28) > next = datetime.date(2010, 10, 5) > delta = next - now > > #delta is datetime.timedelta type. > #(You can extract days diff) > > # Determine date in 7 days > import datetime > now = datetime.date(2010, 9, 28) > delta = datetime.timedelta(days=7) > next = now + delta > > > > > > > > > > > Le Tue, 14 Sep 2010 14:41:09 +0800, > Von a écrit : > > > Hi, > > How to determine a date is just the 7th day after today > > ie: today is 14 Sep the 7th day is 14+7 = 21,but assume today is 28 Sep > the > > 7th day is 5 Oct,is there simple way to do this work? > > I wish I explained clear > > > > Bests, > -- http://mail.python.org/mailman/listinfo/python-list
python tkinter Listbox
Hi all, I am building a simple tool using tkinter,and need multiselection checklist.I find that Listbox with option selectmode=tkinter.MULTIPLE could do this for me. But when I have two Listboxs,I do some selection with one,then do selection with another one,the previous listbox get cleared.I wonder how to keep the previous listbox selected. Wish I explained clear. Regards. -- http://mail.python.org/mailman/listinfo/python-list
python call a procedure at the specified time
Hi, I have a python script running behind the scene,and I need it to call a method on sunday 9 o'clock. I get an idea,that I get the current time,and calculate the seconds to sunday 9 o'clock, then sleep these seconds and call my method,I think there could be an elegant way to resolve this. Regards, -- http://mail.python.org/mailman/listinfo/python-list
Re: python call a procedure at the specified time
Hi Nitin,I need a python solution for that. On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: > are you looking for something like cron? > > On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: > >> Hi, >> I have a python script running behind the scene,and I need it to call a >> method on sunday 9 o'clock. >> I get an idea,that I get the current time,and calculate the seconds to >> sunday 9 o'clock, >> then sleep these seconds and call my method,I think there could be an >> elegant way to resolve this. >> >> Regards, >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > > -- > Nitin Pawar > > -- http://mail.python.org/mailman/listinfo/python-list
Re: python call a procedure at the specified time
Thanks Nitin,I wonder how cron works,does it create a timer thread for each task? On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: > I think to do so either you will need to schedule a cron or write a daemon > process which will run continuously. > Assuming that its running only once a day or say timely manner daemon will > be a costly affair for system resources > > To schedule crons for python, this might be useful (using yaml) > > http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml > > Thanks, > Nitin > > > On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: > >> Hi Nitin,I need a python solution for that. >> >> >> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: >> >>> are you looking for something like cron? >>> >>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>> >>>> Hi, >>>> I have a python script running behind the scene,and I need it to call a >>>> method on sunday 9 o'clock. >>>> I get an idea,that I get the current time,and calculate the seconds to >>>> sunday 9 o'clock, >>>> then sleep these seconds and call my method,I think there could be an >>>> elegant way to resolve this. >>>> >>>> Regards, >>>> >>>> -- >>>> http://mail.python.org/mailman/listinfo/python-list >>>> >>>> >>> >>> >>> -- >>> Nitin Pawar >>> >>> >> > > > -- > Nitin Pawar > > -- http://mail.python.org/mailman/listinfo/python-list
Re: python call a procedure at the specified time
I have read the cron man page just now,It says that cron wakes up every minute to check task. I will try install/uninstall with cron. Cheers, On Wed, Sep 15, 2010 at 3:25 PM, Von wrote: > Thanks Nitin,I wonder how cron works,does it create a timer thread for each > task? > > > On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: > >> I think to do so either you will need to schedule a cron or write a daemon >> process which will run continuously. >> Assuming that its running only once a day or say timely manner daemon will >> be a costly affair for system resources >> >> To schedule crons for python, this might be useful (using yaml) >> >> http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml >> >> Thanks, >> Nitin >> >> >> On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: >> >>> Hi Nitin,I need a python solution for that. >>> >>> >>> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar wrote: >>> >>>> are you looking for something like cron? >>>> >>>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>>> >>>>> Hi, >>>>> I have a python script running behind the scene,and I need it to call a >>>>> method on sunday 9 o'clock. >>>>> I get an idea,that I get the current time,and calculate the seconds to >>>>> sunday 9 o'clock, >>>>> then sleep these seconds and call my method,I think there could be an >>>>> elegant way to resolve this. >>>>> >>>>> Regards, >>>>> >>>>> -- >>>>> http://mail.python.org/mailman/listinfo/python-list >>>>> >>>>> >>>> >>>> >>>> -- >>>> Nitin Pawar >>>> >>>> >>> >> >> >> -- >> Nitin Pawar >> >> > -- http://mail.python.org/mailman/listinfo/python-list
python cxfreeze package pyqt app lost icon and tray icon
Hi, Here is my command: cxfreeze --target-dir=AutoOrder gui.py --base-name=D:\Python31\Lib\site-packages\cx_Freeze\bases\Win32GUI.exe --include-path=. -z icon.jpg Both app icon and tray icon used icon.jpg Regards, -- http://mail.python.org/mailman/listinfo/python-list
Re: python call a procedure at the specified time
I used timer way,and I found that threading.Timer didn't work with PyQt,so I used QTimer instead,and it did work. On Wed, Sep 15, 2010 at 3:44 PM, Nitin Pawar wrote: > cron is daemon running which maps the tasks with the frequency > > if you want to run a task at a specific time, you can schedule it for the > same > > if you need any help, ping on gtalk, can help you out > > Thanks, > Nitin > > On Wed, Sep 15, 2010 at 1:05 PM, Von wrote: > >> I have read the cron man page just now,It says that cron wakes up every >> minute to check task. >> I will try install/uninstall with cron. >> >> Cheers, >> >> >> On Wed, Sep 15, 2010 at 3:25 PM, Von wrote: >> >>> Thanks Nitin,I wonder how cron works,does it create a timer thread for >>> each task? >>> >>> >>> On Wed, Sep 15, 2010 at 2:35 PM, Nitin Pawar wrote: >>> >>>> I think to do so either you will need to schedule a cron or write a >>>> daemon process which will run continuously. >>>> Assuming that its running only once a day or say timely manner daemon >>>> will be a costly affair for system resources >>>> >>>> To schedule crons for python, this might be useful (using yaml) >>>> >>>> http://code.google.com/appengine/docs/python/config/cron.html#About_cron_yaml >>>> >>>> Thanks, >>>> Nitin >>>> >>>> >>>> On Wed, Sep 15, 2010 at 11:54 AM, Von wrote: >>>> >>>>> Hi Nitin,I need a python solution for that. >>>>> >>>>> >>>>> On Wed, Sep 15, 2010 at 2:15 PM, Nitin Pawar >>>>> wrote: >>>>> >>>>>> are you looking for something like cron? >>>>>> >>>>>> On Wed, Sep 15, 2010 at 11:43 AM, Von wrote: >>>>>> >>>>>>> Hi, >>>>>>> I have a python script running behind the scene,and I need it to call >>>>>>> a method on sunday 9 o'clock. >>>>>>> I get an idea,that I get the current time,and calculate the seconds >>>>>>> to sunday 9 o'clock, >>>>>>> then sleep these seconds and call my method,I think there could be >>>>>>> an elegant way to resolve this. >>>>>>> >>>>>>> Regards, >>>>>>> >>>>>>> -- >>>>>>> http://mail.python.org/mailman/listinfo/python-list >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Nitin Pawar >>>>>> >>>>>> >>>>> >>>> >>>> >>>> -- >>>> Nitin Pawar >>>> >>>> >>> >> > > > -- > Nitin Pawar > > -- http://mail.python.org/mailman/listinfo/python-list
Re: I don't get why sys.exit(1) doesn't exit the while loop in the follow case
Try to use sys.exit(0)
Maybe you should print out the error in your except block.
2010/10/5, chad :
> Given the following..
>
> #!/usr/bin/python
>
> import urllib2
> import sys
> import time
>
> while 1:
> try:
> con = urllib2.urlopen("http://www.google.com";)
> data = con.read()
> print "connected"
> #The loop doesn't exit if I use sys.exit(1)
> break
> except:
> time.sleep(2)
>
>
> If I would replace 'break' with 'sys.exit(1)', the while loop will
> keep printing connected every 2 seconds? Why I this? I thought exit
> meant exit.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: asyncore.poll() question
The urlparse module is load only when this module run as main entry.
Its for test purpose of modules.
2010/10/17, chad :
> On Oct 16, 11:02 am, Felipe Bastos Nunes
> wrote:
>> You edited the source of asyncore.py puttin the print statments and
>> nothing happend? It should work as the method is called as the page
>> you posted said.
>>
>> 2010/10/16, chad :
>>
>>
>>
>> > On Oct 16, 6:47 am, Lucasm wrote:
>> >> On 16 Okt, 15:31, chad wrote:
>>
>> >> > At the following url..
>>
>> >> >http://www.nightmare.com/medusa/programming.html
>>
>> >> > The author has the following code for a simple HTTP client
>>
>> >> > #!/usr/bin/python
>>
>> >> > import asyncore
>> >> > import socket
>> >> > import string
>>
>> >> > class http_client (asyncore.dispatcher):
>>
>> >> > def __init__ (self, host, path):
>> >> > asyncore.dispatcher.__init__ (self)
>> >> > self.path = path
>> >> > self.create_socket (socket.AF_INET, socket.SOCK_STREAM)
>> >> > self.connect ((host, 80))
>>
>> >> > def handle_connect (self):
>> >> > self.send ('GET %s HTTP/1.0\r\n\r\n' % self.path)
>>
>> >> > def handle_read (self):
>> >> > data = self.recv (8192)
>> >> > print data
>>
>> >> > def handle_write (self):
>> >> > pass
>>
>> >> > if __name__ == '__main__':
>> >> > import sys
>> >> > import urlparse
>> >> > for url in sys.argv[1:]:
>> >> > parts = urlparse.urlparse (url)
>> >> > if parts[0] != 'http':
>> >> > raise ValueError, "HTTP URL's only, please"
>> >> > else:
>> >> > host = parts[1]
>> >> > path = parts[2]
>> >> > http_client (host, path)
>> >> > asyncore.loop()
>>
>> >> > Right after that, the author states the following...
>>
>> >> > " A really good way to understand select() is to put a print
>> >> > statement
>> >> > into the asyncore.poll() function:
>>
>> >> > [...]
>> >> > (r,w,e) = select.select (r,w,e, timeout)
>> >> > print '---'
>> >> > print 'read', r
>> >> > print 'write', w
>> >> > [...]
>>
>> >> > Each time through the loop you will see which channels have fired
>> >> > which events.
>> >> > "
>>
>> >> > How the heck do I modify the code put the print statement into the
>> >> > asyncore.poll() function?
>>
>> >> > Chad
>>
>> >> Hi,
>>
>> >> You can find the file in your Python directory, in my case /usr/lib/
>> >> Python2.6/asyncore.py. You should delete the .pyc file to make sure it
>> >> is recompiled. And you will need root access :).
>>
>> >> Lucas
>>
>> > I just did that...
>>
>> > [r...@localhost python2.6]# ls -al asyncore.py
>> > -rw-r--r-- 1 root root 19262 Oct 16 10:22 asyncore.py
>> > [r...@localhost python2.6]# ls -al asyncore.pyc
>> > -rw-r--r-- 1 root root 16773 Oct 16 10:26 asyncore.pyc
>> > [r...@localhost python2.6]# ls -al asyncore.pyo
>> > -rw-r--r-- 1 root root 16773 Oct 16 10:42 asyncore.pyo
>> > [r...@localhost python2.6]#
>>
>> > And nothing happened. Ideas?
>> > --
>
> One last question.
>
> Why does the author have both import sys and import urlparse below
> __main__? Ie
>
> if __name__ == '__main__':
> import sys
> import urlparse
>
> Why not just put them at the top with the rest?
>
> Chad
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list
help install on Win 7
I have tried to install python on my home laptop several times, using 3.6 or 3.7. Each time I get the following error - anyone know what I am doing wrong? [image: image.png] thanks in advance Andrew -- https://mail.python.org/mailman/listinfo/python-list
Re: how to comment out a block of code
A bit of a hack of course, but you can enclose the code that should be commented out with ''' and ''' or """ and """ (not sure about the name of this tripple-quoting) OTOH, some (or even most if not all) Python editors support blockquoting by pushing a button or using shortcuts. SPE and IDLE for example. -- http://mail.python.org/mailman/listinfo/python-list
Extending an embeded Python
I'm trying to embed Python in a Windows exe, and extend it with some
functions in the same program. So far I only add one function:
static PyObject* py_print( PyObject* self, PyObject* args ) {
const char* msg;
if( !PyArg_ParseTuple( args, "s", &msg ) )
return 0;
EventLog::log( msg );
Py_INCREF( Py_None );
return Py_None;
}
static PyMethodDef StoneAgeMethods[] = {
{ "log", py_print, METH_VARARGS, "Print a message to the log" },
{ 0, 0, 0, 0 } /* sentinel */
};
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int ) {
EventLog::init( "con_dump.txt" );
Py_Initialize();
EventLog::log( "Python version '%s'", Py_GetVersion() );
PyObject* res0 = Py_InitModule( "stoneage", StoneAgeMethods );
res1 = PyRun_SimpleString( "stoneage.log( \"test\" )\n" ); // FAIL
res2 = PyRun_SimpleString( "log( \"test\" )\n" ); // FAIL
res3 = PyRun_SimpleString( "print \"test\"\n" ); // OK
Py_Finalize();
}
This compiles without problems, but when I run it I can't use the "log"
function. Result res0 is a non-null object.
As far as I can understand the "Extending and Embedding the Python
Interpreter" doc, res1 should work but it doesn't!
I'm a total newbie to Python, so any help appreciated :)
--
http://mail.python.org/mailman/listinfo/python-list
New user's initial thoughts / criticisms of Python
Hi Everyone, I'm Mr. Noobie here, I've just started easing into Python (2.7.4) and am enjoying working along to some youtube tutorials. I've done a little programming in the past. I've just got a few thoughts I'd like to share and ask about: * Why not allow floater=float(int1/int2) - rather than floater=float (int1)/float(int2)? Give me a float (or an error message) from evaluating everything in the brackets. Don't make me explicitly convert everything myself (unless I want to) * No sign of a select .. case statement Another useful tool in the programmer's toolbox Select DayofWeek case "mon" ... end select * Call me pedantic by why do we need a trailing comma for a list of one item? Keep it intuitive and allow lstShopping=[] or ["Bread"] or ["Bread", "Milk","Hot Chocolate"] I don't like ["Bread",]. It bugs me. Just some initial thoughts. I just wanted to know the reasoning behind the above, be shown the shortcomings of my ignorance, pointed in the right direction. Let the High Priests of Python come forth and speak wise words and show me the ignorance of thy ways. Let my cup be filled to overflowing with your kind knowledge and wisdom. Is everyone happy with the way things are? Could anyone recommend a good, high level language for CGI work? Not sure if I'm going to be happy with Perl (ahhh, get him, he's mentioned Perl and is a heretic!) or Python. I would very much value any constructive criticism or insights. And a "thank you", ["sirs","madams"] but pls, not just ["sirs",] JvH -- https://mail.python.org/mailman/listinfo/python-list
Re: New user's initial thoughts / criticisms of Python
On Sat, 09 Nov 2013 07:08:25 -0600, John von Horn wrote: Thanks so much for the replies. I'll get my head down and keep on going. Sometimes it's great to be wrong. I have a good feeling about this language. It's also nice that I can tap into this pool of knowledge that is comp.lang.python - I'll be heading down to that watering hole on a regular basis. *Help, Help - the python's got me, I've been ambushed* And a "thank you" [guys] - alright! My next program: print 'And a '"thank you"' [guys] to the screen, expanding the list of guys to their individual names that have replied to my opening comment. displayed as a comma delimited list. Time to say "goodbye" to "Hello World" and take it to the next level. First floor, here I come. We are on a mission! I'm lovin' it. JvH -- https://mail.python.org/mailman/listinfo/python-list
addressof object with id()
Hi, I have a single questions regarding id() built-in function. example 1: var1 = "some string" var2 = "some string" if use the id() function on both, it returns exactly the same address. example 2: data = "some string" var1 = data var2 = data if use the id() function on var1 and var2, it returns exactly the same address. can anyone explain me please why does this happens? Is this correct? Thanks in advance and regards, Fabian -- http://mail.python.org/mailman/listinfo/python-list
import in Python3.3
Hi, I have a package name collections and inside of my package I want to import the collections package from the standard library, but there is name conflicts. How do I import explicitly from the standard library? Im working on Python3.3 Thanks in advance and regards, Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: import in Python3.3
Hi Steven, thanks a lot for the explanation. I will keep in mind not to use names for my modules that can shadow the standard library. Regards, Fabian On 03/24/2013 07:27 PM, Steven D'Aprano wrote: > On Sun, 24 Mar 2013 18:12:49 -0500, Fabian von Romberg wrote: > >> Hi, >> >> I have a package name collections and inside of my package I want to >> import the collections package from the standard library, but there is >> name conflicts. >> >> How do I import explicitly from the standard library? > > You can't. However, you can import explicitly from your package, or > implicitly by using a relative import. > > Starting from Python 2.7, the "import" statement is always absolute. So > the line: > > import collections > > will always find the first *top level* module or package "collections" in > the python search path. See below for an important proviso. > > Inside your package, you can either use an explicit import like this: > > import mypackage.collections as collections > > or use a relative import like this: > > from . import collections > > Here is a concrete example. I create a package containing five files: > > mypackage/ > +-- __init__.py > +-- collections.py > +-- absolute_import.py > +-- explicit_import.py > +-- relative_import.py > > with the following content: > > # absolute_import.py > import collections > > # explicit_import.py > import mypackage.collections as collections > > # relative_import.py > from . import collections > > > The other two files (collections.py and __init__.py) can be blank. Now, > from *outside* the package, I can do this: > > > py> import mypackage.absolute_import > py> import mypackage.explicit_import > py> import mypackage.relative_import > py> > py> mypackage.absolute_import.collections > > py> mypackage.explicit_import.collections > > py> mypackage.relative_import.collections > > > > Of course "from mypackage import absolute_import" etc. will also work. > > > However, beware: if you cd into the package directory, and then launch > Python, the current directory will contain a file "collections.py" which > will shadow the standard library collections.py. So don't do that. > > > -- http://mail.python.org/mailman/listinfo/python-list
io.BytesIO
Hi, is there any way to get the allocated memory size from a io.BytesIO object? Thanks and regards, Fabian -- http://mail.python.org/mailman/listinfo/python-list
Re: io.BytesIO
Hi Steven, actually why I need is to know how much memory has been allocated for buffering. getsizeof gets the size of the object structure. For example, if I do io.BytesIO.truncate(1), it will resize the buffer to 1 bytes. So my question is how to get those 1 back from an attribute or method? Regards, Fabian On 03/24/2013 11:47 PM, Steven D'Aprano wrote: > On Sun, 24 Mar 2013 22:56:12 -0500, Fabian von Romberg wrote: > >> Hi, >> >> is there any way to get the allocated memory size from a io.BytesIO >> object? > > The same as for any object: > > py> import io, sys > py> obj = io.BytesIO() > py> sys.getsizeof(obj) > 48 > > > Is this what you are after, the size of the object itself, including any > overhead? > > -- http://mail.python.org/mailman/listinfo/python-list
Re: io.BytesIO
Hi Steve, thanks for your reply. Actually I played around with these methods. Whe you truncate(12468) for example, I thought the object would allocate 12468 bytes and I wanted to get that back. The methods your mention, works only for what ha been written (obj.write()). I think I should use io.BufferedWriter instead. Just one question, what has better performance: BufferedWriter or BytesIO? Thanks and regards, Fabian On 03/25/2013 01:54 AM, Steven D'Aprano wrote: > On Mon, 25 Mar 2013 00:10:04 -0500, Fabian von Romberg wrote: > >> Hi Steven, >> >> >> actually why I need is to know how much memory has been allocated for >> buffering. >> >> getsizeof gets the size of the object structure. > > I can see at least four ways to get the current size of the BytesIO > buffer: > > py> obj = io.BytesIO(b"x"*12468) > py> obj.getbuffer().nbytes > 12468 > py> len(obj.getvalue()) > 12468 > py> len(obj.getbuffer()) > 12468 > py> obj.seek(0, 2) > 12468 > > > As far as I can tell, BytesIO objects do not have a fixed size buffer. > They will increase in size as needed, just like real file objects on a > disk. > > > -- http://mail.python.org/mailman/listinfo/python-list
Re: A question on Encoding and Decoding.
[EMAIL PROTECTED] wrote:
> Hello,
> I think this remark is more to the point. In my experience, the general
> problem is that python operates with the default encoding "ascii" as in
> sys.getdefaultencoding(). It is possible to set the defaultencoding in
> sitecustomize.py, with sys.setdefaultencoding('latin1'). I have placed
> sitecustomize.py in Lib/site-packages. It is not possible to set the
> encoding once python has started. Setting the encoding only works if
> you can bind yourself to this one encoding and is therefore no general
> fix.
> The only reasonable way to work is to get your strings into unicode
> (and sometimes back out again).
> If for instance you type:
> s = "äÄöÖüÜß" and then try
> us = unicode(s) you will get a traceback identical to yours.
I missed the beginning of this thread, but why not write
s = u"äÄöÖüÜß"
Is there ever a reason _not_ to exclusively use the unicode stringtype
throughout your Python program? (of course you may need to encode/decode
when interfacing with the world outside your program)
/johan
--
http://mail.python.org/mailman/listinfo/python-list
Re: os.lisdir, gets unicode, returns unicode... USUALLY?!?!?
Laurent Pointal wrote: > gabor a écrit : >> hi, >> >> from the documentation (http://docs.python.org/lib/os-file-dir.html) for >> os.listdir: >> >> "On Windows NT/2k/XP and Unix, if path is a Unicode object, the result >> will be a list of Unicode objects." > > Maybe, for each filename, you can test if it is an unicode string, and > if not, convert it to unicode using the encoding indicated by > sys.getfilesystemencoding(). > > Have a try. > > A+ > > Laurent. Strange coincident, as I was wrestling with this problem only yesterday. I found this most illuminating discussion on the topic with contributions from Mr Lövis and others: http://www.thescripts.com/forum/thread41954.html /johan -- http://mail.python.org/mailman/listinfo/python-list
wxPython, Syntax highlighting
Hi, I am looking for wx widget that has the ability to show text, edit the text (like a TextCtrl) but also does syntax highlighting (if the text is e.g. XML or HTML). I have been looking in the latest wxPython version but I could not really find anything. Any suggestions? (I need this because my collegue who is very Java-minded can apparently do that without any problems) Kd -- http://mail.python.org/mailman/listinfo/python-list
Looking for a event-message-qeue framework
Hi, I am looking for a kind of framework that let's me send events between systems. What I had in mind is common event bus that can be spread over multiple systems. On each system, there should be sort of an 'agent' that listens to the events on the bus and acts upon them if they are destined for the agent. The agent should also be able to send events. Some queue mechanism would also be nice. Is there something like this in Python? (I really want to avoid Java or MQ series) Eric -- http://mail.python.org/mailman/listinfo/python-list
first time use of swig, python and c++ .. it's a mess ... please advice
Hi,
we have a third-party product that has a C++ api on HP-UX.
I would like be able to use the API in Python (as I remember Python is
good at doing this).
I have no experience with this so I Googled and tried to find some
info on what I had to do.
So, I installed Python 2.4.4 and Swig 1.3.33
The header file to the library is '/opt/OV/include/opcsvcapi.h'.
I created a SWIG file with the following content:
"
%module opcsvcapi
%{
/* Includes the header in the wrapper code */
#include "/opt/OV/include/opcsvcapi.h"
%}
/* Parse the header file to generate wrappers */
%include "/opt/OV/include/opcsvcapi.h"
"
Then I ran the cmd:
# swig -c++ -python opcsvcapi.i
with output:
"
/opt/OV/include/opcsvcapi.h:41: Warning(362): operator= ignored
/opt/OV/include/opcsvcapi.h:46: Warning(503): Can't wrap 'operator
Type' unless renamed to a valid identifier.
"
The result are two files:
opcsvcapi.py
opcsvcapi_wrap.cxx
I created a 'setup.py' file with the following content:
"
import distutils
from distutils.core import setup, Extension
setup(name = "opcsvcapi",
version = "1.0",
ext_modules = [Extension("_opcsvcapi",
["opcsvcapi.i","opcsvcapi.cxx"])])
"
Then I run: python setup.py build
This results in an extra file:
opcsvcapi_wrap.c and a 'build' directory
and the following errors:
"
running build
running build_ext
building '_opcsvcapi' extension
swigging opcsvcapi.i to opcsvcapi_wrap.c
swig -python -o opcsvcapi_wrap.c opcsvcapi.i
creating build
creating build/temp.hp-ux-B.11.11-9000-800-2.4
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-
prototypes -fPIC -I/usr/local/include/python2.4 -c opcsvcapi_wrap.c -o
build/temp.hp-ux-B.11.11-9000-800-2.4/opcsvcapi_wrap.o
In file included from /usr/local/include/python2.4/Python.h:8,
from opcsvcapi_wrap.c:118:
/usr/local/include/python2.4/pyconfig.h:851:1: warning:
"_POSIX_C_SOURCE" redefined
:1:1: warning: this is the location of the previous
definition
In file included from opcsvcapi_wrap.c:2490:
/opt/OV/include/opcsvcapi.h:12:18: error: vector: No such file or
directory
In file included from opcsvcapi_wrap.c:2490:
/opt/OV/include/opcsvcapi.h:15: error: expected '=', ',', ';', 'asm'
or '__attribute__' before 'SvcAPI'
opcsvcapi_wrap.c: In function 'Swig_var_SvcAPI_set':
opcsvcapi_wrap.c:2505: error: 'SvcAPI' undeclared (first use in this
function)
opcsvcapi_wrap.c:2505: error: (Each undeclared identifier is reported
only once
opcsvcapi_wrap.c:2505: error: for each function it appears in.)
opcsvcapi_wrap.c:2505: error: 'namespace' undeclared (first use in
this function)
opcsvcapi_wrap.c:2505: error: expected expression before ')' token
opcsvcapi_wrap.c: In function 'init_opcsvcapi':
opcsvcapi_wrap.c:3064: error: 'Swig_var_SvcAPI_get' undeclared (first
use in this function)
error: command 'gcc' failed with exit status 1
"
and that's it.
Any idea what I am doing wrong?
Any help much appreciated
Kris
--
http://mail.python.org/mailman/listinfo/python-list
Re: first time use of swig, python and c++ .. it's a mess ... please advice
On Feb 27, 9:44 pm, "Bronner, Gregory" <[EMAIL PROTECTED]>
wrote:
> The operator= stuff is usually innocuous.
> The compiler died because it couldn't find 'vector', which is reasonable,
> since it thought it was compiling a C file.
>
> Probably because you swigged the file without the magic "-c++" option -- I'm
> not sure how distutils passes arguments to swig, but if you do it from the
> command line, you'll do something like swig -c++ -python -I
> and it will generate a .cpp file and a .py file, which will
> (hopefully) compile.
>
> I'd focus on doing it manually, then getting distutils to work properly.
>
> -Original Message-
> From: Hyuga [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, February 27, 2008 10:01 AM
> To: [EMAIL PROTECTED]
> Subject: Re: first time use of swig, python and c++ .. it's a mess ... please
> advice
>
> On Feb 26, 3:38 pm, Eric von Horst <[EMAIL PROTECTED]> wrote:
> > Hi,
>
> > we have a third-party product that has a C++ api on HP-UX.
>
> > I would like be able to use the API in Python (as I remember Python is
> > good at doing this).
>
> > I have no experience with this so I Googled and tried to find some
> > info on what I had to do.
>
> > So, I installed Python 2.4.4 and Swig 1.3.33
>
> > The header file to the library is '/opt/OV/include/opcsvcapi.h'.
>
> > I created a SWIG file with the following content:
> > "
> > %module opcsvcapi
> > %{
> > /* Includes the header in the wrapper code */
> > #include "/opt/OV/include/opcsvcapi.h"
> > %}
>
> > /* Parse the header file to generate wrappers */
> > %include "/opt/OV/include/opcsvcapi.h"
> > "
> > Then I ran the cmd:
> > # swig -c++ -python opcsvcapi.i
> > with output:
> > "
> > /opt/OV/include/opcsvcapi.h:41: Warning(362): operator= ignored
> > /opt/OV/include/opcsvcapi.h:46: Warning(503): Can't wrap 'operator
> > Type' unless renamed to a valid identifier.
> > "
>
> > The result are two files:
> > opcsvcapi.py
> > opcsvcapi_wrap.cxx
>
> > I created a 'setup.py' file with the following content:
> > "
> > import distutils
> > from distutils.core import setup, Extension
>
> > setup(name = "opcsvcapi",
> > version = "1.0",
> > ext_modules = [Extension("_opcsvcapi",
> > ["opcsvcapi.i","opcsvcapi.cxx"])])
> > "
>
> > Then I run: python setup.py build
>
> > This results in an extra file:
> > opcsvcapi_wrap.c and a 'build' directory
>
> > and the following errors:
> > "
> > running build
> > running build_ext
> > building '_opcsvcapi' extension
> > swigging opcsvcapi.i to opcsvcapi_wrap.c swig -python -o
> > opcsvcapi_wrap.c opcsvcapi.i creating build creating
> > build/temp.hp-ux-B.11.11-9000-800-2.4
> > gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-
> > prototypes -fPIC -I/usr/local/include/python2.4 -c opcsvcapi_wrap.c -o
> > build/temp.hp-ux-B.11.11-9000-800-2.4/opcsvcapi_wrap.o
> > In file included from /usr/local/include/python2.4/Python.h:8,
> > from opcsvcapi_wrap.c:118:
> > /usr/local/include/python2.4/pyconfig.h:851:1: warning:
> > "_POSIX_C_SOURCE" redefined
> > :1:1: warning: this is the location of the previous
> > definition In file included from opcsvcapi_wrap.c:2490:
> > /opt/OV/include/opcsvcapi.h:12:18: error: vector: No such file or
> > directory In file included from opcsvcapi_wrap.c:2490:
> > /opt/OV/include/opcsvcapi.h:15: error: expected '=', ',', ';', 'asm'
> > or '__attribute__' before 'SvcAPI'
> > opcsvcapi_wrap.c: In function 'Swig_var_SvcAPI_set':
> > opcsvcapi_wrap.c:2505: error: 'SvcAPI' undeclared (first use in this
> > function)
> > opcsvcapi_wrap.c:2505: error: (Each undeclared identifier is reported
> > only once
> > opcsvcapi_wrap.c:2505: error: for each function it appears in.)
> > opcsvcapi_wrap.c:2505: error: 'namespace' undeclared (first use in
> > this function)
> > opcsvcapi_wrap.c:2505: error: expected expression before ')' token
> > opcsvcapi_wrap.c: In function 'init_opcsvcapi':
> > opcsvcapi_wrap.c:3064: error: 'Swig_var_SvcAPI_get' undeclared (first
> > use in this function)
> > error: command 'gcc' failed with exit statu
[email protected]
Hi, I need some advice on Drag&Drop. What I want to achieve is the following: - I have a window that is divided in two : on the left hand I have a wx.TreeCtlr and on the other hand a wx.StaticBitmap I want to be able to drag an item from the tree onto the static bitmap. I know how to do drag&drop in a treeCtrl but is there a way that I can make the bitmap detect that something has been dropped on it? I would only need to know the name of the tree obj that was dropped on the bitmap (and the location) Any help much appreciated Erik -- http://mail.python.org/mailman/listinfo/python-list
Python and 3D
Hi, I am looking for Python modules that allow you to manipulate 3D objects, more specifically Alias Wavefront .OBJ objects. Also, a module that would allow you to vizualize these models and rotate them etc.. The goal is not to build a new renderer or something; just a small program that I need to do some manipulations in bulk on a set of OBJs Any help much appreciated Eric -- http://mail.python.org/mailman/listinfo/python-list
Re: HELP!...Google SketchUp needs a Python API
On Fri, 28 Nov 2008 15:22:58 -0800, r wrote: > You know I said before that I hoped Guido never see's this thread...but > i wonder if maybe he should see it...To see how far the "great > advocates" have fallen. I am disappointed to say the least. I would not > want to be in his shoes and see this! I am shocked! Shocked and dismayed and distraught and heart-borken by the vile, dastardly, spineless false-friend's who have BETRAYED Pyhton and STABBED ME IN TEH BACK like the cowardly FIENDS they ARE! Everybody except r on this thread is banned from using Ptyhon. No, EVERYBODY is banned from Pyhton. I'm going to stop all work on it immediatelty and delete it from my website. See what you have made me do, you RUBY LOVERS!!?!?!! -- Giudo -- http://mail.python.org/mailman/listinfo/python-list
Looking for documentation tools
Hello. For documening my thesis project, i'm, looking for 2 things: A GUI tool that allows me to enter descriptions, arguments, return values etc, for each function, class, etc. in some forms and then generates and inserts the correct comment syntax, so pydoc can generate the documentation HTML. (preferrably for windows) And a diagram tool that reverse engineers the used python modules and draws a class diagram with relations between the classes etc.? Either as a standalone app or as something that generates graphviz scripts or similar. I hope you guys have some suggestions? -Esben -- http://mail.python.org/mailman/listinfo/python-list
Help with suds: HTTP Error 401
Hi,
I am trying to do a very simple thing with SUDS but I think I am
missing the obvious (first time I use suds)
I have small program that tries to open a wsdl. When I execute the
program I am getting 'suds.transport.TransportError: HTTP Error 401:
Unauthorized' Seems obvious but I specify username and pwd in the
code.
when use IE to go the wsdl, I get a pop-up asking me for the username
and pwd, I enter them, and the wsdl is displayed.
This is my code:
"
from suds import WebFault
from suds.client import Client
from suds.transport.http import HttpAuthenticated
t = HttpAuthenticated(username='admin', password='admin')
client = Client('http://.xxx.xx.x:8080/axis2/services/UcmdbService?
wsdl', transport=t)
"
I seems straightforward :(
Any help much appreciated.
Erik
--
http://mail.python.org/mailman/listinfo/python-list
Re: Status of Python threading support (GIL removal)?
Digging through my problem, I discovered Python isn't exactly thread safe and to solve the issue, there's this Global Interpreter Lock (GIL) in place. It's the opposite: Python is exactly thread safe precisely because it has the GIL in place. Is there any other way to work around the issue aside from forking new processes or using something else? If you know that your (C) code is thread safe on its own, you can release the GIL around long-running algorithms, thus using as many CPUs as you have available, in a single process. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Status of Python threading support (GIL removal)?
Digging through my problem, I discovered Python isn't exactly thread safe and to solve the issue, there's this Global Interpreter Lock (GIL) in place. It's the opposite: Python is exactly thread safe precisely because it has the GIL in place. Is there any other way to work around the issue aside from forking new processes or using something else? If you know that your (C) code is thread safe on its own, you can release the GIL around long-running algorithms, thus using as many CPUs as you have available, in a single process. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Protecting against callbacks queuing up?
Hello I'm using Python for S60 1.9.7 on my Nokia phone. I've made a program that gets input from an accelerometer sensor, and then calculates some stuff and displays the result. The sensor framework API does a callback to a function defined by me, every time new data is available. The problem is, that sometimes, the calculations may take longer than others, but if the callback is called before the first calculation is done, it seems like it's queuing up all the callbacks, and execute them sequentially, afterwards. What I need, is to simply ignore the callback, if the previous call hasn't finished it's operations before it's called again. I thought that this code would do the trick, but it obviously doesn't help at all, and i can't understand why... def doCallback(self): if self.process_busy==False: self.process_busy=True self.data_callback() self.process_busy=False doCallback is defined as a callback function for the accelerometer instance, and data_callback does some calculations and show them on the display of the phone. What to do? Thanks... -- http://mail.python.org/mailman/listinfo/python-list
Re: Protecting against callbacks queuing up?
Hendrik van Rooyen wrote: see if there is an "after" method somewhere. What you have to do is to "break the link" between the callback and the processing. Your code above is all in the callback "thread", despite the fact that you call another function to do the processing. So if you replace the data_callback() with an after call, it should work as you expect. HTH - Hendrik Thanks I'm new to python, what is an after function and an after call? Couldn't find excact answer on google...? Do you have a link to some docs? -- http://mail.python.org/mailman/listinfo/python-list
Re: Protecting against callbacks queuing up?
Dennis Lee Bieber wrote: On Mon, 24 Aug 2009 17:32:23 +0200, Esben von Buchwald declaimed the following in gmane.comp.python.general: I'm new to python, what is an after function and an after call? Couldn't find excact answer on google...? Do you have a link to some docs? They would be particular to whatever GUI/event library is in use. They aren't part of Python itself. This is how the accelerometer is accessed http://pys60.garage.maemo.org/doc/s60/node59.html I found this called "after"... http://pys60.garage.maemo.org/doc/s60/node12.html would that be usable? If so, how? -- http://mail.python.org/mailman/listinfo/python-list
Re: Protecting against callbacks queuing up?
Hendrik van Rooyen wrote: would that be usable? Probably If so, how? This is a guess, for your device, but I suspect something along these lines: t = Ao_timer() cb = t.after(100,thing_that_does_the_work(with_its_arguments)) Lots of assumptions here - the 100 should give you a tenth of a second... Don't know what the arguments look like, and if you need to pass an instance (like self) - that would depend on where you are calling it from. Play and see :-) You should also be able to cancel the callback like this: t.cancel(cb) If you do it before the time out - Hendrik I don't really get it... I can see that I should put a t.after(...) around the function that does the work, when calling it. That delays each call for the given period. I just tried it out, the console keeps saying - Traceback (most recent call last): File "c:\resource\python25\python25.zip\sensorfw.py", line 499, in data_cb File "c:\resource\python25\python25.zip\sensorfw.py", line 160, in custom_cb File "e:\python\r3s_contextdata.py", line 79, in acc_filter self.acc_callback() File "e:\python\r3s_contextdata.py", line 85, in acc_callback self.doCallback() File "e:\python\r3s_contextdata.py", line 47, in doCallback self.at.after(0.05,self.data_callback) RuntimeError: Timer pending - cancel first - It seems like i should cancel the current counting timer, when a new call comes in - but how to determine when to cancel etc? I'm kind of new to all this async python stuff. -- http://mail.python.org/mailman/listinfo/python-list
Re: Protecting against callbacks queuing up?
Dennis Lee Bieber wrote: On Tue, 25 Aug 2009 15:21:16 +0200, Esben von Buchwald declaimed the following in gmane.comp.python.general: This is how the accelerometer is accessed http://pys60.garage.maemo.org/doc/s60/node59.html I found this called "after"... http://pys60.garage.maemo.org/doc/s60/node12.html would that be usable? Based on the documentation... I'd suggest... def doCallback(self): self.accelerometer.stop_listening() self.data_callback() self.accelerometer.start_listening() with appropriate changes to whatever reference you use for the accelerometer would solve the problem... IE, when the callback is triggered, you STOP the accelerometer action, compute results, and then restart the accelerometer.. I just tried that - it made the application lock up, leaving the sensors unusable until next reboot of the phone. I don't think these start/stop calls are supposed to be called as often as it does the callback... -- http://mail.python.org/mailman/listinfo/python-list
Re: Protecting against callbacks queuing up?
Dennis Lee Bieber wrote: The only other thing I could suggest is exactly what is done on: http://pys60.garage.maemo.org/doc/s60/node59.html Initialize a counter value to 0, then increment it in the callback, only doing REAL work every n calls. def doCallback(self): if self.count % 35 == 0:#doc says 35 hits/second, so this self.data_callback()#will run one once per second self.count += 1 You'll still get that slew of backlogged callbacks that built up while doing the real processing, but unless self.data_callback() takes more time than the "35" covers, most of the callbacks will just come in and exit with an increment. Of course I can do that. But it'll only make a noticable delay EVERY time the user moves, and not prevent the build up of calls if it doesn't finish within the 35 callbacks. The point is that I don't know in advance, how long the call will take. It depends on the amount of data i load and process during the call. I only know when the calculations have finished, and when they are called, and think there might be some way to block further callbacks until the first one returns? -- http://mail.python.org/mailman/listinfo/python-list
Re: Protecting against callbacks queuing up?
Hendrik van Rooyen wrote: Hmm - now I am really starting to fly by the seat of my pants - but it looks as if your problem is that your routine is basically being called faster than what it can do the processing. So what I would try is to define a global (you should really acquire a lock, but forget that for the moment) So lets call this thing running_calculation. Then you set this in the routine just before the after call, and reset it just before exiting the calculation routine, and if it is set when you get into the first routine, then you just exit, without doing the after. This should have the effect of skipping some calls, to make it all manageable. Then you should (hopefully) not have the duplication that it looks to me like you are now having. Bye the way, make the time short - like 1 - it could also be that the time is now so long before you start calculating, that you do not have a snowball's hope in hell to be finished before the next value comes in. OK, now things starts to make sense. You tell me to do something like this? def doCallback(self): if self.process_busy==False: self.process_busy=True self.at.after(0.01,self.data_callback) def doneCallback(self): self.process_busy=False And the after command will cause python to spawn a new thread, which runs self.data_callback, which measn that the doCallback will return immediately, so the next callback from accelerometer can be processed? And when the self.data_callback() finishes, i'd make it call the doneCallback() to release my busy flag, right? I'm gonna try this tomorrow :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Protecting against callbacks queuing up?
It seems to solve the problem. What I did: def contextDataHandler(self): self.contextdata.process_busy=True self.services.findServices() self.drawDisplay() self.contextdata.process_busy=False def doCallback(self): self.at.cancel() if self.process_busy==False: self.at.after(0.01,self.data_callback) The app works awesomely stable now data_callback refers to contextDataHandler in parent class Thanks guys, good job -- http://mail.python.org/mailman/listinfo/python-list
Collection console output
Hello Are there any simple ways to collect the data, python prints to the console when running an app? I'm doing som apps for S60 mobile phones and can't see the console, when the UI is running, but i'd like to collect the output, to look for eventual exceptions etc. Cant it be redirected to a log file, just like when runing a script in unix, where you say $ ./script.pl > logfile.txt ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Collection console output
MRAB wrote: Esben von Buchwald wrote: Hello Are there any simple ways to collect the data, python prints to the console when running an app? I'm doing som apps for S60 mobile phones and can't see the console, when the UI is running, but i'd like to collect the output, to look for eventual exceptions etc. Cant it be redirected to a log file, just like when runing a script in unix, where you say $ ./script.pl > logfile.txt ? Does the S60 support a command line like *nix and Windows? An alternative from within the script is: import sys sys.stdout = open(log_path, "w") You might also want to capture stderr: import sys log_file = open(log_path, "w") sys.stdout = log_file sys.stderr = log_file Thanks a lot - it works fine :) I've made this class which works perfectly class Consolefile: def __init__(self): self.file=None self.status='init' def start(self): self.filename="%s\\%s_console.log"%(cfg.logdir,FILEID) print self.filename self.oldstderr=sys.stderr self.oldstdout=sys.stdout self.file=open(self.filename,'w') print >> self.file, '#Logging STDERR and STDOUT to this file' sys.stderr=self.file sys.stdout=self.file self.status='started' def stop(self): print >> self.file, '#Console logging stopped' sys.stderr=self.oldstderr sys.stdout=self.oldstdout self.file.close() self.status='stopped' -- http://mail.python.org/mailman/listinfo/python-list
