Re: __file__

2007-04-10 Thread Gabriel Genellina
En Tue, 10 Apr 2007 21:20:51 -0300, 7stud <[EMAIL PROTECTED]>  
escribió:

> I'm having trouble understanding what the definition of __file__ is.
> With this program:
>
> --
> #data.py:
>
> def show():
> print __file__
>
> if __name__ == "__main__":
> show()
> ---
>
> if I run data.py with the prompt pointing to the directory that
> contains data.py, then __file__ produces a filename:
>
> data.py

[cut: other examples showing different paths to data.py]

__file__ corresponds to the filename used to locate and load the module,  
whatever it is. When the module is found on the current directory  
(corresponding to '' in sys.path), you get just the filename; if sys.path  
contains a relative path, that's what you get; the same for any absolute  
path.
Whatever path worked to find and load the module, that's stored as  
__file__.

If you plan to use it, it's a good idea to make it early into an absolute  
path (using os.path.abspath(__file__)) just in case the current directory  
changes.

> And some modules have __file__ in their __dict__ and some don't:
> pprint.pprint(sys.__dict__)

sys is a builtin module: no sys.py/sys.pyc exists, so __file__ is  
meaningless.

-- 
Gabriel Genellina

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


Re: Does python have the static function member like C++

2007-04-10 Thread goodwolf
On Apr 11, 5:19 am, "7stud" <[EMAIL PROTECTED]> wrote:
> On Apr 10, 9:08 pm, "人言落日是天涯,望极天涯不见家" <[EMAIL PROTECTED]> wrote:
>
> > I define the class like this:
> > class AAA:
> > counter = 0
> > def __init__(self):
> > pass
> > def counter_increase():
> > AAA.counter += 1
> > print "couter now :", AAA.counter
>
> > But how could I call the function "counter_incrrease" ?
>
> > Thanks !
>
> 1)
> class AAA:
> counter = 0
> def __init__(self):
> pass
> @staticmethod
> def counter_increase():
> AAA.counter += 1
> print "couter now :", AAA.counter
>
> AAA.counter_increase()
>
> 2)
> class AAA:
> counter = 0
> def __init__(self):
> pass
> def counter_increase():
> AAA.counter += 1
> print "couter now :", AAA.counter
> counter_increase = staticmethod(counter_increase)
>
> AAA.counter_increase()
>
> 3)
> class AAA:
> counter = 0
> def __init__(self):
> pass
> def counter_increase(self):
> AAA.counter += 1
> print "couter now :", AAA.counter
> aaa = AAA()
> AAA.counter_increase(aaa)

1. In this case you will prefer a classmethod instead a staticmethod.
2. If counter is the number of instances of class AAA then you will
incrase counter inside __init__ method.

class AAA (object):
counter = 0
def __init__(self):
type(self).counter_increase()
@classmethod
def counter_increase(cls):
cls.counter += 1

or

class AAA (object):
counter = 0
def __init__(self):
type(self).counter += 1

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

Re: Does python have the static function member like C++

2007-04-10 Thread bearophileHUGS
> Many thanks for you!
> I've never heard of the "staticmethod" , that's great!

Note that you don't need an empty __init__ :

class AAA:
counter = 0

@staticmethod
def counter_increase():
AAA.counter += 1
print "couter now:", AAA.counter

AAA.counter_increase()

Bye,
bearophile

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


[ANN] IPython 0.8.0 is out

2007-04-10 Thread Fernando Perez
Hi all,

The IPython team is happy to release version 0.8.0, with a lot of new
enhancements, as well as many bug fixes.

We hope you all enjoy it, and please report any problems as usual.


WHAT is IPython?


1. An interactive shell superior to Python's default. IPython has many
features for object introspection, system shell access, and its own special
command system for adding functionality when working interactively.

2. An embeddable, ready to use interpreter for your own programs. IPython
can
be started with a single call from inside another program, providing access
to
the current namespace.

3. A flexible framework which can be used as the base environment for other
systems with Python as the underlying language.

4. A shell for interactive usage of threaded graphical toolkits. IPython has
support for interactive, non-blocking control of GTK, Qt and WX applications
via special threading flags. The normal Python shell can only do this for
Tkinter applications.


Where to get it
---

IPython's homepage is at:

http://ipython.scipy.org

and downloads are at:

http://ipython.scipy.org/dist

We've provided:

  - Source download (.tar.gz)
  - A Python Egg (http://peak.telecommunity.com/DevCenter/PythonEggs).
  - A python 2.4 RPM.
  - A native win32 installer.

The egg is 'light', as it doesn't include documentation and other ancillary
data.  If you want a full ipython installation, use the source tarball or
your
distribution's favorite system.

We note that IPython is now officially part of most major Linux and BSD
distributions, so packages for this version should be coming soon, as the
respective maintainers have the time to follow their packaging procedures.
Many thanks to the distribution packagers for their work, which helps users
get
IPython more conveniently.

Thanks to all the users who contributed bug reports, ideas and especially
patches.  The ChangeLog has hopefully detailed acknowledgements, but please
let
us know if we've accidentally ommitted giving you due credit.

Many thanks to Enthought for their continued hosting support for IPython.


Release notes
-

As always, the full ChangeLog is at http://ipython.scipy.org/ChangeLog.  The
highlights of this release follow.  Also see the "What's New" page at

http://ipython.scipy.org/moin/WhatsNew

 * Support for KeyboardInterrupt (Ctrl-C) when running in multithreaded mode
   with GUI support.  This had been a long-requested feature that we had
never
   quite been able to implement correctly.  Many thanks to Tomer Filiba's
for
   his ctypes-based trick: http://sebulba.wikispaces.com/recipe+thread2,
which
   we used (any implementation mistakes are our own and not his fault). 
Users
   of Python 2.4 should note that they need to install ctypes separately to
   access this feature; ctypes is part of Python 2.5 already.

 * Fully syntax-highlighted tracebacks and debugger listings.  IPython used
to
   color tracebacks, but only certain elements; now the source is actually
   highlighted by the same engine that handles '??' source listings, both in
   tracebacks and during interactive debugging.
   
 * Improved the ipipe system: http://ipython.scipy.org/moin/UsingIPipe,
   including a new WX-based graphical browser.

 * Much improved unicode support.  There may still be bugs remaining, but a
   number of known-incorrect cases have been fixed.

 * Make the execution of 'from pylab import *' when -pylab is given be
otional.
   A new flag (which can be set in your ipythonrc file), pylab_import_all
   controls this behavior, the default is True for backwards compatibility.
   
 * Extensions for perforce support via a new magic (%p4) and custom command
   completers.

 * Improved support for (X)Emacs under win32.

 * Several small fixes and improvements to the interactive demo module.

 * Add \N for the actual prompt number, without any coloring, as an escape
for
   customized prompt definitions.  This lets users write their own custom
   prompts with arbitrary coloring schemes.
 
 * Many more bugfixes and small features everywhere (the ChangeLog linked
above
   has the gory details).

   
API changes:

 * genutils.clock() now returns user+system time.  The new clocku/clocks
   functions return respectively user and system time only.


Enjoy, and as usual please report any problems.


The IPython team.

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


Re: tuples, index method, Python's design

2007-04-10 Thread Carsten Haese
On Tue, 2007-04-10 at 21:23 -0700, Paul Rubin wrote:
> Carsten Haese <[EMAIL PROTECTED]> writes:
> > You have a point. Here is my revised solution:
> > 
> > assert current_player in p
> > opponents = tuple(x for x in p if x is not current_player)
> 
> Still wrong on two counts.  First, assert is a no-op if optimization
> is turned on.

Right. I already responded to this when Bjorn made the same objection.
Please try to keep up.

>   Second, your version returns a different result from
> the original if current_player occurs in p more than once.

First of all, in the use case we're talking about, current_player
shouldn't occur in p more than once. And if it did, is it really
reasonable to demand that that player be their own opponent? I don't
think so. So yes, the result is different because it's correct, and the
tuple.index-based solution is actually incorrect in this case.

-Carsten


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


Re: Universal Feed Parser issue

2007-04-10 Thread i3dmaster
On Apr 10, 6:45 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Tue, 10 Apr 2007 14:58:42 -0300, i3dmaster <[EMAIL PROTECTED]>
> escribió:
>
> > I have a sample Atom feed like this:
>
> > 
> >  ...
> >   
> >   
> > 
>
> > After parsed by feedparser, the timezone element does not get the
> > attribute "America/Mountain". Same thing on status element. This does
> > not sound an expected result.  I am wondering if it should be
> > considered a bug...
>
> Usually it's a good idea to read the documentation...  
> http://www.feedparser.org/docs/namespace-handling.html
>
> --
> Gabriel Genellina


I did. Perhaps its because of not 100% atom compatible of my feed
format? See if I use gnosis xml utility to parse it, it works fine
though...

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


Re: Check for keypress on Linux xterm ?

2007-04-10 Thread Grant Edwards
On 2007-04-11, hlubenow <[EMAIL PROTECTED]> wrote:
> I wrote:
>
>> Hello,
>> 
>> I'd like to check, if a single key is pressed on a Linux xterm.
>> My problem is, I don't want my program to wait for the keypress.
>> I just want to check, if a key is currently pressed and if not, I'd like
>> to continue with my program (like "INKEY$" in some BASIC-dialects).
>
> Ok, here's the code I use now. Thanks to Grant Edwards for pointing me into
> the right direction:
>
> --
>
> #!/usr/bin/env python
>
> import os
> import sys
> import tty
> import termios 
> import fcntl
> import time
>
> fd = sys.stdin.fileno()
>
> oldterm = termios.tcgetattr(fd)
> oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
>
> tty.setcbreak(sys.stdin.fileno())
> newattr = termios.tcgetattr(fd)
> newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
>
>
> def oldTerminalSettings():
> termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
> fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
>
>
> def newTerminalSettings():
> termios.tcsetattr(fd, termios.TCSANOW, newattr)
> fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
>
>
> def checkKey():
>
> try:
> c = sys.stdin.read(1)
> return ord(c)
>
> except IOError:
> return 0

Ah, but how do you tell "no key" from ctrl-@ (which has a
ordinal value of 0)?   If I were you, I'd return None in the case
where there is nothing to return:

def checkKey():
try:
   return ord(sys.stdin.read(1))
except IOError:
   return None

I'm also not sure if there are other possible causes for the
IOError exception that you'd need to watch out for.  Ideally,
you'd check to make sure its an EAGAIN.

> print
> print "Ok, in 3 seconds, I'll check 100 times, which key you press."
> print
>
> # Initializing: Things like "raw_input()" won't work after that:
> newTerminalSettings()
>
> time.sleep(3)
>
> for i in range(100):
> a = "Key pressed: "
>
> key = checkKey()
>
> if key:

And here, you'd have this:

  if key is not None:
> a += chr(key)
> a += "."
> else:
> a += "Nothing pressed."
>
> print a


-- 
Grant Edwards   grante Yow!  When you get your
  at   PH.D. will you get able to
   visi.comwork at BURGER KING?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: itertools, functools, file enhancement ideas

2007-04-10 Thread Paul Rubin
"Klaas" <[EMAIL PROTECTED]> writes:
> Still don't see much advantage over writing a lambda (except perhaps
> speed).

Well, it's partly a matter of avoiding boilerplate, especially with
the lambdaphobia that many Python users seem to have.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples, index method, Python's design

2007-04-10 Thread Paul Rubin
Carsten Haese <[EMAIL PROTECTED]> writes:
> You have a point. Here is my revised solution:
> 
> assert current_player in p
> opponents = tuple(x for x in p if x is not current_player)

Still wrong on two counts.  First, assert is a no-op if optimization
is turned on.  Second, your version returns a different result from
the original if current_player occurs in p more than once.
-- 
http://mail.python.org/mailman/listinfo/python-list


RELEASED Python 2.5.1, release candidate 1

2007-04-10 Thread Anthony Baxter
On behalf of the Python development team and the Python community, 
I'm happy to announce the release of Python 2.5.1 (release 
candidate 1).

This is the first bugfix release of Python 2.5. Python 2.5 is now 
in bugfix-only mode; no new features are being added. According to 
the release notes, over 150 bugs and patches have been addressed 
since Python 2.5, including a fair number in the new AST compiler 
(an internal implementation detail of the Python interpreter).

For more information on Python 2.5.1, including download links for
various platforms, release notes, and known issues, please see:

  http://www.python.org/2.5.1/

Highlights of this new release include:

Bug fixes. According to the release notes, at least 150 have 
been fixed.

Highlights of the previous major Python release (2.5) are available
from the Python 2.5 page, at

  http://www.python.org/2.5/highlights.html

Enjoy this release,
Anthony

Anthony Baxter
[EMAIL PROTECTED]
Python Release Manager
(on behalf of the entire python-dev team)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: install wxPython

2007-04-10 Thread 7stud
On Apr 9, 2:20 pm, Marco <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a problem to install wxPython on my MacBook (Pythonversion 2.5).
> If would install the wxPython (python setup.py install), then I got  
> this error:
>
> Traceback (most recent call last):
> File "/Users/marco/Desktop/flexo1/wxpython/wxPython-src-2.8.3.0/
> wxPython/setup.py", line 49, in 
> copy_file('config.py', 'wx/build', update=1, verbose=1)
> File "/Users/marco/python//lib/python2.5/distutils/file_util.py",  
> line 119, in copy_file
> "can't copy '%s': doesn't exist or not a regular file" % src
> distutils.errors.DistutilsFileError: can't copy 'config.py': doesn't  
> exist or not a regular file
>
> Where is the problem and how could i fix it?
>
> Thx for your answers.
> marco

I just installed wxPython successfully on an imac.  My imac came with
python 2.3.5 pre-installed along with some version of wxPython--I was
able to run a hello world wxPython program by typing:

$ pythonw wxHelloWorld.py

First, I installed a "framework" build of a newer version of python(I
chose 2.4.4 since the download said it has more modules for macs).
The download was called:

python-2.4.4-macosx2006-10-18.dmg

The new python version was automatically installed in /Applications/
MacPython2.4/.  Then I downloaded the wxPython version for Macs with
python version 2.4.  It was called:

wxPython2.8-osx-unicode-2.8.3.0-universal10.4-py2.4.dmg.

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


Re: How to get IP address of client from CGI module?

2007-04-10 Thread Graham Dumpleton
On Apr 11, 12:22 pm, John Nagle <[EMAIL PROTECTED]> wrote:
>The documentation for Python's CGI module doesn't seem to say how to get
> the IP address of the client.  Don't see an obvious way to get that info
> from reading the source, either. Ideas?
>
> John Nagle

Read the CGI RFC.

  http://www.ietf.org/rfc/rfc3875

Specifically section 4.1.8.

This value should be supplied by way of variable in os.environ as are
all the CGI variables.

Graham

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


Re: Python-list Digest, Vol 43, Issue 155

2007-04-10 Thread Amit K Saha
Hi mike!
> > I've played with the win32 module's text-to-speech abilities a little.
> > You may be able to get ideas from that. Here's a link to more info:
> > http://surguy.net/articles/speechrecognition.xml
> > 
> > http://www.cs.unc.edu/~parente/tech/tr02.shtml
> > 
I forgot to mention that I am actually targeting the GNOME desktop for
my application. So the win32 solution wont work for me.

Thanks for the help anyways

> > This isn't pure Python, but it may be helpful as well:
> > http

> > ://sourceforge.net/projects/VoiceCode/
This link is a nice one!


Send instant messages to your online friends http://in.messenger.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does python have the static function member like C++

2007-04-10 Thread 人言落日是天涯,望极天涯不见家
On Apr 11, 11:19 am, "7stud" <[EMAIL PROTECTED]> wrote:
> On Apr 10, 9:08 pm, "人言落日是天涯,望极天涯不见家" <[EMAIL PROTECTED]> wrote:
>
> > I define the class like this:
> > class AAA:
> >     counter = 0
> >     def __init__(self):
> >         pass
> >     def counter_increase():
> >         AAA.counter += 1
> >         print "couter now :", AAA.counter
>
> > But how could I call the function "counter_incrrease" ?
>
> > Thanks !
>
> 1)
> class AAA:
>     counter = 0
>     def __init__(self):
>         pass
>     @staticmethod
>     def counter_increase():
>         AAA.counter += 1
>         print "couter now :", AAA.counter
>
> AAA.counter_increase()
>
> 2)
> class AAA:
>     counter = 0
>     def __init__(self):
>         pass
>     def counter_increase():
>         AAA.counter += 1
>         print "couter now :", AAA.counter
>     counter_increase = staticmethod(counter_increase)
>
> AAA.counter_increase()
>
> 3)
> class AAA:
>     counter = 0
>     def __init__(self):
>         pass
>     def counter_increase(self):
>         AAA.counter += 1
>         print "couter now :", AAA.counter
> aaa = AAA()
> AAA.counter_increase(aaa)

Many thanks for you!
I've never heard of the "staticmethod" , that's great!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Please help!!!

2007-04-10 Thread James Stroud
gslm wrote:
> On 10 Nisan, 23:16, "Paul McGuire" <[EMAIL PROTECTED]> wrote:
> 
>>On Apr 10, 2:43 pm, "gslm" <[EMAIL PROTECTED]> wrote:
>>
>>
>>In fact ı know this, but I asked some questions like this, but ı haven't get 
>>any answer.And I thought that may be it could be better to use a header like 
>>this for help.Sorry!
>>
>>
>>>Hi to all!
>>>I want to do a calendar with pictures near months.
>>>I have designed the form's view.But unfortunately, I am not be able to
>>>save this view as an image file.And so I am not be able to print this
>>>image file too.
>>>Question:
>>>How can I determine the coordinates of a button?Namely How can I use
>>>the comand ImageGrab for this purpose?
>>
>>>But only I wan to get the button's ares.Because my applicationis on
>>>this.
>>
>>>Or if it's possible, how can I print the area of this button with the
>>>components on it?
>>
>>>Thanks...
>>
>>Suggestion 1: "Please help!!!" is just about the worst newsgroup
>>subject line there is (other than those related to government
>>conspiracies or earthquake prediction).  You are unlikely to attract
>>the attention of those who really know anything - they are quite busy
>>and must husband their time carefully.  Instead, you'll get those who
>>are idly curious, to see what sort of junk is floating about Usenet.
>>
>>Suggestion 2: Consider your audience.  What the heck are you talking
>>about?!  Your post goes on about calendars and buttons and views.  In
>>fact, trying to make sense of your post, it sounds like you've done
>>something truly bizarre, like making the whole view one giant button
>>with lots of images on it, and you want to print it out when the
>>"button" is clicked.  Is this even a Python question?  Any particular
>>GUI package you are using, such as Tk, wxPython, QT, your own homebrew
>>invention?  ImageGrab?  Sounds promising, what do the docs say?
>>
>>A more thorough discussion of these 
>>suggestions:http://www.catb.org/~esr/faqs/smart-questions.html
>>
>>-- Paul- Alıntıyı gizle -
>>
>>- Alıntıyı göster -
> 
> 
> 

gslm:

Just so you know, you are annoying everyone on this list with your ill 
formed "questions"--Not just Paul who happened to be nice enough to give 
you some advice.

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


Re: Does python have the static function member like C++

2007-04-10 Thread 7stud
On Apr 10, 9:08 pm, "人言落日是天涯,望极天涯不见家" <[EMAIL PROTECTED]> wrote:
> I define the class like this:
> class AAA:
>     counter = 0
>     def __init__(self):
>         pass
>     def counter_increase():
>         AAA.counter += 1
>         print "couter now :", AAA.counter
>
> But how could I call the function "counter_incrrease" ?
>
> Thanks !

You can also do this:

class AAA:
counter = 0
def __init__(self):
pass

AAA.counter += 1
print AAA.counter
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Does python have the static function member like C++

2007-04-10 Thread 7stud
On Apr 10, 9:08 pm, "人言落日是天涯,望极天涯不见家" <[EMAIL PROTECTED]> wrote:
> I define the class like this:
> class AAA:
>     counter = 0
>     def __init__(self):
>         pass
>     def counter_increase():
>         AAA.counter += 1
>         print "couter now :", AAA.counter
>
> But how could I call the function "counter_incrrease" ?
>
> Thanks !

1)
class AAA:
counter = 0
def __init__(self):
pass
@staticmethod
def counter_increase():
AAA.counter += 1
print "couter now :", AAA.counter

AAA.counter_increase()


2)
class AAA:
counter = 0
def __init__(self):
pass
def counter_increase():
AAA.counter += 1
print "couter now :", AAA.counter
counter_increase = staticmethod(counter_increase)

AAA.counter_increase()

3)
class AAA:
counter = 0
def __init__(self):
pass
def counter_increase(self):
AAA.counter += 1
print "couter now :", AAA.counter
aaa = AAA()
AAA.counter_increase(aaa)

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

Does python have the static function member like C++

2007-04-10 Thread 人言落日是天涯,望极天涯不见家
I define the class like this:
class AAA:
counter = 0
def __init__(self):
pass
def counter_increase():
AAA.counter += 1
print "couter now :", AAA.counter

But how could I call the function "counter_incrrease" ?

Thanks !

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


How to get IP address of client from CGI module?

2007-04-10 Thread John Nagle
   The documentation for Python's CGI module doesn't seem to say how to get
the IP address of the client.  Don't see an obvious way to get that info
from reading the source, either. Ideas?

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


Re: Universal Feed Parser issue

2007-04-10 Thread Gabriel Genellina
En Tue, 10 Apr 2007 14:58:42 -0300, i3dmaster <[EMAIL PROTECTED]>  
escribió:

> I have a sample Atom feed like this:
>
> 
>  ...
>   
>   
> 
>
> After parsed by feedparser, the timezone element does not get the
> attribute "America/Mountain". Same thing on status element. This does
> not sound an expected result.  I am wondering if it should be
> considered a bug...

Usually it's a good idea to read the documentation...  
http://www.feedparser.org/docs/namespace-handling.html

-- 
Gabriel Genellina

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


Re: Please help!!!

2007-04-10 Thread Paul McGuire
On Apr 10, 3:59 pm, "gslm" <[EMAIL PROTECTED]> wrote:
> On 10 Nisan, 23:16, "Paul McGuire" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Apr 10, 2:43 pm, "gslm" <[EMAIL PROTECTED]> wrote:
>
> > In fact ý know this, but I asked some questions like this, but ý haven't 
> > get any answer.And I thought that may be it could be better to use a header 
> > like this for help.Sorry!
>
> > > Hi to all!
> > > I want to do a calendar with pictures near months.
> > > I have designed the form's view.But unfortunately, I am not be able to
> > > save this view as an image file.And so I am not be able to print this
> > > image file too.
> > > Question:
> > > How can I determine the coordinates of a button?Namely How can I use
> > > the comand ImageGrab for this purpose?
>
> > > But only I wan to get the button's ares.Because my applicationis on
> > > this.
>
> > > Or if it's possible, how can I print the area of this button with the
> > > components on it?
>
> > > Thanks...
>
> > Suggestion 1: "Please help!!!" is just about the worst newsgroup
> > subject line there is (other than those related to government
> > conspiracies or earthquake prediction).  You are unlikely to attract
> > the attention of those who really know anything - they are quite busy
> > and must husband their time carefully.  Instead, you'll get those who
> > are idly curious, to see what sort of junk is floating about Usenet.
>
> > Suggestion 2: Consider your audience.  What the heck are you talking
> > about?!  Your post goes on about calendars and buttons and views.  In
> > fact, trying to make sense of your post, it sounds like you've done
> > something truly bizarre, like making the whole view one giant button
> > with lots of images on it, and you want to print it out when the
> > "button" is clicked.  Is this even a Python question?  Any particular
> > GUI package you are using, such as Tk, wxPython, QT, your own homebrew
> > invention?  ImageGrab?  Sounds promising, what do the docs say?
>
> > A more thorough discussion of these 
> > suggestions:http://www.catb.org/~esr/faqs/smart-questions.html
>
> > -- Paul- Alýntýyý gizle -
>
> > - Alýntýyý göster -- Hide quoted text -
>
> - Show quoted text -

Just go do some homework for yourself.  Then if you still need help,
imagine the person you want to help you reading the subject and your
question - how will they know what you need help with?  how will they
recognize what software you are using, what version of the software,
what things you have tried and didn't work, and how did they fail?  If
you got a traceback, include it, plus the *actual code* that caused
it.  Then come back with a posting (and posting subject) that that
person can understand and respond to.  But don't post with "Please
help!!!" - that's like posting on a job board with the subject "Need a
job".

-- Paul

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


Re: tuples, index method, Python's design

2007-04-10 Thread Terry Reedy

"Paul Boddie" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| always enlightening/entertaining to see the rationales given for the
| rejection of this and other features, in contrast to things like "y if
| x else z" which just seem to mysteriously acquire momentum and then
| power their way in regardless.

No mystery.  It was Guido's initial proposal and he never changed his mind. 



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


Re: tuples, index method, Python's design

2007-04-10 Thread Terry Reedy

"BJörn Lindqvist" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
On 4/10/07, Steve Holden <[EMAIL PROTECTED]> wrote:
> One might perversely allow extension to lists and tuples to allow
>
>[3, 4] in [1, 2, 3, 4, 5, 6]
>
> to succeed, but that's forcing the use case beyond normal limits.

I'd love to have that! There are at least one million use cases for
finding a sequence in a sequence and implementing it yourself is
non-trivial. Plus then both list and tuple's index methods would work
*exactly* like string's. It would be easier to document and more
useful. A big win.

===
It would be ambiguous: [3,4] in [[1,2], [3,4], [5,6]] is True now.

Strings are special in that s[i] can only be a (sub)string of length 1.
'b' in 'abc' is True.  This makes looking for longer substrings easy.

However, [2] in [1,2,3] is False.  IE, list[i] is not normally a list.  So 
looking for sublists is different from looking for items.

Terry Jan Reedy



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

__file__

2007-04-10 Thread 7stud
Hi,

I'm having trouble understanding what the definition of __file__ is.
With this program:

--
#data.py:

def show():
print __file__

if __name__ == "__main__":
show()
---

if I run data.py with the prompt pointing to the directory that
contains data.py, then __file__ produces a filename:

data.py

If I run data.py with the prompt pointing to a different directory,
then file produces what I entered on the command line, e.g.:

./2testing/dir1/data.py


If I import the data module into another python program, e.g.:

---
#test1.py:

from data import show
show()
--

and test1.py is in the same directory as data.py, __file__ produces an
absolute path to the data module:

/Users/me/2testing/dir1/data.pyc

If test1.py is in a different directory than data.py, __file__
produces the path used in sys.path.append(), e.g.:


import sys
sys.path.append("./2testing/dir1")

import data
data.show()
---output:--
./2testing/dir1/data.pyc

or==

import sys
sys.path.append("/Users/me/2testing/dir1")

import data
data.show()
---output:---
/Users/me/2testing/dir1/data.pyc


And some modules have __file__ in their __dict__ and some don't:

---
import sys, pprint, data

pprint.pprint(data.__dict__)
print
print "***"
print
pprint.pprint(sys.__dict__)

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


Re: Check for keypress on Linux xterm ?

2007-04-10 Thread hlubenow
I wrote:

> Hello,
> 
> I'd like to check, if a single key is pressed on a Linux xterm.
> My problem is, I don't want my program to wait for the keypress.
> I just want to check, if a key is currently pressed and if not, I'd like
> to continue with my program (like "INKEY$" in some BASIC-dialects).

Ok, here's the code I use now. Thanks to Grant Edwards for pointing me into
the right direction:

--

#!/usr/bin/env python

import os
import sys
import tty
import termios 
import fcntl
import time

fd = sys.stdin.fileno()

oldterm = termios.tcgetattr(fd)
oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)

tty.setcbreak(sys.stdin.fileno())
newattr = termios.tcgetattr(fd)
newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO


def oldTerminalSettings():
termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)


def newTerminalSettings():
termios.tcsetattr(fd, termios.TCSANOW, newattr)
fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)


def checkKey():

try:
c = sys.stdin.read(1)
return ord(c)

except IOError:
return 0

print
print "Ok, in 3 seconds, I'll check 100 times, which key you press."
print

# Initializing: Things like "raw_input()" won't work after that:
newTerminalSettings()

time.sleep(3)

for i in range(100):
a = "Key pressed: "

key = checkKey()

if key:
a += chr(key)
a += "."
else:
a += "Nothing pressed."

print a

# Somehow it doesn't work, if this loop runs too fast, so:
time.sleep(0.05)

oldTerminalSettings()

print
print "Terminal-settings restored."
print
raw_input("raw_input() works again. So please press Return: ")
print

--

Thanks again

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


Re: problem with UDP broadcast on Windows XP

2007-04-10 Thread Irmen de Jong
Paul McGuire wrote:

> I would investigate Windows security settings as a likely culprit.  My
> guess is that you are running WinXP SP2 with the default security
> policies, which are likely to prohibit such promiscuous behavior.
> 
> Here's a URL that may shed some light, it seems surprisingly
> instructive for MS support: http://support.microsoft.com/kb/842242 -
> Some programs seem to stop working after you install Windows XP
> Service Pack 2

Paul, that was terrific.
Seems that the windows firewall blocks the broadcast stuff for services.
After I disabled the thing, my service works again as intended!
Have to add this to the notes of my software ;)

Wonderful that my windows specific problem got solved in this Python group.

Thanks again for all the ideas everyone for my silly offtopic problem.

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


Re: XML-RPC SSL and client side certs?

2007-04-10 Thread Jeff McNeil
I apologize for not giving you a Python specific answer, but for the
XMLRPC services I've deployed, I front them with Apache and proxy back
to localhost:8080.

I do all of the encryption and authentication from within the Apache
proper and rely on mod_proxy to forward validated requests on.  I've
settled on basic authentication, but I see no reason why you couldn't
take advantage of mod_ssl.

Thanks, hope that helps. Just another option, really.

Jeff




On 10 Apr 2007 14:43:40 -0700, Eli Criffield <[EMAIL PROTECTED]> wrote:
>
> Does anyone have an example setup of a XML-RPC sever using client side
> certs for authentication?
>
> And instead of having a list of certs allowed to connect, I'd like to
> allow any cert signed by my CA.
>
> It doesn't seem like it would be to hard to do and I'll probably spend
> some time setting it up here soon, but would be interested if anyone
> else has already written a solution like this or has used one (in
> python of course).
>
> Eli Criffield
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Why NOT only one class per file?

2007-04-10 Thread Delaney, Timothy (Tim)
Bruno Desthuilliers wrote:

> I came to this conclusion from my own experience, and it seems that
> quite a few other programmers (most of them either better and/or more
> experimented than me) came to the same conclusion. But feel free to

Been more experimented on, or have experimented more on others?

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


RE: tuples, index method, Python's design

2007-04-10 Thread Delaney, Timothy (Tim)
Carsten Haese wrote:

> assert current_player in p
> opponents = tuple(x for x in p if x is not current_player)

That would perform better as:

opponents = tuple(x for x in p if x is not current_player)
assert opponents

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


Re: About Eggs

2007-04-10 Thread Mark Elston
* Rob Wolfe wrote (on 4/10/2007 1:38 PM):
> Mark Elston <[EMAIL PROTECTED]> writes:
> 
>> This is probably a *really* stupid question but...
>> I have looked at all the documentation I have for 2.4.3
>> and all the docs I can download for 2.5 and I simply cannot
>> find anything, anywhere that documents what egg files are.
>>
>> I have read posts referring to them and have been able to
>> deduce that they are some form of zip file for the distribution
>> of modules but beyond that I cannot find *any* docs for them
>> anywhere.
> 
> Start here:
> http://peak.telecommunity.com/DevCenter/setuptools
> 

Thanks to Rob and Mike for their answers.  I will bookmark these
pages immediately.

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


Re: About Trolltech QT OpenSource license.

2007-04-10 Thread Damjan
> @ Kevin and Jarek :
> thanks for the enlightening of that GPL thing. So, if i understand, i
> create my Python software using Qt as my GUI, i earn the money for it
> with the obligation to release my source code and somewhere in my
> files i explicilty write that this software is under the GPL lisence,
> is that correct ?? And i am legal all the way out ??

This is correct... but you should also understand the GPL license aswell.

> So why these people at Trolltech have the word "Commercial" at their
> mouth all the time ?? I can understand of course that money is all
> about but becauce they released Qt under GPL they simply cannot
> prevent anyone from gaining money using it.

That is a mistake, the oposite of libre software is non-libre or
proprietary.


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


Re: About Trolltech QT OpenSource license.

2007-04-10 Thread Kevin Walzer
king kikapu wrote:

> 
> 
> @ Kevin and Jarek :
> thanks for the enlightening of that GPL thing. So, if i understand, i
> create my Python software using Qt as my GUI, i earn the money for it
> with the obligation to release my source code and somewhere in my
> files i explicilty write that this software is under the GPL lisence,
> is that correct ?? And i am legal all the way out ??

That's correct, as far as I know. (IANAL)
> 
> So why these people at Trolltech have the word "Commercial" at their
> mouth all the time ?? I can understand of course that money is all
> about but becauce they released Qt under GPL they simply cannot
> prevent anyone from gaining money using it.
> 

In this case, "commercial" == "proprietary" == "closed-source." If your 
source is released in complicance with the GPL, you don't have to buy a 
license from Trolltech.

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: grabbing Pictures from the web

2007-04-10 Thread Josh Bloom

I don't have any experience with TK so I can't comment on that but for
getting pics from the web, you will need to do the following:
1) Work with the flickr API or flickr feeds to get the url for each picture
that you want to work with.
2) Either download the image to disk or read it into memory to work with.

Here's some sample code to open a url and save it to disk. (This is
expecting that the url points to a .jpg)

import urllib
picture = urllib.urlopen(pathToTheImageThatYouWant).readlines()
newPic = open('YourNewFile.jpg', 'wb') #Use wb as you're writing a binary
file.
newPic.writelines(picture)
newPic.close()

-Josh


On 4/10/07, Juan Vazquez < [EMAIL PROTECTED]> wrote:


I am new to python (2 weeks old)  and I would like to write a script that
grabs pictures from the web (specifically flickr) and put them on a Tk
Canvas for a slide show/editing program. my 2 questions are
1) How do I grab a picture from the web
2) is the use of the Tk canvas for working with the picture the best
approach?

Any help or references to resources that point me in the right direction
would be greatly appreciated. Thanks in Advance.
-Juan

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

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

Re: Why NOT only one class per file?

2007-04-10 Thread Bruno Desthuilliers
Sherm Pendley a écrit :
> Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
> 
> 
>>Sherm Pendley a écrit :
>>
>>>Bruno Desthuilliers <[EMAIL PROTECTED]> writes:
>>>
>>>
>>>
Sherm Pendley a écrit :

In my book, it's huge classes and methods that are usually a smell of
a design problem.
>>>
>>>
>>>Obviously we're reading different books.
>>
>>Obviously. But I didn't gain this knowledge from books.
> 
> 
> Obviously, you have no sense of humor.

Obviously, we don't have the same sense of humor.

>>FWIW, I'd be interested if you'd let us know about any book pretending
>>that monster classes are good design !-)
>  
> You've already decided that "monster classes" are bad design,

I came to this conclusion from my own experience, and it seems that 
quite a few other programmers (most of them either better and/or more 
experimented than me) came to the same conclusion. But feel free to 
believe it's an a priori if that makes you feel better.

> and that
> anything conflicting with your belief is mere pretense. Why should I waste
> my time debating when you've already made up your mind?

Then don't. But I'd still be interested if you could let us know about 
any book advocating monster classes as good design.

>>>But that's OK - I'm not on a crusade to convince everyone to work my way.
>>>If "one class per file" doesn't work well for you, don't write that way.
>>>All I'm saying is, what works well for you isn't necessarily what works
>>>well for everyone.
>>
>>It seems that it works well for almost anyone having some real-world
>>experience with languages like Python.
>  
> I didn't say otherwise.

So let's rephrase your previous assertion :
"what works well for almost anyone having some real world experience 
with languages like Python isn't necessarily what works well for 
everyone" (implied : "... when using a Python-like language" - this 
seemed obvious but it may be better to state it more explicitly, just in 
case...).

> You're arguing a false dichotomy;

Nope, just stating a fact - from which you may or not derive some 
conclusions.

> the fact that one
> approach works well does not prove that others won't work equally well.

The fact that a in a given context a significant majority of 
experimented users usually favors one approach over the other might be 
taken as an indication that there might be some reason for this.

About "proofs", I'm afraid that "proving" things learned from experience 
can be sometimes difficult - or at least above my own skills, specially 
in a language I'm not very fluent with. But I think I did tried (perhaps 
unsuccessfully, but that's another problem) to back my POV, instead of 
just resorting to rethoric like you're doing here.

> I'm
> not saying that your preferred style is wrong; I'm just saying that it's a
> matter of preference, not a universal truth.

If it was only *my* "preferred style", I wouldn't even argue. Now I'm 
not presenting it as a "universal truth", but as the result of 
experience (and not only my own) with a given class of languages.

Asserting that one should *always* only put one class per file is just 
as non-sensical as asserting that one should *always* put several 
classes in a same file. Not only because Python doesn't requires you to 
use classes, but mostly because it's arbitrary and dogmatic. You seem to 
have (dis)missed the point where I said that I *almost* never had a 
single class in a file - which implies that I *sometimes* do this - when 
it makes sens from either a practical or logical POV.

FWIW, I would certainly not try to apply this "preferred style" when 
writing GUIs in C++. You see, the fact that some idiom (style, whatever) 
works well with a given (class of) language(s) doesn't mean it's the 
more effective in some other context. Here again, it seems that you 
(dis)missed the point where I asked you if your thousands-lines-long 
classes were written in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples, index method, Python's design

2007-04-10 Thread BJörn Lindqvist
> > while not game_has_ended:
> >   for current_player in p:
> > player_does_something(current_player)
> >
>
> I'm curious why someone would even consider using a tuple in this case
> regardless. I think that much of the desire for tuple.index is because
> people use a tuple where they could have a list, but either a) some
> vestige of B&D language programming comes out and they want to make

Maybe someone had to much alcohol when they were coding? Maybe they
don't know better? Maybe they thought that an index method on a
sequence made sense? Who are you to spoil their fun? Could it be that
YOU are the B&D person?

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: menu drop down icons (inactive) look horrible in Windows Classic Theme

2007-04-10 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, ilikewine wrote:

> The menu drop down icons (only the gray inactive icons) look horrible
> in Windows Classic Theme. Once they are active and have color, they
> look fine. If we switch to XP theme, they look just fine. Anyone else
> run into this problem with python rewriting "shotty" inactive icons in
> the Windows Classic Theme?
> 
> ANY help appreciated.

What the heck are you talking about?  Tkinter?

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


Re: About Trolltech QT OpenSource license.

2007-04-10 Thread king kikapu

Ο/Η Peter Decker έγραψε:
> There is another alternative: Dabo, which wraps the wxPython toolkit.
> It has a GUI designer, although not as polished as the Qt Designer.
> Check out some of their screencasts to see their tools in action. You
> can find them at http://dabodev.com/documentation

I am aware but i prefer to use PythonCard if i choose wxPython over
Qt. I think Dadbo has a lot of work to be done, it is surely very
promising, thanks!


@ Kevin and Jarek :
thanks for the enlightening of that GPL thing. So, if i understand, i
create my Python software using Qt as my GUI, i earn the money for it
with the obligation to release my source code and somewhere in my
files i explicilty write that this software is under the GPL lisence,
is that correct ?? And i am legal all the way out ??

So why these people at Trolltech have the word "Commercial" at their
mouth all the time ?? I can understand of course that money is all
about but becauce they released Qt under GPL they simply cannot
prevent anyone from gaining money using it.

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

menu drop down icons (inactive) look horrible in Windows Classic Theme

2007-04-10 Thread ilikewine
The menu drop down icons (only the gray inactive icons) look horrible
in Windows Classic Theme. Once they are active and have color, they
look fine. If we switch to XP theme, they look just fine. Anyone else
run into this problem with python rewriting "shotty" inactive icons in
the Windows Classic Theme?

ANY help appreciated.

Best,

FT

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


XML-RPC SSL and client side certs?

2007-04-10 Thread Eli Criffield

Does anyone have an example setup of a XML-RPC sever using client side
certs for authentication?

And instead of having a list of certs allowed to connect, I'd like to
allow any cert signed by my CA.

It doesn't seem like it would be to hard to do and I'll probably spend
some time setting it up here soon, but would be interested if anyone
else has already written a solution like this or has used one (in
python of course).

Eli Criffield

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


Re: Parsing log in SQL DB to change IPs to hostnames

2007-04-10 Thread KDawg44
On Apr 10, 2:47 pm, Steve Holden <[EMAIL PROTECTED]> wrote:
> KDawg44 wrote:
> > On Apr 10, 11:11 am, "Kushal Kumaran" <[EMAIL PROTECTED]>
> > wrote:
> >> On Apr 10, 8:37 pm, "KDawg44" <[EMAIL PROTECTED]> wrote:
>
> >>> Hi,
> >>> I am brand new to Python.  In learning anything, I find it useful to
> >>> actually try to write a useful program to try to tackle an actual
> >>> problem.
> >>> I have a syslog server and I would like to parse the syslog messages
> >>> and try to change any ips to resolved hostnames.  Unfortunately, I am
> >>> not getting any matches on my regular expression.
> >>> A message will look something like this:
> >>>  Apr 10 2007 00:30:58 DEVICE : %DEVICEINFO: 1.1.1.1 Accessed URL
> >>> 10.10.10.10:/folder/folder/page.html
> >>> I would like to change the message to have the hostnames, or even
> >>> better actually, have it appear as hostname-ip address.  So a changed
> >>> message would look like:
> >>>  Apr 10 2007 00:30:58 DEVICE : %DEVICEINFO: pcname-1.1.1.1 Accessed
> >>> URLwww.asite.com-10.10.10.10:/folder/folder/page.html
> >>> or some equivalent.
> >>> Here is what i have so far.  Please be kind as it is my first python
> >>> program :)
> >>> #! /usr/bin/python
> >>> import socket
> >>> import re
> >>> import string
> >>> import MySQLdb
> >>> ipRegExC = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
> >>> ipRegEx = re.compile(ipRegExC)
> >>> try:
> >>> conn = MySQLdb.connect(host="REMOVED", user="REMOVED",
> >>> passwd="REMOVED", db="REMOVED")
> >>> except MySQLdb.Error, e:
> >>> print "Error connecting to the database: %d - %s " %
> >>> (e.args[0], e.args[1])
> >>> sys.exit(1)
> >>> cursor = conn.cursor()
> >>> cursor.execute("SELECT msg, seq FROM REMOVED WHERE seq = 507702")
> >>> # one specific message so that it doesn't parse the whole DB during
> >>> testing...
> >>> while(1):
> >>> row = cursor.fetchone()
> >>> if row == None:
> >>> break
> >>> if ipRegEx.match(row[0]):
> >>> 
> >>> 
> >> See the documentation of the re module for the difference between
> >> matching and searching.
>
> >> --
> >> Kushal
>
> > Thank you very much.  I think I have it figured out, except for an
> > error on the SQL statement:
>
> > [- BEGIN ERROR ---]
> > Traceback (most recent call last):
> >   File "changeLogs.py", line 47, in ?
> > cursor.execute("""UPDATE logs SET msg = %s WHERE seq = %i""",
> > (newMsg,seqNum))
> >   File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
> > 148, in execute
> > query = query % db.literal(args)
> > TypeError: int argument required
> > [- END ERROR ---]
>
> > Here is my code
>
> > [- BEGIN CODE ---]
> > #! /usr/bin/python
>
> > import socket
> > import sys
> > import re
> > import string
> > import MySQLdb
>
> > def resolveHost(ipAdds):
> > ipDict = {}
> > for ips in ipAdds:
> > try:
> > ipDict[ips] = socket.gethostbyaddr(ips)[0]
> > except:
> > ipDict[ips] = "Cannot resolve"
> > return ipDict
>
> > ipRegExC = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
> > ipRegEx = re.compile(ipRegExC)
>
> > try:
> > conn = MySQLdb.connect(host="REMOVED", user="REMOVED",
> > passwd="REMOVED", db="REMOVED")
>
> > except MySQLdb.Error, e:
> > print "Error connecting to the database: %d - %s " %
> > (e.args[0], e.args[1])
> > sys.exit(1)
>
> > cursor = conn.cursor()
> > cursor.execute("SELECT msg, seq FROM `logs` WHERE seq = 507702")
> > while(1):
> > row = cursor.fetchone()
> > ipAddresses = []
> > resolvedDict = {}
> > if row == None:
> > break
> > if ipRegEx.search(row[0]):
> > seqNum = row[1]
> > ipAddresses = ipRegEx.findall(row[0])
> > resolvedDict = resolveHost(ipAddresses)
> > newMsg = row[0]
> > for ip in resolvedDict.keys():
> > newMsg = newMsg.replace(ip,ip + "-" +
> > resolvedDict[ip])
> > cursor.execute("""UPDATE REMOVED SET msg = %s WHERE
> > seq = %i""", (newMsg,seqNum))
>
> > [- END CODE ---]
>
> > Thanks again!
>
> Since the source line that the traceback complains about doesn't appear
> in the quoted code it's difficult to know what's going wrong. I'd hazard
> a guess that you have a string in seqNum instead of an integer message
> number (in which case try using int(seqNum) instead).
>
> Otherwise show us the real code, not the one after you modified it to
> try and make it work, amd we might be able to help more ;-)
>
> regards
>   Steve
> --
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC/Ltd  http://www.holdenweb.com
> Skype: holdenwebhttp://del.icio.us/steve.holden
> Recent Ramblings  http://holdenweb.blogspot.com

hmmm...  I tried seqNum = int(seqNum[i]) to make seqNum an integer.
That is the real code with th

Re: block scope?

2007-04-10 Thread Bruno Desthuilliers
Paul Rubin a écrit :
> [EMAIL PROTECTED] (Alex Martelli) writes:
> 
>locals['x']=5
>>
>>Traceback (most recent call last):
>>  File "", line 1, in 
>>TypeError: 'builtin_function_or_method' object does not support item
>>assignment
> 
> 
> 
> Whoops, yeah, meant "locals()['x'] = 5".
> 
> 
>>I think that ideally there should be a runtime error when assigning an
>>item of locals() with a key that's not a local variable name (possibly
>>excepting functions containing exec, which are kind of screwy anyway).
> 
> 
> I have no opinion of this, locals() has always seemed like a crazy
> part of the language to me and I never use it.  I'd be happy to see it
> gone since it makes compiling a lot easier.

I personally find locals() handy in few cases, like

def output():
   foo = 42
   bar = baaz()
   quux = blah(foo, bar)
   return "the %(bar)s is %(foo)d and the %(quux)s shines" % locals()

or:

class Foo(object):
   @apply
   def bar():
 def fget(self):
return self._quux / 42
 def fset(self, value):
self._quux = value * 42
 return property(**locals())


I'd be very unhappy to see it gone...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Custom Python Runtime

2007-04-10 Thread Martin v. Löwis
Jack schrieb:
> Thanks for all the replies. It would be great to have all customization
> related information on one doc page.

Please put it into a wiki page, at wiki.python.org

> 1. One Windows, it's possible to zip all files in a Python24.zip. I'm not
> very clear if it's used in the stardard distribution. What can,
> and what can not be put into this file? I suppose zip file will help
> reduce the distribution size.

I would have to use the source again: if you set PYTHONHOME, you
can put the entire library into the zip file. If you don't, I
think os.py really needs to exist on disk (if so, that might be
a bug, as the intention is that you can put all .py/.pyc into the
zip file).

> 2. I remember trying the compiler option to strip doc strings didn't
> help but maybe I didn't do it right. I had to write some code to compile
> selected py files. Is there a way to compile a stripped Python with
> compile time options?

Sure: -OO.

> 3. Some files go to the Windows\system32 directory, including some win32all
> files. Can they be in the current directory as python.exe?

If you don't need COM, or other dynamic embedding of pythonxy.dll, no.

> 4. Are the registry entries necessary?

No.

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


Re: Please help!!!

2007-04-10 Thread gslm
On 10 Nisan, 23:16, "Paul McGuire" <[EMAIL PROTECTED]> wrote:
> On Apr 10, 2:43 pm, "gslm" <[EMAIL PROTECTED]> wrote:
>
>
> In fact ı know this, but I asked some questions like this, but ı haven't get 
> any answer.And I thought that may be it could be better to use a header like 
> this for help.Sorry!
>
> > Hi to all!
> > I want to do a calendar with pictures near months.
> > I have designed the form's view.But unfortunately, I am not be able to
> > save this view as an image file.And so I am not be able to print this
> > image file too.
> > Question:
> > How can I determine the coordinates of a button?Namely How can I use
> > the comand ImageGrab for this purpose?
>
> > But only I wan to get the button's ares.Because my applicationis on
> > this.
>
> > Or if it's possible, how can I print the area of this button with the
> > components on it?
>
> > Thanks...
>
> Suggestion 1: "Please help!!!" is just about the worst newsgroup
> subject line there is (other than those related to government
> conspiracies or earthquake prediction).  You are unlikely to attract
> the attention of those who really know anything - they are quite busy
> and must husband their time carefully.  Instead, you'll get those who
> are idly curious, to see what sort of junk is floating about Usenet.
>
> Suggestion 2: Consider your audience.  What the heck are you talking
> about?!  Your post goes on about calendars and buttons and views.  In
> fact, trying to make sense of your post, it sounds like you've done
> something truly bizarre, like making the whole view one giant button
> with lots of images on it, and you want to print it out when the
> "button" is clicked.  Is this even a Python question?  Any particular
> GUI package you are using, such as Tk, wxPython, QT, your own homebrew
> invention?  ImageGrab?  Sounds promising, what do the docs say?
>
> A more thorough discussion of these 
> suggestions:http://www.catb.org/~esr/faqs/smart-questions.html
>
> -- Paul- Alıntıyı gizle -
>
> - Alıntıyı göster -


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


Re: About Trolltech QT OpenSource license.

2007-04-10 Thread Jarek Zgoda
king kikapu napisał(a):

>> This is a bullsh*t. Qt is free (as in "free speech") on GPL. Nothing
>> stops you from using it in any commercial project if only it fits the
>> licensing terms (i.o.w. it's free software). This specially applies to
>> inhouse development, as in such case there's no "distribution".
> 
> Hmmm...how a commercial software (that means i get paid for give it)
> it will be consider "free software" ?
> I ask because i surely do not understand correctly the GPL lisence and
> all that stuff.

The GPL is about distribution of software. If you provide your program
with sources and allow redistribution under provisions of GPL, it will
be free (as you provide some "freedoms" listed in the license
statement), even if you earn cash for it. It's "free as in freedom" (or
free speech), not as in "free beer". Please, contact your local FSF,
CreativeCommons or ISOC lawyer to get an advice if you feel you need a
lawyer's assistance. For the brief explanation of the problem, see
http://www.gnu.org/philosophy/selling.html. This document should cover
most cases. ;)

>> Plus, this (sales)person forgot to state clearly, that GPL covers only
>> distribution, not the cost of software. If you manage to get some hot
>> cash for selling sources of your GPL-ed program, the license would not
>> try to stop you from doing that. ;)
> 
> As i said, i do not fully understand all this license stuff. All i
> want to ask is, i can make GPL software and gain money from this ? And
> if that so, then why they "force" you to buy the commercial lisence in
> such case ?

They cann't and the don't. If you obey GPL rules, you're right. The
(sales)person you had a conversation with is, well, just a salesperson.
Trolltech makes money from selling commercial licenses, so these persons
will always try to persuade you to buying a license or two, "just in
case". ;)

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About Trolltech QT OpenSource license.

2007-04-10 Thread Peter Decker
On 10 Apr 2007 12:29:36 -0700, king kikapu <[EMAIL PROTECTED]> wrote:
> Hi to all,
>
> i am coming from the Microsoft (.net) world and at the quest of
> finding the right GUI toolkit that i can use from Python, i have two
> obvious choices to choose from: wxPython and Qt.
>
> Both are looking very good. Qt has Qt designer, a tool that really
> reminds me of the forms designers that we have in VS.Net.The
> productivity someone can gain from tools like these can be really
> astonished.

There is another alternative: Dabo, which wraps the wxPython toolkit.
It has a GUI designer, although not as polished as the Qt Designer.
Check out some of their screencasts to see their tools in action. You
can find them at http://dabodev.com/documentation

-- 

# p.d.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: About Trolltech QT OpenSource license.

2007-04-10 Thread Kevin Walzer
king kikapu wrote:

> As i said, i do not fully understand all this license stuff. All i
> want to ask is, i can make GPL software and gain money from this ?

Yes. Nothing in the GPL prevents you from developing and marketing an 
application for as high a price as you can get from it.

HOWEVER:

you will have to distribute the source code to your application to 
anyone who purchases a binary from you.

AND:

they will be permitted under the GPL to redistribute your application, 
source code and all. The GPL would allow them to buy your application 
from you and then redistribute it at no cost to others.

Most commercial shrink-wrap software depends on enforcing restrictions 
on end users to compel a revenue stream: withholding some of the 
application's functionality prior to payment, hiding the locking 
algorithm inside obfuscated source code, and prohibiting modification 
and redistribution of the application and/or its code. If this is your 
business model, then the GPL is probably not for you.

If you use the GPL, you would have to make your locking alogrithim as 
plain as day; someone out there would likely have the knowledge to patch 
your software to work without the locking algorithm, assuming they 
obtained the binary and source code legally (either by purchasing it 
from you or obtaining it from someone who purchased it from you); and 
they would be legally free to redistribute the patched application, with 
or without cost.

Of course, there's no guarantee this will happen; such patching also 
happens with closed-source software. But many commercial developers look 
at the GPL and decide that this is a risk they do not want to take.

--Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with getting an option value

2007-04-10 Thread Nanjundi
On Apr 10, 10:23 am, "Lucas Malor" <[EMAIL PROTECTED]> wrote:
> Peter Otten wrote:
> > Lucas Malor wrote:
>
> >> The problem is options is an instance, so options."delete", for example,
> >> is wrong; I should pass options.delete . How can I do?
>
> > Use getattr():
>
> Thank you. Do you know also if I can do a similar operation with functions? I 
> want to select with a string a certain get() function of ConfigParser:
>
> if   type == "int" :
> funcname = "getint"
> elif type == "bool" :
> funcname = "getboolean"
> etc.
>
 > How can I invoke the funcion with its name in a string?

Use exec to assign to a variable.

>>> def testPrint(msg):
...print 'Msg: %s' % msg
...
>>> sfunc = "testPrint"
>>> exec("f = %s" % sfunc)
>>> f('Hello Python')
Msg: Hello Python

& use 'f = self.%s' % name for class methods.

Hope its not a bad practice!

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


Re: pluie documentation in english

2007-04-10 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> On Apr 10, 3:14 am, "Méta-MCI" <[EMAIL PROTECTED]>
> wrote:
> 
>>Bonjour !
>>
>>Avec Internet-Explorer 6 :
>>
>>Dans Internet-explorer, par le menu, faire :   Outils  +  Options_internet
>>Aller sur le dernier onglet (Avancé), et cocher : autoriser le contenu actif
>>
>>(désolé pour le français, mais mon anglais est vraiment trop mauvais).
>>
>>Et, merci pour l'info, ça m'a permis d'ajouter un item à la F.A.Q.

With IE6:

In IE6, use the tools/internet options menu, go to the last tab 
('Advanced'), and check "allow active content" [1].

(pardon my french, but my english is way too bad)

Oh, and thanks for the feedback, I added an entry for this in the FAQ.

HTH

[1] translator's note : I don't have IE6 (I don't use windows), so 
please someone correct me if that's not the correct label here.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NLTK, Random Sentence Generators?

2007-04-10 Thread James Stroud
Passer By wrote:
> James Stroud <[EMAIL PROTECTED]> writes:
> 
> 
>>Passer By wrote:
>>
>>
>>>Has any created or not of examples of random sentence generators
>>>using n-gram models (or other models might be interesting).  I
>>>know of one example from a course at MIT, but besides that
>>>nothing.  Any help would be great.
>>>
>>
>>Best is to just cull text from your spam folder as these are often
>>generated by similar means--but somehow I think you knew that.
>>
> 
> 
> Emotive on Usenet? Thats original.
> 
> 
Anonimity on usenet? That's suspiscious.

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


Re: problem with UDP broadcast on Windows XP

2007-04-10 Thread Paul McGuire
On Apr 10, 3:30 pm, Irmen de Jong <[EMAIL PROTECTED]> wrote:
> > Hendrik van Rooyen wrote:
> >> I am not sure if this is at all relevant - but I seem to recall seeing
> >> something once that had a list of socket numbers, splitting them
> >> between UDP & TCP - can the socket actually rx UDP?
> Yeah, as I wrote: when I'm sending UDP packets to the port directly
>
> on the server's IP address, it responds just fine.
>
> It's just the broadcast packets that don't seem to arrive.
> (sent to ('',9090) )
>
> Steve Holden wrote:
> > It's most likely, I suspect without knowing to much about it, that the
> > service is stalling because of a failure to "pump" Windows messages.
> > Irmen, are you taking any action in your service to ignore Windows
> > messages that your service process receives?
>
> Hm, seeing that it processes TCP and "directed" UDP packets just fine,
> there shouldn't be a problem here?
>
> No I'm not knowingly doing stuff that ignores windows messages...
>
> (I could maybe put up the code if someone wants to take a look but
> not right now. Need to rip a fair deal out - there's a lot of
> other stuff in there that's not relevant to the problem.)
>
> --Irmen

I would investigate Windows security settings as a likely culprit.  My
guess is that you are running WinXP SP2 with the default security
policies, which are likely to prohibit such promiscuous behavior.

Here's a URL that may shed some light, it seems surprisingly
instructive for MS support: http://support.microsoft.com/kb/842242 -
Some programs seem to stop working after you install Windows XP
Service Pack 2

-- Paul


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


Re: About Eggs

2007-04-10 Thread Rob Wolfe
Mark Elston <[EMAIL PROTECTED]> writes:

> This is probably a *really* stupid question but...
> I have looked at all the documentation I have for 2.4.3
> and all the docs I can download for 2.5 and I simply cannot
> find anything, anywhere that documents what egg files are.
>
> I have read posts referring to them and have been able to
> deduce that they are some form of zip file for the distribution
> of modules but beyond that I cannot find *any* docs for them
> anywhere.

Start here:
http://peak.telecommunity.com/DevCenter/setuptools

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


Re: About Eggs

2007-04-10 Thread kyosohma
On Apr 10, 3:30 pm, Mark Elston <[EMAIL PROTECTED]> wrote:
> This is probably a *really* stupid question but...
> I have looked at all the documentation I have for 2.4.3
> and all the docs I can download for 2.5 and I simply cannot
> find anything, anywhere that documents what egg files are.
>
> I have read posts referring to them and have been able to
> deduce that they are some form of zip file for the distribution
> of modules but beyond that I cannot find *any* docs for them
> anywhere.
>
> Where are they documented and how do I take advantage of them?
>
> Mark

You need to go here:

http://peak.telecommunity.com/DevCenter/PythonEggs
http://peak.telecommunity.com/DevCenter/EggFormats

Enjoy!

Mike

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


Re: Can I get the exit code "n" passed to sys.exit(n) ?

2007-04-10 Thread Gabriel Genellina
En Tue, 10 Apr 2007 15:15:57 -0300, Yujo <[EMAIL PROTECTED]>  
escribió:

> In the following code of the finish() function, is there any way to
> get the exit code passed to sys.exit() ?
>
> def finish() :
>RETURN_CODE_FROM_SYS_EXIT = # how can I get it ?
>if RETURN_CODE_FROM_SYS_EXIT = 0 :
>  # process ended OK
>else :
>  # process ended with some error
>  # execute something
>
> atexit.register(finish)
>
> # this is my main program
>
> ERR_CODE=3
> sys.exit(ERR_CODE)

Uhm, I think you can't, unfortunately (at least on 2.4; I don't have the  
2.5 sources at hand).
But you can instead wrap your main function with a try/except SystemExit:

def main():
   return 3

try:
   sys.exit(main())
except SystemExit, exitcode:
   finish(exitcode)

-- 
Gabriel Genellina

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


Re: [offtopic?] problem with UDP broadcast on Windows XP

2007-04-10 Thread Irmen de Jong
> Hendrik van Rooyen wrote:
>> I am not sure if this is at all relevant - but I seem to recall seeing
>> something once that had a list of socket numbers, splitting them 
>> between UDP & TCP - can the socket actually rx UDP?

Yeah, as I wrote: when I'm sending UDP packets to the port directly
on the server's IP address, it responds just fine.

It's just the broadcast packets that don't seem to arrive.
(sent to ('',9090) )

Steve Holden wrote:
> It's most likely, I suspect without knowing to much about it, that the 
> service is stalling because of a failure to "pump" Windows messages. 
> Irmen, are you taking any action in your service to ignore Windows 
> messages that your service process receives?

Hm, seeing that it processes TCP and "directed" UDP packets just fine,
there shouldn't be a problem here?

No I'm not knowingly doing stuff that ignores windows messages...


(I could maybe put up the code if someone wants to take a look but
not right now. Need to rip a fair deal out - there's a lot of
other stuff in there that's not relevant to the problem.)

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


Re: About Trolltech QT OpenSource license.

2007-04-10 Thread king kikapu

Ο/Η Jarek Zgoda έγραψε:
> king kikapu napisa³(a):
>
> This is a bullsh*t. Qt is free (as in "free speech") on GPL. Nothing
> stops you from using it in any commercial project if only it fits the
> licensing terms (i.o.w. it's free software). This specially applies to
> inhouse development, as in such case there's no "distribution".

Hmmm...how a commercial software (that means i get paid for give it)
it will be consider "free software" ?
I ask because i surely do not understand correctly the GPL lisence and
all that stuff.

> Hey, there's no such statement here. Where did you get this "must buy
> the commercial lisence"?

Good point! I got it because at the last portion of my email, i asked
for it. I asked them that:
"And in  the case i want to build something that i want to later sell
(as an individual)..."

so i got it back.


> Plus, this (sales)person forgot to state clearly, that GPL covers only
> distribution, not the cost of software. If you manage to get some hot
> cash for selling sources of your GPL-ed program, the license would not
> try to stop you from doing that. ;)

As i said, i do not fully understand all this license stuff. All i
want to ask is, i can make GPL software and gain money from this ? And
if that so, then why they "force" you to buy the commercial lisence in
such case ?

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

About Eggs

2007-04-10 Thread Mark Elston
This is probably a *really* stupid question but...
I have looked at all the documentation I have for 2.4.3
and all the docs I can download for 2.5 and I simply cannot
find anything, anywhere that documents what egg files are.

I have read posts referring to them and have been able to
deduce that they are some form of zip file for the distribution
of modules but beyond that I cannot find *any* docs for them
anywhere.

Where are they documented and how do I take advantage of them?

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


Re: About Trolltech QT OpenSource license.

2007-04-10 Thread Jarek Zgoda
king kikapu napisał(a):

> I saw at the forum here that a lot of debate is coming from the
> "strange" interpretation of it's Open Source Edition lisence.
> After a lot of reading i was under the impression (and many others
> with me) that even a stand alone developer working in-house at company
> cannot use Qt OS Edition and must buy the commercial lisence.

This is a bullsh*t. Qt is free (as in "free speech") on GPL. Nothing
stops you from using it in any commercial project if only it fits the
licensing terms (i.o.w. it's free software). This specially applies to
inhouse development, as in such case there's no "distribution".

> I sent an emai to them today and i think their response is
> interesting, so i appose it here;
> 
> #
> Thank you for your inquiry regarding the Qt Open Source Edition.
> 
> The open source edition may be used for either your own private use or
> for an application used only internally by your company if the
> application is developed by you on company time.  With internal
> company use under the GPL it is absolutely imperative that the
> application not be distributed outside of the legal entity.  If this
> happens then the GPL source distribution requirements (as well as all
> other GPL
> requirements) will take effect.  The internal use by the company falls
> under the "private modification" exception to the GPL.
> 
> Please note that if you begin your application development with the
> GPL version, that application must be GPL licensed and Trolltech does
> not permit developers to start with the Qt Open Source Edition and
> later convert to a commercial license.
> 
> Good luck with your development and please contact [EMAIL PROTECTED]
> if your company wishes to purchase a commercial Qt license at some
> point in the future.

Hey, there's no such statement here. Where did you get this "must buy
the commercial lisence"?

Plus, this (sales)person forgot to state clearly, that GPL covers only
distribution, not the cost of software. If you manage to get some hot
cash for selling sources of your GPL-ed program, the license would not
try to stop you from doing that. ;)

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Please help!!!

2007-04-10 Thread Paul McGuire
On Apr 10, 2:43 pm, "gslm" <[EMAIL PROTECTED]> wrote:
> Hi to all!
> I want to do a calendar with pictures near months.
> I have designed the form's view.But unfortunately, I am not be able to
> save this view as an image file.And so I am not be able to print this
> image file too.
> Question:
> How can I determine the coordinates of a button?Namely How can I use
> the comand ImageGrab for this purpose?
>
> But only I wan to get the button's ares.Because my applicationis on
> this.
>
> Or if it's possible, how can I print the area of this button with the
> components on it?
>
> Thanks...

Suggestion 1: "Please help!!!" is just about the worst newsgroup
subject line there is (other than those related to government
conspiracies or earthquake prediction).  You are unlikely to attract
the attention of those who really know anything - they are quite busy
and must husband their time carefully.  Instead, you'll get those who
are idly curious, to see what sort of junk is floating about Usenet.

Suggestion 2: Consider your audience.  What the heck are you talking
about?!  Your post goes on about calendars and buttons and views.  In
fact, trying to make sense of your post, it sounds like you've done
something truly bizarre, like making the whole view one giant button
with lots of images on it, and you want to print it out when the
"button" is clicked.  Is this even a Python question?  Any particular
GUI package you are using, such as Tk, wxPython, QT, your own homebrew
invention?  ImageGrab?  Sounds promising, what do the docs say?

A more thorough discussion of these suggestions:
http://www.catb.org/~esr/faqs/smart-questions.html

-- Paul

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


Re: NLTK, Random Sentence Generators?

2007-04-10 Thread [EMAIL PROTECTED]
On Apr 10, 1:59 pm, Paulo da Silva <[EMAIL PROTECTED]> wrote:
> gene tani escreveu:
>
> > On Apr 10, 1:36 am, Passer By <[EMAIL PROTECTED]> wrote:
> >> Has any created or not of examples of random sentence generators using
> >> n-gram models (or other models might be interesting).
>
> >> I know of one example from a course at MIT, but besides that nothing.
>
> >> Any help would be great.
>
> > Markov chains e.g.
> >http://rubyquiz.com/quiz74.html
>
> Seems interesting ... Is there anybody who masters both python and ruby
> to "translate" the code into python?

Wouldn't it be easier to translate Python:



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


Re: OT: Question about RGB color method

2007-04-10 Thread Paul McGuire
Ah, the Wikipedia article for "Primary Colors" is much better at
explaining this than the one for "RGB Color".  For instance, in the
Tempra-paint-compatible subtractive system, you probably recall mixing
red, yellow, and blue, and getting black, or at least a dark muddy
brown.  Conversely, in the additive system of RGB, mixing red, green,
and blue, gives you... white!  You've combined all the light there is,
you should get the lightest color of them all.

-- Paul

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


Re: OT: Question about RGB color method

2007-04-10 Thread Paul McGuire
On Apr 10, 2:32 pm, John Salerno <[EMAIL PROTECTED]> wrote:
> Sorry for this non-Python question, but since it's computer related I
> know you guys will have an answer, and I don't really know where else to
> ask. Mainly I'm just curious anyway.
>
> I'm wondering, why do computers use a RGB color scheme instead of the
> primary colors? Is there something you can't do with yellow? It seems
> weird that RGB can be combined to make all colors, when that's supposed
> to be the job of the primary colors. I'm sure there some technical
> computer-related reason that it had to be this way.
>
> Thanks.

See this link: http://www.rgbworld.com/color.html

The "red-yellow-blue" system we used in elementary school art classes
corresponded to the color mixing capabilities available using the
Tempra paint technology at hand.  At the RGBworld URL, the web page
shows how paints and inks follow a "subtractive" color system (called
CMY for cyan-magenta-yellow, instead of blue-red-yellow, but close
enough), in that paint reflects a given color by subtracting out all
frequencies that are not that color.  So mixing two subtractive
filters follows a subtractive color "algebra".

However, computer monitors do not follow a substractive scheme, but
rather an additive one, by adding brightness along red-green-and-blue
(RGB) dimensions, mixing red and green light to get yellow.  This
raises an interesting problem when *printing* a color image.  You
cannot just render the RGB colors from the monitor's additive system
into CMY colors on your inkjet printer's subtractive system.  Google
for "RGB color" and you will be presented with a long list of
references for dealing with this issue, including several competing
standards on how to handle it.  Even the Wikipedia article on RGB
colors is largely devoted to this issue (as opposed to your more
common question).

-- Paul

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


Re: OT: Question about RGB color method

2007-04-10 Thread Grant Edwards
On 2007-04-10, John Salerno <[EMAIL PROTECTED]> wrote:

> Sorry for this non-Python question, but since it's computer related

It isn't.  Computer-related, that is.

> I'm wondering, why do computers use a RGB color scheme instead
> of the primary colors?

The same reason televisions and all other additive-mixing media
use RGB:

http://en.wikipedia.org/wiki/Primary_colors

-- 
Grant Edwards   grante Yow!  I'm also against
  at   BODY-SURFING!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Question about RGB color method

2007-04-10 Thread Carsten Haese
On Tue, 2007-04-10 at 15:32 -0400, John Salerno wrote:
> Sorry for this non-Python question, but since it's computer related I 
> know you guys will have an answer, and I don't really know where else to 
> ask. Mainly I'm just curious anyway.
> 
> I'm wondering, why do computers use a RGB color scheme instead of the 
> primary colors? Is there something you can't do with yellow? It seems 
> weird that RGB can be combined to make all colors, when that's supposed 
> to be the job of the primary colors. I'm sure there some technical 
> computer-related reason that it had to be this way.

You'll find your answer in great detail at
http://en.wikipedia.org/wiki/Primary_colors. Television sets and
computer screens use the additive color system because they emit light
rather than reflect light. Yellow is a subtractive primary color. The
additive primary colors are red, green, and blue.

-Carsten


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


Re: OT: Question about RGB color method

2007-04-10 Thread kyosohma
On Apr 10, 2:32 pm, John Salerno <[EMAIL PROTECTED]> wrote:
> Sorry for this non-Python question, but since it's computer related I
> know you guys will have an answer, and I don't really know where else to
> ask. Mainly I'm just curious anyway.
>
> I'm wondering, why do computers use a RGB color scheme instead of the
> primary colors? Is there something you can't do with yellow? It seems
> weird that RGB can be combined to make all colors, when that's supposed
> to be the job of the primary colors. I'm sure there some technical
> computer-related reason that it had to be this way.
>
> Thanks.

It's a pigment vs. light-beam thing.

Check out http://en.wikipedia.org/wiki/RGB_color_model

Mike

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


Re: OT: Question about RGB color method

2007-04-10 Thread Matimus
On Apr 10, 12:32 pm, John Salerno <[EMAIL PROTECTED]> wrote:
> Sorry for this non-Python question, but since it's computer related I
> know you guys will have an answer, and I don't really know where else to
> ask. Mainly I'm just curious anyway.
>
> I'm wondering, why do computers use a RGB color scheme instead of the
> primary colors? Is there something you can't do with yellow? It seems
> weird that RGB can be combined to make all colors, when that's supposed
> to be the job of the primary colors. I'm sure there some technical
> computer-related reason that it had to be this way.
>
> Thanks.

See the Wikipedia article on primary colors: 
http://en.wikipedia.org/wiki/Primary_colors

The quick answer is that RGB is a method of additive color mixing, and
RBY is subtractive (and its not really RBY but YCM). Also, the colors
emitted by your monitor are Red, Green and Blue.

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


Re: Problem with getting an option value

2007-04-10 Thread Gabriel Genellina
En Tue, 10 Apr 2007 11:23:37 -0300, Lucas Malor <[EMAIL PROTECTED]>  
escribió:

> Peter Otten wrote:
>> Lucas Malor wrote:
>>>
>>> The problem is options is an instance, so options."delete", for  
>>> example,
>>> is wrong; I should pass options.delete . How can I do?
>>
>> Use getattr():
>
> Thank you. Do you know also if I can do a similar operation with  
> functions? I want to select with a string a certain get() function of  
> ConfigParser:
>
> if   type == "int" :
> funcname = "getint"
> elif type == "bool" :
> funcname = "getboolean"
> etc.
>
> How can I invoke the funcion with its name in a string?

Methods are searched the same way as "data" attributes, so you can apply  
the same technique. A first try would be (assuming cfg is a ConfigParser  
instance):

if   datatype == "int":
  funcname = "getint"
elif datatype == "bool":
  funcname = "getboolean"
func = getattr(cfg, funcname)
value = func(section, option)

(Using "type" as variable name is not a good idea - you are hiding the  
builtin "type".)
You can even write it as:

if   datatype == "int":
  func = cfg.getint
elif datatype == "bool":
  func = cfg.getboolean
value = func(section, option)

cfg.getint, by example, is a reference to the getint method of  
ConfigParser - bound to the cfg instance, and ready to be used as any  
other function. It's the same as getattr(cfg, "getint")

> PS: your answers had not arrived to my mail account. Is because I'm  
> using a disposal address? Or simply it's because I'm not registered to  
> the list?

I cannot tell for P. Otten, but many people (almost all, perhaps...)  
respond only to the list, so you may want to subscribe to it, or  
periodically check the last messages in some way. The list is mirrored  
back and forth with a newsgroup, and you can read it thru a web interfase  
(Google groups or gmane.org, by example).
Anyway, I've noticed some problems with the posted messages; I'm using  
gmane news and some messages come out of order, or very delayed, or never  
at all (I've seen replies to messages, and not the original ones).

-- 
Gabriel Genellina

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


Re: Parsing log in SQL DB to change IPs to hostnames

2007-04-10 Thread Steve Holden
KDawg44 wrote:
> On Apr 10, 11:11 am, "Kushal Kumaran" <[EMAIL PROTECTED]>
> wrote:
>> On Apr 10, 8:37 pm, "KDawg44" <[EMAIL PROTECTED]> wrote:
>>
>>
>>
>>> Hi,
>>> I am brand new to Python.  In learning anything, I find it useful to
>>> actually try to write a useful program to try to tackle an actual
>>> problem.
>>> I have a syslog server and I would like to parse the syslog messages
>>> and try to change any ips to resolved hostnames.  Unfortunately, I am
>>> not getting any matches on my regular expression.
>>> A message will look something like this:
>>>  Apr 10 2007 00:30:58 DEVICE : %DEVICEINFO: 1.1.1.1 Accessed URL
>>> 10.10.10.10:/folder/folder/page.html
>>> I would like to change the message to have the hostnames, or even
>>> better actually, have it appear as hostname-ip address.  So a changed
>>> message would look like:
>>>  Apr 10 2007 00:30:58 DEVICE : %DEVICEINFO: pcname-1.1.1.1 Accessed
>>> URLwww.asite.com-10.10.10.10:/folder/folder/page.html
>>> or some equivalent.
>>> Here is what i have so far.  Please be kind as it is my first python
>>> program :)
>>> #! /usr/bin/python
>>> import socket
>>> import re
>>> import string
>>> import MySQLdb
>>> ipRegExC = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
>>> ipRegEx = re.compile(ipRegExC)
>>> try:
>>> conn = MySQLdb.connect(host="REMOVED", user="REMOVED",
>>> passwd="REMOVED", db="REMOVED")
>>> except MySQLdb.Error, e:
>>> print "Error connecting to the database: %d - %s " %
>>> (e.args[0], e.args[1])
>>> sys.exit(1)
>>> cursor = conn.cursor()
>>> cursor.execute("SELECT msg, seq FROM REMOVED WHERE seq = 507702")
>>> # one specific message so that it doesn't parse the whole DB during
>>> testing...
>>> while(1):
>>> row = cursor.fetchone()
>>> if row == None:
>>> break
>>> if ipRegEx.match(row[0]):
>>> 
>>> 
>> See the documentation of the re module for the difference between
>> matching and searching.
>>
>> --
>> Kushal
> 
> Thank you very much.  I think I have it figured out, except for an
> error on the SQL statement:
> 
> 
> [- BEGIN ERROR ---]
> Traceback (most recent call last):
>   File "changeLogs.py", line 47, in ?
> cursor.execute("""UPDATE logs SET msg = %s WHERE seq = %i""",
> (newMsg,seqNum))
>   File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
> 148, in execute
> query = query % db.literal(args)
> TypeError: int argument required
> [- END ERROR ---]
> 
> Here is my code
> 
> [- BEGIN CODE ---]
> #! /usr/bin/python
> 
> import socket
> import sys
> import re
> import string
> import MySQLdb
> 
> def resolveHost(ipAdds):
> ipDict = {}
> for ips in ipAdds:
> try:
> ipDict[ips] = socket.gethostbyaddr(ips)[0]
> except:
> ipDict[ips] = "Cannot resolve"
> return ipDict
> 
> 
> ipRegExC = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
> ipRegEx = re.compile(ipRegExC)
> 
> try:
> conn = MySQLdb.connect(host="REMOVED", user="REMOVED",
> passwd="REMOVED", db="REMOVED")
> 
> except MySQLdb.Error, e:
> print "Error connecting to the database: %d - %s " %
> (e.args[0], e.args[1])
> sys.exit(1)
> 
> cursor = conn.cursor()
> cursor.execute("SELECT msg, seq FROM `logs` WHERE seq = 507702")
> while(1):
> row = cursor.fetchone()
> ipAddresses = []
> resolvedDict = {}
> if row == None:
> break
> if ipRegEx.search(row[0]):
> seqNum = row[1]
> ipAddresses = ipRegEx.findall(row[0])
> resolvedDict = resolveHost(ipAddresses)
> newMsg = row[0]
> for ip in resolvedDict.keys():
> newMsg = newMsg.replace(ip,ip + "-" +
> resolvedDict[ip])
> cursor.execute("""UPDATE REMOVED SET msg = %s WHERE
> seq = %i""", (newMsg,seqNum))
> 
> 
> [- END CODE ---]
> 
> Thanks again!
> 
> 
Since the source line that the traceback complains about doesn't appear 
in the quoted code it's difficult to know what's going wrong. I'd hazard 
a guess that you have a string in seqNum instead of an integer message 
number (in which case try using int(seqNum) instead).

Otherwise show us the real code, not the one after you modified it to 
try and make it work, amd we might be able to help more ;-)

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

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


Please help!!!

2007-04-10 Thread gslm
Hi to all!
I want to do a calendar with pictures near months.
I have designed the form's view.But unfortunately, I am not be able to
save this view as an image file.And so I am not be able to print this
image file too.
Question:
How can I determine the coordinates of a button?Namely How can I use
the comand ImageGrab for this purpose?

But only I wan to get the button's ares.Because my applicationis on
this.

Or if it's possible, how can I print the area of this button with the
components on it?

Thanks...

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


OT: Question about RGB color method

2007-04-10 Thread John Salerno
Sorry for this non-Python question, but since it's computer related I 
know you guys will have an answer, and I don't really know where else to 
ask. Mainly I'm just curious anyway.

I'm wondering, why do computers use a RGB color scheme instead of the 
primary colors? Is there something you can't do with yellow? It seems 
weird that RGB can be combined to make all colors, when that's supposed 
to be the job of the primary colors. I'm sure there some technical 
computer-related reason that it had to be this way.

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


Re: Parsing log in SQL DB to change IPs to hostnames

2007-04-10 Thread KDawg44
On Apr 10, 1:54 pm, "KDawg44" <[EMAIL PROTECTED]> wrote:
> On Apr 10, 11:11 am, "Kushal Kumaran" <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > On Apr 10, 8:37 pm, "KDawg44" <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
>
> > > I am brand new to Python.  In learning anything, I find it useful to
> > > actually try to write a useful program to try to tackle an actual
> > > problem.
>
> > > I have a syslog server and I would like to parse the syslog messages
> > > and try to change any ips to resolved hostnames.  Unfortunately, I am
> > > not getting any matches on my regular expression.
>
> > > A message will look something like this:
> > >  Apr 10 2007 00:30:58 DEVICE : %DEVICEINFO: 1.1.1.1 Accessed URL
> > > 10.10.10.10:/folder/folder/page.html
>
> > > I would like to change the message to have the hostnames, or even
> > > better actually, have it appear as hostname-ip address.  So a changed
> > > message would look like:
>
> > >  Apr 10 2007 00:30:58 DEVICE : %DEVICEINFO: pcname-1.1.1.1 Accessed
> > > URLwww.asite.com-10.10.10.10:/folder/folder/page.html
>
> > > or some equivalent.
>
> > > Here is what i have so far.  Please be kind as it is my first python
> > > program :)
>
> > > #! /usr/bin/python
>
> > > import socket
> > > import re
> > > import string
> > > import MySQLdb
>
> > > ipRegExC = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
> > > ipRegEx = re.compile(ipRegExC)
>
> > > try:
> > > conn = MySQLdb.connect(host="REMOVED", user="REMOVED",
> > > passwd="REMOVED", db="REMOVED")
>
> > > except MySQLdb.Error, e:
> > > print "Error connecting to the database: %d - %s " %
> > > (e.args[0], e.args[1])
> > > sys.exit(1)
>
> > > cursor = conn.cursor()
> > > cursor.execute("SELECT msg, seq FROM REMOVED WHERE seq = 507702")
> > > # one specific message so that it doesn't parse the whole DB during
> > > testing...
> > > while(1):
> > > row = cursor.fetchone()
> > > if row == None:
> > > break
> > > if ipRegEx.match(row[0]):
> > > 
> > > 
>
> > See the documentation of the re module for the difference between
> > matching and searching.
>
> > --
> > Kushal
>
> Thank you very much.  I think I have it figured out, except for an
> error on the SQL statement:
>
> [- BEGIN ERROR ---]
> Traceback (most recent call last):
>   File "changeLogs.py", line 47, in ?
> cursor.execute("""UPDATE logs SET msg = %s WHERE seq = %i""",
> (newMsg,seqNum))
>   File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
> 148, in execute
> query = query % db.literal(args)
> TypeError: int argument required
> [- END ERROR ---]
>
> Here is my code
>
> [- BEGIN CODE ---]
> #! /usr/bin/python
>
> import socket
> import sys
> import re
> import string
> import MySQLdb
>
> def resolveHost(ipAdds):
> ipDict = {}
> for ips in ipAdds:
> try:
> ipDict[ips] = socket.gethostbyaddr(ips)[0]
> except:
> ipDict[ips] = "Cannot resolve"
> return ipDict
>
> ipRegExC = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
> ipRegEx = re.compile(ipRegExC)
>
> try:
> conn = MySQLdb.connect(host="REMOVED", user="REMOVED",
> passwd="REMOVED", db="REMOVED")
>
> except MySQLdb.Error, e:
> print "Error connecting to the database: %d - %s " %
> (e.args[0], e.args[1])
> sys.exit(1)
>
> cursor = conn.cursor()
> cursor.execute("SELECT msg, seq FROM `logs` WHERE seq = 507702")
> while(1):
> row = cursor.fetchone()
> ipAddresses = []
> resolvedDict = {}
> if row == None:
> break
> if ipRegEx.search(row[0]):
> seqNum = row[1]
> ipAddresses = ipRegEx.findall(row[0])
> resolvedDict = resolveHost(ipAddresses)
> newMsg = row[0]
> for ip in resolvedDict.keys():
> newMsg = newMsg.replace(ip,ip + "-" +
> resolvedDict[ip])
> cursor.execute("""UPDATE REMOVED SET msg = %s WHERE
> seq = %i""", (newMsg,seqNum))
>
> [- END CODE ---]
>
> Thanks again!

Also, i tried changing seqNum = row[1] to seqNum = int(row[1]) to cast
it as an integer and I get the same error (because I think that
pulling from a DB makes everything a string by default?)

Thanks.

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


About Trolltech QT OpenSource license.

2007-04-10 Thread king kikapu
Hi to all,

i am coming from the Microsoft (.net) world and at the quest of
finding the right GUI toolkit that i can use from Python, i have two
obvious choices to choose from: wxPython and Qt.

Both are looking very good. Qt has Qt designer, a tool that really
reminds me of the forms designers that we have in VS.Net.The
productivity someone can gain from tools like these can be really
astonished.
I saw at the forum here that a lot of debate is coming from the
"strange" interpretation of it's Open Source Edition lisence.
After a lot of reading i was under the impression (and many others
with me) that even a stand alone developer working in-house at company
cannot use Qt OS Edition and must buy the commercial lisence.

I sent an emai to them today and i think their response is
interesting, so i appose it here;

#
Thank you for your inquiry regarding the Qt Open Source Edition.

The open source edition may be used for either your own private use or
for an application used only internally by your company if the
application is developed by you on company time.  With internal
company use under the GPL it is absolutely imperative that the
application not be distributed outside of the legal entity.  If this
happens then the GPL source distribution requirements (as well as all
other GPL
requirements) will take effect.  The internal use by the company falls
under the "private modification" exception to the GPL.

Please note that if you begin your application development with the
GPL version, that application must be GPL licensed and Trolltech does
not permit developers to start with the Qt Open Source Edition and
later convert to a commercial license.

Good luck with your development and please contact [EMAIL PROTECTED]
if your company wishes to purchase a commercial Qt license at some
point in the future.

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


Re: itertools, functools, file enhancement ideas

2007-04-10 Thread Klaas
On Apr 8, 9:34 am, Paul Rubin  wrote:
> [EMAIL PROTECTED] writes:

> > >   a) def flip(f): return lambda x,y: f(y,x)
> > Curious resemblance to:
> >itemgetter(1,0)
>
> Not sure I understand that.

I think he read it as lambda (x, y): (y, x)

More interesting would be functools.rshift/lshift, that would rotate
the positional arguments (with wrapping)

def f(a, b, c, d, e):
...
rshift(f, 3) --> g, where g(c, d, e, a, b) == f(a, b, c, d, e)

Still don't see much advantage over writing a lambda (except perhaps
speed).

-Mike

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


Re: NLTK, Random Sentence Generators?

2007-04-10 Thread Paulo da Silva
gene tani escreveu:
> On Apr 10, 1:36 am, Passer By <[EMAIL PROTECTED]> wrote:
>> Has any created or not of examples of random sentence generators using
>> n-gram models (or other models might be interesting).
>>
>> I know of one example from a course at MIT, but besides that nothing.
>>
>> Any help would be great.
> 
> Markov chains e.g.
> http://rubyquiz.com/quiz74.html
> 

Seems interesting ... Is there anybody who masters both python and ruby
to "translate" the code into python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Problems with curses.start_color()

2007-04-10 Thread skip

Environment: Solaris 10, Python 2.4.2.

I'm trying to convert a very simple (display-wise) program to use curses.
This is my first try at using curses.  I have wrapped my main:

try:
sys.exit(curses.wrapper(main, *sys.argv[1:]))
except (KeyboardInterrupt, SystemExit):
sys.exit(0)

According to the docs, curses.wrapper() calls curses.start_color(), but if I
don't call it myself I get this traceback when I try to use colors:

Traceback (most recent call last):
  File "snake/scripts/message-tracker.py", line 141, in display
  attr = curses.color_pair(0)
error: must call start_color() first

If I call start_color() unconditionally I get this error:

Traceback (most recent call last):
  File "snake/scripts/message-tracker.py", line 229, in ?
sys.exit(curses.wrapper(main, *sys.argv[1:]))
  File "/opt/app/g++lib6/python-2.4/lib/python2.4/curses/wrapper.py", line 
44, in wrapper
return func(stdscr, *args, **kwds)
  File "snake/scripts/message-tracker.py", line 215, in main
curses.start_color()
  File "/opt/app/g++lib6/python-2.4/lib/python2.4/curses/__init__.py", line 
41, in start_color
retval = _curses.start_color()
error: start_color() returned ERR

If I protect the call like so:

try:
curses.start_color()
except:
pass

I get the first traceback again.

A quick Google search didn't turn this up as an obvious problem.  What have
I missed?

Thx,

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


Re: Parsing log in SQL DB to change IPs to hostnames

2007-04-10 Thread KDawg44
On Apr 10, 11:11 am, "Kushal Kumaran" <[EMAIL PROTECTED]>
wrote:
> On Apr 10, 8:37 pm, "KDawg44" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > I am brand new to Python.  In learning anything, I find it useful to
> > actually try to write a useful program to try to tackle an actual
> > problem.
>
> > I have a syslog server and I would like to parse the syslog messages
> > and try to change any ips to resolved hostnames.  Unfortunately, I am
> > not getting any matches on my regular expression.
>
> > A message will look something like this:
> >  Apr 10 2007 00:30:58 DEVICE : %DEVICEINFO: 1.1.1.1 Accessed URL
> > 10.10.10.10:/folder/folder/page.html
>
> > I would like to change the message to have the hostnames, or even
> > better actually, have it appear as hostname-ip address.  So a changed
> > message would look like:
>
> >  Apr 10 2007 00:30:58 DEVICE : %DEVICEINFO: pcname-1.1.1.1 Accessed
> > URLwww.asite.com-10.10.10.10:/folder/folder/page.html
>
> > or some equivalent.
>
> > Here is what i have so far.  Please be kind as it is my first python
> > program :)
>
> > #! /usr/bin/python
>
> > import socket
> > import re
> > import string
> > import MySQLdb
>
> > ipRegExC = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
> > ipRegEx = re.compile(ipRegExC)
>
> > try:
> > conn = MySQLdb.connect(host="REMOVED", user="REMOVED",
> > passwd="REMOVED", db="REMOVED")
>
> > except MySQLdb.Error, e:
> > print "Error connecting to the database: %d - %s " %
> > (e.args[0], e.args[1])
> > sys.exit(1)
>
> > cursor = conn.cursor()
> > cursor.execute("SELECT msg, seq FROM REMOVED WHERE seq = 507702")
> > # one specific message so that it doesn't parse the whole DB during
> > testing...
> > while(1):
> > row = cursor.fetchone()
> > if row == None:
> > break
> > if ipRegEx.match(row[0]):
> > 
> > 
>
> See the documentation of the re module for the difference between
> matching and searching.
>
> --
> Kushal

Thank you very much.  I think I have it figured out, except for an
error on the SQL statement:


[- BEGIN ERROR ---]
Traceback (most recent call last):
  File "changeLogs.py", line 47, in ?
cursor.execute("""UPDATE logs SET msg = %s WHERE seq = %i""",
(newMsg,seqNum))
  File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
148, in execute
query = query % db.literal(args)
TypeError: int argument required
[- END ERROR ---]

Here is my code

[- BEGIN CODE ---]
#! /usr/bin/python

import socket
import sys
import re
import string
import MySQLdb

def resolveHost(ipAdds):
ipDict = {}
for ips in ipAdds:
try:
ipDict[ips] = socket.gethostbyaddr(ips)[0]
except:
ipDict[ips] = "Cannot resolve"
return ipDict


ipRegExC = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
ipRegEx = re.compile(ipRegExC)

try:
conn = MySQLdb.connect(host="REMOVED", user="REMOVED",
passwd="REMOVED", db="REMOVED")

except MySQLdb.Error, e:
print "Error connecting to the database: %d - %s " %
(e.args[0], e.args[1])
sys.exit(1)

cursor = conn.cursor()
cursor.execute("SELECT msg, seq FROM `logs` WHERE seq = 507702")
while(1):
row = cursor.fetchone()
ipAddresses = []
resolvedDict = {}
if row == None:
break
if ipRegEx.search(row[0]):
seqNum = row[1]
ipAddresses = ipRegEx.findall(row[0])
resolvedDict = resolveHost(ipAddresses)
newMsg = row[0]
for ip in resolvedDict.keys():
newMsg = newMsg.replace(ip,ip + "-" +
resolvedDict[ip])
cursor.execute("""UPDATE REMOVED SET msg = %s WHERE
seq = %i""", (newMsg,seqNum))


[- END CODE ---]

Thanks again!


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


Re: installing pyqt4 on ubuntu 6.06

2007-04-10 Thread Joshua J. Kugler
On Tuesday 10 April 2007 07:35, Pradnyesh Sawant wrote:

> Any pointers regarding what packages should i install to get the
> system into working condition would be very helpful

It's next to impossible, due to conflicts with SIP, and other dependencies. 
See these two threads (both started by me) for more information:

http://ubuntuforums.org/showthread.php?t=243936
http://ubuntuforums.org/showthread.php?t=244612

j

-- 
Joshua Kugler
Lead System Admin -- Senior Programmer
http://www.eeinternet.com
PGP Key: http://pgp.mit.edu/  ID 0xDB26D7CE

-- 
Posted via a free Usenet account from http://www.teranews.com

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

Re: exec statement Syntax Error on string pulled from MySQL

2007-04-10 Thread [EMAIL PROTECTED]
On Apr 10, 2:19 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Now I just have to figure out how the '\r' are getting in
> there.  I entered that piece of code using PHPMyAdmin so that could be
> doing it, or MySQLdb could be doing it when returning it, or it could
> be something about the DB encoding!  I'll post back if I find out.
>

Hmm, searches didn't turn up anything.  The best I can figure is that
the HTML textarea / browser combination is sending the text in that
way.  I can check for sure on that later.

-Greg


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


Re: writing my own extension

2007-04-10 Thread kyosohma
On Apr 10, 12:52 pm, "spohle" <[EMAIL PROTECTED]> wrote:
> hi,
>
> i use a lot the enumerate in my scripts and got really interested in
> possibly writing my own enumerate as an extension, for which i would
> want to extend it to be able to pass a start and step attribute.
>
> can anyone point me on my way with good examples for that and how to
> write extensions ?
>
> thank you in advance

The range() builtin has this functionality. Also check out
http://docs.python.org/lib/itertools-functions.html

As for writing extensions, check out the following links:

http://docs.python.org/inst/tweak-flags.html
http://docs.python.org/dist/describing-extensions.html
http://www.geocities.com/foetsch/python/extending_python.htm
http://cxx.sourceforge.net/
http://www.vrplumber.com/programming/mstoolkit/

Interesting notes on iterators with (or without) a "step()":

http://mail.python.org/pipermail/python-bugs-list/2004-February/022007.html
http://www.thescripts.com/forum/thread556059.html
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498272

Mike

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


Mysterious argument count error to __new__

2007-04-10 Thread Clarence
I'm having problems with JPype and am trying to change the way
it creates Python classes as proxies for Java classes and interfaces.
I'm trying to get around "inconsistent mro" problems, but in doing
so, I've run into a real mystery.

Here's the original code. It first makes a metaclass, then makes a
class using that metaclass.

##
metaclass = type.__new__(type, name+"$$Static", tuple(meta_bases),
static_fields)
members['__metaclass__'] = metaclass
result =  type.__new__(metaclass, name, tuple(bases), members)
##

I'm getting an error on the first call to __new__, but I want to see
if my "bases" list is acceptable, putting aside for the moment that
"meta_bases" is having a problem.

So I put this line directly ahead of the three quoted above:
##
type.__new__(type, 'aoeu', tuple(bases), members)
##
You can see that this is essentially exactly the same as the first of
the three, just using a different name, a diffent bases tuple, and a
different dictionary. Whereas the first of the three gets an mro kind
of error, when I insert this new line, it gets:
type.__new__(type, 'aoeu', tuple(bases), members)
 TypeError: __new__() takes exactly 2 arguments (4 given)

How is it possible that I get a number-of-arguments error when the
following line, with the same number of arguments, does not?
(This can't even be relevant, really, but I also printed out the
value of "type" before the line, and got  as it should
be.)

Thanks for any help.
Clarence

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


Re: Can I get the exit code "n" passed to sys.exit(n) ?

2007-04-10 Thread kyosohma
On Apr 10, 1:15 pm, "Yujo" <[EMAIL PROTECTED]> wrote:
> Hello everybody,
>
> In the following code of the finish() function, is there any way to
> get the exit code passed to sys.exit() ?
>
> def finish() :
>RETURN_CODE_FROM_SYS_EXIT = # how can I get it ?
>if RETURN_CODE_FROM_SYS_EXIT = 0 :
>  # process ended OK
>else :
>  # process ended with some error
>  # execute something
>
> atexit.register(finish)
>
> # this is my main program
>
> ERR_CODE=3
> sys.exit(ERR_CODE)
>
> Regards,
>
> Yujo

I'm not sure if this will help or not, but this article is pretty
enlightening and is written by a well-known Pythonista:

http://www.artima.com/weblogs/viewpost.jsp?thread=4829

Here is another older post with helpful information:
http://www.daniweb.com/techtalkforums/thread31226.html

And here's a hack that might work: 
http://www.daniweb.com/techtalkforums/thread31166.html

Mike

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


Re: Kill thread or at least socket.getaddrinfo

2007-04-10 Thread Chris Mellon
On 10 Apr 2007 11:07:51 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> On 26 Mar., 18:08, [EMAIL PROTECTED] wrote:
> > you know the pid, you can kill it, but that's not always a
> > clean way of accomplishing the task.
>
> So I have to open the connection in a new process... Sigh.. How I hate
> this part of Python.
>

This isn't a python problem. You can't cleanly or safely kill threads,
period. If you have to use blocking functions like this (you don't,
you might consider using Twisted for your networking instead) the way
you "cancel" it is to just stop waiting for the response and discard
the response (or error) when it eventually comes.

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


Re: exec statement Syntax Error on string pulled from MySQL

2007-04-10 Thread [EMAIL PROTECTED]
On Apr 10, 4:49 am, Georg Brandl <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] schrieb:
>
>
>
> > It's the strangest thing,  I'm pulling some text out of a MySQL table
> > and trying to run exec on it, and it keeps giving me a syntax error,
> > always at the end of the first line.
>
> > Thanks in advance for any help.  I'm really stuck on this one!
>
> > -Greg
>
> > I'm not sure what information would be most useful but here's a start:
>
> > The last code I stored in the table and pulled out was simply:
> > print 'greg'
> > print 'greg2'
>
> > To which my error log says:
> > Traceback (most recent call last):
> >   File "/home/public/web/webapi.py", line 303, in wsgifunc
> > result = func()
> >   File "/home/public/web/request.py", line 125, in 
> > func = lambda: handle(inp, fvars)
> >   File "/home/public/web/request.py", line 61, in handle
> > return tocall(*([urllib.unquote(x) for x in args] + fna))
> >   File "/home/public/EZsession.py", line 119, in proxyfunc
> > return func(self, *args, **kw)
> >   File "/home/htdocs/code.py", line 94, in POST
> > print utility.run(name,revision,inp)
> >   File "/home/public/utility.py", line 177, in run
> > exec code+'\n' in context
> >   File "", line 1
> > print 'greg'
> > ^
> > SyntaxError: invalid syntax
> > (Note the ^ actually appears under after the ' )
>
> You have Windows line endings (\r\n) in the string, which Python doesn't like.
>
> Don't store it like that, or if you must, do a .replace('\r', '') before
> exec'ing it.

Wow,
exec code.replace('\r','') in context
works!  Now I just have to figure out how the '\r' are getting in
there.  I entered that piece of code using PHPMyAdmin so that could be
doing it, or MySQLdb could be doing it when returning it, or it could
be something about the DB encoding!  I'll post back if I find out.

Thanks for help!

-Greg

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


Can I get the exit code "n" passed to sys.exit(n) ?

2007-04-10 Thread Yujo
Hello everybody,

In the following code of the finish() function, is there any way to
get the exit code passed to sys.exit() ?

def finish() :
   RETURN_CODE_FROM_SYS_EXIT = # how can I get it ?
   if RETURN_CODE_FROM_SYS_EXIT = 0 :
 # process ended OK
   else :
 # process ended with some error
 # execute something

atexit.register(finish)

# this is my main program

ERR_CODE=3
sys.exit(ERR_CODE)


Regards,

Yujo

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


Re: Kill thread or at least socket.getaddrinfo

2007-04-10 Thread [EMAIL PROTECTED]
On 26 Mar., 18:08, [EMAIL PROTECTED] wrote:
> you know the pid, you can kill it, but that's not always a
> clean way of accomplishing the task.

So I have to open the connection in a new process... Sigh.. How I hate
this part of Python.

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


Re: tuples, index method, Python's design

2007-04-10 Thread Chris Mellon
On 4/10/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Tue, 2007-04-10 at 19:21 +0200, BJörn Lindqvist wrote:
> > On 4/10/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
> > > > > opponents = tuple(x for x in p if x is not current_player)
> > > > >
> > > > Your alternative is wrong because it wont raise ValueError if
> > > > current_player is not present in the tuple. Please revise your
> > > > "solution."
> > >
> > > You have a point. Here is my revised solution:
> > >
> > > assert current_player in p
> > > opponents = tuple(x for x in p if x is not current_player)
> > >
> > > The added advantage is that AssertionError is better than IndexError for
> > > conveying that a severe program bug has occurred.
> >
> > Assertions are not checked when you run scripts with -O.
>
> Right. Which is why you use assert to guard against situations that
> should never happen, and you determine in unit tests that they, in fact,
> don't happen. Realistically, in a game loop such as
>
> while not game_has_ended:
>   for current_player in p:
> player_does_something(current_player)
>

I'm curious why someone would even consider using a tuple in this case
regardless. I think that much of the desire for tuple.index is because
people use a tuple where they could have a list, but either a) some
vestige of B&D language programming comes out and they want to make
sure a caller can't mutate it or b) they decide it's not going to
change and use the "immutable list" version of the tuple.

The first reason is clearly perverse, and can be discounted.

The second means this is not so much about tuple.index as it is about
appropriate data types. It's not going to be resolved by use cases,
because clearly the only use of tuple.index is when you're using it as
an immutable list, as in this case. Any use case where you'd want to
search a tuple can be rewritten (trivially) as a list.

So the solution for the dissenters is to justify the need for a frozen
list, not to justify index on tuples.

The only use case which even approaches reasonableness in this thread
is the binary parsing example (where the position of a value in an
unpacked binary blob might be something you need to know). This is a
rare enough use case and is easy enough to work around (convert it to
a list, write a helper function) that I don't think it's worth any
language change overhead at all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Universal Feed Parser issue

2007-04-10 Thread i3dmaster
I have a sample Atom feed like this:



  http://app.example.com/fjie4id939xdl3io23
  foo
  
bar
[EMAIL PROTECTED]
  
  2007-04-09T22:14:15.000Z
  
  
  


After parsed by feedparser, the timezone element does not get the
attribute "America/Mountain". Same thing on status element. This does
not sound an expected result.  I am wondering if it should be
considered a bug...

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


writing my own extension

2007-04-10 Thread spohle
hi,

i use a lot the enumerate in my scripts and got really interested in
possibly writing my own enumerate as an extension, for which i would
want to extend it to be able to pass a start and step attribute.

can anyone point me on my way with good examples for that and how to
write extensions ?

thank you in advance

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


Re: Having trouble with relative imports

2007-04-10 Thread Echo
On 4/9/07, Echo <[EMAIL PROTECTED]> wrote:
> Here is my setup:
> rpg
> -objects
> --__init__.py
> --gameobject.py
> --material.py
> -__init__.py
> -run_tests.py
> -stats.py
>
> the contents of run_test.py is:
> import objects as o
>
> the contents of objects/__init__.py is:
> from material import *
>
> in objects/material.py I have:
> from .gameobject import GameObject
> from ..stats import stats
>
> When I try to run run_tests.py, I get this traceback:
> (1:30:59 PM) OshEcho: [EMAIL PROTECTED] ~/projects/rpg $ python run_tests.py
> Traceback (most recent call last):
>   File "run_tests.py", line 4, in 
> import objects as o
>   File "/home/echo/projects/rpg/objects/__init__.py", line 3, in 
> from material import *
>   File "/home/echo/projects/rpg/objects/material.py", line 4, in 
> from ..stats import stats
> ValueError: Attempted relative import beyond toplevel package
>
>
> Could someone point out to me what I am doing wrong?
> I'm running Python 2.5 on Gentoo
>
> --
> -Echo
>

Well, since I've gotten no answer and since that Python 2.5 doesn't
play well with some programs on Gentoo, I will be switch back to 2.4
for now.

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


ANN: pywinauto 0.3.7 now released

2007-04-10 Thread Mark Mc Mahon
Hi,

0.3.7 release of pywinauto is now available.

pywinauto is an open-source (LGPL) package for using Python as a GUI
automation 'driver' for Windows NT based Operating Systems (NT/W2K/XP/Vista?).

SourceForge project page:
http://sourceforge.net/projects/pywinauto

Download from SourceForge
http://sourceforge.net/project/showfiles.php?group_id=157379


Here is the list of changes from the previous release (0.3.6):

0.3.7 Merge of Wait changes and various bug fixes/improvements
--
10-April-2007

* Added Timings.WaitUntil() and Timings.WaitUntilPasses() which
  handle the various wait until something in the code. Also
  refactored existing waits to use these two methods.

* Fixed a major Handle leak in RemoteMemorBlock class (which is
  used extensively for 'Common' controls. I was using OpenHandle
  to open the process handle, but was not calling CloseHandle()
  for each corresponding OpenHandle().

* Added an active_() method to Application class to return the
  active window of the application.

* Added an 'active' option to WindowSpecification.Wait() and
  WaitNot().

* Some cleanup of the clipboard module. GetFormatName()
  was improved and GetData() made a little more robust.

* Added an option to findwindows.find_windows() to find only
  active windows (e.g. active_only = True). Default is False.

* Fixed a bug in the timings.Timings class - timing values are
  Now accessed through the class (Timings) and not through the
  intance (self).

* Updated ElementTree import in XMLHelpers so that it would work
  on Python 2.5 (where elementtree is a standard module) as well
  as other versions where ElementTree is a separate module.

* Enhanced Item selection for ListViews, TreeViews - it is now
  possible to pass strings and they will be searched for. More
  documentation is required though.

* Greatly enhanced Toolbar button clicking, selection, etc.
  Though more documentation is required.

* Added option to ClickInput() to allow mouse wheel movements
  to be made.

* menuwrapper.Menu.GetProperties() now returns a dict like all other
  GetProperties() methods. This dict for now only has one key
  'MenuItems' which contains the list of menuitems (which had been
  the previous return value).


Thanks
 Mark

Mark Mc Mahon
Manchester, NH 03110, USA

http://sourceforge.net/projects/pywinauto";>pywinauto 0.3.7
Simple Windows GUI automation with Python. (10-Apr-07)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples, index method, Python's design

2007-04-10 Thread Carsten Haese
On Tue, 2007-04-10 at 19:21 +0200, BJörn Lindqvist wrote:
> On 4/10/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
> > > > opponents = tuple(x for x in p if x is not current_player)
> > > >
> > > Your alternative is wrong because it wont raise ValueError if
> > > current_player is not present in the tuple. Please revise your
> > > "solution."
> >
> > You have a point. Here is my revised solution:
> >
> > assert current_player in p
> > opponents = tuple(x for x in p if x is not current_player)
> >
> > The added advantage is that AssertionError is better than IndexError for
> > conveying that a severe program bug has occurred.
> 
> Assertions are not checked when you run scripts with -O.

Right. Which is why you use assert to guard against situations that
should never happen, and you determine in unit tests that they, in fact,
don't happen. Realistically, in a game loop such as

while not game_has_ended:
  for current_player in p:
player_does_something(current_player)

it's obvious that the assertion "current_player in p" will never fail.

> Furthermore,
> changing the exception type and the message it produces, is quite a
> big deviation from list.index.

What's your point? I wasn't talking about coding a drop-in replacement
for list.index. I was suggesting one possible solution to a problem that
may or may not be solved by using tuple.index.

-Carsten


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


Re: Database in memory

2007-04-10 Thread Nicko
On Apr 10, 1:10 pm, "Nicko" <[EMAIL PROTECTED]> wrote:
> If you expect to do exact-match look-up where the keys are not unique
> then build a dictionary containing 'set' objects which are the sets of
> records which have the given key. This lets you neatly find the
> intersection of selections on multiple criteria (e.g. matches =
> zipcode_index["94101"] & hometype_index["condo"] ).

Just FYI, if you're going to go this route then the items that you are
indexing have to be hashable, which the built in 'list' type is not.
Tuples are, or you can make some custom class (or your own subtype of
list) which implements the __hash__ method based on some 'primary key'
value from your data.  Or you could just go for SQLite...

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


Re: Why is __getslice__ still implemented?

2007-04-10 Thread Steven Bethard
Torsten Bronger wrote:
> Hallöchen!
> 
> Steven Bethard writes:
> 
>> Torsten Bronger wrote:
>>
>>> [...]
>>>
>>> [...]  It forces people to implement a deprecated function after
>>> all.  I think the docs should say that you still have to override
>>> __getslice__ when subclassing from a built-in type, unless I
>>> really don't understand the issue correctly.
>> [...] If you have a specific suggestion for what doc should be
>> updated and how, that would be helpful. Please post it to:
>>
>> http://sourceforge.net/tracker/?group_id=5470&atid=105470
> 
> Done.

Thanks!

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


Re: tuples, index method, Python's design

2007-04-10 Thread BJörn Lindqvist
On 4/10/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
> > > opponents = tuple(x for x in p if x is not current_player)
> > >
> > Your alternative is wrong because it wont raise ValueError if
> > current_player is not present in the tuple. Please revise your
> > "solution."
>
> You have a point. Here is my revised solution:
>
> assert current_player in p
> opponents = tuple(x for x in p if x is not current_player)
>
> The added advantage is that AssertionError is better than IndexError for
> conveying that a severe program bug has occurred.

Assertions are not checked when you run scripts with -O. Furthermore,
changing the exception type and the message it produces, is quite a
big deviation from list.index.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tuples, index method, Python's design

2007-04-10 Thread bearophileHUGS
BJörn Lindqvist:
> > One might perversely allow extension to lists and tuples to allow
> >[3, 4] in [1, 2, 3, 4, 5, 6]
> > to succeed, but that's forcing the use case beyond normal limits. The
> > point I am trying to make is that circumstances alter cases, and that we
> > can't always rely on our intuition to determine how specific methods
> > work, let alone whether they are available.
>
> I'd love to have that! There are at least one million use cases for
> finding a sequence in a sequence and implementing it yourself is
> non-trivial. Plus then both list and tuple's index methods would work
> *exactly* like string's. It would be easier to document and more
> useful. A big win.

Sublist search (and generally adding a bit of pattern matching
features to Python) looks far from being perverse, it may even become
pythonic ;-)

Bye,
bearophile

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


grabbing Pictures from the web

2007-04-10 Thread Juan Vazquez

I am new to python (2 weeks old)  and I would like to write a script that
grabs pictures from the web (specifically flickr) and put them on a Tk
Canvas for a slide show/editing program. my 2 questions are
1) How do I grab a picture from the web
2) is the use of the Tk canvas for working with the picture the best
approach?

Any help or references to resources that point me in the right direction
would be greatly appreciated. Thanks in Advance.
-Juan
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Why is __getslice__ still implemented?

2007-04-10 Thread Torsten Bronger
Hallöchen!

Steven Bethard writes:

> Torsten Bronger wrote:
>
>> [...]
>>
>> [...]  It forces people to implement a deprecated function after
>> all.  I think the docs should say that you still have to override
>> __getslice__ when subclassing from a built-in type, unless I
>> really don't understand the issue correctly.
>
> [...] If you have a specific suggestion for what doc should be
> updated and how, that would be helpful. Please post it to:
>
> http://sourceforge.net/tracker/?group_id=5470&atid=105470

Done.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
  (See http://ime.webhop.org for ICQ, MSN, etc.)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: NLTK, Random Sentence Generators?

2007-04-10 Thread gene tani
On Apr 10, 1:36 am, Passer By <[EMAIL PROTECTED]> wrote:
> Has any created or not of examples of random sentence generators using
> n-gram models (or other models might be interesting).
>
> I know of one example from a course at MIT, but besides that nothing.
>
> Any help would be great.

Markov chains e.g.
http://rubyquiz.com/quiz74.html

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


Re: Check for keypress on Linux xterm ?

2007-04-10 Thread hlubenow
Grant Edwards wrote:

> I do make mistakes, but before telling somebody he's wrong, it
> might be a good idea to actually try what he's suggested. ;)

I completely agree. The script waited at first for key-input, so I thought,
I was right. But I was not. I apologize !

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


Re: tuples, index method, Python's design

2007-04-10 Thread Antoon Pardon
On 2007-04-10, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Tue, 2007-04-10 at 13:21 +, Antoon Pardon wrote:
>> >  But if you are so eager to rewrite, how about the following:
>> > 
>> > I am using the struct module to get binary data from a file.
>> > Sometimes I want to skip until I find a particular binary
>> > number. Somewhat simplified it looks like this:
>> > 
>> > 
>> > class Itemfile:
>> >   def __init__(self, fn):
>> > self.fl = open(fn)
>> > self.ix = 80
>> > 
>> >   def nextitem(self):
>> > if self.ix == 80:
>> >   self.buf = struct.unpack("80i", self.fl.read(320))
>> >   self.ix = 0
>> > result = self.buf[self.ix]
>> > self.ix += 1
>> > return result
>> > 
>> >   def skipuntil(self, val):
>> > done = False
>> > while not done:
>> >   try:
>> > self.ix = self.buf.index(val, self.ix)
>> >done = True
>> >   except ValueError:
>> > self.ix = 0
>> >self.buf = struct.unpack("80i", self.fl.read(320))
>> > 
>> > 
>> > Now I'm sure you can rewrite this without the need of tuple.index.
>> > It just seems odd that I have to go through extra hoops here to
>> > get the effect of tuple.index because struct.unpack returns its result
>> > in a tuple and a tuple doesn't provide index.
>
> Your data is an array. Choosing a data structure that doesn't fit your
> data is always going to cause pain. Instead of using struct.unpack, you
> should use array.array, and voila!, you get an index method.

No it is not. This is exactly what I thought was going to happen. One
simplifies a problem so that the code is not too big to discuss here
and people will use characteristics of the simplified code to suggest
how one should have solved the problem differently.

I'm not interrested in going through such a merry around again.

As I said, writing an index function that works with any kind
of sequence is easy enough and once written can be used as
often as one whishes. So although I prefer more consistency
from a language that python currently provides the language
has enough going for it to stick with it dispite these kind
of warts. So having that function is a practical enough solution
for me. And curiously, having that function makes using
tuples no longer painfull in situations where other would
argue that tuples don't fit my data. If tuples don't fit
my data, I sure find it strange that one little function
causes you to no longer experience it as such.

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


Re: Check for keypress on Linux xterm ?

2007-04-10 Thread Grant Edwards
On 2007-04-10, hlubenow <[EMAIL PROTECTED]> wrote:

>>> My problem is, I don't want my program to wait for the
>>> keypress. I just want to check, if a key is currently pressed
>>> and if not, I'd like to continue with my program (like
>>> "INKEY$" in some BASIC-dialects).
>> 
>> The answer to this frequently asked question is actually in the FAQ:
>
> http://www.python.org/doc/faq/library.html#how-do-i-get-a-single-keypress-at-a-time
>
> You're answer is only less than half correct:
>
> Most of the given examples use something like
>
> c = sys.stdin.read(1)
>
> like my example does. This blocks input.

read() will not block if the file has been set to non-blocking
mode.  That's what these two lines in the FAQ answer do:

  oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
  fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)

I do make mistakes, but before telling somebody he's wrong, it
might be a good idea to actually try what he's suggested. ;)

-- 
Grant Edwards   grante Yow!  Edwin Meese made me
  at   wear CORDOVANS!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >