Looping through a file a block of text at a time not by line

2006-06-13 Thread Rosario Morgan
Hello

Help is great appreciated in advance.

I need to loop through a file 6000 bytes at a time.  I was going to 
use the following but do not know how to advance through the file 6000 
bytes at a time.

file = open('hotels.xml')
block = file.read(6000) 
newblock = re.sub(re.compile(r''),'',block)
print newblock

I cannot use readlines because the file is 138MB all on one line.

Suggestions?

-Rosario



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


Re: python-dev Summary for 2006-05-01 through 2006-05-15

2006-06-13 Thread garabik-news-2005-05
This summary is tagged as being in ISO-8859-1 encoding:
  Content-Type: text/plain; charset=ISO-8859-1; format=flowed
However, it really is in UTF-8, which results in this mojibake:

> 
> Martin v. Löwis and Marc-Andre Lemburg discussed how to include both



-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: "groupby" is brilliant!

2006-06-13 Thread Frank Millman

Benji York wrote:
> Frank Millman wrote:
> > reader = csv.reader(open('trans.csv', 'rb'))
> > rows = []
> > for row in reader:
> > rows.append(row)
>
> Why do you create a list of rows instead of just iterating over the
> reader directly?
> --
> Benji York

A - didn't think of it - good idea

B - can't always do it -
B1 - if the file is not sorted, I have to sort the rows first
B2 - if I need to update the file, I can modify the rows in place, and
then call
csv.writer(open('trans.csv','wb')).writerows(rows)

BTW, I know that B2 is simplistic - to be safe I should rename, then
write, then unlink. I will do that for production code.

BTW2, an alternative to B2 is
reader = csv.reader(open('trans.csv', 'rb'))
newtrans = open('newtrans.csv','wb')
writer = csv.writer(newtrans)
for row in reader:
[process and modify row]
writer.writerow(row)
newtrans.close()
[unlink and rename]

Could be useful if the file is large. Food for thought.

Thanks

Frank

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


curses module bug in windows python?

2006-06-13 Thread kernel1983
when I type command below in windows python:
import curses

it gives the error msg! It can't find _curses.pyd

Is this a bug?

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


Re: .py and running in Windows:

2006-06-13 Thread Dog Walker
On Tuesday 13 June 2006 07:04, Michael Yanowitz wrote:
> Thanks.
> 
>XP looks to be the same as 2000.
> Works as expected now. Thank You.
> 
> Not sure what this 'thread' issue is.
> I never specified a thread. I think perhaps though because I did
> open another message in this mailing list (to get the correct
> email address to send to), but I deleted all its contents i put
> it under that other thread, however there is no indication of a
> thread in Outlook email. I am sorry if it came up in another
> thread that was not my intention.
> 

To start a  new thread use a new email: even though you deleted the contents,
In-Reply-To: and References: headers remain in the email, and when they are
present, they determine the thread rather than the Subject: header.

> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf
> Of Iain King
> Sent: Tuesday, June 13, 2006 9:48 AM
> To: python-list@python.org
> Subject: Re: .py and running in Windows:
> 
> 
> 
> Andrew Gwozdziewycz wrote:
> > You'll have better results posting this to it's own thread.
> >

[...]


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


python-dev Summary for 2006-05-01 through 2006-05-15

2006-06-13 Thread Steven Bethard
python-dev Summary for 2006-05-01 through 2006-05-15


.. contents::

[The HTML version of this Summary is available at
http://www.python.org/dev/summary/2006-05-01_2006-05-15]



=
Announcements
=

---
Python 2.5 progress
---

Python 2.5 is moving steadily towards its first beta release.  See
`PEP 356`_ for more details and the full schedule.

.. _PEP 356: http://www.python.org/dev/peps/pep-0356/

Contributing threads:

- `2.5 open issues
`__
- `nag, nag -- 2.5 open issues
`__

--
Experimental wiki for editing the Python library reference
--

Fredrik Lundh introduced his `pyref wiki`_ which allows wiki-style
editing of the Python Library Reference.  In addition to providing
useful links, like unique URLs for all keywords, types and special
methods, the project aims to make cleaning up and rewriting parts of
the Python documentation as easy as editing a wiki.  If you'd like to
help out, let `Fredrik`_ know your infogami user name and he can add
you to the group.

.. _pyref wiki: http://pyref.infogami.com/
.. _Fredrik: [EMAIL PROTECTED]

Contributing threads:

- `introducing the experimental pyref wiki
`__
- `introducing the experimental pyref wiki
`__
- `more pyref: continue in finally statements
`__
- `more pyref: a better term for "string conversion"
`__
- `more pyref: comparison precedence
`__
- `context guards, context entry values, context managers, context
contexts `__

---
Assigning a SourceForge group to a tracker item
---

When opening a new patch on the SourceForge tracker, you should set
"Group" to the earliest still-maintained Python version to which it
applies.  Currently, that means if it's a candidate for backporting,
you should set the "Group" to 2.4.

Contributing thread:

- `Assigning "Group" on SF tracker?
`__


=
Summaries
=


PEP 3102: Keyword-only arguments


This fortnight continued discussion from the last on Talin's PEP for
keyword-only arguments.  Mainly the discussion focused on the second
half of his proposal which would allow positional arguments and
keyword-only arguments at the same time with syntax like::

  def compare(a, b, *, key=None):

The arguments for it included:

* It allows function APIs to be more strict initially to allow API
evolution without breaking existing code.
* It provides better documentation for functions that currently would
have to take a \*\*kwargs.

Still, a lot of people felt uncomfortable with the idea that the
writer of a function could force the callee to use keyword arguments
even if the callee found positional arguments to be simpler.

Contributing thread:

- `PEP 3102: Keyword-only arguments
`__

--
Alternative to PEP 355 path object
--

Noam Raphael suggested an alternative to the path object suggested by
`PEP 355`_ which makes paths more like tuples than strings.  The
ensuing discussion considered a variety of options, which would have
allowed code something like::

pth = Path("~/foo/bar/baz.tar.gz"):
assert pth.basepath == HOMEDIR
assert pth.dirparts == ('foo', 'bar')
assert pth.nameparts == ('baz', 'tar', 'gz')
assert pth.prefix == str(pth.basepath)
assert pth.dir == os.sep.join(pth.dirparts + ('',))
assert pth.name == os.extsep.join(pth.nameparts)

Most of the ideas were also posted to the wiki under
`AlternativePathClass`_ or `AlternativePathDiscussion`_, and a number
of people asked for a PEP, but none was available at the time of this
summary.

.. _PEP 355: http://www.python.org/dev/peps/pep-0355/
.. _AlternativePathClass: http://wiki.python.org/moin/AlternativePathClass
.. _AlternativePathDiscussion:
http://wiki.python.org/moin/AlternativePathDiscussion

Contributing thread:

- `Alternative path suggestion
`__


Mechanics for Python sprints


Tim Peters started a discussion about the best w

python-dev Summary for 2006-04-16 through 2006-04-30

2006-06-13 Thread Steven Bethard
python-dev Summary for 2006-04-16 through 2006-04-30


.. contents::

[The HTML version of this Summary is available at
http://www.python.org/dev/summary/2006-04-16_2006-04-30]



=
Announcements
=

---
Python 2.5 alpha 2 released
---

Python 2.5 alpha 2 was released on April 27th.  If you haven't tried
it out yet, now's the time!  `PEP 356`_ has more details and the full
schedule.

.. _PEP 356: http://www.python.org/dev/peps/pep-0356/

Contributing threads:

- `TRUNK FREEZE from 00:00 UTC, 27th April 2006 for 2.5a2
`__
- `RELEASED Python 2.5 (alpha 2)
`__
- `trunk is UNFROZEN
`__
- `2.5 open issues
`__


QOTF: Quote of the Fortnight


Phillip J. Eby, on the social behavior of package distributors (and
why setuptools goes to such efforts to guess what package distributors
were really trying to do):

The problem isn't fundamentally a technical one, but a social one.
 You can effect [sic] social change through technology, but not by
being some random guy with a nagging 'bot.

(And yes, Phillip, you can nominate yourself for QOTF.) ;-)

Contributing thread:

- `setuptools: past, present, future
`__


=
Summaries
=

---
Adding setuptools to the stdlib
---

Phillip J. Eby started checking in some of the `setuptools`_ modules
for Python 2.5.  People started to get nervous about some of the
modules because:

* Setuptools changes the distutils "install" command to install
everything as zipfile eggs
* Setuptools changes the distutils "sdist" command to automate
generation of MANIFEST.in and MANIFEST.
* Setuptools adds 'site.py' files so that .pth files are processed in
PYTHONPATH directories.
* Setuptools monkey-patches three classes from distutils:
Distribution, Command, and Extension.

While most people recognized the need for the features that setuptools
provides, a number of them objected to introducing setuptools as a new
package and instead argued for merging setuptools into distutils.
Phillip said that such a merge might be possible, but that there were
a fair number of backwards compatibility concerns (e.g. its
redefinition of the "install" and "sdist" commands) and that it would
make it much harder for him to maintain external versions of
setuptools compatible with Python 2.3 and 2.4.

In the end, Phillip suggested withdrawing setuptools from Python 2.5,
and figuring out how to merge setuptools into distutils for the 2.6
release.  In particular, he asked for help with the mostly trivial
porting of the "alias", "rotate", "saveopts" and "setopt" commands.
Additionally, he made available some information about the `setuptools
internals`_ for anyone who wanted to see better what was going on
behind the scenes.

.. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools
.. _setuptools internals: http://peak.telecommunity.com/DevCenter/EggFormats

Contributing threads:

- `[Python-checkins] r45510 - python/trunk/Lib/pkgutil.py
python/trunk/Lib/pydoc.py
`__
- `Place for setuptools manuals and source for .exe files?
`__
- `setuptools in the stdlib ([Python-checkins] r45510 -
python/trunk/Lib/pkgutil.py python/trunk/Lib/pydoc.py)
`__
- `setuptools in the stdlib ( r45510 - python/trunk/Lib/pkgutil.py
python/trunk/Lib/pydoc.py)
`__
- `setuptools in the stdlib
`__
- `Raising objections (was: setuptools in the stdlib)
`__
- `Raising objections
`__
- `3rd party extensions hot-fixing the stdlib (setuptools in the
stdlib) `__
- `setuptools in 2.5.
`__
- `magic in setuptools (Was: setuptools in the stdlib)
`__
- `Distutils for Python 2.1 (was "Raising objections")
`__
- `setuptools in 2.5. (summary)
`__
- `Distutils thoughts


Bundling an application with third-party modules

2006-06-13 Thread Ben Finney
Howdy all,

I'm improving an existing application that's partly written using
Python and the standard library. Many of the improvements I want to
make can be done by using third-party free software.

The immediate customer for this application is happy to install Python
on their machine, but I'd like to remove the hassle of asking them to
continually install new versions of great third-party Python software
that isn't packaged for their OS. I want to supply those modules as
part of implementing my application.

What I'd like to do is:

  - Pull down the external packages and modules from the internet

  - Put those things in a predictable location within my application's
source tree

  - Have the third-party stuff be placed in a location specific for
this application, so that I know my application is using exactly
what I pulled down from the internet

  - Have the implementation of my application, and all the new
versions of whatever third-party software I use, be automated with
a command I can give to the customer

I specifically *don't* want the third-party packages to need to be
installed explicitly by the customer. I would prefer if all this can
be done without needing root access on the implementation machine.

What kind of infrastructure am I looking at? Python eggs, for my
application and all its dependencies? That would likely involve making
eggs of other people's programs. Moving files around and diddling the
system path?

I would expect this type of requirement isn't particularly unique. How
have other people solved it?

-- 
 \  "Well, my brother says Hello. So, hooray for speech therapy."  |
  `\-- Emo Philips |
_o__)  |
Ben Finney

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


Re: daily python url - gmane links dead?

2006-06-13 Thread imcs ee
same error here.

On 6/14/06, K.S.Sreeram <[EMAIL PROTECTED]> wrote:
> Is it just me.. or are all the gmane links on daily-python dead?
> All the c.l.py.announce entries point to gmane, and none of them seem to
> be working. This is the error i get on gmane:
>
> Warning: fsockopen(): unable to connect to hugh:8010 in
> /home/httpd/gmane/php/lib.php on line 18
> Couldn't contact hugh:8010
> The web interface is down for maintenance.
>
> How about using google groups or the python.org archives instead of gmane?
>
> Regards
> Sreeram
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


os.spawn* on Windows

2006-06-13 Thread Antoine
Hello list

I am using Python 2.4 to invoke other programs on Windows XP, using
syntax like this:

os.spawnv(P_WAIT, "C:\\my.exe", ("C:\\my.exe",))

where my.exe is a console-mode program.

When the above statement is executed, the my.exe program creates a
window, what used to be called a Dos prompt but is no doubt called
something else now, and steals the keyboard input focus. This proves to
be highly annoying (because the window pops up unexpectedly in front of
my other windows and often steals several characters of what I am
typing).

I would rather the 'Dos prompt' was created minimised and did not steal
the input focus. Is there any way to achieve this end by using a
different Python command to invoke my.exe? Or would I have to change
my.exe itself?

Cheers
A.

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


Re: TONIGHT! Lisp group beerfest in NYC, PyCells to be discussed

2006-06-13 Thread [EMAIL PROTECTED]

Ken Tilton wrote:
> The royal We has just learned that His Kennyness will be honoring the
> boozehounds of LispNYC with His Presence tonight (deets below).
>
> He will come bearing Celtk and news of PyCells, though the top billing
> tonight goes to SoC student Extraordinaire Samantha Kleinberg.
>
> kenzo
>
> > Please join us for our next meeting on Tuesday, June 13th from 7:00
> > to 9:00 at Westside Brewery.
> >
> > With Summer of Code being here, this is a great opportunity to talk and
> > drink regarding the students and their projects!
> >
> > Hope to see you there!
> >
> >
> >
> > Directions:
> >
> >  Westside Brewery in the VIP room
> >  340 Amsterdam Ave.
> >  (On the West side of Amsterdam Ave., 76th-77th)
> >
> > Directions by subway: 1-2-3-9 (the red line) to 72nd or 79th and
> > Broadway.  From 72nd, walk up Amsterdam (not Broadway).  From 79th, walk
> > east one long block to Amsterdam and turn right/south.
> >
> > Directions by car: 79th street exit from west side highway, down West
> > End Ave or Broadway to 76th, turn left and one or two blocks to
> > Amsterdam.
>
> --
> Cells: http://common-lisp.net/project/cells/
>
> "I'll say I'm losing my grip, and it feels terrific."
> -- Smiling husband to scowling wife, New Yorker cartoon

Why are all of the cool Lisp things up north?  No Lispers down south?

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


proper way to use popen4

2006-06-13 Thread micklee74
hi
i have to execute some SQL statements against a database using a SQL
client
i want to use the os.popen4 module
can someone correct the way i use os.popen4?
thanks

fin = "select * from some_table" #sql statement
client = "osql server user password" #sql client syntax
fin, fout = os.popen4(client)
fin.close()  <--- i need to close the stdin first right?
print fout.read()

I get no results when i did the above...
thanks

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


Re: Dr. Dobb's Python-URL! - weekly Python news and links (Jun 12)

2006-06-13 Thread and-google
John Salerno wrote:

> I love the new 'folder' icon, but how can I access it as an icon?

I've just given these are proper home, so here:

  http://doxdesk.com/software/py/pyicons.html

cheers!

-- 
And Clover
mailto:[EMAIL PROTECTED]
http://www.doxdesk.com/

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


Re: DispatchEx('.Application')

2006-06-13 Thread Roger Upole
There's a project to create a COM api for Firefox that's identical to IE:

http://www.iol.ie/~locka/mozilla/mozilla.htm

 Roger

<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> When using win32com and DispatchEx to work with a webbrowser, eg:
>
> from win32com.client import DispatchEx
>
> ie = DispatchEx('InternetExplorer.Application')
>
> can anyone suggest the right answer to this?
>
> mf = DispatchEx('MozillaFirefox.Application')
>
> It is an invalid class string, but I don't know how to find the right
> class string for Mozilla (or any other window for that matter)? Can
> somebody suggest to me an easy way to 'get' this information.
>
> After that I intend to do this:
>
> mf.Navigate('www.groups.google.com.au/etc'')
>
> Will all of these functions work with Firefox or is it only Internet
> Explorer(I can use either but I prefer Firefox?)
> 



== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question on dict subclassing and overriding __setitems__

2006-06-13 Thread George Sakkis
Eric S. Johansson wrote:

> Diez B. Roggisch wrote:
> > Or better even
> >
> >super(subclass, self).__setitem__(key.upper(), value)
>
> hmm.  http://fuhm.net/super-harmful/

Interesting link, didn't know about it. I've always found super() ugly
and doubted that it was in practice better suited for multiple
inheritance than explicit method call, but I kept using it nonetheless
since it was "blessed" for new style classes. Unless of course the code
broke for one of the reasons mentioned in the article, in which case I
reverted back to the "old way". Good to know that I can safely get rid
of practically all super() calls. Any python-dev-er's take on super()'s
utility and future in Py3K ?

George

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


Re: How to select a folder with native windows dialog box?

2006-06-13 Thread Roger Upole
You can use SHBrowseForFolder:

from win32com.shell import shell
shell.SHBrowseForFolder()

   Roger

<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
>I found the win32ui.CreateFileDialog() function to select a file but
> nothing to select a folder :'-(
> Maybe someone has a solution for this?
> Thanks!
> 



== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [*SPAM*] Python open proxy honeypot

2006-06-13 Thread Alex Reinhart
Eric S. Johansson wrote:
> Alex Reinhart wrote:
>> Yeah, I just realized that. What would I do to act as an open proxy as
>> well?
> 
> emulate the Apache proxy capability, especially the reverse proxy.
> 
> more seriously, what you need to do is from common proxy and web server
> ports, accept proxy requests with a destination port number of 25 and
> pretend to relay them.  at least, that was the behavior I saw on a
> misconfigured Apache web server proxy.
Is there a library that implements such functionality (that I can
override) or will I have to implement SOCKS and such myself? I've found
one SOCKS library and it's rather old and out of date...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I ignore the errors thrown by the DB api?

2006-06-13 Thread Ben Finney
"fyleow" <[EMAIL PROTECTED]> writes:

> It would be great if I could just insert values into the DB and let
> the uniqueness check at the DB level to either add or refuse the
> duplicate value.

The Pythonic way to do this is find out what exception is generated by
the event you want to handle, and handle that exception.

record_stuff = build_new_record()
try:
insert_record(record_stuff)
except FailedToInsert, e:
handle_insert_failure(e, record_stuff)

Define each of those functions, name the actual exception class, and
you're done.

-- 
 \   "A lot of people are afraid of heights. Not me, I'm afraid of |
  `\widths."  -- Steven Wright |
_o__)  |
Ben Finney

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


Re: question on dict subclassing and overriding __setitems__

2006-06-13 Thread Eric S. Johansson
Diez B. Roggisch wrote:
>dict.__setitem__(self, index.upper()) = value

oh duh.

> Or better even
> 
>super(subclass, self).__setitem__(key.upper(), value)

hmm.  http://fuhm.net/super-harmful/

I think I need to do some more reading.

---eric

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


Re: [OT] Re: Python open proxy honeypot

2006-06-13 Thread Alex Reinhart
Serge Orlov wrote:
> Alex Reinhart wrote:
>> Serge Orlov wrote:
>>> IMHO it's pretty useless, spammers are starting to use botnets, and the
>>> more you make inconvenient to them use open proxies, the more of them
>>> will move to closed botnets.
>> As long as I inconvenience them, or at least catch one or two, I'll be
>> satisfied.
> 
> What makes you think that spammers won't discover you're blackholing
> their spam as soon as you start to make some impact on their business?
> They will just skip your proxypots and move to real open proxies.
There are so many spammers and (hopefully) more than one proxypot, so a
stream of less-than-coordinated spammers would probably be caught. The
more coordinated, careful ones would probably avoid them quickly enough,
but I'm sure there are plenty of stupid spammers.

> I think you'll make bigger impact if you implement proxy checking
> software  in Python, so it can run on windows
> too.
That would be a good goal as well.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Screen capturing on Windows

2006-06-13 Thread jUrner

Rune Strand schrieb:

> Is it possible by use of pyWin32 or ctypes to make a screen capture of
> an inactive, or a hidden window if the hwnd/WindowName/ClassName is
> known? I've seen dedicated screen capture software do this. While
> PIL.ImageGrab.grab() is excellent, it will only capture the foreground
> of the desktop. I've tried for hours, but I soon get helplessly lost in
> the labyrinths of the Win32API.


As it says: the window is hidden. You can not make a screen shot of a
hidden
window 'cos it has no visual representation at the very moment. Simply
show it.
And if you do not want to see it while it's shown show it somewhere out
of the bounds of your virtual screen.  

regards

Juergen

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


Re: "groupby" is brilliant!

2006-06-13 Thread Paul McGuire
John Machin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On 14/06/2006 8:38 AM, Robert Kern wrote:
> > Gary Herron wrote:
> >> John Machin wrote:
> >>
> >>> On 13/06/2006 6:28 PM, Paul McGuire wrote:
> >>>
>  (Oh, and I like groupby too!  Combine it with sort to quickly create
>  histograms.)
> 
>  # tally a histogram of a list of values from 1-10
>  dataValueRange = range(1,11)
>  data = [random.choice(dataValueRange) for i in xrange(1)]
> 
>  hist = [ (k,len(list(g))) for k,g in
itertools.groupby(sorted(data)) ]
> >>> That len(list(g)) looks like it uses O(N) memory just to find out what
N
> >>> is :-(
> >> Not at all! A python list *knows* its length at all times. len() is a
> >> constant time lookup of an internal attribute.
> >
> > The point is that you had to create the list in the first place. g is an
iterator.
> >
>
> I didn't have to create a list in the first place. Paul did. The point
> of my post was to avoid the memory grab caused by list(g) by seeking a
> way that just counted g's output.
>
> Sorry for the confusion my lack of clarity has evidently caused. I'll
> rephrase:
>
> That whole construct
>  len(list(g))
> looks like it uses O(N) memory just to find out what N is.
> Better?

Ok, ok!!!  Here's a non-O(N) memory allocation, using a generator expression
to count the number of items in the list.

hist = [ (k,sum(1 for _g in g)) for k,g in itertools.groupby(sorted(data)) ]

-- Paul


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


Re: question on dict subclassing and overriding __setitems__

2006-06-13 Thread Diez B. Roggisch
Eric S. Johansson schrieb:
> I apologize if this is an FAQ but googling has not turned up anything, 
> at least to my keywords.
> 
> I need to parse a configuration file from an existing application and 
> I'm treating it as a dictionary.  I created my class with a parent class 
> of dict.  Everything works okay except I discover I need to force keys 
> to uppercase when setting a value.
> 
> I override __setitems__ and, as you'd expect, I get a recursive loop. 
> I'm obviously missing a clue on how to break the recursion.  My 
> admittedly simpleminded method overloading looks like:
> 
> def __setitem__ (self, index, value):
> """force keys to uppercase"""
> self[index.upper()] = value
   dict.__setitem__(self, index.upper()) = value

Or better even

   super(subclass, self).__setitem__(key.upper(), value)


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


How do I ignore the errors thrown by the DB api?

2006-06-13 Thread fyleow
Here's the code I have in place right now.

cursor.execute("SELECT link FROM feeds_feed WHERE link=%s",
(self.link,))
db.commit()

if cursor.rowcount == 0:
cursor.execute("INSERT INTO feeds_feed (release_group,
title, link, category, pub_date) VALUES (%s, %s, %s, %s, now())",
(self.group, self.title, self.link, self.category,))
db.commit()
print "Inserting"
else:
print "Already Exists"

Basically the uniqueness of the link attribute is enforced in the
database so if I try to insert a value that already exists I get an
error that breaks the program.  Right now I do a SELECT query first to
check if the value already exists.  The insert is only executed only if
the value doesn't already exist.

This is a really bad way of doing things because I'm accessing the DB
way more than I need to.  It would be great if I could just insert
values into the DB and let the uniqueness check at the DB level to
either add or refuse the duplicate value.  I'm not really interested if
a particular value is rejected or added, I just want the most efficient
way to insert values.

I would really appreciate any suggestions or tips.

Thanks.

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


[OT] Re: Python open proxy honeypot

2006-06-13 Thread Serge Orlov
Alex Reinhart wrote:
> Serge Orlov wrote:
> > IMHO it's pretty useless, spammers are starting to use botnets, and the
> > more you make inconvenient to them use open proxies, the more of them
> > will move to closed botnets.
> As long as I inconvenience them, or at least catch one or two, I'll be
> satisfied.

What makes you think that spammers won't discover you're blackholing
their spam as soon as you start to make some impact on their business?
They will just skip your proxypots and move to real open proxies.

I think you'll make bigger impact if you implement proxy checking
software  in Python, so it can run on windows
too.

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


question on dict subclassing and overriding __setitems__

2006-06-13 Thread Eric S. Johansson
I apologize if this is an FAQ but googling has not turned up anything, 
at least to my keywords.

I need to parse a configuration file from an existing application and 
I'm treating it as a dictionary.  I created my class with a parent class 
of dict.  Everything works okay except I discover I need to force keys 
to uppercase when setting a value.

I override __setitems__ and, as you'd expect, I get a recursive loop. 
I'm obviously missing a clue on how to break the recursion.  My 
admittedly simpleminded method overloading looks like:

 def __setitem__ (self, index, value):
 """force keys to uppercase"""
 self[index.upper()] = value

thanks for any pointers.


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


Re: [*SPAM*] Python open proxy honeypot

2006-06-13 Thread Eric S. Johansson
Alex Reinhart wrote:
> Yeah, I just realized that. What would I do to act as an open proxy as well?

emulate the Apache proxy capability, especially the reverse proxy.

more seriously, what you need to do is from common proxy and web server 
ports, accept proxy requests with a destination port number of 25 and 
pretend to relay them.  at least, that was the behavior I saw on a 
misconfigured Apache web server proxy.

for what it's worth, I advocate abandoning Apache as it is too complex 
to configure correctly quickly.  This is especially true of the built-in 
proxy.  For what it's worth, folks should consider using alternatives 
like pound (very good secure proxy) and Cherokee (my favorite).  But 
seriously, any web server except IIS is better than Apache.  Find one 
that works for your application and use it.

---eric

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


Re: "groupby" is brilliant!

2006-06-13 Thread John Machin
On 14/06/2006 8:38 AM, Robert Kern wrote:
> Gary Herron wrote:
>> John Machin wrote:
>>
>>> On 13/06/2006 6:28 PM, Paul McGuire wrote:
>>>
 (Oh, and I like groupby too!  Combine it with sort to quickly create
 histograms.)

 # tally a histogram of a list of values from 1-10
 dataValueRange = range(1,11)
 data = [random.choice(dataValueRange) for i in xrange(1)]

 hist = [ (k,len(list(g))) for k,g in itertools.groupby(sorted(data)) ]
>>> That len(list(g)) looks like it uses O(N) memory just to find out what N 
>>> is :-(
>> Not at all! A python list *knows* its length at all times. len() is a
>> constant time lookup of an internal attribute.
> 
> The point is that you had to create the list in the first place. g is an 
> iterator.
> 

I didn't have to create a list in the first place. Paul did. The point 
of my post was to avoid the memory grab caused by list(g) by seeking a 
way that just counted g's output.

Sorry for the confusion my lack of clarity has evidently caused. I'll 
rephrase:

That whole construct
 len(list(g))
looks like it uses O(N) memory just to find out what N is.
Better?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [OT] Re: Python open proxy honeypot

2006-06-13 Thread Alex Reinhart
Serge Orlov wrote:
> IMHO it's pretty useless, spammers are starting to use botnets, and the
> more you make inconvenient to them use open proxies, the more of them
> will move to closed botnets.
As long as I inconvenience them, or at least catch one or two, I'll be
satisfied.

> My spam folder at gmail is not growing anymore for many months (it is
> about 600-700 spams a month). Have spammers given up spamming gmail.com
> only or is it global trend?
> 
I get several spam mails a day at gmail.com.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "groupby" is brilliant!

2006-06-13 Thread Robert Kern
Gary Herron wrote:
> John Machin wrote:
> 
>>On 13/06/2006 6:28 PM, Paul McGuire wrote:
>>
>>>(Oh, and I like groupby too!  Combine it with sort to quickly create
>>>histograms.)
>>>
>>># tally a histogram of a list of values from 1-10
>>>dataValueRange = range(1,11)
>>>data = [random.choice(dataValueRange) for i in xrange(1)]
>>>
>>>hist = [ (k,len(list(g))) for k,g in itertools.groupby(sorted(data)) ]
>>
>>That len(list(g)) looks like it uses O(N) memory just to find out what N 
>>is :-(
> 
> Not at all! A python list *knows* its length at all times. len() is a
> constant time lookup of an internal attribute.

The point is that you had to create the list in the first place. g is an 
iterator.

-- 
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


Re: "groupby" is brilliant!

2006-06-13 Thread John Machin
On 14/06/2006 8:06 AM, Gary Herron wrote:
> John Machin wrote:
>> On 13/06/2006 6:28 PM, Paul McGuire wrote:
>>
>>   
>>> (Oh, and I like groupby too!  Combine it with sort to quickly create
>>> histograms.)
>>>
>>> # tally a histogram of a list of values from 1-10
>>> dataValueRange = range(1,11)
>>> data = [random.choice(dataValueRange) for i in xrange(1)]
>>>
>>> hist = [ (k,len(list(g))) for k,g in itertools.groupby(sorted(data)) ]
>>> 
>> That len(list(g)) looks like it uses O(N) memory just to find out what N 
>> is :-(
>>   
> Not at all! A python list *knows* its length at all times. len() is a
> constant time lookup of an internal attribute.

Did you see any reference to time in what I wrote? Did you notice the 
word "memory" at all?

My point is that "g" is an iterator, and list(g) actually builds a list 
of size N, merely in order to use len(that_list) to count the number of 
items that g will produce.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to select a folder with native windows dialog box?

2006-06-13 Thread flaus . a
I found the win32ui.CreateFileDialog() function to select a file but
nothing to select a folder :'-(
Maybe someone has a solution for this?
Thanks!

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


Correctly reading stdout/stderr from subprocess

2006-06-13 Thread Christoph Haas
Evening,

I'm having trouble with running a process through Python 2.4's
subprocess module. Example code:


def run(command):
   run = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, 
stderr=subprocess.PIPE)

   # Wait for the process to return
   returncode = run.wait()
   stdout = run.stdout.readlines()
   stderr = run.stderr.readlines()

   # Strip newlines at the end of each line
   stdout = [line.rstrip('\n') for line in stdout]
   stderr = [line.rstrip('\n') for line in stderr]

   return returncode,stdout,stderr


Unfortunately this def fails when it runs programs that do a lot of
output. I believe this problem has also been described in Bug #1162428.
It says: "You must read away the data before wait() on the process."
Easier said than done. If I put the readlines() call before the
run.wait() then the process hangs, too, waiting for further lines.

Then I read about the communicate() call which handles both
stdout/stderr reading and also waiting for the process to end.
Unfortunately it returned the output char-wise instead of line-wise. I
could certainly re-join the lines. But somehow I feel I'm missing
something simple.

Any ideas?

Kindly
 Christoph

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


[OT] Re: Python open proxy honeypot

2006-06-13 Thread Serge Orlov
Alex Reinhart wrote:
> Being deluged by spam like nearly all of us (though fortunately I have a
> very good spam filter), I also hate spam as much as almost everybody. I
> know basic Python (enough to make a simple IRC bot) and I figured a good
> project to help learn Python would be to make a simple "proxypot."
>
> I've done some research and found one already existing, written in Perl
> (http://www.proxypot.org/). However, I prefer the syntax and ease of
> Python (and Proxypot is no longer maintained, as far as I can see), so I
> decided to write my own. I have just one question:
>
> Is running Python's built-in smtpd, pretending to accept and forward all
> messages, enough to get me noticed by a spammer, or do I have to do
> something else to "advertise" my script as an open proxy?
>
> I'm hoping to make this proxy script "distributed", in that several
> honeypots are run on different servers, and the results are then
> collected on a central server that provides statistics and a listing of
> all spammers caught. So, just out of curiosity, I'd like to know how
> many people would actually be willing to run a honeypot on their server,
> and how many are opposed to the idea (just so I know if the concept is
> even valid).

IMHO it's pretty useless, spammers are starting to use botnets, and the
more you make inconvenient to them use open proxies, the more of them
will move to closed botnets.

My spam folder at gmail is not growing anymore for many months (it is
about 600-700 spams a month). Have spammers given up spamming gmail.com
only or is it global trend?

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


Re: "groupby" is brilliant!

2006-06-13 Thread Gary Herron
John Machin wrote:
> On 13/06/2006 6:28 PM, Paul McGuire wrote:
>
>   
>> (Oh, and I like groupby too!  Combine it with sort to quickly create
>> histograms.)
>>
>> # tally a histogram of a list of values from 1-10
>> dataValueRange = range(1,11)
>> data = [random.choice(dataValueRange) for i in xrange(1)]
>>
>> hist = [ (k,len(list(g))) for k,g in itertools.groupby(sorted(data)) ]
>> 
>
> That len(list(g)) looks like it uses O(N) memory just to find out what N 
> is :-(
>   
Not at all! A python list *knows* its length at all times. len() is a
constant time lookup of an internal attribute.

Gary Herron

> The best I could come up with is sum(itertools.imap(lambda x: 1, g)) -- 
> but that does look a bit ugly ...
>
>   

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


Re: DispatchEx('.Application')

2006-06-13 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> When using win32com and DispatchEx to work with a webbrowser, eg:
> 
> from win32com.client import DispatchEx
> 
> ie = DispatchEx('InternetExplorer.Application')
> 
> can anyone suggest the right answer to this?
> 
> mf = DispatchEx('MozillaFirefox.Application')
> 
> It is an invalid class string, but I don't know how to find the right
> class string for Mozilla (or any other window for that matter)? Can
> somebody suggest to me an easy way to 'get' this information.
> 
> After that I intend to do this:
> 
> mf.Navigate('www.groups.google.com.au/etc'')
> 
> Will all of these functions work with Firefox or is it only Internet
> Explorer(I can use either but I prefer Firefox?)
> 
This might help: 
http://mail.python.org/pipermail/python-win32/2005-June/003413.html

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


Re: "groupby" is brilliant!

2006-06-13 Thread John Machin
On 13/06/2006 6:28 PM, Paul McGuire wrote:

> (Oh, and I like groupby too!  Combine it with sort to quickly create
> histograms.)
> 
> # tally a histogram of a list of values from 1-10
> dataValueRange = range(1,11)
> data = [random.choice(dataValueRange) for i in xrange(1)]
> 
> hist = [ (k,len(list(g))) for k,g in itertools.groupby(sorted(data)) ]

That len(list(g)) looks like it uses O(N) memory just to find out what N 
is :-(

The best I could come up with is sum(itertools.imap(lambda x: 1, g)) -- 
but that does look a bit ugly ...

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


Test functions and test discovery (was: Re: Is there a better way of accessing functions in a module?)

2006-06-13 Thread Ben Finney
"Ant" <[EMAIL PROTECTED]> writes:

> def a_test():
> print "Test A"
> 
> def b_test():
> print "Test B"

Incidentally, the convention is to name test functions as 'test_foo'
not 'foo_test'; this will make your module more easily compatible with
existing testing tools.

> if __name__ == "__main__":
> tests = ["%s()" % x for x in dir() if x.endswith("test")]
> 
> for test in tests:
> eval(test)

No need for eval. (You already found globals(), so I'll use that.)

if __name__ == "__main__":
test_funcs = [x for name, x in globals()
if name.startswith("test") and hasattr(x, "__call__")
]

for test in test_funcs:
test()

I'll concur with other posters on this thread and encourage you to
consider using the standard 'unittest' module, and recommend 'nose'
for test discovery and execution:

http://somethingaboutorange.com/mrl/projects/nose/>

-- 
 \ "Unix is an operating system, OS/2 is half an operating system, |
  `\   Windows is a shell, and DOS is a boot partition virus."  -- |
_o__)  Peter H. Coffin |
Ben Finney

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


Re: Getting "TypeError:list indices must be integers"

2006-06-13 Thread Larry Bates
Girish Sahani wrote:
>> On 13/06/2006 4:11 PM, Girish Sahani wrote:
>> [snip]
>>>instance = ti2(k)
>>>tiNew = ti1.append(instance)
>> ti2 is quacking "function" but ti1 is quacking "list".
>>
>> Possibilities:
>> (1) You meant to type ti2[k] ... and this section of code has not yet
>> been executed, and would have featured as episode N+1 had morbid
>> curiosity not led me to read further.
> That is corrected. I'm appending a particular element of ti2 to ti1.
> It hasnt been executed because i'm stuck on that TypeError since 2 hours
> :( (2) You have the weirdest system of choosing names that I have seen for
>> decades.
> :((
>> (3) Both of the above.
>>
>> Cheers,
>> John
>>
> 
How about just inserting some print statements that show you the
type and value of each index before you use it.  It is old fashioned,
but it actually works.

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


Re: Writing PNG with pure Python

2006-06-13 Thread Ben Finney
"Johann C. Rocholl" <[EMAIL PROTECTED]> writes:

> How about this here construct?
> 
> #!/usr/bin/env python
> # png.py - PNG encoder in pure Python
> # Copyright (C) 2006 Johann C. Rocholl <[EMAIL PROTECTED]>
> #
> # This file is licensed alternatively under one of the following:
> # 1. GNU Lesser General Public License (LGPL), Version 2.1 or newer
> # 2. GNU General Public License (GPL), Version 2 or newer
> # 3. Apache License, Version 2.0 or newer
> # 4. The following license (aka MIT License)

Pointless. Licensing it under the Expat license (what you're calling
"MIT License", but we've already discussed the ambiguities in that
term) allows all the rights granted in all the other license you name,
plus just about anything else.

Hence, there's no point listing the others if you are also happy for
people to have it under the Expat license. On the other hand, if you
want to be more restrictive than the terms of the Expat license, you
need to choose a different license.

Simplify. Please don't attempt to write yet another set of license
terms without expert legal assistance. You've already chosen the Expat
license as being acceptable; use that, and you grant all the rest
without even mentioning it.

-- 
 \   "[On the Internet,] power and control will shift to those who |
  `\   are actually contributing something useful rather than just |
_o__) having lunch."  -- Douglas Adams |
Ben Finney

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


Re: What's wrong in this HTML Source file of a Bank

2006-06-13 Thread Remi Villatel
[EMAIL PROTECTED] wrote:

> Several times I logged-in successfully but after log-in I can't use
> features/services which were shown prior to my login. Can anyone exoert
> from this forum check , is it technical fault of Bank Web Site or this
> problem pertaining to the user(me).

This is definitively not the right newsgroup for HTML issues. Go to:

http://validator.w3.org/

And I'm already too nice...

-- 
==
Remi Villatel
[EMAIL PROTECTED]
==
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "groupby" is brilliant!

2006-06-13 Thread Jon Clements
Not related to itertools.groupby, but the csv.reader object...

If for some reason you have malformed CSV files, with embedded newlines
or something of that effect, it will raise an exception. To skip those,
you will need a construct of something like this:

raw_csv_in = file('filenamehere.csv')
for raw_line in raw_csv_in:
try:
# Do something to rawline here maybe if necessary to "clean it
up"
row = csv.reader( [raw_line] ).next()
# Do your stuff here
except csv.Error:
pass # or do something more appropriate if the record is
important

May not be applicable in your case, but has stung me a few times...

All the best,

Jon.


Frank Millman wrote:
> Paul McGuire wrote:
> > >
> > > reader = csv.reader(open('trans.csv', 'rb'))
> > > rows = []
> > > for row in reader:
> > > rows.append(row)
> > >
> >
> > This is untested, but you might think about converting your explicit "for...
> > append" loop into either a list comp,
> >
> > rows = [row for row in reader]
> >
> > or just a plain list constructor:
> >
> > rows = list(reader)
> >
> > Neh?
> >
> > -- Paul
> >
>
> Yup, they both work fine.
>
> There may be times when you want to massage the data before appending
> it, in which case you obviously have to do it the long way. Otherwise
> these are definitely neater, the last one especially.
>
> You could even do it as a one-liner -
> rows = list(csv.reader(open('trans.csv', 'rb')))
> 
> It still looks perfectly readable to me.
> 
> Thanks
> 
> Frank

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


Re: Is there a better way of accessing functions in a module?

2006-06-13 Thread Kent Johnson
Ant wrote:
> Ant wrote:
> ...
>> But this feels like a hack... Is there a cleaner way for accessing the
>> functions of the current module similar to the __dict__ attribute of
>> classes? i.e. a way to access the local symbol table?
> 
> Sorry - posted too soon. Found the globals() built-in...

You can also
import __main__
tests = [x for x in dir(__main__) if x.endswith("test")]

for test in tests:
getattr(__main__, test)()

but I second the suggestion of looking in to unittest or one of the 
other test frameworks.

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


Re: Combining The Best Of Python, Ruby, & Java??????

2006-06-13 Thread Ravi Teja

Luis M. González wrote:
> Diez B. Roggisch wrote:
> > > But semantically it is a proper functional language. The features may
> > > not attract Python users who might prefer Boo/Jython/IronPython. But it
> > > does offer something to disillusioned Groovy users.
> >
> > Are they disillusioned? Just wondering.
> >
> > Diez
>
> Whay talking about disillutioned programmers?
> These are tools, not religions...
> I love python, and I like it more everyday. And with the advent of
> Pypy, its future looks brighter than ever.
> But I also find very interesting these new options that are coming up.
> Although I'm not a professional programmer (not even a serious
> aficionado), I love to be able to translate my python skills very
> easily to .NET through Boo, for example.
> I even find it more appealing than Ironpython, because it was created
> from the ground up to take advantage of the CLR.
> On the other hand, porting pure python to .NET is in many aspects like
> trying to fit a square on a circle (I don't know if this sentence makes
> sense in english...).
> Because many of the design choices taken by GvR back in the early
> nineties were surely conditioned by the platform he chose to write
> python, which is the c language.
> The good thing is that python is having a lot of influence in these new
> languages.
> As far as I could see, even C# 3.0 is showing up some pythonic traits.

I did not realize the flame potential of that remark. Just to clarify,
I have no criticism of any kind on Groovy. I mentioned Groovy since
Scala, the original topic of the thread addresses the needs of the same
group (a modern language with a Java friendly syntax). I am not a
language bigot. Note that I am defending Scala, a new language, in this
thread so far. I do not want this thread to break into a language war
from my remark. I hope that Python gets some of the features listed in
my above post in it's own unique Pythonic way eventually. The
discussion perhaps is more constructive if we can see some good in
Scala that is worth adopting.

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


Re: "groupby" is brilliant!

2006-06-13 Thread James Stroud
James Stroud wrote:
> Frank Millman wrote:
> 
>> Hi all
>>
>> This is probably old hat to most of you, but for me it was a
>> revelation, so I thought I would share it in case someone has a similar
>> requirement.
>>
>> I had to convert an old program that does a traditional pass through a
>> sorted data file, breaking on a change of certain fields, processing
>> each row, accumulating various totals, and doing additional processing
>> at each break. I am not using a database for this one, as the file
>> sizes are not large - a few thousand rows at most. I am using csv
>> files, and using the csv module so that each row is nicely formatted
>> into a list.
>>
>> The traditional approach is quite fiddly, saving the values of the
>> various break fields, comparing the values on each row with the saved
>> values, and taking action if the values differ. The more break fields
>> there are, the fiddlier it gets.
>>
>> I was going to do the same in python, but then I vaguely remembered
>> reading about 'groupby'. It took a little while to figure it out, but
>> once I had cracked it, it transformed the task into one of utter
>> simplicity.
>>
>> Here is an example. Imagine a transaction file sorted by branch,
>> account number, and date, and you want to break on all three.
>>
>> -
>> import csv
>> from itertools import groupby
>> from operator import itemgetter
>>
>> BRN = 0
>> ACC = 1
>> DATE = 2
>>
>> reader = csv.reader(open('trans.csv', 'rb'))
>> rows = []
>> for row in reader:
>> rows.append(row)
>>
>> for brn,brnList in groupby(rows,itemgetter(BRN)):
>> for acc,accList in groupby(brnList,itemgetter(ACC)):
>> for date,dateList in groupby(accList,itemgetter(DATE)):
>> for row in dateList:
>> [do something with row]
>> [do something on change of date]
>> [do something on change of acc]
>> [do something on change of brn]
>> -
>>
>> Hope someone finds this of interest.
>>
>> Frank Millman
>>
> 
> I'm sure I'm going to get a lot of flac on this list for proposing to 
> turn nested for-loops into a recursive function, but I couldn't help 
> myself. This seems more simple to me, but for others it may be difficult 
> to look at, and these people will undoubtedly complain.
> 
> 
> import csv
> from itertools import groupby
> from operator import itemgetter
> 
> reader = csv.reader(open('trans.csv', 'rb'))
> rows = []
> for row in reader:
> rows.append(row)
> 
> def brn_doer(row):
>   [doing something with brn here]
> 
> def acc_doer(date):
>   [you get the idea]
> 
> [etc.]
> 
> doers = [brn_doer, acc_doer, date_doer, row_doer]
> 
> def doit(rows, doers, i=0):
>   for r, alist in groupby(rows, itemgetter(i)):
> doit(alist, doers[1:], i+1)
> doers[0](r)
> 
> doit(rows, doers, 0)
> 
> Now all of those ugly for loops become one recursive function. Bear in 
> mind, its not all that 'elegant', but it looks nicer, is more succinct, 
> abstracts the process, and scales to arbitrary depth. Tragically, 
> however, it has been generalized, which is likely to raise some hackles 
> here. And, oh yes, it didn't answer exactly your question (which you 
> didn't really have). I'm sure I will regret this becuase, as you will 
> find, suggesting code on this list with additional utility is somewhat 
> discouraged by the vociferous few who make a religion out of 'import this'.
> 
> Also, I still have no idea what 'groupby' does. It looks interesting 
> thgough, thanks for pointing it out.
> 
> James
> 

Forgot to test for stopping condition:


def doit(rows, doers, i=0):
   for r, alist in groupby(rows, itemgetter(i)):
 if len(doers) > 1:
   doit(alist, doers[1:], i+1)
 doers[0](r)

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxpython: bringing up a dialog box with a button

2006-06-13 Thread jean-michel bain-cornu
John Salerno a écrit :
> import wx
> class InputForm(wx.Frame):
> 
> def __init__(self, parent=None, id=wx.ID_ANY, title=''):
> wx.Frame.__init__(self, parent, id, title)
> panel = wx.Panel(self)
> btnModal = wx.Button(panel, -1, 'Modal')
> dialog = wx.Dialog(self, -1, 'Modal Dialog')
> self.Bind(wx.EVT_BUTTON, dialog.ShowModal, btnModal)
Don't bind directly ShowModal to EVT_BUTTON
> Traceback (most recent call last):
>   File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\_windows.py", 
> line 688, in ShowModal
> return _windows_.Dialog_ShowModal(*args, **kwargs)
> TypeError: Dialog_ShowModal() takes exactly 1 argument (2 given)
When your button gives an event, wx send two arguments : the object 
itself and an event object. So you can't bind directly.
What you have to do is to use an intermediate method. Something like:
self.dialog = wx.Dialog(self, -1, 'Modal Dialog')
 self.Bind(wx.EVT_BUTTON, self.OnClick, b)
 def OnClick(self, event):
 self.dialog.ShowModal()

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


Redirecting Print Streams

2006-06-13 Thread Mike Driscoll
Hi,I am working on a Tkinter GUI that will display software package's install status. I work for a company that wants to control how software is installed and where. Anyway, the package installer I am working with currently prints to a console window for each software package installed. So, if we have 4 packages, it would open 4 windows in sequence. I want it to just print what it is doing in a Tkinter GUI instead of opening windows, but I cannot figure out how to redirect the print streams in the custom package installer. 
Here is the main module I am trying to redirect data from:def InstallPack(PackageName):    """ Installs a software package """    iniFile = '%s\\client$\\Packages\\%s\\package.ini' % (serverName, PackageName)
    print iniFile    config = section2Dict(iniFile)    reg = ConnectRegistry(None, HKEY_LOCAL_MACHINE)    regpath = r"SOFTWARE\MCIS"    key = OpenKey(reg, regpath, 0, KEY_ALL_ACCESS)    iniSerial = config['SerialNumber']
    try:        q = QueryValueEx(key, PackageName)    RegSerial = q[0]    #print "Package: %s found in Registry!" % PackageName    if RegSerial == iniSerial:    print "Package already installed. Installation aborted!"
    sys.exit(0)    except WindowsError:    # Package not installed    pass    print 'Installing package: %s' % PackageName    print 'Description: %s' % config['Description']
    zipPart(PackageName, config['ZipFile'])    regPart(PackageName, config['RegFile'], config['RegType'])    SetValueEx(key, PackageName, 0, REG_EXPAND_SZ, iniSerial)    CloseKey(key)Thanks a lot!
Mike
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Combining The Best Of Python, Ruby, & Java??????

2006-06-13 Thread Ravi Teja

Diez B. Roggisch wrote:
> > But semantically it is a proper functional language. The features may
> > not attract Python users who might prefer Boo/Jython/IronPython. But it
> > does offer something to disillusioned Groovy users.
>
> Are they disillusioned? Just wondering.

Nah! Just a poor passing attempt at humor. Groovy is a great language
too. I should watch out. Maybe Groovy programmers have knives too :-).
http://cardboard.nu/blog/2005_02_02/gosling_on_jvm_scripting.html

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


Re: "groupby" is brilliant!

2006-06-13 Thread James Stroud
Frank Millman wrote:
> Hi all
> 
> This is probably old hat to most of you, but for me it was a
> revelation, so I thought I would share it in case someone has a similar
> requirement.
> 
> I had to convert an old program that does a traditional pass through a
> sorted data file, breaking on a change of certain fields, processing
> each row, accumulating various totals, and doing additional processing
> at each break. I am not using a database for this one, as the file
> sizes are not large - a few thousand rows at most. I am using csv
> files, and using the csv module so that each row is nicely formatted
> into a list.
> 
> The traditional approach is quite fiddly, saving the values of the
> various break fields, comparing the values on each row with the saved
> values, and taking action if the values differ. The more break fields
> there are, the fiddlier it gets.
> 
> I was going to do the same in python, but then I vaguely remembered
> reading about 'groupby'. It took a little while to figure it out, but
> once I had cracked it, it transformed the task into one of utter
> simplicity.
> 
> Here is an example. Imagine a transaction file sorted by branch,
> account number, and date, and you want to break on all three.
> 
> -
> import csv
> from itertools import groupby
> from operator import itemgetter
> 
> BRN = 0
> ACC = 1
> DATE = 2
> 
> reader = csv.reader(open('trans.csv', 'rb'))
> rows = []
> for row in reader:
> rows.append(row)
> 
> for brn,brnList in groupby(rows,itemgetter(BRN)):
> for acc,accList in groupby(brnList,itemgetter(ACC)):
> for date,dateList in groupby(accList,itemgetter(DATE)):
> for row in dateList:
> [do something with row]
> [do something on change of date]
> [do something on change of acc]
> [do something on change of brn]
> -
> 
> Hope someone finds this of interest.
> 
> Frank Millman
> 

I'm sure I'm going to get a lot of flac on this list for proposing to 
turn nested for-loops into a recursive function, but I couldn't help 
myself. This seems more simple to me, but for others it may be difficult 
to look at, and these people will undoubtedly complain.


import csv
from itertools import groupby
from operator import itemgetter

reader = csv.reader(open('trans.csv', 'rb'))
rows = []
for row in reader:
 rows.append(row)

def brn_doer(row):
   [doing something with brn here]

def acc_doer(date):
   [you get the idea]

[etc.]

doers = [brn_doer, acc_doer, date_doer, row_doer]

def doit(rows, doers, i=0):
   for r, alist in groupby(rows, itemgetter(i)):
 doit(alist, doers[1:], i+1)
 doers[0](r)

doit(rows, doers, 0)

Now all of those ugly for loops become one recursive function. Bear in 
mind, its not all that 'elegant', but it looks nicer, is more succinct, 
abstracts the process, and scales to arbitrary depth. Tragically, 
however, it has been generalized, which is likely to raise some hackles 
here. And, oh yes, it didn't answer exactly your question (which you 
didn't really have). I'm sure I will regret this becuase, as you will 
find, suggesting code on this list with additional utility is somewhat 
discouraged by the vociferous few who make a religion out of 'import this'.

Also, I still have no idea what 'groupby' does. It looks interesting 
thgough, thanks for pointing it out.

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [pysqlite] [ANN] pysqlite 2.3.0

2006-06-13 Thread Dawid Gajownik
Dnia 06/13/2006 09:40 PM, Użytkownik Gerhard Häring napisał:

> I've uploaded a fixed source tarball now.

Thanks!

BTW new packages for Fedora should be available tomorrow on mirrors :)

-- 

   ^_*

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

wxpython: bringing up a dialog box with a button

2006-06-13 Thread John Salerno
I'm not exactly sure how to call the method ShowModal(). This is what I 
have so far:

--

import wx


class InputForm(wx.Frame):

 def __init__(self, parent=None, id=wx.ID_ANY, title=''):
 wx.Frame.__init__(self, parent, id, title)
 panel = wx.Panel(self)

 btnModal = wx.Button(panel, -1, 'Modal')
 dialog = wx.Dialog(self, -1, 'Modal Dialog')
 self.Bind(wx.EVT_BUTTON, dialog.ShowModal, btnModal)

class MyApp(wx.App):

 def OnInit(self):
 frame = InputForm(title='Data Entry Form')
 self.SetTopWindow(frame)
 frame.Show()
 return True


app = MyApp(redirect=False)
app.MainLoop()

-

and this is what I get:

 >>>
Traceback (most recent call last):
   File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\_windows.py", 
line 688, in ShowModal
 return _windows_.Dialog_ShowModal(*args, **kwargs)
TypeError: Dialog_ShowModal() takes exactly 1 argument (2 given)
 >>>

Hope someone can correct me here!
-- 
http://mail.python.org/mailman/listinfo/python-list


interactive programme & pyTTS

2006-06-13 Thread carmel stanley



Hi i have been making an interactive programme,i 
have recently tried using "pyTTS" with it.
This is a small ammount of it.
 
import pyTTS
 
tts = pyTTS.Create()tts.Rate = 
-3tts.Speak('hi molly how old are you?.')s = raw_input ("how old are 
you?")if s=='3':    print "thats great"else: print 
"tuttut"tts.speak('tututut')
 
What i dont get is if i type in "4" it prints 
"tuttut" but it does not say it,am i overlooking something here.
Thanks nige

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

Re: [pysqlite] [ANN] pysqlite 2.3.0

2006-06-13 Thread Gerhard Häring
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Dawid Gajownik wrote:
> Dnia 06/13/2006 08:52 PM, Użytkownik Gerhard Häring napisał:
> 
>> pysqlite 2.3.0 released
> 
> Great :) I have one more problem, though. It does not compile: [...]
> src/connection.c:31:26: error: sqlitecompat.h: No such file or directory
> [...]
> I had to manually download this file [sqlitecompat.h]
> Why it's not included in the tarball?

python setup.py sdist didn't recreate the MANIFEST file, so it was omitted.
I've uploaded a fixed source tarball now.

It's my fault, I should have tried to build from the source tarball, like I
normally do before a release ...

- -- Gerhard
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEjxShdIO4ozGCH14RAuodAJ9N5bbR5lBtdWjzk2xMMivATIi63wCgoHNP
y77XMzv1kmP9kIMFc3yQCSI=
=VdBx
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Tuple Syntax and ()

2006-06-13 Thread James Stroud
[EMAIL PROTECTED] wrote:
> I keep accidently trying to declare t-tuples as mytuple = (myitem)
> 
> I know this doesn't work and that you need the trailing comma, but
> reading something online, I just came to realize the parenthesises
> don't have any special meaning in relation to tuples at all, do they?
> 

Aside from grouping, they are special to construct an empty tuple.

py> () == tuple()
True

Also, don't underestimate their relationship with tuples when it comes 
to grouping:

py> a, b, c = 1, 2, 3
py>
py> a == a, b, c
(True, 2, 3)
py> a == (a, b, c)
False

James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Tuple Syntax and ()

2006-06-13 Thread tactics40
I keep accidently trying to declare t-tuples as mytuple = (myitem)

I know this doesn't work and that you need the trailing comma, but
reading something online, I just came to realize the parenthesises
don't have any special meaning in relation to tuples at all, do they?

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


Re: Making a Label that looks the same as a button.

2006-06-13 Thread Dustan

Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> Grayson, John <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> >Buttons can look like labels without the need to create another object -
> >just remove the
> >Command binding, set state to DISABLED and disabledforeground='same
> >color as NORMAL'...
> >
> >This demonstrates how to play with button styles:
>   .
>   .
>   .
> John, as I read the original poster, Tkinter.DISABLED is *exactly*
> what he wants (although he might not realize it yet); I suspect
> there's no need at all for other styling.
>
> Are Button and Label styles truly identical except for
> disabledforeground?  While I can't make the time now to research
> this for myself, it surprises me; I thought there were padding
> differences ...
>
> Your remark about the Command has me curious:  why remove it?  In
> terms of the original poster's description, what does this serve?
> I repeat my speculation that Tkinter.DISABLED will "do it all" for
> him.

Yes, that's what I needed (and I knew about that before), but I didn't
know about the disabledforeground option. Thanks for the information;
it worked nicely.

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


Re: [pysqlite] [ANN] pysqlite 2.3.0

2006-06-13 Thread Dawid Gajownik
Dnia 06/13/2006 08:52 PM, Użytkownik Gerhard Häring napisał:

> pysqlite 2.3.0 released

Great :) I have one more problem, though. It does not compile:

gcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic 
-fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -O2 -g -pipe -Wall 
-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector 
--param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic 
-fasynchronous-unwind-tables -fPIC -DMODULE_NAME="pysqlite2.dbapi2" 
-I/usr/include -I/usr/include/python2.4 -c src/connection.c -o 
build/temp.linux-i686-2.4/src/connection.o
src/connection.c:31:26: error: sqlitecompat.h: No such file or directory
src/connection.c: In function '_set_result':
src/connection.c:404: error: 'Py_ssize_t' undeclared (first use in this 
function)
src/connection.c:404: error: (Each undeclared identifier is reported 
only once
src/connection.c:404: error: for each function it appears in.)
src/connection.c:404: error: expected ';' before 'buflen'
src/connection.c:417: error: 'buflen' undeclared (first use in this 
function)
src/connection.c: In function '_build_py_params':
src/connection.c:443: error: 'Py_ssize_t' undeclared (first use in this 
function)
src/connection.c:443: error: expected ';' before 'buflen'
src/connection.c:472: error: 'buflen' undeclared (first use in this 
function)
error: command 'gcc' failed with exit status 1

I had to manually download this file → 
http://www.initd.org/tracker/pysqlite/browser/pysqlite/tags/2.3.0/src/sqlitecompat.h
 
Why it's not included in the tarball?

Regards,
Dawid

-- 

   ^_*

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

Re: embedded python and windows multi threading, can't get it to work

2006-06-13 Thread Serge Orlov
freesteel wrote:
> I am trying to run a python programme embedded from C++. I want to run
> the same python code concurrently in several threads. I read the manual
> on embedding, especially chapter 8, and searched for relevant info on
> google all afternoon, but I can't get this to work. What am I doing
> wrong? I use python2.4 and vc++7 (.net). The first thread seems to work
> okay, the 2nd thread crashes, but the exception information is not very
> useful:
> (An unhandled exception of type 'System.NullReferenceException'
> occurred in pyembed_test.exe

Running one iterpreter in more than one thread is not supported. You
need to create one interpreter per thread using Py_NewInterpreter
(don't forget to read "Bugs and caveats" paragraph). I hope you also
realize the interpreters won't share objects.

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


[ANN] pysqlite 2.3.0

2006-06-13 Thread Gerhard Häring
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

pysqlite 2.3.0 released
===

I'm pleased to announce the availability of pysqlite 2.3.0. This is a major
release with a few new features.

Go to http://pysqlite.org/ for downloads, online documentation and
reporting bugs.

What is pysqlite?

pysqlite is a DB-API 2.0-compliant database interface for SQLite.

SQLite is a relational database management system contained in a
relatively small C library. It is a public domain project created
by D. Richard Hipp.  Unlike the usual client-server paradigm, the
SQLite engine is not a standalone process with which the program
communicates, but is linked in and thus becomes an integral part
of the program. The library implements most of SQL-92 standard,
including transactions, triggers and most of complex queries.

pysqlite makes this powerful embedded SQL engine available to
Python programmers. It stays compatible with the Python database
API specification 2.0 as much as possible, but also exposes most
of SQLite's native API, so that it is for example possible to
create user-defined SQL functions and aggregates in Python.

If you need a relational database for your applications, or even
small tools or helper scripts, pysqlite is often a good fit. It's
easy to use, easy to deploy, and does not depend on any other
Python libraries or platform libraries, except SQLite. SQLite
itself is ported to most platforms you'd ever care about.

It's often a good alternative to MySQL, the Microsoft JET engine
or the MSDE, without having any of their license and deployment
issues.

pysqlite can be downloaded from http://pysqlite.org/ - Sources and
Windows binaries for Python 2.4 are available. Windwos binaries for
Python 2.3 will follow during the next days.


===
CHANGES
===

"Errors should never pass silently."


Errors in callbacks used to simply be ignored. They would lead to the
column in question having a NULL value, for example. Now they result
in the query being aborted with a useful error message like
"User-defined function raised exception".

Errors in callbacks can now be printed to stderr. You have to enable
this feature first by calling enable_callback_tracebacks(1), though.

Aborting long-running queries
=

You can now interrupt queries by calling interrupt() on the connection
(from a different thread)

Now with built-in paranoia
==

There is a new connection-level method set_authorizer() for adding authorizer
hooks. You can use it to accept arbitrary SQL statements from users
and limiting what they can do with the database, for example only
allow SELECT statements and restricting access to certain tables or
columns.

Changes for converters
==

Converters are now looked up in a case-insensitive manner.

Bugfixes


Fixed a bug where it was possible that one error while constructing a
result row was hidden by another error. This resulted in segmentation
faults.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEjwmCdIO4ozGCH14RAtUAAJ9UpQFdcPhqEvQEdPWNJUaP2LtoagCcC8Hu
JhIIha/vNIOpahH+pNMOZzo=
=VpsE
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


daily python url - gmane links dead?

2006-06-13 Thread K.S.Sreeram
Is it just me.. or are all the gmane links on daily-python dead?
All the c.l.py.announce entries point to gmane, and none of them seem to
be working. This is the error i get on gmane:

Warning: fsockopen(): unable to connect to hugh:8010 in
/home/httpd/gmane/php/lib.php on line 18
Couldn't contact hugh:8010
The web interface is down for maintenance.

How about using google groups or the python.org archives instead of gmane?

Regards
Sreeram



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: numeric/numpy/numarray

2006-06-13 Thread Robert Kern
Bryan wrote:
> hi,
> 
> what is the difference among numeric, numpy and numarray?  i'm going to start 
> using matplotlib soon and i'm not sure which one i should use.

There's a reasonably complete telling (and up-to-date!) of the history behind
these packages here:

http://www.scipy.org/History_of_SciPy

-- 
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


Re: wxpython: how do i write this without the id parameter?

2006-06-13 Thread John Salerno
Scott David Daniels wrote:

> def __init__(self, parent=None, id=-1, title=__file__):

I get that __file__ is not defined.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Earthquake and Tornado Forecasting Programs June 13, 2006

2006-06-13 Thread CBFalconer
Frank Silvermann wrote:
> 
> [snip]
> I look forward to a day when meteorology has more to do with precise
> models than models, although I'm all for Russian-style delivery of such
> data.  I forecast that a lot of people will be surprised by the weather
> today, as they are categorical idiots, as is the OP.  frank

Oh for a newsreader that can eliminate all such ugly excessively
cross-posted articles lacking follow-ups.  PLONK thread is the only
remaining answer.

-- 
 Some informative links:
   news:news.announce.newusers
   http://www.geocities.com/nnqweb/
   http://www.catb.org/~esr/faqs/smart-questions.html
   http://www.caliburn.nl/topposting.html
   http://www.netmeister.org/news/learn2quote.html


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


Re: wxpython: how do i write this without the id parameter?

2006-06-13 Thread John Salerno
Scott David Daniels wrote:

> class InputForm(wx.Frame):
> def __init__(self, parent=None, id=-1, title=__file__):

Also, is there a way to define parent and id with defaults, but not 
title? Is it good to change the order around to do this?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: numeric/numpy/numarray

2006-06-13 Thread Dan Christensen
Bryan <[EMAIL PROTECTED]> writes:

> on the python wiki
> "NumArray is the current reimplementation of NumPy."
> http://wiki.python.org/moin/NumArray
>
> so, was Numarray written *before* NumPY, or was it a reimplementation of 
> NumPy 
> which implies it came *after* NumPy? 

I clarified that wiki page to use the name "Numeric" for the old
version, and to point out that there is "Numpy" which is even newer
than numarray.

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


Re: USB support

2006-06-13 Thread Richard Townsend
On 13 Jun 2006 11:08:59 -0700, rodmc wrote:

> Hi,
> 
> I need to write a program which can access the USB ports on Mac and
> Linux, is there a library available for Python?
> 
> Thanks in advance.
> 
> Best,
> 
> rod

Not tried it, but:

http://pyusb.berlios.de/


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


Re: Combining The Best Of Python, Ruby, & Java??????

2006-06-13 Thread Luis M. González

Diez B. Roggisch wrote:
> > But semantically it is a proper functional language. The features may
> > not attract Python users who might prefer Boo/Jython/IronPython. But it
> > does offer something to disillusioned Groovy users.
>
> Are they disillusioned? Just wondering.
>
> Diez

Whay talking about disillutioned programmers?
These are tools, not religions...
I love python, and I like it more everyday. And with the advent of
Pypy, its future looks brighter than ever.
But I also find very interesting these new options that are coming up.
Although I'm not a professional programmer (not even a serious
aficionado), I love to be able to translate my python skills very
easily to .NET through Boo, for example.
I even find it more appealing than Ironpython, because it was created
from the ground up to take advantage of the CLR.
On the other hand, porting pure python to .NET is in many aspects like
trying to fit a square on a circle (I don't know if this sentence makes
sense in english...).
Because many of the design choices taken by GvR back in the early
nineties were surely conditioned by the platform he chose to write
python, which is the c language.
The good thing is that python is having a lot of influence in these new
languages.
As far as I could see, even C# 3.0 is showing up some pythonic traits.

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


embedded python and windows multi threading, can't get it to work

2006-06-13 Thread freesteel
I am trying to run a python programme embedded from C++. I want to run
the same python code concurrently in several threads. I read the manual
on embedding, especially chapter 8, and searched for relevant info on
google all afternoon, but I can't get this to work. What am I doing
wrong? I use python2.4 and vc++7 (.net). The first thread seems to work
okay, the 2nd thread crashes, but the exception information is not very
useful:
(An unhandled exception of type 'System.NullReferenceException'
occurred in pyembed_test.exe

Additional information: Object reference not set to an instance of an
object.)

Here is a simplified example, it is heavily based on this article:
http://www.codeproject.com/cpp/embedpython_1.asp



#include 
#include 
#include 
#include 

#define USE_AFX 0




#if USE_AFX
UINT MyThread(LPVOID lpParam)
#else
void MyThread(void* lpParam)
#endif
{
Py_Initialize();
//#if 0
//  PyEval_InitThreads();
PyThreadState *mainthreadstate = PyThreadState_Get();
PyInterpreterState *maininterpreterstate = mainthreadstate->interp;
PyThreadState *mythreadstate =
PyThreadState_New(maininterpreterstate);
PyEval_ReleaseLock();
PyEval_AcquireLock();
PyThreadState *tmpstate = PyThreadState_Swap(mythreadstate);
//#endif


int* num = (int *)lpParam;
int ret = 0;
ret = PyRun_SimpleString("x = []");
ret = PyRun_SimpleString("for i in range(10):\n  x.append(i)");
char cmd[100];
sprintf(cmd, "f = open('test%d.txt', 'w')", *num);
ret = PyRun_SimpleString(cmd);
ret = PyRun_SimpleString("f.write('%s' % x.__str__())");
ret = PyRun_SimpleString("f.close()");

//#if 0
PyThreadState_Swap(tmpstate);
PyEval_ReleaseLock();
PyThreadState_Clear(mythreadstate);
PyThreadState_Delete(mythreadstate);
//#endif



Py_Finalize();
#if USE_AFX
return 0;
#else
_endthread();
#endif
}

class CMyWinApp : public CWinApp
{
public:
CMyWinApp() { }
BOOL InitInstance()
{
int num0 = 0, num1 = 1;
HANDLE hnd0, hnd1;
#if USE_AFX
CWinThread* pThread0 = AfxBeginThread(MyThread, &num0);
hnd0 = pThread0->m_hThread;
CWinThread* pThread1 = AfxBeginThread(MyThread, &num1);
hnd1 = pThread1->m_hThread;
#else
hnd0 = (HANDLE) _beginthread(MyThread, 0, &num0);
hnd1 = (HANDLE) _beginthread(MyThread, 0, &num1);
#endif

// wait for the worker thread to terminate.
WaitForSingleObject(hnd0, INFINITE);
WaitForSingleObject(hnd1, INFINITE);

return TRUE;
};
};

CMyWinApp app;

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


USB support

2006-06-13 Thread rodmc
Hi,

I need to write a program which can access the USB ports on Mac and
Linux, is there a library available for Python?

Thanks in advance.

Best,

rod

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


Re: Very nice python IDE (windows only)

2006-06-13 Thread Luis M. González

Jan Bijsterbosch wrote:
> Hello Luis,
>
> "Luis M. González" <[EMAIL PROTECTED]> schreef in bericht
> news:[EMAIL PROTECTED]
> >
> > [EMAIL PROTECTED] wrote:
> >> I happen to have delphi, so if someone wants me to make small changes,
> >> just let me know, I'll try to help
> >
> > Hmm... now that you offer, would it be possible to have the colors of
> > text just like in IDLE?
> > I tried configuring the colors, but some of them don't exist as options
> > in this IDE (for example "orange").
>
> Hmm, it's a little bit hidden, but if you go to Options / Editor / Syntax
> Colors and be sure to select Python language as editor syntax then select
> 'reserved words' and after that from the color dropdown box select Custom...
> (the topmost option) a color dialog pops up and you can select any color You
> want...;-))
>
> > I like how text looks in IDLE, with orange for reserved words, green
> > for strings, etc...
>
> With the above, no problem at all...;-))
>
> Greetings from sunny Amsterdam,
>
> Jan

Thank you!
You're right, the custom option is a litle bit hiddenm but now I
customized it just as I wanted.
Great IDE! I love it...

Luis

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


Trace KeyboardInterrupt exception?

2006-06-13 Thread Tony Nelson
I'm trying to find out what is eating some KeyboardInterrupt exceptions 
in a fairly large program (yum).  My KeyboardInterrupt handler is called 
for some Ctl-C presses, but for others nothing seems to happen.  
Grepping the source (what of it I've found, looking at import 
statements) doesn't turn up anything likely.

My thinking is that either some "except:" clause is eating them, or some 
place I haven't looked is eating them, or possibly C code is eating 
them.  For the first two, at least, I'd like to use a debugger to trace 
KeyboardInterrupt exceptions, make sure that they're happening, and see 
what is handling them.  I don't see a way to trace or break on a 
specific exception type in Idle.  Can someone give me a hint on how to 
do this?  I'm willing to consider other debuggers, including gdb (DDD).

TonyN.:'[EMAIL PROTECTED]
  '  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Customized Boot Manager in Python

2006-06-13 Thread 3c273
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Now, I have to create a visual interface for such kind of small
> program.
>
> I have 2 questions
> (i) How can we use operating system specific commands like ssh within
> the python program (ii) Which grphics library (wxPython or any other)
> would be the fastest with least learning curve to get this thing done.
>
> Thanks

(i)Check out the subprocess module.
(ii)If you are just looking to put a couple of buttons on a gui, I learned
to do this pretty quickly using Tkinter and one of the online tutorials.
Louis


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


DispatchEx('.Application')

2006-06-13 Thread iainws
When using win32com and DispatchEx to work with a webbrowser, eg:

from win32com.client import DispatchEx

ie = DispatchEx('InternetExplorer.Application')

can anyone suggest the right answer to this?

mf = DispatchEx('MozillaFirefox.Application')

It is an invalid class string, but I don't know how to find the right
class string for Mozilla (or any other window for that matter)? Can
somebody suggest to me an easy way to 'get' this information.

After that I intend to do this:

mf.Navigate('www.groups.google.com.au/etc'')

Will all of these functions work with Firefox or is it only Internet
Explorer(I can use either but I prefer Firefox?)

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


Re: Is there a better way of accessing functions in a module?

2006-06-13 Thread Mike Kent
Yes, you can go that route.  But since it appears that what you are
doing is unit testing related, and you are interested in aranging for
all of your unit test cases to be run automatically, I'd suggest using
the unittest module.

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


Re: .py and running in Windows:

2006-06-13 Thread Fredrik Lundh
Michael Yanowitz wrote:

> I never specified a thread. I think perhaps though because I did
> open another message in this mailing list (to get the correct
> email address to send to), but I deleted all its contents i put
> it under that other thread, however there is no indication of a
> thread in Outlook email. I am sorry if it came up in another
> thread that was not my intention.

your message contains the line

In-Reply-To: <[EMAIL PROTECTED]>

which indicates that you pressed "reply to", rather than "new message". 
changing the subject doesn't change that; your mail program still 
does what you asked it to do.



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


Re: Is there a better way of accessing functions in a module?

2006-06-13 Thread Ant

Ant wrote:
...
> But this feels like a hack... Is there a cleaner way for accessing the
> functions of the current module similar to the __dict__ attribute of
> classes? i.e. a way to access the local symbol table?

Sorry - posted too soon. Found the globals() built-in...

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


Is there a better way of accessing functions in a module?

2006-06-13 Thread Ant
I have the following code which works fine for running some tests
defined within a module:

def a_test():
print "Test A"

def b_test():
print "Test B"

if __name__ == "__main__":
tests = ["%s()" % x for x in dir() if x.endswith("test")]

for test in tests:
eval(test)

But this feels like a hack... Is there a cleaner way for accessing the
functions of the current module similar to the __dict__ attribute of
classes? i.e. a way to access the local symbol table?

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


Re: Earthquake and Tornado Forecasting Programs June 13, 2006

2006-06-13 Thread Frank Silvermann
[snip]
I look forward to a day when meteorology has more to do with precise 
models than models, although I'm all for Russian-style delivery of such 
data.  I forecast that a lot of people will be surprised by the weather 
today, as they are categorical idiots, as is the OP.  frank
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 411.

2006-06-13 Thread Steve Holden
Brian van den Broek wrote:
> Mike T said unto the world upon 13/06/06 10:46 AM:
> 
>>What exactly is 411 in this context?  A reference to higher education
>>perhaps?  Or perhaps part of the American constitution? What exactly?
>>Also for that matter what is 101?
>>
>>Cheers,
>>Mike
>>
> 
> 
> Hi Mike,
> 
> 411 is the number one dials in North America to reach directory 
> assistance (getting telephone numbers). So, it has a slang usage 
> meaning something like information. Introductory university course in 
> a field are often numbered 101 (i.e. Computer Science 101). So, that 
> number has acquired a slang meaning of basic and introductory information.
> 
> Where I did my undergrad studies, a few Departments had 001 classes. 
> Somehow that felt more honest ;-)
> 
Surely 000 would have been more consistent ...

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: ANN: Dao 1.0.0-alpha is released

2006-06-13 Thread Ilias Lazaridis
[EMAIL PROTECTED] wrote:
> Hello,
> 
> It is a pleasure to announce in this mailing list the newly released
> Dao. This is the first release after the Dao interpreter being
...

> Two modules are also released along with the virtual machine: DaoMySQL
> and DaoPyhon. DaoPython is particularly interesting, because it allows
> Python modules to be loaded by Dao, then Python variables, functions
> and classes can be used conviniently in Dao scripts.
...

> For more detail about this release: please visit http://www.xdao.org,
> and http://xdao.org/dokuwiki/.

the documentation looks nice!

hope you've implemented most of my suggestions subjecting reflection.

Whenever I have the time, I will take a closer look and check dao 
against this one:

http://lazaridis.com/case/lang/

> Your suggestions and comments are extremely welcome!
> Limin FU

.

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


Re: [*SPAM*] Python open proxy honeypot

2006-06-13 Thread Alex Reinhart
Tim Williams wrote:
> On 13/06/06, Alex Reinhart <[EMAIL PROTECTED]> wrote:
>>
>> Is running Python's built-in smtpd, pretending to accept and forward all
>> messages, enough to get me noticed by a spammer, or do I have to do
>> something else to "advertise" my script as an open proxy?
> 
> This will get you noticed by crawlers that scan the Internet looking
> for SMTP open-relays on port 25,  its not an open-proxy :):)
> 
Yeah, I just realized that. What would I do to act as an open proxy as well?

> This will work as planned,  but you should also have some email
> addresses using this server for a full range of spam hits.   A single
> domain is cheap and you can use it just for incoming spam - seed a few
> addresses around the internet and wait
> 
> Things you should be aware of:
> 
> a) You may be breaking your ISP's T&Cs and AUPs
I plan on asking them first - it's not actually a proxy/relay, just
pretending to be one.
> 
> b) your ISP connection must have port 25 open
They use SMTP for their mailservers, so I assume they do.
> 
> c) Be prepared for potentially huge numbers of connections in
> intermittent but sustained batches which may make your connection
> unusable.
I'm hoping to host it on another server, preferably with a firewall to
keep things from getting too hairy.

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


Re: Decimals

2006-06-13 Thread Diez B. Roggisch
Tgone wrote:

> Sybren Stuvel wrote:
>> Tgone enlightened us with:
>> > Sorry, when I print out the variable it displays as '15.0'. The
>> > price is '15.00' in the database though.
>>
>> That's the same thing, isn't it? 15.0 == 15.0
> 
> Yes, they're both mathematically the same. I never said they weren't...
> 
>> > Here's my code:
>> >
>> > product = Product.get(2)
>> > print product.price # 15.0
>>
>> Try string formatting:
>>
>> print '%.2f' % product.price
> 
> That works. I expected Python to display the data exactly as it is in
> the database, like most languages.

Care to give us an example of "one of those"? 

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


Re: Decimals

2006-06-13 Thread Steve Holden
Tgone wrote:
> Sybren Stuvel wrote:
> 
>>Tgone enlightened us with:
>>
>>>Sorry, when I print out the variable it displays as '15.0'. The
>>>price is '15.00' in the database though.
>>
>>That's the same thing, isn't it? 15.0 == 15.0
> 
> 
> Yes, they're both mathematically the same. I never said they weren't...
> 
> 
>>>Here's my code:
>>>
>>>product = Product.get(2)
>>>print product.price # 15.0
>>
>>Try string formatting:
>>
>>print '%.2f' % product.price
> 
> 
> That works. I expected Python to display the data exactly as it is in
> the database, like most languages.
> 
Well I'm sorry Python doesn't live up to your expectations, but I think 
your assertion "like most languages" is a little over-reaching.

What's actually happening is that the database is storing the number in 
some internal format known to itself. The module you are using to access 
the database is actually converting that value to a floating-point 
number (I'm guessing here: some more modern modules will convert it to a 
decimal). That's where the scaling factor gets lost, as until fairly 
recently Python only *had* floats (well, and complex numbers)to 
represent non-integral numbers.

So basically you are likely to be stuck with formatting the data the way 
you want to see it. This is fairly usual in my experience.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Making a Label that looks the same as a button.

2006-06-13 Thread Fredrik Lundh
Andrew Gwozdziewycz wrote:

> It's imperative that you explain which toolkit you are using since  
> they all have differences.

however, if you knew the answer, you would have recognized what toolkit 
he was using.



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


TONIGHT! Lisp group beerfest in NYC, PyCells to be discussed

2006-06-13 Thread Ken Tilton
The royal We has just learned that His Kennyness will be honoring the 
boozehounds of LispNYC with His Presence tonight (deets below).

He will come bearing Celtk and news of PyCells, though the top billing 
tonight goes to SoC student Extraordinaire Samantha Kleinberg.

kenzo

> Please join us for our next meeting on Tuesday, June 13th from 7:00
> to 9:00 at Westside Brewery.
> 
> With Summer of Code being here, this is a great opportunity to talk and
> drink regarding the students and their projects!
> 
> Hope to see you there!
> 
> 
> 
> Directions:
> 
>  Westside Brewery in the VIP room
>  340 Amsterdam Ave.
>  (On the West side of Amsterdam Ave., 76th-77th)
> 
> Directions by subway: 1-2-3-9 (the red line) to 72nd or 79th and
> Broadway.  From 72nd, walk up Amsterdam (not Broadway).  From 79th, walk
> east one long block to Amsterdam and turn right/south.
> 
> Directions by car: 79th street exit from west side highway, down West
> End Ave or Broadway to 76th, turn left and one or two blocks to
> Amsterdam.

-- 
Cells: http://common-lisp.net/project/cells/

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie]apache authentication questions

2006-06-13 Thread Steve Holden
Michael Ströder wrote:
> Steve Holden wrote:
> 
>>[EMAIL PROTECTED] wrote:
>>
>>
>>>It is not impossible though and in cases where you don't have a choice
>>>but to use a HTTP authentication scheme, use of AJAX may be the
>>>answer to still allowing use of a form based login scheme. See:
>>>
>>>  http://www.peej.co.uk/articles/http-auth-with-html-forms.html
>>>
>>
>>That's neat!
> 
> 
> IMHO this makes things more complicated and error-prone. And it requires
> Javascript. I also can't see why this is more secure than a proper
> session management (using cookies or URL for passing the session ticket
> around).
> 
I don't believe I said it *was* any of those things. But I am constantly 
amazed at the lengths the world will go to just to prove me wrong!

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Love me, love my blog  http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Writing PNG with pure Python

2006-06-13 Thread Johann C. Rocholl
How about this here construct?

#!/usr/bin/env python
# png.py - PNG encoder in pure Python
# Copyright (C) 2006 Johann C. Rocholl <[EMAIL PROTECTED]>
#
# This file is licensed alternatively under one of the following:
# 1. GNU Lesser General Public License (LGPL), Version 2.1 or newer
# 2. GNU General Public License (GPL), Version 2 or newer
# 3. Apache License, Version 2.0 or newer
# 4. The following license (aka MIT License)
#
# - start of license -
# Copyright (C) 2006 Johann C. Rocholl <[EMAIL PROTECTED]>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# --- end of license -
#
# You may not use this file except in compliance with at least one of
# the above four licenses.

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


Re: Python 411.

2006-06-13 Thread Terry Reedy

"Brian van den Broek" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> meaning something like information. Introductory university course in
> a field are often numbered 101 (i.e. Computer Science 101). So, that
> number has acquired a slang meaning of basic and introductory 
> information.
>
> Where I did my undergrad studies, a few Departments had 001 classes.
> Somehow that felt more honest ;-)

This is OT, but...
Course numbering varies by college/university, but I think typically 1xx, 
2xx, 3xx, and 4xx are aimed at students in years 1, 2, 3, and 4 majoring in 
that subject.  Pre-100 courses would be remedial or aimed or even limited 
to non-major students.  So a Math department might have 023 Business Math 
that would not count toward the math units needed to get a BS in math.

tjr



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


Re: .py and running in Windows:

2006-06-13 Thread imcs ee
i modify 
"C:\Python\python.exe" -i "%1" %* 
to 
cmd /k;"C:\Python\python.exe" -i "%1" %* 
or
cmd /k;"C:\Python\python.exe" "%1" %* 
 
just a little trick. 
On 13 Jun 2006 06:48:23 -0700, Iain King <[EMAIL PROTECTED]> wrote:
Andrew Gwozdziewycz wrote:> You'll have better results posting this to it's own thread.>
He certainly should have, but since I've read it here anyway:> On Jun 13, 2006, at 9:29 AM, Michael Yanowitz wrote:>> > Hello:> >> >   Presently in my Windows 2000 system, when I double-click on a
> > .py file (open it) it automatically runs it in Python. I would> > like to change that behavour. That is fine for .pyc file, but> > for .py files, I would either like to have it run in Python but
> > return to the Python shell prompt when finished rather than> > exit the shell. How do I do that?> >   Or would it cause a problem (so that Python no longer works) if> > I change the default .py extension to open in an editor rather
> > than execute it if I open it?> >In an explorer window, go to Tools->Folder OptionsGo to the File Types tab, find the PY extension, then click onAdvanced*Select the 'open' action, and click Edit...
change the 'Application used to perform action', inserting a '-i'between the exe and the first parameter.  For example, I changed mineto:"C:\Python\python.exe" -i "%1" %*The exact line will depend on where your 
python.exe is.OK all the dialogs you've opened, then double click a .py file to testit.*I'm using WinXP, so the exact name of some of the buttons may bedifferent for you.Iain--
http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: a string problem

2006-06-13 Thread Mitja Trampus
John Salerno wrote:
> [EMAIL PROTECTED] wrote:
>> hi
>>
>> if i have a some lines  like this
>> a ) "here is first string"
>> b ) "here is string2"
>> c ) "here is string3"
>>
>> When i specify i only want to print the lines that contains "string" ie
> ...
> And I'm actually ashamed to admit that I know the RE way, but not the 
> regular string manipulation way, if there is one! This seems like 
> something easy enough to do without REs though.

I'd just split it on whitespace, just like with the RE:
if "string" in "here is first string".split(): ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a string problem

2006-06-13 Thread Maric Michaud
Le Mardi 13 Juin 2006 15:59, John Salerno a écrit :
> And I'm actually ashamed to admit that I know the RE way, but not the
> regular string manipulation way, if there is one!

eheh,

In [39]: import string

In [40]: sub, s1, s2 = 'string', 're string2, ,string1', 're string2, ,string'

In [41]: sub in [ e.strip(string.punctuation) for e in s1.split() ]
Out[41]: False

In [42]: sub in [ e.strip(string.punctuation) for e in s2.split() ]
Out[42]: True

> This seems like 
> something easy enough to do without REs though.

Yes, but python way seems a little faster

python2.4 -mtimeit -s "import re" "re.match('\bstring\b', 're 
string2, ,string1') and True"
10 loops, best of 3: 7.3 usec per loop
python2.4 -mtimeit -s "import string" "'string' in [ 
e.strip(string.punctuation) for e in 're string2, ,string1'.split() ]"
10 loops, best of 3: 6.99 usec per loop


-- 
_

Maric Michaud
_

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Making a Label that looks the same as a button.

2006-06-13 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Grayson, John <[EMAIL PROTECTED]> wrote:
> 
>
>
>Buttons can look like labels without the need to create another object -
>just remove the
>Command binding, set state to DISABLED and disabledforeground='same
>color as NORMAL'...
>
>This demonstrates how to play with button styles:
.
.
.
John, as I read the original poster, Tkinter.DISABLED is *exactly* 
what he wants (although he might not realize it yet); I suspect
there's no need at all for other styling.

Are Button and Label styles truly identical except for
disabledforeground?  While I can't make the time now to research
this for myself, it surprises me; I thought there were padding
differences ...

Your remark about the Command has me curious:  why remove it?  In
terms of the original poster's description, what does this serve?
I repeat my speculation that Tkinter.DISABLED will "do it all" for
him.
-- 
http://mail.python.org/mailman/listinfo/python-list


Vancouver Python Workshop - Talk submission reminder

2006-06-13 Thread Brian Quinlan
What's New?
===

The deadline for submitting a talk or tutorial for the Vancouver Python
Workshop is fast approaching. Talks will be accepted until Friday June
16th.

To submit a talk, see:
http://www.vanpyz.org/conference/talksubmission.html

About the Vancouver Python Workshop
===

The conference will begin with keynote addresses on August 4st by Guido
van Rossum [1], Jim Hugunin [2], and Ian Cavén [3]. Further talks (and
tutorials for beginners) will take place on August 5th and 6th. The
Vancouver Python Workshop is a community organized and designed for both
the beginner and for the experienced Python programmer with:

   * tutorials for beginning programmers
   * advanced lectures for Python experts
   * case studies of Python in action
   * after-hours social events
   * informative keynote speakers
   * tracks on multimedia, Web development, education and more

More information see: http://www.vanpyz.org/conference/
or contact Brian Quinlan at: [EMAIL PROTECTED]

Vancouver
=

In addition to the opportunity to learn and socialize with fellow
Pythonistas, the Vancouver Python Workshop also gives visitors the
opportunity to visit one of the most extraordinary cities in the world
[4]. For more information about traveling to Vancouver, see:

http://www.vanpyz.org/conference/vancouver.html
http://www.tourismvancouver.com
http://en.wikipedia.org/wiki/Vancouver

Important dates
===

Talk proposals accepted: May 15th to June 15th
Early registration (discounted): May 22nd to June 30th
Normal registration: from July 1st
Keynotes: August 4th
Conference and tutorial dates: August 5th and 6th

[1] Guido van Rossum (Google) is the inventor of Python and has managed
  its growth and development for more than a decade. Guido was
  awarded the Free Software Foundation Award in 2002 and Dr.Dobb's
  1999 Excellence in Programming Award. Guido works at Google and
  spends half of his time on Python.

[2] Jim Hugunin (Microsoft) is the creator of numerous innovations that
 take Python into new application domains. Jim's most recent project,
 IronPython integrates Python into Microsoft's .NET runtime. Jim's
 previous project, Jython is Python for the Java runtime and was the
 second production-quality implementation of Python. Before that,
 Jim's Numeric Python adapted Python to the needs of number crunching
 applications. Jim works at Microsoft adapting the .NET runtime to
 the needs of dynamic languages like Python.

[3] Ian Cavén is the primary developer of the Lowry Digital Images
 motion picture restoration system. This Python and Zope-based system
 has been used to restore over 150 motion pictures. Highlights
 include Citizen Kane, Sunset Boulevard and both the Indiana Jones
 and Star Wars trilogies. While Ian was Chief Scientist at Lowry
 Digital, his rack of computers grew from a few Macintoshes on his
 desktop to over six hundred Macintosh and Linux servers - at
 one point earning Lowry the title as the second biggest installation
 of parallel processing Maintoshes in the world. In 2005, Lowry
 Digital Images was acquired by DTS (the famous movie audio company)
 and renamed DTS Digital Images. The motion picture restoration
 system has been discussed in publications as diverse as IEEE
 Spectrum, USA Today, the BBC NEWS, the New York Times and Apple.com.
 Ian has been a Python enthusiast since 1999.

[4] http://news.bbc.co.uk/2/hi/business/2299119.stm

Cheers,
Brian

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


Re: "groupby" is brilliant!

2006-06-13 Thread Benji York
Frank Millman wrote:
> reader = csv.reader(open('trans.csv', 'rb'))
> rows = []
> for row in reader:
> rows.append(row)

Why do you create a list of rows instead of just iterating over the 
reader directly?
--
Benji York
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a string problem

2006-06-13 Thread Rune Strand

[EMAIL PROTECTED] wrote:
> hi
>
> if i have a some lines  like this
> a ) "here is first string"
> b ) "here is string2"
> c ) "here is string3"
>
> When i specify i only want to print the lines that contains "string" ie
> the first line and not the others. If i use re module, how to compile
> the expression to do this? I tried the re module and using simple
> search() and everytime it gives me all the 3 lines that have "string"
> in it, whereas i only need line 1.
> If re module is not needed, how can i use string manipulation to do
> this? thanks

If this is a RL-situation, 
if mystring.endswith('string') will do

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


Re: Python 411.

2006-06-13 Thread Ron Stephens
Steve, thanks for the note. The name Python411 comes from me copying my
good friend Rob Walch, who named his podcast Podcast411, which is a
popular show on which he interviews other podcasters like Adam Curry
etc. He also has a book just published about podcasting.

Ron Stephens

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


Re: numeric/numpy/numarray

2006-06-13 Thread John Hunter
> "Bryan" == Bryan  <[EMAIL PROTECTED]> writes:

Bryan> hi, what is the difference among numeric, numpy and
Bryan> numarray?  i'm going to start using matplotlib soon and i'm
Bryan> not sure which one i should use.

numpy is the successor to numarray and Numeric.  All three do
basically the same thing.  You should use numpy.

matplotlib works with all three, you just need to be sure to set your
"numerix" setting to "numpy" in your matplotlibrc file.

numerix  : numpy  # numpy, Numeric or numarray

On unix like OSes, this file is placed in ~/.matplotlib.  On windows
systems, it is usually found in C:\Documents and
Settings\yourname\.matplotlib

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


Re: Linux info

2006-06-13 Thread vasudevram
os.system('ls -lL ' + path)
should also work. But check, I may be wrong about the L option, and am
not near a Linux system right now.

That's "lL" - a small letter l (ell) followed by a capital letter L in
the ls options above.

This way may be slower than os.path.realpath if that is implemented as
a system call, i.e.via Python ->C->Linux kernel, which it probably is.
Slower since my way given above will create a new process to run the ls
command in. Just mentioning it as another way, plus, it does have the
small benefit that it'll work the same way on any other language such
as Perl, Ruby, etc., which supports something similar to os.system().

Vasudev Ram
http://www.geocities.com/vasudevram
PDF conversion tools: http://sourceforge.net/projects/xtopdf


faulkner wrote:
> os.path.realpath
>
> TheSaint wrote:
> > Hello there,
> >
> > I still learning, but I couldn't find anything which tells me where a
> > symlink is pointing to.
> > A part of os.system('ls -l ' + path) and cutting down to the need, I haven't
> > got any specialized function.
> > 
> > F

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


Re: numeric/numpy/numarray

2006-06-13 Thread Bryan
Ben Sizer wrote:
> Bryan wrote:
> 
>> at the end of that page, it says:
>>
>> "Numarray is another implementation of an arrayobject for Python written 
>> after
>> Numeric and before NumPy. Sponsors of numarray have indicated they will be
>> moving to NumPy as soon as is feasible for them so that eventually numarray 
>> will
>> be phased out."
>>
>>
>> on the python wiki
>> "NumArray is the current reimplementation of NumPy."
>> http://wiki.python.org/moin/NumArray
>>
>> so, was Numarray written *before* NumPY, or was it a reimplementation of 
>> NumPy
>> which implies it came *after* NumPy?  it seems clear that Numeric is the old 
>> one
>> and i read is not being worked on anymore.  so that leaves Numarray and 
>> numpy.
>> which of these two should i use?
> 
> Bryan,
> 
> NumPy is the name of both an old package and a new package. I believe
> that NumArray came after the first incarnation, but that the new
> incarnation of NumPy is the most recent, and is probably the one you
> want.
> 

thanks ben,

i'll use NumPy then.  just wish it was clear and obvious which one to use so i 
wouldn't have had to ask this question here.

bryan

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


Re: a string problem

2006-06-13 Thread micklee74

John Salerno wrote:
> [EMAIL PROTECTED] wrote:
>
> > just curious , if RE has the \b and it works, can we look into the
> > source of re and see how its done for \b ?
>
> I had a look in the sre module (which re seems to import), but I
> couldn't find much. I'm not the best at analyzing source code, though. :)
>
> What is it you want to know about \b? It searches for the empty string
> before and after a word (word being an alphanumeric character that can
> include underscores).
>
> A little more specific info is in the docs:
>
> Matches the empty string, but only at the beginning or end of a word. A
> word is defined as a sequence of alphanumeric or underscore characters,
> so the end of a word is indicated by whitespace or a non-alphanumeric,
> non-underscore character. Note that \b is defined as the boundary
> between \w and \ W, so the precise set of characters deemed to be
> alphanumeric depends on the values of the UNICODE and LOCALE flags.
> Inside a character range, \b represents the backspace character, for
> compatibility with Python's string literals.

thanks..actually i had seen \b in the docs before, just that it slipped
my mind when i was doing the coding. was even meddling with look aheads
..which is not the answer anyway.
well, since re has the \b, was wondering why there is no implementation
of it in strings. So the idea of looking at the source or re on how
it's done came to my mine..i suppose we have to go down to viewing the
C source then..:-)

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


  1   2   >