Writing elapsed time as a string

2008-05-05 Thread Simon Pickles

Hello.

I'm sorry if this has been asked a thousand (million) times.

Is there a nifty pythonesque way to produce a string representing an 
elapsed time period, in terms of years, months, days, hours, mins, seconds?


I am storing times in a MySQL db, and would love to be able to write the 
time elapsed between accesses of certain data. These are in seconds 
since the epoch, as produced by time.time()


It is probable right in front of me in the docs but I am spinning off 
into outer space (mentally!)


Thanks for the temporary loan of your clarity and experience.

Simon
--

http://www.squirtual-reality.com

Linux user #458601 - http://counter.li.org.
--
http://mail.python.org/mailman/listinfo/python-list


Writing elapsed time as a string

2008-05-05 Thread Simon Pickles

Hello.

I'm sorry if this has been asked a thousand (million) times.

Is there a nifty pythonesque way to produce a string representing an 
elapsed time period, in terms of years, months, days, hours, mins, seconds?


I am storing times in a MySQL db, and would love to be able to write the 
time elapsed between accesses of certain data. These are in seconds 
since the epoch, as produced by time.time()


It is probable right in front of me in the docs but I am spinning off 
into outer space (mentally!)


Thanks for the temporary loan of your clarity and experience.

Simon
--

http://www.squirtual-reality.com

Linux user #458601 - http://counter.li.org.



--
http://mail.python.org/mailman/listinfo/python-list


Re: Garbage collection

2008-02-19 Thread Simon Pickles
Ken wrote:
> What is your __del__ method doing?
>   
Actually, nothing but printing a message when the object is deleted, 
just morbid curiosity.

I've yet to see one of the destructor messages, tho

>
>   from sys import getrefcount
>   print getrefcount(x)
>
>   
Perfect, thanks

Simon
-- 
http://mail.python.org/mailman/listinfo/python-list


Garbage collection

2008-02-18 Thread Simon Pickles
Hi,

I'm building a server with python, but coming from a c++ background, 
garbage collection seems strange.

For instance, I have a manager looking after many objects in a dict. 
When those objects are no longer needed, I use del manager[objectid], 
hoping to force the garbage collector to perform the delete.

However, this doesn't trigger my overloaded __del__ destructor. Can I 
simply rely on the python garbage collector to take it from here?

Is there a way to find how many references exist for an object?

Thanks

Simon

-- 
Linux user #458601 - http://counter.li.org.



-- 
http://mail.python.org/mailman/listinfo/python-list


Sudden pyexpat error with ElementTree

2008-02-09 Thread Simon Pickles
Hi,

I've been using ElementTree for a few weeks without problem, with 
Stackless Python.

Suddenly I have an error importing expat, in both application and console:

[EMAIL PROTECTED]:~$ python
Python 2.5.2a0 Stackless 3.1b3 060516 (release25-maint:60694M, Feb  9 
2008, 13:21:41)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from xml.parsers import expat
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.5/site-packages/_xmlplus/parsers/expat.py", 
line 4, in 
from pyexpat import *
ImportError: 
/usr/lib/python2.5/site-packages/_xmlplus/parsers/pyexpat.so: undefined 
symbol: PyUnicodeUCS4_Decode
 >>>

Google shows a few other sufferers, but reveals no answers. I have just 
rebuilt python to see if I had messed it up somehow, but the problem 
persists.

Thanks for your advice.

Simon



-- 
http://mail.python.org/mailman/listinfo/python-list


Events in Python

2008-01-30 Thread Simon Pickles
Hi,

I have a stackless python app, using twisted in parts (.internet and 
.adbapi).

I need a little help getting pythonic after years of c++ hell.

I'd like to use a system of events and observers, like c++ boost.signal.

I'd like to be able to subscribe multiple callbacks to a single function 
and cal them all using something like:

event.invoke("some data to send with invocation")

I'm thinking twisted callbacks do this:

 def observe(self, f);
  self.event.addcallback(f)

Are there other ways?

Thanks

Si

-- 
Linux user #458601 - http://counter.li.org.



-- 
http://mail.python.org/mailman/listinfo/python-list


refcount

2008-01-29 Thread Simon Pickles
Hi,

Is is possible to access the refcount for an object?

Ideally, I am looking to see if I have a refcount of 1 before calling del

Thanks

Simon

-- 
Linux Counter: User# 424693 



-- 
http://mail.python.org/mailman/listinfo/python-list


REALLY simple xml reader

2008-01-27 Thread Simon Pickles
Hi

Can anyone suggest a really simple XML reader for python? I just want to 
be able to do something like this:

xmlDoc = xml.open("file.xml")
element = xmlDoc.GetElement("foo/bar")

... to read the value of:


   42



Thanks

Simon

-- 
Linux user #458601 - http://counter.li.org.



-- 
http://mail.python.org/mailman/listinfo/python-list


Hashable

2008-01-26 Thread Simon Pickles
Hi,

The term 'hashable'.

Am I right in thinking it means it can be indexed? like a string or a dict?

Thanks

Si

-- 
Linux user #458601 - http://counter.li.org.



-- 
http://mail.python.org/mailman/listinfo/python-list


del self?

2008-01-25 Thread Simon Pickles
Hi,

Just curious... What are the implications of a class member calling:

del self

is that what the __del__ method calls anyway?

Thanks

Simon

-- 
Linux user #458601 - http://counter.li.org.



-- 
http://mail.python.org/mailman/listinfo/python-list


Pythonland documentation

2008-01-18 Thread Simon Pickles
Hi

I am new to python (fairly) but can't stop pythonning.

c++ seems so far away now from here it looks like a horrid scribble :)

Anyway my question is really about doc tools. I've been used to 
doxygen in c++ land, and although it makes a reasonable stab with a 
python project in java mode, the output is a bit messy.

Can any one suggest a more tailored tool? or do I risk a flamewar? :)

Thanks

SiPi

-- 
Linux user #458601 - http://counter.li.org.



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Looking for a good Python environment

2007-11-14 Thread Simon Pickles
Well,

I am recent Windows escapee, and was dismayed by lack of Pyscripter for 
Linux.

Hold on... there is hope!

Pyscripter works great using WINE. search  
http://groups.google.com/group/PyScripter?hl=en for "Linux"

Enjoy!

Paul Rudin wrote:
> jwelby <[EMAIL PROTECTED]> writes:
>
>
>   
>> This is a fair question. I didn't phrase my post too well.
>>
>> I find PyScripter does pretty much everything I need in terms of doing
>> actual development for Python. My use of 'lightweight' is by no means
>> a criticism of PyScripter - it's more of a compliment, as it refers to
>> the relatively modest demands that it makes on my system compared with
>> Eclipse, which can be hog.
>>
>> The main reason I have used Eclipse for larger, team based, projects
>> is for the source control plug-ins. Eclipse has plug-in support for
>> cvs and svn. PyScripter may have this too - perhaps I've missed it.
>> (I'm away from my Windows box at the moment, otherwise I would check).
>> Of course, there are other ways to implement source control without it
>> needing to be integrated in the IDE, so even this need not put off
>> anyone who wants to use PyScripter with source control.
>>
>> Summary - unless you need the added flexibility offered by Eclipse
>> plug-ins, PyScripter is a great tool for developing with Python on
>> Windows.
>> 
>
> I'm not sure if you count emacs as "lightweight" but it's certainly
> less resource hungry than eclipse/pydev, and does have integrated
> cvs/svn functionality.
>   



-- 
http://mail.python.org/mailman/listinfo/python-list


Python IDE

2007-11-03 Thread Simon Pickles
Hi,

I have recently moved from Windows XP to Ubuntu Gutsy.

I need a Python IDE and debugger, but have yet to find one as good as 
Pyscripter for Windows. Can anyone recommend anything? What are you all 
using?

Coming from a Visual Studio background, editing text files and using the 
terminal to execute them offends my sensibilities :)

Thanks

Si
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running another python interpreter

2007-10-20 Thread Simon Pickles
This is very nearly perfect. I have a second console window. 
Unfortunately, the first is waiting for the second to close. Is there 
anyway to specify the equivalent of os.P_NOWAIT?

Gabriel Genellina wrote:
> --- Simon Pickles <[EMAIL PROTECTED]> escribió:
>
>   
>> os.spawnl(os.P_NOWAIT, sys.executable,
>> sys.executable, "gateway.py")
>> ... works but both process output to the same
>> interpreter window. Is there a way to run another
>> interpreter window containing gateway.py?
>> 
>
> Use the subprocess module, passing CREATE_NEW_CONSOLE into creationflags:
>
> subprocess.call([sys.executable, "gateway.py", "other", "arguments"],
>  creationflags = subprocess.CREATE_NEW_CONSOLE)
>
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running another python interpreter

2007-10-18 Thread Simon Pickles
Well, I tried:
   
os.spawnv(os.P_NOWAIT, "gateway.py", ())

and got:

OSError: [Errno 8] Exec format



Simon Pickles wrote:
> Hello,
>
> I have several servers which link to each other (and of course, to clients).
>
> At present, I am starting them in turn manually. Is there a way with 
> python to say, "open gateway.py in a new interpreter window"?
>
> I looked at execv, etc, but they seem to replace the current process. 
> Ah, maybe I need spawnv().
>
> I am on windows i386, python 2.5
>
> Thanks
>
> si
>   
-- 
http://mail.python.org/mailman/listinfo/python-list


Running another python interpreter

2007-10-18 Thread Simon Pickles
Hello,

I have several servers which link to each other (and of course, to clients).

At present, I am starting them in turn manually. Is there a way with 
python to say, "open gateway.py in a new interpreter window"?

I looked at execv, etc, but they seem to replace the current process. 
Ah, maybe I need spawnv().

I am on windows i386, python 2.5

Thanks

si
-- 
http://mail.python.org/mailman/listinfo/python-list


Help a C++ escapee!

2007-06-07 Thread Simon Pickles
Hi,

Can someone help me leave the murky c++ world and enter shiny pythonland?

I have a problem with importing and global variables, here's my code:


##server.py

#socket connections
from socketManager import*

network = CNetworkManager()
network.Listen()

--
##socketManager.py

from time import sleep
from socket import*

import threading


class CNetworkManager():
def __init__(self):
self.hostName = ""
self.portNumber = 15500
self.buffer = 500
self.serverAddress = ( self.hostName, self.portNumber )
self.maxClients = 2
## previous stuff to send to new client
self.serverData = []

self.serverSocket = socket ( AF_INET, SOCK_STREAM )
self.serverSocket.bind ( self.serverAddress )
print( "Socket started " )
self.serverSocket.listen ( self.maxClients )
print( "Server is waiting for a connection" )

def Listen(self):
self.threadArray =[]
self.ch = 0
while self.ch < self.maxClients:
#Create a thread listening to each socket
self.newThreadObject = CServerThread()
self.newThreadObject.start()
self. threadArray.append(self.newThreadObject)
self.ch=self.ch+1



class CServerThread(threading.Thread):
def run(self):
while (1):
self.clientSocket, self.clientAddress = network.accept()
print("New Client:", self.clientAddress)
if network.serverData:
for i in range(len(network.serverData)):
clientSocket.send(str(network.serverData[i]))
sleep(0.01)
else:
clientSocket.send("You are logged in")
print("Entering loop for client ", clientAddress )
while 1:
clientData = clientSocket.recv(Buffer)
if not clientData:
print( clientAddress + " has closed the connection" )
break
print( "%s says %s" % (clientAddress, clientData))
clientData = clientData + "~~"
network.serverData.append(clientData)
for i in range(len(network.serverData)):
clientSocket.send(str(network.serverData[i]))
sleep(0.01)
print("Ready to receive more data")

clientData.close()
break
network.serverSocket.close()
--

When run, I come unstuck here:

self.clientSocket, self.clientAddress = network.accept()

I get a nameError on 'network', yet it is one in the global namespace, 
defined in server.py before CServerThread.Listen() is called.

In c++, I understood how to declare variables, here I have a problem. Its 
like I need an extern statement from c++.

Can anyone clarify this for me?

Many thanks

Simon

_
Play your part in making history - Email Britain! 
http://www.emailbritain.co.uk/

-- 
http://mail.python.org/mailman/listinfo/python-list