pexpect problem, spawn says I/O on closed file

2005-04-15 Thread edwin

Hi,

I'm using pexpect in a plugin script within bartbot (an python based irc
bot). When I execute the plugin, python comes back with:

ERROR exceptions.ValueError file:
/home/edwin/devel/bartbot/myplugins/rttest.py linenr: 17 msg: I/O \
operation on closed file

rttest.py being the plugin script, line 17 being:
child = spawn("ssh -l %s %s /bin/ls -l"%(user, host))

before i paste the whole script here, does anybody have any "ah, that's
simple, check..."'s? ;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming exercises/challenges

2008-12-08 Thread Edwin
On Nov 22, 2:15 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> I'm only a very occasional user of vi, so I don't really know how vim
> integrates with MacOS X but have you tried aquamacs
> (http://aquamacs.org/)?
>
> --
> Arnaud

I've tried it but I ended up using original (I'm sure there's a better
adjective) Emacs compiled --with-ns... it's very nice (at least for
what I do, in the little experience I've gained).

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


Snippets management

2008-11-05 Thread Edwin
Hi there,

I've been looking for a snippet manager and found PySnippet but it
requires PyGTK. Do you know any other option that doesn't need much? 

I'm sort of new to python and user interfaces seem a bit far for me
right now, that's why I thought having to install PyGTK was
unnecessary.

Would you recommend installing it anyway? 

I'm on a Mac, maybe some users of Steve's Unix flavour know about a
snippets software piece? I'm looking for free/open source alternatives.

Thank you!

P.S.: I'm also new to usenet ;) and hope my english is not that bad.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Snippets management

2008-11-06 Thread Edwin
Robert Lehmann <[EMAIL PROTECTED]> writes:

> On Wed, 05 Nov 2008 19:55:51 -0600, Edwin wrote:
>
>> Hi there,
>> 
>> I've been looking for a snippet manager and found PySnippet but it
>> requires PyGTK. Do you know any other option that doesn't need much?
> [snip]
>
> If you're looking for a snippet manager for actually *using* it (not 
> educational purposes or something), I'd recommend your favorite editor 
> and the version control system of your choice. I found DVCSes to be 
> rather nice for local ad-hoc repositories (particulary Git_). If you'd 
> like to modify your snippet system you could take a look at Mercurial or 
> Bazaar, both being written in Python.
>
> HTH,
>
> .. _Git: http://git.or.cz/

That sounds interesting. As I'm learning Python sometimes I look for
different approaches to the same problem so I use Git branches in order
to save every try. It's just that I'm looking for a 'global' place in my
system where I can save code ideas and useful snippets not particular to
any project. Quick access could be useful for some copy/paste
operations... I don't know. 

How would you set this up? A git folder 'snippets' maybe?

Thanks for your ideas.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Snippets management

2008-11-07 Thread Edwin
On Nov 7, 6:36 pm, Ricardo Aráoz <[EMAIL PROTECTED]> wrote:
>
> Since you are in Linux you should definitely check "Basket". Go to it's
> website and you'll be hooked, just what you need.

Actually I use Mac OS and Free BSD but I'll check it out mate.
Thanks for the tip!!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Snippets management

2008-11-07 Thread Edwin
On Nov 7, 5:38 pm, Stef Mientki <[EMAIL PROTECTED]> wrote:

> I've to extract the right libs from the larger program,
> as I'm in an import crisis right now,
> it may take a couple of days.
> If it's not here by the end of next week,
> mail be directly, because I forget a lot :-)
>
> cheers,
> Stef
>
> > Cheers!
> > --
> >http://mail.python.org/mailman/listinfo/python-list

Take your time mate. Thank you in advance.
In the meantime. I'm going to check BasKet as Ricardo recommended.
I'm also starting some sketches to make my own, ala Python. I don't
know how much will it take me but if anyone is interested I can send
you a message as soon as I've got something working.

Cheers,

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


Re: Snippets management

2008-11-11 Thread Edwin
On Nov 10, 3:14 pm, Stef Mientki <[EMAIL PROTECTED]> wrote:
> expora wrote:
> > On Nov 6, 12:38 pm, Stef Mientki <[EMAIL PROTECTED]> wrote:
>
> >> Edwin wrote:
>
> >>> Hi there,
>
> >>> I've been looking for a snippet manager and found PySnippet but it
> >>> requires PyGTK. Do you know any other option that doesn't need much?
>
> >>> I'm sort of new to python and user interfaces seem a bit far for me
> >>> right now, that's why I thought having to install PyGTK was
> >>> unnecessary.
>
> >>> Would you recommend installing it anyway?
>
> >>> I'm on a Mac, maybe some users of Steve's Unix flavour know about a
> >>> snippets software piece? I'm looking for free/open source alternatives.
>
> >>> Thank you!
>
> >>> P.S.: I'm also new to usenet ;) and hope my english is not that bad.
> >>> --
> >>>http://mail.python.org/mailman/listinfo/python-list
>
> >> I developed one in wxPython, you can see some of the features here.
> >>  http://mientki.ruhosting.nl/data_www/pylab_works/pw_code_editor.html
>
> >> Although it's part of a larger part it can be used standalone,
> >> but then it requires two actions copy and paste.
> >> Started from a python application you can do copy+paste with just one
> >> action.
> >> It has integrated a full blown scintilla editor,
> >> with syntax highlighting, code completion, and syntax checker.
>
> >> If there's interest, I can distribute the files as a separate package.
>
> >> cheers,
> >> Stef Mientki
>
> > Wicked!
> > I'm going to check it out Stef.
>
> > Is the source available? It's all about learning for me right now.
>
> source can now be found here:
>  http://pylab-works.googlecode.com/files/Test_Scintilla_Templates.zip
>
> cheers,
> Stef

How great!
Thanks for sharing mate! Downloading...

Cheers,
E.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming exercises/challenges

2008-11-19 Thread Edwin
On Nov 18, 6:39 pm, [EMAIL PROTECTED] wrote:
> Hi guys,
>
> I'm learning Python by teaching myself, and after going through several
> tutorials I feel like I've learned the basics. Since I'm not taking a
> class or anything, I've been doing challenges/programs to reinforce the
> material and improve my skills. I started out with stuff like "Guess my
> number" games, hangman, etc. and moved on to making poker and card
> games to work with classes. For GUIs I created games like minesweeper,
> and a GUI stock portfolio tracker. I am out of ideas and am looking 
> forprogrammingprojects, challenges, or programs that have helped you'll
> learn. I'm working on the project Euler problems, but I find that they
> don't really help myprogrammingskills; they are more math focused.
> Suggestions? What has been useful or interesting to you? I'd also
> welcome sources of textbook type problems, because the ones provided in
> tutorials tend to be repetitive.
>
> Thanks,
> Ben

I'm also learning Python by myself, downloading open ebooks, reading
tutorials, reading other people's code, etc. and in order to put my
knowledge into practice I've been writing small programs to solve my
everyday computer problems: a simple email client (because sometimes
it seems to me that email clients now have so many features and
preferences) that reads my fetchmailrc, a diary manager compatible
with my Emacs diary file (sometimes I don't want to open Emacs for a
quick note)... in general I try to solve problems related to my own
workflow.

I also try to play with some of my girlfriend's ideas on computer use:
she came up with an idea for a calculator with which she could easily
keep track of our bills (but found financial software a bit
complicated for simple tasks, once again, too many features and
preferences) so I started to code a small multi-touch app as
"intuitive" as possible (and still working on it).

What I'm saying is that I've found useful not to think about
programming itself but just think of it as a medium to solve my own
(common) problems.

Best regards,
E.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming exercises/challenges

2008-11-20 Thread Edwin
On Nov 20, 12:39 am, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> Edwin <[EMAIL PROTECTED]> writes:
>
> [...]
>
> > a diary manager compatible with my Emacs diary file (sometimes I don't
> > want to open Emacs for a quick note)
>
> You mean that you sometimes don't have emacs open?
>
> --
> Arnaud

heh... I believe in the potpourri style mate (and I don't mean petals
and spices).
After all I'm no expert.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming exercises/challenges

2008-11-20 Thread Edwin
On Nov 20, 6:28 am, [EMAIL PROTECTED] wrote:
>     >> a diary manager compatible with my Emacs diary file (sometimes I
>     >> don't want to open Emacs for a quick note)
>
>     Arnaud> You mean that you sometimes don't have emacs open?
>
> I am constantly amazed at work that people open a separate emacs for each
> file they want to edit.  Most of them seem not to even know that find-file
> exists.
>
> Skip

Come on mate... it's already a bit hard to post in a non-native
language. As a beginner in Python it's just "my two pennies worth",
really.

Cheers,
E.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Programming exercises/challenges

2008-11-21 Thread Edwin
On Nov 20, 10:32 pm, [EMAIL PROTECTED] wrote:
>     >> I am constantly amazed at work that people open a separate emacs for
>     >> each file they want to edit.  Most of them seem not to even know that
>     >> find-file exists.
>
>     Edwin> Come on mate... it's already a bit hard to post in a non-native
>     Edwin> language. As a beginner in Python it's just "my two pennies
>     Edwin> worth", really.
>
> No knock on you at all, just an observation about the work patterns many of
> my colleagues have.  The people I work with are professional software
> engineers, engineers, quantitative analysts, etc.  Many not at all new to
> Python, C++, Unix or Emacs.  And it's not like I haven't shown them how to
> do it.  I showed one guy how to exchange two adjacent words today with M-t.
> He about fell off his chair.
>
> Come to think of it, the one other person I work with who always keeps an
> Emacs open is a vi user who likes it for sql mode.  Nothing else.  He runs
> viper mode and keeps an sql mode buffer open continuously with all his
> little sql snippets ready to submit to our Sybase server.  When he uses vim
> to edit?  One vim session per file.  I'm pretty sure that vim allows you to
> open multiple files at once as well.  Go figure.
>
> Skip

No worries. I actually agree. I've found myself in situations like the
ones you describe, finding new commands and realizing there's more to
it than I thought. I have to point out that I myself use Vim more than
Emacs. Not because I think it's better (I'm not a religious person)
but because it has better integration with my Mac... and actually, I
use them for different programming tasks.

As a newcomer to Unix (I've come from Web related fields) I've been
learning not only how to use the operating system, but also Python,
Emacs, Vim, bash, etc. This hasn't been easy, of course, but it has
been quite interesting and as I'm learning a specific topic (say
learning readline commands, how to access command history, etc.) I
don't always keep my editor open; sometimes I want to learn how an
editor does its stuff and then I 'hack' a script for manipulating a
relevant text file (like my diary).

I know you can run your favorite shell inside Emacs and learn from
there, but being the only computer at home (and not the fastest) I
don't want to be opening programs all the time (maybe my girlfriend
has several programs running) so being able to write some beginners'
scripts to solve common tasks has been a good learning experience for
me.

Greetings from the third world (or is it underdeveloped? ;))
E.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Parsing] How do I process loops with PLY?

2004-12-26 Thread Edwin Young
"F. GEIGER" <[EMAIL PROTECTED]> writes:

> But when loops enter the game, things seem to become more difficult:
> 
> A=12
> B=23
> C=45
> D=56
> DX=0
> 
> FOR C # Exec the following lines C times
>G X=A+DX Y=B Z=34 # Move to X, Y, Z
> 
># more statements...
> 
>DX=DX+67
> NEXT
> 
> How can I tell PLY to go back to the beginning of the FOR-loop's
> body to execute it C-1 more times? A syntax checker would not need
> to do that, but an interpreter (which actually I am building) has
> to.

Typically, you would separate parsing from executing the code. Use PLY
to parse the whole thing once and produce a data structure
representing the code (usually called an 'abstract syntax tree') then
write an interpreter which uses that tree as its input.

Regards,
--
Edwin
-- 
http://mail.python.org/mailman/listinfo/python-list


Calling a thread asynchronously with a callback

2006-11-27 Thread Edwin Gomez
I'm a C# developer and I'm new to Python.  I would like to know if the concept 
of Asynchronous call-backs exists in Python.  Basically what I mean is that I 
dispatch a thread and when the thread completes it invokes a method from the 
calling thread.  Sort event driven concept with threads.


Thanks. 

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


Re: Python-list Digest, Vol 38, Issue 390

2006-11-27 Thread Edwin Gomez
Regarding Topic number 3: 3. Calling a thread asynchronously with a callback 
(Edwin Gomez):
Thanks Bjorn for you quick answer and by the way, that works.  Diez, in answer 
to your question regarding async callbacks in C#; C# runs in a multi threaded 
apartments.  Many times we'll setup listener objects in a dictionary and each 
member is responsible for monitoring and manipulating it's own data.  In the 
case where data is shared, then of course, we use a locking machanism.
> - Original Message -
> From: [EMAIL PROTECTED]
> To: python-list@python.org
> Subject: Python-list Digest, Vol 38, Issue 390
> Date: Mon, 27 Nov 2006 19:45:03 +0100
> 
> 
> Send Python-list mailing list submissions to
>   python-list@python.org
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/python-list
> or, via email, send a message with subject or body 'help' to
>   [EMAIL PROTECTED]
> 
> You can reach the person managing the list at
>   [EMAIL PROTECTED]
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-list digest..."
> 
> Today's Topics:
> 
> 1. Re: Several entries on Tile and TableList at the Tkinter wiki
>(jim-on-linux)
> 2. shtoom complicated install (Croteam)
> 3. Calling a thread asynchronously with a callback (Edwin Gomez)
> 4. Re: Active State and Komodo... (Trent Mick)
> 5. Re: working with files and directories (halex2000)
> 6. Re: Calling a thread asynchronously with a callback
>(Diez B. Roggisch)
> 7. Re: Calling a thread asynchronously with a callback
>(Bjoern Schliessmann)
> 8. python skipping lines? ([EMAIL PROTECTED])
> 9. can't get cgi values (ronrsr)
>10. Re: can't get cgi values (Fredrik Lundh)
>11. Re: can't get cgi values (Paul McGuire)
> 
> From: jim-on-linux <[EMAIL PROTECTED]>
> To: python-list@python.org
> Cc: Kevin Walzer <[EMAIL PROTECTED]>
> Subject: Re: Several entries on Tile and TableList at the Tkinter wiki
> Date: Mon, 27 Nov 2006 12:29:58 -0500
> 
> 
> Thanks for posting this entry,
> 
> The fact that a wiki or help site doesn't get a
> lot of traffic is not an necessarily an indicator
> of it's usfulness.  It indicates to me that the
> product, in this case Tkinter, may be easy to use
> and understand, after working with it a little, A
> lot of help may not be necessary.
> 
> A good example is the py2exe help site.
> At one time not to long ago there might be 8 to 12
> post per day, or more. Today by my unscientific
> count method, I don't think there are more than 3
> to 4 post per week.  Yet, py2exe and Tkinter is
> almost as valuable as Python. If we couldn't
> build programs for Windows, where would a python
> programmes's money come from?
> 
> Thanks again,
> 
> jim-on-linux
> http://www.inqvista.com
> 
> 
> 
> On Sunday 26 November 2006 15:50, Kevin Walzer
> wrote:
> > I'm not sure how often members of this list
> > visit the Tkinter wiki at
> > http://tkinter.unpythonic.net/wiki/FrontPage; this wiki seems to 
> > have less traffic in general
> > than the Tcl/Tk wiki at http://wiki.tcl.tk.
> > Given that, I hope it's not out of line for me
> > to call attention to several pages that I've
> > posted about integrating Tile
> > (http://tktable.sourceforge.net/tile) and
> > TableList (http://www.nemethi.de,
> > http://wiki.tcl.tk/5527) into Tkinter
> > applications. I've noted a serious lack of
> > resources/documentation about these two
> > powerful Tk components. In addition to some
> > documentation, screenshots, and sample
> > applications, I've posted updated versions of
> > the original TableList and Tile wrappers by
> > Martin Franklin.
> >
> > I should take this moment to thank Mr. Franklin
> > for his work on these wrappers; whatever I
> > added to them was pretty minimal compared to
> > the heavy lifting he did. He originally posted
> > them on the Internet last year, but the site
> > that hosted them has gone dark. Anyway, Mr.
> > Franklin, if you are reading this, thank you
> > for your hard work; it has been enormously
> > helpful. I hope my own efforts extend your work
> > and make it even more useful for other Tkinter
> > developers.
> >
> > Here are the links:
> >
> > http://tkinter.unpythonic.net/wiki/UsingTile
> > http://tkinter.unpythonic.net/wiki/TileWrapper
> > http://tkinter.unpythonic.net/wiki/TableListWra
> > pper
> > 

building python from source on HP

2007-05-07 Thread Edwin . Madari
appreciate hints or pointers for building python on HP.

running 'make test'  fails with following cryptic message,  after running 
configure, & make. Attempting to build python from source on HP-UX  
B.11.11 U 9000/800 3314646674 unlimited-user license

*** Error exit code 1
Stop.

not sure if output from configure and make would make a difference. If so I can 
send them.

thanks in advance
Edwin




The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

Re: Snippets management

2008-11-05 Thread Edwin B.
r <[EMAIL PROTECTED]> writes:

> On Nov 5, 7:55 pm, [EMAIL PROTECTED] (Edwin) wrote:
>> Hi there,
>>
>> I've been looking for a snippet manager and found PySnippet but it
>> requires PyGTK. Do you know any other option that doesn't need much?
>>
>> I'm sort of new to python and user interfaces seem a bit far for me
>> right now, that's why I thought having to install PyGTK was
>> unnecessary.
>>
>> Would you recommend installing it anyway?
>>
>> I'm on a Mac, maybe some users of Steve's Unix flavour know about a
>> snippets software piece? I'm looking for free/open source alternatives.
>>
>> Thank you!
>>
>> P.S.: I'm also new to usenet ;) and hope my english is not that bad.
>
> I don't use one, but why not take a stab at coding one yourself.
> Use Tkinter to start, its easy.  well documented
> gotta learn GUI somehow
> if you need links to docs or help let me know
>

Good idea. It's not that I don't want to learn GUI, but coming from Web
related fields I'm taking it one step at a time, while learning Unix
(editors, shell, filesystem hierarchy, etc.).

All of this had been obscured by 'Apple's lifestyle'. It's been less than a
year since I realized I had so much powerful software around.

I'll start with Python documentation. If in any trouble, I'll get to you.

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


Re: Snippets management

2008-11-06 Thread Edwin B.
Robert Lehmann <[EMAIL PROTECTED]> writes:

> I don't think there is a one-size-fits-all solution.

I definetly agree.

> Setting up a 'snippets' repository sounds good if you just want to be 
> able to look back at what you've done and/or have a place to stash away 
> quick tests. I have set up a 'sandbox' folder (unrevisioned) and put 
> together a few shell aliases for easier access and it works pretty well. 
> I almost never look back at that code though.
>
> If you develop a lot of small scripts you think you'll reuse in your 
> daily routine, you should add a dedicated 'bin' directory and add it to 
> your PATH.

This is a nice method. I'm already putting it to use. I've learned about
/usr/bin and /usr/local/bin so I went ahead and created $HOME/bin and
added it to my path for this sort of code.

Now, I was thinking more of a notes+code program. Let me give you an
example:

I use Emacs.app (Emacs compiled with --with-ns) and in order to get a
meta key in the Spanish keyboard on my Mac I had to try different lines
but I didn't want to keep all these tries in my .emacs file. I also
wanted to keep the lines that didn't work for later tests in my Free BSD
PC (also with a Spanish keyboard). So I keep all of them in my notebook.

Then, I start coding Python. This time I try to translate an old PHP
script to Python and want to keep a few important lines visible. It'll
be nice to take some notes of the main differences in my scripts in a
different place. Like a student's notebook. Once again, all this goes to
my little program.

Then, I remember I had to run some Mac maintenance commands... I don't
remember the complete line very well, so I go to my notebook.

My point is that sometimes not every note is useful for a program. I
guess as I gain experience all these little notes will be kept in my
mind ;). But as a newbie it seems useful.

As r said, I think it'll be good to write this program. If it doesn't
result in a very useful piece, it'll be a good way to practice.

I forgot to mention I don't use a notes program to keep personal and
programming notes separately.

Thanks mate!

P.S.: Man I hope my English doesn't suck too much.

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


RE: Continually check object status

2008-08-02 Thread Edwin . Madari
updated creature running in its own thread will get you started. try it for 
yourself, change sleep times per your need.

import os, sys, threading,  time
class Creature:
   def __init__(self, status):
  self.status = status
  self.state = 'run'

   def start(self):
  self.athread = threading.Thread(target=self.print_status)
  self.athread.start()

   def change_status(self, new_status):
  self.status = new_status

   def print_status(self):
  while self.state == 'run':
 print self.status
 time.sleep(1)

   def stop(self):
  self.state = 'stop'
  self.athread.join()

#main loop
c = Creature('happy')
c.start()
time.sleep(3)  #wait some time
c.change_status('managing')
time.sleep(3)  #wait some more time
c.change_status('bye')
time.sleep(1)
c.stop()


concept would be similar with GUI as well

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: Saturday, August 02, 2008 1:54 PM
To: python-list@python.org
Subject: Re: Continually check object status


On Aug 2, 1:05 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] schrieb:
>
>
>
> > Beginner, so please bare with me.  I'm not sure what to call what it
> > is I'm looking for.
>
> > If I have an object class, let's call it "Creature":
>
> > class Creature:
> >     def __init__(self, status):
> >         self.status = "happy"
>
> >     def change_status(self, new_status):
> >         self.status = new_status
>
> >     def print_status(self):
> >         print self.status
>
> > I would like to be able to print out the Creature's status every 20
> > seconds.  Let's say I use a script like this:
>
> > import time
> > while True:
> >     time.sleep(20)
> >     Creature.print_status()
>
> > But, while cycling through printing the status, I would like to be
> > able to update Creature.status to something new.
>
> > I might be approaching this from the wrong direction entirely.  Thanks
> > for your input.
>
> The "simple", yet possibly dangerous answer is: you need
> multi-threading. Multi-threading is a technique that allows several
> (quasi)-parallel paths of execution whilst sharing memory and objects
> inside that memory. The module in python to achieve this is called
> "threading".
>
> However, concurrent programming is a very advanced topic, ridded with
> pitfalls for even experienced developers.
>
> There are other ways to solve the problem, commonly known as event-loops
> and timers. These are usually part of frameworks for e.g GUI-creation an
> such, but you can also roll your own if you like.
>
> So, the better answer might be a question: what do you ultimately want
> to achieve? Given the name of your class, Creature, I assume you are
> writing on some game or such. Depending on how you plan to do that, you
> might have a framwork providing you with the needed tools/library calls
> or whatever.
>
> Diez

I was afraid that someone was going to mention threading.  I have read
about it before but not been able to do much with it.

My ultimate goal is to create some sort of tamagotchi style virtual
pet to interact with.  Over time it gets hungry or bored, but the
process can be fixed by a user "feeding" or "playing with" it.  I
wanted to take this opportunity to teach myself some PyGTK coding as
well, but I thought that maybe I could build the creature object and
looping in such a way that it would be possible to add a GUI to it
later.
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: Decimals not equalling themselves (e.g. 0.2 = 0.2000000001)

2008-08-03 Thread Edwin . Madari
for nth square root: use math.sqrt n times for example
>>> import math
>>> num = 625
>>> how_many_sqrt = 2
>>> for i in range(how_many_sqrt):
.. num = math.sqrt(num)
.. 
>>> num
5.0

all comparisons work fine for arbitrary floating point numbers... 
For readability print them with required precision. for example
>>> a = .2
>>> b = .4
>>> b = b/2
>>> a == b
True
>>> a, b
(0.20001, 0.20001)
>>> '%.2f' % a, '%.2f' % b
('0.20', '0.20')
>>>  

thx. Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of CNiall
Sent: Sunday, August 03, 2008 10:03 AM
To: python-list@python.org
Subject: Decimals not equalling themselves (e.g. 0.2 = 0.21)


I am very new to Python (I started learning it just yesterday), but I 
have encountered a problem.

I want to make a simple script that calculates the n-th root of a given 
number (e.g. 4th root of 625--obviously five, but it's just an example 
:P), and because there is no nth-root function in Python I will do this 
with something like x**(1/n).

However, with some, but not all, decimals, they do not seem to 'equal 
themselves'. This is probably a bad way of expressing what I mean, so 
I'll give an example:
 >>> 0.5
0.5
 >>> 0.25
0.25
 >>> 0.125
0.125
 >>> 0.2
0.20001
 >>> 0.33
0.33002

As you can see, the last two decimals are very slightly inaccurate. 
However, it appears that when n in 1/n is a power of two, the decimal 
does not get 'thrown off'. How might I make Python recognise 0.2 as 0.2 
and not 0.20001?

This discrepancy is very minor, but it makes the whole n-th root 
calculator inaccurate. :\
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: xlrd

2008-08-04 Thread Edwin . Madari
here is working code that will read & display  contents of all rows & columns 
in all the sheets, you need xlrd 0.6.1

import xlrd, os, sys

book = xlrd.open_workbook(sys.argv[1])
print "The number of worksheets is", book.nsheets
for shx in range(book.nsheets):
   sh = book.sheet_by_index(shx)
   print 'tab:%s rows:%s cols:%s ' % (sh.name, sh.nrows, sh.ncols)
   for rx in range(sh.nrows):
  for cx in range(sh.ncols):
 try:
if sh.row_types(rx)[cx] and sh.row_values(rx)[cx]:
   print '%4s %s' % (xlrd.cellname(rx, cx), sh.row_values(rx)[cx])
 except:
print xlrd.cellname(rx, cx), 'Exception - could not read'
   print

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Gary Herron
Sent: Monday, August 04, 2008 5:01 AM
Cc: python-list@python.org
Subject: Re: xlrd


Yeats wrote:
> Hi,
>  
> Years ago i use xlrd to read data from excel and now I need again, but 
> i get strange result. The code is:
>  
> from xlrd import *
>  
> Planilha = open_workbook('C:\\Resultados.xls')
> Resultados = Planilha.sheet_by_name('Resultados')
> c = (Resultados.cell_value(2,2))
> print c
>  
> and the result is: 0, but the value in cell is : VERDADEIRO
>  
> What´s the problem

I've never used xlrd, but based on other packages for accessing spread 
sheets, here's one guess.

Cells can have numeric values or string values.  Your cell apparently 
has a string, but you are asking for a numeric value, so you get a 
zero.  Should you be asking for a string value?  (That's the way 
OpenOffice/python works if I remember correctly.)

Or are you accessing a different cell because you've confused 0-based / 
1-based indexing?

Or are you using old outdated versions of xlrd, Python or Excel?

Gary Herron



>  
> Thanks and sorry my bad english
> Yeats
>  
> 
>
> --
> http://mail.python.org/mailman/listinfo/python-list

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



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: UnicodeDecodeError, how to elegantly deal with this?

2008-08-04 Thread Edwin . Madari
if you can print out values  of 'filemask', and 'thefile' variables, when it 
crashes, I can help.

thx. Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Jorgen Bodde
Sent: Monday, August 04, 2008 2:24 PM
To: python-list@python.org
Subject: UnicodeDecodeError, how to elegantly deal with this?


Hi All,

I am relatively new to python unicode pains and I would like to have
some advice. I have this snippet of code:

def playFile(cmd, args):
argstr = list()
for arg in appcfg.options[appcfg.CFG_PLAYER_ARGS].split():
thefile = args["file"]
filemask = u"%file%"
therep = arg.replace(filemask, thefile)   # error here
argstr.append(therep)
argstr.insert(0, appcfg.options[appcfg.CFG_PLAYER_PATH])

try:
subprocess.Popen( argstr )
except OSError:
cmd.html = "Can't play file" + args["file"]
return

cmd.redirect = _getBaseURL("series?cmd_get_series=%i" % args["id"])
cmd.html = ""

---

It crashes on this:

20:03:49:   File
"D:\backup\important\src\airs\webserver\webdispatch.py", line 117, in
playFile therep = arg.replace(filemask, thefile)

20:03:49: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in
position 93: ordinal not in range(128)

20:03:49: Unhandled Error: :
'ascii' codec can't decode byte 0xc2 in position 93: ordinal not in
range(128)

It chokes on a ` character in a file name. I read this file from disk,
and I would like to play it. However in the replace action it cannot
translate this character. How can I transparently deal with this issue
because in my eyes it is simply replacing a string with a string, and
I do not want to be bothered with unicode problems. I am not sure in
which encoding it is in, but I am not experienced enough to see how I
can solve this

Can anybody guide me to an elegant solution?

Thanks in advance!
- Jorgen
--
http://mail.python.org/mailman/listinfo/python-list



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


soap call through firewall

2008-08-06 Thread Edwin . Madari
hi,

any hints/pointers appreciated if you have succeeded in making a soap call 
through a firewall. 
other than this  http://www.ibm.com/developerworks/xml/library/x-tipfire.html 
cannot find much.

thanks in advance
Edwin


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

SOAPpy how to

2008-08-06 Thread Edwin . Madari
unable to get past local proxy server with SOAPpy client. In the code below 
using 'thproxy' or 'httpproxy' variable for http_proxy fails.

from SOAPpy import WSDL

proxyuser='..'
proxypass='..
httpproxy="a.b.c.com:1234"
theproxy='http://'+proxyuser+':'+proxypass+'@'+httpproxy

wsdl='sample.wsdl'
#soap service provided by the soap server defined in the wsdl
server = WSDL.Proxy(wsdl, http_proxy=httpproxy)  #fails with 
SOAPpy.Errors.HTTPError: 
#server = WSDL.Proxy(wsdl, http_proxy=theproxy) #fails with socket.gaierror: 
(7, 'getaddrinfo failed')

a = server.aTestMethod( arg1, arg2, )
print a

any suggestions or hints any one..

thanks in advance
Edwin



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

python equivalent for this perl soap client

2008-08-06 Thread Edwin . Madari
use SOAP::Lite;
use Data::Dumper;

$ENV{HTTP_proxy} = "my_proxy_server_not_soap_proxy_server";
$ENV{HTTP_proxy_user} = ""; #set correct value
$ENV{HTTP_proxy_pass} = ""; #set correct value

my $soap = SOAP::Lite ->service('file:./local_file_copy_of_wsdl.wsdl');
my $som = $soap->soapMethod("method", "args", "as", "required");
print Dumper($som);

although above perl code (yes it works!), connects to the soap server through 
the http proxy with proper credentials, I would rather do it python. has any 
out there succeeded in making a soap request through firewall using wsdl 
something like below

from SOAPpy import WSDL
server = WSDL.Proxy('./local_file_copy_of_wsdl.wsdl')
res = server.soapMethod("method", "args", "as", "required")

tried every which way but cannot get it to work. any hints, suggestions 
appreciated.

thanks in advance
Edwin




The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

Re: Using an DTD not specified in XML file for validation

2008-08-06 Thread Edwin . Madari
can you edit the xml and add the dtd/scheama ?

.Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Ben Finney
Sent: Wednesday, August 06, 2008 7:07 PM
To: python-list@python.org
Subject: Re: Using an DTD not specified in XML file for validation


Brian Quinlan <[EMAIL PROTECTED]> writes:

> I'm trying to figure out how I can validate an XML file using a DTD
> that isn't specified in the XML file.

When your inention is to start a new discussion, you could compose a
new message, *not* reply to an existing message. Your message here is
now part of an existing thread of discussion, yet is confusingly
unrelated in its content, and will not be noticed by most readers.

-- 
 \  "Whatever you do will be insignificant, but it is very |
  `\important that you do it." -Mahatma Gandhi |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: A question about string and float number

2008-08-06 Thread Edwin . Madari
type(s) == type(float())

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Wei Guo
Sent: Wednesday, August 06, 2008 9:23 PM
To: python-list@python.org
Subject: A question about string and float number


Hi all,
 
I am new of python. Could anyone help me a question as below?
 
Is there any function that can judge a string s is a float number or not? FOr 
example, if s = '1.232' or s='1e+10', then it returns true, otherwise, it will 
return false.
 
isdigit() in string doesn't work. float() will throw an exception and I just 
need true or false as result.
 
Thanks a lot in advance,
 
Wei



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

RE: A question about string and float number

2008-08-06 Thread Edwin . Madari
#this is a better way of testing a string for float
def isFloat(s):
try:
s = float(s)
except:
return False
return True

-Original Message-
From: Madari, Edwin 
Sent: Wednesday, August 06, 2008 10:22 PM
To: 'Wei Guo'; python-list@python.org
Subject: RE: A question about string and float number


type(s) == type(float())

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Wei Guo
Sent: Wednesday, August 06, 2008 9:23 PM
To: python-list@python.org
Subject: A question about string and float number


Hi all,
 
I am new of python. Could anyone help me a question as below?
 
Is there any function that can judge a string s is a float number or not? FOr 
example, if s = '1.232' or s='1e+10', then it returns true, otherwise, it will 
return false.
 
isdigit() in string doesn't work. float() will throw an exception and I just 
need true or false as result.
 
Thanks a lot in advance,
 
Wei



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

RE: Testing for the first few letters of a string

2008-08-07 Thread Edwin . Madari
use re module

import re
template = '^My name is alex'
astring = 'My name is alex, and I like pie'
if re.match(template, astring):
print 'Found it'
else: print '%s does not begin with %s' % (astring, template)

good luck.
Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Alexnb
Sent: Thursday, August 07, 2008 11:40 AM
To: python-list@python.org
Subject: Testing for the first few letters of a string



Okay, I have a fix for this problem, but it is messy and I think there might
be a better way. Heres an example:

Lets say I have a string: "My name is alex"

and I have another string "My name is alex, and I like pie". 

I want to test to see if just the "My name is alex" part is there. I don't
care about the pie part. 
My first instinct was to just create a for loop and test for the string like
this:

n = 0

for x in string1:
  if string1[n] == string2[n]
n = n +0
  else:
break
and then later testing to see what n was = to and figuring out if it got
through the whole loop. I feel like there should be an easier way to do
this, and probably is. So Does anyone have a suggestion?
-- 
View this message in context: 
http://www.nabble.com/Testing-for-the-first-few-letters-of-a-string-tp18873375p18873375.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: very newbie question

2008-08-07 Thread Edwin . Madari
delete the extra 'tries += 1'  after 
else:
print "Higher..."
tries += 1  #delete this 

while at it, and add this line as the first line in function ask_number()
global the_number, tries
 
good luck.
Edwin

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of garywood
Sent: Thursday, August 07, 2008 1:56 PM
To: python-list@python.org
Subject: very newbie question 


stuck on python for absolute beginners 
chapter 6 
i actually done what i was supposed to do use the function ask_number for guess 
a number 
but for some reason it does not count correctly the number of tries 
 
# Guess My Number
#
# The computer picks a random number between 1 and 100
# The player tries to guess it and the computer lets
# the player know if the guess is too high, too low
# or right on the money
 
import random  
 
print "\tWelcome to 'Guess My Number'!"
print "\nI'm thinking of a number between 1 and 100." 
print "Try to guess it in as few attempts as possible.\n"
 
# set the initial values
 
 
 
def ask_number():
the_number = random.randrange(100) + 1
guess = int(raw_input("Take a guess: "))
tries = 1




while (guess != the_number):


if (guess > the_number):
print "Lower..."

else:
print "Higher..."
tries += 1


guess = int(raw_input("Take a guess: "))
tries += 1




ask_number()
 
 
 

print "You guessed it!  The number was", the_number
print "And it only took you", tries, "tries!\n"
  
raw_input("\n\nPress the enter key to exit.")




The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

RE: sending to an xterm

2008-08-08 Thread Edwin . Madari
since I do not have access to xterm, here is the interactive session for 
spawning bash(another session if you will), sending ls command to it, and 
retrieving the results.
things to note are:
1. after spawning expect for the prompt, timeout, and eof #which ever happens 
first
2. return value is the action that matched
3. if prompt matched, the 'before' has the results
4. even the command 'ls' with '\r\n' will be in the results.
actual session------
[EMAIL PROTECTED]:/c/Edwin/Projects/expect
$ python
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) 
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexpect
>>> c = pexpect.spawn('/bin/bash')
>>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
2
>>> c.before
'[EMAIL PROTECTED]:/c/Edwin/Projects/expect\r\n'
>>> c.after
'$ '
>>> c.sendline('ls')
3
>>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
2
>>> c.before
'[EMAIL PROTECTED]:/c/Edwin/Projects/expect\r\n'
>>> c.after
'$ '
>>> 
>>> exit()
[EMAIL PROTECTED]:/c/Edwin/Projects/expect
$ 
---

good luck
Edwin
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Kent Tenney
Sent: Friday, August 08, 2008 4:25 PM
To: python-list@python.org
Subject: sending to an xterm


Howdy,

I want to open an xterm, send it a command and have it execute it.

I thought pexpect would do this, but I've been unsuccessful.

term = pexpect.spawn('xterm')

starts an xterm, but

term.sendline('ls') 

doesn't seem to do anything.

Suggestions?

Thanks,
Kent

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


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: Extract string from log file

2008-08-09 Thread Edwin . Madari
from each line separate out url and request parts. split the request into 
key-value pairs, use urllib to unquote key-value pairs..as show below...

import urllib
line = "GET 
/stat.gif?stat=v&c=F-Secure&v=1.1%20Build%2014231&s=av%7BNorton%20360%20%28Symantec%20Corporation%29+69%3B%7Dsw%7BNorton%20360%20%28Symantec%20Corporation%29+69%3B%7Dfw%7BNorton%20360%20%28Symantec%20Corporation%29+5%3B%7Dv%7BMicrosoft%20Windows%20XP+insecure%3BMicrosoft%20Windows%20XP%20Professional+f%3B26027%3B26447%3B26003%3B22452%3B%7D&r=0.9496
 HTTP/1.1"
words = line.split()
for word in words:
if word.find('?') >= 0:
req = word[word.find('?') + 1:]
  kwds = req.split('&')
  for kv in kwds:
print urllib.unquote(kv)


stat=v
c=F-Secure
v=1.1 Build 14231
s=av{Norton 360 (Symantec Corporation)+69;}sw{Norton 360 (Symantec 
Corporation)+69;}fw{Norton 360 (Symantec Corporation)+5;}v{Microsoft Windows 
XP+insecure;Microsoft Windows XP Professional+f;26027;26447;26003;22452;}
r=0.9496

good luck
Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: Saturday, August 09, 2008 10:48 AM
To: python-list@python.org
Subject: Extract string from log file


203.114.10.66 - - [01/Aug/2008:05:41:21 +0300] "GET /stat.gif?
stat=v&c=F-Secure&v=1.1%20Build%2014231&s=av%7BNorton
%20360%20%28Symantec%20Corporation%29+69%3B%7Dsw%7BNorton
%20360%20%28Symantec%20Corporation%29+69%3B%7Dfw%7BNorton
%20360%20%28Symantec%20Corporation%29+5%3B%7Dv%7BMicrosoft%20Windows
%20XP+insecure%3BMicrosoft%20Windows%20XP%20Professional+f
%3B26027%3B26447%3B26003%3B22452%3B%7D&r=0.9496 HTTP/1.1" 200 43
"http://dfstage1.f-secure.com/fshc/1.1/release/devbw/1.1.14231/
card.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1; .NET CLR 2.0.50727)"



does anyone know how can i extract certain string from this log file
using regular expression in python or using XML. can teach me.
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: "shelve" save object

2008-08-09 Thread Edwin . Madari
since choice of dbm used by shelve http://docs.python.org/lib/node327.html 
depends on os, and whats available on it, shevle files saved on one os, most 
likely do not work on another os, sometimes on similar os but different 
machines might not work either - goes back to what's available on that machine.

inter operability of shelve files with similar os-es works! yes I had used it. 

For inter-operability of saved information across os-es, roll up your own bit 
of code to write it out into pickle files. Yes pickle files are inter-operable. 

Consider a database for persistent storage and retrieval from many os-es


good luck.
Edwin



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of hypermonkey2
Sent: Saturday, August 09, 2008 3:33 PM
To: python-list@python.org
Subject: "shelve" save object


Hi there!
I am using the "shelve" module in a script to save information in
between runtime sessions of the program. (its a sort of
data collector, so its important to hold on to anything computed  ).
In any case, I shelve into a file "test.txt". I notice that when i try
running the program on a different computer (by either emailing or
transfering the file "test.txt" via USB key), the program is unable to
load the shelve file.
What can I do to fix this? It would be a great shame to see that after
collecting all this information and shelving it that I cannot move to
another computer or share the information through the "save.txt" file.

Thanks in advance!
Jon
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: How to round a floating point to nearest 10?

2008-08-09 Thread Edwin . Madari
>>> round(76.1, -2)
100.0
>>> round(76.1, -1)
80.0
>>> round(76.1)
76.0
>>> 

builtin function round,  will work for you..
Help on built-in function round in module __builtin__:
round(...)
round(number[, ndigits]) -> floating point number

Round a number to a given precision in decimal digits (default 0 digits).
This always returns a floating point number.  Precision may be negative.

good luck..
Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of John Machin
Sent: Saturday, August 09, 2008 5:54 PM
To: python-list@python.org
Subject: Re: How to round a floating point to nearest 10?


On Aug 10, 1:19 am, Mensanator <[EMAIL PROTECTED]> wrote:
> On Aug 9, 6:31 am, Will Rocisky <[EMAIL PROTECTED]> wrote:
>
> > I want my 76.1 to be rounded to decimal 80 and 74.9 to decimal 70.
> > How can I achieve that?
> >>> print '%.0e' % 74.9
> 7e+01
> >>> print '%.0e' % 76.1
>
> 8e+01

But:
>>> print '%.0e' % 176.1
2e+002

Giving the Subject ("How to round a floating point to nearest 10?"),
there's a strong presumption that the OP would want the answer to be
180, not 200.
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: regular expression extracting groups

2008-08-10 Thread Edwin . Madari
if its *NOT* an exercise in re,  and if input is a bunch of lines within '{' 
and '}' and each line is key="value" pairs, I would not go near re. instead 
simply parse keys and array of values into a dictionary, and process them from 
the dictionary as below, and the key option correctly has 2 entries 'value' and 
'7' in the right order. will work with any input...
 
# assuming variable s has the string..
s = """{
option=value
foo=bar
another=42
option=7
}"""

>>> for line in s.split():
.. ix = line.find('=')
.. if ix >= 0:
.. key = line[:ix]
.. val = line[ix + 1: ]
.. try:
.. data[key].append(val)
.. except KeyError:
.. data.setdefault(key, [val])
.. 
>>> 
>>> 
>>> for k, v in data.items():
.. print 'key=%s val=%s' % (k, v)
.. 
.. 
key=foo val=['bar']
key=option val=['value', '7']
key=another val=['42']

with another dictionary of keys to be processed with a function  to process 
values for that key, its a matter of iterating over keys..  

hope that simplifies and helps.. 
thx Edwin



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: Sunday, August 10, 2008 8:30 AM
To: python-list@python.org
Subject: regular expression extracting groups


Hi list,

I'm trying to use regular expressions to help me quickly extract the
contents of messages that my application will receive. I have worked
out most of the regex but the last section of the message has me
stumped. This is mostly because I want to pull the content out into
regex groups that I can easily access later. I have a regex to extract
the key/value pairs but it ends up with only the contents of the last
key/value pair encountered.

An example of the section of the message that is troubling me appears
like this:

{
option=value
foo=bar
another=42
option=7
}

So it's basically a bunch of lines. Every line is terminated with a
'\n' character. The number of key/value fields changes depending on
the particular message. Also notice that there are two 'option' keys.
This is allowable and I need to cater for it.


A couple of example messages are:
xpl-stat\n{\nhop=1\nsource=vendor-device.instance\ntarget=*\n}
\nhbeat.basic\n{\ninterval=10\n}\n

xpl-stat\n{\nhop=1\nsource=vendor-device.instance\ntarget=vendor-
device.instance\n}\nconfig.list\n{\nreconf=newconf\noption=interval
\noption=group[16]\noption=filter[16]\n}\n


As all messages follow the same pattern I'm hoping to develop a
generic regex, instead of one for each message kind - because there
are many, that can pull a message from a received packet.



The regex I came up with looks like this:
# This should match any xPL message

GROUP_MESSAGE_TYPE = 'message_type'
GROUP_HOP = 'hop'
GROUP_SOURCE = 'source'
GROUP_TARGET = 'target'
GROUP_SRC_VENDOR_ID = 'source_vendor_id'
GROUP_SRC_DEVICE_ID = 'source_device_id'
GROUP_SRC_INSTANCE_ID = 'source_instance_id'
GROUP_TGT_VENDOR_ID = 'target_vendor_id'
GROUP_TGT_DEVICE_ID = 'target_device_id'
GROUP_TGT_INSTANCE_ID = 'target_instance_id'
GROUP_IDENTIFIER_TYPE = 'identifier_type'
GROUP_SCHEMA = 'schema'
GROUP_SCHEMA_CLASS = 'schema_class'
GROUP_SCHEMA_TYPE = 'schema_type'
GROUP_OPTION_KEY = 'key'
GROUP_OPTION_VALUE = 'value'


XplMessageGroupsRe = r'''(?P<%s>xpl-(cmnd|stat|trig))
\n # message type
   \
{\n
#
   hop=(?P<%s>[1-9]{1})
\n  # hop
count
   source=(?P<%s>(?P<%s>[a-z0-9]{1,8})-(?P<%s>[a-z0-9]{1,8})\.(?P<
%s>[a-z0-9]{1,16}))\n  # source identifier
   target=(?P<%s>(\*|(?P<%s>[a-z0-9]{1,8})-(?P<%s>[a-z0-9]{1,8})\.(?P<
%s>[a-z0-9]{1,16})))\n  # target identifier
   \}
\n
#
   (?P<%s>(?P<%s>[a-z0-9]{1,8})\.(?P<%s>[a-z0-9]{1,8}))\n
# schema
   \
{\n
#
   (?:(?P<%s>[a-z0-9\-]{1,16})=(?P<%s>[\x20-\x7E]{0,128})\n){1,64}   #
key/value pairs
   \}\n''' % (GROUP_MESSAGE_TYPE,
  GROUP_HOP,
  GROUP_SOURCE,
  GROUP_SRC_VENDOR_ID,
  GROUP_SRC_DEVICE_ID,
  GROUP_SRC_INSTANCE_ID,
  GROUP_TARGET,
  GROUP_TGT_VENDOR_ID,
  GROUP_TGT_DEVICE_ID,
  GROUP_TGT_INSTANCE_ID,
  GROUP_SCHEMA,
  GROUP_SCHEMA_CLASS,
  GROUP_SCHEMA_TYPE,
  GROUP_OPTION_KEY,
  GROUP_OPTION_VALUE)

XplMessageGroups = re.compile(XplMessageGroupsRe, re.VERBOSE |
re.DOTALL)


If I pass the second example 

Re: SSH utility

2008-08-11 Thread Edwin . Madari
for similar tasks, I use pexpect http://pypi.python.org/pypi/pexpect.

spawning bash process and simulate an interactive session. Here sending ls 
command, retrieving results and exiting. In the spawned process ssh or any 
other command, is just another command. 

actual session--
$ python
Python 2.5.1 (r251:54863, May 18 2007, 16:56:43) 
[GCC 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pexpect
>>> c = pexpect.spawn('/bin/bash')
>>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
2
>>> c.before, c.after
('[EMAIL PROTECTED]:~\r\n', '$ ')
>>> c.sendline('ls')
3
>>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
2
>>> c.before, c.after
('ls\r\x.txt  xx.txt  xy.txt  [EMAIL PROTECTED]:~\r\n', '$ ')
>>> c.sendline('exit')
5
>>> c.expect([pexpect.TIMEOUT, pexpect.EOF, '\$ '])
1
>>> c.before, c.after
('exit\r\nexit\r\n', )
>>> exit()
[EMAIL PROTECTED]:~
$ 
---

hope that helps.

regards.
Edwin


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of James Brady
Sent: Monday, August 11, 2008 12:26 AM
To: python-list@python.org
Subject: SSH utility


Hi all,
I'm looking for a python library that lets me execute shell commands
on remote machines.

I've tried a few SSH utilities so far: paramiko, PySSH and pssh;
unfortunately all been unreliable, and repeated questions on their
respective mailing lists haven't been answered...

It seems like the sort of commodity task that there should be a pretty
robust library for. Are there any suggestions for alternative
libraries or approaches?

Thanks!
James
--
http://mail.python.org/mailman/listinfo/python-list



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: for x,y in word1, word2 ?

2008-08-11 Thread Edwin . Madari
sounds like *soundex* is what you are looking for.  google soundex

regards
Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Marc 'BlackJack' Rintsch
Sent: Monday, August 11, 2008 3:09 AM
To: python-list@python.org
Subject: Re: for x,y in word1, word2 ?


On Sun, 10 Aug 2008 23:14:50 -0700, ssecorp wrote:

> I know zip but lets say I have a word "painter" and I want to compare it
> to a customer's spelling, he might have written "paintor" and I want to
> check how many letters are the same.
> 
> Now I know how I could do this, it is not hard. I am just wondering if
> these is any specific simple syntax for it.

No special syntax for that, but you can combine the `sum()` function, a 
generator expression and `zip()`:

In [40]: sum(int(a == b) for a, b in zip('painter', 'paintor'))
Out[40]: 6

Or this way if you think it's more clear:

In [41]: sum(1 for a, b in zip('painter', 'paintor') if a == b)
Out[41]: 6

Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: Checking a file's time stamp.

2008-08-12 Thread Edwin . Madari
os.paht.gmtime(path) returns the last modification of path.
check out http://docs.python.org/lib/module-os.path.html

regards
Edwin

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of William Purcell
Sent: Tuesday, August 12, 2008 1:47 PM
To: Python List
Subject: Checking a file's time stamp.


Hi all,
I am wanting to check to see the last time a file was edited. For example, I 
have a directory containing two text files, file1.txt and file2.txt.   I want 
to be able to process these files but only if they have been edited since the 
last time they were processed. I think that I want to be able to check the time 
stamp of each file. Can anyone tell me how to do that or point me in a better 
direction of checking the last time a file was edited?
Thanks,
Bill





The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: Random Problems

2008-08-13 Thread Edwin . Madari
use songs.extend( asongs ) #append is for single item - where ever it might be.

>>> l1 = range(5) 
>>> l2 = range(5,10)
>>> l1
[0, 1, 2, 3, 4]
>>> l2
[5, 6, 7, 8, 9]
>>> l1.extend(l2)
>>> l1
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> 

good luck.
Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Cousin Stanley
Sent: Wednesday, August 13, 2008 10:19 PM
To: python-list@python.org
Subject: Re: Random Problems




> Well the othe day I was making a program to make a list 
> of all the songs in certian directorys but I got a problem, 
> only one of the directorys was added to the list. 
> 
>
  Here's some code  that illustrates yours 

import glob

songs  = glob.glob( '/path/to/somewhere/*.mp3' )

asongs = glob.glob( 'path/to/somewhere/else/*.mp3' )

songs.append( asongs )

# repeat a few times appending lists from other dirs

> all goes well but pick awalys is from the first directory 
> but songs awalys includes all the files I want it to. 

  songs.append( asongs ) is appending the entire  asongs  list
  as a single item to the end of the  songs  list, not adding
  each individual song as an entry  

  For example 

>>> l1 = range(  0 ,  5 )
>>> l2 = range(  5 , 10 )
>>> l3 = range( 11 , 15 )
>>>
>>> l1
[0, 1, 2, 3, 4]
>>>
>>> l2
[5, 6, 7, 8, 9]
>>>
>>> l3
[11, 12, 13, 14]
>>>
>>> l1.append( l2 )
>>>
>>> l1
[0, 1, 2, 3, 4, [5, 6, 7, 8, 9]]
>>>
>>> l1.append( l3 )
>>>
>>> l1
[0, 1, 2, 3, 4, [5, 6, 7, 8, 9], [11, 12, 13, 14]]
 
  So, if you have a  lot  of entries in the original  songs  list
  you're only adding a  few  entries to it in the form of another
  list and most likely you didn't run enough  random.choice  tests
  to flush out a  pick  that  turned out to be one of the entire
  asong lists that you added  

  You might try something like the following 
  where each tune gets added individually to
  the song pool  un-tested 


# ---

import random
import glob

base_dir = 'c:/Documents and Settings/Admin/My Documents'

list_subdirs = [
'LimeWire/Saved/*.mp3' ,
'Downloads/*/*.mp3' ,
'Downloads/*/*/*.mp3' ,
'Downloads/*/*/*/*.mp3 ]

song_pool = [ ] 

for this_dir in list_subdirs :

list_songs = glob.glob( "'%s/%s'" % ( base_dir , this_dir )

if list_songs :

for this_song in list_songs :

song_pool.append( this_song )

npicks = 41

print

for n in range( npicks ) : 

this_pick = random.choice( song_pool )

print '   ' , this_pick

# --- 
   

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

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


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: Formatting input text file

2008-08-14 Thread Edwin . Madari
save following code in script.py, and run it as 'python script.py 
'
with your sample data this prints out following which is what you are looking 
for (i think)
3.08333 9.05526 3.13581
4.08322 4.02526 3.95891

import sys

data = []
row = []
fh = open(sys.argv[1])
for line in fh:
   line = line.strip()
   if not line or line.startswith(''):
  continue
   if line.startswith('X'):
  if row:
 data.append(row)
 row = []
  continue
   row.append(line.split()[1])
if row:
   data.append(row)

for  i in data:
   print ' '.join(i)
=====

good luck.
Edwin
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of [EMAIL PROTECTED]
Sent: Thursday, August 14, 2008 7:07 AM
To: python-list@python.org
Subject: Formatting input text file


Hi,

it's me again with tons of questions. I hava an input file structured
like this:

  X   XYData-1

1. 3.08333
2. 9.05526
3. 3.13581
...

  X   XYData-2

1. 4.08322
2. 4.02526
3. 3.95891
...

i want to format it so i only get the second column, in order to place
it in a mxn matrix. Let's say i want this:

number1   number2   number3
number4   number5   number6

i hope it is not too hard to do. Any help greatly apreciated. Thanks,

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


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: Fixed-length text file to database script

2008-08-14 Thread Edwin . Madari
here is a working code snippet to  read from MySQL db. 
python tutorial has examples of reading from files.
put them together to do your task.
===
import MySQLdb

con = MySQLdb.connect(host='127.0.0.1', 
   port=4321, user='joe', passwd='shmoe', db='tst')
cursor = con.cursor()
sql = 'select * from YOUR_TABLE'
cursor.execute(sql)
results = cursor.fetch()
con.close()
=

hope that helps. good luck
Edwin
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Diez B. Roggisch
Sent: Thursday, August 14, 2008 7:11 AM
To: python-list@python.org
Subject: Re: Fixed-length text file to database script


Stacey wrote:

> Hi Guys,
> 
> I'm new to Python (mostly) and I'm wanting to use it for a new project
> I'm faced with.
> 
> I have a machine (PLC) that is dumping its test results into a
> fixed-length text file.  I need to pull this data into a database
> (MySQL most likely) so that I can access it with Crystal Reports to
> create daily reports for my engineers.
> 
> I've been reading the Python manual for about a week now and I'm
> learning a lot.  Unfortunately, I was given a deadline today that I
> cannot meet without a little help.
> 
> I need to know how to write a script that will DAILY pull this text
> file into a MySQL database.
> 
> Can anyone show me how to do this?

Show us code & data, and we show you how to improve the code.

Or would you be able to write the script with the above information?

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


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: a question about mysqldb

2008-08-14 Thread Edwin . Madari
replace the name of table before calling *.execute.
s.dbptr.execute(str % (e[0]))

good luck.
Edwin
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Evan
Sent: Thursday, August 14, 2008 11:27 AM
To: python-list@python.org
Subject: a question about mysqldb


a simple problem but I do not know why...:(, could anyone help me?

MySQLdb nominally uses just the %s placeholder style, in my script, i
got error if you want to use placeholder(%s) for table name:
+
>>> str="select tID,tNote from %s where tID=1"   < check here
>>>
>>> e=["tmp"]

>>> s.dbptr.execute(str,e)
Traceback (most recent call last):
  File "", line 1, in ?
  File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
166, in execute
self.errorhandler(self, exc, value)
  File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line
35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: (1064, "You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near ''tmp') where tID=1' at line
1")
>>>



But sql worked but the I got no query result:

>>> str="select tID,tNote from tmp where %s = %s"  <--check here
>>> e=["tID",int(1)]
>>> s.dbptr.execute(str,e)
0L<-- check here
>>>
>>> s.dbptr.fetchall()
()
>>>



And then, it worked if I do:

>>> str="select tID,tNote from %s where %s = %s" % ("tmp","tID",1)
>>>
>>> str
'select tID,tNote from tmp where tID = 1'
>>> s.dbptr.execute(str)
1L
>>>
>>> s.dbptr.fetchall()
({'tID': 1L, 'tNote': 'kao'},)



mysql> desc tmp
-> ;
+---+-+--+-+-++
| Field | Type| Null | Key | Default | Extra  |
+---+-+--+-+-++
| tID   | int(11) | NO   | PRI | NULL| auto_increment |
| tDate | date| YES  | | NULL||
| tSID  | int(11) | NO   | | NULL||
| tCom  | varchar(15) | YES  | | NULL||
| tNote | text| YES  | | NULL||
+---+-+--+-+-++
5 rows in set (0.00 sec)
+

mysql>
mysql>

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


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: a question about mysqldb

2008-08-14 Thread Edwin . Madari
db module properly formats arguments, if input arguments are separated from 
table_name and colum_names.

columns = ('tID', 'tNote')
table_name = 'tmp'
sql = 'select %s from %s where tID=:1' % ( ', '.join(columns), table_name)
cursor.execute(sql, (1,))

# sql is now 'select tID, tNote from tmp where tID=:1'
# note the comma in argument tuple to execute (1,)

thanks Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Eric Wertman
Sent: Thursday, August 14, 2008 2:13 PM
To: python-list@python.org
Subject: Re: a question about mysqldb


I also like to use escaped identifiers in cases like this:

sql = "select tID,tNote from %s where %s = %%s" % ("tmp","tID")
cursor.execute(sql,1)

should work fine.
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: Fixed-length text file to database script

2008-08-14 Thread Edwin . Madari
#your thought is right. 
===
def sizes2fields(sizes):
   d = []
   begin = 0
   for i in sizes:
  if begin:
 end = begin + i
  else: end = i
  d.append((begin, end))
  begin += i
   return tuple(d)

def slicestring(s, fields):
   d = []
   for i in fields:
  d.append(s[i[0]:i[1]])
   return tuple(d)

sizes = [16,4,8,8,8]
s = '123456789012345678901234567890123456789012345678901234567890'
print slicestring(s, sizes2fields(sizes))
==
prints out:
('1234567890123456', '7890', '12345678', '90123456', '78901234')

hope it helps.
thanks Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Eric Wertman
Sent: Thursday, August 14, 2008 1:59 PM
To: python-list@python.org
Subject: Re: Fixed-length text file to database script


I have a machine (PLC) that is dumping its test results into a fixed-
length text file.


While it has nothing to do with python,  I found that creating a MySQL
table with the proper fixed length char() fields and using 'load data
infile'  was the easiest way to deal with that sort of scenario.   The
python script is the secondary part, that handles the normalization
and proper typing of the first table to the second, permanent storage
area.  But in this case, the more advanced bits are the database and
SQL details, and python is just a very convenient way to build the SQL
statements and execute them.

I'm really not sure what the best way to deal with fixed length data
is in python.  I might define a list with the field lengths and use a
string slicing to get the items.. as a first thought:

myfile = '/somewhere/somefile.txt'
sizes = [16,4,8,8,8]

fd = open(myfile,r)

for line in fd.readlines() :

idx1 = 0
for l in sizes :
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: threading

2008-08-14 Thread Edwin . Madari
1. check out the Caveats for thread module: 
http://docs.python.org/lib/module-thread.html

Threads interact strangely with interrupts: the KeyboardInterrupt exception 
will be received by an arbitrary thread. (When the signal module is available, 
interrupts always go to the main thread.) 

i.e., all threads (including main) to catch interrupt exceptions, and propagate 
that information to  other threads.

2. since there is no way to interrupt a sleep (not aware of any), sleep is not 
the choice. use something  else like napping.  I mean, take shorter intervals 
of sleep, check every thing is fine and go back to napping. if something is 
fishy - go catch it.

hope that helps.
Edwin


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Rhamphoryncus
Sent: Thursday, August 14, 2008 2:52 PM
To: python-list@python.org
Subject: Re: threading


On Aug 14, 3:30 am, "Mathieu Prevot" <[EMAIL PROTECTED]> wrote:
> 2008/8/13 Parimala <[EMAIL PROTECTED]>:
>
>
>
> > Hello,
>
> >        I am using python2.5.1 version to run my test scripts. I want to use
> > 'threading' module in my tests. As a startup program, I had run the
> > following one.
>
> > importthreading
> > import sys
> > import time
>
> > def hello():
> >   i=0
> >   try:
> >     while i<10:
> >       print "hi"
> >       time.sleep(1)
> >       i+=1
> >   except KeyboardInterrupt:
> >     print 'KeyboardInterrupt'
> >     raise KeyboardInterrupt
>
> > try:
> >   thread=threading.Thread(target=hello,args=())
> >   thread.start()
> > except KeyboardInterrupt:
> >   print 'KeyboardInterrupt'
> >   raise KeyboardInterrupt
>
> > once program starts, problem is..
> > I am not able to abort the thread using (CTRL+C) KeyboardInterrupt.  While
> > running if I press CTRL+C, it won't generate any exception until the end of
> > the execution. Once the execution gets over,  it will give "Exception
> > exceptions.KeyboardInterrupt in  > 'C:\python25\lib\threading.py'> ignored" this message and exits.
>
> > I had gone through some documents, it says if a thread is joined with
> > .join() method then we can't stop that process until it releases the lock
> > what it acquired. But in the above program I didn't use .join() method but
> > still I am not able to abort the thread.
>
> > Could you please suggest me how can I abort the thread at any point in time
> > using CTRL+C.
>
> Hi,
>
> a terminate method is given here:http://sebulba.wikispaces.com/recipe+thread2
>
> so you can terminate the thread by:
>
> (...)
> t.start()
> (...)
>
> while True:
>   try:
>     #some code
>   except KeyboardInterrupt:
>     t.terminate()
>     break
>
> Mathieu

(For some reason the OP hasn't come through to groups.google.com..
odd)

Note that it won't interrupt any blocked I/O, which is often what you
need the most.  If your threads are CPU-bound you can simply have them
check a flag and exit if it becomes True.
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: urldecode function?

2008-08-14 Thread Edwin . Madari
afraid not.. simple to create your own, NOTE that key words can be supplied 
more than once. Hence... 

import urllib
 
def urldecode(query):
   d = {}
   a = query.split('&')
   for s in a:
  if s.find('='):
 k,v = map(urllib.unquote, s.split('='))
 try:
d[k].append(v)
 except KeyError:
d[k] = [v]
 
   return d
 
s = 'Cat=1&by=down&start=1827&start=1234&anotherCat=me%3Dow%7e'
print urldecode(s)

prints out following and preserves the order of inputs for those keys given 
more than once as with 'start' key
{'start': ['1827', '1234'], 'anotherCat': ['me=ow~'], 'by': ['down'], 'Cat': 
['1']}
 
 
hope that helps..
Edwin
 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED]
Sent: Thursday, August 14, 2008 12:32 PM
To: python-list@python.org
Subject: urldecode function?


hi
is there a function that does the opposite of urllib.urlencode? 

for example
urldecode('Cat=1&by=down&start=1827')

returns a dictionary with {'Cat':1, 'by':'down','start':1827)

thanks




The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

RE: SOAPpy and ArrayOfString

2008-08-14 Thread Edwin . Madari
for someMethod(Field1 ArrayOf_xsd_string, other_parameters)
a call someMethod( ['str1', 'str2', 'str3'], other_parameters)  *works for me* 
with SOAPpy 0.12.0. yes sir it does.
 
in PERL, let alone array types, even for simple types it was hard for me with 
all the '->', and '$'  prefixing for objects and variables.
 
I use following snippet to  check arguments, and return types from a wsdl for 
each method. If any on them is not a simple type, check the wsdl manually for 
details of the data type.

import os, sys, glob
from SOAPpy import WSDL
 
def checkwsdl(file):
   if os.path.isfile(file):
  print 'wsdl:%s' % file
  server = WSDL.Proxy(file)
  for ct, k in enumerate(server.methods.keys()):
 args =[]
 rets = []
 callInfo = server.methods[k]
 for ct2, name in enumerate(callInfo.inparams):
args.append('%s %s' % (name.name.encode(), name.type[1].encode()))
 for ct2, name in enumerate(callInfo.outparams):
rets.append('%s %s' % (name.name.encode(), name.type[1].encode()))
 print '%s. %s(%s)\n\treturns(%s)' % ( ct+1, k.encode(),
  ',\n\t\t'.join(args),   ',\n\t\t'.join(rets))
  print
 
if __name__ == '__main__' :
   args = sys.argv[1:]
   for arg in args:
  for file in glob.glob(arg):
 checkwsdl(file)

 
Even though a method may be asking for an array, server may be accepting only 
up to a certain number of elements in the array.
And check the data type for elements in the array.
 
of course I had to tweak a couple of SOAPpy modules to accept long data type, 
and work from behind a firewall.
 
hope that helps...
thanks Edwin
 
 -Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of annu miya
Sent: Thursday, August 14, 2008 12:11 PM
To: python-list@python.org
Subject: SOAPpy and ArrayOfString




Hi, 
 
In the article below you mention that you were succesful at doing this through 
perl. Would it be possible to send me the perl code?
 
http://mail.python.org/pipermail/python-list/2007-January/423311.html
 
Thank You
 
Regards
 
Sid




The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

RE: updating dictionaries from/to dictionaries

2008-08-14 Thread Edwin . Madari
if the values for any of the keys are None, both do not work as can be seen 
below!!. 

since both loops are iterating over keys(), 'get' method which would return a 
'0' for non existing key does not encounter any non-existing keys.

import copy, sys

foo = { 'one' : 1, 'two' : 2, 'three' : None  }
bar = copy.deepcopy(foo)

try:
   for key in foo:
  foo[key] += bar.get(key, 0)
except:
   print 'foo',  sys.exc_info()[:2]

try:
   for key in bar:
  foo[key] += bar[key]
except:
   print 'bar', sys.exc_info()[:2]

foo (, TypeError("unsupported operand type(s) for 
+=: 'NoneType' and 'NoneType'",))
bar (, TypeError("unsupported operand type(s) for 
+=: 'NoneType' and 'NoneType'",))

hope that helps to clarify both point of views.
thanks Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Brandon
Sent: Thursday, August 14, 2008 8:35 PM
To: python-list@python.org
Subject: Re: updating dictionaries from/to dictionaries



> (1) iterating over foo:
> for key in foo:
>foo[key] += bar.get(key, 0)
>
> (2) iterating over bar:
> for key in bar:
>foo[key] += bar[key]
>
> I (again) challenge you to say *why* you feel that the "iterating over
> bar" solution will not work.


Well if you're going to be clever enough to iterate over bar and then
send the results to another dictionary altogether, I obviously cannot
put up a good argument on this matter!

Thanks for the input, I appreciate it.
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


RE: updating dictionaries from/to dictionaries

2008-08-14 Thread Edwin . Madari
by the way, iterating over bar will throw KeyError if that key does not exist 
in foo. to see that in action, simply set another key in bar after 
copy.deepcopy stmt in this example..
bar['xtra'] = 0
and re-run

fun learning with python...
Edwin

-Original Message-
From: Madari, Edwin 
Sent: Thursday, August 14, 2008 9:24 PM
To: 'Brandon'; python-list@python.org
Subject: RE: updating dictionaries from/to dictionaries


if the values for any of the keys are None, both do not work as can be seen 
below!!. 

since both loops are iterating over keys(), 'get' method which would return a 
'0' for non existing key does not encounter any non-existing keys.

import copy, sys

foo = { 'one' : 1, 'two' : 2, 'three' : None  }
bar = copy.deepcopy(foo)

try:
   for key in foo:
  foo[key] += bar.get(key, 0)
except:
   print 'foo',  sys.exc_info()[:2]

try:
   for key in bar:
  foo[key] += bar[key]
except:
   print 'bar', sys.exc_info()[:2]

foo (, TypeError("unsupported operand type(s) for 
+=: 'NoneType' and 'NoneType'",))
bar (, TypeError("unsupported operand type(s) for 
+=: 'NoneType' and 'NoneType'",))

hope that helps to clarify both point of views.
thanks Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Brandon
Sent: Thursday, August 14, 2008 8:35 PM
To: python-list@python.org
Subject: Re: updating dictionaries from/to dictionaries



> (1) iterating over foo:
> for key in foo:
>foo[key] += bar.get(key, 0)
>
> (2) iterating over bar:
> for key in bar:
>foo[key] += bar[key]
>
> I (again) challenge you to say *why* you feel that the "iterating over
> bar" solution will not work.


Well if you're going to be clever enough to iterate over bar and then
send the results to another dictionary altogether, I obviously cannot
put up a good argument on this matter!

Thanks for the input, I appreciate it.
--
http://mail.python.org/mailman/listinfo/python-list


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


any success in compiling mod_python3.3 on cygwin for apache2.2

2008-08-16 Thread Edwin . Madari
has any one out there succeeded in compiling/installing mod_python for apache2 
and python 2.5.  I am using python 2.5  on cygwin.

thanks in advance
Edwin




The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

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

Re: Python does not get environment variable when using cron.

2008-08-18 Thread Edwin . Madari
source in or execute .profile (or .bash_profile which ever is applicable to 
you) as a first thing in the cron to get environment variables.

hope that helps.
Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Eric Wertman
Sent: Sunday, August 17, 2008 9:39 PM
To: python-list@python.org
Subject: Re: Python does not get environment variable when using cron.


I'm not sure about the environment variable, but os.uname() should
give you what you need otherwise.
--
http://mail.python.org/mailman/listinfo/python-list



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: Vmware api

2008-08-18 Thread Edwin . Madari
do the ESX server provide any api's or an interactive session may ?

thx. Edwin
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Eric Wertman
Sent: Sunday, August 17, 2008 2:43 PM
To: python-list@python.org
Subject: Re: Vmware api


I would also be interested in anything anyone can offer.  I spend some
time looking around, and took a fair stab at using the wsdl2py that
comes with The ZSI package.  Ultimately I couldn't get anything to
work, and reverted to using perl (yuk).

I'm interested mostly in interrogating the ESX servers to get
configuration and performance data, from external hosts.

Thanks!

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



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: How to delete a line with re?

2008-08-18 Thread Edwin . Madari
running this snippet, is blanking out ^abdc$.. what is the issue ?
abcd
efg
hijk
lmn
$

efg
hijk
lmn

regards
Edwin

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of Peng Yu
Sent: Sunday, August 17, 2008 11:47 PM
To: python-list@python.org
Subject: How to delete a line with re?


Hi,

I want to delete the line with abc in the following program. But the
following program does not do what I want. Can somebody let me know
how to do it?

Thanks,
Peng

#!/usr/bin/python

import re

file="""abcd
efg
hijk
lmn
"""

regex = re.compile("^abcd$", re.MULTILINE)

print file,
print "$"
print regex.sub('', file),
--
http://mail.python.org/mailman/listinfo/python-list



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: Newbie problem inserting into MySQL

2008-08-18 Thread Edwin . Madari
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]
> ython.org]
> On Behalf Of len
> Sent: Monday, August 18, 2008 11:55 AM
> To: python-list@python.org
> Subject: Newbie problem inserting into MySQL
> 
> 
> Hi All
> 
> I have started a little pet project to learn python and MySQL.  The
> project involves figuring out all the combinations for a 5 number
> lottery and storing the data in a MySQL file.
> 
> The file looks like this;
> +--+-+--+-+-
> ++
> | Field| Type| Null | Key | Default |
> Extra  |
> +--+-+--+-+-
> ++
> | lottryid | int(11) | NO   | PRI | NULL|
> auto_increment |
> | lottryno | char(10)| YES  | | NULL
> ||
> | no1  | tinyint(3) unsigned | NO   | | NULL
> ||
> | no2  | tinyint(3) unsigned | NO   | | NULL
> ||
> | no3  | tinyint(3) unsigned | NO   | | NULL
> ||
> | no4  | tinyint(3) unsigned | NO   | | NULL
> ||
> | no5  | tinyint(3) unsigned | NO   | | NULL
> ||
> | nosum| tinyint(3) unsigned | NO   | | NULL
> ||
> | nohits   | int(10) unsigned| YES  | | NULL
> ||
> +--+-+--+-+-
> ++
> 
> The code looks as follows;
> #!/usr/lib/env python
> 
> import MySQLdb
> import datetime
> 
> db = MySQLdb.Connection(host="localhost", user="lenyel",
> passwd="lsumnler", \
> db="lottery")
> 
> cursor = db.cursor()
> 
> cursor.execute('delete from littlelottery')
> 
> listofrec = []
> 
> tupcnt = 0
> print "first tuple created"
> for a in xrange(1,36):
> for b in xrange(2,37):
> for c in xrange(3,38):
> for d in xrange(4,39):
> for e in xrange(5,40):
> tupcnt += 1
> thekey = ('%02i%02i%02i%02i%02i' % (a,b,c,d,e))
> mysum = a + b + c + d + e
> rectuple = tupcnt, thekey, a, b, c, d, e, mysum, 0
> listofrec.append(rectuple)
> if tupcnt % 1 == 0:
> print "beginnign of mysql write"
> print datetime.datetime.now().time()
> cursor.executemany('''insert into
> littlelottery
> values (?,?,?,?,?,?,?,?,?)''', listofrec)
> db.close()
> print "end of mysql write"
> print datetime.datetime.now().time()
> os._exit()
> 
> print "insert into mysql completed"
> 
> i get the following error on insert;
> raise errorclass, errorvalue
> TypeError: not all arguments converted during string formatting
> Script terminated.
> 
> Do I have to covert all of the fields in the tuple records to string
> or what?
> 
> Len Sumnler
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

statement prepared first and executed many times with exectemany - db API 
http://www.python.org/dev/peps/pep-0249/ 
inline statemets can be exeucuted only.

hope that helps
Edwin



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: Newbie problem inserting into MySQL

2008-08-18 Thread Edwin . Madari


>  -Original Message-
> From: Madari, Edwin  
> Sent: Monday, August 18, 2008 3:03 PM
> To:   'len'; python-list@python.org
> Subject:  Re: Newbie problem inserting into MySQL
> 
> > -Original Message-
> > From: 
> [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED]
> > ython.org]
> > On Behalf Of len
> > Sent: Monday, August 18, 2008 11:55 AM
> > To: python-list@python.org
> > Subject: Newbie problem inserting into MySQL
> > 
> > 
> > Hi All
> > 
> > I have started a little pet project to learn python and MySQL.  The
> > project involves figuring out all the combinations for a 5 number
> > lottery and storing the data in a MySQL file.
> > 
> > The file looks like this;
> > +--+-+--+-+-
> > ++
> > | Field| Type| Null | Key | Default |
> > Extra  |
> > +--+-+--+-+-
> > ++
> > | lottryid | int(11) | NO   | PRI | NULL|
> > auto_increment |
> > | lottryno | char(10)| YES  | | NULL
> > ||
> > | no1  | tinyint(3) unsigned | NO   | | NULL
> > ||
> > | no2  | tinyint(3) unsigned | NO   | | NULL
> > ||
> > | no3  | tinyint(3) unsigned | NO   | | NULL
> > ||
> > | no4  | tinyint(3) unsigned | NO   | | NULL
> > ||
> > | no5  | tinyint(3) unsigned | NO   | | NULL
> > ||
> > | nosum| tinyint(3) unsigned | NO   | | NULL
> > ||
> > | nohits   | int(10) unsigned| YES  | | NULL
> > ||
> > +--+-+--+-+-
> > ++
> > 
> > The code looks as follows;
> > #!/usr/lib/env python
> > 
> > import MySQLdb
> > import datetime
> > 
> > db = MySQLdb.Connection(host="localhost", user="lenyel",
> > passwd="lsumnler", \
> > db="lottery")
> > 
> > cursor = db.cursor()
> > 
> > cursor.execute('delete from littlelottery')
> > 
> > listofrec = []
> > 
> > tupcnt = 0
> > print "first tuple created"
> > for a in xrange(1,36):
> > for b in xrange(2,37):
> > for c in xrange(3,38):
> > for d in xrange(4,39):
> > for e in xrange(5,40):
> > tupcnt += 1
> > thekey = ('%02i%02i%02i%02i%02i' % (a,b,c,d,e))
> > mysum = a + b + c + d + e
> > rectuple = tupcnt, thekey, a, b, c, d, 
> e, mysum, 0
> > listofrec.append(rectuple)
> > if tupcnt % 1 == 0:
> > print "beginnign of mysql write"
> > print datetime.datetime.now().time()
> > cursor.executemany('''insert into
> > littlelottery
> > values (?,?,?,?,?,?,?,?,?)''', listofrec)
> > db.close()
> > print "end of mysql write"
> > print datetime.datetime.now().time()
> > os._exit()
> > 
> > print "insert into mysql completed"
> > 
> > i get the following error on insert;
> > raise errorclass, errorvalue
> > TypeError: not all arguments converted during string formatting
> > Script terminated.
> > 
> > Do I have to covert all of the fields in the tuple records to string
> > or what?
> > 
> > Len Sumnler
> > --
> > http://mail.python.org/mailman/listinfo/python-list
> > 
> 
> statement prepared first and executed many times with 
> exectemany - db API http://www.python.org/dev/peps/pep-0249/ 
> inline statemets can be exeucuted only.
> 
> hope that helps
> Edwin

another thing - cumulative inserts will result, since listofrec is not emptied 
after each sql execution.

regards
Edwin



The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: who to call a list of method inside the class itself

2008-08-19 Thread Edwin . Madari

[EMAIL PROTECTED] wrote:
> Hi,
> 
> Is the following code is ok. who to call all method.
> It is working but the call to m() without a reference to self seems
> strange
> 
> Thanks for your help
> 
> class CustomMethod:
> def method1(self):
> 
> def method2(self):
> 
> def method3(self):
>
> 
> def getAllMethod(self):
> return [self.method1, self.method2, self.method3]
> 
> def applyAll(self):
> for m in self.getAllMethod():
> # how to call all methods ?
> # is it correct
> m()

1. return string names of required methods in getAllMethod
return ['method1', 'method2', 'method3']
2. use gettattr on self and then exetute methods in applyAll
def applyAll(self):
for method_name in self.getAllMethod():
    method = gettattr(self,method_name)
  method() #execute method now

regards.
Edwin   




The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: who to call a list of method inside the class itself

2008-08-19 Thread Edwin . Madari
[EMAIL PROTECTED] wrote:
> 
> [EMAIL PROTECTED] wrote:
> 
> > 1. return string names of required methods in getAllMethod
> > return ['method1', 'method2', 'method3']
> > 2. use gettattr on self and then exetute methods in applyAll
> > def applyAll(self):
> > for method_name in self.getAllMethod():
> > method = gettattr(self,method_name)
> >   method() #execute method now
> 
> why?

ensure instance's method invocation with all state information to that point, 
rather than relying on implemenation.

regards.
Edwin


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: urllib fails to connect

2008-08-20 Thread Edwin . Madari
jlist wrote:
>
> I found out why. I set a proxy in IE and I didn't know
> ActiveState Python use IE proxy!
> 
> > I'm running ActiveState Python 2.5 on Windows XP. It used
> > to work fine. Today however I get (10061, 'Connection refused')
> > for any site I try with urllib.urlopen().
> 

switching to urllib2, installing the proxy opener, worked for me. 
here is the sample. variable names are self explanatory

import urllib2
proxy=urllib2.ProxyHandler({"http":'http://'+proxyuser+':'+proxypass+'@'+httpproxy})
opener=urllib2.build_opener(proxy, urllib2.HTTPHandler)
urllib2.install_opener(opener)
req = urllib2.Request(url, form, headers)
fd = urllib2.urlopen(req)
print fd.code, fd.info(), fd.read()

regards
Edwin


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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


Re: cx_oracle and commands

2008-09-05 Thread Edwin . Madari
gaius hammond Wrote:
>Hi all,
>
>
>I am having a very strange problem with cx_Oracle, has anyone 
>seen this kind of behavior before:
>
>
>
>ActivePython 2.5.2.2 (ActiveState Software Inc.) based on
>Python 2.5.2 (r252:60911, Mar 27 2008, 18:53:24) [C] on sunos5
>Type "help", "copyright", "credits" or "license" for more information.
>>>> from commands import getstatusoutput
>>>> (status, output) = getstatusoutput('ls')
>>>> status
>0
>>>> from cx_Oracle import connect, SYSDBA
>>>> db = connect(mode=SYSDBA)
>>>> (status, output) = getstatusoutput('ls')
>Traceback (most recent call last):
>  File "", line 1, in 
>  File "/opt/ASpy25/lib/python2.5/commands.py", line 55, in 
>getstatusoutput
>sts = pipe.close()
>IOError: [Errno 10] No child processes
>
>
>
>Basically, once I have made a connection to Oracle I can no 
>longer use getstatusoutput(). This is a real problem as
>I need to get a list of things to work on from Oracle then 
>spawn commands to process them...
>
>
>Thanks,
>

There is no mode parameter to connect. use try-catch around 
db = connect(mode=SYSDBA) line to see what's going on.
 

Edwin 


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.


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