Be careful, though - make sure you can absolutely trust your source of
data before calling eval on it.
If an unauthorised person could forseeably modify your file, then they
could insert a string containing arbitrary Python code into it in place
of your list, and then running your program would ca
If you decide to steer clear of eval, the following comes close to what
you want, and is somewhat Pythonic (I feel):
def back_to_list(str):
return str.strip("[]").split(", ")
>>> s = "[1, 2, 3, 4, 5, 6]"
>>> back_to_list(s)
['1', '2', '3', '4', '5', '6']
So parsing the list structure is prett
You can add Australia to the list :)
Any volunteers for a fourth continent? Antarctica, perhaps? ;)
- Jordan
--
http://mail.python.org/mailman/listinfo/python-list
The problem with all posts that say "Use Visual Basic, its easy for
small programs" is that small programs, seemingly inevitably, become
bigger programs (unless they become dead, unmaintained programs). If
your users - you, your boss, coworkers, whoever - find your software
useful, and you start to
Python 3000 is the proveribal and so far hypothetical version of the
language in which backward incompatible changes will be allowed (and
encouraged).
See
http://www.python.org/peps/pep-3000.html
for details.
[EMAIL PROTECTED] wrote:
> Guido gave a nice "Python Regrets" Power Point talk at OSCO
I don't know how hard this would be to do in Python - appending text to
a file is straightforward, but it sounds like you'd need to extend the
browser itself to get the functionality you want. The most obvious
choice if you want an extensible browser is Mozilla Firefox
(http://www.mozilla.org/produ
used for URLs too" debate, though).
Ultimately, its just not different enough from backslash to be very
confusing (hear I'll put in a disclaimer, that I don't have enough
computing experience to know of any OS where neither type of slash is
used in paths.)
And thats my 14.5 cents :)
Raising an assertion error for a < b is a bit of overkill, since its
not really a case of bad input. So normally you see Euclid done like
this:
def gcd(a,b): # All lowercase for a function is a bit more
conventional.
if a < b:
a, b = b, a # Ensures a >= b by swapping a and b if nessec
Correct me if I'm wrong, but I think the OP was asking if metaclasses
work with old-style classes, not new-style.
[EMAIL PROTECTED] wrote:
> This may be a limitation Zope imposes.
>
> I wrote this program:
> #---
> class M(type):
Good point. I suppose I'd only ever seen it implemented with the if
test, but you're right, the plain while loop should work fine. Silly
me.
def gcd(a,b):
while b != 0:
a, b = b, a%b
return a
Even nicer.
--
http://mail.python.org/mailman/listinfo/python-list
Talin asked:
> Also, on a completely different subject: Has there been much discussion
> about extending the use of the 'is' keyword to do type comparisons a la
> C# (e.g. "if x is list:") ?
>
> -- Talin
No, is already has a specific, well defined meaning - object identity.
IDLE 1.1
>>> a = [1,2
could ildg said:
> I want to use re because I want to extract something from a html. It
> will be very complicated without using re. But while using re, I
> found that I must exlude a hole word "", certainly, there are
> many many "" in this html.
Actually, for properly processing html, you shou
Sounds like you want the bitwise and operator, &
>>> 2 & 3
2
>>> 32 & 16
0
>>> 31 & 12
12
etc.
[EMAIL PROTECTED] inquired:
> i have an interesting project at work going on. here is the challenge.
> i am using the serial module to read data from a serial input.
> it comes in as a hex. i need to m
What you've posted looks right, more or less.
To get any sort of meaningful feedback, you really need to post a full
version of your code, including the print statements, what's being
printed, and why you think this shows the code is not working. What
you've shown is far too little for anybody els
I've written this kind of iterator before, using collections.deque,
which personally I find a little more elegant than the list based
approach:
from collections import deque
def interleave(*iterables):
iters = deque(iter(iterable) for iterable in iterables)
while iters:
it = iters
First, a disclaimer. I am a second year Maths and Computer Science
undergraduate, and this is my first time ever on Usenet (I guess I'm
part of the http generation). On top of that, I have been using Python
for a grand total of about a fortnight now. Hence, I apologise if what
follows is a stupid s
Sorry about the mangled formatting... like i said, first time on Usenet
Suggestions, comments, replies, etc most welcome.
This definitely includes replies of the form: "This is stupid,
because..."
provided it isnt followed with "youre a jerk who knows nothing.
Period."
Heres a follow up rant in
Thanks for the very fast feedback :)
I specifically set optionalline = None to deal with that bug you
mentioned, with the implicit assumption createRecord knows how to deal
with a None argument. If that guard got destroyed in the copy paste
process, my bad.
As for you solution, yes, you could do
Yes, granted.
This is basically the same as Andrew's reply, except with Iterators in
place of generators, so I'll let my answer to that stand. In fact, its
my solution, but with iter.next() in place of accept :)
This is probably something like how I wanted to solve the problem when
I first was lo
Wow, if I'm going to get replies (with implemented solutions!) this
quickly, I'll post here more often :-)
This is the most different to my solution, and also the shortest, and
therefore the most interesting, reply so far. Its also the last one
I'll reply to before I go to bed.
Its taken
> No, it's nothing special about groupby. record simply stores its
state in a
> mutable default parameter. This isn't general good practice: at
least you have
> to be careful with it. You can see the behavior in the following
example:
> >>> def accumulate(value, accum = []):
> ... accum.
Hmmm, I like the terminology consumers better than acceptors.
The ability to have 'full coroutines', or at least more 'coroutiney
behaviour' than is provided by generators alone, was I think what I was
trying to get at with my original idea, although things got a bit
sidetracked by the way I focus
I think I found your bug, although it took a bit of time, a fair bit of
thought, and a fair bit of extra test-framework code - your program is
very concise, reasonably complex, and very unreadable. Its perfect for
testing maths theorems of your own interest, but you probably should
have polished it
Sean McIlroy wrote:
>
> Wow again. I had a real "V8 moment" when I looked at your solution
> (smacking my forhead, groaning ruefully, etc). You were right: my
> intention was simply to hide the trivial cases from view; I
completely
> missed the fact that I was now testing for membership in a diffe
Unless I'm mistaken, this doesnt quite work, because it switches the
parity of phase every time a comparison is made, rather than every time
a swap is made. So:
#
phase = 1
def mycmp(x,y):
global phase
c = cmp(x,y)
if c > 0: # i.e. a swap will be performed in the sort
phase = -pha
rickle wrote:
> I'm trying to compare sun patch levels on a server to those of what
sun
> is recommending. For those that aren't familiar with sun patch
> numbering here is a quick run down.
>
> A patch number shows up like this:
> 113680-03
> ^^ ^^
> patch# revision
>
> What I want to do is
Max M wrote:
> I am writing a "find-free-time" function for a calendar. There are a
lot
> of time spans with start end times, some overlapping, some not.
>
> To find the free time spans, I first need to convert the events into
a
> list of non overlapping time spans "meta-spans".
>
> This nice asci
Should work fine as far as I can see. Of course, thats not very
'pythonic' - I should probably give at least 10 different unit tests
that it passes ;)
Its gratifying to know I'm not the only one who needed that final
yield.
Jim Sizelove wrote:
> Bengt Richter wrote:
> > On Tue, 10 May 2005 15:14:
y first time, how exciting!), and in the
meantime, I'll let replies start accumulating froma whole lot of
people who are a lot smarter and more experience in Python than myself
:)
Several-weeks-in-and-still-liking-Python-better-than-any-other-previously-learned-language-ly
yours,
Jordan Rastrick
--
http://mail.python.org/mailman/listinfo/python-list
Leif K-Brooks wrote:
> Regardless of the various issues surrounding isinstance(), you have a
> difference in functionality. Since you're just storing a reference in
> the case of another LinkedList instead of copying it, mutating the
> LinkedList will be different from mutating another iterable t
Thanks for the replies, everyone. As is usual when reading
comp.lang.python, I got some invaluable exposure to new ideas (multiple
dispatching in particular seems to fill a gap I've felt in OO
programming in the past.)
I'm starting to think this newsgroup is in its own right an excellent
reason to
Well, copying and pasting this text, and changing <<>> to Foo so
that its a legal Python identifier (why did you not want to name your
class, out of curiosity), I get no problems with this.
class Foo:
def digest():
''' char[28] digest ( )
Return the digest of the strings passe
If you email the script to me, I'd be happy to take a look at it and
see if I come up with the same error (I'm running IDLE on a Windows XP
box here, cant remember if the filesystem is FAT or NTFS ;-))
Although as a relative newbie I've never come across it myself, one
possible source of such myst
Is having to read two lines really that much worse than one? And the
only thing you find objectionable about the most obvious solution?
If so, then what's wrong with:
def foo():
# do some stuff
if debug: emit_dbg_obj(DbgObjFoo(a,b,c))
# do more stuff
To my mind, this is no l
Although you get infinite recursion with this code, you still get
enough information on the error from the interpreter to help you debug.
Running IDLE, I get a traceback of:
File "C:/Documents and Settings/Jordan/Desktop/more_blah.py", line 11,
in __init__
self.createFrames()
File "C:/Docum
comp.lang.python is a great newsgroup in that respect - so long as you
ask a semi-intelligent question, you nearly always end up with a quick
and helpful response.
Good luck with learning programming, and Python (IMO its one of the
best possible languages to do it in)
--
http://mail.python.org/m
Can anybody please give me a decent justification for this:
class A(object):
def __init__(self, a):
self.a = a
def __eq__(self, other):
return self.a == other.a
s = A(3)
t = A(3)
>>> print s == t
True
>>> print s != t
True
I just spent a long, long time tracking down a
Well, I don't really want the objects to be comparable. In fact, to
quote that PEP you linked:
An additional motivation is that frequently, types don't have a
natural ordering, but still need to be compared for equality.
Currently such a type *must* implement comparison and thus
Just because a behaviour is documented, doesn't mean its not counter
intutitive, potentially confusing, and unnessecary.
I have spent a fair amount of time reading the Python docs. I have not
yet memorised them. I may have read this particular section of the
reference manual, or I may have not, I
I'd suggest the only nessecary change is, if objects a,b both define
__eq__ and not __ne__, then a != b should return not (a == b)
If a class defines __ne__ but not __eq__, well that seems pretty
perverse to me. I don't especially care one way or another how thats
resolved to be honest.
The order
Well, I'll admit I haven't ever used the Numeric module, but since
PEP207 was submitted and accepted, with Numeric as apparently one of
its main motivations, I'm going to assume that the pros and cons for
having == and ilk return things other than True or False have already
been discussed at length
I'm a Maths and Philosophy undergraduate first and foremost, with
Computer Science as a tacked on third; I've studied a fair bit of logic
both informally and formally, and am familiar with things such as the
non-nessecity of the law of the excluded middle in an arbitrary
propositional calculus farm
The : is used in Python for slice notation, which is explained pretty
thoroughly in the Python tutorial, specifically at:
http://www.python.org/doc/2.4/tut/node5.html
--
http://mail.python.org/mailman/listinfo/python-list
Python's current scoping differs from that in versions 2.1 and earlier
- statically nested (lexical) scoping was introduced under PEP 227.
I don't know what differences, if any, remain between Python's and
Perl's scoping rules, or if there is any tutorial concerning Python
scoping thats aimed spec
I've coded some simple recursive tree data structures using OO before
(unfortunately not in Python though). It's not nessecarily an
ill-suited approach to the task, although it depends on the specific
details of what you're doing. What's the the piece of code from which
your if...elif fragment is t
Another thing to keep in mind is that while technically both Python and
Java are converted into intermediate byte-codes, which are then
interpreted, the Java Virtual Machine runs java bytecode significantly
faster. Partly this is because Sun have put a lot of effort into making
Java as fast as poss
46 matches
Mail list logo