Re: download x bytes at a time over network

2009-03-16 Thread Saurabh
> This isn't exactly how things work.  The server *sends* you bytes.  It can
> send you a lot at once.  To some extent you can control how much it sends
> before it waits for you to catch up, but you don't have anywhere near
> byte-level control (you might have something like 32kb or 64kb level
> control).

What abt in Python3 ?
It seems to have some header like the one below : b'b495 - binary mode
with 46229 bytes ? Or is it something else ?

>>> import urllib.request
>>> url = "http://feeds2.feedburner.com/jquery/";
>>> handler = urllib.request.urlopen(url)
>>> data = handler.read(1000)
>>> print("""Content :\n%s \n%s \n%s""" % ('=' * 100, data, '=' * 100))
Content :

b'b495\r\n\r\nhttp://feeds2.feedburner.com/~d/styles/itemcontent.css";?>http://purl.org/rss/1.0/modules/content/";
xmlns:wfw="http://wellformedweb.org/CommentAPI/";
xmlns:dc="http://purl.org/dc/elements/1.1/";
version="2.0">\r\n\r\n\r\n\tjQuery
Blog\r\n\thttp://blog.jquery.com\r\n\tNew
Wave Javascript.\r\n\tFri, 13 Mar 2009 13:07:07
+\r\n\thttp://wordpress.org/?v=2.0.11\r\n\ten\r\n\t\t\thttp://www.w3.org/2005/Atom"; rel="self"
href="http://feeds2.feedburner.com/jquery"; type="application/rss+xml"
/>\r\n\t\tThis Week in jQuery, vol.
1\r\n\t\thttp://blog.jquery.com/2009/03/13/this-week-in-jquery-vol-1/\r\n\t\thttp:'

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


OMPC- m-script to python script convertor

2009-03-16 Thread gopal mishra
Hi,

 

I am trying to convert Matlab script to python script using OMPC.(
http://ompc.juricap.com/ )

 

My matlab code is (.m file)

Npts=100;

R=0.5;

X=[0:1/Npts:1]';

Y=[0:0.01:1]';

for i=1:Npts+1

  if(X(i) <= .5)

  Ytop(i)=1.0;

  Ybot(i)=0.0;

  else

  Z=sqrt(R^2-(X(i)-R)^2)-R;

  Ytop(i)=2*R+Z;

  Ybot(i)=-Z;

  end 

end

 

OMPC convert it to (.pym) file

from ompc import *

 

Npts = 100

R = 0.5

X = mcat([mslice[0:1 / Npts:1]]).cT

Y = mcat([mslice[0:0.01:1]]).cT

for i in mslice[1:Npts + 1]:

if (X(i) <= .5):

Ytop(i).lvalue = 1.0

Ybot(i).lvalue = 0.0

else:

Z = sqrt(R ** 2 - (X(i) - R) ** 2) - R

Ytop(i).lvalue = 2 * R + Z

Ybot(i).lvalue = -Z

end

end

 

while executing pym file it gives memory error at line no  5 i.e.(X =
mcat([mslice[0:1 / Npts:1]]).cT)

 

I also tryied out in IDE, it gives error on,

>>> mslice[0:1 / Npts:1]

Traceback (most recent call last):

  File "", line 1, in 

  File "C:\Python25\lib\site-packages\ompc\ompclib\ompclib_numpy.py", line
1056, in __getitem__

s.init_data()

  File "C:\Python25\lib\site-packages\ompc\ompclib\ompclib_numpy.py", line
910, in init_data

self._a = np.array(list(self), dtype='f8').reshape(self.msize[::-1])

MemoryError

 

Is there any updated OMPC version, which has solved this issue.

How this can be solved. 

 

Thanks,

Gopal

 

 

 

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


Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-16 Thread Rhodri James
On Tue, 17 Mar 2009 02:41:23 -, MRAB   
wrote:



Rhodri James wrote:
On Tue, 17 Mar 2009 01:47:32 -, MRAB   
wrote:



I'm not against putting a comma in the format to indicate that grouping
should be used just as a dot indicates that a decimal point should be
used. The locale would say what characters would be used for them.

I would prefer the format to have a fixed default so that if you don't
specify the locale the result is predictable.

 Shouldn't that be the global locale?


Other parts of the language, such as str.upper, aren't locale-sensitive,
so I think that format shouldn't be either. If you want it to be
locale-sensitive, then specify the locale, even if it's the system
locale.


Yes, but the format type 'n' is currently defined as taking its cues
from the global locale, so in that sense format already is
locale-sensitive.

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


Re: having a function called after the constructor/__init__ is done

2009-03-16 Thread Michael Spencer

thomas.han...@gmail.com wrote:
...


So any ideas on how to get a function called on an object just after
__init__ is done executing?
--
http://mail.python.org/mailman/listinfo/python-list



Yes, you *can* use metaclasses - you need to override the type.__call__ method, 
which is what normally calls __new__ then __init__:


 >>> class MetaOnLoad(type):
 ... def __call__(cls, *args, **kw):
 ... obj=type.__call__(cls, *args, **kw)
 ... obj.on_load()
 ... return obj
 ...
 >>> class A(object):
 ... __metaclass__ = MetaOnLoad
 ... def __init__(self):
 ... print "__init__ A"
 ... def on_load(self):
 ... print "on_load"
 ...
 >>> class B(A):
 ... def __init__(self):
 ... super(B,self).__init__()
 ... print "__init__ B"
 ...
 >>> b=B()
 __init__ A
 __init__ B
 on_load
 >>> class C(B):
 ... def __init__(self):
 ... super(C,self).__init__()
 ... print "__init__ C"
 ...
 >>> c=C()
 __init__ A
 __init__ B
 __init__ C
 on_load
 >>> #Check that __new__ machinery is still available:
 >>> class D(C):
 ... def __new__(cls,*args, **kw):
 ... obj = object.__new__(cls, *args, **kw)
 ... print "__new__ D"
 ... return obj
 ...
 >>> d=D()
 __new__ D
 __init__ A
 __init__ B
 __init__ C
 on_load
 >>>

HTH
Michael

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


Re: having a function called after the constructor/__init__ is done

2009-03-16 Thread Steven D'Aprano
On Mon, 16 Mar 2009 20:11:18 -0700, thomas.han...@gmail.com wrote:

> Hi all,
> 
> We've been breaking our heads over a good way of accomplishing an
> "on_load" event in our multitouch GUI frameowork PyMT.  We think we'd
> like to trigger an "on_load" event after a class is fully instantiated
...
> Can I do something fancy with metaclasses here?

class MetaLoad(type):
def __new__(cls, name, bases, dict):
obj = type.__new__(cls, name, bases, dict)
return obj
def __call__(cls, *args, **kwargs):
instance = super(MetaLoad, cls).__call__(*args, **kwargs)
instance.on_load()
return instance

class Parrot(object):
__metaclass__ = MetaLoad
def __init__(self, colour='blue'):
print "I'm a Norwegian %s." % colour
def on_load(self):
print "Loaded"





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


Re: having a function called after the constructor/__init__ is done

2009-03-16 Thread Armin Moradi
class MyClass(object):
   def __init__(self, really_init=True):
   self.a = 3
   self.b = 4
   # other initialization
   if really_init: on_load()

   def on_load(self):
   print 'hello!'

class B(MyClass):
def __init__(self):
super(B, self).__init__(False)
self.c = 4
print "B initialized"
   MyClass.on_load()

def on_load(self):
print 'hello!'


Would this work?

(posted it again to include the python-list in To:)

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


Re: having a function called after the constructor/__init__ is done

2009-03-16 Thread alex goretoy
__del__

I use it to close a mysql connection

-Alex Goretoy
http://www.goretoy.com

E. B. White  - "Be obscure clearly."

On Mon, Mar 16, 2009 at 10:11 PM, thomas.han...@gmail.com <
thomas.han...@gmail.com> wrote:

> Hi all,
>
> We've been breaking our heads over a good way of accomplishing an
> "on_load" event in our multitouch GUI frameowork PyMT.  We think we'd
> like to trigger an "on_load" event after a class is fully instantiated
> (or just a function call for simplicity, so you dont need to worry
> about our specific system).  This is so that if I make a subclass of
> some widget, I dont have to overwrite the __init__ method (use super,
> know the args, and pass them) everytime.  Maybe I just want to do some
> really basic stuff that doesn't really have anything to do with the
> parent class.
>
> Anyway.  My first attempt was to simply put a call to self.on_load at
> the end of the widget base class.  This doesn't work though, because,
> if I subclass it and do things after the call to super.__init__,
> on_load will be called before the constructor finishes (when the top
> most parent class __init__ finishes)
>
> We've sort of managed to achieve this by using a decorator that
> changes the __init__ function.  but even this doesnt seem like the
> best way to do this.  a) I now have to decorate every constructor i
> ever write. b) it seems impossible to make it so that it only happens
> once after the object is actually instantiated (since i have a
> decorator on all my constructors..each constructor in the inheritance
> line will call on_load once)
>
> Can I do something fancy with metaclasses here?  I think I could kind
> of do this by making all my classes use __new__, and then essentially
> use __init__ as what i want on_load to be...but that just seems really
> nasty and unpythonic.  not to speak about the confusion it would cause
> with people trying to figure out the library.
>
> So any ideas on how to get a function called on an object just after
> __init__ is done executing?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


cool things you can do with dict

2009-03-16 Thread alex goretoy
I though this was cool so I'd post about it, its one of the recipes

class peanutsdict(dict):
def __init__(self,default=None):
dict.__init__(self)
self.default = default

def __getitem__(self,key):
if key in self:
return dict.__getitem__(self,key)
else:

return self.default

def get(self, key, *args):
if not args:
args = (self.default,)
return dict.get(self, key, *args)

def merge(self, other):
for key in other:
if key not in self:
self[key] = other[key]

a=peanutsdict()
a.b=peanutsdict()
a.b.c=peanutsdict()
a.x=1
a.b.y=2
a.b.c.z=3

>>> print a
{}
>>> print a.__dict__
{'default': None, 'x': 1, 'b': {}}
>>> print a.b.__dict__
{'default': None, 'y': 2, 'c': {}}
>>> print a.b.c.__dict__
{'default': None, 'z': 3}
>>> print a.b.c.z
3
>>> print a.b.c
{}
>>> a.b.b=peanutsdict()
>>> class pdict(dict): pass
...
>>> a.b.b.a=pdict()
>>> a.b.b
{}
>>> a.b.b.__dict__
{'default': None, 'a': {}}
>>> a.b.b.__dict__['a']
{}
>>> a.b.b.__dict__['a'].x=4
>>> a.b.b.__dict__['a'].x
4
>>> a.b.b.a.x
4

Anyone else know anymore cool pieces of code?


-Alex Goretoy
http://www.goretoy.com

Jean Anouilh  - "What you get free costs too much."
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question: How do I add elements to **kwargs in a function?

2009-03-16 Thread Aaron Garrett
On Mar 16, 9:59 pm, Chris Rebert  wrote:
> On Mon, Mar 16, 2009 at 7:48 PM, Aaron Garrett
>
>
>
>  wrote:
> > I have spent quite a bit of time trying to find the answer on this
> > group, but I've been unsuccessful. Here is what I'd like to be able to
> > do:
>
> > def A(**kwargs):
> >    kwargs['eggs'] = 1
>
> > def B(**kwargs):
> >    print(kwargs)
>
> > def C(**kwargs):
> >    A(**kwargs)
> >    B(**kwargs)
>
> > I'd like to be able to make a call like:
>
> > C(spam=0)
>
> > and have it print
> > {'spam': 0, 'eggs': 1}
>
> > But it doesn't do that. Instead, it gives
> > {'spam': 0}
>
> > I was under the impression that kwargs is passed by reference and,
>
> It's not. Semantically, the dictionary broken up into individual
> keyword arguments on the calling side, and then on the callee side, a
> fresh dictionary is created from the individual arguments. So while
> Python uses call-by-object, extra packing/unpacking takes place in
> this case, causing copying, and thus your problem.
>
> Cheers,
> Chris
>
> --
> I have a blog:http://blog.rebertia.com


Thank you for the explanation.

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


having a function called after the constructor/__init__ is done

2009-03-16 Thread thomas.han...@gmail.com
Hi all,

We've been breaking our heads over a good way of accomplishing an
"on_load" event in our multitouch GUI frameowork PyMT.  We think we'd
like to trigger an "on_load" event after a class is fully instantiated
(or just a function call for simplicity, so you dont need to worry
about our specific system).  This is so that if I make a subclass of
some widget, I dont have to overwrite the __init__ method (use super,
know the args, and pass them) everytime.  Maybe I just want to do some
really basic stuff that doesn't really have anything to do with the
parent class.

Anyway.  My first attempt was to simply put a call to self.on_load at
the end of the widget base class.  This doesn't work though, because,
if I subclass it and do things after the call to super.__init__,
on_load will be called before the constructor finishes (when the top
most parent class __init__ finishes)

We've sort of managed to achieve this by using a decorator that
changes the __init__ function.  but even this doesnt seem like the
best way to do this.  a) I now have to decorate every constructor i
ever write. b) it seems impossible to make it so that it only happens
once after the object is actually instantiated (since i have a
decorator on all my constructors..each constructor in the inheritance
line will call on_load once)

Can I do something fancy with metaclasses here?  I think I could kind
of do this by making all my classes use __new__, and then essentially
use __init__ as what i want on_load to be...but that just seems really
nasty and unpythonic.  not to speak about the confusion it would cause
with people trying to figure out the library.

So any ideas on how to get a function called on an object just after
__init__ is done executing?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question: How do I add elements to **kwargs in a function?

2009-03-16 Thread alex goretoy
I think you may need to do something like this in your code, this is what I
will be doing here shortly too

class peanutsdict(dict):
__slots__ = ['defaultZZz']
def __init__(self,default=None):
dict.__init(self)
self.default = default

def __getitem__(self,key):
if key in self:
return dict.__getitem__(self,key)
else:

return self.default

def get(self, key, *args):
if not args:
args = (self.default,)
return dict.get(self, key, *args)

def merge(self, other):
for key in other:
if key not in self:
self[key] = other[key]

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question: How do I add elements to **kwargs in a function?

2009-03-16 Thread Chris Rebert
On Mon, Mar 16, 2009 at 7:48 PM, Aaron Garrett
 wrote:
> I have spent quite a bit of time trying to find the answer on this
> group, but I've been unsuccessful. Here is what I'd like to be able to
> do:
>
> def A(**kwargs):
>    kwargs['eggs'] = 1
>
> def B(**kwargs):
>    print(kwargs)
>
> def C(**kwargs):
>    A(**kwargs)
>    B(**kwargs)
>
> I'd like to be able to make a call like:
>
> C(spam=0)
>
> and have it print
> {'spam': 0, 'eggs': 1}
>
> But it doesn't do that. Instead, it gives
> {'spam': 0}
>
> I was under the impression that kwargs is passed by reference and,

It's not. Semantically, the dictionary broken up into individual
keyword arguments on the calling side, and then on the callee side, a
fresh dictionary is created from the individual arguments. So while
Python uses call-by-object, extra packing/unpacking takes place in
this case, causing copying, and thus your problem.

Cheers,
Chris

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


Newbie question: How do I add elements to **kwargs in a function?

2009-03-16 Thread Aaron Garrett
I have spent quite a bit of time trying to find the answer on this
group, but I've been unsuccessful. Here is what I'd like to be able to
do:

def A(**kwargs):
kwargs['eggs'] = 1

def B(**kwargs):
print(kwargs)

def C(**kwargs):
A(**kwargs)
B(**kwargs)

I'd like to be able to make a call like:

C(spam=0)

and have it print
{'spam': 0, 'eggs': 1}

But it doesn't do that. Instead, it gives
{'spam': 0}

I was under the impression that kwargs is passed by reference and,
since I'm only modifying it (rather than making it point to something
else) that the changes would be reflected back out to the thing being
passed in.

So, why doesn't this work the way I expect it to? And, is there some
other way to make this work to accomplish the same goal?

Thank you in advance,
Aaron



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


Re: PyWin32 for Python 3.x

2009-03-16 Thread Mark Tolonen


"cgoldberg"  wrote in message 
news:6047c263-c6cb-4357-ad9b-96b61ec7e...@j8g2000yql.googlegroups.com...

Release 213 is out already:


Tim, Mark,
this is great news.. thanks for tracking 3.x so closely.  I big
barrier for me to eventually adopt 3.x is the ability to use pywin32.

thanks!

-Corey


I am using 213 on both 2.6.1 (default) and 3.0.1 and had no problems with 
installation.   I agree it is beta and have found a couple of bugs, but in 
general it is working well.


I encourage people to download, use and report bugs.  I haven't seen a lot 
of activity about it on the python.windows newsgroup, so more users will 
probably encourage fixes.


-Mark


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


Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-16 Thread MRAB

Rhodri James wrote:
On Tue, 17 Mar 2009 01:47:32 -, MRAB  
wrote:



I'm not against putting a comma in the format to indicate that grouping
should be used just as a dot indicates that a decimal point should be
used. The locale would say what characters would be used for them.

I would prefer the format to have a fixed default so that if you don't
specify the locale the result is predictable.


Shouldn't that be the global locale?


Other parts of the language, such as str.upper, aren't locale-sensitive,
so I think that format shouldn't be either. If you want it to be
locale-sensitive, then specify the locale, even if it's the system
locale.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Run on Startup

2009-03-16 Thread MRAB

Ian Mallett wrote:

Hi,

I'd like to make a program that automatically runs on startup (right 
after login).  How should I do that?



Put it in the folder:

C:\Documents and Settings\\Start Menu\Programs\Startup

The exact path depends on your login/username and I'm assuming that
Windows is installed on drive C.

I'm also assuming that you're using Windows. Chances are that you are
(you didn't say!).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-16 Thread Rhodri James
On Tue, 17 Mar 2009 01:47:32 -, MRAB   
wrote:



I'm not against putting a comma in the format to indicate that grouping
should be used just as a dot indicates that a decimal point should be
used. The locale would say what characters would be used for them.

I would prefer the format to have a fixed default so that if you don't
specify the locale the result is predictable.


Shouldn't that be the global locale?

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


Run on Startup

2009-03-16 Thread Ian Mallett
Hi,

I'd like to make a program that automatically runs on startup (right after
login).  How should I do that?

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


Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-16 Thread MRAB

Rhodri James wrote:
On Mon, 16 Mar 2009 23:04:58 -, MRAB  
wrote:



It should probably(?) be:

 financial = Locale(group_sep=",", grouping=[3])
 print("my number is {0:10n:fin}".format(1234567, fin=financial))

The format "10n" says whether to use separators or a decimal point; the
locale "fin" says what the separator and the decimal point look like.


That works, and isn't an abomination on the face of the existing 
syntax.  Excellent.


I'm rather presuming that the "n" presentation type does grouping.  I've 
only got Python 2.5 here, so I can't check it out (no str.format() 
method and "%n" isn't supported by "%" formatting).  If it does, an "m" 
type to do the same thing only with the LC_MONETARY group settings 
instead of the LC_NUMERIC ones would be a good idea.


This would be my preferred solution to Raymond's original 
comma-in-the-format-string proposal, by the way: add an "m" presentation 
type as above, and tell people to override the LC_MONETARY group 
settings in the global locale.  It's clear that it's a bodge, and 
weaning users onto local locales (!) wouldn't be so hard later on.


Anyway, time I stopped hypothesising about locales and started looking 
at the actual code-base, methinks.



I'm not against putting a comma in the format to indicate that grouping
should be used just as a dot indicates that a decimal point should be
used. The locale would say what characters would be used for them.

I would prefer the format to have a fixed default so that if you don't
specify the locale the result is predictable.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why does Python not return first line?

2009-03-16 Thread Steven D'Aprano
On Mon, 16 Mar 2009 15:20:18 -0700, Falcolas wrote:

> FWIW, I've rarely seen a \r by itself, even in Windows (where it's
> usually \r\n). Unix generally just outputs the \n, so my guess is that
> some other process which created the output removed newline characters,
> but didn't account for the carriage return characters first.


\r is the line terminator for classic Mac. (I think OS X uses \n, but 
presumably Apple applications are smart enough to use either.)

I also remember a software package that allowed you to choose between \r
\n and \n\r when exporting data to text files. It's been some years since 
I've used it -- by memory it was a custom EDI application for a rather 
large Australian hardware company. (Presumably their developers couldn't 
remember which came first, the \r or the \n, so they made it optional.)

The Unicode standard specifies that all of the following should be 
considered line terminators:

LF:Line Feed, U+000A
CR:Carriage Return, U+000D
CR+LF: CR followed by LF, U+000D followed by U+000A
NEL:   Next Line, U+0085
FF:Form Feed, U+000C
LS:Line Separator, U+2028
PS:Paragraph Separator, U+2029

http://en.wikipedia.org/wiki/Newline#Unicode

so presumably if you're getting data from non-Windows or Unix systems, 
you could find any of these. Aren't standards wonderful? There are so 
many to choose from.


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


Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-16 Thread Rhodri James
On Mon, 16 Mar 2009 23:04:58 -, MRAB   
wrote:



It should probably(?) be:

 financial = Locale(group_sep=",", grouping=[3])
 print("my number is {0:10n:fin}".format(1234567, fin=financial))

The format "10n" says whether to use separators or a decimal point; the
locale "fin" says what the separator and the decimal point look like.


That works, and isn't an abomination on the face of the existing syntax.   
Excellent.


I'm rather presuming that the "n" presentation type does grouping.  I've  
only got Python 2.5 here, so I can't check it out (no str.format() method  
and "%n" isn't supported by "%" formatting).  If it does, an "m" type to  
do the same thing only with the LC_MONETARY group settings instead of the  
LC_NUMERIC ones would be a good idea.


This would be my preferred solution to Raymond's original  
comma-in-the-format-string proposal, by the way: add an "m" presentation  
type as above, and tell people to override the LC_MONETARY group settings  
in the global locale.  It's clear that it's a bodge, and weaning users  
onto local locales (!) wouldn't be so hard later on.


Anyway, time I stopped hypothesising about locales and started looking at  
the actual code-base, methinks.


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


Can python quickly display results like bash?

2009-03-16 Thread robert song
Hello, everyone.
python can be debugged with pdb, but if there anyway to get a quick
view of the python execution.
Just like sh -x of bash command.
I didn't find that there is an option of python that can do it.

besh wishes,
robert
--
http://mail.python.org/mailman/listinfo/python-list


Re: Integer arithmetic in hardware descriptions

2009-03-16 Thread JanC
bearophileh...@lycos.com wrote:

> JanC:
>> In most "modern" Pascal dialects the overflow checks can be (locally)
>> enabled or disabled with compiler directives in the source code,
>
> I think that was possible in somewhat older versions of Pascal-like
> languages too (like old Delphi versions, and maybe TurboPascals too).

Yeah, I think Turbo Pascal supported this since v3 or v4 at least.
(By "modern" I meant as opposed to the original Pascal & the other "classic"
Pascals that were available before Turbo Pascal came around.)

>>so the "speed issue" is not a real issue in practice...<
>
> How can I help Walter (the designer and writer of the D language)
> understand this? Do you have articles or other ways that support this
> point of view?

"Premature optimization is the root of all evil in programming" ?  ;-)


(And D became way too complicated over the years, so I'm not really
interested in it much anymore.)


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


Re: multiprocessing.sharedctypes and built-in locks

2009-03-16 Thread Ahmad Syukri b
On Mar 16, 5:19 pm, Aaron Brady  wrote:
> It's not one of the guarantees that Python
> makes.  Operations aren't atomic by default, such as unless stated
> otherwise.  

Well, in the documentation for RawArray:
"Note that setting and getting an element is potentially non-atomic –
use Array() instead to make sure that access is automatically
synchronized using a lock."
So I assumed operations for Array() would be atomic

> > I also realized that the created lock's release and acquire
> > methods are also imbued to the created shared object, and this is also
> > undocumented.
>
> Sorry, I don't follow you.

Sorry if that wasn't clear. By this, I meant:

b = multiprocessing.Array('i',5)
if b.acquire():
 b[0] += 1
 b.release()

though you don't get to use the with statement with this one. Also
only one RLock is created per array, whilst my code needed a lock for
each array member.

> By the way, your first example didn't
> produce the expected result on my machine-- even with the 'if
> __name__' statement.

Strange, I just copied and pasted the first example on a new blank
file and ran python3 with it again, it comes out find and dandy
(totalling 40). I also tried the second example with the gl.append
line deleted, and it also runs (of course, with the wrong results)
--
http://mail.python.org/mailman/listinfo/python-list


Re: switch to interactive mode

2009-03-16 Thread nntpman68

Hi JBW.


code.interact() does what I wanted. Great !!!


Thanks



N

JBW wrote:

On Mon, 16 Mar 2009 23:49:34 +0100, nntpman68 wrote:


I'd like, that a python script can be started by just calling it
(clicking on it),

but that the script can decide to enter interactive mode if certain
conditions occur.

Is this possible?


Don't know about the clicky-clicky part, but I've used code.interact to 
do something similar.


JBW


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


Re: switch to interactive mode

2009-03-16 Thread Mike Driscoll
On Mar 16, 5:49 pm, nntpman68  wrote:
> Hi
>
> I know about two ways to enter python interactive mode
>
> 1.) just start python
>
> 2.) run python -i pythonscript.py
>
> What I am looking for is slightly different:
>
> I'd like, that a python script can be started by just calling it
> (clicking on it),
>
> but that the script can decide to enter interactive mode if certain
> conditions occur.
>
> Is this possible?

That sounds kind of like needing to embed the interpreter. I would
recommend looking into that. Wingware's Wing IDE has this feature
where you can run the program up a breakpoint and then use their
debugger to interact with the variables and objects and such.

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


Re: Style question - defining immutable class data members

2009-03-16 Thread Rhodri James
On Mon, 16 Mar 2009 09:31:59 -, Aaron Brady   
wrote:

[snippety snip]

Otherwise, either /1, every instance has its own entries for class
functions, and subsequent changes to the class don't affect existing
instances, or /2, every method call is of the form x.__class__.foo
( ).  They're both bad.  (...unless that's a false dilemma.)


I must admit I was envisaging a horribly inefficient (in space terms)
version of (1) in which the instance entries were binding stubs that
referenced the class entries, but that still falls over when new
methods get dynamically added to the class.  I blame having two hours
of sleep in three days for this particular bit of dimness, sorry.


P.S.  Do you pronounce 'wildebeeste' like 'vildebeeste'?


No, with a "w" not a "v".  It's just one of those titles that
stick with you no matter what you do.

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


Re: switch to interactive mode

2009-03-16 Thread JBW
On Mon, 16 Mar 2009 23:49:34 +0100, nntpman68 wrote:

> I'd like, that a python script can be started by just calling it
> (clicking on it),
> 
> but that the script can decide to enter interactive mode if certain
> conditions occur.
> 
> Is this possible?

Don't know about the clicky-clicky part, but I've used code.interact to 
do something similar.

JBW

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


Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-16 Thread MRAB

Rhodri James wrote:
On Mon, 16 Mar 2009 02:36:43 -, MRAB  
wrote:



The field name can be an integer or an identifier, so the locale could
be too, provided that you know where to look it up!

 financial = Locale(group_sep=",", grouping=[3])
 print("my number is {0:10n:{fin}}".format(1234567, fin=financial))

Then again, shouldn't that be:

 fin = Locale(group_sep=",", grouping=[3])
 print("my number is {0:{fin}}".format(1234567, fin=financial))


Except that loses you the format, since the locale itself is a collection
of parameters the format uses.  The locale knows how to do groupings, but
not whether to do them, nor what the field width should be.  Come to think
of it, it doesn't know whether to use the LC_NUMERIC grouping information
or the LC_MONETARY grouping information.  Hmm.

I can't believe I'm even suggesting this, but how about:

  print("my number is {fin.format("10d", {0}, True)}".format(1235467, 
fin=financial))


assuming the locale.format() method remains unchanged?  That's horrible,
and I'm pretty sure it can't be right, but I'm too tired to think of
anything more sensible right now.


It should probably(?) be:

financial = Locale(group_sep=",", grouping=[3])
print("my number is {0:10n:fin}".format(1234567, fin=financial))

The format "10n" says whether to use separators or a decimal point; the
locale "fin" says what the separator and the decimal point look like.
--
http://mail.python.org/mailman/listinfo/python-list


switch to interactive mode

2009-03-16 Thread nntpman68

Hi

I know about two ways to enter python interactive mode

1.) just start python

2.) run python -i pythonscript.py

What I am looking for is slightly different:

I'd like, that a python script can be started by just calling it 
(clicking on it),



but that the script can decide to enter interactive mode if certain 
conditions occur.


Is this possible?



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


Re: error writing str to binary stream - fails in Python 3.0.1, works in 2.x

2009-03-16 Thread John Machin
On Mar 17, 9:29 am, "R. David Murray"  wrote:
> walle...@gmail.com wrote:
> > On Mar 16, 4:10 pm, Benjamin Peterson  wrote:
> > >   gmail.com> writes:
>
> > > > self.out.write(b'BM') worked beautifully.  Now I also have a similar
> > > > issue, for instance:
> > > > self.out.write("%c" % y) is also giving me the same error as the other
> > > > statement did.
> > > > I tried self.out.write(bytes("%c" %y),encoding=utf-8) in an attempt to
> > > > convert to bytes, which it did, but not binary.  How do I affect
> > > > self.out.write("%c" % y) to write out as a binary byte steam?  I also
> > > > tried self.out.write(b"%c" % y), but b was an illegal operator in when
> > > > used that way.
> > > > It is also supposed to be data being written to the .bmp file. --Bill
>
> > > Are you writing to sys.stdout? If so, use sys.stdout.buffer.write(b'some
> > > bytes'). If you're writing to a file, you have to open it in binary mode 
> > > like
> > > this: open("someimage.bmp", "wb")
>
> > Yes, I am writing to a file.  That portion is correct and goes like
> > this:
>
> > self.out=open(filename,"wb")
> >     self.out.write(b"BM")          # This line works thanks to advice given
> >                                    # in previous reply
>
> > However, here is some more code that is not working and the error it
> > gives:
>
> > def write_int(self,n):
> >     str_out='%c%c%c%c' % ((n&255),(n>>8)&255,(n>>16)&255,(n>>24)&255)
> >     self.out.write(str_out)
>
> > this is line 29, does not work - not
> > sure how to get this complex str converted over to binary bytes to
> > write to bmp file.
>
> (I reformatted your message slightly to make the code block stand out more.)
>
> A byte array is an array of bytes, and it understands integers as input.
> Check out the PEP (the official docs leave some things out):
>
>    http://www.python.org/dev/peps/pep-0358/
>
> Here is some example code that works:

No it doesn't. There is an extra "(" in the assignment to bytesout.

>
>     out=open('temp', "wb")
>     out.write(b"BM")
>
>     def write_int(out, n):
>         bytesout=bytes(([n&255), (n>>8)&255, (n>>16)&255, (n>>24)&255])
>         out.write(bytesout)  
>
>     write_int(out, 125)

Consider using the struct module; it's expressly designed for that
sort of thing.

import struct
out.write(struct.pack("<2sI", "BM", 125))

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


Re: error writing str to binary stream - fails in Python 3.0.1, works in 2.x

2009-03-16 Thread Scott David Daniels

R. David Murray wrote:

...
Here is some example code that works:

out=open('temp', "wb")
out.write(b"BM")

def write_int(out, n):
bytesout=bytes(([n&255), (n>>8)&255, (n>>16)&255, (n>>24)&255])
out.write(bytesout)
write_int(out, 125)


or even:
import struct
...
def write_int(out, n):
out.write(struct.pack('http://mail.python.org/mailman/listinfo/python-list


Re: Rough draft: Proposed format specifier for a thousands separator

2009-03-16 Thread Rhodri James
On Mon, 16 Mar 2009 02:36:43 -, MRAB   
wrote:



The field name can be an integer or an identifier, so the locale could
be too, provided that you know where to look it up!

 financial = Locale(group_sep=",", grouping=[3])
 print("my number is {0:10n:{fin}}".format(1234567, fin=financial))

Then again, shouldn't that be:

 fin = Locale(group_sep=",", grouping=[3])
 print("my number is {0:{fin}}".format(1234567, fin=financial))


Except that loses you the format, since the locale itself is a collection
of parameters the format uses.  The locale knows how to do groupings, but
not whether to do them, nor what the field width should be.  Come to think
of it, it doesn't know whether to use the LC_NUMERIC grouping information
or the LC_MONETARY grouping information.  Hmm.

I can't believe I'm even suggesting this, but how about:

  print("my number is {fin.format("10d", {0}, True)}".format(1235467,  
fin=financial))


assuming the locale.format() method remains unchanged?  That's horrible,
and I'm pretty sure it can't be right, but I'm too tired to think of
anything more sensible right now.

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


ANN: eGenix pyOpenSSL Distribution 0.8.1-0.9.8j-1

2009-03-16 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING

   eGenix.com pyOpenSSL Distribution

Version 0.8.1-0.9.8j-1


 An easy to install and use repackaged distribution
   of the pyOpenSSL Python interface for OpenSSL -
  available on Windows and Unix platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.8.1-0.9.8j-1-GA.html



INTRODUCTION

The eGenix.com pyOpenSSL Distribution includes everything you need to
get started with SSL in Python. It comes with an easy to use installer
that includes the most recent OpenSSL library versions in pre-compiled
form.

pyOpenSSL is an open-source Python add-on (http://pyopenssl.sf.net/)
that allows writing SSL aware networking applications as well as
certificate management tools.

OpenSSL is an open-source implementation of the SSL protocol
(http://www.openssl.org/).

For more information, please see the product page:

http://www.egenix.com/products/python/pyOpenSSL/



NEWS

This new release of the eGenix.com pyOpenSSL Distribution fixes a
serious problem in pyOpenSSL 0.8 related to threaded applications.

The problem causes invalid thread states in the Python interpreter which
then result in random core dumps and seg faults. The patch was provided
by Maxim Sobolev on SourceForge:

http://sourceforge.net/tracker/index.php?func=detail&aid=2543118&group_id=31249&atid=401760

Note that this patch has not yet been integrated into upstream
pyOpenSSL.

We have also fixed several compiler warnings found in the code. The
version of pyOpenSSL you find in the source release has those patches
applied.

Binaries are available for Linux x86 and x64 as well as Windows x86
and include pyOpenSSL as well as the OpenSSL libraries.

For Plone users and friends of buildout scripts, we have added
pre-built binaries for Windows. They install just like the Linux
versions and allow easy integration of the archives into buildout
scripts.



DOWNLOADS

The download archives and instructions for installing the package can
be found at:

http://www.egenix.com/products/python/pyOpenSSL/



UPGRADING

Before installing this version of pyOpenSSL, please make sure that
you uninstall any previously installed pyOpenSSL version. Otherwise,
you could end up not using the included OpenSSL libs.

___

SUPPORT

Commercial support for these packages is available from eGenix.com.
Please see

http://www.egenix.com/services/support/

for details about our support offerings.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Mar 16 2009)
>>> Python/Zope Consulting and Support ...http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/


::: Try our new mxODBC.Connect Python Database Interface for free ! 


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
   Registered at Amtsgericht Duesseldorf: HRB 46611
   http://www.egenix.com/company/contact/


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


Re: Guidance on writing a top-like console

2009-03-16 Thread cgoldberg
> >> I am interested in writing an application that functions like a Unix
> >> or Linux top in the way it displays data.
> >> It should be command-line based but dynamically refreshing.

also check out the source for "dstat".  It is written in python and
displays top-like information and more.  It dynamically updates the
way top does.

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


Re: error writing str to binary stream - fails in Python 3.0.1, works in 2.x

2009-03-16 Thread R. David Murray
walle...@gmail.com wrote:
> On Mar 16, 4:10 pm, Benjamin Peterson  wrote:
> >   gmail.com> writes:
> >
> >
> >
> > > self.out.write(b'BM') worked beautifully.  Now I also have a similar
> > > issue, for instance:
> > > self.out.write("%c" % y) is also giving me the same error as the other
> > > statement did.
> > > I tried self.out.write(bytes("%c" %y),encoding=utf-8) in an attempt to
> > > convert to bytes, which it did, but not binary.  How do I affect
> > > self.out.write("%c" % y) to write out as a binary byte steam?  I also
> > > tried self.out.write(b"%c" % y), but b was an illegal operator in when
> > > used that way.
> > > It is also supposed to be data being written to the .bmp file. --Bill
> >
> > Are you writing to sys.stdout? If so, use sys.stdout.buffer.write(b'some
> > bytes'). If you're writing to a file, you have to open it in binary mode 
> > like
> > this: open("someimage.bmp", "wb")
> 
> Yes, I am writing to a file.  That portion is correct and goes like
> this:
>
> self.out=open(filename,"wb")
> self.out.write(b"BM")  # This line works thanks to advice given
># in previous reply
> 
> However, here is some more code that is not working and the error it
> gives:
>
> def write_int(self,n):
> str_out='%c%c%c%c' % ((n&255),(n>>8)&255,(n>>16)&255,(n>>24)&255)
> self.out.write(str_out) 
>
> this is line 29, does not work - not
> sure how to get this complex str converted over to binary bytes to
> write to bmp file.

(I reformatted your message slightly to make the code block stand out more.)

A byte array is an array of bytes, and it understands integers as input.
Check out the PEP (the official docs leave some things out):

http://www.python.org/dev/peps/pep-0358/

Here is some example code that works:

out=open('temp', "wb")
out.write(b"BM")

def write_int(out, n):
bytesout=bytes(([n&255), (n>>8)&255, (n>>16)&255, (n>>24)&255])
out.write(bytesout)   

write_int(out, 125)

--
R. David Murray   http://www.bitdance.com

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


Re: Why does Python not return first line?

2009-03-16 Thread Falcolas
On Mar 15, 6:25 pm, Gilles Ganault  wrote:
> address = re_address.search(response)
> if address:
> address = address.group(1).strip()
>
> #Important!
> for item in ["\t","\r"," "]:
> address = address.replace(item,"")
>

As you found, your script works just fine, it's just that during
terminal output the \r performs a carriage return and wipes out
everything prior to it.

FWIW, I've rarely seen a \r by itself, even in Windows (where it's
usually \r\n). Unix generally just outputs the \n, so my guess is that
some other process which created the output removed newline
characters, but didn't account for the carriage return characters
first.

Wiping out the \r characters as you did will solve your display
issues, though any other code should read right past them.

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


Re: How to interface with C# without IronPython

2009-03-16 Thread Mudcat
On Mar 13, 8:37 pm, Christian Heimes  wrote:
> Chris Rebert wrote:
> > Haven't used it, butPythonfor .NET sounds like it might be what you
> > want:http://pythonnet.sourceforge.net/
>
> I've done some development for and with PythonDotNET. It's definitely
> the right thing. It works with .NET, Mono andPython2.4 to 2.6.
>
> Christian

That looks exactly like what I'm searching for. I'll give it a shot.

One question, the last update for that is back in '07. Do you know if
it's still in active development?

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


Re: Problem: Terminal (OS X) window exits immediately on opening. & Solution.

2009-03-16 Thread Lou Pecora

Python wrote:


On 16 mrt 2009, at 22:10, Lou Pecora wrote:




why don't you just execute the script directly form the terminal?
then you will be able to read all error messages...
and you can delete all the files you want

just my 2c

Arno


Because the shell process in the Terminal window would exit right 
after it started even when I was just trying to open a new window 
(not even running a script), i.e. command-N in Terminal.  So I could 
not run anything from the Terminal.

--

(please use reply-all so it also goes to the list :)  )


i don't understand...
if you open the terminal from /Applications/Utilities/Terminal
it comes up with a window and you can execute any script from there

No.

without the window closing when the script exits, or not?


No, I could not execute anything when I opened a window.  A shell would 
start, then immediately exit leaving an error message and a logout.  The 
Terminal has an 'Executestring' property in the preferences (Property 
List) which it tries to execute before giving you a shell prompt.  If 
that string has a bad command or refers to a file that does not exist 
(my case), the shell exits (Logout).  The Terminal is incapacitated 
until you remove that bad 'Executestring' from the preferences.  
Terminal does not crash.  The window stays open, but the shell is logged 
out.  Open another window, same thing happens.


I got that problem while running Python scripts from an Editor.  But 
even trying to just open a window/shell caused a failure.  The strange 
thing was that the bad file was a .py file down in the /var directory 
which something (BBEdit? The Terminal? Python? The System? ??) put 
there.  Why?  I don't know.


--
Cheers,

Lou Pecora

Code 6362
Naval Research Lab
Washington, DC  20375, USA
Ph:  +202-767-6002
email:  louis.pec...@nrl.navy.mil

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


Re: error writing str to binary stream - fails in Python 3.0.1, works in 2.x

2009-03-16 Thread Terry Reedy

walle...@gmail.com wrote:


Thanks for the assist.  One more question, please.

self.out.write(b'BM') worked beautifully.  Now I also have a similar
issue, for instance:
self.out.write("%c" % y) is also giving me the same error as the other
statement did.
I tried 



self.out.write(bytes("%c" %y),encoding=utf-8)



in an attempt to convert to bytes, which it did, but not binary.


If you actually wrote that, try

self.out.write(bytes("%c" %y,encoding=utf-8))

To aid respondents, copy an paste actually code run and actual result or 
traceback received.


tjr

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


Re: error writing str to binary stream - fails in Python 3.0.1, works in 2.x

2009-03-16 Thread wallenpb
On Mar 16, 4:10 pm, Benjamin Peterson  wrote:
>   gmail.com> writes:
>
>
>
> > self.out.write(b'BM') worked beautifully.  Now I also have a similar
> > issue, for instance:
> > self.out.write("%c" % y) is also giving me the same error as the other
> > statement did.
> > I tried self.out.write(bytes("%c" %y),encoding=utf-8) in an attempt to
> > convert to bytes, which it did, but not binary.  How do I affect
> > self.out.write("%c" % y) to write out as a binary byte steam?  I also
> > tried self.out.write(b"%c" % y), but b was an illegal operator in when
> > used that way.
> > It is also supposed to be data being written to the .bmp file. --Bill
>
> Are you writing to sys.stdout? If so, use sys.stdout.buffer.write(b'some
> bytes'). If you're writing to a file, you have to open it in binary mode like
> this: open("someimage.bmp", "wb")

Yes, I am writing to a file.  That portion is correct and goes like
this:
self.out=open(filename,"wb")
self.out.write(b"BM")  # This line works thanks to advice
given in previous reply

However, here is some more code that is not working and the error it
gives:
def write_int(self,n):
str_out='%c%c%c%c' % ((n&255),(n>>8)&255,(n>>16)&255,(n>>24)&255)
self.out.write(str_out)   #this is line 29, does not work - not
sure how to get this complex str converted over to binary bytes to
write to bmp file.
  #tried to use self.out.write(bytes
("blah", encoding='utf-8')) type coding here.  This way ran without
error, but
  #did not write proper data to the .bmp
file.In hex editor it was obvious it was filling in wrong bits.
  #Also tried self.out.write(b'%c%c%c%c' %
(blah)) but this gave errors for bad operands for % operator.
-
Traceback (most recent call last):
File "C:\Python30\py_kohn_bmp.py", line 29, in write_int
self.out.write(str_out)
  File "C:\Python30\lib\io.py", line 1038, in write
raise TypeError("can't write str to binary stream")
TypeError: can't write str to binary stream
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem: Terminal (OS X) window exits immediately on opening. & Solution.

2009-03-16 Thread Lou Pecora
In article ,
 Python  wrote:

> > --
> why don't you just execute the script directly form the terminal?
> then you will be able to read all error messages...
> and you can delete all the files you want
> 
> just my 2c
> 
> Arno

Because the shell process in the Terminal window would exit right after 
it started even when I was just trying to open a new window (not even 
running a script), i.e. command-N in Terminal.  So I could not run 
anything from the Terminal. 

More info:  There is an Executestring in the Terminal preferences that 
is executed (I would guess as a shell command or script) when the shell 
starts up (which happens whenever a new window is opened).  If that is 
bad in any way, the shell exists with an error message.  There is no way 
to run any shell in the Terminal at that point.  The only option appears 
to be to clean up the preferences.  I don't know why the preferences got 
a bad command while I was running Python scripts.  Maybe nothing to do 
with Python, maybe it does.  Not sure.

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


Re: Problem: Terminal (OS X) window exits immediately on opening. & Solution.

2009-03-16 Thread Python


On 16 mrt 2009, at 22:10, Lou Pecora wrote:




why don't you just execute the script directly form the terminal?
then you will be able to read all error messages...
and you can delete all the files you want

just my 2c

Arno


Because the shell process in the Terminal window would exit right  
after it started even when I was just trying to open a new window  
(not even running a script), i.e. command-N in Terminal.  So I could  
not run anything from the Terminal.

--

(please use reply-all so it also goes to the list :)  )


i don't understand...
if you open the terminal from /Applications/Utilities/Terminal
it comes up with a window and you can execute any script from there
without the window closing when the script exits, or not?


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


Re: error writing str to binary stream - fails in Python 3.0.1, works in 2.x

2009-03-16 Thread Benjamin Peterson
  gmail.com> writes:
> 
> self.out.write(b'BM') worked beautifully.  Now I also have a similar
> issue, for instance:
> self.out.write("%c" % y) is also giving me the same error as the other
> statement did.
> I tried self.out.write(bytes("%c" %y),encoding=utf-8) in an attempt to
> convert to bytes, which it did, but not binary.  How do I affect
> self.out.write("%c" % y) to write out as a binary byte steam?  I also
> tried self.out.write(b"%c" % y), but b was an illegal operator in when
> used that way.
> It is also supposed to be data being written to the .bmp file. --Bill

Are you writing to sys.stdout? If so, use sys.stdout.buffer.write(b'some
bytes'). If you're writing to a file, you have to open it in binary mode like
this: open("someimage.bmp", "wb") 




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


Re: How to add months to a date?

2009-03-16 Thread Scott David Daniels

So, I see nobody has seen fit to make the obvious joke.
I will demonstrate my lack of restraint, by answering:

The way to add months to a date is to begin by
asking about your date's early childhood.

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


Re: Problem: Terminal (OS X) window exits immediately on opening. & Solution.

2009-03-16 Thread Python


On 16 mrt 2009, at 18:21, Lou Pecora wrote:


Since this happened with a Python script and some people here use OS X
and Terminal to run scripts I thought this might be helpful.

I recently ran into this problem using Terminal and found the  
solution.

I thought those who use the Terminal in OS X might be interested.

The problem appeared suddenly.  Whenever I tried to open a new  
window in

Terminal I would get the message that Terminal tried to execute a
certain file (way down in the /var directory), but the file didn't
exist.  And the process would Exit.  Very frustrating since you can't
use the Terminal to help find the problem.

E.g error message:

/var/tmp/folders.501/Cleanup\ At\
Startup/drvrSDWB_2-258580497.358.py.command; exit
-bash: /var/tmp/folders.501/Cleanup At
Startup/drvrSDWB_2-258580497.358.py.command: No such file or directory

The Solution is to go into the preference file for the Terminal  
(located

in
/Users/your_account_name_here/Library/Preferences/ 
com.apple.Terminal.plis
t) and open it with the Property List Editor (should open  
automatically

with a double click or you might have to install the Property List
Editor from the System CDs that came with your computer).  Under the
heading Executionstring you will see the name of the file that the
Terminal is choking on.  Double click the name and delete it.  Save.  
and

quit the Property List Editor.  The Terminal should work normally now.

More info.  I got this problem while running Python scripts from  
BBEdit
(which automatically launches the scripts in a Terminal Window). Why  
it

happened is lost on me.  I don't know if Python, BBEdit, or Terminal
munged the property list.  At least I managed to track it down.

I hope this helps someone if you've had this problem.

--
-- Lou Pecora
--

why don't you just execute the script directly form the terminal?
then you will be able to read all error messages...
and you can delete all the files you want

just my 2c

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


Re: is there an easy way to parse a nested list ?

2009-03-16 Thread Stef Mientki

thanks Aaron, Paul and Vlastimil,
sorry I phrased my question wrong,
I was looking for parsing an expression of an element of a nested list
the code below seems to do what I'm looking for.

cheers,
Stef


Aaron Brady wrote:

On Mar 15, 6:44 pm, Stef Mientki  wrote:
  

hello,

I need to parse a nested list, given as a string, like this

line = " A  [  B  [ C+2 ] + 3 ] "

( I probably can do it with find, but I guess that's not the most
elegant way, besides recusrion is not my strongest point)

which should be parsed so I get an list from inner to outer side (don't
know if these are the correct words),
but I should like to have a list or tuple for tis case:

parsed = [ C+2,  B[C+2]+3,   A  [  B  [ C+2 ] + 3 ] ]
   or (last term is not needed, as well as the constants aren't)
parsed = [ C,  B[C+2] ]

this all, to improve the improved error / exception message even more ;-)

thanks,
Stef



Hi Stef,

This looks like what you want:

def parse_list( s, start= 0 ):
x= []
i= start
while i< len( s ):
c= s[ i ]
if c== '[':
y, i= parse_list( s, i+ 1 )
x= x+ y
if c== ']':
return x+ [ s[start: i ] ], i
i+= 1
return x+ [ s ]

line = " A  [  B  [ C+2 ] + 3 ] "
print( parse_list( line ) )
#[' C+2 ', '  B  [ C+2 ] + 3 ', ' A  [  B  [ C+2 ] + 3 ] ']

line = " A  [  B  [ C+2 ] [ D+2 ] + 3 ] "
print( parse_list( line ) )
#[' C+2 ', ' D+2 ', '  B  [ C+2 ] [ D+2 ] + 3 ', ' A  [  B  [ C+2 ] [ D
+2 ] + 3 ] ']

...So long as you don't have any brackets inside strings or what not.
It just admits two special characters, '[' and ']'.
--
http://mail.python.org/mailman/listinfo/python-list
  


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


Re: Pycon Spam

2009-03-16 Thread python
Andrew,

I'm on a lot of Python (and Python related) mailing lists and haven't
received a message like you described.

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


Re: error writing str to binary stream - fails in Python 3.0.1, works in 2.x

2009-03-16 Thread wallenpb
On Mar 16, 11:05 am, "R. David Murray"  wrote:
> walle...@gmail.com wrote:
> > I am working with a bit of code that works ok in Python 2.x (tested
> > fine in 2.5.4 and 2.6.1) but fails in 3.0.1.
> > The code opens a file for binary output to witht the objective to
> > produce a .bmp graphics file.  The code below illustrates the first of
> > several like errors when a str object is attempted to be written to
> > the binary file.  From what I have seen, this was a fairly common
> > technique prior to 3.0.1 being released so I am assuming the type
> > checking is tighter with the new version.  What is the proper way of
> > doing this now, or the work around?  Any help appreciated.  -- Bill
>
> > the code:
> > ---
> > self.out=open(filename,"wb")
> >     self.out.write("BM")          # magic number
>
> > This the is the error output from Python:
> > 
> > Traceback (most recent call last):
> >   File "py_mandel.py", line 19, in 
> >     my_bmp=kohn_bmp("out.bmp",image_width,image_height,3)
> >   File "C:\Python30\py_kohn_bmp.py", line 47, in __init__
> >     self.out.write("BM")          # magic number
> >   File "C:\Python30\lib\io.py", line 1038, in write
> >     raise TypeError("can't write str to binary stream")
> > TypeError: can't write str to binary stream
>
> In 3.x the 'str' type is unicode.  If you want to work with binary byte
> streams, you want to use the 'bytes' type.  Bytes contstants are
> written with a leading 'b', so the code snipped above would become
>
>     self.out.write(b'BM')
>
> --
> R. David Murray          http://www.bitdance.com
David,
Thanks for the assist.  One more question, please.

self.out.write(b'BM') worked beautifully.  Now I also have a similar
issue, for instance:
self.out.write("%c" % y) is also giving me the same error as the other
statement did.
I tried self.out.write(bytes("%c" %y),encoding=utf-8) in an attempt to
convert to bytes, which it did, but not binary.  How do I affect
self.out.write("%c" % y) to write out as a binary byte steam?  I also
tried self.out.write(b"%c" % y), but b was an illegal operator in when
used that way.
It is also supposed to be data being written to the .bmp file. --Bill
--
http://mail.python.org/mailman/listinfo/python-list


Pycon Spam

2009-03-16 Thread andrew cooke

Has anyone else received spam (unsolicited email) about PyCon 2009?

I've just got an email from "Roy Hyunjin Han" <@columbia.edu> and as
far as I can tell it's not associated with any list I've subscribed to. 
If it is spam I'm guessing the from address is fake (why would someone I
don't know send me an impersonal notice at Pycon?).  But on the other
hand, why would anyone spam about Pycon anyway?

Hmmm.  At the end of the email are two links to job sites ventureloop and
startuply.  Are they responsible for the spam?

Anyway - anyone else got this?

It starts:

  This year's Python Conference is in Chicago and will feature
  topics ranging from web development and scientific computing

Andrew


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


Re: Lists aggregation

2009-03-16 Thread Mensanator
On Mar 16, 1:40 pm, Peter Otten <__pete...@web.de> wrote:
> mattia wrote:
> > I have 2 lists, like:
> > l1 = [1,2,3]
> > l2 = [4,5]
> > now I want to obtain a this new list:
> > l = [(1,4),(1,5),(2,4),(2,5),(3,4),(3,5)]
> > Then I'll have to transform the values found in the new list.
> > Now, some ideas (apart from the double loop to aggregate each element of
> > l1 with each element of l2):
> > - I wanted to use the zip function, but the new list will not aggregate
> > (3,4) and (3,5)
> > - Once I've the new list, I'll apply a map function (e.g. the exp of the
> > values) to speed up the process
> > Some help?
>
> Why would you keep the intermediate list?
>
> With a list comprehension:
>
> >>> a = [1,2,3]
> >>> b = [4,5]
> >>> [x**y for x in a for y in b]
>
> [1, 1, 16, 32, 81, 243]
>
> With itertools:
>
> >>> from itertools import product, starmap
> >>> from operator import pow
> >>> list(starmap(pow, product(a, b)))
>
> [1, 1, 16, 32, 81, 243]

That looks nothing like [(1,4),(1,5),(2,4),(2,5),(3,4),(3,5)].

>
> Peter

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


Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread Scott David Daniels

bdb112 wrote:

... the difference between ...
print(" %d,  %d, buckle my shoe" % (1,2))
... and ...
print(" %d, " + " %d, buckle my shoe" % (1,2))
# a bug or a feature?


A feature.   a + b % c   is   a + (b % c)
But do note that string constant concatentation is higher priority
than the other operators.
> print(" %d, "  " %d, buckle my shoe" % (1,2))

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


More copyright briefs

2009-03-16 Thread Scott David Daniels

On Groklaw, there is the motion filed by Harvard's Charles Nelson
argues that "statutory damages for noncommercial defendants under
copyright law are unconstitutional, unreasonable, and way out of
proportion to any alleged injury to the plaintiffs."

http://www.groklaw.net/article.php?story=20090310172906129

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


Re: String to sequence

2009-03-16 Thread S Arrowsmith
Peter Otten  <__pete...@web.de> wrote:
>assert s.startswith("[")
>assert s.endswith("]")
>s = s[1:-1]

s.strip('[]')

(I suppose it all depends on how much you can trust the consistency
of the input.)

-- 
\S

   under construction

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


Re: Lists aggregation

2009-03-16 Thread Peter Otten
mattia wrote:

> I have 2 lists, like:
> l1 = [1,2,3]
> l2 = [4,5]
> now I want to obtain a this new list:
> l = [(1,4),(1,5),(2,4),(2,5),(3,4),(3,5)]
> Then I'll have to transform the values found in the new list.
> Now, some ideas (apart from the double loop to aggregate each element of
> l1 with each element of l2):
> - I wanted to use the zip function, but the new list will not aggregate
> (3,4) and (3,5)
> - Once I've the new list, I'll apply a map function (e.g. the exp of the
> values) to speed up the process
> Some help?

Why would you keep the intermediate list?

With a list comprehension:

>>> a = [1,2,3]
>>> b = [4,5]
>>> [x**y for x in a for y in b]
[1, 1, 16, 32, 81, 243]

With itertools:

>>> from itertools import product, starmap
>>> from operator import pow
>>> list(starmap(pow, product(a, b)))
[1, 1, 16, 32, 81, 243]

Peter

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


Re: [ActivePython 2.5.1.1] Why does Python not return first line?

2009-03-16 Thread Scott David Daniels

Dennis Lee Bieber wrote:

Teletypes, OTOH, really did use one character to advance the platen
by a line, and a second to move the print-head to the left. (and may
have needed "rub-out" characters to act as timing delays while the
print-head moved)

I remember writing a printer driver for a terminal which kept the print
head horizontal position "soft".  The trick to printing fast was to
start a line feed, and use horizontal positioning (returns, backspace,
space, tab) as part of the time delay required before printing the first
actual printing character.  Once you had to print a printing character,
we used ASCII NULs (though I have seen rub-out used as well) to finish
the time delay needed.  Since we needed eight (or was it twelve) chars
of delay, this driver substantially improved the print speed for our
listings.

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


Re: Lists aggregation

2009-03-16 Thread bearophileHUGS
mattia:
> Now, some ideas (apart from the double loop to aggregate each element of
> l1 with each element of l2):

>>> from itertools import product
>>> list(product([1,2,3], [4,5]))
[(1, 4), (1, 5), (2, 4), (2, 5), (3, 4), (3, 5)]

Bye,
bearophile
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lists aggregation

2009-03-16 Thread Armin
On Monday 16 March 2009 15:07:06 mattia wrote:
> I have 2 lists, like:
> l1 = [1,2,3]
> l2 = [4,5]
> now I want to obtain a this new list:
> l = [(1,4),(1,5),(2,4),(2,5),(3,4),(3,5)]
> Then I'll have to transform the values found in the new list.
> Now, some ideas (apart from the double loop to aggregate each element of
> l1 with each element of l2):
> - I wanted to use the zip function, but the new list will not aggregate
> (3,4) and (3,5)
> - Once I've the new list, I'll apply a map function (e.g. the exp of the
> values) to speed up the process
> Some help?
>
> Thanks, Mattia
> --
> http://mail.python.org/mailman/listinfo/python-list

zip wouldn't work here, you can use list comprehensions:

l = [(x, y) for x in l1 for y in l2]

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


Lists aggregation

2009-03-16 Thread mattia
I have 2 lists, like:
l1 = [1,2,3]
l2 = [4,5]
now I want to obtain a this new list:
l = [(1,4),(1,5),(2,4),(2,5),(3,4),(3,5)]
Then I'll have to transform the values found in the new list.
Now, some ideas (apart from the double loop to aggregate each element of 
l1 with each element of l2):
- I wanted to use the zip function, but the new list will not aggregate 
(3,4) and (3,5)
- Once I've the new list, I'll apply a map function (e.g. the exp of the 
values) to speed up the process
Some help?

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


Re: How to add months to a date (datetime object)?

2009-03-16 Thread Lorenzo
On Mar 15, 1:28 pm, tinn...@isbd.co.uk wrote:
> I have a date in the form of a datetime object and I want to add (for
> example) three months to it.  At the moment I can't see any very
> obvious way of doing this.  I need something like:-
>
>     myDate = datetime.date.today()
>     inc = datetime.timedelta(months=3)
>     myDate += inc
>
> but, of course, timedelta doesn't know about months. I had a look at
> the calendar object but that didn't seem to help much.
>
> --
> Chris Green

After seeing all this discussion, the best suggestion that comes to my
mind is:

Implement your own logic, and handle special cases as desired, using
calendar.monthrange as a reference to determine if the day really
exists on the new month. i.e.

from datetime import datetime
import calendar
months_to_add = 3
d = datetime.now()
if d.months + months_to_add > 12:
d.replace(year = d.year + (d.months + months_to_add)/12)
d.replace(month = (d.months + months_to_add)%12)
else:
d.replace(month = (d.months + months_to_add))
if d.day > calendar.monthrange(d.year,d.month)[1]:
# do some custom stuff i.e. force to last day of the month or skip
to the next month 

just my .02
--
http://mail.python.org/mailman/listinfo/python-list


Problem: Terminal (OS X) window exits immediately on opening. & Solution.

2009-03-16 Thread Lou Pecora
Since this happened with a Python script and some people here use OS X 
and Terminal to run scripts I thought this might be helpful.

I recently ran into this problem using Terminal and found the solution.  
I thought those who use the Terminal in OS X might be interested.

The problem appeared suddenly.  Whenever I tried to open a new window in 
Terminal I would get the message that Terminal tried to execute a 
certain file (way down in the /var directory), but the file didn't 
exist.  And the process would Exit.  Very frustrating since you can't 
use the Terminal to help find the problem.

E.g error message:

/var/tmp/folders.501/Cleanup\ At\ 
Startup/drvrSDWB_2-258580497.358.py.command; exit
-bash: /var/tmp/folders.501/Cleanup At 
Startup/drvrSDWB_2-258580497.358.py.command: No such file or directory

The Solution is to go into the preference file for the Terminal (located 
in 
/Users/your_account_name_here/Library/Preferences/com.apple.Terminal.plis
t) and open it with the Property List Editor (should open automatically 
with a double click or you might have to install the Property List 
Editor from the System CDs that came with your computer).  Under the 
heading Executionstring you will see the name of the file that the 
Terminal is choking on.  Double click the name and delete it.  Save. and 
quit the Property List Editor.  The Terminal should work normally now. 

More info.  I got this problem while running Python scripts from BBEdit 
(which automatically launches the scripts in a Terminal Window). Why it 
happened is lost on me.  I don't know if Python, BBEdit, or Terminal 
munged the property list.  At least I managed to track it down.

I hope this helps someone if you've had this problem.

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


error writing str to binary stream - fails in Python 3.0.1, works in 2.x

2009-03-16 Thread R. David Murray
walle...@gmail.com wrote:
> I am working with a bit of code that works ok in Python 2.x (tested
> fine in 2.5.4 and 2.6.1) but fails in 3.0.1.
> The code opens a file for binary output to witht the objective to
> produce a .bmp graphics file.  The code below illustrates the first of
> several like errors when a str object is attempted to be written to
> the binary file.  From what I have seen, this was a fairly common
> technique prior to 3.0.1 being released so I am assuming the type
> checking is tighter with the new version.  What is the proper way of
> doing this now, or the work around?  Any help appreciated.  -- Bill
> 
> the code:
> ---
> self.out=open(filename,"wb")
> self.out.write("BM")  # magic number
> 
> 
> 
> This the is the error output from Python:
> 
> Traceback (most recent call last):
>   File "py_mandel.py", line 19, in 
> my_bmp=kohn_bmp("out.bmp",image_width,image_height,3)
>   File "C:\Python30\py_kohn_bmp.py", line 47, in __init__
> self.out.write("BM")  # magic number
>   File "C:\Python30\lib\io.py", line 1038, in write
> raise TypeError("can't write str to binary stream")
> TypeError: can't write str to binary stream

In 3.x the 'str' type is unicode.  If you want to work with binary byte
streams, you want to use the 'bytes' type.  Bytes contstants are
written with a leading 'b', so the code snipped above would become

self.out.write(b'BM')

--
R. David Murray   http://www.bitdance.com

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


error writing str to binary stream - fails in Python 3.0.1, works in 2.x

2009-03-16 Thread wallenpb
I am working with a bit of code that works ok in Python 2.x (tested
fine in 2.5.4 and 2.6.1) but fails in 3.0.1.
The code opens a file for binary output to witht the objective to
produce a .bmp graphics file.  The code below illustrates the first of
several like errors when a str object is attempted to be written to
the binary file.  From what I have seen, this was a fairly common
technique prior to 3.0.1 being released so I am assuming the type
checking is tighter with the new version.  What is the proper way of
doing this now, or the work around?  Any help appreciated.  -- Bill

the code:
---
self.out=open(filename,"wb")
self.out.write("BM")  # magic number



This the is the error output from Python:

Traceback (most recent call last):
  File "py_mandel.py", line 19, in 
my_bmp=kohn_bmp("out.bmp",image_width,image_height,3)
  File "C:\Python30\py_kohn_bmp.py", line 47, in __init__
self.out.write("BM")  # magic number
  File "C:\Python30\lib\io.py", line 1038, in write
raise TypeError("can't write str to binary stream")
TypeError: can't write str to binary stream
--
http://mail.python.org/mailman/listinfo/python-list


Re: download x bytes at a time over network

2009-03-16 Thread Jean-Paul Calderone

On Mon, 16 Mar 2009 13:02:07 +0530, Saurabh  wrote:

I want to download content from the net - in chunks of x bytes or characters
at a time - so that it doesnt pull the entire content in one shot.


This isn't exactly how things work.  The server *sends* you bytes.  It can
send you a lot at once.  To some extent you can control how much it sends
before it waits for you to catch up, but you don't have anywhere near
byte-level control (you might have something like 32kb or 64kb level
control).

If you try downloading a large enough file and increasing the numbers in
your example, then you can probably see the behavior you were expecting.

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


Re: Encoding/decoding: Still don't get it :-/

2009-03-16 Thread Antoon Pardon
On 2009-03-13, Johannes Bauer  wrote:
> Peter Otten schrieb:
>
>> encoding = sys.stdout.encoding or "ascii"
>> for row in rows:
>> id, address = row[:2]
>> print id, address.encode(encoding, "replace")
>> 
>> Example:
>> 
> u"ähnlich lölich üblich".encode("ascii", "replace")
>> '?hnlich l?lich ?blich'
>
> A very good tip, Peter - I've also had this problem before and didn't
> know about your solution.

If you know before hand that you will be using ascii, you can eliminate
the accents, so that you will get the unaccentuated letter (followed by
a question mark if you prefer) instead of a question mark

>>> from unicodedata import normalize, combining
>>> example = u"ähnlich lölich üblich"
>>> normalised =  normalize('NFKD', example)
>>> normalised.encode("ascii", "replace")
'a?hnlich lo?lich u?blich'
>>> eliminated = u''.join(l for l in normalised if not combining(l))
>>> eliminated.encode("ascii", "replace")
'ahnlich lolich ublich'

-- 
Antoon Pardon

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


2nd Call for Papers | Extended deadline: April 07 | CENTERIS'2009 - Conference on ENTERprise Information Systems | 2nd Call for Papers

2009-03-16 Thread CENTERIS'2009 - Conference on ENTERprise Information Systems
-
Please consider contributing to and/or forwarding to the appropriate groups and 
peers the following call for papers.
(please excuse us if you received this call more than once)
-
You are receiving this email because of your research activities on the 
conference topic. 
To unsubscribe please send an email to secretar...@centeris.eiswatch.org with 
the subject "Unsubscribe python-list@python.org" 
-


- CENTERIS’2009  |  Call for Papers 
- Conference on ENTERprise Information Systems

- Ofir, Portugal, 07-09 October 2009

http://centeris.eiswatch.org
extended submission deadline (full paper):  April 07, 2009
-


Dear Sirs,

It is our great pleasure to invite you to the CENTERIS’2009 - Conference on 
ENTERprise Information Systems – aligning technology, organizations and people, 
to be held in Ofir, Portugal, organized by the Polytechnic Institute of Cávado 
and Ave and the University of Trás-os-Montes e Alto Douro.

This is the place where, from 07 to 09 October 2009, under the leitmotiv of 
Enterprise Information Systems, academics, scientists, IT/IS professionals, 
managers and solution providers from all over the world will have the 
opportunity to share experiences, bring new ideas, debate issues, introduce the 
latest developments in the field.

CENTERIS’2009 is an international conference that will address the largely 
multidisciplinary field embraced by the Enterprise Information Systems (EIS), 
from the social, organizational and technological perspectives. 
The 3-day conference follows an innovative format, previewing scientific 
sessions, tutorial and technical sessions, and simultaneously exhibitions by 
solutions providers and product presentations. 
There will also be a social program that will enable participants to get to 
know each other and informally exchange information, contacts and experiences, 
discuss projects, and incubate partnerships.

-
- Submission and Publications

Submissions will be reviewed on a double-blind review basis. 
Only original contributions will be accepted.

All accepted papers will be published in the Conference Proceedings Book (full 
texts) with ISBN and on a CD-ROM to be distributed during the conference.

Authors of a selection of around 25 papers will be invited for enhancing and 
extending their papers for inclusion in a book to be published by IGI-Global, 
to be released by early 2010. Depending on the number of high quality papers 
accepted, the Organization can consider the edition of two books, instead of 
one.

According to the Scientific Committee recommendations, authors of selected 
papers will be invited to enhance the paper for publication in:

 -  A Special Issue of the Information Resources Management Journal (IRMJ);
 -  The International Journal of Enterprise Information Systems (IJEIS);
 -  Journal of Theoretical and Applied Electronic Commerce Research (JTAER);
 -  International Journal of Information Technologies and Systems Approach 
(IJITSA);
 -  The emerging “Information and Communication Technologies for the 
Advanced Enterprise: an international journal” (ICT'ae).

At the end of this message you will find the composition of the Editorial Board.

- 
- Hotel and travel arrangements

The Conference will take place at AXIS OFIR Beach Resort Hotel in Ofir, 
Esposende, Portugal, a 4-star Hotel located in one of the most beautiful 
landscapes in the North of Portugal. The Atlantic coast of Esposende is part of 
the Natural Park of the North Coast, a protected area of great beauty.
Ofir is located in a wonderful historic and cultural region with three 
locations/zones proclaimed as UNESCO cultural World Heritage within 100 km: 
Historic Centre of Guimaraes (50Km), Historic Centre of Porto (40Km) and Alto 
Douro Wine Region.
The Hotel Axis Ofir is located 35 km north of the Oporto International Airport 
“Francisco Sa Carneiro”. It is connected by the highway A28. We suggest getting 
a taxi which cost would be around 35 Euros (one way), taking less than 30 min 
to the Hotel.
- 

For more detailed information, please visit  http://centeris.eiswatch.org

We hope to see you in Ofir.

Best wishes,
Manuela Cunha
Luís Amaral
João Varajão


- General Chair
Maria Manuela Cruz-Cunha  (mcu...@ipca.pt)
Polytechnic Institute of Cávado and Ave, Portugal

- Program Chair
Luís Amaral  (ama...@dsi.uminho.pt)
University of Minho, Portugal

- Organization Chair
João Eduardo Varajão  (jvara...@utad.pt)
University of Trás-os-Montes e Alto Douro, Portugal

- Secretariat
secretar...@centeris.eiswatch.org



- 
- Editorial Board
(This list is not complete as the invitation process is still going on)

Adamantios Koumpis, Research Programmes Division, ALTEC S.A, Grece
Adolfo Vanti, Universidade do Vale do Rio dos Sinos, Brasil
Albert Boo

Re: how to identify the file system type of a drive?

2009-03-16 Thread Tim Golden

venutaurus...@gmail.com wrote:

hi all,
 Is there any way to identify the File system type of a drive
in python in Windows? Some thing like:

C:\ -- NTFS
D:\ -- FAT32..




import win32api
import win32file

def file_system (drive_letter):
 return win32api.GetVolumeInformation (
   win32file.GetVolumeNameForVolumeMountPoint (
 "%s:\\" % drive_letter
   )
 )[4]


print file_system ("C")




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


Re: How to add months to a date (datetime object)?

2009-03-16 Thread Peter Pearson
On Sun, 15 Mar 2009 16:27:01 -0400, Roy Smith  wrote:
> In article ,
>  Chris Rebert  wrote:
>
>> Besides your behavior, one could equally well argue that a 31st repeat
>> on months without a 31st should just be dropped, or that it should
>> carry over onto the 1st of the next month (ignoring the complications
>> of February). Which behavior one needs is completely
>> context-dependent.
>
> Indeed.  For example, my wife started her current job on a
> Feb 29th.  There are significant financial events that
> happen on various anniversaries of her employment (vesting
> of stock and retirement benefits).  It really is important
> that everybody know exactly what is meant by "10 years
> from Feb 29th, on a given year", and what it means in one
> context may not mean what it means in another.

Remember Frederic, in Pirates of Penzance, who was apprenticed
to a pirate until his twenty-first birthday, but was born on
Feb 29?

-- 
To email me, substitute nowhere->spamcop, invalid->net.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Guidance on writing a top-like console

2009-03-16 Thread Hyuga
On Feb 27, 6:08 pm, ntwrkd  wrote:
> I am interested in writing an application that functions like a Unix
> or Linux top in the way it displays data.
> It should be command-line based but dynamically refreshing.
>
> I'm not sure what I should take into account or how I might go about
> implementing this?
> Any suggestions are appreciated.


Do by any chance play TF2?  I've seen someone with the username
'ntwrkd' before.  Not that it's necessarily an uncommon username, but
it was the first thing I thought of when I saw this post.

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


Re: is there an easy way to parse a nested list ?

2009-03-16 Thread Paul McGuire
On Mar 16, 4:29 am, Vlastimil Brom  wrote:
> 2009/3/16 Vlastimil Brom :
>
>
>
> > 2009/3/16 Stef Mientki :
> >> hello,
>
> >> I need to parse a nested list, given as a string, like this
>
> >> line = " A  [  B  [ C+2 ] + 3 ] "
>
> > ...
>
> >> thanks,
> >> Stef
>
> > there is a "nestedExpr" (and probably other options, I'm not aware of ...:-)
> > ...
> > regards
> > vbr
>
> Well, I thought, there was something already there in the examples for
> pyparsing, but couldn't find it first.
> check the selective pyparsing evaluator, which also supports lists:
>
> http://pyparsing.wikispaces.com/file/view/parsePythonValue.py
>

The OPs test cases aren't really valid Python lists, so nestedExpr
will have to do:


from pyparsing import oneOf, alphas, Word, nums, OneOrMore, nestedExpr

# an element within the list can be:
# - a single alphabetic letter
# - one of + - * or /
# - an unsigned integer
element = oneOf(list(alphas+"+-*/")) | Word(nums)

expr = OneOrMore(element |
nestedExpr("[", "]", content=OneOrMore(element))
)

src = " A  [  B  [ C+2 ] + 3 ] "
print expr.parseString(src)

Prints:

['A', ['B', ['C', '+', '2'], '+', '3']]

Note that this is an actual Python nested list, the []'s of the
original string have been stripped away (they aren't needed, as the
nested structure that was defined by the []'s is now represented as a
data structure with actual nesting).

Also, pyparsing is pretty forgiving about whitespace.  This same
parser, even though no whitespace is explicitly mentioned, will just
as easily parse "A[B[C+2]+3]".

-- Paul
(More pyparsing info at http://pyparsing.wikispaces.com.)
--
http://mail.python.org/mailman/listinfo/python-list


setattr() on "object" instance

2009-03-16 Thread R. David Murray
Sean DiZazzo  wrote:
> Why is it that you can setattr() on an instance of a class that
> inherits from "object", but you can't on an instance of "object"
> itself?
> 
> >>> o = object()
> >>> setattr(o, "x", 1000)
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'object' object has no attribute 'x'
> 
> >>> class Object(object):pass
> ...
> >>> o = Object()
> >>> setattr(o, "x", 1000)
> >>> o.x
> 1000
> 
> I notice that the first example's instance doesn't have a __dict__.
> Is the second way the idiom?

The lack of a __dict__ is why you can't set the attribute.
I've occasionally wanted to use instances of object as holders of
arbitrary attributes and wondered why I couldn't (from a language design
perspective).  But that was only for testing.  In real code I think I'd
always want a fully defined class.

--
R. David Murray   http://www.bitdance.com

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


Re: setup.py install and bdist_egg

2009-03-16 Thread Hyuga
On Mar 13, 4:41 pm, Jasiu  wrote:
> Hey,
>
> I work at a company where I'm lucky enough to write web apps using
> Python and WSGI :). We develop more and more stuff in Python and it's
> becoming a mess of dependencies, so we thought we would create a
> guideline for developers that describes the whole process of deploying
> a Python app on a server. Since all of our servers run Debian, all of
> our software has to be installed as Debian packages - other
> departments that don't use Python (shame on them! :D) already follow
> this policy.
>
> Here is what we have figured so far:
> 1) Write your code.
> 2) Prepare setup.py, and put names of required eggs in there.
> 3) Write a Debian wrapper that uses CDBS Python class, and put names
> of required Debian packages in there.
> 4) Build Debian package.
> 5) Done! Deploy on server and have fun :).
>
> This guideline already works pretty well for us, but I thought I could
> tweak it a little. I want to make the Debian package wrapper as thin
> as possible so that if we ever stop using Debian, we will still be
> able to deploy all of our software as eggs. This goal turned to be
> pretty challenging. I have a few questions.

Glad to see I'm not the only one with this sort of challenge.  Though
it sounds like you're already a step ahead of me in that you're
properly maintaining requirements/dependencies for your Python
packages.  When I build my Debian packages I make sure that *they*
have the correct dependencies.  But my setup.py files do not have all
their dependencies listed, so it's a pain to get everything set up
correctly when not doing it through the Debian package system.

> 1) Debian has a debian/dirs file where you can list all the
> directories that the package should create, for example those in /var/
> log, /var/lib . I already figured out that I can use setup.py
> 'install_data' keyword for that, even for empty directories. Then I
> can use 'setup.py install' command and things work great. But... How
> about eggs? I'd like my egg to somehow contain or create such
> directories. For example, I have a config file that I want to place
> in /etc directory. I can do that using 'setup.py install', but
> 'setup.py bdist_egg' will just create an egg containing etc/
> directory. Can I do something about it? Also, why doesn't an egg
> contain empty dirs that I place in install_data?

My approach to this has been to use a postinst script to copy files
out of the eggs (or when I'm not installing as an egg, from /usr/
share) to the correct locations in /etc.  However, this doesn't work
so well if you're not using a Debian package.  But see below:

> 2) What about file permissions? Can they be set by setup.py? My
> software runs as www-data user and so /var/log and /var/lib
> directories should have proper owner, group and permissions. I didn't
> figure out a way to change permissions using setup.py. In Debian I can
> use postinst script for that.

I'm also using a postinst script for configuring my system, but I want
to move away from that.  I already have a command-line tool for easily
administering certain aspects of the system.  So my plan is to
implement a "deploy" command that creates all the directories with the
correct permissions, generates the config files, and performs all the
configuration my postinst script currently does.  Then the postinst
script simply needs to call the deploy command.  That way I can take
advantage of debconf without being dependent on it.

> If anything sounds unclear, blame my bad english :).

Sounds perfectly clear to me!
--
http://mail.python.org/mailman/listinfo/python-list


Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread R. David Murray
> On Mar 16, 5:00 pm, bdb112  wrote:
> > #   is the difference between
> > print(" %d,  %d, buckle my shoe" % (1,2))
> > #   and
> > print(" %d, " + " %d, buckle my shoe" % (1,2))
> > # a bug or a feature?

It is correct behavior.  On the other hand, it is one of the, well,
bugs, that is avoided by the 'format' method in 3.x.

--
R. David Murray   http://www.bitdance.com

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


Re: PyWin32 for Python 3.x

2009-03-16 Thread cgoldberg
> Release 213 is out already:

Tim, Mark,
this is great news.. thanks for tracking 3.x so closely.  I big
barrier for me to eventually adopt 3.x is the ability to use pywin32.

thanks!

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


how to identify the file system type of a drive?

2009-03-16 Thread venutaurus...@gmail.com
hi all,
 Is there any way to identify the File system type of a drive
in python in Windows? Some thing like:

C:\ -- NTFS
D:\ -- FAT32..

so on..

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


Re: How to add months to a date (datetime object)?

2009-03-16 Thread Aahz
In article ,
John Machin   wrote:
>On Mar 16, 3:08=A0pm, a...@pythoncraft.com (Aahz) wrote:
>> In article ,
>> Roy Smith =A0 wrote:

 Besides your behavior, one could equally well argue that a 31st repeat
 on months without a 31st should just be dropped, or that it should
 carry over onto the 1st of the next month (ignoring the complications
 of February). Which behavior one needs is completely
 context-dependent.
>>>
>>>Indeed. =A0For example, my wife started her current job on a Feb 29th. =
>=A0There
>>>are significant financial events that happen on various anniversaries of
>>>her employment (vesting of stock and retirement benefits). =A0It really =
>is
>>>important that everybody know exactly what is meant by "10 years from Fe=
>b
>>>29th, on a given year", and what it means in one context may not mean wh=
>at
>>>it means in another.
>>
>> Because I'm well-aware of such issues, I would have asked to make my
>> official start date March 1. =A0;-)
>
>Which means that any goodies accruing after 4, 8, etc years are
>granted on 1 March instead of the (obvious?) 29 February.
>
>What you want is an agreement that the anniversary of commencement in
>any year is the last day of February.

You may want that; I'd rather just have less hassle.  Nobody will ever
have problems with March 1.
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

Adopt A Process -- stop killing all your children!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Upgrade Python on a Mac

2009-03-16 Thread Aahz
In article ,
Jorgen Grahn   wrote:
>
>\begin{whine}
>
>Why is Python a "Framework" under "Libraries"?  In any other Unix, a
>third-party Python installation would have been placed in /usr/local/
>or /opt/.  Also, editing a user's dotfiles while installing software
>seems cruel and unusual -- to that user, and to the other users for
>whom the newly installed software "doesn't work".
>
>\end{whine}

Because that's what Apple wants.  :-/
-- 
Aahz (a...@pythoncraft.com)   <*> http://www.pythoncraft.com/

Adopt A Process -- stop killing all your children!
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to add months to a date (datetime object)?

2009-03-16 Thread tinnews
Ned Deily  wrote:
> In article <49bd42ac$0$512$bed64...@news.gradwell.net>,
>  tinn...@isbd.co.uk wrote:
> > I was just hoping there was some calendar object in Python which could
> > do all that for me (I need the handling of 31st and February etc.)
> 
> Whatever your requirement, chances are dateutil will be of help:
> 
> 
> 
Yes, you are right, I think dateutil does what I need and thus I won't
have to reinvent the wheel.  Thank you!

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


Creating a 256 byte/block filesystem using FUSE in python

2009-03-16 Thread Sreejith K
Anyone got any idea of how to create a 256 byte/block filesystem using
FUSE in python ? How to implement block level reads/writes instead of
byte level reads/writes in fuse-python ?
--
http://mail.python.org/mailman/listinfo/python-list


Re: A request (was: how to repeat function definitions less

2009-03-16 Thread Michele Simionato
On Mar 16, 8:08 am, Dennis Lee Bieber  wrote:
> On Sun, 15 Mar 2009 23:18:54 -0500, alex goretoy
>         Many of your posts are actually exceeding the 500-line limit I've
> set in my client for down-load -- yet have nothing worthy of 500 lines!

Could this be the reason why I cannot see his messages on Google
Groups?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Encoding/decoding: Still don't get it :-/

2009-03-16 Thread Gilles Ganault
On Fri, 13 Mar 2009 14:24:52 +0100, Peter Otten <__pete...@web.de>
wrote:
>It seems the database gives you the strings as unicode. When a unicode
>string is printed python tries to encode it using sys.stdout.encoding
>before writing it to stdout. As you run your script on the windows commmand
>line that encoding seems to be cp437. Unfortunately your database contains
>characters the cannot be expressed in that encoding.

Vielen Dank for the help :) I hadn't thought about the code page used
to display data in the DOS box in XP.

It turns out that the HTML page from which I  was trying to extract
data using regexes was encoded in 8859-1 instead of UTF8, the SQLite
wrapper expects Unicode only, and it had a problem with some
characters.

For those interested, here's how I solved it, although there's likely
a smarter way to do it:


data = re_data.search(response)
if data:
name = data.group(1).strip()
address = data.group(2).strip()

#content="text/html; charset=iso-8859-1">
name  = name.decode('iso8859-1')
address = address.decode('iso8859-1')

sql = 'BEGIN;'
sql = sql + 'UPDATE companies SET name=?,address=? WHERE id=?;'
sql = sql + "COMMIT"

try:
cursor.execute(sql, (name,address,id) )
except:
print "Failed UPDATING"
raise
else:
print "Pattern not found"


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


Re: Style question - defining immutable class data members

2009-03-16 Thread Aaron Brady
On Mar 15, 9:54 pm, "Rhodri James" 
wrote:
> On Sun, 15 Mar 2009 23:26:04 -, Aaron Brady   
> wrote:
>
>
>
>
>
> > On Mar 15, 1:50 pm, "Rhodri James" 
> > wrote:
> >> On Sun, 15 Mar 2009 17:55:25 -, Aaron Brady   
> >> wrote:
>
> >> > On Mar 15, 12:39 pm, John Posner  wrote:
> >> >> (My apologies if the thread has already covered this.) I believe I  
> >> >> understand the WHAT in this situation, but I don't understand the >>  
> >> WHY  
> [snip]
> >> > Yes.  If you access an attribute, you want the search to go like this:
>
> >> > - check instance for attribute
> >> > - check class for attribute
> >> > - check base classes for attribute
>
> >> But do you, though?  The only occasion I can think of that I'd want
> >> the search to go past the instance is this "auto-initialisation",
> >> and frankly I'd rather do that in an __init__ anyway.  Perhaps
> >> static methods or class methods work that way, I don't know how
> >> the innards of the interpreter handle that.
>
> > As Bruno stated, yes, for resolving 'self.method', and other
> > descriptors.  You acknowledge that 'foo.jam' would need to identify
> > itself as coming from an instance, class, or base, since the only
> > entries in 'foo's dictionary are those attributes which are particular
> > to 'foo'.
>
> No, I don't acknowledge that.  (Note that John's original question
> was *WHY*, and you effectively gave him a *HOW* answer by asserting
> that it's what he wants.  I'm playing Devil's Advocate to an extent.)

Very valid.  Evidently I thought that the 'how' would justify it.
However, a *WHAT* in this case is pretty close to a 'why'.

You can access instance attributes and class attributes with the same
syntax.  It has the advantage that you can mix two statements into
one:

attr= x.attr
<>
if 'attr' in x.__dict__:
attr= x.__dict__[ 'attr' ]
else:
attr= x.__class__.__dict__[ 'attr' ]

Otherwise, either /1, every instance has its own entries for class
functions, and subsequent changes to the class don't affect existing
instances, or /2, every method call is of the form x.__class__.foo
( ).  They're both bad.  (...unless that's a false dilemma.)

> "self.method" is not the same object as "Class.method"; one's bound
> and the other isn't, for starters.  It's therefore by no means
> obvious that method lookup isn't being done via the instance's
> dictionary.

No.  What makes it obvious is that subsequent changes to the class
affect existing instances.

> After all, some kind of binding has to be done at
> instance creation time.  If you're telling me that it's time-
> efficient (or at least space-efficient and not horribly time-
> inefficient) to use the class dictionary and magically know to
> wrapper the call, then we've that makes things different and
> gives us a reason for wanting that search order.

It's more space efficient.  However, the additional time involved in
the 'instance-first-class-second' search, plus the process of creating
the bound method (once per access, by the way, currently), can
counterweigh or outweigh that.

> It's the same story with descriptors; in fact they mask rather
> more of the detail of what they're doing and look at first glance
> more tightly bound to the instance than the class.  Further steps
> get you to the same "why" answer, but they are further steps.

No, I did leave some of the steps to the analysis tacit.  My mistake.

> > Class attributes are grouped together in the class dictionary,
> > instance attributes are grouped together in the instance dictionary,
> > and instances need to see both.
>
> True, but they don't need to see both with instance attribute
> syntax.  That they can is what we're trying to justify here.

As above, the alternatives (explicit class access and redundant
instance membership) are bad.

> > If you have a counter-proposal, either for a wishlist for behavior, or
> > a way of arranging its implementation, I for one would entertain it,
> > even on the c-l-python newsgroup, and even though it wouldn't have
> > much of a chance of making it in to Python.
>
> Nope, no proposal.  Mildly considering one, but I thought I'd try
> understanding why what happens is considered a good thing before I
> let my hare-brainedness off the leash.

I know... that was just a tactic to get you to do the work of
enumerating the alternatives.  Bah.

> > As a side note, this argument of 'whose methods am I seeing?' has an
> > inconvenient artifact: the behavior of 'foo.method'.  'foo.method'
> > needs to refer to an instance method, due to not needing the 'self'
> > attribute respecified; while 'foo.__class__.method' needs to refer to
> > a plain function.  Python's solution is a skeleton type, that just
> > redirects 'foo.method( )' to an append of the arguments plus call.
>
> As I said, this inconvenient artefact is exactly why I didn't think
> assuming instance method lookup happened via the *class* dictionary
> was safe!

It's not.  If you assign a function to an instance attribute, the

Re: is there an easy way to parse a nested list ?

2009-03-16 Thread Vlastimil Brom
2009/3/16 Vlastimil Brom :
> 2009/3/16 Stef Mientki :
>> hello,
>>
>> I need to parse a nested list, given as a string, like this
>>
>> line = " A  [  B  [ C+2 ] + 3 ] "
>>
> ...
>>
>> thanks,
>> Stef
>>
>
> there is a "nestedExpr" (and probably other options, I'm not aware of ...:-)
> ...
> regards
> vbr
>
Well, I thought, there was something already there in the examples for
pyparsing, but couldn't find it first.
check the selective pyparsing evaluator, which also supports lists:

http://pyparsing.wikispaces.com/file/view/parsePythonValue.py

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


Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread alex goretoy
>
>   print(10 + 20 % 7)
> a bug or a feature?

It is a feature
print ((10+20) % 7)

-Alex Goretoy
http://www.goretoy.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: setattr() on "object" instance

2009-03-16 Thread Duncan Booth
Ahmad Syukri b  wrote:

> On Mar 16, 1:21 pm, Sean DiZazzo  wrote:
>> Why is it that you can setattr() on an instance of a class that
>> inherits from "object", but you can't on an instance of "object"
>> itself?
>>
>> >>> o = object()
>> >>> setattr(o, "x", 1000)
>>
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> AttributeError: 'object' object has no attribute 'x'
> 
> I suppose you cannot set attributes to instances of any built-in
> classes, i.e. int(), list() etc.

No, there are some built-in types where you can set additional attributes: 
e.g. functions.

You can set additional attributes on any class which has a __dict__ 
attribute. When you subclass an existing type your new type will always 
have a __dict__ unless you define __slots__ and the base class did not 
already have a __dict__.



> Since all classes inherit from object, I suppose the definition can be
> as simple as 'class Object:pass', and assignment can be as simple as
> 'o.x = 1000'

Inheriting from object by default is only true if you are talking about 
Python 3.x.

-- 
Duncan Booth http://kupuguy.blogspot.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyPy Progress (and Psyco)

2009-03-16 Thread James Matthews
Everything starts out small. I am sure that things will grow if there is a
demand for it...

On Mon, Mar 16, 2009 at 5:55 AM, JanC  wrote:

> andrew cooke wrote:
>
> > Fuzzyman wrote:
> >> On Mar 15, 3:46 pm, Gerhard Häring  wrote:
> > [...]
> >>> Me too. I doubt it, though. From an outside view, the project seems to
> >>> lack focus. To me, it looks like a research platform, and producing a
> >>> successor to CPython seems to be just one out of a dozen projects.
> > [...]
> >> Well, I know the guys involved and they are focused on making PyPy a
> >> practical (and importantly a faster) alternative to CPython. It has
> >> just taken a long time - but is finally showing real progress.
> >>
> >> They did get distracted along the way, but one of things that happened
> >> last year was a culling of a lot of the side projects that made it
> >> harder to make progress on the core goals.
> >
> > This is so good to hear.  I had exactly the same concerns as Gerhard.
> > Thanks for posting some information.
>
> I think the period as a research platform (IIRC the project was funded by a
> research grant from the EU after all[*]) was maybe necessary to get where
> they are now...?
>
>
> [*] I'm happy to see at least this part of my taxes being spent for
> something good...  ;-)
>
> --
> JanC
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.astorandblack.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: VMware and pywin32 error...

2009-03-16 Thread James Matthews
The issue seems to be with your windows installation. Try getting another
copy etc... There shouldn't be any issues I have tried and used both
seamlessly

On Mon, Mar 16, 2009 at 7:55 AM, dash dot <""wernermerkl\"@fujitsu(dash)
siemens.com"> wrote:

> Joshua Kugler schrieb:
>
>> dot wrote:
>>
>>> has anyone experience with installing Python and pywin32 to Windows XP
>>> Pro running in a VMware environment?
>>>
>>> At the end of installing pywin32 I get following error:
>>>
>>> 
>>> Traceback (most recent call last):
>>>   File "", line 601, in 
>>>   File "", line 311, in install
>>>   File "", line 149, in LoadSystemModule
>>> ImportError: DLL load failed: This application has failed to start
>>> because the application configuration is incorrect. Reinstalling the
>>> application may fix this problem.
>>> 
>>>
>>> I use following versions:
>>>
>>> VMware Workstation 6.5.0 build-118166
>>> Microsoft Windows XP Professional English Build 2600
>>> added SP1 and than SP3
>>> Python 2.6.1
>>> pywin32 213
>>>
>>
>> I've installed and run Python and pywin32 in a VMWare environment and have
>> had no trouble.  This is not an issue with VMWare. Something is
>> misconfigured in your XP and/or Python install.  I'm assuming you
>> installed
>> Python before installing pywin32?
>>
>> j
>>
>>  Yes. Of course. Python 2.6.1 installs with no problem.
>
> BTW: I get the same result, if I use Microsoft VirtualPC 2007 instead of
> VMware...
>
> Werner
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.astorandblack.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: is there an easy way to parse a nested list ?

2009-03-16 Thread Aaron Brady
On Mar 15, 6:44 pm, Stef Mientki  wrote:
> hello,
>
> I need to parse a nested list, given as a string, like this
>
> line = " A  [  B  [ C+2 ] + 3 ] "
>
> ( I probably can do it with find, but I guess that's not the most
> elegant way, besides recusrion is not my strongest point)
>
> which should be parsed so I get an list from inner to outer side (don't
> know if these are the correct words),
> but I should like to have a list or tuple for tis case:
>
> parsed = [ C+2,  B[C+2]+3,   A  [  B  [ C+2 ] + 3 ] ]
>    or (last term is not needed, as well as the constants aren't)
> parsed = [ C,  B[C+2] ]
>
> this all, to improve the improved error / exception message even more ;-)
>
> thanks,
> Stef

Hi Stef,

This looks like what you want:

def parse_list( s, start= 0 ):
x= []
i= start
while i< len( s ):
c= s[ i ]
if c== '[':
y, i= parse_list( s, i+ 1 )
x= x+ y
if c== ']':
return x+ [ s[start: i ] ], i
i+= 1
return x+ [ s ]

line = " A  [  B  [ C+2 ] + 3 ] "
print( parse_list( line ) )
#[' C+2 ', '  B  [ C+2 ] + 3 ', ' A  [  B  [ C+2 ] + 3 ] ']

line = " A  [  B  [ C+2 ] [ D+2 ] + 3 ] "
print( parse_list( line ) )
#[' C+2 ', ' D+2 ', '  B  [ C+2 ] [ D+2 ] + 3 ', ' A  [  B  [ C+2 ] [ D
+2 ] + 3 ] ']

...So long as you don't have any brackets inside strings or what not.
It just admits two special characters, '[' and ']'.
--
http://mail.python.org/mailman/listinfo/python-list


Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread John Machin
On Mar 16, 7:00 pm, bdb112  wrote:
> #   is the difference between
> print(" %d,  %d, buckle my shoe" % (1,2))
> #   and
> print(" %d, " + " %d, buckle my shoe" % (1,2))
> # a bug or a feature?

Here's a question for you:
Is the difference between
   print(30 % 7)
and
   print(10 + 20 % 7)
a bug or a feature?

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


Re: multiprocessing.sharedctypes and built-in locks

2009-03-16 Thread Aaron Brady
On Mar 15, 11:42 pm, Ahmad Syukri b  wrote:
> On Mar 15, 6:19 am, Aaron Brady  wrote:
>
>
>
> > Your code hung on my machine.  The call to 'main()' should be in an
> > 'if __name__' block:
>
> > if __name__== '__main__':
> >     main()
>
> > Is it possible you are just seeing the effects of the non-atomic
> > '__iadd__' operation?  That is, the value is read, added, and written
> > at different times, between which other processes might have
> > intervened.
>
> I've forgotten to remove ' gl.append(mp.Lock()) ' from the second
> code.
>
> Anyways if what you said is true, then why doesn't the documentation
> say so?

I couldn't find it either.  It's not one of the guarantees that Python
makes.  Operations aren't atomic by default, such as unless stated
otherwise.  Though it does seem counterintuitive to have to write:

with a_lock:
a+= 1

> I also realized that the created lock's release and acquire
> methods are also imbued to the created shared object, and this is also
> undocumented.

Sorry, I don't follow you.  By the way, your first example didn't
produce the expected result on my machine-- even with the 'if
__name__' statement.
--
http://mail.python.org/mailman/listinfo/python-list


Re: is there an easy way to parse a nested list ?

2009-03-16 Thread Vlastimil Brom
2009/3/16 Stef Mientki :
> hello,
>
> I need to parse a nested list, given as a string, like this
>
> line = " A  [  B  [ C+2 ] + 3 ] "
>
...
>
> thanks,
> Stef
>

Hi,
I guess, you can use e.g. pyparsing;
there is a "nestedExpr" (and probably other options, I'm not aware of ...:-)
Check the example
http://pyparsing.wikispaces.com/file/view/nested.py
 or othere to see, if you can adapt it for your needs.

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


Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread bdb112
#whoops, the first output is actually

 1,  2, buckle my shoe

# in case it wasn't obvious


On Mar 16, 5:00 pm, bdb112  wrote:
> #   is the difference between
> print(" %d,  %d, buckle my shoe" % (1,2))
> #   and
> print(" %d, " + " %d, buckle my shoe" % (1,2))
> # a bug or a feature?
>
> First output
> ... print(" %d " + " %d, buckle my shoe" % (1,2))
>
> Second output
> TypeError: not all arguments converted during string formatting
>
> Version Info:
> Python 2.5.1 (r251:54863, Oct 30 2007, 13:54:11)
> [GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2
>
> also
>
> Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
> (Intel)] on win32

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


print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread bdb112
#   is the difference between
print(" %d,  %d, buckle my shoe" % (1,2))
#   and
print(" %d, " + " %d, buckle my shoe" % (1,2))
# a bug or a feature?

First output
... print(" %d " + " %d, buckle my shoe" % (1,2))

Second output
TypeError: not all arguments converted during string formatting

Version Info:
Python 2.5.1 (r251:54863, Oct 30 2007, 13:54:11)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2

also

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
(Intel)] on win32
--
http://mail.python.org/mailman/listinfo/python-list


Re: tkinter: loading file before entering mainloop

2009-03-16 Thread Eric Brunel
Peter Billam wrote:
>> Peter Billam wrote:
>>   window = MainWindow(application)
>>   if (len(sys.argv) > 1) and os.path.exists(sys.argv[1]):
>>   window.loadFile(sys.argv[1])
>>   application.mainloop()
>>   File "./midimix", line 465, in loadFile
>> space0.grid(row=grid_row,
>>  pady=round(0.5*(ymid[track_num]-ymid[track_num-1]))-50)
>>   ...
>>   _tkinter.TclError: bad pad value "-50": must be positive screen distance
>> presumably because the window doesn't have dimensions before mainloop
>> is entered.  Can I force the window to be laid out before entering
>> mainloop? Or can I invoke loadFile() after mainloop has started ?
>
> On 2009-03-14, Peter Otten <__pete...@web.de> wrote:
>> The latter. Try
>> application.after_idle(window.loadFile, sys.argv[1])
>
> Thank you! That almost worked :-) It opened a window (which it didn't
> do last time), and it laid out the frames and so on apparently OK,
> and even posted a "Loaded v.mid" message on the StatusBar, but then
> just drew a couple of zero-thickness lines right at the top of the
> canvas, and failed with the same message:
>   File "./midimix", line 465, in loadFile
> space0.grid(row=grid_row,
>  pady=round(0.5*(ymid[track_num]-ymid[track_num-1]))-50)
>   File "/usr/local/lib/python3.0/tkinter/__init__.py",
>line 1845, in grid_configure
> + self._options(cnf, kw))
>   _tkinter.TclError: bad pad value "-50": must be positive screen distance
>
> but I say "almost" because I googled after_idle, and the very similar:
> application.after(500, window.loadFile, sys.argv[1])
> does work, exactly as intended :-) except of course that it's a
> race condition, and will fail for very impatient people or on very
> slow machines.  On my machine it still works with 20ms, but fails
> with 10ms.  Is there one extra magic trick I need to know?

I had the same kind of problems with the latest tcl/tk version (8.5):
apparently, the interface goes idle before all widgets are completely
displayed, and tricks like these - that used to work with former tcl/tk
version - now fail...

You may have a better chance with a binding on the '<>' virtual
event, which will trigger when your widget changes its size. You just have to
make sure it'll trigger only once, even if the user resizes the window while
your script is running... The binding should be set on the widget you query to
get its dimensions.

> I also tried invoking after_idle on the canvas widget:
>window.canvas.after_idle(window.loadFile, sys.argv[1])
> but that fails with the same message.
> (I am using python 3.0.1 in case that's, er, relevant.)

On tcl/tk level, 'after idle' is actually a command that doesn't act on a
widget, so calling after_idle on any widget will have exactly the same
behaviour.


On a more general level, if you want to have the same script that can be
called either from a GUI or from the command line, you might want to separate
your "functional" code from the GUI aspects, meaning have a module or a set of
modules containing the part that actually does something, and doesn't know
anything about from where it is called, and another module or set of modules
for the GUI and/or the CLI, which display things nicely and call the first
part when it has to actually do something. This would avoid problems like the
one you have.

> Thanks for your help,  Regards,  Peter

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


Re: tkinter: loading file before entering mainloop

2009-03-16 Thread Peter Billam
Peter Billam wrote:
>> They're multiplied up from
>>   canvas_height = self.canvas.winfo_height()
>> so I guess mainloop already think it's idle, while grid is still
>> taking 10ms to work out what goes where.
 
On 2009-03-15, John McMonagle  wrote:
> You need to query the requested width and height for windows which
> are not yet realised.
> canvas_height = self.canvas.winfo_reqheight()

Good suggestion: it didn't work for me, perhaps because I just ask for
an overall window geometry, then leave it to grid to assign as much
as possible to the canvas?This does the job:

num_retries = 0
  ...
canvas_height = self.canvas.winfo_height()
global num_retries
if canvas_height < 5:  # is 1 in the 10ms it takes for grid to work
if num_retries > 4:
print("loadFile: can't get canvas height",file=sys.stderr)
num_retries = 0
return
application.after(50, self.loadFile, sys.argv[1])
num_retries += 1
return

though I'm not quite sure how :-) because
application = tkinter.Tk()
at the top level, and I haven't had to declare
global application
within loadFile...
I am a python newbie, so things mysterious to me do happen.

Regards,  Peter

-- 
Peter Billam   www.pjb.com.auwww.pjb.com.au/comp/contact.html
--
http://mail.python.org/mailman/listinfo/python-list


download x bytes at a time over network

2009-03-16 Thread Saurabh
I want to download content from the net - in chunks of x bytes or characters
at a time - so that it doesnt pull the entire content in one shot.

import urllib2
url = "http://python.org/";
handler = urllib2.urlopen(url)

data = handler.read(100)
print """Content :\n%s \n%s \n%s""" % ('=' * 100, data, '=' * 100)

# Disconnect the internet

data = handler.read(100) # I want it to throw an exception because it cant
fetch from the net
print """Content :\n%s \n%s \n%s""" % ('=' * 100, data, '=' * 100) # But
still works !

Apparently, handler = urllib2.urlopen(url) takes the entire data in buffer
and handler.read(100) is just reading from the buffer ?

Is it possible to get content from the net in chunks ? Or do I need to use
HTTPClient/sockets directly ?

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


Re: A request (was: how to repeat function definitions less

2009-03-16 Thread alex goretoy
sorry, I'll try to keep it cool
-Alex Goretoy
http://www.goretoy.com



On Mon, Mar 16, 2009 at 2:08 AM, Dennis Lee Bieber wrote:

> On Sun, 15 Mar 2009 23:18:54 -0500, alex goretoy
>  declaimed the following in
> gmane.comp.python.general:
>
> > what is I just set
> > "colors": self.opt['arg_opts_options']['imp_colors']
> >
> > then they are both pointing to the same place, correct?
> >
> > -Alex Goretoy
> > http://www.goretoy.com
> >
> >
>Could you PLEASE learn to trim quoted material -- especially...
> >
> > On Sun, Mar 15, 2009 at 11:16 PM, alex goretoy
> > wrote:
> >
>
> ... when replying to yourself!
>
>This (the message I'm replying too) has just FIVE lines of new text,
> but has a 4KB binary signature, and logs in as 180 lines in my news
> client!
>
>Many of your posts are actually exceeding the 500-line limit I've
> set in my client for down-load -- yet have nothing worthy of 500 lines!
> --
>WulfraedDennis Lee Bieber   KD6MOG
>wlfr...@ix.netcom.com   wulfr...@bestiaria.com
>HTTP://wlfraed.home.netcom.com/
>(Bestiaria Support Staff:   web-a...@bestiaria.com)
>HTTP://www.bestiaria.com/
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Flags in fuse python

2009-03-16 Thread Sreejith K
Hi,

I'm writing a file system under fuse-python. The main problem I'm
facing now is that the flags which are provided by the fuse module
when r/w are called, are screwing up the situation.

I wrote a file class for fuse as shown below.

class FlusterFile(object):
def __init__(self, path, flags, *mode):
global WRITE_METHOD
global NORMAL_WRITE
global SNAP_WRITE
global FRESH_SNAP
tf.writelines("File initiating..\n")
curdir = GetDirPath('.' + path)
snapdir = '.' + path + '_snaps'
snap_cnt = 0
if os.path.exists(snapdir):
snap_cnt = len(os.listdir(snapdir))
elif FRESH_SNAP == 1:
os.mkdir(snapdir)
if FRESH_SNAP == 1:
tf.writelines("Creating Fresh Snap\n")
tf.writelines("File flags: %s mode: %s\n" % 
(flags,mode))
### FIXME ###
self.file = os.fdopen(os.open(snapdir + 
"/snap%s" % repr(snap_cnt
+1), flags),flag2mode(flags))
self.fd = self.file.fileno()
WRITE_METHOD = SNAP_WRITE
FRESH_SNAP = 0
snap_cnt += 1
tf.writelines("Fresh Snap created %s %s %s\n" %
(WRITE_METHOD,SNAP_WRITE,NORMAL_WRITE))
elif snap_cnt is 0:
tf.writelines("Initiating Normal File...\n")
self.file = os.fdopen(os.open("." + path, 
flags, *mode),flag2mode
(flags))
self.fd = self.file.fileno()
WRITE_METHOD = NORMAL_WRITE
else:
tf.writelines("Initiating latest Snap file..\n")
self.file = os.fdopen(os.open(snapdir + 
"/snap%s" % repr
(snap_cnt), flags, *mode),flag2mode(flags))
self.fd = self.file.fileno()
WRITE_METHOD = SNAP_WRITE

This init is called when we are accessing a file for r/w.

Suppose the filesystem source is named fluster.py. (the filesystem
mirrors files under /mnt/gfs_local to /fluster). When I set the
FRESH_SNAP variable to 1 the error occurs and no file gets created.

[r...@sreejith fuse]# ./flusterbeta.py /fluster/
[r...@sreejith fuse]# echo 'revenge' >> /fluster/fuse/fuse.txt
-bash: /fluster/fuse/fuse.txt: No such file or directory

Here I'm trying to pass the new data to a new snap file, which is to
be created (but fuse doesn't allow this)
Does this mean the fuse checks if the file is existing or not before
it generates the appropriate flags ?
--
http://mail.python.org/mailman/listinfo/python-list