change gtk STOCK_SAVE label text on the fly

2011-07-29 Thread Peter Irbizon
Hello, how could I change STOCK_SAVE label text? I would like to have "Save it!" instead of "Save" And other question related to this is how can I change translation of STOCK_SAVE on the fly? I think I need to set locale for pygtk...but don't know how -- http://mail.python.org/mailman/listinfo/py

Re: removing nested iffs

2011-07-29 Thread Peter Otten
Josh Benner wrote: > I'm writing a function to create a string that gets longer iff an argument > is defined. In there a more elegant way than nesting all those ifs? > > def format_rsync_src_string(args, server="RSYNC"): > """ Format an rsync source directory string. """ > if args.server

Re: change gtk STOCK_SAVE label text on the fly

2011-07-29 Thread Peter Irbizon
> (Don't feel you need to answer this: Do you really think you need on-the-fly language switching? It's "cool", but how many users are going to want to use that?) yes, you're right. anyway it's cool feature and I hoped it's easy to do it in python / but it isn't... > Why do you want to change it?

Re: removing nested iffs

2011-07-30 Thread Peter Otten
Chris Angelico wrote: > On Sat, Jul 30, 2011 at 6:42 AM, Peter Otten <__pete...@web.de> wrote: >> def format_pairs(pairs): >> for template, value in pairs: >> if value is None: >> break >> yield template.format(value) >> > > Cool! May I sugg

Re: Question

2011-08-01 Thread Peter Otten
Camilo Andres Roca Duarte wrote: > My name is Camilo Roca, I'm a student and recently installed the 2.7.2 > Python version. The problem is that anytime I try to run a script from the > Python Shell it returns an error message. I am new using python so I am > not sure what to do since what I'm typi

Re: Complex sort on big files

2011-08-01 Thread Peter Otten
aliman wrote: > Apologies I'm sure this has been asked many times, but I'm trying to > figure out the most efficient way to do a complex sort on very large > files. > > I've read the recipe at [1] and understand that the way to sort a > large file is to break it into chunks, sort each chunk and w

Re: python reading file memory cost

2011-08-02 Thread Peter Otten
Chris Rebert wrote: >> The running result was that read a 500M file consume almost 2GB RAM, I >> cannot figure it out, somebody help! > > If you could store the floats themselves, rather than their string > representations, that would be more space-efficient. You could then > also use the `array`

Re: range() vs xrange() Python2|3 issues for performance

2011-08-02 Thread Peter Otten
harrismh777 wrote: > The following is intended as a helpful small extension to the xrange() > range() discussion brought up this past weekend by Billy Mays... > > With Python2 you basically have two ways to get a range of numbers: > range() , which returns a list, and >xrange() , which r

Re: Hardlink sub-directories and files

2011-08-02 Thread Peter Otten
loial wrote: > I am trying to hardlink all files in a directory structure using > os.link. > > This works fine for files, but the directory also contains sub- > directories (which themselves contain files and sub-directories). > However I do not think it is possible to hard link directories ? >

Re: Please code review.

2011-08-02 Thread Peter Otten
Karim wrote: > I need a generator to create the cellname in a excell (using pyuno) > document to assign value to the correct cell. Isn't there a way to use a (row, column) tuple directly? If so I'd prefer that. Also, there used to be an alternative format to address a spreadsheet cell with som

Re: Please code review.

2011-08-02 Thread Peter Otten
Karim wrote: > values = ( (22.5,21.5,121.5), > (5615.3,615.3,-615.3), > (-2315.7,315.7,415.7) ) > > it = _xrange_cellnames(rows=len(value), cols=len(values[0])) > > table.getCellByName(it.next()).setValue(22.5) > table.getCellByName(it.next()).setValue(5615.3) > table.getCellByName(it.next()).se

Re: attach cString to memoryview?

2011-08-03 Thread Peter Otten
Phlip wrote: > q = cStringIO.StringIO() > p = Popen(cmd, shell=True, stdout=q, bufsize=4096) > The Subject line problem refers to how to get rid of this: > > AttributeError: 'cStringIO.StringO' object >has no attribute 'fileno' What's wrong wi

Re: Snippet: The leanest Popen wrapper

2011-08-03 Thread Peter Otten
Phlip wrote: > Groupies: I smell a slight misperception of the audience you are addressing ;) > This is either a code snippet, if you like it, or a request for a > critique, if you don't. > > I want to call a command and then treat the communication with that > command as an object. And I want

Re: parsing function parameters

2011-08-03 Thread Peter Otten
Lee Harr wrote: > I am trying to get some information about a function > before (and without) calling it. If you allow for the function arguments to be evaluated it's easy (requires Python 2.7): >>> import inspect >>> def get_args(*args, **kw): ... return args, kw ... >>> argstr = "1, 2, z=

HSeparator() in gtk.layour

2011-08-04 Thread Peter Irbizon
hello, how can I add hseparator to gtk.layout? I tried hseparator = gtk.HSeparator() self.layout.put(hseparator, 50,195) but it does not work :/ -- http://mail.python.org/mailman/listinfo/python-list

Re: __set__ method is not called for class attribute access

2011-08-05 Thread Peter Otten
Ryan wrote: > In the context of descriptors, the __set__ method is not called for > class attribute access. __set__ is only > called to set the attribute on an instance instance of the owner class > to a new value, value. WHY? Is there some other mechanism for > accomplishing this outcome. This su

Re: __set__ method is not called for class attribute access

2011-08-05 Thread Peter Otten
Duncan Booth wrote: > The descriptor protocol only works when a value is being accessed or set > on an instance and there is no instance attribute of that name so the > value is fetched from the underlying class. Unlike normal class attributes a descriptor is not shaded by an instance attribute:

Re: problem with bcd and a number

2011-08-05 Thread Peter Otten
Chris Angelico wrote: > On Fri, Aug 5, 2011 at 1:40 AM, Dan Stromberg wrote: > print int(hex(0x72).replace('0x', '')) >> 72 > > Or simpler: int(hex(0x72)[2:]) > > Although if you have it as a string, you need to ord() the string. Or use str.encode(): >>> int("\x72".encode("hex")) 72 >>> i

Re: problem with bcd and a number

2011-08-05 Thread Peter Pearson
On Thu, 04 Aug 2011 21:52:45 +0200, Christoph Hansen wrote: > MRAB schrieb: > >> The value is MSB * 100 + (LSB>> 4) * 10 + (LSB& 0xF) > > i would say > > (MSB >> 4)*100 + (MSB & 0xF)*10 + (LSB >> 4) > > but who knows I concur. I think the documentation is trying to say that the low-order nibb

Re: How do I implement two decorators in Python both of which would eventually want to call the calling function

2011-08-06 Thread Peter Otten
Devraj wrote: > Hi all, > > I am trying to simply my Web application handlers, by using Python > decorators. > > Essentially I want to use decorators to abstract code that checks for > authenticated sessions and the other that checks to see if the cache > provider (Memcache in this instance) has

Re: Calling super() in __init__ of a metaclass

2011-08-06 Thread Peter Otten
Eli Bendersky wrote: > Consider this standard metaclass definition: > > class MyMetaclass(type): > def __init__(cls, name, bases, dct): > super(MyMetaclass, cls).__init__(name, bases, dct) > # do meta-stuff > > class Foo(object): > __metaclass__ = MyMetaclass > > The cal

gtk STOCK_SAVE text in another language

2011-08-10 Thread Peter Irbizon
hello, I have slovak win but I would like to have english captions on pygtk STOCK_SAVE buttons. How can I set this? thanks -- http://mail.python.org/mailman/listinfo/python-list

problem with GTK language

2011-08-10 Thread Peter Irbizon
Hello, I have strange problem with gtk language in pygtk. When I run .py file it shows all gtk labels in my default windows language (slovak). But when I compile it with py2exe and run exe file all labels are in english. Why this happens? How can I define on program startup which language to use? I

Re: Processing a large string

2011-08-12 Thread Peter Otten
goldtech wrote: > Hi, > > Say I have a very big string with a pattern like: > > akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn. > > I want to split the sting into separate parts on the "3" and process > each part separately. I might run into memory limitations if I use > "split" and

Re: Processing a large string

2011-08-12 Thread Peter Otten
Peter Otten wrote: > goldtech wrote: >> Say I have a very big string with a pattern like: >> >> akakksssk3dhdhdhdbddb3dkdkdkddk3dmdmdmd3dkdkdkdk3asnsn. >> >> I want to split the sting into separate parts on the "3" and process >> each part s

Re: How do I convert String into Date object

2011-08-13 Thread Peter Otten
MrPink wrote: > I have file of records delimited by spaces. > I need to import the date string and convert them into date datatypes. > > '07/27/2011' 'Event 1 Description' > '07/28/2011' 'Event 2 Description' > '07/29/2011' 'Event 3 Description' > > I just discovered that my oDate is not an obje

Re: surprising interaction between function scope and class namespace

2011-08-15 Thread Peter Otten
Stefan Behnel wrote: > Hi, > > I just stumbled over this: > >>>> A = 1 >>>> def foo(x): >... A = x >... class X: >... a = A >... return X >... >>>> foo(2).a >2 >>>> def foo(x): >... A = x >... class X: >... A

Re: testing if a list contains a sublist

2011-08-16 Thread Peter Otten
Johannes wrote: > what is the best way to check if a given list (lets call it l1) is > totally contained in a second list (l2)? > > for example: > l1 = [1,2], l2 = [1,2,3,4,5] -> l1 is contained in l2 > l1 = [1,2,2,], l2 = [1,2,3,4,5] -> l1 is not contained in l2 > l1 = [1,2,3], l2 = [1,3,5,7] ->

Re: testing if a list contains a sublist

2011-08-16 Thread Peter Otten
Johannes wrote: > Am 16.08.2011 09:44, schrieb Peter Otten: >> Johannes wrote: >> >>> what is the best way to check if a given list (lets call it l1) is >>> totally contained in a second list (l2)? >>> >>> for example: >>> l1 = [1,2

Re: extend class: include factories functions inside constructor

2011-08-18 Thread Peter Otten
aspineux wrote: > Hi > I have a closed class and 2 factories function > > class Data: > def __init__(self): > self.payload=None > > def data_from_string(payload): > data=Data() > data.payload=payload > return data > > def data_from_file(f): > data=Data() > data.payload=f.read()

Re: lists and for loops

2011-08-18 Thread Peter Pearson
On Wed, 17 Aug 2011 20:08:23 -0700 (PDT), Emily Anne Moravec wrote: > I want to add 5 to each element of a list by using a for loop. > > Why doesn't this work? > > numbers = [1, 2, 3, 4, 5] > for n in numbers: > n = n + 5 > print numbers Because integers are immutable. You cannot turn 1 into

Re: List spam

2011-08-18 Thread Peter Pearson
On Thu, 18 Aug 2011 16:58:04 +0200, Alain Ketterlin wrote: > Ghodmode writes: > > [...] >> Make an effort to curb the spam even if it means killing the newsgroup >> availability. Choose mailman or Google Groups, or another single >> solution. Make it members only, but allow anyone to register wi

Re: List spam

2011-08-18 Thread Peter Pearson
On Thu, 18 Aug 2011 12:15:59 -0400, gene heskett wrote: [snip] > What is wrong with the mailing list only approach? In the mailing-list approach, how do I search for prior discussions on a subject? (I'm not particularly opposed to the mailing list, I'm just an NNTP follower worried about the unc

Re: Compare tuples of different lenght

2011-08-20 Thread Peter Otten
Jurgens de Bruin wrote: > Hi, > > I have a list of tuples: > > [(2,),(12,13),(2,3,4),(8,),(5,6),(7,8,9),] > > I would like to compare all the tuples to each other and if one > element if found two tuples the smallest tuples is removed from the > list. > > example if tuple 1 and tuple 3 are com

Re: Adding modified methods from another class without subclassing

2011-08-22 Thread Peter Otten
John O'Hagan wrote: > I have a class like this: > > class MySeq(): > def __init__(self, *seq, c=12): > self.__c = c > self.__pc = sorted(set([i % __c for i in seq])) > self.order = ([[self.__pc.index(i % __c), i // __c] for i in seq]) > #other calculated attrib

Re: locale.format without trailing zeros

2011-08-22 Thread Peter Otten
przemol...@poczta.fm wrote: import locale locale.setlocale(locale.LC_ALL, "pl_PL") > 'pl_PL' i=0.20 j=0.25 locale.format('%f', i) > '0,20' locale.format('%f', j) > '0,25' > > I need to print the numbers in the following format: > '0,2' (i) > '0,25'(j)

Re: Optimizing Text Similarity Algorithm

2011-08-22 Thread Peter Otten
Yaşar Arabacı wrote: > I originally posted this question on stackoverflow, you can find it here: > http://stackoverflow.com/q/7133350/886669 > > I just want people check what I am doing and express their opinion about > the thing I am doing is acceptable, or are there some expects of it that > co

Re: locale.format without trailing zeros

2011-08-22 Thread Peter Otten
przemol...@poczta.fm wrote: > How about this format: > ',1' > (the local zero is also not printed) > > (I know this is strange but I need compatibility with local requirements) I believe you have to do it yourself: >>> locale.format("%f", 0.123) '0,123000' >>> locale.format("%f", 0.123).strip("

Re: Adding modified methods from another class without subclassing

2011-08-22 Thread Peter Otten
John O'Hagan wrote: > On Mon, 22 Aug 2011 11:32:18 +0200 > Peter Otten <__pete...@web.de> wrote: > >> John O'Hagan wrote: >> >> > I have a class like this: >> > >> > class MySeq(): >> > def __init__(self, *seq, c=12

Re: Why __slots__ slows down attribute access?

2011-08-23 Thread Peter Otten
Jack wrote: > People have illusion that it is faster to visit the attribute defined > by __slots__ . > http://groups.google.com/group/comp.lang.python/msg/c4e413c3d86d80be > > That is wrong. The following tests show it is slower. Not so fast. Here's what I get (python2.6.4, 64 bit): $ python -

Re: is there any principle when writing python function

2011-08-23 Thread Peter Otten
smith jack wrote: > i have heard that function invocation in python is expensive, but make > lots of functions are a good design habit in many other languages, so > is there any principle when writing python function? > for example, how many lines should form a function? Five ;) -- http://mail.p

incorporate png/ico to exe and use it in application

2011-08-23 Thread Peter Irbizon
hello, I am zsing py2exe to compile exe files. I would like to incorporate png and icon file into exe and then use it during program run (to show it in about dialog and system tray). How can I do it? For example now I use self.staticon.set_from_file(os.path.join(module_path(), "icon.ico")) but I

aboutdialog space between program name/version and logo

2011-08-23 Thread Peter Irbizon
Hello, please how can i set space between program name/version and logo in this code? thanks about = gtk.AboutDialog() about.set_program_name("name") about.set_version("0.0.1") about.set_logo(gtk.gdk.pixbuf_new_from_file("file.png")) -- http://mail.python.org/mailman/listinfo/python-list

Re: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data...

2011-08-24 Thread Peter Otten
Adam Jorgensen wrote: > Hi all, I'm experiencing a weird issue with closuring of parameters > and some nested functions I have inside two functions that > return decorators. I think it's best illustrated with the actual code: You should have made an effort to reduce its size > # This decorator do

Re: Getting a module's code object

2011-08-25 Thread Peter Otten
Arnaud Delobelle wrote: > In Python 3, a function f's code object can be accessed via f.__code__. > > I'm interested in getting a module's code object, i.e. the code that > is executed when the module is run. I don't think it's accessible via > the module object itself (although I would be glad

Re: How cai i encode url

2011-08-25 Thread Peter Otten
John Smithury wrote: > Hi pythons. > > following is my code > > # -*- coding: utf8 -*- > import urllib2 > import urllib > > url = "http://a.shanting.mobi/百家讲坛/大国医/list"; > print url > p1=u"百家讲坛".encode('utf8') > p2=u"大国医".encode('utf8') > encodeurl = "http://a.shanting.mobi/"+p1+"/"+p2+"/"+"lis

Re: The RAISE_VARARGS opcode in Python 3

2011-08-26 Thread Peter Otten
Arnaud Delobelle wrote: > Here is an extract from the dis module doc [1] > > """ > RAISE_VARARGS(argc) > Raises an exception. argc indicates the number of parameters to the > raise statement, ranging from 0 to 3. The handler will find the > traceback as TOS2, the parameter as TOS1, and the except

Re: Understanding .pth in site-packages

2011-08-27 Thread Peter Otten
Josh English wrote: > I have a development version of a library in c:\dev\XmlDB\xmldb > > After testing the setup script I also have > c:\python27\lib\site-packages\xmldb > > Now I'm continuing to develop it and simultaneously building an > application with it. > > I thought I could plug into m

Re: Unpickle error -- "object has no attribute ...."

2011-08-29 Thread Peter Otten
luvspython wrote: > I have an application that needs to keep a history of the values of > several attributes of each of many instances of many classes. The > history-keeping logic is in a helper class, HistoryKeeper, that's > inherited by classes like Vehicle in the example below. > > Pickling a

Re: Help me understand this logging config

2011-08-30 Thread Peter Otten
Roy Smith wrote: > I'm using django 1.3 and python 2.6. Isn't dictConfig() new in 2.7? It looks like that is what you are using... > My logging config is: > > > LOGGING = { > 'version': 1, > 'disable_existing_loggers': False, > 'formatters': { > 'verbose': { > '

Re: Making `logging.basicConfig` log to *both* `sys.stderr` and `sys.stdout`?

2011-08-30 Thread Peter Otten
Michel Albert wrote: > I use python oftentimes to write automation scripts on Linux servers. > And there's a big pattern in my scripts: > > - I *always* use `logging` instead of `print` statements. > - I *always* create two stream handlers. One for `sys.stdout` with > level `INFO` and one for `sy

Re: Unpickle error -- "object has no attribute ...."

2011-08-30 Thread Peter Otten
luvspython wrote: > THANK YOU! Special-casing "__dict__" did the trick. Not sure I'd > have ever figured that out, which leads to a different question: > > I can figure out most things, though perhaps very slowly and > painfully, if I can trace through code. I use WingIDE (love it), but > the

Re: PC locks up with list operations

2011-08-31 Thread Peter Otten
Steven D'Aprano wrote: > Twice in a couple of weeks, I have locked up my PC by running a Python 2.5 > script that tries to create a list that is insanely too big. > > In the first case, I (stupidly) did something like: > > mylist = [0]*12345678901234 > > After leaving the machine for THREE DAYS

Re: idiomatic analogue of Perl's: while (<>) { ... }

2011-08-31 Thread Peter Otten
Sahil Tandon wrote: > I've been tasked with converting some programs from Perl -> Python, and > am (as will soon be obvious) new to the language. A few archive/google > searches were inconclusive on a consensus approach, which is OK, but I > just wonder if there is a more Python-esque way to do t

Re: idiomatic analogue of Perl's: while (<>) { ... }

2011-09-01 Thread Peter Otten
Peter Otten wrote: > A quick look into fileinput.py reveals that it uses readlines() and slurps > in the complete "file". I'm not sure that was a clever design decision... Correction: >>> with open("tmp.txt") as f: lines = f.readlines(0) ... >>>

Re: Constructors...BIIIIG PROBLEM!

2011-09-01 Thread Peter Otten
Amogh M S wrote: > Hey guys... > I think we have a problem with my _init_ method and the constructor > When I create a class and its _init_ method and try to create an object of > it outside the class, > Say, something like > > class S: >def _init_(self, name=None): Your __init__() method ne

Re: Regex to match all trailing whitespace _and_ newlines.

2011-09-01 Thread Peter Otten
Dotan Cohen wrote: > In the terrific Anki [1] application I am trying to remove trailing > whitespace from form fields. This is my regex: > [\n+\s+]$ My attempt: >>> sub = re.compile(r"\s*?(\n|$)").sub >>> sub("", "alpha \nbeta \r\n\ngamma\n") 'alphabetagamma' >>> sub("", "alpha \nbeta \

Re: Need help with simple OOP Python question

2011-09-05 Thread Peter Otten
Kristofer Tengström wrote: > Hi, I'm having trouble creating objects that in turn can have custom > objects as variables. The code looks like this: > > - > > class A: > sub = dict() Putting it into the class like this means sub is shared by all in

Re: Need help with simple OOP Python question

2011-09-05 Thread Peter Otten
Kristofer Tengström wrote: > Thanks everyone, moving the declaration to the class's __init__ method > did the trick. Now there's just one little problem left. I'm trying to > create a list that holds the parents for each instance in the > hierarchy. This is what my code looks like now: > > --

Re: Need help with simple OOP Python question

2011-09-05 Thread Peter Otten
Jon Clements wrote: > I > must say I'm not 100% sure what the OP wants to achieve... Learn Python? ;) -- http://mail.python.org/mailman/listinfo/python-list

Re: One line command line filter

2011-09-06 Thread Peter Otten
Jon Redgrave wrote: > It seems unreasonably hard to write simple one-line unix command line > filters in python: > > eg: ls | python -c " print x.upper()" > > to get at sys.stdin or similar needs an import, which makes a > subsequent for-loop illegal. > python -c "import sys; for x in sys.stdin

Re: PEP 20 - Silly Question?

2011-09-06 Thread Peter Otten
Joseph Armbruster wrote: > I have used Python for some time and ran a windows build-bot for a bit. > This morning, I told a fellow developer "There should be only one obvious > way to do it." and then I proceeded to forward him to the Zen of Python > and sent him a link to: > http://www.python.or

Re: How to structure packages

2011-09-07 Thread Peter Otten
bclark76 wrote: > I'm learning python, and was playing with structuring packages. If you are coming from Jave you have to unlearn a thing or two. > Basically I want to have a package called mypackage that defines a > number of classes and functions. > I'm trying to follow the rule that every f

Re: Is this a safe use of eval?

2011-02-24 Thread Peter Otten
Frank Millman wrote: > Hi all > > I know that the use of 'eval' is discouraged because of the dangers of > executing untrusted code. > > Here is a variation that seems safe to me, but I could be missing > something. > > I have a class, and the class has one or more methods which accept various

Re: 2to3 chokes on bad character

2011-02-24 Thread Peter Otten
John Machin wrote: > On Feb 23, 7:47 pm, "Frank Millman" wrote: >> Hi all >> >> I don't know if this counts as a bug in 2to3.py, but when I ran it on my >> program directory it crashed, with a traceback but without any indication >> of which file caused the problem. >> > [traceback snipped] > >>

Re: 2to3 chokes on bad character

2011-02-25 Thread Peter Otten
John Machin wrote: > On Feb 25, 12:00 am, Peter Otten <__pete...@web.de> wrote: >> John Machin wrote: > >> > Your Python 2.x code should be TESTED before you poke 2to3 at it. In >> > this case just trying to run or import the offending code file would >>

Re: Various behaviors of doctest

2011-02-28 Thread Peter Otten
Gnarlodious wrote: > Yeah, I just spent about 2 hours trying everything I could think of... > without success. Including your suggestions. Guess I'll have to skip > it. But thanks for the ideas. > > -- Gnarlie Are you using Python 2.x? Then you cannot redefine print. Instead you have to redirec

Re: python simplejson decoding

2011-03-02 Thread Peter Otten
Arthur Mc Coy wrote: > Hi all, > > > > I'm trying an example (in attached file, I mean the bottom of this > message). > > First, I create a list of 3 objects. Then I do: > > > PutJSONObjects(objects) > objects = GetJSONObjects() > PutJSONObjects(objects, "objects2.json") > > > 1) PutJSONOb

Re: I'm happy with Python 2.5

2011-03-03 Thread Peter Parker
On 02/27/2011 09:27 AM, Tom Zych wrote: n00m wrote: Am I turmoiling your wishful thinking? You may nourish it till the end of time. Let us cease to nourish those fabled ones who dwell under bridges. LOL ! -- http://mail.python.org/mailman/listinfo/python-list

Re: Extending dict (dict's) to allow for multidimensional dictionary

2011-03-05 Thread Peter Otten
Ravi wrote: > I found a solution here: > > http://parand.com/say/index.php/2007/07/13/simple-multi-dimensional- dictionaries-in-python/ > > Please tell how good is it? Follow the link to the cookbook and read Andrew Dalke's comment ;) To spell it out: >>> class D(dict): ... def __missing_

Re: required help in manual sort

2011-03-07 Thread Peter Otten
Manjunath N wrote: > Hello users, > I'm quite new to python programming. I need help in manually sorting > a > list which is shuffled. The problem i'm facing is with respect to last > element in the list when checking the condition using if statement. Below > I have pasted my code. The

Re: A question about Cmd Class

2011-03-08 Thread Peter Otten
ames(self, text.replace("-", "_"), *ignored) class Cmd(MyCmd): def do_eat_fish(self, rest): print "eat fish", rest def do_drink_beer(self, rest): print "drink beer", rest def do_EOF(self, rest): return True if __name__ == "__main__": c = Cmd() c.cmdloop() If you need the "help_" prefix to work, too, you have to tweak it further. I don't know if there are other hidden quirks... Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: python cmd.Cmd auto complete feature

2011-03-08 Thread Peter Otten
Jean-Michel Pichavant wrote: > I'm trying to autoexpand values as well as arguments using the builtin > cmd.Cmd class. > > I.E. > Consider the following command and arguments: > > > sayHello target=Georges > 'Hello Georges !' > > I can easily make 'tar' expand into 'target=' however I'd like t

Re: Reference Cycles with instance method

2011-03-09 Thread Peter Otten
Amit Dev wrote: > Simple question. If I have the following code: > > class A: > def __init__(self, s): > self.s = s > self.m2 = m1 > > def m1(self): > pass > > if __name__ == '__main__': > a = A("ads") > a.m1() > a = None > > The object is not garbag

Re: error in exception syntax

2011-03-09 Thread Peter Otten
Aaron Gray wrote: > On Windows I have installed Python 3.2 and PyOpenGL-3.0.1 and am getting > the following error :- > > File "c:\Python32\lib\site-packages\OpenGL\platform\win32.py", line 13 > except OSError, err: > ^ > > It works okay on my Linux machine running Pyth

Re: my computer is allergic to pickles

2011-03-09 Thread Peter Otten
Bob Fnord wrote: > I'm using python to do some log file analysis and I need to store > on disk a very large dict with tuples of strings as keys and > lists of strings and numbers as values. > > I started by using cPickle to save the instance of the class that > contained this dict, but the pickli

Re: Use-cases for alternative iterator

2011-03-11 Thread Peter Otten
Steven D'Aprano wrote: > The iter() built-in takes two different forms, the familiar > iter(iterable) we all know and love, and an alternative form: > > iter(callable, sentinel) > I've never seen this second form in actual code. Does anyone use it, and > if so, what use-cases do you have? I fo

Re: Two random lists from one list

2011-03-11 Thread Peter Otten
noydb wrote: > Hello All, > > I am just looking to see if there is perhaps a more efficient way of > doing this below (works -- creates two random teams from a list of > players). Just want to see what the experts come up with for means of > learning how to do things better. > > Thanks for any

Re: generator / iterator mystery

2011-03-13 Thread Peter Otten
the local x of the current enum3() call. Another fix is to use chain.from_iterable(...) instead of chain(*...): >>> list(chain.from_iterable(((x, n) for n in range(3)) for x in "abc")) [('a', 0), ('a', 1), ('a', 2), ('b', 0), ('b', 1), ('b', 2), ('c', 0), ('c', 1), ('c', 2)] Here the outer generator proceeds to the next x only when the inner generator is exhausted. Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: os.walk/list

2011-03-20 Thread Peter Otten
ecu_jon wrote: > so i am trying to add md5 checksum calc to my file copy stuff, to make > sure the source and dest. are same file. > i implemented it fine with the single file copy part. something like : > for files in sourcepath: > f1=file(files ,'rb') > try: > shutil.

Re: os.walk/list

2011-03-21 Thread Peter Otten
ecu_jon wrote: > yes i agree breaking stuff into smaller chunks is a good way to do it. > even were i to do something like > > def safe_copy() > f1=file(files ,'rb') > f2 = file(os.path.join(currentdir,fname,files)) > truth = md5.new(f1.read()).digest() == > md5.new(f2.read()).dig

Re: Problem with re module

2011-03-22 Thread Peter Otten
John Harrington wrote: > I'm trying to use the following substitution, > > lineList[i]=re.sub(r'(\\begin{document})([^$])',r'\1\n\n > \2',lineList[i]) > > I intend this to match any string "\begin{document}" that doesn't end > in a line ending. If there's no line ending, then, I want to pl

Re: Non-deterministic output

2011-03-28 Thread Peter Otten
Esben Nielsen wrote: > Hi, > > We are making a prototype program in Python. I discovered the output was > non-deterministic, i.e. I rerun the program on the same input files and > get different output files. We do not use any random calls, nor > threading. > > One of us thought it could be set a

Re: ValueError: insecure pickle string

2011-03-28 Thread Peter Otten
pradeepbpin wrote: > I am encountering 'Value Error: insecure string pickle' when trying to > execute the script on Ubuntu. The same script and the pickled file > works without any problem in Windows. For working in Ubuntu I just > copied both the script file and pickled file from Windows. > > >

Re: Python problem

2011-03-28 Thread Peter Pearson
On Mon, 28 Mar 2011 11:38:29 -1000, John Parker wrote: [snip] > I have written the following code so far but get an error. > > infile = open("scores.txt", "r") > lines = infile.readlines() > infile.close() > tokens = lines.split(",") [snip] > error: > Traceback (most recent call last): > File

Re: Python3 Tkinter difficulty

2011-03-29 Thread Peter Otten
harrismh777 wrote: > Greetings folks, > I am very new to this usenet forum, and I am brand new to Python3... Welcome. > so be gentle We don't eat children above the age of three ;) > The source tarball for Python3 compiled and installed (local install > for first experiments $HOME/loc

Re: Sudden error: SyntaxError: Non-ASCII character '\xc2' in file

2011-03-30 Thread Peter Otten
Gnarlodious wrote: > RSS script runs fine on my dev machine but errors on the server > machine. Script was last run 3 days ago with no problem. Possible > clue: dev machine is (Mac OSX) running Python 3.1.1 while server is > running Python 3.1.3. I have not updated anything that should suddenly >

Re: Sudden error: SyntaxError: Non-ASCII character '\xc2' in file

2011-03-30 Thread Peter Otten
Benjamin Kaplan wrote: > On Wed, Mar 30, 2011 at 10:34 AM, Gnarlodious > wrote: >> RSS script runs fine on my dev machine but errors on the server >> machine. Script was last run 3 days ago with no problem. Possible >> clue: dev machine is (Mac OSX) running Python 3.1.1 while server is >> running

Re: Mathematical Operations on Array

2011-04-01 Thread Peter Otten
bryan.fodn...@gmail.com wrote: > I am loading text into an array and would like to convert the values. > > from math import * > from numpy import * > from pylab import * > > data=loadtxt('raw.dat') > mincos=degrees(acos(data[:,0])) > minazi=degrees(data[:,1]) > minthick=data[:,2]/0.006858 > > I

Re: Python-list Digest, Vol 91, Issue 15

2011-04-02 Thread Peter Otten
Alden Meneses wrote: > YuyYYyYyUuyuuiaAku. UUuqsuiuiuiui Please post the complete traceback, throw your phone over the right shoulder and clap your hands just before it hits the ground. That'll fix your problem. -- http://mail.python.org/mailman/listinfo/python-list

Re: Gammu in python error

2011-04-02 Thread Peter Otten
Santhosh Kumar wrote: > Hi all, > I am new to gammu. I did the cofiguration with gammu very > successfully > and if I try to send sms with command mode ( sudo echo "sms test from > santhos pc probably yo vl call me" | /usr/bin/gammu --sendsms TEXT > +919840411410 ) its working fine. So,

Re: TypeError: iterable argument required

2011-04-04 Thread Peter Otten
Νικόλαος Κούρας wrote: >> if "@" in mail and comment not in INVALID_COMMENTS: > In my original question can you explain to me what the meaning of the > following error is? > > > mail = None, comment = None > TypeError: iterable argument required > arg

Re: proposal to allow to set the delimiter in str.format to something other than curly bracket

2011-04-04 Thread Peter Otten
Alia Khouri wrote: > Terry Reedy wrote: > >> Just double the brackets, just as one doubles '\\' to get '\' in a >> string. >> >> >>> "class {0}Model {{ public bool IsModel(){{ returntrue; >> ".format('My') >> >> 'class MyModel { public bool IsModel(){ returntrue; } }' >> > > Indeed, I tried

Re: a better way to invert a list?

2011-04-06 Thread Peter Otten
Glazner wrote: >> > def invert(p): >> > inverse = [None] * len(p) >> > for (i, j) in enumerate(p): >> > inverse[j] = i >> > return inverse >> >> Elegant. This seems like the best solution, although it isn't as much >> fun to write as a "one-liner". Thanks > > invert([1, 2, 3, 1]) > [None, 3

Re: Loading Modules

2011-04-13 Thread Peter Otten
Cornelius Kölbel wrote: > I am wondering about loading modules.What is a good way of doing this? > > In my code I got one single function, where I need some functionality > from a built-in module. built-in modules are always imported by definition, so you cannot save space or time by moving the

Re: memory usage multi value hash

2011-04-14 Thread Peter Otten
christian wrote: > Hello, > > i'm not very experienced in python. Is there a way doing below more > memory efficient and maybe faster. > I import a 2-column file and then concat for every unique value in > the first column ( key) the value from the second > columns. > > So The ouptut is someth

Re: Pythonic infinite for loop?

2011-04-15 Thread Peter Otten
Paul Rubin wrote: > Chris Angelico writes: >>> sentinel = object() >>> seq = (dct.get('Keyword%d'%i,sentinel) for i in count(1)) >>> lst = list(takewhile(lambda x: x != sentinel, seq)) >> >> If I understand this code correctly, that's creating generators, >> right? It won't evaluate past the sent

Re: memory usage multi value hash

2011-04-15 Thread Peter Otten
Terry Reedy wrote: > On 4/14/2011 12:55 PM, Peter Otten wrote: > >> I don't expect that it matters much, but you don't need to sort your data >> if you use a dictionary anyway: > > Which means that one can build the dict line by line, as each is read, > in

Re: Pythonic infinite for loop?

2011-04-15 Thread Peter Otten
Chris Angelico wrote: > Apologies for interrupting the vital off-topic discussion, but I have > a real Python question to ask. > > I'm doing something that needs to scan a dictionary for elements that > have a particular beginning and a numeric tail, and turn them into a > single list with some p

Re: Pythonic infinite for loop?

2011-04-15 Thread Peter Otten
Chris Angelico wrote: > On Fri, Apr 15, 2011 at 6:25 PM, Peter Otten <__pete...@web.de> wrote: >> The initial data structure seems less than ideal. You might be able to >> replace it with a dictionary like >> >> {"Keyword": [value_for_keyword_1, value

<    3   4   5   6   7   8   9   10   11   12   >