Binding a variable?

2005-10-21 Thread Paul Dale

Hi everyone,

Is it possible to bind a list member or variable to a variable such that

temp = 5

list = [ temp ]

temp == 6

list

would show

list = [ 6 ]

Thanks in advance?

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


Re: Binding a variable?

2005-10-24 Thread Paul Dale

Thanks everyone for your comments and suggestions!

I haven't quite decided which approach I'll take, but it's nice to have 
some options.

Paul

Tom Anderson wrote:

>On Fri, 21 Oct 2005, Paul Dale wrote:
>
>  
>
>>Is it possible to bind a list member or variable to a variable such that
>>
>>temp = 5
>>list = [ temp ]
>>temp == 6
>>list
>>
>>would show
>>
>>list = [ 6 ]
>>
>>
>
>As you know by now, no. Like any problem in programming, this can be 
>solved with a layer of abstraction: you need an object which behaves a bit 
>like a variable, so that you can have multiple references to it. The 
>simplest solution is to use a single-element list:
>
>  
>
>>>>temp = [None] # set up the list
>>>>temp[0] = 5
>>>>list = [temp]
>>>>temp[0] = 6
>>>>list
>>>>
>>>>
>[[6]]
>
>I think this is a bit ugly - the point of a list is to hold a sequence of 
>things, so doing this strikes me as a bit of an abuse.
>
>An alternative would be a class:
>
>class var:
>   def __init__(self, value=None):
>   self.value = value
>   def __str__(self): # not necessary, but handy
>   return "<<" + str(self.val) + ">>"
>
>  
>
>>>>temp = var()
>>>>temp.value = 5
>>>>list = [temp]
>>>>temp.value = 6
>>>>list
>>>>
>>>>
>[<<6>>]
>
>This is more heavyweight, in terms of both code and execution resources, 
>but it makes your intent clearer, which might make it worthwhile.
>
>tom
>
>  
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Redirect os.system output

2005-10-25 Thread Paul Dale

You might want to try python expect which gives you a very simple and 
scriptable interface to a process.

http://pexpect.sourceforge.net/

I've been using it on windows to automate a few things.

Cheers,

Paul

jas wrote:

>Kent,
>  Yes, your example does work.  So did os.popen...however, the problem
>is specific to "cmd.exe".
>   Have you tried that yet?
>
>Thanks!
>
>Kent Johnson wrote:
>  
>
>>jas wrote:
>>
>>
>>>Ok, I tried this...
>>>
>>>C:\>python
>>>Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
>>>on win32
>>>Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>  
>>>
>>import subprocess as sp
>>p = sp.Popen("cmd", stdout=sp.PIPE)
>>
>>result = p.communicate("ipconfig")
>>
>>
>>>'result' is not recognized as an internal or external command,
>>>operable program or batch file.
>>>
>>>
>>>
>>>basically I was opening to send the "ipconfig" command to cmd.exe and
>>>store the result in the "result" variable.  But you can see there was
>>>an error with result.
>>>  
>>>
>>This works for me:
>>import subprocess as sp
>>p = sp.Popen("ipconfig", stdout=sp.PIPE)
>>result = p.communicate()[0]
>>print result
>>
>>Kent
>>
>>
>
>  
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Redirect os.system output

2005-10-25 Thread Paul Dale

pexpect is POSIX compliant and works under Cygwin. I haven't tried it 
under pythonw.

Just install cgywin (including python) then follow the standard 
instructions for pexpect.

There was one small trick I had to do to get cygwin working totally 
properly on my machine which was run a rebaseall.

Rebaseall sets the memory addresses for the DLLs or something like that.

However, there is a slight problem. The rebaseall runs inside cygwin and 
uses one of the DLLs. To get around this I change the rebaseall script 
to write it's command to a text file and then  run those commands in a 
DOS cmd shell. After that everything has worked without problem.


Good luck,

Paul

jas wrote:

>Paul,
>   I did ceck out the PExpect, however, I thought it was not ported for
>Windows.  Did you find a ported version?  If not, what did you have to
>do to be able to use it?
>
>Thanks
>
>Paul Dale wrote:
>  
>
>>You might want to try python expect which gives you a very simple and
>>scriptable interface to a process.
>>
>>http://pexpect.sourceforge.net/
>>
>>I've been using it on windows to automate a few things.
>>
>>Cheers,
>>
>>Paul
>>
>>jas wrote:
>>
>>
>>
>>>Kent,
>>> Yes, your example does work.  So did os.popen...however, the problem
>>>is specific to "cmd.exe".
>>>  Have you tried that yet?
>>>
>>>Thanks!
>>>
>>>Kent Johnson wrote:
>>>
>>>
>>>  
>>>
>>>>jas wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>Ok, I tried this...
>>>>>
>>>>>C:\>python
>>>>>Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
>>>>>on win32
>>>>>Type "help", "copyright", "credits" or "license" for more information.
>>>>>
>>>>>
>>>>>
>>>>>  
>>>>>
>>>>>>>>import subprocess as sp
>>>>>>>>p = sp.Popen("cmd", stdout=sp.PIPE)
>>>>>>>>
>>>>>>>>result = p.communicate("ipconfig")
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>'result' is not recognized as an internal or external command,
>>>>>operable program or batch file.
>>>>>
>>>>>
>>>>>
>>>>>basically I was opening to send the "ipconfig" command to cmd.exe and
>>>>>store the result in the "result" variable.  But you can see there was
>>>>>an error with result.
>>>>>
>>>>>
>>>>>  
>>>>>
>>>>This works for me:
>>>>import subprocess as sp
>>>>p = sp.Popen("ipconfig", stdout=sp.PIPE)
>>>>result = p.communicate()[0]
>>>>print result
>>>>
>>>>Kent
>>>>   
>>>>
>>>>
>>>>
>>> 
>>>
>>>  
>>>
>
>  
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml.dom.minidom - parseString - How to avoid ExpatError?

2005-10-28 Thread Paul Dale

Hi Greg,

Not really an answer to your question but I've found 4Suite ( 
http://4suite.org/index.xhtml ) quite useful for my XML work and the 
articles linked to from there authored by Uche Ogbuji to be quite 
informative.

Best,

Paul

Gregory PiƱero wrote:

> Thanks, John.  That was all very helpful.  It looks like one option 
> for me would be to put cdata[ around my text with all the weird 
> characters.  Otherwise running it through on of the SAX utilities 
> before parsing might work.
>
> I wonder if the sax utilities would give me a performance hit.  I have 
> 6000 xml files to parse at 100KB each.
>
> -Greg
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: up to date books?

2005-08-18 Thread Paul Dale

I highly recommend the "Safari" library service from Oreilly ( 
http://safari.oreilly.com ) you can check out all of the books listed 
below and about 10,000 more. The library contains much more than just 
Oreilly's books, but they are, of course, all in there.

The first 2 weeks is free after that it's $20/month. You can check out 
10 books at a time and you have to keep them for a month. You can 
download chapters, print pages, and search all the books in the library, 
as well as search across books you've checked out.

It's a great way to get access to a broad range of technical books.

One thing to be careful of. As the old books are there too it's possible 
to grab a first version when you might want a second or third version. 
Always list by date and make sure you're looking at the new stuff.

Cheers,

Paul

Adriaan Renting wrote:

>I learned Python from the "Learning Python" book that's first on Alessandros 
>list. If you have the Second Edition, that includes coverage for Python 2.3, I 
>think you have quite a nice introductory book.
>As a reference book "Python in a Nutshell" and of course the Python 
>documentation itself are quite good.
>
>Adriaan
> 
> 
>  
>
Alessandro Bottoni <[EMAIL PROTECTED]> 08/18/05 9:02 am >>> 


>John Salerno wrote: 
> 
>  
>
>>hi all. are there any recommendations for an intro book to python that 
>>is up-to-date for the latest version? 
>>
>>
> 
>I do not know how much up-to-date they are but I have to suggest you these 
>books: 
> 
>- Learning Python 
>By Mark Lutz and David Ascher 
>published by O'Reilly 
>Most likely the best introductory book on Python 
> 
>- Python Cookbook 
>By Alex Martelli and David Ascher 
>published by O'Reilly 
>By far the most useful book on Python after your first week of real use of 
>this language 
> 
>Also, the fundamental 
>- Programming Python (the 2nd edition ONLY) 
>By Mark Lutz 
>published by O'Reilly 
>Is very useful for understanding the most inner details of Python 
> 
>  
>
>>would reading a book from a year or two ago cause me to miss much? 
>>
>>
> 
>No. Python did not changed too much since rel. 1.5. You can still use a book 
>published in 2001 as a introductory book (as I do). The changes are 
>exhaustively described both in the official documentation and in the very 
>fine "what's new in..." articles written by Andrew Kuchlin for every new 
>release (see www.python.org). 
> 
>CU 
> 
>--- 
>Alessandro Bottoni 
>  
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Nested Regex Conditionals

2005-08-23 Thread Paul Dale

Hi All,

I know that several of you will probably want to reply "you should write 
a parser", and I may. For that matter any tips on theory in that 
direction would be appreciated.

However, if you would indulge me in my regex question I would also be 
most grateful.

I'm writing an edi parser and to be in compliance with the specification 
I need to have conditionals that are dependent on conditionals. In some 
regular expression implementations this is possible. The code ...

#!/usr/bin/env python
import re
pattern = re.compile(r"""
(?P(first))
  (?(first)
(?P(second))
  )
  (?(second)
(?P(third))
  )
  """, re.VERBOSE)
string = 'firstsecondthird'
match = re.match(pattern,string)
print match.group('first','second','third')

Prints ('first', 'second', None)

and I haven't found any way to have a second conditional, nor any 
reference to it in any documentation I've found.

Am I missing something, and it is possible? Or is it not possible in python?

It seems like it might be a bug, as it knows there is a group (None, 
instead of an IndexError), but it doesn't match ...

Thanks for any help :)

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


Re: Should I move to Amsterdam?

2005-08-25 Thread Paul Dale

>But yes, the Netherlands is a highly civilised country - up there with 
>Denmark and Canada, and above the UK, France or Germany, IMNERHO. I'm not 
>going to bother comparing it to the US!
>  
>
How strange that you put Canada so high on your list.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to tell if an exception has been caught ( from inside the exception )?

2005-09-22 Thread Paul Dale

Hi everyone,

I'm writing an exception that will open a trouble ticket for certain 
events. Things like network failure. I thought I would like to have it 
only open a ticket if the exception is not caught. Is there a way to do 
this inside the Exception? As far as I can see there are only two events 
called on the exception, __init__ and __del__, both of which will be 
called wether or not an exception is caught (right?)

Am I missing something, or is there a way to do this with exceptions?

Thanks!

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


Re: Checking function calls

2006-03-06 Thread paul . dale
I will be out of the office from March 3rd to March 31st.
In urgent cases please contact [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list