__call__(sys.argv) # instead of "main()"
No major benefit there, we've just changed main to __call__. But
then you can call the script as a stand-alone piece of code from within
Python:
import script
result = script(my_args)
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
is a continuous variable, not a binary
on/off state. Less control gives more flexibility. More control reduces
opportunities.
That's a minor quibble really, the essay is grand and should be read by
all developers.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
turn TABLE % tuple(L)
def type_test(inst1, inst2):
L = ["Comparing object types:"]
for obj in (ham, spam, eggs, inst1.ham, inst1.spam, inst1.eggs, \
inst2.ham, inst2.spam, inst2.eggs):
L.append(get_type(obj))
return TABLE2 % tuple(L)
def main():
inst1 =
eloper
"use these at your own risk", without preventing developers who need them
from using them. You have most of the benefits of private variables with
none of the disadvantages.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
solved by throwing extra layers of software at it?
There is a difference between one million users each who make one request
once a month, and one million users who are each hammering the system with
ten requests a second. Number of users on its own is a meaningless
indicator of req
Terry Reedy wrote:
> "Ron Adam" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>>Actually I think I'm getting more confused. At some point the function
>>is wrapped. Is it when it's assigned, referenced, or called?
>
>
> When it is referenced via the class.
> If you lookup i
y to please change your class and turn that private
attribute into a public one. What happens if you refuse? Can I have you
taken out and shot and seize ownership of your class, or do I have to
copy and paste your class into my code, creating a duplicate class I can
modify as much as I like?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, 28 Sep 2005 16:36:03 -0700, Paul Rubin wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> No, but that is precisely why Python's semi-private variables are
>> usually better. Names like _X and class.__X are warnings to the developer
>> "use t
On Thu, 29 Sep 2005 18:29:36 +0400, en.karpachov wrote:
> On Fri, 30 Sep 2005 00:16:02 +1000
> Steven D'Aprano wrote:
>
>> Say you have written a class, with a private variable. I decide that I
>> need access to that variable, for reasons you never foresaw.
>
ote from "The Princess Bride" is too strong.
Describing Guido's so-called haughtiness: "That word you keep using. I do
not think it means what you think it means."
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
Jorge Godoy wrote:
> From Google I found almost all of those. But do you have any suggestion on
> which one would be better to parse Fortran code? Or more productive to use
> for this task?
>
[snip]
>
>>PyParsing
>> http://pyparsing.sourceforge.net/
Well, I've never had to parse Fortan code,
ional debate. Until we find a way to send electric
shocks through the Internet, all we can do is ignore him. To argue with
him just gives him the sick entertainment he wants.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
;commands"]
As I also said the first time I answered this, you may find the split()
string method useful for creating that list. (Hint: if x is a string, you
call x.split() and get back a list.)
For future reference: any time you think you have found a bug in Python,
the chances are about 999,999 in a million that you've found a bug in your
code.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
David Murmann wrote:
> Hi all!
>
> I could not find out whether this has been proposed before (there are
> too many discussion on join as a sequence method with different
> semantics). So, i propose a generalized .join method on all sequences
> with these semantics:
>
> def join(self, seq):
>
n't you are taking a chance that your class name doesn't
clash with one of the bases.
In other words, this is a Gotcha, not a world-shattering disaster.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
o and the Timbot kicked down my front door and forced me at gun point
to start programming in Python.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
ally worked up over language philosophies, but
comparing lack of "real" private variables to rape is going overboard.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
quot;.
What you are suggesting is that you have private variables that are only
private by convention, since anyone can simply call use spy to treat
them as public. In other words, no different from what Python already
does, except it avoids underscores and introduces at least one new keyword
(spy) and one new syntax element (something to flag a variable as private).
Yeah, that will make a huge difference.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 30 Sep 2005 03:42:32 -0700, Paul Rubin wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> Still, [EMAIL PROTECTED]'s point that you must know the base classes
>> is correct. It is *easy* to find them out (NotSoSecret.__bases__ should do
>> i
vdrab wrote:
> hello pythoneers,
>
> I recently tried to install wordnet 2.0 and pywordnet on both an ubuntu
> linux running python 2.4 and a winXP running activePython 2.4.1, and I
> get the exact same error on both when I try to "from wordnet import *"
> :
>
> running install
> error: invalid P
ss_is_an_idiot are
merely different names for the same underlying module. Change one and you
change the other.
I'm curious... I don't expect you to comment on your boss' mental state,
but how/why do you need to duplicate the module?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
p noticed the extra crazy behaviour on this particular weekend, and
manged to fool himself into thinking it matched a full moon.
See here for more details, plus references to research:
http://skepdic.com/fullmoon.html
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 01 Oct 2005 00:18:44 -0400, Sherm Pendley wrote:
> *whoosh*
>
> That, my friend, was the sound of a joke flying past and completely
> missing you. ;-)
Wouldn't be the first time, and surely not the last. *wink*
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
Paul Rubin wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>> > It's not easy if the base classes change after you check your code in.
>> > You shouldn't need to know about that if it happens. Modularity, remember?
>>
>> Yes. An
nstance attribute
def __str__(self):
"""Convert instance to a string for printing."""
holder = self.left_delimiter
for item in self.data:
holder = holder + str(item) + self.item_delimiter
holder = holder + self.right_delimiter
ed "Fred1" and find "Fred2" instead, oh no.
I'm surprised that they don't just add Yet Another Secret Option to
Firefox's preferences: FileCollision, with two possible values: "Do the
wrong thing" and "Ask the user".
After all, more prefere
re are always trade-offs to be made. Java makes the trade-off one way,
Python the other.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
There are lots of people who can do that. Are you asking them to do it for
free, or are you looking to hire a Python developer to design, build and
test your program?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
he NASA
employee who thought the compiler would catch errors.
Declared variables have considerable labour costs, and only marginal
gains. Since the steps you take to protect against other errors will also
protect against mistyping variables, declarations of variables is of
little practical benefit
er people rely on.
That's why you have testing. You do test, don't you?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
vdrab wrote:
> I had WordNet 2.0 installed but just now I tried it with 1.7.1 as well
> and the result was the same. It's a shame, glossing over the pywordnet
> page really made me want to give it a try.
> Are there any workarounds you can recommend ?
What's your wordnet setup like? I have mine i
time you modify the internal implementation of a function.
Changing the unittests, or any other testing for that matter, only needs
to be done when you change the interface.
In principle, if you have an interface designed up front before you write
any code, you could write all your tests at the start of the project and
never change them again. You can't do that with variable declarations,
since every time you change the implementation you have to change the
declarations.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
declarations aren't almost
free, because they cost a lot in human labour, and that they give you
practically nothing that your unit testing wouldn't give you anyway.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
of consulting and
development work.)
How much money will you save by dropping MS SQL licence fees by migrating
to MySQL or Postgres? Will that money saved be enough to hire a full-time
developer to keep adodbapi updated?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
oss-platform, while
calling a Windows DLL will only work under Windows.
The optimal solution will be to call the DLL when it is
available, and fall back on pure Python if it is not.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
, do you mean "can't cope with long
lines"? How curious -- that's precisely the opposite
definition of well-behaved I use.
> or why mail readers that wrap text/plain content are broken.
Curiouser and curiouser. Again that's the exact
opposite of my definition of broken.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
Mike Meyer wrote:
> Steven D'Aprano <[EMAIL PROTECTED]> writes:
>
>>Declared variables have considerable labour costs, and only marginal
>>gains. Since the steps you take to protect against other errors will also
>>protect against mistyping variables, decla
l clients should support a
subset of HTML so as to provide rich text. But even that comes at a
serious cost (animated smileys, urgh) and in my opinion, the good things
you can do with formatted text don't make that cost worth paying.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
xes
are within the valid range for the list, but (s)he makes that check
*after* attempting to use the indexes. So the code fails before it reaches
the test.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
y to prevent that is to use Python's namespaces: instead of "from
module import name", use "import module", and then call module.name.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
that deliberately
uses this feature for good use, but in general it is something you want to
avoid. Instead of:
def spam(obj, L=[]):
L.append(obj)
do this:
def spam(obj, L=None):
if L is None: L = []
L.append(obj)
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
cal, without
being too specific. You started with the problem "How can I count the
number of times each item in list ttllst exists in ttllst?" A more general
question is "How do I count the number of items *any* object exists in
*any* list?", and then use that code to answer your first question.
Hope this helps,
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
t;10944800e"
but then x will be a string, not a number.
If none of these answers is what you need, you will need to explain your
problem a little better.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
. Instead of pulling our hair out that Python has no
type checking ("that's a bug in the language design, woe woe woe!!!") we
can just say that Python does JIT type checking, which not only is a
feature, but also satisfies the Pointy Haired Bosses who demand buzzwords
they c
ssible -- not forbidden, impossible -- in Latin is no reason to forbid
them in English.
The linguist Steven Pinker calls the sort of people who claim split
infinitives are bad English "language mavens", and he doesn't mean it as
a compliment. See, for example, chapter 12 in his book &
It because
using mixins looks like subclassing to me.
Can anyone help me understand what's going on?
Thanks,
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
e child "being a
kind of" the parent.
[end quote]
from http://c2.com/cgi/wiki?MixIn
Is that all they are?
It is amazing how you can take the simplest concept, and by using
appropriate terminology, make it as confusing and opaque as you want...
*wink*
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
s?
Thanks,
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
well. Vimes
could see the flaw there straight away.
-- The Fifth Elephant
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
ome
else if the result is userpassword:
# we have a match!
go to card "Secret card"
else:
# password doesn't match
go to card "Password failure"
Hope this is of some help to you, and I haven't led you too far astray.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
n its own (e.g. "y" or "n") to mean the same as the entire word.
Using this simpler method:
def yesno(s):
s = s.strip().lower()
if s in ('yes', 'y'):
return 1
elif s in ('no', 'n'):
return 0
else:
return -1
def query:
print "Start process? (y/n)"
choice = yesno(raw_choice("> "))
if choice == -1:
print "Please type Yes or No."
return query()
else:
return choice
Hope this is helpful.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
'E', 'e'):
> #do second option
Is it *really* a good idea if the user types "STOP!!!" and it has the
same effect as if they typed "Start please"?
I've heard of "Do what I mean, not what I said" systems, which are usually
a really bad i
s spoke in very polished
English accents, while the Macedonians (who by their own admission had
been goat herders only to generations before) spoke in broad
Irish/Scottish accents, and the lower class they were, the thicker the
accent.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
command(commands[cmd])
This should accept any combination of:
1 "start"
2 "end" "e"
3 "scratch head"
4 "burp" "b"
in any mix of upper and lower case.
Hope this works for you.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 08 Oct 2005 13:19:48 +1000, Steven D'Aprano wrote:
>
> def count_matches(s, words):
> temp = [word.lower().startswith(s) for word in words]
> return len(temp)
Oops! A *serious* bug in that code :-(
Replace "return len(temp)" with "return len(f
nt
> get it to work. I tryed if choice1 == None it would loop and ask for a new
> input but that didnt seem to work. . .Any ideas for that?
Test for choice1 == "" (the empty string) instead of None.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
de.
You may also find that you could get a slight performance increase by
using the idiom
try:
return cache[args]
except:
# calculate the result and store it in the cache.
instead of testing for membership. As always, timing some test functions
is your friend...
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
rash, reboot, and just pick up the calculations from the last one that
completed. Try doing that with Wintel! :-)
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
elif pr < 0.9:
list_num = 1
else:
list_num = 2
return random.choice(main_list[list_num])
or however you want to extract an item.
On average, this will mean 60% of the items will come from list1 etc, but
for small numbers of trials, you may have significant differences.
--
Steven.
--
the ability to format
text.
> Some people use email PRIMARILY for sharing photos.
Which you can do by attaching the photo to the email. Even mutt or pine
can attach binary files to an email.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 08 Oct 2005 20:44:12 +, Roedy Green wrote:
> On Wed, 05 Oct 2005 09:38:49 +1000, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote or quoted :
>
>>Yes it is. HTML means that after I've specified my email client use my
>>favourite font, in the size I
On Sat, 08 Oct 2005 20:44:44 +, Roedy Green wrote:
> On Wed, 05 Oct 2005 09:38:49 +1000, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote or quoted :
>
>>Even more invariably, they set the point size directly rather than in
>>relative terms, and they are on Windows
recipient can actually
read the damn thing without having to get out a magnifying glass.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
a spam folder.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
27;t care what people will be using in 200 years. I don't care
if in 200 years the default email format is so big and bloated that it
takes three weeks to download even a single sentence, because I won't be
around to suffer.
If you think that people will be using the current data formats fo
again -- that's the dog on the left, in case it isn't clear. Just for a
change, this is Johnny wearing a hat. It is blue with a feather in it,
in case you couldn't tell from, oh I don't know, looking at the actual
picture."
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
ll before I received my first spam. I still hate
it, long after I've got my spam problem under control.
If and when somebody comes up with a non-broken, non-dangerous way of
allowing formatting in emails, I'll consider it. But HTML is not and never
will be that format.
--
Steven.
--
http://ma
olete technology.)
You may have noticed that even Microsoft have acknowledged the power and
flexibility of text-based shells, and will be (if they get the technology
right in time) building one into Vista.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
l?
>
> The photo doesn't have to be included (as in attached)? with the email?
I'll repeat the question: what do attachments have to do with HTML emails?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
That assumes that cache can be seen in this way. If it can't, is this a
way to create "really private" variables in Python?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
hand.
For instance, if you find yourself writing a loop like this:
counter = 0
while counter < some_value:
do_something_with(counter)
counter = counter + 1
you almost always want to change that to:
for counter in range(some_value):
do_something_with(counter)
If you find a loop like this:
for indx in range(len(some_list)):
obj = some_list[indx]
do_something_with(obj)
you almost always want to write it like this:
for obj in some_list:
do_something_with(obj)
Don't fight the language -- you aren't programming in C or Java now, this
is Python and there is usually an easier way to do something.
*wink*
Hope this is of use to you,
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 09 Oct 2005 13:43:38 +0200, Fredrik Lundh wrote:
> Steven D'Aprano wrote:
>
>> I notice that type(some_closure) and type(ordinary_function) both return
>> the same result, . I also notice that both the closure
>> and ordinary functions have an attribute &quo
On Sun, 09 Oct 2005 14:27:32 +0200, Fredrik Lundh wrote:
> Steven D'Aprano wrote:
>
>> Yes I did. Did you read my post?
>
> given that the wikipedia page says
>
> "a closure is an abstraction representing a function, plus the
> lexical environm
ectly there thank you very much.
Yeah. Fine *and* sensible.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
ography - and a public key really *is* public.
The term you want is "wrong", not "confusing".
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
r without needing to call up a search engine.
Honestly, anyone would think that photos and photo albums never existed
before Google. Why force one particular bad technological solution on
everyone for the sake of something which many people don't even perceive
as a problem?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
arning says, could cause Python to
sigfault if you get the opcodes wrong.
I think that this is close enough to "really private" to satisfy most
people. Maybe even Paul Rubin *wink*
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 09 Oct 2005 18:00:13 +0200, Fredrik Lundh wrote:
> Steven D'Aprano wrote:
>
>> "Each def or lambda expression that is executed will create a closure if
>> the body of the function or any contained function has free variables."
>>
>> Pr
ey belonged to different classes.
Python is not like that, which is why you can write a function to return
functions (a factory function?). If the output function needs access to
the namespace of the factory function, Python adds a closure to that
output function, giving it access to the objects in that namespace.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
. the
namespace of the function which created it.
Am I getting there now?
--
Steven
who is very grateful for the time folks have taken to explain this.
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 09 Oct 2005 19:28:31 +, Roedy Green wrote:
> On Sun, 09 Oct 2005 20:54:32 +1000, Steven D'Aprano
> <[EMAIL PROTECTED]> wrote or quoted :
>
>>Only if your photos are so obscure and confusing that they need captions.
>
> That is a hair shirt appro
isten to you go anyone would think that human
communication was impossible before HTML email was invented.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
restarts.
I'm not saying that you will need to restart Python once an hour, or even
once a month. But if you did, would it matter? What's more important is
the state of the operating system. (I'm assuming that, with a year uptime
the requirements, you aren't even thinking o
ood luck
with it. I wish you every success, but don't ask me to buy shares in your
startup.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
what it is worth, Python is compiled AND interpreted -- it compiles
byte-code which is interpreted in a virtual machine. That makes it an
compiling interpreter, or maybe an interpreting compiler, in my book.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
George Sakkis wrote:
> Steven D'Aprano wrote:
>
>
>>On Sun, 09 Oct 2005 23:00:04 +0300, Ville Voipio wrote:
>>
>>
>>>I would need to make some high-reliability software
>>>running on Linux in an embedded system. Performance
>>>
then there is the
question, can you trust the voting mechanism... But if
this is so critical you are worried about cosmic rays,
maybe it is the way to go.
If it is not a secret, what are you monitoring with
this device?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
print "Time with loops:", t1
print "Time with sets:", t2
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
e.
Can anyone point me in the right direction?
Thanks,
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
was considerably slower than the software Lisp solution
of the time.
On the other hand, there were Forth enthusiasts who hacked their
Macintoshes with Forth chips, and they went like a rocket.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
start with. If so, I see
nothing morally wrong with putting it up on your website. (The law may
disagree.)
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
smaller than an ordinary list of N
integers, depending on how large N is.
So it won't use *less* memory -- at best, it will use just slightly more.
Is there a way from within Python to find out how much memory a single
object uses, and how much memory Python is using in total?
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
Laszlo Zsolt Nagy wrote:
> class A(object):
>cnt = 0
>a_cnt = 0
>def __init__(self):
>A.cnt += 1
>if self.__class__ is A:
>A.a_cnt += 1
> class B(A):
>pass
> print A.cnt,A.a_cnt # 0,0
> b = B()
> print A.cnt,A.a_cnt # 1,0
> a = A()
> print A.c
of our sys admins accidentally turned off the
blacklisting at the mail server. In the ten minutes it took to get it
turned back on, the CEO of our company received eight hundred spams.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
or if you use an older version, or a version on a
different platform, or even because you've deleted an item from a dict and
then put it back in. (And if you know anything about typical
implementations of hash tables, you will understand why that last one is
quite reasonable.)
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
black wrote:
> anyone could figure me out ?
No, I suspect people would have to be a trained
psychologist to figure you out.
*wink*
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
the
modules being used, and search them for the string
"error"? Ignore any hits which are in a comment. One of
the others is almost certainly responsible.
You can test that by changing the string to "this is a
PITA" and see if your mysterious error message changes
or not.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
mazon this month...").
If you think this is too ridiculous for words, think of this: how valuable
to Steve Ballmer and Bill Gates do you think Google's internal emails
would be?
Information is power, and power makes money.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
here are fewer places for bugs to hide.
> 3) Where do I find a command list, with syntax and all that fun stuff
> for Python? I've explored the python site to no end, but I can't seem to
> find a list.
Have you looked here?
http://docs.python.org/index.html
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
nction with a "cls" argument, you must add it to the
class with a classmethod() call, and then call it from either the class or
an instance. This method cannot access the instance that calls it, only
the class.
If you write the function without a "self" or "cls" argument, you must add
it to the class with a staticmethod() call. This method cannot access
either the class or the instance object.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
3801 - 3900 of 15563 matches
Mail list logo