Let's Unite Against Jews and Mongrels!

2007-08-27 Thread Nenad Milicevic - The Aryan Serb
Rise up and shine, white sons and daughters
Rise up and shine, you gotta fight to part those waters
When we swim in the light, all will be okay
The black, yellow and brown man will wash away.
--
Let's break the chains of Jewish and black domination! Unite, white
brothers and sisters, and let's defeat those who oppress our white
heritage!

Our skin is our uniform!


Serbian Committee for Aryan Defence
Nenad Milicevic, executive
Usenet name: Raoul Endymion or Raul Endymion
ICQ 208030128
[EMAIL PROTECTED]
[EMAIL PROTECTED]
Belgrade, Serbia

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


Win32: Detecting when system is locked or sleeping

2007-08-27 Thread Muhammad_Shiraz

Hi

I saw your post on the net. We are having a similar problem. Did you
ever find out how to detect system lock? 

Muhammad Asif Shiraz
Dell Inc. - eIntelligence
Ph: 512.728.6479

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

Re: Co-developers wanted: document markup language

2007-08-27 Thread Wildemar Wildenburger
Robert Kern wrote:
> Wildemar Wildenburger wrote:
>   
>> Torsten Bronger wrote:
>> 
>>> Hallöchen!
>>>   
>>>   
>> Yes, you're German. Have you ever noticed that (we) Germans are 
>> virtually the only ones that feel the need to rub our nationality into 
>> everyones faces? ;)
>> 
>
> Howdy!
>
> We Americans do the same.  ;-)
>
>   
Weeell, you guys mostly rub your ignorance about the rest of the world 
into everyones faces. That's a little different.

There, I did it. Now I got my country invaded. But maybe that's a good 
thing ... at least we will get democracy and finally find happiness.

/W
(OK, sorry. I couldn't resist. Don't take it personally. Take it 
nationally. ;) )
-- 
http://mail.python.org/mailman/listinfo/python-list

POP3 - Saving an image attachment only.

2007-08-27 Thread Sick Monkey
I wrote some code below (Code1 block) which will read a pop3 email account
and will open each email in the inbox.
What I want my code to do is only pull the attachment; as you see below I
basically output everything.  Is there an easy way to just pull
attachments?  (NOTE, the only attachements that I want to pull are images)
===
I also tried this, but for some reason the part.get_filename Always equal
"None"

 msg = email.message_from_string(mstring)
 for part in msg.walk():
fn = part.get_filename()
if fn <>None:
   filenames.append(fn)
   attachedcontents.append(part.get_payload())
   print "im here"


*..::CODE1:..
===*
for email in items:
  id, size = string.split(email)
  resp, text, octets = server.retr(id)
  text = string.join(text, "\n")
  file = StringIO.StringIO(text)
  message = rfc822.Message(file)
  print message.fp.read()

*..::OUTPUT1::..
===*
--__CONTENT_64564_PART_BOUNDARY__33243242__
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by
njbrmotmta9.vzwpix.com id l7LIT1GZ008951

Some email text

--__CONTENT_64564_PART_BOUNDARY__33243242__
Content-Type: image/jpeg;
 name="0815071408.jpg"
Content-ID: <0815071408.jpg>
Content-Location: 0815071408.jpg
Content-Transfer-Encoding: base64

/9j/4AkjSkZYWAAQ/9j/2wCEABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdA
SFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2MBERISGBUYLxoaL2NCOEJjY2NjY2NjY2Nj
Y2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY//EAaIAAAEFAQEBAQEB
AAABAgMEBQYHCAkKCxAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJx
FDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZ
WmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLD
xMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6AQADAQEBAQEBAQEB
AQIDBAUGBwgJCgsRAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGx
wQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdo
aWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJ
ytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/AABEIAHgAoAMBIQACEQEDEQH/2gAMAwEA
AhEDEQA/AMead5GxnJ9KjaPYuTy1YtnQlYqk7ZM1dgl3Lg1b2MzZ02TMZX0qvr97cR2AtIjt
idsvjq1EZWkRKPMZ2j2U9xcIqxts/i4rv7SwW2gVFGB1NKb1HcfNEGXBFZstlDz8xBqAM+8Q
QoTnIrmtQuQcgGriJk3hqXF1IPUV10T5FWySXNJmkA1z8prjPEHf/eo6jRhir9r0q2NGnDG
XqNc5frnPrULMMk/NgdqkMoTB+XjrzVO4uBgDlyfQUpWa2KS7H//2Q==
--__CONTENT_64564_PART_BOUNDARY__33243242__--
-- 
http://mail.python.org/mailman/listinfo/python-list

Lists

2007-08-27 Thread Lamonte Harris
Ok

a = ['spam', 'eggs', 100, 1234]

So basically when I do
print a[1:-1]

that will display all the choices in the array besides 0,3

Slicing was kinda weird, just making sure.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to replace a method in an instance.

2007-08-27 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit :
> On Aug 22, 12:48 am, Bruno Desthuilliers
> <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] a écrit :
>>
(snip)

>>> Of course, a function in a
>>> class is also know as a method.
>> Less obvious but still wrong !-)
> 
> 
> I wish the authors of the Python books would get a clue then.

I'd think that at least some authors of some Python books would explain 
all this much better than I did. But FWIW, all these rules are clearly 
documented in the Fine Manual.

> 
(snip)
> I'm not going to help with these class / instance / whatever any more
> and leave it to all you professionals.

How do you think I learned ? One of the big things with usenet is that 
you get a chance to be corrected when you're wrong, and I personnally 
owe a lot of thanks to all the people that corrected me so far and still 
correct me.

> Yes, it you can use self in an outside method, but the way the OP
> asked the question and the nature of the traceback pointed to it just
> being a normal function, 

Indeed, Steve's problem was that the function he attached to his 
instance was *not* wrapped into a method object.

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


Best open source Python online *CHAT* apps?

2007-08-27 Thread [EMAIL PROTECTED]
Best open source Python online chat apps?

I believe there are a few PHP online chat apps to allow people to have
conversation
via a web server but a Python one would soothe the soul.

Any available?

Thanks,

Chris

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


Re: Chaining programs with pipe

2007-08-27 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Gabriel
Genellina wrote:

> On 22 ago, 11:08, Grant Edwards <[EMAIL PROTECTED]> wrote:
> 
>> but I'm a Unix guy who occasionally tries
>> to ship a Windows version of a Python app: the concept of a
>> process defaulting to having a stderr or stdout that wasn't
>> writable was utterly foreign to me.
>
> Ah, that explains your previous post telling that things on Windows
> don't work as they "should". They work, but not necesarily as a
> "foreigner" would expect.

So what's the good reason for Windows having unusable defaults for stderr
and stdout, then?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Win32: Detecting when system is locked or sleeping

2007-08-27 Thread Tim Golden
[EMAIL PROTECTED] wrote:

> I saw your post on the net. We are having a similar problem. Did you 
> ever find out how to detect system lock?

I can't seem to see the original post you're referring to
(reading this via the mailing list) but assuming that by
"locked" you mean: Ctrl-Alt-Del locked, then you can try
this technique:

http://timgolden.me.uk/python/win32_how_do_i/see_if_my_workstation_is_locked.html

and assuming that by "sleeping" you mean: in standby mode, then
you might be able to adapt this:

http://timgolden.me.uk/python/wmi_cookbook.html#monitor-multiple-machines-for-power-events

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


Re: pySerial in a daemon process

2007-08-27 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, paul
wrote:

> Before I had posted this question first thing I did was to look at /
> dev/ttyS0, and indeed the group is dialout (gid=20)...

What are the full protections on the serial port? That is, can you post the
output of

ls -l /dev/ttyS0

please?

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


Re: SCF released to GPL

2007-08-27 Thread M�ta-MCI \(MVP\)
Salut !

Le deuxième envoi aurait pu être en français.
Cela aurait évité le doublon, tout en maintenant le message.

@+

Michel Claveau

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


Re: my parser.py isn't imported

2007-08-27 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Torsten Bronger wrote:

> So I'd like to know a means to tell *explicitly* what I want to
> import.  Maybe I could use the imp module but that's ugly.

That seems to be the standard Python-provided way to explicitly import the
file you want from the place you want.

> I mean, there are hundreds of modules on my harddisk, so trying to avoid
> nameclashs should not be the solution...

That is what namespace qualifiers are for, e.g.

import my_custom_stuff.parser

versus

import parser

> John Machin writes:
>
>> 2. Failure to RTFabulousM:
>> """
>> Details of the module searching and loading process are
>> implementation and platform specific. It generally involves
>> searching for a ``built- in'' module with the given name and then
>> searching a list of locations given as sys.path.
>> """
> 
> ... the whole systems seems largely arbitrary, which I don't
> believe.  ;-)

The documentation  says quite
clearly that the search order is controlled by sys.path. So why not
manipulate that to get the effect you want?

> "parser" is built-in on Windows but not on Linux.

It is standard on all platforms
.

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


Re: my parser.py isn't imported

2007-08-27 Thread Torsten Bronger
Hallöchen!

John Machin writes:

> Torsten Bronger wrote:
>
>> I have a module parser.py in the same directory as the main
>> module.  In the main module, I import "parser".  On Linux, this
>> works as expected, however on Windows, it imports the stdlib
>> parser module.  sys.path[0] points to the directory of my
>> parser.py in both cases.  What went wrong here?
>
> [...]
>
> 2. Failure to RTFabulousM:
> """
> Details of the module searching and loading process are implementation
> and platform specific. It generally involves searching for a ``built-
> in'' module with the given name and then searching a list of locations
> given as sys.path.
> """

Okay, I did the following to avoid this:

import sys, os.path
modulepath = os.path.abspath(os.path.dirname(sys.argv[0]))
def import_local_module(name):
"""Load a module from the local modules directory.

Loading e.g. a local "parser" module is difficult because on
Windows, the stdlib parser module is a built-in and thus loaded
with higher priority.  With
http://www.python.org/dev/peps/pep-0328/ it may become simpler.

:Parameters:
  - `name`: name of the module, as it would be given to
``import``.

:Return:
  the module object or ``None`` if none was found

:rtype:
  module
"""
import imp
try:
return sys.modules[name]
except KeyError:
pass
fp, pathname, description = imp.find_module(name, [modulepath])
try:
return imp.load_module(name, fp, pathname, description)
finally:
# Since we may exit via an exception, close fp explicitly.
if fp:
fp.close()

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: ANN: SCF released GPL

2007-08-27 Thread Stefan Behnel
Alex Martelli wrote:
> hg <[EMAIL PROTECTED]> wrote:
>...
>> I am looking for a free subversion server resource to put the code ...
>> if you know of any.
> 
> Check out code.google.com -- it has a hosting service for open source
> code, too, these days (and it IS subversion).

It's Google, though, so it requires people to register with Google to work on
the project. Might be a blocker for some contributors.

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


Re: Let's Unite Against Jews and Mongrels!

2007-08-27 Thread Raptor

ra ra ra ra ra rara ra ra ra


you're so irrelevant man!!!



"Nenad Milicevic - The Aryan Serb" <[EMAIL PROTECTED]> wrote in 
message news:[EMAIL PROTECTED]
> Rise up and shine, white sons and daughters
> Rise up and shine, you gotta fight to part those waters
> When we swim in the light, all will be okay
> The black, yellow and brown man will wash away.
> --
> Let's break the chains of Jewish and black domination! Unite, white
> brothers and sisters, and let's defeat those who oppress our white
> heritage!
>
> Our skin is our uniform!
>
>
> Serbian Committee for Aryan Defence
> Nenad Milicevic, executive
> Usenet name: Raoul Endymion or Raul Endymion
> ICQ 208030128
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> Belgrade, Serbia
> 


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


Re: ANN: SCF released GPL

2007-08-27 Thread Stefan Behnel
Paul Rubin wrote:
> hg <[EMAIL PROTECTED]> writes:
>> I am looking for a free subversion server resource to put the code
>> ... if you know of any.
> 
> Does it have to be SVN?  I think Savannah and Sourceforge both still
> use CVS.

At least SF has usable Subversion support by now. You can choose between CVS
or SVN.

Berlios works alike, and it's Europe based.

http://developer.berlios.de/


> I'm not sure what Launchpad uses.

Launchpad is Ubuntu, meaning it uses Bazaar. It has SVN integration, though.

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


wx.grid and different Value Choice each line ?

2007-08-27 Thread BH
Hi,

Hox can I have different value choice for each line in a grid with 
wxPython ?
I want to develop a small software for satisfaction surveys. Each line 
of the grid is a different question. Sometimes answers are the sames 
between two lines, but sometimes not.

Thx,

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


Re: Lists

2007-08-27 Thread Wildemar Wildenburger
Lamonte Harris wrote:
> Ok
> a = ['spam', 'eggs', 100, 1234]
>
>
> So basically when I do
> print a[1:-1] 
>
> that will display all the choices in the array besides 0,3 
>
> Slicing was kinda weird, just making sure.
>
And your question is?

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


Re: how setup a dll file as a module?

2007-08-27 Thread Diez B. Roggisch
smalltalk wrote:

> 
> 
> in arcgis , arcgisscripting is a dll file
> there is a script as following:
> 
> import  arcgisscripting
> gp = arcgisscripting.create()
> 
> why can the script run?
> how can we setup a dll file as a module?

There can be python-extension that are essentially C-modules. You can write
them your own, or using various wrapper technologies. See 

http://docs.python.org/ext/ext.html

for starters, and google

SIP
boost::python
SWIG
PyRex

for more information.

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


Re: beginner, idomatic python 2

2007-08-27 Thread Steve Holden
bambam wrote:
[but he top-posted]
> "Dan Bishop" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> On Aug 23, 10:21 pm, "bambam" <[EMAIL PROTECTED]> wrote:
>>> Would someone like to suggest a replacement for this? This is a
>>> function that returns different kinds of similar objects, depending
>>> on what is asked for. PSP and PWR are classes.  I don't really
>>> want to re-write the calling code very much: I'm just wondering
>>> if the function can be replaced with some kind of OOP pattern.
>>>
>>> def Device(DeviceType):
>>> if DeviceType=='PSP':
>>> return PSP()
>>> elif DeviceType=="Power Supply"
>>> return PWR()
>>> etc...
>>>
>>> Thanks!
>> Typically, you'd use a dictionary:
>>
>> DEVICE_DICT = {
>>'PSP': PSP.
>>'Power Supply': PWR,
>># etc.
>> }
>>
>> and your function would simply return DEVICE_DICT[device_type]()
>>
 > Thank you. I didn't reply earlier because I was trying to get my
 > head around what you wrote, which was strange and foreign
 > to me.
 >
 > It seems to me that the dictionary object you suggested is a
 > direct replacement for the function code, only more efficient
 > because the case table is internalised with a hash table, and
 > the original if/elif/else case table was unlikely to be implemented
 > as a hash table.
 >
 > And presumably, it is idiomatic because Python programmers
 > expect to use dictionaries for their lookup tables.
 >
 > You have answered a question I didn't know enough to ask :~)
 > --which is why I started with the general question, so I don't
 > feel too stupid about that --.
 >
 > And now I wonder about the 'other' question. Should I consider
 > dynamically overriding the methods in my 'Device' class, instead
 > of creating separate classes for the Psp and Pwr devices?
 > I could create an object of the base Device class, and at init
 > I could make sure the methods were connected for a Psp or
 > a Pwr device. When (if ever) is that a good idea?
 >
The fact that it's technically possible in Python doesn't mean it's 
always a good idea. I prefer to reserve that kind of behavior for when 
the effective behavior of an object needs to change after it's been 
created. Here you know at creation time which type you want, so it makes 
sense to me to create exactly that kind of object. Otherwise you are 
obscuring your program's structure by using dynamic type modification 
unnecessarily.

Just my $0.02, others will have different opinions.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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


Python-URL! - weekly Python news and links (Aug 27)

2007-08-27 Thread Gabriel Genellina
QOTW:  "There is something to be said for Python's 'elitism' ;)" - Carsten
Haese

"While the discipline of TDD is good and useful, there's a time and place
for unstructured and informal experimentation too." - Steven D'Aprano


Issue tracker migration is complete - now at
http://bugs.python.org and based on Roundup.

http://groups.google.com/group/comp.lang.python/browse_thread/thread/7cc2fc8f85b9e5cf/c582a66d35a03e7c

How to properly cleanup resources (don't rely on __del__ for this)

http://groups.google.com/group/comp.lang.python/browse_thread/thread/6f5784070d7b6b64/fee0c252b4311c1f

How to open a file using its associated application (multi-platform)

http://groups.google.com/group/comp.lang.python/browse_thread/thread/4913652c4cce31a4/42c670204411f000

For number-crunching lawyers: does shuffle() produce a uniform
distribution()?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/48931f2f7ca7b49e/22fa264d9706d2d6

Replacing a method with another depending on the instance.

Bonus for language lawyers: the difference between functions and
methods, and how the descriptor protocol works in short.

http://groups.google.com/group/comp.lang.python/browse_thread/thread/47cec38e789032be/832f0f648e6893a4#a1b7360e83905033

Sometimes -e.g. for benchmarking- one wants to purge the disk cache

http://groups.google.com/group/comp.lang.python/browse_thread/thread/1273b79934a3e3e9/0b4e52a7bfa4e922

Do some foolish things when creating a class, and you'll need
a Python guru to understand what really happened

http://groups.google.com/group/comp.lang.python/browse_thread/thread/4373307ef75d1278/a8610ba4e2f9d9ef

Learning Python using a book based on version 1.5: some people
say "OK", other say "No"

http://groups.google.com/group/comp.lang.python/browse_thread/thread/ffcccbdcae177ff/75b819d9c362b4ca

A small trick: how to generate short exception names

http://groups.google.com/group/comp.lang.python/browse_thread/thread/54c9b0f626b6a8fe/562c3a6eace389fd

A proposal for a new document markup language (a LaTeX competitor)

http://groups.google.com/group/comp.lang.python/browse_thread/thread/6b72f25206aacf7/7242c98c672a21e6



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish "the efforts of Python enthusiats":
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the "Planet" sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Python411 indexes "podcasts ... to help people learn Python ..."
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

Steve Bethard continues the marvelous tradition early borne by
Andrew Kuchling, Michael Hudson, Brett Cannon, Tony Meyer, and Tim
Lesher of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
 

Re: Error with long running web spider

2007-08-27 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Josh
Volz wrote:

> My problem is that I keep having an issue where the
> program appears to freeze.  Once this freezing happens the activity of
> the program drops to zero.  No exception is thrown or caught.  The
> program simply stops doing anything.  It even stops printing out its
> activity to stdout.

What happens afterwards? Does it continue running as though nothing had
happened? Throw an exception?

>From the output that appears beforehand, does it look like the freeze is
always happening in the same place?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how setup a dll file as a module?

2007-08-27 Thread smalltalk
On Aug 27, 6:45 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> smalltalk wrote:
>
> > in arcgis , arcgisscripting is a dll file
> > there is a script as following:
>
> > import  arcgisscripting
> > gp = arcgisscripting.create()
>
> > why can the script run?
> > how can we setup a dll file as a module?
>
> There can be python-extension that are essentially C-modules. You can write
> them your own, or using various wrapper technologies. See
>
> http://docs.python.org/ext/ext.html
>
> for starters, and google
>
> SIP
> boost::python
> SWIG
> PyRex
>
> for more information.
>
> Diez

thank you very much

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


Re: non-blocking communication with imaplib

2007-08-27 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Igor V. Rafienko wrote:

> I would like to talk to an IMAP-server, imaplib being the tool of
> choice, of course. Unfortunately it may happen that the IMAP-server
> fails to respond to certain commands, and I would like to be able to
> detect that within a given time period (on the scale of 5-10 seconds).
> 
> Initially, I thought about playing with setsockblocking() for the
> communication socket in the imaplib.IMAP4 object. However, the IMAP4
> object uses a file object ("created from" the said socket), and the
> underlying socket must be blocking according to [1].
>
> [1] 

According to the documentation
, you can override
the "read" and "readline" methods. How about replacing them with routines
that use select.select on the socket() object to implement a timeout?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beginner, idomatic python 2

2007-08-27 Thread Bruno Desthuilliers
bambam a écrit :

Steve, could you please stop top-posting ?-) TIA 

> "Dan Bishop" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>> On Aug 23, 10:21 pm, "bambam" <[EMAIL PROTECTED]> wrote:
>>> Would someone like to suggest a replacement for this? This is a
>>> function that returns different kinds of similar objects, depending
>>> on what is asked for. PSP and PWR are classes.  I don't really
>>> want to re-write the calling code very much: I'm just wondering
>>> if the function can be replaced with some kind of OOP pattern.
>>>
>>> def Device(DeviceType):
>>> if DeviceType=='PSP':
>>> return PSP()
>>> elif DeviceType=="Power Supply"
>>> return PWR()
>>> etc...
>>>
>>> Thanks!
>> Typically, you'd use a dictionary:
>>
>> DEVICE_DICT = {
>>'PSP': PSP.
>>'Power Supply': PWR,
>># etc.
>> }
>>
>> and your function would simply return DEVICE_DICT[device_type]()
>>
> Thank you. I didn't reply earlier because I was trying to get my
> head around what you wrote, which was strange and foreign
> to me.
> 
> It seems to me that the dictionary object you suggested is a
> direct replacement for the function code,

Almost, yes !-)

> only more efficient
> because the case table is internalised with a hash table, and
> the original if/elif/else case table was unlikely to be implemented
> as a hash table.
> 
> And presumably, it is idiomatic

It is. Dicts are probably the central data structure in Python, and are 
highly optimised. You'll find quite a lot of dict-based dispatch in 
Python code.

> because Python programmers
> expect to use dictionaries for their lookup tables.

Indeed - that's what dictionnaries are for.

> You have answered a question I didn't know enough to ask :~)
> --which is why I started with the general question, so I don't
> feel too stupid about that --.
> 
> And now I wonder about the 'other' question. Should I consider
> dynamically overriding the methods in my 'Device' class, instead
> of creating separate classes for the Psp and Pwr devices?
> I could create an object of the base Device class, and at init
> I could make sure the methods were connected for a Psp or
> a Pwr device. When (if ever) is that a good idea?

While it's technically possible, I wouldn't advise such a design (which 
looks pretty close to the Prototype pattern) unless you need to have 
something *highly* extensible and customisable (and even then, there are 
other - possibly better - ways, depending on the context). If the Device 
taxonomy is stable and well defined, you're certainly 
DoingTheSimplestThing (here, a dict-based dispatch encapsulated in a 
factory function...).

As a side note, in Python, inheritance is mostly an implementation 
detail, and should usually not be used for typing.

My 2 cents...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: beginner, idiomatic python

2007-08-27 Thread Bruno Desthuilliers
bambam a écrit :
> Thank you, I have been through the tutorial several times, I guess
> I'm just not smart enough. Perhaps I have been led astray by what
> I read here?
> 
> My code started like this:
> 
> for i in range(self.parent.GetPageCount()):
> 
> I was asked:
> 
>> Does page count change? i.e. is it necessary to retrieve it in every loop
> 
> 
> Is self.parent.GetPageCount() 'retrieved every loop'?

If your question is 'is self.parent.GetPageCount()' called for each 
iteration of this loop, then the answer is obviously 'no', and it's 
quite easy to check it out:

Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> def test():
... print "test called"
... return range(5)
...
 >>> for x in test(): print x
...
test called
0
1
2
3
4
 >>>


Now if you need to use the result of self.parent.GetPageCount() more 
than once in the same function and this result is not likely to change 
during the function's execution, you're certainly better storing it in a 
local variable - but now that's such a CS101 thing that it's probably 
not even worth mentionning.

IOW, Zentrader's remark was at best misleading, at worst plain wrong...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Problem from complex string messing up

2007-08-27 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] wrote:

> Well, anyway, a
> javascript error pops-up somewhere in that code after I run my script
> on the files.

What is the error? In Firefox, under the "Tools" menu, select "Error
Console". Click the "Clear" icon to get rid of whatever junk may already
have accumulated, then go to view your page and see what new errors appear.

While you're at it, you may want to reformat that JavaScript code for
clarity.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: expat error, help to debug?

2007-08-27 Thread Andreas Lobinger
Aloha,

Lawrence D'Oliveiro wrote:
> In message <[EMAIL PROTECTED]>, Andreas Lobinger wrote:
>>Anyone any idea where the error is produced?

> Do you want to try adding an EndElementHandler as well, just to get more
> information on where the error might be happening?

I want.

Adding an EndElement (left as an exercise to the user) handler the
output looks like this:
[42] scylla(scylla)> python pbxml.py s3.xml
s 7 book {}
x bookinfo bookinfo.xml None
s 9 chapter {u'id': u'technicalDescription'}
s 9 title {}
e title
s 10 para {}
e para
e chapter
e book
Traceback (most recent call last):
   File "pbxml.py", line 29, in ?
 fromxml(sys.argv[1])
   File "pbxml.py", line 24, in fromxml
 p.ParseFile(file(fname))
TypeError: an integer is required

which shows me that the error is caused after parsing the /book ...
BUT still within p.ParseFile (expat internal), so i can't look
into it.

The example here may be missleading. It was stripped down from
a quite large docbook.xml and there ther error happened in the
middle of the document, not at the end.

Wishing a happy day,
LOBI
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parser Generator?

2007-08-27 Thread Paul McGuire
On Aug 26, 10:48 pm, Steven Bethard <[EMAIL PROTECTED]> wrote:
> Paul McGuire wrote:
> > On Aug 26, 8:05 pm, "Ryan Ginstrom" <[EMAIL PROTECTED]> wrote:
> >> The only caveat being that since Chinese and Japanese scripts don't
> >> typically delimit "words" with spaces, I think you'd have to pass the text
> >> through a tokenizer (like ChaSen for Japanese) before using PyParsing.
>
> > Did you think pyparsing is so mundane as to require spaces between
> > tokens?  Pyparsing has been doing this type of token-recognition since
> > Day 1.  Looking for tokens without delimiting spaces was one of the
> > first applications for pyparsing.  This issue is not unique to Chinese
> > or Japanese text.  Pyparsing will easily find the tokens in this
> > string:
>
> > y=a*x**2+b*x+c
>
> > as
>
> > ['y','=','a','*','x','**','2','+','b','*','x','+','c']
>
> The difference is that in the expression above (and in many other
> tokenization problems) you can determine "word" boundaries by looking at
> the class of character, e.g. alphanumeric vs. punctuation vs. whatever.
>
> In Japanese and Chinese tokenization, word boundaries are not marked by
> different classes of characters. They only exist in the mind of the
> reader who knows which sequences of characters could be words given the
> context, and which sequences of characters couldn't.
>
> The closest analog would be to ask pyparsing to find the words in the
> following sentence:
>
> Thepyparsingmoduleprovidesalibraryofclassesthatclientcodeusestoconstructthe­grammardirectlyinPythoncode.
>
> Most approaches that have been even marginally successful on these kinds
> of tasks have used statistical machine learning approaches.
>
> STeVe- Hide quoted text -
>
> - Show quoted text -

Steve -

You mean like this?

from pyparsing import *

knownWords = ['of', 'grammar', 'construct', 'classes', 'a',
'client', 'pyparsing', 'directly', 'the', 'module', 'uses',
'that', 'in', 'python', 'library', 'provides', 'code', 'to']

knownWord = oneOf( knownWords, caseless=True )
sentence = OneOrMore( knownWord ) + "."

mush =
"ThepyparsingmoduleprovidesalibraryofclassesthatclientcodeusestoconstructthegrammardirectlyinPythoncode."

print sentence.parseString( mush )

prints:

['the', 'pyparsing', 'module', 'provides', 'a', 'library', 'of',
'classes', 'that', 'client', 'code', 'uses', 'to', 'construct',
'the', 'grammar', 'directly', 'in', 'python', 'code', '.']

In fact, this is almost the exact scheme used by Zhpy for extracting
Chinese versions of Python keywords, and mapping them back to English/
Latin words.  Of course, this is not practical for natural language
processing, as the vocabulary gets too large. And you can get
ambiguous matches, such as a vocabulary containing the words ['in',
'to', 'into'] - the runtogether "into" will always be assumed to be
"into", and never "in to".  Fortunately (for pyparsing), your example
was sufficiently friendly as to avoid ambiguities.  But if you can
select a suitable vocabulary, even a runon mush is parseable.

-- Paul


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

Re: wx.grid and different Value Choice each line ?

2007-08-27 Thread kyosohma
On Aug 27, 5:08 am, BH <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Hox can I have different value choice for each line in a grid with
> wxPython ?
> I want to develop a small software for satisfaction surveys. Each line
> of the grid is a different question. Sometimes answers are the sames
> between two lines, but sometimes not.
>
> Thx,
>
> Bertrand

I don't know if you can insert a combobox into a grid object or not.
It's probably possible. You should post your question to the wxPython
group though since this is a very specific issue. See here:
http://www.wxpython.org/maillist.php

If it was me though, I would probably use a wizard and put my
questions and choices on it. Or maybe use a notebook control.

Mike

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


RE:question

2007-08-27 Thread JYOUNG79
Hi MRAB,

Thanks so much for taking the time to help me with this!  I've learned a ton 
from the 
example you sent!  I 
studied each part of your code so I could get a good understanding of how it 
worked.  There 
was one question I 
had; on the regex line, you used "(\d+)$" and I was curious why you used the 
parenthesis 
around the '\d+'?

After studying the 'listdir' a bit, I realized it only grabbed the files from 
the current directory I 
was in.  I went 
online and with a little bit of searching I found 'walk'.  I'm not sure if I'm 
using this correctly, 
but I found a way 
to use 'walk' to grab all the appropriate files in nested folders too (I 
attached the code below).  
I'm really 
impressed with the power of Python!!

Again, thanks MRAB for the incredible help you've given me.  I really 
appreciate it!!  :-)

Jay

#!/usr/bin/python

import os
import re

folder = "~/Desktop/logoFiles/"

pathList = []

for root, dirs, files in os.walk(folder):
  for name in files:
if name.upper().startswith("LOGO"):
pathList.append(os.path.join(root, name))

dList = {}

for x in pathList:
parts = x.split("/")
if parts[-2].isdigit():  # Make sure folder name is a number
n = re.findall(r"(\d+)$", parts[-1])   # Grab number off file name
if n:
dList[int(n[0])] = "%s<::>LOGO%s\n" % (x, n[0])

keyList = dList.keys()
keyList.sort()

sortedList = "".join([dList[x] for x in keyList])

newFile = open("/Users/jyoung1/Desktop/LogoBook_Data/sortedData.txt", "w")
newFile.write(sortedList)
newFile.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Let's Unite Against Jews and Mongrels!

2007-08-27 Thread Lost in the Wasteland
Nenad Milicevic - The Aryan Serb wrote:

> Belgrade, Serbia
> 

  Looks like a nice place to vacation.

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


Re: wxpython on FreeBSD 6.2 broken

2007-08-27 Thread kyosohma
On Aug 26, 7:35 am, Michael S <[EMAIL PROTECTED]> wrote:
> Good day all,
>
> I was wondering if anyone was using the latest
> wxpython on FreeBSD 6. I just installed it yesterday
> as well as wxGlade. wxGlade doesn't function properly
> - it does not display any controls. I then tried some
> simple examples from the web and half of them don't
> work.
>
> Anyone aware of this?
> Michael

I'm not, but the wxpython group might. Try posting there:
http://www.wxpython.org/maillist.php

Mike

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


Re: Best open source Python online *CHAT* apps?

2007-08-27 Thread kyosohma
On Aug 27, 3:12 am, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Best open source Python online chat apps?
>
> I believe there are a few PHP online chat apps to allow people to have
> conversation
> via a web server but a Python one would soothe the soul.
>
> Any available?
>
> Thanks,
>
> Chris

Dunno, but I see Gozerbot just had another release. Check it out. I
also found this link, but my business blocks it so I'm not sure how
useful it is: 
http://www.bigwebmaster.com/Python/Scripts_and_Programs/Chat_Scripts/

Mike

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


How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread rfv-370
have made the following small test:

Before starting my test my UsedPhysicalMemory(PF): 555Mb

>>>tf=range(0,1000)PF: 710Mb ( so 155Mb for my List)
>>> tf=[0,1,2,3,4,5] PF: 672Mb (Why? Why the remaining 117Mb is not 
>>> freed?)
>>> del tfPF: 672Mb (unused memory not freed)

So changing the list contents and/or deleting the list changes
nothing...from a memory point of view.

This is a problem as I have several applications/threads competing for
memory share. (ie wxpython app).

So how can I force Python to clean the memory and free the memory that
is not used?


PS: gc.collect() does nothing - To return memory I need to kill my
process (ie the interpreter).

Any ideas is welcome.

Thanx

Robert

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


Re: Parser Generator?

2007-08-27 Thread Steven Bethard
Paul McGuire wrote:
> On Aug 26, 10:48 pm, Steven Bethard <[EMAIL PROTECTED]> wrote:
>> In Japanese and Chinese tokenization, word boundaries are not marked by
>> different classes of characters. They only exist in the mind of the
>> reader who knows which sequences of characters could be words given the
>> context, and which sequences of characters couldn't.
>>
>> The closest analog would be to ask pyparsing to find the words in the
>> following sentence:
>>
>> Thepyparsingmoduleprovidesalibraryofclassesthatclientcodeusestoconstructthe­grammardirectlyinPythoncode.
>>
>> Most approaches that have been even marginally successful on these kinds
>> of tasks have used statistical machine learning approaches.
> 
> You mean like this?
> 
> from pyparsing import *
> 
> knownWords = ['of', 'grammar', 'construct', 'classes', 'a',
> 'client', 'pyparsing', 'directly', 'the', 'module', 'uses',
> 'that', 'in', 'python', 'library', 'provides', 'code', 'to']
> 
> knownWord = oneOf( knownWords, caseless=True )
> sentence = OneOrMore( knownWord ) + "."
> 
> mush =
> "ThepyparsingmoduleprovidesalibraryofclassesthatclientcodeusestoconstructthegrammardirectlyinPythoncode."
> 
> print sentence.parseString( mush )
> 
> prints:
> 
> ['the', 'pyparsing', 'module', 'provides', 'a', 'library', 'of',
> 'classes', 'that', 'client', 'code', 'uses', 'to', 'construct',
> 'the', 'grammar', 'directly', 'in', 'python', 'code', '.']
> 
> In fact, this is almost the exact scheme used by Zhpy for extracting
> Chinese versions of Python keywords, and mapping them back to English/
> Latin words.  Of course, this is not practical for natural language
> processing, as the vocabulary gets too large. And you can get
> ambiguous matches, such as a vocabulary containing the words ['in',
> 'to', 'into'] - the runtogether "into" will always be assumed to be
> "into", and never "in to".

Yep, and these kinds of things occur quite frequently with Chinese and 
Japanese. The point was not that pyparsing couldn't do it for a small 
subset of characters/words, but that pyparsing is probably not the right 
solution for general purpose Japanese/Chinese tokenization.

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


Image.open( "C:\test.jpg") is this wrong ?

2007-08-27 Thread Carnell, James E


> I am trying to simply open an image with PIL... My problem is that I
> don't know what my active directory is so I am putting an absolute
> path name in quotes. It can't find the specified file or directory.
> I'm horrible with docs. I also tried to save an image file (to find
> where it saved it, but I didn't understand what mode is (I now know it
> is RGB etc.). Does everyone usually do fairly well with the docs
> except for me??? For instance, it says Image.open(file, ...something
> else [I'm at work so I don't remember]). How am I supposed to know
> even to put quotes around the filepath? I'm really starting to wonder
> if there is something wrong with me.
> 
> So How do I open an image?
> 
> Image.open("C:\test.jpg")  # this is what I have right now. And it
> can't find the file or directory. The file is there (it is everywhere
> on my computer now!!!)
> 
I found some code where they apply the file path to a variable in single
quotes. Is that how it is done. Also I thought single quotes were for
characters not strings.

> Sincerely,
> 
> James Carnell
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread Alex Martelli
rfv-370 <[EMAIL PROTECTED]> wrote:

> have made the following small test:
> 
> Before starting my test my UsedPhysicalMemory(PF): 555Mb
> 
> >>>tf=range(0,1000)PF: 710Mb ( so 155Mb for my List)
> >>>tf=[0,1,2,3,4,5] PF: 672Mb (Why? Why the remaining 117Mb is
> >>>not freed?) del tfPF: 672Mb (unused memory
> >>>not freed)

Integer objects that are once generated are kept around in a "free list"
against the probability that they might be needed again in the future (a
few other types of objects similarly keep a per-type free-list, but I
think int is the only one that keeps an unbounded amount of memory
there).  Like any other kind of "cache", this free-list (in normal
cases) hoards a bit more memory than needed, but results in better
runtime performance; anomalous cases like your example can however
easily "bust" this too-simple heuristic.

> So how can I force Python to clean the memory and free the memory that
> is not used?

On Windows, with Python 2.5, I don't know of a good approach (on Linux
and other Unix-like systems I've used a strategy based on forking, doing
the bit that needs a bazillion ints in the child process, ending the
child process; but that wouldn't work on Win -- no fork).

I suggest you enter a feature request to let gc grow a way to ask every
type object to prune its cache, on explicit request from the Python
program; this will not solve the problem in Python 2.5, but work on 3.0
is underway and this is just the right time for such requests.


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


Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread MC
Hi!

For windows, I had a soft for this (reduce_memory.exe). Sorry, it's not 
write with Python.

If you want, I will give a URL for download it.

-- 
@-salutations

Michel Claveau


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


Re: How to replace a method in an instance.

2007-08-27 Thread Alex Martelli
Bruno Desthuilliers <[EMAIL PROTECTED]>
wrote:

> >>> Of course, a function in a
> >>> class is also know as a method.
> >> Less obvious but still wrong !-)
> > 
> > I wish the authors of the Python books would get a clue then.
> 
> I'd think that at least some authors of some Python books would explain
> all this much better than I did. But FWIW, all these rules are clearly
> documented in the Fine Manual.

Speaking as one such author, I think I do a reasonable job of this in
"Python in a Nutshell" (2nd ed): on p. 82 and 85 I have brief mentions
that "class attributes bound to functions are also known as methods of
the class" (p.82) and again that "functions (called methods in this
context) are important attributes for most class objects" (p.85); on
p.91-94, after explaining descriptors, instances, and the basics of
attribute reference, I can finally cover the subject thoroughly in
"Bound and Unbound Methods".  I realize that a beginner might be
confused into believing that "class attributes bound to functions" means
"function in a class", if they stop reading before p.91;-), but I don't
literally make that wrong assertion...;-)


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


getLabel() CD-ROM

2007-08-27 Thread Guillermo Heizenreder
Hi list, I'm new whit pygtk library.

I'm interest to know if there is a class in the graphics library that it
can provide me with information about the CD-ROM label ( something
similar to class KMount in the graphic library pykde[1]).

At the time I'm using pycdio class[2],but i don't wont to my application
by dependent on the above class mentioned.

Thanks and kind regards from Argentina.

P/D: my English it to bad, I'm a novice. 

[1]http://www.riverbankcomputing.com/Docs/PyKDE3/classref/allclasses.html
[2]http://pypi.python.org/pypi/pycdio/0.12




-- 
Heizenreder Guillermo
http://code.google.com/u/gheize/

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


Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread Marc 'BlackJack' Rintsch
On Mon, 27 Aug 2007 07:18:26 -0700, rfv-370 wrote:

> have made the following small test:
> 
> Before starting my test my UsedPhysicalMemory(PF): 555Mb
> 
tf=range(0,1000)PF: 710Mb ( so 155Mb for my List)
 tf=[0,1,2,3,4,5] PF: 672Mb (Why? Why the remaining 117Mb is 
 not freed?)
 del tfPF: 672Mb (unused memory not freed)
> 
> So changing the list contents and/or deleting the list changes
> nothing...from a memory point of view.

>From the OS memory point of view to be precise.  Although here the integer
cache applies as Alex pointed out, in the general case memory might be
kept allocated by Python to be re-used later.  The Python allocator is
better suited for frequent allocation and deallocation of many small
objects than `malloc()` from the C standard library is.  And even a
`free()` in the C standard library doesn't guarantee that memory is given
back to the OS and reported as free memory again.

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


Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread Peter Otten
Alex Martelli wrote:

> Integer objects that are once generated are kept around in a "free list"
> against the probability that they might be needed again in the future (a

Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 1000
>>> y = 1000
>>> x is y
False

Why don't x and y point to the same object then?

Peter
 

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


Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread Peter Otten
Peter Otten wrote:

> Alex Martelli wrote:
> 
>> Integer objects that are once generated are kept around in a "free list"
>> against the probability that they might be needed again in the future (a
> 
> Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
> [GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
 x = 1000
 y = 1000
 x is y
> False
> 
> Why don't x and y point to the same object then?
> 
> Peter

Oops, I think I got it now. The actual objects are freed, only the memory is
kept around for reuse with other ints...

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


Re: comparing two lists

2007-08-27 Thread Ladislav Andel
I have learnt a lot from your example and used it for my purpose.
Thank you, it very helped me.
Lada

Peter Otten wrote:
> Ladislav Andel wrote:
>
>   
>> need to be stopped before deleting any instance from items.
>> So I need to call stopLoop method in the given item in items before it
>> gets removed.
>> If there is any addition to items it's quite easy to call
>> item.startLoop() method.
>> 
>
> Unless you want to rely on the __del__ method or introduce another
> complication (weak references) you have to be explicit:
>
> # untested
> # removing items
> db_items = set(Item(**d) for d in dblist)
> delenda = items - db_items
> for item in delenda:
> item.stopLoop()
> items.remove(item)
>
>   
>> (I use twisted but it should not make any difference):
>> 
>
> I've not worked with twisted, so I can't confirm that.
> I can imagine that they provide their own way to spell a finalizer...
>
> Peter
>   

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


Re: Image.open( "C:\test.jpg") is this wrong ?

2007-08-27 Thread Simon Brunning
On 8/27/07, Carnell, James E <[EMAIL PROTECTED]> wrote:

> Image.open("C:\test.jpg")

Try:

Image.open(r"C:\test.jpg")

See http://docs.python.org/ref/strings.html

-- 
Cheers,
Simon B.
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues
-- 
http://mail.python.org/mailman/listinfo/python-list


weird edgecolumn behavior in scintilla

2007-08-27 Thread SHY
hey everyone,

i decided its time to heavily improve myself in python-gui programming and
so i started building my own editor/ide for PHP. so far, most of the
general/basic features are inspired (read: mostly copy-pasted) by eric4 IDE
build upon qt4/scintilla combination.

but i came across to a weird problem with the scintilla's edgemodes. when i
set it up to edgeline mode and the edgecolumn is set to 80, the edgeline is
drawn (assuming the default scintilla settings) at approximately 50th
character from the left (and 30th character when the lexer is off - aka txt
files), instead of the expected 80. ive tried to play around with the
lexers' styles to change fonts (courier new, size 10) and stuff but it keeps
drawing the line on 50th column.

ive made a non-elegant and non-pragmatic workaround to this, by setting the
edgecolumn to 128 when the lexer is turned on and 213 when it is off. both
values approximately match the 80th column for courier-new size 10.

i originally thought that the column length for the edgecolumn value is
computed from the character width of the particular font, and so that by
changing the font or its size, the edgecolumn would change appropriately.
dunno if this is the problem of scintilla (cause the exactly same thing is
present in eric4 as well) or i just missed some important setting.

this is the code that handles the edgecolumn stuff when the editor is
launched:

[code]
edgeMode = Preferences.getEditor("EdgeMode")
edge = QsciScintilla.EdgeMode(edgeMode)
self.setEdgeMode(edge)
if edgeMode:
self.setEdgeColumn(Preferences.getEditor("EdgeColumn"))
self.setEdgeColor(Preferences.getEditorColour("Edge"))

[/code]

the EdgeColumn preferences value defaults to 80.

any ideas?

thanks in advance.
SHY
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Image.open( "C:\test.jpg") is this wrong ?

2007-08-27 Thread Tim Williams
On 27/08/07, Simon Brunning <[EMAIL PROTECTED]> wrote:
> On 8/27/07, Carnell, James E <[EMAIL PROTECTED]> wrote:
>
> > Image.open("C:\test.jpg")
>
> Try:
>
> Image.open(r"C:\test.jpg")
>
> See http://docs.python.org/ref/strings.html

r"C:\test.jpg"

also

"C:\\test.jpg"  or  'C:/test.jpg'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: passing arguments with ampersands

2007-08-27 Thread SHY
that was the problem. when i manually reassociated the extension, i somehow
didnt quote the argument for the filename. my bad.

thanks for the various explanations and options for this :)

cheers.

2007/8/20, Gabriel Genellina <[EMAIL PROTECTED]>:
>
> En Sat, 18 Aug 2007 09:24:35 -0300, SHY <[EMAIL PROTECTED]> escribi�:
>
> > theres no special portion of code, just the one that handles filenames
> > with
> > spaces.
> > the problem is that when i associate a file extension to my application
> > and
> > i open it, the filename is not quoted before passed as an arguement. i
> > dont
> > know if its the problem of windows or something, or it was just my fault
> > when i incorrectly associated the extension.
>
> How did you associate it?
> Usually the registry entries are:
>
> HKCR\.ext = filetype
> HKCR\filetype = File Description
> HKCR\filetype\shell\open\command = "path\to\your\program" "%1"
>
> (Note the double quotes around %1)
>
> Get it right at the registry, and forget all that trickery joining
> sys.argv parts
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/mailman/listinfo/python-list
-- 
http://mail.python.org/mailman/listinfo/python-list

sorting a list of lists

2007-08-27 Thread nicksavill
Hi,

i would like to sort a list of lists. The list is first sorted on the
second item in the sub-lists (which I can do), then on the third item
(which I can't).

eg. records = [['dog',1,2], ['chair',2,1], ['cat',1,3], ['horse',3,4],
['table',3,2], ['window',3,5]]

I want sorted to [['dog',1,2], ['cat',1,3], ['chair',2,1], ['table',
3,2], ['horse',3,4], ['window',3,5]]

To sort on the second item in the sub-lists I do the following

pass1 = itemgetter(1)
sorted(records, key=pass1)

How can I then sort on the third item in the sub-lists whilst keeping
the order on the second item?

Nick

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


Re: sorting a list of lists

2007-08-27 Thread Peter Otten
 [EMAIL PROTECTED] wrote:

> i would like to sort a list of lists. The list is first sorted on the
> second item in the sub-lists (which I can do), then on the third item
> (which I can't).
> 
> eg. records = [['dog',1,2], ['chair',2,1], ['cat',1,3], ['horse',3,4],
> ['table',3,2], ['window',3,5]]
> 
> I want sorted to [['dog',1,2], ['cat',1,3], ['chair',2,1], ['table',
> 3,2], ['horse',3,4], ['window',3,5]]
> 
> To sort on the second item in the sub-lists I do the following
> 
> pass1 = itemgetter(1)
> sorted(records, key=pass1)
> 
> How can I then sort on the third item in the sub-lists whilst keeping
> the order on the second item?

list.sort() is stable, so

items = sorted(records, key=itemgetter(2)) # minor order first
items.sort(key=itemgetter(1)) # major order

should give the desired result (items with equal item[1] are sorted by
item[2]. Python 2.5 also allows to pass multiple indices to itemgetter()

sorted(records, key=itemgetter(1, 2))

IIRC for Python 2.4 you'd have to write your own key routine:

def key(item):
return item[1], item[2]
sorted(records, key=key)

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


Re: Python error on Mac

2007-08-27 Thread Jay Loden
Clover wrote:
> When trying to do some things on my Mac (starting Lyx, compiling Latex 
> via TextMate) I get this error:
> 
> python: execv: 
> /Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python:
>  
> No such file or directory
> 
> I (and people on Lyx and TextMate lists) are at a complete loss as to 
> why this is happening. I didn't (at least intentionally) fiddle with 
> Python setup.
> 
> Thanks!

what is the output of 'which python' - this should show what python executable 
is running: 

[EMAIL PROTECTED] jloden]$ which python
/Library/Frameworks/Python.framework/Versions/Current/bin/python

You should then check the output of ls -l agains the value of the above: 

[EMAIL PROTECTED] jloden]$ ls -l 
/Library/Frameworks/Python.framework/Versions/Current/bin/python
lrwxr-xr-x   1 root  admin  9 Jul 14 01:53 
/Library/Frameworks/Python.framework/Versions/Current/bin/python -> python2.5

That will show what the executable is actually linked to. 

Other thoughts would be to check if the 
/Library/Frameworks/Python.framework/Versions/2.5/Resources/Python.app/Contents/MacOS/Python
 directory exists, or even if 
/Library/Frameworks/Python.framework/Versions/2.5/ exists. Perhaps you are 
trying to execute Python 2.5 but don't actually have it installed? 

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


Re: the del function

2007-08-27 Thread Matt McCredie
> For some odd reason the del array[ray] isn't actually deleting the array
> item in the list I get the following output:
>
> C:\Documents and
> Settings\program\Desktop\python\pygame>remix.py
> [2, 2, 2, 4, 4, 4, 4, 3, 3, 3, 3]
> [2, 2, 2, 4, 4, 4, 4, 3, 3, 3, 3]
> [2, 2, 2, 2, 4, 4, 4, 3, 3, 3, 3]
> [2, 2, 2, 2, 4, 4, 4, 3, 3, 3, 3]
> [2, 2, 4, 4]
>
> The _red function is fine, but the del function isn't working.  What did I
> do wrong?

The code is doing what you told it to:

[code]
while x < 4:
array = single_players[4:17] # <-- you are re-creating `array' in every loop
length = len(array) - 1
ray = random.randint(0,length)
_red[x] = array[ray]
del array[ray]
print array
x = x + 1
print _red
[/code]

My guess is that you want this:

[code]
array = single_players[4:17]
while x < 4:
length = len(array) - 1
ray = random.randint(0,length)
_red[x] = array[ray]
del array[ray]
print array
x = x + 1
print _red
[/code]

I'm sure you could do something with random.shuffle or random.choice
though that would be much cleaner. It isn't entirely clear what you
are trying to do though, so I'm stopping short of posting any code.

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


Re: Co-developers wanted: document markup language

2007-08-27 Thread Steve Holden
Wildemar Wildenburger wrote:
> Robert Kern wrote:
>> Wildemar Wildenburger wrote:
>>   
>>> Torsten Bronger wrote:
>>> 
 Hallöchen!
   
   
>>> Yes, you're German. Have you ever noticed that (we) Germans are 
>>> virtually the only ones that feel the need to rub our nationality into 
>>> everyones faces? ;)
>>> 
>> Howdy!
>>
>> We Americans do the same.  ;-)
>>
>>   
> Weeell, you guys mostly rub your ignorance about the rest of the world 
> into everyones faces. That's a little different.
> 
> There, I did it. Now I got my country invaded. But maybe that's a good 
> thing ... at least we will get democracy and finally find happiness.
> 
> /W
> (OK, sorry. I couldn't resist. Don't take it personally. Take it 
> nationally. ;) )

Unfortunately Americans are also well known for their inability to 
detect irony, so your pointed remarks about democracy and happiness will 
probably go mostly unnoticed.

regards
  Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd   http://www.holdenweb.com
Skype: holdenweb  http://del.icio.us/steve.holden
--- Asciimercial --
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
--- Thank You for Reading -

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

Re: sorting a list of lists

2007-08-27 Thread iapain
> i would like to sort a list of lists. The list is first sorted on the
> second item in the sub-lists (which I can do), then on the third item
> (which I can't).

Write a comparator instead of dirty hacks

mylistoflist.sort(mycomparator)

def mycomparator(a, b):
  #do


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


Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread M�ta-MCI \(MVP\)
Re! 

Sended by direct (private) e-mail

@+

Michel Claveau




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


convert non-delimited to delimited

2007-08-27 Thread RyanL
I'm a newbie!  I have a non-delimited data file that I'd like to
convert to delimited.

Example...
Line in non-delimited file:
01397256359210100534+42050-102800FM-15+1198KAIA

Should be:
0139,725635,9,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA

What is the best way to go about this?  I've looked all over for
examples, help, suggestions, but have not found much.  CSV module
doesn't seem to do exactly what I want.  Maybe I'm just missing
something or not using the correct terminology in my searches.  Any
assistance is greatly appreaciated!  Using Python 2.4

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


Re: How to free memory ( ie garbage collect) at run time with Python 2.5.1(windows)

2007-08-27 Thread M�ta-MCI \(MVP\)
Aïe!

gmail said :  "illegal attachment"   (because  .exe?)
I will try to send a zipped-file...

@+

Michel Claveau


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


Re: beginner, idiomatic python

2007-08-27 Thread Neil Cerutti
On 2007-08-27, bambam <[EMAIL PROTECTED]> wrote:
> Thank you, I have been through the tutorial several times, I
> guess I'm just not smart enough. Perhaps I have been led astray
> by what I read here?
>
> My code started like this:
>
> for i in range(self.parent.GetPageCount()):
>
> I was asked:
>
>> Does page count change? i.e. is it necessary to retrieve it in
>> every loop
>
> Is self.parent.GetPageCount() 'retrieved every loop'?

No. The question seems to imply that if you wish it to be
retrieved every loop you must change the code to something else.

i = 0
while i < self.parent.GetPageCount():
  # do stuff
  i += 1

I find that kind of while loop clunky. Since Python is
hard-headed about not providing a structured looping construct,
you may feel the need to compose your own special-purpose
iterator or generator instead.

def pageCountGenerator(document):
  i = 0
  while i < document.GetPageCount():
yield i
i += 1

It can be used like this:

for i in pageCountGenerator(self.parent):
  # do stuff

That way you get the happy syntax of a for loop, with the
additional safety of checking the page count each iteration.

This sort of suggests a direct solution:

for i in xrange(self.parent.GetPageCount()):
  if i >= self.parent.GetPageCount():
break
  # do stuff

At least that way you're spared the manual manipulation of i.

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


Re: sorting a list of lists

2007-08-27 Thread Stefan Behnel
iapain wrote:
>> i would like to sort a list of lists. The list is first sorted on the
>> second item in the sub-lists (which I can do), then on the third item
>> (which I can't).
> 
> Write a comparator instead of dirty hacks
> 
> mylistoflist.sort(mycomparator)
> 
> def mycomparator(a, b):
>   #do

Taking advantage of stable sorting is totally not a hack. The OP just tried
the two sorting steps in the wrong order.

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


Re: convert non-delimited to delimited

2007-08-27 Thread Mark Elston
* RyanL wrote (on 8/27/2007 10:59 AM):
> I'm a newbie!  I have a non-delimited data file that I'd like to
> convert to delimited.
> 
> Example...
> Line in non-delimited file:
> 01397256359210100534+42050-102800FM-15+1198KAIA
> 
> Should be:
> 0139,725635,9,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
> 
> What is the best way to go about this?  I've looked all over for
> examples, help, suggestions, but have not found much.  CSV module
> doesn't seem to do exactly what I want.  Maybe I'm just missing
> something or not using the correct terminology in my searches.  Any
> assistance is greatly appreaciated!  Using Python 2.4
> 

Since you have to know, a priori, how to break the input string I
assume that these fields are of fixed length.  You can use the following
to do what you want:

 >>> a="01397256359210100534+42050-102800FM-15+1198KAIA"
 >>> print "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" %
 (a[0:4],a[4:10],a[10:15],a[15:19],a[19:21],a[21:23],a[23:25],
  a[25:27],a[27],a[28:34],a[34:41],a[41:46],a[46:51],a[51:])

which results in the following output:

0139,725635,9,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA

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


Re: convert non-delimited to delimited

2007-08-27 Thread [EMAIL PROTECTED]
On Aug 27, 1:35 pm, Mark Elston <[EMAIL PROTECTED]> wrote:
> * RyanL wrote (on 8/27/2007 10:59 AM):
>
>
>
>
>
> > I'm a newbie!  I have a non-delimited data file that I'd like to
> > convert to delimited.
>
> > Example...
> > Line in non-delimited file:
> > 01397256359210100534+42050-102800FM-15+1198KAIA
>
> > Should be:
> > 0139,725635,9,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
>
> > What is the best way to go about this?  I've looked all over for
> > examples, help, suggestions, but have not found much.  CSV module
> > doesn't seem to do exactly what I want.  Maybe I'm just missing
> > something or not using the correct terminology in my searches.  Any
> > assistance is greatly appreaciated!  Using Python 2.4
>
> Since you have to know, a priori, how to break the input string I
> assume that these fields are of fixed length.  You can use the following
> to do what you want:
>
>  >>> a="01397256359210100534+42050-102800FM-15+1198KAIA"
>  >>> print "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" %
>  (a[0:4],a[4:10],a[10:15],a[15:19],a[19:21],a[21:23],a[23:25],
>   a[25:27],a[27],a[28:34],a[34:41],a[41:46],a[46:51],a[51:])
>
> which results in the following output:
>
> 0139,725635,9,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
>
> Mark

Or try this:

import struct
test = '01397256359210100534+42050-102800FM-15+1198KAIA'
template = '4s6s5s4s2s2s2s2s1s6s7s5s5s4s'
the_line = struct.unpack(template,test)
print the_line
print ','.join(the_line)

##  ('0139', '725635', '9', '2000', '01', '01', '00', '53', '4',
'+42050', '-102800', 'FM-15', '+1198', 'KAIA')
##
##
0139,725635,9,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA

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


Re: convert non-delimited to delimited

2007-08-27 Thread Michael Bentley

On Aug 27, 2007, at 10:59 AM, RyanL wrote:

> I'm a newbie!  I have a non-delimited data file that I'd like to
> convert to delimited.
>
> Example...
> Line in non-delimited file:
> 01397256359210100534+42050-102800FM-15+1198KAIA
>
> Should be:
> 0139,725635,9,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
>
> What is the best way to go about this?  I've looked all over for
> examples, help, suggestions, but have not found much.  CSV module
> doesn't seem to do exactly what I want.  Maybe I'm just missing
> something or not using the correct terminology in my searches.  Any
> assistance is greatly appreaciated!  Using Python 2.4

Is each data element a fixed size?


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


Re: convert non-delimited to delimited

2007-08-27 Thread Matimus
On Aug 27, 10:59 am, RyanL <[EMAIL PROTECTED]> wrote:
> I'm a newbie!  I have a non-delimited data file that I'd like to
> convert to delimited.
>
> Example...
> Line in non-delimited file:
> 01397256359210100534+42050-102800FM-15+1198KAIA
>
> Should be:
> 0139,725635,9,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA
>
> What is the best way to go about this?  I've looked all over for
> examples, help, suggestions, but have not found much.  CSV module
> doesn't seem to do exactly what I want.  Maybe I'm just missing
> something or not using the correct terminology in my searches.  Any
> assistance is greatly appreaciated!  Using Python 2.4

I don't think you are going to find anything that will just do this
for you. You are going to have read the file, figure out where to
split the string, and reprint it delimited with commas. As for
suggesting code... I can't tell how you actually want to delimit the
stuff from the above example? Are the fields always a fixed number of
characters? If they aren't then is there some other method for
determining how many characters to group into a field? From the looks
of it you could split that string any way you want and get something
that looks right, but isn't.

Matt

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


Re: sorting a list of lists

2007-08-27 Thread iapain
> Taking advantage of stable sorting is totally not a hack. The OP just tried
> the two sorting steps in the wrong order.

I didnt say not to use stable sorting, but write a generic function
and hacky code. It is always better to adopt a generic approach.


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


Re: beginner, idiomatic python

2007-08-27 Thread Neil Cerutti
On 2007-08-27, Neil Cerutti <[EMAIL PROTECTED]> wrote:
> This sort of suggests a direct solution:
>
> for i in xrange(self.parent.GetPageCount()):
>   if i >= self.parent.GetPageCount():
> break
>   # do stuff
>
> At least that way you're spared the manual manipulation of i.

On second thought, that last suggestion is flawed, as a growing
page count would be ignored. Please ignore.

-- 
Neil Cerutti
Whenever I see a homeless guy, I always run back and give him money, because I
think: Oh my God, what if that was Jesus? --Pamela Anderson
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: convert non-delimited to delimited

2007-08-27 Thread Neil Cerutti
On 2007-08-27, RyanL <[EMAIL PROTECTED]> wrote:
> I'm a newbie!  I have a non-delimited data file that I'd like to
> convert to delimited.
>
> Example...
> Line in non-delimited file:
> 01397256359210100534+42050-102800FM-15+1198KAIA
>
> Should be:
> 0139,725635,9,2000,01,01,00,53,4,+42050,-102800,FM-15,+1198,KAIA

It looks like a fixed format data file, also called flat-record
files, in which fields are of fixed lengths, and records are
separated by newlines.

> What is the best way to go about this?  

Check out chapter 2 of _Text Processing in Python_ for one
solution.

http://gnosis.cx/TPiP/chap2.txt

-- 
Neil Cerutti
Weight Watchers will meet at 7 p.m. Please use large double door at the side
entrance. --Church Bulletin Blooper
-- 
http://mail.python.org/mailman/listinfo/python-list


[PyQt] Help on resizing a custom widget

2007-08-27 Thread [EMAIL PROTECTED]
Ok, here's what's going on. I've just created a custom widget. it
works great. I'm having some trouble, however, figuring out how to
allow the said widget to resize. For example, when I throw the widget
into a new dialog (using Qt Designer), I want to be able to drag it
larger/smaller and have widget expand/shrink to that size. Right now,
I can drag the widget bigger/smaller all I want, but it doesn't
actually change size.

I'm pretty new to PyQt (and therefore, Qt), so I'm pretty sure that
the answer is a property that needs to be set somewhere. I'm just not
sure which one. So you know, I'm using Python 2.4.3 and PyQt 3.1.6.

Any help and suggestions would be appreciated. Thanks.

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


an eval()-like exec()

2007-08-27 Thread Abel Daniel
Hi!

A python interactive interpreter works by having the user type in some
code, compiling and running that code, then printing the results. For
printing, the results are turned into strings.

I would like make an interpreter which does this, without the last
part: i.e. where the results are returned as objects, instead of as
strings. I.e. have I would like to see something that behaves like
this:

>>> ip = MyInterpreter()
# this started a new interpreter
>>> ip.run("import math") is None
True
>>> ip.run("math.pi") is math.pi
True

Neither exec() or eval() is usable for this, as far as I see, because
eval can't handle arbitrary python code (eval("import math") ), and
exec() doesn't return the results.

Subclassing an code.InteractiveInterpreter or code.InteractiveConsole
seems like a usable idea, but I couldn't find out what to do to get
the results before they are turned into strings.

Using compile() and then eval() didn't seem usable either.

Any ideas?

Thanks in advance,
Daniel Abel

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


Re: Image.open( "C:\test.jpg") is this wrong ?

2007-08-27 Thread Nicholas Amorim
Ah

"My problem is that I don't know what my active directory is so I am putting
an absolute path name in quotes."

import os

os.getcwd() # it returns your current directory
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: sorting a list of lists

2007-08-27 Thread [EMAIL PROTECTED]
On Aug 27, 2:41 pm, iapain <[EMAIL PROTECTED]> wrote:
> ... It is always better to adopt a generic approach.

 The above statement is incorrect.

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


Socket - gaierror

2007-08-27 Thread half . italian
Hi all,

I'm having trouble with the socket module resolving a hostname.  It
seems like this is a system level problem, but I'm not even sure where
to start.  I can ping the smtp server by name and IP, but when
smtp.SMTP("theHost") tries to get the hostname, it keeps giving me the
following error:

  File "bin/program.py", line 123, in notify
smtp = smtplib.SMTP("theHost")

  File "/usr/lib/python2.4/smtplib.py", line 255, in __init__
addr = socket.gethostbyname(socket.gethostname())

gaierror: (-2, 'Name or service not known')

I tried changing to a different smtp server, using an ip instead of a
host name.  I could ping both boxes by name oor IP.

any ideas?

~Sean

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


Re: beginner, idiomatic python

2007-08-27 Thread Paul Rubin
Neil Cerutti <[EMAIL PROTECTED]> writes:
> i = 0
> while i < self.parent.GetPageCount():
>   # do stuff
>   i += 1

Alternatively:

from itertools import count

for i in count():
   if i >= self.parent.GetPageCount():
  break
  ...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Socket - gaierror

2007-08-27 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> Hi all,
> 
> I'm having trouble with the socket module resolving a hostname.  It
> seems like this is a system level problem, but I'm not even sure where
> to start.  I can ping the smtp server by name and IP, but when
> smtp.SMTP("theHost") tries to get the hostname, it keeps giving me the
> following error:
> 
>   File "bin/program.py", line 123, in notify
> smtp = smtplib.SMTP("theHost")
> 
>   File "/usr/lib/python2.4/smtplib.py", line 255, in __init__
> addr = socket.gethostbyname(socket.gethostname())
> 
> gaierror: (-2, 'Name or service not known')
> 
> I tried changing to a different smtp server, using an ip instead of a
> host name.  I could ping both boxes by name oor IP.
> 
> any ideas?
> 
> ~Sean
> 
The specific error shown is a DNS resolution problem.  Based on the
URL "theHost" smtplib can't resolve to an IP address (which is what
socket.gethostbyname does).  You don't say what happened when you changed to 
ip, 
but I suspect it is a different error or some other problem.  Maybe a firewall 
issue (port 25 not open?), but I'm just guessing.

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


Re: Socket - gaierror

2007-08-27 Thread half . italian
On Aug 27, 12:32 pm, Larry Bates <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hi all,
>
> > I'm having trouble with the socket module resolving a hostname.  It
> > seems like this is a system level problem, but I'm not even sure where
> > to start.  I can ping the smtp server by name and IP, but when
> > smtp.SMTP("theHost") tries to get the hostname, it keeps giving me the
> > following error:
>
> >   File "bin/program.py", line 123, in notify
> > smtp = smtplib.SMTP("theHost")
>
> >   File "/usr/lib/python2.4/smtplib.py", line 255, in __init__
> > addr = socket.gethostbyname(socket.gethostname())
>
> > gaierror: (-2, 'Name or service not known')
>
> > I tried changing to a different smtp server, using an ip instead of a
> > host name.  I could ping both boxes by name oor IP.
>
> > any ideas?
>
> > ~Sean
>
> The specific error shown is a DNS resolution problem.  Based on the
> URL "theHost" smtplib can't resolve to an IP address (which is what
> socket.gethostbyname does).  You don't say what happened when you changed to 
> ip,
> but I suspect it is a different error or some other problem.  Maybe a firewall
> issue (port 25 not open?), but I'm just guessing.
>
> -Larry

Changing it to IP gives me the same exact error...

  File "bin/prgram.py", line 123, in notify
smtp = smtplib.SMTP("XXX.XXX.XXX.XXX")

  File "/usr/lib/python2.4/smtplib.py", line 255, in __init__
addr = socket.gethostbyname(socket.gethostname())

gaierror: (-2, 'Name or service not known')

Looks like the smtp port is closed on the client machine...doh Should
have gotten to that!

Thank you.

~Sean

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


some problems with mod_python

2007-08-27 Thread Johan
Hi

I have installed and tested this on centos, fedora and freebsd all
give the same problem so I guess I missed some steps.

I have compiled bot apache (2.2.4) and mod_python (3.3.1) according to
the docs and no problem with this.
But when I have made everything about testing mod_python an browse to
http://server/test and there expecting to see "Hello world" I instead
get an index of contents in this directory. If I go to  
http://server/test/mptest.py
it works. No errors in any log either.

What Have I missed?

This I added to httpd.conf

AllowOverride All
AddHandler mod_python .py
PythonHandler mptest
PythonDebug On



this is my mptest.py:
from mod_python import apache

def handler(req):
req.content_type = 'text/plain'
req.write("Hello World!")
return apache.OK

/johan

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


Getting subprocesses to be hidden on Windows

2007-08-27 Thread geoffbache
Hi,

As part of my efforts to write a test tool that copes with GUIs
nicely, I'm trying to establish how I can start a GUI process on
Windows that will not bring up the window. So I try to hide the window
as follows:

info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE

proc = subprocess.Popen(..., startupinfo=info)

This works, in a way, but doesn't work recursively. I.e. if the
started process itself starts a window, that second window will not be
hidden. This even applies to dialog boxes within the application. So
instead of a lot of windows popping up I now get a lot of disembodied
dialogs appearing, which is a slight improvement but not much.

Also, certain processes (e.g. tkdiff) seem to ignore the directive to
be hidden altogether.

This is dead easy on UNIX with virtual displays like Xvfb. Can someone
shed any light if it's possible on Windows from python?

Regards,
Geoff Bache

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


Re: some problems with mod_python

2007-08-27 Thread Greg Donald
On 8/27/07, Johan <[EMAIL PROTECTED]> wrote:
> This I added to httpd.conf
> 
> AllowOverride All
> AddHandler mod_python .py
> PythonHandler mptest
> PythonDebug On
> 

This is the syntax I have working locally:

# mod_python

  AddHandler python-program .py
  PythonHandler test
  PythonDebug On


In particular my AddHandler directive is different from yours.


-- 
Greg Donald
http://destiney.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [PyQt] Help on resizing a custom widget

2007-08-27 Thread Phil Thompson
On Monday 27 August 2007, [EMAIL PROTECTED] wrote:
> Ok, here's what's going on. I've just created a custom widget. it
> works great. I'm having some trouble, however, figuring out how to
> allow the said widget to resize. For example, when I throw the widget
> into a new dialog (using Qt Designer), I want to be able to drag it
> larger/smaller and have widget expand/shrink to that size. Right now,
> I can drag the widget bigger/smaller all I want, but it doesn't
> actually change size.
>
> I'm pretty new to PyQt (and therefore, Qt), so I'm pretty sure that
> the answer is a property that needs to be set somewhere. I'm just not
> sure which one. So you know, I'm using Python 2.4.3 and PyQt 3.1.6.
>
> Any help and suggestions would be appreciated. Thanks.

Probably best to start with the following...

http://doc.trolltech.com/4.3.0/layout.html#custom-widgets-in-layouts

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


Re: some problems with mod_python

2007-08-27 Thread Johan
On Aug 27, 10:29 pm, "Greg Donald" <[EMAIL PROTECTED]> wrote:

> This is the syntax I have working locally:
>
> # mod_python
> 
>   AddHandler python-program .py
>   PythonHandler test
>   PythonDebug On
> 
>
> In particular my AddHandler directive is different from yours.
>
If I did understand the docs about the difference between python-
program and mod_python is that the later is the new way, while using
python-program still works.
It does not matter which I use, same result.

/johan

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


Re: sorting a list of lists

2007-08-27 Thread Tuomas
 >>> records = [['dog',1,2], ['chair',2,1], ['cat',1,3], ['horse',3,4],
... ['table',3,2], ['window',3,5]]
 >>> sorted(records, key = lambda x: (x[1], x[2]))
[['dog', 1, 2], ['cat', 1, 3], ['chair', 2, 1], ['table', 3, 2], 
['horse', 3, 4], ['window', 3, 5]]


[EMAIL PROTECTED] wrote:
> Hi,
> 
> i would like to sort a list of lists. The list is first sorted on the
> second item in the sub-lists (which I can do), then on the third item
> (which I can't).
> 
> eg. records = [['dog',1,2], ['chair',2,1], ['cat',1,3], ['horse',3,4],
> ['table',3,2], ['window',3,5]]
> 
> I want sorted to [['dog',1,2], ['cat',1,3], ['chair',2,1], ['table',
> 3,2], ['horse',3,4], ['window',3,5]]
> 
> To sort on the second item in the sub-lists I do the following
> 
> pass1 = itemgetter(1)
> sorted(records, key=pass1)
> 
> How can I then sort on the third item in the sub-lists whilst keeping
> the order on the second item?
> 
> Nick
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Biased random?

2007-08-27 Thread Ivan Voras
Hi,

I have a list of items, and need to choose several elements from it,
"almost random". The catch is that the elements from the beginning
should have more chance of being selected than those at the end (how
much more? I don't care how the "envelope" of probability looks like at
this point - can be linear). I see that there are several functions in
Python standard libraries for various distribution, but is there an easy
pythonic way to make them do what I need?




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

Re: Help on resizing a custom widget

2007-08-27 Thread [EMAIL PROTECTED]
On Aug 27, 4:40 pm, Phil Thompson <[EMAIL PROTECTED]>
wrote:
> On Monday 27 August 2007, [EMAIL PROTECTED] wrote:
>
> > Ok, here's what's going on. I've just created a custom widget. it
> > works great. I'm having some trouble, however, figuring out how to
> > allow the said widget to resize. For example, when I throw the widget
> > into a new dialog (using Qt Designer), I want to be able to drag it
> > larger/smaller and have widget expand/shrink to that size. Right now,
> > I can drag the widget bigger/smaller all I want, but it doesn't
> > actually change size.
>
> > I'm pretty new to PyQt (and therefore, Qt), so I'm pretty sure that
> > the answer is a property that needs to be set somewhere. I'm just not
> > sure which one. So you know, I'm using Python 2.4.3 and PyQt 3.1.6.
>
> > Any help and suggestions would be appreciated. Thanks.
>
> Probably best to start with the following...
>
> http://doc.trolltech.com/4.3.0/layout.html#custom-widgets-in-layouts
>
> Phil

Thanks for pointing me in the right direction. I'll take a look at it.

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


Re: Biased random?

2007-08-27 Thread Jon Clements
How about decorating your list of elements with an additional value,
which indicates the weight of that element. A value of 1 will indicate
'as likely as any other', < 1 will be 'less likely than' any other and
> 1 will be 'more likely than any other'. Then create a sorted list
based on the combined value of weight and the output of random(); from
this take the first N many elements to meet your requirements.

hth

Jon




On 27 Aug, 21:42, Ivan Voras <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a list of items, and need to choose several elements from it,
> "almost random". The catch is that the elements from the beginning
> should have more chance of being selected than those at the end (how
> much more? I don't care how the "envelope" of probability looks like at
> this point - can be linear). I see that there are several functions in
> Python standard libraries for various distribution, but is there an easy
> pythonic way to make them do what I need?
>
>  signature.asc
> 1KDownload


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


Re: Getting subprocesses to be hidden on Windows

2007-08-27 Thread kyosohma
On Aug 27, 3:21 pm, geoffbache <[EMAIL PROTECTED]> wrote:
> Hi,
>
> As part of my efforts to write a test tool that copes with GUIs
> nicely, I'm trying to establish how I can start a GUI process on
> Windows that will not bring up the window. So I try to hide the window
> as follows:
>
> info = subprocess.STARTUPINFO()
> info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
> info.wShowWindow = subprocess.SW_HIDE
>
> proc = subprocess.Popen(..., startupinfo=info)
>
> This works, in a way, but doesn't work recursively. I.e. if the
> started process itself starts a window, that second window will not be
> hidden. This even applies to dialog boxes within the application. So
> instead of a lot of windows popping up I now get a lot of disembodied
> dialogs appearing, which is a slight improvement but not much.
>
> Also, certain processes (e.g. tkdiff) seem to ignore the directive to
> be hidden altogether.
>
> This is dead easy on UNIX with virtual displays like Xvfb. Can someone
> shed any light if it's possible on Windows from python?
>
> Regards,
> Geoff Bache

I'm confused. Why would you create a GUI if you're not going to
actually display it? Isn't that the point of a GUI? Or are you talking
about the command window popping up?

Mike

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


"Try:" which only encompasses head of compound statement

2007-08-27 Thread Jameson . Quinn
I have:

try:
for line in open(myFileName):
count += 1
except IOError:
print "Can't open myfile"

(I know, this is bad, I never close the file, but its just for
illustration). But then I change it to:

try:
for line in open(myFileName):
count += openAndProcessSubfile(line)
except IOError:
print "Can't open myfile"

... now the 'except' incorrectly catches errors from
openAndProcessSubfile.
Of course, I can always do:

try:
myFile = open(myFileName)
except IOError:
print "Can't open myfile"
for line in myFile:
count += openAndProcessSubfile(line)

...But if my compound statement is "with" instead of "for" that seems
to defeat the purpose:

try:
myFile = open(myFileName)
except IOError:
print "Can't open myfile"
with myFile as anotherNameForMyFile:


This is not a very readable "with" statement, I end up giving the same
thing two names, and there's a moment when the above code doesn't know
to close myFile.

It's hard to imagine a good idiom to fix this. The best I can do is:

for line in open(myFileName)
exceptHead IOError:
print "Can't open myfile"
count += openAndProcessSubfile(line)

exceptHead would be usable as the first indented line in any compound
statement, and would catch any errors raised by the preceding line
only. The bad thing about this (besides the silly name exceptHead) is
that after the except block, control flow would skip the entire
compound statement including else blocks.

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


include folder

2007-08-27 Thread Raul Araya
Dear Python users and developers:

My trouble is as follows: I'm putting back on line an old pc-linux cluster.
Today while trying to install a python based program I got an error 
regarding the Python.h file that should be in the /include/Phyton2.3 
folder. So I went looking for the file but it wasn't there, I mean the 
whole folder /Phyton2.3 inside the /usr/include directory was not there. 
I am not te administrator of that cluster that has been off for at least 
2 years, so I really don't know what to do. Please help.
My Linux version is: Debian GNU-Linux
My Python version is: 2.3

Many thanks
Raúl Araya
Faculty of sciences
Universidad de Chile
Santiago Chile

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


Re: Biased random?

2007-08-27 Thread Jun-geun Park
Ivan Voras wrote:
> Hi,
> 
> I have a list of items, and need to choose several elements from it,
> "almost random". The catch is that the elements from the beginning
> should have more chance of being selected than those at the end (how
> much more? I don't care how the "envelope" of probability looks like at
> this point - can be linear). I see that there are several functions in
> Python standard libraries for various distribution, but is there an easy
> pythonic way to make them do what I need?
> 
> 

That's weird. random.randint(a,b) will be enough for most cases. Test
your system to see the distribution is uniform with something like:


import random

dist = {}
for z in xrange(10):
 u = random.randint(1,10)
 try:
 dist[u] = dist[u] + 1
 except KeyError:
 dist[u] = 1

print dist

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


Re: "Try:" which only encompasses head of compound statement

2007-08-27 Thread Bjoern Schliessmann
 [EMAIL PROTECTED] wrote:
> I have:
> 
> try:
> for line in open(myFileName):
> count += 1
> except IOError:
> print "Can't open myfile"
> 
> (I know, this is bad, I never close the file, but its just for
> illustration). But then I change it to:
> 
> try:
> for line in open(myFileName):
> count += openAndProcessSubfile(line)
> except IOError:
> print "Can't open myfile"
> 
> ... now the 'except' incorrectly catches errors from
> openAndProcessSubfile.

The typical way to counter this would be by catching the IOError
earlier so it won't propagate to the outmost "try":

try:
for line in open(myFileName):
try: 
count += openAndProcessSubfile(line)
except IOError:
print "Can't open subfile"
except IOError:
print "Can't open myfile"

Regards,


Björn

-- 
BOFH excuse #121:

halon system went off and killed the operators.

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


Re: Biased random?

2007-08-27 Thread Grant Edwards
On 2007-08-27, Jun-geun Park <[EMAIL PROTECTED]> wrote:

>> I have a list of items, and need to choose several elements
>> from it, "almost random". The catch is that the elements from
>> the beginning should have more chance of being selected than
>> those at the end (how much more? I don't care how the
>> "envelope" of probability looks like at this point - can be
>> linear). I see that there are several functions in Python
>> standard libraries for various distribution, but is there an
>> easy pythonic way to make them do what I need?

> That's weird. random.randint(a,b) will be enough for most
> cases. Test your system to see the distribution is uniform
> with something like:

Except he wants a non-uniform distribution.

-- 
Grant Edwards   grante Yow! I'm changing the
  at   CHANNEL ... But all I get
   visi.comis commercials for "RONCO
   MIRACLE BAMBOO STEAMERS"!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: my parser.py isn't imported

2007-08-27 Thread John Machin
On Aug 27, 7:33 pm, Lawrence D'Oliveiro <[EMAIL PROTECTED]
central.gen.new_zealand> wrote:
> In message <[EMAIL PROTECTED]>, Torsten Bronger wrote:
>
> > So I'd like to know a means to tell *explicitly* what I want to
> > import.  Maybe I could use the imp module but that's ugly.
>
> That seems to be the standard Python-provided way to explicitly import the
> file you want from the place you want.
>
> > I mean, there are hundreds of modules on my harddisk, so trying to avoid
> > nameclashs should not be the solution...
>
> That is what namespace qualifiers are for, e.g.
>
> import my_custom_stuff.parser
>
> versus
>
> import parser
>
> > John Machin writes:
>
> >> 2. Failure to RTFabulousM:
> >> """
> >> Details of the module searching and loading process are
> >> implementation and platform specific. It generally involves
> >> searching for a ``built- in'' module with the given name and then
> >> searching a list of locations given as sys.path.
> >> """
>
> > ... the whole systems seems largely arbitrary, which I don't
> > believe.  ;-)
>
> The documentation  says quite
> clearly that the search order is controlled by sys.path. So why not
> manipulate that to get the effect you want?

Short answer: it doesn't work. The documentation that I quoted
previously says that if a module is is built in, it will be selected,
*before* sys.path is examined. The OP's original message stated quite
clearly that the directory containing his own parser.py is at the
front of sys.path.

>
> > "parser" is built-in on Windows but not on Linux.
>
> It is standard on all platforms
> .

"standard" != "builtin"


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


Re: Image.open( "C:\test.jpg") is this wrong ?

2007-08-27 Thread Matt McCredie
> Image.open("C:\test.jpg")  # this is what I have right now. And it can't
> find the file or directory. The file is there (it is everywhere on my
> computer now!!!)
>
> I found some code where they apply the file path to a variable in single
> quotes. Is that how it is done. Also I thought single quotes were for
> characters not strings.

In python there is no difference between single and double quotes. You
are close, but the "C:\test.jpg", sees the "\t" as the escape sequence
for `tab'. You can generally use three things:

"C:\\test.jpg" where "\\" is the escape sequence for a single backslash `\'

You can use a raw string: r"C:\test.jpg" which disables escaping.

You can use forward slashes "C:/test.jpg", which might look funny but does work.

Read more here:
http://docs.python.org/tut/node5.html#SECTION00512

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


Re: some problems with mod_python

2007-08-27 Thread Graham Dumpleton
On Aug 28, 6:13 am, Johan <[EMAIL PROTECTED]> wrote:
> Hi
>
> I have installed and tested this on centos, fedora and freebsd all
> give the same problem so I guess I missed some steps.
>
> I have compiled bot apache (2.2.4) and mod_python (3.3.1) according to
> the docs and no problem with this.
> But when I have made everything about testing mod_python an browse 
> tohttp://server/testand there expecting to see "Hello world" I instead
> get an index of contents in this directory. If I go to  
> http://server/test/mptest.py
> it works. No errors in any log either.
>
> What Have I missed?
>
> This I added to httpd.conf
> 
> AllowOverride All
> AddHandler mod_python .py
> PythonHandler mptest
> PythonDebug On
> 
>
> this is my mptest.py:
> from mod_python import apache
>
> def handler(req):
> req.content_type = 'text/plain'
> req.write("Hello World!")
> return apache.OK
>
> /johan

You need to look at the Apache documentation for the difference
between AddHandler and SetHandler directives. If you don't want to
read the Apache documentation and learn more about it, at least read:

http://www.dscpl.com.au/wiki/ModPython/Articles/SetHandlerVersusAddHandler

Graham


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


Re: Socket - gaierror

2007-08-27 Thread half . italian
On Aug 27, 12:47 pm, [EMAIL PROTECTED] wrote:
> On Aug 27, 12:32 pm, Larry Bates <[EMAIL PROTECTED]> wrote:
>
>
>
> > [EMAIL PROTECTED] wrote:
> > > Hi all,
>
> > > I'm having trouble with the socket module resolving a hostname.  It
> > > seems like this is a system level problem, but I'm not even sure where
> > > to start.  I can ping the smtp server by name and IP, but when
> > > smtp.SMTP("theHost") tries to get the hostname, it keeps giving me the
> > > following error:
>
> > >   File "bin/program.py", line 123, in notify
> > > smtp = smtplib.SMTP("theHost")
>
> > >   File "/usr/lib/python2.4/smtplib.py", line 255, in __init__
> > > addr = socket.gethostbyname(socket.gethostname())
>
> > > gaierror: (-2, 'Name or service not known')
>
> > > I tried changing to a different smtp server, using an ip instead of a
> > > host name.  I could ping both boxes by name oor IP.
>
> > > any ideas?
>
> > > ~Sean
>
> > The specific error shown is a DNS resolution problem.  Based on the
> > URL "theHost" smtplib can't resolve to an IP address (which is what
> > socket.gethostbyname does).  You don't say what happened when you changed 
> > to ip,
> > but I suspect it is a different error or some other problem.  Maybe a 
> > firewall
> > issue (port 25 not open?), but I'm just guessing.
>
> > -Larry
>
> Changing it to IP gives me the same exact error...
>
>   File "bin/prgram.py", line 123, in notify
> smtp = smtplib.SMTP("XXX.XXX.XXX.XXX")
>
>   File "/usr/lib/python2.4/smtplib.py", line 255, in __init__
> addr = socket.gethostbyname(socket.gethostname())
>
> gaierror: (-2, 'Name or service not known')
>
> Looks like the smtp port is closed on the client machine...doh Should
> have gotten to that!
>
> Thank you.
>
> ~Sean

I take it back, that wasn't the solution.  I got it to work by
haacking smtplib with a static host instead of the
socket.gethostbyname(socket.gethostname()) call...but if I leave that
in there I might get shot one day.  What could cause the shell to be
able to resolve the addresses properly, but not python?
nnsswitch.conf ?

I don't know enough about what's going on in the background.  Any
other ideas? Or should I try this on a unix board?

~Sean

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


Re: Biased random?

2007-08-27 Thread [EMAIL PROTECTED]
On Aug 27, 3:42 pm, Ivan Voras <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a list of items, and need to choose several elements from it,
> "almost random". The catch is that the elements from the beginning
> should have more chance of being selected than those at the end (how
> much more? I don't care how the "envelope" of probability looks like at
> this point - can be linear). I see that there are several functions in
> Python standard libraries for various distribution, but is there an easy
> pythonic way to make them do what I need?
>
>  signature.asc
> 1KDownload

If your list is small enough, you could do something
like this:

import random
test = ['a','b','c','d','e','f','g','h','i','j']
temp = []
size = len(test)-1
for i,j in enumerate(test):
  temp.extend(j*(2**(size-i)))
for i in xrange(400):
  if i % 30 == 0: print
  print random.choice(temp),

##  a a b a a a i c a a a b c b b a a a a b a a a d a b a a g f
##  a e a a a i a b a a b c b a a b a b b c b a b a c a a a a a
##  b a a c a c e d b d a a a a a c a b b e a a b a a b a a c a
##  a a a a a a b a b a c a a a c a d a c a a d b b b b d a a a
##  a a d b a a a b a b b a b a c a a a b b a c b c a a c c c a
##  a a b a a a b a b a a a a d c a a b c b b b d b b a a b c a
##  a a a a a a b a d b c d b a b c a d b b b a b a b b b b b a
##  b c a b a a b c a a a a a a a a b a a a b a a a a a d a b b
##  a b b a c a b c a a a a a a a a c b a c c a a e a a a c b b
##  a c e b b a a b c a b a b a a b a g a b e a a a c c a a c b
##  b i a b a a a a c c c b a a a a a b b b a b b a a b b h a a
##  d b a b a b b a a b c a b a a b a a a c a d a a b a b a a a
##  a d a b b a b a a c a b c d b a a d a a b b a a a a a d a c
##  a a a b a a b a c b

Here, 'a' is twice as likely to occur as 'b',
which is twice as likely to occur as 'c',
which is twice as likely to occur as 'd',
etc.

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


Re: Biased random?

2007-08-27 Thread J. Cliff Dyer

I don't know if this is pythonic or not, but try something like this:

from math import log
from random import randint
def: skewedrandom(n):
   int(log(randrange(1,n), 2))

Play with your log to get the range you want

Cheers,
Cliff

Grant Edwards wrote:

On 2007-08-27, Jun-geun Park <[EMAIL PROTECTED]> wrote:

  

I have a list of items, and need to choose several elements
from it, "almost random". The catch is that the elements from
the beginning should have more chance of being selected than
those at the end (how much more? I don't care how the
"envelope" of probability looks like at this point - can be
linear). I see that there are several functions in Python
standard libraries for various distribution, but is there an
easy pythonic way to make them do what I need?
  


  

That's weird. random.randint(a,b) will be enough for most
cases. Test your system to see the distribution is uniform
with something like:



Except he wants a non-uniform distribution.

  


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

Re: Socket - gaierror

2007-08-27 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] wrote:

> What could cause the shell to be
> able to resolve the addresses properly, but not python?
> nnsswitch.conf ?

How did you test the name resolution in the shell--was it with "host"
or "ping"? I would recommend ping, because that would use the same C
runtime gethostbyname call that your Python code is trying to use.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "Try:" which only encompasses head of compound statement

2007-08-27 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, 
[EMAIL PROTECTED] wrote:

> try:
> for line in open(myFileName):
> count += 1
> except IOError:
> print "Can't open myfile"
> 
> (I know, this is bad, I never close the file, but its just for
> illustration).

No, that's fine. The file object returned by "open" is refcounted, so when
the last reference to it disappears, it is closed.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Biased random?

2007-08-27 Thread Sebastian Bassi
On 8/27/07, J. Cliff Dyer <[EMAIL PROTECTED]> wrote:
>  Play with your log to get the range you want

Here you can get "true" random numbers (not pseudorandom, they claim
to use a quatum generaton (?)) by fetching them from:
http://random.irb.hr/
They give you a python class t insert into your code, but you need to
register to use it (free).
I am not affiliated to them in any way, I just used it once to play
with it and it worked.
Best,

-- 
Sebastián Bassi (セバスティアン)
Diplomado en Ciencia y Tecnología.
GPG Fingerprint: 9470 0980 620D ABFC BE63 A4A4 A3DE C97D 8422 D43D
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: an eval()-like exec()

2007-08-27 Thread Matt McCredie
> A python interactive interpreter works by having the user type in some
> code, compiling and running that code, then printing the results. For
> printing, the results are turned into strings.
>
> I would like make an interpreter which does this, without the last
> part: i.e. where the results are returned as objects, instead of as
> strings. I.e. have I would like to see something that behaves like
> this:
>
> >>> ip = MyInterpreter()
> # this started a new interpreter
> >>> ip.run("import math") is None
> True
> >>> ip.run("math.pi") is math.pi
> True
>
> Neither exec() or eval() is usable for this, as far as I see, because
> eval can't handle arbitrary python code (eval("import math") ), and
> exec() doesn't return the results.
>
> Subclassing an code.InteractiveInterpreter or code.InteractiveConsole
> seems like a usable idea, but I couldn't find out what to do to get
> the results before they are turned into strings.
>
> Using compile() and then eval() didn't seem usable either.
>
> Any ideas?

Well, my first thought is that exec and eval serve two different
purposes, and you should just have both of them and use the
appropriate one based on the situation. However, I think it is
possible to enable the behavior you want:

[code]
def myeval(statement, globals_=None, locals_=None):
try:
return eval(statement, globals_, locals_)
except SyntaxError:
if locals_ is None:
import inspect
locals_ = inspect.currentframe().f_back.f_locals
exec statement in globals_, locals_
[/code]

It seems to work for me.

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


  1   2   >