On Thursday, 16 August 2012 19:49:43 UTC+2, Steven D'Aprano wrote:
> On Thu, 16 Aug 2012 10:03:51 -0700, Richard Thomas wrote:
>
>
>
> > class Foo(object):
>
> > def __new__(cls, arg):
>
> > if isinstance(arg, list):
>
> >
> a is a Foo
> b is a Foo
> therefore a and b are the same type
What you mean here is "a and b share a common base class".
--
http://mail.python.org/mailman/listinfo/python-list
class Foo(object):
def __new__(cls, arg):
if isinstance(arg, list):
cls = FooList
elif isinstance(arg, dict):
cls = FooDict
return object.__new__(cls, arg)
class FooList(Foo, list):
pass
class FooDict(Foo, dict):
pass
You could even hav
Assuming you have:
lib/__init__.py
lib/foo.py
lib/foo.c
Then:
from distutils.core import setup, Extension
setup(name="lib", packages=["lib"], ext_modules=[Extension("lib._foo",
["lib/foo.c"])])
--
http://mail.python.org/mailman/listinfo/python-list
On Saturday, 17 March 2012 05:30:34 UTC, Cosmia Luna wrote:
> I'm porting my existing work to Python 3.X, but...
>
> class Foo:
> def bar(self):
> pass
>
> mthd = Foo.bar
>
> assert mthd.im_class is Foo # this does not work in py3k
mthd.im_class is the class of mthd.im_self not the
On Feb 4, 6:13 pm, noydb wrote:
> How do you build a dictionary dynamically? Doesn't seem to be an
> insert object or anything. So I need an empty dictionary that I then
> want to populate with values I get from looping through a list and
> grabbing some properties. So simply, I have (fyi, arcp
> >>> def findself():
>
> """Find myself. Ooh look, there I am!"""
> import sys
> try:
> 1/0
> except:
> traceback=sys.exc_info()[2]
> # Now I'm not sure what to do with traceback.
> # traceback.tb_frame.f_code.co_name
On Jun 3, 9:35 pm, Joe wrote:
> Hello,
>
> I'm trying to implement a way to restrict method usage based on the
> caller's attributes. In the following example I'd like to execute the
> server method "bar" only if the caller's method has a "blue" value for
> it's color attribute.
>
> The current o
On May 9, 9:52 pm, Andrew Berg wrote:
> I need to find whether a given file is 32-bit or 64-bit (and raise an
> exception if the file doesn't exist or isn't an executable file). I
> thought platform.architecture() would do this, but it returns ('64bit',
> '') no matter what value I assign to the e
On May 6, 7:36 am, Jabba Laci wrote:
> Hi,
>
> If I want to check if a list is empty, which is the more pythonic way?
>
> li = []
>
> (1) if len(li) == 0:
> ...
> or
> (2) if not li:
> ...
>
> Thanks,
>
> Laszlo
I prefer (1), it feels more explicit about what I'm testing. The fact
that empty sequ
On Apr 17, 8:56 pm, Chris Rebert wrote:
> On Sun, Apr 17, 2011 at 12:30 PM, Gerald Britton
>
>
>
>
>
>
>
>
>
> wrote:
> > I apologize if this has been answered before or if it is easy to find
> > in the docs. (I couldn't find it but might have missed it)
>
> > I'm trying to understand the differe
On Feb 16, 2:23 am, s...@uce.gov wrote:
> How can I do something like this in python:
>
> #!/usr/bin/python3.1
>
> class MyNumbers:
> def __init__(self, n):
> self.original_value = n
> if n <= 100:
> self = SmallNumers(self)
> else:
> self = BigNumbers(self)
>
> clas
On Jan 13, 3:59 pm, Alain Ketterlin
wrote:
> Richard Thomas writes:
> > On Jan 13, 10:02 am, Alain Ketterlin
> >> def clusterings(l):
> >> if len(l) == 1:
> >> print repr(l)
> >> else:
> >> n = len(l)
> >>
On Jan 13, 10:02 am, Alain Ketterlin
wrote:
> justin writes:
> > Suppose I have [1,2,3,4,5], then there are many ways of making
> > clustering.
> > Among them, I want to pair up terminals until there is only one left
> > at the end.
>
> Are you trying "ascending hierarchical clustering" by any ch
On Nov 22, 11:38 am, Ulrich Eckhardt
wrote:
> Hi!
>
> I'm writing tests and I'm wondering how to achieve a few things most
> elegantly with Python's unittest module.
>
> Let's say I have two flags invert X and invert Y. Now, for testing these, I
> would write one test for each combination. What I
On Oct 31, 7:04 pm, Zeynel wrote:
> On Oct 31, 5:52 am, Dave Angel wrote:
>
>
>
>
>
>
>
>
>
> > On 2:59 PM, Zeynel wrote:> class Rep(db.Model):
> > > author = db.UserProperty()
> > > replist = db.ListProperty(str)
> > > unique = db.ListProperty(str)
> > > date = db.DateTimePro
On Oct 31, 5:42 am, Zeynel wrote:
> class Rep(db.Model):
> author = db.UserProperty()
> replist = db.ListProperty(str)
> unique = db.ListProperty(str)
> date = db.DateTimeProperty(auto_now_add=True)
>
>
>
> Rep().replist = L
> Rep().put()
> mylist = Rep().all().fetch(10)
>
> I
On Oct 8, 1:39 am, Logan Butler wrote:
> question about an assignment:
>
> >>> places("home sweet home is here",' ')
>
> [4, 10, 15, 18]
>
> this is my code:
>
> def places(x, y):
> return [x.index(y) for v in x if (v == y)]
>
> so far I'm only getting
> [4, 4, 4, 4]
>
> so the first value is
On Oct 4, 3:26 pm, sd44 wrote:
> In
> part III
> how does Python handle it if you try to extract a sequence in reverse,
> with the lower bound greater than the higher bound (e.g., L[3:1])? Hint:
> try
> assigning to this slice (L[3:1]=['?']), and see where the value is put.
>
> >>> L=[1,2,3,4]
>
On Sep 28, 11:31 pm, Hidura wrote:
> Hello, i have a project on Python3k, and i have a very big problem i
> don' t find how take an upload file i am using the wsgiref lib, and or
> theres any way to connect to the client in order to get the file by
> myself?
>
> Thank you
> Diego Hidalgo.
>
> --
>
On Sep 6, 5:55 pm, Sal Lopez wrote:
> The following code runs OK under 3.1:
>
> @filename=cats_and_dogs.py
>
> #!/usr/bin/python
>
> def make_sound(animal):
> print(animal + ' says ' + sounds[animal])
>
> sounds = { "cat": "meow", "dog": "woof" }
>
> for i in sounds.keys():
> make_sound(i)
On Jul 17, 12:34 am, candide wrote:
> I don't understand why some parts of the Python language (or the Python
> standard library too) are implemented in C while some other parts are
> implemented in the Python language itself. For instance, lists and
> dictionnaries are implemented in C but sets a
On Jul 7, 3:11 am, "Alf P. Steinbach /Usenet" wrote:
> Donald Knuth once remarked (I think it was him) that what matters for a
> program
> is the name, and that he'd come up with a really good name, now all he'd had
> to
> do was figure out what it should be all about.
>
> And so considering Stu
On Jun 25, 2:15 pm, WANG Cong wrote:
> Hi, list!
>
> I have a doubt about the design of dynamic attribute creation by
> assignments in Python.
>
> As we know, in Python, we are able to create a new attribute of
> a class dynamically by an assignment:
>
>
>
> >>> class test: pass
> ...
> >>> test.a
On Jun 8, 9:03 am, ch1zra wrote:
> I have following code :
>
> import os, time, re, pyodbc, Image, sys
> from datetime import datetime, date, time
> from reportlab.lib.pagesizes import A4
> from reportlab.lib.units import cm
> from reportlab.pdfgen import canvas
> from reportlab.pdfbase import pdf
On Jun 7, 10:17 am, Peter Otten <__pete...@web.de> wrote:
> Alfred Bovin wrote:
> > I'm working on something where I need to read a (binary) file bit by bit
> > and do something depending on whether the bit is 0 or 1.
>
> > Any help on doing the actual file reading is appreciated.
>
> The logical u
Python's map has the useful feature that nobody is in any doubt about
what it does. I don't know much about Ruby I have to say but looking
at that piece of syntax you gave I had no idea how to interpret it.
Anyway, I looked it up.
Calling an method on each of a collection of objects is best
accomp
For this kind of problem you should avoid all that stringification. I
find it best to deal with sequences of digits of a fixed length and go
from there. For example:
def count1(m, n, cache={}):
"""Number of digit sequences of length `n` summing to `m`."""
if n < 0 or m < 0:
return
On Apr 8, 5:46 pm, Tobiah wrote:
> I'm having a difficult time with this. I want
> to display a continuous range of hues using HTML
> hex representation (#RRGGBB). How would I go
> about scanning through the hues in order to
> make a rainbow?
>
> Thanks,
>
> Toby
Look at the colorsys module.
h
On Apr 5, 4:40 pm, Roald de Vries wrote:
> Dear all,
>
> PEP 245 and 246 about interfaces for python are both rejected for
> 'something much better' (GvR in 246's rejection notice). Does anybody
> know what this is? I am *very* curious!
>
> Kind regards, Roald
Given that was in 2001, probably
On Feb 25, 2:03 pm, fat bold cyclop wrote:
> > Both are not equal, so the comparison returns an arbitrary result in Py2.
>
> Thanks, Stefan. If I understand you correctly the comparison is not
> valid.
> But I wonder if there is any logic behind this (in 2.x).
> Is it possible to predict result of
On Jan 31, 6:15 pm, tinn...@isbd.co.uk wrote:
> I'm trying to read some data from standard input, what I'm actually
> trying to do is process some date pasted in using the mouse cut and
> paste on a Linux box (xubuntu 9.10) in a terminal window.
>
> First attempts failed so I'm now trying the trivi
On Jan 20, 4:43 pm, NighterNet wrote:
> Need help on python version 3.1.x. I can't seem to know what going on
> a bit. The code that I check that the hash is different every time. Is
> there a way to make the hash the same? I using as to check the class
> is the same variables but if it different
On Dec 18, 3:42 pm, seafoid wrote:
> Hi Guys,
>
> When python reads in a file, can lines be referred to via an index?
>
> Example:
>
> for line in file:
> if line[0] == '0':
> a.write(line)
>
> This works, however, I am unsure if line[0] refers only to the first line or
> the first c
On Dec 11, 9:26 am, Jan Mach wrote:
> Hi everybody,
> I am currently solving the following problem and I am stuck. I am trying
> to create instance of the class of variable name. I know, that the
> following works:
>
> if (something):
> classToUse = C1
> else:
> classToUse = C2
>
> o = cla
On Dec 9, 10:17 am, Gabriel Rossetti
wrote:
> Hello everyone,
>
> I get this error on python 2.6.1 on mac os x 10.6 :
>
> UnboundLocalError: local variable '_[1]' referenced before assignment
>
> here's the code that raises this:
>
> params = [ self.__formatData(paramProcFunc, query, p) for p in p
On Dec 8, 1:22 am, r0g wrote:
> Torsten Mohr wrote:
> > Hi,
>
> > i'd like to test if an input string starts with a python expression
> > and also where that expression ends. An example:
>
> > a_func(3*7, '''abc''') +5 pls some more
>
> > The first part until (inclusive) the 5 should be found as
On Nov 24, 2:45 am, geremy condra wrote:
> On Mon, Nov 23, 2009 at 9:10 PM, geremy condra wrote:
> > On Mon, Nov 23, 2009 at 9:03 PM, geremy condra wrote:
> >> On Mon, Nov 23, 2009 at 7:05 PM, Paul Miller
> >> wrote:
> >>> I was wondering if there were any neat tools (like for instance,
> >>> s
On 22 Nov, 00:07, MRAB wrote:
> Steve Howell wrote:
> > I have been writing some code that parses a mini-language, and I am
> > running into what I know is a pretty common design pattern problem,
> > but I am wondering the most Pythonic way to solve it.
>
> > Basically, I have a bunch of really si
On Aug 15, 4:28 am, Mag Gam wrote:
> I am writing an application which has many command line arguments.
> For example: foo.py -args "bar bee"
>
> I would like to create a test suit using unittest so when I add
> features to "foo.py" I don't want to break other things. I just heard
> about unittest
Say I have a project like this:
./run.py
./package/__init__.py
./package/mod1.py
./package/subpackage/__init__.py
./package/subpackage/mod2.py
./package/subpackage/mod3.py
And suppose that "." and "package" (or their absolute paths) are in
sys.path.
Now mod1.py and mod2.p
On 27/09/2007, Casey <[EMAIL PROTECTED]> wrote:
> On Sep 27, 12:48 pm, "Simon Brunning" <[EMAIL PROTECTED]>
> wrote:
> > On 9/27/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> > > I tried writing a true and false If statement and didn't get
> > > anything? I read some previous posts, but I
42 matches
Mail list logo