Re: A Universe Set

2006-10-04 Thread MonkeeSage
Jorgen Grahn wrote: > - infinite xrange()s Fun. How about in-memory objects which use no memory, and self-referential anonymous functions, and object states without objects... Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Subclassing built-in classes

2006-10-05 Thread MonkeeSage
I know that python doesn't allow extending built-in objects like the str class; but you can subclass them using a class of the same name and thus shadow them to get the same general effect (albeit you have to use the explicit constructor rather than literals). class str(str): def display(self):

Re: Subclassing built-in classes

2006-10-05 Thread MonkeeSage
Steve Holden wrote: > Unfortunately the literals are interpreted during bytecode generation, > before the compiled program is available, and your modifications to > __builtns__ haven't been made, so the answer is "no", I'm afraid. Ah! That makes sense. I guess the only way to do it would be to add

Re: Asychronous execution *with* return codes?

2006-10-05 Thread MonkeeSage
utabintarbo wrote: > pid = subprocess.Popen([app] + lstArgs).pid Check out the poll() method and the returncode attribute: http://docs.python.org/lib/node533.html Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: building strings from variables

2006-10-05 Thread MonkeeSage
wesley chun wrote: > from the performance standpoint, i believe that #4 (list join) from > scott is the fastest. #1 (string formatting) is next preferred only > because #3 (string concat) is the worst [think "realloc()"]. #2 is > useful for when you have users who aren't as comfortable with #1. I

Re: building strings from variables

2006-10-05 Thread MonkeeSage
Ps. For readability you can also roll your own sprintf function: def format(s, *args, **kwargs): if args: return s % args elif kwargs: return s % kwargs else: return s s = 'I like %s and %s.' print format(s, 'ham', 'cheese') s = 'I like %(b)s and %(c)s.' print format(s, b='butt

Re: Metaprogramming question

2006-10-05 Thread MonkeeSage
Steve Menard wrote: > So my question is, how to replicate new.instance() functionality with new > classes? class A(object): def __init__(self): print "Class A" A() A.__new__(A) # <- this one Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: printing variables

2006-10-05 Thread MonkeeSage
[EMAIL PROTECTED] wrote: > Thanks all for the answers. Yup, i think i will use dicts/tuples/lists > instead... Even though you should be using some kind of container, you can still do what you origianlly asked for with relative ease...you just have to use the evil eval function (gasp!): for i in

Re: help on pickle tool

2006-10-05 Thread MonkeeSage
hanumizzle wrote: > Why a subset? I don't think JSON is a subset of YAML. Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: help on pickle tool

2006-10-05 Thread MonkeeSage
On Oct 6, 1:06 am, hanumizzle <[EMAIL PROTECTED]> wrote: > I'm happy with my Pythonesque YAML syntax, thank you. :) YAML is a little more complex, and a little more mature. But JSON should not be ruled out. I actually like JSON personally. Regards, Jordan -- http://mail.python.org/mailman/lis

Re: help on pickle tool

2006-10-05 Thread MonkeeSage
On Oct 6, 1:28 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > when did you last look at the spec? I'm fairly versed in JS objects, having written 10 or so extensions for firefox; but I've only used YAML for trivial tasks like config files. So I can't really say how they stack up in "the big pict

Re: Subclassing built-in classes

2006-10-06 Thread MonkeeSage
On Oct 6, 4:58 am, Maric Michaud <[EMAIL PROTECTED]> wrote: > As the first post said "...couldn't python (in theory)...", I was discussing > if it would be possible for python (in some future version) to manage the > literals so that they use the constructors in the __builtin__ module, I > didn't

Re: Names changed to protect the guilty

2006-10-06 Thread MonkeeSage
On Oct 6, 6:27 pm, [EMAIL PROTECTED] (Aahz) wrote: > The following line of lightly munged code was found in a publicly > available Python library... Yes, this violates the Holy, Inspired, Infallible Style Guide (pbuh), which was written by the very finger of God when the world was still in chaot

Re: Names changed to protect the guilty

2006-10-06 Thread MonkeeSage
On Oct 6, 8:02 pm, "MonkeeSage" <[EMAIL PROTECTED]> wrote: > it is clearer to you to make the condition explicit ("blah not False"), "blah not False" -> "blah is False" -- http://mail.python.org/mailman/listinfo/python-list

Re: Names changed to protect the guilty

2006-10-06 Thread MonkeeSage
On Oct 6, 8:34 pm, Neil Cerutti <[EMAIL PROTECTED]> wrote: > And in the original case, I'd agree that "if X.has_key():" is > quite clear, already yielding a boolian value, and so doesn't > need to be tested for if it's False. But I wouldn't like to test > for an empty list or for None implicitly.

Re: Can't get around "IndexError: list index out of range"

2006-10-06 Thread MonkeeSage
On Oct 6, 8:23 pm, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > if 2 in [1,2,3]: print "Use the same (in) operator" > elif 'E' in ('E','r','i','k'): print "Works for any sequence" > elif 'o' in 'hello': print "Even strings" This isn't really analogous is it? For "somedict.has_key(k)" or "k in

Re: problem with split

2006-10-06 Thread MonkeeSage
On Oct 6, 11:33 pm, hanumizzle <[EMAIL PROTECTED]> wrote: > import re > > > > if line.startswith('instr'): > p = re.compile(r'(\d+)\s+;(.*)$') > m = p.search(line) > > return (m.group(1), m.group(2)) You probably don't want startswith, in case there are initial spaces in the line. Also, sin

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread MonkeeSage
On Oct 7, 3:27 am, Gabriel Genellina <[EMAIL PROTECTED]> wrote: > The meaning comes from the most common usage. I wasn't suggesting that the "in" keyword have a different sematic for sequence types. I was just saying that regarding the question whether there is anything similar to "dict.has_key

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread MonkeeSage
On Oct 7, 12:37 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > for what? key in self.keys() And d.get() looks like sugar for: if self.has_key(key): return self[key] else: return default_value Why not have the same sugar for sequence types? E.g., def has_index(self, index):

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread MonkeeSage
On Oct 7, 7:14 pm, Duncan Smith <[EMAIL PROTECTED]> wrote: > No. The above constructs a list of keys and searches the list for the > key, O(n). "key in somedict" is a lookup, O(1). My point wasn't in regard to implementation details, but in regard to convenience methods. Obviously the sugary d

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread MonkeeSage
On Oct 7, 7:41 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > Are you just making a philosophical point? In which case I agree: *if* you > make the analogy "a dictionary key is analogous to a sequence index", > *then* the operation of "in" isn't semantically analogous between mappings > and sequ

Re: Can't get around "IndexError: list index out of range"

2006-10-07 Thread MonkeeSage
On Oct 7, 8:06 pm, "MonkeeSage" <[EMAIL PROTECTED]> wrote: > More often and easier to implement than dict.has_key / get? More -> Less -- http://mail.python.org/mailman/listinfo/python-list

Re: Can't get around "IndexError: list index out of range"

2006-10-08 Thread MonkeeSage
On Oct 8, 5:57 am, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > No, *less* often. That's the point -- it is fairly common for people to > want dictionary lookup to return a default value, but quite rare for them > to want sequence lookup to return a default value. A sequence with a > default value

Re: Can't get around "IndexError: list index out of range"

2006-10-08 Thread MonkeeSage
On Oct 8, 1:44 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > but "let's hypergeneralize and treat sequences and mappings as the same > thing" proposals are nothing new; a trip to the archives might be help- > ful. Huh? I don't want to treat sequences and mappings as the same thing. I'm talking a

Re: Can't get around "IndexError: list index out of range"

2006-10-08 Thread MonkeeSage
On Oct 8, 3:05 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > No: you are proposing to add features to the sequence interface for > which there are few demonstrable use cases. If I really wanted to find them, how many instances do you think I could find [in the standard lib and community-respected

Re: Can't get around "IndexError: list index out of range"

2006-10-09 Thread MonkeeSage
On Oct 9, 2:31 am, Steve Holden <[EMAIL PROTECTED]> wrote: > Keep right on guessing. I hope I'm not offending one whom I consider to be much more skilled and versed than I am, not only in python, but in programming in general; but I must say: it seems you are being rather obtuse here. I think I l

Re: Can't get around "IndexError: list index out of range"

2006-10-10 Thread MonkeeSage
On Oct 10, 1:57 am, Steve Holden <[EMAIL PROTECTED]> wrote: > I think we'll just have to agree to differ in this repsecrt, as I don't > see your suggestions for extending the sequence API as particularly > helpful. No worries. :) On Oct 10, 11:22 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > s

Re: how do you get the name of a dictionary?

2006-09-08 Thread MonkeeSage
Simon Brunning wrote: > It's not inconcevable that Python could behave that way, it's just > that it would impose an overhead on the 99.999% of Python users who > would have no use for the feature. It's a price not worth paying. I guess I don't get the problem with the OP's request, either. There

Re: how do you get the name of a dictionary?

2006-09-08 Thread MonkeeSage
Simon Brunning wrote: > On 8 Sep 2006 02:24:49 -0700, MonkeeSage <[EMAIL PROTECTED]> wrote: > > I guess I don't get the problem with the OP's request, either. There is > > already a name<->identifier mapping in place for objects. > > Do you mean a name

Re: best split tokens?

2006-09-08 Thread MonkeeSage
John Machin wrote: > Not picking on Tim in particular; try the following with *all* > suggestions so far: > > textbox = "He was wont to be alarmed/amused by answers that won't work" Not perfect, but would work for many cases: s = "He was wont to be alarmed/amused by answers that won't work" r = r

Re: convert loop to list comprehension

2006-09-08 Thread MonkeeSage
[EMAIL PROTECTED] wrote: > Cool ... and damn but you guys are fast with the answers. This appears > to work find, but in a quick and dirty test it appears that the [list] > version takes about 2x as long to run as the original loop. Is this > normal? You could also do it 'functionally' with map(),

Re: convert loop to list comprehension

2006-09-08 Thread MonkeeSage
Paul Rubin wrote: > "MonkeeSage" <[EMAIL PROTECTED]> writes: > > Ps. I don't know if xrange is faster...I thought the difference was > > that range created a temporary variable holding a range object and > > xrange created an iterator? > > There'

Re: how do you get the name of a dictionary?

2006-09-08 Thread MonkeeSage
Dennis Lee Bieber wrote: > id() returns, in C based Python, the memory address at which an > object is stored. That is all... Names in Python are mapped to the > object -- essentially they are mapped to the address of the object. > There is NO intermediate hidden identifier. > > [snip] > > Ob

Re: How to get the "longest possible" match with Python's RE module?

2006-09-11 Thread MonkeeSage
Licheng Fang wrote: > Basically, the problem is this: > > >>> p = re.compile("do|dolittle") > >>> p.match("dolittle").group() > 'do' >From what I understand, this isn't python specific, it is the expected behavior of that pattern in any implementation. You are using alternation, which means "eithe

Re: How to get the "longest possible" match with Python's RE module?

2006-09-11 Thread MonkeeSage
Licheng Fang wrote: > Hi, according to these regexp engine discussions, it's NOT a behavior > true to any implementation. > [snip] Well, I just double-checked in ruby (oniguruma regexp engine): r = Regexp.new("do|dolittle") puts r.match("dolittle")[0] # do r = Regexp.new("one(self)?(sufficient)?

Re: How to get the "longest possible" match with Python's RE module?

2006-09-11 Thread MonkeeSage
MonkeeSage wrote: > So, it seems they are all broken, or python is correct as well. Aha, sorry about that Licheng (re: Tim's post). I guess "broken" depends on if you are expecting perl-compatible behavior or otherwise. I have my own scripts I use to do (f)grep and sed-lik

Re: How to get the "longest possible" match with Python's RE module?

2006-09-11 Thread MonkeeSage
Licheng Fang wrote: > Oh, please do have a look at the second link I've posted. There's a > table comparing the regexp engines. The engines you've tested probably > all use an NFA implementation. Sorry! *blush* I admit I skipped over your links. I'll have a look now. BTW, just an idea that may or

Re: How to get the "longest possible" match with Python's RE module?

2006-09-11 Thread MonkeeSage
Or mabye something like this is better: def matcher(string, pattern): out = '' for match in re.findall(r'\S*%s\S*' % pattern, string): if (len(match) >= len(out)): out = match return out p1 = 'dodad donkeykong dolittle dodaday' p2 = 'oneself self-serving selfsufficient oneselfsuff

Re: Is it just me, or is Sqlite3 goofy?

2006-09-12 Thread MonkeeSage
[EMAIL PROTECTED] wrote: > But it was stated in the sqlite docs that ALL SQL databases > use static types implying that sqlite will be incompatible > with any "heavy" database should the need arise to migrate > upwards. The issue is not that there will be compatibilty > problems with any data migra

Re: SQLwaterheadretard3 (Was: Is it just me, or is Sqlite3 goofy?)

2006-09-12 Thread MonkeeSage
Oops! Sorry for the top-post! -- http://mail.python.org/mailman/listinfo/python-list

Re: add without carry

2006-09-15 Thread MonkeeSage
Hugh wrote: > Sorry, here's an example... > > 5+7=12 > > added without carrying, 5+7=2 > > i.e the result is always less than 10 def add(a, b, c=10): an = a + b if an >= c: an -= c return an add(5, 7) # = 2 ? Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding dynamic libraries

2006-09-15 Thread MonkeeSage
Bill Spotz wrote: > Is there a way to tell an executing python script where to look for > dynamically-loaded libraries? If I understand, you want to tell an already running python process to import some extensions from arbitrary locations? If that is correct, you could use a file to hold the dynam

Re: Finding dynamic libraries

2006-09-17 Thread MonkeeSage
Robert Kern wrote: > No, his extensions link against other shared libraries which are not Python > extensions. Those shared libraries are in nonstandard locations because he is > running his tests before installing the libraries and his Python code. In that case, couldn't it be done by placing a c

Re: Finding dynamic libraries

2006-09-17 Thread MonkeeSage
Robert Kern wrote: > It depends on the OS. Most Linux systems do not. Hmm. Looks like 'man dlopen' confirms that (on my box anyway). It looks like the working directory is never searched at all (unless it is explicitly listed somewhere). Bummer. What about using ldconfig -l? Regards, Jordan --

Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread MonkeeSage
Ilias Lazaridis wrote: > How do I do this? It's easy: def writeDebug(msg): print "I do not debug things, I _evaluate_ with professionals on the industries! See ticket 547!\n" \ "Oh yeah, and %s" % msg ... class Foo: writeDebug("how can I configure the interpreter for understand Klingo

Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-19 Thread MonkeeSage
Ilias Lazaridis wrote: > where do I place this function... The place where you want it to be. > ...thus it becomes available within class "Foo" and all other Classes? Anything defined in the top-level (i.e., the sys.modules['__main__'] namespace) is accessible in every scope...but I assume you a

Re: Curious issue with simple code

2006-09-19 Thread MonkeeSage
codefire wrote: > As above it all works as expected. However, on the marked line, if I > use f instead of fp then that condition returns false! Surely, > isfile(f) should return true, even if I just give a filename, rather > than the full path? Hi Tony, Actually the file is in a different directo

Re: newbe's re question

2006-09-19 Thread MonkeeSage
Hi Eric, Don't let people offput you from learning python. It's a great language, and is fun to use. But really, George does have a point -- if you want to learn python, then the best way is to swim with the tide rather than against it. But still, don't worry too much about being pythonic and what

Re: include statement

2006-09-19 Thread MonkeeSage
[EMAIL PROTECTED] wrote: > Hello, > > is it possible in python to include another python source file into the > current namespace, i.e.completely analogous to the #include statement > in C. > > Regards Joakim from blah import * # where blah is a blah.py file in sys.path Also see: http://pyref.in

Re: byte count unicode string

2006-09-20 Thread MonkeeSage
John Machin wrote: > The answer is, "You can't", and the rationale would have to be that > nobody thought of a use case for counting the length of the UTF-8 form > but not creating the UTF-8 form. What is your use case? Playing DA here, what if you need to send the byte-count on a server via a he

Re: new string method in 2.5 (partition)

2006-09-20 Thread MonkeeSage
s = "There should be one -- and preferably only one -- obvious way to do it".partition('only one') print s[0]+'more than one'+s[2] ;) Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: byte count unicode string

2006-09-20 Thread MonkeeSage
OK, so the devil always loses. ;P Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: CONSTRUCT - Adding Functionality to the Overall System

2006-09-20 Thread MonkeeSage
Ilias Lazaridis wrote: > no, I don't know it. OK...so how do you evaluate a language when you don't know its basic operations? Hmmm, sounds fishy. > how do I define something into the top-level namespace? I assume I > could place it into the root-package of my project, into the __init__ > functio

Re: Is it possible to save a running program and reload next time ?

2006-09-21 Thread MonkeeSage
[EMAIL PROTECTED] wrote: > Is it possible that the program can save all running data to a file when > I want it to stop, and can reload the data and continue to run from > where it stops when the computer is free ? This isn't what you asked for (I have no idea how to do that), but given your descr

Re: Evaluation of Truth Curiosity

2006-09-21 Thread MonkeeSage
James Stroud wrote: > What is the logic of the former expression not evaluating to True (or > why the latter not 1?)? Is there some logic that necessitates the first > operand's dictating the result of the evaluation? Or is this an artefact > of the CPython implementation? If I understand correctl

Re: Can I inherit member variables?

2006-09-21 Thread MonkeeSage
[EMAIL PROTECTED] wrote: > When I run my code from within the derived class, self.weight > and self.colour are not inherited (although methods are inherited as I > would have expected). Animal is never initialized and you're not passing weight and color into it anyway. You need something like:

Re: Can I inherit member variables?

2006-09-21 Thread MonkeeSage
Hi Lorcan, Mabye thinking of it like this will help: birds and fishes (I love that word, even if it is incorrect) can _do_ all the things that all animals have in common: eat, drink, die, reproduce, &c; but that is generic. class animal(object): def eat(self, food): pass ... class bird(animal

Re: Can I inherit member variables?

2006-09-21 Thread MonkeeSage
[EMAIL PROTECTED] wrote: > If you have multiple inheritance do you need the old style init anyway? I guess so, I'm not really sure. This page talks about super() and MRO and such, but I have only glanced over it the other day. I will read it more fully sometime. I

Re: Can I inherit member variables?

2006-09-21 Thread MonkeeSage
Ps. Aristotle can rest easy tonight: class mortal(object): pass class man(mortal): pass Socrates = man() all_men = mortal() if Socrates == all_men: print "Socrates == all_man" else: print "Undistributed Middle is indeed a fallacy" ;) Regards, Jordan -- http://mail.python.org/mailman/listi

Re: Does Python provide "Struct" data structure?

2006-09-22 Thread MonkeeSage
Hi Daniel, To avoid problems you could vendor the ipython file you require, but an easier solution may just be to implement your own version of the class (it's extreemly easy): class struct(): def __init__(self, *args, **kwargs): for k, v in kwargs.items(): setattr(self, k, v) mystru

Re: Isn't bool __invert__ behaviour "strange"?

2006-09-22 Thread MonkeeSage
Hi Saizan, I don't really see anything wrong with creating a custom class for evaluating those kinds of logical statements. It does make the code for statements more concise and easy to follow (with less binding ambiguity). Mabye something like this would help: class logic(int): def __sub__(sel

Re: Python Input from keyboard

2006-09-22 Thread MonkeeSage
utab wrote: > I want to read some input continuously from keyboard and then I would > like to process these input. > > I have a code like this but getting errors, I would like to terminate > when there is an empty string in the input, why is not this easy as the > "cin" or "scanf". I had to search

Re: Isn't bool __invert__ behaviour "strange"?

2006-09-23 Thread MonkeeSage
Steve Holden wrote: > Is this a serious suggestion, or simply an attempt at sardonic obscurantism? Well, I was being serious, but now I'm afraid to see what kind of evils I've acidentally stepped in, heh!? I honestly don't see anything wrong with creating a DSL for a given problem domain. Where di

Re: grabbing random words

2006-09-23 Thread MonkeeSage
Another approach would be to just scrape a CS's random (5.75 x 10^30) word haiku generator. ;) import urllib import libxml2 import random uri = 'http://www.cs.indiana.edu/cgi-bin/haiku' sock = urllib.urlopen(uri) data = sock.read() sock.close() doc = libxml2.htmlParseDoc(data, None) words

Re: Isn't bool __invert__ behaviour "strange"?

2006-09-23 Thread MonkeeSage
Lawrence D'Oliveiro wrote: > In message <[EMAIL PROTECTED]>, > MonkeeSage wrote: > > > I don't really see anything wrong with creating a custom class for > > evaluating those kinds of logical statements. It does make the code for > > statements more co

Re: Isn't bool __invert__ behaviour "strange"?

2006-09-23 Thread MonkeeSage
MonkeeSage wrote: > > Why not express everything in Conjunctive Normal Form? > > [snip] Oh, you meant the actual form. Duh! Yeah, that would work. For some reason I was thinking you were asking why I didn't implement the standard symbols, sorry. Regards, Jordan -- http:

Re: Isn't bool __invert__ behaviour "strange"?

2006-09-23 Thread MonkeeSage
Bjoern Schliessmann wrote: > Lawrence D'Oliveiro wrote: > > > Which is why C++ allows "not", "and" and "or". > > Is this standards compliant? My reference (book) doesn't contain it, > but g++ allows it. "The C++ standard provides _operator keywords_ (Fig. 21.8) that can be used in place of several

Re: Need compile python code

2006-09-23 Thread MonkeeSage
mistral wrote: > Just to comple python ode - it creates html page, nothing more, nothing > else.. Just generate one html page. I *think* this is what you want: python -O -m py_compile file.py python file.pyo See: http://docs.python.org/lib/module-pycompile.html Regards, Jordan -- http://mail.

Re: Need compile python code

2006-09-23 Thread MonkeeSage
mistral wrote: > this not work for me, show compilation error. Is there simple way > compile pythone file? its absolutely unclear with command line. Just > show me exact command I need run(from python interactive shell?) OK... # cd to where the file.py is $ cd /some/dir # start python interacti

Re: Need compile python code

2006-09-23 Thread MonkeeSage
MonkeeSage wrote: > >>> import py_compile > >>> py_compiler.compile('file.py') ^^^ Should be: >>> py_compile.compile('file.py') -- http://mail.python.org/mailman/listinfo/python-list

Re: Need compile python code

2006-09-23 Thread MonkeeSage
mistral wrote: > No, something is wrong there. what I need is just compile one python > file which will generate html page, with parameters: > "exec" "python" "-O" "$0" "$@" > > just need simple way do this(script is correct), i will not set any > patches anywhere, can i do this wrom normal GUI?

Re: webbrowser module's Firefox support

2006-09-23 Thread MonkeeSage
Dustan wrote: > I did do a search here, but came up empty-handed. Can anyone tell me > how to get the webbrowser module to recognize firefox's existence, > given this information? Looks like it is checking %PATH% for firefox.exe. Try: >>> import os >>> os.environ["PATH"] = r"C:\Program Files\Mozi

Re: webbrowser module's Firefox support

2006-09-23 Thread MonkeeSage
Dustan wrote: > >>> cont=webbrowser._browsers['firefox'][1] Why not use the api? cont=webbrowser.get('firefox') > ValueError: close_fds is not supported on Windows platforms > > Looking in the docs on subprocess.Popopen > (http://docs.python.org/lib/node529.html), it says "If close_fds is > true,

Re: Isn't bool __invert__ behaviour "strange"?

2006-09-23 Thread MonkeeSage
Bjoern Schliessmann wrote: > Thanks. Only if I'd known that earlier ;) NP. I had to look it up 'cause I'd never seen them used either. Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: webbrowser module's Firefox support

2006-09-23 Thread MonkeeSage
Dustan wrote: > That didn't work either. Well, I'm out of ideas. It's also odd that it was being read as webbrowser.BackgroundBrowser...whatever that is! It should have been webbrowser.Mozilla. > Another thing: your fix is only temporary. Is there a way to make it > work even after I close IDLE?

Re: grabbing random words

2006-09-24 Thread MonkeeSage
Steven D'Aprano wrote: > That isn't 5.75e30 words, it is the number of possible haikus. There > aren't that many words in all human languages combined. Doh! This is why _I'm_ not a computer scientist. I'm kinda slow. ;) > (Note however that there are languages like Finnish which allow you to > st

Re: HTTP GET Explodes...

2006-09-24 Thread MonkeeSage
Pete wrote: > So, I looked at my search path under the account that was experiencing > the problem. That wasn't it... Then I'm thinking there's an > environmental variable causing this. Too many to work right now. Will > investigate later. You can see all environment variables with the declare com

Re: gtk.Entry Colors

2006-09-24 Thread MonkeeSage
Tuomas wrote: > I would like to manipulate PyGTK Entry widget's background and > foreground colors. Is it possible? How? Yes, it is possible: # widget color entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse("#FF")) # frame color entry.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("#00

Re: ruby %w equivalent

2006-09-24 Thread MonkeeSage
Tim Chase wrote: > to give it that perl/ruby-ish feel of terseness and obscurity. Don't feel bad, you always have things like r'%s\%s' % (u'blah', u'blah') and so on. But of course, it's only the other guys who are evil / ugly / stupid. As the human torch says, "Flame On". :) [Full disclosure: I

Re: gtk.Entry Colors

2006-09-25 Thread MonkeeSage
Tuomas wrote: > Yes, I read the reference before posting here. I tried something like: Hi Tuomas, I didn't mean to say that you hadn't read the docs (I had a hard time finding the right methods in the docs too, even though I know the methods); I just wanted to give you the references so you could

Re: Emphasizing a gtk.Label

2006-09-25 Thread MonkeeSage
ravenheart wrote: > What would be the best solution? How to do it? I have found how to > change colors and underscoring but nothing else. I don't know about the best, but I would use: label = gtk.Label() # Pango markup should be on by default, if not use this line #label.set_use_markup(True) labe

Re: ruby %w equivalent

2006-09-25 Thread MonkeeSage
hg wrote: > Why would they want to make such an obscure API ? ... didn't they have > Python to learn from (I am truly amazed - nothing cynical ...just ... > why ?) In ruby there are several special literal notations, just like python. In ruby it goes like this: %{blah} / %Q{blah} # same as "b

Re: ruby %w equivalent

2006-09-25 Thread MonkeeSage
hg wrote: > But today ? what is the cost of replacing %w("blah blah") by > Hi_I_Want_To_Split_The_String_That_Follows( "blah blah") How about r'blah', u'blah', """blah""", and '''blah'''. :) Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: Survival of the fittest

2006-09-26 Thread MonkeeSage
James Stroud wrote: > Out of curiosity, what are these features that ruby has that python > lacks. I've always wondered whether I should look at ruby--whether, as a > language, it has anything to teach me that say python, C, and Java don't > (LISP/Scheme is on my short-list to learn.) Just a guess

Re: Questions on Using Python to Teach Data Structures and Algorithms

2006-09-28 Thread MonkeeSage
Bruno Desthuilliers wrote: > Brendon Towle wrote: > > Some of your Lisp translations are subtly off... > > Seems correct to me. Lisp lists are linked lists, not arrays. Actually, Brendon was correct. In lisp / scheme: (cons 1 '(2 3)) -> (1 2 3) (car '(1 2 3)) -> 1 (cdr '(1 2 3)) -> (2 3) But Bre

Re: Resuming a program's execution after correcting error

2006-09-28 Thread MonkeeSage
Georg Brandl wrote: > As I said before, this can be done by finding out where the error is raised, > what the cause is and by inserting an appropriate try-except-statement in > the code. I could be mistaken, but I *think* the OP is asking how to re-enter the stack at the same point as the exceptio

Re: Questions on Using Python to Teach Data Structures and Algorithms

2006-09-28 Thread MonkeeSage
sturlamolden wrote: > Thus I stand by my original claim. Essentlially: > > def cons(car,cdr): return (car,cdr) # or [car,cdr] > def car(cons): return cons[0] > def cdr(cons): return cons[1] I guess you were talking about implementing the _structure_ of lisp lists in python syntax (as you seem to i

Re: Can string formatting be used to convert an integer to its binary form ?

2006-09-28 Thread MonkeeSage
So far as unobfuscated versions go, how about the simple: def to_bin(x): out = [] while x > 0: out.insert(0, str(x % 2)) x = x / 2 return ''.join(out) Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: Questions on Using Python to Teach Data Structures and Algorithms

2006-09-28 Thread MonkeeSage
Dennis Lee Bieber wrote: > Though if this suddenly inspires the creation of a Common LISP > interpreter written in Python, I may want to close my eyes Hehe! I actually thought of trying that once, but I realized that I'm too stupid and / or lazy to pull it off. ;) Regards, Jordan -- http

Re: Can string formatting be used to convert an integer to its binary form ?

2006-09-28 Thread MonkeeSage
Steve Holden wrote: > >>> to_bin(0) > '' Doh! Oh, yeah...that! ;) OK... def to_bin(x): out=[] while x > 0: out.insert(0, str(x % 2)) x /= 2 else: out.append(str(x)) return ''.join(out) Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: retry in exception

2006-09-29 Thread MonkeeSage
Sybren Stuvel wrote: > Antoine De Groote enlightened us with: > > I hope I don't upset anybody by comparing Python to Ruby (again). Is > > there something like Ruby's retry keyword in Python? > > Please don't assume that everybody knows Ruby through and through... In ruby, the equivalent to try...

Re: retry in exception

2006-09-29 Thread MonkeeSage
Everyone wrote: > [cool stuff] Ps. I've only used retry a handful of times in about 3 or 4 years of using ruby; I wasn't advocating it or criticizing python, just trying to explain the OPs request. Regards, Jordan -- http://mail.python.org/mailman/listinfo/python-list

Re: storing variable names in a list before they are used?

2006-09-29 Thread MonkeeSage
John Salerno wrote: > If I want to have a list like this: > > [(first_name, 'First Name:'), (last_name, 'Last Name:').] Do you need the data to be ordered? If not, just use a dictionary: d = {'First Name:': '', 'Last Name:': ''} d['First Name:'] = 'Bob' d['Last Name:'] = 'Smith' print "Hi, I

Re: DAT file compilation

2006-09-29 Thread MonkeeSage
Jay wrote: > Is there a way through python that I can take a few graphics and/or > sounds and combine them into a single .dat file? If so, how? And how > can I access the data in the .dat file from inside the python script? How about in a sqlite database? Sqlite has built-in bindings in python 2

Re: File I/O

2006-09-30 Thread MonkeeSage
Diez B. Roggisch wrote: > Good to know that you can get drunk under any circumstances. +(++)1 heh! > I have seen a bazillion bad xml/html parsing-hacks using regexes and the > like, which stopped working after somehow the xml came all in one line, or > some other implicit assumption about its lay

Re: The Python world tries to be polite [formerly offensive to another language]

2006-09-30 Thread MonkeeSage
Steve Holden wrote: > Perhaps so, but none the less comp.lang.perl has a demonstrable history > of newbie-flaming. Don't know what it's like now, as it's years since I > read that group, but they used to just love the smell of crisply-toasted > newbie in the morning ;-) C'mon! No reason why a newb

Re: Hot new programming languages - according to the TIOBE index

2006-09-30 Thread MonkeeSage
vasudevram wrote: > Ruby and Python are doing well, according to the latest TIOBE index. Doing well?? Ruby is up 14 points, relatively...ghea! ruby p0wns!11 ;) D is an interesting language, though, I must say. Looks like they did all the things right that C++ did wrong. Regards, Jordan -- http

Re: for: else: - any practical uses for the else clause?

2006-09-30 Thread MonkeeSage
Sybren Stuvel wrote: > I must say that the for/else construct is a LOT more readable than the > rewritten alternatives. +1 I just wish it had a more intuitive name like "after:" or "then:", as "else:" seems like a choice between the loop and the other block (but really the choice is between StopI

Re: Hot new programming languages - according to the TIOBE index

2006-09-30 Thread MonkeeSage
MonkeeSage wrote: > vasudevram wrote: > > Ruby and Python are doing well, according to the latest TIOBE index. > > Doing well?? Ruby is up 14 points, relatively...ghea! ruby p0wns!11 ;) Sorry my fellow pythonistas! I didn't see that this was cross-posted. I was of course being

Re: ruby %w equivalent

2006-09-30 Thread MonkeeSage
Nick Craig-Wood wrote: > These are snatched straight from perl. In perl they are spelt > slightly differently Yup, they are; perl had _some_ good ideas; no doubt. ;) > In perl (and maybe in ruby I don't know) the { } can be replaced with > any two identical chars, or the matching pair if bracket

  1   2   3   >