On Thu, 27 Jan 2005 14:20:25 +0100 (CET), [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > [EMAIL PROTECTED] > > You can reach the person managing the list at > [EMAIL PROTECTED] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > > Today's Topics: > > 1. how to pass attribute name via sys.argv (Felix Hebeler) > 2. Re: how to pass attribute name via sys.argv (Wolfram Kraus) > 3. Re: how to pass attribute name via sys.argv (Gilles Lenfant) > 4. Re: Please suggest on the book to follow (Satchidanand Haridas) > 5. Re: redirect of standard output of jython to JTextArea > (Jan Gregor) > 6. Point of Sale (Andreas Pauley) > 7. Re: Please suggest on the book to follow (Ola Natvig) > 8. a question about boost.python (Li Daobing) > 9. Re: What's so funny? WAS Re: rotor replacement (Lucas Raab) > 10. Re: exclude binary files from os.walk (Mark McEahern) > 11. Re: import hook, overwrite import? (Steve Holden) > > > > ---------- Forwarded message ---------- > From: Felix Hebeler <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 13:48:28 +0100 > Subject: how to pass attribute name via sys.argv > Hi all, > I am doing some Python scripting for a while, but I'm not too deep into > it yet. So I have a problem I can't solve. > > I need to call an object attribute: > > value = object.attrName[0] > > the problem is, that the attribute name can only be specified at runtime. > > So what I have is something like > > >>> attrName = sys.argv[1] > >>> attrName > 'cellsize' > > and I need to pass it on so I can call > > value = object.cellsize[0] > > Can this be done using Python? > > Thanks for any hints > > Cheers > Felix > > > > ---------- Forwarded message ---------- > From: Wolfram Kraus <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 13:53:26 +0100 > Subject: Re: how to pass attribute name via sys.argv > Felix Hebeler wrote: > > Hi all, I am doing some Python scripting for a while, but I'm not too > > deep into it yet. So I have a problem I can't solve. > > > > I need to call an object attribute: > > > > value = object.attrName[0] > > > > the problem is, that the attribute name can only be specified at > > runtime. > > > > So what I have is something like > > > >>>> attrName = sys.argv[1] attrName > > 'cellsize' > > > > and I need to pass it on so I can call > > > > value = object.cellsize[0] > Use getattr: > value = getattr(object, attrName)[0] > > > > > Can this be done using Python? > > > > Thanks for any hints > > > > Cheers Felix > > HTH, > Wolfram > > > > ---------- Forwarded message ---------- > From: Gilles Lenfant <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 13:57:02 +0100 > Subject: Re: how to pass attribute name via sys.argv > Felix Hebeler a écrit : > > Hi all, > > I am doing some Python scripting for a while, but I'm not too deep into > > it yet. So I have a problem I can't solve. > > > > I need to call an object attribute: > > > > value = object.attrName[0] > > > > the problem is, that the attribute name can only be specified at runtime. > > > > So what I have is something like > > > > >>> attrName = sys.argv[1] > > >>> attrName > > 'cellsize' > > > > and I need to pass it on so I can call > > > > value = object.cellsize[0] > > > > > > Can this be done using Python? > > > > Thanks for any hints > > > > Cheers > > Felix > > The builtin "setattr" is your friend. > "object" is now a reserved (builtin) name, use "objekt" instead. > > class Foo(object): > pass > objekt = Foo() > attrName = sys.argv[1] > values = ['foo', 'bar', 'whatever'] > setattr(objekt, attrName, values) > > HTH > > -- > Gilles > > > > ---------- Forwarded message ---------- > From: Satchidanand Haridas <[EMAIL PROTECTED]> > To: santanu <[EMAIL PROTECTED]> > Date: Thu, 27 Jan 2005 18:34:17 +0530 > Subject: Re: Please suggest on the book to follow > Hi, > > Probably the best resources for learning Python are available online. > Here are a few sites that you might find helpful: > > 1. http://byteofpython.info/ > > 2. http://www.diveintopython.org/ -- Writted by Mark Pilgrim, covers > many advanced material. The site says /"Dive into Python"/ is a "Python > book for experienced programmers." > > 3. http://gnosis.cx/TPiP/ -- "Site for Text Processing in Python", a > book by David mertz. You will find many other very good Python related > material on his website. > > regards, > Satchit > > ---- > Satchidanand Haridas (sharidas at zeomega dot com) > > ZeOmega (www.zeomega.com) > Open Minds' Open Solutions > > #20,Rajalakshmi Plaza, > South End Road, > Basavanagudi, > Bangalore-560 004, India > > santanu wrote: > > >Hi all, > > > >I know a little python (not the OOP part) learnt by studying the online > > > >tutorial. Now I would like to learn it more thoroughly. > > > >I have access to 'Programming Python' which I liked (on flipping > >through the > >pages), but the problem is it deals only with version 2.0 of Phython. > > > >So, I would be glad if you could suggest me whether it would be really > >a good > >idea to learn from this book. In other words, will I have to unlearn > >too much > >after I complete this book (by the time I am done with this book, I > >believe > >we will be having Python 2.6 or so). > > > >Please suggest. > > > >Regards, > >Santanu > > > > > > > > > > ---------- Forwarded message ---------- > From: Jan Gregor <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 13:53:45 +0100 > Subject: Re: redirect of standard output of jython to JTextArea > problem solved. > > in class: > > sys.stdout = StdOutRedirector(self) > > class StdOutRedirector: > def __init__(self, console): > self.console = console > > def write(self, data): > #print >> sys.stderr, ">>%s<<" % data > if data != '\n': > # This is a sucky hack. Fix printResult > self.console.textArea.append(data) > > Jan > > Jan Gregor wrote: > > Hello > > > > I want to redirect output of jython's functions print and println to > > JTextArea component. Is it possible ? > > > > I tried this (swingConsole.textArea is instance): > > > > In my class > > > > self.printStream= MyPrintStream(System.out) > > System.setOut(self.printStream) > > > > ---------------------------------------------------- > > class MyPrintStream (PrintStream): > > > > def println (str): > > swingConsole.textArea.append(str) > > > > def print (str): > > swingConsole.textArea.append(str) > > > > > > Output is still directed to standard output. > > > > > > Thanks for help, > > Jan > > > > ---------- Forwarded message ---------- > From: Andreas Pauley <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 15:07:47 +0200 (SAST) > Subject: Point of Sale > Hi, > > My company has given me a rather cool project: > I have to provide them with an open-source python-based point-of-sale / > cash register system that can integrate with their existing ERP backend. > > The project will include development to ensure that the features they > require are included in the open-source POS system. > > Can you recommend anything that I can use? > > Regards, > Andreas > > > > ---------- Forwarded message ---------- > From: Ola Natvig <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 14:02:19 +0100 > Subject: Re: Please suggest on the book to follow > santanu wrote: > > Hi all, > > > > I know a little python (not the OOP part) learnt by studying the online > > > > tutorial. Now I would like to learn it more thoroughly. > > > > I have access to 'Programming Python' which I liked (on flipping > > through the > > pages), but the problem is it deals only with version 2.0 of Phython. > > > > So, I would be glad if you could suggest me whether it would be really > > a good > > idea to learn from this book. In other words, will I have to unlearn > > too much > > after I complete this book (by the time I am done with this book, I > > believe > > we will be having Python 2.6 or so). > > > > Please suggest. > > > > Regards, > > Santanu > > > > I realy would recomend Practival Python it's a wery good book which I > think it's written for 2.2 or 2.3, but it's got all the basic modern > python aspects like new style classes. > > http://www.amazon.com/exec/obidos/tg/detail/-/1590590066/qid=1106830797/sr=8-1/ref=sr_8_xs_ap_i1_xgl14/104-9460635-7128701?v=glance&s=books&n=507846 > > -- > -------------------------------------- > Ola Natvig <[EMAIL PROTECTED]> > infoSense AS / development > > > > ---------- Forwarded message ---------- > From: "Li Daobing" <[EMAIL PROTECTED]> > To: python-list@python.org > Date: 27 Jan 2005 05:05:44 -0800 > Subject: a question about boost.python > I can't use .def(str(self)) > I write a simple example, without `str', I can build it well, but with > this one, I can't build > > //Rational.cpp > #include <boost/python.hpp> > #include <iostream> > > using namespace std; > using namespace boost::python; > > class Rational > {}; > > ostream& operator<<(ostream& os, Rational r){ > return os; > } > BOOST_PYTHON_MODULE(Rational) > { > class_<Rational>("Rational") > .def(str(self)) // __str__ > ; > } > // end. > > I don't know how to write Jamfile, so I write a Makefile, it works if i > don't use .def(str(self)) > > # Makefile > CC = g++ > > CFLAGS = -Wall -W -fPIC -I/usr/include/boost \ > -I/usr/include/python2.3 -DBOOST_PYTHON_DYNAMIC_LIB \ > -O2 > > LDFLAGS = -L/usr/local/lib -lboost_python -L/usr/lib/python2.3 \ > -Wl,-rpath-link,. -fPIC > > CXXFLAGS = $(CFLAGS) > > SLIB = hello.so Rational.so > > all: $(SLIB) > > %.so : %.o > /usr/bin/objcopy --set-section-flags .debug_str=contents,debug > $^ > $(CC) $(LDFLAGS) $^ -shared -o $@ > > clean : > rm -f $(WORLD) $(OBJS) > # end. > > or a simple setup.py, it also works if I don't use `str' > > # setup.py > from distutils.core import setup, Extension > > ext_modules = [Extension('Rational', ['Rational.cpp'], > define_macros=[('BOOST_PYTHON_DYNAMIC_LIB', > None)], > libraries=['boost_python'])] > > setup(name="itcc", > version="0.2.2", > author='Li Daobing', > author_email='[EMAIL PROTECTED]', > ext_modules = ext_modules > ) > # end. > > This is the error message: > $ make > g++ -Wall -W -fPIC -I/usr/include/boost -I/usr/include/python2.3 > -DBOOST_PYTHON_DYNAMIC_LIB -O2 -c -o Rational.o Rational.cpp > Rational.cpp: In function `std::ostream& operator<<(std::ostream&, > Rational)': > Rational.cpp:10: warning: unused parameter `Rational r' > /usr/include/boost/python/def_visitor.hpp: In static member function > `static > void boost::python::def_visitor_access::visit(const V&, classT&) > [with V = > boost::python::def_visitor<boost::python::api::object>, classT = > boost::python::class_<Rational, > boost::python::detail::not_specified, > boost::python::detail::not_specified, > boost::python::detail::not_specified>] > ': > /usr/include/boost/python/def_visitor.hpp:67: instantiated from `void > boost::python::def_visitor<DerivedVisitor>::visit(classT&) const [with > classT = boost::python::class_<Rational, > boost::python::detail::not_specified, > boost::python::detail::not_specified, > boost::python::detail::not_specified>, DerivedVisitor = > boost::python::api::object]' > /usr/include/boost/python/class.hpp:225: instantiated from > `boost::python::class_<T, X1, X2, X3>& boost::python::class_<T, X1, X2, > X3>::def(const boost::python::def_visitor<Derived>&) [with Derived = > boost::python::api::object, W = Rational, X1 = > boost::python::detail::not_specified, X2 = > boost::python::detail::not_specified, X3 = > boost::python::detail::not_specified]' > Rational.cpp:15: instantiated from here > /usr/include/boost/python/def_visitor.hpp:31: error: no matching > function for > call to > `boost::python::api::object::visit(boost::python::class_<Rational, > boost::python::detail::not_specified, > boost::python::detail::not_specified, > boost::python::detail::not_specified>&) const' > make: *** [Rational.o] Error 1 > > > > ---------- Forwarded message ---------- > From: Lucas Raab <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 13:12:07 GMT > Subject: Re: What's so funny? WAS Re: rotor replacement > <snip> > > > > > As long as we are discussing cryptography, what's wrong with m2crypto? > > > > http://sandbox.rulemaker.net/ngps/m2/ > > > > Why not incorporate it into the standard distribution? > > > > Or, what about Andrew Kuchling's crypto toolkit? > > > > http://www.amk.ca/python/code/crypto.html > > > > <snip> > > Umm, is it just me or did we just discuss the legal issues of that?? > > > > ---------- Forwarded message ---------- > From: Mark McEahern <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 07:18:14 -0600 > Subject: Re: exclude binary files from os.walk > The OP wrote: > > > Is there an easy way to exclude binary files (I'm working on Windows > XP) from the file list returned by os.walk()? > > Sure, piece of cake: > > #!/usr/bin/env python > > import os > > def textfiles(path): > include = ('.txt', '.csv',) > for root, dirs, files in os.walk(path): > for name in files: > prefix, ext = os.path.splitext(name) > if ext.lower() not in include: > continue > filename = os.path.join(root, name) > yield filename > > path = os.getcwd() > for name in textfiles(path): > print name > > ;-) > > // m > > > > ---------- Forwarded message ---------- > From: Steve Holden <[EMAIL PROTECTED]> > To: python-list@python.org > Date: Thu, 27 Jan 2005 08:14:02 -0500 > Subject: Re: import hook, overwrite import? > Kartic wrote: > > > Hi Torsten, > > > > If you want to use other methods to import (other than good ole file > > system), yes, you can create an importer class and register it as an > > importer module, that import will use to search and import. > > > > For example, it is possible to use zip imports (this functionality is > > already builtin) to import from a zip archive. > > py>>> import zlib # required > > py>>> import sys > > py>>> sys.path.append('/location/to/zippedmodules.zip') > > py>>> import testzip > > py>>> testzip.__file__ > > '/location/to/zippedmodules.zip/testzip,py' > > > > To generally do it, you have to: > > 1. Create a class that provides a load_module method that returns a > > module type. > > 2. Install your class as a hook using > > sys.path_hooks.append(your_importer_class) > > > > Please take a look at the imp module : > > http://docs.python.org/lib/module-imp.html for a complete description > > on accessing the import internals. There is also a simple example in > > this section. > > > > Is this is what you are looking for? > > > > Thanks, > > --Kartic > > PS: This about how much I know...the more I find out, I will share :-) > > > I will just chime in to say I too am looking for information in this > area. I hope to put some sort of BoF or Open Space event together for > people wishing to learn about (and teach about) the import system from > PEP 302 at PyCon this year. > > Early bird registration rates are still available today and tomorrow! > > regards > Steve > > > -- > http://mail.python.org/mailman/listinfo/python-list > >
-- Atte, Eduardo Henríquez A. 9-6975236 -- http://mail.python.org/mailman/listinfo/python-list