Re: Inheriting Object

2011-05-19 Thread William
Hi Nav:

Here is the long why.
http://www.python.org/download/releases/2.2.3/descrintro/
I guess for most programs, there is no big difference, but if
you use some special features that might be different. Say, could use
super when using type() instead of class(), also, when using multiple
inheritance, you can't multiply inherit from different built-in types.
Some new features such as property() is not supported in type either.
   

BRs
William
 
On 01/-9/-28163 03:59 AM, Navkirat Singh wrote:
> Hi Guys,
>
> I have been wondering for a while now as to why some classes inherit
> Object? And what does it really do for the class? Can anyone shed some
> light on this?
>
> Regards,
> Nav

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


Re: Inheriting Object

2011-05-19 Thread William
Hi Nav:

 Here is the long why.
http://www.python.org/download/releases/2.2.3/descrintro/
 I guess for most programs, there is no big difference. But in
term of some new added features in python, you might not be able to
work. Say, you could not use super in type, also you can't multiply
inherit from different built-in types, what's more you could not use
some builtin feature such as property.

BRs
William

On 01/-9/-28163 03:59 AM, Navkirat Singh wrote:
> Hi Guys,
>
> I have been wondering for a while now as to why some classes inherit
> Object? And what does it really do for the class? Can anyone shed some
> light on this?
>
> Regards,
> Nav

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


How use Distutils for plugins ?

2005-09-24 Thread william
I've got 2 differents sources of code, one for the main code (let's
call it Main), and the other one for plugins (let's call it Plugins).

The setup.py for Main is trivial and install all files in /site-packages/Main/. Thus, Works well.

My problem is because Plugins must go to:/site-packages/Main/plugins/

By reading the doc, I've found that we can use the "--install-lib"
parameter, and that works. But it's not automatic.

I would find a way to define the insatll-lib parameters automatically
inside the setup.py of Plugins.
My idea is to load Main and get is installed place by using the
Main.__file__ variable.

Any ideas ?

Thanks

William

---
http://www.opensource4you.com/

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


urllib on windows machines

2005-12-03 Thread william
I've got a strange problem on windows (not very familiar with that OS).

I can ping a host, but cannot get it via urllib (see here under).
I can even telnet the host on port 80.

Thus network seems good, but not for python ;-(.

Does any windows specialist can guide me (a poor linux user) to get
Network functionalitiies with python on windows ?

I'm runnning on Windows XP (sorry to not give more, I don't know the
equivalent of uname).
I'm using standard (msi) python-2.4.2

Thanks.



test.py contains the following lines:
"
import urllib
g=urllib.urlopen('http://www.google.com')
"


C:\Temp>python test.py
Traceback (most recent call last):
  File "test.py", line 2, in ?
g=urllib.urlopen('http://www.google.com')
  File "c:\william\tools\python24\lib\urllib.py", line 77, in urlopen
return opener.open(url)
  File "c:\william\tools\python24\lib\urllib.py", line 185, in open
return getattr(self, name)(url)
  File "c:\william\tools\python24\lib\urllib.py", line 308, in
open_http
h.endheaders()
  File "c:\william\tools\python24\lib\httplib.py", line 795, in
endheaders
self._send_output()
  File "c:\william\tools\python24\lib\httplib.py", line 676, in
_send_output
self.send(msg)
  File "c:\william\tools\python24\lib\httplib.py", line 643, in send
self.connect()
  File "c:\william\tools\python24\lib\httplib.py", line 627, in connect
raise socket.error, msg
IOError: [Errno socket error] (10053, 'Software caused connection
abort')

C:\Temp>ping www.google.com

Pinging www.l.google.com [66.249.93.104] with 32 bytes of data:

Reply from 66.249.93.104: bytes=32 time=22ms TTL=246
Reply from 66.249.93.104: bytes=32 time=23ms TTL=246
Reply from 66.249.93.104: bytes=32 time=22ms TTL=246
Reply from 66.249.93.104: bytes=32 time=22ms TTL=246

Ping statistics for 66.249.93.104:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 22ms, Maximum = 23ms, Average = 22ms

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


Re: urllib on windows machines

2005-12-03 Thread william
Thanks Scott

>
> This part I can help you with:
>  >>> import platform
>  >>> platform.platform()
>  'Windows-2000-5.0.2195-SP4'  # in my case
>  >>> platform.architecture()
>  ('32bit', 'WindowsPE')
>  >>> platform.python_version()
>  '2.4.2'
>  >>> platform.python_compiler()
>  'MSC v.1310 32 bit (Intel)'
>  >>> platform.python_build()
>  (67, 'Sep 28 2005 12:41:11')
>

>>> import platform
>>> platform.platform()
'Windows-XP-5.1.2600'
>>> platform.architecture()
('32bit', 'WindowsPE')
>>> platform.python_version()
'2.4.2'
>>> platform.python_compiler()
'MSC v.1310 32 bit (Intel)'
>>> platform.python_build()
(67, 'Sep 28 2005 12:41:11')


> So off-hand, I'd suspect some firewall thingie is getting in the way.
> Can you "bless" \Python24\python.exe and \Python24\pythonw.exe as
> applications allowed to do net traffic?
>

Bingo!
That's the problem: "Blocked outgoing TCP - Source Local: (1898)
Destination: 67.18.1.164: http(80)"

But why the "telnet www.google.com 80" is wroking ?
Why Firefox is running ?

Thanks.



William

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


python chat

2011-11-20 Thread William
Hi,

I've started a new site called StudyBrunch, where we offer a chance for online 
studygroups with video conferencing, screen sharing etc.   I'd like to keep the 
groups small to be maneageble.   I will offer a basic session on python for 
people who are interested, on Saturday or Sunday evening.   If you are 
interested, you can look at:
http://www.studybrunch.com/studysession/intro-to-python/

For this month, general membership is free and I hope to move on to more 
advanced topics later.   If you have questions, or suggestion for topics (for 
example, classes, wxpython, urllib2, etc.), then contact us 
through http://www.studybrunch.com/contact/ so we don't spam the list.

I have listed some preliminary times on the site in EST, but let me know on the 
site if you can't make those and I can try to schedule another session later in 
the week.   

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


Re: csv format to DBase III format

2006-01-06 Thread William

Peter Otten wrote:
> [EMAIL PROTECTED] wrote:
>
> > I need to transfer csv format file to DBase III format file.
> > How do i do it in Python language?
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715
>
> Peter

Hi,

I create a dbf file, it can be opened by Excel but it cannot be opened
by Access. Where
is the error in my script. My script is as follows:

#!/opt/bin/python2.3

import struct, datetime,itertools,time


def dbfwriter(f, fieldnames, fieldspecs, records):

""" Return a string suitable for writing directly to a binary dbf
file.

File f should be open for writing in a binary mode.

Fieldnames should be no longer than ten characters and not include
\x00.
Fieldspecs are in the form (type, size, deci) where
type is one of:
C for ascii character data
M for ascii character memo data (real memo fields not
supported)
D for datetime objects
N for ints or decimal objects
L for logical values 'T', 'F', or '?'
size is the field width
deci is the number of decimal places in the provided decimal
object
Records can be an iterable over the records (sequences of field
values).

"""
# header info
ver = 3
now = datetime.datetime.now()
yr, mon, day = now.year-1900, now.month, now.day
numrec = len(records)
numfields = len(fieldspecs)
lenheader = numfields * 32 + 33
#   lenrecord = sum(field[1] for field in fieldspecs) + 1
num = 0
for field in fieldspecs :
 num = num + int(field[1])

lenrecord = num + 1

hdr = struct.pack('http://mail.python.org/mailman/listinfo/python-list


Re: csv format to DBase III format

2006-01-10 Thread William

Peter Otten wrote:
> William wrote:
>
> > Peter Otten wrote:
> >> [EMAIL PROTECTED] wrote:
> >>
> >> > I need to transfer csv format file to DBase III format file.
> >> > How do i do it in Python language?
> >>
> >> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362715
>
> > I create a dbf file, it can be opened by Excel but it cannot be opened
> > by Access. Where is the error in my script.
>
> No idea, but here's some brainstorming.
>
> > f = open('test.dbf','w')
>
> First make sure that you open the file in binary mode 'wb'.
> If you have an application around that can generate dbfs you could compare a
> manually created file with the python-generated one. Have you tried the dbf
> with no records? If that is opened without error, you could successively
> add records until you find the culprit. Finally, if Excel and Access
> disagree about the dbf's validity, the Access import filter could be
> broken. Are there other filters for the Dbase family (Foxpro, Clipper)? Try
> one of them.
>
> Peter

I have no idea too. I use Foxpro to open the file, but it is failure.
The warning message
is as follows
"Either the table record count does not match the actual records in the
table, or the file size on the disk does not match the expected file
size from the table header."

Anybody have any idea?

William

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


Re: BeautifulSoup error

2006-06-16 Thread William
"Serge Orlov" <[EMAIL PROTECTED]> writes:

[...]

> Look at the traceback: you're not calling BeautifulSoup module! In
> fact, there is no feed method in the current BeautifulSoup
> documentation. Maybe it used to work well, but now it's definitely
> going to fail. As I understand documentation you need to write
>
> soup = BeautifulSoup(port)

Ah, yes ! Things change ! :-)

BeautifulSoup feed() method used to exist before 3.0.0, and was left
over to SGMLParser later. As explained in the changlog,

http://www.crummy.com/software/BeautifulSoup/CHANGELOG.html

Release 3.0.0 (2006/05/28), "Who would not give all else for two p"

Beautiful Soup no longer implements a feed method. You need to pass a
string or a filehandle into the soup constructor, not with feed after
the soup has been created. There is still a feed method, but it's the
feed method implemented by SGMLParser and calling it will bypass
Beautiful Soup and cause problems.

Thanks for all the help !

-- 
William

Thrashing is just virtual crashing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: warning for google api users

2006-02-22 Thread William
Isn't this because the index that the api uses is (a lot) older than
the index used by www.google.com? total results are always estimated,
so they are not reliable (seen the variance)

Gabriel B. schreef:

> the google webservices (aka google API) is not even close for any kind
> of real use yet
>
> if you search for the same term 10 times, you get 3 mixed totals. 2
> mixed result order. and one or two "502 bad gateway"
>
> i did an extensive match agains the API and the regular search
> service. the most average set of results:
>
> results 1-10; total: 373000
> results 11-20; total: 151000
> results 21-30; total: 151000
> results 31-40; total: 373000
> results 41-50; total: 373000
> results 51-60; total: 373000
> results 61-70; total: 151000
> ( 502 bad gateway. retry)
> results 71-80; total: 373000
> results 81-90; total: 151000
> ( 502 bad gateway. retry)
> results 91-100; total: 373000
>
> on the regular google search, total:  2,050,000 (for every page, of
> course)
>
> besides that, the first and third result on the regular google search,
> does not apear in the 100 results from the API in this query, but this
> is not average, more like 1 chance in 10 :-/
>
> So, no matter how much google insists that this parrot is sleeping,
> it's simply dead.
>
>
> now, what i presume that is happening, is that they have a dozen of
> machine pools, and each one has a broken snapshot of the production
> index (probably they have some process to import the index and or it
> explode in some point or they simply kill it after some time). and
> they obviously don't run that process very often.
>
> Now... anyone has some implementation of pygoogle.py that scraps the
> regular html service instead of using SOAP? :)
> 
> Gabriel B.

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


build windows module for python-2.4

2006-03-04 Thread william
Does any one having working python 2.4 compiler can give some details
on how to set it up ?

I've read lot of different website, but some are outdated, others
referencing dead links, ...

I would just use an existing python 2.3 module (VC6) to python-2.4.
I think the best is to recompile it with VC7.1, but how to setup the VC
environements?

Thanks.

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


questions about object references

2009-08-07 Thread William
I have a question.  Suppose I do the following:

def myfunc(a,b):
  return a+b

myfunc2=myfunc

is there anyway to find all of the references to myfunc?  That is, can I find 
out all of the functions that may be aliased to myfunc?

second question:



class MyClass(object):
 def __init__(a,b):
   self.a=a
   self.b=b
  def myfunc(self):
    return self.a+self.b

myclass=MyClass(3,4)
myclass.myfunc2=myclass.myfunc

Is there any way to find all the references to myclass.myfunc--in this case,
myclass.myfunc2?

Thanks,
William

is there a way to 





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


Re: reloading the module imported as 'from ... import ...'

2009-08-10 Thread William
What about using the reimport library?

http://code.google.com/p/reimport/

Cheers,
William




From: AlF 
To: python-list@python.org
Sent: Monday, August 10, 2009 1:48:31 AM
Subject: Re: reloading the module imported as 'from ... import ...'

Steven D'Aprano wrote:
> On Sun, 09 Aug 2009 20:43:41 -0700, AlF wrote:
> 
>> Hi,
>> 
>> what is the best way to reload the module imported using 'from ...
>> import ...'
> 
> 
> Have you tried "from ... import ..." again?
> 

I have not because of an assumption that "import" imports the module just once. 
In fact this still works that way:

here is a terminal 1:

$ cat > a.py
a=1
$ cat > a.py
a=2
$


and terminal 2:

>>> from a import a
>>> a
1
>>> a
1
>>> from a import a
>>> a
1
>>>

In spite of changing a.py in fly, the imported a is still 1


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



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


Re: Is there any package implanation the following arithmetics?

2009-08-11 Thread William
What you want is:
http://www.cgal.org/

I believe it has python bindings.

Cheers,
William




From: Emile van Sebille 
To: python-list@python.org
Sent: Tuesday, August 11, 2009 12:49:19 PM
Subject: Re: Is there any package implanation the following arithmetics?

On 8/11/2009 1:49 AM zhongshq said...
> Hi,
> 
> I wonder if there has any package can check whether two rectangles are
> overlap, is a dot inside or outside a polygon, etc.

PythonCad at http://sourceforge.net/projects/pythoncad/ has intersections built 
in.

Emile

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



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


Re: SQLObject 0.11.0

2009-08-12 Thread William
I don't want to start a flame war and would just like some information before 
diving in--
What are some the advantages and disadvantages of SQLObject compared to 
SQLAlchemy?

Thanks,
William




From: Oleg Broytmann 
To: Python Mailing List ; Python Announce Mailing List 

Sent: Wednesday, August 12, 2009 6:24:53 AM
Subject: SQLObject 0.11.0

Hello!

I'm pleased to announce version 0.11.0, the first stable release of 0.11 branch
of SQLObject.


What is SQLObject
=

SQLObject is an object-relational mapper.  Your database tables are described
as classes, and rows are instances of those classes.  SQLObject is meant to be
easy to use and quick to get started with.

SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite,
Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB).


Where is SQLObject
==

Site:
http://sqlobject.org

Development:
http://sqlobject.org/devel/

Mailing list:
https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss

Archives:
http://news.gmane.org/gmane.comp.python.sqlobject

Download:
http://cheeseshop.python.org/pypi/SQLObject/0.11.0

News and changes:
http://sqlobject.org/News.html


What's New
==

News since 0.10
-

Features & Interface


* Dropped support for Python 2.3. The minimal version of Python for
  SQLObject is 2.4 now.

* Dropped support for PostgreSQL 7.2. The minimal supported version of
  PostgreSQL is 7.3 now.

* New magic attribute 'j' similar to 'q' was added that automagically does
  join with the other table in MultipleJoin or RelatedJoin.

* SQLObject can now create and drop a database in MySQL, PostgreSQL, SQLite
  and Firebird/Interbase.

* Added some support for schemas in PostgreSQL.

* Added DecimalStringCol - similar to DecimalCol but stores data as strings
  to work around problems in some drivers and type affinity problem in
  SQLite.

* Added sqlobject.include.hashcol.HashCol - a column type that automatically
  hashes anything going into it, and returns out an object that hashes
  anything being compared to itself. Basically, it's good for really simple
  one-way password fields, and it even supports the assignment of None to
  indicate no password set. By default, it uses the md5 library for
  hashing, but this can be changed in a HashCol definition.

* RowDestroyedSignal and RowUpdatedSignal were added.

Minor features
~~

* Use reversed() in manager/command.py instead of .__reversed__().

* Minor change in logging to console - logger no longer stores the output
  file, it gets the file from module sys every time by name; this means
  logging will use new sys.stdout (or stderr) in case the user changed
  them.

* Changed the order of testing of SQLite modules - look for external
  PySQLite2 before sqlite3.

For a more complete list, please see the news:
http://sqlobject.org/News.html

Oleg.
-- 
 Oleg Broytmannhttp://phd.pp.ru/p...@phd.pp.ru
   Programmers don't die, they just GOSUB without RETURN.
-- 
http://mail.python.org/mailman/listinfo/python-list



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


Re: Komodo(!)

2009-08-14 Thread William
Personally, I rather like Wing




From: Kee Nethery 
To: python-list@python.org
Sent: Friday, August 14, 2009 3:28:54 PM
Subject: Re: Komodo(!)

>From the web site it looks like the free version does not include the 
>debugging stuff.

I've been using the paid version with the debugger functionality and I find it 
easy to use and incredibly nice for trying to understand what the code is 
doing. The built-in debugger has saved me tons of time, especially when 
troubleshooting CGIs.

I'm using a Mac and of the Python IDEs I looked at, Komodo had the easiest to 
use user interface, in my opinion.

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



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


Re: IDE for python similar to visual basic

2009-08-28 Thread William
For visual designers, you may try:
QTDesigner with PyQt
or WxForms or WxGlade or BoaConstructor with WxPython


It's not like VB.NET where you can put in callbacks write after doing layout, 
but some prefer the above designers to hand coding guis.  

Good luck,
William

--- On Fri, 8/28/09, qwe rty  wrote:

From: qwe rty 
Subject: Re: IDE for python similar to visual basic
To: python-list@python.org
Date: Friday, August 28, 2009, 6:43 PM

On Aug 29, 1:22 am, Craig  wrote:
> Try wingware i have it and i like it.
>
> --- On Fri, 8/28/09, qwe rty  wrote:
>
> > From: qwe rty 
> > Subject: IDE for python similar to visual basic
> > To: python-l...@python.org
> > Date: Friday, August 28, 2009, 5:19 PM
> > i have been searching for am IDE for
> > python that is similar to Visual
> > Basic but had no luck.shall you help me please?
> > --
> >http://mail.python.org/mailman/listinfo/python-list
>
>

OMG, it has no visual designer !!
-- 
http://mail.python.org/mailman/listinfo/python-list



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


Re: Python for professsional Windows GUI apps?

2009-08-30 Thread William
For wxFormbuilder, does it also support AUI (dockable windows,etc.)?

Thanks,
William

--- On Wed, 8/26/09, Robert Kern  wrote:

From: Robert Kern 
Subject: Re: Python for professsional Windows GUI apps?
To: python-list@python.org
Date: Wednesday, August 26, 2009, 7:40 PM

On 2009-08-26 18:08 PM, sturlamolden wrote:
> On 26 Aug, 22:47, David C Ullrich  wrote:
> 
>>> Nothing, except lobbying for wxFormBuilder for anyone who still doesn't
>>> know of it. :)
>> 
>> That's great. But do you know of anything I can use as a
>> visual form design tool in wxPython?
> 
> Right... I don't know if you are trying to be funny, but as I said
> there is wxFormBuilder...
> 
> 3.0 generates XRC that you can use with wxPython.
> 3.1 beta generates wxPython classes you can subclass.
> 
> Honestly, it's the best GUI builder for wxPython I know of.

It's possible that he is not asking for a visual form designer tool *for* 
building a wxPython app, but one that can be used *inside* a wxPython app like 
an IDE or something similar.

-- Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

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



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


Re: Why on CentOS, python consumes too much memory ?

2013-07-18 Thread William Bai
I found that it was caused by not by python but by 
/usr/lib/locale/locale-archive, the same problem as that described in
http://illiterat.livejournal.com/4615.html.

William

在 2013年7月18日星期四UTC+8下午12时45分01秒,William Bai写道:
> Hi:
> 
> 
> 
>Previously, we found that our python scripts consume too much memory. So I 
> use python's resource module to restrict RLIMIT_AS's soft limit and hard 
> limit to 200M.
> 
> On my RHEL5.3(i386)+python2.6.2, it works OK. But on CentOS 
> 6.2(x86_64)+python2.6.6, it reports memory error(exceeding 200M).
> 
> 
> 
> And I tested with a very small script, and result is out of my expect, it 
> still use too much memory on my CentOS 6.2 python:
> 
> import time
> 
> time.sleep(200)
> 
> 
> 
> I use guppy and memory_profiler to see the memory usage and see that 
> python objects just use about 6M memory both on RHEL5.3(i386)+python2.6 and 
> CentOS 6.2(x86_64)+python2.6. But when I cat /proc//status. I found that 
> though VmRss is not very large on both machines. But the VmSize on CentOS 
> 6.2(x86_64)+python2.6 is 140M-180M, while on my RHEL5.3+python2.6, the VmSize 
> is just 6M. And I tested on CentOS 5.7(x86_64)+python2.4.3, the VmSize is 70M.
> 
> 
> 
>  I could understand that 64 bit machines will occupy more virtual memory 
> than that on 32 bit, because the length of some types are not the same. But I 
> don't know why they differs so greatly(6M to 180M), Or is this only caused by 
> that python2.6 on CentOS 6.2's memory allocation is different from python's 
> default one? Could you kindly give me some clues? Thank you very much.
> 
> 
> 
> Best Regards
> 
> William

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


Current Web URL

2012-01-25 Thread William Abdo
Hi All,

I have been breaking my brains to find a solution to determining what
the current URL is in a web browser navigation bar.

It cannot be a prefixed values since I will not know what platform it is
running from at the time it is opened by the users.

Can this URL be extracted from the navigation bar so it can be parsed?

I tried this "response =
urllib2.urlopen('http://www.google.com').geturl()" however it seems to
always to give me the google url and not the one in the navigation bar.

Any Suggestions Please?

 

 

Respectfully,

 

William Abdo

 



This email message is intended for the use of the person to whom it has been 
sent, and may contain information that is confidential or legally protected. If 
you are not the intended recipient or have received this message in error, you 
are not authorized to copy, distribute, or otherwise use this message or its 
attachments. Please notify the sender immediately by return e-mail and 
permanently delete this message and any attachments. Verio, Inc. makes no 
warranty that this email is error or virus free.  Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lisp refactoring puzzle

2011-07-13 Thread William Clifford
Neil Cerutti  writes:

> On 2011-07-12, Petter Gustad  wrote:
>> Xah Lee  writes:
>>
>>> it's funny, in all these supposedly modern high-level langs, they
>>> don't provide even simple list manipulation functions such as union,
>>> intersection, and the like. Not in perl, not in python, not in lisps.
>>
>> In Common Lisp you have:
>>
>> CL-USER> (union '(a b c) '(b c d))
>> (A B C D)
>> CL-USER> (intersection '(a b c) '(b c d))
>> (C B)
>
> What's the rationale for providing them? Are the definitions
> obvious for collections that a not sets?

This seems like a good general question to me, although, I feel like the
answer to this question specifically is "yes, obvious enough." A general
purpose programming language ought to be general enough to allow
expansion, but have enough "obvious" features, that one doesn't have to
reinvent the wheel.

I recently read somewhere that human languages "differ less in what they
allow, and more in what they require" (paraphrase). I have little-to-no
computer science expertise, but I sense that in computer languages with
Turing equivalency this is exactly true.

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


Help parsing a text file

2011-08-29 Thread William Gill
I haven't done much with Python for a couple years, bouncing around 
between other languages and scripts as needs suggest, so I have some 
minor difficulty keeping Python functionality Python functionality in my 
head, but I can overcome that as the cobwebs clear.  Though I do seem to 
keep tripping over the same Py2 -> Py3 syntax changes (old habits die hard).


I have a text file with XML like records that I need to parse.  By XML 
like I mean records have proper opening and closing tags. but fields 
don't have closing tags (they rely on line ends).  Not all fields appear 
in all records, but they do adhere to a defined sequence.


My initial passes into Python have been very unfocused (a scatter gun of 
too many possible directions, yielding very messy results), so I'm 
asking for some suggestions, or algorithms (possibly even examples)that 
may help me focus.


I'm not asking anyone to write my code, just to nudge me toward a more 
disciplined approach to a common task, and I promise to put in the 
effort to understand the underlying fundamentals.

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


Re: Help parsing a text file

2011-08-29 Thread William Gill

On 8/29/2011 2:31 PM, Philip Semanchuk wrote:


If the syntax really is close to XML, would it be all that difficult to convert 
it to proper XML? Then you have nice libraries like ElementTree to use for 
parsing.



Possibly, but I would still need the same search algorithms to find the 
opening tag for the field, then find and replace the next line end with 
a matching closing tag.  So it seems to me that the starting point is 
the same, and then it's my choice to either process the substrings 
myself or employ something like ElementTree.

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


Re: Help parsing a text file

2011-09-01 Thread William Gill

On 9/1/2011 1:58 PM, JT wrote:

On Monday, August 29, 2011 1:21:48 PM UTC-5, William Gill wrote:


I have a text file with XML like records that I need to parse.  By XML
like I mean records have proper opening and closing tags. but fields
don't have closing tags (they rely on line ends).  Not all fields appear
in all records, but they do adhere to a defined sequence.


lxml can parse XML and broken HTML (see http://lxml.de/parsing.html).

- James


Thanks to everyone.

Though I didn't get what I expected, it made me think more about the 
reason I need to parse these files to begin with.  So I'm going to do 
some more homework on the overall business application and work backward 
from there. Once I know how the data fits in the scheme of things, I 
will create an appropriate abstraction layer, either from scratch, or 
using one of the existing parsers mentioned, but I won't really know 
that until I have finished modeling.





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


Functions vs OOP

2011-09-03 Thread William Gill
During some recent research, and re-familiarization with Python, I came 
across documentation that suggests that programming using functions, and 
programming using objects were somehow opposing techniques.


It seems to me that they are complimentary.  It makes sense to create 
objects and have some functions that take those objects as arguments. 
Are they suggesting that any function that takes an object as an 
argument should always be a method of that object?  Conversely I can see 
creating functions that take raw input (e.g. strings) and return it in a 
format compatible with an object's constructor, rather than have objects 
accept any conceivable format for its constructor.


Am I missing something, or am I taking things too literally?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Functions vs OOP

2011-09-03 Thread William Gill

On 9/3/2011 12:29 PM, MRAB wrote:

I think you mean "complementary". :-)
How polite of you to point out my spelling deficiency.  I guess 
shouldn't be watching football while typing (I'm sure the beer didn't 
help either).



I think that it's all about "state".

In functional programming, there's no state; a function's result
depends solely on its arguments, so it will always return the same
result for the same given arguments.

In OOP, on the other hand, an object often has a state; a method may
return a different result each time it's called, even for the same
given arguments.


I think you mean "it [sic, a function] will "return the same result for 
the same given values..."


x=1
y= myFn(x)

will return the same result as

y= myFn(1)

A method may use an attribute as an implicit argument, and that 
attribute's value change, just like the value of x (above) may change. 
It may or may not return anything (it may just modify an attribute).


The question wasn't about encapsulation, it was about programming 
paradigms, and if they conflict.


As was pointed out elsewhere, I may have just confused "functional 
programming" with "programming using functions".



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


Re: Functions vs OOP

2011-09-03 Thread William Gill

On 9/3/2011 2:50 PM, Ian Kelly wrote:


I think you may be confusing "functional programming" and "programming
using functions".  These are not the same thing.



I think you may be right, Ian.  It didn't make much sense


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


Re: Functions vs OOP

2011-09-03 Thread William Gill

On 9/3/2011 3:15 PM, Terry Reedy wrote:

William Gill wrote:


During some recent research, and re-familiarization with Python, I came
across documentation


Ours, or someone else's?


Python.



Since in Python, everything is an object, that would mean that every
function has to be a method, which would mean creating classes just to
have a class to attach functions to. How awful.


Exactly why I asked, but I realize the the mistake was mine.  I think 
they were talking about "functional programming" not "using functions in 
an OO program."


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


Re: Functions vs OOP

2011-09-03 Thread William Gill

On 9/3/2011 5:39 PM, Ben Finney wrote:

William Gill  writes:


On 9/3/2011 3:15 PM, Terry Reedy wrote:

William Gill wrote:


During some recent research, and re-familiarization with Python, I
came across documentation


Ours, or someone else's?


Python.


Can you show exactly where in the Python documentation you found the
passage which confused you?

Sorry, no.  I tried to locate the exact reference again, and couldn't 
remember where I read it (short term memory problems).

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


Re: Functions vs OOP

2011-09-03 Thread William Gill

On 9/3/2011 9:51 PM, Terry Reedy wrote:


It is possible that our doc was less than crystal clear. We are
constantly improving it where we can see fixable faults. If you run
across whatever it was and it still seems a bit muddy, post something
again.


Will do.

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


Re: Functions vs OOP

2011-09-04 Thread William Gill

On 9/4/2011 2:32 PM, Terry Reedy wrote:

On 9/4/2011 4:13 AM, tinn...@isbd.co.uk wrote:

Ian Kelly wrote:



Functional programming is about using functions in the *mathematical*
sense. A mathematical function maps one value (or tuple of values) to
another value. The mapped value never varies; if it did, it would be
a different function. So functional programming eschews the use of
functions where the results depend on any internal or external state
beyond the values of the passed-in arguments, such as the variable
state of the object the method is being called on.


I think there may be another issue here. If someone says "functional
programming" to me then I would generally assume that they *do* mean
"programming using functions". While your distinction of the two may
be strictly correct I don't think it's the generally accepted meaning.


The distintion drawn by Ian *is* generally accepted in computer science.
See
https://secure.wikimedia.org/wikipedia/en/wiki/Functional_programming
For instance, programming is C is imperative programming with functions
but it generally is not 'functional programming' in the sense referred
to by Ian and the Wikipedia article. Given that our docs are written by
people who do understand the technical distinction, you are probably
wrong to assume otherwise.

However, as I said to William, it is possible that our docs could be
improved so as to not depend on all readers having prior knowledge of
the intended meaning of 'functional programming'. As the use of Python
has expanded, so has the variety of backgrounds of Python programmers.

Since I am the one who opened this can of worms, and since I believe I 
have relocated the document that I misinterpreted,  I feel compelled to 
jump in here.


The source of my error is "Functional Programming HOWTO 
(/python-3.1.3-docs-html/howto/functional.html)"


Having arrived at this page indirectly (searching for and skimming other 
information regarding functions and methods) I was only half paying 
attention.  As a result I made the same mistake Chris did.


As a point of reference, I would not call myself a programmer, and any 
formal exposure was many, many years ago.  I am familiar with the 
concepts of procedural, declarative, and object-oriented programming, 
but not functional.  At least not in this context.


Having done a little more digging I now understand the difference. 
"Functional programming" is the proper terminology, and had I come 
across it from another direction, or with a more deliberate focus I 
probably wouldn't have made the initial mistake.


If you read the material with even a nominal understanding of the 
functional paradigm (functional relationships in a mathematical sense, 
not functions in the procedural sense), it is clear.  If you read it 
without consciously recognizing this difference, the material does 
nothing to alert you to the initial error.





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


Re: Functions vs OOP

2011-09-04 Thread William Gill

On 9/4/2011 7:41 PM, Steven D'Aprano wrote:

William Gill wrote:


The source of my error is "Functional Programming HOWTO
(/python-3.1.3-docs-html/howto/functional.html)"


For those who don't have access to William's local file system, I expect
he's looking at this:

http://docs.python.org/release/3.1.3/howto/functional.html

or the most recent version:

http://docs.python.org/dev/howto/functional.html


I didn't expect anyone to access my file system so I trimmed the path, 
but left enough for an industrious soul like yourself to figure it out. 
 You did, so it seems I was correct, or do you think "functional.html" 
would have been sufficient? ;-)




[...]

If you read the material with even a nominal understanding of the
functional paradigm (functional relationships in a mathematical sense,
not functions in the procedural sense), it is clear.  If you read it
without consciously recognizing this difference, the material does
nothing to alert you to the initial error.


What about the entire "Introduction" section, which starts with this
statement?

"This section explains the basic concept of functional programming"


Which clears up the misunderstanding, how?  Unless the target audience 
is people who already understands "the basic concept of functional 
programming."  That seems like a circular reference.


The article is introducing a concept.  To assume any familiarity with 
that concept as a basis, is not an introduction.


As previously stated; I was already familiar with the concepts of 
procedural, declarative, and object-oriented programming, but not 
functional programming.  Nothing I read (I'll be honest; scanned) did 
anything to contradict my incorrect point of reference.



If you would like to suggest improvements, please do so.


How about a caveat stating something like "NOTE: functional as in 
mathematical functions, not to be confused with functions/procedures."



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


Re: Functions vs OOP

2011-09-05 Thread William Gill

On 9/4/2011 9:13 AM, rusi wrote:

On Sep 3, 9:15 pm, William Gill  wrote:

During some recent research, and re-familiarization with Python, I came
across documentation that suggests that programming using functions, and
programming using objects were somehow opposing techniques.


Staying with (for the moment) the suggestion that OO-P and F-P are
complementary, I believe it is worthwhile to distinguish syntactic OO-
P vs F-P from semantic OO-P vs F-P.

Syntactically: f(x) is functional x.f() is object oriented.
Semantically if f's return value depends only on x ie does not depend
on state it is functional (in the math sense) -- the jargon is that f
is referentially transparent.


Not to split hairs, but syntactically f(x) is a function in many 
programming paradigms.


As I understand it functional programming places specific requirements 
on functions, i.e.referential transparency.  So f(x) may or may not be 
"functional".


x.f() is also a function, but it is a member of the object x, is 
referred to as a 'method' of x, and uses the syntactical "dot" notation 
object"dot"function for identification.



Referential opaqueness is usually such a source of problems that it
turns out good to contain the problem somewhat -- hence the wish for
encapsulation.

One can find in the python library itself all 4 combinations:
syntactically and semantically OO : sort
syntactically and semantically FP: sorted
syntactically OO semantically FP: join


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


Re: Functions vs OOP

2011-09-05 Thread William Gill

On 9/3/2011 12:25 PM, Steven D'Aprano wrote:

William Gill wrote:


Are they suggesting that any function that takes an object as an
argument should always be a method of that object?


Yes.


I can think of times when a special application, such as a converter, 
would take an object as an argument, but the somewhat unique nature of 
the application wouldn't justify changing the class to make the behavior 
into a method.


I could extend the underlying class to include the new behavior 
(method), but that would mean existing instances of the base class would 
need conversion to the new class, requiring yet another method.


Seems to me, that would be POOP (Puristic Object Oriented Programming) ;-)

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


Re: Functions vs OOP

2011-09-05 Thread William Gill

On 9/5/2011 3:04 PM, Jean-Michel Pichavant wrote:

William Gill wrote:


Not to split hairs, but syntactically f(x) is a function in many
programming paradigms.

As I understand it functional programming places specific requirements
on functions, i.e.referential transparency. So f(x) may or may not be
"functional".

x.f() is also a function, but it is a member of the object x, is
referred to as a 'method' of x, and uses the syntactical "dot"
notation object"dot"function for identification.



Functional programming is not about writing a programm with functions
. This may cause some confusion.


It can, and it did.  That was the impression I (incorrectly) got from 
the documentation.  Which didn't make sense to me.




(google it for more info).


I can, and I did.  That, and the answers I got in this ng are how I 
corrected my misconception.




Your original post was about functions vs methods, which are identical
except some syntax detail. FYI, in python x.f() is equivalent to f(x).
In an OOP world one will prefer the x.f() form.

No, my original post was about how (based on the aforementioned 
misconception) the documentation seemed to suggest that OOP should never 
have free standing functions, only methods.


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


RE: CentOS 5.5 x86_64 rpmbuild from source

2011-03-08 Thread William S .
I will answer myself. For those interested, because rpm will break the
dependencies on the OS,  you can install 2.7 with a simple bash script:
http://willsani.com/2011/03/02/centos-5-5-x86_64-install-python-2-7/ 

Regards,
Will 

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


Re: Inheriting Object

2011-05-19 Thread William . Bai
Hi Nav:

 Here is the long why.
http://www.python.org/download/releases/2.2.3/descrintro/
 I guess for most programs, there is no big difference. But in
term of some new added features in python, you might not be able to
work. Say, you could not use super in type, also you can't multiply
inherit from different built-in types, what's more you could not use
some builtin feature such as property.

BRs
William

On 01/-9/-28163 03:59 AM, Navkirat Singh wrote:
> Hi Guys,
>
> I have been wondering for a while now as to why some classes inherit
> Object? And what does it really do for the class? Can anyone shed some
> light on this?
>
> Regards,
> Nav

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


Re: Any good explanations on pd.merge(df,df2, on=['Code', 'Region'])

2017-11-08 Thread William Ayd
Assuming df and df2 are dataframes you are essentially doing a SQL-like join of 
the two objects where the records within match on both the Code and Region 
columns

Sent from my iPhone
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Trace back error just trying to run a simple import of requests

2018-02-01 Thread William Sewell
My python script which I run daily just blew up.  So, I went into python to 
diagnose and just typed in the first line - import requests.  I received 
screenfulls of errors.  Why?  What could have happened when nothing changed on 
my end?  The traceback is copied below.


[cid:image001.png@01D39B71.014E8850]


Dr. William Sewell
Direct Line: 385.428.5377  Toll Free: 877.435.7948 ext 5377
Course Instructor, IT

WGU will be closed President's Day, February 19th.
Mountain Time Office hours: Sun 3:00 PM - 8:00 PM, Mon 6:30 AM - 3:30 PM, Tue 
9:30 AM - 6:30 PM, Wed 9:00 AM - 5:00 PM, Thu 6:30 AM - 3:30 PM
Your success is very important to me.
IT MSDA and Database Team
cmdatab...@wgu.edu<mailto:cmdatab...@wgu.edu>
Toll Free: 1-877-435-7948
Student Services: 1-866-903-0110
WellConnect Counseling Services: 1-877-685-3269
Western Governors University
mailto:william.sew...@wgu.edu

[WGU]<https://timetrade.com/app/wgu-mentoring/workflows/WGU100/schedule/?locationId=course_mentoring&appointmentTypeGroupId=CM&resourceId=005a00CBjHbAAL>

More about WGU in Fast Company, CNN, NPR, NBC Nightly News, Money, The 
Atlantic, TIME, etc.<http://www.wgu.edu/>
wgu.edu<http://www.wgu.edu/>


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


RE: Trace back error just trying to run a simple import of requests

2018-02-01 Thread William Sewell
It is allright.  I just cannot account for the sudden change.  In my usual path 
everything worked fine.  Now, I have to navigate to where the Python 
executable, even though I have added the path to the Windows path.

Please close my case.


Dr. William Sewell
Direct Line: 385.428.5377  Toll Free: 877.435.7948 ext 5377
Course Instructor, IT

WGU will be closed President's Day, February 19th.
Mountain Time Office hours: Sun 3:00 PM - 8:00 PM, Mon 6:30 AM - 3:30 PM, Tue 
9:30 AM - 6:30 PM, Wed 9:00 AM - 5:00 PM, Thu 6:30 AM - 3:30 PM
Your success is very important to me.  
IT MSDA and Database Team 
cmdatab...@wgu.edu
Toll Free: 1-877-435-7948
Student Services: 1-866-903-0110
WellConnect Counseling Services: 1-877-685-3269
Western Governors University
mailto:william.sew...@wgu.edu



More about WGU in Fast Company, CNN, NPR, NBC Nightly News, Money, The 
Atlantic, TIME, etc.
wgu.edu


-Original Message-
From: Cameron Simpson [mailto:c...@cskk.id.au] 
Sent: Thursday, February 01, 2018 8:08 PM
To: William Sewell 
Cc: python-list@python.org
Subject: Re: Trace back error just trying to run a simple import of requests

On 01Feb2018 20:26, William Sewell  wrote:
>My python script which I run daily just blew up.  So, I went into python to 
>diagnose and just typed in the first line - import requests.  I received 
>screenfulls of errors.  Why?  What could have happened when nothing changed on 
>my end?  The traceback is copied below.
>
>
>[cid:image001.png@01D39B71.014E8850]

Please followup to the list with a cut/paste of the error text. This list is 
text only and strips attachments as an aid to readability.

We want to help you, but we deal in plain text - it is far more useful to all.

Cheers,
Cameron Simpson  (formerly c...@zip.com.au)

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


Re: ImportError: The ``fake-factory`` package is now called ``Faker``.

2016-12-20 Thread William Mayor
I came across this error this morning.

In my case I was running a script that did this: “pip install fake-factory”

The install worked properly but then I couldn’t import the library (with the 
same error message as you).

I had to update the pip install command to say “pip install Faker” and then 
everything worked as before.

The authors appear to have forced a name change: 
https://github.com/joke2k/faker/blob/fake-factory/faker/__init__.py 


I’ve just checked and if you pin your requirements (e.g. pip install 
fake-factory==0.7.4) then it still works.


> On 20 Dec 2016, at 16:57, Uri Even-Chen  wrote:
> 
> Hi, we get this error with Python 3.4 and 3.5:
> https://travis-ci.org/urievenchen/speedy-net/jobs/185497863
> 
> 
> --
> 
> ImportError: Failed to import test module:
> speedy.net.accounts.tests.test_factories
> 
> Traceback (most recent call last):
> 
>  File "/opt/python/3.5.2/lib/python3.5/unittest/loader.py", line 428,
> in _find_test_path
> 
>module = self._get_module_from_name(name)
> 
>  File "/opt/python/3.5.2/lib/python3.5/unittest/loader.py", line 369,
> in _get_module_from_name
> 
>__import__(name)
> 
>  File 
> "/home/travis/build/urievenchen/speedy-net/speedy/net/accounts/tests/test_factories.py",
> line 4, in 
> 
>import factory
> 
>  File 
> "/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/factory/__init__.py",
> line 46, in 
> 
>from .faker import Faker
> 
>  File 
> "/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/factory/faker.py",
> line 41, in 
> 
>import faker
> 
>  File 
> "/home/travis/virtualenv/python3.5.2/lib/python3.5/site-packages/faker/__init__.py",
> line 7, in 
> 
>raise ImportError(error)
> 
> ImportError: The ``fake-factory`` package is now called ``Faker``.
> 
> Please update your requirements.
> 
> 
> What is the problem? We didn't update our requirements recently.
> 
> Thanks,
> Uri.
> 
> *Uri Even-Chen*
> [image: photo] Phone: +972-54-3995700
> Email: u...@speedy.net
> Website: http://www.speedysoftware.com/uri/en/
>   
>    
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

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


[no subject]

2020-01-04 Thread William Johnsson
Hello! My name is William and im 14 years old and live in sweden.  Im pretty 
new to programing in python and i need some help with code, (That’s why i’m 
here). But i couldn’t really find what i was searching for on the internet. I’m 
trying to write code that can check only the first line in a .txt file and 
check if it’s the same as the int 1000.   I preferably want it to be an if 
satement but anything works, i just don’t know how i should write it. I’ve been 
browsing the internet for a solution but sadly can’t seem to find a solution to 
it.

I don’t really know if this is the right way to get help or even if this email 
is for something else. Hopefully i will get some kind of response.

Best regards, William
-- 
https://mail.python.org/mailman/listinfo/python-list


Puzzling difference between lists and tuples

2020-09-17 Thread William Pearson
I am puzzled by the reason for this difference between lists and tuples.

A list of with multiple strings can be reduced to a list with one string with 
the expected results:

for n in ['first','second']:
print n

for n in ['first']:
print n

The first loop prints "first", "second", and the second prints "first".



This is not true for a tuple:

for n in ('first','second'):
print n

for n in ('first'):
print n


prints "first", "second" in the first case, but "f","i","r","s","t" in the 
second.

Where is this inconsistency explained?

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


Re: Simple Dialogs

2005-09-29 Thread William Park
[EMAIL PROTECTED] wrote:
> I'm looking for a lightweight dialog boxes from Python.
> JavaScript uses: alert(), confirm() and prompt()
> VB uses: MsgBox() and InputBox()
> EasyGui seemed perfect, but a "Hello World" application takes nearly a
> minute to execute after the program has been compiled by py2exe.
> 
> There appear to be dozens of windowing toolkits avilable for Python,
> could someone point me in the direction of something lightweight?

If you can run it outside Python, then
http://home.eol.ca/~parkw/index.html#gtk
will get you started.

If you must run it inside Python, then you should look into Python
wrapper for GTK+, and write the code yourself.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamic character substitution.

2005-09-29 Thread William Park
John Bausano <[EMAIL PROTECTED]> wrote:
> Hello all,
> 
> 
> 
> I've been using Ansys which is a commercial FEA package which can be 
> controlled through its own scripting language they call APDL.  Now I'm 
> trying to write some stand alone code in Python to supplement my current 
> efforts.
> 
> 
> 
> In Ansys I can do something like this.
> 
> 
> 
> *do,n,1,3  #loop 
> through n
> 
> *dim,data%n%,1000,2 #creates variables 
> arrays data1(1000,2), data2(1000,2)..
> 
> *vread,data%n%,filename%n%#fills arrays with data 
> from filename1,.


I await English translation of the above.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Info] PEP 308 accepted - new conditional expressions

2005-10-11 Thread William Park
Paul Rubin <http://[EMAIL PROTECTED]> wrote:
> Reinhold Birkenfeld <[EMAIL PROTECTED]> writes:
> > For a conditional, syntax must be found, and the tradition of Python
> > design is not to use punctuation for something that can be solved
> > with keywords.
> 
> Yeah, "if C then A else B" is a ancient tradition stretching from
> Algol-60 to OCAML, and who knows what all else in between.  I'm not
> sure what Guido saw in the "A if C else B" syntax but it's not a big
> deal.

Perhaps, he's preparing Python for the eventual absorption into Perl7.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: need some advice on x y plot

2005-10-21 Thread William Park
[EMAIL PROTECTED] wrote:
> the time is DateTime.DateTime object from a mySQLdb query.
> the value is a number anywhere between 0 and 15.
> the datetime is formatted like 2005-10-20 08:40:34
> 
> i could strip it and make a timestamp out of it. but reading the
> number of seconds since january of 1970 doesn't make a neat chart.
> 
> any suggestions?

Python is capable of integer arithmetic, eg.
>>> 2000 - 500
1500

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to replace first word in string?

2005-10-21 Thread William Park
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I am looking for the best and efficient way to replace the first word
> in a str, like this:
> "aa to become" -> "/aa/ to become"
> I know I can use spilt and than join them
> but I can also use regular expressions
> and I sure there is a lot ways, but I need realy efficient one

I doubt you'll find faster than Sed.

man sed

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: best way to replace first word in string?

2005-10-22 Thread William Park
Chris F.A. Johnson <[EMAIL PROTECTED]> wrote:
> On 2005-10-22, William Park wrote:
> > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >> I am looking for the best and efficient way to replace the first word
> >> in a str, like this:
> >> "aa to become" -> "/aa/ to become"
> >> I know I can use spilt and than join them
> >> but I can also use regular expressions
> >> and I sure there is a lot ways, but I need realy efficient one
> >
> > I doubt you'll find faster than Sed.
> 
>On the contrary; to change a string, almost anything will be faster
>than sed (except another external program).
> 
>If you are in a POSIX shell, parameter expansion will be a lot
>faster.
> 
>In a python program, one of the solutions already posted will be
>much faster.

Care to put a wager on your claim?

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: XML GUI

2005-11-09 Thread William Park
py <[EMAIL PROTECTED]> wrote:
> Looking for information on creating a GUI using a configuration file
> (like an XML file or something).  Also, how do you map actions (button
> clicks, menu selections, etc) to the XML?
> 
> Any other suggestions for building GUI's for Python projects...even
> Jython.

If you're talking about simple "dialog" thing, where you ask question
and users respond, then take a look at
http://home.eol.ca/~parkw/index.html#gtk

Also, you may want to look at Glade which spits out the layout in XML.

But, for more intricate to-and-fro, use C and GTK+2. :-)

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python choice of database

2005-06-20 Thread William Park
Philippe C. Martin <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> I am looking for a stand-alone (not client/server) database solution
> for Python.
> 
> 1) speed is not an issue
> 2) I wish to store less than 5000 records
> 3) each record should not be larger than 16K
>
> As I start with Python objects, I thought of using shelve, but looking
> at the restrictions (record size + potential collisions) I feel I
> should study my options a bit further before I get started.

Possible approach might be:
1.  5000 files -- my personal favourite.
2.  GDBM
3.  SQLite

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Full featured Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


'custom' events ?

2005-06-22 Thread William Gill
I am trying to create a Python UI in Tkinter and have several (frame) 
widgets that display various data fields.  I am trying to create a 
'changed' event that each widget can trigger when they have been edited. 
  I see lots of references that suggest that 'custom' events can be 
created, but haven’t found any that give me a clue as to how.  Also, can 
parent or sibling widgets capture the 'custom' event (similar to using 
)?

Thanks,

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


a comprehensive Tkinter document?

2005-06-22 Thread William Gill
I know a major problem I am having is that I am finding lots of Tkinter 
information in 'fragments' of various , sometimes conflicting vintages. 
  For example the python reference I was using didn't show the '%%' as 
an escape sequence, I posted asking how to escape the '%' and after 
several helpful responses voila I found a more complete table of escape 
sequences.  Is there a comprehensive document or book that I can get 
that is relatively current?  I realize that updates and changes are 
dynamic, but I'm realizing that I am trying to use documents that look 
similar, only to find that one is several years old, or that another 
applies to an offshoot of Tkinter.  I'm not even sure Tkinter is the 
'preferred' gui anymore.  Any suggestions?

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


Re: a comprehensive Tkinter document?

2005-06-22 Thread William Gill
Kent Johnson wrote:
> William Gill wrote:
> 
>> I know a major problem I am having is that I am finding lots of 
>> Tkinter information in 'fragments' of various , sometimes conflicting 
>> vintages.  For example the python reference I was using didn't show 
>> the '%%' as an escape sequence, I posted asking how to escape the '%' 
>> and after several helpful responses voila I found a more complete 
>> table of escape sequences.  Is there a comprehensive document or book 
>> that I can get that is relatively current?  
> 
> 
> Maybe not comprehensive but I think reasonably current:
> http://www.pythonware.com/library/tkinter/introduction/index.htm
> http://infohost.nmt.edu/tcc/help/pubs/tkinter/
> 
> Kent

Yes, these are two of my staples, though I have occasionally slipped 
into 'copies' elsewhere that aren't kept up.

Thanks,

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


pass an event up to parent widget

2005-06-23 Thread William Gill
I have a Tkinter (frame) widget that contains several other frame 
widgets, each containing entry widgets.  In the parent frame I have a 
'save' button that is initially disabled.  As it is now, each widget has 
a hasChanged property that I can poll to see if updates to the source 
data need to be made.  hasChanged is set to True by an event routine in 
each frame widget, and this works fine for my exit routine which knows 
to poll each widget for hasChanged.  What I don't know how to do is send 
an event up the chain to the top so it can change the 'save' button to 
NORMAL (telling the user 'The data has been changed and can be saved if 
wanted') .  I don’t think bind_class() to all entry widgets is the way 
to go.  I could create an after() alarm callback to poll hasChanged, but 
again this seems to awkward.  I have looked at widget.event_add() but, 
don't know if this is viable. I am thinking a virtual event without any 
SEQUENCE, and then triggering it programmatically (from within the 
sub-widget event handlers).  Is that doable? Isn't there a better way?


Any suggestions?


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


Re: Favorite non-python language trick?

2005-06-25 Thread William Heymann
On Friday 24 June 2005 02:53 pm, D H wrote:

> Again, you are splitting hairs.  His point still stands that it is not
> possible to do method overloading in python (unless you use decorator
> hacks).  It may be possible to add this feature when type declarations
> and type checking are added to a future version of python.

Decorators are actually a syntax hack remember. Everything you can do in a 
decorator you could do with python before since they work via nested scopes. 
It is easy to write wrapper methods and I use them for many purposes but not 
for type checking. 

Wrapper methods are very useful to take out common checking code. The checking 
of conditions does not really belong in the caller (the caller could forget), 
it does not really belong in the called function since that is not that 
functions purpose but putting it in a wrapper and having it wrap the called 
function sure gives a nice seperation and makes life simpler.
-- 
http://mail.python.org/mailman/listinfo/python-list


tkinter radiobutton

2005-06-25 Thread William Gill
I am placing radiobuttons in a 4 X 4 matrix (using loops) and keep 
references to them in a 2 dimensional list ( rBtns[r][c] ).  It works 
fine, and I can even make it so only one button per column can be 
selected, by assigning each column to an intVar.  In many languages a 
radiobutton has a property that can be directly read to see if it is 
selected on unselected.  Tkinter radiobuttons don't seem to have any 
such property.  Is there any way to look (via the script not the screen) 
to determine if it is selected?, or can this only be achieved via 
control variables?

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


Re: tkinter radiobutton

2005-06-27 Thread William Gill
 >> to determine if it is selected?, or can this only be achieved via
 >> control variables?

 > The value and variable options for a radiobutton seem to be what
 > you're looking for.

Thanks, I knew that, but I was looking for a way to read the 
selected/unselected status directly.  Using control variables gets a 
little messy because of the relationship of the rb matrix.  They are 
arranged in a 4 X 4 matrix where each column is grouped (via intVars) so 
that no more than 1 rb per column can be selected, but each row makes up 
the 'status' on one 'item' so any combination of buttons in a row is 
acceptable.

One solution I have been contemplating requires setting the value of 
each rb to the row number ( 0, 1, 2, or 3 or 1,2,3, or 4 in case I need 
to use 0 for 'none selected'), and using one intVar for each column. 
Then I would have to loop through all four intVars four times to 
determine which radiobuttons are selected in each row.  That's what I 
mean by messy.

Bill

Eric Brunel wrote:
> On Sat, 25 Jun 2005 19:34:50 GMT, William Gill <[EMAIL PROTECTED]> wrote:
> 
>> I am placing radiobuttons in a 4 X 4 matrix (using loops) and keep
>> references to them in a 2 dimensional list ( rBtns[r][c] ).  It works
>> fine, and I can even make it so only one button per column can be
>> selected, by assigning each column to an intVar.  In many languages a
>> radiobutton has a property that can be directly read to see if it is
>> selected on unselected.  Tkinter radiobuttons don't seem to have any
>> such property.  Is there any way to look (via the script not the screen)
>> to determine if it is selected?, or can this only be achieved via
>> control variables?
> 
> 
> The value and variable options for a radiobutton seem to be what you're 
> looking for. Here is an example showing how to use them:
> 
> 
> from Tkinter import *
> 
> root = Tk()
> v = StringVar()
> Radiobutton(root, text='foo', value='foo', variable=v).pack()
> Radiobutton(root, text='bar', value='bar', variable=v).pack()
> 
> def p():
>   print v.get()
> 
> Button(root, command=p, text='Print').pack()
> 
> root.mainloop()
> 
> 
> HTH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter radiobutton

2005-06-28 Thread William Gill
 > or use a custom subclass ...

I had considered extending radiobutton to add whatever properties 
needed, but the net/net is the same, that property must be set using 
methods that trigger on the rb command procedure, or an external (to the 
rb) control variable value.

The radiobutton widget knows if it is selected or unselected, or it 
wouldn't be able to display correctly, but based on what I'm seeing, 
that information is inaccessable to the app.  Instead the app must 
evaluate an associated control variable.  That doesn't make sence to me, 
but even trying to look at the code for the radiobutton class didn't help.

I guess I need to set up an observer on the control variable, or a 
command procedure on the radiobutton (effectively to create my own 
control variable).

I know I can 'slice' my original 4 X 4 matrix vertically, by associating 
a different intVar to each 'column', but I can't figure out how to 
'slice' them horizontally w/o breaking their vertical relationships.


Bill

Peter Otten wrote:
> William Gill wrote:
> 
> 
>>I am placing radiobuttons in a 4 X 4 matrix (using loops) and keep
>>references to them in a 2 dimensional list ( rBtns[r][c] ).  It works
>>fine, and I can even make it so only one button per column can be
>>selected, by assigning each column to an intVar.  In many languages a
>>radiobutton has a property that can be directly read to see if it is
>>selected on unselected.  Tkinter radiobuttons don't seem to have any
>>such property.  Is there any way to look (via the script not the screen)
>>to determine if it is selected?, or can this only be achieved via
>>control variables?
> 
> 
> You can either write a little helper function
> 
> def selected(rbn):
> return rbn.getvar(rbn["variable"]) == rbn["value"]
> 
> or use a custom subclass of Tkinter.Radiobutton with a 'selected' attribute:
> 
> class Radiobutton(Tkinter.Radiobutton):
> def __getattr__(self, name):
> if name == "selected":
> return self.getvar(self["variable"]) == self["value"]
> raise AttributeError
> 
> 
> Peter
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter radiobutton

2005-06-28 Thread William Gill
I thought the problem was practical, not philosophical, but what do I 
know I'm the one asking for help.

I have radiobuttons arranged in 4 rows of 4 buttons each ( 4 rows and 4 
columns )

The user can select no more than 1 choice in any column, but any number 
in any row.

   Restated:
   columns can have 0 or 1 selection
   rows can have 0,1,2,3, or 4 selections.


Columns can be restricted to 0 or 1 selection through the use of an 
intVar. So we now have 4 intVars (control variables)

The app needs to examine the buttons and aggregate the selections for 
each row, efectively converting columnar information to row information.

one solution:

Create 4 intVars
 Column0 = intVar()
 Column1 = intVar()
 Column2 = intVar()
 Column3 = intVar()

Assign  0, 1, 2, 3 and 4 to values to correspond to the row number.
Row1rb1  =  Radiobutton(self, variable = Column0, value = 1)
Row1rb2  =  Radiobutton(self, variable = Column1, value = 1)
Row1rb3  =  Radiobutton(self, variable = Column2, value = 1)
Row1rb4  =  Radiobutton(self, variable = Column3, value = 1)
Row2rb1  =  Radiobutton(self, variable = Column0, value = 2)
Row2rb2  =  Radiobutton(self, variable = Column1, value = 2)
…
…
Row4rb4  =  Radiobutton(self, variable = Column3, value = 4)

to 'read' the user's response:

Loop through the 4 intVars 4 times; compare their value to the value for 
the row being processed; if they are the same bitor a value to a 
rowVariable i.e. convert the column information (intVar values) to row 
information.


Bill



Peter Otten wrote:
> William Gill wrote:
> 
> 
>>The radiobutton widget knows if it is selected or unselected, or it
>>wouldn't be able to display correctly, but based on what I'm seeing,
>>that information is inaccessable to the app.  Instead the app must
>>evaluate an associated control variable.  That doesn't make sence to me,
>>but even trying to look at the code for the radiobutton class didn't help.
> 
> 
> I guessed you wanted to solve a practical problem, but the thoughts
> expressed above suggest, err, philosophical qualms. So, for the sake of the
> argument and since we both don't know the implementation details, be it in
> C or TCL, let's assume that the individual radiobuttons do *not* /know/
> whether they are selected or not but instead compare their associated
> 'variable' with their 'value' every time they are /asked/ to draw
> themselves. That would avoid duplicate state and require only log N instead
> of N bits. Wouldn't that be an elegant implementation, at least in theory?
> 
> So why bother about the layers below when you have all the information to
> write code that works?
> 
> Peter
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter radiobutton

2005-06-28 Thread William Gill
 > What follows looks more like a spec than a question.
It is, but  I wanted to show why I was getting confused trying to use 
control variables to maintain the overall relationship.

Thank you.  This is exactly what I'm trying to do, and oddly enough 
similar in concept to what I was doing, but far more readable and 
maintainable (thus the philosophical component :-))
using 'for x, column in enumerate(columns):' for a looping structure
cleared up a lot of the convoluted 'score keeping' I was trying to do in 
my nested loops.

Also, does 'row == var.get() for var in self.variables' perform the 
comparison row == var.get() for each item in self.variables?  I would 
have had to write:

for var in self.variables:
   return row == var.get()

Again, thanks.

Bill

Peter Otten wrote:
> William Gill wrote:
> 
> 
>>I thought the problem was practical, not philosophical, but what do I
>>know I'm the one asking for help.
> 
> 
> What follows looks more like a spec than a question.
> 
> 
>>   columns can have 0 or 1 selection
>>   rows can have 0,1,2,3, or 4 selections.
> 
> 
>>Loop through the 4 intVars 4 times; compare their value to the value for
>>the row being processed; if they are the same bitor a value to a
>>rowVariable i.e. convert the column information (intVar values) to row
>>information.
> 
> 
> Here's my implementation: 
> 
> import Tkinter as tk
> 
> class Radiogrid(tk.Frame):
> def __init__(self, master, columns, trace_write=None):
> tk.Frame.__init__(self)
> self.variables = []
> self.buttons = []
> for x, column in enumerate(columns):
> var = tk.IntVar()
> if trace_write:
> var.trace_variable("w", trace_write)
> self.variables.append(var)
> self.buttons.append([])
> for y, text in enumerate(column):
> rbn = tk.Radiobutton(self, text=text, variable=var, value=y)
> rbn.grid(column=x, row=y)
> self.buttons[-1].append(rbn)
> def get_row_state(self, row):
> return tuple(row == var.get() for var in self.variables)
> 
> if __name__ == "__main__":
> root = tk.Tk()
> def show_state(*args):
> for i in range(3):
> print "row", i, rg.get_row_state(i)
> print
> rg = Radiogrid(root,
>  ["alpha beta gamma".split(),
>  "one two three".split(),
>  "guido van rossum".split()],
>  show_state
> )
> rg.pack()
> root.mainloop()
> 
> I hope this will move further discussion from the abstract to the
> concrete :-)
> 
> Peter
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter radiobutton

2005-06-28 Thread William Gill
p.s.  I tweaked

rbn = tk.Radiobutton(self, text=text, variable=var, value=y)
   to
rbn = tk.Radiobutton(self, text=text, variable=var, value=y+1)

   and

return tuple(row == var.get() for var in self.variables)
   to
return tuple(row+1 == var.get() for var in self.variables)

so that the Radiogrid doesn't initialize w/row 1 selected, and 
accomodates cases where nothing is selected in any column.

Bill

Peter Otten wrote:
> William Gill wrote:
> 
> 
>>I thought the problem was practical, not philosophical, but what do I
>>know I'm the one asking for help.
> 
> 
> What follows looks more like a spec than a question.
> 
> 
>>   columns can have 0 or 1 selection
>>   rows can have 0,1,2,3, or 4 selections.
> 
> 
>>Loop through the 4 intVars 4 times; compare their value to the value for
>>the row being processed; if they are the same bitor a value to a
>>rowVariable i.e. convert the column information (intVar values) to row
>>information.
> 
> 
> Here's my implementation: 
> 
> import Tkinter as tk
> 
> class Radiogrid(tk.Frame):
> def __init__(self, master, columns, trace_write=None):
> tk.Frame.__init__(self)
> self.variables = []
> self.buttons = []
> for x, column in enumerate(columns):
> var = tk.IntVar()
> if trace_write:
> var.trace_variable("w", trace_write)
> self.variables.append(var)
> self.buttons.append([])
> for y, text in enumerate(column):
> rbn = tk.Radiobutton(self, text=text, variable=var, value=y)
> rbn.grid(column=x, row=y)
> self.buttons[-1].append(rbn)
> def get_row_state(self, row):
> return tuple(row == var.get() for var in self.variables)
> 
> if __name__ == "__main__":
> root = tk.Tk()
> def show_state(*args):
> for i in range(3):
> print "row", i, rg.get_row_state(i)
> print
> rg = Radiogrid(root,
>  ["alpha beta gamma".split(),
>  "one two three".split(),
>  "guido van rossum".split()],
>  show_state
> )
> rg.pack()
> root.mainloop()
> 
> I hope this will move further discussion from the abstract to the
> concrete :-)
> 
> Peter
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter radiobutton

2005-06-29 Thread William Gill
I did some more digging based on your code, and discovered list 
comprehensions.  They didn't register the first time I skimmed the 
language reference and tutorial.  It's obvious the more I learn, the 
more I need to relearn what I think I know.  I need to study 
comprehensions, but they open up lots of opportunities for simpler, 
clearer code.

 >>return row == var.get()
Oops!  I saw this as soon as I sent it, but knew you would get my point.

 > var.set(-1)
Though both ways may seem roughly equivalent today, I'd bet that in 6 
months

...
var.set(-1) # initialize as no choice
...

will be clearer.

Thanks again!

Bill

Peter Otten wrote:
> William Gill wrote:
> 
> 
>>Also, does 'row == var.get() for var in self.variables' perform the
>>comparison row == var.get() for each item in self.variables?  I would
>>have had to write:
>>
>>for var in self.variables:
>>return row == var.get()
> 
> 
> Or rather
> 
> result = []
> for var in self.variables:
> result.append(row == var.get())
> return tuple(result)
> 
> This can be rewritten to a 'list comprehension'
> 
> return tuple([row == var.get() for var in self.variables])
> 
> and, since Python 2.4, to the 'generator expression' that I used and which
> avoids building the intermediate list. Both constructs also feature an
> if-clause, see
> 
> http://docs.python.org/tut/node7.html#SECTION00714
> http://docs.python.org/tut/node11.html#SECTION000
> 
> 
>>p.s.  I tweaked
>>
>>rbn = tk.Radiobutton(self, text=text, variable=var, value=y)
>>to
>>rbn = tk.Radiobutton(self, text=text, variable=var, value=y+1)
>>
>>and
>>
>>return tuple(row == var.get() for var in self.variables)
>>to
>>return tuple(row+1 == var.get() for var in self.variables)
>>
>>so that the Radiogrid doesn't initialize w/row 1 selected, and
>>accomodates cases where nothing is selected in any column.
> 
>  
> Another option would have been to initialize the variables
> 
> ...
> var = tk.IntVar()
> var.set(-1)
> if trace_write:
> ...
> 
> Peter
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Escaping commas within parens in CSV parsing?

2005-07-03 Thread William Park
felciano <[EMAIL PROTECTED]> wrote:
> Thanks for all the postings. I can't change delimiter in the source
> itself, so I'm doing it temporarily just to handle the escaping:
> 
> def splitWithEscapedCommasInParens(s, trim=False):
> pat = re.compile(r"(.+?\([^\(\),]*?),(.+?\).*)")
> while pat.search(s):
> s = re.sub(pat,r"\1|\2",s)
> if trim:
> return [string.strip(string.replace(x,"|",",")) for x in
> string.split(s,",")]
> else:
> return [string.replace(x,"|",",") for x in 
> string.split(s,",")]
> 
> Probably not the most efficient, but its "the simplest thing that
> works" for me :-)
> 
> Thanks again for all the quick responses.

How about changing '(' or ')' into three double-quotes '"""'?  That will
solve splitting issue.  But, I'm not sure how you would get back '(' or
')', without much coding.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter grid layout

2005-07-06 Thread William Gill
Excuse me for intruding, but I followed examples and ended up with a 
similar architecture:

 from Tkinter import *
 class MyMain(Frame):
 def __init__(self, master):
 self.root = master
 self.master=master
 root = Tk()
 app = MyMain(root)
 app.master.title("Object Editor")
 root.mainloop()

Erick, are you saying it should be modified to something like :

 from Tkinter import *
 class MyMain(Tk):
 ...
 ...
 app = MyMain()
 app.title("My App")
 app.mainloop()

Thanks,
Bill

Eric Brunel wrote:
> On Wed, 06 Jul 2005 11:44:55 +0100, Richard Lewis 
> <[EMAIL PROTECTED]> wrote:
> 
>> Hi there,
>>
>> I've got a tree control in Tkinter (using the ESRF Tree module) but I
>> can't get it to layout how I want it.
>>
>> I'd like to have it so that it streches north/south (anchored to the top
>> and bottom), is of a fixed width and is anchored to the left hand side.
>> Here's my code (its derived from one of the examples from the ESRF web
>> site):
>>
>> class MainWindow(Frame):
> 
> [snip code]
> 
> First of all, it is not a good idea to make your so-called window 
> inherit from Frame: a Frame is not a window in tk, but a generic 
> container. Creating a Frame without a container window will 
> automatically initialize the tk toolkit, creating a default window which 
> will become the default parent for widgets where you don't specify one. 
> According to the well-known "explicit is better than implicit" 
> principle, if a MainWindow instance are actually the main window for 
> your application, you'd really better inherit from the Tkinter class for 
> the main window, which is Tk. Doing it this way has a lot of advantages 
> over what you do; for example, if you later have to create a menu bar 
> for your application, you will be able to do it in the MainWindow class. 
> If you inherit from Frame, you won't get any access to the actual 
> window, so you won't be able to create a menu in it.
> 
> This may seems to be unrelated to your problem, but it's not: by 
> creating a Frame, you introduce one more unneeded container. So, in some 
> code you don't show here, you have to insert the MainWindow instance 
> into its parent window via a call to its pack or grid method. Since the 
> code you show seems to be correct, I guess the problem is in this call 
> to pack or grid, which probably does not tell the Frame how to behave 
> when its parent window is resized, causing it to get the default 
> behaviour, which is "do nothing at all".
> 
> To be sure this actually is the problem, try to replace the line:
> Frame.__init__(self, master)
> in MainWindow.__init__ by:
> Frame.__init__(self, master, bg='blue', bd=2)
> This way, a blue border will appear around the frame, allowing you to 
> see how it grows.
> Then run your application, and resize the window. You should see that 
> the frame does not grow when the window grows, explaining why your tree 
> deos not grow (in fact, it would grow if its container did; but its 
> container doesn't...)
> 
> So you should either make your MainWindow class inherit from Tk, which 
> eliminates the unneeded container and the problems it may cause, or make 
> sure the pack or grid on your MainWindow instance actually tells the 
> container to grow with its container. With pack, it's quite easy: just 
> do myWindow.pack(fill=BOTH, expand=1). With grid, it's a bit more 
> complicated, since you will have to configure the grid on the container.
> 
> But basically, my advice would be:
> - Never make your windows inherit from Frame; make them inherit from Tk 
> for the main window or from Toplevel for all other ones
> - When you have resize problems, always check the whole widget hierarchy 
> from the actual window down to the widget showing the problem. The cause 
> is very often not on the widget itself, but on one of its containers.
> 
> HTH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter Button widget

2005-07-14 Thread William Park
Peter Otten <[EMAIL PROTECTED]> wrote:
> Shankar Iyer ([EMAIL PROTECTED]) wrote:
> 
> >  I have another Tkinter-related question.  At the beginning of my
> >  program, a tkinter window is created with six buttons.  Each of these
> >  buttons is assigned a function that should be executed only when the
> >  button is pressed.  However, it seems that these functions are all
> >  executed once when the button widgets are first created.  Why is this
> >  the case and how do I prevent this from happening?
> 
> Change your source code from 
> 
> # wrong
> button = Tkinter.Button(..., command=some_function(),...)
> 
> to
> 
> # correct
> button = Tkinter.Button(..., command=some_function,...)
> 
> to pass the *function* to the widget instead of the *result* of a
> function call. And, next time, remember to post some code alongside
> with your question.

Hmm, maybe I should learn Tk + Python.  Telepathetic powers of Python
programmers are amazing.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: all possible combinations

2005-07-14 Thread William Park
rbt <[EMAIL PROTECTED]> wrote:
> Say I have a list that has 3 letters in it:
> 
> ['a', 'b', 'c']
> 
> I want to print all the possible 4 digit combinations of those 3
> letters:
> 
> 4^3 = 64
> 
> 
> abaa
> aaba
> aaab
> acaa
> aaca
> aaac
> ...
> 
> What is the most efficient way to do this? 

Since you're doing cross product (ie. 3*3*3*3), manual loop of 4 level
deep would be the fastest in terms of algorithm.  C vs. Python is
implementation detail.

In Bash shell, this is one-liner,
echo {a,b,c}{a,b,c}{a,b,c}{a,b,c}
or maybe two,
abc=(a b c)
echo {^abc}{^abc}{^abc}{^abc}

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Python vs. Access VBA

2005-07-15 Thread William Lodge
I'm at a loss on how to compare Python vs. Access VBA for a database
project. I'm estimating 20 tables and several forms and reports. Some of the
tables could grow to many thousands of rows w/i a year or so. The app would
be resident on my client as no network connectivity is needed b/c I'll be
the only user. I'd probably use Access tables for now and plan on scaling up
to Oracle later if necessary (which it probably won't be).

If the project is successful, it may be adopted in the division. There is no
time limit but this is being done on my own time, and my guestimate for a
practical limit would be 3-4 months. I'm not a developer but have done
programming in the academic world as part of MSIS degree. I also want the
app to have a GUI. 

I'm currently reviewing Wingware's Python product. Will review Komodo next.
It doesn't appear that the Wingware product has a GUI builder, but Komodo's
Pro version does (although more costly). Anybody have any recommendations in
this regard? Any thoughts as to whether implementing in Python would be any
harder or easier to do than in Access?

Finally, does anybody know of any Web sites having examples of database apps
in Python?

Thanks for your help. Bill
<>-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Parsing html :: output to comma delimited

2005-07-16 Thread William Park
samuels <[EMAIL PROTECTED]> wrote:
> Hello All,
> 
> I am a total python newbie, and I need help writing a script.
> 
> This is what I want to do:
> 
> There is a list of links at http://www.rentalhq.com/fulllist.asp.  Each
> link goes to a page like,
> http://www.rentalhq.com/store.asp?id=907%2F272%2D4425, that contains a
> company name, address, phone, and fax.  I want extract each page, parse
> this information, and export it to a comma delimited text file, or tab
> delimited.  The important information in each page is:
> 
>  style="border-collapse: collapse" bordercolor="#11" width="100%"
> id="AutoNumber1">
>   
> 
> 
> United Rentals Inc.
> 
> 
> 3401 Commercial Dr. 
> Anchorage AK, 99501-3024
> 
> 
>  href="http://maps.google.com/maps?q=3401+Commercial+Dr%2E Anchorage AK
> 99501-3024 ">
> 
>  border="0">
> 
> 
>   
>   
> 
>  
> 
> 
> Phone - 907/272-4425
>  Fax - 907/272-9683 
> 
> So from that I want output like :
> 
> United Rentals Inc.,3401 Commercial
> Dr.,Anchorage,AK,"995013024","9072724425","9072729683"
> 
> or
> 
> United Rentals Inc. 3401 Commercial
> Dr. Anchorage   AK  995013024   9072724425  9072729683
> 
> 
> I have been messing around with beautiful soup
> (http://www.crummy.com/software/BeautifulSoup/index.html) but haven't
> gotten very far. (specially because the html is so sloppy)
> 
> Any help would be really appreciated!  Just point me in the right
> direction, what to use, examples...  Thanks!

I'm sure others will give proper Python solution.  But, here, shell is
not a bad tool.

lynx -dump 'http://www.rentalhq.com/store.asp?id=907%2F272%2D4425' | \
awk '/Return to List of Rental Stores/,/To reserve an item/' | \
sed -n -e '3p;5p;10p;11p'

gives me

United Rentals Inc.
3401 Commercial Dr.  Anchorage AK, 99501-3024
   Phone - 907/272-4425
   Fax - 907/272-9683

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


main window in tkinter app

2005-07-18 Thread William Gill
A short while ago someone posted that(unlike the examples) you should 
use Tk as the base for your main window in tkinter apps, not Frame.   Thus :

   class MyMain(Frame):
   def __init__(self, master):
   self.root = master
   self.master=master
   self.createWidgets()
   def createWidgets():
...
   root = Tk()
   app = MyMain(root)
   app.master.title("Object Editor")
   root.mainloop()

would become:

class MyMain(Tk):
   ...
   ...
app = MyMain()
app.title("My App")
app.mainloop()

When I try converting to this approach I run into a problem with the 
__init__() method.  It appears to go into an infinite loop in 
tkinter.__getattr__().

If I omit __init__() I get a properly titled window, but must explicitly 
call my createWidgets method from __main__.

class MyMain(Tk):
   createWidgets()
 ...
   ...

app = MyMain()
app.title("My App")
app.createWidgets()
app.mainloop()

Am I missing something?

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


Re: main window in tkinter app

2005-07-19 Thread William Gill
 > I never ran into this problem. ...

O.K. That, means I probably have something else wrong.  I will need to 
start with a 'clean slate' instead of trying to modify existing code. 
It's getting to convoluted to follow anyway after all the cobbling I've 
done.

If I get a repeat of the original problem I will post the code and the 
exact error message, but at least now I know It SHOULD work.

Thanks

Bill,


Eric Brunel wrote:
> On Mon, 18 Jul 2005 16:57:51 GMT, William Gill <[EMAIL PROTECTED]> wrote:
> 
>> A short while ago someone posted that(unlike the examples) you should
>> use Tk as the base for your main window in tkinter apps, not Frame.   
>> Thus :
>>
>>class MyMain(Frame):
>>def __init__(self, master):
>>self.root = master
>>self.master=master
>>self.createWidgets()
>>def createWidgets():
>> ...
>>root = Tk()
>>app = MyMain(root)
>>app.master.title("Object Editor")
>>root.mainloop()
>>
>> would become:
>>
>> class MyMain(Tk):
>>...
>>...
>> app = MyMain()
>> app.title("My App")
>> app.mainloop()
>>
>> When I try converting to this approach I run into a problem with the
>> __init__() method.  It appears to go into an infinite loop in
>> tkinter.__getattr__().
> 
> [...]
> 
> I never ran into this problem. Can you please post a short script 
> showing this behavior? Without knowing what you exactly do in your 
> __init__ and createWidgets method, it's quite hard to figure out what 
> happens...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: main window in tkinter app

2005-07-19 Thread William Gill
O.K. I tried from scratch, and the following snippet produces an 
infinite loop saying:

   File "C:\Python24\lib\lib-tk\Tkinter.py", line 1647, in __getattr__
   return getattr(self.tk, attr)

If I comment out the __init__ method, I get the titled window, and print 
out self.var ('1')


import  os
from Tkinter import *

class MyApp(Tk):
 var=1
 def __init__(self):
   pass
 def getval(self):
   return self.var


app = MyApp()

app.title("An App")
print app.getval()
app.mainloop()


Eric Brunel wrote:
> On Mon, 18 Jul 2005 16:57:51 GMT, William Gill <[EMAIL PROTECTED]> wrote:
> 
>> A short while ago someone posted that(unlike the examples) you should
>> use Tk as the base for your main window in tkinter apps, not Frame.   
>> Thus :
>>
>>class MyMain(Frame):
>>def __init__(self, master):
>>self.root = master
>>self.master=master
>>self.createWidgets()
>>def createWidgets():
>> ...
>>root = Tk()
>>app = MyMain(root)
>>app.master.title("Object Editor")
>>root.mainloop()
>>
>> would become:
>>
>> class MyMain(Tk):
>>...
>>...
>> app = MyMain()
>> app.title("My App")
>> app.mainloop()
>>
>> When I try converting to this approach I run into a problem with the
>> __init__() method.  It appears to go into an infinite loop in
>> tkinter.__getattr__().
> 
> [...]
> 
> I never ran into this problem. Can you please post a short script 
> showing this behavior? Without knowing what you exactly do in your 
> __init__ and createWidgets method, it's quite hard to figure out what 
> happens...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: main window in tkinter app

2005-07-19 Thread William Gill
It also seems to operate the same with or without " app.mainloop()".  Is 
an explicit call to mainloop needed?

William Gill wrote:
> O.K. I tried from scratch, and the following snippet produces an 
> infinite loop saying:
> 
>   File "C:\Python24\lib\lib-tk\Tkinter.py", line 1647, in __getattr__
>   return getattr(self.tk, attr)
> 
> If I comment out the __init__ method, I get the titled window, and print 
> out self.var ('1')
> 
> 
> import  os
> from Tkinter import *
> 
> class MyApp(Tk):
> var=1
> def __init__(self):
>   pass
> def getval(self):
>   return self.var
> 
> 
> app = MyApp()
> 
> app.title("An App")
> print app.getval()
> app.mainloop()
> 
> 
> Eric Brunel wrote:
> 
>> On Mon, 18 Jul 2005 16:57:51 GMT, William Gill <[EMAIL PROTECTED]> 
>> wrote:
>>
>>> A short while ago someone posted that(unlike the examples) you should
>>> use Tk as the base for your main window in tkinter apps, not Frame.   
>>> Thus :
>>>
>>>class MyMain(Frame):
>>>def __init__(self, master):
>>>self.root = master
>>>self.master=master
>>>self.createWidgets()
>>>def createWidgets():
>>> ...
>>>root = Tk()
>>>app = MyMain(root)
>>>app.master.title("Object Editor")
>>>root.mainloop()
>>>
>>> would become:
>>>
>>> class MyMain(Tk):
>>>...
>>>...
>>> app = MyMain()
>>> app.title("My App")
>>> app.mainloop()
>>>
>>> When I try converting to this approach I run into a problem with the
>>> __init__() method.  It appears to go into an infinite loop in
>>> tkinter.__getattr__().
>>
>>
>> [...]
>>
>> I never ran into this problem. Can you please post a short script 
>> showing this behavior? Without knowing what you exactly do in your 
>> __init__ and createWidgets method, it's quite hard to figure out what 
>> happens...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to kill easygui dialog?

2005-07-19 Thread William Park
[EMAIL PROTECTED] wrote:
> I am using an easygui(http://www.ferg.org/easygui/index.html) dialog
> (enterbox) to retrieve some info from a user. The program then goes on
> and does a bit of processing, sometimes for several minutes. In the
> meantime, the dialog stays there, dead but visible. I would prefer that
> either another dialog ("Processing") would be shown while
> background stuff happens, or that the current dialog would simply
> disappear. Ideas?

I know I'm going to get flamed for this... but, perhaps, 
http://home.eol.ca/~parkw/index.html#gtk
would side-step the problem altogether.

Essentially, you describe your layout in XML syntax, feed it through
Bash shell, and it will display GTK+2 widgets.  When user clicks or
types, data will be stored in shell variable or specified shell command
will be executed.  That's all.

In order to call it from Python, you'd have to use os.system(), and
store the shell variable to file or print it out to stdout.  Then, you
can read it back from Python.  In fact, you can feed the input data
directly from Python to shell.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: main window in tkinter app

2005-07-20 Thread William Gill
That does it!, thanks.

Thinking about it, when I created a derived class with an  __init__ 
method, I  overrode the base class's init.  It should have been 
intuitive that I needed to explicitly call baseclass.__init(self), it 
wasn't.  It might have hit me if the fault was related to someting in 
baseclass.__init() not taking place, but the recursion loop didn't give 
me a clue.  Any idea why failing to init the base class caused the loop?


Bill


Christopher Subich wrote:
> William Gill wrote:
> 
>> O.K. I tried from scratch, and the following snippet produces an 
>> infinite loop saying:
>>
>>   File "C:\Python24\lib\lib-tk\Tkinter.py", line 1647, in __getattr__
>>   return getattr(self.tk, attr)
>>
>> If I comment out the __init__ method, I get the titled window, and 
>> print out self.var ('1')
>>
>>
>> import  os
>> from Tkinter import *
>>
>> class MyApp(Tk):
>> var=1
>> def __init__(self):
>>   pass
>> def getval(self):
>>   return self.var
>>
>>
>> app = MyApp()
>>
>> app.title("An App")
>> print app.getval()
>> app.mainloop()
> 
> 
> You're not calling the parent's __init__ inside your derived class.  I 
> would point out where the Python Tutorial points out that you should do 
> this, but it's not in the obvious place (Classes: Inheritance).
> 
> Python does -not- automagically call parent-class __init__s for derived 
> classes, you must do that explicitly.  Changing the definition of your 
> class to the following works:
>  >>> class MyApp(Tk):
> var=1
> def __init__(self):
>   Tk.__init__(self)
>   pass
> def getval(self):
>   return self.var
> 
> It works when you comment out __init__ because of a quirk in Python's 
> name resolution.  As you'd logically expect, if you don't define a 
> function in a derived class but call it (such as instance.method()), it 
> will call the method from the base class.
> 
> You just proved that this works for __init__ methods also.  When you 
> didn't define __init__ for your derived class, MyApp() called 
> Tk.__init__(), which Does the Right Thing in terms of setting up all the 
> specific Tkinter-specific members.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to build email message with attachment?

2005-07-26 Thread William Park
praba kar <[EMAIL PROTECTED]> wrote:
> Dear All,
> 
>Can any one let me know? How to build
> email in python? with some some examples.

If all else fails, 
    mutt -a ...

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why Tcl/Tk?

2005-07-27 Thread William Park
Jerry He <[EMAIL PROTECTED]> wrote:
> I'm a little curious, why does most scripting
> languges(i.e. python and ruby) use Tcl/Tk rather than
> wx or Fox as its standard GUI? Although I did notice
> that the Vpython IDE that uses Tkinker starts up a lot
> faster than the DrPython IDE that uses wxpython. But
> that makes no sense, Tk is based on Tcl, a scripting
> language, but wx is written in C++. 

Old habits die hard.  Soon, these folks will die off, and we'll be left
with GTK+ or wxWidgets.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why Tcl/Tk?

2005-08-02 Thread William Park
Thomas Bartkus <[EMAIL PROTECTED]> wrote:
> 
> "William Park" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Jerry He <[EMAIL PROTECTED]> wrote:
> > > I'm a little curious, why does most scripting
> > > languges(i.e. python and ruby) use Tcl/Tk rather than
> > > wx or Fox as its standard GUI? Although I did notice
> > > that the Vpython IDE that uses Tkinker starts up a lot
> > > faster than the DrPython IDE that uses wxpython. But
> > > that makes no sense, Tk is based on Tcl, a scripting
> > > language, but wx is written in C++.
> >
> > Old habits die hard.  Soon, these folks will die off, and we'll be left
> > with GTK+ or wxWidgets.
> >
> 
> Ahhh! That devilish little "or"
> 
> If we only knew which one :-)
> Thomas Bartkus

If you're C, then GTK+.  If you're C++, then wxWidgets.  Since I do C
mostly, I looked into GTK+ (actually, stared at the doc for 2 weeks and
absorbed what I can through osmosis) and decided to include GTK+
interface into Bash shell.  Here is the result:
http://home.eol.ca/~parkw/index.html#gtk

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


cut & paste text between tkinter widgets

2005-08-03 Thread William Gill
Is there a simple way to cut and paste from a tkinter text widget to an 
entry widget?  I know I could create a mouse button event that triggers 
a popup (message widget) prompting for cut/paste in each of the widgets 
using a temp variable to hold the text, but I don't wnat to reinvent the 
wheel if there already is something that does the job.

Thanks,

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


Re: cut & paste text between tkinter widgets

2005-08-03 Thread William Gill


>> Is there a simple way to cut and paste from a tkinter text widget to 
>> an entry widget?  I know I could create a mouse button event that 
>> triggers a popup (message widget) prompting for cut/paste in each of 
>> the widgets using a temp variable to hold the text, but I don't wnat 
>> to reinvent the wheel if there already is something that does the job.
> 
> 
> 1) TKinter text and entry widgets should already have proper event 
> bindings for cut/copy/paste.  Test first with your system-default 
> keyboard shortcuts (^C, ^X, ^V on Windows).  I haven't tried it myself, 
> but I think those events bind to '<>', '<>', and '<>', 
> so generating them should Do The Right Thing with selected text.

^C, ^X, and ^V  work just fine!  (I swear I tried that before I posted 
and they didn't???)


> 2) If you need to do any processing on the clipboard data, look at 
> widget.selection_get [so named because of the way that X handles its 
> clipboard]

 From my reading, w.selection_get will return the selected text in w, 
and  places it on the clipboard.   I didn't see any way to get data from 
the clipboard.

Thanks,

Bill

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


Re: cut & paste text between tkinter widgets

2005-08-04 Thread William Gill
handy.

Thanks,

Bill

[EMAIL PROTECTED] wrote:
> Here's some code that gives a cut-copy-paste pop-up window on all Entry 
> widgets
> in an application.
> 
> This code is released into the public domain.
> 
> Jeff Epler
> #
> import Tkinter
> 
> def make_menu(w):
> global the_menu
> the_menu = Tkinter.Menu(w, tearoff=0)
> the_menu.add_command(label="Cut")
> the_menu.add_command(label="Copy")
> the_menu.add_command(label="Paste")
> 
> def show_menu(e):
> w = e.widget
> the_menu.entryconfigure("Cut",
> command=lambda: w.event_generate("<>"))
> the_menu.entryconfigure("Copy",
> command=lambda: w.event_generate("<>"))
> the_menu.entryconfigure("Paste",
> command=lambda: w.event_generate("<>"))
> the_menu.tk.call("tk_popup", the_menu, e.x_root, e.y_root)
> 
> t = Tkinter.Tk()
> make_menu(t)
> 
> e1 = Tkinter.Entry(); e1.pack()
> e2 = Tkinter.Entry(); e2.pack()
> e1.bind_class("Entry", "", show_menu)
> 
> t.mainloop()
> #
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sample code for parsing html file to get contents of td fields

2005-08-04 Thread William Park
yaffa <[EMAIL PROTECTED]> wrote:
> does anyone have sample code for parsting an html file to get contents
> of a td field to write to a mysql db?  even if you have everything but
> the mysql db part ill take it.

I usually use Expat XML parser to extract the field.
http://home.eol.ca/~parkw/index.html#expat

Expat is everywhere.  Python has it and even Gawk has it.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Splitting a string into groups of three characters

2005-08-08 Thread William Park
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hi,
> 
> Is there a function that split a string into groups, containing an "x"
> amount of characters?
> 
> Ex.
> TheFunction("Hello World",3)
> 
> Returns:
> 
> ['Hell','o W','orl','d']
> 
> 
> Any reply would be truly appreciated.

Look into 're' module.  Essentially, split using '...', but return the
separator as well.  Then, remove empty items.  In Bash shell, you would
do
a="Hello World"
set -- "${a|?...}"  # extract '...' separators
pp_collapse # remove null items
printf '{%s}\n' "[EMAIL PROTECTED]"

Translating to Python is left as homework.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


problem extending tkSimpleDialog.Dialog

2005-08-12 Thread William Gill
I have created a widget that extends Frame() and contains labels, 
checkboxes, and entrys.  I am trying to use tkSimpleDialog.Dialog to 
create a modal display of this widget, but am running into some 
(addressing) problems.  My widget displays in the parent widget, not the 
tkSimpleDialog.Dialog?  I hope this snippet is enough to help, as my 
actual code is really too hard to follow.

class showtestWidget(tkSimpleDialog.Dialog):
 def body(self,master):
   Label(master,text="showPhoneNums").grid()
   testWidget(self).grid()

class testWidget(Frame):
 def __init__(self, master):
   Frame.__init__(self)
   self.createWidgets()
 def createWidgets(self):
   Label(self,text="testWidget").grid()

When the parent script instantiates showtestWidget() it should create a 
transient dialog containing a label with the text "showPhoneNums".  It 
does, but the label containing the text "testWidget" is being created in 
the parent widget, not the dialog.

It seems obvious to me that I'm addressing the wrong parent somehow, 
since the label (probably the testWidget) is being created, but in the 
wrong place.

I tried changing   testWidget(self).grid() to 
testWidget(master).grid(), just to see if that helped, but it made no 
difference.

Can someone show me where I went wrong?

Bill


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


Re: problem extending tkSimpleDialog.Dialog

2005-08-12 Thread William Gill
I'm still hammering away, and have found that when I change:

class testWidget(Frame):
  def __init__(self, master):
Frame.__init__(self)
self.createWidgets()
  def createWidgets(self):
Label(self,text="testWidget").grid()
to:
  def __init__(self, master):
Frame.__init__(self)
self.x=master
self.createWidgets()
  def createWidgets(self):
Label(self.x,text="testWidget").grid()

It seems to work correctly.  However my actual widget, an extended Frame 
widget, still doesn't work correctly.  This seems to confirm what I 
thought about addressing the correct parent, but I still haven't figured 
  it out completely.

Unless someone can give me a clue, I guess I can keep modifying 
testWidget(Frame) to add the components of my original until I can see 
where it breaks down.  On the surface it looks like I'm not passing the 
correct master reference to my frame.

Bill


William Gill wrote:
> I have created a widget that extends Frame() and contains labels, 
> checkboxes, and entrys.  I am trying to use tkSimpleDialog.Dialog to 
> create a modal display of this widget, but am running into some 
> (addressing) problems.  My widget displays in the parent widget, not the 
> tkSimpleDialog.Dialog?  I hope this snippet is enough to help, as my 
> actual code is really too hard to follow.
> 
> class showtestWidget(tkSimpleDialog.Dialog):
> def body(self,master):
>   Label(master,text="showPhoneNums").grid()
>   testWidget(self).grid()
> 
> class testWidget(Frame):
> def __init__(self, master):
>   Frame.__init__(self)
>   self.createWidgets()
> def createWidgets(self):
>   Label(self,text="testWidget").grid()
> 
> When the parent script instantiates showtestWidget() it should create a 
> transient dialog containing a label with the text "showPhoneNums".  It 
> does, but the label containing the text "testWidget" is being created in 
> the parent widget, not the dialog.
> 
> It seems obvious to me that I'm addressing the wrong parent somehow, 
> since the label (probably the testWidget) is being created, but in the 
> wrong place.
> 
> I tried changing   testWidget(self).grid() to testWidget(master).grid(), 
> just to see if that helped, but it made no difference.
> 
> Can someone show me where I went wrong?
> 
> Bill
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UCALC equivalent

2005-08-12 Thread William Park
Dark Cowherd <[EMAIL PROTECTED]> wrote:
> http://www.ucalc.com/mathparser/index.html
> 
> There is a great library called UCALC which allows you to set up an
> expression and evaluate it
> for e.g. you an define an expression by calling a function in UCALC
> then call it with various values of x
> 
> for e.g. see this page
> http://www.ucalc.com/mathparser/sample6.html
> 
> It is very fast. I have used it in VB when there is lot of number
> crunching to be done.
> Is there a Python equivalent.
> 
> I looked at numPy and SciPy sites (just skimmed through) did'nt seem
> to have what I wanted.
> 
> Any pointers?

Python has 'eval' and 'exec', so you can process at run-time anything
that you can type into script file.  However, it will be a bit more
verbose than UCALC, because Python is more general.

If you're looking for scientific calculator, which can be embedded or
scripted, then perhaps you should take a look at
http://home.eol.ca/~parkw/index.html#rpn
It is RPN calculator with full support for  functions and some
features found in typical programmable scientific calculators.

Eg.
3+4/5-8 --> rpn 4 5 / 3 + 8 - = --> -4.2

x^2+5x-10
--> rpn 'f(x)= dup 5 + x 10 -' 
rpn 1 'f(x)' =  --> -4
rpn 5 'f(x)' =  --> 40
or it can be scripted directly using shell function, like
--> func () {
rpn $1 dup 5 + x 10 - =
}
func 1
func 5

Sum(x^2+5, 1, 10).  I assume this is sum of x^2+5, for x=1,2,...,10
--> rpn clear
for i in {1..10}; do
rpn $i x^2 5 + +
done
rpn =   --> 435

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem extending tkSimpleDialog.Dialog

2005-08-12 Thread William Gill
Problem solved.  I was not properly passing the master widget reference 
in my frame classes

class MyWidget(Frame):
 def __init__(self, master, columns,rows, trace_write=None):
 Frame.__init__(self) #<<<< here's my mistake
 ...
 ...
 ...

should have been:

class MyWidget(Frame):
 def __init__(self, master, columns,rows, trace_write=None):
 Frame.__init__(self,master)
 ...
 ...
 ...


Bill

P.S.  I haven't been working on this since my last post.  I had to quit 
to go see my oldest graduate.

William Gill wrote:
> I have created a widget that extends Frame() and contains labels, 
> checkboxes, and entrys.  I am trying to use tkSimpleDialog.Dialog to 
> create a modal display of this widget, but am running into some 
> (addressing) problems.  My widget displays in the parent widget, not the 
> tkSimpleDialog.Dialog?  I hope this snippet is enough to help, as my 
> actual code is really too hard to follow.
> 
> class showtestWidget(tkSimpleDialog.Dialog):
> def body(self,master):
>   Label(master,text="showPhoneNums").grid()
>   testWidget(self).grid()
> 
> class testWidget(Frame):
> def __init__(self, master):
>   Frame.__init__(self)
>   self.createWidgets()
> def createWidgets(self):
>   Label(self,text="testWidget").grid()
> 
> When the parent script instantiates showtestWidget() it should create a 
> transient dialog containing a label with the text "showPhoneNums".  It 
> does, but the label containing the text "testWidget" is being created in 
> the parent widget, not the dialog.
> 
> It seems obvious to me that I'm addressing the wrong parent somehow, 
> since the label (probably the testWidget) is being created, but in the 
> wrong place.
> 
> I tried changing   testWidget(self).grid() to testWidget(master).grid(), 
> just to see if that helped, but it made no difference.
> 
> Can someone show me where I went wrong?
> 
> Bill
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


help with mysql cursor.execute()

2005-08-14 Thread William Gill
I have been trying to pass parameters as indicated in the api.
when I use:

   sql= 'select * from %s where cusid = %s ' % name,recID)
   Cursor.execute(sql)

it works fine, but when I try :

   sql= 'select * from %s where cusid like %s '
   Cursor.execute(sql,(name,recID))

or

   sql= 'select * from ? where cusid like ? '
   Cursor.execute(sql,(name,recID))

it fails.

Can someone help me with the semantics of using parameterized queries?

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


Re: help with mysql cursor.execute()

2005-08-14 Thread William Gill
I have been testing and it seems that:

1- Cursor.execute does not like '?' as a placeholder in sql

2- Cursor.execute accepts '%s' but puts the quotation mark around the 
substitution.

   sql = 'select * from %s where cusid = ? ' % name
   Cursor.execute(sql, (recID,))

still fails, but:

   sql = 'select * from basedata where cusid = %s '
   Cursor.execute(sql, (recID,))

works regardless of recID being a string or an int.  Obviously this 
stems from trying to parameterize the table name.

If I use:

   sql = 'select * from %s where cusid = %%s ' % name
   Cursor.execute(sql, (recID,))

It makes 1 substitution in the first line, and another in the execute()

   sql = 'select * from %s where cusid = %%s ' % name
   # sql now == 'select * from basedata where cusid = %s '
   Cursor.execute(sql, (recID,))

and it works.

Between your comments re: column names and table names , and the notes 
in cursor.py, I was able to figure it out.

FYI I wanted to create a tableHandler class that could be extended for 
individual tables.  That's why the query needs to accept variables for 
tablename.

Thanks.

Bill

Scott David Daniels wrote:
> William Gill wrote:
> 
>> I have been trying to pass parameters as indicated in the api.
>> when I use:
>>   sql= 'select * from %s where cusid = %s ' % name,recID)
>>   Cursor.execute(sql)
>> it works fine, but when I try :
>>   sql= 'select * from %s where cusid like %s '
>>   Cursor.execute(sql,(name,recID))
>> or
>>   sql= 'select * from ? where cusid like ? '
>>   Cursor.execute(sql,(name,recID))
>> it fails.
>> Can someone help me with the semantics of using parameterized queries?
> 
> 
> Neither column names nor table names can be parameters to
> fixed SQL.  Values are what you fiddle with.  This squares with
> the DBMS being allowed to plan the query before looking at the
> parameters (deciding which indices to use, which tables to join
> first, ...), then reusing the plan for identical queries with
> different values.  MySQL may not take advantage of this two-step
> approach, but the DB interface is designed to allow it, so
> the parameterization is constrained.
> 
> See if something like this works:
> 
> sql = 'select * from %s where cusid like ? ' % name
> Cursor.execute(sql, (recID,))
> 
> --Scott David Daniels
> [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with mysql cursor.execute()

2005-08-15 Thread William Gill


Steve Holden wrote:
> William Gill wrote:
> 
>> I have been testing and it seems that:
>>
>> 1- Cursor.execute does not like '?' as a placeholder in sql
>>
> The particular format required by each DBI-compatible module should be 
> available as the module's "paramstyle" variable. mxODBC, for example, 
> uses the "qmark" style, but MySQLdb uses "format".
> 
>> 2- Cursor.execute accepts '%s' but puts the quotation mark around the 
>> substitution.
>>
>>sql = 'select * from %s where cusid = ? ' % name
>>Cursor.execute(sql, (recID,))
>>
>> still fails, but:
>>
>>sql = 'select * from basedata where cusid = %s '
>>Cursor.execute(sql, (recID,))
>>
>> works regardless of recID being a string or an int.  Obviously this 
>> stems from trying to parameterize the table name.
>>
> That's correct, as Scott has pointed out (with a good explanation of why).
> 
>> If I use:
>>
>>sql = 'select * from %s where cusid = %%s ' % name
>>Cursor.execute(sql, (recID,))
>>
>> It makes 1 substitution in the first line, and another in the execute()
>>
>>sql = 'select * from %s where cusid = %%s ' % name
>># sql now == 'select * from basedata where cusid = %s '
>>Cursor.execute(sql, (recID,))
>>
>> and it works.
>>
> That's right: you are now building a table-dependent query (i.e. the 
> table name is hard-wired in the SQL string) parameterized to the 
> required value for cusid.
> 
>> Between your comments re: column names and table names , and the notes 
>> in cursor.py, I was able to figure it out.
>>
>> FYI I wanted to create a tableHandler class that could be extended for 
>> individual tables.  That's why the query needs to accept variables for 
>> tablename.
> 
> 
> You might want to take a look at how some existing object-mappers 
> achieve this - Ian Bicking's sqlobject module might be a good place to 
> start.

I also might want to take a tutorial on searching.  This looks like it 
could have saved me lots of wheel re-inventing.

Thanks,

Bill

> 
> regards
>  Steve
> 
>>
>> Thanks.
>>
>> Bill
>>
>> Scott David Daniels wrote:
>>
>>> William Gill wrote:
>>>
>>>
>>>> I have been trying to pass parameters as indicated in the api.
>>>> when I use:
>>>>  sql= 'select * from %s where cusid = %s ' % name,recID)
>>>>  Cursor.execute(sql)
>>>> it works fine, but when I try :
>>>>  sql= 'select * from %s where cusid like %s '
>>>>  Cursor.execute(sql,(name,recID))
>>>> or
>>>>  sql= 'select * from ? where cusid like ? '
>>>>  Cursor.execute(sql,(name,recID))
>>>> it fails.
>>>> Can someone help me with the semantics of using parameterized queries?
>>>
>>>
>>>
>>> Neither column names nor table names can be parameters to
>>> fixed SQL.  Values are what you fiddle with.  This squares with
>>> the DBMS being allowed to plan the query before looking at the
>>> parameters (deciding which indices to use, which tables to join
>>> first, ...), then reusing the plan for identical queries with
>>> different values.  MySQL may not take advantage of this two-step
>>> approach, but the DB interface is designed to allow it, so
>>> the parameterization is constrained.
>>>
>>> See if something like this works:
>>>
>>>sql = 'select * from %s where cusid like ? ' % name
>>>Cursor.execute(sql, (recID,))
>>>
>>> --Scott David Daniels
>>> [EMAIL PROTECTED]
> 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with mysql cursor.execute()

2005-08-16 Thread William Gill

Dennis Lee Bieber wrote:
> On Sun, 14 Aug 2005 19:28:04 GMT, William Gill <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
> 
> 
>>I have been trying to pass parameters as indicated in the api.
>>when I use:
>>
>>   sql= 'select * from %s where cusid = %s ' % name,recID)
>>   Cursor.execute(sql)
>>
>>it works fine, but when I try :
>>
>>   sql= 'select * from %s where cusid like %s '
>>   Cursor.execute(sql,(name,recID))
>>
> 
>   Hypothesis: the database TABLE may need to be filled in externally.
> .execute() parsing is designed to properly quote arguments for data
> fields where needed.
> 
>   I suspect you are getting quote marks around the table name, which
> is not a position they are expected.
> 

 From my testing, your suspicion is correct, as is your suggestion.

   sql = 'select * from %s where cusid = %%s ' % tablename
   Cursor.execute(sql, (recID,))

works,

Bill
>   You'll likely have to use a two-step process: use string formatting
> to fill in table and field names (if you are getting those from user
> input, you'll have to validate that there isn't an injection attack --
> ie, user didn't enter "name; delete from name" as the table to be
> processed); then use .execute() to pass the field values.
> 
>   If using MySQLdb, you could always read the source files... (Though,
> unfortunately, the very bottom is a compiled library and hence
> unreadable...
> 
> 
>   You'll find .execute() invokes an .escape()
> 
> Py> escape(...)
> Py> escape(obj, dict) -- escape any special characters in object
> obj
> Py> using mapping dict to provide quoting functions for each
> type.
> Py> Returns a SQL literal string.
> 
>   Note the last line: it returns a "literal string" -- in the form
> needed to pass /data/. That won't work for field and table names, and
> MySQLdb doesn't attempt any semantic parsing to find out is being
> substituted -- if just converts (escapes) ALL parameters based on
> datatype, THEN does a normal Python string formatting operation.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Zope, Python 2.4 pythonScripts import problem

2005-08-17 Thread William Heymann
On Tuesday 16 August 2005 07:09 am, [EMAIL PROTECTED] wrote:
> I see that Python 2.4.x does not work with Zope-2-7-6 properly. When I
> start zope I get warning that I should recompile my pythonScripts by
> executing manage_addProduct/PythonScripts/recompile. I do it and get
> list of scripts whoose were compiled but when I repeat that action I
> get the same list of scripts. It doesn't compile them -> when I visit
> script by ZMI I still get the following error message "invalid syntax
> (Script (Python), line 1)".
>
> The first script at page
> http://www.zope.org/Members/goppelt/2-4-3Upgrade gives no effect ->
> outcome is "invalid syntax (Script (Python), line 1)" error i scripts.
>
> I'm affraid that I will have to resign with Python 2.4.x :(
> I read that Python 2.4 was complaisant back but I don't think that
> Zope-2-7-6 is???
>

Please read the docs that come with zope. No version of zope supports python 
2.4 right now. For zope 2.7 and zope 2.8 the python version to use is python 
2.3.5.

Everytime a new version of python is done a lot of stuff is checked to make 
sure it works and minor changes are made. I know it is possible to get 
zope2.7 and 2.8 working fine on python 2.4 but that should only be done by 
zope developers and not by zope users. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter text widget question

2005-08-21 Thread William Gill


rafi wrote:
> William Gill wrote:
> 
>> The tkinter text widget uses indexes to identify row:column offsets 
>> within the text, but it seems counter intuitive to have to convert row 
>> and column integers to a string like "0.1'.  It's great that index can 
>> take a string, but what about looping through rows and columns?  Am I 
>> missing a way to use integers directly, or should I create a class 
>> that takes the two integers and returns them formatted as the proper 
>> string?
> 
> 
> tkinter relies on tk that is for tcl at first, and in tcl every thing is 
> a string (more or less).
> 
> "%s.%s" % (row, column)

Simple enough.  (sometimes I can't see the simplest things, without 
complicating them)

Thanks,

Bill
> 
> should answer your problem easily
> 
> my 2 cents
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


tkinter text widget question

2005-08-21 Thread William Gill
The tkinter text widget uses indexes to identify row:column offsets 
within the text, but it seems counter intuitive to have to convert row 
and column integers to a string like "0.1'.  It's great that index can 
take a string, but what about looping through rows and columns?  Am I 
missing a way to use integers directly, or should I create a class that 
takes the two integers and returns them formatted as the proper string?

Thanks

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


Re: split function

2005-08-22 Thread William Park
Mohammed Altaj <[EMAIL PROTECTED]> wrote:
> 
> Dear All
> 
> What i want to do is , my input is like
> 0 2
> 0 3
> 0 4
> 1 2
> 1 4
> 2 3
> 3 4
> 
> I am comparing and put the number in group , like ,the first three lines
> , all has zero as first input for each line, so the out put should look
> like
> 0 2 3 4
> and so on
> 1 2 4
> 2 3
> 3 4

Use Python's dictionary (also known as associative array or hash).  Read
documentation.

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


a question about tkinter StringVars()

2005-08-24 Thread William Gill
Working with tkinter, I have a createWidgets() method in a class.
Within createWidgets() I create several StringVars() and
assign them to the textvariable option of several widgets.
Effectively my code structure is:

def createWidgets(self):
 ...
 var = StringVar()
 Entry(master,textvariable=var)
 ...
 ...

Though 'var' would normally go out of scope when createWidgets 
completes, since the Entry and its reference do not go out of scope, 
only the name 'var' goes out of scope, not the StringVar object, Right?

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


Re: a question about tkinter StringVars()

2005-08-24 Thread William Gill


Eric Brunel wrote:
> On Wed, 24 Aug 2005 15:07:27 GMT, William Gill <[EMAIL PROTECTED]> wrote:
> 
>> Working with tkinter, I have a createWidgets() method in a class.
>> Within createWidgets() I create several StringVars() and
>> assign them to the textvariable option of several widgets.
>> Effectively my code structure is:
>>
>> def createWidgets(self):
>>  ...
>>  var = StringVar()
>>  Entry(master,textvariable=var)
>>  ...
>>  ...
>>
>> Though 'var' would normally go out of scope when createWidgets
>> completes, since the Entry and its reference do not go out of scope,
>> only the name 'var' goes out of scope, not the StringVar object, Right?
> 
> 
> Well, apparently not:
> 
> 
> from Tkinter import *
> 
> class MyStringVar(StringVar):
>   def __del__(self):
> print "I'm dying!"
> 
> root = Tk()
> 
> def cw():
>   var = MyStringVar()
>   Entry(root, textvariable=var).pack()
> 
> cw()
> 
> root.mainloop()
> 
> 
> Running this script actually prints "I'm dying!", so there is obviously 
> no reference from the Entry widget to the variable object. The reference 
> is actually kept at tcl level between an entry and the *tcl* variable, 
> which knows nothing about the *Python* variable.
I will have to do some experimenting.
> 
> BTW, the whole purpose of StringVar's is to be kept so that the text for 
> the entry can be retrieved or modified by another part of the program. 
> So what can be the purpose of creating variables in a function or method 
> and not keeping them anywhere else than a local variable?
I was trying to keep my question simple.
In actuality,  I have a widget I'll call dataForm that extends 
tkSimpleDialog.Dialog.  In it I have several entry and checkbox widgets, 
and a call to a changed() method passed from the parent.  When I'm done 
editing dataForm, all the variables are processed in a save() method, 
and dataForm is destroyed.

What happened when I used self.var = MyStringVar() and Entry(root, 
textvariable=self.var).pack(), is that a subsequent call to create a 
dataForm instance has residual data from the previous instance AND the 
change callback caused an error.  Changing to local variables seemed to 
cure the problems.

I just tried changing back to the self.var approach, and it seems to 
work fine???  I must have had some name conflicts in my earlier code. 
I'll try to figure it out, and post if I do.

Bill


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


prevent callback during initialization

2005-08-25 Thread William Gill
I am creating several tkinter widgets.  In my classes they each have a
change() method that is a callback to various IntVar, and StringVar
objects.  Everything works fine, but don't really want to trigger the
callback  when I am initializing each widget/control variable.  I can
use a "flag" like self.initialized= true, and wrap the change() procedures
in an "if self.initialized:" block.  I get the impression using "flags" is
not the preferred approach.  Is there some other way to accomplish
this without using a flag?

Can I redefine my change() method in __init__(), or would that mess up
the callback references already established?

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


Re: a question about tkinter StringVars()

2005-08-25 Thread William Gill


Eric Brunel wrote:
> On Wed, 24 Aug 2005 15:07:27 GMT, William Gill <[EMAIL PROTECTED]> wrote:
> 
>> Working with tkinter, I have a createWidgets() method in a class.
>> Within createWidgets() I create several StringVars() and
>> assign them to the textvariable option of several widgets.
>> Effectively my code structure is:
>>
>> def createWidgets(self):
>>  ...
>>  var = StringVar()
>>  Entry(master,textvariable=var)
>>  ...
>>  ...
>>
>> Though 'var' would normally go out of scope when createWidgets
>> completes, since the Entry and its reference do not go out of scope,
>> only the name 'var' goes out of scope, not the StringVar object, Right?
> 
> 
> Well, apparently not:
> 
> 
> from Tkinter import *
> 
> class MyStringVar(StringVar):
>   def __del__(self):
> print "I'm dying!"
> 
> root = Tk()
> 
> def cw():
>   var = MyStringVar()
>   Entry(root, textvariable=var).pack()
> 
> cw()
> 
> root.mainloop()
> 
> 
> Running this script actually prints "I'm dying!", so there is obviously 
> no reference from the Entry widget to the variable object. The reference 
> is actually kept at tcl level between an entry and the *tcl* variable, 
> which knows nothing about the *Python* variable.
> 
> BTW, the whole purpose of StringVar's is to be kept so that the text for 
> the entry can be retrieved or modified by another part of the program. 
> So what can be the purpose of creating variables in a function or method 
> and not keeping them anywhere else than a local variable?

I posted that changing back to a non-local variable works now, and that 
my problem was probably name conflict.  I haven't been able to verify 
that, but I have to assume that was the original problem.

My band-aid may have 'worked' because tcl maintained the control 
variable and callback even though the Python variable was gone.

As far as "... the purpose of creating variables ... and not keeping 
them anywhere else...".  I actually was keeping them in a non-local 
list.  I was creating a local variable, appending it to the list, then 
reusing the local name for the next new control variable:
...
   var= IntVar()
   self.variables.append(var)
...
This was 'copied' from a snippet I was using as a template.

I now use:
...
   self.variables.append(IntVar())
...

Please let me know if I'm on thin ice here.

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


Re: formal math ?

2005-08-28 Thread William Park
[EMAIL PROTECTED] wrote:
> Hi,
> 
> I have just discovered python and it seems so easy ans so powerful to
> me that it remind me matlab or maple programming language (sorry free
> software purists ears).
> 
> So I was wondering if there a sort of formal math library, that can do
> a thing like:
> 
> lib.solve("x+1=0")
> -> x=-1
> 
> I have checked numarray and I think it can not do this.
> 
> Thanks in advance,

No, you need to type some more. :-)  You need to define function
def f(x):
return x + 1
and call root solver, either from a library or function imported from
module.

For simple cases, I use RPN calculator recently added to Bash shell,
like
rpn 'f(x)= 1 +' 0 1 secant =
rpn 'f(x)= 1 +' 'fd(x)= 1'  0 newton =

-- 
William Park <[EMAIL PROTECTED]>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
  http://freshmeat.net/projects/bashdiff/
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   4   5   6   >