suid/sudo in python

2009-03-29 Thread rustom
Im trying to write a program that has su permissions for some file
system tasks and is non-su elsewhere. This is typically done in C with
suid root owned code.

What is the python paradigm for this kind of thing? (if at all)
--
http://mail.python.org/mailman/listinfo/python-list


Re: global name 'self' is not defined - noob trying to learn

2009-03-29 Thread Chris Rebert
2009/3/29 Scott David Daniels :
> mark.sea...@gmail.com wrote:
>>
>> On Mar 29, 9:52 pm, Chris Rebert  wrote:
>>>
>>> On Sun, Mar 29, 2009 at 9:18 PM,   wrote:

 ...
>>>
>>> ... Also, you shouldn't use `class_ ` as the name of the first argument
>>> to
>>> __new__(). Use `cls` instead since that's the conventional name for
>>> it.
>
> Actually, according to PEP 8, class_ is the preferred name.

In other contexts where you have a class as a variable, yes, but not
in the case of classmethods such as this. See the docs for __new__
itself for example
(http://docs.python.org/reference/datamodel.html#object.__new__).

>>> My best guess as to what you're trying to do is (completely untested):
>>> class myclass(long):
>>>    def __new__(cls, init_val, reg_info):
>>>        print reg_info.message
>>>        instance = long.__new__(cls, init_val)
>>>        instance.reg_info = reg_info
>>>        return instance
>
> Normally, these changes are done in the __init__ phase (post-instance
> creation), so you might go for something like:

I think the whole reason he's using __new__ instead of __init__ is
because of this tidbit from the aforementioned __new__() docs:
"""
__new__() is intended mainly to allow subclasses of immutable types
(like int, str, or tuple) to customize instance creation. It is also
commonly overridden in custom metaclasses in order to customize class
creation.
"""

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: global name 'self' is not defined - noob trying to learn

2009-03-29 Thread Scott David Daniels

mark.sea...@gmail.com wrote:

On Mar 29, 9:52 pm, Chris Rebert  wrote:

On Sun, Mar 29, 2009 at 9:18 PM,   wrote:

...

... Also, you shouldn't use `class_ ` as the name of the first argument to
__new__(). Use `cls` instead since that's the conventional name for
it.

Actually, according to PEP 8, class_ is the preferred name.


My best guess as to what you're trying to do is (completely untested):
class myclass(long):
def __new__(cls, init_val, reg_info):
print reg_info.message
instance = long.__new__(cls, init_val)
instance.reg_info = reg_info
return instance


Normally, these changes are done in the __init__ phase (post-instance 
creation), so you might go for something like:


class myclass(long):
def __new__(class_, init_val, reg_info):
return long.__new__(class_, init_val)

def __init__(self, init_val, reg_info):
self.reg_info = reg_info


--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: PID lockfile

2009-03-29 Thread JanC
Aahz wrote:

>>Okay. But is that something that needs to be accommodated with,
>>specifically, PID file handling? Why would a PID file ever need to be
>>on NFS storage instead of local?
>
> That's the question.  You'll probably get some complaints from people
> running diskless machines, eventually, some years down the line.

I think on diskless machines using a tmpfs (or similar) for PID files would
be more sane anyway, but of course not everybody will (or can?) use
that...


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


Re-raising exceptions with a different type and message, preserving existing information

2009-03-29 Thread Ben Finney
Howdy all,

I'm writing a module and want to have a unified exception hierarchy
for the exceptions that it can raise. This allows users of the module
to catch those particular exceptions and handle them distinctly, if
needed. But many of the exceptions raised from the module are raised
because of some other exception; e.g. failing at some task because of
an OSError on a file.

What I need is to “wrap” the exception caught such that it has a
different type and message. But I don't want to lose the existing
type, message, and stack trace; that's all useful information for
someone trying to debug the problem.

Python's PEP 3134 “Exception Chaining and Embedded Tracebacks”
discusses a change accepted in Python 3.0 for “chaining” exception
objects, to indicate that a new exception was raised during the
handling of an existing exception.

What I'm trying to do is related: I need it working in earlier Python
versions, and I need it not for chaining, but only for polymorphism.
What is the right way to do this?

-- 
 \   “… whoever claims any right that he is unwilling to accord to |
  `\ his fellow-men is dishonest and infamous.” —Robert G. |
_o__)   Ingersoll, _The Liberty of Man, Woman and Child_, 1877 |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list


Re: global name 'self' is not defined - noob trying to learn

2009-03-29 Thread mark . seagoe
On Mar 29, 9:52 pm, Chris Rebert  wrote:
> On Sun, Mar 29, 2009 at 9:18 PM,   wrote:
> > Hi.  So now I have this class that works to allow me to pass in my
> > reg_info struct.  However when I try to make it part of my class it
> > gets an error "global name 'self' is not defined.  I've never seen
> > this error before.  If I comment out the line below 'self.reg_info =
> > reg_info" then the code runs... but I need to add stuff to this class,
> > and so I'm wondering why I can't use 'self' anymore?
>
> `self` is not magical or a language keyword. It's just the
> conventional name for the first argument to an instance method (which
> is the instance the method is acting upon). For example, a small
> minority use `s` instead for brevity. There is no variable `self` in
> the parameters of __new__(), hence you get a NameError, as you would
> when trying to access any other nonexistent variable.
>
> Also, you shouldn't use `class_ ` as the name of the first argument to
> __new__(). Use `cls` instead since that's the conventional name for
> it.
>
> My best guess as to what you're trying to do is (completely untested):
> class myclass(long):
>     def __new__(cls, init_val, reg_info):
>         print reg_info.message
>         instance = long.__new__(cls, init_val)
>         instance.reg_info = reg_info
>         return instance
>
> Cheers,
> Chris
>
> --
> I have a blog:http://blog.rebertia.com

Thanks Chris.  It was tested working (with the offending line editted
out).
Yep this is helpful - I thought 'self' was a keyword.  And I see I
should differentiate the instance methods and objects from the cls
reference.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problems with background processes on Windows

2009-03-29 Thread Gabriel Genellina
Gabriel Genellina  yahoo.com.ar> writes:
> En Sat, 28 Mar 2009 06:03:33 -0300, geoffbache  
jeppesen.com>  
> escribió:
> >
> > Well yes, but the point is surely that the standard output of the
> > background sleeping process is pointed to a different location? (you
> > can replace the null device with a file name of your choice and the
> > point is the same.) This process should not have any connection to the
> > standard output of sleep.py, and hence we shouldn't need to wait for
> > it to finish when collecting the standard output of sleep.py, surely?
> > (Even explicitly calling sys.stdout.close() in sleep.py doesn't seem
> > to help)
> 
> Thesis: When the subprocess module creates the child process, it inherits  
> the stdin/stdout/stderr handles from its parent (even if its own  
> stdin/stdout/stderr are redirected; they're different). Until the  
> grandchild process finishes, the grandparent stdout.read() won't return,  
> because the pipe isn't closed until the last handle to it is closed.

I've confirmed the above description.

--- begin p0.py ---
import subprocess,os

p1 = subprocess.Popen(["python", "p1.py"], 
  stdout=subprocess.PIPE,
  stderr=open(os.devnull, "wt"),
  stdin=open(os.devnull))
print p1.communicate()
--- end p0.py ---

--- begin p1.py ---
import subprocess,sys,os,msvcrt

subprocess.Popen(
["python", "p2.py", str(msvcrt.get_osfhandle(sys.stdout.fileno()))], 
stdout=open(os.devnull, "wt"),
stderr=open(os.devnull, "wt"),
stdin=open(os.devnull, "rt"))
print "exit p1.py"
--- end p1.py ---

--- begin p2.py ---
import sys, win32api, time, os

with open("p2.pid","wt") as f: f.write("%d" % os.getpid())
win32api.CloseHandle(int(sys.argv[1]))
time.sleep(30)
--- end p2.py ---

p2 has to close the inherited file handle corresponding to p1's stdout. Then, 
when p1 itself finishes, the writing end of the pipe is actually closed and p0 
can continue.

C:\TEMP\subp>python p0.py
('exit p1.py\r\n', None)

C:\TEMP\subp>type p2.pid
3018
C:\TEMP\subp>tasklist | find "python.exe"
python.exe  3018 0 4.304 KB

I'm unsure this could be considered a bug in subprocess - the documentation 
says that parameter close_fds=True is not supported on Windows (so, the child 
process inherits all open files, and this includes the parent's 
stdin/stdout/stderr). 

At the end, this is due to the fact that file handles 0, 1, 2 have no special 
significance on Windows - it's the C runtime library which makes such things 
special, not the OS.


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


Re: global name 'self' is not defined - noob trying to learn

2009-03-29 Thread Chris Rebert
On Sun, Mar 29, 2009 at 9:18 PM,   wrote:
> Hi.  So now I have this class that works to allow me to pass in my
> reg_info struct.  However when I try to make it part of my class it
> gets an error "global name 'self' is not defined.  I've never seen
> this error before.  If I comment out the line below 'self.reg_info =
> reg_info" then the code runs... but I need to add stuff to this class,
> and so I'm wondering why I can't use 'self' anymore?

`self` is not magical or a language keyword. It's just the
conventional name for the first argument to an instance method (which
is the instance the method is acting upon). For example, a small
minority use `s` instead for brevity. There is no variable `self` in
the parameters of __new__(), hence you get a NameError, as you would
when trying to access any other nonexistent variable.

Also, you shouldn't use `class_ ` as the name of the first argument to
__new__(). Use `cls` instead since that's the conventional name for
it.

My best guess as to what you're trying to do is (completely untested):
class myclass(long):
def __new__(cls, init_val, reg_info):
print reg_info.message
instance = long.__new__(cls, init_val)
instance.reg_info = reg_info
return instance

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Speech activated scripting/macroing for Windows

2009-03-29 Thread John Doe

For a time, a Dr. Rick Mohr worked on a Vocola project that allowed 
continuous command recognition through Dragon NaturallySpeaking in 
Windows. Currently Vocola is available for Windows Vista and higher, 
but no longer available for use through DNS. 

More recently, Christo Butcher has begun a Python project called 
"Dragonfly" that works with NaturallySpeaking through NatLink (a 
crucial part of the continuous command recognition process that might 
be in need of further development).

http://dragonfly.googlecode.com/svn/trunk/dragonfly/

Apparently Dragonfly is the only current programming method to allow 
continuous command recognition (aka "command sequences") spoken to a 
computer through Naturally Speaking. 

This is hot stuff IMO. Currently, speech recognition is a pain to use, 
but it is improving (enough for Microsoft to include SR in Windows for 
"casual users"). In fact, command recognition is much easier than 
dictation because the vocabulary is extremely limited compared to a 
human vocabulary. Continuous command recognition represents the advent 
of natural communication with a computer. It allows defining words and 
then using those words on the fly (ad lib), very similar to a human 
language.

If you have any interest in voice-activated scripting/macroing for 
Windows, please take a look at Christo's Dragonfly project. 

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


global name 'self' is not defined - noob trying to learn

2009-03-29 Thread mark . seagoe
Hi.  So now I have this class that works to allow me to pass in my
reg_info struct.  However when I try to make it part of my class it
gets an error "global name 'self' is not defined.  I've never seen
this error before.  If I comment out the line below 'self.reg_info =
reg_info" then the code runs... but I need to add stuff to this class,
and so I'm wondering why I can't use 'self' anymore?

from ctypes import Structure, c_byte, c_char

class REG_INFO(Structure):
_fields_ = [
('address', c_byte),
('message', c_char * 256)
]

class myclass(long):
def __new__(class_, init_val, reg_info):
print reg_info.message
self.reg_info = reg_info # <== Offending line
return long.__new__(class_, init_val)

#
# setup
my_reg = REG_INFO()
my_reg.address = 0xab
my_reg.message = 'hello world'

print 'TEST 1'
dog = 0x123456789ABCDEF0
print 'type(dog) = %s' % type(dog)
print 'dog val = 0x%016X' % dog

print 'TEST 2'
cat = myclass(0x55, my_reg)
print 'cat val = 0x%016X' % cat
print 'type(cat) = %s' % type(cat)

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


Re: i have to change default tab length in pydev

2009-03-29 Thread Coonay
On Mar 30, 6:13 am, "Rhodri James" 
wrote:
> On Sat, 28 Mar 2009 11:30:36 -, Coonay  wrote:
> > during last few days, i code python using notepad++ or pydev, the
> > compiler always complain there is a problem with Indentation,in my
> > eyes ,there is no Indentation problem at all,because i format the code
> > to make it comply with python style guide strictly,but after i change
> > the default tab length ,it works.
>
> If you're mixing tabs and spaces, which from your description you are,
> then you aren't complying strictly with the Python style guide.  PEP 8
> says:
>
> """
> Tabs or Spaces?
>
>     Never mix tabs and spaces.
> """
>
> Clearly the compiler was considering tabs to be a different width to
> your editor's initial setting.  Where you saw:
>
>          Line starting with 8 spaces
>          Line starting with a tab
>
> in the editor window, the compiler instead saw:
>
>          Line starting with 8 spaces
>      Line starting with a tab
>
> or something like that.  Running with "python -t" will warn you about
> this sort of thing.
>
> --
> Rhodri James *-* Wildebeeste Herder to the Masses
i understand that you get request token,and you need to get Access
tokens after that,
my question is about Access tokens:which mechanism  do u use to tore
access tokens for future use
--
http://mail.python.org/mailman/listinfo/python-list


Re: email from windows

2009-03-29 Thread prakash jp
nope not successful. DO let me know the usage of:
#From : prakash.st...@gmail.com
#To: prakash.st...@gmail.com

import sys, smtplib
import string
fromaddr = raw_input("From: ")
toaddrs  = string.splitfields(raw_input("To: "), ',')
print "Enter message, end with ^D:"
msg = ''
count = 3
while count > 0:
line = sys.stdin.readline()
#if not line:
#break
msg = msg + line
count = count -1
# The actual mail send
server = smtplib.SMTP('localhost')
server.sendmail(fromaddr, toaddrs, msg)
server.quit()
#pls define the usage

On Mon, Mar 30, 2009 at 7:40 AM, prakash jp  wrote:

> Hi all,
>
> In windows environment, how to send email from one gmail address to another
> gmail (or another mail) addrress
>
>
> Regards
> Prakash
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python print and types selection

2009-03-29 Thread Scott David Daniels

mark.sea...@gmail.com wrote:

...
I'm not sure what the "something * 3" does?  Here is the printout:
dog = HugeNumber(369) = 0171
But I was able to put the concept into practice.



It was simply meant to be an absurd example.
If you could apply it, you've got the idea.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python print and types selection

2009-03-29 Thread mark . seagoe
On Mar 28, 1:47 pm, Scott David Daniels  wrote:
> mark.sea...@gmail.com wrote:
> > ...
> > It appears that if I make the class a subclass of long...
> > class bignumber(long):
> >     def __init__(self, initval):
> >         self.val = initval
>
> > Then if I make a new class of subclass of bignumber...
> > class myclass(bignumber):
> >     def __init__(self, another_custom_class)
> >         bignumber.__init__(self, 0)
> >         do some stuff with another_custom_class
>
> > When I try to use this, I get an error sort of like this:
> > "TypeError: long() argument must be a string or a number, not
> > [whatever type another_custom_class is]"
>
> Remember that long is an immutable class (so you need to fiddle __new__,
> not __init__).  So, do something a bit more like:
>
>      class BigNumber(long):
>          def __repr__(self):
>              return '%s(%s)' % (type(self).__name__, self)
>
>      class HugeNumber(BigNumber):
>          def __new__(class_, something):
>              return BigNumber.__new__(class_, something * 3)
>
>   then you can do something like:
>      print 'dog = %r = %016X' % (HugeNumber(123), HugeNumber(123))
>
> Hope that helps.
>
> --Scott David Daniels
> scott.dani...@acm.org- Hide quoted text -
>
> - Show quoted text -

Thanks, Scott.

I'm not sure what the "something * 3" does?  Here is the printout:
dog = HugeNumber(369) = 0171
But I was able to put the concept into practice.

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


Fwd: Re: 2.5/2.4 multiprocessing backport doc typo

2009-03-29 Thread messlinger
Please get me off this merry-go-round from hell i plead the blood of JESUS you 
guys need help your clogging my computor and all i wanted to do was know about 
a movie give me a break take my e-mail off all your links please i feel as tho  
a pytho has ahold of me and i will kill it! christ blood applied will do 
it
--
GOD BLESS WINDWOMAN!!!

> From: a...@pythoncraft.com (Aahz)
> Subject: Re: 2.5/2.4 multiprocessing backport doc typo
> Date: 29 Mar 2009 17:14:57 -0700
> To: python-list@python.org
> 
> In article ,
> Daniel Fetchinson   wrote:
> >
> >===
> >Changes
> >===
> >
> >2.6.1.1 -- 2009-12-07
> >
> >I guess it should be 2008-12-07 :)
> 
> That's just the time machine in operation.
> -- 
> Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/
> 
> "Debugging is twice as hard as writing the code in the first place.
> Therefore, if you write the code as cleverly as possible, you are, by
> definition, not smart enough to debug it."  --Brian W. Kernighan
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Fwd: Re: 2.5/2.4 multiprocessing backport doc typo

2009-03-29 Thread messlinger
Please get me off this merry-go-round from hell i plead the blood of JESUS you 
guys need help your clogging my computor and all i wanted to do was know about 
a movie give me a break take my e-mail off all your links please i feel as tho  
a pytho has ahold of me and i will kill it! christ blood applied will do 
it
--
GOD BLESS WINDWOMAN!!!

> From: a...@pythoncraft.com (Aahz)
> Subject: Re: 2.5/2.4 multiprocessing backport doc typo
> Date: 29 Mar 2009 17:14:57 -0700
> To: python-list@python.org
> 
> In article ,
> Daniel Fetchinson   wrote:
> >
> >===
> >Changes
> >===
> >
> >2.6.1.1 -- 2009-12-07
> >
> >I guess it should be 2008-12-07 :)
> 
> That's just the time machine in operation.
> -- 
> Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/
> 
> "Debugging is twice as hard as writing the code in the first place.
> Therefore, if you write the code as cleverly as possible, you are, by
> definition, not smart enough to debug it."  --Brian W. Kernighan
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Fwd: Re: 2.5/2.4 multiprocessing backport doc typo

2009-03-29 Thread messlinger
Please get me off this merry-go-round from hell i plead the blood of JESUS you 
guys need help your clogging my computor and all i wanted to do was know about 
a movie give me a break take my e-mail off all your links please i feel as tho  
a pytho has ahold of me and i will kill it! christ blood applied will do 
it
--
GOD BLESS WINDWOMAN!!!

> From: a...@pythoncraft.com (Aahz)
> Subject: Re: 2.5/2.4 multiprocessing backport doc typo
> Date: 29 Mar 2009 17:14:57 -0700
> To: python-list@python.org
> 
> In article ,
> Daniel Fetchinson   wrote:
> >
> >===
> >Changes
> >===
> >
> >2.6.1.1 -- 2009-12-07
> >
> >I guess it should be 2008-12-07 :)
> 
> That's just the time machine in operation.
> -- 
> Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/
> 
> "Debugging is twice as hard as writing the code in the first place.
> Therefore, if you write the code as cleverly as possible, you are, by
> definition, not smart enough to debug it."  --Brian W. Kernighan
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Fwd: Re: 2.5/2.4 multiprocessing backport doc typo

2009-03-29 Thread messlinger
Please get me off this merry-go-round from hell i plead the blood of JESUS you 
guys need help your clogging my computor and all i wanted to do was know about 
a movie give me a break take my e-mail off all your links please i feel as tho  
a pytho has ahold of me and i will kill it! christ blood applied will do 
it
--
GOD BLESS WINDWOMAN!!!

> From: a...@pythoncraft.com (Aahz)
> Subject: Re: 2.5/2.4 multiprocessing backport doc typo
> Date: 29 Mar 2009 17:14:57 -0700
> To: python-list@python.org
> 
> In article ,
> Daniel Fetchinson   wrote:
> >
> >===
> >Changes
> >===
> >
> >2.6.1.1 -- 2009-12-07
> >
> >I guess it should be 2008-12-07 :)
> 
> That's just the time machine in operation.
> -- 
> Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/
> 
> "Debugging is twice as hard as writing the code in the first place.
> Therefore, if you write the code as cleverly as possible, you are, by
> definition, not smart enough to debug it."  --Brian W. Kernighan
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Fwd: Re: 2.5/2.4 multiprocessing backport doc typo

2009-03-29 Thread messlinger
Please get me off this merry-go-round from hell i plead the blood of JESUS you 
guys need help your clogging my computor and all i wanted to do was know about 
a movie give me a break take my e-mail off all your links please i feel as tho  
a pytho has ahold of me and i will kill it! christ blood applied will do 
it
--
GOD BLESS WINDWOMAN!!!

> From: a...@pythoncraft.com (Aahz)
> Subject: Re: 2.5/2.4 multiprocessing backport doc typo
> Date: 29 Mar 2009 17:14:57 -0700
> To: python-list@python.org
> 
> In article ,
> Daniel Fetchinson   wrote:
> >
> >===
> >Changes
> >===
> >
> >2.6.1.1 -- 2009-12-07
> >
> >I guess it should be 2008-12-07 :)
> 
> That's just the time machine in operation.
> -- 
> Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/
> 
> "Debugging is twice as hard as writing the code in the first place.
> Therefore, if you write the code as cleverly as possible, you are, by
> definition, not smart enough to debug it."  --Brian W. Kernighan
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Re: email from windows

2009-03-29 Thread David Lyon

Hi Prakash,

You need to tell the system your smtp host...

ie 

> server = smtplib.SMTP('localhost')

needs to read something like

server = smtplib.SMTP('smtp.myisp.in')


On Mon, 30 Mar 2009 08:58:49 +0530, prakash jp 
wrote:
> preexistant code :
> 
> import sys, smtplib
> import string
> fromaddr = raw_input("From: ")
> toaddrs  = string.splitfields(raw_input("To: "), ',')
> print "Enter message, end with ^D:"
> msg = ''
> count = 3
> while count > 0:
> line = sys.stdin.readline()
> #if not line:
> #break
> msg = msg + line
> count = count -1
> # The actual mail send
> server = smtplib.SMTP('localhost')
> server.sendmail(fromaddr, toaddrs, msg)
> server.quit()
> 
> -
> Running the program:
> --
> From: prakash.st...@gmail.com
> To: prakash.st...@gmail.com
> hai
> how r
> u
> ---
> error creeps in :
> error says
> 
> Traceback (most recent call last):
>   File "C:\Python25\python-collection\mail\mail.py", line 17, in 
> server = smtplib.SMTP('localhost')
>   File "C:\Python25\lib\smtplib.py", line 244, in __init__
> (code, msg) = self.connect(host, port)
>   File "C:\Python25\lib\smtplib.py", line 310, in connect
> raise socket.error, msg
> error: (10061, 'Connection refused')
> 
> On Mon, Mar 30, 2009 at 7:40 AM, prakash jp 
> wrote:
> 
>> Hi all,
>>
>> In windows environment, how to send email from one gmail address to
> another
>> gmail (or another mail) addrress
>>
>>
>> Regards
>> Prakash
>>

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


Re: email from windows

2009-03-29 Thread prakash jp
preexistant code :

import sys, smtplib
import string
fromaddr = raw_input("From: ")
toaddrs  = string.splitfields(raw_input("To: "), ',')
print "Enter message, end with ^D:"
msg = ''
count = 3
while count > 0:
line = sys.stdin.readline()
#if not line:
#break
msg = msg + line
count = count -1
# The actual mail send
server = smtplib.SMTP('localhost')
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

-
Running the program:
--
From: prakash.st...@gmail.com
To: prakash.st...@gmail.com
hai
how r
u
---
error creeps in :
error says

Traceback (most recent call last):
  File "C:\Python25\python-collection\mail\mail.py", line 17, in 
server = smtplib.SMTP('localhost')
  File "C:\Python25\lib\smtplib.py", line 244, in __init__
(code, msg) = self.connect(host, port)
  File "C:\Python25\lib\smtplib.py", line 310, in connect
raise socket.error, msg
error: (10061, 'Connection refused')

On Mon, Mar 30, 2009 at 7:40 AM, prakash jp  wrote:

> Hi all,
>
> In windows environment, how to send email from one gmail address to another
> gmail (or another mail) addrress
>
>
> Regards
> Prakash
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: email from windows

2009-03-29 Thread Alan G Isaac

2009/3/29 prakash jp :

In windows environment, how to send email from one gmail address to another
gmail (or another mail) addrress



On 3/29/2009 10:20 PM Chris Rebert apparently wrote:

Use the `smtplib` and `email` standard libraries (which, as a bonus,
are cross-platform):
http://docs.python.org/library/smtplib.html
http://docs.python.org/library/email.html



Also see:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/67083

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


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac
On Mon, 30 Mar 2009 00:13:46 +0100, Alan G Isaac  
wrote:

Since you did not address my question about
the nuance of "magic", I'm inclined to treat
you as a "no" vote.



On 3/29/2009 7:19 PM Rhodri James apparently wrote:

And you'd be wrong.



So seriously, you'd read e.g. John's usage
of the term "magic" (in this thread)
to suggest "indignation"?

Curious.  But I recognize that cultures differ.

Alan Isaac



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


RE: Cannot register to submit a bug report

2009-03-29 Thread John Posner
 >> 
 >> We can try to debug this :)
 >> 
 >> > E-mail message checked by Spyware Doctor (6.0.0.386)
 >> > Database version: 
 >> 5.12060http://www.pctools.com/en/spyware-doctor-antivirus/
 >> 
 >> Any chance it's Spyware Doctor or some anti-virus flagging 
 >> the message
 >> and hiding it?
 >> 

Thanks for the suggestion, but that's probably not it. No message appears on
my ISP mail server (Yahoo), either. That's beyond the reach of my machine's
Spyware Doctor.

I plan to take Terry's suggestion: send a message to the Webmaster.

Tx,
John





E-mail message checked by Spyware Doctor (6.0.0.386)
Database version: 5.12060
http://www.pctools.com/en/spyware-doctor-antivirus/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Installing PLPython - Version Problem

2009-03-29 Thread Scott David Daniels

andrew cooke wrote:
> ray wrote:
>> I am trying to get Python 2.6 and PostgreSQL 8.3 to work together
>> under Windows 2000.

i haven't got much of a clue about python's binary api, but what you are
doing sounds absolutely crazy to me.

Andrew is right; unless you want to do exploratory work, install the
latest 2.5, and use that Python for your PostGres work.  A number of
packages have not made it to 2.6 yet.


i guess you are using a binary prebuilt to use a certain python version
(ie 2.5).  your simplest solution is to install that python version (it is
possible to have more than one version of python installed at a time,
although i do not the details of how to do this on windows).

The details are trivial compared to what it takes for other platforms:
install the latest 2.5 and (if you _really_ want to be normally using
2.6), install the latest 2.6 afterwards.  You can avoid re-installing
2.6 with a few command line manipulations (ftype and assoc), possibly
also changing %PATH% (the PATH environment variable), but the simplest
way is to just re-install 2.6.  By the way, it looks like Barry Warsaw
will be releasing 2.6.2 soon -- 2.6.2 rc1 on 6-April, hoping for 2.6.2
final on 10-April).

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: email from windows

2009-03-29 Thread Chris Rebert
2009/3/29 prakash jp :
> Hi all,
>
> In windows environment, how to send email from one gmail address to another
> gmail (or another mail) addrress

Use the `smtplib` and `email` standard libraries (which, as a bonus,
are cross-platform):
http://docs.python.org/library/smtplib.html
http://docs.python.org/library/email.html

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


email from windows

2009-03-29 Thread prakash jp
Hi all,

In windows environment, how to send email from one gmail address to another
gmail (or another mail) addrress


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


Re: 2.5/2.4 multiprocessing backport doc typo

2009-03-29 Thread Scott David Daniels

Aahz wrote:

In article ,
Daniel Fetchinson   wrote:

===
Changes
===

2.6.1.1 -- 2009-12-07

I guess it should be 2008-12-07 :)


That's just the time machine in operation.

I thought I smelled ozone.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Installing PLPython - Version Problem

2009-03-29 Thread andrew cooke

i haven't got much of a clue about python's binary api, but what you are
doing sounds absolutely crazy to me.

i guess you are using a binary prebuilt to use a certain python version
(ie 2.5).  your simplest solution is to install that python version (it is
possible to have more than one version of python installed at a time,
although i do not the details of how to do this on windows).

alternatively, you might try building postgres yourself and seeing if it
will build against python 2.6, but that sounds like a whole pile of work,
while installing the right python version should be pretty easy.

andrew


ray wrote:
> I am trying to get Python 2.6 and PostgreSQL 8.3 to work together
> under Windows 2000.
>
> When I try to add Python to PostgreSQL via:
> createlang plpythonu dbname
>
> But when doing so, I get an error:
> createlang: language installation failed: ERROR:  could not load
> library "C:/Program Files/PostgreSQL/8.3/lib/createlang: language
> installation failed: ERROR:  could not load library "C:/Program Files/
> PostgreSQL/8.3/lib/plpython.dll": The specified module could not be
> found."
>
> So I Used "depends" to walk the references of plpython.dll, I found
> that it can not find python25.dll.  Since I have 2.6, only
> python26.dll is in ...system32.
>
> 1) The first question is how do I get this stack to look for the 2.6
> version?
>
> If I make a copy of python26.dll and rename it python25.dll, that
> reference is resolved but a new one appears for apphelp.dll:
> Error opening file.  The system cannot find the file specified (2).
> Warning: At least on delay-load dependency module was not found.
> Warning:  At least on module has an unresolved import due to a missing
> export function in a delayed-load dependent module.
>
> 2) I do not find apphelp on my system.  Where do I get a copy and
> where should it be placed?
>
> When I rename the dll to python26, the PL installed without error.
> But I am concerned that something else is wrong.  I would really like
> to find out how to get this to install correctly on production
> machines.
>
> Ray
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


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


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Rhodri James
On Mon, 30 Mar 2009 00:45:41 +0100, Alan G Isaac   
wrote:

On 3/29/2009 6:49 PM Scott David Daniels apparently wrote:
What happens to your TV when you change the channel before turning it  
on?


I think we can agree this is a safe action, but the result
depends  on the kind of TV (and on what "turning it on" means).
So I think your analogy makes my point: allowing
the state of the variable to be registered at use rather than
creation is feasible, although it would perhaps not be best.
(E.g., it would not be simplest.)


s/simplest/safest/.  The chances of something going wrong if you
have a staggered setup like that are quite high.  The chances of
someone trying to use a ???Var before any of the rest of the
system is set up (and, if they're lucky, seg-faulting) shouldn't
be overlooked either.

Amusingly, I'm just old enough to remember when the answer to
Scott's question was "you probably get static, because the odds
of turning the dial to exactly the right spot are small."

Printing a StrVar is not the same as printing the contents of a  
StrVar.  Having "magic" conversions happen for you when they can be  
useful simply allows you to make mistakes about what things are what.


This sounds like an argument against duck typing, and maybe
even an argument for eliminating most of the special method
names, although I'm sure you did not mean it to be this.  ;-)


When you're talking implementation details (which is most of
what we're doing), duck typing does allow you to make mistakes
about what's actually happening.  That's the whole point of
it.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Installing PLPython - Version Problem

2009-03-29 Thread ray
I am trying to get Python 2.6 and PostgreSQL 8.3 to work together
under Windows 2000.

When I try to add Python to PostgreSQL via:
createlang plpythonu dbname

But when doing so, I get an error:
createlang: language installation failed: ERROR:  could not load
library "C:/Program Files/PostgreSQL/8.3/lib/createlang: language
installation failed: ERROR:  could not load library "C:/Program Files/
PostgreSQL/8.3/lib/plpython.dll": The specified module could not be
found."

So I Used "depends" to walk the references of plpython.dll, I found
that it can not find python25.dll.  Since I have 2.6, only
python26.dll is in ...system32.

1) The first question is how do I get this stack to look for the 2.6
version?

If I make a copy of python26.dll and rename it python25.dll, that
reference is resolved but a new one appears for apphelp.dll:
Error opening file.  The system cannot find the file specified (2).
Warning: At least on delay-load dependency module was not found.
Warning:  At least on module has an unresolved import due to a missing
export function in a delayed-load dependent module.

2) I do not find apphelp on my system.  Where do I get a copy and
where should it be placed?

When I rename the dll to python26, the PL installed without error.
But I am concerned that something else is wrong.  I would really like
to find out how to get this to install correctly on production
machines.

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


Re: python -TFTP over LAN

2009-03-29 Thread MRAB

prakash jp wrote:

Hi all,
 
I am interested in using python based TFTP over my LAN. Do let me know 
how to ahead and any specific urls. Thaks in advance.
 

http://sourceforge.net/projects/tftpy/
--
http://mail.python.org/mailman/listinfo/python-list


python -TFTP over LAN

2009-03-29 Thread prakash jp
Hi all,

I am interested in using python based TFTP over my LAN. Do let me know how
to ahead and any specific urls. Thaks in advance.

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


Re: 2.5/2.4 multiprocessing backport doc typo

2009-03-29 Thread Aahz
In article ,
Daniel Fetchinson   wrote:
>
>===
>Changes
>===
>
>2.6.1.1 -- 2009-12-07
>
>I guess it should be 2008-12-07 :)

That's just the time machine in operation.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."  --Brian W. Kernighan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding JSON

2009-03-29 Thread WallyDD
On Mar 29, 4:58 pm, Chris Rebert  wrote:
> On Sun, Mar 29, 2009 at 1:39 PM, WallyDD  wrote:
> > Hello,
>
> > I am trying to geocode some map data using the google maps API.
>
> > By using the urllib I can get the JSON output;
> >http://maps.google.com/maps/geo?q=New+York+USA&output=json&oe=utf8&se...
>
> > I then read it using;
> > gmapiresult = json.loads(fg.read())
> > somedata = gmapiresult['Placemark']
>
> > result is; (somedata)
> > [{u'Point': {u'coordinates': [-73.9869515, 40.7560539,
> > 0]}, u'ExtendedData': {u'LatLonBox': {u'west': -74.25909, u'east':
> > -73.699793, u'north': 40.9174989, u'south':
> > 40.4773833}}, u'AddressDetails': {u'Country': {u'CountryName':
> > u'USA', u'AdministrativeArea': {u'AdministrativeAreaName': u'NY',
> > u'Locality': {u'LocalityName': u'New York'}}, u'CountryNameCode':
> > u'US'}, u'Accuracy': 4}, u'id': u'p1', u'address': u'New York, NY,
> > USA'}]
>
> > Can I further refine the data in "somedata" or am I reliant on string
> > manipulation?
> > all I need to get is the data in "coordinates".
>
> > I am not sure if this is a json problem or if I don't understand lists
> > well enough.
>
> What you get back from the JSON is just some nested lists and
> dictionaries containing the data, not a giant string (wouldn't be a
> very useful serialization format then, now would it?).
> If you pretty-print the data using pprint.pprint(), it becomes much
> more readable (I hope linewrap did not get activated...):
>
> [{u'AddressDetails': {u'Accuracy': 4,
>                       u'Country': {u'AdministrativeArea':
> {u'AdministrativeAreaName': u'NY',
>
> u'Locality': {u'LocalityName': u'New York'}},
>                                    u'CountryName': u'USA',
>                                    u'CountryNameCode': u'US'}},
>   u'ExtendedData': {u'LatLonBox': {u'east': -73.699793,
>                                    u'north': 40.9174989,
>                                    u'south': 40.4773833,
>                                    u'west': -74.25909}},
>   u'Point': {u'coordinates': [-73.9869515, 40.7560539, 0]},
>   u'address': u'New York, NY,USA',
>   u'id': u'p1'}]
>
> So to get the coordinates, you simply do:
> coords = somedata[0]['Point']['coordinates']
>
> which gets the first and only element in the toplevel list, and this
> element is a dictionary,
> and then gets the value associated with the key 'Point' in that
> dictionary, which gives us another dictionary (that happens to have
> only one key-value pair),
> and finally gets the value associated with the key 'coordinates' in
> that dictionary, which gives us the desired list of floats.
>
> Cheers,
> Chris
> --
> I have a blog:http://blog.rebertia.com

Excellent.
Thank you very much.

pprint looks very helpful.
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

On 3/29/2009 6:49 PM Scott David Daniels apparently wrote:
Right.  Tkinter could have been built to make a root at 
the first instantiation of a StringVar or IntVar, but it 
wasn't.  Answering your why is a bit like answering the 
"Why did Picasso choose primarily blue in his Blue Period, 
rather than green?"


But this is a fine answer: a choice had to be made, and
nothing much seemed to be at issue, so this was the simpler
(or whatever) choice.  I did not ask for a deeper answer,
but if that is the correct answer, it cannot be expected to
be obvious to those who are new to the code.


Hmmm -- where cvould things go wrong --- segment fault? 
what happens when you call code that hasn't had the setup run? 


Again, I do not understand, and I think I explained why.
Of course if the Variable is not registered with Tcl/Tk at
*creation*, it will have to be registered when first
associated with a widget (or in any way with the event
mechanism).  But of course my question was why a Variable
cannot exist independently of the event mechanism.  Since
you did not critique the answer I proposed in my previous
post, I assume you do not have a big problem with it.  If it
is correct, it is the kind of answer I was looking for.


What happens to your TV when you change the channel before 
turning it on? 


I think we can agree this is a safe action, but the result
depends  on the kind of TV (and on what "turning it on" means).
So I think your analogy makes my point: allowing
the state of the variable to be registered at use rather than
creation is feasible, although it would perhaps not be best.
(E.g., it would not be simplest.)


Printing a StrVar is not the same as printing the contents 
of a StrVar.  Having "magic" conversions happen for you 
when they can be useful simply allows you to make mistakes 
about what things are what.


This sounds like an argument against duck typing, and maybe
even an argument for eliminating most of the special method
names, although I'm sure you did not mean it to be this.  ;-)

Thanks for the discussion.  Your willingness to converse
with someone whose initial "tone" irritated you has helped
me to improve my understanding, and hopefully some future
user will find this thread of some use.

Cheers,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bullshit Generator

2009-03-29 Thread livibetter
This is fun. I tried to add speech synthesis on Linux, hope you don't
mind.

If you have speech-dispatcher [1] worked normally, you can replace the
main program with

# --
# main program
# --
try:
import win32com.client
voice = win32com.client.Dispatch("sapi.SPVoice")
except:
try:
import speechd
voice = speechd.SSIPClient('bullshit.py')
# Choose one module you have on your system
voice.set_output_module('espeak')
voice.set_punctuation(speechd.PunctuationMode.SOME)
except:
voice = None

print "press  to resume, 'q'+ to quit\n"

while True:
print
for i in xrange(8):
generatedSentence = sentence.getString()
print generatedSentence,
if voice:
voice.speak(generatedSentence)
if raw_input().strip().lower() == "q":
voice.cancel()
import sys
sys.exit(0)
# End of Main Program

[1] http://cvs.freebsoft.org/doc/speechd/
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Rhodri James
On Mon, 30 Mar 2009 00:13:46 +0100, Alan G Isaac   
wrote:



Since you did not address my question about
the nuance of "magic", I'm inclined to treat
you as a "no" vote.


And you'd be wrong.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: dict view to list

2009-03-29 Thread Rhodri James
On Sun, 29 Mar 2009 08:39:10 +0100, Aaron Brady   
wrote:



I guess there are two arguments for the change.

1.  Flat is better than nested.


I don't think that's really what this is refering to.


2.  It interferes with the way people read text.


Insert "some" before "people" and I'd have to agree.


The order of events are: First, get the view.  Then convert it to a
list.  Hence, dictA.get_view( ).to_list( ).


Alternatively, "get the list of dictA's view," or
list(dictA.get_view()).  Both are legitimate text, after all.


This may call for a more fundamental change to a programming language
than Python should make; and it may have to wait for another
generation.  It entails that function applications should be of the
form '( x )f' instead of 'f( x )', in a pretty general way.


Sorry, but if what you're describing isn't essentially calling a
method, then I don't understand the point you're trying to make.
If it is, you still need to address Terry's point about why lists
get the special treatment and not other built-in types.


I also recognize that natural language and thus human thinking does
admit of a certain depth of nesting.  English, notably, has two means
of nesting, at least in the possessive case.  'The mother of
invention' and "invention's mother".  Here is a predicate example too:
'The cat is on the mat' and 'On the mat is the cat', although the late
is mostly unattested-to these days.


Erm, this isn't what I understand by 'nesting' in language, which has
more to do with how many subclauses, like these, you can cope with
being active at any one time before you forgot what the sentence
started off being about :-)

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

On 3/29/2009 6:50 PM Rhodri James apparently wrote:

In this case, your choice of wording
(the nearest thing we have in print to "tone of voice") did not
inspire me to go digging around in source that you have just as
easy access to, in order to answer questions that I'm not
particularly interested in.



I certainly was not trying to inspire you to do so.
The question was meant for people who had this
level of understanding already, or who already
knew with some specificity where I might dig.

Since you did not address my question about
the nuance of "magic", I'm inclined to treat
you as a "no" vote.

Thanks,
Alan Isaac

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


Re: Cannot register to submit a bug report

2009-03-29 Thread ajaksu
John Posner wrote:
> I've tried twice to register myself at bugs.python.org. But the confirmation
> email message never arrives. (Yes, I checked my spam folder.) What do I do
> now?

We can try to debug this :)

> E-mail message checked by Spyware Doctor (6.0.0.386)
> Database version: 5.12060http://www.pctools.com/en/spyware-doctor-antivirus/

Any chance it's Spyware Doctor or some anti-virus flagging the message
and hiding it?

Here are some headers I get in a test confirmation email, maybe the
different values for 'from' make it look spammish:
  FROM: roundup-ad...@example.com
  TO: lo...@localhost
  From nobody Sun Mar 29 23:02:37 2009
[...]
  Subject: Complete your registration to Tracker -- key ITK...
  To: lo...@localhost
  From: Tracker 
  Date: Sun, 29 Mar 2009 23:02:37 +
  Precedence: bulk

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


Re: if there is a return type of a method definition like java does

2009-03-29 Thread Rhodri James

On Sat, 28 Mar 2009 03:11:20 -, Coonay  wrote:


if there is a return type of a method definition,that would lead to
faster decision to do with the method called,do you think so?


A method definition always returns a function object.  There.

Less facetiously, I don't see how knowing the return type of a
function or method affects decision speed in calling it at all.
I suppose it might allow some optimisation of subsequent
operations on the result, but given the dynamic typing nature
of Python I can't see that being worth the considerable effort.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cannot register to submit a bug report

2009-03-29 Thread Terry Reedy

John Posner wrote:

I've tried twice to register myself at bugs.python.org. But the confirmation
email message never arrives. (Yes, I checked my spam folder.) What do I do
now?


I will not suggest that you register at the roundup tracker to report 
this ;-, especially since it may be a local problem.  If no answer here, 
try email to webmaster.python.org.


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


Re: Python AppStore / Marketplace

2009-03-29 Thread Daniel Fetchinson
>> How will your solution be different from distutils, setuptools, pip,
>> zc.buildout and a couple other similar packages I don't recall now?
>
> For a start.. it doesn't replace those.. it drives them...
>
>> Have you considered joining one of these efforts in order to not
>> fragment the "packaging and distribution" arena?
>
> They seem pretty comprehensive and well developed as they are. I am not
> sure what I could do to improve the under-the-hood functionality at this
> point in time.
>
> My GUI just drives their back end code..
>
>> Have you evaluated these solutions in detail and have found that they
>> are not appropriate for your needs?
>
> Yes. They don't have a GUI.
>
> If yes, what is the most problematic features of these
>> already existing solutions that you don't like?
>
> Not having a GUI is the biggest problem. Since I am swapping
> languages (Python/Perl/+1 more) in any given day I'm just after
> something that is "simple". I can never remember the commandlines..

Okay, I see your point. You might find it useful to go through the
following [1] thread on python-dev that talks about various packaging
and distribution options. Tarek Ziade led a discussion on this topic
at pycon, you might find that helpful too [2] and he also conducted a
survey on packaging [3].

[1] http://mail.python.org/pipermail/python-dev/2009-March/087590.html
[2] http://mail.python.org/pipermail/python-dev/2009-March/087834.html
[3] http://mail.python.org/pipermail/python-dev/2009-March/087656.html

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Rhodri James
On Sun, 29 Mar 2009 22:37:24 +0100, Alan G Isaac   
wrote:



On 3/29/2009 2:46 PM Scott David Daniels apparently wrote:
You ask, "What exactly is the role of ...", rather than saying  
something like, "I don't understand the role of ...", and continue to  
ask why the code is not architected the way you first expected it to be  
architected, calling those things you do not understand "magic"  (not  
"magically" which would at least invoke a sense of wonder, rather than  
indignation).



Clearly there are some cultural differences here.  I am not
a CS type.  I would not presume to criticize the
architecture, and in my world, questions are generally
assumed to be what they appear to be: questions.


A question does not stop being a question just because it is
arrogant or respectful, terse or verbose, or whatever else
it manages to communicate.  In this case, your choice of wording
(the nearest thing we have in print to "tone of voice") did not
inspire me to go digging around in source that you have just as
easy access to, in order to answer questions that I'm not
particularly interested in.

--
Rhodri James *-* Wildebeeste Herder to the Masses
(Also a bit grumpy this weekend.  It must be the weather.)
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Scott David Daniels

Alan G Isaac wrote:

Alan asked:
- Why does a Variable need a master? - If s is a StringVar instance, 
why is   str(s) its name rather than its value?


On 3/29/2009 2:46 PM Scott David Daniels apparently wrote:
The answer to that, grasshopper, lies in the answer to the question, 
"What are StringVars designed to do?"  StringVars, and IntVars, and 
... are elements to receive, hold, and propagate changes to values 
that will produce effects in the programs behavior or display.  I find 
IntVars easier to explain, since you get values for numbers lots of 
ways.  If a slider updates an IntVar, a signal must reach anything 
"interested" in the value of that IntVar.  For example, you have a 
rectangle, and a display of its height, width, area, and aspect ratio. 
If you change the height or the width, the area and aspect ratio need 
updating (as well as the value in the height or width).


In short, a Variable can have observers.  My question does
not lie here.  At least, you have not persuaded me that it does.


But the answers to your questions lie here.  (1) An XxxVar is something
much different than its current contents -- it is an addressable point
in a web of interacting events.  The value currently in the XxxVar is
(in many ways) the least interesting thing about it.  If you created
the XxxVar before initializing the event system, there would have to be
a funny dance done when that event system got initialized: it would have
to run around and find all of the XxxVars and associate them with the
event system.  Also, the XxxVar code would have to know how to behave
when its value is set before the event system is started (as many things
start initialized).


I take this to be the core of your argument: that a Variable
cannot signal to a widget until the event mechanism is up
and running.  But of course if you create e.g. a Frame, the
"root" is automagically created.  So I do not understand
your reasoning.

Right.  Tkinter could have been built to make a root at the
first instantiation of a StringVar or IntVar, but it wasn't.
Answering your why is a bit like answering the "Why did Picasso
choose primarily blue in his Blue Period, rather than green?"


To elaborate, where could things go wrong if I could
instantiate a Variable without first instantiating a Tk root
object?  [S]uppose I want to associate an ``Entry`` with

> a ``StringVar``. If I have not already created a root,
> I would have to create the ``Entry`` first (which
> auotmagically creates the root) and then the ``StringVar``,
> but what is the payoff from this restriction?

Hmmm -- where cvould things go wrong --- segment fault?
what happens when you call code that hasn't had the setup run?
The initialization of the XxxVar to some fixed value is the first
event generated by that XxxVar.  The XxxVar code calls the event
system saying 'blahblah' has been set to 0 or whatever.  Once the
event system is running, it can ignore this as nobody (no other
code such as an Entry instance) has expressed an interest.  Before
then the data structures may not be in a safe state.  What happens
to your TV when you change the channel before turning it on?


Just to be clear, I am not so presumptuous as to try to
challenge the design.  I am trying to understand it.

But you are trying to understand it by asking why it is
not different from how it currently is.  Sometimes the
answer is "because it is the way it is."


PS If you were also offering an answer to the second question,
I missed it altogether, but although it is perhaps slightly
less obvious than with a StringVar, I would ask the same
basic question of an IntVar: why does it not behave more
like an int?  E.g., why is ``int(IntVar(value=5))`` an
error, or at least, why is ``str(IntVar(value=5))`` the name
of the IntVar instead of '5'?


I think I answered that above, but here's another try before I'm
done with you:  Printing a StrVar is not the same as printing the
contents of a StrVar.  Having "magic" conversions happen for you
when they can be useful simply allows you to make mistakes about
what things are what.  Python has a set of design principles
available through "import this", the second (Explicit is better
than implicit) and twelfth (In the face of ambiguity, refuse the
temptation to guess) apply here.  int((1,)) is not 1, it is a failure.
str(("test",)) is "('test',)", not 'test'.

--Scott David Daniels
scott.dani...@acm.org



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


Re: Bullshit Generator

2009-03-29 Thread james

just make sure it stays out of the hands of IT managers.

Quoting Dotan Cohen :


Hello,

For those of you that
- want to surf on the edge of Web technology without understanding it,
- desire to be considered as a software guru,
- are forced to write technical documents that nobody will read.
- want to laugh a bit,

I have written a "Bullshit Generator" script in Python (see below). It
generates English sentences at random, talking about leading-edge Web-based
technologies. For example it can produce simple sentences like

"The interface subscriber manages the web-based online ontology."

or more complex, like

"Generally speaking, the architecture is collected by the client from the
encapsulation related to the artifact that retrieves the data in the UDDI
where the integration enabled by the issuer delivers a Portal technology
responsible for an XML operation."

The algorithm is based on a simplified English grammar, fed with hard-coded
lists of (buzz)words. The sentence structure is selected by choosing
randomly among a set of weighted rules, i.e. some rules are more likely to
be used than others. The sentences are oriented to hype Web technologies but
you can easily switch to your preferred domain, simply by changing the list
of words.

For Windows XP/Vista users: if you have installed the win32com package
(delivered with PythonWin), you should hear the sentences pronounced by
synthesized speech.



You should really post this on a blog somewhere. Instant slashdot!

--
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
--
http://mail.python.org/mailman/listinfo/python-list




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


2.5/2.4 multiprocessing backport doc typo

2009-03-29 Thread Daniel Fetchinson
Whoever wrote the multiprocessing backport for 2.4/2.5, a big thank you!
Just one note: on the page
http://pypi.python.org/pypi/multiprocessing/ there is a news item from
the future:

===
Changes
===

2.6.1.1 -- 2009-12-07

I guess it should be 2008-12-07 :)

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyGTK and skins?

2009-03-29 Thread Emanuele D'Arrigo
On Mar 29, 12:28 am, Cousin Stanley  wrote:
>     You might try the pygtk mailing list available
>     via the  news.gmane.org  server 

Than you Stanley, much appreciated!

Manu


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


Re: i have to change default tab length in pydev

2009-03-29 Thread Rhodri James

On Sat, 28 Mar 2009 11:30:36 -, Coonay  wrote:


during last few days, i code python using notepad++ or pydev, the
compiler always complain there is a problem with Indentation,in my
eyes ,there is no Indentation problem at all,because i format the code
to make it comply with python style guide strictly,but after i change
the default tab length ,it works.


If you're mixing tabs and spaces, which from your description you are,
then you aren't complying strictly with the Python style guide.  PEP 8
says:

"""
Tabs or Spaces?

   Never mix tabs and spaces.
"""

Clearly the compiler was considering tabs to be a different width to
your editor's initial setting.  Where you saw:

Line starting with 8 spaces
Line starting with a tab

in the editor window, the compiler instead saw:

Line starting with 8 spaces
Line starting with a tab

or something like that.  Running with "python -t" will warn you about
this sort of thing.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to access object created in Main?

2009-03-29 Thread Rhodri James
On Sun, 29 Mar 2009 19:12:23 +0100, Muddy Coder   
wrote:



Hi Folks,

I need to update the text field of a Label created in Main, but can't
find a way to do it. Please take a look at my code:

from Tkinter import *

def makemenu(r)
   amenu = Menu(r)
   amenu.add_command(., command=update_label)

def update_label():
how to access mesg created in __main__ ?

if __name__ == '__main__':
root = Tk()
mesg = Label(root, text='foo\nbar\nfoo')
mesg.pack(expand=YES, fill=BOTH)
root.mainloop()


A style point: the "if __name__ == '__main__'" construct implies that
you expect your file to be included as a module at some time in the
future.  When that time comes, having your menu structure rely on
module globals that will not exist (because the "mesg = Label()"
doesn't get run) will cause your program to explode messily in a
deeply confusing way.


--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python AppStore / Marketplace

2009-03-29 Thread David Lyon


On Fri, 27 Mar 2009 08:16:01 -0700, Daniel Fetchinson
 wrote:
>
> How will your solution be different from distutils, setuptools, pip,
> zc.buildout and a couple other similar packages I don't recall now?

For a start.. it doesn't replace those.. it drives them...

> Have you considered joining one of these efforts in order to not
> fragment the "packaging and distribution" arena? 

They seem pretty comprehensive and well developed as they are. I am not
sure what I could do to improve the under-the-hood functionality at this
point in time.

My GUI just drives their back end code..

> Have you evaluated these solutions in detail and have found that they 
> are not appropriate for your needs? 

Yes. They don't have a GUI.

If yes, what is the most problematic features of these
> already existing solutions that you don't like?

Not having a GUI is the biggest problem. Since I am swapping
languages (Python/Perl/+1 more) in any given day I'm just after
something that is "simple". I can never remember the commandlines..

Regards

David






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


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

On 3/29/2009 2:46 PM Scott David Daniels apparently wrote:
You ask, "What exactly is the role of ...", rather than 
saying something like, "I don't understand the role of 
...", and continue to ask why the code is not architected 
the way you first expected it to be architected, calling 
those things you do not understand "magic"  (not 
"magically" which would at least invoke a sense of wonder, 
rather than indignation). 



Clearly there are some cultural differences here.  I am not
a CS type.  I would not presume to criticize the
architecture, and in my world, questions are generally
assumed to be what they appear to be: questions.

Additionally, I confess to be completely ignorant of the
nuances you suggest between using the term "magic" and
saying something happened "magically".  I meant it only in
the sense that John has since used it: as suggesting
something not obvious (to me) was taking place.  I had no
intent to communicate indignation with this term and indeed
am startled that it could be so construed.  Is this nuance
really universal on this list?

Cheers,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

Alan asked:
- Why does a Variable need a master? 
- If s is a StringVar instance, why is 
  str(s) its name rather than its value?


On 3/29/2009 2:46 PM Scott David Daniels apparently wrote:
The answer to that, grasshopper, lies in the answer to the question, 
"What are StringVars designed to do?"  StringVars, and IntVars, and ... 
are elements to receive, hold, and propagate changes to values that 
will produce effects in the programs behavior or display.  I find 
IntVars easier to explain, since you get values for numbers lots of 
ways.  If a slider updates an IntVar, a signal must reach anything 
"interested" in the value of that IntVar.  For example, you have a 
rectangle, and a display of its height, width, area, and aspect ratio. 
If you change the height or the width, the area and aspect ratio need 
updating (as well as the value in the height or width).


In short, a Variable can have observers.  My question does
not lie here.  At least, you have not persuaded me that it does.


Rather than building systems where every control maintain 
lists of what to notify and how to communicate the value, 
things like IntVars and StringVars work as data store and 
signal propagation points.  One of the Vars is more Var 
than value: a place to go to look for the current value, 
and a place to register for notification when changes 
happen.  Clearly you cannot signal changes from a variable 
unless the whole event mechanism is running.



I take this to be the core of your argument: that a Variable
cannot signal to a widget until the event mechanism is up
and running.  But of course if you create e.g. a Frame, the
"root" is automagically created.  So I do not understand
your reasoning.

To elaborate, where could things go wrong if I could
instantiate a Variable without first instantiating a Tk root
object?  You note that the variable would have no work to do
in an event mechanism until that mechanism was created, but
then again, it could not (right?) have an relevant
association under the current architecture until a root was
instantiated.

For example, suppose I want to associate an ``Entry`` with
a ``StringVar``. If I have not already created a root,
I would have to create the ``Entry`` first (which
auotmagically creates the root) and then the ``StringVar``,
but what is the payoff from this restriction?


A StringVar needs to know where to send signals about its 
changes.  Thus two different StringVars containing the 
same text can behave quite differently, as each may be 
hooked into a different network of event propagation. 


Yes of course.  See above.
Just to be clear, I am not so presumptuous as to try to
challenge the design.  I am trying to understand it.

Here's what I think the answer might be (following a hint
from Francesco).  I think that this restriction serves no
direct function in Python, but is used manage communication
between Python and Tk/Tcl.  That is, the current design
simply ensures that *at creation* a Variable has a corresponding
Tcl variable and is named in a way that matches the order of
creation.  (Roughly.  In addition it looks like multiple Variable
instances can share a name and thus reference a single Tcl
variable.)  While this does not explain why a Variable,
unlike a Widget, will not create a root object on an as
needed basis, it does explain why the root object is
required for Variable creation.

Thanks,
Alan Isaac

PS If you were also offering an answer to the second question,
I missed it altogether, but although it is perhaps slightly
less obvious than with a StringVar, I would ask the same
basic question of an IntVar: why does it not behave more
like an int?  E.g., why is ``int(IntVar(value=5))`` an
error, or at least, why is ``str(IntVar(value=5))`` the name
of the IntVar instead of '5'?

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


RE: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread John Posner
Scott David Daniels said:

 >> You ask, "What exactly is the role of ...", rather than saying
 >> something like, "I don't understand the role of ...", and continue
 >> to ask why the code is not architected the way you first expected
 >> it to be architected, calling those things you do not understand
 >> "magic"  (not "magically" which would at least invoke a sense of
 >> wonder, rather than indignation).

I agree with Scott that Alan could use a little attitude adjustment. OTOH,
the following IDLE transcript does suggest that some "magic" is occurring:

 >>>  RESTART

 >>> from Tkinter import *
 >>> root = Tk()
 >>> ss = StringVar()
 >>>  RESTART

 >>> from Tkinter import *
 >>> ss = StringVar()

 Traceback (most recent call last):
  File "", line 1, in 
ss = StringVar()
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 251, in __init__
Variable.__init__(self, master, value, name)
  File "C:\Python26\lib\lib-tk\Tkinter.py", line 182, in __init__
self._tk = master.tk
 AttributeError: 'NoneType' object has no attribute 'tk'

Here's the "magic" in this situation, which is not exactly highlighted in
existing Tkinter documentation:

   If you do not specify a master object in the StringVar() statement, the
Tk object becomes
   the variable's master. If no Tk object exists, an error occurs.
   
   You can create a Tk object explicitly with the Tk() statement. A Tk
object is created
   implicitly when you create a widget -- for example, with Frame() or
Entry().

I *did* find this in the "Configuration Interface" section of 
Fredrik Lundh's "An Introduction to Tkinter"
(http://www.pythonware.com/media/data/an-introduction-to-tkinter.pdf):

  widgetclass(master, option=value, ...)   ->  widget

  Create an instance of this widget class, as a child to the given 
  master, and using the given options. All options have default 
  values, so in the simplest case, you only have to specify the 
  master. You can even leave that out if you really want; Tkinter 
  then uses the most recently created root window as master.

BTW, the last sentence appears to be false in Python 2.6.1 -- the *first*
root window is used as the master.





E-mail message checked by Spyware Doctor (6.0.0.386)
Database version: 5.12060
http://www.pctools.com/en/spyware-doctor-antivirus/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't get a simple TCP program to work

2009-03-29 Thread Irmen de Jong

Zach wrote:

The following *extremely* simple script complains that "Socket is not
connected" when I try to call recv. Could anyone provide some quick
guidance?

http://pastebin.com/m64317b32


replace node2.recv() by new_socket.recv() - you need to get data from the
client socket that you got from accept(), not from the server socket...

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


Re: New Python Runtime

2009-03-29 Thread Tim Roberts
Adonis  wrote:

>Came across this article on Ars on a new LLVM (Low Level Virtual 
>Machine) JIT compiler for Python being built by Google:
>
>http://arstechnica.com/open-source/news/2009/03/google-launches-project-to-boost-python-performance-by-5x.ars
>
>Now the question is will this make Vista run faster?

Is that a joke?

Or did you mean to say "...make Python run faster?"
-- 
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Introducing Python to others

2009-03-29 Thread BackSeat
On Mar 26, 10:35 am, "Paddy O'Loughlin" 
wrote:

> If I were to do a (very) short demonstration one web framework for the
> PHP devs, what should I use?

No question: use web2py. See the website and the videos that
demonstrate it. You could build a reasonably substantial application
in 2-3 minutes if you practice it first - for example, a wiki.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bullshit Generator

2009-03-29 Thread Dotan Cohen
> Hello,
>
> For those of you that
> - want to surf on the edge of Web technology without understanding it,
> - desire to be considered as a software guru,
> - are forced to write technical documents that nobody will read.
> - want to laugh a bit,
>
> I have written a "Bullshit Generator" script in Python (see below). It
> generates English sentences at random, talking about leading-edge Web-based
> technologies. For example it can produce simple sentences like
>
> "The interface subscriber manages the web-based online ontology."
>
> or more complex, like
>
> "Generally speaking, the architecture is collected by the client from the
> encapsulation related to the artifact that retrieves the data in the UDDI
> where the integration enabled by the issuer delivers a Portal technology
> responsible for an XML operation."
>
> The algorithm is based on a simplified English grammar, fed with hard-coded
> lists of (buzz)words. The sentence structure is selected by choosing
> randomly among a set of weighted rules, i.e. some rules are more likely to
> be used than others. The sentences are oriented to hype Web technologies but
> you can easily switch to your preferred domain, simply by changing the list
> of words.
>
> For Windows XP/Vista users: if you have installed the win32com package
> (delivered with PythonWin), you should hear the sentences pronounced by
> synthesized speech.
>

You should really post this on a blog somewhere. Instant slashdot!

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
--
http://mail.python.org/mailman/listinfo/python-list


Re: Understanding JSON

2009-03-29 Thread Chris Rebert
On Sun, Mar 29, 2009 at 1:39 PM, WallyDD  wrote:
> Hello,
>
> I am trying to geocode some map data using the google maps API.
>
> By using the urllib I can get the JSON output;
> http://maps.google.com/maps/geo?q=New+York+USA&output=json&oe=utf8&sensor=true&key=your_api_key
>
> I then read it using;
> gmapiresult = json.loads(fg.read())
> somedata = gmapiresult['Placemark']
>
> result is; (somedata)
> [{u'Point': {u'coordinates': [-73.9869515, 40.7560539,
> 0]}, u'ExtendedData': {u'LatLonBox': {u'west': -74.25909, u'east':
> -73.699793, u'north': 40.9174989, u'south':
> 40.4773833}}, u'AddressDetails': {u'Country': {u'CountryName':
> u'USA', u'AdministrativeArea': {u'AdministrativeAreaName': u'NY',
> u'Locality': {u'LocalityName': u'New York'}}, u'CountryNameCode':
> u'US'}, u'Accuracy': 4}, u'id': u'p1', u'address': u'New York, NY,
> USA'}]
>
>
> Can I further refine the data in "somedata" or am I reliant on string
> manipulation?
> all I need to get is the data in "coordinates".
>
> I am not sure if this is a json problem or if I don't understand lists
> well enough.

What you get back from the JSON is just some nested lists and
dictionaries containing the data, not a giant string (wouldn't be a
very useful serialization format then, now would it?).
If you pretty-print the data using pprint.pprint(), it becomes much
more readable (I hope linewrap did not get activated...):

[{u'AddressDetails': {u'Accuracy': 4,
  u'Country': {u'AdministrativeArea':
{u'AdministrativeAreaName': u'NY',

u'Locality': {u'LocalityName': u'New York'}},
   u'CountryName': u'USA',
   u'CountryNameCode': u'US'}},
  u'ExtendedData': {u'LatLonBox': {u'east': -73.699793,
   u'north': 40.9174989,
   u'south': 40.4773833,
   u'west': -74.25909}},
  u'Point': {u'coordinates': [-73.9869515, 40.7560539, 0]},
  u'address': u'New York, NY,USA',
  u'id': u'p1'}]

So to get the coordinates, you simply do:
coords = somedata[0]['Point']['coordinates']

which gets the first and only element in the toplevel list, and this
element is a dictionary,
and then gets the value associated with the key 'Point' in that
dictionary, which gives us another dictionary (that happens to have
only one key-value pair),
and finally gets the value associated with the key 'coordinates' in
that dictionary, which gives us the desired list of floats.

Cheers,
Chris
-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Understanding JSON

2009-03-29 Thread WallyDD
Hello,

I am trying to geocode some map data using the google maps API.

By using the urllib I can get the JSON output;
http://maps.google.com/maps/geo?q=New+York+USA&output=json&oe=utf8&sensor=true&key=your_api_key

I then read it using;
gmapiresult = json.loads(fg.read())
somedata = gmapiresult['Placemark']

result is; (somedata)
[{u'Point': {u'coordinates': [-73.9869515, 40.7560539,
0]}, u'ExtendedData': {u'LatLonBox': {u'west': -74.25909, u'east':
-73.699793, u'north': 40.9174989, u'south':
40.4773833}}, u'AddressDetails': {u'Country': {u'CountryName':
u'USA', u'AdministrativeArea': {u'AdministrativeAreaName': u'NY',
u'Locality': {u'LocalityName': u'New York'}}, u'CountryNameCode':
u'US'}, u'Accuracy': 4}, u'id': u'p1', u'address': u'New York, NY,
USA'}]


Can I further refine the data in "somedata" or am I reliant on string
manipulation?
all I need to get is the data in "coordinates".

I am not sure if this is a json problem or if I don't understand lists
well enough.

Thanks for any help.

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


Re: PyFits for Windows?

2009-03-29 Thread andrew cooke
W. eWatson wrote:
[...]
> Along these lines, there was an astronomy python site at the U of
> Washington
> not many months ago. The link is broken. Any idea where it went? I sent
> the
> astro dept a msg about it a few hours ago. NASA has one too, but it's not
> loading today. The govt. sites seem to have troubles on the weekend.

sorry, no idea (i used to work on iraf, but left a couple of years ago). 
andrew

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


if there is a return type of a method definition like java does

2009-03-29 Thread Coonay
if there is a return type of a method definition,that would lead to
faster decision to do with the method called,do you think so?
--
http://mail.python.org/mailman/listinfo/python-list


i have to change default tab length in pydev

2009-03-29 Thread Coonay
during last few days, i code python using notepad++ or pydev, the
compiler always complain there is a problem with Indentation,in my
eyes ,there is no Indentation problem at all,because i format the code
to make it comply with python style guide strictly,but after i change
the default tab length ,it works.

why is that?
--
http://mail.python.org/mailman/listinfo/python-list


Wing IDE Backup configuration settings?

2009-03-29 Thread John Doe

Anyone know how to back up the configuration settings like font sizes 
and colors in the Wing IDE? Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Cannot register to submit a bug report

2009-03-29 Thread John Posner
I've tried twice to register myself at bugs.python.org. But the confirmation
email message never arrives. (Yes, I checked my spam folder.) What do I do
now?






E-mail message checked by Spyware Doctor (6.0.0.386)
Database version: 5.12060
http://www.pctools.com/en/spyware-doctor-antivirus/
--
http://mail.python.org/mailman/listinfo/python-list


Re: meta question - how to read comp.lang.python w/o usenet feed/google interface?

2009-03-29 Thread skip
aahz> In article 
<03081704-17b5-4c7d-82db-8efb7ebce...@q11g2000yqh.googlegroups.com>,
aahz> Esmail   wrote:
>> 
>> I've been reading/posting to usenet since the 80s with a variety of
>> tools (vn, and most recently Thunderbird) but since my ISP
>> (TimeWarner) no longer provides usenet feeds I'm stuck.

aahz> You have options for paid usenet feeds.  Personally, I like my ISP
aahz> (panix.com), but you can also just get a plain feed from
aahz> e.g. Newsguy.

Sorry, I don't recall seeing the original message, so maybe this has already
been suggested, but is Gmane a possibility?  Also, you can always subscribe
to python-list@python.org and read it via email.

-- 
Skip Montanaro - s...@pobox.com - http://www.smontanaro.net/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bullshit Generator

2009-03-29 Thread Irmen de Jong

Pierre Denis wrote:


I have written a "Bullshit Generator" script in Python (see below). It
generates English sentences at random, talking about leading-edge Web-based
technologies. For example it can produce simple sentences like

"The interface subscriber manages the web-based online ontology."


Pretty cool piece of code, to get rid of those boring Lorum Ipsum generators!


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


Re: Bullshit Generator

2009-03-29 Thread Martin P. Hellwig

Tim Chase wrote:


Is it an upgrade from
  from urllib import urlopen
  bs = urlopen("http://xahlee.org";).read()


Yes it is. Although both produce random quantities of text, only the 
name can be interpreted offensive, not the content.


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


Re: Safe to call Py_Initialize() frequently?

2009-03-29 Thread Graham Dumpleton
On Mar 30, 4:35 am, a...@pythoncraft.com (Aahz) wrote:
> [p&e]
>
> In article 
> ,
> Graham Dumpleton   wrote:
>
>
>
>
>
> >In mod_wsgi however, Apache will completely unload the mod_wsgi module
> >on a restart. This would also mean that the Python library is also
> >unloaded from memory. When it reloads both, the global static
> >variables where information was left behind have been lost and nulled
> >out. Thus Python when initialised again, will recreate the data it
> >needs.
>
> >So, for case where Python library unloaded, looks like may well suffer
> >a memory leak regardless.
>
> >As to third party C extension modules, they aren't really an issue,
> >because all that is done in Apache parent process is Py_Initialize()
> >and Py_Finalize() and nothing else really. Just done to get
> >interpreter setup before forking child processes.
>
> >There is more detail on this analysis in that thread on mod_wsgi list
> >at:
>
> Missing reference?

It was in an earlier post. Yes I knew I forget to add it again, but
figured people would read the whole thread.

  http://groups.google.com/group/modwsgi/browse_frm/thread/65305cfc798c088c

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


CGIXMLRPCRequestHandler example

2009-03-29 Thread Phoe6
I have the following CGIXMLRPCRequestHandler usage example. I have
both the server and the client in the same directory.  I based this
following this example: 
http://mail.python.org/pipermail/python-list/2005-May/320696.html


Server Code: Foo.py

import os
import SimpleXMLRPCServer

class Foo:
def settings(self):
return os.environ
def echo(self, something):
return something

handler = SimpleXMLRPCServer.CGIXMLRPCRequestHandler()
handler.register_instance(Foo())
handler.handle_request()


And the Client which tries to Access it.

import xmlrpclib
server = xmlrpclib.ServerProxy('http://127.0.0.1/Foo.py')
print server
print dir(server)
sometext = 'Hello'
tup = tuple(sometext)
print tup
textcall = xmlrpclib.dumps(tup, ("server.echo"))
print textcall
print server.echo("Hello")


When I call the Client, the call fails at server.echo("Hello") and
says Connection Refused.

socket.error: [Errno 111] Connection refused

Should I do more? The handler is waiting for the requests, but do I
need to run a server or anything? Any pointers appreciated.

Thank you,
Senthil
--
http://mail.python.org/mailman/listinfo/python-list


speak or Speak ?, was Re: Bullshit Generator

2009-03-29 Thread Stef Mientki

quit nice !

But I had to replace "speak" by  "Speak"
   voice.Speak ( generatedSentence )

not a big issue,
but as I want to deploy programs with Sapi,
I'm interested if there are different speak engines around.

thanks
Stef Mientki

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


Re: Bullshit Generator

2009-03-29 Thread Tim Chase

For those of you that
- want to surf on the edge of Web technology without understanding it,
- desire to be considered as a software guru,
- are forced to write technical documents that nobody will read.
- want to laugh a bit,

I have written a "Bullshit Generator" script in Python (see below). It
generates English sentences at random, talking about leading-edge Web-based
technologies.


+1 for inclusion in stdlib :)


Is it an upgrade from

  from urllib import urlopen
  bs = urlopen("http://xahlee.org";).read()

?



-tkc





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


Re: numpy array sorting weirdness

2009-03-29 Thread Daniel Fetchinson
>> Is there any reason the 'axis' keyword argument doesn't default to the
>> value that corresponds to python list behaviour? That would make lot
>> of sense I think. Or retaining compatibility with python lists is not
>> really a goal of numpy.array?
>
> Not at all. It's an entirely different data structure.
>

Thanks a lot!

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: Bullshit Generator

2009-03-29 Thread Daniel Fetchinson
> Hello,
>
> For those of you that
> - want to surf on the edge of Web technology without understanding it,
> - desire to be considered as a software guru,
> - are forced to write technical documents that nobody will read.
> - want to laugh a bit,
>
> I have written a "Bullshit Generator" script in Python (see below). It
> generates English sentences at random, talking about leading-edge Web-based
> technologies.

+1 for inclusion in stdlib :)

Cheers,
Daniel


-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Scott David Daniels

Alan G Isaac wrote:

On 3/29/2009 3:43 AM Scott David Daniels apparently wrote:

OK, that was plain rude.  a couple of questions is not six questions.
A reply telling you how to get to some of what you are looking for
is assistance.  If you want exact answers to an array of questions,
pay someone to fetch you the answers, or do your own homework.

Clearly I am too grumpy this weekend.


Yes you are too grumpy.  It is *not* rude to point
out that the answers are not where I was pointed.
The available docs are much more focused on "how"
rather than on "why".


But, in your original post, here is the full beginning:
> I'm a complete newbie to GUI.
> I have a couple questions about tkinter.
>
> 1. Where is the list of changes
>in Python 3's tkinter?
>
> 2. What exactly is the role of the root object,
>traditionally created as ``root=tk.Tk()``?
>What is an example where one should create this
>before creating a Frame instance (which will
>otherwise implicitly create one as its master)?

The post contains seven numbered questions (two questions are
numbered 2), the first pair of which read like demands.  Nowhere
(except the "complete newbie" part) do you say, "I might be
misunderstanding something, but ", nor do you ask "how can
I find out, "  You assume there _is_ a "list of changes."
You ask, "What exactly is the role of ...", rather than saying
something like, "I don't understand the role of ...", and continue
to ask why the code is not architected the way you first expected
it to be architected, calling those things you do not understand
"magic"  (not "magically" which would at least invoke a sense of
wonder, rather than indignation).

Now I could have rooted around and found the answers to some of your
questions, but I fully expected that your reply would then have been,
"why wasn't that in the documentation," and I was feeling like asking
you to apply for a full refund on your purchase price of your Python.

It looked to me like you had no clue and wanted to learn things your
way.  If so, fine, don't ask others for help for free.  If not, it
is _your_ responsibility to discover how answers you got were meant
to help you.  You really should read:
http://www.catb.org/~esr/faqs/smart-questions.html


Please show me how to use that response to get
even one of the answers.  (Please skip #2, since I
fear a repetition of the kind of answer in all the docs,
which is half an answer.) Or, withdraw your claim.

Btw, I cannot find the answers in Grayson's book either.
It's a big book though, and covers much ground, so I
do not deny the answers might well be in there somewhere.


Mike Driscoll said, among other things, "There is tons of info on the
Python wiki:   http://wiki.python.org/moin/TkInter"; and pointed you
specifically at "Lutz's 'Programming Python'".  As far as I can tell,
Grayson is not Lutz's former name :-).  People learn in very different
ways.  Some people take Grayson's book and are off and running.  Lutz
takes a different approach, the Python wiki takes another approach.
Your questions reveal no particular understanding (nor effort), so the
best replies are not to address the individual questions, but to address
how you might get a global understanding.  That is how Mike Driscoll's
answer could have helped you.

Remember Python 3.X is a rebuilt Python, so lists of changes would be 
useless -- you'd be swamped in detail.


Unfortunately, every GUI system I've seen is swamped in detail, there
are a few core things to understand, but a lot of detail gets addressed
piece by piece.  There is no accepted "theory of operation" to learn in
one or two "aha" moments.  SO, the people who learn by copy-and-tweak
are much happier working in GUI than the "from first principles" people.


Let's try just these two:

Actually a couple? Imagine that.

- Why does a Variable need a master?
- If s is a StringVar instance, why is
  str(s) its name rather than its value?


The answer to that, grasshopper, lies in the answer to the question,
"What are StringVars designed to do?"  StringVars, and IntVars, and ...
are elements to receive, hold, and propagate changes to values that
will produce effects in the programs behavior or display.  I find
IntVars easier to explain, since you get values for numbers lots of
ways.  If a slider updates an IntVar, a signal must reach anything
"interested" in the value of that IntVar.  For example, you have a
rectangle, and a display of its height, width, area, and aspect ratio.
If you change the height or the width, the area and aspect ratio need
updating (as well as the value in the height or width).  Rather than
building systems where every control maintain lists of what to notify
and how to communicate the value, things like IntVars and StringVars
work as data store and signal propagation points.  One of the Vars is
more Var than value: a place to go to look for the current value, and
a place to register for notification when changes happen.  Clearly
you 

Re: Ordered Sets

2009-03-29 Thread CTO
On Mar 28, 3:33 am, "Gabriel Genellina" 
wrote:
> En Thu, 26 Mar 2009 12:20:17 -0300, Scott David Daniels  
>  escribió:
>
> > (2) Why, oh why, do people feel so comforted adding double_underscores
> >      to data structures?

Probably because other authors feel too comfortable using single
underscores for
things the end user should mess with, as in namedtuple.
--
http://mail.python.org/mailman/listinfo/python-list


How to access object created in Main?

2009-03-29 Thread Muddy Coder
Hi Folks,

I need to update the text field of a Label created in Main, but can't
find a way to do it. Please take a look at my code:

from Tkinter import *

def makemenu(r)
   amenu = Menu(r)
   amenu.add_command(., command=update_label)

def update_label():
how to access mesg created in __main__ ?

if __name__ == '__main__':
root = Tk()
mesg = Label(root, text='foo\nbar\nfoo')
mesg.pack(expand=YES, fill=BOTH)
root.mainloop()

What I need to do is simple: when Menu (amenu) is clicked, it should
execute update_label function that is expected to update the text of
Label mesg in MAIN, with a syntax like: mesg.config(text='new text')
What I don't know is the path of accessing this object mesg. I tried
root.mesg, no good. I am confused here: since mesg is created on root
as its master, why root.mesg is not its path? Can somebody help me
out? Thanks a lot!

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


Re: Read Garmin XML (TCX) files in Python...

2009-03-29 Thread Diez B. Roggisch

cmalmqui schrieb:

Dear All,
Garmin uses XML as an exchange format for their Forerunner GPS series
(http://developer.garmin.com/schemas/tcx/v2/) and I have been thinking
about creating a python script that parses the Garmin XML file and
dumps the training information to a KML file as well as various graphs
(png or maybe SVG).

I am however struggling when I try to access the XML file in python. I
normally use python to create rather simple "top down" scripts (from a
Matlab background) and I have not been able to find a tutorial giving
me a gentle introduction to XML parsing with python. Right now I am
doubting whether XML + Python is achievable for a python novice.

I would thus be grateful if somebody could point me in the right
direction, either with some code suggestions or linking to some good
tutorials on the web, before I drop this idea and move on :-)


http://effbot.org/zone/element-index.htm

Elementtree is since python2.5 part of the standard lib. You can simply 
translate the examples adjusting the imports.


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


Bullshit Generator

2009-03-29 Thread Pierre Denis
Hello,

For those of you that
- want to surf on the edge of Web technology without understanding it,
- desire to be considered as a software guru,
- are forced to write technical documents that nobody will read.
- want to laugh a bit,

I have written a "Bullshit Generator" script in Python (see below). It
generates English sentences at random, talking about leading-edge Web-based
technologies. For example it can produce simple sentences like

"The interface subscriber manages the web-based online ontology."

or more complex, like

"Generally speaking, the architecture is collected by the client from the
encapsulation related to the artifact that retrieves the data in the UDDI
where the integration enabled by the issuer delivers a Portal technology
responsible for an XML operation."

The algorithm is based on a simplified English grammar, fed with hard-coded
lists of (buzz)words. The sentence structure is selected by choosing
randomly among a set of weighted rules, i.e. some rules are more likely to
be used than others. The sentences are oriented to hype Web technologies but
you can easily switch to your preferred domain, simply by changing the list
of words.

For Windows XP/Vista users: if you have installed the win32com package
(delivered with PythonWin), you should hear the sentences pronounced by
synthesized speech.

Have fun,

Pierre Denis

Instruction: simply copy the following lines in a bullshit_generator.py file
and executes the script (requires Python 2.3 at least). Press enter to get
more sentences and 'q' + enter to exit.

'''
==
 Bullshit Generator 
by Pierre Denis, March 2009
==
'''

# --
# grammar engine
# --

from random import choice, random
from bisect import bisect

class Node(object):

def setTermsChoices(self,*termsChoices):
self.termsChoices = []
weights = []
for weight, termChoice in termsChoices:
self.termsChoices.append(termChoice)
weights.append(weight)
totalWeight = sum(weights)
self.thresholds = []
threshold = 0.0
for weight in weights[:-1]:
threshold += weight
self.thresholds.append(threshold/totalWeight)

def getWords(self):
terms = self.termsChoices[bisect(self.thresholds,random())]
for term in terms:
if isinstance(term,str):
yield term
else:
for word in term.getWords():
yield word

def getString(self):
# note : starting from Python 2.4, the two following statements
# may be changed to use generator expressions,
# i.e. remove list(...) and brackets []
res = " ".join(list(self.getWords()))
res = ", ".join([w.strip() for w in res.split(",") if w.strip()])
if res.endswith(", "):
res = res[:-2]
return res[0].upper() + res[1:] + "."


class TerminalNode(object):

def __init__(self,*words):
self.words = words

def getWords(self):
yield choice(self.words)

# --
# grammar
# --

verb = TerminalNode(
"accesses", "activates", "administrates", "aggregates", "builds",
"calculates", "checks", "competes with", "completes", "complies with",
"controls", "covers", "delivers", "dispatches", "eases", "encapsulates",
"encompasses", "executes", "extracts", "features",
"generates", "gets", "governs", "guides", "has", "increases",
"inherits from", "is", "keeps track of", "leverages", "makes",
"manages",
"manages", "maximizes", "mitigates", "monitors", "must have", "needs",
"offers", "opens", "operates on", "optimizes", "orchestrates",
"overwrites", "performs", "populates", "precludes", "provides",
"provides",
"provides an interface to", "reads", "receives", "reduces",
"reduces the need of", "registers", "regulates", "relies on",
"requires",
"resides on", "resides within", "retrieves", "retrieves the data in",
"runs on",
"schedules", "integrates with", "sends", "shall be",
"shall have", "should be", "should have", "starts", "stores",
"streamlines", "subscribes to", "subscribes to", "supersedes", "takes",
"targets", "triggers", "updates", "validates", "writes")

passiveVerb = TerminalNode(
"accessed by", "achieved by", "aggregated by", "applicable for",
"asserted by", "authorized by",
"based upon", "built from", "built upon", "collected by",
"controlled by",
"dedicated to", "deployed on", "derived from", "dispatched by",
"driven by", "eased by", "enabled by", "envisioned in",
"extracted from", "generated by", "in the scope of", "installed on",
"integrated i

Re: PyFits for Windows?

2009-03-29 Thread drobi...@gmail.com
On Mar 29, 9:39 am, "W. eWatson"  wrote:
> John Yeung wrote:
> > On Mar 28, 4:03 pm, Michiel Overtoom  wrote:
> >> W. eWatson wrote:
> >>> It looks like PyFits downloads are for Linux.
> >>> Isn't there anything available for Win (xp)?
> >> To install it, unpack the tar file and
> >> type: python setup.py install"
>
> >> It looks like PyFits is platform-independent.
>
> > Perhaps the original poster is referring to the tar file, which isn't
> > natively supported by Windows and possibly isn't understood by WinZip
> > either (not sure about that one).  I recommend downloading and
> > installing 7-Zip, which is free and handles more formats.  It will let
> > you extract the contents, which you can then install normally with the
> > setup script as shown above.
>
> > John
>
> Yes, I keep getting to a tar file with Google and just going to the STSci
> site. I use IZarc. Maybe it handles tar files. I'll give it a try.
>
> --
>                                 W. eWatson
>
>               (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
>                Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
>
>                      Web Page: 

A windows tar can be found at:
 http://gnuwin32.sourceforge.net/packages/gtar.htm

(personally, I use cygwin)
--
http://mail.python.org/mailman/listinfo/python-list


Read Garmin XML (TCX) files in Python...

2009-03-29 Thread cmalmqui
Dear All,
Garmin uses XML as an exchange format for their Forerunner GPS series
(http://developer.garmin.com/schemas/tcx/v2/) and I have been thinking
about creating a python script that parses the Garmin XML file and
dumps the training information to a KML file as well as various graphs
(png or maybe SVG).

I am however struggling when I try to access the XML file in python. I
normally use python to create rather simple "top down" scripts (from a
Matlab background) and I have not been able to find a tutorial giving
me a gentle introduction to XML parsing with python. Right now I am
doubting whether XML + Python is achievable for a python novice.

I would thus be grateful if somebody could point me in the right
direction, either with some code suggestions or linking to some good
tutorials on the web, before I drop this idea and move on :-)

Cheers,
Christian
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyFits for Windows?

2009-03-29 Thread W. eWatson

andrew cooke wrote:

W. eWatson wrote:

I downloaded the tar file, and untarred it with IZarc. That's a strange
way
to package it, that is, for Windows. This almost suggests not many Win
users
are using it.

One of the pages, ,
has a lot of tutorial material. It almost looks like overload on the
subject. I'm hoping the use of this library will be relative simple for my
purposes, which are basically to write an image to a fits file with a
somewhat simple header, which might include lat/long, date, image size,
date-time, and a comment.


i have no idea what the current status is, but there used to be a python
implementation of the iraf astronomy image processing system (iraf) called
pyraf.  if was developed by stsci, if i remember correctly.  you might
find that useful.  it will certainly support manipulating fits files etc,
but may be a bit "heavweight" for your needs.

andrew


Along these lines, there was an astronomy python site at the U of Washington 
not many months ago. The link is broken. Any idea where it went? I sent the 
astro dept a msg about it a few hours ago. NASA has one too, but it's not 
loading today. The govt. sites seem to have troubles on the weekend.


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: Safe to call Py_Initialize() frequently?

2009-03-29 Thread Aahz
[p&e]

In article ,
Graham Dumpleton   wrote:
>
>In mod_wsgi however, Apache will completely unload the mod_wsgi module
>on a restart. This would also mean that the Python library is also
>unloaded from memory. When it reloads both, the global static
>variables where information was left behind have been lost and nulled
>out. Thus Python when initialised again, will recreate the data it
>needs.
>
>So, for case where Python library unloaded, looks like may well suffer
>a memory leak regardless.
>
>As to third party C extension modules, they aren't really an issue,
>because all that is done in Apache parent process is Py_Initialize()
>and Py_Finalize() and nothing else really. Just done to get
>interpreter setup before forking child processes.
>
>There is more detail on this analysis in that thread on mod_wsgi list
>at:

Missing reference?
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."  --Brian W. Kernighan
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyFits for Windows?

2009-03-29 Thread Scott David Daniels

W. eWatson wrote:

Michiel Overtoom wrote:

W. eWatson wrote:

It looks like PyFits downloads are for Linux. Isn't there anything 
available for Win (xp)?


According to http://www.stsci.edu/resources/software_hardware/pyfits:

...
That link gives me a Resource Not Found!, but does have info about 
STSci. I think this gets me back to their page with a tar file. I see 
tar comes up below, so I'll appear down there.

Probably the link should not have ended with a colon.  It looks to me
like the colon was used to introduce the text below the link, improving
the sentence as English, while reducing its utility as a clickie.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Geometry package

2009-03-29 Thread Max Erickson
Justin Pearson  wrote:

> Hi all,
> 
> I'm looking for a geometry package in Python; something that will
> let me define line segments, and can tell me if two line segments
> intersect. It would be nice if the lines could be defined in
> n-space (rather than be confined to 2 or 3 dimensions), but this
> is not a hard constraint. Other functionality might include
> support for polygons, convex hulls, etc.
> 
> I've searched Pypi and found a package called Shapely, but when I
> followed its installation instructions, it threw a bunch of
> errors and tried to re-install Python :(.
> 
> Is there a well-known geometry package I'm missing?
> 
> Thanks for your help,
> Justin
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

I don't know if it is well known, but you could take a look at 
Euclid:

http://partiallydisassembled.net/euclid.html

The geometry support is pretty basic.


max

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


Re: Help with dict and iter

2009-03-29 Thread mattia
Il Sun, 29 Mar 2009 12:00:38 -0400, andrew cooke ha scritto:

> mattia wrote:
>>[i wrote]:
>>> don't you just want to have a new job machine?
>>>
>>> for job_list in job_list_list:
>>>   job_machine = dict((x+1, iter(JOBS[x])) for x in range(NJOBS)) for x
>>>   in job_list:
>>> print(next(job_machine[x]))
> 
> ok - btw you can probably simplify the code.
> 
> this might work:
> 
> job_machine = list(map(iter, JOBS))
> 
> andrew
> 
> [...]
>> Well, you are right, just creating every time a new dict is a good
>> solution, I was just adding complexity to a simple problem, thanks.

Yes, it works perfectly, the only change is next(job_machine[x-1]). 
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ordered Sets

2009-03-29 Thread Aahz
In article <01d457aa$0$17208$c3e8...@news.astraweb.com>,
Steven D'Aprano   wrote:
>On Fri, 20 Mar 2009 11:50:28 -0700, Scott David Daniels wrote:
>> Raymond Hettinger wrote:
>>> [Aahz]

 The doubly-linked list part is what's sick and perverted.
>>> 
>>> The doubly-linked list part is what gives it big-oh running times the
>>> same as regular sets.  If the underlying sequence is stored as a list,
>>> then deletion goes from O(1) to O(n). If the insertion times are
>>> recorded in a dictionary, then the insertion order has to be sorted
>>> prior to iteration which makes iteration go from O(n) to O(n log n).
>> 
>> The double-linked list part could be done with weakrefs and perhaps Aahz
>> would relax a bit.
>
>I'm not sure whether Aahz's description is meant to be taken seriously, 
>or if there is a smiley hidden in his post. After all, doubly-linked 
>lists are a standard building block in data structure design.

It's a half-smiley.  I find the trick of using a Python list to store the
doubly-linked list difficult to understand (as opposed to the usual
mechanism of a node class).  I understand why it was done (time and space
efficiency), but I also still feel emotionally that it's somewhat sick
and perverted.  I probably would feel more comfortable if the
doubly-linked list were abstracted out and commented.  Heck, the whole
thing needs unit tests.

I needed to look up the code again, so I might as well repeat the URL to
make it handy for everyone else:

http://code.activestate.com/recipes/576694/
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it."  --Brian W. Kernighan
--
http://mail.python.org/mailman/listinfo/python-list


Re: meta question - how to read comp.lang.python w/o usenet feed/google interface?

2009-03-29 Thread Aahz
In article <03081704-17b5-4c7d-82db-8efb7ebce...@q11g2000yqh.googlegroups.com>,
Esmail   wrote:
>
>I've been reading/posting to usenet since the 80s with a variety of
>tools (vn, and most recently Thunderbird) but since my ISP
>(TimeWarner) no longer provides usenet feeds I'm stuck.

You have options for paid usenet feeds.  Personally, I like my ISP
(panix.com), but you can also just get a plain feed from e.g. Newsguy.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

"At Resolver we've found it useful to short-circuit any doubt and just
refer to comments in code as 'lies'. :-)"
--Michael Foord paraphrases Christian Muirhead on python-dev, 2009-3-22
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help with dict and iter

2009-03-29 Thread andrew cooke
mattia wrote:
>[i wrote]:
>> don't you just want to have a new job machine?
>>
>> for job_list in job_list_list:
>>   job_machine = dict((x+1, iter(JOBS[x])) for x in range(NJOBS)) for x
>>   in job_list:
>> print(next(job_machine[x]))

ok - btw you can probably simplify the code.

this might work:

job_machine = list(map(iter, JOBS))

andrew

[...]
> Well, you are right, just creating every time a new dict is a good
> solution, I was just adding complexity to a simple problem, thanks.


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


Re: Help with dict and iter

2009-03-29 Thread mattia
Il Sun, 29 Mar 2009 11:17:50 -0400, andrew cooke ha scritto:

> mattia wrote:
>> Hi all, I a list of jobs and each job has to be processed in a
>> particular order by a list of machines.
>> A simple representation is:
>> # Ordering of machines
>> JOB1 = [3, 1, 2, 4]
>> JOB2 = [2, 3, 1, 4]
>> JOBS = [JOB1, JOB2]
>> NJOBS = len(JOBS)
>> Now, I have a list of jobs and I want to have the associated list of
>> machines, e.g:
>> [JOB1, JOB1, JOB2] --> [3, 1, 2]
>> My original idea was to have a dict with associated the job number and
>> an iterator associated by the list of machines: job_machine =
>> dict((x+1, iter(JOBS[x])) for x in range(NJOBS)) Now, something like:
>> for x in job_list:
>> print(next(job_machine[x]))
>> Works good, but imagine I have a list of job_list, now obviously I have
>> a StopIteration exception after the
>> first list. So, I'm looking for a way to "reset" the next() value every
>> time i complete the scan of a list.
> 
> don't you just want to have a new job machine?
> 
> for job_list in job_list_list:
>   job_machine = dict((x+1, iter(JOBS[x])) for x in range(NJOBS)) for x
>   in job_list:
> print(next(job_machine[x]))
> 
> you can certainly write a generator that resets itself - i've done it by
> adding a special reset exception and then using generator.throw(Reset())
> - but it's a lot more complicated and i don't think you need it.  if you
> do, you need to look at writing generators explicitly using yield, and
> then at "enhanced generators" for using throw().
> 
> andrew

Well, you are right, just creating every time a new dict is a good 
solution, I was just adding complexity to a simple problem, thanks. 
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

On 3/29/2009 7:29 AM Francesco Bochicchio apparently wrote:
1. Tkinter is only a thin wrapper over Tk, a GUI library initially 
developed for Tcl language, so many of the answer to the design choices 
you question (e.g. what is the master) cannot between answered within 
the python documentation but should be searched in the Tcl/Tk 
documentation. So google for tcl/tk. 
Anyway, all GUI libraries I know of build the GUI as a hierarchical 
structure. The master (often called root) ia the root of this 
hierarchy, and you have to build it before building the rest. 


I understand this.  But I do not understand what we get
by having each Variable instance register a master.
(In contrast, e.g., to a container widget, such as a Frame,
where I do not have this question.)


2. Another good source of information is the source of Tkinter itself, 
which is mostly in the Tkinter.py file. 


In Python 3, I'm finding most of the useful stuff to be in
``tkinter/__init__.py``.  It is indeed useful, but not
always transparent.  At least to a new user.


if you for instance look at the __init__ method of the 
Variable class (which is the basic class of StringVar), 
you will easily find the 'magic' to which you refer to.  


What we find is that Variable is initialized with:
if not master:
master = _default_root
which in turn is initialized to None.  I understand this.
Actually, talking this through, I get it now.  I was not
properly thinking about the use of module level globals.
Thanks.


If you don't like the choices which have been made there 
(e.g not automagically creatinga a master for variables 
but doing it for frames ), you could try and submit 
a  patch :-)


I am not so presumptuous.  I just want to understand why a
Variable needs a master.  How is this used?

And, I would like to understand if there is a *reason* that
a StringVar instance, for example, does not behave more like
a string.


3. Usually the changes between one version of python and the next are 
documented (but not in all gory details) in "What is new" documents you 
can find  in python.org site. I'm not aware of any change 
for Tkinter, in Python 3.0 but go read it yourself.


I did look there, and explicitly got only that the new name
is ``tkinter``.   However, there are other changes, e.g. the
names and location of ``colorchooser`` and ``filedialog``.
I realize now that the statement "related modules have been
grouped into packages, and usually the submodule names have
been simplified" is supposed to capture all this, but an
explicit list would have been helpful to me.  (And,
I assume, to others.)  I also just assumed that some active
user had made a list of changes, which I had overlooked, but
that someone on this list would be aware of.

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


Re: Help with dict and iter

2009-03-29 Thread andrew cooke
mattia wrote:
> Hi all, I a list of jobs and each job has to be processed in a particular
> order by a list of machines.
> A simple representation is:
> # Ordering of machines
> JOB1 = [3, 1, 2, 4]
> JOB2 = [2, 3, 1, 4]
> JOBS = [JOB1, JOB2]
> NJOBS = len(JOBS)
> Now, I have a list of jobs and I want to have the associated list of
> machines, e.g:
> [JOB1, JOB1, JOB2] --> [3, 1, 2]
> My original idea was to have a dict with associated the job number and an
> iterator associated by the list of machines:
> job_machine = dict((x+1, iter(JOBS[x])) for x in range(NJOBS))
> Now, something like:
> for x in job_list:
> print(next(job_machine[x]))
> Works good, but imagine I have a list of job_list, now obviously I have a
> StopIteration exception after the
> first list. So, I'm looking for a way to "reset" the next() value every
> time i complete the scan of a list.

don't you just want to have a new job machine?

for job_list in job_list_list:
  job_machine = dict((x+1, iter(JOBS[x])) for x in range(NJOBS))
  for x in job_list:
print(next(job_machine[x]))

you can certainly write a generator that resets itself - i've done it by
adding a special reset exception and then using generator.throw(Reset()) -
but it's a lot more complicated and i don't think you need it.  if you do,
you need to look at writing generators explicitly using yield, and then at
"enhanced generators" for using throw().

andrew

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


Re: Python AppStore / Marketplace

2009-03-29 Thread Paul Boddie
On 27 Mar, 06:54, David Lyon  wrote:
>
> Just a GUI for package management that lets you seperate what is available
> for the python platform that you are running on. Install, deinstall, and
> get package information.
>
> https://sourceforge.net/projects/pythonpkgmgr/
>
> We only have source at the moment. Only for windows... and only for
> python 2.5. Pretty limited... but we'll get there.

See this page for details of a similar (cross-platform) tool for
browsing the Package Index:

http://www.boddie.org.uk/david/Projects/Python/PyPI-Browser/index.html

For a more ambitious project, take a look at the Smart Package
Manager:

http://labix.org/smart

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


Re: Cross platform installer builder for Python? (like IzPack for Java)

2009-03-29 Thread W. Martin Borgert
Hola Gabriel:

On 2009-03-25 19:19, Gabriel Genellina wrote:
> To distribute complete applications, py2exe + InnoSetup (Windows).

That's the point: IzPack (Java) creates installers, that work at
least on Windows and Linux, create menu entries in Windows and
Gnome/KDE etc. Only one .jar file to distribute for all
platforms. Maybe this is just missing in the Python universe?

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


Help with dict and iter

2009-03-29 Thread mattia
Hi all, I a list of jobs and each job has to be processed in a particular 
order by a list of machines.
A simple representation is:
# Ordering of machines
JOB1 = [3, 1, 2, 4]
JOB2 = [2, 3, 1, 4]
JOBS = [JOB1, JOB2]
NJOBS = len(JOBS)
Now, I have a list of jobs and I want to have the associated list of 
machines, e.g:
[JOB1, JOB1, JOB2] --> [3, 1, 2]
My original idea was to have a dict with associated the job number and an 
iterator associated by the list of machines:
job_machine = dict((x+1, iter(JOBS[x])) for x in range(NJOBS))
Now, something like:
for x in job_list:
print(next(job_machine[x]))
Works good, but imagine I have a list of job_list, now obviously I have a 
StopIteration exception after the
first list. So, I'm looking for a way to "reset" the next() value every 
time i complete the scan of a list.
Is it possible? Another solution can be:
empty = dict((x+1, (0, JOBS[x])) for x in range(NJOBS))
job_machine = dict((x+1, (0, JOBS[x])) for x in range(NJOBS))
and then every time do:
for job_list in p:
for x in job_list:
print(job_machine[x][1][job_machine[x][0]])
job_machine.update({x:(job_machine[x][0]+1, JOBS[x-1])})
job_machine = empty.copy()
Can you suggest me a more python way? 

Ciao,
Mattia
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter questions: behavior of StringVar, etc

2009-03-29 Thread Alan G Isaac

On 3/29/2009 3:43 AM Scott David Daniels apparently wrote:

OK, that was plain rude.  a couple of questions is not six questions.
A reply telling you how to get to some of what you are looking for
is assistance.  If you want exact answers to an array of questions,
pay someone to fetch you the answers, or do your own homework.

Clearly I am too grumpy this weekend.



Yes you are too grumpy.  It is *not* rude to point
out that the answers are not where I was pointed.
The available docs are much more focused on "how"
rather than on "why".

Please show me how to use that response to get
even one of the answers.  (Please skip #2, since I
fear a repetition of the kind of answer in all the docs,
which is half an answer.) Or, withdraw your claim.

Btw, I cannot find the answers in Grayson's book either.
It's a big book though, and covers much ground, so I
do not deny the answers might well be in there somewhere.

Let's try just these two:
- Why does a Variable need a master?
- If s is a StringVar instance, why is
  str(s) its name rather than its value?

Thank you,
Alan Isaac
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyFits for Windows?

2009-03-29 Thread andrew cooke
W. eWatson wrote:
> I downloaded the tar file, and untarred it with IZarc. That's a strange
> way
> to package it, that is, for Windows. This almost suggests not many Win
> users
> are using it.
>
> One of the pages, ,
> has a lot of tutorial material. It almost looks like overload on the
> subject. I'm hoping the use of this library will be relative simple for my
> purposes, which are basically to write an image to a fits file with a
> somewhat simple header, which might include lat/long, date, image size,
> date-time, and a comment.

i have no idea what the current status is, but there used to be a python
implementation of the iraf astronomy image processing system (iraf) called
pyraf.  if was developed by stsci, if i remember correctly.  you might
find that useful.  it will certainly support manipulating fits files etc,
but may be a bit "heavweight" for your needs.

andrew


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


Re: Calendar module: HTMLCalendar overrides style sheet settings

2009-03-29 Thread Sibylle Koczian
Sibylle Koczian schrieb:
> Hello,
> 
> So I looked into the calendar module and made a LocalHTMLCalendar
> subclass. Putting in additional style classes for "my" dates wasn't
> difficult, but there is one thing I don't like at all: the methods
> formatmonth() and formatyear() both return tables with explicit and ugly
> formatting:
> 
> 
> 

I was quite wrong: this doesn't overwrite formatting by a style sheet.
Should have studied them a bit more first - sorry for the noise!

Regards
Sibylle

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


Re: PyFits for Windows?

2009-03-29 Thread W. eWatson

W. eWatson wrote:

Michiel Overtoom wrote:

W. eWatson wrote:

It looks like PyFits downloads are for Linux. Isn't there anything 
available for Win (xp)?


According to http://www.stsci.edu/resources/software_hardware/pyfits:

"PyFITS’s source code is pure Python. It requires Python version 2.3 
or newer. PyFITS also requires the numarray module. PyFITS uses 
python’s distutils for its installation. To install it, unpack the tar 
file and type: python setup.py install"


It looks like PyFits is platform-independent.

Greetings,

That link gives me a Resource Not Found!, but does have info about 
STSci. I think this gets me back to their page with a tar file. I see 
tar comes up below, so I'll appear down there.


I downloaded the tar file, and untarred it with IZarc. That's a strange way 
to package it, that is, for Windows. This almost suggests not many Win users 
are using it.


One of the pages, , 
has a lot of tutorial material. It almost looks like overload on the 
subject. I'm hoping the use of this library will be relative simple for my 
purposes, which are basically to write an image to a fits file with a 
somewhat simple header, which might include lat/long, date, image size, 
date-time, and a comment.


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


  1   2   >