Re: Convert xml symbol notation

2007-04-07 Thread dumbkiwi
On Apr 7, 5:23 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> dumbkiwi wrote:
> > I'm working on a script to download and parse a web page, and it
> > includes xml symbol notation, such as ' for the ' character.  Does
> > anyone know of a pre-existing python script/lib to convert the xml
> > notation back to the actual symbol it represents?
>
> Try the htmlentitydefs module.

Is that a standard module?  I can't see it anywhere - googled it.


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


Re: Understanding Python's interpreter

2007-04-07 Thread Gabriel Genellina
Rafael Almeida wrote:

> I'm studying compilers now on my university and I can't quite
> understand one thing about the python interpreter. Why is its input a
> binary file (pyc)? The LOAD_CONST opcode is 100 (dec) and STORE_FAST's
> is 125 (dec). The translation of the following code:
> 
> foo.py:
>   x = 10
> 
> Could be this:
> 
> foo.pyc:
>   100 10
>   125 0
> 
> That way you wouldn't need code such as 
> static void
> w_long(long x, WFILE *p)
> {
> w_byte((char)( x  & 0xff), p);
> w_byte((char)((x>> 8) & 0xff), p);
> w_byte((char)((x>>16) & 0xff), p);
> w_byte((char)((x>>24) & 0xff), p);
> }
> since you could read it with strtol and write back using a simple
> printf. So you wouldn't need a buch of casts by simple using ascii
> input and output.

A "simple" printf or strtol involves hundreds of instructions. And 
people want Python to execute fast...

> What's the reason for having it in a binary form instead of writting
> it in ascii? (yeah, I know ascii would be binary also, but I think you
> get my point.)

Speed? Eficiency? File size? Ease of use?
A .pyc *could* be written in ASCII, but what do you gain? Replacing a 
few trivial functions in the Python core with a printf/scanf equivalent? 
  At the same time you lose a lot of speed, so I don't see the point.

> So I was writting this interpreter for some assembly language defined
> in class and I did something like python does, so I had a binary file
> to interpret. After a while I thought it was far harder to program.

Why harder? Once you read the file, they're just numbers. Anyway, being 
harder to program the *interpreter* is not a problem, if you gain 
something like speed or eficiency for the interpreted language.

> And when I tried to code an assembler my problems got greater, as I
> wanted to code it in python (the interpreter was in C++) and I had a
> hard time trying to figure out how I would print something that's not a
> ascii or unicode string. As for the benefits, I couldn't figure out any.

Sorry, I could not understand what you said here.

-- 
Gabriel Genellina


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


Re: block scope?

2007-04-07 Thread James Stroud
Paul Rubin wrote:
> John Nagle <[EMAIL PROTECTED]> writes:
>> In a language with few declarations, it's probably best not to
>> have too many different nested scopes.  Python has a reasonable
>> compromise in this area.  Functions and classes have a scope, but
>> "if" and "for" do not.  That works adequately.
> 
> I think Perl did this pretty good.  If you say "my $i" that declares
> $i to have block scope, and it's considered good practice to do this,
> but it's not required.  You can say "for (my $i=0; $i < 5; $i++) { ... }"
> and that gives $i the same scope as the for loop.  Come to think of it
> you can do something similar in C++.

How then might one define a block? All lines at the same indent level 
and the lines nested within those lines?

i = 5
for my i in xrange(4):
   if i: # skips first when i is 0
 my i = 100
 if i:
   print i   # of course 100
 break
   print i   # i is between 0 & 3 here
print i # i is 5 here


Doesn't leave a particularly bad taste in one's mouth, I guess (except 
for the intended abuse).

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


Re: Convert xml symbol notation

2007-04-07 Thread Gabriel Genellina
dumbkiwi wrote:

> On Apr 7, 5:23 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:

>>Try the htmlentitydefs module.
> 
> Is that a standard module?  I can't see it anywhere - googled it.

Sure! For quite a while, at least, since Python 1.5 (I can't go earlier 
in time...)
http://svn.python.org/view/python/trunk/Lib/htmlentitydefs.py
Added Wed Sep 27 16:22:08 1995 UTC (11 years, 6 months ago) by guido

-- 
Gabriel Genellina


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


Re: Custom Python Runtime

2007-04-07 Thread Kay Schluehr
On Apr 7, 1:52 am, "Jack" <[EMAIL PROTECTED]> wrote:
> Since the full installation of Python (from either the standard installer or
> ActiveState installer) is too big for my intended use, I'd like to build a
> custom distribution of Python for Windows platform, omitting some lib files,
> such as audio, tk, printing, testing units, etc.
>
> Is there a way to customize the Windows build? In my case, there is no need
> to build an installer. The best way is to have everything in a directory, as
> long as I know where to find Python and Python knows where to find the
> necessary libs. Any online docs describing this? Thanks!


In principle it suffices to drop in just the pythonxx.dll. If you want
to isolate those scripts and additional libraries your project
requires you might try out the py2exe even when you don't finally plan
to deliver an executable. py2exe factors and copies everything needed
for a complete application. For builds you can comment out includes in
the header file python.h but this won't usually buy you that much.

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


Re: Understanding Python's interpreter

2007-04-07 Thread Rafael Almeida
On Sat, 07 Apr 2007 04:35:49 +0200
Gabriel Genellina <[EMAIL PROTECTED]> wrote:

> Speed? Eficiency? File size? Ease of use?
> A .pyc *could* be written in ASCII, but what do you gain? Replacing a 
> few trivial functions in the Python core with a printf/scanf equivalent? 
>   At the same time you lose a lot of speed, so I don't see the point.

Hm, I didn't realise that it would be that much slower.

> Why harder? Once you read the file, they're just numbers. Anyway, being 
> harder to program the *interpreter* is not a problem, if you gain 
> something like speed or eficiency for the interpreted language.

Well, it's harder to get 4 bytes and create an int out of it in a
portable way than just call strtol or scanf, that's what I thought
while I was coding my interpreter. It's not the hardest thing to do,
of course, but it made me wonder why not just do the simplest thing.

Since I've never seen a .pyc bigger than a few kilobytes, I thought an
ascii file would take more space, but it wouldn't be anything really
prohibitive.

I didn't think using strtol would make that much difference in speed.
But now you talked about it, and after thinking a little bit more about
it, I'm convinced that the speed difference may be relevant.

> > And when I tried to code an assembler my problems got greater, as I
> > wanted to code it in python (the interpreter was in C++) and I had a
> > hard time trying to figure out how I would print something that's not a
> > ascii or unicode string. As for the benefits, I couldn't figure out any.
> 
> Sorry, I could not understand what you said here.

It's not anything important, I was just saying that I had to write a
little more code to make an integer such as 0xff into '\0\0\0\377' than
it would need to just print the integer. Well, unless there's already a
python function that does just that and I didn't know about. It's was
just an example on how writting in ascii is easier.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SWIG, Python, C++, and Coca-Cola

2007-04-07 Thread Martin v. Löwis
> Any clues as to what is happening here or what to do next?

Apparently, it tries to wrap the main() function. It should
not do that: main should not be callable from Python. Most
likely, you have a declaration of main somewhere so it thinks
it should wrap it. You should not have a declaration of main,
anyway, so you should be safely able to drop that.

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


Re: Convert xml symbol notation

2007-04-07 Thread Martin v. Löwis
> I'm working on a script to download and parse a web page, and it
> includes xml symbol notation, such as ' for the ' character.  Does
> anyone know of a pre-existing python script/lib to convert the xml
> notation back to the actual symbol it represents?

If you have this given in an XML file (rather than an HTML file which
is not well-formed XML), you could use an XML parser for the entire
file. This would automatically unescape character references. Likewise,
you can parse it with HTMLParser, which will invoke the handle_charref
method for these.

If you just want to unescape references, you can use the code in

http://effbot.org/zone/re-sub.htm

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


Re: Why NOT only one class per file?

2007-04-07 Thread Hendrik van Rooyen
 "Bart Willems" <[EMAIL PROTECTED]> wrote:

> Steven D'Aprano wrote:
> > On Wed, 04 Apr 2007 14:23:19 -0700, Chris Lasher wrote:
> > 
> >> A friend of mine with a programming background in Java and Perl places
> >> each class in its own separate file in . I informed him that keeping
> >> all related classes together in a single file is more in the Python
> >> idiom than one file per class. He asked why, and frankly, his valid
> >> question has me flummoxed.
> > 
> > 
> > Hah! Writing one class per file is for wimps! When I program, I write one
> > *method* per file, then import them and build the class at runtime.
> > 
> > I have a friend who writes one *line* per file, then pulls them all
> > together with exec(), but that's just being stupid.
> > 
> > 
> > 
> I guess you're one of those sissies who uses EDLIN as an editor.
> 
> REAL programmers use COPY CON: ... :)

Naaah.. Real programmers fill in their coding sheets using
indelible ink in their fountain pens, and then send them off 
to be punched and verified.

None of this weak minded backspace stuff for us...

- Hendrik

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


os.path.isfile() error

2007-04-07 Thread 7stud
Here's the code:

import os, os.path, pprint

mydir = "/Users/me/2testing"

files = [file for file in os.listdir(mydir)]
pprint.pprint(files)

print os.path.join(mydir, "helloWorld.py")

files = [file
for file in os.listdir(mydir)
if os.path.isfile(os.path.join(dir, file) )
]

pprint.pprint(files)
output:

['.DS_Store', 'cpTest', 'dir1', 'testfile1', 'xmlFile.xml']
/Users/me/2testing/helloWorld.py
Traceback (most recent call last):
  File "test1.py", line 16, in ?
files = [file
  File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
python2.3/posixpath.py", line 62, in join
elif path == '' or path.endswith('/'):
AttributeError: 'builtin_function_or_method' object has no attribute
'endswith'

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


Re: Understanding Python's interpreter

2007-04-07 Thread Martin v. Löwis
>> Why harder? Once you read the file, they're just numbers. Anyway, being 
>> harder to program the *interpreter* is not a problem, if you gain 
>> something like speed or eficiency for the interpreted language.
> 
> Well, it's harder to get 4 bytes and create an int out of it in a
> portable way than just call strtol or scanf

That's not necessarily true for C. To deal with ASCII-printed
integers in C, you need to deal with memory management, and
variable-sized buffer. For example, if you want to print to
memory, you need to overallocate memory, print to it, and
then shrink the extra allocation (e.g. by copying the string
elsewhere).

For 4-byte integers in binary, no memory-management issue arises.
You know exactly how much memory you will need.

> Since I've never seen a .pyc bigger than a few kilobytes, I thought an
> ascii file would take more space, but it wouldn't be anything really
> prohibitive.

That would probably defeat the point of .pyc files entirely: you
already *have* an ASCII version of it, the .py file. So why create
a second file?

> It's not anything important, I was just saying that I had to write a
> little more code to make an integer such as 0xff into '\0\0\0\377' than
> it would need to just print the integer. Well, unless there's already a
> python function that does just that and I didn't know about. It's was
> just an example on how writting in ascii is easier.

Sure: Take a look at the struct module.

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


Re: os.path.isfile() error

2007-04-07 Thread Peter Otten
7stud wrote:

> Here's the code:
> 
> import os, os.path, pprint
> 
> mydir = "/Users/me/2testing"
> 
> files = [file for file in os.listdir(mydir)]
> pprint.pprint(files)
> 
> print os.path.join(mydir, "helloWorld.py")
> 
> files = [file
> for file in os.listdir(mydir)
> if os.path.isfile(os.path.join(dir, file) )

That should be mydir, not dir.

> ]
> 
> pprint.pprint(files)
> output:
> 
> ['.DS_Store', 'cpTest', 'dir1', 'testfile1', 'xmlFile.xml']
> /Users/me/2testing/helloWorld.py
> Traceback (most recent call last):
>   File "test1.py", line 16, in ?
> files = [file
>   File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/posixpath.py", line 62, in join
> elif path == '' or path.endswith('/'):
> AttributeError: 'builtin_function_or_method' object has no attribute
> 'endswith'

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


Re: Welch essential for learning Tkinter well?

2007-04-07 Thread Dick Moores
At 10:36 AM 4/6/2007, Russell E. Owen wrote:
>In article <[EMAIL PROTECTED]>,
>  Kevin Walzer <[EMAIL PROTECTED]> wrote:
>
> > James Stroud wrote:
> > >This begs the
> > > question, is anyone truly an expert in Tkinter?
> >
> > Frederick Lundh is, if anyone is.
> >
> > http://www.pythonware.com/library/tkinter/introduction/index.htm (outdated)
> > http://effbot.org/tkinterbook/ (new but incomplete)
>
>I agree that this is an excellent resource.
>
>I find Welch's book and the on-line tcl/tk help very helpful for Tkinter
>programming--especially some of the more obscure details. But to use
>either of these resources comfortably you must learn the basics of
>Tkinter first (including understanding the simple mapping between
>Tkinter and Tcl/Tk).

Where can I get this mapping spelled out?

>For learning the basics of Tkinter I suggest the links that Kevin listed
>above and/or Alex Martelli's "Python in a Nutshell" (an excellent
>reference in any case).

Although owning the 2nd ed. of "Python is a Nutshell", I hadn't 
thought of looking into it for Tkinker. There's a whole chapter, 
"Tkinter GUIs" (46 pages!).

>  Grayson's book is another reasonable alternative
>(and includes enough reference material to keep you from having to refer
>to the tcl/tk documentation very often).

One web tutorial that looks good to me is "Thinking in Tkinter", by 
Stephen Ferg ().

My thanks to all who responded.

Dick Moores


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


Re: os.path.isfile() error

2007-04-07 Thread John Machin
On Apr 7, 6:56 pm, "7stud" <[EMAIL PROTECTED]> wrote:
> Here's the code:
> 
> import os, os.path, pprint
>
> mydir = "/Users/me/2testing"
>
> files = [file for file in os.listdir(mydir)]
> pprint.pprint(files)
>
> print os.path.join(mydir, "helloWorld.py")
>
> files = [file
> for file in os.listdir(mydir)
> if os.path.isfile(os.path.join(dir, file) )
> ]
>
> pprint.pprint(files)
> output:
>
> ['.DS_Store', 'cpTest', 'dir1', 'testfile1', 'xmlFile.xml']
> /Users/me/2testing/helloWorld.py
> Traceback (most recent call last):
>   File "test1.py", line 16, in ?
> files = [file
>   File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/posixpath.py", line 62, in join
> elif path == '' or path.endswith('/'):
> AttributeError: 'builtin_function_or_method' object has no attribute
> 'endswith'

Re your subject: os.path.isfile is nothing to do with the problem.
As is evident from the traceback, the error (which is in *your* code)
was detected in os.path.join, before os.path.isfile was called.

Looking at the source file (posixpath.py), one sees that the offending
"path" (the builtin function/method with no endswith attribute) is the
first formal arg of os.path.join. You have supplied "dir" as the first
actual arg. dir is a builtin function. You meant "mydir" instead.

BTW, don't use "file" (or the name of any other builtin function) for
your own variables. Use meaningful names -- what you have called
"file" is not a file, it is the name of a file. Get pychecker and/or
pylint and run them over your source periodically. They'll detect not
only shadowing builtins but many other types of actual and potential
gotchas.

HTH,
John

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


Re: Custom Python Runtime

2007-04-07 Thread Martin v. Löwis
> Is there a way to customize the Windows build? In my case, there is no need 
> to build an installer. The best way is to have everything in a directory, as 
> long as I know where to find Python and Python knows where to find the 
> necessary libs. Any online docs describing this? Thanks! 

The interpreter will search for its libraries relative to the location
of the .exe file. So if you place python.exe and pythonxy.dll into
a directory, you need to add a Lib directory

Inside Lib, the minimum file you need to have is os.py: Python will
use it as a landmark. If you run 'python.exe -S', this is all
you need.

If you want site.py to work, you also need (tested for 2.4):
- site, codecs, copy_reg, locale, ntpath, stat, types UserDict,
  encodings/__init__, encodings/aliases

If you eliminate the aliasmbcs function from site.py, you can drop
codecs, locale, encodings/*.

If you eliminate the copy_reg references from os.py, you can also drop
copy_reg.

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


Re: os.path.isfile() error

2007-04-07 Thread mik3l3374
On Apr 7, 4:56 pm, "7stud" <[EMAIL PROTECTED]> wrote:
> Here's the code:
> 
> import os, os.path, pprint
>
> mydir = "/Users/me/2testing"
>
> files = [file for file in os.listdir(mydir)]
> pprint.pprint(files)
>
> print os.path.join(mydir, "helloWorld.py")
>
> files = [file
> for file in os.listdir(mydir)
> if os.path.isfile(os.path.join(dir, file) )
> ]
>
> pprint.pprint(files)
> output:
>
> ['.DS_Store', 'cpTest', 'dir1', 'testfile1', 'xmlFile.xml']
> /Users/me/2testing/helloWorld.py
> Traceback (most recent call last):
>   File "test1.py", line 16, in ?
> files = [file
>   File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/posixpath.py", line 62, in join
> elif path == '' or path.endswith('/'):
> AttributeError: 'builtin_function_or_method' object has no attribute
> 'endswith'

is 'dir' defined? or is it 'mydir'?

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


Re: Convert xml symbol notation

2007-04-07 Thread Martin v. Löwis
>> I'm working on a script to download and parse a web page, and it
>> includes xml symbol notation, such as ' for the ' character.  Does
>> anyone know of a pre-existing python script/lib to convert the xml
>> notation back to the actual symbol it represents?
> 
> Try the htmlentitydefs module.

That won't help: this is a character reference, not an entity reference.
htmlentitydefs only contains the definitions of entities.

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


Re: os.path.isfile() error

2007-04-07 Thread 7stud
On Apr 7, 2:56 am, "7stud" <[EMAIL PROTECTED]> wrote:
> Here's the code:
> 
> import os, os.path, pprint
>
> mydir = "/Users/me/2testing"
>
> files = [file for file in os.listdir(mydir)]
> pprint.pprint(files)
>
> print os.path.join(mydir, "helloWorld.py")
>
> files = [file
> for file in os.listdir(mydir)
> if os.path.isfile(os.path.join(dir, file) )
> ]
>
> pprint.pprint(files)
> output:
>
> ['.DS_Store', 'cpTest', 'dir1', 'testfile1', 'xmlFile.xml']
> /Users/me/2testing/helloWorld.py
> Traceback (most recent call last):
>   File "test1.py", line 16, in ?
> files = [file
>   File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
> python2.3/posixpath.py", line 62, in join
> elif path == '' or path.endswith('/'):
> AttributeError: 'builtin_function_or_method' object has no attribute
> 'endswith'

I got it: 'mydir' v. 'dir'

> mydir = "/Users/me/2testing"
> ...
> if os.path.isfile(os.path.join(dir, file) )

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


Re: tuples, index method, Python's design

2007-04-07 Thread 7stud
On Apr 6, 1:24 pm, Carsten Haese <[EMAIL PROTECTED]> wrote:
> Except that that wasn't the only justification. GvR also said:
>
> """
> For tuples, I suspect such a function would rarely be used; I think
> that is most cases where x.index() would be useful, x is generally a
> list, whose contents varies in time, rather than a tuple (which cannot
> change easily).
> """
>

Touche.


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


Re: Welch essential for learning Tkinter well?

2007-04-07 Thread James Stroud
Dick Moores wrote:
> At 10:36 AM 4/6/2007, Russell E. Owen wrote:
>> I find Welch's book and the on-line tcl/tk help very helpful for Tkinter
>> programming--especially some of the more obscure details. But to use
>> either of these resources comfortably you must learn the basics of
>> Tkinter first (including understanding the simple mapping between
>> Tkinter and Tcl/Tk).
> 
> Where can I get this mapping spelled out?

Grayson Appendix A. $25 pdf--well worth it in your time.

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


Re: Understanding Python's interpreter

2007-04-07 Thread Steve Holden
Rafael Almeida wrote:
> On Sat, 07 Apr 2007 04:35:49 +0200
> Gabriel Genellina <[EMAIL PROTECTED]> wrote:
> 
>> Speed? Eficiency? File size? Ease of use?
>> A .pyc *could* be written in ASCII, but what do you gain? Replacing a 
>> few trivial functions in the Python core with a printf/scanf equivalent? 
>>   At the same time you lose a lot of speed, so I don't see the point.
> 
> Hm, I didn't realise that it would be that much slower.

You may mistakenly believe that casts are an expensive operation, when 
in fact they take no time at all - they merely instruct the compiler to 
treat specific pieces of data in specific ways.

> 
>> Why harder? Once you read the file, they're just numbers. Anyway, being 
>> harder to program the *interpreter* is not a problem, if you gain 
>> something like speed or eficiency for the interpreted language.
> 
> Well, it's harder to get 4 bytes and create an int out of it in a
> portable way than just call strtol or scanf, that's what I thought
> while I was coding my interpreter. It's not the hardest thing to do,
> of course, but it made me wonder why not just do the simplest thing.
> 
Because they aer smarter than you, without wishing to be too rude.

> Since I've never seen a .pyc bigger than a few kilobytes, I thought an
> ascii file would take more space, but it wouldn't be anything really
> prohibitive.
> 
> I didn't think using strtol would make that much difference in speed.
> But now you talked about it, and after thinking a little bit more about
> it, I'm convinced that the speed difference may be relevant.
> 
Which is a good reason to think about things *before* you post.

>>> And when I tried to code an assembler my problems got greater, as I
>>> wanted to code it in python (the interpreter was in C++) and I had a
>>> hard time trying to figure out how I would print something that's not a
>>> ascii or unicode string. As for the benefits, I couldn't figure out any.
>> Sorry, I could not understand what you said here.
> 
> It's not anything important, I was just saying that I had to write a
> little more code to make an integer such as 0xff into '\0\0\0\377' than
> it would need to just print the integer. Well, unless there's already a
> python function that does just that and I didn't know about. It's was
> just an example on how writting in ascii is easier.

Speed, baby, speed.

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: Debugging multithreaded program using Eclipse/Pydev

2007-04-07 Thread Ritesh Raj Sarraf
John Henry wrote:

>>From what I can gather, it appears the only real option I have is to
> debug under Eclipse/Pydev.  I did a google search of this newsgroup
> and didn't turn up too many hits.  Before I invest the time to learn
> Eclipse/Pydev, I like to hear from somebody that have gone this path.
> Have you been successful in using Eclipse/Pydev to debug multi-
> threaded Python applications?  Is so, what was the learning curve like
> to you?

I use pydev extensively for all my Python related work. And I really love
it.

The good part about Eclipse/PyDev is that (if you are an Eclipse user)
you'll have to learn only a single IDE for all your programming works in
most of the languages. The interface, the shortcut keys to step, all are
the same across all languages that you use in Eclipse.

As for PyDev, it works very good with Eclipse.
Be it code-completion or thread debugging, all is supported. For
multithreaded applications, in PyDev, you'll see all the threads listed.
Then you can use each thread and proceed with debugging the code.

Learning Eclipse might take some time but that's worth it.

HTH,
Ritesh
-- 
Ritesh Raj Sarraf
RESEARCHUT - http://www.researchut.com
"Necessity is the mother of invention."
"Stealing logic from one person is plagiarism, stealing from many is
research."
"The great are those who achieve the impossible, the petty are those who
cannot - rrs"

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


Re: block scope?

2007-04-07 Thread Neal Becker
James Stroud wrote:

> Paul Rubin wrote:
>> John Nagle <[EMAIL PROTECTED]> writes:
>>> In a language with few declarations, it's probably best not to
>>> have too many different nested scopes.  Python has a reasonable
>>> compromise in this area.  Functions and classes have a scope, but
>>> "if" and "for" do not.  That works adequately.
>> 
>> I think Perl did this pretty good.  If you say "my $i" that declares
>> $i to have block scope, and it's considered good practice to do this,
>> but it's not required.  You can say "for (my $i=0; $i < 5; $i++) { ... }"
>> and that gives $i the same scope as the for loop.  Come to think of it
>> you can do something similar in C++.
> 
> How then might one define a block? All lines at the same indent level
> and the lines nested within those lines?
> 
> i = 5
> for my i in xrange(4):
>if i: # skips first when i is 0
>  my i = 100
>  if i:
>print i   # of course 100
>  break
>print i   # i is between 0 & 3 here
> print i # i is 5 here
> 
> 
> Doesn't leave a particularly bad taste in one's mouth, I guess (except
> for the intended abuse).
> 
> James

Yes, the above is pretty much what I had in mind.  +1.


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


Saving output of Turtle Graphics?

2007-04-07 Thread Dick Moores
I accidentally stumbled across the Turtle Graphics module (turtle.py) 
the other day and have been having some fun with it.

Now I'm wondering if there is a way to build into a script the saving 
of each window just before it is cleared. For example, here are a 
couple that I've saved by screen capture:



They were produced by this script:

=
# randomTriangles.py

import turtle as T
from random import *

def twoRndN(low=0, high=1):
 """
 generate two random floats x, y in the range [low, high) such that x <= y
 """
 x, y = uniform(low, high), uniform(low, high)
 if x <= y:
 return x, y
 else:
 return y, x

T.setup(width=1000, height=700, startx=0, starty=0)
T.title("Random Triangles with random R,G,B")

colorRange = "all"
if colorRange == "random":
 lowR, highR = twoRndN()
 lowG, highG = twoRndN()
 lowB, highB = twoRndN()

count = 0
for n in range(300):
 wdth = randrange(0,7,3)
 T.width(wdth)
 T.speed("fastest")
 if colorRange == "dark":
 R = uniform(.1, .5)
 G = uniform(.1, .5)
 B = uniform(.1, .5)
 elif colorRange == "pastel":
 R = uniform(.5, .9)
 G = uniform(.5, .9)
 B = uniform(.5, .9)
 elif colorRange == "all":
 R = uniform(0, 1)
 G = uniform(0, 1)
 B = uniform(0, 1)
 # set RGB for one color of your choice
 elif colorRange == "manual":
 R = .45
 G = .2
 B = .2
 elif colorRange == "random":
 R = uniform(lowR, highR)
 G = uniform(lowG, highG)
 B = uniform(lowB, highB)

 T.color(R,G,B)
 T.begin_fill()
 # 2 connected lines will fill as a triangle
 for x in range(2):
 coord = (randint(-500,500), randint(-350,350))
 T.goto(coord)
 T.end_fill()

 count += 1
 if count > 5:
 clr = randint(0,5)
 if clr == 0:
 T.clear()
 count = 0
T.done()
==
(The docs for Turtle graphics for Tk are at 
)

But how could I have saved them "automatically"?

The script as shown will clear (T.clear() -- the 3rd line from the 
bottom) the window after producing 6 to maybe 15 superimposed 
triangles, so clearing will take place maybe 30 times. How can I save 
as images each of the 30 windows just before they are cleared?

Thanks,

Dick Moores

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


Re: os.path.isfile() error

2007-04-07 Thread Steve Holden
[EMAIL PROTECTED] wrote:
> On Apr 7, 4:56 pm, "7stud" <[EMAIL PROTECTED]> wrote:
>> Here's the code:
>> 
>> import os, os.path, pprint
>>
>> mydir = "/Users/me/2testing"
>>
>> files = [file for file in os.listdir(mydir)]
>> pprint.pprint(files)
>>
>> print os.path.join(mydir, "helloWorld.py")
>>
>> files = [file
>> for file in os.listdir(mydir)
>> if os.path.isfile(os.path.join(dir, file) )
>> ]
>>
>> pprint.pprint(files)
>> output:
>>
>> ['.DS_Store', 'cpTest', 'dir1', 'testfile1', 'xmlFile.xml']
>> /Users/me/2testing/helloWorld.py
>> Traceback (most recent call last):
>>   File "test1.py", line 16, in ?
>> files = [file
>>   File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/
>> python2.3/posixpath.py", line 62, in join
>> elif path == '' or path.endswith('/'):
>> AttributeError: 'builtin_function_or_method' object has no attribute
>> 'endswith'
> 
> is 'dir' defined? or is it 'mydir'?
> 
[this is for 7stud, not for the poster] Clearly it should be 'mydir', 
but 'dir' is also defined - it's a built-in function, which is why it 
has no 'endswith' method.

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: Welch essential for learning Tkinter well?

2007-04-07 Thread Dick Moores
At 03:43 AM 4/7/2007, James Stroud wrote:
>Dick Moores wrote:
> > At 10:36 AM 4/6/2007, Russell E. Owen wrote:
> >> I find Welch's book and the on-line tcl/tk help very helpful for Tkinter
> >> programming--especially some of the more obscure details. But to use
> >> either of these resources comfortably you must learn the basics of
> >> Tkinter first (including understanding the simple mapping between
> >> Tkinter and Tcl/Tk).
> >
> > Where can I get this mapping spelled out?
>
>Grayson Appendix A. $25 pdf--well worth it in your time.

Terrific! Thank you.

Dick

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


Python - ogr2ogr

2007-04-07 Thread Szkandera . Karel
Hi, 
I need to do web service, which will be convert vector formats, like shapefile, 
dgn, mapinfo..(and other formats, which are supported in ogr2ogr).  I want to 
do it with using ogr2ogr in the ogr python module, but i am newbie in python, 
so here is my questions. Is here anybody, who wrote any similar scripts and can 
give it me? If not, can at least anyone point me to few examples of using 
ogr2ogr in the ogr 
python module?

Thank you for every answer, K.Szkandera
-- 
http://mail.python.org/mailman/listinfo/python-list


Automated email response

2007-04-07 Thread tonydevlin

I currently have the python code 
obj=sti.object 
creator = obj.Creator() 
history = sti.getHistory() 
wf_tool = context.portal_workflow 

mMsg = """ 
Content has been submitted for your review. 
The url was %s. 
The reason was %s. 
""" 

member = context.portal_membership.getMemberById(creator) 
creator = {'member':member, 
   'id':member.getId(), 
   'fullname':member.getProperty('fullname', 'Fullname missing'), 
   'email':member.getProperty('email', None)} 

actorid = wf_tool.getInfoFor(obj, 'actor') 
actor = context.portal_membership.getMemberById(actorid) 
reviewer = {'member':actor, 
'id':actor.getId(), 
'fullname':actor.getProperty('fullname', 'Fullname missing'), 
'email':actor.getProperty('email', None)} 

mTo = reviewer['email'] 
mFrom = creator['email'] 
mSubj = 'Your item has transitioned' 
obj_url = obj.absolute_url() #use portal_url + relative_url 
comments = wf_tool.getInfoFor(obj, 'comments') 

message = mMsg % (obj_url, comments) 
context.MailHost.send(message, mTo, mFrom, mSubj) 

This is attached to a transitions in a workflow and when a user selects the
transition they are emailed. I want it to email all of the users or selected
members like managers.  How would I go about changing the above code to do
that? 

I have tried the following code from the definitve guide to plone book, but
it does not have any effect on my workflow and does not email anyone.  Is
there something that I need to change on my setting possibly in Plone to get
the email response working, I have set up my mailhost and this works because
when I add a new user it emails them. 

# the objects we need 
object = state_change.object 
mship = context.portal_membership 
mhost = context.MailHost 
administratorEmailAddress = context.email_from_address 
  
# the message format, %s will be filled in from data 
message = """ 
From: %s 
To: %s 
Subject: New item submitted for approval - %s 
  
%s 
  
URL: %s 
""" 

for user in mship.listMembers(): 
if "Reviewer" in mship.getMemberById(user.id).getRoles(): 
if user.email: 
msg = message % ( 
 administratorEmailAddress, 
 user.email, 
 object.TitleOrId(), 
 object.Description(), 
 object.absolute_url() 
) 
mhost.send(msg)

-- 
View this message in context: 
http://www.nabble.com/Automated-email-response-tf3540615.html#a9883575
Sent from the Python - python-list mailing list archive at Nabble.com.

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


subprocess.Popen output to file?

2007-04-07 Thread John Pye
Hi all

I am trying to set up a python script to manage backups of a mysql
database the 'right way' using pipes. I want to send the output of the
'mysqldump' command to a file. Using a normal shell script this would
be easy using a ">" operator. What is the efficient and best way to do
this using pure python, bearing in mind that it will be too much data
to keep in memory? I presume using the subprocess module, but how to
get the output to a file? It's not really documented, AFAICS.

Cheers
JP

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


Re: block scope?

2007-04-07 Thread irstas
On Apr 7, 6:48 am, James Stroud <[EMAIL PROTECTED]> wrote:
> Neal Becker wrote:
> > One thing I sometimes miss, which is common in some other languages (c++),
> > is idea of block scope.  It would be useful to have variables that did not
> > outlive their block, primarily to avoid name clashes.  This also leads to
> > more readable code.  I wonder if this has been discussed?
>
> Probably, with good code, block scope would be overkill, except that I
> would welcome list comprehensions to have a new scope:

Generator expressions have a new scope, and in Python 3.0 list
comprehensions will have one as well (according to 
http://www.python.org/dev/peps/pep-0289/
). It's a fix that might break existing code so it couldn't be
introduced in "minor" versions like 2.4 and 2.5.

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


Can't Get Email Interface Working

2007-04-07 Thread Eric Price
Hi;
I'm writing a script that includes an email function. So I went to the 
cookbook and dug up this, and tweaked it just a bit to make it easier to get 
it to work, but it throws an error:

>>>def createMail(sender, recipient, subject, html, text):
... import MimeWriter, mimetools, cStringIO
... out = cStringIO.StringIO()
... #   txtin = cStringIO.StringIO(msg)
... writer = MimeWriter.MimeWriter(out)
... writer.addheader("From", sender)
... writer.addheader("To", recipient)
... writer.addheader("Subject", subject)
... writer.addheader("MIME-Version", "1.0")
... writer.startmultipartbody("alternative")
... writer.flushheaders()
... subpart = writer.nextpart()
... subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
... pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
... mimetools.encode(txtin, pout, 'quoted-printable')
... txtin.close()
... subpart = writer.nextpart()
... subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
... pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
... mimetools.encode(htmlin, pout, 'quoted-printable')
... htmlin.close()
... writer.lastpart()
... msg = "test"
... out.close()
... return msg
...
>>># ---
... def sendMail(sender, recipient, subject, html, text):
... import smtplib
... message = createMail(sender, recipient, subject, html, text)
... server = smtplib.SMTP("localhost")
... server.sendmail(sender, recipient, message)
... server.quit()
...
>>>if __name__=="__main__":
... sendMail("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", "Web Stie(s) 
Down!!!", "", "text")
...
Traceback (most recent call last):
  File "", line 2, in ?
  File "", line 4, in sendMail
  File "", line 10, in createMail
  File "/usr/local/lib/python2.4/MimeWriter.py", line 153, in 
startmultipartbody
self._boundary = boundary or mimetools.choose_boundary()
  File "/usr/local/lib/python2.4/mimetools.py", line 130, in choose_boundary
hostid = socket.gethostbyname(socket.gethostname())
socket.gaierror: (8, 'hostname nor servname provided, or not known')
>>>

Now, I can send email from my server no problem. In fact, I have my script 
working already...but with a shell script instead of this python code. 
Please advise.
TIA,
Eric

_
Get a FREE Web site, company branded e-mail and more from Microsoft Office 
Live! http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/

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


Re: Getting Stack Trace on segfault

2007-04-07 Thread [EMAIL PROTECTED]
After a night's rest, I was able to add a function trace to pydb,
command option --fntrace, short option -F, and set/show command
"fntrace".

It's still a little bit funky. (Hey, I didn't get *that* good of a
rest). But it's out there in pydb's CVS in case folks want to try it.

Also, following an idea given in the recipe, I've extended the 'Call'
and 'Return' indicators so that we list the current stack level. For
"Return" we'll also list the return value (or at least a repr() of it
for strings and scalars) and/or return type. What's a little odd here
is that levels from the debugger are included in the nesting count. So
the top-level in the user program will be greater than 1.

It's possible there will be another release around the time of the
next ipython release since there is better coordination between the
two with respect to colorizing lines of code.

On Apr 6, 10:49 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> On Apr 6, 8:13 am, James Stroud <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hello All,
>
> > The built-in mac osx vecLib is segfaulting in some cases--A very fun
> > fact to find out the hard way over two nights of work. I also spent an
> > embarrassing amount of time figuring out just where. Although I'm in
> > quite a self-congratulatory mood right now, in the future, I feel like I
> > could save a lot of time by coercing the interpreter to spew forth
> > method calls to stderr. Is this possible?
>
> > I would hope to produce something hauntingly reminiscent of
>
> > [] my_function
> > [my_function] another_function
> > [my_function -> another_function] yet_a_deeper_function
>
> > Presentation, of course, is irrelevant.
>
> > I read the docs onpdb, but it did not seem to do what I want--unless,
> > of course, I missed something.
>
> > James
>
> pydb (http://bashdb.sf.net0has the ability to do noninteractive line
> tracing.  
> Seehttp://bashdb.sourceforge.net/pydb/pydb/lib/subsubsection-set.html
> or the showmedo demo. It would be kind of neat to extend this to allow
> for method/fn tracing. Alas the simple hack I tried, didn't work
> because of code obscurities. (The code could stand to use a rewrite.)


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


Re: tuples, index method, Python's design

2007-04-07 Thread bearophileHUGS
Carsten Haese:
> The lack of convincing use cases is still a pertinent reason today. Note
> that the original poster on this thread did not present a use case for
> tuple.index, they were only asking out of curiosity.
> If you have a use case for tuple.index, please show it to me, and I'll
> show you what you should be using instead of a tuple.

Maybe we can add such methods to the PyPy tuples for some time, to
experimentally see if they make the language worse :-)

(Adding such methods may reduce the amound of information you have to
keep in your brain to program with Python. If tuples and lists share
more methods then you don't have to remember what methods tuples don't
have. This means less complexity.)

Bye,
bearophile

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


Re: Saving output of Turtle Graphics?

2007-04-07 Thread Wojciech Muła
Dick Moores wrote:
> I accidentally stumbled across the Turtle Graphics module (turtle.py) 
> the other day and have been having some fun with it.
> 
> Now I'm wondering if there is a way to build into a script the saving of 
> each window just before it is cleared. For example, here are a couple 
> that I've saved by screen capture:
> 
> 

Turtle module uses Tk canvas element to draw graphics ('_canvas'
attribute). I've written module, that exports canvas graphics to SVG
file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
for you.

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


Re: Understanding Python's interpreter

2007-04-07 Thread Mike C. Fletcher
Steve Holden wrote:
> Rafael Almeida wrote:
>   
...
> Because they aer smarter than you, without wishing to be too rude.
>   
Replace that with "more experienced", please.  Otherwise it is a bit 
rude, despite your wishes.  We've always been newbie positive on 
Python-list, and new compiler writers are just as important educational 
targets as new Python programmers.

Have fun,
Mike

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: tuples, index method, Python's design

2007-04-07 Thread Carsten Haese
On Sat, 2007-04-07 at 06:45 -0700, [EMAIL PROTECTED] wrote:
> Carsten Haese:
> > The lack of convincing use cases is still a pertinent reason today. Note
> > that the original poster on this thread did not present a use case for
> > tuple.index, they were only asking out of curiosity.
> > If you have a use case for tuple.index, please show it to me, and I'll
> > show you what you should be using instead of a tuple.
> 
> Maybe we can add such methods to the PyPy tuples for some time, to
> experimentally see if they make the language worse :-)

Adding useless features always makes a product worse. What's your use
case for tuple.index?

-Carsten


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


Re: subprocess.Popen output to file?

2007-04-07 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, John Pye wrote:

> I am trying to set up a python script to manage backups of a mysql
> database the 'right way' using pipes. I want to send the output of the
> 'mysqldump' command to a file. Using a normal shell script this would
> be easy using a ">" operator. What is the efficient and best way to do
> this using pure python, bearing in mind that it will be too much data
> to keep in memory? I presume using the subprocess module, but how to
> get the output to a file? It's not really documented, AFAICS.

I think it is documented, that's what the `stderr` and `stdout` arguments
are used for.  Untested:

f = open('dump.txt', 'wb')
p = Popen(('mysqldump', '--option', '--another-option'), stdout=f)
r = p.wait()

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


What happened to http://www.pythonware.com/daily and http://mechanicalcat.net/pyblagg.html?

2007-04-07 Thread asker
These sites are not updated since almost one month.
Does anybody knows why?

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


Re: Hide the python-script from user

2007-04-07 Thread hlubenow
hlubenow wrote:

> hlubenow wrote:
> 
>> ts-dev wrote:
>> 
>>> On Apr 6, 3:19 pm, hlubenow <[EMAIL PROTECTED]> wrote:
 recently there was a thread about hiding the python-script from the
 user. The OP could use
>>> 
>>> Interesting - thanks
>> 
>> Well, testing it, it doesn't seem to work very well ...
>> 
>> It seems, Python-code is rather difficult to obfuscate, probably because
>> of its clear syntax and indentations. Here's yet another approach:
>> 
>>
>
http://pythonhacker.is-a-geek.net/my_programs/pyfuscate/pyfuscate-0.1.zip/view
>> 
>> H.
> 
> That didn't work very well either :(.
> 
> Ok, but now I can offer a real secure solution:
> 
> You can have real encryption in Python using this modules:
> 
> 
> http://www.amk.ca/files/python/crypto/pycrypto-2.0.1.tar.gz
> 
> and
> 
> http://sourceforge.net/projects/yawpycrypto
> 
> Below I post a code-example that I've written some time ago. With it,
> encrypting text is rather easy.
> 
> Then you have to program a start-script, that reads in your script and the
> decryption-key. The decryption-key must be encrypted too. Such a encrypted
> key can be generated by the modules if you don't pass a password to my
> function "doEncrypt(). The decryption-key must then be hidden somewhere
> within the encrypted program-script. That's because, if the user knows
> where to find the key, he can decrypt the program-script.
> 
> If your start-script is written, everything should work automatically, one
> shouldn't nearly notice the decryption-process.
> 
> Ok, here's my example code, how to encrypt and decrypt some text with the
> modules:
> 
>

> 
> #!/usr/bin/env python
> 
> import os
> import sys
> import base64
> 
> from yawPyCrypto.Cipher import DecryptCipher, EncryptCipher
> from yawPyCrypto.Cipher import ZipDecryptCipher, ZipEncryptCipher
> from yawPyCrypto.Constants import CIPHER_BLOWFISH, MODE_CBC
> 
> 
> def doEncrypt(text, passw = None):
> 
> e = EncryptCipher(passw, CIPHER_BLOWFISH, MODE_CBC)
> e.feed(text)
> e.finish()
> encryptedtext = e.data
> 
> if passw != None:
> passwr = passw
> else:
> passwr = e.password
> 
> a = (encryptedtext, passwr)
> return a
> 
> 
> def doDecrypt(encryptedtext, passw):
> d = DecryptCipher(passw)
> d.feed(encryptedtext)
> d.finish()
> decoded = (d.data)
> return decoded
> 
> 
> # Calling the encryption routine.
> # If you just pass the text to encrypt, a password is generated:
> 
> a = doEncrypt("For your eyes only !", "Melina")
> 
> 
> # Just trying to clean the screen:
> 
> if sys.platform == "win32":
> os.system("cls")
> else:
> os.system("clear")
> 
> print
> print "Hello !"
> print
> print "I just encrypted some text. It looks like this now:"
> print
> 
> print base64.b64encode(a[0])
> 
> print
> print 'Please notice, that I just encoded the text once more using
"base64.b64encode()" to make it printable.'
> print
> print "The password for decryption is: "
> print
> print base64.b64encode(a[1])
> print
> print "Let's decrypt again (the original password must be passed without
b64encoding):"
> print
> print doDecrypt(a[0], a[1])
> print
> 
>

> 
> See you
> 
> H.

This still has a problem: The start-script has to know how to decrypt the
main-script and the start-script is visible, so the user can see how it
does it.
Perhaps one could obfuscate the start-script or write a C extension, that
does decrypting instead of the start-script.
This is getting rather complicated ...

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


1 Thread = 3 interpreter launched ???

2007-04-07 Thread nono240
Hi all, and thanks for reading !

I'm using Python 2.4.2 with an embedded platform (16MB RAM) running
Linux 2.6.20.
My main script use a thread for some reasons (more precisely a
periodic timer within a separate module).
While looking at the memory consumption, here's what i found :

  PID USER STATUS   RSS  PPID %CPU %MEM COMMAND
  171 root R384   164  1.5  2.6 top
  218 root R   4172   217  0.1 29.1 main_script.py
  216 root S   4172   180  0.0 29.1 main_script.py
  217 root S   4172   216  0.0 29.1 main_script.py

When creating the thread, Python forks 2 times and thus consume me
around 60% of RAM !

Is it a normal behaviour while using threads ???

It's very critical, am i missed something ?

Thank U...

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


Checking whether list element exists

2007-04-07 Thread Rehceb Rotkiv
I want to check whether, for example, the element myList[-3] exists. So 
far I did it like this:

index = -3
if len(myList) >= abs(index):
print myList[index]

Another idea I had was to (ab-?)use the try...except structure:

index = -3
try:
print myList[index]
except:
print "Does not exist!"

Is it ok to use try...except for the test or is it bad coding style? Or 
is there another, more elegant method than these two?

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


Re: Can't Get Email Interface Working

2007-04-07 Thread hlubenow
Eric Price wrote:

> Hi;
> I'm writing a script that includes an email function. So I went to the
> cookbook and dug up this, and tweaked it just a bit to make it easier to
> get it to work, but it throws an error:
> 
def createMail(sender, recipient, subject, html, text):
> ... import MimeWriter, mimetools, cStringIO
> ... out = cStringIO.StringIO()
> ... #   txtin = cStringIO.StringIO(msg)
> ... writer = MimeWriter.MimeWriter(out)
> ... writer.addheader("From", sender)
> ... writer.addheader("To", recipient)
> ... writer.addheader("Subject", subject)
> ... writer.addheader("MIME-Version", "1.0")
> ... writer.startmultipartbody("alternative")
> ... writer.flushheaders()
> ... subpart = writer.nextpart()
> ... subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
> ... pout = subpart.startbody("text/plain", [("charset", 'us-ascii')])
> ... mimetools.encode(txtin, pout, 'quoted-printable')
> ... txtin.close()
> ... subpart = writer.nextpart()
> ... subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
> ... pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
> ... mimetools.encode(htmlin, pout, 'quoted-printable')
> ... htmlin.close()
> ... writer.lastpart()
> ... msg = "test"
> ... out.close()
> ... return msg
> ...
# ---
> ... def sendMail(sender, recipient, subject, html, text):
> ... import smtplib
> ... message = createMail(sender, recipient, subject, html, text)
> ... server = smtplib.SMTP("localhost")
> ... server.sendmail(sender, recipient, message)
> ... server.quit()
> ...
if __name__=="__main__":
> ... sendMail("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", "Web Stie(s)
> Down!!!", "", "text")
> ...
> Traceback (most recent call last):
>   File "", line 2, in ?
>   File "", line 4, in sendMail
>   File "", line 10, in createMail
>   File "/usr/local/lib/python2.4/MimeWriter.py", line 153, in
> startmultipartbody
> self._boundary = boundary or mimetools.choose_boundary()
>   File "/usr/local/lib/python2.4/mimetools.py", line 130, in
>   choose_boundary
> hostid = socket.gethostbyname(socket.gethostname())
> socket.gaierror: (8, 'hostname nor servname provided, or not known')

> 
> Now, I can send email from my server no problem. In fact, I have my script
> working already...but with a shell script instead of this python code.

:lol:

> Please advise.
> TIA,
> Eric

You may want to take a look at simplemail.py:

http://gelb.bcom.at/trac/simplemail/browser/trunk/simplemail.py

that does sending mails in Python comfortably.

HTH

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


Re: Saving output of Turtle Graphics?

2007-04-07 Thread Dick Moores
At 06:50 AM 4/7/2007, =?ISO-8859-2?Q?Wojciech_Mu=B3a?= wrote:
>Dick Moores wrote:
> > I accidentally stumbled across the Turtle Graphics module (turtle.py)
> > the other day and have been having some fun with it.
> >
> > Now I'm wondering if there is a way to build into a script the saving of
> > each window just before it is cleared. For example, here are a couple
> > that I've saved by screen capture:
> > 
> > 
>
>Turtle module uses Tk canvas element to draw graphics ('_canvas'
>attribute). I've written module, that exports canvas graphics to SVG
>file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
>for you.

I afraid I'm totally unfamiliar with SVG. Would it be possible for 
you or someone else on the list to show how to use your module to 
export the simple product of this simple script to an SVG file?

===
import turtle as T
from random import randint
T.setup(width=1000, height=700, startx=0, starty=0)
T.color(1, .5, .5)
T.begin_fill()
# 2 connected lines will fill as a triangle
for x in range(2):
 coord = (randint(-500,500), randint(-350,350))
 T.goto(coord)
T.end_fill()

T.done()


Thanks,

Dick Moores
Win XP Pro SP2
Python 2.5
Python IDE: Ulipad 3.6


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


Re: Checking whether list element exists

2007-04-07 Thread Wojciech Muła
Rehceb Rotkiv wrote:
> I want to check whether, for example, the element myList[-3] exists. So 
> far I did it like this:
> 
> index = -3
> if len(myList) >= abs(index):
>   print myList[index]

IMHO it is good way.

> Another idea I had was to (ab-?)use the try...except structure:
> 
> index = -3
> try:
>   print myList[index]
> except:
>   print "Does not exist!"

In general case it won't work, because lists accept negative indexes:
http://docs.python.org/lib/typesseq.html, 3rd note.

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


How to tell when a file is opened

2007-04-07 Thread Adam
Hello,

I want to know if it possible to tell when a file is opened. However I
don't want it to be the last access time. I want to know how many
times a file opened so I can generate statistics of file usage.

I will be wanting to watch all files on a server so this will be on
quite a large scale. So checking a directory on a loop for accesses
won't work.

Maybe some way to monitor the Open Files section of Computer
Management?

I check through Tim Golden's site but nothing jumped out at me.
Any pointers would be great.

Thanks,
Adam

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


Re: Saving output of Turtle Graphics?

2007-04-07 Thread Wojciech Muła
Dick Moores wrote:
>> Turtle module uses Tk canvas element to draw graphics ('_canvas'
>> attribute). I've written module, that exports canvas graphics to SVG
>> file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
>> for you.
> 
> I afraid I'm totally unfamiliar with SVG. Would it be possible for you
> or someone else on the list to show how to use your module to export the 
> simple product of this simple script to an SVG file?
> 
> ===
> import turtle as T
import canvasvg
> from random import randint
> T.setup(width=1000, height=700, startx=0, starty=0)
> T.color(1, .5, .5)
> T.begin_fill()
> # 2 connected lines will fill as a triangle
> for x in range(2):
> coord = (randint(-500,500), randint(-350,350))
> T.goto(coord)
> T.end_fill()

canvasvg.saveall("image.svg", T._canvas)

> T.done()
> 

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


Re: tuples, index method, Python's design

2007-04-07 Thread bearophileHUGS
Carsten Haese:
> Adding useless features always makes a product worse. What's your use
> case for tuple.index?

Ruby is a bit younger than Python, it has shown that few things may be
better done in a different way. An advantage of PyPy is that it allows
faster and simpler ways to perform language experiments. So you can
even try things first and judge them later. You can find usercases
later. This may help rejuvenate Python a bit :-)

Bye,
bearophile

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


Re: Checking whether list element exists

2007-04-07 Thread Rehceb Rotkiv
> In general case it won't work, because lists accept negative indexes:
> http://docs.python.org/lib/typesseq.html, 3rd note.

Yes, I know! I _want_ the "3rd last list element", i.e. list[-3]. But it 
may be that the list does not have 3 elements. In this case, list[-3] 
will throw an error, cf.:

>>> arr = ['a','b','c']
>>> print arr[-3]
a
>>> print arr[-4]
Traceback (most recent call last):
  File "", line 1, in ?
IndexError: list index out of range
>>> 

I thought maybe I could catch the error with try...except so that I do 
not need the if-test, but I don't know whether this is proper usage of 
the try...except structure.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Checking whether list element exists

2007-04-07 Thread [EMAIL PROTECTED]
On Apr 7, 10:37�am, Wojciech Mula
<[EMAIL PROTECTED]> wrote:
> Rehceb Rotkiv wrote:
> > I want to check whether, for example, the element myList[-3] exists. So
> > far I did it like this:
>
> > index = -3
> > if len(myList) >= abs(index):
> > � �print myList[index]
>
> IMHO it is good way.
>
> > Another idea I had was to (ab-?)use the try...except structure:
>
> > index = -3
> > try:
> > � �print myList[index]
> > except:
> > � �print "Does not exist!"
>
> In general case it won't work, because lists accept negative 
> indexes:http://docs.python.org/lib/typesseq.html, 3rd note.

Why? What does negative indexes have to do with it?

>>> a = [1,2]
>>> index = -3
>>> try:
print a[index]
except:
print 'does not exist'


does not exist



>
> w.


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

Re: Can't Get Email Interface Working

2007-04-07 Thread Eric Price
Good grief! And they call a 722-line program "simple"?! LOL!
I did what I need to do with a __one_line_shell_script__ LOL!
Naw, if I have to go through all that, I'll skip on python this time around, 
thank you very much!
Eric


>From: hlubenow <[EMAIL PROTECTED]>
>To: python-list@python.org
>Subject: Re: Can't Get Email Interface Working
>Date: Sat, 07 Apr 2007 17:33:38 +0200
>
>Eric Price wrote:
>
> > Hi;
> > I'm writing a script that includes an email function. So I went to the
> > cookbook and dug up this, and tweaked it just a bit to make it easier to
> > get it to work, but it throws an error:
> >
> def createMail(sender, recipient, subject, html, text):
> > ... import MimeWriter, mimetools, cStringIO
> > ... out = cStringIO.StringIO()
> > ... #   txtin = cStringIO.StringIO(msg)
> > ... writer = MimeWriter.MimeWriter(out)
> > ... writer.addheader("From", sender)
> > ... writer.addheader("To", recipient)
> > ... writer.addheader("Subject", subject)
> > ... writer.addheader("MIME-Version", "1.0")
> > ... writer.startmultipartbody("alternative")
> > ... writer.flushheaders()
> > ... subpart = writer.nextpart()
> > ... subpart.addheader("Content-Transfer-Encoding", 
>"quoted-printable")
> > ... pout = subpart.startbody("text/plain", [("charset", 
>'us-ascii')])
> > ... mimetools.encode(txtin, pout, 'quoted-printable')
> > ... txtin.close()
> > ... subpart = writer.nextpart()
> > ... subpart.addheader("Content-Transfer-Encoding", 
>"quoted-printable")
> > ... pout = subpart.startbody("text/html", [("charset", 'us-ascii')])
> > ... mimetools.encode(htmlin, pout, 'quoted-printable')
> > ... htmlin.close()
> > ... writer.lastpart()
> > ... msg = "test"
> > ... out.close()
> > ... return msg
> > ...
> # ---
> > ... def sendMail(sender, recipient, subject, html, text):
> > ... import smtplib
> > ... message = createMail(sender, recipient, subject, html, text)
> > ... server = smtplib.SMTP("localhost")
> > ... server.sendmail(sender, recipient, message)
> > ... server.quit()
> > ...
> if __name__=="__main__":
> > ... sendMail("[EMAIL PROTECTED]", "[EMAIL PROTECTED]", "Web Stie(s)
> > Down!!!", "", "text")
> > ...
> > Traceback (most recent call last):
> >   File "", line 2, in ?
> >   File "", line 4, in sendMail
> >   File "", line 10, in createMail
> >   File "/usr/local/lib/python2.4/MimeWriter.py", line 153, in
> > startmultipartbody
> > self._boundary = boundary or mimetools.choose_boundary()
> >   File "/usr/local/lib/python2.4/mimetools.py", line 130, in
> >   choose_boundary
> > hostid = socket.gethostbyname(socket.gethostname())
> > socket.gaierror: (8, 'hostname nor servname provided, or not known')
> 
> >
> > Now, I can send email from my server no problem. In fact, I have my 
>script
> > working already...but with a shell script instead of this python code.
>
>:lol:
>
> > Please advise.
> > TIA,
> > Eric
>
>You may want to take a look at simplemail.py:
>
>http://gelb.bcom.at/trac/simplemail/browser/trunk/simplemail.py
>
>that does sending mails in Python comfortably.
>
>HTH
>
>H.
>--
>http://mail.python.org/mailman/listinfo/python-list

_
Interest Rates Fall Again! $430,000 Mortgage for $1,399/mo - Calculate new 
payment 
http://www.lowermybills.com/lre/index.jsp?sourceid=lmb-9632-18679&moid=7581

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


Re: Checking whether list element exists

2007-04-07 Thread [EMAIL PROTECTED]
On Apr 7, 10:52�am, Rehceb Rotkiv <[EMAIL PROTECTED]> wrote:
> > In general case it won't work, because lists accept negative indexes:
> >http://docs.python.org/lib/typesseq.html, 3rd note.
>
> Yes, I know! I _want_ the "3rd last list element", i.e. list[-3]. But it
> may be that the list does not have 3 elements. In this case, list[-3]
> will throw an error, cf.:
>
> >>> arr = ['a','b','c']
> >>> print arr[-3]
> a
> >>> print arr[-4]
>
> Traceback (most recent call last):
> � File "", line 1, in ?
> IndexError: list index out of range
>
>
>
> I thought maybe I could catch the error with try...except so that I do
> not need the if-test, but I don't know whether this is proper usage of
> the try...except structure.

It's better than seeing if length>=abs(index).

>>> b = []
>>> index = 0
>>> if len(b)>=abs(index):
print b[index]

Traceback (most recent call last):
  File "", line 2, in 
print b[index]
IndexError: list index out of range
>>> try:
print b[index]
except:
print 'does not exist'

does not exist

The length test fails for an empty list but the
try/except method works when the list is empty.

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

Re: How to tell when a file is opened

2007-04-07 Thread Tim Golden
Adam wrote:
> I want to know if it possible to tell when a file is opened. However I
> don't want it to be the last access time. I want to know how many
> times a file opened so I can generate statistics of file usage.
> 
> I will be wanting to watch all files on a server so this will be on
> quite a large scale. So checking a directory on a loop for accesses
> won't work.
> 
> Maybe some way to monitor the Open Files section of Computer
> Management?
> 
> I check through Tim Golden's site but nothing jumped out at me.
> Any pointers would be great.

I take it from the fact that you mention my site (and
your reference to "Computer Management") that you're
looking at Win32? It's always best to be explicit when
you're asking for help; a lot of people on this list
will be using Linux or Mac where the answers are
probably very different.

This is no small task you've set yourself! As far as I know,
you're going to have to go down to the level of change journals
for this kind of thing. (Search for "NTFS change journal").

Although you might think: the filesystem knows when files are
being accessed; can't I hook into that directly? I think the
answer is: no. But I could be wrong.

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


Re: Saving output of Turtle Graphics?

2007-04-07 Thread Dick Moores
At 08:48 AM 4/7/2007, =?ISO-8859-2?Q?Wojciech_Mu=B3a?= wrote:
>Dick Moores wrote:
> >> Turtle module uses Tk canvas element to draw graphics ('_canvas'
> >> attribute). I've written module, that exports canvas graphics to SVG
> >> file: http://wmula.republika.pl/proj/canvas2svg/ -- it may be useful
> >> for you.
> >
> > I afraid I'm totally unfamiliar with SVG. Would it be possible for you
> > or someone else on the list to show how to use your module to export the
> > simple product of this simple script to an SVG file?
> >
> > ===
> > import turtle as T
>import canvasvg
> > from random import randint
> > T.setup(width=1000, height=700, startx=0, starty=0)
> > T.color(1, .5, .5)
> > T.begin_fill()
> > # 2 connected lines will fill as a triangle
> > for x in range(2):
> > coord = (randint(-500,500), randint(-350,350))
> > T.goto(coord)
> > T.end_fill()
>
>canvasvg.saveall("image.svg", T._canvas)
>
> > T.done()
> > 

OK, thanks, now I've got

===
http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>http://www.w3.org/2000/svg";>


What do I do to see this?

Dick

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


Re: Checking whether list element exists

2007-04-07 Thread Gary Herron
Rehceb Rotkiv wrote:
> I want to check whether, for example, the element myList[-3] exists. So 
> far I did it like this:
>
> index = -3
> if len(myList) >= abs(index):
>   print myList[index]
>
> Another idea I had was to (ab-?)use the try...except structure:
>
> index = -3
> try:
>   print myList[index]
> except:
>   print "Does not exist!"
>   
A try...except is a perfectly valid way to make the test.   However, the 
printing of the result is not necessary, and a "naked" except, as you 
have, is very dangerous programming practice.

That form of the except will catch ANY error and end up printing "Does 
not exist!", even errors that have nothing to do with what you're 
intending to test.

For instance, if you mistype the
  myList[index]
as
  myList[indx]
or
  mylist[indx]
an exception would be raised and caught by your except clause.

Or if you hit a keyboard control-c at exactly the right time, the 
resulting SystemExit exception would also be caught by your except clause.

A good programming practice would be to ALWAYS catch only the specific 
exception you want, and let any other's be reported as the errors they are:

try: 
  myList[index]
except IndexError:
  ...whatever...


Gary Herron

> Is it ok to use try...except for the test or is it bad coding style? Or 
> is there another, more elegant method than these two?
>
> Regards,
> Rehceb
>   

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


Debugging embedded python

2007-04-07 Thread kalita
I'm a Python newbie, and I'm looking for a way to debug Python scripts
run from a C++ program by using PyRun_FileEx() function.

So far I tried pdb, but it only raises bdb.BdbQuit exception in a line
immediately after pdb.set_trace() is called. I guess it's because it
is not running under normal Python interpreter, but just as well I may
be doing something wrong.

Can you please suggest what I may be doing wrong with pdb, or maybe
another python debugger?

cheers,
Marcin

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


Re: Saving output of Turtle Graphics?

2007-04-07 Thread Wojciech Muła
Dick Moores wrote:
> What do I do to see this?

For example Opera 9 and Firefox 1.5+ are able to view SVG files;
there is a free plugin for IrfanView.

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


Test Tube Zealots: The American Chemical Society Terminates the Membership of Chemists from Iran

2007-04-07 Thread stj911
http://counterpunch.org/rahni04072007.html

Test Tube Zealots: The American Chemical Society Terminates the
Membership of Chemists from Iran

By DAVID N. RAHNI

The American Chemical Society (ACS) has once again led the way, with
its "zealot" interpretation of "embargo" by the Department of
Treasury's Office of Foreign Asset Control, by terminating the
membership of its long-standing members in Iran, many of whom are post
Ph.D. Alumni of American Universities. Several years ago, the ACS
undertook a similar unprecedented action, under the same law. Then, it
unilaterally stopped accepting scholarly and research manuscripts from
Iranian scientists for its three dozen periodicals in the publication
division. However, later, under embarrassing pressure from the
American scientific community and its membership, the ACS retracted
its decision and agreed to take it up instead with the federal
government. Paradoxically and notwithstanding rhetoric, such ill-
conceived measures are against the current U.S. Administration policy
of promoting people-to-people contact as enunciated by the Assistant
Secretary of State Nicholas Burns at the March 29 hearing of the
Senate Foreign Relations Committee.

Yudhijit Bhattacharjee, in Science Magazine, reported that the ACS
Assistant General Counsel, David Smorodin when "re-reading the embargo
rules, made the recommendation to terminate Iranian membership(Science
Magazine, Vol. 315, 30 March 2007). One can not help but speculate
whether or not such decision is truly serving the interests of member-
based ACS or enforcing the laws to the limit as he has served as a
U.S. Assistant District Attorney before joining the ACS. Nonetheless,
despite the abrupt termination of individual membership of Iranian
chemical scientists with no due process, the ACS has stated that while
they [Iranians] can continue to purchase journals and other "non-
sensitive products at full-rate, the ACS might apply for a special
license from the Treasury Department to reinstate their memberships.
This has in the meantime deprived American chemists to learn about the
scholarly contributions of their Iranian peers.

It should be noted that as in the past, the American Physical Society
(APS), in contrast, stated, "We have NO plan to do anything similar,
and continue to serve our members in Iran." Judy Franz, a director at
the APS further stated that, "We would resist having to obtain a
license to the extent we can."

When interviewed by Science Magazine, the official publication of the
American Association for the Advancement of Science (AAAS), David
Rahni an Iranian-American chemistry professor in New York stated, "I,
like most ACS members and peers in the scientific community, strongly
question the ACS motive on this issue, and expect ACS,s leadership to
refrain from allowing politics to taint the high stature the
Organization has achieved." Rahni further stated that this has
personally concerned him gravely since he has served the ACS with
distinctions in the past thirty years, as typified by his positions as
the chair of the ACS New York, the chair of the Middle Atlantic
Regional Meeting, and the chair of Nichols Medal. 90% of the ACS
projects, publications and activities are run by a huge cadre of
volunteer professionals who, with no expectations, give their time,
energy, money and intellects and talents to the advancement of the
chemical sciences worldwide. It is painfully ironic to many,
especially the ACS American members to witness the politicization of
their disciplines through the ACS as they continue to register their
grave concerns with the ACS lucratively remunerated executive
directors. As a chemistry professor with having given fifty years of
his life to the ACS and the profession so eloquently put it, "Never
mind the Iranians as one may not give a darn about them and their
plights, what, I am bewildered to speculate the ulterior motives of
the ACS paid "professional leadership is to embarrass us as
freethinking science. ACS is US and not its DC staff as they are
required by our mandate to serve our interests and not create problems
for us.

The consensus among the nearly one million Americans of Iranian
ancestry is to reaffirm their yearning commitment to the attainment of
justice, security, stability, equity, transparency and human rights
through "home-grown", indigenous and democratic reforms in Iran, but
not at the expense of isolating the scientific community in their
motherland from their peers worldwide. They further deplore any
possible unilateral military action against Iran, as they firmly
believe this is counter-productive to the organic, slow, but steady
evolution of Iran through educational benchmark, cultural reforms and
communication with the rest of the world. They further consider
military action and/or isolation counter-productive to the credibility
of their American homeland which would inevitably lead, once again, to
the priceless loss of human life and loss of credibility for

Re: Pyserial example program error: win32file.SetupComm reports 'Incorrect function.'

2007-04-07 Thread hg
Ron Jackson wrote:

> Dennis Lee Bieber wrote:
>> On Wed, 07 Feb 2007 11:14:39 -0800, Ron Jackson
>> <[EMAIL PROTECTED]> declaimed the following in
>> comp.lang.python:
>> 
>> 
>>>I am using Python 2.5 on Windows XP. I have installed Pyserial and
>>>win32all extensions.
>>>
>> 
>> 2.4 on XP Pro SP2...
>> 
>> 
>>>When I try to run the example program scan.py (included below), or any
>>>other program using pyserial, as soon as it hits the statement:
>>>
>>>s = serial.Serial(i)
>>>
>> 
>> 
>import serial
>for i in range(256):
>> 
>> ...  try:
>> ...  print i,
>> ...  s = serial.Serial(i)
>> ...  print s.portstr
>> ...  s.close()
>> ...  except serial.SerialException:
>> ...  print
>> ...
>> 0 COM1
>> 1
>> 2 COM3
>> 3
>> 4
>> 5
>> 6
>> 7
>> 8
>> 9
>> 10
>> 11
>> and on and on...
>> 
>> 
>>>What do I need to do to fix this? Thanks for the help!
>> 
>> 
>> Does the serial port module require a compile for use with 2.5?
>> Well, with only one download since Python 2.2, guess not...
>> 
>> Something glitched in win32? Sorry, I don't know... However, since
>> those are Python source files, you could always plug in some debugging
>> lines around that win32 call to see what actually is there. Do you have
>> any unnatural serial ports on the machine? (Like a USB<>serial
>> converter?)
> 
> Trying your program, I get the same error 'Incorrect function.':
> 
> Traceback (most recent call last):
>File "", line 4, in 
>  s = serial.Serial(i)
>File "C:\Python25\Lib\site-packages\serial\serialutil.py", line 156, in
>__init__
>  self.open()
>File "C:\Python25\lib\site-packages\serial\serialwin32.py", line 57, in
>open
>  win32file.SetupComm(self.hComPort, 4096, 4096)
> error: (1, 'SetupComm', 'Incorrect function.')
> 
> 
> I tried PySerial on a laptop, also running XP Home SP2, and both the
> example program and the program you suggested work fine on the laptop.
> 
> The desktop computer that is giving me the error doesn't have any
> unnatural serial ports on it currently. The laptop worked fine, either
> with a USB device emulating COMM6 present or with the USB device
> disconnected.
> 
> I checked and both machines are running the same version of win32file,
> which is site-packages\win32\win32file.pyd, 88 KB dated 9/22/2006.
> 
> So my question is:
> 
> Why would the statement win32file.SetupComm(self.hComPort, 4096, 4096)
> 
> work just fine on one machine and not the other?
> 
> win32file.pyd can't be opened like a .py file, and I don't know what the
> rather cryptic error 'Incorrect function.' is trying to tell me. Does
> anyone who is familiar with win32file have an idea what the problem is?
> 
> Thanks for the help!
> 
>-- Ron


I am now facing your problem ... on a machine that used to work fine.

Have you figured it out ?

Could it be a conflict between pyserial and pywin32 ?

hg


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


Re: Saving output of Turtle Graphics?

2007-04-07 Thread Peter Otten
Dick Moores wrote:

> OK, thanks, now I've got

[an svg file]

> What do I do to see this?

You can convert it to a jpeg using ImageMagick's convert.

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


Re: Can't Get Email Interface Working

2007-04-07 Thread Tim Williams
On 07/04/07, Eric Price <[EMAIL PROTECTED]> wrote:
> Good grief! And they call a 722-line program "simple"?! LOL!
> I did what I need to do with a __one_line_shell_script__ LOL!
> Naw, if I have to go through all that, I'll skip on python this time around,
> thank you very much!
> Eric

Yup, its not so simple

Your problem is :

 File "/usr/local/lib/python2.4/mimetools.py", line 130, in choose_boundary
   hostid = socket.gethostbyname(socket.gethostname())
socket.gaierror: (8, 'hostname nor servname provided, or not known')

What do you get if you do the following in your interpreter?


>>> import socket
>>> socket.gethostname()
'twilliams'
>>> socket.gethostbyname(socket.gethostname())
'194.129.107.254'
>>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: block scope?

2007-04-07 Thread Alex Martelli
Neal Becker <[EMAIL PROTECTED]> wrote:
   ...
> > i = 5
> > for my i in xrange(4):
> >if i: # skips first when i is 0
> >  my i = 100
> >  if i:
> >print i   # of course 100
> >  break
> >print i   # i is between 0 & 3 here
> > print i # i is 5 here
> > 
> > 
> > Doesn't leave a particularly bad taste in one's mouth, I guess (except
> > for the intended abuse).
> > 
> > James
> 
> Yes, the above is pretty much what I had in mind.  +1.

I prefer Java's approach (14.4.2 in the JLS 2nd edition): forbid "inner"
blocks from shadowing variables in "outer" ones.  I quote:
"""
If a declaration of an identifier as a local variable of the same
method, constructor, or initializer block appears within the scope of a
parameter or local variable of the same name, a compile-time error
occurs.
Thus the following example does not compile:

class Test {
public static void main(String[] args) {
int i;
for (int i = 0; i < 10; i++)
System.out.println(i);
}
}
This restriction helps to detect some otherwise very obscure bugs.
"""
I entirely agree with the JLS here, having fought just such bugs in C++
and other languages that lack the restriction in question.  I just wish
Python had adopted the same restriction regarding nested functions, when
proper lexical scoping was introduced -- I argued for it at the time,
but backwards compatibility blocked its introduction.  There are
definitely NOT many Java-specific language characteristics that I like,
but this one is a winner!-)  [[but, I disagree with the lack in Java of
a similar restriction against shadowing between instance variables and
local variables, and the weak rationale for that in the JLS:-)]].


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


Re: Can't Get Email Interface Working

2007-04-07 Thread Eric Price

From: "Tim Williams" <[EMAIL PROTECTED]>
To: "Eric Price" <[EMAIL PROTECTED]>
CC: [EMAIL PROTECTED], python-list@python.org
Subject: Re: Can't Get Email Interface Working
Date: Sat, 7 Apr 2007 17:53:28 +0100

On 07/04/07, Eric Price <[EMAIL PROTECTED]> wrote:

Good grief! And they call a 722-line program "simple"?! LOL!
I did what I need to do with a __one_line_shell_script__ LOL!
Naw, if I have to go through all that, I'll skip on python this time 
around,

thank you very much!
Eric


Yup, its not so simple

Your problem is :

File "/usr/local/lib/python2.4/mimetools.py", line 130, in choose_boundary
  hostid = socket.gethostbyname(socket.gethostname())
socket.gaierror: (8, 'hostname nor servname provided, or not known')

What do you get if you do the following in your interpreter?



import socket
socket.gethostname()

'twilliams'

socket.gethostbyname(socket.gethostname())

'194.129.107.254'





import socket
socket.gethostname()

'server312.example.com'

socket.gethostbyname(socket.gethostname())

Traceback (most recent call last):
 File "", line 1, in ?
socket.gaierror: (8, 'hostname nor servname provided, or not known')




Obviously, I substituted "example.com" above; however, the host that comes 
back no longer exists, so it may as well be "example.com"! And the server # 
is courtesy of the server farm. In fact, the whole thing is. What do?

TIA,
Eric

_
Can’t afford to quit your job? – Earn your AS, BS, or MS degree online in 1 
year. 
http://www.classesusa.com/clickcount.cfm?id=866145&goto=http%3A%2F%2Fwww.classesusa.com%2Ffeaturedschools%2Fonlinedegreesmp%2Fform-dyn1.html%3Fsplovr%3D866143


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

Re: Saving output of Turtle Graphics?

2007-04-07 Thread Dick Moores
At 09:31 AM 4/7/2007, =?ISO-8859-2?Q?Wojciech_Mu=B3a?= wrote:
>Dick Moores wrote:
> > What do I do to see this?
>
>For example Opera 9 and Firefox 1.5+ are able to view SVG files;
>there is a free plugin for IrfanView.

Ha. I had tried it with Firefox 2 already, but I stupidly changed the 
extension to HTM first. I'll also get the IrfanView plugin.

Thanks for all the help, and especially for your canvasvg.py module.

Dick


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


Is http://cheeseshop.python.org/pypi/ having issues

2007-04-07 Thread RobJ
Has any one noticed any issues with http://cheeseshop.python.org/pypi/
? I have been trying for  hours to install packages (using
easy_install) but the connection keeps timing out.

Any Help would be a appreciated.

Rob J

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


Re: Checking whether list element exists

2007-04-07 Thread Terry Reedy

"Rehceb Rotkiv" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
|I want to check whether, for example, the element myList[-3] exists. So
| far I did it like this:
|
| index = -3
| if len(myList) >= abs(index):
| print myList[index]
# Note that tabs gets lost in some newsreaders. Spaces are better for 
posting

A full test of the index, equivalent to the try below, is as follows:

n = len(myList)
if -n <= index < n  # same as <= n-1, but avoids subtraction

This works for empty lists also (-0 <= i < 0 is never true!).

| Another idea I had was to (ab-?)use the try...except structure:
|
| index = -3
| try:
| print myList[index]
| except:
| print "Does not exist!"

Follow Gary Herron's comment on this.

| Is it ok to use try...except for the test

Both idioms are acceptible.  Some people would chose based on whether they 
expect bad indexes to be a normal occurence or an exceptional occurrence. 
One rule-of-thumb division point is 10% frequency.  More expensive tests 
would push this higher.

Terry Jan Reedy



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


Re: Custom Python Runtime

2007-04-07 Thread Terry Reedy

""Martin v. Löwis"" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
|> Is there a way to customize the Windows build? In my case, there is no 
need
| > to build an installer. The best way is to have everything in a 
directory, as
| > long as I know where to find Python and Python knows where to find the
| > necessary libs. Any online docs describing this? Thanks!
|
| The interpreter will search for its libraries relative to the location
| of the .exe file. So if you place python.exe and pythonxy.dll into
| a directory, you need to add a Lib directory
|
| Inside Lib, the minimum file you need to have is os.py: Python will
| use it as a landmark. If you run 'python.exe -S', this is all
| you need.
|
| If you want site.py to work, you also need (tested for 2.4):
| - site, codecs, copy_reg, locale, ntpath, stat, types UserDict,
|  encodings/__init__, encodings/aliases
|
| If you eliminate the aliasmbcs function from site.py, you can drop
| codecs, locale, encodings/*.
|
| If you eliminate the copy_reg references from os.py, you can also drop
| copy_reg.

If this information somewhere on python.org?  This is at least an 
occasional question here.

tjr 



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

Re: How to tell when a file is opened

2007-04-07 Thread Terry Reedy

"Adam" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| Hello,
|
| I want to know if it possible to tell when a file is opened.

Just by Python? (Hack the file and open and possibly os.open code)
or by any program? (Hack the OS -- good luck!)



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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 119"
Filter name: "KEYWORD= spam: Timing"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


Re: Is http://cheeseshop.python.org/pypi/ having issues

2007-04-07 Thread David Boddie
On Saturday 07 April 2007 19:36, RobJ wrote:

> Has any one noticed any issues with http://cheeseshop.python.org/pypi/
> ? I have been trying for  hours to install packages (using
> easy_install) but the connection keeps timing out.

Don't worry, you're not the first person to notice:

http://mail.python.org/pipermail/catalog-sig/2007-April/001050.html

Maybe someone can suggest a workaround for easy_install while the server
is unavailable.

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


Re: Comments in ConfigParser module

2007-04-07 Thread Joel Granados

On 4/6/07, James Stroud <[EMAIL PROTECTED]> wrote:


Joel Andres Granados wrote:
> Hi list:
> Any comment greatly appreciated

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



clever ???
Well I would expect that the ";" character to behave the same way that the
"#", as they are both characters that come before a comment.  But it
doesn't.  So I'm missing something here.  Why is the different behavior
clever?

--
Joel Andrés Granados
Medellín Colombia
--
[EMAIL PROTECTED]
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Dr Jeff King, A Jewish MIT Engineer is the LEAD SPEAKER on 911 truth, no Islamics involved http://video.google.com/videoplay?docid=1822764959599063248

2007-04-07 Thread Dr. V I Plankenstein

<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> See the video with your own EYEBALLS, that is if you have some courage
> and shame left:
>
> http://video.google.com/videoplay?docid=1822764959599063248



OK - I watched the video and I think it is a ridiculous position. They claim
that they can see puffs of smoke from squibs and charges ? That is stupid.
Clearly, it is an air blast from a  bellows effect of an entire floor of a
building being slapped flat by many many tons of force.

Then they are trying to figure out how office products could become
pulverized. Stupid. Obviously, all that energy must be going somewhere.

This is fucking idiotic to think that the Gov blew up WTC - pure fucking
idiocy.

Look at some actual footage of a controlled demo and you can see the charges
firing. In WTC there is dust clouds, but no flashes of light from charges,
which would have been practically impossible to disguise.

The notion that the smoke came from an explosive blast is utterly
ridiculous. Really, completely stupid and contemptible to even say such a
thing.

The whole idea is false, and idiotic.










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


Re: Is http://cheeseshop.python.org/pypi/ having issues

2007-04-07 Thread RobJ
On Apr 7, 1:51 pm, David Boddie <[EMAIL PROTECTED]> wrote:
> On Saturday 07 April 2007 19:36, RobJ wrote:
>
> > Has any one noticed any issues withhttp://cheeseshop.python.org/pypi/
> > ? I have been trying for  hours to install packages (using
> > easy_install) but the connection keeps timing out.
>
> Don't worry, you're not the first person to notice:
>
> http://mail.python.org/pipermail/catalog-sig/2007-April/001050.html
>
> Maybe someone can suggest a workaround for easy_install while the server
> is unavailable.
>
> David

Thanks David

I thought I was going nuts.

Rob J

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


Unicode problem

2007-04-07 Thread Rehceb Rotkiv
Please have a look at this little script:

#!/usr/bin/python
import sys
import codecs
fileHandle = codecs.open(sys.argv[1], 'r', 'utf-8')
fileString = fileHandle.read()
print fileString

if I call it from a Bash shell like this

$ ./test.py testfile.utf8.txt

it works just fine, but when I try to pipe the output to another process 
("|") or into a file (">"), e.g. like this

$ ./test.py testfile.utf8.txt | cat

I get an error:

Traceback (most recent call last):
  File "./test.py", line 6, in ?
print fileString
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in 
position 538: ordinal not in range(128)

I absolutely don't know what's the problem here, can you help?

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


Re: Checking whether list element exists

2007-04-07 Thread Rehceb Rotkiv
Thanks for your many helpful tips!

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


Re: How to tell when a file is opened

2007-04-07 Thread Adam
On Apr 7, 5:09 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
> Adam wrote:
> > I want to know if it possible to tell when a file is opened. However I
> > don't want it to be the last access time. I want to know how many
> > times a file opened so I can generate statistics of file usage.
>
> > I will be wanting to watch all files on a server so this will be on
> > quite a large scale. So checking a directory on a loop for accesses
> > won't work.
>
> > Maybe some way to monitor the Open Files section of Computer
> > Management?
>
> > I check through Tim Golden's site but nothing jumped out at me.
> > Any pointers would be great.
>
> I take it from the fact that you mention my site (and
> your reference to "Computer Management") that you're
> looking at Win32? It's always best to be explicit when
> you're asking for help; a lot of people on this list
> will be using Linux or Mac where the answers are
> probably very different.
>
> This is no small task you've set yourself! As far as I know,
> you're going to have to go down to the level of change journals
> for this kind of thing. (Search for "NTFS change journal").
>
> Although you might think: the filesystem knows when files are
> being accessed; can't I hook into that directly? I think the
> answer is: no. But I could be wrong.
>
> TJG

Sorry about not mentioning my platform.

What you mention looks promising. Will look into it. Like I said
knowing the last access time is not useful as I would have to be
constantly looping through the directory looking for changes.

Will look into NTFS change journals when I get some spare time.

Thanks for the reply.
Adam

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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 120"
Filter name: "KEYWORD= spam: Timing"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 120"
Filter name: "KEYWORD= spam: Timing"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 120"
Filter name: "KEYWORD= spam: Timing"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


Re: Can't Get Email Interface Working

2007-04-07 Thread Eric Price
>   Complain to the providers of the server? Or find out what the host
>name is for the outgoing SMTPd connection, and use it directly.

Complaining isn't going to help. How do I determine the outgoing smtpd 
connection and how do I use it directly?
TIA,
Eric

_
Exercise your brain! Try Flexicon. 
http://games.msn.com/en/flexicon/default.htm?icid=flexicon_hmemailtaglineapril07

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


Re: Mail not setting timestamp

2007-04-07 Thread Lorenzo Thurman
Gabriel Genellina wrote:
> Lorenzo Thurman wrote:
> 
>> I'm using the Mimewriter and mimetools modules to create html messages.
>> They work OK, except that when the messages are received, they always
>> have the timestamp of 12/31/1969. I've looked through both packages and
>> can't find anything that would allow me to manually set it. Can someone
>> help me out?
> 
> The date goes into the message headers, like From, To, Subject...
> message.add_header("Date", "Thu, 22 Jun 2006 23:18:15 -0300")
> 
> --
> Gabriel Genellina
> 
Thanks for the reply. When I try this though, I get an error:

Traceback (most recent call last):
   File "./synctest.py", line 202, in ?
 message = createhtmlmail(html, text, subject)
   File "./synctest.py", line 49, in createhtmlmail
 writer.addheader("Date", theDate)
   File "/usr/lib/python2.4/MimeWriter.py", line 100, in addheader
 lines = value.split("\n")
AttributeError: 'datetime.datetime' object has no attribute 'split'

I'm trying to use a variable for the date, since of course, it should 
always be 'now'.
someDate = datetime.datetime.now()
writer.addheader("Date", someDate)
Hard coding a date, like your example, works just fine.
Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to tell when a file is opened

2007-04-07 Thread Gabriel Genellina
Adam wrote:

> On Apr 7, 5:09 pm, Tim Golden <[EMAIL PROTECTED]> wrote:

> > Adam wrote:

> > > I want to know if it possible to tell when a file is opened. However I
> > > don't want it to be the last access time. I want to know how many
> > > times a file opened so I can generate statistics of file usage.

You may look into some tools like FileMon and Process Monitor from
www.sysinternals.com; I think that doing the processing in Python
would slow down your system a lot (or not, just try!)

--
Gabriel Genellina

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


Re: Mail not setting timestamp

2007-04-07 Thread Gabriel Genellina
Lorenzo Thurman wrote:
> Gabriel Genellina wrote:
> > Lorenzo Thurman wrote:
> >
> >> I'm using the Mimewriter and mimetools modules to create html messages.
> >> They work OK, except that when the messages are received, they always
> >> have the timestamp of 12/31/1969. I've looked through both packages and
> >>
> > The date goes into the message headers, like From, To, Subject...
> > message.add_header("Date", "Thu, 22 Jun 2006 23:18:15 -0300")
> >
> Thanks for the reply. When I try this though, I get an error:
> AttributeError: 'datetime.datetime' object has no attribute 'split'
> I'm trying to use a variable for the date, since of course, it should
> always be 'now'.

You have to convert the date into a string, using the right format.
The docs for the time module have a recipe:
http://www.python.org/doc/current/lib/module-time.html
(look for RFC 2822)

--
Gabriel Genellina

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


Re: tuples, index method, Python's design

2007-04-07 Thread 7stud
On Apr 7, 8:27 am, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Sat, 2007-04-07 at 06:45 -0700, [EMAIL PROTECTED] wrote:
> > Carsten Haese:
> > > The lack of convincing use cases is still a pertinent reason today. Note
> > > that the original poster on this thread did not present a use case for
> > > tuple.index, they were only asking out of curiosity.
> > > If you have a use case for tuple.index, please show it to me, and I'll
> > > show you what you should be using instead of a tuple.
>
> > Maybe we can add such methods to the PyPy tuples for some time, to
> > experimentally see if they make the language worse :-)
>
> Adding useless features always makes a product worse. What's your use
> case for tuple.index?
>
> -Carsten

I'll trade you an index method for tuples for the whole complex number
facility.

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


Re: Unicode problem

2007-04-07 Thread Gabriel Genellina
Rehceb Rotkiv wrote:

> #!/usr/bin/python
> import sys
> import codecs
> fileHandle = codecs.open(sys.argv[1], 'r', 'utf-8')
> fileString = fileHandle.read()
> print fileString
>
> if I call it from a Bash shell like this
>
> $ ./test.py testfile.utf8.txt
>
> it works just fine, but when I try to pipe the output to another process
> ("|") or into a file (">"), e.g. like this
>
> $ ./test.py testfile.utf8.txt | cat
>
> I get an error:
>
> Traceback (most recent call last):
>   File "./test.py", line 6, in ?
> print fileString
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in
> position 538: ordinal not in range(128)
>
> I absolutely don't know what's the problem here, can you help?

Using codecs.open, when you read the file you get Unicode. When you
print the Unicode object, it is encoded using your terminal default
encoding (utf8 I presume?)
But when you redirect the output, it's no more connected to your
terminal so no encoding can be assumed, and the default encoding is
used.

Try this line at the top:
print
"stdout:",sys.stdout.encoding,"default:",sys.getdefaultencoding()
I get stdout: ANSI_X3.4-1968 default: ascii normally and stdout: None
default: ascii when redirected.

You have to encode the Unicode object explicitely: print
fileString.encode("utf-8")
(or any other suitable one; I said utf-8 just because you read the
input file using that)

--
Gabriel Genellina

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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 121"
Filter name: "KEYWORD= spam: Timing"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 121"
Filter name: "KEYWORD= spam: Timing"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 121"
Filter name: "KEYWORD= spam: Timing"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


Re: Comments in ConfigParser module

2007-04-07 Thread Gabriel Genellina
Joel Andres Granados wrote:

> The module also allows the comments to appear in the same line as the
> "name = value" constructs.  The only difference being that this is only
> possible with ";" and not with "#" character.  I did not see this in the
> documentation but this is how it is behaving.

Yes, it's not documented. There is only a comment in the source code:

# ';' is a comment delimiter only if it
follows
# a spacing character

I think it's either a bug in the code or in the documentation.

> QUESTION...So the question is:
> Can you use "#" and ";" as comment characters? and if so why does the
> "#" not apply for the same situations as the ";"?

If you follow the documentation, comments are ONLY allowed to start a
line.
The actual implementation discards any text following a ;
sequence.

> Just for reference:
> On the RFC 822  (a document
> referenced in the documentation) there is a mention of ";" being used as
> comment character but not necessarily at the beginning of the line.

RFC822 uses ";" to include comments in the syntax rules, not for
comments in the actual message headers (parenthesis are used there).

--
Gabriel Genellina

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


Re: Convert xml symbol notation

2007-04-07 Thread Gabriel Genellina
Martin v. Löwis wrote:

> >> I'm working on a script to download and parse a web page, and it
> >> includes xml symbol notation, such as ' for the ' character.  Does
> >
> > Try the htmlentitydefs module.
>
> That won't help: this is a character reference, not an entity reference.
> htmlentitydefs only contains the definitions of entities.

Ouch! Sorry.

--
Gabriel Genellina

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

Re: Pyserial example program error: win32file.SetupComm reports 'Incorrect function.'

2007-04-07 Thread hg
Dennis Lee Bieber wrote:

> On Sat, 07 Apr 2007 11:36:05 +0200, hg <[EMAIL PROTECTED]> declaimed the
> following in comp.lang.python:
> 
>> 
>> I am now facing your problem ... on a machine that used to work fine.
>> 
>> Have you figured it out ?
>> 
>> Could it be a conflict between pyserial and pywin32 ?
>>
> 
> The test still runs on my system -- which is still running the
> ActiveState 2.4.3 build*... So that probably clears M$ of any
> malfeasance (via various and sundry patches).
> 
> The closest a google search came up with was someone trying to
> control a serial port printer getting failures on setupcomm (and /not/
> via Python). I think the gist was that any port except the one the
> printer was connected to was okay.
> 
> So... Is there some device connected to the port in question?
> Possibly a device that has a system level driver (ie, a Windows printer
> entry) that might be preventing changes...
> 
> 
> 
> 
> 
> * Too many 3rd-party modules still aren't available in 2.5 versions
> for my tastes...
> --
> Wulfraed  Dennis Lee Bieber   KD6MOG
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/


My fault,

I actually _had_ the issue with python 2.4

I removed everything and reinstalled python 2.4.4, pywin( lastest) and
pyserial (latest) ... the problem is gone.

hg



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


Re: Objects, lists and assigning values

2007-04-07 Thread Manuel Graune
"7stud" <[EMAIL PROTECTED]> writes:

>
> What book are you reading?
>

I worked my way through most of the online-docs. A bit to casual
obviously.

As printed desktop-reference I use a german book called 
"Python ge-packt".


-- 
A hundred men did the rational thing. The sum of those rational choices was
called panic. Neal Stephenson -- System of the world
http://www.graune.org/GnuPG_pubkey.asc
Key fingerprint = 1E44 9CBD DEE4 9E07 5E0A  5828 5476 7E92 2DB4 3C99
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to tell when a file is opened

2007-04-07 Thread Adam
On Apr 7, 8:02 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote:
> Adam wrote:
> > On Apr 7, 5:09 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
> > > Adam wrote:
> > > > I want to know if it possible to tell when a file is opened. However I
> > > > don't want it to be the last access time. I want to know how many
> > > > times a file opened so I can generate statistics of file usage.
>
> You may look into some tools like FileMon and Process Monitor 
> fromwww.sysinternals.com;I think that doing the processing in Python
> would slow down your system a lot (or not, just try!)
>
> --
> Gabriel Genellina

You see I was mainly hoping that python would not be doing the
processing per se. More that, as Tim put it, it would hook itself into
whatever monitors the shares to see when files are open and dump that
info somewhere (like a database or xml) then at a set time (at night
for example) Python would take that information collect it into
historical logs and update a web page with recent stats.

Obviously I have to check that the most vital part is even possible or
at least within my limit programming knowledge (which is why I ask
here.)

Adam

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


Re: 1 Thread = 3 interpreter launched ???

2007-04-07 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb:
> Hi all, and thanks for reading !
> 
> I'm using Python 2.4.2 with an embedded platform (16MB RAM) running
> Linux 2.6.20.
> My main script use a thread for some reasons (more precisely a
> periodic timer within a separate module).
> While looking at the memory consumption, here's what i found :
> 
>   PID USER STATUS   RSS  PPID %CPU %MEM COMMAND
>   171 root R384   164  1.5  2.6 top
>   218 root R   4172   217  0.1 29.1 main_script.py
>   216 root S   4172   180  0.0 29.1 main_script.py
>   217 root S   4172   216  0.0 29.1 main_script.py
> 
> When creating the thread, Python forks 2 times and thus consume me
> around 60% of RAM !
> 
> Is it a normal behaviour while using threads ???
> 
> It's very critical, am i missed something ?

Yes. That some linuxes list each thread as one process. No need to worry...

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


Re: Understanding Python's interpreter

2007-04-07 Thread Steve Holden
Mike C. Fletcher wrote:
> Steve Holden wrote:
>> Rafael Almeida wrote:
>>   
> ...
>> Because they aer smarter than you, without wishing to be too rude.
>>   
> Replace that with "more experienced", please.  Otherwise it is a bit 
> rude, despite your wishes.  We've always been newbie positive on 
> Python-list, and new compiler writers are just as important educational 
> targets as new Python programmers.
> 
Maybe I was feeling a little crabby this morning. "More experienced" is 
certainly a more appropriate way to express the sentiment. Thanks.

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: Objects, lists and assigning values

2007-04-07 Thread 7stud
On Apr 7, 2:52 pm, Manuel Graune <[EMAIL PROTECTED]> wrote:
> "7stud" <[EMAIL PROTECTED]> writes:
>
> > What book are you reading?
>
> I worked my way through most of the online-docs. A bit to casual
> obviously.
>

See the online tutorial's section on default function arguments here:

http://docs.python.org/tut/node6.html#SECTION00671

specifically the "Important Warning".

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


Re: block scope?

2007-04-07 Thread Steve Holden
Alex Martelli wrote:
> Neal Becker <[EMAIL PROTECTED]> wrote:
>...
>>> i = 5
>>> for my i in xrange(4):
>>>if i: # skips first when i is 0
>>>  my i = 100
>>>  if i:
>>>print i   # of course 100
>>>  break
>>>print i   # i is between 0 & 3 here
>>> print i # i is 5 here
>>>
>>>
>>> Doesn't leave a particularly bad taste in one's mouth, I guess (except
>>> for the intended abuse).
>>>
>>> James
>> Yes, the above is pretty much what I had in mind.  +1.
> 
> I prefer Java's approach (14.4.2 in the JLS 2nd edition): forbid "inner"
> blocks from shadowing variables in "outer" ones.  I quote:
> """
> If a declaration of an identifier as a local variable of the same
> method, constructor, or initializer block appears within the scope of a
> parameter or local variable of the same name, a compile-time error
> occurs.
> Thus the following example does not compile:
> 
> class Test {
> public static void main(String[] args) {
> int i;
> for (int i = 0; i < 10; i++)
> System.out.println(i);
> }
> }
> This restriction helps to detect some otherwise very obscure bugs.
> """
> I entirely agree with the JLS here, having fought just such bugs in C++
> and other languages that lack the restriction in question.  I just wish
> Python had adopted the same restriction regarding nested functions, when
> proper lexical scoping was introduced -- I argued for it at the time,
> but backwards compatibility blocked its introduction.  There are
> definitely NOT many Java-specific language characteristics that I like,
> but this one is a winner!-)  [[but, I disagree with the lack in Java of
> a similar restriction against shadowing between instance variables and
> local variables, and the weak rationale for that in the JLS:-)]].
> 
What do you think the chances are of this being accepted for Python 3.0? 
It is indeed about the most rational approach, though of course it does 
cause problems with dynamic namespaces.

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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 122"
Filter name: "KEYWORD= spam: Timing"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 122"
Filter name: "KEYWORD= spam: Timing"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 122"
Filter name: "KEYWORD= spam: Timing"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


Antigen Notification: Antigen found a message matching a filter

2007-04-07 Thread Antigen_VITORIA
Microsoft Antigen for Exchange found a message matching a filter. The message 
is currently Detected.
Message: "Python_list Digest_ Vol 43_ Issue 122"
Filter name: "KEYWORD= spam: collect _AND_ check"
Sent from: "[EMAIL PROTECTED]"
Folder: "SMTP Messages\Inbound And Outbound"
Location: "ITURAN/First Administrative Group/VITORIA"


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


  1   2   >