Re: Extract doc strings

2010-07-01 Thread Jean-Michel Pichavant
moerchendiser2k3 wrote: Hi all, when I have a PyCodeObject, is there any way to extract a doc string from the code? For instance the following script <---script> """ Hello World! """ def main(): pass main() I would like to get "Hello World!". Any chance? Thanks in advance!! Bye, moer

Re: Why are String Formatted Queries Considered So Magical?

2010-07-01 Thread Jean-Michel Pichavant
Stephen Hansen wrote: On 6/30/10 11:58 PM, Jorgen Grahn wrote: On Wed, 2010-06-30, Steven D'Aprano wrote: On Wed, 30 Jun 2010 14:14:38 +, Jorgen Grahn wrote: On Tue, 2010-06-29, Stephen Hansen wrote: There's nothing silly about it. It is an exaggeration though: but it does represent a g

Re: optphart (alpha2)

2010-07-01 Thread Jean-Michel Pichavant
Stephen Hansen wrote: On 6/28/10 11:50 PM, rantingrick wrote: You just don't get the point, do you? And just what *point* an i supposed to be "getting" Stephen? That you don't like my contribution? If thats your point then i very much "get" it. This garbage: "optphart is the nemisis of the

Re: [ANN] eric 5.0.0 released

2010-07-05 Thread Jean-Michel Pichavant
Detlev Offenbach wrote: Hi, I just uploaded eric 5.0.0. This is the first official release. It is available via the eric web site. http://eric-ide.python-projects.org/index.html What is it? --- eric5 is the Python3 variant of the well know eric4 Python IDE and is the first developme

Re: 'reload M' doesn't update 'from M inport *'

2010-07-09 Thread Jean-Michel Pichavant
Frederic Rentsch wrote: I develop in an IDLE window. Module M says 'from service import *'. Next I correct a mistake in function 'service.f'. Now 'service.f' works fine. I do 'reload (service); reload (M)'. The function 'M.f' still misbehaves. 'print inspect.getsource (service.f)' and 'print i

Re: Hello

2010-07-09 Thread Jean-Michel Pichavant
Dani Valverde wrote: Sorry, I forgot to mention that I am using Linux. In fact, my first test have been with gedit. Is there any way to directly run the Python code into the console? Cheers! Dani Bradley Hintze wrote: There are lots of great editors out there. It really depends on personal

Re: 'reload M' doesn't update 'from M inport *'

2010-07-12 Thread Jean-Michel Pichavant
Aahz wrote: In article , Jean-Michel Pichavant wrote: PS : You're misusing the del statement. It does not remove any object >from mmory, however, it removes the reference to it, the object is still in memory. They are very few cases where del is usefull in python, so try

Re: 'reload M' doesn't update 'from M inport *'

2010-07-12 Thread Jean-Michel Pichavant
Hi, Don't use reload, this is nothing but a trap, espacially if your using it to update your objects with the code you are writting. JM I've found "reload" very usable for development in IDLE. IDLE memorizes my input, and the variables I assign output to. If restart IDLE I lose it all

Re: integer >= 1 == True and integer.0 == False is bad, bad, bad!!!

2010-07-12 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: My complaint (an oddly enough the title of this thread!) concerns the fact that Python treats 0 as False and every integer above and below 0 as True. Which is another example of how *some* aspects of Python support bad coding styles. Yes, Python does support bad codi

Re: Naming Conventions, Where's the Convention Waldo?

2010-07-12 Thread Jean-Michel Pichavant
rantingrick wrote: On Jul 11, 3:03 am, "Günther Dietrich" wrote: So, it is not a disadvantage that the functions you listed above are named in this way. In the contrary, it is an advantage, as it keeps newcomers from using stupid variable names. "int" for an Integer is stupid? "list"

Re: integer >= 1 == True and integer.0 == False is bad, bad, bad!!!

2010-07-13 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Mon, 12 Jul 2010 19:28:28 -0600, Ian Kelly wrote: On Mon, Jul 12, 2010 at 6:18 PM, Steven D'Aprano wrote: I prefere to explicitly write what I want to test: if myInt <> 0: I would argue against that. Why do you, the coder, care about the specific d

Re: Check if a command is valid

2010-07-13 Thread Jean-Michel Pichavant
Kenny Meyer wrote: Hello, I have to figure out if a string is callable on a Linux system. I'm actually doing this: def is_valid_command(command): retcode = 100 # initialize if command: retcode = subprocess.call(command, shell=True) if retcode is 0:

Re: Code generator and visitor pattern

2010-07-16 Thread Jean-Michel Pichavant
Karsten Wutzke wrote: Yes, typo, I meant strictly. Damn, I mean strongly. At least not for identifying which methods to call depending on the type/s. Karsten Stringly is the perfect combination of strictly and strongly. Nice one :) JM -- http://mail.python.org/mailman/listinfo/pytho

Re: Difference between import in script and from interpreter

2010-07-19 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Mon, 19 Jul 2010 00:53:56 -0400, Edward Diener wrote: In a python script a: from xxx.yyy.zzz import aaa fails with the message: "ImportError: No module named xxx.yyy.zzz" but from within the python interpreter the same line succeeds. What would be the causes of

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Jean-Michel Pichavant
dmitrey wrote: hi all, I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if someone invokes "myObject.size", it is generated (as another oofun) and connected to myObject as attribute. So, when I invoke in other code part "hasattr(myObject,

Re: hasattr + __getattr__: I think this is Python bug

2010-07-20 Thread Jean-Michel Pichavant
dmitrey wrote: On 20 июл, 15:00, Jean-Michel Pichavant wrote: dmitrey wrote: hi all, I have a class (FuncDesigner oofun) that has no attribute "size", but it is overloaded in __getattr__, so if someone invokes "myObject.size", it is generated (as another oof

Re: loading configuration files that are themselves python

2010-07-29 Thread Jean-Michel Pichavant
Ben Finney wrote: Lawrence D'Oliveiro writes: In message <7j8w5tylmw@rapun.sel.cam.ac.uk>, Matthew Vernon wrote: Is there a more idiomatic way of loading in a configuration file that's python code ... Is it really a good idea to have a configuration language that’s Turing

Re: Download Microsoft C/C++ compiler for use with Python 2.6/2.7 ASAP

2010-07-29 Thread Jean-Michel Pichavant
Robert Kern wrote: On 7/23/10 7:08 PM, Lawrence D'Oliveiro wrote: In message, Robert Kern wrote: There are also utilities for mounting ISOs directly without burning them to a physical disk. You need special utilities to do this?? On at least some versions of Windows, Yes. You need the

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-29 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Sun, 25 Jul 2010 13:58:00 +1200, Gregory Ewing wrote: Lacrima wrote: But what if SuperClass1 is from third party library? If it hasn't been designed for super(), then you can't use super() with it. super() only works when *every* class in the hierarc

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-29 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: [snip] super() is just as explicit as len(), or str.upper(). It says, explicitly, that it will call the method belonging to one or more superclass of the given class. Come on Steven, you're better than this :) . Everybody can accurately guess what len and upper are d

Re: stdout of external program.

2010-07-30 Thread Jean-Michel Pichavant
Paul Lemelle wrote: HELP! :) I am trying to output the following program's output to either a file or variable, how can this be done? # Writing the output to a standard argv argument #1/usr/bin/python import sys for arg in sys.argv: print arg #END Thanks, Paul Hi Paul, after reading

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: [snip] As someone already said in this list, the main problem with super is that it tends to refer to the superclass method while in fact it calls the next MRO method. Why do you think that

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-07-30 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Fri, 30 Jul 2010 19:37:29 +1200, Gregory Ewing wrote: Steven D'Aprano wrote: On Thu, 29 Jul 2010 19:29:24 +0200, Jean-Michel Pichavant wrote: > "mro" would have been the proper name for "super".

Re: Basic Information about Python

2010-07-30 Thread Jean-Michel Pichavant
Durga D wrote: Hi All, I am new to python based application developement. I am using Windows XP. 1. Can I create desktop application (just hello world program) with Python language like exe in VC++? yes http://www.py2exe.org/ 2. If First statement is Yes, Can I include this applicati

Re: Access stdout from external program.

2010-07-30 Thread Jean-Michel Pichavant
Paul Lemelle wrote: JM, Thanks for the response. I am trying to capture the stdout of a program from another program. Example, I want to launch the below program from a second python script then capture the first's program stdout to a file or variable. Is this possible? Thanks again, Paul

Re: Access stdout from external program.

2010-08-02 Thread Jean-Michel Pichavant
Paul Lemelle wrote: Hi JM, My last dumb question: When I try to run the below script as an executable, I get the following error: ptt...@ptttestvm:~$ ./argv.py 4 import: unable to open X server `/tmp/launch-c8feFG/org.x:0' @ import.c/ImportImageCommand/361. ./argv.py: line 8: syntax error n

Re: Builtn super() function. How to use it with multiple inheritance? And why should I use it at all?

2010-08-02 Thread Jean-Michel Pichavant
Paul Rubin wrote: Michele Simionato writes: I am actually more radical than that. From http://www.artima.com/weblogs/viewpost.jsp?thread=237121: In this series I have argued that super is tricky; I think nobody can... When I look at that URL, I see a Java stack dump: java.lang.Runt

Re: namespaces, scoping and variables

2010-08-03 Thread Jean-Michel Pichavant
rantingrick wrote: On Aug 2, 3:12 pm, Chris Hare wrote: Also you should use 4 space indention and never use tabs. This is the accepted way. Then ask yourself why tabs are still in python 3. Nice troll by the way. JM -- http://mail.python.org/mailman/listinfo/python-list

Re: simple (I hope!) problem

2010-08-03 Thread Jean-Michel Pichavant
samwyse wrote: I'm writing for the Google app engine and have stubbed my toe yet again on a simple obstacle. Non-trivial app engines programs require the import of several modules that aren't normally in my PYTHONPATH. I'd like to be able to test my code outside of the app engine framework. I'v

Re: simple integer subclass

2010-08-03 Thread Jean-Michel Pichavant
Andreas Pfrengle wrote: On 3 Aug., 03:22, Carl Banks wrote:> You are creating an object that differs from a built-in, int, in a highly misleading way that only makes sense in a very limited context, and this object's modified behavior gives no clue that it's been modified in such as way. (T

Re: simple integer subclass

2010-08-03 Thread Jean-Michel Pichavant
Jean-Michel Pichavant wrote: Andreas Pfrengle wrote: On 3 Aug., 03:22, Carl Banks wrote:> You are creating an object that differs from a built-in, int, in a highly misleading way that only makes sense in a very limited context, and this object's modified behavior gives no clue t

Re: Why is python not written in C++ ?

2010-08-04 Thread Jean-Michel Pichavant
Carl Banks wrote: On Aug 3, 7:07 pm, Paul Rubin wrote: Mozilla is fed up with C++ and seems to be working on its own language, called Rust: http://lambda-the-ultimate.org/node/4009 That looks much better than Go. It's like all the cool features of Go without the annoying polemics

Re: Global variables problem

2010-08-04 Thread Jean-Michel Pichavant
Navkirat Singh wrote: On 04-Aug-2010, at 9:46 AM, Daniel da Silva wrote: Please post approximate code that actually works and displays the problem. On Tue, Aug 3, 2010 at 9:00 PM, Navkirat Singh > wrote: Hey guys, I am using a multiprocessing program, w

Re: A new syntax for writing tests

2010-08-05 Thread Jean-Michel Pichavant
Jonathan Fine wrote: Hi I just discovered today a new syntax for writing tests. The basic idea is to write a function that contains some statements, and run it via a decorator. I wonder if anyone had seen this pattern before, and how you feel about it. For myself, I quite like it. Let's

Re: simple (I hope!) problem

2010-08-05 Thread Jean-Michel Pichavant
samwyse wrote: On Aug 3, 1:20 am, Steven D'Aprano wrote: On Mon, 02 Aug 2010 17:19:46 -0700, samwyse wrote: Fortunately, I don't need the functionality of the object, I just want something that won't generate an error when I use it. So, what is the quickest way to to create such an ob

Re: subprocess escaping POpen?!

2010-08-05 Thread Jean-Michel Pichavant
Chris Withers wrote: Hi All, I have a script that does the following: from subprocess import Popen,PIPE,STDOUT def execute(command,cwd): return Popen( command, stderr=STDOUT, stdout=PIPE, universal_newlines=True, cwd=cwd, shell=True,

Re: subprocess escaping POpen?!

2010-08-05 Thread Jean-Michel Pichavant
Chris Withers wrote: Jean-Michel Pichavant wrote: You did not redirect stdin, so it is expected you can still read input from the console. Okay, so if I definitely wanted no input, what should I pass as the stdin parameter to the POpen constructor? You do want an input don't you ? &

Re: A new syntax for writing tests

2010-08-05 Thread Jean-Michel Pichavant
jfine wrote: On 5 Aug, 10:17, Jean-Michel Pichavant wrote: Jonathan Fine wrote: Hi I just discovered today anewsyntaxfor writing tests. The basic idea is to write a function that contains some statements, and run it via a decorator. I wonder if anyone had seen this pattern

Re: easy question on parsing python: "is not None"

2010-08-05 Thread Jean-Michel Pichavant
wheres pythonmonks wrote: How does "x is not None" make any sense? "not x is None" does make sense. I can only surmise that in this context (preceding is) "not" is not a unary right-associative operator, therefore: x is not None === IS_NOTEQ(X, None) Beside "not in" which seems to work simila

Re: easy question on parsing python: "is not None"

2010-08-06 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Thu, 05 Aug 2010 12:07:53 -0400, wheres pythonmonks wrote: P.S. Sorry for the top-post -- is there a way to not do top posts from gmail? I haven't used usenet since tin. Er, surely you can just move the cursor before you start typing??? CTRL+END will b

Re: Python Script Cannot Write to Directory

2010-08-06 Thread Jean-Michel Pichavant
Lawrence D'Oliveiro wrote: In message <4c5a6d00$0$29614$426a3...@news.free.fr>, News123 wrote: The original question lacks necessary information That seems to be very common in this newsgroup. ... JM -- http://mail.python.org/mailman/listinfo/python-list

Re: easy question on parsing python: "is not None"

2010-08-10 Thread Jean-Michel Pichavant
Ben Finney wrote: Peter Pearson writes: Hey, that's a cute example, but . . . what a trap! Is it possible to document the use-the-object-not-the-string requirement loudly enough that people won't get caught? Don't use strings for such values. The data isn't going to be used, so there

Re: Python "why" questions

2010-08-10 Thread Jean-Michel Pichavant
Ben Finney wrote: "D'Arcy J.M. Cain" writes: No. You are giving me math and logic but the subject was common sense. Common sense is often unhelpful, and in such cases the best way to teach something is to plainly contradict that common sense. Common sense, for example, would have t

Re: GUI automation tool (windows)

2010-08-11 Thread Jean-Michel Pichavant
Grant Edwards wrote: On 2010-08-11, Lawrence D'Oliveiro wrote: In message , Alex Barna wrote: On Aug 10, 10:05 am, Lawrence D'Oliveiro Can???t understand the point to it. ???GUI automation??? is a contradiction in terms, because a GUI is designed for use by humans to do man

Re: How to swallow traceback message

2010-08-11 Thread Jean-Michel Pichavant
Back9 wrote: Hi, I run my py app to display a file's contents, and it is normally very long. So I use it like below: python myapp.py input_file | more to see them step by step. But when I try to exit it, normally I use Ctrl+ C key to quit it. Problem is every time I do like it, it shows Traceb

Re: Confused: Newbie Function Calls

2010-08-11 Thread Jean-Michel Pichavant
fuglyducky wrote: I am a complete newbie to Python (and programming in general) and I have no idea what I'm missing. Below is a script that I am trying to work with and I cannot get it to work. When I call the final print function, nothing prints. However, if I print within the individual functio

Re: looping through possible combinations of McNuggets packs of 6, 9 and 20

2010-08-12 Thread Jean-Michel Pichavant
Baba wrote: level: beginner exercise: given that packs of McNuggets can only be bought in 6, 9 or 20 packs, write an exhaustive search to find the largest number of McNuggets that cannot be bought in exact quantity. exercise source: http://ocw.mit.edu/courses/electrical-engineering-and-computer

Re: __class__ of what

2010-08-12 Thread Jean-Michel Pichavant
Eric J. Van der Velden wrote: Hello, I have, class C: n=0 def __init__(s): __class__.n+=1 Should be class C: n = 0 def __init__(self): self.__class__.n+=1 C.n+=1 # equivalent to this line (I prefer this one, more readable, less refactor-

writing \feff at the begining of a file

2010-08-13 Thread Jean-Michel Pichavant
Hello python world, I'm trying to update the content of a $Microsoft$ VC2005 project files using a python application. Since those files are XML data, I assumed I could easily do that. My problem is that VC somehow thinks that the file is corrupted and update the file like the following: -

Re: Dump logging configuration

2010-08-16 Thread Jean-Michel Pichavant
Kxepal wrote: Hi all! Sorry for dumb question if it is - I'd tried to google it before but have found nothing. Is there any way to dump current logging configuration for future loading it via fileConfig/dictConfig? I may be wrong but I don't think so. JM -- http://mail.python.org/mailman/li

Re: Dump logging configuration

2010-08-16 Thread Jean-Michel Pichavant
Jean-Michel Pichavant wrote: Kxepal wrote: Hi all! Sorry for dumb question if it is - I'd tried to google it before but have found nothing. Is there any way to dump current logging configuration for future loading it via fileConfig/dictConfig? I may be wrong but I don't thi

Re: passing variables as object attributes

2010-08-16 Thread Jean-Michel Pichavant
Vikas Mahajan wrote: On 16 August 2010 19:23, Nitin Pawar wrote: you would need to define a class first with its attiributes and then you may want to initiate the variables by calling the class initilializer Actually I have to dynamically add attributes to a object. I am writing pytho

Re: 79 chars or more?

2010-08-17 Thread Jean-Michel Pichavant
Michele Simionato wrote: On Aug 17, 6:50 am, AK wrote: On 08/17/2010 12:26 AM, James Mills wrote: By the way, the reason I asked is that we're working on a python tutorial and I realized that even though I'm used to 99, I wasn't sure if it's ok to teach that to new users or not.. -andrei

Re: 79 chars or more?

2010-08-18 Thread Jean-Michel Pichavant
D'Arcy J.M. Cain wrote: On Tue, 17 Aug 2010 16:28:02 +0200 Stefan Schwarzer wrote: I'd probably reformat this to self.expiration_date = translate_date( find(response, 'MPNExpirationDate').text, '%Y-%m-%d', '%m%d%Y') or even self.expiration_date

Re: 79 chars or more?

2010-08-24 Thread Jean-Michel Pichavant
Lawrence D'Oliveiro wrote: In message , Jean-Michel Pichavant wrote: Saying that, if one intend to distribute its code, he should stick to 80 chars per line. Why? Because some(many ?) people cannot deal with more than 80 chars, otherwise this rule would be pointless.

Re: What is a class method?

2010-08-24 Thread Jean-Michel Pichavant
Paulo da Silva wrote: Em 23-08-2010 04:30, James Mills escreveu: On Mon, Aug 23, 2010 at 12:49 PM, Paulo da Silva wrote: I understand the concept of a static method. However I don't know what is a class method. Would anybody pls. explain me? Please read this first: http://docs.

Re: Helper classes design question

2010-08-24 Thread Jean-Michel Pichavant
John O'Hagan wrote: I want to know the best way to organise a bunch of functions designed to operate on instances of a given class without cluttering the class itself with a bunch of unrelated methods. What I've done is make what I think are called helper classes, each of which are initialize

Re: Messing up with classes and their namespace

2009-06-05 Thread Jean-Michel Pichavant
Scott David Daniels wrote: Jean-Michel Pichavant wrote: Hello world, I had recently a very nasty bug in my python application. The context is quite complex, but in the end the problem can be resume as follow: 2 files in the same directory : lib.py: >import foo >foo.Foo.BOOM='l

Re: can it be shorter?

2009-06-08 Thread Jean-Michel Pichavant
Aaron Brady wrote: Shorter is always better. url+= { '/': '' }.get( url[ -1 ], '/' ) Why bother with spaces or 3 letter-wide token, check this :o) : x+={'/':''}.get(x[-1],'/') Apart from joking, the following proposed solution is by **far** the one I prefer if not url.endswith('/'):

Start the interactive shell within an application

2009-06-09 Thread Jean-Michel Pichavant
I was wondering if there is a way to start an interactive shell within a script/application. I'm sometimes tired of adding prints to scan the current namespace so I'd like to pause the execution and give the user the shell prompt. This is obviously for debugging purpose. I know that I may use t

Re: What is the actual type of "interrupted system call"?

2009-06-09 Thread Jean-Michel Pichavant
mrstevegross wrote: I'm trying to write a try/catch block to handle an "interrupted system call". However, I can't seem to locate information on the actual typename of the exception. Does anyone know what it would be? I want my code to look like this: try: ... except InterruptedSystemCall # wh

Re: What is the actual type of "interrupted system call"?

2009-06-10 Thread Jean-Michel Pichavant
mrstevegross wrote: exceptions.EOFError exceptions.ReferenceError exceptions.ZeroDivisionError ... exceptions.NotImplementedError exceptions.UnicodeError exceptions.__str__ Is there a single parent exception to all those? Or should I just write it as: try: ... catch Exception: ... Than

Re: OT: Periodic table gets a new element

2009-06-11 Thread Jean-Michel Pichavant
Not if this element is to end up in some further ultimate nuclear weapon :-) , unless you are using python to conquer the world (I've been told this is GVR main secret objective). MRAB wrote: Element 112 is to be named. Do you think we could persuade the scientists to name it "Pythonium"? :-

Re: Need help in Python regular expression

2009-06-12 Thread Jean-Michel Pichavant
To the OP, I suggest if you haven't yet Kodos, to get it here http://kodos.sourceforge.net/. It's a python regexp debugger, a lifetime saver. Jean-Michel John S wrote: On Jun 11, 10:30 pm, meryl wrote: Hi, I have this regular expression blockRE = re.compile(".*RenderBlock {\w+}") it w

Re: trying to understand dictionaries

2009-06-12 Thread Jean-Michel Pichavant
Basically, dictionaries are a bunch of couples of key and value where key is an immutable object. In fact you'll find a more accurate definition in any python book or online tutorial. The thing is that keys are usually used as an easy and quick way the search and index items. You can see dict a

Re: EOF problem with ENTER

2009-06-12 Thread Jean-Michel Pichavant
Prasoon wrote: I modified my code to #Euler Totient Function import sys from math import sqrt def etf(n): i,res =2,n while(i*i<=n): if(n%i==0): res-=res/i while(n%i==0): n/=i i+=1 if(n>1): res-=res/n return res def main(): while Tr

Re: Question about None

2009-06-12 Thread Jean-Michel Pichavant
def setNext(nxt): assert nxt==None or isinstance(nxt, Node), "next must be a Node" self.next = nxt works ok, but it's uglier than it ought to be. I don't find it that ugly. It's accurate, easy to read and understand. "What else ?" would say a famous coffee representative. If you

Re: Perl's @foo[3,7,1,-1] ?

2009-06-17 Thread Jean-Michel Pichavant
On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: What's np.arange? import numpy as np -- Pierre "delroth" Bourdon Étudiant à l'EPITA / Student at EPITA Perfect example of why renaming namespaces should be done only when absolutely required, that is, almost never. Jean-Michel

Re: Regarding Python is scripting language or not

2009-06-17 Thread Jean-Michel Pichavant
abhishek goswami wrote: Hi, I have very basic question about Python that do we consider pyhton as script language. I searched in google but it becomes more confusion for me. After some analysis I came to know that Python support oops . Can anyone Guide me that Python is Oject oriented program

Re: Pythonic way to overwrite a file

2009-06-17 Thread Jean-Michel Pichavant
Cameron Pulsford wrote: Hey all, hopefully a simple question. I'm writing a simple python tool that opens a file, and does something like for line in file.readlines(): temp.write(line.doStuff()) However, I want to provide the option do this "in place", as in have the destination file be

Re: Perl's @foo[3,7,1,-1] ?

2009-06-22 Thread Jean-Michel Pichavant
J. Cliff Dyer wrote: On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: What's np.arange? import numpy as np -- Pierre "delroth" Bourdon Étudiant à l'EPITA / Student at EPITA

Re: Perl's @foo[3,7,1,-1] ?

2009-06-22 Thread Jean-Michel Pichavant
J. Cliff Dyer wrote: On Mon, 2009-06-22 at 14:57 +0200, Jean-Michel Pichavant wrote: J. Cliff Dyer wrote: On Wed, 2009-06-17 at 14:13 +0200, Jean-Michel Pichavant wrote: On Wed, Jun 17, 2009 at 04:14, Steven D'Aprano wrote: What's

Re: Perl's @foo[3,7,1,-1] ?

2009-06-22 Thread Jean-Michel Pichavant
Lie Ryan wrote: Jean-Michel Pichavant wrote: Maybe I've been a little bit too dictatorial when I was saying that renaming namespaces should be avoided. Sure your way of doing make sense. In fact they're 2 main purposes of having strong coding rules: 1/ ease the coder's l

Re: A superclass using a child classes' methods

2009-06-24 Thread Jean-Michel Pichavant
Kurt Schwehr wrote: I'm trying to build an OO system for encoding and decoding datapackets. I'd like the parent class to have an encode function that uses each of the child classes' packing methods. It appears that this works for attributes of children accessed by the parent, but not for method

Re: Get name of class without instance

2009-06-24 Thread Jean-Michel Pichavant
Bryan wrote: Given a class: class Foo(object): pass How can I get the name "Foo" without having an instance of the class? str(Foo) gives me more than just the name Foo. "__main__.Account" Foo.__class__.__name__ gives me "type" I don't want to do: Foo().__class__.__name__ if possible. I

Re: pep 8 constants

2009-06-30 Thread Jean-Michel Pichavant
Eric S. Johansson wrote: Ethan Furman wrote: Eric S. Johansson wrote: yup how long will i[t] be before you become disablesd? maybe not as badly as I am but you should start feeling some hand problems in your later 40's to early 50's and it goes down hill from there. self preservation

Re: string character count

2009-07-01 Thread Jean-Michel Pichavant
MRAB wrote: noydb wrote: If I have a string for a file name such that I want to find the number of characters to the left of the dot, how can that be done? I did it this way: x = "text12345.txt" dot = x.find('.') print dot Was curious to see what method others would use - helps me learn. I gu

Re: question of style

2009-07-03 Thread Jean-Michel Pichavant
Simon Forman wrote: Hey I was hoping to get your opinions on a sort of minor stylistic point. These two snippets of code are functionally identical. Which would you use and why? The first one is easier [for me anyway] to read and understand, but Easier for you but not for those who are familia

Re: Clarity vs. code reuse/generality

2009-07-03 Thread Jean-Michel Pichavant
kj wrote: I'm will be teaching a programming class to novices, and I've run into a clear conflict between two of the principles I'd like to teach: code clarity vs. code reuse. I'd love your opinion about it. [...] sense = cmp(func(hi), func(lo)) if sense == 0: return None M

Re: Clarity vs. code reuse/generality

2009-07-06 Thread Jean-Michel Pichavant
kj wrote: I've rewritten it like this: sense = cmp(func(hi), func(lo)) assert sense != 0, "func is not strictly monotonic in [lo, hi]" Thanks for your feedback! kj As already said before, unlike other languages, sense in english does **not** mean direction. You should rewrite th

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-06 Thread Jean-Michel Pichavant
protocol = {"start":initialiser,"hunt":hunter,"classify":classifier,other states} def state_machine(): next_step = protocol["start"]() while True: next_step = protocol[next_step]() Woot ! I'll keep this one in my mind, while I may not be that concerned by speed unlike t

Re: Code that ought to run fast, but can't due to Python limitations.

2009-07-06 Thread Jean-Michel Pichavant
Hendrik van Rooyen wrote: "Jean-Michel Pichavant" wrote: Woot ! I'll keep this one in my mind, while I may not be that concerned by speed unlike the OP, I still find this way of doing very simple and so intuitive (one will successfully argue how I was not figuring this o

Re: Clarity vs. code reuse/generality

2009-07-07 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Tue, 07 Jul 2009 05:13:28 +, Lie Ryan wrote: When people are fighting over things like `sense`, although sense may not be strictly wrong dictionary-wise, it smells of something burning... That would be my patience. I can't believe the direction this disc

Re: Clarity vs. code reuse/generality

2009-07-10 Thread Jean-Michel Pichavant
Nobody wrote: On Thu, 09 Jul 2009 04:57:15 -0300, Gabriel Genellina wrote: Nobody says you shouldn't check your data. Only that "assert" is not the right way to do that. "assert" is not the right way to check your *inputs*. It's a perfectly reasonable way to check data which "should"

the ultimate logging facility for debugging code

2009-07-10 Thread Jean-Michel Pichavant
Greetings, Sorry for the dubious title :o). I was wandering if there is a standard (or reliable) python module that implements the following feature: http://code.activestate.com/recipes/198078/ >>>Recipe 198078: Wrapping method calls (meta-class example) >>> >>>A metaclass is used to wrap all

Re: language analysis to enforce code standards

2009-07-10 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Fri, 10 Jul 2009 02:06:35 +, Jason S. Friedman wrote: Hello, I administer the Informatica ETL tool at my company. Part of that role involves creating and enforcing standards. I want the Informatica developers to add comments to certain key objects and I want t

Re: Why not enforce four space indentations in version 3.x?

2009-07-15 Thread Jean-Michel Pichavant
John Nagle wrote: walterbyrd wrote: I believe Guido himself has said that all indentions should be four spaces - no tabs. Since backward compatibility is being thrown away anyway, why not enforce the four space rule? At least that way, when I get python code from somebody else, I would know wh

Re: Colour of output text

2009-07-15 Thread Jean-Michel Pichavant
Nobody wrote: On Fri, 10 Jul 2009 09:23:54 +, garabik-news-2005-05 wrote: I would like to learn a way of changing the colour of a particular part of the output text. I've tried the following On Unix operating systems this would be done through the curses interface: http://docs

Re: missing 'xor' Boolean operator

2009-07-15 Thread Jean-Michel Pichavant
Christian Heimes wrote: Chris Rebert wrote: Using the xor bitwise operator is also an option: bool(x) ^ bool(y) I prefer something like: bool(a) + bool(b) == 1 It works even for multiple tests (super xor): if bool(a) + bool(b) + bool(c) + bool(d) != 1: raise ValueError("

Re: missing 'xor' Boolean operator

2009-07-15 Thread Jean-Michel Pichavant
Hrvoje Niksic wrote: [snip] Note that in Python A or B is in fact not equivalent to not(not A and not B). >>> l = [(True, True), (True, False), (False, True), (False, False)] >>> for p in l: ... p[0] or p[1] ... True True True False >>> for p in l: ... not(not p[0] and not p[1]) ... T

Re: missing 'xor' Boolean operator

2009-07-15 Thread Jean-Michel Pichavant
Miles Kaufmann wrote: On Jul 15, 2009, at 1:43 PM, Jean-Michel Pichavant wrote: Hrvoje Niksic wrote: [snip] Note that in Python A or B is in fact not equivalent to not(not A and not B). >>> l = [(True, True), (True, False), (False, True), (False, False)] >>> for p in l: .

Re: missing 'xor' Boolean operator

2009-07-16 Thread Jean-Michel Pichavant
Nobody wrote: On Wed, 15 Jul 2009 21:05:16 +0200, Jean-Michel Pichavant wrote: So if I resume: - not 'foo' => False - 'foo' or 'foo' => 'foo' I may be missing something, but honestly, Guido must have smoked some heavy stuff to write such logic

Re: missing 'xor' Boolean operator

2009-07-16 Thread Jean-Michel Pichavant
Emile van Sebille wrote: On 7/16/2009 2:06 AM Jean-Michel Pichavant said... Ok then, why "or" does not return True, if the first element is considered True ? Why returning the element itself. Any reason for that ? Because it's confusing, maybe people used to that logic find it

Re: missing 'xor' Boolean operator

2009-07-16 Thread Jean-Michel Pichavant
Emile van Sebille wrote: On 7/16/2009 7:04 AM Unknown said... On 2009-07-16, Emile van Sebille wrote: daysInAdvance = int(inputVar) or 25 I don't get it. That doesn't work right when inputVar == "0". Aah, but you didn't get to define right. :) For that particular example 0 is not a vali

Re: missing 'xor' Boolean operator

2009-07-17 Thread Jean-Michel Pichavant
Luis Alberto Zarrabeitia Gomez wrote: Quoting Jean-Michel Pichavant : Emile van Sebille wrote: On 7/16/2009 7:04 AM Unknown said... On 2009-07-16, Emile van Sebille wrote: daysInAdvance = int(inputVar) or 25 I don't get it. That doesn't work

Re: missing 'xor' Boolean operator

2009-07-17 Thread Jean-Michel Pichavant
Steven D'Aprano wrote: On Thu, 16 Jul 2009 15:53:45 +0200, Jean-Michel Pichavant wrote: Given three result codes, where 0 means "no error" and an arbitrary non- zero integer means some error, it is simple and easy to write: failed = result_1 or result_2 or result_3 The equi

Re: Design question.

2009-07-20 Thread Jean-Michel Pichavant
Lacrima wrote: Hello! I am newbie in python and I have really simple question, but I need your advice to know how to do best. I need to store a number of dictionaries in certain place. I've decided to store them in a separate module. Like this: dicts.py --- dict1 = {} dic

Re: How to import pydoc and then use it?

2009-07-21 Thread Jean-Michel Pichavant
Albert Hopkins wrote: On Mon, 2009-07-20 at 13:38 -0700, mrstevegross wrote: I know how to use pydoc from the command line. However, because of complicated environmental setup, it would be preferable to run it within a python script as a native API call. That is, my python runner looks a bit

Re: Regular expression

2009-07-21 Thread Jean-Michel Pichavant
Rhodri James wrote: On Tue, 21 Jul 2009 14:30:47 +0100, Peter Fodrek wrote: Dear conference! I have third party regular expression self.pattern_main = re.compile('(\s+|\w(?:[+])?\d*(?:\.\d*)?|\w\#\d+|\(.*?\)| \#\d+\=(?:[+])?\d*(?:\.\d*)?)') Also, whoever wrote this regular expression

doted filenames in import statements

2009-07-21 Thread Jean-Michel Pichavant
Hi fellows, I'd like to use the dynamic __import__ statement. It works pretty well with non dotted names, but I cannot figure how to make it work with dotted file paths. example: file = "/home/dsp/test.py" test = __import__(file) works like a charm file = "/home/dsp/4.6.0.0/test.py" test =

<    4   5   6   7   8   9   10   >