Re: OT: novice regular expression question

2004-12-31 Thread It's me
Oops!

Sorry, didn't realize that.

Thanks,

"M.E.Farmer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> It's me wrote:
> > The shlex.py needs quite a number of .py files.  I tried to hunt down
> a few
> > of them and got really tire.
> >
> > Is there one batch of .py files that I can download from somewhere?
> >
> > Thanks,
> Not sure what you mean by this.
> Shlex is a standard library module.
> It imports os and sys only, they are standard library modules.
> If you have python you have them already.
> If you mean cStringIO it is in the standard library(at least on my
> system).
> You dont have to use it just feed shlex an open file.
> py>lexer = shlex.shlex(open('myrecord.txt', 'r'))
>
> Hth,
> M.E.Farmer
>


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


Re: Parsing a search string

2004-12-31 Thread It&#x27;s me
I am right in the middle of doing text parsing so I used your example as a
mental exercise.   :-)

Here's a NDFA for your text:

   b  0 1-9 a-Z ,  . +  -   '   " \n
S0: S0 E   E  S1  E E E S3 E S2  E
S1: T1 E   E  S1  E E E  E  E  E T1
S2: S2 E   E  S2  E E E  E  E T2  E
S3: T3 E   E  S3  E E E  E  E  E T3

and the end-states are:

E: error in text
T1: You have the words: moo, cow
T2: You get "farmer john" (w quotes)
T3: You get zug

Can't gurantee that I did it right - I did it really quick - and it's
*specific* to your text string.

Now just need to hire a programmer to write some clean Python parsing code.
:-)

--
It's me





"Freddie" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Happy new year! Since I have run out of alcohol, I'll ask a question that
I
> haven't really worked out an answer for yet. Is there an elegant way to
turn
> something like:
>
>  > moo cow "farmer john" -zug
>
> into:
>
> ['moo', 'cow', 'farmer john'], ['zug']
>
> I'm trying to parse a search string so I can use it for SQL WHERE
constraints,
> preferably without horrifying regular expressions. Uhh yeah.
>
>  From 2005,
>Freddie
>



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


Re: Parsing a search string

2004-12-31 Thread It&#x27;s me

"Andrew Dalke" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "It's me" wrote:
> > Here's a NDFA for your text:
> >
> >b  0 1-9 a-Z ,  . +  -   '   " \n
> > S0: S0 E   E  S1  E E E S3 E S2  E
> > S1: T1 E   E  S1  E E E  E  E  E T1
> > S2: S2 E   E  S2  E E E  E  E T2  E
> > S3: T3 E   E  S3  E E E  E  E  E T3
>
> Now if I only had an NDFA for parsing that syntax...
>

Just finished one (don't ask me to show it - very clumpsy Python code -
still in learning mode).   :)

Here's one for parsing integer:

#   b 0 1-9 , . + - ' " a-Z \n
# S0: S0 S0 S1 T0 E S2 S2 E E E   T0
# S1: S3 S1 S1 T1 E E E E E E   T1
# S2: E S2 S1 E E E E E E E   E
# S3: S3 T2 T2 T1 T2 T2 T2 T2 T2 T2  T1

T0: you got a null token
T1: you got a good token, separator was ","
T2: you got a good token b, separator was " "
E: bad token


>   :)
> Andrew
> [EMAIL PROTECTED]
>


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


Re: Parsing a search string

2004-12-31 Thread It&#x27;s me

"John Machin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Andrew Dalke wrote:
> > "It's me" wrote:
> > > Here's a NDFA for your text:
> > >
> > >b  0 1-9 a-Z ,  . +  -   '   " \n
> > > S0: S0 E   E  S1  E E E S3 E S2  E
> > > S1: T1 E   E  S1  E E E  E  E  E T1
> > > S2: S2 E   E  S2  E E E  E  E T2  E
> > > S3: T3 E   E  S3  E E E  E  E  E T3
> >
> > Now if I only had an NDFA for parsing that syntax...
>
> Parsing your sentence as written ("if I only had"): If you were the
> sole keeper of the secret??
>
> Parsing it as intended ("if only I had"), and ignoring the smiley:
> Looks like a fairly straight-forward state-transition table to me.

Exactly.

> The
> column headings are not aligned properly in the message, b means blank,
> a-Z is bletchworthy, but the da Vinci code it ain't.
>
> If only we had an NDFA (whatever that is) for guessing what acronyms
> mean ...
>

I believe  (I am not a computer science major):

NDFA = non-deterministic finite automata

and:

S: state
T: terminal
E: error

So, S1 means State #1..T1 means Terminal #1, so forth

You are correct that parsing that table is not hard.

a) Set up a stack and place the buffer onto the stack, start with S0
b) For each character that comes from the stack, looking up the next state
for that token
c) If it's not a T or E state, jump to that state
d) If it's a T or E state, finish


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


Re: arbitrary number of arguments in a function declaration

2005-01-02 Thread it&#x27;s me
And in case it's not obvious already, you get the number of arguments that
got passed down from:

len(args)

"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> rbt wrote:
> > How do I set up a function so that it can take an arbitrary number of
> > arguments? For example, I have a bunch of expenses which may grow or
> > shrink depending on the client's circumstance and a function that sums
> > them up... hard coding them is tedious. How might I make this dynamic so
> > that it can handle any amount of expenses?
> >
> > def tot_expenses(self, e0, e1, e2, e3):
> > pass
>
> The Python Tutorial is a wonderful thing. . .
>
> Anyway, you can either set up your function to take a proper list, and
then
> discover that the sum function already exists to add up the contents of a
list:
>
> def tot_expenses(self, expenses):
>self.total_expenses = sum(expenses)
>
> Or, have the function take a variable number of arguments, and do the same
thing:
>
> def tot_expenses(self, *args):
>self.total_expenses = sum(args)
>
> Cheers,
> Nick.
>
> -- 
> Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
> ---
>  http://boredomandlaziness.skystorm.net


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


Re: Developing Commercial Applications in Python

2005-01-03 Thread It&#x27;s me
Shaw-PTI (www.pti-us.com) uses Python in their software.   See:
http://www.pti-us.com/pti/news/index.cfm and search "2004 PSS/E User Group
Meeting"

<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello All,
> I am trying to convince my client to use Python in his new product. He
> is worried about the license issues. Can somebody there to point me any
> good commercial applications developed using python ?. The licence
> clearly says Python can be used for commercial applications. Is there
> any other implications like that of GPL to make the source open ?
> Thanks for any help.
> eeykay
>


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


Re: Developing Commercial Applications in Python

2005-01-03 Thread It&#x27;s me

"Richards Noah (IFR LIT MET)" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> Begging your pardon, but a better resource would be the brochure available
> (http://www.pti-us.com/PTI/company/brochures/PSSE.pdf).  It appears that
the
> program was probably (originally) written in C/C++ (using MFC for the
GUI),
> and now employs Python for adding modules and scripting support.  Very
> interesting stuff :)
>
>

It was actually developed in Fortran some 35 years ago.   Then migrated to
F77.   Then added a C/C++ layer to sit ontop.   Then converted to API based.
Then added a Python layer on top.

The only thing unfortunate is that they went with MFC on the newest version.
Yuck!


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


Re: Developing Commercial Applications in Python

2005-01-03 Thread It&#x27;s me
Well, now that they are API based, they can easily add any script language
they so wish through SWIG (www.swig.org).

Maybe not LISP.   SNOBOL would be the right thing to do.  (*NOT*)


"Richards Noah (IFR LIT MET)" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
>
> > It was actually developed in Fortran some 35 years ago.   Then migrated
to
> > F77.   Then added a C/C++ layer to sit ontop.   Then converted to API
> based.
> > Then added a Python layer on top.
> >
> > The only thing unfortunate is that they went with MFC on the newest
> version.
> > Yuck!
> >
>
> Hahaha, sounds like a party to me.  And they didn't even throw in a layer
of
> Lisp for good effort?  Too bad, if you ask me :)
>
>


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


Hlelp clean up clumpsy code

2005-01-03 Thread It&#x27;s me
Another newbie question.

There must be a cleaner way to do this in Python:

 section of C looking Python code 
a = [[1,5,2], 8, 4]
a_list = {}
i = 0
for x in a:
if isinstance(x, (int, long)):
x = [x,]
for w in [y for y in x]:
i = i + 1
a_list[w] = i
print a_list
#

The code prints what I want but it looks so "C-like".  How can I make it
more Python like?

Thanks,



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


Re: Hlelp clean up clumpsy code

2005-01-04 Thread It&#x27;s me
Thanks, Steve and Nick.

Yes, that's what I need to do.   I didn't know it's call "flattening" a list
structure but that's precisely what I needed to do.

Steve,

I am using 2.3 and so I will go with Nick's version.

Thanks to both for helping.


"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> > Another newbie question.
> >
> > There must be a cleaner way to do this in Python:
> >
> >  section of C looking Python code 
> > a = [[1,5,2], 8, 4]
> > a_list = {}
> > i = 0
> > for x in a:
> > if isinstance(x, (int, long)):
> > x = [x,]
> > for w in [y for y in x]:
> > i = i + 1
> > a_list[w] = i
> > print a_list
> > #
> >
> > The code prints what I want but it looks so "C-like".  How can I make it
> > more Python like?
>
> Firstly, calling your dictionary "a_list" is evil. . .
>
> Secondly, explaining what you want the code to do in English is handy when
> asking for help cleaning up code (since we then know which features are
> deliberate, and which are accidental implementation artificacts).
>
> If I'm reading the code correctly, you want to flatten a data structure
which
> may contain either substructures or actual elements.
>
> A custom generator will do nicely:
>
> Py> def flatten(seq):
> ...   for x in seq:
> ... if hasattr(x, "__iter__"):
> ...   for y in flatten(x):
> ... yield y
> ... else:
> ...   yield x
> ...
> Py> data = [[1,5,2],8,4]
> Py> val_to_pos = {}
> Py> for i, x in enumerate(flatten(data)):
> ...   val_to_pos[x] = i + 1
> ...
> Py> print val_to_pos
> {8: 4, 1: 1, 2: 3, 4: 5, 5: 2}
>
> Not any shorter, but this version works correctly for any leaf elements
which
> don't supply __iter__ (e.g. strings), and internal elements which do (e.g.
> tuples) and the depth is limited only by the maximum level of recursion.
Don't
> try to flatten a circular structure, though :)
>
> You may not even need to write the generator, since if you have Tkinter,
that
> already supplies a near-equivalent function:
>
> Py> from Tkinter import _flatten as flatten
> Py> data = [[1,5,2],8,4]
> Py> val_to_pos = {}
> Py> for i, x in enumerate(flatten(data)):
> ...   val_to_pos[x] = i + 1
> ...
> Py> print val_to_pos
> {8: 4, 1: 1, 2: 3, 4: 5, 5: 2}
>
> It even works with strings as leaf elements:
>
> Py> data = [["abc","def",2],8,"xyz"]
> Py> flatten(data)
> ('abc', 'def', 2, 8, 'xyz')
>
> Cheers,
> Nick.
>
> -- 
> Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
> ---
>  http://boredomandlaziness.skystorm.net


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


Re: Hlelp clean up clumpsy code

2005-01-04 Thread It&#x27;s me
What's "LBYL"?  Oh...Look-before-you-leap.  OK.

I think I understand what's going on now (I read up on generator and
iterators and my head still hurts).  I knew there must be a cleaner way of
"walking" around in Python.  I will experiment with generator more.

Thanks everybody.


"Jp Calderone" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
>
> On Tue, 04 Jan 2005 08:18:58 -0800, Scott David Daniels
<[EMAIL PROTECTED]> wrote:
> >Nick Coghlan wrote:
> > > A custom generator will do nicely:
> > >
> > > Py> def flatten(seq):
> > > ...   for x in seq:
> > > ... if hasattr(x, "__iter__"):
> > > ...   for y in flatten(x):
> > > ... yield y
> > > ... else:
> > > ...   yield x
> >
> > Avoiding LBYL gives you:
> >  def flatten(seq):
> >  for x in seq:
> >  try:
> >  for y in flatten(x):
> >  yield y
> >  except TypeError:
> >  yield x
>
>   But totally messes up on error handling.  Instead:
>
> def flatten(seq):
> for x in seq:
> try:
> subseq = iter(x)
> except TypeError:
> yield x
> else:
> for subx in flatten(subseq):
> yield subx
>
>   to avoid catching TypeErrors from .next().
>
>   Jp


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


Re: Python 2.4 on Windows XP

2005-01-05 Thread It&#x27;s me
I am running 2.3 and it's doing the same thing on my computer - except that
I can't even get it to start from the command prompt.

It used to work but after I switched back and forth between 2.3, and 2.4 and
somewhere in between, it stopped working.

I hope somebody on the list would have a clue how to fix this.


"DavidHolt" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I have a problem that I see on two different machines, one running XP
> SP1 and one XP SP 2.
>
> On both I installed Python 2.4.
>
> I can't seem to start IDLE. When I try to start it, I get an hourglass
> cursor for a short time then nothing more happens. This happens whether
> I click the IDLE shortcut or click the pythonw.exe directly, or attempt
> to launch pythonw from a command line.
>
> I don't have any trouble running the python command line version.
>
> Any ideas?
> Thanks,
> David Holt
> Software Developer
> HighJump Software, a 3M Company
>


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


win32com.client problem

2005-01-05 Thread It&#x27;s me
I've been using the win32com module with very good success in placing data
onto an Excel spreadsheet.  However, whenever I have an error in my script
(like mapping a non-square array onto the spreadsheet), something breaks.
After fixing my error and restart the Python program again, Excel would
start up a window with a "Microsoft Excel - BookX" where X is a increasing
number (1,2,3,4,) instead of just 1.  Then, the spreadsheet portion of
the screen is hidden - I can only see the menu bars (on top).

If I restart the computer, run the Python script again and Excel would
behave fine and it would start with "Microsoft Excel - Book1" everytime.

My guess is that there is a zombie Excel process that got stuck in the
system.  However I couldn't tell for sure by looking at the Process Manager
list.

Any idea how I can prevent this?

Thanks,

--
Me


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


Re: win32com.client problem

2005-01-05 Thread It&#x27;s me
Thanks for the reply.  I will chew on this a bit.

"Kartic" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> 1. Put your COM invokations in a try/except loop. From my experience,
> that helped me prevent, in most cases, Excel from "hanging" and having
> to restart the PC too. In the except part, release the Excel (or other
> COM resource) (e.g.calling workbook.Close() or excelobj.Quit(),
> depending on the state of your program)
>
> 2. Look at
> http://www.faqts.com/knowledge_base/entry/versions/index.phtml?aid=5847
> to see how to get the actual error.
>
> 3. Delete instances of the COM connection, RS object or whatever
> win32com.client instances you create. I do this:
> sheetobj = None
> wbkbobj = None
> excelobj = None
> del sheetobj
> del wbkobj
> del excelobj
>
> 4. At the end of my scripts, I do the following during the development
> stage:
> ActiveComConn = pythoncom._GetInterfaceCount()
> print 'Done! Active Com Connections :',ActiveComConn # Print count of
> Active COM connections.
>
> Thank you,
> --Kartic
>


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


Re: Python 2.4 on Windows XP

2005-01-05 Thread It&#x27;s me
In my case, there is *no* error message of any kind.  When I run pythonw.exe
from the python23 directory, the screen blinked slightly and goes back to
the command prompt.

"Jeff Shannon" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> DavidHolt wrote:
>
> > I have a problem that I see on two different machines, one running XP
> > SP1 and one XP SP 2.
> >
> > On both I installed Python 2.4.
> >
> > I can't seem to start IDLE. When I try to start it, I get an hourglass
> > cursor for a short time then nothing more happens. This happens whether
> > I click the IDLE shortcut or click the pythonw.exe directly, or attempt
> > to launch pythonw from a command line.
>
> Maybe I'm misinterpreting you, here, but pythonw.exe is *not* IDLE.
> It is, instead, a console-less version of the Python interpreter,
> which can run the Python scripts for IDLE (among other things).
>
> My version of Python is older, but in %pythondir%/Tools/idle, there is
> an idle.pyw file.  Try running that.  If it doesn't work, then copy &
> paste any error messages (you'll probably need to run it from a
> command line for this) to your next post here so that we can try to
> troubleshoot a bit more effectively.
>
> Jeff Shannon
> Technician/Programmer
> Credit International
>
>
>


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


Re: Python 2.4 on Windows XP

2005-01-05 Thread It&#x27;s me
Thanks, Jeff.

That works.


"Jeff Shannon" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
>
> > In my case, there is *no* error message of any kind.  When I run
pythonw.exe
> > from the python23 directory, the screen blinked slightly and goes back
to
> > the command prompt.
>
> Right -- pythonw.exe is a console-less interpreter.  Having no
> console, it doesn't have an interactive mode, and since you didn't
> give it a script to run, it simply started, found nothing to do, and
> then terminated itself.
>
> You need to run idle.pyw, *not* pythonw.exe.  The idle.pyw script runs
> inside the pythonw.exe interpreter, but the latter can't do anything
> without instructions.
>
> Jeff Shannon
> Technician/Programmer
> Credit International
>


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


Another PythonWin Excel question

2005-01-05 Thread It&#x27;s me
I followed the example in
http://stompstompstomp.com/weblog/technical/2004-05-20 and learned that to
add a new worksheet to an Excel workbook, you would use the
workbook.Worksheets.Add() method.   That works.   However, the new worksheet
got added *in front* of the last worksheet I was at.   How can I get it to
add *after*?

Thanks,

--
Me


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


Re: Another PythonWin Excel question

2005-01-05 Thread It&#x27;s me

"Kartic" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I am not sure about this but I believe you can give a parameter
> after="sheet1". to Add(), like so, Add(after="sheet1").
>

I get a "got an expected keyword argument 'after'" from Add().

> Unfortunately I do not have Excel installed on this machine to confirm
> this.
>
> A tip: if you have VBA (which you should if you have Excel) installed,
> lookup the Add method for the Worksheets collection. VBA will show the
> code completion, with all the arguments for the method call. Try the
> same for any of the methods.
>

Yes, I read about that but unfortunately I have no experience with VBA *at
all*.  :=(

> Thanks,
> --Kartic
>


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


Re: Another PythonWin Excel question

2005-01-05 Thread It&#x27;s me
Ah, this work:

self.xlbook.Worksheets.Add(None,sht)

got it from:

http://mail.python.org/pipermail/python-list/2003-September/183367.html

Thanks again.

--
Me


"It's me" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> "Kartic" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > I am not sure about this but I believe you can give a parameter
> > after="sheet1". to Add(), like so, Add(after="sheet1").
> >
>
> I get a "got an expected keyword argument 'after'" from Add().
>
> > Unfortunately I do not have Excel installed on this machine to confirm
> > this.
> >
> > A tip: if you have VBA (which you should if you have Excel) installed,
> > lookup the Add method for the Worksheets collection. VBA will show the
> > code completion, with all the arguments for the method call. Try the
> > same for any of the methods.
> >
>
> Yes, I read about that but unfortunately I have no experience with VBA *at
> all*.  :=(
>
> > Thanks,
> > --Kartic
> >
>
>


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


Re: Another PythonWin Excel question

2005-01-06 Thread It&#x27;s me

"Marten Bauer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> I did it yesterday like this way and it works well (part of my code):
>
>  wb.Worksheets.Add(Count=nrMonths,After=wb.Worksheets(1))
>

> As I read in MSDN you could not write After="sheet1" instead you must
> use the Object of sheet1 like in my example and it works well in my
> case. The Count=... statement will create n Sheets after the first
worksheet
>

Yes, I learn that as well.  The parameter to After is a Worksheet object.
It appears if you don't specify any parameters, it would add it Before the
current sheet.

Thanks,


>
> By
> Marten


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


Re: Another PythonWin Excel question

2005-01-06 Thread It&#x27;s me
Thanks,

"David Bolen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "It's me" <[EMAIL PROTECTED]> writes:
>
> > Yes, I read about that but unfortunately I have no experience with VBA
*at
> > all*.  :=(
>
> You don't really have to know VBA, but if you're going to try to
> interact with COM objects from Python, you'll find it much smoother if
> you at least use any available reference information for the COM
> object model and interfaces you are using.
>
> In the Excel case, that means understanding - or at least knowing how
> to look in a reference - its object model, since that will tell you
> exactly what parameters an Add method on a worksheet object will take
> and how they work.
>
> For excel, online documentation can be found in a VBAXL9.CHM help file
> (the "9" may differ based on Excel release), but it might not always
> be installed depending on what options were selected on your system.  In
> my English, Office 2000 installation, for example, the files are located
in:
> c:\Program Files\Microsoft Office\Office\1033
>
> You can load that file directly, or Excel itself will reference it
> from within the script editor help (Tools->Macro->Visual Basic Editor,
> then F1 for help).  If you methods or classes and have the help
> installed it'll bring in the reference.
>
> You can also find it on MSDN on the web, although it can be tricky to
> navigate down to the right section - the top of the Office 2000 object
> documentation should be available at:
>
>
http://msdn.microsoft.com/library/en-us/odeomg/html/deovrobjectmodelguide.asp
>
> This is mostly reference information, but there are some higher level
> discussions of overall objects (e.g., worksheets, workbooks, cells,
> etc...) too.
>
> -- David


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


Re: Another PythonWin Excel question

2005-01-06 Thread It&#x27;s me
Yes, Mike,

Others pointed that out as well.

The difficulty is that they are all in VBAs.   Most of them can be
translated to Python fairly easily, and some I can get from looking at the
recorded macro - but some requires quite a bit of head scratching.

For instance, I wanted to figure out how create a new window.   So, I went
through the record macro process and looked at the VBA code,  it says:

ActiveWindow.NewWindow

Okay.  Now what???

And for switching window, it says:

Windows("Book1:1").Activate

Okay.  ???

So, I look through the online information on msdn and viola!  No mentioning
of that anwhere

Would be nice if there's a Python specific of itbut just dreaming...

Back to reading MSDN.

Thanks,


"Mike Thompson"  wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> > I followed the example in
> > http://stompstompstomp.com/weblog/technical/2004-05-20 and learned that
to
> > add a new worksheet to an Excel workbook, you would use the
> > workbook.Worksheets.Add() method.   That works.   However, the new
worksheet
> > got added *in front* of the last worksheet I was at.   How can I get it
to
> > add *after*?
> >
> > Thanks,
> >
> > --
> > Me
> >
> >
>
> Does this help?
>
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_wrcore/html/wrtskhowtomoveworksheetswithinworkbooks.asp
>
> --
> Mike


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


Re: Another PythonWin Excel question

2005-01-06 Thread It&#x27;s me
Okay, thanks.  That helps a lot.

"Mike Thompson"  wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> > Yes, Mike,
> >
> > Others pointed that out as well.
>
> For good reason.
>
> >
> > The difficulty is that they are all in VBAs.   Most of them can be
> > translated to Python fairly easily, and some I can get from looking at
the
> > recorded macro - but some requires quite a bit of head scratching.
> >
> > For instance, I wanted to figure out how create a new window.   So, I
went
> > through the record macro process and looked at the VBA code,  it says:
> >
> > ActiveWindow.NewWindow
>
> app.ActiveWindow.NewWindow()
>
> >
> > Okay.  Now what???
> >
> > And for switching window, it says:
> >
> > Windows("Book1:1").Activate
>
> app.Windows.Item("Book1:1").Activate()
>
> -
>
> from win32com.client import Dispatch, constants
>
> app = Dispatch("Excel.Application")
> app.Visible = True
>
> workbook = app.Workbooks.Add()
>
> defaultWorksheet = workbook.Worksheets(1)
>
> app.ActiveWindow.NewWindow()
> app.ActiveWindow.NewWindow()
>
> # grab the capation (like 'Book1:1') from one of the windows
> thridWindowsCaption = app.Windows[2].Caption
>
> print thridWindowsCaption
> app.Windows.Item(thridWindowsCaption).Activate()
>
> 
>
> Sometimes its useful to look in the file generated by makepy. It details
> all the classes and their methods AND there are annotations in the form
> of comments.  Having said that, if you've never looked in a makepy
> generated module before, you're in for a shock -  it takes a while
> before you figure out what you are looking at.
>
> When you get stuck, trial & error and a good debuger are your friend.
>
> --
> Mike


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


Re: sorting on keys in a list of dicts

2005-01-07 Thread It&#x27;s me
What does it mean by "stability in sorting"?

Can somebody please give a sample for using the code posted?  I am a little
lost here and I like to know more about the use of keys

Thanks,

"Nick Coghlan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Jeff Shannon wrote:
> > I suppose that your version has the virtue that, if the sortkey value is
> > equal, items retain the order that they were in the original list,
> > whereas my version will sort them into an essentially arbitrary order.
> >  Is there anything else that I'm missing here?
>
> Stability in sorting is a property not to be sneezed at - it means
switching to
> sorting by a second key gives the effect of "sort by key 1, then by key
2",
> whereas that doesn't hold with an unstable sort algorithm. If you've ever
used
> an application with an unstable sorting process and that only allows
sorting a
> table on one column at a time, you'll appreciate the frustration that can
cause :)
>
> Also, it's required to match the behaviour of the Python 2.4 version
(which gets
> to take advantage of the stability of the builtin sort).
>
> Cheers,
> Nick.
>
> -- 
> Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
> ---
>  http://boredomandlaziness.skystorm.net


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


Re: else condition in list comprehension

2005-01-09 Thread It&#x27;s me
> z = [i + (2, -2)[i % 2] for i in range(10)]

But then why would you want to use such feature?  Wouldn't that make the
code much harder to understand then simply:

z=[]
for i in range(10):
if  i%2:
z.append(i-2)
else:
z.append(i+2)

Or are we trying to write a book on "Puzzles in Python"?


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


Re: complex numbers

2005-01-10 Thread It&#x27;s me
For those of us that works with complex numbers, having complex number as a
natively supported data type is a big advantage.  Non-native add-ons are not
sufficient and lead to very awkward program code.


"Jürgen Exner" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> [EMAIL PROTECTED] wrote:
> > #python supports complex numbers.
> [...]
>
> So?
>

The world would come to a halt if all of a sudden nobody understands complex
numbers anymore.  :-)

> > # Perl doesn't support complex numbers. But there are packages that
> > supports it.
>
> The Math::Complex module is part of the standard installation already, no
> need for any "packages" (whatever that might be).
> Did you check "perldoc Math::Complex"
>
> NAME
> Math::Complex - complex numbers and associated mathematical functions
> [...]
>
> jue
>
>


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


Re: complex numbers

2005-01-11 Thread It&#x27;s me
Operator overloading (and function overloading) helps but not enough.You
have to be aware of the complex type *everywhere* you go and that's very
annoying and error prone.  I've been the works with C++, and later with
Modelica.   I am very happy that Python included *native* complex number
support.

I really like Python's notion of having just one data type: the duck.



"Anno Siegel" <[EMAIL PROTECTED]> wrote in message
news:cs145l$8d6



>
> Like this?
>
> use Math::Complex;
>
> my $z = sqrt( -1);
> print 1 + $z, "\n"; # prints "1+i"
>
> Operator overloading makes it possible to work with complex numbers as if
> they were a native data type.
>
> Anno
>


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


Re: complex numbers

2005-01-11 Thread It&#x27;s me

"Big and Blue" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
>  >
> > I am very happy that Python included *native* complex
number
> > support.
>
> And I have always been happy that FORTRAN supports them.
>
> > I really like Python's notion of having just one data type: the duck.
>
> So have you considered using Python for your problem?
>

Yes, over the holiday, I wrote a somewhat complex program using Python -
just so I can apply what I have learned so far.   It's a joy to use.   I was
able to finished the program in a fraction of the time it used to take me in
Fortran (and later C).


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


Re: complex numbers

2005-01-11 Thread It&#x27;s me
You are focusing on computational type applications of complex numbers.  For
those, you can do it with any languages - including machine language.  It's
just a matter of how much headache you want.

For instance, when constructing "software lego parts" (such as the
Matlab/Simulink type), it's very annoying that you need to know what kind of
signal comes in and goes out.   In Malab/Simulink, for instance, you specify
that the signal is of the "inherit" type (meaning you don't care what type
it is - just process it).   In Python, it's of type "duck", just pass it
on...I don't need to care if it's real or complex.   I don't need to devise
yet another overloaded operator or function whenever I encounter a situation
where the native language doesn't handle.



"Anno Siegel" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

>
> What kind of awareness do you mean?
>
> There are some operations (as comparison) that work for reals, but not
> for complex numbers.  If you want your program to run with complex input,
> you have to avoid such operations, whether the data type is native or not.
>
> What other considerations are there?  A typical numeric program should
> just run and give complex output when fed complex input.  I made the
> experiment with the Perl module Statistics::Descriptive, which was
> certainly written without concern for complex input, and it works without
> a hitch.  I'm not sure if the (complex) variance of several complex
> numbers is a reasonably interpretable quantity, but I'm certain the
> maths is done right.  What else do you want?
>
> Anno


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


Re: complex numbers

2005-01-11 Thread It&#x27;s me

"Robert Kern" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> That's *it*.

So, how would you overload an operator to do:

With native complex support:

def  twice(a):
return 2*a

print twice(3+4j), twice(2), twice("abc")

Let's presume for a moment that complex is *not* a native data type in
Python.  How would we implement the above - cleanly?


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


Re: complex numbers

2005-01-12 Thread It&#x27;s me
Precisely.   One have to convert complex number into vectors, and vector of
complex numbers into vector of vectors, list of complex numbers into list of
vectors, , you get the idea.

And my code no longer look like the equation I have on paper...

Like I said, I've travelled down that path before with C++ and Modelica.
It gets ugly.

Anyway.



"Antoon Pardon" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Op 2005-01-12, It's me schreef <[EMAIL PROTECTED]>:
> >
> > "Robert Kern" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >>
> >> That's *it*.
> >
> > So, how would you overload an operator to do:
> >
> > With native complex support:
> >
> > def  twice(a):
> > return 2*a
> >
> > print twice(3+4j), twice(2), twice("abc")
> >
> > Let's presume for a moment that complex is *not* a native data type in
> > Python.  How would we implement the above - cleanly?
>
>
> I suppose in the same way as (graphic) points and vectors can be
> implemented cleanly.
>
> A few years back I had written a Vector class in python, just
> to get an understanding of how things worked. It worked without
> a problem with your twice function.
>
>
> >>> Vec(1.0,2.0)
> Vector[1.0, 2.0]
> >>> def twice(a):
> ...   return 2 * a
> ...
> >>> twice(Vec(1.0,2.0))
> Vector[2.0, 4.0]
> >>>
>
>
> I suppose what can be done with a vector class could have been
> done with a complex class should complex numbers not have been
> native to python.
>
> -- 
> Antoon Pardon


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


Why would I get a TypeEror?

2005-01-12 Thread It&#x27;s me
For this code snip:

a=3

b=(1,len(a))[isinstance(a,(list,tuple,dict))]

Why would I get a TypeError from the len function?

Thanks,


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


counting items

2005-01-12 Thread It&#x27;s me
Okay, I give up.

What's the best way to count number of items in a list?

For instance,

a=[[1,2,4],4,5,[2,3]]

I want to know how many items are there in a (answer should be 7 - I don't
want it to be 4)

I tried:

b=len([x for y in a for x in y])

That doesn't work because you would get an iteration over non-sequence.

I tried:

g=lambda x: (1,len(x))[isinstance(x,(list,tuple,dict))]
b=sum(lambda(x) for x in a)

and that didn't work because I get a TypeError from the len function (don't
know why)

I can, of course:

i=0
for x in a:
if isinstance(x,(list,tuple,dict)):
i += len(x)
else:
i += 1

but that's so C-like...

Thanks,


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


Re: Iteration over two sequences

2005-01-12 Thread It&#x27;s me
I tried this and I got:

[(1, 'a'), (2, 'b'), (3, 'c')]

But if I change:

a=[1,2]

I got:

[(1, 'c')]

Why is that?  I thought I should be getting:

[(1, 'a'),(2,'b')]

?


"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> zip or izip is your friend:
>
> import itertools
>
> a = [1,2,3]
> b = ['a', 'b', 'c']
>
> for a,b in itertools.izip(a, b):
> print a, b
>
> -- 
> Regards,
>
> Diez B. Roggisch


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


Re: Why would I get a TypeEror?

2005-01-12 Thread It&#x27;s me
Sorry if my question was a little "lazy" and yes, I was asking about the
"lazy evaluation".  :=)

I am surprised about this (and this can be dangerous, I guess).

If this is true, I would run into trouble real quick if I do a:

(1/x,1.0e99)[x==0]

and that's not good.

Something to keep in mind.  :-(


"harold fellermann" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> On 12.01.2005, at 18:35, It's me wrote:
>
> > For this code snip:
> >
> > a=3
> > 
> > b=(1,len(a))[isinstance(a,(list,tuple,dict))]
> >
> > Why would I get a TypeError from the len function?
>
> the problem is, that (1,len(a)) is evaluated, neither what type a
> actually has
> (python has no builtin lazy evaluation like ML). You have to do it this
> way
> instead:
>
> a=3
> ...
> b = isinstance(a,(list,tuple,dict)) and len(a) or 1
>
> - harold -
>
> --
> The opposite of a correct statement is a false statement.
> But the opposite of a profound truth may be another profound truth.
> -- Niels Bohr
>


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


Re: counting items

2005-01-12 Thread It&#x27;s me
Oh, darn.  I asked this kind of question before.  

Somebody posted an answer before:

def flatten(seq):
for x in seq:
if hasattr(x, "__iter__"):
for subx in flatten(x):
yield subx
else:
yield x

data = [[1,5,2],8,4]
val_to_pos = {}
for i, x in enumerate(flatten(data)):
   val_to_pos[x] = i + 1
print val_to_pos



"It's me" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Okay, I give up.
>
> What's the best way to count number of items in a list?
>
> For instance,
>
> a=[[1,2,4],4,5,[2,3]]
>
> I want to know how many items are there in a (answer should be 7 - I don't
> want it to be 4)
>
> I tried:
>
> b=len([x for y in a for x in y])
>
> That doesn't work because you would get an iteration over non-sequence.
>
> I tried:
>
> g=lambda x: (1,len(x))[isinstance(x,(list,tuple,dict))]
> b=sum(lambda(x) for x in a)
>
> and that didn't work because I get a TypeError from the len function
(don't
> know why)
>
> I can, of course:
>
> i=0
> for x in a:
> if isinstance(x,(list,tuple,dict)):
> i += len(x)
> else:
> i += 1
>
> but that's so C-like...
>
> Thanks,
>
>


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


Re: counting items

2005-01-12 Thread It&#x27;s me
Yes, Mark, I came up with almost the same code (after reading back old
answers from this list):

def flatten(seq):
for x in seq:
if hasattr(x, "__iter__"):
for subx in flatten(x):
yield subx
else:
yield x

def count_item(data):
return len([(i,x) for i, x in enumerate(flatten(data))])

data = [[1,5,2],8,4]
print count_item(data)


Thanks everybody.



"Mark McEahern" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
>
> >Okay, I give up.
> >
> >What's the best way to count number of items in a list [that may contain
lists]?
> >
> >
> a = [[1,2,4],4,5,[2,3]]
>
> def iterall(seq):
> for item in seq:
> try:
> for subitem in iterall(item):
> yield subitem
> except TypeError:
> yield item
>
> all = [x for x in iterall(a)]
> print len(all)
>


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


Re: counting items

2005-01-12 Thread It&#x27;s me
Thanks.

May be flatten should be build into the language somehow


"Paul McGuire" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "It's me" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Okay, I give up.
> >
> > What's the best way to count number of items in a list?
> >
> > For instance,
> >
> > a=[[1,2,4],4,5,[2,3]]
> >
> > I want to know how many items are there in a (answer should be 7 - I
don't
> > want it to be 4)
> >
> 
>
> I've sure seen a lot of questions about the flattening of lists.  I found
> this version of flatten somewhere, I thought I got it from the Python
> Cookbook but I can't find it now.  Perhaps it was posted here on c.l.py.
I
> *don't* claim authorship, I'm merely an admirer of such a clean-looking
> solution.
>
> def flatten(a):
> if not isinstance(a, (tuple,list)): return [a]
> if len(a)==0: return []
> return flatten(a[0])+flatten(a[1:])
>
> a = [[1, 2, 4], 4, 5, [2, 3], 6, [6], [], 'askjdf']
>
> print len(flatten(a))
>
> gives the value 10.
>
> Considering how often this comes up, might there be a place for some sort
of
> flatten() routine in the std dist, perhaps itertools?
>
> -- Paul
>
>


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


Re: Why would I get a TypeEror?

2005-01-14 Thread It&#x27;s me
Say again???

"Reinhold Birkenfeld" <[EMAIL PROTECTED]> wrote in
message news:[EMAIL PROTECTED]
> It's me wrote:
> > Sorry if my question was a little "lazy" and yes, I was asking about the
> > "lazy evaluation".  :=)
> >
> > I am surprised about this (and this can be dangerous, I guess).
> >
> > If this is true, I would run into trouble real quick if I do a:
> >
> > (1/x,1.0e99)[x==0]
> >
> > and that's not good.
> >
> > Something to keep in mind.  :-(
>
> Lazy evaluation: use the (x==0 and 1e99 or 1/x) form!
>
> Reinhold


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


problem with PythonCard -> wxPython -> _core.py -> class point -> __getitem__

2005-02-22 Thread It&#x27;s me
I've built a Python application using PythonCard 1.9 and Python 2.3 running
under Windows XP.   Everything works except that when I use the keyboard
instead of the mouse to do certain operations in a data entry field (like
Shift-Home), the
program stops at line 1014 of wx-2.5.3-msw.ansi\wx\_core.py.

def __getitem__(self, index):
try:
x = self.Get()[index]
except IndexError:
raise IndexError, "tuple index %d out of range of %d"
%(index,len(self.Get()))
return x

I downloaded the current version of wxPython (2.5.3.1) and tried again.
Same problem except that they've removed the exception handler and simply go
with:

def __getitem__(self, index):return self.Get()[index]

at line 1012.   The debugging shows that someone is calling this routine
repeatedly with index greater then the left of self.Get().   That's the best
I can do.

Any help?

(I can report to the wxPython list if nobody knows how to get around this)

Thanks,



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


Re: PythonCard and Py2Exe

2005-02-22 Thread It&#x27;s me
It's:

from PythonCard.components import radiogroup

not just:

from PythonCard import radiogroup


"PipedreamerGrey" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm trying to create a standalone version (.exe) of PythonCard's Custdb
> sample using Py2Exe version 0.5.0.  Everytime I attempt to compile the
> program, I get an error during compilation.  This is the exact code I'm
> using in the setup file:
>
> from distutils.core import setup
> import py2exe
> setup( name = "custdb",
>console = ["custdb.py"],
>data_files = [ (".", ["custdb.ini", "custdb.de.rsrc.py",
> "custdb.rsrc.py", "customerdata.csv"]) ]
>)
>
> This is the error message I get when I run custdb.exe:
>
> Traceback (most recent call last):
>   File "custdb.py", line 202, in ?
> app = model.Application(CustDbStack)
>   File "PythonCard\model.pyc", line 337, in __init__
>   File "PythonCard\resource.pyc", line 48, in getResource
>   File "PythonCard\resource.pyc", line 86, in __init__
>   File "PythonCard\resource.pyc", line 91, in __init__
>   File "PythonCard\resource.pyc", line 91, in __init__
>   File "PythonCard\resource.pyc", line 96, in __init__
>   File "PythonCard\resource.pyc", line 139, in enforceSpec
>   File "PythonCard\resource.pyc", line 30, in loadComponentModule
> ImportError: cannot import module 'radiogroup
>
> When I add "radiogroup" to the imports at the top of custdb.py, I get
> this error message:
>
> Traceback (most recent call last):
>   File "custdb.py", line 18, in ?
> ImportError: cannot import name radiogroup
>
> This is line 18 in Custdb.py: from PythonCard import dialog, model,
> radiogroup
>


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


Re: Pythoncard - Mistake in walkthrough?

2005-02-23 Thread It&#x27;s me
As stated in the on-line WalkThrough, the information there was written for
an older version of the program.


"Deltones" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi all,
>
> I'm just getting into Python/wxPython/Pythoncard and I'm trying the
> tutorial from this page:
> http://pythoncard.sourceforge.net/walkthrough1.html
>
> Is it me who's totally dense or there's some sort of confusion with
> this tutorial?
>
> Here's what is said in the tutorial:
>
> Open the file starter1.py in your Python-aware editor of choice. The
> Python script is, as you'd expect, brief and to the point. Here's the
> important part to focus on:
>
> def on_menuFileExit_select(self, event):
> pass
>
>
> But here's the starter1.py code:
>
> #!/usr/bin/python
>
> from PythonCard import model
>
> class Minimal(model.Background):
> pass
>
> if __name__ == '__main__':
> app = model.Application(Minimal)
> app.MainLoop()
>
>
> As you can see, the on_menu line is not in the starter1.py original
> script, so I guessed that it should be a part of the Minimal class.
>
> Then the tutorial ask me to replace the on_menu "pass" line with:
>
> result = dialog.alertDialog(self, 'It works!', 'Showing Off')
>
> but when you run the script, it runs, but clicking on Exit does not
> display any dialog box. I did change the import line to include
> dialog.
>
> Is there something I'm not seeing here or there is really a mistake
> with the walkthrough?
>
> Thanks
>
> Denis


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


Re: Pythoncard - Mistake in walkthrough?

2005-02-24 Thread It&#x27;s me
No, those are old still.


"Deltones" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> > As stated in the on-line WalkThrough, the information there was written
for
> > an older version of the program.
> >
> 
>
> Hi,
>
> I understand, but the walkthrough I'm doing comes from the doc folder
> of the latest windows package. I thought that the walkthrough were
> updated to fit the newest version. Thanks though.
>
> Denis


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


Newbie getting confused again

2005-03-04 Thread It&#x27;s me
If I have:

a = (1,2,3)

how do I ended up with:

res=[(1), (2), (3), (4), (5)]

without doing:

res=[(a[0]), (a[1]), (a[2]), (4), (5)]

???

ps: This is just a nobrainer example of what my real code is trying to do.
"a" might have many many elements.   That's why the explicit indexing method
won't work.

Thanks,





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


Re: Newbie getting confused again

2005-03-04 Thread It&#x27;s me
*bonk, bonk, bonk*

Now I feel better.

Thanks, everybody.   The "+" is indeed what I was looking for.It just
didn't occur to me that this is the way you concatenate two lists together.
But of course, that makes sense, doesn't it?

Thanks again.


"Peter Hansen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> > If I have:
> >
> > a = (1,2,3)
>
> Note that this is a tuple.
>
> > how do I ended up with:
> >
> > res=[(1), (2), (3), (4), (5)]
>
> Not that this is a list.  The two aren't the same thing.
> If you don't understand the difference, you might want
> to review the tutorial or head over to the tutor list.
>
> Also note that (1) is just the same as 1, so what you
> show above is the same as res=[1, 2, 3, 4, 5].  Is that
> what you wanted?
>
> > without doing:
> >
> > res=[(a[0]), (a[1]), (a[2]), (4), (5)]
>
> Presumably what you are asking is how you can create
> a new list (or tuple?) based on the contents of the
> original tuple "a" but with two more elements added?
>
> This will do precisely what you've described, though
> it does convert "a" from a tuple into a list because
> you couldn't concatenate (join together) the two objects
> otherwise:
>
> res = list(a) + [4, 5]
>
>
> -Peter


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


Re: Newbie getting confused again

2005-03-05 Thread It&#x27;s me
Thanks, got it.


"M.E.Farmer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> > If I have:
> >
> > a = (1,2,3)
> >
> > how do I ended up with:
> >
> > res=[(1), (2), (3), (4), (5)]
> >
> > without doing:
> >
> > res=[(a[0]), (a[1]), (a[2]), (4), (5)]
> >
> > ???
> >
> > ps: This is just a nobrainer example of what my real code is trying
> to do.
> > "a" might have many many elements.   That's why the explicit indexing
> method
> > won't work.
> >
> > Thanks,
> Hello,
> List objects have a method called extend().
> It is made for this.
> Py> a = [1,2,3]
> Py> b = [4,5,6]
> Py> a.extend(b)
> Py> a
> [1, 2, 3, 4, 5, 6]
> Since you are a newbie I also suggest you look at
> your objects a little and see what they have available.
>
> Py>dir(a)
> ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__',
> '__delslice__', '__doc__', '__eq__', '__ge__', '__getattribute__',
> '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__',
> '__imul__', '__init__', '__le__', '__len__', '__lt__', '__mul__',
> '__ne__', '__new__', '__reduce__', '__repr__', '__rmul__',
> '__setattr__', '__setitem__', '__setslice__', '__str__', 'append',
> 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse',
> 'sort']
>
> Then you can try and get some help from Python.
> Py>help(a.extend)
> Help on built-in function extend:
>
> extend(...)
> L.extend(iterable) -- extend list by appending elements from the
> iterable
>
> And finally use pydoc it is very helpful.
> Cl> python pydoc -g
> hth,
> M.E.Farmer
>


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


How do I do this? (eval() on the left hand side)

2004-12-07 Thread It&#x27;s me
I am new to the Python language.

How do I do something like this:

I know that

a = 3
y = "a"
print eval(y)

would give me a print out of 3 - but how do I do something to the effect of:

eval(y) = 4# hopefully the value of a gets changed to 4

??

Thanks,

--
It's me


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


Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread It&#x27;s me

"Caleb Hattingh" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi It's me
>
> >
> > a = 3
> > y = "a"
> > print eval(y)
> >
>
> To get 'a' to be 4 here, you would say
>
> a = 4
>

Obviously but that's not what I wish to do.

> I am not sure why you would want to do otherwise?  Perhaps you could
> sketch out a little more about what you are trying to do?  That would help
> a lot.  Are you aiming for something like pointer emulation with simple
> datatypes?
>

In REXX, for instance, one can do a:

interpret y' = 4'

Since y contains a, then the above statement amongs to:

a = 4

There are many situations where this is useful.   For instance, you might be
getting an input which is a string representing the name of a variable and
you wish to evaluate the expression (like a calculator application, for
instance).


> Thanks
> Caleb


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


sys.stdin.read question

2004-12-07 Thread It&#x27;s me
Why do I get an "AttributeError: read" message when I do:

import sys
r=sys.stdin.read()

??

I've tried:

r=sys.stdin.read(80)
r=sys.stdin.read(1)

same error message.

I couldn't find any reference to this function in my Python book (they have
the stdout but not in).

Some sample code I saw uses this function in the same manner I am and so I
am assuming this is the correct syntax?

Or is this a bug in Python 2.4?

--
It's me


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


Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread It&#x27;s me
Yes, Russell, what you suggested works.

I have to chew more on the syntax to see how this is working.

because in the book that I have, it says:

exec code [ in globaldict [, localdict] ]

...

--
It's me


"Russell Blau" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "It's me" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> >
> > In REXX, for instance, one can do a:
> >
> > interpret y' = 4'
> >
> > Since y contains a, then the above statement amongs to:
> >
> > a = 4
> >
> > There are many situations where this is useful.   For instance, you
might
> be
> > getting an input which is a string representing the name of a variable
and
> > you wish to evaluate the expression (like a calculator application, for
> > instance).
>
> In Python, the canonical advice for this situation is, "Use a dictionary."
> This has a number of advantages, including keeping your user's namespace
> separate from your application's namespace.  Plus it's easier to debug and
> maintain the code.
>
> But, if you absolutely, positively have to refer to your variable
> indirectly, you could do:
>
> exec "%s = 4" % y
>
> If y refers to the string "a", this will cause the variable a to refer to
> the value 4.
>
> -- 
> I don't actually read my hotmail account, but you can replace hotmail with
> excite if you really want to reach me.
>
>


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


Re: sys.stdin.read question

2004-12-07 Thread It&#x27;s me

"Grant Edwards" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On 2004-12-07, It's me <[EMAIL PROTECTED]> wrote:
> > Why do I get an "AttributeError: read" message when I do:
> >
> > import sys
> > r=sys.stdin.read()
>
> Dunno. Works fine for me under 2.3.4, and according to the
> docs, should work under 2.4.
>
> What do you get when you do this:
>
>  import sys

Done that.

>  type(sys.stdin)

I get:



>  dir(sys.stdin)

I get:

['_RPCProxy__attributes', '_RPCProxy__getattributes',
'_RPCProxy__getmethods', '_RPCProxy__methods', '__doc__', '__getattr__',
'__init__', '__module__', 'encoding', 'oid', 'sockio']

>
> > Some sample code I saw uses this function in the same manner I
> > am and so I am assuming this is the correct syntax?
>
> Should be.
>
> > Or is this a bug in Python 2.4?
>
> That would be a little hard to believe.
>

Well, here's a copy from the Python Shell output:

>>> print sys.stdin.read(5)

Traceback (most recent call last):
  File "", line 1, in -toplevel-
print sys.stdin.read(5)
AttributeError: read
>>>




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


Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread It&#x27;s me
Thanks for all the replies and yes I realize the associated issue of doing
something like this.

For simplicity sake, let's say I need to do something like this (for
whatever reason):





In situations like this, I wouldn't know the name of the variable in Python
I need to use ahead of time and so I would have to somehow convert a string
to be used as variable.  Of course, I can create a dictionary to keep track
of which variable has what name and this method of using exec should be
avoid if at all possible.

I am just trying to understand the language and see what it can do.

--
It's me




"Steven Bethard" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> > How do I do something like this:
> >
> > I know that
> >
> > a = 3
> > y = "a"
> > print eval(y)
> >
> > would give me a print out of 3 - but how do I do something to the effect
of:
> >
> > eval(y) = 4# hopefully the value of a gets changed to 4
>
> Generally, if you find yourself doing this, you may want to rethink your
> program organization.  That being said, if you are in the global scope,
> one option looks something like:
>
>  >>> a = 3
>  >>> y = 'a'
>  >>> globals()[y] = 4
>  >>> a
> 4
>
> If you can give us some more context on why you want to do this, we can
> probably suggest a better approach.  There aren't too many places where
> even advanced Python programmers need to use eval...
>
> Steve


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


Re: sys.stdin.read question

2004-12-07 Thread It&#x27;s me
Yes, if I run the script from the command prompt, it works.   I was running
it inside the Python IDE.

Thanks,

--
It's me


"Grant Edwards" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On 2004-12-07, It's me <[EMAIL PROTECTED]> wrote:
>
> >> Dunno. Works fine for me under 2.3.4, and according to the
> >> docs, should work under 2.4.
> >>
> >> What do you get when you do this:
> >>
> >>  import sys
> >
> > Done that.
> >
> >>  type(sys.stdin)
> >
> > I get:
> >
> > 
> >
> >>  dir(sys.stdin)
> >
> > I get:
> >
> > ['_RPCProxy__attributes', '_RPCProxy__getattributes',
> > '_RPCProxy__getmethods', '_RPCProxy__methods', '__doc__', '__getattr__',
> > '__init__', '__module__', 'encoding', 'oid', 'sockio']
>
> > 
>
> As somebody else already suggested, you must be running your
> program inside some sort of IDE that replaces sys.stdin with
> some other object that doesn't have a read() method.  Try
> running the program from a shell prompt.
>
>
> -- 
> Grant Edwards   grante Yow!  Someone in
DAYTON,
>   at   Ohio is selling USED
>visi.comCARPETS to a
SERBO-CROATIAN


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


Re: Python 2.3.5 ?

2004-12-07 Thread It&#x27;s me
Not to mention that there are packages out there that doesn't work (yet)
with 2.4.  Pynum is one such package.

--
It's me


"Larry Bates" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Just because 2.4 arrives doesn't mean that ALL work is stopped
> on 2.3.  It is quite common to have releases overlap.  The very
> newest release is put out (2.4) , but bugs are still being fixed
> in older (2.3).
>
> Larry Bates
>
>
>
> Luis M. Gonzalez wrote:
> > I'm confussed...
> > Python 2.4 (final) hs been released a few days ago, but now I see that
> > Python 2.3.5 is being worked on.
> > Why? What does it mean?
> >


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


swig & Python question

2004-12-08 Thread It&#x27;s me
I am playing around with SWING building a Python module using the no brainer
example in http://www.swig.org/tutorial.html.   With that first example,


/* File : example.c */

 #include 
 double My_variable = 3.0;

 int fact(int n) {
 if (n <= 1) return 1;
 else return n*fact(n-1);
 }

 int my_mod(int x, int y) {
 return (x%y);
 }

 char *get_time()
 {
 time_t ltime;
 time(<ime);
 return ctime(<ime);
 }
and using the swig file of:
/* example.i */
 %module example
 %{
 /* Put header files here (optional) */
 %}

 extern double My_variable;
 extern int fact(int n);
 extern int my_mod(int x, int y);
 extern char *get_time();
I was able to execute this Python script:


>>> import example
 >>> example.fact(5)
 120
 >>> example.my_mod(7,3)
 1
 >>> example.get_time()
 'Sun Feb 11 23:01:07 1996'
 >>>
However, when I try to access the gloabl variable My_variable by doing:

print example.cvar

I get a blank (rather then a value of 3.0).

Why?

--
It's me


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


Re: swig & Python question

2004-12-08 Thread It&#x27;s me

"It's me" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I am playing around with SWING building a Python module using the no
brainer
> example in http://www.swig.org/tutorial.html.   With that first example,
>

Oops!  Soapy fingers.   "SWIG" - not "SWING".

--
It's me.


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


Re: Calling a C program from a Python Script

2004-12-09 Thread It&#x27;s me
I would expect C to run circles around the same operation under Python.   As
a general rule of thumb, you should use C for time cirtical operations
(computer time, that is), and use Python for human time critical situations
(you can get a program developed much faster).

I just discovered a magical package call SWIG (http://www.swig.org) that
makes writing C wrappers for Python always a child's play.  It's incredible!
Where were these guys years ago when I had to pay somebody moocho money to
develop a script language wrapper for my application!!!

--
It's me


"Brad Tilley" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Grant Edwards wrote:
> > Huh?  What do you mean "write a file open"?  You want to read a
> > C source file and execute the C source?  If you have access to
> > a C interpreter, I guess you could invoke the interpreter from
> > python using popen, and feed the C source to it.  Alternatively
> > you could invoke a compiler and linker from C to generate an
> > executable and then execute the resulting file.
> >
> >
> >>for root, files, dirs in os.walk(path)
> >> for f in files:
> >> try:
> >> EXECUTE_C_PROGRAM
> >
> >
> > You're going to have to explain clearly what you mean by
> > "EXECUTE_C_PROGRAM".  If you want to, you can certainly run a
> > binary executable that was generated from C source, (e.g. an
> > ELF file under Linux or whatever a .exe file is under Windows).
>
> Appears I was finger-tied. I meant "a C program that opens and reads
> files" while Python does everything else. How does one integrate C into
> a Python script like that?
>
> So, instead of this:
>
> for root, files, dirs in os.walk(path)
>   for f in files:
>   try:
>   x = file(f, 'rb')
>   data = x.read()
>   x.close()
> this:
>
> for root, files, dirs in os.walk(path)
>   for f in files:
>   try:
>   EXECUTE_C_PROGRAM
>
>  From the Simpsons:
> Frink: "Here we have an ordinary square."
> Wiggum: "Whoa! Slow down egghead!"


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


Re: New versions breaking extensions, etc.

2004-12-11 Thread It&#x27;s me
On the other hand, it can be annoying.

I can't use Python 2.4 right now because NumPy won't run.  So, I need to
wait for NumPy to get updated.

Of course, one would say: but NumPy is open source, go build it yourself.

My answer is simple: If there are more then 24 hours to a day, I definitely
would...

--
It's me


"John Machin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Jive wrote:
> "Martin v. Löwis" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > OTOH, people who only have VC6 just need to buy VS.NET 2003,
> > which is still available.
>
> I don't even know how to do that! :-)  What's the difference between
VC++
> .net Standard and Visual Studio .net Pro?  (Besides $370?)  Is the
former
> C++ only, but with the IDE, and the later the whole shebang with
SourceSafe,
> VBASIC, and all that?
>
> OH NO!  I've gone seriously off-topic.  Please don't call the Spanish
> Inquisiton.  Allow me to re-phrase the question:  What do I need to
build
> (on-topic) Python extensions?

Short answer to Jive's question: (1) free non-MS C compiler (either
MinGW or Borland) (2) inner calm.

I really can't understand what all the screaming and yelling is about.
Windows Python is built using an MS compiler. Those extension
developers who can't/won't buy the MS compiler use either the free
MinGW compiler or the free Borland 5.5 compiler (or both!). Yes, you
have to be careful about mixing the runtimes. An extension that tries
to use a FILE * that was created by Python will crash. Using free() on
a pointer that was malloc()ed by the other party isn't a bright idea
either. There are adequate solutions to these problems, involving
Python-supplied higher-level functions instead of C runtime functions.
Otherwise, not a problem. Distutils has made the process of using MinGW
and bcpp a snap. The documentation is adequate. When a new version of
Python comes out, one rebuilds and tests one's extensions. So ... now
there are THREE compilers that can be used instead of the one that
Python's built with; what's the big deal?


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


Re: PythonWin Not Updating

2004-12-14 Thread It&#x27;s me
It works fine here.

--
It's me

"Chris" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm working on a program in PythonWin.  The problem I'm running into is
> that after I make a code change, PythonWin doesn't always see it.  Has
> anyone else had this problem?
>
> Chris


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


Re: BASIC vs Python

2004-12-16 Thread It&#x27;s me

"Adam DePrince" <[EMAIL PROTECTED]> wrote in message



>
> Don't do it, unless your goal is simply to embarrass and insult
> programmers.
>

I saw this code from an earlier post:

lst1 = ["ab", "ac", "ba", "bb", "bc"]
lst2 = ["ac", "ab", "bd", "cb", "bb"]
dct1 = dict.fromkeys(lst1)
print [x for x in lst1 if x not in dct1]
print [x for x in lst1 if x in dct1]

It's simply remarkable for somebody to be able to do it so cleanly (and so
obviously) - "out of the box", if you may.

Sure, you can do it in Basic.  Ur...sure?  Yes, sure...


>
>
> Adam DePrince
>
>


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


Re: BASIC vs Python

2004-12-17 Thread It&#x27;s me

"Gregor Horvath" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Peter Otten wrote:
>
> > May you could give us an idea of the current state of basic affairs then
by
> > translating the following example snippet:
>
> yes you can do it in VB6, but pythons lists and dictionarys are superior
> to those built in in VB and I think to those in most other languages.
>
> >
> > It's me wrote:
> >
> >
> >>I saw this code from an earlier post:
> >>
> >>lst1 = ["ab", "ac", "ba", "bb", "bc"]
> >>lst2 = ["ac", "ab", "bd", "cb", "bb"]
> >>dct1 = dict.fromkeys(lst1)
> >>print [x for x in lst1 if x not in dct1]
> >>print [x for x in lst1 if x in dct1]
>
> I think line3 should be
>
>  >>dct1 = dict.fromkeys(lst2)
>
> correct?
>

Correct.

> VB6 Code:
>
> Sub xy()
>
> Dim lst1 As New Collection
> Dim lst2 As New Collection
>
> lst1.Add "ab", "ab": lst1.Add "ac", "ac": lst1.Add "ba", "ba": lst1.Add
> "bb", "bb": lst1.Add "bc", "bc"
> lst2.Add "ac", "ac": lst2.Add "ab", "ab": lst2.Add "bd", "bd": lst2.Add
> "cb", "cb": lst2.Add "bb", "bb"
>
> For Each item In lst1
>If ColHasKey(lst2, item) Then Debug.Print "in:" & item
> Next
>
> For Each item In lst1
>If Not ColHasKey(lst2, item) Then Debug.Print "not in:" & item
> Next
>
> End Sub
>
>
> Function ColHasKey(col As Collection, item) As Boolean
> On Error GoTo er
>A = col(item)
>ColHasKey = True
> Exit Function
> er:
>If Err.Number = 5 Then
>  ColHasKey = False
>Else
>  Err.Raise Err.Number
>End If
> End Function

Absolutely *ugly*!

But still, your point is well taken.  Thank you for pointing this out.

Adam was right:

"Don't do it, unless your goal is simply to embarrass and insult
programmers".




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


Re: BASIC vs Python

2004-12-17 Thread It&#x27;s me

"Gregor Horvath" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> > Absolutely *ugly*!
> >
> > But still, your point is well taken.  Thank you for pointing this out.
> >
> > Adam was right:
> >
> > "Don't do it, unless your goal is simply to embarrass and insult
> > programmers".
>
>
> OK. Then please schow me, how you can create a complex form with grids,
> explorer like trees etc. in 2 minutes in standard python.
>
> Or make any given standard python object accessible from MS Excel in 2
> minutes.
>
> --
> Greg

I thought we are talking about the language, are we not?

--
It's me


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


PyCrust: What am I suppose to do?

2004-12-17 Thread It&#x27;s me
I am trying out PyCrust and at a lost what to do next.  With the previous
IDE I tried, the IDE pops up the console and the editor.  From the editor, I
can set up breakpoints and debug and so forth.  Yes, I can even run the
script.

With PyCrust, the nice looking 3-pane window pops up with lots of tabs...a
prompt...and then???   Where is the file I am trying to run?  Even the File
options are all greyed out...





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


Re: swig & Python question

2004-12-11 Thread It&#x27;s me
Whether SWIG will work in a "no brainer" way or not depends on the original
code, I think.  If the original code uses a very convoluted design, of
course things will get hairy.   If the package uses a very clean structure,
I think you will find SWIG works out very nicely.

The intriguing things is, however, once you structure the package to a form
SWIG would work, it opens up the door to support multiple script languages
(and they have a long list of supported script languages).

If you hand crafted it to run the Python-C API, then you can only use Python
as script.

--
It's me


"Keith Dart" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> > "It's me" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> >
> >>I am playing around with SWING building a Python module using the no
> >
> > brainer
> >
> >>example in http://www.swig.org/tutorial.html.   With that first example,
> >>
> >
> >
> > Oops!  Soapy fingers.   "SWIG" - not "SWING".
> >
> > --
> > It's me.
>
> I have used SWIG before, and it's not always such a "no-brainer". In
> fact, it rarely is except for trivial examples. But it can work. I think
> it is best suited for wrapping large libraries. For small stuff, it
> would be better to just do it "manually" using the Python C API.
>
>
> Good luck.
>
> --
> It's not me.
>
>
>
>
> -- 
> \/ \/
> (O O)
> -- oOOo~(_)~oOOo--
--
> Keith Dart <[EMAIL PROTECTED]>
> public key: ID: F3D288E4
>



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


Re: BASIC vs Python

2004-12-16 Thread It&#x27;s me

"abisofile" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> hi
>
> I'm new to programming.I've try a little BASIC so I want ask since
> Python is also interpreted lang if it's similar to BASIC.
>
>
>

Is a Ferrari similar to a horse-wagon?  Yes, they both have 4 wheels.

:=)


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


Re: BASIC vs Python

2004-12-18 Thread It&#x27;s me

"Jan Dries" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Michael Hoffman wrote:
> > Gregor Horvath wrote:
> >
> >  > Or make any given standard python object accessible from MS Excel in
2
> >  > minutes.
> >
> > from win32com.client import Dispatch
> >
> > xlApp = Dispatch("Excel.Application")
> > xlApp.Visible = 1
> > xlApp.Workbooks.Add()
> > xlApp.ActiveSheet.Cells(1,1).Value = 'Python Rules!'
> > xlApp.ActiveWorkbook.ActiveSheet.Cells(1,2).Value = 'Python Rules 2!'
> > xlApp.ActiveWorkbook.Close(SaveChanges=0)
> > xlApp.Quit()
> > del xlApp
> >
> > (stolen from )
>
> Nice, but not really what the OP asked for.

What the OP asked for isn't what was discussed neither.

> You make Excel accessible
> from Python, instead of the other way round.
>

Again, that's a political issue - not technical nor language related.
Monopolictic empire has their way of doing things and as IT slaves, we have
to obey what the master BG wants us to do.

Anyway, here's another piece I find very nice:

http://starship.python.net/crew/pirx/spam7/COMtut.PPT



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


Re: BASIC vs Python

2004-12-18 Thread It&#x27;s me
Does this one count?

http://hacks.oreilly.com/pub/h/2630


"Jan Dries" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Michael Hoffman wrote:
> > Gregor Horvath wrote:
> >
> >  > Or make any given standard python object accessible from MS Excel in
2
> >  > minutes.
> >
> > from win32com.client import Dispatch
> >
> > xlApp = Dispatch("Excel.Application")
> > xlApp.Visible = 1
> > xlApp.Workbooks.Add()
> > xlApp.ActiveSheet.Cells(1,1).Value = 'Python Rules!'
> > xlApp.ActiveWorkbook.ActiveSheet.Cells(1,2).Value = 'Python Rules 2!'
> > xlApp.ActiveWorkbook.Close(SaveChanges=0)
> > xlApp.Quit()
> > del xlApp
> >
> > (stolen from )
>
> Nice, but not really what the OP asked for. You make Excel accessible
> from Python, instead of the other way round.
>
> Regards,
> Jan


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


Re: Tricks to install/run Python on Windows ?

2004-12-26 Thread It&#x27;s me
Try running with the latest version of Python 2.3 instead of 2.4.   May be
you would have better luck.

I've found similar stability problems with some of the tools (eventhough
they have 2.4 releases) as well.

I switched back to 2.3 and so far I have no complains.



"StepH" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> I'm new to Python.  I'm working under XP, and I've alot of prob. (not
> with the langage itself, but with the tools):
>
> I've install Pyhton 2.4 in C:\Python24, using the .msi windows installer.
> Then, I've install "PythonWin" (the last build-203).
>
> I'll try to summerize my prob.:
>
> 1./ The PythonWin IDE is not stable at all.  Sometimes it exit without
> reason, or don't stop on breakpoint, etc...  Are some of you aware of
> bugs in the last PyhtonWin IDE release ?  I've to open the TaskManager.
>   AT some point, i'm not able to (p.e.) open a file under it !!!
>
> 2./ I've try to download Komode (he 3.1 personnal).  I've also prob.
> with it !  Also, the breakpoint seems to not always work...
>
> 3./ So, i've try to use the command line, but i've to manualy change the
> code page od my dos box from 437 to 1252 (i'm live in belgium).  And
> i've not try how to do that permanently !
>
> 4./ Before, I had Python23 and it seems that when unstalling it, all the
> keys in the registry are not removed at all.  When i've install the 2.4,
> I had a mismatch which force me to complety re-install the machine (I'm
> not an expert of the registry)...
>
> 5./ Installing komodo seems to "block" pythonwinIDE completly...
>
> What's wrong ?  Python seems terific, but the tools...
>
> So... maybe i've to try BlackAdder ?


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


argument type

2004-12-27 Thread It&#x27;s me
A newbie question.

How can I tell from within a function whether a particular argument is a
sigular type, or a complex type?

For instance, in:

def abc(arg1)

How do I know if arg1 is a single type (like a number), or a list?

In C++, you would do it with function overloading.  If arg1 is always simple
type, I wouldn't care what it is.  But what if I *do* need to know whether
arg1 is a list or not?

I hate to have to have 2 functions: 1 for simple types, and one for list
types and then do something like:

abc_simple(1.0)
abc_list([1.0,2.0])

Any help would be greatly appreciated.


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


Re: argument type

2004-12-27 Thread It&#x27;s me
Donn,

That would lead to program error easily because when one forgets to include
the needed [], you get unintended result from the program.

I am going to try the "isinstance" approach mentioned by Brian.

Thanks,

"Donn Cave" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Quoth "It's me" <[EMAIL PROTECTED]>:
> | A newbie question.
> |
> | How can I tell from within a function whether a particular argument is a
> | sigular type, or a complex type?
> |
> | For instance, in:
> |
> | def abc(arg1)
> |
> | How do I know if arg1 is a single type (like a number), or a list?
> |
> | In C++, you would do it with function overloading.  If arg1 is always
simple
> | type, I wouldn't care what it is.  But what if I *do* need to know
whether
> | arg1 is a list or not?
> |
> | I hate to have to have 2 functions: 1 for simple types, and one for list
> | types and then do something like:
> |
> | abc_simple(1.0)
> | abc_list([1.0,2.0])
> |
> | Any help would be greatly appreciated.
>
> How about abc([1.0])?  That's easy, and it's a lot cleaner than
> mucking up your API with functions whose parameters have multiple
> possible interpretations.  C++ doesn't always point the way to
> great programming models.
>
> Donn Cave, [EMAIL PROTECTED]


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


Re: argument type

2004-12-27 Thread It&#x27;s me
Steve,

The argument I wish to pass is either one string, or a list of strings, or a
tuple of strings.

For instance, I have:

def abc(arg1, arg2, arg3)

Let say that I expect arg1 and arg3 to be a number, and arg2 can be either
one string, or a bunch of strings and I need to do something on each of the
strings passed down.  So, using the isinstance function suggested, I can
have:

def abc(arg1, arg2, arg3)
if isinstance(arg2,(list,tuple)):
for item in arg2:
abc(arg1, item)
else:
# do whatever with arg2 and I know now arg2 is a single instance
of a string
...

This way, when I invoke the function, I don't have to always remember the []
like:

abc(1,["String 1",],5)

I can simply do:

abc(1,"String 1",5)

and likewise, I can do:

abc(1,["String 1","String 2"],5)

Am I on the right track?


"Steven Bethard" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> > A newbie question.
> >
> > How can I tell from within a function whether a particular argument is a
> > sigular type, or a complex type?
> >
> > For instance, in:
> >
> > def abc(arg1)
> >
> > How do I know if arg1 is a single type (like a number), or a list?
> >
> > In C++, you would do it with function overloading.  If arg1 is always
simple
> > type, I wouldn't care what it is.  But what if I *do* need to know
whether
> > arg1 is a list or not?
> >
> > I hate to have to have 2 functions: 1 for simple types, and one for list
> > types and then do something like:
> >
> > abc_simple(1.0)
> > abc_list([1.0,2.0])
> >
>
> Generally, if I have a function that might take one or more args, I'd
> write it like:
>
>  def abc(*args)
>
> and then call it with one of the following:
>
>  abc(1.0)
>  abc(1.0, 2.0)
>  abc(*[1.0, 2.0])
>
> If you're really stuck with the one argument signature, I tend towards
> the "ask forgiveness rather than permission" instead of the "look before
> you leap" style.  Something like:
>
>  def abc(arg1):
>  try:
>  x = iter(arg1)
>  except TypeError:
>  x = iter([arg1])
>  # now do whatever you want with x
>
> Note that this might give you some problems if you want to pass in
> strings (since they're iterable).  Can you give some more specifics on
> the problem?  What is the actual function you want to write and what
> kind of arguments to you expect to receive?
>
> Steve


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


Re: argument type

2004-12-27 Thread It&#x27;s me



>
> def abc(arg1, arg2, arg3)
> if isinstance(arg2,(list,tuple)):
> for item in arg2:
> abc(arg1, item)

Typo:

   abc(arg1, item, arg3)



> and likewise, I can do:
>
> abc(1,["String 1","String 2"],5)
>
> Am I on the right track?
>

Let me reiterate that in this case, I know the first and last argument are
numbers but I don't know if the second argument is one string, or a bunch of
strings.   Hence, I would think that I *do* need to use the "look before
leap" (I like that term) type style.



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


Re: argument type

2004-12-27 Thread It&#x27;s me

"Steven Bethard" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]



>
> Yeah, given those constraints, you basically have two options -- check
> for list/tuple (as you have above) or check for str/unicode (as I do
> below).  I personally prefer the latter because it seems much more
> likely that users will define alternate collection classes than that
> users will define alternate string classes.  My code would look like:
>
>  def abc(arg1, arg2, arg3):
>  if not isinstance(arg2, basestring):
>  for item in arg2:
>  abc(arg1, item, arg3)
>  else:
>  # do whatever with arg2 (guaranteed to be a string)
>
> That way if you later call your code with, say:
>
>  abc(1, set(["String 1", "String 2"]), 5)
>
> or
>
>  abc(1, collections.deque(["String 1", "String 2"]), 5)
>
> it still works.
>

Of course.  For now, it's okay because I haven't learn about set and other
types yet.   I am still thinking in very elementary terms.

I need to look up and see what:

  if not isinstance(arg2, basestring):

does.


>
> Steve
>
>
> P.S.  My real preference here would be to change the order of your
> arguments and write the function as:
>
>  def abc(arg1, arg3, *arg2s)
>  for arg2 in arg2s:
>  # do whatever with arg2 (should be a string)
>
> and then write your function calls as:
>
>   abc(1, 5, "String 1")
>   abc(1, 5, "String 1", "String 2")
>
> Then you don't ever have to remember []s. ;-)  But if you really are
> stuck with arg2 as the second argument, I'd probably go for testing
> isinstance(x, basestring).
>

No, that was just an example.   I actually have additional arguments that
are similar to arg2.  It's not like I can do:

  def abc(arg1, arg3, *arg2s, *arg3s, *arg4s)

:-)


> Steve


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


Re: argument type

2004-12-27 Thread It&#x27;s me

"It's me" <[EMAIL PROTECTED]> wrote in message news:EO6Ad.3296>
> I need to look up and see what:
>
>   if not isinstance(arg2, basestring):
>
> does.
>

Okay, I got the idea there.

Now, what if arg2 is not a string but either a number or a bunch of numbers?
Using your method, can I say something to the effect of "if arg2 is *not* an
instance of a simple number"?



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


Re: argument type

2004-12-28 Thread It&#x27;s me
Rocco, your comment noted.

Okay, I got what I need to know for this issue.

Thanks everybody for your help.  I greatly appreciate it.


"Rocco Moretti" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "It's me" wrote:
>
>  > No, that was just an example.   I actually have additional arguments
>  > that are similar to arg2.  It's not like I can do:
>  >
>  >  def abc(arg1, arg3, *arg2s, *arg3s, *arg4s)
>
> ...
>
> > Now, what if arg2 is not a string but either a number or a bunch of
numbers?
> > Using your method, can I say something to the effect of "if arg2 is
*not* an
> > instance of a simple number"?
>
> Methinks you are trying to shove a 5 bushel problem in a 2 bushel sack.
>
> Take a deep breath. Get a cup of coffee. Read the newspaper. Come back
> in 10-15 min and re-examine the problem with a fresh mind. Do you really
> have to pass multiple, variable sized lists of varying types to the same
> function? Is there some way to break the function into simpler pieces?
> Is there some better way to organize the program as a whole so that you
> avoid the issue altogether - perhaps by defining a new class?
>
> It's been my experience that whenever I'm confused on how I'm going to
> pass a number of parameters to a function, the function is too complex
> and needs to be simplified, either by splitting it up into simpler
> functions, or by moving functionality into object methods. In the end,
> the program not only does what I want, but is also easier to understand.


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


A scoping question

2004-12-28 Thread It&#x27;s me
This must be another newbie gotchas.

Consider the following silly code, let say I have the following in file1.py:

#=
import file2
global myBaseClass
myBaseClass = file2.BaseClass()
myBaseClass.AddChild(file2.NextClass())
#=

and in file2.py, I have:

#=
global myBaseClass
class BaseClass:
def __init__(self):
self.MyChilds = []
 ...
def AddChild(NewChild):
self.MyChilds.append(NewChild)
...
class NextClass:
def __init__(self):
for eachChild in myBaseClass.MyChilds:  # <- ERROR
...
#=

When I run this, Python complains that myBaseClass is undefined in the last
line above.

What am I doing wrong?  (Yes, I know I am thinking too much in C).  I
thought the global declaration would have been sufficient but it's obviously
not.

Thanks,


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


Re: A scoping question

2004-12-28 Thread It&#x27;s me

"Premshree Pillai" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Tue, 28 Dec 2004 19:34:36 GMT, It's me <[EMAIL PROTECTED]> wrote:
> > This must be another newbie gotchas.
> >
> > Consider the following silly code, let say I have the following in
file1.py:
> >
> > #=
> > import file2
> > global myBaseClass
> > myBaseClass = file2.BaseClass()
> > myBaseClass.AddChild(file2.NextClass())
> > #=
>
> You have declared myBaseClass to be global, but it doesn't exist.
>

No, myBaseClass exists in file1.py.   The question is how can I tell
file2.py that the global variable is in file1 (without doing a silly
file1.myBaseClass

Since I am invoking file2 from file1, I would have thought that global
variables in file1 exists automatically(too much C thinking, I know)


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


Re: A scoping question

2004-12-28 Thread It&#x27;s me
Thanks, Steve.

So, global is only to within a module (I was afraid of that).  Those words
flashed by me when I was reading it but since the word "module" didn't
translate to "file" in my C mind, I didn't catch that.

In that case, you are correct that I have to do an import of file1 in file2.

Not that this is not real code, I am still trying to learn the ins and outs
of Python by writing some silly code - but will be important to help me
understand how I would write the real code.

Regarding the question of not placing everything in one module, I wouldn't
think that that's how I would do it.  I might get ambitous later and write
code for a larger project.  In that case, I will need to know more about
scoping across multiple modules.  So, this helps me understand what to do.

Thanks again.

"Steven Bethard" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]



>
> I think you're confused about what the global keword does.  Declaring a
> name as global makes that name global *to the module*:
>
> http://docs.python.org/ref/global.html
> http://docs.python.org/lib/built-in-funcs.html#l2h-32
>
> What you probably want instead is:
>
>  file1.py 
> import file2
> myBaseClass = file2.BaseClass()
> myBaseClass.AddChild(file2.NextClass())
> --
>
>  file2.py 
> class BaseClass:
>  def __init__(self):
>  self.MyChilds = []
>  def AddChild(self, NewChild):
>  self.MyChilds.append(NewChild)
> class NextClass:
>  def __init__(self):
>  from file1 import myBaseClass  # IMPORT
>  for eachChild in myBaseClass.MyChilds:
>  pass
> --
>
> Note that I import myBaseClass in __init__.  If I imported it at the top
> of the module, then file1 would import file2 which would then import
> file1 and you'd have a circular dependency.
>
> As it is, your code is very tightly coupled.  Why don't you put all this
> code into a single module?
>
> Steve


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


Re: copying classes?

2004-12-29 Thread It&#x27;s me
I would not think that a generic deepcopy would work for all cases.   An
object can be as simple as a number, for instance, but can also be as
complex as the universe.  I can't imagine anybody would know how to copy a
complex object otherthen the object itself.

I always think that a well designed object should have a copyme method.
:=)

"Bob Van Zant" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Ha. I just read down to the bottom of pyDoc page.
>
> "This version does not copy types like module, class, function, method,
> nor stack trace, stack frame, nor file, socket, window, nor array, nor
> any similar types."
>
> However, I actually tried it and it worked at least in the simple case:
> >>> class x:
> ...   def __init__(self):
> ... self.y = 1
> ...
> >>> obj = x()
> >>> obj.y
> 1
> >>>
> >>> import copy
> >>> z = copy.deepcopy(obj)
> >>> z.y
> 1
> >>> obj.y = 4
> >>> obj.y
> 4
> >>> z = copy.deepcopy(obj)
> >>> z.y
> 4
>
> -Bob
>
> On Wed, 2004-12-29 at 10:42 -0800, Bob Van Zant wrote:
> > copy.deepcopy() should do the trick. This URL answers a little bit of
> > your question about the difficulties in copying "complex" data
> > structures.
> >
> > http://pydoc.org/2.3/copy.html
> >
> > -Bob
> >
> > On Wed, 2004-12-29 at 19:29 +0100, harold fellermann wrote:
> > > Hi all,
> > >
> > > In the documentation of module 'copy' it is said that "This version
> > > does not copy types like module, class, function, method, stack trace,
> > > stack frame, file, socket, window, array, or any similar types."
> > >
> > > Does anyone know another way to (deep)copy objects of type class? What
> > > is special about the objects of these types that they cannot be easily
> > > copied?
> > >
> > > Any help appreciated,
> > >
> > > - harold -
> > >
> > >
> > > --
> > > I like pigs. Dogs look up to us. Cats look down to us.
> > > Pigs treat us as equal.
> > > -- Winston Churchill
> > >
> >
>


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


Why would I use inspect.isclass()?

2004-12-29 Thread It&#x27;s me
I discovered the hardway what inspect.isclass() is doing.  Consider this no
brainer code:

###
import inspect

class Abc:
def Hello(self):
return

an_instance=Abc()
print inspect.isclass(an_instance)
###

It took me a while to understand how I can get inspect.isclass to return a
True (like: inspect.isclass(Abc)).

But what good is that?  Of course I know Abc is a class, why would I want to
inspect it so that it would tell me what I already know?

I would have thought this would be the situation I need that for:

###
import inspect

class Abc:
def Hello(self, some_class):
# since I don't know if the argument passed down *is* a class or not, I
would:
if inspect.isclass(some_class)==True:
   ...
return
###

But that obviously isn't what isclass is for.  What should I use?

Thanks,


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


Re: Using Python in my programs

2004-12-29 Thread It&#x27;s me
Assuming your program is written in C/C++, I would recommend that you start
with SWIG.

http://www.swig.org

You can play around with that as a start.  If later you decided that SWIG is
not for you, you can always do it natively.   There are plenty of
information at www.python.org.

"Squirrel Havoc"  wrote in
message news:[EMAIL PROTECTED]
> Hello. I am sorry if this has been asked before,
> but I am new here.
>
> If I recall correctly, Python can be used as a
> scripting language for other programs, as if
> the program had a builtin Python interpreter.
> I wish to extend my programs by making them
> scriptable with Python scripts.
>
> Is this possible? If so, does anyone know where
> I can find documentation on it? I searched the
> python.org site and didnt find anything useful
>
> Thanks
>
> SH


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


Re: calling functions across threads

2004-12-29 Thread It&#x27;s me
I haven't play with the thread stuff in Python (yet) but in general terms
(from a C mind), one should not expect read/write actions to be sequential
across threads.  I would assume the Python threads eventually goes back to
some system calls for thread handling.   If that were the case, you should
not be surprised at all that the I/O sequences appear to be quite
unpredictable.

If you absolutely, positively wants them to come out in a certain way, you
need to build in additionally serialization mechanisims in your code (like
use semaphores and stuff).



"Steven Bethard" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I'm playing around with some threading stuff right now, and I'm having a
> little trouble calling a function from one thread that affects another.
>   Here's my setup:
>
> py> import os, threading, time
> py> def write(file_in, input_lines):
> ... for line in input_lines:
> ... time.sleep(0.5)
> ... file_in.write(line)
> ... file_in.flush()
> ... file_in.close()
> ...
> py> def read(file_out, output_list):
> ... while True:
> ... line = file_out.readline()
> ... if not line:
> ... break
> ... output_list.append(line)
> ...
> py> def runthreads(lst):
> ... file_in, file_out, file_err = os.popen3('cat')
> ... write_thread = threading.Thread(
> ... target=write, args=(file_in,
> ... ['%s\n' % x for x in range(10)]))
> ... read_thread = threading.Thread(target=read,
> ...args=(file_out, lst))
> ... write_thread.start()
> ... read_thread.start()
> ... write_thread.join()
> ... read_thread.join()
> ...
>
> Basically, I start one thread to read and one thread to write (from a
> os.pipe).  This all works fine for me:
>
> py> lst = []
> py> runthreads(lst)
> py> lst
> ['0\n', '1\n', '2\n', '3\n', '4\n', '5\n', '6\n', '7\n', '8\n', '9\n']
>
> I run into a problem though when I try to call an update method every
> time I read a line:
>
> py> class updatinglist(list):
> ... def __init__(self, updater):
> ... super(updatinglist, self).__init__()
> ... self.updater = updater
> ... def append(self, item):
> ... super(updatinglist, self).append(item)
> ... self.updater(len(self))
> ...
> py> def update(i):
> ... print i
> ...
> py> lst = updatinglist(update)
> py> runthreads(lst)
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> py> lst
> ['0\n', '1\n', '2\n', '3\n', '4\n', '5\n', '6\n', '7\n', '8\n', '9\n']
>
> I get the correct output, but if you run this yourself, you'll see that
> the numbers 1 through 10 aren't printed in sync with the writes (i.e.
> every half second); they're all printed at the end.  Could someone
> explain to me why this happens, and how (if possible) I can get the
> numbers printed in sync with the appends to the list?
>
> Thanks,
>
> Steve


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


Re: Why would I use inspect.isclass()?

2004-12-29 Thread It&#x27;s me
Nicolas,

Thanks for the response.  Please see comment below.

"Nicolas Fleury" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> > an_instance=Abc()
>
> > But what good is that?  Of course I know Abc is a class, why would I
want to
> > inspect it so that it would tell me what I already know?
>
> Well, for no reason in that case.  For the same reason you would not
> call isinstance(an_instance, Abc) if you already know an_instance is an
> instance of Abc.
>
> > def Hello(self, some_class):
> > # since I don't know if the argument passed down *is* a class or
not, I
> > would:
> > if inspect.isclass(some_class)==True:
> >...
> > return
> > ###
> >
> > But that obviously isn't what isclass is for.  What should I use?
>
> Well, it's obviously what isclass is for;)  (By the way, you would be
> better not compare your conditions with True, unless it's really what
> you want).
>

But inspect.isclass(some_class) returns a False no matter what.   That's why
I am confused.

The only way I get isclass to return True is inspect.isclass(Abc) in my
example.


> I guess another example would be an assert on the type of argument:
> def foo(someClass):
>  assert inspect.isclass(someClass)
>  # rest of code
>

But that would always fail!  (I just tried it).

> This way errors on types are handled at the beginning and at the same
> time the code it documenting itself.  The function could also be useful
> in cases where you do some C++-like overloading mechanism.  Anyway,
> isclass, like iscallable, are functions that are not used often, but you
> still might need them.
>
> Regards,
> Nicolas


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


Re: Problem in threading

2004-12-29 Thread It&#x27;s me

"Gurpreet Sachdeva" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> So That means blindly using threads on any process won't help!
>

It depends on what "help" means to you.   Both Windows and Unix (and it's
variances) are considered "thread-weak" OSes.  So, using thread will come
with some cost.   The long gone IBM OS/2 is a classic example of a
"thread-strong" OS.

Still, a good use of thread would be, for example, a name-pipe server.   See
for instance:

http://www-106.ibm.com/developerworks/linux/library/l-rt4/?open&t=grl,l=252,p=pipes

Here you will see a performance improvement when threads are being used.

The example you listed isn't a good use of thread for performance
improvement sake.



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


Re: Why would I use inspect.isclass()?

2004-12-30 Thread it&#x27;s me
Okay, Nick, I didn't know you can pass a "Class" rather then an instance.  I
have to chew on what your example does.

But no, I want to pass an instance of a Class.  But how do I know that the
calling routine *did* pass me a class - pardon me: an instance of a Class?

--
It's me



"Nicolas Fleury" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
> >>I guess another example would be an assert on the type of argument:
> >>def foo(someClass):
> >> assert inspect.isclass(someClass)
> >> # rest of code
> >>
> > But that would always fail!  (I just tried it).
>
> Are you sure you haven't pass an instance instead of a class?  Remember,
> classes are also objects in Python:
>
>  >>> import inspect
>  >>> class A: pass
> ...
>  >>> def foo(a): assert inspect.isclass(a)
> ...
>  >>> foo(A)
>  >>>
>
> Works fine and makes sense, no?  Of course, if I pass an instance
> instead of a class it would fail:
>
>  >>> myA = A()
>  >>> foo(myA)
> Traceback (most recent call last):
>File "", line 1, in ?
>File "", line 1, in foo
> AssertionError
>
> Maybe your question is in what situations passing a class can be useful?
> There's many examples and once you're used to that capability it can
> be powerful.  One simple example could be the generation of
> documentation; since you usually want to doc your classes, not
> instances.  So it would make sense to do something like:
>
> def writeHtmlDoc(file, someClass): ...
>
> Regards,
> Nicolas


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


Re: Using python to deploy software

2004-12-30 Thread it&#x27;s me
pyro is most intriguing!  Thanks for the information.

"Anand" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I haven't but one of my friends have used Pyro (Python Remote Objects)
> to do so.
>
> You basically need to write a custom Pyro server and run it on a
> central machine. Your pyro clients can be installed on the machines
> where the software need to be installed.
>
> For more details and similar ideas refer the project page of pyro at
> http://pyro.sourceforge.net/projects.html .
>
> -Anand
>


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


Re: Why would I use inspect.isclass()?

2004-12-30 Thread It&#x27;s me
Steve,

You are correct that I worry too much about types.   It's *really* hard not
to - having so many years of C in my head (and I am not exactly a
programmer).

I realize that "if you don't understand duck typing, you don't really
understand Python" - and that's why I am struggling to learn about this.

It's hard to writing a routine and not thinking what kind of parameters will
be passed down from above.  In the old days, we go out of the way to do that
so programs don't fail in mysterous ways.


"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> it's me wrote:
>
> > Okay, Nick, I didn't know you can pass a "Class" rather then an
instance.  I
> > have to chew on what your example does.
> >
> > But no, I want to pass an instance of a Class.  But how do I know that
the
> > calling routine *did* pass me a class - pardon me: an instance of a
Class?
> >
> You should Google for "duck typing" and stop worrying so much about what
> your functions//methods have been passed.
>
> At least, that's the traditional Python approach. I suspect you are
> still trying to program in C in Python :-)
>
> regards
>   Steve
> -- 
> Steve Holden   http://www.holdenweb.com/
> Python Web Programming  http://pydish.holdenweb.com/
> Holden Web LLC  +1 703 861 4237  +1 800 494 3119


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


OT: novice regular expression question

2004-12-30 Thread It&#x27;s me
I am never very good with regular expressions.  My head always hurts
whenever I need to use it.

I need to read a data file and parse each data record.  Each item on the
data record begins with either a string, or a list of strings.  I searched
around and didn't see any existing Python packages that does that.
scanf.py, for instance, can do standard items but doesn't know about list.
So, I figure I might have to write a lex engine for it and of course I have
to deal wit RE again.

But I run into problem right from the start.   To recognize a list, I need a
RE for the string:

1) begin with ["  (left bracket followed by a double quote with zero or more
spaces in between)
2) followed by any characters until ] but only if that left bracket is not
preceeded by the escape character \.

So, I tried:

^\[[" "]*"[a-z,A-Z\,, ]*(\\\])*[a-z,A-Z\,, \"]*]

and tested with:

["This line\] works"]

but it fails with:

["This line fails"]

I would have thought that:

   (\\\])*

should work because it's zero or more incidence of the pattern \]

Any help is greatly appreciated.

Sorry for beign OT.  I posted this question at the lex group and didn't get
any response.  I figure may be somebody would know around here.


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


Re: Problem in threading

2004-12-30 Thread It&#x27;s me
That's an OT topic.   :=)

There were lots of discussions about this topic in the old days.   No need
to dive into it again.

Windows context switching overhead is very high.   You would be lucky to get
it down to the mid-30ms.   OS/2 can get it down to less then 10.   And for
OS/2, thread swithing time is only a few machine instructionsOT.OT.


"David Bolen" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "It's me" <[EMAIL PROTECTED]> writes:
>
> > It depends on what "help" means to you.   Both Windows and Unix (and
it's
> > variances) are considered "thread-weak" OSes.  So, using thread will
come
> > with some cost.   The long gone IBM OS/2 is a classic example of a
> > "thread-strong" OS.
> (...)
>
> Interesting - can you clarify what you perceive as the differences
> between a thread-weak and thread-strong OS?  If given the choice, I
> would probably refer to Windows (at least NT based systems, let's
> ignore 9x) as thread-strong, and yes, often think of Windows as
> preferring thread based solutions, while Unix would often prefer
> process based.
>
> Windows is far more efficient at handling large numbers of threads
> than it is processes, with much less overhead and there is lots of
> flexibility in terms of managing threads and their resources.  Threads
> are first class OS objects at the kernel and scheduler level (waitable
> and manageable).
>
> I can't think of anything offhand specific that OS/2 did with respect
> to threads that isn't as well supported by current Win32 systems.
>
> -- David


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


Re: Why would I use inspect.isclass()?

2004-12-30 Thread It&#x27;s me

"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Well the basic idea is "treat what you've been passed as though it is
> the type you wanted". When it's only you writing the code that's likely
> going to be the case. When it's others, you have to be a little more
> careful to catch the exceptions (except when you don;t bother, in which
> case the users will have to understand the tracebacks).
>

I grew up in an environment that believes in prevention, rather then
after-the-fact fixing.   That's why it's hard for me to delegate error
checking tasks to exception, rather then assert - it just feel so"nake".
:=)

Anyway, points taken.


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


Re: The Industry choice

2004-12-30 Thread It&#x27;s me

"Premshree Pillai" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> It certainly is not because Python is bad or something. Organizations
> typically take lot of time to change -- be it technology or office
> furniture.
>

In our industry, the code for the bread and butter tool hasn't really change
in over 40 years!


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


Re: OT: novice regular expression question

2004-12-30 Thread It&#x27;s me
I'll chew on this.  Thanks, got to go.


"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> It's me wrote:
>
> > I am never very good with regular expressions.  My head always hurts
> > whenever I need to use it.
> >
> Well, they are a pain to more than just you, and the conventional advice
> is "even when you are convinced you need to use REs, try and find
> another way".
>
> > I need to read a data file and parse each data record.  Each item on the
> > data record begins with either a string, or a list of strings.  I
searched
> > around and didn't see any existing Python packages that does that.
> > scanf.py, for instance, can do standard items but doesn't know about
list.
> > So, I figure I might have to write a lex engine for it and of course I
have
> > to deal wit RE again.
> >
> Well, you haven't yet convinced me that you *have* to. Personally, I
> think you just like trouble :-)
>
> > But I run into problem right from the start.   To recognize a list, I
need a
> > RE for the string:
> >
> > 1) begin with ["  (left bracket followed by a double quote with zero or
more
> > spaces in between)
> > 2) followed by any characters until ] but only if that left bracket is
not
> > preceeded by the escape character \.
> >
> So the pattern is
>
> 1. If the line begins with a "[" it should end with a "]"
>
> 2. Otherwise, it shouldn't?
>
> I'm trying to gently point out that the syntax you want to accept isn't
> actually very clear. If the format is "Python strings and lists of
> strings" then you might want to use the Python lexer to parse them, but
> that's quite an advanced topic. [too advanced for me :-]
>
> The problem is matching "up to a right bracket not preceded by a
> backslash". This seems to require what's technically referred to as a
> "negative lookbehind assertion" - in other words, a pattern that doesn't
> match anything, but checks that a specific condition is false or fails.
>
> > So, I tried:
> >
> > ^\[[" "]*"[a-z,A-Z\,, ]*(\\\])*[a-z,A-Z\,, \"]*]
> >
> > and tested with:
> >
> > ["This line\] works"]
> >
> > but it fails with:
> >
> > ["This line fails"]
> >
> > I would have thought that:
> >
> >(\\\])*
> >
> > should work because it's zero or more incidence of the pattern \]
> >
> > Any help is greatly appreciated.
> >
> > Sorry for beign OT.  I posted this question at the lex group and didn't
get
> > any response.  I figure may be somebody would know around here.
>
> I'd start with baby steps. First of all, make sure that you can match
> the individual strings. Then use that pattern, parenthesized to turn it
> into a group, as a component in a more complex pattern.
>
> Do you want to treat "this is also \" a string" as an allowable string?
> In that case you need a pattern that matches 'up to the first quotation
> mark not preceded by a backslash" as well!
>
> Let's try matching a single string first:
>
>   >>> s = re.compile(r'(".*?(?   >>> s.match('"s1", "s2"').groups()
> ('"s1"',)
>
> Note that I followed the "*" with a "?" to stop it being greedy, and
> matching as many characters as it could. OK, does that work when we have
> escaped quotation marks?
>
>   >>> s.match(r'"s1\"\"", "s2"').groups()
> ('"s1\\"\\""',)
>
> Apparently so. The negative lookbehind assertion stops a quote from
> matching when it's preceded by a backslash. Can we match a
> comma-separated list of such strings?
>
>   >>> slpat = r'(".*?(?   >>> s = re.compile(slpat)
>
> This is a bit trickier: here the second grouping beginning with "(?:" is
> intended to ensure that only the strings that get matched are included
> in the groups, not the separators, even though they must be grouped
> together. The list *must* be separated by ", ", but you could alter the
> pattern to allow zero or more whitespace characters.
>
>   >>> s.match(r'"s1\"\"", "s2"').groups()
> ('"s1\\"\\""', '"s2"')
>
> Well, that seems to work. Note that these patterns all ignore bracket
> characters, so all you need to do now is to surround them with patterns
> to match the opening and closing brackets, and you're done (I hope).
>
> Anyway, it'll give you a few ideas to work with.
>
> regards
>   Steve
> -- 
> Steve Holden   http://www.holdenweb.com/
> Python Web Programming  http://pydish.holdenweb.com/
> Holden Web LLC  +1 703 861 4237  +1 800 494 3119


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


Re: OT: novice regular expression question

2004-12-30 Thread It&#x27;s me
The shlex.py needs quite a number of .py files.  I tried to hunt down a few
of them and got really tire.

Is there one batch of .py files that I can download from somewhere?

Thanks,


"M.E.Farmer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello me,
> Have you tried shlex.py it is a tokenizer for writing lexical
> parsers.
> Should be a breeze to whip something up with it.
> an example of tokenizing:
> py>import shlex
> py># fake an open record
> py>import cStringIO
> py>myfakeRecord = cStringIO.StringIO()
> py>myfakeRecord.write("['1','2'] \n 'fdfdfdfd' \n 'dfdfdfdfd'
> ['1','2']\n")
> py>myfakeRecord.seek(0)
> py>lexer = shlex.shlex(myfakeRecord)
>
> py>lexer.get_token()
> '['
> py>lexer.get_token()
> '1'
> py>lexer.get_token()
> ','
> py>lexer.get_token()
> '2'
> py>lexer.get_token()
> ']'
> py>lexer.get_token()
> 'fdfdfdfd'
>
> You can do a lot with it that is just a teaser.
> M.E.Farmer
>


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