Re: difference between urllib2.urlopen and firefox view 'page source'?

2007-03-20 Thread Tina I
cjl wrote:
 Hi.
 
 I am trying to screen scrape some stock data from yahoo, so I am
 trying to use urllib2 to retrieve the html and beautiful soup for the
 parsing.
 
 Maybe (most likely) I am doing something wrong, but when I use
 urllib2.urlopen to fetch a page, and when I view 'page source' of the
 exact same URL in firefox, I am seeing slight differences in the raw
 html.
 
 Do I need to set a browser agent so yahoo thinks urllib2 is firefox?
 Is yahoo detecting that urllib2 doesn't process javascript, and
 passing different data?
 
 -cjl
 
Unless the data you you need depends on the site detecting a specific 
browser you will probably receive a 'cleaner' code that's more easily 
parsed if you don't set a user agent. Usually the browser optimization 
they do is just eye candy, bells and whistles anyway in order to give 
you a more 'pleasing experience'. I doubt that your program will care 
about that ;)

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


Re: Anything available that can read Microsoft .MDB files from Python?

2007-03-20 Thread Diez B. Roggisch
 
What MDBtools did you install?  The RPM, a checkout from CVS,
 or the downloadable distribution?  They're all different.


The one that comes with ubuntu edgy. Just


apt-get install mdbtools

or something, that's it.

I don't want to start a distro war here - but I always found the 
RPM-based distros lacking, to say the least.

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


Re: When is List Comprehension inappropriate?

2007-03-20 Thread bearophileHUGS
BJörn Lindqvist:
 While they
 may be faster, Psyco is great here. Also, if you have lots of 2d-loops
 like for x in something: for y in something:, then it could be more
 beautiful to separate the iteration from the task:

 def iterimage(im, width, height, step = 1):
 for y in range(0, height, step):
 for x in range(0, width, step):
 yield (x, y), im.getpixel((x, y))

Just a note: Psyco usually isn't able to speed up generators (ShedSkin
recently has hadded a support of them too, and it seem fast enough).

Bye,
bearophile

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


Re: Anything available that can read Microsoft .MDB files from Python?

2007-03-20 Thread Shane Geiger
Try installing it from source.  Perhaps getting a newer verion is all 
you would need.  If at that point you find there is a bug, report it.



Diez B. Roggisch wrote:

   What MDBtools did you install?  The RPM, a checkout from CVS,
or the downloadable distribution?  They're all different.




The one that comes with ubuntu edgy. Just


apt-get install mdbtools

or something, that's it.

I don't want to start a distro war here - but I always found the 
RPM-based distros lacking, to say the least.


Diez
  


--
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
x-mozilla-html:FALSE
url:http://www.ncee.net
version:2.1
end:vcard

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

Re: Anything available that can read Microsoft .MDB files from Python?

2007-03-20 Thread Duncan Booth
Terry Reedy [EMAIL PROTECTED] wrote:

 
[EMAIL PROTECTED] wrote in message 
 news:[EMAIL PROTECTED]
| I've read .MDB files using ODBC. I don't know how big your files are,
| but I had a file with almost 3000 rows and I was able to fetch it in
| 1-2 seconds. If you want to give it whirl, you just need to create an
| ODBC connection and then do the following:
 
 I'll just mention that OpenOffice.org Base can make ODBC connections and 
 output in several formats.  Don't know if their ODBC works with .MDB.
 

I just tried opening an mdb file from Open Office under Ubuntu. No problems 
whatsoever except that the pulldown for 'Connect to an existing database' 
listed 'Microsoft Access' twice. (This was a completely standard, never 
before run, copy of Base.)


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


python java

2007-03-20 Thread sandeep patil
hi

i am fresher i python can any bady tell me who i will use python in
web technologies in java base application.
what it roll

sandeep patil

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


Re: any ways to judge whether an object is initilized or not in a class

2007-03-20 Thread Bruno Desthuilliers
Steven D'Aprano a écrit :
 On Mon, 19 Mar 2007 19:48:37 +1100, Ben Finney wrote:
 
 It's also best to inherit every class from another class, leading to a
 single hierarchy for all classes and types. 'object' is the one to
 choose if you don't want the behaviour of any other class.
 
 What's wrong with old-style classes?

Almost everything. That's why Python 2.2 introduced new-style classes. 
IIRC it was some 6 years ago now.

 On the plus side:
 
 - Why inherit from something if you don't need to?

You don't have to inherit. You can also make a class new-style by 
setting it's __metaclass__ attribute properly. But that's more typing !-)

 - Less typing.

Lol. Six keystrokes in the worst case.

 - Attribute-lookup is much faster, perhaps as much as twice as fast.
 http://www.python.org/~jeremy/weblog/030506.html

This was in 2003. Did you bother testing now ? with Python 2.4.4:

  class Old:
... def __init__(self):
... self.attr = old
...
  class New(object):
... def __init__(self):
... self.attr = new
...
  from timeit import Timer
  told = Timer('old.attr', 'from __main__ import Old; old=Old()')
  tnew = Timer('new.attr', 'from __main__ import New; new=New()')
  told.repeat()
[0.40867519378662109, 0.39075493812561035, 0.38998913764953613]
  tnew.repeat()
[0.58840394020080566, 0.5948030948638916, 0.36941695213317871]

Not really twice as fast AFAICT.

Now if you're really favor raw speed over expressivity, then you might 
wan to choose another language.

 
 - Documentation on old style classes is more extensive.

Since new-style classes are backward compatible with old-style ones, 
almost all the old-style classes documentation applies to new-style ones 
as well. Everything else is quite well documented too:
http://www.python.org/doc/newstyle/

 - You can't use new style classes for exceptions.

Exceptions are new-style classes in 2.5.

 
 
 On the minus side:
 
 - Properties don't work as you expect them too.

properties don't work. Period. Properties rely on the descriptor 
protocol, which only works with new-style classes.

 - Slots don't work at all.
 
  - no support for the descriptor protocol
  - no __getattribute__
  - no metaclasses
  - no proper constructor
  - no classmethod
  - no super()

 In other words, the only reason why you HAVE to use a new style class is
 that you need properties or __slots__.

The reason why you have to use new-style classes is that it's the 
official Python object model since december 2001 - old-style classes 
being kept for compatibility. The reason why you want to use them is 
that they provide everything old-style classes did, and *way much more*. 
FWIW, if Python didn't have this powerful object model, I would have 
switched to another language long ago. And I'm probably not the only one.

 You might WANT to use a new style
 class to inherit from built-in types. 

Since builtin types are all new-style classes, any class inheriting from 
a builtin is a new-style class. FWIW, that's one of the reason for the 
object model changes way back in 2001.

 Otherwise, the choice between old
 and new is not very important.

Your opinion. Too bad you're missing some of the most powerful parts of 
the language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python java

2007-03-20 Thread rishi pathak

See www.*jython*.org

On 20 Mar 2007 02:23:07 -0700, sandeep patil [EMAIL PROTECTED]
wrote:


hi

i am fresher i python can any bady tell me who i will use python in
web technologies in java base application.
what it roll

sandeep patil

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





--
Regards--
Rishi Pathak
National PARAM Supercomputing Facility
Center for Development of Advanced Computing(C-DAC)
Pune University Campus,Ganesh Khind Road
Pune-Maharastra
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: XML based programming language

2007-03-20 Thread stefaan
 Don't you think the lex/yacc combo is complex even in anything in
 real-life?
If real-life means: C++, then yes, it is impossible :)
If real-life means: some domain specific language, then it is ok.

The XML tree simplification implementations (as Elementtree
 can be considered) has other complex tasks to do.

I fully agree. Perhaps I need a validating parser with user-definable
hooks for semantic actions. This would be a layer on top of
Elementtree.



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


Re: Re: python java

2007-03-20 Thread rishi pathak

Jython is written in pure java.
You can use java classes inside python and also can use python classes
inside java
You can write applets too in python using jython.
It converts your python code in java code.


On 20 Mar 2007 10:06:00 -, sandeep patil [EMAIL PROTECTED]
wrote:


  what diff betn python  jython


On Tue, 20 Mar 2007 rishi pathak wrote :

See www.*jython*.org

On 20 Mar 2007 02:23:07 -0700, sandeep patil [EMAIL PROTECTED]
wrote:

hi

i am fresher i python can any bady tell me who i will use python in
web technologies in java base application.
what it roll

sandeep patil

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




-- Regards--
Rishi Pathak
National PARAM Supercomputing Facility
Center for Development of Advanced Computing(C-DAC)
Pune University Campus,Ganesh Khind Road
Pune-Maharastra



[image: 
Diageo]http://adworks.rediff.com/cgi-bin/AdWorks/click.cgi/www.rediff.com/signature-home.htm/[EMAIL
 PROTECTED]/1119380_1113690/1118605/1?PARTNER=3OAS_QUERY=null+target=new+





--
Regards--
Rishi Pathak
National PARAM Supercomputing Facility
Center for Development of Advanced Computing(C-DAC)
Pune University Campus,Ganesh Khind Road
Pune-Maharastra
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Create TarFile using string buffers

2007-03-20 Thread Gabriel Genellina
En Mon, 19 Mar 2007 21:55:30 -0300, [EMAIL PROTECTED]  
[EMAIL PROTECTED] escribió:

 Thanks. It almost works. The problem is I don't know the size of the
 file until it has finished streaming. It looks like the tar file
 format need the file size written at the beginning :(

Yes, maybe because it's originally a tape format. Anyway it could be done;  
addfile() could seek back to the header and patch it after the file size  
is known...

-- 
Gabriel Genellina

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


Re: When is List Comprehension inappropriate?

2007-03-20 Thread Steve Holden
Alex Martelli wrote:
 BJörn Lindqvist [EMAIL PROTECTED] wrote:
...
 even2 = [(pos, col) for pos, col in iterimage(im, width, height, 2)]
 
 list(iterimage(etc etc))
 
 is surely a better way to express identical semantics.  More generally,
 [x for x in whatever] (whether x is a single name or gets peculiarly
 unpacked and repacked like here) is a good example of inappropriate LC,
 to get back to the question in the subject: list(whatever) is the one
 obvious way to perform the same task.
 
Clearly the comprehension you complain about is sub-optimal.

The essential difference, however, is between

   [x for x in iterimage(im, width, height, 2)]

and

   list(iterimage(im, width, height, 2))

I agree that the latter is the obvious way, but the difference isn't as 
large as your leap makes it look - and we had to await the invention of 
the generator expression for it to be a practical choice.

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

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


Re: XML based programming language

2007-03-20 Thread Diez B. Roggisch
stefaan wrote:

 All of these are grammar-specifications that allow you to define the
 structure of your XML-documents with more constraints.
 
 Ok, I should have foreseen the schema checker answer...my point really
 is that
 yacc can do even more than just checking the conformance to a grammar.
 
 It also allows me to specify semantic actions,
 e.g. to help in building an abstract syntax tree from
 the concrete syntax tree, or to implement a very basic
 interpreter...
 
 mock example:
 inputdefinevar name=a value=10/definevar name=b value=12 /
/input
 outputsum arg1=a arg2=b//output
 
 No schema checker can take this specification and simply output 22.
 XSLT might be able to implement it, but it is complex for anything
 real-life. Elementtree can immediately give me the concrete syntax
 tree,
 but any semantic actions have to be implemented during a
 manually programmed tree traversal.

Yep, they have. But to be brutally honest: I haven't felt the need to go
with semantic actions when using e.g. ANTLR. IMHO it only works for small
examples like the one above. The mixing of syntactic structure definition
together with real code gets really messy, and you are very rigid
regarding even smaller grammar changes.

The very moment you are getting more complex, you want an AST, and work upon
that. It will be much easier and robust to work on it, even if you alter
your grammar a bit.

And XML _is_ your AST, and working on it means... writing code. 
*If* there was anything as yacc regarding semantic actions, it would be an
extension to XSD or any other schema. I'm not aware of such a beast.

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


Re: python java

2007-03-20 Thread Diez B. Roggisch
sandeep patil wrote:

 hi
 
 i am fresher i python can any bady tell me who i will use python in
 web technologies in java base application.
 what it roll

No idea where who rolls to whom, but you should check out jython:

http://www.jython.org/

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


Re: Load three different modules which have the same name

2007-03-20 Thread abcd
 Blerch! Why not just call the modules by the right names in the first
 place? Then each will have its own sys.modules entry for a start ...

 regards
   Steve

what do i need to do?  also, is there a way I can load each one as I
have but each one have its own unique entry in sys.modules?  For
example i could load Person from Person (in alpha) as, Person_Alpha
or something like that in sys.modules?  not sure how I might do that.

Thanks!

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


Re: Load three different modules which have the same name

2007-03-20 Thread Gabriel Genellina
En Tue, 20 Mar 2007 07:40:53 -0300, abcd [EMAIL PROTECTED] escribió:

 Blerch! Why not just call the modules by the right names in the first
 place? Then each will have its own sys.modules entry for a start ...

 what do i need to do?  also, is there a way I can load each one as I
 have but each one have its own unique entry in sys.modules?  For
 example i could load Person from Person (in alpha) as, Person_Alpha
 or something like that in sys.modules?  not sure how I might do that.

Use the as clause when importing; it's almost the same phrase you wrote  
above:
 from alpha.Person import Person as Person_Alpha
or something like that.
alpha should be a package, as someone already said.

-- 
Gabriel Genellina

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


Re: Displaying EPS in a GUI

2007-03-20 Thread Piet van Oostrum
 [EMAIL PROTECTED] (V) wrote:

V Does anybody know of a good way to display Encapsulated Postscript
V images in a GUI? I'm currently using wx, but would be perfectly
V willing to switch to another binding to keep the program from becoming
V hackish.

You need e Postscript interpreter, e.g. Ghostscript.
If you have Ghostscript installed PIL can read EPS images. Then they can be
converted to wx images:
http://wiki.wxpython.org/index.cgi/WorkingWithImages
-- 
Piet van Oostrum [EMAIL PROTECTED]
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Load three different modules which have the same name

2007-03-20 Thread Steve Holden
abcd wrote:
 Blerch! Why not just call the modules by the right names in the first
 place? Then each will have its own sys.modules entry for a start ...

 regards
   Steve
 
 what do i need to do?  also, is there a way I can load each one as I
 have but each one have its own unique entry in sys.modules?  For
 example i could load Person from Person (in alpha) as, Person_Alpha
 or something like that in sys.modules?  not sure how I might do that.
 
 Thanks!
 
The easiest way to proceed is simply to call the .py files by different 
names - then they automatically get theor own sys.modules entry.

[sys.modules is a dictionary where you can look modules up by name. it's 
helpful to ensure each module gets its own entry, and the presence of 
the entry is how the system avoids unnecessary reloading of modules].

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

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


Re: Load three different modules which have the same name

2007-03-20 Thread Ben Finney
abcd [EMAIL PROTECTED] writes:

 nevermind this took care of it:

 import sys

 def tryAllThree():
 a = c:\\alpha
 b = c:\\beta
 g = c:\\gamma

 sys.path.append(a)
 import Person
 alpha = Person.Person()

To avoid this confusion, follow PEP 8
URL:http://www.python.org/dev/peps/pep-0008/; in particular, name
your classes with TitleCase and name your modules (i.e., name the
files that contain the code) with lowercase.

import person
alpha_person = person.Person()

As to the original question, you've already seen the answer:

from alpha import person
alpha_person = person.Person()

from beta import person
beta = person.Person()

from gamma import person
gamma_person = person.Person()

-- 
 \  If I ever get real rich, I hope I'm not real mean to poor |
  `\   people, like I am now.  -- Jack Handey |
_o__)  |
Ben Finney

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


Re: List to string

2007-03-20 Thread Bruno Desthuilliers
Steven D'Aprano a écrit :
 On Mon, 19 Mar 2007 13:11:09 +0100, Bruno Desthuilliers wrote:
 
 There's no cast in Python. It would make no sens in a dynamically 
 typed language, where type informations belong to the LHS of a binding, 
 not the RHS.
 
 Surely you have left and right mixed up?

(rereading)
(ashamed)
Obviously, yes.
Thanks for the correction.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pycron for windows - please help

2007-03-20 Thread Al
heh... didn't think about that... thanks.

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


Bullet proof passing numeric values from NMEA data stream.

2007-03-20 Thread Doug Gray
Folks,
I am looking for a fast but most importantly a bullet proof method to pass
and NMEA data stream (GPS output) ascii numeric strings. The best I can
offer is:

def fint(a):
 try: return int(float(a))
 except: return 0

The reason for this is the quality of the data from the huge variety of
GPS units available varies considerably.  Some units do not follow the
standard and I want to pass the data as best I can without hanging the
code for an oddball data value.

Can anyone suggest better?

For example, each of the following throw the exception so do not return
the correct value:

int('00.')
int(' 00.')
float('-  00')
float(' -  00')
float(' -  00')
float(' -  00.')
float('-  00.')
float('-  10.')
float('- 10.')
float('- 10.')
int('- 10.')
int('- 10.')
float('- 10.')
int('1.0')

Also, why should I consider the string module?  Is it faster/better?

TIA,
Doug
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any ways to judge whether an object is initilized or not in a class

2007-03-20 Thread Steven D'Aprano
On Tue, 20 Mar 2007 10:28:10 +0100, Bruno Desthuilliers wrote:

[deploying weapons of mass snippage]

 Otherwise, the choice between old
 and new is not very important.
 
 Your opinion. Too bad you're missing some of the most powerful parts of 
 the language.

Yes, it is my opinion, and it seems that in your zeal to defend new-style
classes against an imaginary attack, you've completely misunderstood what
my opinion is.

I'm not against new-style classes. I do use new-style classes. There are a
whole lot of extra features that new-style classes have that old-style
classes don't have, some of which I didn't even think of. (Thanks for
pointing them out, and I'm not being sarcastic.)

There are plenty of reasons for preferring new style classes. If those
reasons hold for you, then of course you should use new style classes.

But that's not the same thing as saying that you should use new style
classes *even when you don't care about those features*.

I never once suggested that new style classes are unnecessary, or a waste
of time, or bad, or whatever else you seem to think I was saying. My point
was, if you don't _need_ a new style class, there is no reason to avoid
using an old style class. It is a purely personal choice.

There seems to be a misunderstanding that classic classes have been
depreciated. They certainly have not. We've been told that old style
classes will eventually disappear, probably in Python 3. That is not
the same thing at all. The docs are very careful to avoid saying that old
style classes are depreciated.

(See, for example http://docs.python.org/ref/node33.html)

What I predict is that under the hood, Python 3 will complete the job of
unifying types and classes. The distinction between classic classes and
new style classes will go away. All classes will behave the same, whether
you write class X: or class X(): or class X(object): or whatever
syntax Python 3 uses for defining classes.



-- 
Steven.

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


How to send

2007-03-20 Thread Admir Saric
Hi,

i have created an application in pygtk. The application creates files with 
its own file type and extensions and saves them. I would like to extend the 
application to be able to send these files over WLAN. I would use the 
application in my Nokia 770 Internet tablet and send the files from one 
tablet to the other. Does anybody know how to make python application send 
files over the WLAN.

Best regards
Admir

_
Schlagerfeber på MSN! http://festival.msn.se/

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


Re: List to string

2007-03-20 Thread Steven D'Aprano
On Tue, 20 Mar 2007 13:01:36 +0100, Bruno Desthuilliers wrote:

 Steven D'Aprano a écrit :
 On Mon, 19 Mar 2007 13:11:09 +0100, Bruno Desthuilliers wrote:
 
 There's no cast in Python. It would make no sens in a dynamically 
 typed language, where type informations belong to the LHS of a binding, 
 not the RHS.
 
 Surely you have left and right mixed up?
 
 (rereading)
 (ashamed)
 Obviously, yes.
 Thanks for the correction.

That's okay, I have a big L and R written on the bottom of my shoes.
Of course, they didn't do me any good until I got a L and R tattooed
on my feet.



-- 
Steven.

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


Re: Load three different modules which have the same name

2007-03-20 Thread abcd
thanks for the help.

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


Re: Eureka moments in Python

2007-03-20 Thread Doug Gray
On Tue, 13 Mar 2007 18:16:15 +1100, Steven D'Aprano wrote:

 I'd be interested in hearing people's stories of Eureka moments in Python,
 moments where you suddenly realise that some task which seemed like it
 would be hard work was easy with Python.

Mine was the discovery of the pybluez module.

I had been sweating the task of interfacing a bluetooth GPS unit to my
python applicaton. I googled for 'python bluetooth GPS' and found 20 lines
of python code that had the interface up and running before breakfast.
This included the package install with 'yum install pybluez' in Fedora
Core 5.

See:
http://www.robertprice.co.uk/robblog/archive/2007/1/Using_A_Bluetooth_GPS_From_Python.shtml

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


Re: any ways to judge whether an object is initilized or not in a class

2007-03-20 Thread Steven D'Aprano
On Tue, 20 Mar 2007 10:28:10 +0100, Bruno Desthuilliers complained about
classic classes:

 What's wrong with old-style classes?
 
 Almost everything. 

That's rather an exaggeration, don't you think? They have methods, and
inheritance, and attributes, all the critical features of classes, and
work perfectly well even if they don't support the more advanced features.


 - Documentation on old style classes is more extensive.
 
 Since new-style classes are backward compatible with old-style ones, 

Then almost everything is wrong with new style classes too? *wink*


 almost all the old-style classes documentation applies to new-style ones 
 as well. Everything else is quite well documented too:
 http://www.python.org/doc/newstyle/

On that very page, the first sentence says:

Unfortunately, new-style classes have not yet been integrated into
Python's standard documention.

complete with spelling mistake.


 On the minus side:
 
 - Properties don't work as you expect them too.
 
 properties don't work. Period. Properties rely on the descriptor 
 protocol, which only works with new-style classes.

Non-data descriptors (e.g. properties with only a getter) work fine. It is
only data descriptors (those with both a getter and a setter) that don't
work correctly.


   - no metaclasses

Metaclasses worked all the way back in Python 1.5, although they were
painful and brain-exploding.

http://www.python.org/doc/essays/metaclasses


   - no classmethod

Guido's own documentation for classmethods and staticmethods uses classic
classes. See

http://www.python.org/download/releases/2.2.3/descrintro/#staticmethods

But don't just take his word for it, try it for yourself *wink*



-- 
Steven

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


Re: Bullet proof passing numeric values from NMEA data stream.

2007-03-20 Thread Steve Holden
Doug Gray wrote:
 Folks,
 I am looking for a fast but most importantly a bullet proof method to pass
 and NMEA data stream (GPS output) ascii numeric strings. The best I can
 offer is:
 
 def fint(a):
  try: return int(float(a))
  except: return 0
 
 The reason for this is the quality of the data from the huge variety of
 GPS units available varies considerably.  Some units do not follow the
 standard and I want to pass the data as best I can without hanging the
 code for an oddball data value.
 
 Can anyone suggest better?
 
 For example, each of the following throw the exception so do not return
 the correct value:
 
 int('00.')
 int(' 00.')
 float('-  00')
 float(' -  00')
 float(' -  00')
 float(' -  00.')
 float('-  00.')
 float('-  10.')
 float('- 10.')
 float('- 10.')
 int('- 10.')
 int('- 10.')
 float('- 10.')
 int('1.0')
 
 Also, why should I consider the string module?  Is it faster/better?
 
 TIA,
 Doug

Try something like

def fint(s):
   return float(s.replace( , ))

I really don't think it's a good idea to silently ignore conversion 
errors in GPS positioning.

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

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


Re: Problem with sockets and python 2.5

2007-03-20 Thread Facundo Batista
Jose Alberto Reguero wrote:

 2:
   server.py at x86_64 python 2.5
   client.py at i386 python 2.4
 Don't work

What do you mean with don't work?

They crash? Your machine hungs? Your house explodes?

You'd be more specific in the error you get, and what behaviour you
expect.

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


How to copy a ClassObject?

2007-03-20 Thread Karlo Lozovina
Hi all,

how would one make a copy of a class object? Let's say I have:
  class First:
name = 'First'

And then I write:
  tmp = First

then 'tmp' becomes just a reference to First, so if I write 
tmp.name = Tmp, there goes my First.name. So, how to make 'tmp' a copy 
of First, I tried using copy.copy and copy.deepcopy, but that doesn't 
work.

P.S.
Yes, I can do a:
  class tmp(First):
  pass

but I'd rather make a copy than a subclass.

Thanks.

-- 
 ___Karlo Lozovina - Mosor
|   |   |.-.-. web: http://www.mosor.net || ICQ#: 10667163
|   ||  _  |  _  | Parce mihi domine quia Dalmata sum.
|__|_|__||_|_|
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When is List Comprehension inappropriate?

2007-03-20 Thread Aahz
In article [EMAIL PROTECTED],
Alex Martelli [EMAIL PROTECTED] wrote:

list(iterimage(etc etc))

is surely a better way to express identical semantics.  More generally,
[x for x in whatever] (whether x is a single name or gets peculiarly
unpacked and repacked like here) is a good example of inappropriate LC,
to get back to the question in the subject: list(whatever) is the one
obvious way to perform the same task.

Except of course, when it's

[x for x in whatever if x]

I'm exceedingly fond of replacing filter() with listcomps.  They're so
much more readable and often faster.
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

Typing is cheap.  Thinking is expensive.  --Roy Smith
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Still the __new__ hell ...

2007-03-20 Thread Aahz
In article [EMAIL PROTECTED],
Alex Martelli [EMAIL PROTECTED] wrote:
Steve Holden [EMAIL PROTECTED] wrote:
 
 basestring is a *type*.
 
basestring
 type 'basestring'
 
 It's the base class of which both str and unicode are subclasses.

I believe it used to be a tuple back in Python 2.2 (sorry, don't have a
Python 2.2 installation to check this right now).

Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
Type help, copyright, credits or license for more information.
 basestring
Traceback (most recent call last):
  File stdin, line 1, in ?
NameError: name 'basestring' is not defined
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

Typing is cheap.  Thinking is expensive.  --Roy Smith
-- 
http://mail.python.org/mailman/listinfo/python-list


How many connections can accept a 'binded' socket?

2007-03-20 Thread billiejoex
Hi,
I'm writing a small asyncore-based server application serving a lot of
clients. When I have to handle more than 1021 client simoultaneously
the 'binded' socket object raises an error:

[...]
connections: 1018
connections: 1019
connections: 1020
connections: 1021
Traceback (most recent call last):
  File asyncore_client.py, line 31, in module
  File asyncore.py, line 191, in loop
  File asyncore.py, line 138, in poll
  File asyncore.py, line 80, in write
  File asyncore.py, line 76, in write
  File asyncore.py, line 395, in handle_write_event
  File asyncore_client.py, line 24, in handle_connect
  File asyncore_client.py, line 9, in __init__
  File asyncore.py, line 257, in create_socket
  File socket.py, line 156, in __init__
socket.error: (24, 'Too many open files')

I just wanna know: is there a way to know how many connections can
accept a 'binded' socket BEFORE getting such error? Maybe
socket.SOMAXCONN could help me?

Thanks in advance.

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


Re: How many connections can accept a 'binded' socket?

2007-03-20 Thread Laurent Pointal
billiejoex a écrit :
 Hi,
 I'm writing a small asyncore-based server application serving a lot of
 clients. When I have to handle more than 1021 client simoultaneously
 the 'binded' socket object raises an error:
 
 [...]
 connections: 1018
 connections: 1019
 connections: 1020
 connections: 1021
 Traceback (most recent call last):
   File asyncore_client.py, line 31, in module
   File asyncore.py, line 191, in loop
   File asyncore.py, line 138, in poll
   File asyncore.py, line 80, in write
   File asyncore.py, line 76, in write
   File asyncore.py, line 395, in handle_write_event
   File asyncore_client.py, line 24, in handle_connect
   File asyncore_client.py, line 9, in __init__
   File asyncore.py, line 257, in create_socket
   File socket.py, line 156, in __init__
 socket.error: (24, 'Too many open files')
 
 I just wanna know: is there a way to know how many connections can
 accept a 'binded' socket BEFORE getting such error? Maybe
 socket.SOMAXCONN could help me?

Here you get out of file descriptors, I dont think SOMAXCONN would help.

Under Linux (maybe Unix), there is ulimit -n nnn to setup the maximum
number of files descriptors. I don't know its upper limit (maybe a
kernel compile time information).


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


Re: Bullet proof passing numeric values from NMEA data stream.

2007-03-20 Thread Steven D'Aprano
On Tue, 20 Mar 2007 12:09:29 +, Doug Gray wrote:

 Folks,
 I am looking for a fast but most importantly a bullet proof method to pass
 and NMEA data stream (GPS output) ascii numeric strings. The best I can
 offer is:
 
 def fint(a):
  try: return int(float(a))
  except: return 0


Will your application calculate the wrong results if it starts getting a
whole lot of spurious zeroes? Wouldn't it better to signal this value is
invalid rather than a false zero?

Do you actually want ints? It seems to me that if your data stream is
delivering floats, you're throwing away a lot of data. For example, if the
data stream is: 

2.4, 5.7, 3.9, 5.1, ...

you're getting:

2, 5, 3, 5, ...

which is possibly not even the right way to convert to ints. Shouldn't you
be rounding to nearest (i.e. 2, 6, 4, 5, ...)?

[snip]

 For example, each of the following throw the exception so do not return
 the correct value:
[snip examples]

All your examples include spurious whitespace. If that is the only
problem, here's a simple fix:

def despace(s):
Remove whitespace from string s.
return 

def fix_data(value):
Fix a GPS value string and return as a float.
return float(''.join(value.split()))


If only a few values are malformed, you might find this is faster:

def fix_data2(value):
try:
return float(value)
except ValueError:
return float(''.join(value.split()))

Only measurement with actual realistic data will tell you which is faster.

If you expect to get random non-numeric characters, then here's another
solution:

import string
# initialize some global data
table = string.maketrans(, ) # all 8 bit characters
keep = 1234567890.-+
dontkeep = ''.join([c for c in table if c not in keep])

def fix_data3(value):
try: # a fast conversion first
return float(value)
except ValueError: # fall-back conversion
return float(string.translate(value, table, don'tkeep))

Once you've built the character tables, the translate function itself is
executed in C and is very fast.


 Also, why should I consider the string module?  Is it faster/better?

Most of the time you should use string methods, e.g.:

hello world.upper() 

instead of 

string.upper(hello world)

The only time you should use the string module is when you need one of the
functions (or data objects) that don't exist as string methods (e.g.
translate).



-- 
Steven.

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


Re: How to copy a ClassObject?

2007-03-20 Thread Marc 'BlackJack' Rintsch
In [EMAIL PROTECTED], Karlo Lozovina wrote:

 how would one make a copy of a class object? Let's say I have:
   class First:
 name = 'First'
 
 And then I write:
   tmp = First
 
 then 'tmp' becomes just a reference to First, so if I write 
 tmp.name = Tmp, there goes my First.name. So, how to make 'tmp' a copy 
 of First, I tried using copy.copy and copy.deepcopy, but that doesn't 
 work.
 
 P.S.
 Yes, I can do a:
   class tmp(First):
   pass
 
 but I'd rather make a copy than a subclass.

Why?  Python isn't a prototype based programming language.

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


Re: How to copy a ClassObject?

2007-03-20 Thread Karlo Lozovina
Karlo Lozovina [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 how would one make a copy of a class object? Let's say I have:
   class First:
 name = 'First'
 
 And then I write:
   tmp = First

Silly me, posted a question without Googling first ;. This seems to be 
the answer to my question:

import new
class First:
name = 'First'
tmp = new.classobj('tmp', (First,), {})

After this, tmp is a copy of First, and modifying tmp.name will not affect 
First.name.

P.S.
If my code is somehow mistaken and might not function properly in all 
cases, please correct me. 

Bye,
klm.

-- 
 ___Karlo Lozovina - Mosor
|   |   |.-.-. web: http://www.mosor.net || ICQ#: 10667163
|   ||  _  |  _  | Parce mihi domine quia Dalmata sum.
|__|_|__||_|_|
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Bullet proof passing numeric values from NMEA data stream.

2007-03-20 Thread Steven D'Aprano
On Wed, 21 Mar 2007 00:29:00 +1100, Steven D'Aprano wrote:

 All your examples include spurious whitespace. If that is the only
 problem, here's a simple fix:
 
 def despace(s):
 Remove whitespace from string s.
 return 

Gah! Ignore that stub. I forgot to delete it :(


While I'm at it, here's another solution: simply skip invalid values,
using a pair of iterators, one to collect raw values from the device and
one to strip out the invalid results.

def raw_data():
Generator to collect raw data and pass it on.
while 1:
# grab a single value
value = grab_data_value_from_somewhere()
if value is : # Some special END TRANSMISSION value.
return
yield value

def converter(stream):
Generator to strip out values that can't be converted to float.
for value in stream:
try:
yield float(value)
except ValueError:
pass

values_safe_to_use = converter(raw_data())

for value in values_safe_to_use:
print value


Naturally you can extend the converter to try harder to convert the string
to a float before giving up.


-- 
Steven.

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


Re: Problem with sockets and python 2.5

2007-03-20 Thread Fabio FZero
On Mar 20, 10:05 am, Facundo Batista [EMAIL PROTECTED]
wrote:
 Jose Alberto Reguero wrote:
  2:
 server.py at x86_64 python 2.5
 client.py at i386 python 2.4
  Don't work

 What do you mean with don't work?

 They crash? Your machine hungs? Your house explodes?

Traceback (most recent call last):
  File server.py, line 1, in module
DontWorkError: YOUR HEAD A SPLODE!

:D

FZ

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


help - Module needs access to another module

2007-03-20 Thread abcd
I have the following directory/file structure...

c:\foo\utils.py
c:\foo\bar\ok.py

In ok.py I want to do something like...

import utils
utils.helpMeDoSomething()

However, it seems that ok.py doesn't know about utils.  Other than
manually configuring sys.path what can I do?

thanks

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


Re: Bullet proof passing numeric values from NMEA data stream.

2007-03-20 Thread Doug Gray
On Wed, 21 Mar 2007 00:29:00 +1100, Steven D'Aprano wrote:

 On Tue, 20 Mar 2007 12:09:29 +, Doug Gray wrote:
 
 Folks,
 I am looking for a fast but most importantly a bullet proof method to pass
 and NMEA data stream (GPS output) ascii numeric strings. The best I can
 offer is:
 
 def fint(a):
  try: return int(float(a))
  except: return 0
 
 
 Will your application calculate the wrong results if it starts getting a
 whole lot of spurious zeroes? Wouldn't it better to signal this value is
 invalid rather than a false zero?
 
 Do you actually want ints? It seems to me that if your data stream is
 delivering floats, you're throwing away a lot of data. For example, if the
 data stream is: 
 
 2.4, 5.7, 3.9, 5.1, ...
 
 you're getting:
 
 2, 5, 3, 5, ...
 
 which is possibly not even the right way to convert to ints. Shouldn't you
 be rounding to nearest (i.e. 2, 6, 4, 5, ...)?
 
 [snip]
 

Thanks, a very helpful response. I'll need some time to fully digest.
Yes I will need a float variant, the int version was by way of example. I
can deal with the rounding etc as necessary, but I was after an
pythonistic view of the generic problem.

Re the examples: whitespace and mal positioned signs and decimal point
would be the obvious errors I might expect but of course this is
speculation.  The few GPS units I have tried have all tripped up my first
cut less tolerant code.  I am going to revise the interface to work around
potential problems and my preliminary test efforts highlighted more
exceptions than I expected.

Doug


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


Re: help - Module needs access to another module

2007-03-20 Thread Diez B. Roggisch
abcd wrote:

 I have the following directory/file structure...
 
 c:\foo\utils.py
 c:\foo\bar\ok.py
 
 In ok.py I want to do something like...
 
 import utils
 utils.helpMeDoSomething()
 
 However, it seems that ok.py doesn't know about utils.  Other than
 manually configuring sys.path what can I do?

After a bunch of questions of that kind, I suggest you take a step back, and
read this:

http://docs.python.org/tut/node8.html

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


Re: How to copy a ClassObject?

2007-03-20 Thread Peter Otten
Karlo Lozovina wrote:

 Yes, I can do a:
   class tmp(First):
   pass
 
 but I'd rather make a copy than a subclass.

 tmp = new.classobj('tmp', (First,), {})

That line creates a subclass just as the simpler approach you gave above.

Peter


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


Re: python QT or python-GTK

2007-03-20 Thread Christophe
Dennis Lee Bieber a écrit :
   Not enough experience here... I do know I never liked applications
 targeted to the Gnome look, preferring KDE... So... which toolkit did
 those desktops favor?
 
   wxWidgets, as I recall, is supposed to attempt to look native on
 each OS.

Well, wxWidgets targets the Gnome look ( it means it uses GTK on Linux ) 
and not the KDE look so I guess you wouldn't like wxWidgets either :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help - Module needs access to another module

2007-03-20 Thread abcd
On Mar 20, 9:58 am, Diez B. Roggisch [EMAIL PROTECTED] wrote:
 After a bunch of questions of that kind, I suggest you take a step back, and
 read this:

 http://docs.python.org/tut/node8.html


got it, thanks.

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


Re: help - Module needs access to another module

2007-03-20 Thread Carsten Haese
On Tue, 2007-03-20 at 06:46 -0700, abcd wrote:
 I have the following directory/file structure...
 
 c:\foo\utils.py
 c:\foo\bar\ok.py
 
 In ok.py I want to do something like...
 
 import utils
 utils.helpMeDoSomething()
 
 However, it seems that ok.py doesn't know about utils.  Other than
 manually configuring sys.path what can I do?

Why would you want to do something other than changing sys.path? Except
for physically moving utils to somewhere that's already on the path,
changing the path is cleanest way to handle this situation.

-Carsten


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


Re: How to copy a ClassObject?

2007-03-20 Thread Duncan Booth
Karlo Lozovina [EMAIL PROTECTED] wrote:

 After this, tmp is a copy of First, and modifying tmp.name will not
 affect First.name.

As Peter said, it's not a copy, its a subclass.

Modifying tmp.name would affect First.name (although in your example it is 
immutable so you cannot modify it).
Also, rebinding First.name will change the value you see in tmp.name 
whereas rebinding tmp.name will hide the copy inherited from First.name (so 
a later del would restore it).

 If my code is somehow mistaken and might not function properly in all 
 cases, please correct me. 

Consider yourself corrected.

You could do what you are attempting with:

   tmp = new.classobj('tmp', First.__bases__, dict(First.__dict__))

which creates a new class named 'tmp' with the same base classes and a copy 
of First's __dict__ except that the __name__ attribute for the new class 
will be set to 'tmp'. The attribute values are still shared between the 
classes (which is significant only if they are mutable), but otherwise they 
won't be sharing state.

I have no idea why you would want to do this, nor even why you would want a   
'name' attribute when Python already gives you '__name__'.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to send

2007-03-20 Thread kyosohma
On Mar 20, 7:21 am, Admir Saric [EMAIL PROTECTED] wrote:
 Hi,

 i have created an application in pygtk. The application creates files with
 its own file type and extensions and saves them. I would like to extend the
 application to be able to send these files over WLAN. I would use the
 application in my Nokia 770 Internet tablet and send the files from one
 tablet to the other. Does anybody know how to make python application send
 files over the WLAN.

 Best regards
 Admir

 _
 Schlagerfeber på MSN!http://festival.msn.se/

Probably the easiest way to do this would be to use either the socket
module or the smtp module

Sockets:
http://www.amk.ca/python/howto/sockets/
http://www.quepublishing.com/articles/article.asp?p=686162rl=1

SMTP:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52243

You could even do FTP:
http://snippets.dzone.com/posts/show/711

Good luck!

Mike

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


Re: Still the __new__ hell ...

2007-03-20 Thread Gabriel Genellina
En Tue, 20 Mar 2007 10:16:30 -0300, Aahz [EMAIL PROTECTED] escribió:

 In article [EMAIL PROTECTED],
 Alex Martelli [EMAIL PROTECTED] wrote:
 Steve Holden [EMAIL PROTECTED] wrote:

 basestring is a *type*.

 I believe it used to be a tuple back in Python 2.2 (sorry, don't have a
 Python 2.2 installation to check this right now).

 Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
 [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
 Type help, copyright, credits or license for more information.
 basestring
 Traceback (most recent call last):
   File stdin, line 1, in ?
 NameError: name 'basestring' is not defined

On 2.2 it appeared types.StringTypes == (str,unicode)

-- 
Gabriel Genellina

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


Subject line with smtplib.sendmail()

2007-03-20 Thread Boudreau, Emile
Hey,
I'm trying to send mail from my server to my machine with test
results. I can send the email no problem however, the email doesn't
contain a recipient list or a subject line. I was wondering how
would I go about getting the information on the actual To and
Subject lines so that I know to whom the email was sent and the
subject line without opening the email?

Thanks in advance for the help.

Emile Boudreau
 
 This message may contain privileged and/or confidential information.  If 
you have received this e-mail in error or are not the intended recipient, you 
may not use, copy, disseminate or distribute it; do not open any attachments, 
delete it immediately from your system and notify the sender promptly by e-mail 
that you have done so.  Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Pycron for windows - please help

2007-03-20 Thread Shane Geiger
Here's something else you should consider:  Look at the source code of 
pycron.  I just downloaded it.  Much to my surprise, this is implemented 
in about 115 lines of code.


In particular, look at the run() function.  You should try adding a 
try-except block around the system call to get a hint as to where the 
problem lies:



   try:
os.system('start ' + command)  


   
except:  

   print Unexpected error to catch:, 
sys.exc_info()[0]



I've been trying to use it myself (on a Mac) since I saw you mention it 
on the mailing list.  I'm also having problems using pycron.  Email me 
directly if you figure out the problem.  I'll do the same for you.






Gabriel Genellina wrote:

En Mon, 19 Mar 2007 16:00:04 -0300, Al [EMAIL PROTECTED] escribió:

  

I looked in the pycron.log file, and I noticed that for the entires of
my new job, I see rc=4 and the end of each line. All other jobs have
rc=0 at the end of the line. I assume then, that rc=4 is a reference
to an error code of some kind, but there is no information on this in
the readme.txt, at the pycron website, or here in groups.

Does anyone know how to troubleshhot this? Thanks in advance.



Contacting the author?

  


--
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
x-mozilla-html:FALSE
url:http://www.ncee.net
version:2.1
end:vcard

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

Re: class objects, method objects, function objects

2007-03-20 Thread Fredrik Lundh
Dennis Lee Bieber wrote:

 it(the -- argument list, not the object -- ) is unpacked again

no, it refers to the bound method object, as 7stud would have realized if
he'd read the entire paragraph.  here's the relevant portion:

   /.../ a method object is created by packing (pointers to) the instance object
   and the function object just found together in an abstract object: this is 
the
   method object. When the method object is called with an argument list, it
   is unpacked again /.../

/F 



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


Punit v 0.1 - Python CD ripper

2007-03-20 Thread Mark Bryan Yu
Here's the initial release of my personal open source project to
create a Python CD ripper in Linux.

Punit is a Audio CD ripper for Linux using cdparanoia, LAME and
CDDB.py (http://cddb-py.sourceforge.net/)

http://www.programmingmind.com/bryan/punit.html

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


Re: Subject line with smtplib.sendmail()

2007-03-20 Thread Fredrik Lundh
Boudreau, Emile wrote:

 I'm trying to send mail from my server to my machine with test
 results. I can send the email no problem however, the email doesn't
 contain a recipient list or a subject line. I was wondering how
 would I go about getting the information on the actual To and
 Subject lines so that I know to whom the email was sent and the
 subject line without opening the email?

you have to add the headers yourself.  see the example in the library
reference, or this FAQ entry:

http://effbot.org/pyfaq/how-do-i-send-mail-from-a-python-script

/F 



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


Re: When is List Comprehension inappropriate?

2007-03-20 Thread Alex Martelli
Aahz [EMAIL PROTECTED] wrote:

 In article [EMAIL PROTECTED],
 Alex Martelli [EMAIL PROTECTED] wrote:
 
 list(iterimage(etc etc))
 
 is surely a better way to express identical semantics.  More generally,
 [x for x in whatever] (whether x is a single name or gets peculiarly
 unpacked and repacked like here) is a good example of inappropriate LC,
 to get back to the question in the subject: list(whatever) is the one
 obvious way to perform the same task.
 
 Except of course, when it's
 
 [x for x in whatever if x]
 
 I'm exceedingly fond of replacing filter() with listcomps.  They're so
 much more readable and often faster.

Sure, if there are other clauses in the LC (be they for or if ones) you
can't just call list(...) -- and I do entirely agree that filter can be
put out to pasture.  Similarly, you need the LC if you're performing
some processing on the items -- for example, if you have an iterator
yielding pairs,
  [(y,x) for x,y in whatever]
you do need the unpacking and repacking to achieve this swapping of
items within each pair -- what I was pointing out was re the simpler and
most common case:
  [(x,y) for x,y in whatever]
no processing needed, no if clauses, etc, and thus better expressed as
  list(whatever)


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


Re: Still the __new__ hell ...

2007-03-20 Thread Alex Martelli
Aahz [EMAIL PROTECTED] wrote:

 In article [EMAIL PROTECTED],
 Alex Martelli [EMAIL PROTECTED] wrote:
 Steve Holden [EMAIL PROTECTED] wrote:
  
  basestring is a *type*.
  
 basestring
  type 'basestring'
  
  It's the base class of which both str and unicode are subclasses.
 
 I believe it used to be a tuple back in Python 2.2 (sorry, don't have a
 Python 2.2 installation to check this right now).
 
 Python 2.2.2 (#1, Feb 24 2003, 19:13:11)
 [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2
 Type help, copyright, credits or license for more information.
  basestring
 Traceback (most recent call last):
   File stdin, line 1, in ?
 NameError: name 'basestring' is not defined

Thanks for double checking on my vague and apparently incorrect
historical memory!  Obviously I must have been thinking of some _trick_
whereby one bound basestring to the pair to make isinstance on
basestring work in 2.2 much as it did later, rather than an intrinsic
2.2 feature.


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


Re: How many connections can accept a 'binded' socket?

2007-03-20 Thread Alex Martelli
Laurent Pointal [EMAIL PROTECTED] wrote:

 billiejoex a écrit :
  Hi,
  I'm writing a small asyncore-based server application serving a lot of
  clients. When I have to handle more than 1021 client simoultaneously
  the 'binded' socket object raises an error:
  
  [...]
  connections: 1018
  connections: 1019
  connections: 1020
  connections: 1021
  Traceback (most recent call last):
File asyncore_client.py, line 31, in module
File asyncore.py, line 191, in loop
File asyncore.py, line 138, in poll
File asyncore.py, line 80, in write
File asyncore.py, line 76, in write
File asyncore.py, line 395, in handle_write_event
File asyncore_client.py, line 24, in handle_connect
File asyncore_client.py, line 9, in __init__
File asyncore.py, line 257, in create_socket
File socket.py, line 156, in __init__
  socket.error: (24, 'Too many open files')
  
  I just wanna know: is there a way to know how many connections can
  accept a 'binded' socket BEFORE getting such error? Maybe
  socket.SOMAXCONN could help me?
 
 Here you get out of file descriptors, I dont think SOMAXCONN would help.
 
 Under Linux (maybe Unix), there is ulimit -n nnn to setup the maximum
 number of files descriptors. I don't know its upper limit (maybe a
 kernel compile time information).

A shell command

ulimit -Hn

should report on the hard-limit of the number of open file descriptors;
just ulimit -n should report on the current soft-limit.

If you're going to pass the fd's to select, as asyncore does by default,
a separate limit of 1024 is unfortunately likely to apply anyway; so,
once that ulimit is raised, you may want to pass argument use_poll as
true to asyncore.loop.  The performance of poll with a huge number of
sockets may however not be all that shiny.  Better mechanisms, such as
epoll or kqueue, I believe, are not available for asyncore, even if your
OS supports them; to serve thousands of open sockets with good
performance, you may need to switch to Twisted (which offers many more
implementations of the abstract Reactor interface -- you don't _have_ to
use Twisted's higher layers if you don't want to).


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


Re: any ways to judge whether an object is initilized or not in a class

2007-03-20 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote:
   ...
 There are plenty of reasons for preferring new style classes. If those
 reasons hold for you, then of course you should use new style classes.
 
 But that's not the same thing as saying that you should use new style
 classes *even when you don't care about those features*.

You should always use new-style classes in order to avoid having to stop
and make a decision each time you code a class -- having to stop and ask
yourself do I need any of the many extra features of new-style classes
here, or will legacy classes suffice? each and every time.

There should ideally be only one obvious way -- and that obvious way is
to always use new-style classes and avoid a feature that's there only
for backwards compatibility with legacy code.

It's a specific case of the general rule adopt good habits as
routines; I recommend Limoncelli's excellent treatment of that subject
in his Time Management for System Administrators book.  By not having
to ask yourself do I really need to do X each and every time, but
making it an absolute and invariant habit to always do it, as long as X
is a good habit (will be useful some of the time and not damaging the
rest of the time), you save yourself time-waste, aggravation, and
useless expenditure of attention and mental energy.

 What I predict is that under the hood, Python 3 will complete the job of
 unifying types and classes. The distinction between classic classes and
 new style classes will go away. All classes will behave the same, whether
 you write class X: or class X(): or class X(object): or whatever
 syntax Python 3 uses for defining classes.

Sure -- all the semantical peculiarity of legacy classes will disappear
(and won't be missed).  But meanwhile, no reason not to adopt good
habits.


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


Re: class objects, method objects, function objects

2007-03-20 Thread 7stud
Thanks Duncan and Dennis.

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


os.wait() for Windows

2007-03-20 Thread Damien Byrne
Hello,

I am new to python. I am using the os module to run a command in a 
bashshell. However I need this process to complete before continuing. Is 
there a command that will wait for this process to complete? I am using 
Windows XP and the os.wait() command only works for UNIX systems, and 
therefore doesn't work.

My code is as follows:

import os
FileName = raw_input('Enter the file name: ')
os.system('abaqus job=FileName')
resultsFile = open('FileName.dat','r')

Abaqus will take a few minutes to complete and create the associated results 
file. However once I run this code I get the following error ... IOError: 
[Errno 2] No such file or directory: 'FileName.dat' ... as the file does 
not exist yet. Is there any way of waiting for the job to complete before 
continuing?

I'd appreciate any help.

_
Share folders without harming wildlife! 
http://www.communicationevolved.com/en-ie/

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


Re: Load three different modules which have the same name

2007-03-20 Thread Alex Martelli
Gabriel Genellina [EMAIL PROTECTED] wrote:
   ...
  example i could load Person from Person (in alpha) as, Person_Alpha
  or something like that in sys.modules?  not sure how I might do that.
 
 Use the as clause when importing; it's almost the same phrase you wrote
 above:
  from alpha.Person import Person as Person_Alpha
 or something like that.
 alpha should be a package, as someone already said.

Right, but the as clause does NOT affect sys.modules -- the entry in
sys.modules will still be sys.modules['alpha.Person'].  I doubt this
matters, but since the OP had very specifically askd about in
sys.modules I thought it better to clarify.

If you want to make fake entries in sys.modules you need to do that
explicitly,importing sys and assigning to the entry:

sys.modules['veryweird'] = extremely_tricky_stuph

The only purpose of that is to fool future import veryweird
statements (executed under any circumstances) to use said extremely
tricky stuph.  NOT recommended unless you know what you're doing.


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


Re: difference between urllib2.urlopen and firefox view 'page source'?

2007-03-20 Thread kyosohma
On Mar 20, 1:56 am, Tina I [EMAIL PROTECTED] wrote:
 cjl wrote:
  Hi.

  I am trying to screen scrape some stock data from yahoo, so I am
  trying to use urllib2 to retrieve the html and beautiful soup for the
  parsing.

  Maybe (most likely) I am doing something wrong, but when I use
  urllib2.urlopen to fetch a page, and when I view 'page source' of the
  exact same URL in firefox, I am seeing slight differences in the raw
  html.

  Do I need to set a browser agent so yahoo thinks urllib2 is firefox?
  Is yahoo detecting that urllib2 doesn't process javascript, and
  passing different data?

  -cjl

 Unless the data you you need depends on the site detecting a specific
 browser you will probably receive a 'cleaner' code that's more easily
 parsed if you don't set a user agent. Usually the browser optimization
 they do is just eye candy, bells and whistles anyway in order to give
 you a more 'pleasing experience'. I doubt that your program will care
 about that ;)

 Tina

You can do this fairly easily. I found a similar program in the book
Core Python Programming. It actually sticks the stocks into an Excel
spreadsheet. The code is below. You can easily modify it to send the
output elsewhere.


# Core Python Chp 23, pg 994
# estock.pyw

from Tkinter import Tk
from time import sleep, ctime
from tkMessageBox import showwarning
from urllib import urlopen
import win32com.client as win32

warn = lambda app: showwarning(app, 'Exit?')
RANGE = range(3, 8)
TICKS = ('AMZN', 'AMD', 'EBAY', 'GOOG', 'MSFT', 'YHOO')
COLS = ('TICKER', 'PRICE', 'CHG', '%AGE')
URL = 'http://quote.yahoo.com/d/quotes.csv?s=%sf=sl1c1p2'

def excel():
app = 'Excel'
xl = win32.gencache.EnsureDispatch('%s.Application' % app)
ss = xl.Workbooks.Add()
sh = ss.ActiveSheet
xl.Visible = True
sleep(1)

sh.Cells(1, 1).Value = 'Python-to-%s Stock Quote Demo' % app
sleep(1)
sh.Cells(3, 1).Value = 'Prices quoted as of: %s' % ctime()
sleep(1)
for i in range(4):
sh.Cells(5, i+1).Value = COLS[i]
sleep(1)
sh.Range(sh.Cells(5, 1), sh.Cells(5, 4)).Font.Bold = True
sleep(1)
row = 6

u = urlopen(URL % ','.join(TICKS))
for data in u:
tick, price, chg, per = data.split(',')
sh.Cells(row, 1).Value = eval(tick)
sh.Cells(row, 2).Value = ('%.2f' % round(float(price), 2))
sh.Cells(row, 3).Value = chg
sh.Cells(row, 4).Value = eval(per.rstrip())
row += 1
sleep(1)
u.close()

warn(app)
ss.Close(False)
xl.Application.Quit()


if __name__ == '__main__':
Tk().withdraw()
excel()

# Have fun - Mike

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


Wanted: a python24 package for Python 2.3

2007-03-20 Thread Jonathan Fine
Hello

My problem is that I want a Python 2.4 module on
a server that is running Python 2.3.  I definitely
want to use the 2.4 module, and I don't want to
require the server to move to Python 2.4.

More exactly, I am using subprocess, which is
new in Python 2.4.  What I am writing is something
like
===
from subprocess import Popen
===

This will fail in Python 2.3, in which case I
would like to write something like
===
try:
 from subprocess import Popen
else ImportError:
 from somewhere_else import Popen
===

Put this way, it is clear (to me) that somewhere_else
should be python24.

In other words, I'm asking for a python24 package that
contains all (or most) of the modules that are new to
Python 2.4.

I've looked around a bit, and it seems that this
formulation of the solution is new.  I wonder if
anyone else has encountered this problem, or has
comments on my solution.

-- 
Jonathan

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


Re: os.wait() for Windows

2007-03-20 Thread kyosohma
On Mar 20, 10:32 am, Damien Byrne [EMAIL PROTECTED] wrote:
 Hello,

 I am new to python. I am using the os module to run a command in a
 bashshell. However I need this process to complete before continuing. Is
 there a command that will wait for this process to complete? I am using
 Windows XP and the os.wait() command only works for UNIX systems, and
 therefore doesn't work.

 My code is as follows:

 import os
 FileName = raw_input('Enter the file name: ')
 os.system('abaqus job=FileName')
 resultsFile = open('FileName.dat','r')

 Abaqus will take a few minutes to complete and create the associated results
 file. However once I run this code I get the following error ... IOError:
 [Errno 2] No such file or directory: 'FileName.dat' ... as the file does
 not exist yet. Is there any way of waiting for the job to complete before
 continuing?

 I'd appreciate any help.

 _
 Share folders without harming 
 wildlife!http://www.communicationevolved.com/en-ie/


I would recommend subprocess.call(programToRun) or
subprocess.Popen(programToRun).wait()

Mike

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


Re: Wanted: a python24 package for Python 2.3

2007-03-20 Thread kyosohma
On Mar 20, 10:33 am, Jonathan Fine [EMAIL PROTECTED] wrote:
 Hello

 My problem is that I want a Python 2.4 module on
 a server that is running Python 2.3.  I definitely
 want to use the 2.4 module, and I don't want to
 require the server to move to Python 2.4.

 More exactly, I am using subprocess, which is
 new in Python 2.4.  What I am writing is something
 like
 ===
 from subprocess import Popen
 ===

 This will fail in Python 2.3, in which case I
 would like to write something like
 ===
 try:
  from subprocess import Popen
 else ImportError:
  from somewhere_else import Popen
 ===

 Put this way, it is clear (to me) that somewhere_else
 should be python24.

 In other words, I'm asking for a python24 package that
 contains all (or most) of the modules that are new to
 Python 2.4.

 I've looked around a bit, and it seems that this
 formulation of the solution is new.  I wonder if
 anyone else has encountered this problem, or has
 comments on my solution.

 --
 Jonathan

You might be able to use the from future import SomeModule syntax to
accomplish this, but I am not sure. Other than that, I would just
recommend using the os.popen calls that are native to 2.3

Mike

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


Re: Wanted: a python24 package for Python 2.3

2007-03-20 Thread Alex Martelli
Jonathan Fine [EMAIL PROTECTED] wrote:
   ...
 In other words, I'm asking for a python24 package that
 contains all (or most) of the modules that are new to
 Python 2.4.

For subprocess specifically, see
http://www.lysator.liu.se/~astrand/popen5/ .  I don't think anybody's
ever packaged up ALL the new stuff as you require.


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


making objects with individual attributes!

2007-03-20 Thread Alejandro
I have created a class:

class document:

titre = ''
haveWords = set()

def __init__(self, string):

self.titre = string

#

doc1 = document('doc1')
doc2 = document('doc2')

doc1.haveWords.add(1)
doc2.haveWords.add(2)


print doc1.haveWords

# i get set([1, 2])


doc1 and doc are sharing attribute haveWords!
Why ??? there's a way to assign every objetc document a different
set

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


Re: Eureka moments in Python

2007-03-20 Thread Sion Arrowsmith
Sion Arrowsmith  [EMAIL PROTECTED] wrote:
This is more a batteries included eureka moment than a Python one,
but writing a fetchmail substitute in 6 lines was an eye-opener.

On Fri, Mar 16, 2007 at 01:23:14PM -0500, someone emailed:
[This is a newsgroup/mailing list -- potentially useful information
like this should be shared, not taken to private email.]
 Would you mind sharing your fetchmail substitute code with me?  I'm
 curious to know what that looks like.

Unfortunately, I threw it away, as it was so trivial and I only needed
a one-shot solution. I kept meaning to come back to it and add some
configurability and error checking and such (and most importantly
providing an envelope From), but never did. The general idea is to
take the POP3 example from the library reference
(http://docs.python.org/lib/pop3-example.html) and replace the inner
for loop with smtplib.SMTP('localhost').sendmail('', 'user',
'\n'.join(M.retr(i+1)[1]))

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

#!/usr/bin/env python 2.4?

2007-03-20 Thread rh0dium
Hi Folks,

OK I love the logging module.  I use it everywhere.  I was happily
putting at the top of each of my scripts

--snip--
#!/usr/bin/env python2.4

import logging

LOGLEVEL=logging.INFO

# Set's up a basic logger
logging.basicConfig(level=LOGLEVEL, format=%(asctime)s %(name)s %
(levelname)-8s %(message)s,
datefmt='%d %b %Y %H:%M:%S', stream=sys.stderr)

try:
module= os.path.basename(traceback.extract_stack(limit=2)[1]
[0]).split(.py)[0]+.
except:
module = os.path.basename(traceback.extract_stack(limit=2)[0]
[0]).split(.py)[0]+.

def main(loglevel=False):
 
# Setup Logging
log = logging.getLogger(module+sys._getframe().f_code.co_name )
if loglevel is not False: log.setLevel(loglevel)
else:log.setLevel(logging.WARN)

log.debug(I LOVE LOGGING)

if __name__ == '__main__':
sys.exit(main(loglevel=LOGLEVEL))


--snip--

But now you guys continued to make this cool language and 2.5 came
out. Great now how do I put /usr/bin/env python2.4?

Or can you suggest a better way to skin this cat?

Thanks again!!

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


Freezing Python Apps on Linux?

2007-03-20 Thread Greg Copeland
I seem to recall several different applications which can create
standalone binaries for python on Linux.  I know freeze.py and
cx_Freeze.py exist.  Are these still the preferred methods of creating
a stand alone binary out of a python application on Linux?

Greg

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


Re: making objects with individual attributes!

2007-03-20 Thread Gary Herron
Alejandro wrote:
 I have created a class:

 class document:

 titre = ''
 haveWords = set()

 def __init__(self, string):

 self.titre = string

 #

 doc1 = document('doc1')
 doc2 = document('doc2')

 doc1.haveWords.add(1)
 doc2.haveWords.add(2)


 print doc1.haveWords

 # i get set([1, 2])


 doc1 and doc are sharing attribute haveWords!
 Why ??? there's a way to assign every objetc document a different
 set
   
Of course.  Try this:

class document:
def __init__(self, string):
self.titre = string
self.haveWords = set()

Each instance creation will call __init__ with the instance 
accessible through self, and that code will create two instance
specific attributes.

Don't use so called class level attributes (as in your example) 
unless you  *want* sharing between all instances of a class.

Gary Herron




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


Re: making objects with individual attributes!

2007-03-20 Thread kyosohma
On Mar 20, 11:08 am, Alejandro [EMAIL PROTECTED] wrote:
 I have created a class:

 class document:

 titre = ''
 haveWords = set()

 def __init__(self, string):

 self.titre = string

 #

 doc1 = document('doc1')
 doc2 = document('doc2')

 doc1.haveWords.add(1)
 doc2.haveWords.add(2)

 print doc1.haveWords

 # i get set([1, 2])

 doc1 and doc are sharing attribute haveWords!
 Why ??? there's a way to assign every objetc document a different
 set

You're just slightly off. The code needs to be more like this:

class document:

def __init__(self, string):

self.titre = string
self.haveWords = set()

##

I think what you did was create some kind of global variable that was
then accessible through the namespace. But I really don't know for
sure. This code seems to work now, though.

Mike

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


Re: making objects with individual attributes!

2007-03-20 Thread Diez B. Roggisch
Alejandro wrote:

 I have created a class:
 
 class document:
 
 titre = ''
 haveWords = set()
 
 def __init__(self, string):
 
 self.titre = string
 
 #
 
 doc1 = document('doc1')
 doc2 = document('doc2')
 
 doc1.haveWords.add(1)
 doc2.haveWords.add(2)
 
 
 print doc1.haveWords
 
 # i get set([1, 2])
 
 
 doc1 and doc are sharing attribute haveWords!
 Why ??? there's a way to assign every objetc document a different
 set

Yes, by using instance-attributes instead of class-attributes, as you do.

Btw, it's common to name classes in python with a capital first letter, and
you should use new-style classes, which means you need to subclass it from
object:

class Document(object):

def __init__(self):
self.haveWords = set()


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


Re: Wanted: a python24 package for Python 2.3

2007-03-20 Thread Jonathan Fine
[EMAIL PROTECTED] wrote:
 On Mar 20, 10:33 am, Jonathan Fine [EMAIL PROTECTED] wrote:

My problem is that I want a Python 2.4 module on
a server that is running Python 2.3.  I definitely
want to use the 2.4 module, and I don't want to
require the server to move to Python 2.4.

 You might be able to use the from future import SomeModule syntax to
 accomplish this, but I am not sure. Other than that, I would just
 recommend using the os.popen calls that are native to 2.3

I've already made my mind up.  I want to use subprocess on
both 2.3 and 2.4.  To do this, 2.3 sites have to have a copy
of the subprocess module.

My question (snipped) is how best to package this up.

best regards


Jonathan

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


Re: Wanted: a python24 package for Python 2.3

2007-03-20 Thread Gerald Klix
Hi,
You can't import subproces from future, only syntactic and semantic 
changes that will become standard feature in future python version can 
be activated that way.

You can copy the subprocess module from python 2.4 somewhere where it 
will be found from python 2.3. At least subporcess is importable after that:

--- snip ---
[EMAIL PROTECTED]:~/ttt cp -av /usr/local/lib/python2.4/subprocess.py .
»/usr/local/lib/python2.4/subprocess.py« - »./subprocess.py«
[EMAIL PROTECTED]:~/ttt python2.3
Python 2.3.3 (#1, Jun 29 2004, 14:43:40)
[GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2
Type help, copyright, credits or license for more information.
  import subprocess
 
--- snip ---

HTH,
Gerald

[EMAIL PROTECTED] schrieb:
 On Mar 20, 10:33 am, Jonathan Fine [EMAIL PROTECTED] wrote:
 
Hello

My problem is that I want a Python 2.4 module on
a server that is running Python 2.3.  I definitely
want to use the 2.4 module, and I don't want to
require the server to move to Python 2.4.

More exactly, I am using subprocess, which is
new in Python 2.4.  What I am writing is something
like
===
from subprocess import Popen
===

This will fail in Python 2.3, in which case I
would like to write something like
===
try:
 from subprocess import Popen
else ImportError:
 from somewhere_else import Popen
===

Put this way, it is clear (to me) that somewhere_else
should be python24.

In other words, I'm asking for a python24 package that
contains all (or most) of the modules that are new to
Python 2.4.

I've looked around a bit, and it seems that this
formulation of the solution is new.  I wonder if
anyone else has encountered this problem, or has
comments on my solution.

--
Jonathan
 
 
 You might be able to use the from future import SomeModule syntax to
 accomplish this, but I am not sure. Other than that, I would just
 recommend using the os.popen calls that are native to 2.3
 
 Mike
 

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


Re: How many connections can accept a 'binded' socket?

2007-03-20 Thread John Nagle
billiejoex wrote:
 Hi,
 I'm writing a small asyncore-based server application serving a lot of
 clients. When I have to handle more than 1021 client simoultaneously
 the 'binded' socket object raises an error:

 When you ask questions like this, please specify what
operating system you're using.   Thanks.

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


if __name__ == 'main':

2007-03-20 Thread gtb
Hi,

I often see the following 'if' construct in python code. What does
this idiom accomplish? What happens if this is not main? How did I get
here if it is not main?

Thanks,

gtb

==

if __name__ == 'main':
   myQuest('myQuest').Run()

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


P: maticna graficka monitor

2007-03-20 Thread Gigs_
prodajem:

maticnu sapphire am2rd580adv, pola god stara, pod garancijom - 700kn

graficku sapphire x1650 pro 256 mb pola god start pod garancijom - 600kn

monitor philips 190p6es brilliance (kostao 4.100), star 1.5 godinu 
garancija vrijedi jos 1.5 godinu - 2000kn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: P: maticna graficka monitor

2007-03-20 Thread Gigs_
Gigs_ wrote:
 prodajem:
 
 maticnu sapphire am2rd580adv, pola god stara, pod garancijom - 700kn
 
 graficku sapphire x1650 pro 256 mb pola god start pod garancijom - 600kn
 
 monitor philips 190p6es brilliance (kostao 4.100), star 1.5 godinu 
 garancija vrijedi jos 1.5 godinu - 2000kn


sorry wrong group
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wanted: a python24 package for Python 2.3

2007-03-20 Thread Jonathan Fine
Alex Martelli wrote:
 Jonathan Fine [EMAIL PROTECTED] wrote:
...
 
In other words, I'm asking for a python24 package that
contains all (or most) of the modules that are new to
Python 2.4.
 
 
 For subprocess specifically, see
 http://www.lysator.liu.se/~astrand/popen5/ .  

Thanks for the URL.

 I don't think anybody's
 ever packaged up ALL the new stuff as you require.

Actually, all I require (for now) is subprocess.  So
I went and made a python24 module.  I'll change this
if people think something else would be better.  (It's
easy to ask for forgiveness than ask for permission.)

I can show you what I've done:
 http://texd.cvs.sourceforge.net/texd/py/python24/
http://texd.cvs.sourceforge.net/texd/py/tex/util.py?revision=1.4view=markup

My idea is that python24 should contain the Python 2.4
modules that those who are still on Python 2.3 might
want to use.

Similarly, python26 would be modules that are new
for Python 2.6 (which has not been released next).

I doubt that I'm the only one with this problem, and
this is my suggestion for making it easier to solve.

-- 
Jonathan


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


Re: #!/usr/bin/env python 2.4?

2007-03-20 Thread Steve Holden
rh0dium wrote:
 Hi Folks,
 
 OK I love the logging module.  I use it everywhere.  I was happily
 putting at the top of each of my scripts
 
 --snip--
 #!/usr/bin/env python2.4
 
[...]
 
 But now you guys continued to make this cool language and 2.5 came
 out. Great now how do I put /usr/bin/env python2.4?
 
 Or can you suggest a better way to skin this cat?
 
 Thanks again!!
 
The usual way is something like

#!/usr/bin/env python

Python usually installs so the latest version gets linked as 
/usr/bin/python. HTere's no need to bind your scripts to a particular 
version.

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

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


Re: if __name__ == 'main':

2007-03-20 Thread Facundo Batista
gtb wrote:


 I often see the following 'if' construct in python code. What does
 this idiom accomplish? What happens if this is not main? How did I get
 here if it is not main?
 ...
 if __name__ == 'main':
myQuest('myQuest').Run()

This idiom is for executing the code if you're running the .py directly,
or doing nothing if you're just importing the module. 

Take note, that when you import a module, __name__ gets the module name.

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/


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


Re: if __name__ == 'main':

2007-03-20 Thread Grant Edwards
On 2007-03-20, gtb [EMAIL PROTECTED] wrote:

 I often see the following 'if' construct in python code. What does
 this idiom accomplish?

It checks to see if the file is being run as the main
program, and does something if that is so.

 What happens if this is not main?

Nothing.

 How did I get here if it is not main?

By importing the file.

 if __name__ == 'main':
myQuest('myQuest').Run()



-- 
Grant Edwards   grante Yow!  Thank god!!... It's
  at   HENNY YOUNGMAN!!
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: any ways to judge whether an object is initilized or not in a class

2007-03-20 Thread Steven D'Aprano
On Tue, 20 Mar 2007 08:27:07 -0700, Alex Martelli wrote:

 You should always use new-style classes in order to avoid having to stop
 and make a decision each time you code a class -- having to stop and ask
 yourself do I need any of the many extra features of new-style classes
 here, or will legacy classes suffice? each and every time.

I can sympathize with your argument. I have taught myself to _always_
indicate when turning the car, even when I don't need to. I do it without
thinking, even when turning from my own driveway into my garage (much to
my wife's amusement). And that way, I don't have to think on the road do
I need to indicate now or not?, I just do it.

Rather than keep arguing my case (life is short...) I'll just mention that
both Fredrik Lundh and Aahz were very dismissive of the suggestion that
people should stop using classic classes back in July 2005.

http://www.thescripts.com/forum/thread25853.html

e.g. Aahz wrote: There's a big difference between being gung-ho on
new-style classes and telling people to stop using old-style classes.

Have they changed their mind since then? Not that I'm suggesting that
their opinions outweigh Alex's, but I'm not sure that the situation
vis-a-vis classes has changed that much since 2005. If it has, perhaps I
should be revising my opinion too.


-- 
Steven.

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


Re: if __name__ == 'main':

2007-03-20 Thread Patrick Down
On Mar 20, 11:49 am, gtb [EMAIL PROTECTED] wrote:
 Hi,

 I often see the following 'if' construct in python code. What does
 this idiom accomplish? What happens if this is not main? How did I get
 here if it is not main?

A quick example demonstrates the usage:

C:\codetype temp.py


print Module name is,__name__

if __name__ == __main__:
print I was not imported
else:
print I was imported

C:\codepython temp.py
Module name is __main__
I was not imported

C:\codepython
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
on win32
Type help, copyright, credits or license for more information.
 import temp
Module name is temp
I was imported


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


Yanqui bastards OPERATED 911 RACIST and HEINOUS CRIME Re: +++ Russia Watched 9/11 In REAL TIME on SATELLITE +++

2007-03-20 Thread thermate
Yank Bastards:

What evidence do you have for the 19 hijackers ?

What explanation do you have for thermate products ?

What evidence do INCOMPETENT Graduates of the FBI Academy have for the
suicide of building 7 ?

Why were FBI rats running around to confiscate the evidence of missile
hitting the Pentagon ?

Were the Passengers of the flights taken to Cincinnati incinerated in
a NASA incineration chamber ?

Why did the lawyer, Rudy Bastard Guiliani destroy the evidence of the
crime scene and why does FBI lack the balls to arrest him for a
federal crime ?

On Mar 18, 10:10 pm, [EMAIL PROTECTED] wrote:
 Anyone remember that marvelous photo of Putin when Bush visited Russia
 after 9/11. The most astute leader in the world, was looking at Bush
 into his eyes as if Bush was his adored boyfriend. It was a scene from
 a romance novel. It was the most hilarious photo. Indeed, Putin
 EXACTLY knew what 9/11 was and sought to turn that to his advantage.
 What could be more pleasing to this Russian than his competitor going
 and fighting with his enemy - the Afghan Mujahideen who drove USSR out
 of Afghanistan and led to its economic collapse. But Putin was
 watching US like a hawk, working on his economy, and plotting to put
 Khodorkovsky into jail. He had himself pioneered the use of a
 falseflag based on exploding apartment buildings to enter the second
 Chechen war.

 ===http://home.att.net/~south.tower/911RussianSatellite1.htm
 EXCELLENT LINK

 Russia Watched 9/11
 In Real Time On Satellite

 By Jon Carlson

 Your countrymen have been murdered and the more you delve into it
 the more it looks as though they were murdered by our government, who
 used it as an excuse to murder other people thousands of miles away.
 If you ridicule others who have sincere doubts and who know
 factual information that directly contradicts the official report and
 who want explanations from those who hold the keys to our government,
 and have motive, means, and opportunity to pull off a 9/11, but you
 are too lazy or fearful, or ... to check into the facts yourself, what
 does that make you?

 Full Statement of Lt. Col. Shelton F. Lankford, US Marine Corps (ret)
 Retired U.S. Marine Corps Fighter Pilot
 February 20, 2007

 http://www.patriotsquestion911.com/Statement%20Lankford.html

 In April, 2006, Journalist Webster Tarpley interviewed Thierry
 Meyssan, President of the Voltaire Network, an organization of 20
 different news agencies in Europe, Middle East and Africa, with
 correspondents in many countries. Thierry trumped America's pseudo-
 journalists with his 2002 book, Pentagate, drawing first blood on the
 Pentagon 9/11 Hoax.

 TM:. He (Gen. Ivashov) was the chief of armed forces in Russia on
 9/11. He says the Russian forces were watching North America because
 of the large military exercises being carried out by the US that day,
 so they saw in real time by satellite what was happening on that day.

 TM: When they heard about the attacks, Pres. Putin tried to call
 Bush to tell him that the Russians were not involved. He was not able
 to reach him. But they understood already that the collapse of the
 buildings could not have been done by the planes. They already
 realized it was controlled demolition - an internal problem and not an
 external attack

 WGT. How did US government, the State Dept respond to your
 (Pentagate) critique?
 TM. First they said I would not be allowed to go your country any
 more. Then Ms. Clark of State Dept said that if any journalist talks
 about my book in the US they will not be allowed to attend press
 conferences at the Pentagon. They published on their website a page
 trying to refute my book.

 http://www.waronfreedom.org/tarpley/rbn/RBN-42206-Meyssan.html

 In April, 2005, writer Chevalier Désireé, from France but formerly
 USA, revealed that Russia watched on their satellite as the A3
 Skywarrior left a carrier and impacted the Pentagon:

 It seems that it is common knowledge in these circles that Russian
 satellites photographed a ship-launched craft (seems to have been a
 drone type plane rather than a missle) that ended up impacting the
 Pentagon on Sept 11, 2001, and that, for various reasons this
 information has been withheld from the public.
 I was naturally startled to hear this even though I have long held
 the opinion that it was NOT a commercial jetliner that hit the
 Pentagon. I think the thing that startled me was the fact that, if
 Russia (and perhaps other countries with satellites?) had proof that
 Flight 77 did not hit the Pentagon, why weren't they revealing this?

 http://web.archive.org/web/20050728121017/http://perfectinfidel.blogs...

 In 2002 some US spy satellite photos from the sixties were released to
 the public domain:

 It's a welcome move, said Steven Aftergood of the Project on
 Government Secrecy, an effort of the Federation of American Scientists
 and based in Washington, D.C.
 First and foremost, 

Re: an enumerate question

2007-03-20 Thread Paulo da Silva
[EMAIL PROTECTED] escreveu:
 hi
 say i want to enumerate lines of a file
 eg
 for n,l in enumerate(open(file)):
  # print  next line ie
 
 is there a way to print out the next line from current line using the
 above?.
 Or do i have to do a readlines() first to get it into a list eg
 d = open(file).readlines()
 for n, l in enumerate(d):
 print d[n+1]
 
 thanks
 
for n,l in enumerate(file(file)):
print n,l[:-1] # the :-1 is to drop the \n - print n,l, also works (end
with ',').
HTH
Paulo

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


Re: List to string

2007-03-20 Thread Josh Bloom

That's pretty funny :)

On 3/20/07, Steven D'Aprano [EMAIL PROTECTED] wrote:


On Tue, 20 Mar 2007 13:01:36 +0100, Bruno Desthuilliers wrote:

 Steven D'Aprano a écrit :
 On Mon, 19 Mar 2007 13:11:09 +0100, Bruno Desthuilliers wrote:

 There's no cast in Python. It would make no sens in a dynamically
 typed language, where type informations belong to the LHS of a
binding,
 not the RHS.

 Surely you have left and right mixed up?

 (rereading)
 (ashamed)
 Obviously, yes.
 Thanks for the correction.

That's okay, I have a big L and R written on the bottom of my shoes.
Of course, they didn't do me any good until I got a L and R tattooed
on my feet.



--
Steven.

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

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

Exceptions when closing a file

2007-03-20 Thread Steven D'Aprano
Closing a file can (I believe) raise an exception. Is that documented
anywhere? I've spent a lot of frustrating time trying to track this down,
with no luck, which suggests that either my google-foo is weak or that it
isn't documented. Is IOError the only exception it can raise?

The only thing I have found is this:

http://mail.python.org/pipermail/python-bugs-list/2004-November/026031.html

Out of curiosity, is there a simple way to demonstrate close() raising an
exception that doesn't involve messing about with disk quotas? 


-- 
Steven.

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


Choosing new-style vs classic classes (was Re: any ways to judge whether an object is initilized or not in a class)

2007-03-20 Thread Aahz
In article [EMAIL PROTECTED],
Steven D'Aprano  [EMAIL PROTECTED] wrote:
On Tue, 20 Mar 2007 08:27:07 -0700, Alex Martelli wrote:

 You should always use new-style classes in order to avoid having to stop
 and make a decision each time you code a class -- having to stop and ask
 yourself do I need any of the many extra features of new-style classes
 here, or will legacy classes suffice? each and every time.

I can sympathize with your argument. I have taught myself to _always_
indicate when turning the car, even when I don't need to. I do it without
thinking, even when turning from my own driveway into my garage (much to
my wife's amusement). And that way, I don't have to think on the road do
I need to indicate now or not?, I just do it.

Rather than keep arguing my case (life is short...) I'll just mention that
both Fredrik Lundh and Aahz were very dismissive of the suggestion that
people should stop using classic classes back in July 2005.

http://www.thescripts.com/forum/thread25853.html

e.g. Aahz wrote: There's a big difference between being gung-ho on
new-style classes and telling people to stop using old-style classes.

Have they changed their mind since then? Not that I'm suggesting that
their opinions outweigh Alex's, but I'm not sure that the situation
vis-a-vis classes has changed that much since 2005. If it has, perhaps I
should be revising my opinion too.

My mind has not changed, and it has since been enshrined in _Python for
Dummies_.  ;-)  One point that I should make clear, because I think it
plays a large part of why Fredrik and I differ from Alex: my code at work
still runs on Python 2.2, which I believe should be avoided for heavy use
of new-style classes.  (The differences in new-style classes between 2.2
and later versions are small but significant, and I *don't* want to have
to think about them because we also use 2.3 at work.)  I believe Fredrik
still supports Python 1.5.2.  If you only support 2.3 and later,
suggesting a complete switchover to new-style classes becomes more
reasonable.

Moreover, my codebase at work started with Python 1.4, and upgrading it
all to correctly work with new-style classes would be a monumental
undertaking.  From my POV, as long as the bulk of the standard library is
still based on classic classes, that undertaking is not worth it.

I'm not quite as habitual as you are about turn signals, but I'm pretty
similar...
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

Typing is cheap.  Thinking is expensive.  --Roy Smith
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: difference between urllib2.urlopen and firefox view 'page source'?

2007-03-20 Thread John Nagle
Here's a useful online tool that might help you see what's happening:

http://www.sitetruth.com/experimental/viewer.html

We use this to help webmasters see what our web crawler is seeing.

This reads a page, using Python and FancyURLOpener, with a
USER-AGENT string of SiteTruth.com site rating system.
Then it parses the page with BeautifulSoup, removes all
SCRIPT, EMBED, and OBJECT tags, makes all the links
absolute, then writes the page back out in UTF-8 Unicode.
The resulting cleaned-up page is displayed.

If the page you're trying to read looks OK with our viewer,
you should be able to read it from Python with no problems.

John Nagle

cjl wrote:
 Hi.
 
 I am trying to screen scrape some stock data from yahoo, so I am
 trying to use urllib2 to retrieve the html and beautiful soup for the
 parsing.
 
 Maybe (most likely) I am doing something wrong, but when I use
 urllib2.urlopen to fetch a page, and when I view 'page source' of the
 exact same URL in firefox, I am seeing slight differences in the raw
 html.
 
 Do I need to set a browser agent so yahoo thinks urllib2 is firefox?
 Is yahoo detecting that urllib2 doesn't process javascript, and
 passing different data?
 
 -cjl
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Wanted: a python24 package for Python 2.3

2007-03-20 Thread Aahz
In article [EMAIL PROTECTED],
Alex Martelli [EMAIL PROTECTED] wrote:

For subprocess specifically, see
http://www.lysator.liu.se/~astrand/popen5/ .  I don't think anybody's
ever packaged up ALL the new stuff as you require.

Oh, good that web page came back.  (When we were down to the wire on
_Python for Dummies_, it had been offline for more than a month, and I
had to decide whether to include it, and I did.)
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

Typing is cheap.  Thinking is expensive.  --Roy Smith
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Anything available that can read Microsoft .MDB files from Python?

2007-03-20 Thread John Nagle
Shane Geiger wrote:
 Try installing it from source.  Perhaps getting a newer verion is all 
 you would need.  If at that point you find there is a bug, report it.

I did.

I finally got MDBtools to build by throwing out all the configure
stuff and the makefiles, then writing some simple makefiles of my own
that just build the command line tools.  The supplied build files
fail if you don't have bison, flex, autoconf, etc., although the
documentation claims otherwise.

There are some nice little command line tools in there,
fighting to get out from under all the guck.  The original
author intended, I think, to build this thing up into a full
database module for .MDB files.  But that was back around 2004
and never got done.  So MDBtools doesn't have enough stuff
to directly interface to MDB databases as databases, but
it has too much for a file format converter.  It's the extra
guck that has portability problems.

I posted the makefiles I used to the MDBtools forums on
SourceForge.

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


RE: Subject line with smtplib.sendmail()

2007-03-20 Thread Boudreau, Emile
Thanks for the reply. When I use the instruction from that list this is
the email I receive. I'm using Outlook.

[EMAIL PROTECTED]
To:
--
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Hello!

This Still DOESN't Work

It's just adding the From To Subject in the message itself. I want
to have each field at the correct place and then just the msg in the
body.

Any Help?? Thanks


Emile Boudreau


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Fredrik Lundh
Sent: Tuesday, March 20, 2007 11:08 AM
To: python-list@python.org
Subject: Re: Subject line with smtplib.sendmail()

Boudreau, Emile wrote:

 I'm trying to send mail from my server to my machine with test 
 results. I can send the email no problem however, the email doesn't 
 contain a recipient list or a subject line. I was wondering how 
 would I go about getting the information on the actual To and 
 Subject lines so that I know to whom the email was sent and the 
 subject line without opening the email?

you have to add the headers yourself.  see the example in the library
reference, or this FAQ entry:

http://effbot.org/pyfaq/how-do-i-send-mail-from-a-python-script

/F 



--
http://mail.python.org/mailman/listinfo/python-list
 
 This message may contain privileged and/or confidential information.  If 
you have received this e-mail in error or are not the intended recipient, you 
may not use, copy, disseminate or distribute it; do not open any attachments, 
delete it immediately from your system and notify the sender promptly by e-mail 
that you have done so.  Thank you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: if __name__ == 'main':

2007-03-20 Thread gtb
On Mar 20, 12:13 pm, Patrick Down [EMAIL PROTECTED] wrote:
 On Mar 20, 11:49 am, gtb [EMAIL PROTECTED] wrote:

  Hi,

  I often see the following 'if' construct in python code. What does
  this idiom accomplish? What happens if this is not main? How did I get
  here if it is not main?

 A quick example demonstrates the usage:

 C:\codetype temp.py

 print Module name is,__name__

 if __name__ == __main__:
 print I was not imported
 else:
 print I was imported

 C:\codepython temp.py
 Module name is __main__
 I was not imported

 C:\codepython
 Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)]
 on win32
 Type help, copyright, credits or license for more information. 
 import temp

 Module name is temp
 I was imported


Thanks, all! Makes great sense.


Teas all 'round the canteen now,

gtb

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


Re: Exceptions when closing a file

2007-03-20 Thread kyosohma
On Mar 20, 12:25 pm, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 Closing a file can (I believe) raise an exception. Is that documented
 anywhere? I've spent a lot of frustrating time trying to track this down,
 with no luck, which suggests that either my google-foo is weak or that it
 isn't documented. Is IOError the only exception it can raise?

 The only thing I have found is this:

 http://mail.python.org/pipermail/python-bugs-list/2004-November/02603...

 Out of curiosity, is there a simple way to demonstrate close() raising an
 exception that doesn't involve messing about with disk quotas?

 --
 Steven.

I've never had any problems closing a file. Maybe you need to flush it
before you close it? Are you running threads that access the file in
ad hoc fashion or something else out of the ordinary? Is this some
sort of long running process writing a large file?

Mike

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


Re: Exceptions when closing a file

2007-03-20 Thread Ross Ridge
Steven D'Aprano  [EMAIL PROTECTED] wrote:
Closing a file can (I believe) raise an exception. Is that documented
anywhere? 

In a catch-all statement for file objects: When a file operation fails
for an I/O-related reason, the exception IOError is raised.  The fact
that close() is a file operation that might fail is revealed by file
objects are implemented using C's stdio package and the fact the C's
fclose() function can fail.

 Is IOError the only exception it can raise?

I assume it can raise the exceptions MemoryError and KeyboardInterupt,
which just about any Python operation can raise.

Out of curiosity, is there a simple way to demonstrate close() raising an
exception that doesn't involve messing about with disk quotas? 

Something like the following should work:

f = file(/dev/null, r)
os.close(f.fileno)
f.close()

Normally however, you can expect file method close() to fail for all
the same reasons you would expect write() to fail.

Ross Ridge

-- 
 l/  //   Ross Ridge -- The Great HTMU
[oo][oo]  [EMAIL PROTECTED]
-()-/()/  http://www.csclub.uwaterloo.ca/~rridge/ 
 db  //   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Subject line with smtplib.sendmail()

2007-03-20 Thread kyosohma
On Mar 20, 12:50 pm, Boudreau, Emile [EMAIL PROTECTED]
wrote:
 Thanks for the reply. When I use the instruction from that list this is
 the email I receive. I'm using Outlook.

 [EMAIL PROTECTED]
 To:
 --
 From: [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Subject: Hello!

 This Still DOESN't Work

 It's just adding the From To Subject in the message itself. I want
 to have each field at the correct place and then just the msg in the
 body.

 Any Help?? Thanks

 Emile Boudreau

 -Original Message-
 From: [EMAIL PROTECTED]

 [mailto:[EMAIL PROTECTED] On
 Behalf Of Fredrik Lundh
 Sent: Tuesday, March 20, 2007 11:08 AM
 To: [EMAIL PROTECTED]
 Subject: Re: Subject line with smtplib.sendmail()

 Boudreau, Emile wrote:

  I'm trying to send mail from my server to my machine with test
  results. I can send the email no problem however, the email doesn't
  contain a recipient list or a subject line. I was wondering how
  would I go about getting the information on the actual To and
  Subject lines so that I know to whom the email was sent and the
  subject line without opening the email?

 you have to add the headers yourself.  see the example in the library
 reference, or this FAQ entry:

http://effbot.org/pyfaq/how-do-i-send-mail-from-a-python-script

 /F

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

  This message may contain privileged and/or confidential information.  If 
 you have received this e-mail in error or are not the intended recipient, you 
 may not use, copy, disseminate or distribute it; do not open any attachments, 
 delete it immediately from your system and notify the sender promptly by 
 e-mail that you have done so.  Thank you.

I'm not sure what the problem is. But here's how we do it at my place
of work:


import smtplib
import string

def sendMail(subject, body, TO = [EMAIL PROTECTED],
  FROM=[EMAIL PROTECTED]):
HOST = mailserver
BODY = string.join((
From: %s % FROM,
To: %s % TO,
Subject: %s % subject,
,
body
), \r\n)
server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO], BODY)
server.quit()


This works well for us.

Mike

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


RE: Subject line with smtplib.sendmail()

2007-03-20 Thread Boudreau, Emile
Sorry folks. Scrape the last one that I sent. I noticed that it sends
the email perfectly if the code is not in any of my methods but the
second I insert it into a method I get the ugly email that I described
in my last email. 

Does anyone know how I can get this code in my method so that I have
access to all the variables I have?

thanks


Emile Boudreau

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Boudreau, Emile
Sent: Tuesday, March 20, 2007 1:51 PM
To: python-list@python.org
Subject: RE: Subject line with smtplib.sendmail()

Thanks for the reply. When I use the instruction from that list this is
the email I receive. I'm using Outlook.

[EMAIL PROTECTED]
To:
--
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Hello!

This Still DOESN't Work

It's just adding the From To Subject in the message itself. I want
to have each field at the correct place and then just the msg in the
body.

Any Help?? Thanks


Emile Boudreau


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Fredrik Lundh
Sent: Tuesday, March 20, 2007 11:08 AM
To: python-list@python.org
Subject: Re: Subject line with smtplib.sendmail()

Boudreau, Emile wrote:

 I'm trying to send mail from my server to my machine with test 
 results. I can send the email no problem however, the email doesn't 
 contain a recipient list or a subject line. I was wondering how 
 would I go about getting the information on the actual To and 
 Subject lines so that I know to whom the email was sent and the 
 subject line without opening the email?

you have to add the headers yourself.  see the example in the library
reference, or this FAQ entry:

http://effbot.org/pyfaq/how-do-i-send-mail-from-a-python-script

/F 



--
http://mail.python.org/mailman/listinfo/python-list
 
 This message may contain privileged and/or confidential
information.  If you have received this e-mail in error or are not the
intended recipient, you may not use, copy, disseminate or distribute it;
do not open any attachments, delete it immediately from your system and
notify the sender promptly by e-mail that you have done so.  Thank you.
--
http://mail.python.org/mailman/listinfo/python-list

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


  1   2   >