Re: setting an attribute

2007-05-16 Thread Bruno Desthuilliers
7stud a écrit : > "When you bind (on either a class or an instance) an attribute whose > name is not special...you affect only the __dict__ entry for the > attribute(in the class or instance, respectively)." > > In light of that statement, how would one explain the output of this > code: > > clas

Re: Distributing programs depending on third party modules.

2007-05-16 Thread Bruno Desthuilliers
Kevin Walzer a écrit : > Bruno Desthuilliers wrote: > >>> What platform are you doing this on? On the Linux platform, >>> "dependency hell" of this sort is pretty much unavoidable, >> >> Yes it is. EasyInstall works just fine. > > You can

Re: Trying to choose between python and java

2007-05-16 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > On May 15, 5:16 pm, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: >> Beliavsky a écrit : >> >> >> >>> On May 15, 1:30 am, Anthony Irwin <[EMAIL PROTECTED]> wrote: >>> >>>> #5 someone said th

Re: Sending a JavaScript array to Python script?

2007-05-18 Thread Bruno Desthuilliers
placid a écrit : > Hi All, > > Just wondering if there is any way of sending a JavaScript array to a > Python cgi script? A quick Google search didn't turn up anything > useful. Look for "json". -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Web Programming - looking for examples of solid high-traffic sites

2007-05-18 Thread Bruno Desthuilliers
John Nagle a écrit : > Victor Kryukov wrote: >> Hello list, >> >> our team is going to rewrite our existing web-site, which has a lot of >> dynamic content and was quickly prototyped some time ago. > ... >> Our main requirement for tools we're going to use is rock-solid >> stability. As one of our

Re: Python Web Programming - looking for examples of solid high-traffic sites

2007-05-18 Thread Bruno Desthuilliers
Istvan Albert a écrit : > On May 16, 5:04 pm, Victor Kryukov <[EMAIL PROTECTED]> wrote: > >> Our main requirement for tools we're going to use is rock-solid >> stability. As one of our team-members puts it, "We want to use tools >> that are stable, has many developer-years and thousands of user-ye

Re: Many-to-many pattern possiable?

2007-05-20 Thread Bruno Desthuilliers
Jia Lu a écrit : > Hi all > > I see dict type can do 1-to-1 pattern, But is there any method to do > 1-to-many, a dict of lists > many-to-1 What's the difference with 1-n ? > and many-to-many pattern ? As usual, using an intermediate dict. > What about using some > Serialized objects? What

Re: Python Web Programming - looking for examples of solid high-traffic sites

2007-05-20 Thread Bruno Desthuilliers
John Nagle a écrit : > Bruno Desthuilliers wrote: > >> John Nagle a écrit : >> >>> Victor Kryukov wrote: >>> >>>> Hello list, >>>> >>>> our team is going to rewrite our existing web-site, which ha

Re: How to do basic CRUD apps with Python

2007-05-20 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : (snip) > > Sounds like you're talking about rails. Do any of the python packages > compare with the ease of rails? Turbogears, Django and Pylons. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python compared to other language

2007-05-20 Thread Bruno Desthuilliers
walterbyrd a écrit : > On May 18, 10:24 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > > >>I think that Ruby, which roughly speaking sits somewhere between Python >>and Perl, is closer to Python than Perl is. > > > I don't know much about Ruby, but it does not seem to be commonly used > for any

Re: Simple web apps....mod_python or framework?

2007-05-21 Thread Bruno Desthuilliers
cbmeeks a écrit : > If you guys where going to do a simple web-app (as in, 4-5 tables with > 99% being simple CRUD), would you use a framework (Django, > CodeIgniter, whatever...) or would you do it using maybe mod_python > and Python code? pylons + SQLAlchemy http://pylonshq.com -- http://mail.

Re: [Fwd: Re: managed lists?]

2007-05-21 Thread Bruno Desthuilliers
(snip - I suppose I'm answering to Jorgen, but being another idiot myself I may be wrong... anyway:) > Thanks for the answer. I did make something myself after i could not > find anything, just because it was fun to do :-) I did saw array but > it was not for object, only for small types like int

Re: Python Web Programming - looking for examples of solid high-traffic sites

2007-05-21 Thread Bruno Desthuilliers
Ivan Tikhonov a écrit : > Use php. I am lead programmer/maintainer of big website with a lot of > interactive stuff in user's backoffice and with a lot of interraction > to our non-web apps. > > PHP is a crap, but programming for web in python is a pain in the ass. Strange enough, MVHO on this is

Re: Python Web Programming - looking for examples of solid high-traffic sites

2007-05-21 Thread Bruno Desthuilliers
John Nagle a écrit : (snip) >YouTube's home page is PHP. Try "www.youtube.com/index.php". > That works, while the obvious alternatives don't. > If you look at the page HTML, you'll see things like > >onclick="_hbLink('LogIn','UtilityLinks');">Log In > > So there's definitely PHP

Re: [Fwd: Re: managed lists?]

2007-05-22 Thread Bruno Desthuilliers
Jorgen Bodde a écrit : > Hi Bruno, > > Thanks for your answer. > > Well what I am after is a list of relations to some class type. And in > that list I do not wish to have accidentally put ints, strings, So don't do it !-) > only > one type of object, or interface. Now I can make the list inter

Re: [Fwd: Re: managed lists?]

2007-05-22 Thread Bruno Desthuilliers
Jorgen Bodde a écrit : (snip) > class ObjListException(Exception): >pass > > class ObjListIterator(object): >def __init__(self, objlist): >self.__objlist = objlist >self.__idx = 0 You should use a single underscore here. -- http://mail.python.org/mailman/listinfo/python

Re: Can I reference 1 instance of an object by more names ?

2007-05-23 Thread Bruno Desthuilliers
Stef Mientki a écrit : > hello, > > I'm trying to build a simple functional simulator for JAL (a Pascal-like > language for PICs). > My first action is to translate the JAL code into Python code. > The reason for this approach is that it simplifies the simulator very much. > In this translation I

Re: Basic Class/Instance Question

2007-05-23 Thread Bruno Desthuilliers
Siah a écrit : > Ready to go insane here. Class A, taking on a default value for a > variable. Instantiating two separate objects of A() gives me a shared > val list object. Just see the example bellow: > > > class A(object): > def __init__(self, val=[]): > self.val=val > > obj1 = A(

Re: Can I reference 1 instance of an object by more names ? rephrase

2007-05-23 Thread Bruno Desthuilliers
stef a écrit : > thanks Guys for your information, > > indeed you're all quit right, > but I think I've not correctly described my problem :-( > > I need to have 2 (or more) names, that references the same instance of > an object, > and in assigning a value to the object (or to some property in

Re: Can I reference 1 instance of an object by more names ? rephrase

2007-05-24 Thread Bruno Desthuilliers
Maric Michaud a écrit : > Stef Mientki a écrit : (snip) >> # I need to read and write the individual bits of the byte object >> # so I can create 8 blocks of code like this, one for each bit position >> # I use it, like this >> #name1 = cpu_ports() >> #name1.p5 = True >> # or >> #name1.

Re: function nested

2007-05-24 Thread Bruno Desthuilliers
Gigs_ a écrit : > > i have this function. > > def f(start): > stack = [] > def f1(start): > for fname in os.listdir(startDir): >path = os.path.join(startDir, fname) >if os.path.isfile(path): >stack.append(path) >else: >

Re: Checking parameters prior to object initialisation

2007-05-24 Thread Bruno Desthuilliers
Brett_McS a écrit : > Fairly new to Python (and loving it!) > > In C++ (gack!) I got used to creating a helper function with each class to > check the class object initialisation parameters prior to creating the > object. > > In Python, this would be > --

Re: Rats! vararg assignments don't work

2007-05-30 Thread Bruno Desthuilliers
Matimus a écrit : (snip) > Remember, in Python "there is only one way to do it". Actually, it's : "There should be one-- and preferably only one --obvious way to do it.". ... Which is quite different. Please notice the "should", "preferably" and "obvious". -- http://mail.python.org/mailman/lis

Re: Key Listeners

2007-05-30 Thread Bruno Desthuilliers
Benedict Verheyen a écrit : > [EMAIL PROTECTED] schreef: >> On 30 mai, 04:14, Mike <[EMAIL PROTECTED]> wrote: >>> Are there key listeners for Python? Either built in or third party? >> >> What is a "key listener" ? >> (snip) > In google, the first link is a link to the java sun home page. > The fir

Re: Key Listeners

2007-05-30 Thread Bruno Desthuilliers
kaens a écrit : > On 5/30/07, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: >> Benedict Verheyen a écrit : >> > [EMAIL PROTECTED] schreef: >> >> On 30 mai, 04:14, Mike <[EMAIL PROTECTED]> wrote: >> >>> Are there key listeners for P

[OT] Re: HTML Form/Page and Navigation with multiple buttons

2007-05-31 Thread Bruno Desthuilliers
mosscliffe a écrit : > I am struggling to find a python example of the scenario - I have. > > I have a python script, which generates a page with a search button > (actually an input field). > > The data from the above submissions is interrogated and the same > script produces a new search option

Re: decorators tutorials

2007-07-23 Thread Bruno Desthuilliers
james_027 a écrit : > Hi, > > I am learning python by learning django, and I stumble upon decorator > which is very cool, any beginners resources for python decorators, > although I can google it, I just want to get a good tutorial for this > topic. You should find answers on python.org, and sear

Re: decorators tutorials

2007-07-23 Thread Bruno Desthuilliers
james_027 a écrit : > Hi all, > > I am having difficulty understanding decorator. The definition was > clear for me, but the syntax is not so clear to me. > > will decorators will always have to be in this way > > def check_login(func): > def _check_login(*args): > print "I am decora

Re: Configure apache to run python scripts

2007-07-23 Thread Bruno Desthuilliers
joe jacob a écrit : > I need to configure apache to run python scripts. I followed the steps > mentioned in this site (http://www.thesitewizard.com/archive/ > addcgitoapache.shtml). But I am not able to run python scripts from > Firefox, I got a forbidden error "you do not have permission to >

Re: decorators tutorials

2007-07-23 Thread Bruno Desthuilliers
james_027 a écrit : > hi bruno, > > That seems to be hard to read at all, or I am just very new to python? or just new to higher order functions ? (ie: functions working on functions). > With that decorator how do I take advantage of it compare when I just > write a function that could do the s

Re: classmethod & staticmethod

2007-07-24 Thread Bruno Desthuilliers
james_027 a écrit : > hi, > > python's staticmethod is the equivalent of java staticmethod right? IIRC, yes. A 'staticmethod' is in fact nothing more than a function attached to a class, and which can be called on the class or an instance of. Note that since Python supports modules and function

Re: Where do they tech Python officialy ?

2007-07-24 Thread Bruno Desthuilliers
NicolasG a écrit : > Hi, > > I want to be a professional python programmer, While there are (more and more) professional programmers using Python, either as their main language or not, there's no such thing as a "professional Python programmer", because being a proofessional programmer requir

Re: Hacking with __new__

2007-07-24 Thread Bruno Desthuilliers
Duncan Booth a écrit : (snip) > I think what you want for Bar is something more along the lines: (snip) > class Bar(Foo): > def __new__(cls, a, b, c, *args): > print 'Bar.__new__', len(args) > target = cls You don't use 'target' anywhere... > if not args: >

Re: classmethod & staticmethod

2007-07-24 Thread Bruno Desthuilliers
james_027 a écrit : > hi, > >> The 'real' use is (are) the one(s) you'll find. FWIW, I use >> staticmethods for helper functions that don't need access to the class >> or instance but are too specific to a class to be of any use as plain >> functions. Which is not a very frequent case. Classmethod

Re: Closures / Blocks in Python

2007-07-24 Thread Bruno Desthuilliers
treble54 a écrit : > Does anyone know a way to use closures or blocks in python like those > used in Ruby? Particularly those used in the { } braces. > Instead of looking for what you think is the solution, you'd be better explaining your concrete problem. -- http://mail.python.org/mailman/listi

Re: class C: vs class C(object):

2007-07-25 Thread Bruno Desthuilliers
Aahz a écrit : (snip) > *YOU* are the one confusing people by your dogmatic insistance that > classic classes should be ignored. Grow up. I did. I still do. With every new Python release. I'm sorry for you that you are still stuck with almost prehistoric Python versions, but I don't accept th

Re: classmethod & staticmethod

2007-07-25 Thread Bruno Desthuilliers
Alex Popescu a écrit : > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote > in news:[EMAIL PROTECTED]: > > > >>[snip...] >> >> >>Not necessarily - you can access class attributes from within an >>instance method (but obviously a classmethod can

Re: Technology solutions for Ruby?

2007-07-25 Thread Bruno Desthuilliers
vasudevram a écrit : > Bruno Desthuilliers wrote: > > >>s/some/great/g >> >>Both Ruby and Python are known for this. > > Thanks for the info. This is not exactly a scoop, you know ?-) >>I'd say that - wrt/ "advanced" programming trick

Re: is_iterable function.

2007-07-26 Thread Bruno Desthuilliers
Neil Cerutti a écrit : > def is_iterable(obj): > try: > iter(obj) > return True > except TypeError: > return False > > Is there a better way? The only other alternative I see is worse: def iterable(obj): # strings are iterable and don't have an __iter__ method.

Re: Why PHP is so much more popular for web-development

2007-07-26 Thread Bruno Desthuilliers
walterbyrd a écrit : > On Jul 25, 12:40 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: > > >>What exactly could Python learn from PHP? > > > Remember, I'm a noob, I'm not trolling. > > When I posted "Python" I meant the Python web-developement world. In > particular, python frameworks, like Cher

Re: Reading files, splitting on a delimiter and newlines.

2007-07-26 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Hello, > > I have a situation where I have a file that contains text similar to: > > myValue1 = contents of value1 > myValue2 = contents of value2 but > with a new line here > myValue3 = contents of value3 > > My first approach was to open th

Re: Singleton in Python Cookbook

2007-07-26 Thread Bruno Desthuilliers
Alex Popescu a écrit : > Hi all! > > I was reading through Python Cookbook the Singleton recipe. At this moment > I am a bit puzzled as the example in the book is not working resulting in: > > TypeError: type.__new__(SingleSpam): SingleSpam is not a subtype of type > > (I haven't presented the

Re: I am giving up perl because of assholes on clpm -- switching to Python

2007-07-26 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Python is a better language, with php support, Python has php support ? My, I'm a professional web developper using both, and I didn't knew this. (snip troll) -- http://mail.python.org/mailman/listinfo/python-list

Re: Reading files, splitting on a delimiter and newlines.

2007-07-26 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > On Jul 25, 8:46 am, [EMAIL PROTECTED] wrote: > >>Hello, >> >>I have a situation where I have a file that contains text similar to: >> >>myValue1 = contents of value1 >>myValue2 = contents of value2 but >>with a new line here >>myValue3 = conten

Re: Why PHP is so much more popular for web-development

2007-07-26 Thread Bruno Desthuilliers
SamFeltus a écrit : > PHP is just a more inclusive community. The PHP community is more > concerned with the casual user and the end user. This is PHP's core > strength, and one of Python's core weaknesses. The Python community > would be wise to adopt PHP's concern for the end user. This asse

Re: class C: vs class C(object):

2007-07-26 Thread Bruno Desthuilliers
Aahz a écrit : (snip) > Enh. *All* of the standard Python documentation currently starts with > teaching classic classes, (snip) > There is almost no basic documentation > that starts with new-style classes; (snip) Just for the record: http://docs.python.org/ref/node33.html http://www.python.org

Re: Why PHP is so much more popular for web-development

2007-07-26 Thread Bruno Desthuilliers
walterbyrd a écrit : > On Jul 22, 12:17 am, Bruno Desthuilliers > <[EMAIL PROTECTED]> wrote: > >> Either you are a casual user with 101 web >> development skills trying to set up your personal home page > > But this, sort of, brings me back to my original

Re: Singleton in Python Cookbook

2007-07-26 Thread Bruno Desthuilliers
Alex Popescu a écrit : > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote in > news:[EMAIL PROTECTED]: > >> Alex Popescu a écrit : > >> [snip...] >> >> >> I don't have the book, so if you don't post the code, I just give up >> tryi

Re: generating objects of a type from a name.

2007-07-27 Thread Bruno Desthuilliers
tsuraan a écrit : > I'm not sure what a visual object is, but to create an instance of an > object whose name is known, you can use "eval": Better to use getattr(module, classname), or locals().get(classname), or globals().get(classname). > oname = 'list' obj = eval(oname)() obj

Re: generating objects of a type from a name.

2007-07-27 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > On Jul 27, 1:59 am, tsuraan <[EMAIL PROTECTED]> wrote: >> I'm not sure what a visual object is, but to create an instance of an >> object whose name is known, you can use "eval": >> > oname = 'list' > obj = eval(oname)() > obj >> [] > type(obj) >> >> >

Re: Filtering content of a text file

2007-07-27 Thread Bruno Desthuilliers
Marc 'BlackJack' Rintsch a écrit : > On Fri, 27 Jul 2007 12:15:25 +0200, Bruno Desthuilliers wrote: > >> 4/ print "//-+alibaba sinage"[4:].startswith('a') > > print "//-+alibaba sinage".startswith('a', 4) > > This does n

Re: Filtering content of a text file

2007-07-27 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Hello All, > > I'd greatly appreciate if you can take a look at the task I need help > with. > > It'd be outstanding if someone can provide some sample Python code. No problem. It's 600 euro per day. Do I send you the contract ? > --

Re: Factory pattern again

2007-07-27 Thread Bruno Desthuilliers
Mike Howarth a écrit : > Hi > > I was wondering whether anyone could help me, I'm pretty new to python > coming from a PHP background and I'm having a few products in getting my > head round how to write the factory pattern within python. > > I'm currently looking to try to return values from a

Re: Replacing overloaded functions with closures.

2007-07-30 Thread Bruno Desthuilliers
king kikapu a écrit : > Hi, > > i am trying, to no avail yet, to take a C#'s overloaded functions > skeleton and rewrite it in Python by using closures. > I read somewhere on the net (http://dirtsimple.org/2004/12/python-is- > not-java.html) that in Python we can reduce code duplication for > over

Re: making a variable available in a function from decorator

2007-07-30 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : (top-post corrected) > > On 30 Jul 2007 06:17:25 GMT, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> > wrote: >> On Sun, 29 Jul 2007 15:22:47 -0700, [EMAIL PROTECTED] wrote: >> >>> I create a variable in a decorator. i want to be able to access that >>> variable in the f

Re: Relative-importing *

2007-07-30 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : (snip) > I do take your point that importing * has the potential to unexpectedly > clobber names you didn't intend, Another problem is that it makes harder to know from which module a name comes from. > and that's a good reason to avoid it > unless you have a good reaso

Re: Relative-importing *

2007-07-30 Thread Bruno Desthuilliers
Paul Rubin a écrit : > Steven D'Aprano <[EMAIL PROTECTED]> writes: > >>I read "from module import *" as explicitly saying "clobber the current >>namespace with whatever names module exports". That's what from does: it >>imports names into the current namespace. It isn't some sort of easy to >>miss

Re: Where do they tech Python officialy ?

2007-07-30 Thread Bruno Desthuilliers
Omari Norman a écrit : > On Mon, Jul 23, 2007 at 10:48:10PM -0700, Paul Rubin wrote: > > >>If you're having trouble with Python because you're new at >>programming, I can sympathize--I don't think it's the most >>beginner-friendly of languages despite the efforts in that direction >>by the desig

Re: making a variable available in a function from decorator

2007-07-30 Thread Bruno Desthuilliers
Evan Klitzke a écrit : > On 7/30/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >>is it possible to do this without passing it as a function argument? >> > Sort of. Functions are objects in python, so you can set attribute on them. > E.g. > > def foo(): > return foo.c > > foo.c = 1 > pr

Re: Where do they tech Python officialy ?

2007-07-31 Thread Bruno Desthuilliers
Star > > On Wed, 25 Jul 2007, Bruno Desthuilliers wrote: > >> Omari Norman a écrit : >>> On Mon, Jul 23, 2007 at 10:48:10PM -0700, Paul Rubin wrote: >>> >>> >>>> If you're having trouble with Python because you're new at >>>&g

Re: Why no maintained wrapper to Win32?

2007-07-31 Thread Bruno Desthuilliers
Gilles Ganault a écrit : > On Sun, 29 Jul 2007 06:40:35 +0200, "Martin v. Löwis" > <[EMAIL PROTECTED]> wrote: >> Why do you say that the Win32 API lacks documentation? I find the >> documentation at msdn.microsoft.com to be quite useful. > > No, I meant documentation on how to write Win32 apps usi

Re: Why no maintained wrapper to Win32?

2007-07-31 Thread Bruno Desthuilliers
Gilles Ganault a écrit : > On Sun, 29 Jul 2007 21:49:04 -0700, sturlamolden > <[EMAIL PROTECTED]> wrote: >> Why inflict suffering on yourself with MFC when you can use wxPython >> or PyGTK? > > Because I'd like to avoid having to pack several MB + having to > install the toolkit. Considering the s

Re: get directory and file names

2007-07-31 Thread Bruno Desthuilliers
Alchemist a écrit : > I am working with Python 2.5 on Windows XP (SP2). > > How can I traverse a folder, loop through a list of files and get > their file name and extension in an elegant, pythonic way? http://docs.python.org/lib/module-os.path.html http://docs.python.org/lib/os-file-dir.html (=>

Re: standalone process to interact with the web

2007-08-01 Thread Bruno Desthuilliers
beginner a écrit : > Hi Steve, > > On Jul 31, 11:42 am, Steve Holden <[EMAIL PROTECTED]> wrote: >> beginner wrote: >>> Hi Everyone, >>> I am looking for a way to allow a standalone python process to easily >>> interactive with a few web pages. It has to be able to easily receive >>> requests from

Re: standalone process to interact with the web

2007-08-01 Thread Bruno Desthuilliers
beginner a écrit : (snip) > Yes exactly. I just don't want to reinvent the wheel as I imagine > there are already tons of libraries and frameworks that support RPC or > the like functions. Why go thru the pain of RPC, SOAP or such bloated horrors ? Why not just use plain old HTTP with a RESTful A

Re: access the name of my method inside it

2007-08-01 Thread Bruno Desthuilliers
james_027 a écrit : > Hi, > > On Aug 1, 5:18 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Wed, 01 Aug 2007 09:06:42 +, james_027 wrote: >>> for example I have this method >>> def my_method(): >>> # do something >>> # how do I get the name of this method which is my_met

Re: Where do they tech Python officialy ?

2007-08-01 Thread Bruno Desthuilliers
Alex Popescu a écrit : > [EMAIL PROTECTED] (Alex Martelli) wrote in news:1i23wyk.avc945i4dwsiN% > [EMAIL PROTECTED]: > > >>NicolasG <[EMAIL PROTECTED]> wrote: >> ... >> >>>The problem is that I would like to work as a Python programmer but >>>all the job vacancies I can find requires a couple o

Re: Pythonic way for missing dict keys

2007-08-01 Thread Bruno Desthuilliers
John J. Lee a écrit : > Alex Popescu <[EMAIL PROTECTED]> writes: > > >>Zentrader <[EMAIL PROTECTED]> wrote in news:1185041243.323915.161230 >>@x40g2000prg.googlegroups.com: >> >> >>>On Jul 21, 7:48 am, Duncan Booth <[EMAIL PROTECTED]> wrote: >>> >>>[snip...] >>> >>> From the 2.6 PEP #361 (loo

Re: Pythonic way for missing dict keys

2007-08-01 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : (snip) > Instead of doing: > > > if callable(function): function() > > you should do: > > try: > function() > except TypeError: > pass There are time where you may want to know if you have a callable without calling it... > That should work for most uses of

Re: access the name of my method inside it

2007-08-01 Thread Bruno Desthuilliers
Cousin Stanley a écrit : def my_method(): # do something >>> # how do I get the name of this method # which is my_method here? >>> >>>Why do you need this? There are ways but those >>>are not really good for production code. >>> >> >>I am going to use this in Dja

Re: Emacs + python

2007-08-02 Thread Bruno Desthuilliers
Edward O'Connor a écrit : >> Could anyone put me on the right track to developing Python with emacs >> please : modes to consider, debugging etc hopefully all within emacs. > > Personally, I prefer the python.el that ships with Emacs 22 to the > python-mode.el from python.org. It seems more like o

Re: Emacs + python

2007-08-02 Thread Bruno Desthuilliers
hg a écrit : (snip) > Are there any cscope & ECB equivalent for Python ? ECB (assuming we're talking about the same thing, ie Emacs Code Browser) works just fine with Python. -- http://mail.python.org/mailman/listinfo/python-list

Re: a dict trick

2007-08-02 Thread Bruno Desthuilliers
james_027 a écrit : > hi > > for example I have this dictionary > > dict = {'name':'james', 'language':'english'} > > value = 'sex' in dict and dict['sex'] or 'unknown' > > is a right pythonic of doing this one? No. The first problem is that using 'dict' as an identifier, you're shadowing the

Re: Awkward format string

2007-08-02 Thread Bruno Desthuilliers
beginner a écrit : > Hi, > > In order to print out the contents of a list, sometimes I have to use > very awkward constructions. For example, I have to convert the > datetime.datetime type to string first, construct a new list, s/list/tuple/ > and then > send it to print. The following is an exa

Re: a dict trick

2007-08-02 Thread Bruno Desthuilliers
james_027 a écrit : > Hi, > > what if we're not dealing with dict? is there a pythonic way of doing > ternary? the bool ? x:y Python 2.5 introduced the following syntax: expr1 if condition else expr2 In older Python versions, one has to use and/or (like you wrongly did) or tuple/dict dispatch

Re: Pythonic way for missing dict keys

2007-08-02 Thread Bruno Desthuilliers
Alex Popescu a écrit : > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote in > news:[EMAIL PROTECTED]: (snip) >> if hasattr(obj, '__call__'): >># it's a callable >> >> but I don't find it so Pythonic to have to check for a __magic__ >&

Re: standalone process to interact with the web

2007-08-02 Thread Bruno Desthuilliers
beginner a écrit : > On Aug 1, 5:04 am, Bruno Desthuilliers [EMAIL PROTECTED]> wrote: >> beginner a écrit : >> (snip) >> >>> Yes exactly. I just don't want to reinvent the wheel as I imagine >>> there are already tons of libraries and frameworks tha

Re: Pythonic way for missing dict keys

2007-08-02 Thread Bruno Desthuilliers
Alex Martelli a écrit : > Bruno Desthuilliers <[EMAIL PROTECTED]> > wrote: > >> Alex Popescu a écrit : >>> Bruno Desthuilliers <[EMAIL PROTECTED]> wrote in >>> news:[EMAIL PROTECTED]: >> (snip) >>>> if hasattr(obj, '__call__&#x

Re: Case study: library class inheritance with property declarations

2007-08-02 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : (snip) > Last post -- I swear. > > I failed to realize that it's all part of an extremely well defined > attribute resolution protocol, and handled via the descriptor > specification. Discussing descriptors was on the TODO list for the > type/class unification document,

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > I don't personally use __call__ methods in my classes, but I have > encountered it every now and then here at work in code written by other > people. The other day I replaced __call__ with a more obvious method name, > so now instead of executing > > obj(foo, bar

Re: __call__ considered harmful or indispensable?

2007-08-02 Thread Bruno Desthuilliers
Paul Rubin a écrit : > [EMAIL PROTECTED] writes: > >>In this particular case it was clearly unnecessary and just obfuscated the >>code. I'm wondering, are there some general cases where __call__ methods of >>a user-defined class are simply indispensable? > > > I don't know about "indispensable"

Re: i am new to python-Please somebody help

2007-08-02 Thread Bruno Desthuilliers
gregarican a écrit : (snip) > This link answers my question --> > http://www.google.com/search?hl=en&q=Python+list+rudeness. I seriously don't think that this newsgroup can be qualified as "rude" (and I'm possibly one of the "rudest" persons here). Compared to most comp.* newsgroup, Python is c

Re: __call__ considered harmful or indispensable?

2007-08-03 Thread Bruno Desthuilliers
Skip Montanaro a écrit : >>> In this case there was a bug. Depending on inputs, sometimes obj >>> initialized to a class, sometimes an instance of that class. (I fixed >>> that too while I was at it.) The problem was that the use of __call__ >>> obscured the underlying bug by making the instance

Re: (no) fast boolean evaluation ? missing NOT

2007-08-03 Thread Bruno Desthuilliers
Stef Mientki a écrit : (snip) > Gabriel: you pointed me to this page: > The exact behavior is defined in the Language Reference > > > > or_test ::= and_test | or_test "or" and_test > > Can you imagine, while I'm not a programmer, just a huma

Re: (no) fast boolean evaluation ?

2007-08-03 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : > On Fri, 03 Aug 2007 10:20:59 +0200, Bruno Desthuilliers wrote: > >> Joshua J. Kugler a écrit : >>> On Thursday 02 August 2007 15:19, Evan Klitzke wrote: >>>>> I discovered that boolean evaluation in Python is done "fast&qu

Re: (no) fast boolean evaluation ?

2007-08-03 Thread Bruno Desthuilliers
Joshua J. Kugler a écrit : > On Thursday 02 August 2007 15:19, Evan Klitzke wrote: >>> I discovered that boolean evaluation in Python is done "fast" >>> (as soon as the condition is ok, the rest of the expression is ignored). >> This is standard behavior in every language I've ever encountered. >

Re: Global package variable, is it possible?

2007-08-06 Thread Bruno Desthuilliers
Chris Allen a écrit : > Hello fellow pythoneers. I'm stumped on something, and I was hoping > maybe someone in here would have an elegant solution to my problem. > This is the first time I've played around with packages, so I'm > probably misunderstanding something here... > > Here's what I'd lik

Re: (no) fast boolean evaluation ?

2007-08-06 Thread Bruno Desthuilliers
Ed Leafe a écrit : > On Aug 3, 2007, at 11:57 AM, Bruno Desthuilliers wrote: > >> Sorry, I forgot to mention the language did not allow to have else & if >> in the same statement. IOW : >> >> if some_condition then >>do_sometehing &g

Re: A question on plugin design

2007-08-06 Thread Bruno Desthuilliers
John J. Lee a écrit : > [EMAIL PROTECTED] (John J. Lee) writes: > >> Grzegorz Słodkowicz <[EMAIL PROTECTED]> writes: >> [...] >>> I'd also be grateful for pointers to a well designed Pythonic plugin >>> architecture but I'd much prefer a small project with a simple API. >> Google for setuptools an

Re: Best programs written completly in Python

2007-08-06 Thread Bruno Desthuilliers
markacy a écrit : > On 5 Sie, 12:14, Franz Steinhäusler <[EMAIL PROTECTED]> > wrote: >> Hello NG, >> >> wWhat are the best programs in your opinion, written entirly >> in pyhton, divided into categories like: >> a) Games >> b) Utilities/System >> c) Office >> d) Web/Newsreader/Mail/Browser >> ... >

Re: help with flexible decorators

2007-08-07 Thread Bruno Desthuilliers
james_027 a écrit : > Hi, > > I want to write a flexible decorators to edit a function that may have > 1 or more arguments... > > def enhance(func): > def new(x): > #do something ... > return func(x) > return new > > @enhance > def method_a(x): > #do something ... >

Re: boolean operations on sets

2007-08-07 Thread Bruno Desthuilliers
Flavio a écrit : > Hi, I have been playing with set operations lately and came across a > kind of surprising result given that it is not mentioned in the > standard Python tutorial: > > with python sets, intersections and unions are supposed to be done > like this: > In [7]:set('casa') & set('p

Re: Global package variable, is it possible?

2007-08-07 Thread Bruno Desthuilliers
Chris Allen a écrit : > On Aug 6, 12:41 am, Bruno Desthuilliers [EMAIL PROTECTED]> wrote: >> Chris Allen a écrit : >> (snip) >> Hi Chris... >> I've read all the thread, and it seems that your problem is mostly to >> share a single dynamic state (the co

Re: Heterogeneous lists

2007-08-07 Thread Bruno Desthuilliers
Gordon Airporte a écrit : > This is one of those nice, permissive Python features but I was > wondering how often people actually use lists holding several different > types of objects. Depends on the definition of 'type'. I often have instances of different - possibly unrelated - classes in a

Re: Adding a list of descriptors to a class

2007-08-07 Thread Bruno Desthuilliers
Marc 'BlackJack' Rintsch a écrit : > On Tue, 07 Aug 2007 09:25:32 -0700, Bob B. wrote: > > >>Ok, that "exec" is an ugly hack. There's gotta be someway to plop >>this straight into the class's __dict__ without doing that, but when I >>try adding self.__class__.__dict__[attr] = MyDesc(attr) in MyC

Re: Adding a list of descriptors to a class

2007-08-07 Thread Bruno Desthuilliers
Bob B. a écrit : > I've been playing with descriptors lately. I'm having one problem I > can't seem to find the answer to. I want to assign a descriptor to a > list of attributes. I know I should be able to add these somewhere in > the class's __dict__, but I can't figure out where. Here's some

Re: Buffering HTML as HTMLParser reads it?

2007-08-07 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Hello, > > I am working on a project where I'm using python to parse HTML pages, > transforming data between certain tags. Currently the HTMLParser class > is being used for this. In a nutshell, its pretty simple -- I'm > feeding the contents of the HTML page to HTMLP

Re: Seek the one billionth line in a file containing 3 billion lines.

2007-08-08 Thread Bruno Desthuilliers
Jay Loden a écrit : (snip) > If we just want to iterate through the file one line at a time, why not just: > > count = 0 > handle = open('hugelogfile.txt') > for line in handle.xreadlines(): > count = count + 1 > if count == '10': > #do something for count, line in enumera

Re: Seek the one billionth line in a file containing 3 billion lines.

2007-08-08 Thread Bruno Desthuilliers
Ant a écrit : > On Aug 8, 11:10 am, Bruno Desthuilliers [EMAIL PROTECTED]> wrote: >> Jay Loden a écrit : >> (snip) >> >>> If we just want to iterate through the file one line at a time, why not >>> just: >>> count = 0 >>> handle

Re: Help with Dictionaries and Classes requested please.

2007-08-09 Thread Bruno Desthuilliers
special_dragonfly a écrit : (snip) > I've managed to solve the problem, I really was just being a dunce. Here's > how incase anyone is wondering: > > class MyClass: > def __init__(self): > name="" > dict={} > dict[0]=[] > dict[0].append(MyClass()) > dict[0][0].name="Hello" > print dic

<    7   8   9   10   11   12   13   14   15   16   >