Re: Accessors in Python (getters and setters)
mystilleef ha scritto: > Methods are used to perform actions. Data attributes usually aren't. We > are on different planes. You aren't thinking pythonic. You should not make any difference between accessing an attribute and accessing a function. They both just need to receive the right data to process (and the module doc must tell you wich is it). There is of course many python code wich doesn't use properties, but that's up to the developer: everybody write the way they like. You could also find code with both getter/setter AND properties. well used properties make your code cleaner, but if you don't find yourself confortable with them, just don't use them, but never forget them. Riccardo -- http://mail.python.org/mailman/listinfo/python-list
Re: Depricated String Functions in Python
Steve Holden ha scritto:
> Anoop wrote:
> > Thanks Stefen
> >
> > let me be more specific how would i have to write the following
> > function in the deprecated format
> >
> > map(string.lower,list)
> >
> To avoid the deprecated usage you would use the unbound method of the
> str type (that's the type of all strings):
>
> >>> lst = ['Steve', 'Holden']
> >>> map(str.lower, lst)
> ['steve', 'holden']
> >>>
This isn't exactly equal to use string.lower, because this work with
just encoded strings, when string.lower works with unicode too.
I'm used to have a "lower" func like this one
def lower(x): return x.lower()
to use in map. Of course it's a problem when you need many different
methods.
A solution could be something like this
>>> def doit(what):
...def func(x):
... return getattr(x,what)()
...return func
...
>>> map(doit('lower'),['aBcD',u'\xc0'])
['abcd', u'\xe0']
>>> map(doit('upper'),['aBcD',u'\xc0'])
['ABCD', u'\xc0']
The best is to use in advance just unicode or encoded strings in your
program, but this is not always possible :-/
Riccardo Galli
--
http://mail.python.org/mailman/listinfo/python-list
prog1 | prog2 . How not to make prog2 block if not piped?
I googled around, but couldn't understand how to solve this problem. I have 2 scripts # script1.py # print 'something' #script2.py x=sys.stdin.read() print 'passed' if I run script1.py | script2.py all goes well. But if I run just script2.py the program blocks waiting forever for input. On *nix I used select.select to solve this problem, but on windows? I read that maybe I should use, from win32api, GetStdHandle and WaitForMultipleObjects, but how to do it it's far from my knowledge. Any help? Thank you, Riccardo -- http://mail.python.org/mailman/listinfo/python-list
Re: prog1 | prog2 . How not to make prog2 block if not piped?
imcs ee ha scritto: > do u really need read something even when you run the scripts2.py directly? > why not just change script2.py to > #script2.py > if __name__ == "__main__": > x=sys.stdin.read() > print 'passed' > else: > print 'passed from else branch' > > is it what you want? or anything i misunderstand. it won't do. clever btw. Script2 is not a module, it's a program that _could_ receive input via pipe. -- http://mail.python.org/mailman/listinfo/python-list
Re: prog1 | prog2 . How not to make prog2 block if not piped?
Steve Holden ha scritto: > When you run it "standalone" you should give it some input - type some > text then enter ^D (on Unix-like systems) or ^Z (on Windows). How else > do you expect read() to return anything? It *has* to read to the end fo > the file before it returns a value. > > regards > Steve you've got reason. I must read my command line options, if then there is still text I use that, otherwise I read from stdin. If nothing was piped, the user must complete the work. Thank you all, Riccardo -- http://mail.python.org/mailman/listinfo/python-list
Re: PyGTK and Py2Exe troubles
Tim N. van der Leeuw ha scritto: > I tried to create a windows executable of a pygtk program. My first > attempt worked, kinda, except that no themes were applied and no > readable fonts were found by pango; so all letters where just empty > squares. But the program worked. > > I looked up some docs, found the following recipe on the PyGTK Wiki > site: > http://starship.python.net/crew/theller/moin.cgi/Py2exeAndPyGTK > > I followed those instructions to convert my setup.py file; everything > still worked the same as before. versions of python,gtk,pygtk? wich windows? wich installer of gtk have you used? did you install pycairo too? try again with these one, if different from yours gtk -> http://gladewin32.sourceforge.net pygtk/pycairo -> http://www.mapr.ucl.ac.be/~gustin/win32_ports/ bye, Riccardo -- http://mail.python.org/mailman/listinfo/python-list
