Re: keeping twisted and wxPython in sync
On Feb 8, 2:41 am, "Littlefield, Tyler" wrote: > Hello all: > I have a couple questions. First, is there a way to know if connectTCP > failed? I am writing a client with Twisted and would like to be able to > notify the user if they couldn't connect. > Second, I set the protocol on my factory after a connection has been > made. So when I send my user and password, that is when I connect. Is > there a way to handle waiting for the connection to complete? > > -- > > Take care, > Ty > Web:http://tds-solutions.net > The Aspen project: a light-weight barebones mud > enginehttp://code.google.com/p/aspenmud > > Sent from my toaster. You can send your user & password in connectionMade() method, I think. -- http://mail.python.org/mailman/listinfo/python-list
Re: keeping twisted and wxPython in sync
On Feb 8, 2:41 am, "Littlefield, Tyler" wrote: > Hello all: > I have a couple questions. First, is there a way to know if connectTCP > failed? I am writing a client with Twisted and would like to be able to > notify the user if they couldn't connect. > Second, I set the protocol on my factory after a connection has been > made. So when I send my user and password, that is when I connect. Is > there a way to handle waiting for the connection to complete? > > -- > > Take care, > Ty > Web:http://tds-solutions.net > The Aspen project: a light-weight barebones mud > enginehttp://code.google.com/p/aspenmud > > Sent from my toaster. And for connection failed, you can write some hook code in connectionLost() method, this method will be called when connection failed. -- http://mail.python.org/mailman/listinfo/python-list
Is there anyway to check the number of I/O registered in poll?
I'm using select.poll to do I/O polling. polling is placed in a independent thread from select import poll _poller = poll() def poll(timeout): l = _poller.poll(timeout) return l In my code, in some context, the timeout value will be high ( like 1 hour ), but there is no I/O in _poller, then this poll action will be blocked till timeout. Is there anyway to find how many I/O in _poller? Thus I can avoid polling. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Under what kind of situation, time.sleep(n) would sleep much longer than n seconds?
Hi. I'm writing some scripts with python, and I found sometimes, when I try to use time.sleep(1) to sleep 1 sec, it would actually sleep for 9 secs or even longer. >From python document, I saw this: time.sleep(secs) Also, the suspension time may be longer than requested by an arbitrary amount because of the scheduling of other activity in the system. So, my question: under what kind of condition, time.sleep would suspend longer time than expected? Anybody got interested? Best Regards. -- https://mail.python.org/mailman/listinfo/python-list
Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds?
Hi, Chris & Marko Thanks for your reply. I find the reason why my time.sleep take longer time. In my script, I use wxPython to build up my GUI, and I open another thread to do network communications. It turned out that if you create a wx.Frame & make it show up, then your time.sleep may sleep longer time than expected. I will dig deeper for the root cause. Anyway, it's interesting. Here is a sample code that can reproduce this issue, you need to wait for it to run for a while. ** import time import threading import wx def sleep(): while True: t = time.time() time.sleep(1) print "Actually sleep:", time.time() - t t1 = threading.Thread(target=sleep) t1.start() app =wx.App(False) frame = wx.Frame(None, title="test") frame.Show(True) app.MainLoop() -- https://mail.python.org/mailman/listinfo/python-list
Re: Under what kind of situation, time.sleep(n) would sleep much longer than n seconds?
Hi, Chris Thanks for the suggestion. For my script, I want to download a picture from internet & show it in a window, that's why I use wxPython. Well, I think I may can avoid sleep in wxPython in 2 ways: 1. Use web.py, let python do backend work, let browser show me everything. As you suggested. 2. Write 2 scripts, one script do network related works, sleep at will; the other one show GUI. Use pipe or socket for process communication. Best Regards. -- https://mail.python.org/mailman/listinfo/python-list
Is there anyway to use urllib2 to download a file from http server?
As the title. Or is there other module that can handle this task? Many thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
Is there anyway to run JavaScript in python?
Hi, I'm writing a test tool to simulate Web browser. Is there anyway to run JavaScript in python? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Why there is no "setdefaultencoding" in sys module?
Hi, everyone I'm a new hand at python. I tried to set system default encoding by using "import sys; sys.setdefaultencoding('utf-f')", but I got error message: >>> sys.setdefaultencoding('utf-8') Traceback (most recent call last): File "", line 1, in AttributeError: 'module' object has no attribute 'setdefaultencoding' Then I checked dir(sys), seems there was no function named "setdefaultencoding" in "sys" module. But in python's document, it said I should use sys.setdefaultencoding. So, my questions: why there is no setdefaultencoding in sys module? if I want to change system's default encoding, what should I do? Thanks in advance -- http://mail.python.org/mailman/listinfo/python-list
Re: Why there is no "setdefaultencoding" in sys module?
On Jul 10, 12:04 am, Steven D'Aprano wrote: > On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote: > > So, my questions: why there is no setdefaultencoding in sys module? if I > > want to change system's default encoding, what should I do? > > I think the answer is: > > Don't. > > If you do, you will break built-ins. > > http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-e... > > Googling will find many discussions about this. > > -- > Steven Interesting, so it has been removed from python? then why it's still in document... It's really misleading. Thanks for your quick answer -- http://mail.python.org/mailman/listinfo/python-list
Re: Why there is no "setdefaultencoding" in sys module?
On Jul 10, 12:06 am, crow wrote: > On Jul 10, 12:04 am, Steven D'Aprano > > > > > cybersource.com.au> wrote: > > On Fri, 09 Jul 2010 08:58:35 -0700, crow wrote: > > > So, my questions: why there is no setdefaultencoding in sys module? if I > > > want to change system's default encoding, what should I do? > > > I think the answer is: > > > Don't. > > > If you do, you will break built-ins. > > >http://tarekziade.wordpress.com/2008/01/08/syssetdefaultencoding-is-e... > > > Googling will find many discussions about this. > > > -- > > Steven > > Interesting, so it has been removed from python? then why it's still > in document... It's really misleading. > > Thanks for your quick answer oh, I take back my words, it's still there, just I need to reload(sys). -- http://mail.python.org/mailman/listinfo/python-list
power of explicit self?
I'm looking for an explanation of how explicit self is implimented and what features are only possible because of, or are greatly improved, because of it. I've always liked explicit self and am looking for the computer science behind it, so that I can explain the benefits that I see. I'm also interested in the files/lines of the python source that shows how explicit self is implemented if anyone can point out where that takes place. all help welcome -- http://mail.python.org/mailman/listinfo/python-list
Re: power of explicit self?
> It's not implemented in the compiler. There's a place in the runtime > for invoking a method where the object is inserted at the beginning > of the parameter list. IIRC, that's done by wrapping the function > object. This is the source of Objects/methodobject.c it look like this is where self is added to the argument list, but I'll have to do some more digging. thanks for the tip. 50 PyObject * 51 PyCFunction_GetSelf(PyObject *op) 52 { 53 if (!PyCFunction_Check(op)) { 54 PyErr_BadInternalCall(); 55 return NULL; 56 } 57 return ((PyCFunctionObject *)op) -> m_self; 58 } 69 70 PyObject * 71 PyCFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) 72 { ... 75 PyObject *self = PyCFunction_GET_SELF(func); ... 78 switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) { 79 case METH_VARARGS: 80 if (kw == NULL || PyDict_Size(kw) == 0) 81 return (*meth)(self, arg); 82 break; 83 case METH_VARARGS | METH_KEYWORDS: ... 126 } -- http://mail.python.org/mailman/listinfo/python-list
Re: insert unique data in a list
On Dec 13, 11:37 am, mattia wrote: > How can I insert non-duplicate data in a list? I mean, is there a > particular option in the creation of a list that permit me not to use > something like: > def append_unique(l, val): > if val not in l: > l.append(val) > > Thanks, > Mattia You could also define a custom object that manages a custom ordered set class unique_set(object): def __init__(self,list): self.list = list def __add___(self,val): if val not in self.list self.list.append(val) return True return False >>> unique_list = unique_set(['a','b','c']) >>> unique_list.list ['a', 'b', 'c'] >>> unique_list + 'd' True >>> unique_list + 'e' True >>> unique_list + 'd' False >>> unique_list.list ['a', 'b', 'c', 'd', 'e'] >>> I've used this on a few projects, it makes for wonderfully clean code, because you can look at your program as an overview without all the arithmetic behind it. hope it helps -- http://mail.python.org/mailman/listinfo/python-list
Re: insert unique data in a list
> Also, I'm not sure I like your abuse of the + operator to modify the > object in place and return a flag. It is an API not shared by (as far as > I can see) any other data type in Python. I agree it couuld be more consisten with other object apis, I also think that if every api has to conform to every other api nothing will ever get done. Heres a slightly more familiar version, it returns the value added or none to conform with other APIs. class unique_set(object): def __init__(self,list): self.list = list def __add___(self,val): if val not in self.list self.list.append(val) return val return None >>> unique_list = unique_set(['a','b','c']) >>> unique_list.list ['a', 'b', 'c'] >>> unique_list + 'd' 'd' then a test opperand to verify if a value was inserted could be if unique_list + 'd': # done some stuff but it could also be used in cases like this unique_added = unique_list + 'd' or 'not added' -- http://mail.python.org/mailman/listinfo/python-list