mentor training python Romania with certification

2016-08-16 Thread blue
Hi. 

I'm from Romania.
I need to update my skils under python.
I need to find one mentor ( class, training ) to obtain one certified under 
python language.

Cătălin George Feștilă
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PyQt5, OpenGL, where to start, minimal example code?

2016-10-02 Thread blue
You have here a PyQt5 Reference Guide 
http://pyqt.sourceforge.net/Docs/PyQt5/index.html
Some example can be found here 4 and 5 
http://codeprogress.com/python/libraries/pyqt/

Support for OpenGL http://pyqt.sourceforge.net/Docs/PyQt5/opengl.html told us:

When compiled against Qt v5.1 or later, PyQt5 implements a set of either 
desktop QOpenGL bindings or OpenGL ES v2 bindings depending on how Qt was 
configured. This removes the dependency on any third-party OpenGL bindings such 
as PyOpenGL.

At the moment the desktop bindings are for OpenGL v2.0 and are mostly complete. 
Other versions will be added in later releases. If there are calls which you 
need, but are currently unsupported, then please ask for the support to be 
added.

Obtaining an object that implements the bindings for a particular OpenGL 
version and profile is done in the same way as it is done from C++, i.e. by 
calling versionFunctions(). In addition, the bindings object also contains 
attributes corresponding to all of the OpenGL constants.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Adding colormaps?

2017-01-23 Thread blue
you have here a full example , for another version not significant changes:
http://matplotlib.org/examples/color/colormaps_reference.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: function inclusion problem

2015-02-27 Thread blue
On Wednesday, February 11, 2015 at 1:38:12 AM UTC+2, [email protected] wrote:
> I defined function Fatalln in "mydef.py" and it works fine if i call it from 
> "mydef.py", but when i try to call it from "test.py" in the same folder:
> import mydef
> ...
> Fatalln "my test"
> i have NameError: name 'Fatalln' is not defined
> I also tried include('mydef.py') with the same result...
> What is the right syntax?
> Thanks

...try to set your python utf-8 encode .
and read the FAQ or python manual 
-- 
https://mail.python.org/mailman/listinfo/python-list


Euler module under python 2.7 and 3.4 instalation...

2015-04-07 Thread blue
Dear friends .
I want to install Euler module under python 2.7 and / or 3.4 version.
I try pip and pip 3.4 but seam not working for me.
I need some help with this .
Thank you . Regards.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Which GUI?

2015-07-25 Thread blue
Hi .
I tested all. Now I think the PySide can more.
https://pyside.readthedocs.org/en/latest/

See also 
http://free-tutorials.org/pyside-introduction-part-001/
http://python-catalin.blogspot.ro/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Hi

2015-07-25 Thread blue
... also you can have all python modules from :
http://www.lfd.uci.edu/~gohlke/pythonlibs/

read this mini tutorial ( working also with python 2.7) : 
http://python-catalin.blogspot.ro/2014/10/windows-all-modules-for-python-34.html
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to decrypt encrypted text to a clear text

2017-06-07 Thread blue
Test again your chain programming way , because :
>>> dir(RSA.importKey)
['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__format__', 
'__func__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', 
'__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', 
'__sizeof__', '__str__', '__subclasshook__', 'im_class', 'im_func', 'im_self']
>>> dir(RSA.importKey.decrypt())
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'function' object has no attribute 'decrypt'


On Tuesday, June 6, 2017 at 9:29:52 AM UTC+3, Ho Yeung Lee wrote:
> i use wb to write pubic and private key 
> and succeed to import private, but after decrypt, it return hex number 
> not a clear text 
> is there any more key needed?
> or do wb influence the result?
> 
> from Crypto.PublicKey import RSA 
> keypair = RSA.generate(2048) 
> alice_privkey = keypair.exportKey('PEM', 'mysecret', pkcs=1) 
> #alice_privkey = keypair.exportKey() 
> alice_pubkey = keypair.publickey().exportKey() 
> 
> text_file = open("alice_pubkey.txt", "wb") 
> text_file.write(alice_pubkey) 
> text_file.close() 
> 
> keypair = RSA.generate(2048) 
> bob_privkey = keypair.exportKey('PEM', 'mysecret2', pkcs=1) 
> #bob_privkey = keypair.exportKey() 
> bob_pubkey = keypair.publickey().exportKey() 
> 
> text_file = open("bob_pubkey.txt", "wb") 
> text_file.write(bob_pubkey) 
> text_file.close() 
> 
> text_file = open("alice_privkey.pem", "wb") 
> text_file.write(alice_privkey) 
> text_file.close() 
> text_file = open("bob_privkey.pem", "wb") 
> text_file.write(bob_privkey) 
> text_file.close() 
> 
> 
> #step 2 
> #use alice public key to encrypt 
> pubkey = RSA.importKey(alice_pubkey) 
> alice_masterkey = pubkey.encrypt("i am Martin", None) 
> 
> text_file = open("alice_masterkey.txt", "w") 
> text_file.write(bob_pubkey) 
> text_file.close() 
> 
> quit() 
> python 
> text_file = open("alice_masterkey.txt", "r") 
> alice_masterkey=text_file.read() 
> text_file.close() 
> text_file = open("alice_privkey.pem", "r") 
> alice_privkey=text_file.read() 
> text_file.close() 
> text_file = open("alice_pubkey.txt", "r") 
> alice_pubkey=text_file.read() 
> text_file.close() 
> 
> from Crypto.PublicKey import RSA 
> pubkey = RSA.importKey(alice_pubkey) 
> privkey = RSA.importKey(alice_privkey,passphrase="mysecret") 
> encryption_key = privkey.decrypt(alice_masterkey) 
> encryption_key 
> 
> quit() 
> python 
> text_file = open("alice_masterkey.txt", "r") 
> alice_masterkey=text_file.read() 
> text_file.close() 
> text_file = open("alice_privkey.pem", "r") 
> alice_privkey=text_file.read() 
> text_file.close() 
> text_file = open("alice_pubkey.txt", "r") 
> alice_pubkey=text_file.read() 
> text_file.close() 
> 
> from Crypto.PublicKey import RSA 
> pubkey = RSA.importKey(alice_pubkey) 
> privkey = RSA.importKey(alice_privkey,passphrase="mysecret") 
> encryption_key = privkey.decrypt(alice_masterkey) 
> encryption_key 
> 
> >>> encryption_key 
> 'o\x94\xaeC\xe0S\x81\x05t\xd8\\A\x10?\xd2\xe5\x8c5\xc9\x1d\x14\xc7\xfd)Cs\x8b"cg\x16y\xe2\xf2L\xf1-\x08qHt\x99\xbc\xb5\xf6_\x17c\xd2&Z\x0b\xc5t\t\xe0\x8b\x03G\x10\xce\xd6\xcd\x86\xfc!\xc9i\xa2\xab\x9d\x8a\x92\xfc7
>  
> g\xa5$\x91\x85\xa2L]I\xd6\xc6\xaez\xed\x01\x95\xee)8z\x18\xc9aag\x97\x97\xb0\\)\xec"\xe4\xbez\xd3\xa8\'k%\x12\x1d\xf9\xf0\x0e\x0c\xcb\xa8\xb1\xe7}\x90\xd3\xcfs@\xc2m\x1a^\x1b0\xa7\xdd\xcd\xea\x1f\xd5\x08\x13+y"]vu\xe3\x9e\xba\x97\x10\x90S\xea\xae1=r4Yp,\xe3\xa9\xc66H\xa7\x95[M|n\x91\x98\x9c,\xc4\xf5\x7f\x8cJ\x03\xba\x04Z0lV\xe1\xd6d\xeec@\xe1\xa0\xec\x81]\xef5\r\x12\x88\xbe/\xfc\xe01\xaacn,\x8a\xe1\x14\x8a\xf4\xd85\xd8\xabD\x137\xe7T\xc4\xc1\x84b.\xd9RZ\x0e\x03#\x1e\x8dl\xe8\xe4N^\r\xf0\x1d\x8c'

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


Re: programming by evolution?

2009-02-08 Thread blue indigo
On Fri, 06 Feb 2009 14:32:21 +0100, Pascal Costanza wrote:

> Xah Lee wrote:
>> Pascal Constanza is a Common Lisp fanatic.
> 
> It's Costanza, not Constanza.
> 
> 
> Thank you,
> Pascal

 +---+ .:\:\:/:/:.
 |   PLEASE DO NOT   |:.:\:\:/:/:.:   
 |  FEED THE TROLLS  |   :=.' -   - '.=:  
 |   |   '=(\ 9   9 /)='  
 |   Thank you,  |  (  (_)  ) 
 |   Management  |  /`-vvv-'\ 
 +---+ / \
 |  |@@@  / /|,|\ \   
 |  |@@@ /_//  /^\  \\_\  
   @x@@x@|  | |/ WW(  (   )  )WW  
   \/|  |\|   __\,,\ /,,/__   
\||/ |  | |  (__Y__)  
/\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
==

(f'up set to comp.lang.lisp)

-- 
blue indigo
UA Telecom since 1987
--
http://mail.python.org/mailman/listinfo/python-list


Re-launch of The Gadgets Forum

2008-05-08 Thread Blue Pikes
Re-launch of The Gadgets Forum


Re-launch of "The Gadgets Forum - gadgets.pk" with new and stunning
categories, now you can find latest news and reviews about the
following:

1) Audio/Video Gadgets = MP3 Players, iPods, Speakers, Audio/Video
Systems, Digital Cameras etc.

2) Automobile Gadgets

3) Cell Phones & Accessories

4) Laptops, Desktops & Accessories

5) Clocks & Watches

6) Gaming Gadgets

7) Geek Toys

8) GPS & Satellites

9) Home & Office Gadgets

10) Kitchen Gadgets

11) Solar Powered Gadgets

12) Travel & Power Gadgets


JOIN NOW  http://www.gadgets.pk

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


How to handle file uploads with http.server

2010-03-11 Thread Neil Blue
Hello,

I have a basic http.server instance running (class
HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and I
would like to upload files with multipart forms.

def do_POST(self):
ctype, pdict = cgi.parse_header(self.headers['Content-Type'])
if ctype=='multipart/form-data':
print('parsing...')
query=cgi.parse_multipart(self.rfile, pdict)
print(query)

However the file never seems to finish being parsed. There are no errors,
but the call hangs at: query=cgi.parse_multipart(self.rfile, pdict)

Please can anyone offer some insight into this or somewhere else I may find
some more information.

Thanks
Neil

* 

The information contained in this message is likely to be confidential.  It is 
intended only for the person named above.  Any dissemination, distribution, 
copying, disclosure or use of this message or its contents unless authorised by 
BioWisdom Ltd is strictly prohibited. Any views or opinions expressed within 
this e-mail are those of the author and do not necessarily represent those of 
BioWisdom Ltd. If you have received this message in error, please immediately 
notify us and delete it.  Thank you.  Registered Office: BioWisdom Ltd, Harston 
Mill, Harston, Cambridge, CB22 7GG.  Registered in England: (GB) 3861669.  VAT 
registered: (GB) 750899881.  Tel: +44 (0)1223 874800, Fax: +44 (0) 1223 874801, 
Internet:www.biowisdom.com 

*

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


RE: How to handle file uploads with http.server

2010-03-17 Thread Neil Blue
Thanks Gabriel

Yep, that looks like the same one. 

Cheers
Neil

 

-Original Message-
From: Gabriel Genellina [mailto:[email protected]] 
Sent: 17 March 2010 02:08
To: [email protected]
Subject: Re: How to handle file uploads with http.server

En Thu, 11 Mar 2010 07:30:24 -0300, Neil Blue 
escribió:

> I have a basic http.server instance running (class 
> HTTPHandler(http.server.BaseHTTPRequestHandler), with python 3.1, and 
> I would like to upload files with multipart forms.
>
> def do_POST(self):
>   ctype, pdict = cgi.parse_header(self.headers['Content-Type'])
>   if ctype=='multipart/form-data':
>   print('parsing...')
>   query=cgi.parse_multipart(self.rfile, pdict)
>   print(query)
>
> However the file never seems to finish being parsed. There are no 
> errors, but the call hangs at: query=cgi.parse_multipart(self.rfile, 
> pdict)

This may be related to this bug:

http://bugs.python.org/issue8077

reported last week by Mitchell L. Model in this thread:

http://groups.google.com/group/comp.lang.python/t/8a7752bd79d5f5d6/

--
Gabriel Genellina



* 

The information contained in this message is likely to be confidential.  It is 
intended only for the person named above.  Any dissemination, distribution, 
copying, disclosure or use of this message or its contents unless authorised by 
BioWisdom Ltd is strictly prohibited. Any views or opinions expressed within 
this e-mail are those of the author and do not necessarily represent those of 
BioWisdom Ltd. If you have received this message in error, please immediately 
notify us and delete it.  Thank you.  Registered Office: BioWisdom Ltd, Harston 
Mill, Harston, Cambridge, CB22 7GG.  Registered in England: (GB) 3861669.  VAT 
registered: (GB) 750899881.  Tel: +44 (0)1223 874800, Fax: +44 (0) 1223 874801, 
Internet:www.biowisdom.com 

*

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


Software Engineer - Storage, Python, C++, Java

2012-02-26 Thread Blue Line Talent
Blue Line Talent is looking for a mid-level software engineer with
experience in a combination of Python, C/C++ and/or Java.  Experience
developing middleware is helpful.  The Engineer will join an exciting
start-up environment in a newly established location.  This is an
outstanding opportunity for a high performing software engineer with
3-5 years experience.   Must love coding, variety.

For this position most of the work is being done in Python now but
they expect this SW Engineer will also use increasing amounts of C/C++
and Java.  The languages experience isn't as important as finding a
really sharp Software Engineer who loves programming (not just design)
and would be well suited for the diversity of a start-up environment.

Position Title:  Software Engineer - Storage

Work Location:  Broomfield/Flatirons area, CO

The Employer:
• A strongly positioned Storage Solutions Software company
• Fully funded and established start-up company with excellent
opportunities for growth and advancement
• Comprehensive benefits package

Description:
• Full life-cycle software design, development, implementation, test
and maintenance.
• Develop, test, and maintain infrastructure-oriented software in
Python with some work in C/C++ and Java
• Middleware development - bridge between Linux Kernel and GUI
• Source code control

Experience Profile:
• BS in Computer Science or an applicable engineering subject and 3-5+
years of related software engineering experience
• 2+ years software engineering for complex storage solutions
• Loves programming
• Experience developing middleware
• Experience programming in Python (or C/C++ and/or Java)
• Software Engineering experience in a Linux environment.
• Experience with near-real time software development.
• Stable employment history of direct employment

Helpful/Preferred:
• Experience in a start-up environment
• Experience with real-time software development. (exposure to
embedded software is helpful)
• Enjoys diversity of tasks
• Experience with GUI
• Experience with C/C++ and/or Java
• Experience with various Windows and Linux OS environments
• Exposure to storage subsystems such as Fibre Channel, iSCSI, SAS,
SATA, RAID, Snapshot, Replication, NAS, SAN, etc.
• MS in Computer Science, or related degree

Please apply at www.bluelinetalent.com/active_jobs

NOTES:
• Direct hire with comprehensive benefits
• Local candidates please - no relocation assistance provided
• Not available for Corp-to-Corp, no third parties please

Ron Levis
Principal, Talent Acquisition Mgr
Blue Line Talent, LLC
www.bluelinetalent.com
www.linkedin.com/in/ronlevis (invitations are welcome)

Moderator, Colorado IT Community on LinkedIn Groups

Blue Line Talent is a member-owner of NPA, The Worldwide Recruiting
Network, your connection to premier independent recruiting firms
located throughout Europe, Asia, Australia, Africa and the Americas.
-- 
http://mail.python.org/mailman/listinfo/python-list


Software Engineer - Storage, Python, C++, Java - Broomfield, CO

2012-03-11 Thread Blue Line Talent
Blue Line Talent is looking for a mid-level software engineer with
experience in a combination of Python, C/C++ and/or Java. Experience
developing middleware is helpful. The Engineer will join an exciting
start-up environment in a newly established location. This is an
outstanding opportunity for a high performing software engineer with
3-5 years experience. Must love coding, variety.

For this position most of the work is being done in Python now but
they expect this SW Engineer will also use increasing amounts of C/C++
and Java. The languages experience isn't as important as finding a
really sharp Software Engineer who loves programming (not just design)
and would be well suited for the diversity of a start-up environment.

Position Title: Software Engineer - Storage

Work Location: Broomfield/Flatirons area, CO

The Employer:
• A strongly positioned Storage Solutions Software company
• Fully funded and established start-up company with excellent
opportunities for growth and advancement
• Comprehensive benefits package

Description:
• Full life-cycle software design, development, implementation, test
and maintenance.
• Develop, test, and maintain infrastructure-oriented software in
Python with some work in C/C++ and Java
• Middleware development - bridge between Linux Kernel and GUI
• Source code control

Experience Profile:
• BS in Computer Science or an applicable engineering subject and 3-5+
years of related software engineering experience
• 2+ years software engineering for complex storage solutions
• Loves programming
• Experience developing middleware
• Experience programming in Python (or C/C++ and/or Java)
• Software Engineering experience in a Linux environment.
• Experience with near-real time software development.
• Stable employment history of direct employment

Helpful/Preferred:
• Experience in a start-up environment
• Experience with real-time software development. (exposure to
embedded software is helpful)
• Enjoys diversity of tasks
• Experience with GUI
• Experience with C/C++ and/or Java
• Experience with various Windows and Linux OS environments
• Exposure to storage subsystems such as Fibre Channel, iSCSI, SAS,
SATA, RAID, Snapshot, Replication, NAS, SAN, etc.
• MS in Computer Science, or related degree

Please apply at www.bluelinetalent.com/active_jobs

NOTES:
• Direct hire with comprehensive benefits
• Local candidates please - no relocation assistance provided
• Not available for Corp-to-Corp, no third parties please

Ron Levis
Principal, Talent Acquisition Mgr
Blue Line Talent, LLC
www.bluelinetalent.com
www.linkedin.com/in/ronlevis (invitations are welcome)

Moderator, Colorado IT Community on LinkedIn Groups

Blue Line Talent is a member-owner of NPA, The Worldwide Recruiting
Network, your connection to premier independent recruiting firms
located throughout Europe, Asia, Australia, Africa and the Americas.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: complex numbers

2005-01-11 Thread Big and Blue
It's me wrote:
>
I am very happy that Python included *native* complex number
support.
   And I have always been happy that FORTRAN supports them.
I really like Python's notion of having just one data type: the duck.
   So have you considered using Python for your problem?
--
 Just because I've written it doesn't mean that
  either you or I have to believe it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: turn text lines into a list

2005-06-28 Thread Big and Blue
Gunnar Hjalmarsson wrote:
>
>> @corenames=qw(
>> rb_basic_islamic
>> sq1_pentagonTile
>> sq_arc501Tile
>> sq_arc503Tile
>> );
> 
> 
> Impractical to mix code and data, isn't it?

Obviously not impractical, given he did it quite easily and succinctly.

> chomp( my @corenames =  );
> 
> __DATA__
> rb_basic_islamic
> sq1_pentagonTile
> sq_arc501Tile
> sq_arc503Tile

Not so easy when you have multiple variables to set.  And the original 
version was transparent in what it was doing - your version is not.


-- 
  Just because I've written it doesn't mean that
   either you or I have to believe it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Advice for creating a web app

2006-03-11 Thread Jumping until blue
I'm confused ... and need some advice

Here is what I want to do:

I have a number of files, mostly text files formatted using Markdown
syntax but also pdfs and other types of files, that are stored in a
folder hierarchy and I want to develop a web application where I can
brows, view and search these files. The documents can be
cross-linked.

Currently I use a basic CGI to view/format the markdown files but I
don't know if I should continue to make my own system or if I should
take advantage of some existing framework.

My requirements are:

+   It should work with the text files I have in my
hierarchy (so a system that stores everything
in a database is out of the question)

+   I want to be able to copy the folder hierarchy
to a memory stick and run my system on another
computer without having to install any software
(I'm thinking of using something like Movable 
Python). I'll mostly be running this on Macs
but would like to have the option to run it
on Windows/Linux

+   Searching should be fairly fast

+   I should be able to edit the text files using a
standard text editor without messing up the system.

+   I will use subversion to keep different computers
in sync.

So my question is: should I use some existing framwork? and if so,
which ones should I look at? TurboGears, Django, etc seem to be much
too elaborate for my modest needs.

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


Re: sizeof(struct timeval)

2006-03-13 Thread Big and Blue
Tony Houghton wrote:
> 
> How safe would I be assuming that 
> 
> sizeof(struct timeval) == 2 * sizeof(long)
> 
> is always true on Linux on different architectures? 

Based on what I was looking at today (well, yesterday now), you might 
be wrong.

I do know that the size of a struct utmp differs between a Linux 
Itanium system and a Linux x86_64 system, and I seem to recall it migh be 
related to timeval.  I could be wrong - I wasn't interested in the timeval 
part - but this part of the bits/utmp.h include file indicates the issue:


/* The ut_session and ut_tv fields must be the same size when compiled
32- and 64-bit.  This allows data files and shared memory to be
shared between 32- and 64-bit applications.  */
#if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
   int32_t ut_session;   /* Session ID, used for windowing.  */
   struct
   {
 int32_t tv_sec; /* Seconds.  */
 int32_t tv_usec;/* Microseconds.  */
   } ut_tv;  /* Time entry was made.  */
#else
   long int ut_session;  /* Session ID, used for windowing.  */
   struct timeval ut_tv; /* Time entry was made.  */
#endif


-- 
  Just because I've written it doesn't mean that
   either you or I have to believe it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sizeof(struct timeval)

2006-03-13 Thread Big and Blue
Big and Blue wrote:
 > Tony Houghton wrote:
 >>
 >> How safe would I be assuming that
 >> sizeof(struct timeval) == 2 * sizeof(long)
 >>
 >> is always true on Linux on different architectures?
 >
 >Based on what I was looking at today (well, yesterday now), you might
 > be wrong.

However, it looks as though I was wrong:

linux/time.h:
  struct timeval {
  time_t  tv_sec; /* seconds */
  suseconds_t tv_usec;/* microseconds */
  };

time.h:
  typedef __time_t time_t;

sys/time.h:
  typedef __suseconds_t suseconds_t;

bits/types.h:
  __STD_TYPE __TIME_T_TYPE __time_t;  /* Seconds since the Epoch.  */
  ...
  __STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds 
*/


bits/typesizes.h:
  #define __TIME_T_TYPE   __SLONGWORD_TYPE
  ...
  #define __SUSECONDS_T_TYPE  __SLONGWORD_TYPE

bits/types.h:
  #define __SLONGWORD_TYPElong int



-- 
  Just because I've written it doesn't mean that
   either you or I have to believe it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Minimize Bandwidth

2007-06-08 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I have a python application that hits a web service on a regular basis to
post a string of CSV log data and I'm looking to minimize the amount of
bandwidth that the application uses to send the log data.

 

Is there any way to encode the string into base64 or something, that I can
then post and decode at the other end? Is that likely to save me bandwidth
perhaps? I don't really know much about this encoding stuff, but the smaller
I can compress the string the better.

 

Thanks,

 

Rob

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

Binary / SOAPpy

2007-06-08 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I have a WebService call which returns an array, the first element in that
array is the binary for a zip file, however I'm having trouble writing that
binary string into an actual file when it arrives, I've tried the following
method.

 

Result = call to the webservice that returns the array.

 

file = open("Zips/1.zip", "wb")

file.write(result[0])

file.close()

 

But this throws the error message: 

 

file.write(result[0])

TypeError: argument 1 must be string or read-only buffer, not instance

 

Does anyone know what I might be doing wrong? Once I've resaved this file
can then unzip it and get at all its lovely content.

 

Thanks for any input guys,

 

Rob

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

Strange Thread Issue

2007-06-23 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm having an issue with a thread which I've not come across before and it
has be baffled. The thread doesn't really do a lot, it simple contains a
popen command to run something from cmd, now then i trigger the thread form
my main application using the .start() method nothing happens, the command
prompt program isn't triggered, yet as soon as a ctrl+c to close my
application the thread then seems to kick into life and work.

 

Any ideas what is causing this?

 

Thanks guys,

 

Rob

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

Zip File Woes

2007-06-27 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm having a MASSIVE headache today with zip files, I had it working a while
ago but it all seems to have stopped in the past 30 minutes and I can't
figure out why.

 

I'm simply trying to write a function that will unzip a file, simple as
that. I've currently got this code:

 

Import zipfile

 

  zip = zipfile.ZipFile('Media/Media.zip', 'r')

  unzip(zip)

  zip.close()

 

def unzip(zip):

   for name in zip.namelist():

  newname = 'Media/%s' % (name)

  file(newname, 'wb').write(zip.read(name))

 

Now when I try and run this i get the following error message:

 

  File "/usr/lib/python2.4/zipfile.py", line 242, in _RealGetContents

raise BadZipfile, "File is not a zip file"

zipfile.BadZipfile: File is not a zip file

 

However, if I copy the zip file off the unit client onto my windows box and
unzip it and it works absolutely perfectly, all the files are extracted as I
would expect, which leads me to think the zip file is fine, and i must just
be missing something in my code.

 

Any ideas guys? I'm tearing my hair out here.

 

Rob

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

RE: Zip File Woes

2007-06-27 Thread Robert Rawlins - Think Blue
Just as an update guys:

 

Before my zip code featured below I have another piece of code that creates
the zip file from a binary string, like this:

 

  #f3 = open("Media/Media.zip", "wb")

  #f3.write(base64.decodestring(MediaBinary))

  #f3.close

 

Now, with that code commented out like that so the unzip code is running on
the file generated last time the code was run it works fine, but if I try
and unzip after the file has been freshly created I get that error, I've
even tried placing a 2 second sleep command in between them and still get
the problems.

 

Thanks guys,

 

Rob

 

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Robert Rawlins - Think Blue
Sent: 27 June 2007 15:10
To: [email protected]
Subject: Zip File Woes

 

Hello Guys,

 

I'm having a MASSIVE headache today with zip files, I had it working a while
ago but it all seems to have stopped in the past 30 minutes and I can't
figure out why.

 

I'm simply trying to write a function that will unzip a file, simple as
that. I've currently got this code:

 

Import zipfile

 

  zip = zipfile.ZipFile('Media/Media.zip', 'r')

  unzip(zip)

  zip.close()

 

def unzip(zip):

   for name in zip.namelist():

  newname = 'Media/%s' % (name)

  file(newname, 'wb').write(zip.read(name))

 

Now when I try and run this i get the following error message:

 

  File "/usr/lib/python2.4/zipfile.py", line 242, in _RealGetContents

raise BadZipfile, "File is not a zip file"

zipfile.BadZipfile: File is not a zip file

 

However, if I copy the zip file off the unit client onto my windows box and
unzip it and it works absolutely perfectly, all the files are extracted as I
would expect, which leads me to think the zip file is fine, and i must just
be missing something in my code.

 

Any ideas guys? I'm tearing my hair out here.

 

Rob

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

Threads Dying?

2007-06-28 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I've got an application that seems to be a little bit unstable and freezes
quite a bit, and I'm suspecting it's something in one of my threads that's
causing the problem, when does a thread die? And how can I be sure that its
dyeing when its mean to be?

 

Thanks guys,

 

Rob

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

XML Parsing Help,

2007-06-29 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I'm looking for some help with XML parsing, I've been playing around with
this over the past few days and the only solution I can come up with seems
to be a little slow and also leaves what I think is a memory leak in my
application, which causes all kinds of problems. 

 

I have a very simple XML file which I need to loop over the elements and
extract the attribute information from, but the loop must be conditional as
the attributes must meet a certain criteria.

 

My current solution is using minidom, which I've read isn't one of the
better parsers, if anyone knows of any that are better for the task I would
love to hear it, the content is extracted regularly so whatever we chose
needs to be quick. Take a look at this brief example of the XML we're
dealing with:

 













 

Now what I need to do is loop through the 'event' elements and locate the
first one which has a type of '2' and return the name and location, if it is
unable to find any events with the type of 2 then I want it to return the
default event which is defined by the attributes of the schedules element.

 

I'm pretty inexperienced with parsing XML in python and could really use
some help selecting a parser and writing the code, I'm sure it's all quite
simple I'm just looking for the best solution.

 

Thanks guys,

 

Rob

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

Application Crashing

2007-06-29 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I find my application is freezing/crashing every now and then and it
becoming a bit of a frustration, so this morning I sat down to try and
locate the problem. After doing some debugging I think I've found the line
of code that causes my problem.

 

Print 'Read Results'

New = e.read()

Print 'Results Read'

 

The last thing the application does is print the words 'Read Results' which
leads me to think that the troublesome line is e.read(). This line is
reading the contents of a file object created by a popen command. This runs
without fail most of the time, but on a reasonably regular occurrence it
seems to crash my app.

 

I've tried wrapping it in a try/except, which I don't know much about and
that doesn't appear to make any difference, the app still crashes.

 

  print 'Reading Push'

  

  try:

 new = e.read()

  except:

 new = 'fault'

 

Print 'Results Read'

 

I'm not sure if this makes any difference, but this is all being run from
within a thread.

 

I need some help on handling this a little better to avoid my application
from dying on me, if anyone can offer some advice on what can be done it
would be greatly appreciated, I'm hoping just a small code solution will be
available.

 

Thanks guys, I look forward to hearing from you,

 

Rob

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

DatePart From String

2007-07-03 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I have a date/time as a string which looks like this: 2007-02-01 00:00:00

 

I'm trying to get my hands on the different date parts of that string in the
following formats:

 

Time Only: 00:00:00

Day As Number: 01

Month As Number: 02

Day As Word: Monday

 

I've tried using the time.strptime() function without much success so
thought I'd come and ask your advice.

 

Thanks guys for any advice,

 

Rob

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

RE: DatePart From String

2007-07-03 Thread Robert Rawlins - Think Blue
Hello Dave,

Thanks for getting back to me, I had been trying to use it like this:

time.strptime('2007-01-01 00:00:00','%H:%M:%S')

I was getting an error thrown at me: ValueError: time data did not match 
format:  data=2007-01-01 00:00:00  fmt=%H:%M:%S

I see how your solution works, but I'm hoping to trip is down a little bit as 
this has to be used in a conditional statement such as the one below:

If time.strftime('%H:%M:%S') > time.strptime('2007-01-01 
00:00:00','%H:%M:%S')
Print 'Later In The Day'

You see how that works? I'm basically trying to check if the current time is 
later that the one defined in my string.

Are you able to give me a working example of how I might do this with my 
conditional?

Thanks Dave,

Rob

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dave
Sent: 03 July 2007 10:46
To: [email protected]
Subject: Re: DatePart From String

Robert Rawlins - Think Blue  thinkbluemedia.co.uk> writes:


> I’ve tried using the time.strptime() function without much success so
> thought I’d come and ask your advice.
> 

How exactly does it not work?? This works for me:

from time import mktime, strptime
from datetime import datetime

datetime_string = '2007-02-01 00:00:00'
datetime_object = datetime.fromtimestamp(
  mktime(strptime(datetime_string,'%Y-%m-%d %H:%M:%S')))

print datetime_object.year
print datetime_object.month
print datetime_object.day
print datetime_object.hour
print datetime_object.minute
print datetime_object.second

HTH,
Dave








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

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

POpen - Wait For Process To Complete

2007-07-03 Thread Robert Rawlins - Think Blue
Hello guys,

 

Quite a simple one I'm hoping. I've got a process that I run using popen
which writes to a file, I'm then going to read the file and parse its
contents. However, getting the application to wait until the process is
complete and finished writing before it reads and parses the file is
becoming complicated.

 

Popen is meant to have a wait() function along with a poll() function
(according to the docs), both of which can be used to make the app wait for
the process to finished, but for some reason I can't get them working, when
I try this:



Import popen2



  Process = popen2.popen4('This is my command to run from cmd')

 

  Process.wait()

 

  f = open('path/to/output/file.txt')

  new = f.read()

  f.close()

 

It throws back the following error to me:

 

push.wait()

AttributeError: 'tuple' object has no attribute 'wait'

 

Which is fair enough as popen4 returns a tuple containing the output streams
from the cmd command, but how the hell can I have it wait so I can read the
physical files?

 

I'll be interested to hear your thoughts guys,

 

Rob

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

Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

Is there a command I can run to confirm which version of python I'm running?

 

Another thing I've always wondered, should i be running my applications
using './MyFile.py' or 'Python MyFile.Py' what are the benefits of each
method? One thing I have noticed is that when I used 'Python MyFile.Py' my
processor usage was a lot higher, is that normal?

 

Thanks guys,

 

Rob

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

Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

Is there a command I can run to confirm which version of python I'm running?

 

Another thing I've always wondered, should i be running my applications
using './MyFile.py' or 'Python MyFile.Py' what are the benefits of each
method? One thing I have noticed is that when I used 'Python MyFile.Py' my
processor usage was a lot higher, is that normal?

 

Thanks guys,

 

Rob

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

RE: Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Thanks Tim,

Greatly appreciated, I've been having a few problems with one of my apps
recently crashing at all sorts of odd intervals without throwing an error or
anything like that, So I'm upgrading to 2.5 to see if they'll make life any
simpler.

Thanks mate,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Tim Golden
Sent: 04 July 2007 11:36
Cc: [email protected]
Subject: Re: Which Python Version

Robert Rawlins - Think Blue wrote:
> Is there a command I can run to confirm which version of python I'm
running?

 From outside Python:

   python -V

(that's a capital V)

 From inside Python:

   import sys
   print sys.version

(and a couple of more easily parseable alternatives; look at the sys module
docs)

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

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


Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

Is there a command I can run to confirm which version of python I'm running?

 

Another thing I've always wondered, should i be running my applications
using './MyFile.py' or 'Python MyFile.Py' what are the benefits of each
method? One thing I have noticed is that when I used 'Python MyFile.Py' my
processor usage was a lot higher, is that normal?

 

Thanks guys,

 

Rob

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

Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

Is there a command I can run to confirm which version of python I'm running?

 

Another thing I've always wondered, should i be running my applications
using './MyFile.py' or 'Python MyFile.Py' what are the benefits of each
method? One thing I have noticed is that when I used 'Python MyFile.Py' my
processor usage was a lot higher, is that normal?

 

Thanks guys,

 

Rob

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

Which Python Version

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

Is there a command I can run to confirm which version of python I'm running?

 

Another thing I've always wondered, should i be running my applications
using './MyFile.py' or 'Python MyFile.Py' what are the benefits of each
method? One thing I have noticed is that when I used 'Python MyFile.Py' my
processor usage was a lot higher, is that normal?

 

Thanks guys,

 

Rob

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

GObject and Python 2.5

2007-07-04 Thread Robert Rawlins - Think Blue
Hello Guys,

 

Firstly I should apologise for all the mails that keep landing on the list,
my SMTP server (supplied by my ISP) seems to be playing silly buggers and
sending multiples.

 

I've just installed Python 2.5 on my Debian system and I'm trying to run my
application and I get 'ImportError: No module named gobject' thrown back at
me. I think I've successfully install the glib library using apt-get but the
problem still persists.

 

There is obviously a module I'm missing, any ideas what it might be?

 

Thanks guys,

 

Rob

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

Parsing Help

2007-07-10 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm looking for some help building a function which can parse some XML for
me using ElementTree. The document is of a very consistent format and I've
copied an example of the document below.

 



 









 











 







 





























 











 

















 







 





















 

Now, the piece of information I'm looking to retrieve is inside the
 element and is, in this example , however I want the function to return the standard integer value and not
the unit8 encoded version, so instead of my function returning '0x05' it
just needs to return '5' which is the standard integer version.

 

I will be passing this XML into the function as a string, so the function
will be formed something like this:

 

Def myFunction(XmlAsString):

Pass the xml and exract my value



Return the value as an integer...

 

I'm not sure on the best method to do this, I just want something nice and
quick, lightweight and that's not resource hungry. Can anyone offer some
advice on this?

 

Thanks guys,

 

Rob

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

Time A Script

2007-07-11 Thread Robert Rawlins - Think Blue
Hello Guys,

 

What's the best way to time how long it takes a script to run, from top to
bottom and then have it print that execution time at the end?

 

Thanks guys,

 

Rob

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

Launch One Application From Another

2007-07-12 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm looking for the best method to launch one Python application from
another? Is something like sub process going to be my best bet? Or is there
something more specific for launching one python app from another?

 

Thanks guys,

 

Rob

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

RE: Dict Help

2007-07-15 Thread Robert Rawlins - Think Blue
Thanks Gabriel,

That all works a charm, Iteration on this isn’t important for me so the SET
will work much better I think, I had read about them before but have never
used them, I'm glad to see it works so simply.

Thanks,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Gabriel Genellina
Sent: 15 July 2007 20:33
To: [email protected]
Subject: Re: Dict Help

En Sun, 15 Jul 2007 11:39:24 -0300, Robert Rawlins  
<[EMAIL PROTECTED]> escribió:

> I'm looking for some help expanding on a dictionary I've got and storing  
> multiple values per key and the best way to do it. I'm guessing that I  
> need to store a list inside the value of the dictionary, but I'm not  
> quite sure how that can be achieved, and also how to check for values in  
> that list.
> Here is a brief example of what I want to be able to build:
> Key  Value
> 00:0F:DE:A8:AB:6F  
>
6C66F14B-FED6-D1A4-62EAAD881E9133F0.jpg,01DBB592-F7EB-B000-7F250FD8A2CE158F.
gif,533EAE0F-B211-B2D8-4C2DB662CCECFBD7.3gp
> 00:17:B0:A0:E7:09  
>
6C66F14B-FED6-D1A4-62EAAD881E9133F0.jpg,01DBB592-F7EB-B000-7F250FD8A2CE158F.
gif
> 00:1B:98:16:21:E4  
> 6C66F14B-FED6-D1A4-62EAAD881E9133F0.jpg

There are a few ways to do it. Just translating your own words into  
Python, use a dictionary with a list of values.

> Now I really need to have two functions, one of which appends a value to  
> the list for a specified key, so I have the key and the new value as  
> strings, I then want to locate that key and append the list with the new  
> value.

The simplest way:

d = {}
# add a pair key, value
if key not in d:
   d[key] = [value]
else:
   d[key].append(value)

> The second function I need, is to check for the existence of a value in  
> the list of a particular key, again I have the key and the value and I  
> want to do something like:
> if value in list of values for key:
>do something here...

# check for a key, value
exists = key in d and value in d[key]

> The final function that would be helpful to me would to be able to  
> remove a value from the list for a specific key.

# remove value from key's values
if key in d and value in d[key]:
   d[key].remove(value)

> I'm not sure if a list as the value in a dict is possible, or if its the  
> best way to achieve this, It just made logic sense to me so thought I'd  
> come and get your thoughts on this. If anyone has any better suggestions

It's perfectly possible as you can see. Now, depending on how many values  
you have, or how often do you test, you might replace the list with a set.  
Sets are unordered collections (you will loose the insertion order) but  
are better suited for a "contains" test (O(1) instead of O(n) for a list)
And you might replace the dictionary with a defaultdict. The insertion  
would become:

 from collections import defaultdict
d = defaultdict(set)
# add a pair key, value
d[key].add(value)

The existence check and remove method do not change.

Dicts, lists and sets are documented here:  
 and defaultdict  


-- 
Gabriel Genellina

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

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


Access Object From 2 Applications or Fix Scheduler

2007-07-15 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I have two applications which I need to get talking and sharing an object,
what's the best way to do this? Basically my first application parses an XML
document into a bunch of lists and tuples etc, and I need to access the data
in these lists and tuples from my second application. Is this possible? And
what's the simplest method?

 

This problem all evolves from a hack/work around I've had to place together
as I have been having problems with sched, these two applications used to be
a single one to start with but for some reason when scheduling tasks using
the sched module they wouldn't ever run when supposed too, so I'd schedule
it to run every 2 minutes and it would run between 3 and 15 minutes :-s so I
ripped it out into its own application and it now runs every 2 minutes
exactly.

 

I either need to fix my sched issues or the memory share, either way I'm
quite happy, just need to get it working smoothly.

 

Any ideas?

 

Thanks guys,

 

Rob

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

RE: Access Object From 2 Applications or Fix Scheduler

2007-07-16 Thread Robert Rawlins - Think Blue
Thanks Hendrik & Alex for your suggestions,

I'm glad to see that there are lots of options for me here, and I'll give
them all of a decent exploration to see what my best option is, starting the
second app in a named pipe sounds like a fair solution, but I've not don't
this before, how easy is it to have the second application ready to receive
the new dictionary data?

Just out of interest though I'd still like to know why my first application
schedules didn't work properly, should I be starting them all in their own
thread? Would that work better?

Thanks Guys,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Hendrik van Rooyen
Sent: 16 July 2007 07:29
To: [email protected]
Subject: Re: Access Object From 2 Applications or Fix Scheduler

 Robert Rawlins - Think Blue  wrote:


>Hello Guys,
>
>I have two applications which I need to get talking and sharing an 
>object, what
s the best way to do this? Basically my >first application parses an XML
document into a bunch of lists and tuples etc, and I need to access the data
in these lists >and tuples from my second application. Is this possible? And
whats the simplest method?

>
>This problem all evolves from a hack/work around Ive had to place 
>together as
I have been having problems with >sched, these two applications used to be a
single one to start with but for some reason when scheduling tasks using the
>sched module they wouldnt ever run when supposed too, so Id schedule 
>it to
run every 2 minutes and it would run >between 3 and 15 minutes :-s so I
ripped it out into its own application and it now runs every 2 minutes
exactly.
>
>I either need to fix my sched issues or the memory share, either way 
>Im quite
happy, just need to get it working >smoothly.
>
>Any ideas?
>

You have already split the thing, so I would:

schedule the XML parser and make it do its stuff.
then pickle the results using cPickle
then from this first thing, either:
write the pickles to temp files and start the second thing using eg
os.system() or start the second thing and use a named pipe to pass the
pickles over for unpickling and processing, or use one of the popens, or
have a look at Pyro, or start the second thing as a thread and use a Queue..

of course this whole scheme will fall apart if the combined processing takes
longer than the scheduling interval.

HTH - Hendrik



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


RE: Access Object From 2 Applications or Fix Scheduler

2007-07-16 Thread Robert Rawlins - Think Blue
Also Hendrik,

I should probably mention that the second application is a constant running
application, it's nothing something that can just be 'started' by the first
one, its running non-stop and just needs data passed into it regularly when
the first application finds it.

Application 1   Application 2
Work with dict
Work with dict
Work with dict
Work with dict
New XML Found, Parse Into Dict -->  Work with new dict
Work with new dict
Work with new dict
Work with new dict

You see how that works? Application 1 has a function that runs every minute
and _may_ find a new xml file, if it does then I need it to parse that file
into a list of dictionary and then pass that into application 2, which then
starts using it :-)

Now we may be able to avoid this if there is some type of file watcher
function available in python, my second application could then just watch
the XML file and as soon as a new one is available parse it itself. Is that
something you've heard of?

Thanks,

Rob


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Hendrik van Rooyen
Sent: 16 July 2007 07:29
To: [email protected]
Subject: Re: Access Object From 2 Applications or Fix Scheduler

 Robert Rawlins - Think Blue  wrote:


>Hello Guys,
>
>I have two applications which I need to get talking and sharing an 
>object, what
s the best way to do this? Basically my >first application parses an XML
document into a bunch of lists and tuples etc, and I need to access the data
in these lists >and tuples from my second application. Is this possible? And
whats the simplest method?

>
>This problem all evolves from a hack/work around Ive had to place 
>together as
I have been having problems with >sched, these two applications used to be a
single one to start with but for some reason when scheduling tasks using the
>sched module they wouldnt ever run when supposed too, so Id schedule 
>it to
run every 2 minutes and it would run >between 3 and 15 minutes :-s so I
ripped it out into its own application and it now runs every 2 minutes
exactly.
>
>I either need to fix my sched issues or the memory share, either way 
>Im quite
happy, just need to get it working >smoothly.
>
>Any ideas?
>

You have already split the thing, so I would:

schedule the XML parser and make it do its stuff.
then pickle the results using cPickle
then from this first thing, either:
write the pickles to temp files and start the second thing using eg
os.system() or start the second thing and use a named pipe to pass the
pickles over for unpickling and processing, or use one of the popens, or
have a look at Pyro, or start the second thing as a thread and use a Queue..

of course this whole scheme will fall apart if the combined processing takes
longer than the scheduling interval.

HTH - Hendrik



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


RE: Dict Help

2007-07-17 Thread Robert Rawlins - Think Blue
Morning Gabriel,

I'm looking for a little more advice on this dictionary/list to
defaultdict/set conversion that we were talking about, there were a few
things I was looking to clarify. Firstly, what is the difference between a
standard dict and a default dict? Is it purely a performance issue? 

This dict is likely to grow pretty large and is read/written on a very
regular basis so the better performing one is going to work best for me.
Also, am I still able to iterate over a set in the same way I can a list?

Here is an example of my add function at the moment, how can that be
converted to a defaultdict/set instead of the dict/list approach?

self.History = {}

def addHistory(self, address, media):
if address not in self.History:
self.History[address] = []

self.History[address].append(media)

Thanks Gabriel,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Robert Rawlins - Think Blue
Sent: 15 July 2007 20:47
To: 'Gabriel Genellina'; [email protected]
Subject: RE: Dict Help

Thanks Gabriel,

That all works a charm, Iteration on this isn’t important for me so the SET
will work much better I think, I had read about them before but have never
used them, I'm glad to see it works so simply.

Thanks,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Gabriel Genellina
Sent: 15 July 2007 20:33
To: [email protected]
Subject: Re: Dict Help

En Sun, 15 Jul 2007 11:39:24 -0300, Robert Rawlins  
<[EMAIL PROTECTED]> escribió:

> I'm looking for some help expanding on a dictionary I've got and storing  
> multiple values per key and the best way to do it. I'm guessing that I  
> need to store a list inside the value of the dictionary, but I'm not  
> quite sure how that can be achieved, and also how to check for values in  
> that list.
> Here is a brief example of what I want to be able to build:
> Key  Value
> 00:0F:DE:A8:AB:6F  
>
6C66F14B-FED6-D1A4-62EAAD881E9133F0.jpg,01DBB592-F7EB-B000-7F250FD8A2CE158F.
gif,533EAE0F-B211-B2D8-4C2DB662CCECFBD7.3gp
> 00:17:B0:A0:E7:09  
>
6C66F14B-FED6-D1A4-62EAAD881E9133F0.jpg,01DBB592-F7EB-B000-7F250FD8A2CE158F.
gif
> 00:1B:98:16:21:E4  
> 6C66F14B-FED6-D1A4-62EAAD881E9133F0.jpg

There are a few ways to do it. Just translating your own words into  
Python, use a dictionary with a list of values.

> Now I really need to have two functions, one of which appends a value to  
> the list for a specified key, so I have the key and the new value as  
> strings, I then want to locate that key and append the list with the new  
> value.

The simplest way:

d = {}
# add a pair key, value
if key not in d:
   d[key] = [value]
else:
   d[key].append(value)

> The second function I need, is to check for the existence of a value in  
> the list of a particular key, again I have the key and the value and I  
> want to do something like:
> if value in list of values for key:
>do something here...

# check for a key, value
exists = key in d and value in d[key]

> The final function that would be helpful to me would to be able to  
> remove a value from the list for a specific key.

# remove value from key's values
if key in d and value in d[key]:
   d[key].remove(value)

> I'm not sure if a list as the value in a dict is possible, or if its the  
> best way to achieve this, It just made logic sense to me so thought I'd  
> come and get your thoughts on this. If anyone has any better suggestions

It's perfectly possible as you can see. Now, depending on how many values  
you have, or how often do you test, you might replace the list with a set.  
Sets are unordered collections (you will loose the insertion order) but  
are better suited for a "contains" test (O(1) instead of O(n) for a list)
And you might replace the dictionary with a defaultdict. The insertion  
would become:

 from collections import defaultdict
d = defaultdict(set)
# add a pair key, value
d[key].add(value)

The existence check and remove method do not change.

Dicts, lists and sets are documented here:  
<http://docs.python.org/lib/types.html> and defaultdict  
<http://docs.python.org/lib/defaultdict-objects.html>

-- 
Gabriel Genellina

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

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

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


Subprocess Poll() to sport Application Crash

2007-07-18 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I have an application which launches a sub-process using the sub
process/Popen module, which seems to work great. However on occasion the
launched process will crash, it doesn't appear to full terminate though as
when I run a 'top' command from the Linux system the process is still
displayed in the list, it just appears to be dormant and the TIME+ for the
application stops incrementing.

 

Can I use the poll() method from the sub-process object to test for this? I
would love to test it however the crash is so rare it's very difficult to
simulate, so thought I'd try and see if anyone has any experience of this.

 

Thanks chaps,

 

Rob

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

Subprocess Poll

2007-07-18 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I have an application which launches a sub-process using the sub
process/Popen module, which seems to work great. However on occasion the
launched process will crash, it doesn't appear to full terminate though as
when I run a 'top' command from the Linux system the process is still
displayed in the list, it just appears to be dormant and the TIME+ for the
application stops incrementing.

 

Can I use the poll() method from the sub-process object to test for this? I
would love to test it however the crash is so rare it's very difficult to
simulate, so thought I'd try and see if anyone has any experience of this.

 

Thanks chaps,

 

Rob

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

Copy List

2007-07-18 Thread Robert Rawlins - Think Blue
Hello Guys,

 

What's the best way to create a copy of a list? I've seen several method and
I'm not sure what to use. This will be in a class and one method creates a
list which I then want to move to the self scope, like so:

 

__Init__(self):

Self.myList = []

 

regenerateList(self):

 

newList = []

 

for somthing in somthing:

newList.append('SomeStuff')

 

self.Mylist = newList.copy()

 

See, The iteration and rebuilding of the list could be quite slow, during
which time the application could be reading from the self.mylist variable so
i think simply doing this:

 

regenerateList(self):

 

self.myList = []

 

for somthing in somthing:

self.myList.append('SomeStuff')

 

Might cause a few inconsistencies in the list if it's being read from whilst
I'm appending too it, so I'm guessing that the top example is the best
method, I'm just looking for the best way to copy() that list into the self
scope, should i be using copy(), deepcopy() or simply self.mylist = newlist?

 

Thanks guys,

 

Rob 

 

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

Log Memory Usage

2007-07-19 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I have an embedded application with a suspected memory leak which I'm trying
to confirm. You see, the application seems to crash unexpectedly and when
looking at the resource consumption after the crash system memory has crept
up to nearly 100%.

 

However this takes quite a long time to occur, so sitting and watching the
application run isn't a very effective way of doing it, so I'm looking for
the best way to log the system memory every minute or two.

 

I have a scheduled event which occurs every minute, i just need a code
solution to give me the systems current memory consumptions details, is
there perhaps something in the os module?

 

Thanks for any suggestions guys,

 

Rob

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

DateTime Differance

2007-07-20 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I've used the eGenix date time module to create two date time objects which
I'm now looking to compare like so:

 

If date 1 is more than 5 minutes older than date 2:

Do something here...

 

After reading through the egenix documentation I'm still a little confused
as the best way to do this. Can anyone offer any advice?

 

Thanks guys,

 

Rob

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

Byte-Array to String

2007-04-19 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I have a byte array passed to me by dbus and I'm looking to convert it into
a string? Is that possible? Sorry for seeming like a putts with these
questions, I'm not used to all these complex data types :-D

 

The byte array looks something like this when printed to screen.

 

dbus.Array([dbus.Byte(54), dbus.Byte(0), dbus.Byte(24), dbus.Byte(9),
dbus.Byte(0), dbus.Byte(0), dbus.Byte(10), dbus.Byte(0), dbu
s.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(9), dbus.Byte(0),
dbus.Byte(1), dbus.Byte(53), dbus.Byte(3), dbus.Byte(25), dbus.
Byte(16), dbus.Byte(0), dbus.Byte(9), dbus.Byte(2), dbus.Byte(0),
dbus.Byte(53), dbus.Byte(3), dbus.Byte(9), dbus.Byte(1), dbus.By
te(1)], signature=dbus.Signature('y'))

 

Thanks again,

 

Rob

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

RE: Byte-Array to String

2007-04-19 Thread Robert Rawlins - Think Blue
Thanks for getting back to me on this Tim, *pauses pulling his hair out for
a moment.

I'm back on this damn API and its driving me crazy I get three options
really for returning a service record from the API, they look like this.

array{uint32} GetRemoteServiceHandles(string address, string
match)

This method will request the SDP database of a
remote
device and retrieve the service record handles. To
request service browse send an empty match string.

Possible errors: org.bluez.Error.InvalidArguments
 org.bluez.Error.InProgress

org.bluez.Error.ConnectionAttemptFailed
 org.bluez.Error.Failed

array{byte} GetRemoteServiceRecord(string address, uint32
handle)

This method will request the SDP database of a
remote
device for a service record and return the binary
stream of it.

Possible errors: org.bluez.Error.InvalidArguments
 org.bluez.Error.InProgress
 org.bluez.Error.Failed

string GetRemoteServiceRecordAsXML(string address, uint32
handle)

This method will request the SDP database of a
remote
device for a service record and return its data in
XML
format.

Possible errors: org.bluez.Error.InvalidArguments
 org.bluez.Error.InProgress
 org.bluez.Error.Failed

The first method, when I print its results just gives me
dbus.Array([dbus.UInt32(65547L)], signature=dbus.Signature('u')) the method
gives me that byte array and the third doesn't appear to work at all :-D

Unfortunately nowhere seems to document what exactly those arrays contain,
so I'm trying to crack one open and find out, but as you can see, I'm not
having much luck. Perhaps this is a DBus thing, they do have a mailing list
so I'll give them a go in a while.

If you have any brain waves let me know mate, I'll add another beer to the
tab,

Rob


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Tim Golden
Sent: 19 April 2007 15:54
Cc: [email protected]
Subject: Re: Byte-Array to String

Robert Rawlins - Think Blue wrote:
> I have a byte array passed to me by dbus and I'm looking to convert it
into
> a string? Is that possible? Sorry for seeming like a putts with these
> questions, I'm not used to all these complex data types :-D
> 
> dbus.Array([dbus.Byte(54), dbus.Byte(0), dbus.Byte(24), dbus.Byte(9),
> dbus.Byte(0), dbus.Byte(0), dbus.Byte(10), dbus.Byte(0), dbu
> s.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(9), dbus.Byte(0),
> dbus.Byte(1), dbus.Byte(53), dbus.Byte(3), dbus.Byte(25), dbus.
> Byte(16), dbus.Byte(0), dbus.Byte(9), dbus.Byte(2), dbus.Byte(0),
> dbus.Byte(53), dbus.Byte(3), dbus.Byte(9), dbus.Byte(1), dbus.By
> te(1)], signature=dbus.Signature('y'))

No idea, but what happens when you iterate over it?

for i in array_thingy:
   print i

Or does it support the buffer interface?

for i in buffer (array_thingy):
   print i

If it did then you can at least get access to its
innards and construct some kind of string representation.
I've no idea what the numbers are supposed to represent,
so I don't know what "convert it to a string" is likely
to imply. This looks rather more like a dbus question than
a strictly Python one. Is there a DBus mailing list or
what-have-you?

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

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


RE: Byte-Array to String

2007-04-20 Thread Robert Rawlins - Think Blue
Morning Steve,

 

That stuff looks mighty promising, I did play around with the toString()
function yesterday but couldn't get the damned thing working. The syntax has
me a little muddled, perhaps you can help out on this by taking a look at my
code.

 

#!/usr/bin/python

import dbus

 

bus = dbus.SystemBus()

obj = bus.get_object('org.bluez', '/org/bluez')

obj = bus.get_object('org.bluez', '/org/bluez/hci0')

adapter = dbus.Interface(obj, 'org.bluez.Adapter')

 

# Search For Obex Push Protocol

result = adapter.GetRemoteServiceHandles('00:17:B0:A0:E7:09', 'opp')

 

result2 = adapter.GetRemoteServiceRecord('00:17:B0:A0:E7:09', result[0])

 

Now 'result2' is basically that byte array, Unfortunately the API doesn't
give any more information other than that the function returns a array{byte}
so I can't really shed any more light on that however if I can just get it
to output all the elements from that array then I will know which one it is
I'm looking for.

 

I tried to implement your suggestions below as they look pretty safe, but I
couldn't get it to work, my syntax is pretty confused as I'm so new to the
language. Like I say, there is only one element of the array I'm interested
in, I just need to see them all before I know which it is.

 

Thanks again Steve,

 

Rob

 

From: Steven Howe [mailto:[EMAIL PROTECTED] 
Sent: 19 April 2007 16:51
To: Robert Rawlins - Think Blue
Cc: [email protected]
Subject: Re: Byte-Array to String

 

Robert Rawlins - Think Blue wrote: 

Hello Guys,
 
 
 
I have a byte array passed to me by dbus and I'm looking to convert it into
a string? Is that possible? Sorry for seeming like a putts with these
questions, I'm not used to all these complex data types :-D
 
 
 
The byte array looks something like this when printed to screen.
 
 
 
dbus.Array([dbus.Byte(54), dbus.Byte(0), dbus.Byte(24), dbus.Byte(9),
dbus.Byte(0), dbus.Byte(0), dbus.Byte(10), dbus.Byte(0), dbu
s.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(9), dbus.Byte(0),
dbus.Byte(1), dbus.Byte(53), dbus.Byte(3), dbus.Byte(25), dbus.
Byte(16), dbus.Byte(0), dbus.Byte(9), dbus.Byte(2), dbus.Byte(0),
dbus.Byte(53), dbus.Byte(3), dbus.Byte(9), dbus.Byte(1), dbus.By
te(1)], signature=dbus.Signature('y'))
 
 
 
Thanks again,
 
 
 
Rob
 

When reading about array, I wondered what the hell it was good for. Now I
see. It's a tool to build objects 
to pass to the Operating System or other applications. Something like
ctypes. The OS might store data from left to right, or right to left, or not
use IEEE standards (which VMS certainly doesn't). So the data you give/get
from the system call must be massaged by the application before it's usable.

python/lib/module-array.html (5.14 array -- Efficient arrays of numeric
values)
array.tostring( )
Convert the array to an array of machine values and return the string
representation (the same sequence of bytes that would be written to a file
by the tofile() method.)

I wonder if this is the method you are looking for. 
So you have an object dbus.Array, which, obviously is from a call to the
dbus (another application's data) that contains 28 byte arrays. I would
assume you know which you want, say the first one.

myDbusString01 = dbus.Array[0].tostring() 

or to get the lot:

myDbusStrings = []  #create a new empty list
for array in dbus.Array:
myDbusStrings.append( array.tostring() )

At this point you should have the array converted. But you will still need a
reference as to what you have. The call to the dbus should have some
documentation abut what it's returning. 
Also I'd expect the second example to be very bad programming, as some of
the array elements are probably not going to be characters. They could be
integers, floats or booleans. So creating a dictionary to handle specific
array element handling is probably a better, less error prone, method of
attack.

Not have the contents and defination of your dbus.array handy, I can't test
this, but the approach seems reasonable.

Steven Howe

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

RE: Byte-Array to String

2007-04-20 Thread Robert Rawlins - Think Blue
Thanks for that Carsten,

I've given that a go and I still get similar results to what I've seen in the 
past whereby it prints a couple of elements I would expect to see but other 
which I'm not sure about, and what seems to be ALOT of blank characters.

6e
555 5   5   5   en  j   
5   %OBEX Object Push   ÿ

That's what your suggestion returns to me, I'm using the API to scan a 
Bluetooth device for services, one of which is OBEX Object Push, but the rest 
of that output is apparent junk.

Unfortunately the API doesn’t really give any suggestions at all, take a look 
here http://bluez.cvs.sourceforge.net/*checkout*/bluez/utils/hcid/dbus-api.txt 
if you look down under the 'adapter' section, I'm running the method called 
GetRemoteServiceRecord() which returns the byte array but there really isn’t 
any suggestion as to how you extract the information from what's returned.

I have no idea if we're barking up the right tree here or if we're going about 
this the wrong way.

Thanks again for all your helps guys,

Rob

-Original Message-
From: Carsten Haese [mailto:[EMAIL PROTECTED] 
Sent: 20 April 2007 14:00
To: Robert Rawlins - Think Blue
Cc: [email protected]
Subject: RE: Byte-Array to String

On Fri, 2007-04-20 at 09:51 +0100, Robert Rawlins - Think Blue wrote:
> Morning Steve,
> 
>  
> 
> That stuff looks mighty promising, I did play around with the
> toString() function yesterday but couldn’t get the damned thing
> working.

That's because Steven seems to have given you suboptimal advice. The
thing you're working with is a dbus.Array of dbus.Byte, not a Python
array, so Python's standard array module is not going to help you.

When you work with an API function and you don't know what to do with
the results of calling that function, the documentation for that API
should be your first place to look for help. I don't know what you're
referencing, but Google tells me that the python-dbus API is documented
here: http://dbus.freedesktop.org/doc/dbus-python/api/

So, what do you do with a dbus.Array full of instances of dbus.Byte?
Let's look at their documentation,
http://dbus.freedesktop.org/doc/dbus-python/api/dbus.Array-class.html
and
http://dbus.freedesktop.org/doc/dbus-python/api/dbus.Byte-class.html,
respectively.

The page about dbus.Array tells us that it inherits from list, so you
should be able to do indexed access into it and iterate over it.
dbus.Byte inherits from int, and the documentation says that a dbus.Byte
can be converted to a character (string of length 1) by calling str or
chr on it.

So, to get a string from your dbus.Array, you could do something like
this:

s = ""
for b in myDbusArray:
  s += chr(b)

However, it's better (faster) to use the join idiom for building a
string char-by-char:

s = "".join(chr(b) for b in myDbusArray)

That ought to give you the string you're asking for.

HTH,

Carsten.



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

Schedule Task

2007-04-21 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I've got a method in my app that I want to run every 20 minutes that the
application it running, what's the best way of achieving this? At the moment
I'm using this kind of method.

 

import sched

import time, sys

scheduler = sched.scheduler(time.time, time.sleep)

 

scheduler.enter(1.0, 0, sys.stdout.write, ("one\n",))

scheduler.run()

 

Now when the function runs after 20 minutes I just have it schedule itself
to run again in 20 minutes time, which seems to work for me quite nicely, it
just seems a little 'hacky' to keep the task reoccurring like that.

 

Is there any other method? I've spent some time on Google but couldn't
really find anything. Not sure if it makes any difference but I'm running
Linux.

 

Thanks,

 

Rob

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

Class Not Auto-Init On Import

2007-04-21 Thread Robert Rawlins - Think Blue
Hello Guys,

 

>From my understanding of what I've read, the 'import' is meant to auto Init
my class ready for me to access its methods, but it doesn't appear too, I'm
having to init them myself before I can access them, like this.

 

import LocationService

 

Location = LocationService.LocationService()

 

LocationService.setIP('192.168.1.1')

 

Why is this the case? Should i not just be able to access the setIP() method
by doing LocationService.setIP('192.168.1.1') Without having to create my
own inited reference?

 

Thanks,

 

Rob

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

Styled Output

2007-04-21 Thread Robert Rawlins - Think Blue
Chaps,

 

Hope you're all having a good weekend, I'm sure it'll only be the more 'hard
core' of you reading this, anyone with any sanity would be out in the
sunshine right now.

 

I'm running a program of mine from Linux bash script and it currently
outputs status messages to the command prompt, but they all look a little
boring to say the least, it'll be like this.

 

Application Started

Sucess

Application Configured

Failed

Retry

Application Configured

Success

 

What I'd ideally like to do it give it a little bit of format, so it perhaps
looks something like this.

 

Application Started
[Success]

Application Configured
[Success]

 

And perhaps have the word 'success' in green, or red for 'failed' and things
like that, just to make it a little more presentable to the user.

 

Any ideas on the best way to achieve this?

 

Thanks,

 

Rob

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

Minidom Help

2007-04-24 Thread Robert Rawlins - Think Blue
Hello guys,

 

Not got much experience with working with minidom, but I'm looking to parse
this XML and retrieve the 'name' value from the xml.

 







Think Blue

0x1002

1





 

I've got as far as parsing the XML using self.doc =
xml.dom.minidom.parse(self.filepath) but that's as far as I've managed to
get. I've spent a little time googling around but it's all double Dutch to
me.

 

Any ideas?

 

Thanks,

 

Rob

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

If Dict Contains a particular key

2007-04-24 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm Looking to build a quick if/else statement that checks a dictionary for
a key like follows.

 

If myDict contains ThisKey:

Do this...

Else

Do that...

 

Thats the best way of doing this?

 

Thanks,

 

Rob

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

RE: If Dict Contains a particular key

2007-04-25 Thread Robert Rawlins - Think Blue
Thanks guys for this, glad it was so simple.

 

I used mikes solution in the end, and it worked a charm.

 

Thanks again,

 

Rob

 

From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Michael Bentley
Sent: 24 April 2007 18:37
To: [email protected]
Subject: Re: If Dict Contains a particular key

 

 

On Apr 24, 2007, at 12:28 PM, Robert Rawlins - Think Blue wrote:





Hello Guys,

 

I'm Looking to build a quick if/else statement that checks a dictionary for
a key like follows.

 

If myDict contains ThisKey:

Do this...

Else

Do that...

 

Thats the best way of doing this?

if ThisKey in myDict:

  pass # do this

else:

  pass # do that

 

 

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

If Dict Contains...

2007-04-25 Thread Robert Rawlins - Think Blue
Hello Guys,

 

Looking to build a quick if/else statement that checks a dictionary for a
key like follows.

 

If myDict contains ThisKey:

Do this...

Else

Do that...

 

Thats the best way of doing this?

 

Thanks,

 

Rob

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

popen2 results

2007-04-25 Thread Robert Rawlins - Think Blue
Hello guys,

 

I've recently ported my application from bash to python, however there are
still a few bash line utilities I -have- to use in the application as there
isn't any alternative available to me. In the old days of bash I would have
grep'd the output from these commands to determine the outcome.

 

I'm now using popen2 to run the command which works a charm, but I'm
struggling to parse the results of the function, has anyone had any
experience with this? I've found a few suggested solutions dotted around,
such as this one.

 

 import os

 

 def filtered(command, source):

 dest, result = os.popen2(command)

 dest.write(source)

 dest.close()

 try:

  return result.read()

 finally:

  result.close()

 

But to be honest I'm struggling to get it to do anything as it doesn't
states what the 'source' object is or should be.

 

Thanks for any help guys, I'm just looking to capture the output from the
command and then I can go about a little REGEX on it.

 

Thanks,

 

Rob

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

Now()

2007-04-25 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm using the following function 'str (now)' to place a date time stamp into
a log file, which works fine, however it writes the stamp like this.

 

2007-04-25 11:06:53.873029

 

But I need to expel those extra decimal places as they're causing problems
with the application that parses the log data, all I need is something like
this:

 

2007-04-25 11:06:53

 

With time depicted to the nearest second, from my background in ColdFusion
development we used to have a datetimeformat() function that I could use as

 

DateTimeFormat(now(), "-mm-dd HH:mm:ss")

 

Which would give the current time a mask.

 

Any equivalent for this in python?

 

Thanks,

 

Rob

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

Scheduler Module Help

2007-04-26 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm using the sched module to create a set of functions that run every 10 or
20 minutes whilst the application is running, however it would seem that the
moment I run scheduler.run() it prevents any other operations in my
application from running, its sits dormant until it runs the scheduled
functions.

 

Any ideas on what might be the root of this issue?

 

Thanks,

 

Rob

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

Re-ocurring Events

2007-04-26 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

A bit more of a complex one this time, and I thought I'd get your opinions
on the best way to achieve this. Basically I'm looking for a way to describe
a re-occurring event, like a calendar event or appointment I guess. I'm
likely to use an XML file for the definition of the events, but imagine I've
got an event that looks something like this.

 



 

Now what I want to do is be able to build a class which has a function like
'getCurrentEvent()' which will return any events that should be occurring at
that time. So if the current system time and date is 2007-01-03 13:00:00
then it will return THAT event to me, but if it was say 2007-01-03 16:00:00
then it would not, as the event isn't 'due' to occur at that time. Make
sense?

 

What's the best way of handling this? I'm really a little lost as to how I
might get started, checking a static date time isn't a problem, it's when it
comes to these re-occurring events that I struggle a little. The idea is
that I would have 5 core repetitions, none, daily, weekly, monthly and
annually.

 

Or perhaps you guys have a more full proof method of describing the event in
the XML?

 

Any suggestions are more than welcome guys, thanks again for all your help
recently.

 

Rob

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

RE:: Re-ocurring Events

2007-04-27 Thread Robert Rawlins - Think Blue
Thank you guys for your suggestions.

I've been having a look at that launchd stuff from apple but couldn’t really
see how that applies to my requirements.

I've been putting some serious thought into how this should work as its
essentially the final part of the puzzle for my application, I'll have a
fully working model for my application.

I've been thinking about the possibility of using a combination of xpath to
search the XML with some loops which change the date. As events won't ever
be set to start before 01-01-2007 I can set that as the ceiling for my loop.
So when I'm searching for weekly events, I 'simply' take today's date and
time and loop from now until 01-01-2007 decrementing the date by a week each
iteration of the loop and then search the XML for events in that date, make
sense?

I know that's a fairly intensive way of doing it, but if it works it works.

Now, the loop is where I'm really struggling, I've not done any looping with
dates, can anyone give me a hand with this? How can I loop back in time from
now to beginning of 07 a week at a time? Do we have some form of dateAdd() I
can use with a while loop? Perhaps.

Date = (now)
While date > 2007-01-01:
Date = dateAdd(date, -1, w)

Something to that effect? Then I can quickly xpath for every iteration of
the loop.

Thanks guys for any help.

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Laurent Pointal
Sent: 26 April 2007 15:33
To: [email protected]
Subject: Re: Re-ocurring Events

Daniel Nogradi a écrit :
>> A bit more of a complex one this time, and I thought I'd get your 
>> opinions
>> on the best way to achieve this. Basically I'm looking for a way to 
>> describe
>> a re-occurring event, like a calendar event or appointment I guess. I'm
>> likely to use an XML file for the definition of the events, but 
>> imagine I've
>> got an event that looks something like this.
>>
>> > repeat="daily"
>> />

May take a look at launchd (Apple) XML dialect, it may have at least the 
semantic for your need.

For other parts... elementtree, yes.

>> Now what I want to do is be able to build a class which has a function 
>> like
>> 'getCurrentEvent()' which will return any events that should be 
>> occurring at
>> that time. So if the current system time and date is 2007-01-03 13:00:00
>> then it will return THAT event to me, but if it was say 2007-01-03 
>> 16:00:00
>> then it would not, as the event isn't 'due' to occur at that time. Make
>> sense?
>>
>> What's the best way of handling this? I'm really a little lost as to 
>> how I
>> might get started, checking a static date time isn't a problem, it's 
>> when it
>> comes to these re-occurring events that I struggle a little. The idea is
>> that I would have 5 core repetitions, none, daily, weekly, monthly and
>> annually.
> 
> This will not solve all your problems, but a very convenient way of
> handling XML is the element tree module (that comes with python 2.5):
> http://docs.python.org/lib/module-xml.etree.ElementTree.html
> 
> HTH,
> Daniel
-- 
http://mail.python.org/mailman/listinfo/python-list

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


RE: : Re-ocurring Events

2007-04-27 Thread Robert Rawlins - Think Blue
Just as another quick update, I've found this module for python that may be
able to help me, its designed to spot date patterns for things like
recurring events I guess,

http://www.biostat.wisc.edu/~annis/creations/period.py.html

Quite how I can integrate it into my project I'm not sure but if I can loop
through each of the events in my XML and see if they are meant to be
recurring today then that's fantastic.

If anyone has any rough ideas on how this might work for me I'd love to hear
some rough concepts.

Thanks,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Robert Rawlins - Think Blue
Sent: 27 April 2007 08:24
To: [email protected]
Subject: RE:: Re-ocurring Events

Thank you guys for your suggestions.

I've been having a look at that launchd stuff from apple but couldn’t really
see how that applies to my requirements.

I've been putting some serious thought into how this should work as its
essentially the final part of the puzzle for my application, I'll have a
fully working model for my application.

I've been thinking about the possibility of using a combination of xpath to
search the XML with some loops which change the date. As events won't ever
be set to start before 01-01-2007 I can set that as the ceiling for my loop.
So when I'm searching for weekly events, I 'simply' take today's date and
time and loop from now until 01-01-2007 decrementing the date by a week each
iteration of the loop and then search the XML for events in that date, make
sense?

I know that's a fairly intensive way of doing it, but if it works it works.

Now, the loop is where I'm really struggling, I've not done any looping with
dates, can anyone give me a hand with this? How can I loop back in time from
now to beginning of 07 a week at a time? Do we have some form of dateAdd() I
can use with a while loop? Perhaps.

Date = (now)
While date > 2007-01-01:
Date = dateAdd(date, -1, w)

Something to that effect? Then I can quickly xpath for every iteration of
the loop.

Thanks guys for any help.

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Laurent Pointal
Sent: 26 April 2007 15:33
To: [email protected]
Subject: Re: Re-ocurring Events

Daniel Nogradi a écrit :
>> A bit more of a complex one this time, and I thought I'd get your 
>> opinions
>> on the best way to achieve this. Basically I'm looking for a way to 
>> describe
>> a re-occurring event, like a calendar event or appointment I guess. I'm
>> likely to use an XML file for the definition of the events, but 
>> imagine I've
>> got an event that looks something like this.
>>
>> > repeat="daily"
>> />

May take a look at launchd (Apple) XML dialect, it may have at least the 
semantic for your need.

For other parts... elementtree, yes.

>> Now what I want to do is be able to build a class which has a function 
>> like
>> 'getCurrentEvent()' which will return any events that should be 
>> occurring at
>> that time. So if the current system time and date is 2007-01-03 13:00:00
>> then it will return THAT event to me, but if it was say 2007-01-03 
>> 16:00:00
>> then it would not, as the event isn't 'due' to occur at that time. Make
>> sense?
>>
>> What's the best way of handling this? I'm really a little lost as to 
>> how I
>> might get started, checking a static date time isn't a problem, it's 
>> when it
>> comes to these re-occurring events that I struggle a little. The idea is
>> that I would have 5 core repetitions, none, daily, weekly, monthly and
>> annually.
> 
> This will not solve all your problems, but a very convenient way of
> handling XML is the element tree module (that comes with python 2.5):
> http://docs.python.org/lib/module-xml.etree.ElementTree.html
> 
> HTH,
> Daniel
-- 
http://mail.python.org/mailman/listinfo/python-list

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

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


RE: Re-ocurring Events

2007-04-27 Thread Robert Rawlins - Think Blue
Thanks for getting back to me Laurent.

I've now made some pretty tidy progress on this and -think- it's going to
shape up nicely, I'm just working on converting my date strings from the XML
into a date_struct and we should be good to go.

I'll keep you all posted.

Rob

-Original Message-
From: Laurent Pointal [mailto:[EMAIL PROTECTED] 
Sent: 27 April 2007 09:49
To: Robert Rawlins - Think Blue
Subject: Re: Re-ocurring Events

Robert Rawlins - Think Blue a écrit :
> Thank you guys for your suggestions.
> 
> I've been having a look at that launchd stuff from apple but couldn’t
really
> see how that applies to my requirements.

I was not thinking about launchd itself, but about its XML configuration 
files which manage timed events, as you need.

> I've been putting some serious thought into how this should work as its
> essentially the final part of the puzzle for my application, I'll have a
> fully working model for my application.
> 
> I've been thinking about the possibility of using a combination of xpath
to
> search the XML with some loops which change the date. As events won't ever
> be set to start before 01-01-2007 I can set that as the ceiling for my
loop.
> So when I'm searching for weekly events, I 'simply' take today's date and
> time and loop from now until 01-01-2007 decrementing the date by a week
each
> iteration of the loop and then search the XML for events in that date,
make
> sense?
> 
> I know that's a fairly intensive way of doing it, but if it works it
works.
> 
> Now, the loop is where I'm really struggling, I've not done any looping
with
> dates, can anyone give me a hand with this? How can I loop back in time
from
> now to beginning of 07 a week at a time? Do we have some form of dateAdd()
I
> can use with a while loop? Perhaps.

See datetime module, eventually third party mxDatetime.

> Date = (now)
> While date > 2007-01-01:
>   Date = dateAdd(date, -1, w)
> 
> Something to that effect? Then I can quickly xpath for every iteration of
> the loop.

A+

Laurent.

-- 
Laurent POINTAL
CNRS-LIMSI dépt. CHM, groupes AMI et PS
Courriel: [EMAIL PROTECTED](prof)
   [EMAIL PROTECTED] (perso)
Ouebe: http://www.limsi.fr/Individu/pointal/
Tél. 01 69 85 81 06 (prof)
Fax. 01 69 85 80 88



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


RE: Re-ocurring Events

2007-04-27 Thread Robert Rawlins - Think Blue
Ok, Almost done now, it seems to be working a real charm at the moment.

I need a little help on performing a quick if statement against a date
string. I have couple of date strings returned by

s.attributes.getNamedItem("start").nodeValue
s.attributes.getNamedItem("end").nodeValue

and I need to do and conditional that ensures start is before today's
date/time and end is after today's date/time.

The string looks like: '2007-01-01 00:00:00'

Do I have to convert this to a proper time object to do the comparison? Or
can I do it as a string?

Thanks,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Robert Rawlins - Think Blue
Sent: 27 April 2007 09:55
To: 'Laurent Pointal'
Cc: [email protected]
Subject: RE: Re-ocurring Events

Thanks for getting back to me Laurent.

I've now made some pretty tidy progress on this and -think- it's going to
shape up nicely, I'm just working on converting my date strings from the XML
into a date_struct and we should be good to go.

I'll keep you all posted.

Rob

-Original Message-
From: Laurent Pointal [mailto:[EMAIL PROTECTED] 
Sent: 27 April 2007 09:49
To: Robert Rawlins - Think Blue
Subject: Re: Re-ocurring Events

Robert Rawlins - Think Blue a écrit :
> Thank you guys for your suggestions.
> 
> I've been having a look at that launchd stuff from apple but couldn’t
really
> see how that applies to my requirements.

I was not thinking about launchd itself, but about its XML configuration 
files which manage timed events, as you need.

> I've been putting some serious thought into how this should work as its
> essentially the final part of the puzzle for my application, I'll have a
> fully working model for my application.
> 
> I've been thinking about the possibility of using a combination of xpath
to
> search the XML with some loops which change the date. As events won't ever
> be set to start before 01-01-2007 I can set that as the ceiling for my
loop.
> So when I'm searching for weekly events, I 'simply' take today's date and
> time and loop from now until 01-01-2007 decrementing the date by a week
each
> iteration of the loop and then search the XML for events in that date,
make
> sense?
> 
> I know that's a fairly intensive way of doing it, but if it works it
works.
> 
> Now, the loop is where I'm really struggling, I've not done any looping
with
> dates, can anyone give me a hand with this? How can I loop back in time
from
> now to beginning of 07 a week at a time? Do we have some form of dateAdd()
I
> can use with a while loop? Perhaps.

See datetime module, eventually third party mxDatetime.

> Date = (now)
> While date > 2007-01-01:
>   Date = dateAdd(date, -1, w)
> 
> Something to that effect? Then I can quickly xpath for every iteration of
> the loop.

A+

Laurent.

-- 
Laurent POINTAL
CNRS-LIMSI dépt. CHM, groupes AMI et PS
Courriel: [EMAIL PROTECTED](prof)
   [EMAIL PROTECTED] (perso)
Ouebe: http://www.limsi.fr/Individu/pointal/
Tél. 01 69 85 81 06 (prof)
Fax. 01 69 85 80 88



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

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


RE: what python technology for my app?

2007-04-27 Thread Robert Rawlins - Think Blue
Just thought I'd make a little suggestion about this, I don’t know how
strict you want to be with the web development side of things, but I'm a web
developer by trade and have recently started using python for my non-web
type applications.

If you're looking for a web based server side solution, then you can't go
wrong with Adobe ColdFusion. Its and incredibly powerful and scalable
development platform and yet supports a simple tag based language which
makes life very easy when getting started, and yet will support much more
complex OOP methodology with a whole myriad of frameworks, orm's and object
factories.

For a quick 'run down' of its features take a look at the simple tutorials
on the adobe site, they'll demonstrate how easy it is to achieve even quite
complex tasks like PDF creation, animated statistical charts an all sorts.
As CF is a JAVA based technology you get the power of J2EE platform and its
perfectly multi platform playing nicely with linux, unix, sun, windows or
whatever server environment you wish to run it on.

Just my two pence, I'm a big CF fan so my opinions are no doubt bias, but
might be worth you taking a look.

http://www.adobe.com/uk/products/coldfusion/

Pay attention to the 'ColdFusion Demos' at the bottom right of the main
column.

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Bruno Desthuilliers
Sent: 27 April 2007 12:19
To: [email protected]
Subject: Re: what python technology for my app?

Chris a écrit :
> I have an database containing lots of numerical data. I want to write a 
> browser based interface that will allow selection of various key 
> parameters and yield tables, plots and/or printouts of the data 
> according to the selections. Ultimately I want this to run on an 
> intranet so that others can get access via their browsers.
> 
> The application is for in-house use only and not likely to have more 
> than a few users at any one time. I've managed to hack out enough 
> understanding of sql and sqlAlchemy over the last couple of days to 
> create and access an sqlite3 based database for my data. This seems to 
> suit my purposes for now. Now for a front end and some simple 
> distribution over a network.
> 
> I have written some small Wxpython & matplotlib apps for data analysis 
> and display but I'm not sure how these would work in a browser based 
> world, or even if they are appropriate.

wxPython being a GUI toolkit, it's of course not really appropriate for 
a web-based solution (and yes, this is an understatement).

I don't have any experience with matplotlib, but according to the 
project's FAQ, this shouldn't be a problem:
http://matplotlib.sourceforge.net/faq.html#BATCHMODE

> 
> Any advice on what technologies I should be looking at for this? Python 
> based naturally, and hopefully simple and lightweight. I'm not a 
> programmer by trade and that's not what I really get paid for but I've 
> learned to love python and its myriad of modules for all the data 
> analysis work I need to do. If I can throw something moderately 
> functional together in a week or two (along with all the learning that 
> entails)

If you don't have any experience with web programming, it might take a 
bit more time.

> I'll be happy.

Pylons (http://pylonshq.com) and turbogears are two great web 
frameworks. Both support SQLAlchemy. My own favourite is Pylons, but you 
should try both and choose the one that better fits your brain.

> btw - Platform needs to be windows because that's what on my desk.

Python is mostly platform independant.

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

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


RE: Re-ocurring Events

2007-04-27 Thread Robert Rawlins - Think Blue
Thanks for that tip Jarek, It worked a charm, I just created a format time
string and used that in the compare against my XML and it work perfectly.

Thank you,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Jarek Zgoda
Sent: 27 April 2007 13:01
To: [email protected]
Subject: Re: Re-ocurring Events

Robert Rawlins - Think Blue napisał(a):

> and I need to do and conditional that ensures start is before today's
> date/time and end is after today's date/time.
> 
> The string looks like: '2007-01-01 00:00:00'
> 
> Do I have to convert this to a proper time object to do the comparison? Or
> can I do it as a string?

In the very specific case of string formatted as above, the string
comparison will give the same results as in the case of datetime objects
comparison. You just have to compare the same kinds of things. ;)

-- 
Jarek Zgoda

"We read Knuth so you don't have to."
-- 
http://mail.python.org/mailman/listinfo/python-list

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


RE: what python technology for my app?

2007-04-27 Thread Robert Rawlins - Think Blue
Haha, no Troll, just a shameless plug for my life's one true love ;-)

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Bruno Desthuilliers
Sent: 27 April 2007 14:35
To: [email protected]
Subject: Re: what python technology for my app?

Robert Rawlins - Think Blue a écrit :
> Just thought I'd make a little suggestion about this, I don’t know how
> strict you want to be with the web development side of things, but I'm a
web
> developer by trade and have recently started using python for my non-web
> type applications.
> 
> If you're looking for a web based server side solution, then you can't go
> wrong with Adobe ColdFusion.

Err... is this a troll ?
-- 
http://mail.python.org/mailman/listinfo/python-list

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


Dict Copy & Compare

2007-04-30 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm looking for a little advice on dicts, firstly I need to learn how to
copy a dict, I suppose I could just something like.

 

Self.newdict = self.olddict

 

But I fear that this only creates a reference rather than an actual copy,
this means that as soon as I clear out the old one, the new one will
effectively be empty. What's the best way to ACTUALY copy a dict into a new
variable?

 

Next up I'm looking to compare two different dictionaries, then loop through
the unique results that are in each and print them out. Is there a more
efficient way of doing this other than a loop with an if/else statement?

 

For a in self.dict1:

If a not in self.dict2:

Print 'Found %s' % (a)

 

For b in self.dict2:

If b not in self.dict1:

Print 'Found %s'  % (b)

 

That would firstly loop through the first dict and output any of its unique
values, it then loops through the second dict and output any of its unique
values, is this the best way of doing this? Or is there something more
efficient?

 

Thanks,

 

Rob Rawlins

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

RE: Dict Copy & Compare

2007-04-30 Thread Robert Rawlins - Think Blue
Thanks for that Tim,

The first part for copying the dict seems to work nicely but I'm struggling
to get the second part working properly. Let me explain a little more
specifically what I'm trying to do.

I have two dicts, one named 'this' and the other named 'that'.

I want to get all the unique keys from 'this' and log them into a file, I
then want to take all the unique values from 'that' and log them into a
separate file.

I have functions set up for the logging, so I can call it like
logThis(uniquekey) and logThat(uniquekey).

So it's just a case of firstly returning a list of all keys that are in
'this' but NOT in 'that' and then visa versa, then loop over them performing
the function.

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Tim Golden
Sent: 30 April 2007 09:41
Cc: [email protected]
Subject: Re: Dict Copy & Compare

Robert Rawlins - Think Blue wrote:
> I'm looking for a little advice on dicts, firstly I need to learn how to
> copy a dict, I suppose I could just something like.

> Self.newdict = self.olddict

> But I fear that this only creates a reference rather than an actual copy,
> this means that as soon as I clear out the old one, the new one will
> effectively be empty. What's the best way to ACTUALY copy a dict into a
new
> variable?

Unless you have specialised needs, you can just say:

d2 = dict (d1)

which will initialise d2 from d1's key/value pairs:


d1 = dict (a=1, b=2)
d2 = dict (d1)
d2['a'] = 5
print d1
print d2




> Next up I'm looking to compare two different dictionaries, then loop
through
> the unique results that are in each and print them out. Is there a more
> efficient way of doing this other than a loop with an if/else statement?

This comes up not infrequently on the list. I think there's
even a few recipes in the cookbook. One (fairly recent)
technique is to use set versions of your dictionary keys,
but it depends on what you want to do next. From my example
above:


# relies on the fact that dictionary iterators
# iterate over the keys of the dict.

s1 = set (d1)
s2 = set (d2)

# do whatever set-ops you want, eg

s3 = s1 | s2

for key in s3:
   print "Key:", key
   print "d1 =>", d1[key]
   print "d2 =>", d2[key]



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

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


RE: Dict Copy & Compare

2007-04-30 Thread Robert Rawlins - Think Blue
Hello Tim,

Sorry, that 'value' was a slip up on my part, we're just dealing with keys
here.

I get that a dict stores unique keys only but we're comparing the two dicts,
so when I say 'unique keys in dict 1' I basically mean all those keys that
are in dict one but not in dict 2. So imagine my 2 dicts with the following
keys.

Dict 1  Dict 2
--  ---
00:00:00:00 00:00:00:00
11:11:11:11 11:11:11:11
22:22:22:22 33:33:33:33
44:44:44:44 44:44:44:44
55:55:55:55

Now, 22:22:22:22 and 55:55:55:55 is unique to dict one, and 33:33:33:33 is
unique to dict 2, does that make sense? Sorry for not explaining this stuff
very well, being so new to dicts its easy to get confused with my terms.

I then want to pass those keys as a string value into my function as an
argument, like.

thisFunction('22:22:22:22')
thisFunction('55:55:55:55')

thatFunction('33:33:33:33')

I'm hoping that your method will work for me, I've just got to spend my time
understanding what each step of it does.

Thanks again for all your help Tim,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Tim Golden
Sent: 30 April 2007 10:15
Cc: [email protected]
Subject: Re: Dict Copy & Compare

Robert Rawlins - Think Blue wrote:
> I have two dicts, one named 'this' and the other named 'that'.
> 
> I want to get all the unique keys from 'this' and log them into a file, I
> then want to take all the unique values from 'that' and log them into a
> separate file.

Couple of points which are confusing me:

1) Any dict can *only* have unique keys, ie you can't have
a key appearing more than once in a dictionary by
definition.

2) You speak of unique keys in "this" but unique values
in "that". Is that deliberate on your part? Might be, but
I'm not quite clear.

> I have functions set up for the logging, so I can call it like
> logThis(uniquekey) and logThat(uniquekey).

Here you refer to "uniquekey" in both cases, so maybe a
mistake above?

> So it's just a case of firstly returning a list of all keys that are in
> 'this' but NOT in 'that' and then visa versa, then loop over them
performing
> the function.

OK, well following by example earlier:


d1 = dict (a=1, b=2, c=3)
d2 = dict (b=4, c=5, d=6)

s1 = set (d1) # => set of 'a', 'b', 'c'
s2 = set (d2) # => set of 'b', 'c', 'd'

s1_not_in_s2 = s1 - s2 # => set of 'a'
s2_not_in_s1 = s2 - s1 # => set of 'd'

for key in s1_not_in_s2:
   print key, "=>", d1[key]

for key in s2_not_in_s1:
   print key, "=>", d2[key]



Obviously there are more concise ways of representing
this; I'm just spelling the whole thing out to make it
clearer (I hope). If this approach seems fruitful, have
a look at the set typeit's a recentish addition to
Python but very useful for this kind of thing:

   http://docs.python.org/lib/types-set.html

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

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


RE: Dict Copy & Compare

2007-04-30 Thread Robert Rawlins - Think Blue
Thanks for that Tim,

Don't feel guilty mate, I've learned a little something from you anyway,
whether its applied here or not.

On quick question, how can I order a dict by the 'values' (not keys) before
looping? Is that possible?

Thanks,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Tim Golden
Sent: 30 April 2007 11:27
Cc: [email protected]
Subject: Re: Dict Copy & Compare

Robert Rawlins - Think Blue wrote:
> Hello Tim,
> 
> Sorry, that 'value' was a slip up on my part, we're just dealing with keys
> here.
> 
> I get that a dict stores unique keys only but we're comparing the two
dicts,
> so when I say 'unique keys in dict 1' I basically mean all those keys that
> are in dict one but not in dict 2. So imagine my 2 dicts with the
following
> keys.
> 
> Dict 1Dict 2
> -----
> 00:00:00:00   00:00:00:00
> 11:11:11:11   11:11:11:11
> 22:22:22:22   33:33:33:33
> 44:44:44:44   44:44:44:44
> 55:55:55:55
> 
> Now, 22:22:22:22 and 55:55:55:55 is unique to dict one, and 33:33:33:33 is
> unique to dict 2, does that make sense? Sorry for not explaining this
stuff
> very well, being so new to dicts its easy to get confused with my terms.
> 
> I then want to pass those keys as a string value into my function as an
> argument, like.
> 
> thisFunction('22:22:22:22')
> thisFunction('55:55:55:55')
> 
> thatFunction('33:33:33:33')
> 
> I'm hoping that your method will work for me, I've just got to spend my
time
> understanding what each step of it does.

Well I feel a bit guilty now I look back at your
original post, because I've probably given
you a more complex solution than you really need. Your
initial approach is probably quite adequate. Python
dicts are highly tuned beasts so unless you're doing
something really big or bizarre, you can sensibly do:


d1 = {
   "00:00:00:00" : None,
   "11:11:11:11" : None,
   "22:22:22:22" : None,
   "44:44:44:44" : None,
   "55:55:55:55" : None
}

d2 = {
   "00:00:00:00" : None,
   "11:11:11:11" : None,
   "33:33:33:33" : None,
   "44:44:44:44" : None
}

for k in d1:
   if d1 not in d2:
 thisFunction (d1)

for k in d2
   if d2 not in d1:
thatFunction (k)



But even if this is adequate for your purposes,
it's always good to be aware of what's in your
programming toolbox and there's always the danger
you'll end up implementing sets in dicts (which
is what everyone did before Python 2.3).

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

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


RE: Dict Copy & Compare

2007-04-30 Thread Robert Rawlins - Think Blue
No that makes sense Tim,

Thanks again for all your help on this one, it'll all prove invaluable I'm
sure. I managed to crack all the big troubles last week with my reoccurring
tasks, it's just a case of tidying up a few of these loose ends, then
that'll be python project no.1 over and done with :-D

Thanks,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Tim Golden
Sent: 30 April 2007 12:54
Cc: [email protected]
Subject: Re: Dict Copy & Compare

Robert Rawlins - Think Blue wrote:
> On[e] quick question, how can I order a dict by 
 > the 'values' (not keys) before looping? Is that possible?

Depends on what you want to do. You can loop on
the sorted values very easily:


d1 = dict (a=2, b=1)
for value in sorted (d1.values):
   print value



but inferring the equivalent key is, in effect,
not possible since more than one key might correspond
to that value. Depending on what you're after, the
following technique might be of use:


import operator

d = dict (a=2, b=1, c=-1, d=4)
for k, v in sorted (
   d.items (),
   key=operator.itemgetter (1)
):
   print k, "=>", v



It may look a bit hairy, but break it down:

d.items () returns a list of 2-tuples, each one
corresponding to a key-value pair from the dict.
In our case, that'll be:

[('a', 2), ('b', 1), ('c', -1), ('d', 4)]

Although I've written them out like that,
the order they'll come in is undefined.

sorted () will return a sorted version of
whatever iterable you chuck at it. Under
normal Python semantics, sorted() on the
list above will return no change since I've
listed things out in alphanumeric order.

The extra key= parameter tells the sorted
routine to call the function you provide
against each of the items in the list (in
our case that means against each of the
2-tuples) and using the result of that
function as the sorting order.

The operation.itemgetter (1) bit is a touch
complicated unless you're already familiar with
partial functions, but it basically returns
*another* function which takes the item you
give it and returns the -- in this case --
1st item. Just believe me: it works.

So, in summary:

+ Get a list of key-value pairs
+ Sort them according to the 1st item (Python-style)
which in this case is the value.
+ Do something with the result

Before the key= param was introduced into
sort/sorted, people used to do the same thing
with what's often called DSU (short for
decorate-sort-undecorate), a technique which
here would look something like this:

items = d.items ()
sortable_items = [(i[1], i) for i in items]
sortable_items.sort ()
sorted_items = [i[-1] for i in sortable_items]

I mention this because (a) you still see it around
a fair bit and (b) there are occasions where it's
still useful, for example where a simple function
call can't really cope.

(Did I answer the question, or was I just rambling?)

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

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


Killing Threads

2007-05-01 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I've got an application which I've fearfully placed a couple of threads into
however when these threads are running it seems as if I try and quite the
application from the bash prompt it just seems to freeze the SSH client.
I've also seen that if I have my app running in the background on the system
then my 'reboot' no longer works, it just hangs after saying it's going to
shut down.

 

Is there anything specific i should be doing to kill my threads?

 

Thanks,

 

Rob

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

RE: test

2007-05-01 Thread Robert Rawlins - Think Blue
Test response :-D

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Ray
Sent: 02 May 2007 04:05
To: [email protected]
Subject: test

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

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


Dynamic File Name Open()

2007-05-01 Thread Robert Rawlins - Think Blue
Chaps,

 

I'm trying to open a file using open() but the name of the file is created
dynamically as a variable, but also has part of a static path. For instance,
the file may be called 'dave' and will always be in '/my/files/here/'.

 

Now I've tried a few combinations of getting this to work, such as.

 

Path = '/my/files/here/%s' % (name)

 

Open(Path, 'r')

 

But that does work, can anyone enlighten me on the best way to do this?

 

Thanks,

 

Rob

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

RE: Killing Threads

2007-05-02 Thread Robert Rawlins - Think Blue
Thanks for this Diez and Tim,

I'll take a look into this today, sorry for not posting any code fragments,
its not so much a fragment as it is a bloody great big monster :-D

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Diez B. Roggisch
Sent: 02 May 2007 09:05
To: [email protected]
Subject: Re: Killing Threads

> You probably need to setDaemon (True) on your threads
> after you've created them and before they run. That
> tells the OS: don't bother waiting for these ones to
> finish if the program exits. (At least I think that's
> what it does; I don't use threads all that much)

Actually all it does is to tell the at_exit-handler that it's ok to 
terminate even though there are still some threads. The OS isn't 
concerned with this.

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

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


Spotting Crashed Application

2007-05-09 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I've got an application that I've written, and it sits in an embedded
system, from time to time the application will crash, I'm not quite sure
what's causing this, but as we test it more and more we'll grasp a better
understanding and fix the issues.

 

However, until then I need a quick solution which can spot the crash and
reboot the system. Is there any generic way of writing a separate
application that'll spot the crash in my main application? If not then i was
thinking about having my core application log itself as 'alive' every 5
minutes or so. My new 'spotter' application can check this log, if it's not
been written too in say 6 minutes then the main app must have crashed, and
it can reboot.

 

Any suggestions on how best to handle this? Obviously finding the bug in my
main app is paramount, but a failsafe will never hurt.

 

Thanks again guys,

 

Rob

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

Code Explanation

2007-05-17 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm currently working on a non-python project, and I'm trying to overcome a
task of parsing a text file into a database and/or xml file. I've managed to
find a parser example written in python, and I'm hoping to deconstruct the
code methodology a bit so I can write it in another language. So I'm hoping
someone can explain to me what these following bits of code are doing.

 

lines = range(data.count("\n"))

lined_data = data.split("\n")

print "Read %i vendors, now processing" % data.count("(hex)")

 

I've not used the split() function before, but it partly makes sense to me.
What is that piece of code doing? 'Data' is the content of the text file,
presumably the first line there is counting the number of lines in the file,
but I don't get the rest of it.

 

The rest of the code seems like a relatively simple set of loops, but it's
just this splitting stuff that's got me confused.

 

Thanks,

 

Rob

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

App Leaving 'sh ' Everywhere

2007-05-18 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I've got an application that seems to leave 'sh ' in my os
processes list. I'm running it on Debian, albeit a stripped down embedded
version. I'm not sure what the cause of this is, My application starts
several threads and also uses popen2.popen3() to run a few CMD commands.

 

Any ideas why I'm getting this, or if it's even something to be concerned
about.

 

Thanks,

 

Rob

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

SOAPpy My Class

2007-05-21 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I've used SOAPpy in its very basic form for consuming web services on my web
server, but I'm now looking to publish a web service from my application.
Basically I'm looking to create a public 'proxy' of an object I have in the
application. The idea being that my application will be able to use the
instance of the object, and other applications will also be able to access
this same object, using the web service.

 

I've got my object built, and it has a few basic functions inside of it,
most of them just serving as wrappers for other simple python functions,
working on dicts and lists. What's the best way to go about publishing a web
service that calls on that instance?

 

I've done simple publishing of services in a standard script before, but
I've not worked on this idea of publishing a public facade for an existing
class.

 

Thanks,

 

Rob

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

Restart Linux System

2007-05-22 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm looking to restart a Linux system from my python application. What's the
best way to achieve this, is there something in the OS module?

 

Thanks,

 

Rob

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

Shared Memory Space - Accross Apps & Network

2007-05-22 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I've got an application that runs on an embedded system, the application
uses a whole bunch or dicts and other data types to store state and other
important information.

 

I'm looking to build a small network of these embedded systems, and I'd love
to have them all share the same set or data. Is it possible to share the
applications variables across multiple applications, so certain lists are
like a 'pool' written to by the different systems? I'm sure I could cobble
something together by writing the lists to shared files instead of keeping
them in RAM, but that feels a little inefficient. I'd like to try and
configure some form of master/slave relationship between my applications if
possible.

 

Thanks for any ideas you guys might have.

 

Rob

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

File Handling & TRY/EXCEPT

2007-08-03 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm looking for some advice on how best to handle file read/write errors
with try/except as i'm a little vague on this, I have a small memory leak in
my app and I'm starting to think its generated by my log file write. For an
example of the function look below.

 

   def addAppLog(self, event):

  try:

 logfile = open('/pblue/new/Logs/Application.csv','a')

 

 now = datetime.datetime.now()

 

 logstring = '%s,%s \n' % (event, str(now))

 

 logfile.write(logstring)

  except:

 self.addAppLog(event)

  else:

 logfile.close()

 

Now I'm looking for some help to sort this out as I'm sure it's pretty
untidy, I want to make it as air tight as possible. The basic concept was
that if it tries writing to the log file and it fails, then it needs to
reattempt it, right?

 

What's the best way to handle this to ensure that there are not any memory
leaks caused when the file is open() but not followed by a close(). I'm
running 2.4 and I know some of these newer versions don't need you to
explicitly close() the file objects, but I would certainly feel a lot
better.

 

Any advice?

 

Thanks guys,

 

Rob

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

RE: File Handling & TRY/EXCEPT

2007-08-03 Thread Robert Rawlins - Think Blue
Thanks for your ideas guys,

I'm unfortunately tied to 2.4 so don't have the full try except status, but
I'm now working with the following code:

def addApp(self, event):
try:
logfile =
open('/pblue/new/Logs/Application.csv','a')

now = datetime.datetime.now()
logstring = '%s,%s \n' % (event, str(now))

try:
logfile.write(logstring)
finally:
logfile.close()
except:
self.addApp(event)

I'm trying to slowly debug my app and get rid of all the memory leaks, but
its pain staking work, any help you can offer on that stuff would be a god
send, I'm a little reluctant about posting all my app code on the lists as
I'd like to keep some of it private.

How does that new version look? A little tidier?

Thanks guys,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Steve Holden
Sent: 03 August 2007 14:20
To: [email protected]
Subject: Re: File Handling & TRY/EXCEPT

Robert Rawlins - Think Blue wrote:
> Hello Guys,
> 
>  
> 
> I'm looking for some advice on how best to handle file read/write errors 
> with try/except as i'm a little vague on this, I have a small memory 
> leak in my app and I'm starting to think its generated by my log file 
> write. For an example of the function look below.
> 
>  
> 
>def addAppLog(self, event):
>   try:
>  logfile = open('/pblue/new/Logs/Application.csv','a')
>  now = datetime.datetime.now()
>  logstring = '%s,%s \n' % (event, str(now))
>  logfile.write(logstring)
>   except:
>  self.addAppLog(event)
> 
It seems somewhat perverse, when the logging code raises an exception, 
to recursively log - presumably the same exception will be raised again?

>   else:
> 
>  logfile.close()
> 
Remember that in 2.5 you can use try ... except ... finally

> 
> Now I'm looking for some help to sort this out as I'm sure it's pretty 
> untidy, I want to make it as air tight as possible. The basic concept 
> was that if it tries writing to the log file and it fails, then it needs 
> to reattempt it, right?
> 
Wrong. The one thing you can't log is a logging attempt error!
>  
> 
> What's the best way to handle this to ensure that there are not any 
> memory leaks caused when the file is open() but not followed by a 
> close(). I'm running 2.4 and I know some of these newer versions don't 
> need you to explicitly close() the file objects, but I would certainly 
> feel a lot better.
> 
>  
> 
> Any advice?
> 
This is just a quick on-the-fly look at what you did, I am sure you will 
receive other,  probably more helpful, comments.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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

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


RE: Replacing _xmlplus.dom.minidom with xml.dom.minidom

2007-08-03 Thread Robert Rawlins - Think Blue
Just as a heads up, minidom is pretty inefficient and difficult to work with
too.

On someone else's advice I switched over to ElementTree and have been really
pleased with the results, its much simpler to work with and more efficient
too.

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: 03 August 2007 14:39
To: [email protected]
Subject: Replacing _xmlplus.dom.minidom with xml.dom.minidom

Hi,

I'm working with a number of scripts which were written years ago for
my company for Python 2.2, and I'd like to update for Python 2.5. I
have written a script to add # -*- coding: cp1252 -*- to the beginning
of all my scripts, and that has fixed the encoding issues.

Another issue was the use of -

from _xmlplus.dom import minidom

http://sourceforge.net/project/showfiles.php?group_id=6473

I couldn't get a version of this module for  2.5, so I changed the
above to -

from xml.dom import minidom

The scripts I work with are all working now correctly for 2.5. But I
haven't been able to test the whole system as not all of it concerns
me. Anyway, my colleges are interested in updating also if it will be
reasonably hassle free.

So my main concern now is the use of  _xmlplus.dom.minidom. Why was it
used and what differences should  I look out for with regard to
xml.dom.mididom

Thanks very much for your help,

Barry.

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

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


Devloper Wanted For Debugging / Optimizing

2007-08-03 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I've been writing (with your help) a small application over the past couple
of months but I'm really struggling to iron out all of the creases and its
seems to spring a few memory leaks that I'm unable to find and plug. It's
only a small app, around 500 lines of code I would guess, aside from the
usual python type things it deals with dbus and XML parsing using element
tree, But it's for an embedded Linux platform so keeping it lightweight and
memory leak free is an absolute must.

 

Is anyone interested to take this small project on to have a look at my
code? Perhaps give me a little bit of advice on where I'm going wrong?

 

I would be willing to pay someone for their much needed time to get the
final few creases ironed out, this isn't really stuff we can deal with on
the boards so something private is a must, hence I'm exploring the idea of a
paid contract.

 

If anyone is interested then please feel free to contact me off list.

 

Thanks again guys,

 

Rob

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

Launching App

2007-08-09 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm looking for the best method to launch my python app when my Linux system
boots up. At the moment I just have an entry like this in my rc.local file:

 

CD /myfolder/anotherfolder

./myapp.py

 

Is this the best way to do this? Or is there a better way? I feel like a bit
of a dummy asking this question, I just wanted to ensure the best method.

 

Thanks guys,

 

Rob

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

SOAP Webservices and Python

2007-04-11 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I'm pretty new to the world of Python, but I'm slowly getting my head around
things, and on today's agenda I'm looking at consuming SOAP web services.
I've got an Adobe ColdFusion application which I've written that publishes
the web service that I'm looking to consume, but I'm at a loss as to where
to start. I'm running Python 2.4.4 on a Debian Linux distribution, in case
that makes any difference.

 

I thought I'd start with something very simple, just a service I pass an ID
to and it'll return a Boolean value. Here is the web service link.

 

http://www.yourblue.co.uk/webservicetester/ip.cfc?wsdl

 

I'd be interested to hear any thoughts on the best way to go about this, or
perhaps some working code examples of consuming this service. I will always
have the WSDL file available to me by appending the ?wsdl to the URL, I've
heard this makes life easier. 

 

 like I say, I'm pretty new so it's perfectly ok for you guys to assume I'm
an idiot and talk to me as if I were a small child :-D

 

Thanks,

 

Rob

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

Writing XML Logs

2007-04-11 Thread Robert Rawlins - Think Blue
Hello Chaps,

 

I'm trying to write an application that will log to an XML file, that'll be
later parsed by another application. The proposed log file will look
something like this, listing different event elements and then a record for
each time that event occurs.

 



































































 

What I would really like to do is have a different function for each event,
so logReboot() or something like that which can be called when the
application starts, and it'll create and entry with the current date and
time. This must be a static file that is on the box, allot of the examples
I've seen seem to work using the 'print' function which is a little sketchy
as outputting to the screen isn't any use to me, this needs to be a file
that can be collected by another application.

 

Can anyone offer any advice on how best to get started with this kind of
thing? I'm running python 2.4.4 but when I've tried running any examples
with SAX involved they seem to say 'no module found: sax" or something to
that effect, I was under the impression that sax came bundled with python
2.0 and above?

 

Thanks guys,

 

Rob

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

SOAPPY Install Issues

2007-04-11 Thread Robert Rawlins - Think Blue
Hi Guys,

 

I've been trying hopelessly -ALL- afternoon to get python-xml and
python-soappy working nicely, but for the -LIFE- of me I keep running into
the same brick wall over and over.

 

I'm running Debian and I've installed the latest stable builds of Python,
Python-XML and Python-SOAPPY along with all there depensancies but i get the
following error when trying to run my code.

 

Traceback (most recent call last):

  File "xml.py", line 1, in ?

from SOAPpy import SOAPProxy

  File "/var/lib/python-support/python2.4/SOAPpy/__init__.py", line 5, in ?

from Client  import *

  File "/var/lib/python-support/python2.4/SOAPpy/Client.py", line 57, in ?

from Parser  import parseSOAPRPC

  File "/var/lib/python-support/python2.4/SOAPpy/Parser.py", line 9, in ?

import xml.sax

  File "/pblue/xml.py", line 1, in ?

from SOAPpy import SOAPProxy

ImportError: cannot import name SOAPProxy

 

This is my Code:

 

from SOAPpy import SOAPProxy

url = 'http://services.xmethods.net:80/soap/servlet/rpcrouter'

namespace = 'urn:xmethods-Temperature'  

server = SOAPProxy(url, namespace)  

server.getTemp('27502')

 

It's a very simple program, and its driving me bonkers not being able to get
it working, I'd appreciate any help you can offer to help resolve it.

 

Thanks guys, I'm sure this is just a typical NOOB mistake, but hopefully
once the damn thing is up and running it'll be clear sailing.

 

Rob

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

Binary To File

2007-04-12 Thread Robert Rawlins - Think Blue
Hello Guys,

 

Is there an easy way to take binary data and build it into a file? Generally
this will be BLOB data drawn from a database, the data will be for jpg
images, I want to take the blob data and build it into a physical .jpg file.

 

Is there a simple function for doing this in python? Like binary2file() or
something along those lines?

 

Thanks,

 

Rob

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

Arrays, Got Me Confused

2007-04-13 Thread Robert Rawlins - Think Blue
Hello Guys,

 

I'm struggling to get my head into arrays in python, I've used them plenty
in other languages but I'm struggling to find any decent documentation for
them in python. I'm looking to build a list of network MAC address's into an
array, which will probably be used for logging and firewalling and things.

 

I've build the basic class, the idea is that the class represents the
firewall, and I have functions for the firewall like addDevice() and
isFirewalled() where I pass in the address and it returns a value or updates
the array. However I'm getting an error when trying to create an empty array
on the init.

 

#!/usr/bin/python

# Filename: Firewall.py

 

class Firewall:

 

   def __init__(self):

  Self.FireArray = array(c)

 

p = Firewall()

print p

 

 

Throws:

 

Traceback (most recent call last):

  File "./firewall.py", line 9, in ?

p = Firewall()

  File "./firewall.py", line 7, in __init__

Self.FireArray = array(c)

NameError: global name 'array' is not defined

 

How can I solve this problem? From what I've seen writing I can't see
anything wrong with my syntax, perhaps you can shed some light on the
situation. Whilst I'm writing there is also another question I would like to
pose briefly. How do a create an object from an external file? Obviously in
my one above all I need do is call Firewall() and it creates an instance,
but I'm used to creating my class's as separate files, how do I create them
as an object in my main application?

 

Thanks,

 

Rob

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

RE: Arrays, Got Me Confused

2007-04-13 Thread Robert Rawlins - Think Blue
Hello Guys,

Wider fragments of code don't really exists at this moment in time :-D this
is just a bit of a 'tester' class for me to get used to the methods.
Basically I'm trying to create a class that contains an array of MAC
address, these look something like this 'FD:E4:55:00:FG:A9. I want the class
to have the following methods for easy manipulation of the array.

addDevice(Address) - Pass in the MAC address and have it add it to the
array.

removeDevice(Address) - Finds a device with that address in the array and
removes it.

isFirewalled(Address) - looks for that address in the array and returns
true/false dependant on whether it finds it.

Clear() - empty the array of all its contents.

Sorry for the sloppy code so far, I'm really new to Python so it's a steep
learning curve for me, I'm by no means a programming numpty and allot of the
principles are the same, but the languages I'm used to are more robust and
vague so I don't have to define what type of data i'm storing the array and
things.

Thanks guys,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Tim Golden
Sent: 13 April 2007 13:27
Cc: [EMAIL PROTECTED]
Subject: Re: Arrays, Got Me Confused

Michael Bentley wrote:
> 
> On Apr 13, 2007, at 7:04 AM, Robert Rawlins - Think Blue wrote:
>> #!/usr/bin/python
>>
>> # Filename: Firewall.py
>> class Firewall:
>>def __init__(self):
>>
>>   Self.FireArray = array(c)
>>
>> p = Firewall()
>>
>> print p
>> Throws:
>>
>>
>>
>> Traceback (most recent call last):
>>
>>   File "./firewall.py", line 9, in ?
>>
>> p = Firewall()
>>
>>   File "./firewall.py", line 7, in __init__
>>
>> Self.FireArray = array(c)
>>
>> NameError: global name 'array' is not defined
>>
>>
>>
>> How can I solve this problem?
> from array import array

Well, also the line referencing "Self.FireArray"
is not going to work, unless there's
some global "Self" knocking around. Python is
case-sensitive.

More importantly, I suspect, is that the OP's
almost certainly looking for a Python *list*,
not an array in this case. It's hard to tell,
since we've no idea what's in the "c" which
is being passed to the array.

Robert - can you explain what you're trying to
do and/or post a wider fragment of code?

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

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


RE: Arrays, Got Me Confused

2007-04-13 Thread Robert Rawlins - Think Blue
Thanks for that Tim and Steve, greatly appreciated.

I know that the class method is just a wrapper and it seems a little silly,
but it is partly for the exercise. I'm pretty well savvy with the OOP stuff
but its something my business partner is yet to venture into, so by working
like this it helps him understand the concepts. I also feel more at home if
i can wrap this stuff up in nice user friendly methods that I can access
universally throughout the application.

I will have plenty of other class's and methods throughout the application
that will call upon this firewall stuff, and being able to universally
reference it as Firewall.addDevice() makes things more logical in my mind, I
find trying to go back to a more procedural method pretty tricky now.

Thanks again guys,

Rob

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Tim Golden
Sent: 13 April 2007 14:03
Cc: [EMAIL PROTECTED]
Subject: Re: Arrays, Got Me Confused

Robert Rawlins - Think Blue wrote:
> Hello Guys,
> 
> Wider fragments of code don't really exists at this moment in time :-D
this
> is just a bit of a 'tester' class for me to get used to the methods.
> Basically I'm trying to create a class that contains an array of MAC
> address, these look something like this 'FD:E4:55:00:FG:A9. I want the
class
> to have the following methods for easy manipulation of the array.
> 
> addDevice(Address) - Pass in the MAC address and have it add it to the
> array.
> 
> removeDevice(Address) - Finds a device with that address in the array and
> removes it.
> 
> isFirewalled(Address) - looks for that address in the array and returns
> true/false dependant on whether it finds it.
> 
> Clear() - empty the array of all its contents.

OK, it's easy enough to do this, but you might find
that you don't actually need to do too much of it
yourself. Python has two central datastructures
built in: lists and dictionaries. There are loads
of tutorials around (and if you join the python-tutor
list, the welcome message points you towards several)
so I won't go into the details, but it looks like
you want a dict here.

You could wrap it in a class if you wanted, but
the great thing about Python is that you don't
have to. *Very* rough example code:


macs = {} # create an empty dict

incoming_mac = 'FD:E4:55:00:FG:A9'
macs[incoming_mac] = True

example_mac = 'a:b:c:d'
if example_mac in macs:
   mac_is_firewalled = macs[example_mac]



If you really wanted to go with a class (for the exercise
or because of wider requirements) you could do something
like this:


class Firewalled:
   def __init__ (self):
 self.macs = {}

   def addDevice (address):
 self.macs[address] = True

   def removeDevice (address):
 del self.macs[address]

   def isFirewalled (address):
 return address in self.macs
 # or return self.macs.get (address, False)


but as you can see, in this form you're just wrapping
Python with Python.

> Sorry for the sloppy code so far, I'm really new to Python so it's a steep
> learning curve for me, I'm by no means a programming numpty and allot of
the
> principles are the same, but the languages I'm used to are more robust and
> vague so I don't have to define what type of data i'm storing the array
and
> things.

Ummm... in Python you don't have to define what type of
data you're storing. Welcome to the language in any case:
you'll find that people around here are generally quite
friendly but if you want, you might try the tutor list
where people are very used to dealing with newcomers:

http://mail.python.org/mailman/listinfo/tutor

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

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


Class Dependancy Injection

2007-04-13 Thread Robert Rawlins - Think Blue
Hey again guys,

 

I'm looking to get an answer about dependency injection in python classes,
what is the best way to deal with this?

 

For instance, in my application I have a configuration bean which contains
all the applications configuration information. Now in one of other classes
I need access to those configuration settings. What I would have done in my
ColdFusion/JAVA type applications is create an instance of the configuration
bean, and then pass that in as an argument to the constructor for my other
class, then have the other class set that as a 'self' variable. Then from
within my class I can access the configuration details like
self.config.getName() and it would return the name of the application.

 

How is this best handled in python, can I still inject dependencies as a
constructor argument like that? If so then is there anything in particular I
need to watch out for that may cause me trouble?

 

Thanks,

 

Rob

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

  1   2   >