Re: Decorating methods - where do my arguments go?

2009-05-12 Thread Mikael Olofsson
Michele Simionato wrote: > Still it turns something which is a function into an object and > you lose the docstring and the signature. pydoc will not be too > happy with this approach. Duncan Booth wrote: I don't know why Mikael wants to use a class rather than a function but if he wants to save

Re: Decorating methods - where do my arguments go?

2009-05-12 Thread Mikael Olofsson
Peter Otten wrote: I usually use decorator functions, but I think the following should work, too: class deco(object): def __init__(self, func): self._func = func def __call__(self, *args): print "Decorator:", args self._func(*args) def __get__(self, *args):

Re: Decorating methods - where do my arguments go?

2009-05-11 Thread Mikael Olofsson
Duncan Booth wrote: The __get__ method should be returning a new object, NOT modifying the state of the decorator. As written it will break badly and unexpectedly in a variety of situations: [snip good examples of things going bad] Ouch! So, does that mean that George's solution based on a

Re: Decorating methods - where do my arguments go?

2009-05-11 Thread Mikael Olofsson
George Sakkis wrote: Yes, just return an actual function from the decorator instead of a callable object: def test_decorator2(func): def wrapper(*args): print 'Decorator2:', args func(*args) return wrapper class cls(object): @test_decorator def meth(self,*args):

Re: Decorating methods - where do my arguments go?

2009-05-11 Thread Mikael Olofsson
Peter Otten wrote: You have to turn your decorator into a descriptor by providing a __get__() method. A primitive example: class test_decorator(object): def __init__(self,func): self._func = func def __call__(self, *args): print 'Decorator:', args self._func(self

Decorating methods - where do my arguments go?

2009-05-08 Thread Mikael Olofsson
Hi all! I have long tried to avoid decorators, but now I find myself in a situation where I think they can help. I seem to be able to decorate functions, but I fail miserably when trying to decorate methods. The information I have been able to find on-line focuses on decorating functions, and

Re: Man Bites Python

2009-04-16 Thread Mikael Olofsson
I don't think the guy in question finds it that funny. Roy Hyunjin Han wrote: Hahaha! On Thu, Apr 16, 2009 at 10:27 AM, Aahz wrote: http://news.yahoo.com/s/nm/20090415/od_nm/us_python_odd_1/print -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ Why is this new

Re: What happened to NASA at Python? :(

2009-03-12 Thread Mikael Olofsson
s...@pobox.com wrote: In fact, graphics were added for several organizations. I believe they will be chosen randomly. NASA is still there. In that case, they must be using the random number generator from Dilbert. You know, the one that said 9, 9, 9, 9,... I, at least, get the same parking

Re: confused about __str__ vs. __repr__

2008-12-18 Thread Mikael Olofsson
Diez B. Roggisch wrote: Yep. And it's easy enough if you don't care about them being different.. def __repr__(self): return str(self) If I ever wanted __str__ and __repr__ to return the same thing, I would make them equal: def __str__(self): return 'whatever you want' __repr__ = __s

Re: Negative integers

2008-08-21 Thread Mikael Olofsson
Derek Martin wrote: Zero is a problem, no matter how you slice it. I definitely agree with that. Depends on the the real problem that is behind the OP:s question. Zero can be considered positive or negative (mathematically, 0 = -0). I've read quite a few articles written by mathematician

Re: passing *args "recursively"

2008-05-13 Thread Mikael Olofsson
Guillermo wrote: This must be very basic, but how'd you pass the same *args several levels deep? def func2(*args) print args # ((1, 2, 3),) # i want this to output (1, 2, 3) as func1! # there must be some better way than args[0]? def func1(*args): print args # (1, 2, 3) func

Re: passing *args "recursively"

2008-05-13 Thread Mikael Olofsson
Guillermo wrote: This must be very basic, but how'd you pass the same *args several levels deep? def func2(*args) print args # ((1, 2, 3),) # i want this to output (1, 2, 3) as func1! # there must be some better way than args[0]? def func1(*args): print args # (1, 2, 3) func

Re: Rounding a number to nearest even

2008-04-11 Thread Mikael Olofsson
[EMAIL PROTECTED] commented about rounding towards even numbers from mid-way between integers as opposed to for instance always rounding up in those cases: > Strange request though, why do you need it that way, because 2.5 is > CLOSER to 3 than to 2... That's exactly how I was taught to do roundi

Re: Sine Wave Curve Fit Question

2008-01-31 Thread Mikael Olofsson
Helmut Jarausch wrote: > Your model is A*sin(omega*t+alpha) where A and alpha are sought. > Let T=(t_1,...,t_N)' and Y=(y_1,..,y_N)' your measurements (t_i,y_i) > ( ' denotes transposition ) > > First, A*sin(omega*t+alpha) = > A*cos(alpha)*sin(omega*t) + A*sin(alpha)*cos(omega*t) = > B*si

Re: about __str__

2007-09-24 Thread Mikael Olofsson
Bruno Desthuilliers wrote: > def __str__(self): > return "<%s:%s>" % (self.commiterID_, self.commits_) I would write that in the following way: def __str__(self): return "<%(commiterID_)s:%(commits_)s>" % self.__dict__ More explicit IMHO. And easier to maintain, especially if the string

Re: beginner, idiomatic python

2007-08-24 Thread Mikael Olofsson
bambam wrote: > > In this case it doesn't matter - my lists don't contain > duplicate elements this time - but I have worked with lists in > money market and in inventory, and finding the intersection > and difference for matching off and netting out are standard > operations. I would use a list

Re: Combinatorial of elements in Python?

2007-08-16 Thread Mikael Olofsson
Sebastian Bassi wrote: > On 8/15/07, Mikael Olofsson <[EMAIL PROTECTED]> wrote: > >> What is unclear here is in what order the keys should be visited. The >> following assumes that the keys should be considered in alphanumeric order. >> > > Yes, my f

Re: Combinatorial of elements in Python?

2007-08-15 Thread Mikael Olofsson
Sebastian Bassi wrote: > Hello, could you do it for an indefinite number of elements? You did > it for a fixed (2) number of elements. I wonder if this could be done > for all members in a dictionary. What is unclear here is in what order the keys should be visited. The following assumes that t

Re: Combinatorial of elements in Python?

2007-08-15 Thread Mikael Olofsson
["H","I"]} > > I want to have all possible combinations from "one" and "two", that is: > [snip] Not at all complicated. My solution: >>> A={'one':['A','B','C','D'],'two':['H

Re: c[:]()

2007-05-31 Thread Mikael Olofsson
Warren Stringer wrote: > I want to call every object in a tupple, like so: > [snip examples] > Why? Because I want to make Python calls from a cell phone. > Every keystroke is precious; even list comprehension is too much. If you are going to do this just a few times in your program, I cannot h

Re: Communicating with a DLL under Linux

2007-03-14 Thread Mikael Olofsson
Thanks for all the responces, both on and off list. So, I should forget about the DLL, and if I intend to connect the thing to a Linux computer, I'll have to develop the code myself for communicating with it over USB. Fair enough. I might even try that. I've done some surfing since yesterday. W

Communicating with a DLL under Linux

2007-03-13 Thread Mikael Olofsson
I am interested in peoples experience with communicating with DLLs under Linux. Situation: I'm an electrical engineer that finds pleasure in using my soldering iron from time to time. I also find programming, preferably in Python, entertaining. I wouldn't call myself a programmer, though. Now,

Re: Tell me the truth

2007-03-08 Thread Mikael Olofsson
[EMAIL PROTECTED] wrote: > If I take into account the fact that 'True' and 'False' are singletons > (guaranteed ?) : > (not not x) is bool(x) # should be always True. > [snip code and results of code] > Consider the following: >>> def ok1(x): return (not not x) is bool(x) >>> def ok2

Re: newbie question(file-delete trailing comma)

2007-02-28 Thread Mikael Olofsson
kavitha thankaian wrote: > my script writes a dictionary to a file.but i need only the values > from the dictionary which should be sepearted by a comma,,,so i did as > following: > [snip code that generates the incorrect original file] > when i execute the above code,my test.txt file has the fol

Re: newbie question(file-delete trailing comma)

2007-02-27 Thread Mikael Olofsson
kavitha thankaian wrote: > i get an error when i try to delete in file and rename it as out > file,,the error says > "permission denied". Perhaps you should give us both the exact code you are running and the complete traceback of the error. That could make things easier. There can be numerous re

Re: Convert to binary and convert back to strings

2007-02-23 Thread Mikael Olofsson
Neil Cerutti wrote: > Woah! You better quadruple it instead. > How about Double Pig Latin? > No, wait! Use the feared UDPLUD code. > You go Ubbi Dubbi to Pig Latin, and then Ubbi Dubbi again. > Let's see here... Ubububythubububonubpubay > That's what I call ubububeautubububifubububulbubay. That

Re: Please take me off the list

2007-01-30 Thread Mikael Olofsson
Daniel kavic wrote: > Sorry to waste email space , but I wish to be off this list because I have > tried python and it is too difficult for me. > That's sad. Go to http://mail.python.org/mailman/listinfo/python-list and follow instructions. /MiO -- http://mail.python.org/mailman/listin

Re: Yield

2007-01-10 Thread Mikael Olofsson
I wrote: > The definition given there is "In mathematics , a > *prime number* (or a *prime*) is a natural number > that has exactly two (distinct) natural number > divisors ." The important part of the statement is > "exactly two...divisors", which rules out the number 1. Or should I say: T

Re: Yield

2007-01-10 Thread Mikael Olofsson
Mathias Panzenboeck wrote: > def primes(): > yield 1 > yield 2 > [snip rest of code] > Hmm... 1 is not a prime. See for instance http://en.wikipedia.org/wiki/Prime_number The definition given there is "In mathematics , a *prime number* (or a *prime*) is a natural number

Re: file backup in windows

2006-11-22 Thread Mikael Olofsson
k.i.n.g. wrote: > [snip code] > The above code was fine while printing, when I am trying to use this > (outlook_path) to use as source path it is giving file permission error > can you please clarify this Did you follow the link that Fredrik Lundh gave you? /MiO -- http://mail.python.org/mailman

Re: deleteing item from a copy of a list

2006-11-14 Thread Mikael Olofsson
timmy wrote: > i make a copy of a list, and delete an item from it and it deletes it > from the orginal as well, what the hell is going on?!?!?! > > #create the staff copy of the roster > Roster2 = [] > for ShiftLine in Roster: > #delete phone number from staff copy >

Re: Why do this?

2006-10-05 Thread Mikael Olofsson
Matthew Warren wrote: > I learned over the years to do things like the following, and I like > doing it like this because of readability, something Python seems to > focus on :- > > Print "There are "+number+" ways to skin a "+furryanimal > > But nowadays, I see things like this all over the plac

Re: How can I make a class that can be converted into an int?

2006-10-02 Thread Mikael Olofsson
Matthew Wilson wrote: > What are the internal methods that I need to define on any class so that > this code can work? > > c = C("three") > > i = int(c) # i is 3 From Python Reference Manual, section 3.4.7 Emulating numeric types: __complex__( self) __int__( self) __long__( self) __float__( se

Re: AN Intorduction to Tkinter

2006-09-27 Thread Mikael Olofsson
t Tkinter modules? > You probably mean http://www.pythonware.com/library/tkinter/introduction/ which is copyrighted 1999. There is also http://effbot.org/tkinterbook/ which I think is the most recent version of it. It states that it is last updated in November 2005. HTH /Mikael Olofsso

Re: Changing behaviour of namespaces - solved, I think

2006-09-21 Thread Mikael Olofsson
Peter Otten wrote: > Clearly more elegant than: > > print open(filename).read() > b = a > dummy = 42 names = [] while 1: > ... ns = dict((n, dummy) for n in names) > ... try: > ... execfile(filename, ns) > ... except Name

Re: Changing behaviour of namespaces - solved, I think

2006-09-21 Thread Mikael Olofsson
Peter Otten wrote: > To feed an arbitrary mapping object to execfile() you need to upgrade to > Python 2.4. Thanks! As clear as possible. I will do that. FYI: I think I managed to achieve what I want in Py2.3 using the compiler module: def getNamesFromAstNode(node,varSet): if node._

Changing behaviour of namespaces

2006-09-21 Thread Mikael Olofsson
Hi! This is in Python 2.3.4 under WinXP. I have a situation where I think changing the behaviour of a namespace would be very nice. The goal is to be able to run a python file from another in a separate namespace in such a way that a NameError is not raised if a non-existing variable is used i

Re: cos: "Integer Required"?!?!?!?

2006-06-08 Thread Mikael Olofsson
moonman wrote: > print self.ACphi, type(self.ACphi) yields: > 19412557 > > value = XPLMGetDataf(self.ACphi); print value type(value ) yields: > -0.674469709396 > > print math.radians(XPLMGetDataf(self.ACphi)), > type(math.radians(XPLMGetDataf(self.ACphi))) yields: > > TypeError > : > an integ

Re: Running Python scripts under a different user

2006-05-31 Thread Mikael Olofsson
Laszlo Nagy wrote: > For Windows, you can use the 'runas.exe' program. But it requires a > password too. Or you can get a copy of the shareware program RunAsProfessional, which I use for my kids stupid games that necessarily has to be run by an admin. The price I paid was 10 Euro, which I still

Re: accesibility of the namespace

2006-03-09 Thread Mikael Olofsson
Petr Jakes wrote: > Ops. My keyboard (fingers) was faster than my mind :( > So > There is more than one "run-time changed variable" in the dictionary > and not all strings in the dictionary are formatted using % operator. > Example: > lcd={ > 2:{2:(("Enter you choice"),("Your kredit= %3d" %

Re: implementation of "complex" type

2006-03-09 Thread Mikael Olofsson
Russ wrote: x = complex(4) y = x y *= 2 print x, y > > (4+0j) (8+0j) > > But when I tried the same thing with my own class in place of > "complex" above, I found that both x and y were doubled. I'd like to > make my class behave like the "complex" class. Can someone tell me the >

Re: Writing an applilcation that can easily adapt to any language

2006-03-01 Thread Mikael Olofsson
Chance Ginger wrote: > I am rather new at Python so I want to get it right. What I am doing > is writing a rather large application with plenty of places that > strings will be used. Most of the strings involve statements of > one kind or another. > > I would like to make it easy for the support

Re: Little tool - but very big size... :-(

2006-02-21 Thread Mikael Olofsson
Durumdara wrote: > But it have very big size: 11 MB... :-( > > The dist directory: > [snip relatively small files] > 2005.09.28. 12:41 1 867 776 python24.dll > [snip relatively small files] > 2006.01.10. 19:09 4 943 872 wxmsw26uh_vc.dll > [snip relatively small files] >

Re: Tkinter Checkboxes

2006-02-20 Thread Mikael Olofsson
D wrote: > Ok, I'm sure this is something extremely simple that I'm missing, > but..how do I set a variable in a Tkinter Checkbox? i.e. I have a > variable "test" - if the checkbox is selected, I want to set test=1, > otherwise 0. Thanks! > http://www.pythonware.com/library/tkinter/introduction

Re: Soduku

2006-02-15 Thread Mikael Olofsson
Jonathan Gardner wrote: > How do you have a 16x16 grid for soduku? Are you using 16 digits? 0-F? > > The one I am using has 9 digits, 9 squares of 9 cells each, or 9x9 > cells. What alphabet you use is irrelevant. Sudokus has really nothing to do with numbers. You can use numbers, as well as let

Re: Create dict from two lists

2006-02-10 Thread Mikael Olofsson
py wrote: > Thanks, itertools.izip and just zip work great. However, I should have > mentioned this, is that I need to keep the new dictionary sorted. Dictionaries aren't sorted. Period. /MiO -- http://mail.python.org/mailman/listinfo/python-list

Re: Tk.quit() now working!

2006-01-31 Thread Mikael Olofsson
Fredrik Lundh wrote: >>how do you run your Tkinter program ? al pacino wrote: > like? i was testing it in windows (interactive interpreter) What Fredrik probably means is: Did you by any chance start it from IDLE? In that case it will not work. It doesn't for me. The reason - I've been told - i

Re: OT: excellent book on information theory

2006-01-19 Thread Mikael Olofsson
Terry Hancock wrote: "Tim Peters" <[EMAIL PROTECTED]> wrote: >> UK:Harry smiled vaguely back >> US:Harry smiled back vaguely Terry Hancock wrote: > I know you are pointing out the triviality of this, since > both US and UK English allow either placement -- but is it > really preferred

Re: newbie - How do I import automatically?

2005-11-17 Thread Mikael Olofsson
[EMAIL PROTECTED] wrote: >> I tried to do it on my computer (win XP). I put an extra line in >> PyShell.py >> [snip] >> # test >> sys.modules['__main__'].__dict__['os'] = os >> [snip] >> Then when I start idle I get >> >> IDLE 1.1.1 >> > dir() >> >> >> ['__builtins__', '__doc__', '__name__'] >>

Re: newbie - How do I import automatically?

2005-11-17 Thread Mikael Olofsson
[EMAIL PROTECTED] wrote: > I tried to do it on my computer (win XP). I put an extra line in > PyShell.py > [snip] > # test > sys.modules['__main__'].__dict__['os'] = os > [snip] > Then when I start idle I get > > IDLE 1.1.1 > dir() > > ['__builtins__', '__doc__', '__name__'] > > > So I don

Re: newbie - How do I import automatically?

2005-11-16 Thread Mikael Olofsson
[EMAIL PROTECTED] wrote: > I tried to put the line > from btools import * > in several places in PyShell.py > but to now avail. It does not work, IDLE does not execute it??? IDLE definitely executes PyShell.py upon startup, since IDLE does not even appear on the screen if there is an error in tha

Re: any python module to calculate sin, cos, arctan?

2005-11-08 Thread Mikael Olofsson
Shi Mu wrote: > any python module to calculate sin, cos, arctan? Try module math. Or cmath if you want the functions to be aware of complex numbers. /MiO -- http://mail.python.org/mailman/listinfo/python-list

Re: how to stop a loop with ESC key? [newbie]

2005-11-08 Thread Mikael Olofsson
Fredrik Lundh wrote: > works for me, when running it from a stock CPython interpreter in a windows > console window, with focus set to that window. > > what environment are you using? Could be IDLE. The code Fredrik proposed works well for me in the Python console window, but not in IDLE (thats

Re: Would there be support for a more general cmp/__cmp__

2005-10-20 Thread Mikael Olofsson
Antoon Pardon wrote: > Op 2005-10-20, Duncan Booth schreef <[EMAIL PROTECTED]>: > >>Antoon Pardon wrote: >> >> >>>The problem now is that the cmp protocol has no way to >>>indicate two objects are incomparable, they are not >>>equal but neither is one less or greater than the other. >> >>If that i

Re: Dynamic generation of doc-strings of dynamically generated classes

2005-10-18 Thread Mikael Olofsson
Alex Martelli wrote: > The best way to make classes on the fly is generally to call the > metaclass with suitable parameters (just like, the best way to make > instances of any type is generally to call that type): > > derived = type(base)('derived', (base,), {'__doc__': 'zipp'}) and George Sakki

Dynamic generation of doc-strings of dynamically generated classes

2005-10-17 Thread Mikael Olofsson
Hi! I've asked Google, but have not found any useful information there. Situation: I have a base class, say >>> class base(object): ImportantClassAttribute = None Now, I want to dynamically generate subclasses of base. That's not a problem. However, I very much want those subclasses

Re: Changing the module not taking effect in calling module

2005-09-27 Thread Mikael Olofsson
Gopal wrote: > I've a module report.py having a set of funtions to open/close/write > data to a log file. I invoke these functions from another module > script.py. > > Whenever I'm changing something in report.py, I'm running the file > (however, it has not effect). After that I'm running script.

Re: Help w/ easy python problem

2005-09-22 Thread Mikael Olofsson
[EMAIL PROTECTED] wrote: > I am very much a beginner to python. I have been working on writing a > very simple program and cannot get it and was hoping someone could help > me out. Basically i need to write a code to print a sin curve running > down the page from top to bottom. The trick is I ha

Re: plateform info.

2005-09-20 Thread Mikael Olofsson
Monu Agrawal wrote: > Hi I want to know whether the program is being run on windows or on > Xnix. Is there any variable or method which tells me that it's windows? Will this help? >>> import sys >>> sys.platform 'win32' There is also the platform module, that can give you a lot more informati

Re: Tkinter add_cascade option_add

2005-09-15 Thread Mikael Olofsson
Eric Brunel wrote in reply to Bob Greschke: > I'm still not sure what your exact requirements are. Do you want to have > a different font for the menu bar labels and the menu items and to set > them via an option_add? If it is what you want, I don't think you can do > it: the menus in the menu b

Re: working with VERY large 'float' and 'complex' types

2005-09-15 Thread Mikael Olofsson
Paul Rubin calculates exp(1000.0): > You could rearrange your formulas to not need such big numbers: > > x = 1000. > log10_z = x / math.log(10) > c,m = divmod(log10_z, 1.) > print 'z = %.5fE%d' % (10.**c, m) Nice approach. We should never forget that we do have mathematical skill

Re: Optional algol syntax style

2005-09-05 Thread Mikael Olofsson
Sokolov Yura wrote: > I think, allowing to specify blocks with algol style (for-end, if-end, > etc) will allow to write easy php-like templates > and would attract new web developers to python (as php and ruby do). > It can be straight compilled into Python bytecode cause there is > one-to-one tr

Re: how to join two Dictionary together?

2005-08-30 Thread Mikael Olofsson
gt;>> dict2={'b':'B'} >>> dict3=dict1.copy() >>> dict3 {'a': 'A'} >>> dict3.update(dict2) >>> dict3 {'a': 'A', 'b': 'B'} HTH /Mikael Olofsson Universitetslektor (Seni

Re: aproximate a number

2005-08-29 Thread Mikael Olofsson
Michael Sparks wrote: > def approx(x): > return int(x+1.0) I doubt this is what the OP is looking for. >>> approx(3.2) 4 >>> approx(3.0) 4 Others have pointed to math.ceil, which is most likely what the OP wants. /Mikael Olofsson Universitetslektor (Senior L

Re: prime number

2005-05-31 Thread Mikael Olofsson
at least occationally. So every engineering education program should involve at least some programming. /Mikael Olofsson Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE]) Linköpings universitet --- E-Mail: [EMAIL

Re: a re problem

2005-05-20 Thread Mikael Olofsson
cheng wrote: >>>p.sub('','%s') % "a\nbc" >>> >>> >'a\nbc' > >is it anyone got some idea why it happen? > Make that p.sub('','%s' % "a\nbc") Regards /

Re: Printable version of Python tutorila

2005-04-14 Thread Mikael Olofsson
<[EMAIL PROTECTED]> wrote: I liked the python tutorial ( http://www.python.org/doc/current/tut/tut.html ) very much. Now i want to print this tutorial. Where do i get a printable version of the document? http://www.python.org/doc/current/download.html Regards /Mikael Olofsson Universitets

Re: Begniner Question

2005-03-21 Thread Mikael Olofsson
ed block. You need to put something between if and else, at least a pass. Regards -- /Mikael Olofsson Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE]) Linköpings universitet --- E-Mail: [EMAIL PROTECTED] WWW: ht

Twain problems

2005-01-31 Thread Mikael Olofsson
results in what I interprete as C or C++ code, which does not help me much. I'm less fluent in C or C++ than I am in Italian (I can order a beer and buy postcards or stamps, that's more or less it). I-cannot-order-a-beer-in-C-but-I-can-in-Python-ly yours /Mikael Olofsson Universitetslek

Re: Galois field

2004-12-03 Thread Mikael Olofsson
1 0 x Regards /Mikael Olofsson Universitetslektor (Senior Lecturer [BrE], Associate Professor [AmE]) Linköpings universitet --- E-Mail: [EMAIL PROTECTED] WWW: http://www.dtr.isy.liu.se/en/staff/mikael Phone: +46 - (0)13 - 2

Re: Galois field

2004-12-03 Thread Mikael Olofsson
.edu/~emin/source_code/py_ecc/ I have not looked into those, but at least the first one seems to be in a very early state, since its version number is 0.1.1. The second one contains code for handling Reed-Solomon codes, which among other things includes arithmetic for finite fields. Good luck! /Mikae