Re: Need help with Python scoping rules

2009-08-26 Thread Ulrich Eckhardt
Jean-Michel Pichavant wrote: > class Color: > def __init__(self, r, g,b): > pass > BLACK = Color(0,0,0) > > It make sens from a design point of view to put BLACK in the Color > namespace. But I don't think it's possible with python. class Color: ... setattrib(Color, "BLACK"

Re: Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-26 Thread Diez B. Roggisch
Evan Driscoll schrieb: On Aug 25, 3:47 pm, Evan Driscoll wrote: So here is my simplified version that only works for globals: So I think this works if (1) you only use changed_value in the same module as it's defined in (otherwise it picks up the globals from the module it's defined in, which

Re: PyObject_CallFunction and writable memory

2009-08-26 Thread Diez B. Roggisch
Christopher Nebergall schrieb: I'm working a patch to a hex editor (frhed) written in c++ so it can load python scripts. Internally the c++ code has a unsigned char * of possibly serveral hundred megs which I want to send into the python code to modify.What is the best way to send the unsigne

Re: PyObject_CallFunction and writable memory

2009-08-26 Thread Benjamin Peterson
Christopher Nebergall gmail.com> writes: > > I'm currently using > "PyObject_CallFunction(pFunc, "(s#)",p->lpbMemory, p->dwSize);" to > send an immutable string but I haven't seen what I need to set in the > format string which makes the data writable to python.The solution > can be for eith

Re: Python, qt, and lgpl

2009-08-26 Thread Diez B. Roggisch
sturlamolden schrieb: On 25 Aug, 21:45, Terry Reedy wrote: Will be good news if realized. Good news for everyone except Riverbank. And only if LGPL is something you can live with. Some projects require more liberal licenses. Or is there a commercial license available, too? Diez --

Re: conditional for-statement

2009-08-26 Thread seb
On Aug 25, 11:57 pm, Piet van Oostrum wrote: > You can also say: > [x+y for x in range(3) for y in range(4) if x < y] > If you want to write this as a loop you have to put the for's on > separate lines separated by colons, so why not the if also? Or would you > also like to have the for's on one l

Re: break unichr instead of fix ord?

2009-08-26 Thread Vlastimil Brom
2009/8/25 : > In Python 2.5 on Windows I could do [*1]: > >  # Create a unicode character outside of the BMP. >  >>> a = u'\U00010040' > >  # On Windows it is represented as a surogate pair. >  >>> len(a) >  2 >  >>> a[0],a[1] >  (u'\ud800', u'\udc40') > >  # Create the same character with the uni

Re: Python for professsional Windows GUI apps?

2009-08-26 Thread Simon Brunning
2009/8/26 geekworking : > If you are planning a database driven app, you should first settle on > a DB server. Any real enterprise DB system will put all of the > business logic in the database server. The choice of a front end > should be secondary. The trend for some years now has been to get be

Getting the current PyCFunction while in a python function

2009-08-26 Thread Prémon Nom
Hi I would like to get the PyCFunction object which corresponds to the current function which is executed. I call PyFrameObject* frame = PyEval_GetFrame() I try to parse frame->f_valuestack, but I don't know how to get the index of the function in the stack or event the size of the stack to be

Re: Python on the Web

2009-08-26 Thread Bruno Desthuilliers
Phil a écrit : I've seen lots of web sites explaining everything, but for whatever reason I seem to not be picking something up. I am a graphical person, which is probably the reason I haven't found my answer. May somebody please confirm if my diagram accurately represents the stack, generally sp

Move dictionary from instance to class level

2009-08-26 Thread Frank Millman
Hi all I have a class that uses a dictionary to map message numbers to methods. Here is a simple example - class MyClass(object): def __init__(self): self.method_dict = {} self.method_dict[0] = self.method_0 self.method_dict[1] = self.method_1

Re: Python for professsional Windows GUI apps?

2009-08-26 Thread erikj
Hi, You could have a look at Camelot, to see if it fits your needs : http://www.conceptive.be/projects/camelot/ it was developed with cross platform business apps in mind. when developing Camelot, we tried to build it using wxWidgets first (because of the licensing at that time), but it turned o

Re: print() and unicode strings (python 3.1)

2009-08-26 Thread Piet van Oostrum
> 7stud (7) wrote: >7> Thanks for the response. My OS is mac osx 10.4.11. I'm not really >7> sure how to check my locale settings. Here is some stuff I tried: >7> $ echo $LANG >7> $ echo $LC_ALL >7> $ echo $LC_CTYPE >7> $ locale >7> LANG= >7> LC_COLLATE="C" >7> LC_CTYPE="C" >7> LC_MESS

Re: Move dictionary from instance to class level

2009-08-26 Thread Chris Rebert
On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman wrote: > Hi all > > I have a class that uses a dictionary to map message numbers to methods. > > Here is a simple example - > >    class MyClass(object): >        def __init__(self): >            self.method_dict = {} >            self.method_dict[0] =

Q: multiprocessing.Queue size limitations or bug...

2009-08-26 Thread Michael Riedel
Sorry for being not more specific but I'm not absolutely certain whether I encountered a bug or did anything wrong: The (stupid) code below results in a stall forever or not at 'p0.join()' depending on the value of TROUBLE_MAKER. Any help, thoughts, comments? Thank you for your time. Michael #

Re: Move dictionary from instance to class level

2009-08-26 Thread Frank Millman
On Aug 26, 10:54 am, Chris Rebert wrote: > On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman wrote: > > A > > class MyClass(object): > def on_message_received(self, msg): > self.method_dict[msg](self) > > def method_0(self): > print 'in method_0' > > def method_1(self): >

Re: Move dictionary from instance to class level

2009-08-26 Thread Frank Millman
On Aug 26, 10:54 am, Chris Rebert wrote: > On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman wrote: > > A > > class MyClass(object): > def on_message_received(self, msg): > self.method_dict[msg](self) > > def method_0(self): > print 'in method_0' > > def method_1(self): >

Re: Move dictionary from instance to class level

2009-08-26 Thread Frank Millman
On Aug 26, 10:54 am, Chris Rebert wrote: > On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman wrote: > > A > > class MyClass(object): > def on_message_received(self, msg): > self.method_dict[msg](self) > > def method_0(self): > print 'in method_0' > > def method_1(self): >

Re: Help with arrays

2009-08-26 Thread Stephen Fairchild
Dave Angel wrote: > With this change the best solution changes from a random shuffle to a > binary search. Which is not what the OP asked for. Anyway, I think whatever solution is chosen it's probably best written as a generator. The new pushback syntax may prove useful. -- Stephen Fairchild --

all possible matchings of elements of two lists

2009-08-26 Thread Sandy
Hi all, I basically want all possible matchings of elements from two lists, Ex: [1,2] [a,b,c] Required: [ [(1,a),(2,b)] [(1,b),(2,c)] [(1,c),(2,b)] [(1,b),(2,a)] [(1,c),(2,a)] [(1,a),(2,c)] ] My thought is to get all possible permutations of two lists given and sele

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In John Posner writes: >Stephen Hansen said: >> This sounds like a fundamental confusion -- a namespace is not >> equivalent to a scope, really, I think. >> ... Hmm. I can't find Stephen Hansen's original post anywhere. Where did you come across it? Is there an *official* write-up where th

Re: Python, qt, and lgpl

2009-08-26 Thread Carl Banks
On Aug 25, 5:04 pm, sturlamolden wrote: > On 25 Aug, 21:45, Terry Reedy wrote: > > > Will be good news if realized. > > Good news for everyone except Riverbank. Oh well, Riverbank could have played ball but they didn't, so I guess I don't care if it's bad news for them. Carl Banks -- http://m

Re: Python Processor

2009-08-26 Thread manish
Hi, I am also wondering about how to implement a soft core reconfigurable processor in a FPGA which would directly execute the compiled python bytecode. I am trying to understand the bytecode format but apart from http://docs.python.org/library/dis.html there is hardly any documentation on the py

ubuntu dist-packages

2009-08-26 Thread Robin Becker
I was surprised a couple of days ago when trying to assist a colleage with his python setup on a ubuntu 9.04 system. We built our c-extensions and manually copied them into place, but site-packages wasn't there. It seems that ubuntu now wants stuff to go into lib/python2.6/dist-packages. Wha

Re: all possible matchings of elements of two lists

2009-08-26 Thread dksr
Ok this is how I do it: l1 = [1,2] l2= ['a','b','c'] res = [] l2 = permute(l2) for i in l2: lis = [l1,l2] res.append(zip(*lis)) # or use map depending on what u want res.append(map(None,*lis)) print res On Aug 26, 11:05 am, Sandy wrote: > Hi all, > I basically want all possible m

TypeError: _getfullpathname() argument 1 must be (buffer overflow), not str in windows xp, while making tarfile

2009-08-26 Thread Ryniek90
[snip] Here's my script code: *http://paste.ubuntu.com/259310/ *Shouldn't that bug be patched already :-? Are you giving it the contents of the file when it's actually expecting the filename? Of course the content of the file: [snip] See? *backup_obj.add(read_obj.read())* In previous pa

Re: ubuntu dist-packages

2009-08-26 Thread Diez B. Roggisch
Robin Becker wrote: > I was surprised a couple of days ago when trying to assist a colleage with > his python setup on a ubuntu 9.04 system. > > We built our c-extensions and manually copied them into place, but > site-packages wasn't there. It seems that ubuntu now wants stuff to go > into lib/p

Re: all possible matchings of elements of two lists

2009-08-26 Thread Mark Dickinson
On Aug 26, 11:05 am, Sandy wrote: > Hi all, > I basically want all possible matchings of elements from two lists, > Ex: [1,2] [a,b,c] > > Required: >    [ [(1,a),(2,b)] >      [(1,b),(2,c)] >      [(1,c),(2,b)] >      [(1,b),(2,a)] >      [(1,c),(2,a)] >      [(1,a),(2,c)] >    ] If you're using

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In <7figv3f2m3p0...@mid.uni-berlin.de> "Diez B. Roggisch" writes: >Classes are not scopes. This looks to me like a major wart, on two counts. First, one of the goals of OO is encapsulation, not only at the level of instances, but also at the level of classes. Your comment suggests that Python

Re: multiprocessing managers and socket connection.

2009-08-26 Thread Chris
On Aug 25, 9:11 pm, Terry wrote: > On Aug 25, 10:14 pm, Chris wrote: > > > > > I've been using multiprocessing managers and I really like the > > functionality. > > > I have a question about reconnecting to a manager. I have a situation > > where I start on one machine (A) a manager that is liste

Re: Need help with Python scoping rules

2009-08-26 Thread Ulrich Eckhardt
Ulrich Eckhardt wrote: > Jean-Michel Pichavant wrote: >> class Color: >> def __init__(self, r, g,b): >> pass >> BLACK = Color(0,0,0) >> >> It make sens from a design point of view to put BLACK in the Color >> namespace. But I don't think it's possible with python. > > class Colo

Usefull python tutorial

2009-08-26 Thread gentlestone
Can somebody give me an advise where I can found a really good online tutorial? All I found are useless. For example no tutorial I found explains this piece of code: someList = [element for element in otherList if element is not None] or this example: a = a or [] There are only stupid e

Re: Need help with Python scoping rules

2009-08-26 Thread Carl Banks
On Aug 26, 3:57 am, kj wrote: > In <7figv3f2m3p0...@mid.uni-berlin.de> "Diez B. Roggisch" > writes: > > >Classes are not scopes. > > This looks to me like a major wart, on two counts. Class statements *are* scopes, they are just not accessible from scopes nested within them. > First, one of t

Re: Usefull python tutorial

2009-08-26 Thread Chris Rebert
On Wed, Aug 26, 2009 at 4:44 AM, gentlestone wrote: > Can somebody give me an advise where I can found a really good online > tutorial? All I found are useless. For example no tutorial I found > explains this piece of code: > >    someList = [element for element in otherList if element is not > Non

Re: Division and right shift in python

2009-08-26 Thread Cevahir Demirkıran
The previous one was slower but now it is faster. How can I make this more consistent? Why cannot I control it? Where can I find the algorithms implemented under for example pow, /, %, etc.? I could not see them in python documentation? f2(28136791827937127971286375648628461979219783642686202802

Re: Usefull python tutorial

2009-08-26 Thread Simon Brunning
2009/8/26 gentlestone : > Can somebody give me an advise where I can found a really good online > tutorial? All I found are useless. is really good, as I remember, as is . For example no tutorial I found > explains this piece of code

Re: Division and right shift in python

2009-08-26 Thread Dave Angel
Mark Tolonen wrote: "Cevahir Demirkiran" wrote in message news:3f74e020908251648k7b391a09g78b155507b2f2...@mail.gmail.com... Hi, I would like to do a floor division by a power of 2 in python to make it faster than / (modular division in 2.x). However, it is slower. What is the reason of that

Re: Division and right shift in python

2009-08-26 Thread Cevahir Demirkıran
Thanks for the answer. Run it with a big number: f2(9230821908403878236537264867326482638462035732098490238409328947638257462745672354627356427356742563256745362772537532756732673275732,9) I had this result: 8.1015883211e-06 1.06158743591e-05 512 2009/8/26 Mark Tolonen > > > "Cevahir Demirkira

Re: Need help with Python scoping rules

2009-08-26 Thread Dave Angel
Ulrich Eckhardt wrote: Jean-Michel Pichavant wrote: class Color: def __init__(self, r, g,b): pass BLACK = Color(0,0,0) It make sens from a design point of view to put BLACK in the Color namespace. But I don't think it's possible with python. class Color: ... set

pygtk - What is the best way to change the mouse pointer

2009-08-26 Thread Ido Levy
Hello All, I am writing a dialog which one of its widget is a gtk.ComboBoxEntry ( let's assume widget in the example below is its instance ) When the user select one of the values from the gtk.ComboBoxEntry I need to run some calculations that takes a few seconds. In order to reflect calculation

Re: Move dictionary from instance to class level

2009-08-26 Thread MRAB
Frank Millman wrote: On Aug 26, 10:54 am, Chris Rebert wrote: On Wed, Aug 26, 2009 at 1:22 AM, Frank Millman wrote: A class MyClass(object): def on_message_received(self, msg): self.method_dict[msg](self) def method_0(self): print 'in method_0' def method_1(self)

Re: ubuntu dist-packages

2009-08-26 Thread Ben Finney
Robin Becker writes: > What is the relation between dist-packages/site-packages if any? Is > this just a name change or is there some other problem being > addressed? The problem being addressed is to maintain the distinction between OS-vendor-managed files versus sysadmin-managed files. That is

Object's nesting scope

2009-08-26 Thread zaur
Hi folk! What do you think about idea of "object's nesting scope" in python? Let's imaging this feature, for example, in this syntax: obj=: or : That's means that result object of evaluation is used as nested scope for evaluation. So is this idea useful? Zaur -- http://mail.pyt

Re: Need help with Python scoping rules

2009-08-26 Thread Martin P. Hellwig
kj wrote: First, one of the goals of OO is encapsulation, not only at the level of instances, but also at the level of classes. Who says? Anyway, you could be right (I am not capable to judge it) and Python should change on this issue but from what I gathered, Pythons OO is inspired by the fo

Re: Code formatting question: conditional expression

2009-08-26 Thread Jorgen Grahn
On Wed, 26 Aug 2009 16:47:33 +1000, Ben Finney wrote: > "Nicola Larosa (tekNico)" writes: > >> Nicola Larosa wrote: >> > Here's my take: >> > >> >     excessblk = Block(total - P.BASE, srccol, >> > carry_button_suppress=True >> >         ) if total > P.BASE else None >> >> Oops, it got shortened

Re: Object's nesting scope

2009-08-26 Thread Diez B. Roggisch
zaur wrote: > Hi folk! > > What do you think about idea of "object's nesting scope" in python? > > Let's imaging this feature, for example, in this syntax: > > obj=: > > > or > > : > > > That's means that result object of evaluation is used as > nested scope for evaluation. > >

Re: Need help with Python scoping rules

2009-08-26 Thread 7stud
On Aug 25, 7:26 pm, Dave Angel wrote: > Stephen Fairchild wrote: > > You are trying to run code in a class that does not exist yet. > > > def Demo(): > >     def fact(n): > >         if n < 2: > >             return 1 > >         else: > >             return n * fact(n - 1) > >     return type("De

"JOBS IN ALASKA IT" "JOBS IN ALASKA" "JOBS IN ALASKA IT" "JOBS IN ALASKA" "jobs in alaska anchorage" "jobs in alaska oil" "jobs in alaska usa" "jobs in alaska mines" ON http://jobs-in-alaska.blogspot

2009-08-26 Thread Jawad Alam
"JOBS IN ALASKA IT" "JOBS IN ALASKA" "JOBS IN ALASKA IT" "JOBS IN ALASKA" "jobs in alaska anchorage" "jobs in alaska oil" "jobs in alaska usa" "jobs in alaska mines" ON http://jobs-in-alaska.blogspot.com/ "JOBS IN ALASKA IT" "JOBS IN ALASKA" "JOBS IN ALASKA IT" "JOBS IN ALASKA" "jobs in alaska anch

Re: print() and unicode strings (python 3.1)

2009-08-26 Thread 7stud
On Aug 25, 6:34 am, Nobody wrote: > The underlying OS primitive can only handle bytes. If you read or write a > (unicode) string, Python needs to know which encoding is used. For Python > file objects created by the user (via open() etc), you can specify the > encoding; for those created by the ru

Re: Help with arrays

2009-08-26 Thread Mart.
On Aug 26, 3:02 am, Dave Angel wrote: > Stephen Fairchild wrote: > > Philip Semanchuk wrote: > > >> On Aug 25, 2009, at 6:14 PM, Gleb Belov wrote: > > >>> Hello! I'm working on an exercise wherein I have to write a Guess The > >>> Number game, but it's the computer who's guessing MY number. I can

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In "Martin P. Hellwig" writes: >kj wrote: > >> First, one of the goals of OO is encapsulation, not only at the >> level of instances, but also at the level of classes. >Who says? Python itself: it already offers a limited form of class encapsulation (e.g. class variables). It would be nice if

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In <16b72319-8023-471c-ba40-8025aa6d4...@a26g2000yqn.googlegroups.com> Carl Banks writes: >> First, one of the goals of OO is encapsulation, not only at the >> level of instances, but also at the level of classes. =A0Your comment >> suggests that Python does not fully support class-level encaps

Zlib: correct checksum but error decompressing

2009-08-26 Thread Andre
I have been trying to solve this issue for a while now. I receive data from a TCP connection which is compressed. I know the correct checksum for the data and both the client and server generate the same checksum. However, in Python when it comes to decompressing the data I get the exception: "Erro

Re: os.popen output different from native shell output

2009-08-26 Thread Nobody
On Tue, 25 Aug 2009 11:42:31 -0700, nickname wrote: > The reason why I want to do this is because I am going to do a little > project. I will write a python script called ls which will log the > time and username and then will show the actual ls output. I want this > to be transparent and so want

Re: Need help with Python scoping rules

2009-08-26 Thread Dave Angel
7stud wrote: On Aug 25, 7:26 pm, Dave Angel wrote: Stephen Fairchild wrote: You are trying to run code in a class that does not exist yet. def Demo(): def fact(n): if n < 2: return 1 else: return n * fact(n - 1) return type("Demo"

Re: Need help with Python scoping rules

2009-08-26 Thread Mel
kj wrote: > Is there any good reason (from the point of view of Python's overall > design) for not fixing this? Python is not a compiled language, in the sense that a compiler can go back and forth over the program, filling in the details that make the program runnable. Python is an interprete

Re: Move dictionary from instance to class level

2009-08-26 Thread Frank Millman
"MRAB" wrote in message news:mailman.444.1251290454.2854.python-l...@python.org... > An alternative is: > > >>> class MyClass(object): > ... def on_message_received(self, msg): > ... try: > ... getattr(self, "method_%d" % msg)() > ... except AttributeError: > ...

Re: Need help with Python scoping rules

2009-08-26 Thread Carl Banks
On Aug 26, 7:09 am, kj wrote: > In <16b72319-8023-471c-ba40-8025aa6d4...@a26g2000yqn.googlegroups.com> Carl > Banks writes: > > >> First, one of the goals of OO is encapsulation, not only at the > >> level of instances, but also at the level of classes. =A0Your comment > >> suggests that Python

Re: Need help with Python scoping rules

2009-08-26 Thread Dave Angel
kj wrote: In <7figv3f2m3p0...@mid.uni-berlin.de> "Diez B. Roggisch" writes: Classes are not scopes. This looks to me like a major wart, on two counts. First, one of the goals of OO is encapsulation, not only at the level of instances, but also at the level of classes. Your comment

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In Dave Angel writes: >Thanks for diluting my point. The OP is chasing the wrong problem. Who >cares whether a class initializer can call a method, if the method >doesn't meet its original requirements, to be callable outside the class? >And the arguments about how recursion is restricted

Re: Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-26 Thread Carl Banks
On Aug 25, 1:07 pm, Evan Driscoll wrote: > On Aug 25, 2:33 pm, Evan Driscoll wrote: > > > I want to make a context manager that will temporarily change the > > value of a variable within the scope of a 'with' that uses it. This is > > inspired by a C++ RAII object I've used in a few projects. Ide

Raw data extraction question

2009-08-26 Thread Maggie
i have event timing stretch of code i need to alter. here is code below: -- # we start each run with one full silent trial # creating a "stub" with the duration of a full block # less the discarded acquisitions stub = block_dur - (distax * tr) feed = sys.stdin.readlines() sess = -1 for

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In <1bf83a7e-f9eb-46ff-84fe-cf42d9608...@j21g2000yqe.googlegroups.com> Carl Banks writes: >On Aug 26, 7:09=A0am, kj wrote: >> In <16b72319-8023-471c-ba40-8025aa6d4...@a26g2000yqn.googlegroups.com> Ca= >rl Banks writes: >> >> >> First, one of the goals of OO is encapsulation, not only at the >>

Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-26 Thread Steven D'Aprano
On Tue, 25 Aug 2009 11:45:28 -0700, Mensanator wrote: > On Aug 25, 9:14 am, Steven D'Aprano cybersource.com.au> wrote: >> On Mon, 24 Aug 2009 18:01:38 -0700, Mensanator wrote: >> >> If you want your data file to have values entered in hex, or oct, or >> >> even unary (1=one, 11=two, 111=three, 11

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In Dave Angel writes: >Stephen Fairchild wrote: >> You are trying to run code in a class that does not exist yet. >> >> def Demo(): >> def fact(n): >> if n < 2: >> return 1 >> else: >> return n * fact(n - 1) >> return type("Demo", (object,), {"fa

Re: Need help with Python scoping rules

2009-08-26 Thread Carl Banks
On Aug 26, 8:13 am, Dave Angel wrote: > You can probably work around this by replacing the staticmethod > decorator with an equivalent function call:. > > class Demo9(object): >     def fact(n): >         if n < 2: >             return 1 >         else: >             return n * Demo.fact(n - 1) >

Re: Zlib: correct checksum but error decompressing

2009-08-26 Thread InvisibleRoads Patrol
On Wed, 26 Aug 2009 07:19:42 -0700 (PDT), Andre wrote: > I have been trying to solve this issue for a while now. I receive data > from a TCP connection which is compressed. I know the correct checksum > for the data and both the client and server generate the same > checksum. However, in Python wh

Re: Need help with Python scoping rules

2009-08-26 Thread Steven D'Aprano
On Wed, 26 Aug 2009 10:57:32 +, kj wrote: > In <7figv3f2m3p0...@mid.uni-berlin.de> "Diez B. Roggisch" > writes: > >>Classes are not scopes. > > This looks to me like a major wart, on two counts. > > First, one of the goals of OO is encapsulation, not only at the level of > instances, but a

Re: Help with arrays

2009-08-26 Thread Dave Angel
Mart. wrote: On Aug 26, 3:02 am, Dave Angel wrote: Stephen Fairchild wrote: Philip Semanchuk wrote: On Aug 25, 2009, at 6:14 PM, Gleb Belov wrote: Hello! I'm working on an exercise wherein I have to write a Guess The Number game, but it's the computer who's guessing M

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In <1bf83a7e-f9eb-46ff-84fe-cf42d9608...@j21g2000yqe.googlegroups.com> Carl Banks writes: >Yeah, it's a little surprising that you can't access class scope from >a function, but that has nothing to do with encapsulation. It does: it thwarts encapsulation. The helper function in my example is o

Re: Need help with Python scoping rules

2009-08-26 Thread Steven D'Aprano
On Wed, 26 Aug 2009 13:57:23 +, kj wrote: > In "Martin P. Hellwig" > writes: > >>kj wrote: >> >>> First, one of the goals of OO is encapsulation, not only at the level >>> of instances, but also at the level of classes. >>Who says? > > Python itself: it already offers a limited form of cla

Re: Need help with Python scoping rules

2009-08-26 Thread Nigel Rantor
kj wrote: > > Needless to say, I'm pretty beat by this point. Any help would be > appreciated. > > Thanks, Based on your statement above, and the fact that multiple people have now explained *exactly* why your attempt at recursion hasn't worked, it might be a good idea to step back, accept the a

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In <02a54597$0$20629$c3e8...@news.astraweb.com> Steven D'Aprano writes: >On Wed, 26 Aug 2009 10:57:32 +, kj wrote: >> Recursion! One of the central concepts in the theory of >> functions! This is shown most clearly by the following elaboration of >> my original example: >> >> class Demo(

Re: ubuntu dist-packages

2009-08-26 Thread Jorgen Grahn
On Wed, 26 Aug 2009 12:46:13 +0200, Diez B. Roggisch wrote: > Robin Becker wrote: > >> I was surprised a couple of days ago when trying to assist a colleage with >> his python setup on a ubuntu 9.04 system. >> >> We built our c-extensions and manually copied them into place, but >> site-packages

Re: Move dictionary from instance to class level

2009-08-26 Thread Dave Angel
Frank Millman wrote: "MRAB" wrote in message news:mailman.444.1251290454.2854.python-l...@python.org... An alternative is: class MyClass(object): ... def on_message_received(self, msg): ... try: ... getattr(self, "method_%d" % msg)() ... exc

Re: Need help with Python scoping rules

2009-08-26 Thread Steven D'Aprano
On Wed, 26 Aug 2009 14:09:57 +, kj wrote: >>1. One of the key aspects of Python's design is that attributes must be >>accessed explicitly with dot notation. Accessing class scopes from >>nested functions would (seemingly) allow access to class attributes >>without the dotted notation. Theref

Re: Need help with Python scoping rules

2009-08-26 Thread Carl Banks
On Aug 26, 8:36 am, kj wrote: > In <1bf83a7e-f9eb-46ff-84fe-cf42d9608...@j21g2000yqe.googlegroups.com> Carl > Banks writes: > > >Yeah, it's a little surprising that you can't access class scope from > >a function, but that has nothing to do with encapsulation. > > It does: it thwarts encapsulati

Re: ubuntu dist-packages

2009-08-26 Thread Robin Becker
Jorgen Grahn wrote: On Wed, 26 Aug 2009 12:46:13 +0200, Diez B. Roggisch Well, if you are thinking about Debian Linux, it's not as much "ripping out" as "splitting into a separate package with a non-obvious name". Annoying at times, but hardly an atrocity. so where is the official plac

Re: Python Processor

2009-08-26 Thread Terry Reedy
manish wrote: Hi, I am also wondering about how to implement a soft core reconfigurable processor in a FPGA which would directly execute the compiled python bytecode. I am trying to understand the bytecode format but apart from http://docs.python.org/library/dis.html there is hardly any doc

Re: Need help with Python scoping rules

2009-08-26 Thread Steven D'Aprano
On Wed, 26 Aug 2009 15:36:35 +, kj wrote: > In <1bf83a7e-f9eb-46ff-84fe-cf42d9608...@j21g2000yqe.googlegroups.com> > Carl Banks writes: > >>Yeah, it's a little surprising that you can't access class scope from a >>function, but that has nothing to do with encapsulation. > > It does: it thwa

Re: quantiles of a student distribution

2009-08-26 Thread Colin J. Williams
Pierre wrote: Hello... Do you know how I can calculate the quantiles of a student distribution in pyhton ? Thanks You might look at: http://bonsai.ims.u-tokyo.ac.jp/~mdehoon/software/python/special.html Colin W. -- http://mail.python.org/mailman/listinfo/python-list

Re: Object's nesting scope

2009-08-26 Thread zaur
On 26 авг, 17:13, "Diez B. Roggisch" wrote: > Whom am we to judge? Sure if you propose this, you have some usecases in > mind - how about you present these Ok. Here is a use case: object initialization. For example, person = Person(): name = "john" age = 30 address = Address(): stree

Re: Python on the Web

2009-08-26 Thread Phil
Thanks to everybody. I believe I am understanding things better. I have looked at the links that have been provided, although I have seen most of them in the past month or so that I've been looking into this stuff. I do agree with most of the things Armin stated in that NIH post. I agree with ever

Re: Object's nesting scope

2009-08-26 Thread Rami Chowdhury
person = Person(): name = "john" age = 30 address = Address(): street = "Green Street" no = 12 Can you clarify what you mean? Would that define a Person class, and an Address class? If you are expecting those classes to be already defined, please bear in mind that if you w

Re: Need help with Python scoping rules

2009-08-26 Thread Ulrich Eckhardt
kj wrote: > class Demo(object): > def fact_iter(n): > ret = 1 > for i in range(1, n + 1): > ret *= i > return ret > > def fact_rec(n): > if n < 2: > return 1 > else: > return n * fact_rec(n - 1) > > classvar1

Re: How does the file.seek() work ?

2009-08-26 Thread gert
On Aug 26, 12:46 am, Graham Dumpleton wrote: > On Aug 25, 5:37 am, Tim Chase wrote: > > > > I want the file pointer set to 100 and overwrite everything from there > > [snip] > > > def application(environ, response): > > >     query=os.path.join(os.path.dirname(__file__),'teemp') > > >    

Re: Need help with Python scoping rules

2009-08-26 Thread Terry Reedy
kj wrote: In <7figv3f2m3p0...@mid.uni-berlin.de> "Diez B. Roggisch" writes: Classes are not scopes. Classes are objects. In particular, they are (by default) instances of class 'type'. Unless 'scopes' were instances of some other metaclass, the statement has to be true. I understand 'sco

Re: Numeric literals in other than base 10 - was Annoying octal notation

2009-08-26 Thread Mensanator
On Aug 26, 9:58 am, Steven D'Aprano wrote: > On Tue, 25 Aug 2009 11:45:28 -0700, Mensanator wrote: > > On Aug 25, 9:14 am, Steven D'Aprano > cybersource.com.au> wrote: > >> On Mon, 24 Aug 2009 18:01:38 -0700, Mensanator wrote: > >> >> If you want your data file to have values entered in hex, or o

SimpleXMLRPCServer timeout issue

2009-08-26 Thread Mahi Haile
Hi all, I have an XML-RPC server running that is using SimpleXMLRPCServer, and I am trying to send a relatively large file on a poor connection [simulated low bandwidth, high latency]. The file is simply the return value of a function call available on the server. However, sometime in to the transf

Re: Need help with Python scoping rules

2009-08-26 Thread Ethan Furman
kj wrote: I have many years of programming experience, and a few languages, under my belt, but still Python scoping rules remain mysterious to me. (In fact, Python's scoping behavior is the main reason I gave up several earlier attempts to learn Python.) Here's a toy example illustrating what

Re: Object's nesting scope

2009-08-26 Thread zaur
On 26 авг, 21:11, "Rami Chowdhury" wrote: > > person = Person(): > >   name = "john" > >   age = 30 > >   address = Address(): > >      street = "Green Street" > >      no = 12 > > Can you clarify what you mean? Would that define a Person class, and an   > Address class? I suppose that someone alr

Re: ubuntu dist-packages

2009-08-26 Thread Florian Diesch
Robin Becker writes: > I was surprised a couple of days ago when trying to assist a colleage > with his python setup on a ubuntu 9.04 system. > > We built our c-extensions and manually copied them into place, but > site-packages wasn't there. It seems that ubuntu now wants stuff to go > into lib/

Re: Need help with Python scoping rules

2009-08-26 Thread kj
In <02a54597$0$20629$c3e8...@news.astraweb.com> Steven D'Aprano writes: >http://docs.python.org/reference/executionmodel.html >It is also discussed in the PEP introducing nested scopes to Python: >http://www.python.org/dev/peps/pep-0227/ >It's even eluded to in the tutorial: >http://docs.pyt

Re: Python Processor

2009-08-26 Thread John Nagle
Terry Reedy wrote: manish wrote: Hi, I am also wondering about how to implement a soft core reconfigurable processor in a FPGA which would directly execute the compiled python bytecode. It probably wouldn't help much. CPython's performance problems come from excessive dictionary lookups,

Re: quantiles of a student distribution

2009-08-26 Thread Robert Kern
On 2009-08-26 11:49 AM, Colin J. Williams wrote: Pierre wrote: Hello... Do you know how I can calculate the quantiles of a student distribution in pyhton ? Thanks You might look at: http://bonsai.ims.u-tokyo.ac.jp/~mdehoon/software/python/special.html [Please pardon the piggybacking. I have

ANN: ActivePython 3.1.1.2 is now available

2009-08-26 Thread Sridhar Ratnakumar
I'm happy to announce that ActivePython 3.1.1.2 is now available for download from: http://www.activestate.com/activepython/python3/ This is a patch release that updates ActivePython to core Python 3.1.1 We recommend that you try 2.6 version first. See the release notes for full details:

Re: Context manager to temporarily change the variable of a register [aka write swap(a,b)]

2009-08-26 Thread Evan Driscoll
On Aug 26, 10:15 am, Carl Banks wrote: > Well, it wouldn't be a "can I rebind a variable using a with- > statement" thread if someone didn't post a solution that they thought > worked, but didn't test it on local variables. I'm not going to deny it was pretty stupid... though in my defense, I'm n

Re: Object's nesting scope

2009-08-26 Thread MRAB
zaur wrote: On 26 авг, 21:11, "Rami Chowdhury" wrote: person = Person(): name = "john" age = 30 address = Address(): street = "Green Street" no = 12 Can you clarify what you mean? Would that define a Person class, and an Address class? I suppose that someone already define cl

Re: pygtk - What is the best way to change the mouse pointer

2009-08-26 Thread MRAB
Ido Levy wrote: Hello All, I am writing a dialog which one of its widget is a gtk.ComboBoxEntry ( let's assume widget in the example below is its instance ) When the user select one of the values from the gtk.ComboBoxEntry I need to run some calculations that takes a few seconds. In order to r

Re: Need help with Python scoping rules

2009-08-26 Thread Dave Angel
Carl Banks wrote: On Aug 26, 8:13 am, Dave Angel wrote: You can probably work around this by replacing the staticmethod decorator with an equivalent function call:. class Demo9(object): def fact(n): if n < 2: return 1 else: return n * Demo.fact(n

  1   2   >