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
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):
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
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):
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
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
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
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
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
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
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
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
[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
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
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
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
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
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
["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
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
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
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,
[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
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
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
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
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
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
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
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
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
>
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
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
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
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
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._
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
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
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
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" %
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
>
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
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]
>
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
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
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
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
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
[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__']
>>
[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
[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
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
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
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
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
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
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.
[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
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
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
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
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
gt;>> dict2={'b':'B'}
>>> dict3=dict1.copy()
>>> dict3
{'a': 'A'}
>>> dict3.update(dict2)
>>> dict3
{'a': 'A', 'b': 'B'}
HTH
/Mikael Olofsson
Universitetslektor (Seni
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
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
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
/
<[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
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
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
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
.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
71 matches
Mail list logo