Ron Adam wrote:
> Erik Max Francis wrote:
>
>>Ron Adam wrote:
>>
>>
>>>When you call a method of an instance, Python translates it to...
>>>
>>> leader.set_name(leader, "John")
>>
>>
>>It actually translates it to
>>
>>Person.set_name(leader, "John")
>>
>
>
> I thought that I might have
Jeremy Sanders wrote:
> Colin J. Williams wrote:
>
>
>>Could you not have functions a and b each of which returns a NumArray
>>instance?
>>
>>Your expression would then be something like a(..)+2*b(..).
>
>
> The user enters the expression (yes - I'm aware of the possible security
> issues), as
Ron Adam wrote:
> What I've noticed is you can block the visibility of a class attribute,
> which include methods, by inserting an object in the instance with the
> same name.
>
[snip example of this behavior]
Yes, that's true for "non-data descriptors" (see last two bullets below)
Raymond Het
Lucas Lemmens wrote:
> Dear pythonians,
>
> I've been reading/thinking about the famous function call speedup
> trick where you use a function in the local context to represent
> a "remoter" function to speed up the 'function lookup'.
>
> "This is especially usefull in a loop where you call the
[EMAIL PROTECTED] wrote:
> hi if I have an array
>
> say x = [[2,2,0,0,1,1],
> [1,1,0,0,1,1],
> [1,1,0,0,1,1]]
> I basically want to group regions that are non zero like I want to get
> the coordinates of non zero regions..as (x1,y1,x2,y2)
> [(0,0,2,1),(0,4,2,5)] which show the t
[EMAIL PROTECTED] wrote:
> fredrick's solutions seems to be more closer to what I was looking
> for.But I am still not sure if that could be done without the use of
> Image module.
What do you mean by "closer to what I was looking
for"? For the single test case you provided:
> say x = [[2,2,0,0
Terry Reedy wrote:
> "David Murmann" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
>
>>>def join(sep, seq):
>>>return reduce(lambda x, y: x + sep + y, seq, type(sep)())
>>
>>damn, i wanted too much. Proper implementation:
>>
>>def join(sep, seq):
>>if len(seq):
>>r
Kent Johnson wrote:
> Rusty Shackleford wrote:
>> ...
>> C_1_1 and C_1_2 share a common C ancestor, and in practice may be
>> identical, but theoretically, could have the same function name with two
>> different implementations underneath.
>>
>> ...
>
> How are you instantiating the correct class?
David Isaac wrote:
for a solution when these are available.
> Something like:
> def cumreduce(func, seq, init = None):
> """Return list of cumulative reductions.
>
>
This can be written more concisely as a generator:
>>> import operator
>>> def ireduce(func, iterable, init):
...
Steven Bethard wrote:
> I've got a list of word substrings (the "tokens") which I need to align
> to a string of text (the "sentence"). The sentence is basically the
> concatenation of the token list, with spaces sometimes inserted beetween
> tokens. I need to determine the start and end offse
Brendan wrote:
...
>
> class Things(Object):
> def __init__(self, x, y, z):
> #assert that x, y, and z have the same length
>
> But I can't figure out a _simple_ way to check the arguments have the
> same length, since len(scalar) throws an exception. The only ways
> around this I've
A.M. Kuchling wrote:
> Here are some thoughts on reorganizing Python's documentation, with
> one big suggestion.
>
Thanks for raising this topic, and for your on-going efforts in this field.
I use the compiled html help file provided by PythonWin, which includes all the
core documentation. I u
Daniel Schüle wrote:
> Hello NG,
>
> I am wondering if there were proposals or previous disscussions in this
> NG considering using 'while' in comprehension lists
>
> # pseudo code
> i=2
> lst=[i**=2 while i<1000]
>
You are actually describing two features that list comps don't natively suppor
A.M. Kuchling wrote:
> On Tue, 06 Dec 2005 10:29:33 -0800,
> Michael Spencer <[EMAIL PROTECTED]> wrote:
>> not that helpful. "Miscellaneous Services", in particular, gives no clue to
>> treasures it contains. I would prefer, for example, to see the data
Fredrik Lundh wrote:
> Rocco Moretti wrote:
>
>> Insert punctuation & capitalization to make the following a correct and
>> coherent (if not a little tourtured).
>>
>> fred where guido had had had had had had had had had had had a better
>> effect on the reader
>
> punctuation, including quote ma
Thomas Liesner wrote:
> Hi all,
>
> i am having a textfile which contains a single string with names.
> I want to split this string into its records an put them into a list.
> In "normal" cases i would do something like:
>
>> #!/usr/bin/python
>> inp = open("file")
>> data = inp.read()
>> names =
[EMAIL PROTECTED] wrote:
> I'm trying to add a class to a module at runtime. I've seen examples
> of adding a method to a class, but I haven't been able to suit it to my
> needs.
>
> As part of a testsuite, I have a main process X that searches
> recursively for python test files. Those files ty
[EMAIL PROTECTED] wrote:
...
> exec testModule.TheTestCode %(testModule.TheTestName, testModule.TheTestName )
...
Try changing that to exec ~ in testModule.__dict__
otherwise, your class statement gets executed in the current scope
Michael
--
http://mail.python.org/mailman/listinfo/python-lis
Steve Young wrote:
> Hi, this is probably an easy question but is there a way to get the host and
> path seperatly out of an url?
>
> Example:
>
> url = http://news.yahoo.com/fc/world/iraq
>
> and i want some way of getting:
>
> host = http://news.yahoo.com
> and
> path =
[EMAIL PROTECTED] wrote:
> Thomas Liesner wrote:
>> Hi all,
>>
>> i am having a textfile which contains a single string with names.
>> I want to split this string into its records an put them into a list.
>> In "normal" cases i would do something like:
>>
>>> #!/usr/bin/python
>>> inp = open("file"
Roman Suzi wrote:
Maybe this is too outlandish, but I see lambdas as a "quote" mechanism,
which presents a possibility to postpone (precisely control, delegate)
evaluation. That is, an ovehead for lambda must be much lower but at the
same time visible to the programmer:
d = a + (lambda x, y: x+ y)
Dan Stromberg wrote:
Is there already a pure python module that can do modular-arithmetic unit
conversions, like converting a huge number of seconds into months,
weeks... or a bandwidth measure into megabits/s or gigabits/s or
megabytes/s or gigabytes/s, whatever's the most useful (ala df -h)?
Than
Kamilche wrote:
I want my program to be able to reload its code dynamically. I have a
large hierarchy of objects in memory. The inheritance hierarchy of
these objects are scattered over several files.
I find that after reloading the appropriate files, and overwriting the
__class__ of object instanc
Kamilche wrote:
I want my program to be able to reload its code dynamically. I have a
large hierarchy of objects in memory. The inheritance hierarchy of
these objects are scattered over several files.
Michael Spencer wrote:
An alternative approach (with some pros and cons) is to modify the class
Alex Martelli wrote:
[explanation and the following code:]
>>> a, b, c = it.islice(
... it.chain(
... line.split(':'),
... it.repeat(some_default),
... ),
... 3)
...
...
>>> def pad_with_default(N, iter
Paul Rubin wrote:
YAML looks to me to be completely insane, even compared to Python
lists. I think it would be great if the Python library exposed an
interface for parsing constant list and dict expressions, e.g.:
[1, 2, 'Joe Smith', 8237972883334L, # comment
{'Favorite fruits': ['apple
Fredrik Lundh wrote:
Sion Arrowsmith wrote:
I'm probably not thinking deviously enough here, but how are you
going to exploit an eval() which has very tightly controlled
globals and locals (eg. eval(x, {"__builtins__": None}, {}) ?
try this:
eval("'*'*100*2*2*2*2*2*2*2*2*2")
I updated the s
Francis Girard wrote:
The following implementation is even more speaking as it makes self-evident
and almost mechanical how to translate algorithms that run after their tail
from recursion to "tee" usage :
Thanks, Francis and Jeff for raising a fascinating topic. I've enjoyed trying
to get my
Nick Craig-Wood wrote:
Steven Bethard <[EMAIL PROTECTED]> wrote:
Nick Craig-Wood wrote:
Thinking about this some more leads me to believe a general purpose
imerge taking any number of arguments will look neater, eg
def imerge(*generators):
values = [ g.next() for g in generators ]
while True:
Steven Bethard wrote:
>
> I wish there was a way to, say, exec something with no builtins and
with
> import disabled, so you would have to specify all the available
> bindings, e.g.:
>
> exec user_code in dict(ClassA=ClassA, ClassB=ClassB)
>
> but I suspect that even this wouldn't really
Steven Bethard wrote:
>
> I wish there was a way to, say, exec something with no builtins and
> with import disabled, so you would have to specify all the available
> bindings, e.g.:
>
> exec user_code in dict(ClassA=ClassA, ClassB=ClassB)
>
> but I suspect that even this wouldn't really solve
Steven Bethard wrote:
Michael Spencer wrote:
Safe eval recipe posted to cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469
This recipe only evaluates constant expressions:
"Description:
Evaluate constant expressions, including list, dict and tuple using the
abstract s
Cameron Laird wrote:
In article <[EMAIL PROTECTED]>,
Michael Spencer <[EMAIL PROTECTED]> wrote:
.
.
.
Right - the crux of the problem is how to identify dangerous objects. My point
is that if such as test is po
Davor wrote:
Thanks,
I do not hate OO - I just do not need it for the project size I'm
dealing with - and the project will eventually become open-source and
have additional developers - so I would prefer that we all stick to
"simple procedural" stuff rather than having to deal with a developer
that
Paul Rubin wrote:
Francis Girard <[EMAIL PROTECTED]> writes:
Thank you Nick and Steven for the idea of a more generic imerge.
If you want to get fancy, the merge should use a priority queue (like
in the heapsort algorithm) instead of a linear scan through the
incoming iters, to find the next item
Steven Bethard wrote:
I'm sorry, I assume this has been discussed somewhere already, but I
found only a few hits in Google Groups... If you know where there's a
good summary, please feel free to direct me there.
I have a list[1] of objects from which I need to remove duplicates. I
have to mai
Marc Huffnagle wrote:
I have a number of variables that I want to modify (a bunch of strings
that I need to convert into ints). Is there an easy way to do that
other than saying:
> a = int(a)
> b = int(b)
> c = int(c)
It may not matter to you, at the moment, but a = int(a) is not strictly
'
McBooCzech wrote:
Hallo all,
I am trying to generate SQL SELECT command which will return pivot
table. The number of column in the pivot table depends on the data
stored in the database. It means I do not know in advance how many
columns the pivot table will have.
For example I will test the databa
Jorey Bump wrote:
> ... Is there a NotSoSimpleHTTPServer? ...
Steve Holden wrote:
> ... You want ExtremelyBloodyComplicatedHTTPServer :-)
Lee Harr wrote:
... I think I would point to twisted for that.
Michael :-)
--
http://mail.python.org/mailman/listinfo/python-list
Steven Bethard wrote:
I have lists containing values that are all either True, False or None,
e.g.:
[True, None, None, False]
[None, False, False, None ]
[False, True, True, True ]
etc.
For a given list:
* If all values are None, the function should return None.
* If at leas
Bo Peng wrote:
Dear list,
I have many dictionaries with the same set of keys and I would like to
write a function to calculate something based on these values. For
example, I have
a = {'x':1, 'y':2}
b = {'x':3, 'y':3}
def fun(dict):
dict['z'] = dict['x'] + dict['y']
fun(a) and fun(b) will set
Bo Peng wrote:
Michael Spencer wrote:
>
There are hundreds of items in the dictionary (that will be needed in
the calculation) so passing the whole dictionary is a lot better than
passing individual items.
...
def fun(d):
exec 'z = x + y' in globals(), d
seems to be more readable
Fahri Basegmez wrote:
reduce(lambda x, y: x or y, lst)
works but when I tried
import operator
reduce(operator.or_, lst)
this did not work. It pukes
Traceback (most recent call last):
File "", line 1, in ?
TypeError: unsupported operand type(s) for |: 'NoneType' and 'bool'
Any comments?
Fahri
Ty
Nick Coghlan wrote:
Michael Spencer wrote:
def fun(dict):
# set dict as local namespace
# locals() = dict?
z = x + y
As you no doubt have discovered from the docs and this group, that
isn't doable with CPython.
Not entirely impossible:
Py> def f(d):
... exec "loca
Fahri Basegmez wrote:
"Michael Spencer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Fahri Basegmez wrote:
reduce(lambda x, y: x or y, lst)
works but when I tried
import operator
reduce(operator.or_, lst)
this did not work. It pukes
Traceback (most recent c
Alex Martelli wrote:
Hmmm, you do realize that wrapdict uses a lot of indirection while my
equivalent approach, just posted, is very direct, right? To reiterate
the latter, and dress it up nicely too, it's
class wrapwell(object):
def __init__(self, somedict):
self.__dict__ = somedict
B
Alex Martelli wrote:
Nick Coghlan <[EMAIL PROTECTED]> wrote:
...
Michael Spencer also posted ...
Wasted indirection, IMHO. A better implementation:
class attr_view(object):
def __init__(self, data):
self.__dict__ = data
Alex
Indeed! A complete brain-blip
Michael
-
Steven Bethard wrote:
Nick Coghlan wrote:
class attr_view(object):
def __init__(self, data):
self.__dict__ = data
I think the idea definitely deserves mention as a possible
implementation strategy in the generic objects PEP, with the data
argument made optional:
That's basically wh
Bengt Richter wrote:
...
>
> class Foo(object):
> class __metaclass__(type):
> def __setattr__(cls, name, value):
> if type(cls.__dict__.get(name)).__name__ == 'Descriptor':
> raise AttributeError, 'setting Foo.%s to %r is not allowed'
> %(name, value)
>
Daniel Britt wrote:
> Hello All,
> I am new to Python so if there is an obvious answer to my question please
> forgive me. Lets say I have the following code in mod1.py
>
> class test:
> def func1(self):
> print 'hello'
>
>
> Now lets say I have another file called main.py:
>
> import mod1
>
Neal Becker wrote:
> Like a puzzle? I need to interface python output to some strange old
> program. It wants to see numbers formatted as:
>
> e.g.: 0.23456789E01
>
> That is, the leading digit is always 0, instead of the first significant
> digit. It is fixed width. I can almost get it with
Michael Spencer wrote:
> Neal Becker wrote:
>
>>Like a puzzle? I need to interface python output to some strange old
>>program. It wants to see numbers formatted as:
>>
>>e.g.: 0.23456789E01
>>
>>That is, the leading digit is always 0, instead of t
John J. Lee wrote:
"Adomas" <[EMAIL PROTECTED]> writes:
Well, a bit more secure would be
eval(expression, {'__builtins__': {}}, {})
or alike.
Don't believe this without (or even with ;-) very careful thought,
anyone. Google for rexec.
John
This module provides a more systematic way to set up res
Alex Martelli wrote:
Steven Bethard <[EMAIL PROTECTED]> wrote:
Hmm... interesting. This isn't the main intended use of
Bunch/Struct/whatever, but it does seem like a useful thing to have...
I wonder if it would be worth having, say, a staticmethod of Bunch that
produced such a view, e.g.:
class
Nick Coghlan wrote:
Steven Bethard wrote:
It was because these seem like two separate cases that I wanted two
different functions for them (__init__ and, say, dictview)...
I see this, but I think it weakens the case for a single implementation, given
that each implementation is essentially one me
Steven Bethard wrote:
Do you mean there should be a separate Namespace and Bunch class? Or do
you mean that an implementation with only a single method is less useful?
The former.
If the former, then you either have to repeat the methods __repr__,
__eq__ and update for both Namespace and Bunch,
Jeremy Bowers wrote:
I can't figure out how to write a TM in a Python List Comprehension
without one of either "variable binding" (so we can store the last symbol
list and manipulate it in the next iteration) or "recursive function" (to
express the whole tape as a recursive function), both of whic
Jeremy Bowers wrote:
On Tue, 08 Feb 2005 17:36:19 +0100, Bernhard Herzog wrote:
Now you *can* get at the previous state and write a state-transition
expression in perfectly legal Python.
What do you know, generator comprehensions are Turing Complete and list
comprehensions aren't. I wouldn't have
Jeremy Bowers wrote:
That's not a generator expression, that's a generator function. Nobody
contests they can reference earlier states, that's most of their point :-)
Are you sure?
I just wrote my examples in functions to label them
Here's your example with this method:
>>> import itertools as it
Jeremy Bowers wrote:
OK then, I still don't quite see how you can build a Turing Machine in one
LC, but an LC and one preceding list assignment should be possible,
although the resulting list from the LC is garbage;
Not necessarily garbage - could be anything, say a copy of the results:
>>> resul
Jeremy Bowers <[EMAIL PROTECTED]> writes:
On Tue, 08 Feb 2005 17:36:19 +0100, Bernhard Herzog wrote:
Nick Vargish <[EMAIL PROTECTED]> writes:
"Xah Lee" <[EMAIL PROTECTED]> writes:
is it possible to write python code without any indentation?
Not if Turing-completeness is something you desire.
Ber
Carl Banks wrote:
Pay attention, chief. I suggested this days ago to remove duplicates
from a list.
from itertools import *
[ x for (x,s) in izip(iterable,repeat(set()))
if (x not in s,s.add(x))[0] ]
;)
Sorry, I gave up on that thread after the first 10 Million* posts. Who knows
what other pe
Bernhard Herzog wrote:
Michael Spencer <[EMAIL PROTECTED]> writes:
So, here's factorial in one line:
# state refers to list of state history - it is initialized to [1]
# on any iteration, the previous state is in state[-1]
# the expression also uses the trick of list.append() =>
Cyril BAZIN wrote:
Hello,
I want to build a function which return values which appear two or
more times in a list:
This is very similar to removing duplicate items from a list which was the
subject of a long recent thread, full of suggested approaches.
Here's one way to do what you want:
>>> l
Frans Englich wrote:
Hello,
Have a look at this recursive function:
def walkDirectory( directory, element ):
element = element.newChild( None, "directory", None ) # automatically
appends to parent
element.setProp( "name", os.path.basename(directory))
for root, dirs, files in os.walk(
Steven Bethard wrote:
Peter Hansen wrote:
Of course, most of the other definitions of "is a number" that
have been posted may likewise fail (defined as not doing what the
OP would have wanted, in this case) with a numarray arange.
Or maybe not. (Pretty much all of them will call an arange a
number
Steven Bethard wrote:
Michael Spencer wrote:
Steven Bethard wrote:
Peter Hansen wrote:
Of course, most of the other definitions of "is a number" that
have been posted may likewise fail (defined as not doing what the
OP would have wanted, in this case) with a numarray arange.
How about
Tim Peters wrote:
[Frans Englich]
...
[snip]
class HasPath:
def __init__(self, path):
self.path = path
def __lt__(self, other):
return self.path < other.path
class Directory(HasPath):
def __init__(self, path):
HasPath.__init__(self, path)
self.files = []
Francis Girard wrote:
"""
Example 8
Running after your tail with itertools.tee
The beauty of it is that recursive running after their tai
Roose wrote:
Yeah, as we can see there are a million ways to do it. But none of them are
as desirable as just having a library function to do the same thing. I'd
argue that since there are so many different ways, we should just collapse
them into one: any() and all(). That is more in keeping wit
"Francis Girard" <[EMAIL PROTECTED]> wrote in message
an "iterator" doesn't have to support the "__iter__" method
Terry Reedy wrote:
Yes it does. iter(iterator) is iterator is part of the iterater protocol
for the very reason you noticed...
But, notwithstanding the docs, it is not essential t
Roose wrote:
Previous discussion on this topic:
http://groups-beta.google.com/group/comp.lang.python/msg/a76b4c2caf6c435c
Michael
OK, well then. That's really the exact same thing, down to the names of the
functions. So what ever happened to that?
I don't recall: probably
http://www.google.c
naturalborncyborg wrote:
Hi, I'm using nested lists as arrays and having some problems with
that approach. In my puzzle class there is a swapelement method which
doesn't work out.
What "doesn't work out"? On casual inspection that method seems to "work":
>>> p = Puzzle(2)
>>> p.elements[0][0] =
Terry Reedy wrote:
<[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
def setRandomState(self):
# container for the elements to pick from
container = [1,2,3,4,5,6,7,8,-1]
# create elements of puzzle randomly
i = 0
j = 0
while i <= self.dim-1:
whil
Michael Spencer wrote:
But, notwithstanding the docs, it is not essential that
iter(iterator) is iterator
Terry Reedy wrote:
> iter(iterator) is iterator is part of the iterater protocol
>
[...]I interpret [your post] as saying three things:
1. "There is more than one possible de
Peter Hansen wrote:
Felix Wiemann wrote:
Sometimes (but not always) the __new__ method of one of my classes
returns an *existing* instance of the class. However, when it does
that, the __init__ method of the existing instance is called
nonetheless, so that the instance is initialized a second time
peter wrote:
Hello, nice solution:
but it puzzles me :)
can anyone tell me why
---correct solution
def fA(input):
return input
def newFA(input, f= fA):
return f(input)
fA = newFA
is correct and:
-infinite loop-
def fA(input):
return input
d
Steven Bethard wrote:
So, I have a list of lists, where the items in each sublist are of
basically the same form. It looks something like:
...
Can anyone see a simpler way of doing this?
Steve
You just make these up to keep us amused, don't you? ;-)
If you don't need to preserve the ordering, wo
Terry Reedy wrote:
"Michael Spencer" <[EMAIL PROTECTED]> wrote in message
We are both interested in the murky edges at and beyond conventional usage.
...
I am quite aware that multiple iterators for the same iterable (actual or
conceptual) can be useful (cross products, for exa
Adam DePrince wrote:
How is a spencerator [an iterator that doesn't return itself unmodified on iter]
> different than itertools.tee?
Taking your question literally, it changes the behavior of an itertools.tee
object 'tee', so that iter(tee) returns tee.__copy__(), rather than tee itself.
It wa
peter wrote:
brain reset and understood
thx a lot for all your answers
Peter
Now that you've got reset, you might want to consider an alternative solution:
def fA(input):
return input
oldfA = fA # Hold a reference to the the old function
def newFA(input):
"Do something new"
return oldfA
Michael Spencer wrote:
>>> def resample2(data):
... bag = {}
... random.shuffle(data)
... return [[(item, label)
... for item, label in group
... if bag.setdefault(label,[]).append(item)
... or len(bag[la
Steven Bethard wrote:
Michael Spencer wrote:
Steven Bethard wrote:
So, I have a list of lists, where the items in each sublist are of
basically the same form. It looks something like:
...
Can anyone see a simpler way of doing this?
Steve
You just make these up to keep us amused, don'
Christos TZOTZIOY Georgiou wrote:
On Sat, 12 Feb 2005 16:01:26 -0800, rumours say that Michael Spencer
<[EMAIL PROTECTED]> might have written:
Yup, that's basically what I'm doing right now. The question was really
how to define that adapter function. =)
Steve
OK -
James Stroud wrote:
It seems I need constructs like this all of the time
i = 0
while i < len(somelist):
if oughta_pop_it(somelist[i]):
somelist.pop(i)
else:
i += 1
There has to be a better way...
Do you have to modify your list in place?
If not, just create a copy with the filtered ite
Grant Edwards wrote:
On 2005-02-17, Steven Bethard <[EMAIL PROTECTED]> wrote:
py> class C(object):
... def f(self, *args):
... print "f:", args
... def g(self, *args):
... print "g:", args
...
py> class D(C):
... pass
...
py> class Wrapper(object):
... def __init__(
John Lenton wrote:
On Thu, Feb 17, 2005 at 07:32:55PM +, Grant Edwards wrote:
I'd usually put big fat warnings around this code, and explain exaclty
why I need to do things this way...
As a low-tech alternative, what about sourcecode generation, since you are
targetting a python module? Thi
"Johannes Nix|Johannes.Nix"@uni-oldenburg.de wrote:
Hi,
I have a tricky problem with Numeric. Some time ago, I have generated
a huge and complex data structure, and stored it using the cPickle
module. Now I want to evaluate it quickly again on a workstation
cluster with 64-Bit Opteron CPUs - I have
[EMAIL PROTECTED] wrote:
Kent Johnson wrote:
[EMAIL PROTECTED] wrote:
p.s. the reason I'm not sticking to reversed or even reverse :
suppose
the size of the list is huge.
reversed() returns an iterator so list size shouldn't be an issue.
What problem are you actually trying to solve?
Kent
Oh, you
David Eppstein wrote:
In article <[EMAIL PROTECTED]>,
"Xah Lee" <[EMAIL PROTECTED]> wrote:
given a list aList of n elements, we want to return a list that is a
range of numbers from 1 to n, partition by the predicate function of
equivalence equalFunc.
In the worst case, this is going to have to
[EMAIL PROTECTED] wrote:
When I look at how classes are set up in other languages (e.g. C++), I
often observe the following patterns:
1) for each data member, the class will have an accessor member
function (a Get function)
2) for each data member, the class will have a mutator member function
(a S
[EMAIL PROTECTED] wrote:
If the class had two attributes--x and y--would the code look like
something lik this:
class C(object):
def __init__(self):
self.__x = 0
self.__y = 0
def getx(self):
return self.__x
def setx(self, x):
gf gf wrote:
[wants to extract ASCII from badly-formed HTML and thinks BeautifulSoup is too complex]
You haven't specified what you mean by "extracting" ASCII, but I'll assume that
you want to start by eliminating html tags and comments, which is easy enough
with a couple of regular expressions:
Mike Meyer wrote:
It also fails on tags with a ">" in a string in the tag. That's
well-formed but ill-used HTML.
True enough...however, it doesn't fail too horribly:
>>> striptags("""the text""")
"'>the text"
>>>
and I think that case could be rectified rather easily, by stripping an
Steven Bethard wrote:
Nick Coghlan wrote:
> Hmm, it might be nice if there was a UserList.ListMixin that was the
> counterpart to UserDict.DictMixin
I've thought this occasionally too. One of the tricky issues though is
that often you'd like to define __getitem__ for single items and have
List
David S. wrote:
This still fails to work for instances variables of the class. That is
if I use your property in the following:
py> ...class Flags(object):
...def __init__(self):
... a = singlechar
...
you should write that as:
class Flags(object):
a = singlechar
def
Anthony Liu wrote:
I cannot figure out how to specify a list of a
particular size.
For example, I want to construct a list of size 10,
how do I do this?
A list does not have a fixed size (as you probably know)
But you can initialize it with 10 somethings
>
>>> [None]*10
[None, None, None, None, N
Anthony Liu wrote:
Yes, that's helpful. Thanks a lot.
But what if I wanna construct an array of arrays like
we do in C++ or Java:
myArray [][]
Basically, I want to do the following in Python:
myArray[0][1] = list1
myArray[1][2] = list2
myArray[2][3] = list3
here you have to be careful to create N
Delaney, Timothy C (Timothy) wrote:
Michael Hoffman wrote:
For those who don't know, these implement a hash set/map which
iterates in the order that the keys were first added to the set/map.
I would love to see such a thing.
I've proposed this on python-dev, but the general feeling so far is
agai
Marc Christiansen wrote:
Michael Spencer <[EMAIL PROTECTED]> wrote:
Nice. When you replace None by an object(), you have no restriction on
the elements any more:
Thanks for the suggestion, Marc.
Note that if there is no need to access the middle of the collection, then the
implementat
1 - 100 of 337 matches
Mail list logo