Re: Determining actual elapsed (wall-clock) time

2005-07-02 Thread Roy Smith
Peter Hansen <[EMAIL PROTECTED]> wrote: > I would like to determine the "actual" elapsed time of an operation > which could take place during a time change, in a platform-independent > manner (at least across Linux/Windows machines). > > Using time.time() doesn't appear to be suitable, since tim

Re: Determining actual elapsed (wall-clock) time

2005-07-02 Thread Roy Smith
Peter Hansen <[EMAIL PROTECTED]> wrote: > I guess as long as the NTP client is set up to ensure the time > adjustments are smaller than some value X, it would be acceptable. NTP is generally capable of keeping the various system clocks on a LAN within a few ms of each other, and within a few 10'

Re: Python for everything?

2005-07-02 Thread Roy Smith
Christos "TZOTZIOY" Georgiou <[EMAIL PROTECTED]> wrote: > Were there other Unix C compilers before K&R wrote one? Considering that K&R (along with T) invented both Unix and C, I would say that the answer to the above has to be "No". -- http://mail.python.org/mailman/listinfo/python-list

Re: need to get an index for an item in a list

2005-07-03 Thread Roy Smith
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote: > hey there, > i need to be able to get the index for an item in a list. > the list is a list of lines read from a text file. > > like this: > > file = open("/home/somefile.text", "r") > lines = file.readlines() > file.close() > > now, i

Re: need to get an index for an item in a list

2005-07-03 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Peter Hansen <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > i need to be able to get the index for an item in a list. > > > any ideas? > > Fire up the interactive interpreter and learn to use it to help > yourself. In this case, the most useful thing

Re: looping over a big file

2005-07-03 Thread Roy Smith
"martian" <[EMAIL PROTECTED]> wrote: > 1) how does python handle: > > > for line in big_file: > > is big_file all read into memory or one line is read at a time or a buffer > is used or ...? The "right" way to do this is: for line in file ("filename"): whatever The file object returned by f

Re: looping over a big file

2005-07-03 Thread Roy Smith
Jp Calderone <[EMAIL PROTECTED]> wrote: > Yes, but you need to do it like this: > > fileIter = iter(big_file) > for line in fileIter: > line_after = fileIter.next() That's better than the solution I posted. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do you program in Python?

2005-07-04 Thread Roy Smith
bruno modulix <[EMAIL PROTECTED]> wrote: > Try Emacs + python-mode. Emacs surely has a lot of warts, but I'm still > looking for a better and more versatile code editor/IDE - specially when > it comes to languages with REPL (-> Read-Eval-Print Loop). When you build Python, make sure you build it

Re: Determining actual elapsed (wall-clock) time

2005-07-04 Thread Roy Smith
Peter Hansen <[EMAIL PROTECTED]> wrote: > As it turns out, Windows XP already has support (via NTP > I presume, though of course since this is Microsoft they try to keep the > user base ignorant by making no mention of that even in the help page) > for keeping the clock accurate, right on the la

Re: Existance of of variable

2005-07-04 Thread Roy Smith
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > Should we *really* be encouraging newbies to mess with globals() and > locals()? Isn't that giving them the tools to shoot their foot off before > teaching them how to put shoes on? Why risk damaging perfectly good footwear? But, seriously, I agree wit

Re: Use cases for del

2005-07-08 Thread Roy Smith
Daniel Dittmar <[EMAIL PROTECTED]> wrote: > In a SQL database, NULL = NULL will always return NULL, which is prety > much the same as FALSE. Except for NOT, AS NOT NULL is NULL. SQL's NULL is very much akin to the IEEE NaN (not quite, but close). -- http://mail.python.org/mailman/listinfo/pytho

Re: Should I use "if" or "try" (as a matter of speed)?

2005-07-09 Thread Roy Smith
Steve Juranich <[EMAIL PROTECTED]> wrote: > Without fail, when I start talking with some of the "old-timers" > (people who have written code in ADA or Fortran), I hear the same > arguments that using "if" is "better" than using "try". Well, you've now got a failure. I used to write Fortran on pun

Re: Should I use "if" or "try" (as a matter of speed)?

2005-07-10 Thread Roy Smith
Thomas Lotze <[EMAIL PROTECTED]> wrote: > Basically, I agree with the "make it run, make it right, make it fast" > attitude. However, FWIW, I sometimes can't resist optimizing routines that > probably don't strictly need it. Not only does the resulting code run > faster, but it is usually also shor

Re: Should I use "if" or "try" (as a matter of speed)?

2005-07-10 Thread Roy Smith
[EMAIL PROTECTED] (Aahz) wrote: > Using ``in`` saves a bytecode of method lookup on ``has_key()`` (which is > the correct spelling). You are right. My example is somewhat out of date w/r/t newer language features, and writing hasKey() instead of has_key() was just plain a mistake. Thanks for t

Re: Fwd: Should I use "if" or "try" (as a matter of speed)?

2005-07-12 Thread Roy Smith
Christopher Subich <[EMAIL PROTECTED]> wrote: >try: >f = file('file_here') >do_setup_code >do_stuff_with(f) >except IOError: # File doesn't exist >error_handle It's also a good idea to keep try blocks as small as possible, so you know exactly where the error happened. Imagine if

Re: return None

2005-07-22 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Ximo <[EMAIL PROTECTED]> wrote: >Can I do a function which don't return anything? > >The question is that, if I do a function that have a return or without >return, it returns always "None", but i want that it doesnt return me >nothing What do you mean by "don't r

Need to understand python license

2005-07-27 Thread Roy Smith
I'm looking into the possibility of getting my employer to use Python as an embedded scripting language. A big issue is licensing; we can't use anything that's GPL-like, because that would make us release our source code. Obviously, our lawyers will have the final say, but I'm looking for a rough

Re: Need to understand python license

2005-07-27 Thread Roy Smith
Benji York wrote: > > See http://wiki.python.org/moin/PythonSoftwareFoundationLicenseFaq > Thanks, that's exactly what I needed. -- http://mail.python.org/mailman/listinfo/python-list

Re: The ONLY thing that prevents me from using Python

2005-08-05 Thread Roy Smith
Kevin <[EMAIL PROTECTED]> wrote: >The problem is that it's difficult to find hosting services with Python >installed and supported. I just googled for ["web hosting" python] and got 1,250,000 hits. I can personally recommend panix.com, but there's plenty of other choices too. -- http://mail.pyth

Re: Python -- (just) a successful experiment?

2005-08-07 Thread Roy Smith
"Paul Boddie" <[EMAIL PROTECTED]> wrote: > Perl had the "cool tool" buzz a good ten years ago. That's true, but I think it understates just how important a development Perl really was. Before Perl, unix scripting consisted of awk, sed, grep, tr, a random assortment of incompatible shells, and l

Bizarre error from help()

2005-08-09 Thread Roy Smith
Can anybody explain this bizarre behavior: - Roy-Smiths-Computer:play$ py Python 2.3.4 (#3, Jun 29 2004, 21:48:03) [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> help (isinstance) foos b

Re: Python supports LSP, does it?

2005-08-09 Thread Roy Smith
Andy Leszczynski writes: > Is not LSP more a quality of the desing of class hierachy rather then > language itslef? Comments? I do agree that LSP is more a class hierarchy thing than a language thing. For example, it's easy in Python to write a LSP-violating set of classes: class base: de

Re: Recommendations for CVS systems

2005-08-09 Thread Roy Smith
Mike Meyer <[EMAIL PROTECTED]> wrote: > My current client uses subversion, and I generally wind up cursing at it > at least once a day. What makes you curse at it? I've never actually used it, just been watching the project for several years. I'd be interested to hear your experiences. -- ht

Re: Recommendations for CVS systems

2005-08-09 Thread Roy Smith
Mike Meyer <[EMAIL PROTECTED]> wrote: > Well, the only thing that subversion does that I'd call bad is leave > turds in my development directory. I'm tired of having to tell > commands to ignore .svn files. Of course, Perforce is the only source > control system I know of that doesn't do this. My

Re: Bizarre error from help()

2005-08-09 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "Delaney, Timothy (Tim)" <[EMAIL PROTECTED]> wrote: > Roy Smith wrote: > > > Traceback (most recent call last): > > File "", line 1, in ? > > File "/usr/local/lib/python2.3/site.py", lin

Re: Bizarre error from help()

2005-08-09 Thread Roy Smith
Roy Smith <[EMAIL PROTECTED]> wrote: > No, that works fine. But, now I can't even reproduce the error I reported > earlier (when I try, I get the help message as expected). And, yes, that > was with a brand new interpreter session. Strange. I got it now! Oh, this i

Re: What is Python?!

2005-08-10 Thread Roy Smith
Robert Wierschke <[EMAIL PROTECTED]> wrote: > a scripting language or a "normal" language like C++ etc. It is difficult to define exactly what a "scripting language" is and isn't, but I think most people would classify it as a scripting language. > So please tell me what python is, what ar

Re: PEP 328, absolute/relative import (was: Re: Bizarre error from help())

2005-08-10 Thread Roy Smith
Ben Finney <[EMAIL PROTECTED]> wrote: > Once PEP 328 is fully implemented, all bare 'import foo' statements > specify absolute imports (i.e. from sys.path only). To perform a > relative import (e.g. from current directory) will require different > syntax. It seems like this will break lots of exis

Re: What is Python?!

2005-08-10 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "Jason Drew" <[EMAIL PROTECTED]> wrote: > Roy Smith wrote: "there's a system called Jython, which lets you > compile Java source to Python byte code." > > Don't you have that the wrong way 'round?

Re: How do these Java concepts translate to Python?

2005-08-12 Thread Roy Smith
"Ray" <[EMAIL PROTECTED]> wrote: > I've been learning Python in my sparetime. I'm a Java/C++ programmer by > trade. So I've been reading about Python OO, and I have a few questions > that I haven't found the answers for :) > > 1. Where are the access specifiers? (public, protected, private) Quick

Re: Binary Trees in Python

2005-08-20 Thread Roy Smith
In article <[EMAIL PROTECTED]>, [diegueus9] Diego Andrés Sanabria <[EMAIL PROTECTED]> wrote: > Hello!!! > > I want know if python have binary trees and more? Python does not come with a tree data structure. The basic data structures in Python are lists, tuples, and dicts (hash tables). Peopl

Re: trictionary?

2005-08-28 Thread Roy Smith
Steven Bethard <[EMAIL PROTECTED]> wrote: > In Python, pairs are usually handled with tuples[2], but tuples would be > inconvenient in this case, since the first value must be modified. Instead of modifying the tuple (which you can't do), you can create a new one: a, b = myDict[key] myDict[key]

Re: how to join two Dictionary together?

2005-08-30 Thread Roy Smith
In article <[EMAIL PROTECTED]>, DENG <[EMAIL PROTECTED]> wrote: > >dict1={...something...} > >dict2={...somethind else ..} > >dict1 + dict2 > > >that's does works ..:(, it's not like List... > > >anyone can tell me how to get it? > >thanks in advance First, you have to tell us what you want to hap

Re: Python versus Perl

2005-09-10 Thread Roy Smith
Dieter Vanderelst <[EMAIL PROTECTED]> wrote: > 1 - How does the speed of execution of Perl compares to that of Python? To a first-order approximation, Perl and Python run at the same speed. They are both interpreted languages with roughly the same kind of control flow and data structures. The

Re: No newline using printf

2005-09-15 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "Samuel" <[EMAIL PROTECTED]> wrote: > How can I print a word without appending a newline character? Appending > a "," to the print statement only substitutes the newline for a space, > which is not what I am looking for. For closer control over output, use the wr

Re: Python versus Perl ?

2005-02-06 Thread Roy Smith
"EP" <[EMAIL PROTECTED]> wrote: > There are very very few cases where anyone is going to require > you to use Python Conversely, it pays to understand when you are likely to be permitted to use it (or any new technology), and when you are likely to be forbidden. Companies are generally the most

Re: Is Python as capable as Perl for sysadmin work?

2005-02-08 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "John M. Gabriele" <[EMAIL PROTECTED]> wrote: > I recently posted this sort of question to the c.l.p.m but > didn't get much of a response. I know a little Perl and a > little Python, but master neither at the moment. > > I see that Python is a general purpose OO

Re: Loop in list.

2005-02-08 Thread Roy Smith
Jim <[EMAIL PROTECTED]> wrote: >Where did this type of structure come from: > >mat = ['a' for i in range(3)]? > >This will produce a list of three elements but >I don't see reference for it in any of the books. It's a list comprehension. Unfortunately, this is a bad example of one, since a mu

Re: Loop in list.

2005-02-08 Thread Roy Smith
Jim <[EMAIL PROTECTED]> wrote: > Thanks for the help. Python is somewhat mysterious to an old fortan > programer. You might appreciate http://www.python.org/doc/Humor.html#habits -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python as capable as Perl for sysadmin work?

2005-02-09 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Max M <[EMAIL PROTECTED]> wrote: > Jeff Epler wrote: > > No. > > > > Unlike Perl, Python implements only a *finite turning machine* model of > > computation. An easy way to see this limitation is in the following > > code: > > >>> 1.0 / 10.0 > > 0.100

Re: Unit Testing in Python

2005-02-10 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "rhat" <[EMAIL PROTECTED]> wrote: > Hi Everyone, > I've recently been reading some articles about unit-testing in Python > [1] [2], but I am a bit confused: where do I go to get started with > this? I tried googling for "unittest" but all I've found are some old >

Re: Why doesn't join() call str() on its arguments?

2005-02-16 Thread Roy Smith
In article <[EMAIL PROTECTED]>, David Eppstein <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Leo Breebaart <[EMAIL PROTECTED]> wrote: > > > What I can't find an explanation for is why str.join() doesn't > > automatically call str() on its arguments, so that e.g. > > str.join([1

Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Paul Moore <[EMAIL PROTECTED]> wrote: > I have a class with a read-only attribute, and I want to add a unit > test to ensure that it really *is* read-only. I can do this as > > def test_readonly(self): > """Value and multiplier must be readonly""" >

Re: Unittest - testing properties (read-only attributes)

2005-02-21 Thread Roy Smith
Paul Rubin wrote: > The example I quoted used an assignment expression inside a > lambda. The person who posted it, That was me. > and the person who followed it up > with the setattr alternative, both didn't notice that the assignment > expression wasn't valid Python

Re: Is there way to determine which class a method is bound to?

2005-02-25 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Victor Ng <[EMAIL PROTECTED]> wrote: >I'm doing some evil things in Python and I would find it useful to >determine which class a method is bound to when I'm given a method >pointer. I don't know where (or if) it's documented, but im_class seems to give you what yo

Re: Is there way to determine which class a method is bound to?

2005-02-25 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Victor Ng <[EMAIL PROTECTED]> wrote: >No - that doesn't work, im_class gives me the current class - in the >case of inheritance, I'd like to get the super class which provides >'bar'. Oh my. You said you were doing something evil, but didn't say *how* evil. What

Re: HELP: Python equivalent of UNIX command "touch"

2005-02-28 Thread Roy Smith
pekka niiranen <[EMAIL PROTECTED]> wrote: >Does anybody know Python recipe for changing the date >of the directory or files in W2K to current date and time? >In UNIX shell command "touch" does it. You want os.utime() -- http://mail.python.org/mailman/listinfo/python-list

Re: Faster way to do this...

2005-03-01 Thread Roy Smith
Harlin Seritt <[EMAIL PROTECTED]> wrote: >I've got the following code: > >nums = range(0) >for a in range(100): > nums.append(a) > >Is there a better way to have num initialized to a list of 100 >consecutive int values? Step one would be to change the first line to nums = [] which is simpler a

Re: Help- Simple recursive function to build a list

2005-03-01 Thread Roy Smith
In article <[EMAIL PROTECTED]>, actuary77 <[EMAIL PROTECTED]> wrote: > I am trying to write simple recursive function to build a list: > > > def rec(n,alist=[]): > _nl=alist[:] > print n,_nl > if n == 0: > print n,_nl > return _nl > else: > _nl=_nl

Re: Help- Recursion v. Iter Speed comparison

2005-03-02 Thread Roy Smith
actuary77 <[EMAIL PROTECTED]> wrote: > Recurse from time: 4.305942779541 seconds > > Iter from time: 0.009904632568359 seconds > > No comparison, why is recursion so slow? I believe Edouard Manet said it best, "Damn your recursion, Henri. Iteration, however complex, is always

Re: HELP: Python equivalent of UNIX command "touch"

2005-03-02 Thread Roy Smith
In article <[EMAIL PROTECTED]>, pekka niiranen <[EMAIL PROTECTED]> wrote: >Roy Smith wrote: >> pekka niiranen <[EMAIL PROTECTED]> wrote: >> >>>Does anybody know Python recipe for changing the date >>>of the directory or files in W2K to cur

Re: convert a list to a string?

2005-03-03 Thread Roy Smith
Anthony Liu <[EMAIL PROTECTED]> wrote: > Suppose I have a list > > myList = ["this", "is", "a", "sample", "list"] > > If I don't want to iterate through it and concatenate > the list elements, how do I easily convert it to a > string like > > "this is a sample list" You want: >>> myList = ["

Re: Python 2.4 removes None data type?

2005-03-04 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > I just read in the 'What's New in Python 2.4' document that the None > data type was converted to a constant: > http://python.org/doc/2.4/whatsnew/node15.html > > """ > # None is now a constant; code that binds a ne

Good variable names (Was: Re: Best way to make a list unique?)

2005-03-08 Thread Roy Smith
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > inserted = set() > res = [] > for e in listA: >if not e in inserted: >res.append(e) >inserted.add(e) > listA = res I'm going to go off on a tangent here and put in a plea for better variable naming. I'm looking at the above code

Re: Globals between modules ?

2005-03-10 Thread Roy Smith
In article <[EMAIL PROTECTED]>, PGMoscatt <[EMAIL PROTECTED]> wrote: > Does Python allow a 'global' variable that can be used between different > modules used within an app ? > > Pete You could explicitly import __main__ and use that as a global namespace (see example below). Or (perhaps a be

Re: Iterate using tuple as index

2005-03-10 Thread Roy Smith
James Stroud <[EMAIL PROTECTED]> wrote: >I would like something more like this: > >for list1_item, list2_item in (some_kind_of_expression): > do_something(list1_item, list2_item) I believe you want: for list1_item, list2_item in zip (list1, list2): blah -- http://mail.python.org/mailman/li

Re: a RegEx puzzle

2005-03-11 Thread Roy Smith
Charles Hartman <[EMAIL PROTECTED]> wrote: > I'm still shaky on some of sre's syntax. Here's the task: I've got > strings (never longer than about a dozen characters) that are > guaranteed to be made only of characters 'x' and '/'. One possibility is to cheat completely, and depending on memory

Re: a RegEx puzzle

2005-03-11 Thread Roy Smith
Charles Hartman <[EMAIL PROTECTED]> wrote: >> Hmmm. Are you, by any chance, looking for meter patterns in verse? > >Yes, of course. Ah, now it's a lot clearer. When you said you were looking for "pairs", I was thinking "pairs of numbers, representing the start and end of the string". Now that

Re: Why tuple with one item is no tuple

2005-03-15 Thread Roy Smith
Gregor Horvath <[EMAIL PROTECTED]> wrote: >Hi, > > >>>type(['1']) > > > >>>type(('1')) > > >I wonder why ('1') is no tuple You need to say ('1',). In just plain ('1'), the parens are interpreted as grouping, not as tuple creation. Depending on your point of view, this is either a "special c

Re: Python-list Digest, Vol 18, Issue 208

2005-03-15 Thread Roy Smith
Jeff Shannon <[EMAIL PROTECTED]> wrote: > >> I'd be in favor of that, unless someone can come up with a compelling > >> current use-case for octal literals. I grew up talking octal, and while I'm still more comfortable in octal than hex (newline to me is always going to be 012, not 0xA), even a

Re: Dumping an instance

2005-03-15 Thread Roy Smith
In article <[EMAIL PROTECTED]>, gf gf <[EMAIL PROTECTED]> wrote: > If I want to dump (for debugging) an instance and all > of it's member attributes, what's the simplest way? > > print myInstance > > just gives a pointer to its location in memory You need to write a str() method for the class.

Re: Writing C readable bitfield structs?

2005-03-16 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Cappy2112 <[EMAIL PROTECTED]> wrote: >there is a bitfiled mainpulator class inthe Cookbook, but I don't >understand his explanation, and the example given doesn't really show >off the features of the class. I assume you're talking about the struct module? If you gi

Re: comment out more than 1 line at once?

2004-11-30 Thread Roy Smith
Riko Wichmann <[EMAIL PROTECTED]> wrote: > I'm using emacs (with python-mode) to do most of my editing. also tried > IDLE from python already, which is nice but an old dog doesn't like to > learn new tricks :) Emacs is great for stuff like this. There's probably other ways to do it, but what I

Re: Syntax for extracting multiple items from a dictionary

2004-11-30 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "shark" <[EMAIL PROTECTED]> wrote: > row = {"fname" : "Frank", "lname" : "Jones", "city" : "Hoboken", "state" : > "Alaska"} > cols = ("city", "state") > > Is there a best-practices way to ask for an object containing only the keys > named in cols out of row? In ot

Re: How is Python designed?

2004-12-02 Thread Roy Smith
As far as I can tell, the process works like this: Guido has an idea for something he wants to do and announces it. Everybody beats him up about it. He goes ahead and does it anyway. It's a strange process, but it seems to work. -- http://mail.python.org/mailman/listinfo/python-list

Re: some pointers for a newbie

2004-12-04 Thread Roy Smith
John Evans <[EMAIL PROTECTED]> wrote: > So what i ask is, for someone who wants to dip his toe in the pond and > runs a powerbook with os x what tools, resources should I look into as > being the most useful? I'm also running OSX on a PowerBook, so I guess we're kindred spirits. To a large ext

Re: Seeking Python + Subversion hosting.

2004-12-06 Thread Roy Smith
[EMAIL PROTECTED] (Tom Locke) wrote: > Anyone know of a good hosting company that offers both server-side > Python and a subversion repository? Panix (www.panix.com) has svn and python installed on their unix hosts. You could certainly do CGI in python. Don't know if they have mod_python avail

Re: Ptyon 2.3.5 probably coming in January; get your bugs/patches reported!

2004-12-06 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "Brett C." <[EMAIL PROTECTED]> wrote: > Anthony Baxter, our ever-diligent release manager, mentioned this past week > that Python 2.3.5 will most likely come to fruition some time in January > (this is not guaranteed date). Interesting. Does that mean that 2.3

Re: better regular expression?

2004-12-06 Thread Roy Smith
"Vivek" <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to construct a regular expression using the re module that > matches for > 1. my hostname > 2. absolute from the root URLs including just "/" > 3. relative URLs. Is your goal to learn more about regexes, or to parse URLs? If the latter,

Re: Python vs. Perl

2004-12-11 Thread Roy Smith
Michael McGarry <[EMAIL PROTECTED]> wrote: > I am just starting to use Python. Does Python have all the regular > expression features of Perl? I can't vouch for "all", but the Python reference manual for the "re" module (http://docs.python.org/lib/module-re.html) says, "This module provides reg

Re: A problem with list

2004-12-13 Thread Roy Smith
<[EMAIL PROTECTED]> wrote: >but when I have Mylist in a file and I read it from the file it does >not work as I expect. ># >import string >ff=open('C:\\Robotp\\MyFile.txt','r') # read MyList from a file >MyList=ff.read() >for i in MyList: >print i >### >I will get >[ >' >a >b >c >'

Namespaces and the timeit module

2004-12-13 Thread Roy Smith
I'm playing with the timeit module, and can't figure out how to time a function call. I tried: def foo (): x = 4 return x t = timeit.Timer ("foo()") print t.timeit() and quickly figured out that the environment the timed code runs under is not what I expected: Traceback (most recent

Re: [dictionary] how to get key by item

2004-12-13 Thread Roy Smith
Skip Montanaro <[EMAIL PROTECTED]> wrote: > Roy> BTW, does Python really build the intermediate list and throw it > Roy> away after using it to initialize the dictionary, or is it smart > Roy> enough to know that it doesn't really need to build the whole list > Roy> in memory? > >

Re: lies about OOP

2004-12-14 Thread Roy Smith
Terry Reedy <[EMAIL PROTECTED]> wrote: > I did not really 'get' OOP until after learning Python. The > relatively simple but powerful user class model made more sense to > me than C++. So introducing someone to Python, where OOP is a > choice, not a mandate, is how *I* would introduce a procedura

Re: Why are tuples immutable?

2004-12-16 Thread Roy Smith
if self.lot < other.lot: return -1 if self.lot > other.lot: return 1 return 0 Then I could do something like: p1 = Property (123, 5, "Residential") ownerDict [p1] = "Roy Smith" print ownerDict [Property (123, 5)]# prints my name

Re: Why are tuples immutable?

2004-12-16 Thread Roy Smith
Max M <[EMAIL PROTECTED]> wrote: > The problem is that you don't understand what dicts are typically used > for. Because of the nonliniarity in dict lookups, dicts are used for > optimisation. To me, dicts are first and foremost used when you want a mapping relationship where the key is not a v

Re: cmp of multiple attributes (WAS: Why are tuples immutable?)

2004-12-16 Thread Roy Smith
>Roy Smith wrote: >> def __cmp__ (self, other): >> # I wish there was a less verbose way to do this! >> if self.block < other.block: >> return -1 >> if self.block > other.block: >> return 1 >>

Re: Why are tuples immutable?

2004-12-17 Thread Roy Smith
Jeff Shannon <[EMAIL PROTECTED]> wrote: > The aesthetic purity I'm referring to is that Python respects the proper > meaning of hashing, even if it doesn't force the programmer to. The > builtin objects that Python provides don't offer a __hash__() method > that fails to meet the mathematical

Re: [dictionary] how to get key by item

2004-12-14 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Skip Montanaro <[EMAIL PROTECTED]> wrote: > Egor> i know how to get item by key > ... > Egor> but i wonder how to get key by item > > Assuming your dictionary defines a one-to-one mapping, just invert it: > > >>> forward = {10 : 50, 2 : 12, 4 : 43

Re: [dictionary] how to get key by item

2004-12-14 Thread Roy Smith
"Delaney, Timothy C (Timothy)" <[EMAIL PROTECTED]> wrote: > Python will do what you tell it. Certainly it does. The problem is that sometimes what I told it to do and what I think I told it to do are two different things :-) > Using Python 2.4, the above can be rewritten as a generator expressi

Re: Namespaces and the timeit module

2004-12-14 Thread Roy Smith
[EMAIL PROTECTED] (David M. Cooke) wrote: > > It seems kind of surprising that I can't time functions. Am I just not > > seeing something obvious? > > Like the documentation for Timer? :-) > > class Timer([stmt='pass' [, setup='pass' [, timer=]]]) > > You can't use statements defined elsewhe

Re: Regular Expression

2004-12-15 Thread Roy Smith
Michael McGarry <[EMAIL PROTECTED]> wrote: > I am horrible with Regular Expressions, can anyone recommend a book on it? I just did a search on the Barnes & Noble site for "regular expression" and came up with a bunch of books. The following looks reasonable: http://search.barnesandnoble.com/bo

Re: Why are tuples immutable?

2004-12-15 Thread Roy Smith
Jp Calderone <[EMAIL PROTECTED]> wrote: > Dictionaries support mutable keys just find. What they don't >support is unhashable keys. > > For some objects, this is an important distinction: lists are >mutable but not hashable. Of course, you could subclass list to make a mutable, hashable li

Re: Why are tuples immutable?

2004-12-17 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Jeff Shannon <[EMAIL PROTECTED]> wrote: > Roy Smith wrote: > >All that's needed is to define __hash__() and __cmp__() methods which > >only look at some subset of the object's data atrributes. You can > >keep those

Re: Why are tuples immutable?

2004-12-18 Thread Roy Smith
Nick Coghlan <[EMAIL PROTECTED]> wrote: [quoting from the Reference Manual] > If a class defines mutable objects and implements a __cmp__() > or __eq__() method, it should not implement __hash__(), since the dictionary > implementation requires that a key's hash value is immutable (if the object'

Re: argument type

2004-12-28 Thread Roy Smith
"It's me" <[EMAIL PROTECTED]> wrote: > How can I tell from within a function whether a particular argument is a > sigular type, or a complex type? > ... > In C++, you would do it with function overloading. If arg1 is always simple > type, I wouldn't care what it is. But what if I *do* need to kno

Re: pyUnitPerf

2004-12-28 Thread Roy Smith
"Grig" <[EMAIL PROTECTED]> wrote: > "Problem with porting patterns/api's from java straight to python is > that most of the outcome feels unpythonic. I'll not go about my own > feelings python vs. java here now, but I just want to point out that > there's already a rather large core of hard-python

Re: Why tuples use parentheses ()'s instead of something else like <>'s?

2004-12-29 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2004-12-29, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > Tuples are defined with regards to parentheses ()'s as everyone knows. > > Except they're not. > > >>> x = 1,2,3,4 > >>> type(x) > > >>> > > Tuples

Re: Why tuples use parentheses ()'s instead of something else like <>'s?

2004-12-29 Thread Roy Smith
"John Roth" <[EMAIL PROTECTED]> wrote: > > If Python had originally been invented in a unicode world, I suppose we > > wouldn't have this problem. We'd just be using guillemots for tuples > > (and have keyboards which made it easy to type them). > > I suppose the forces of darkness will forever k

Re: Why tuples use parentheses ()'s instead of something else like <>'s?

2004-12-29 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Reinhold Birkenfeld <[EMAIL PROTECTED]> wrote: > >>+<< being an operator Looks more like a smiley for "guy wearing a bowtie" -- http://mail.python.org/mailman/listinfo/python-list

Re: Why tuples use parentheses ()'s instead of something else like <>'s?

2004-12-29 Thread Roy Smith
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Aahz) wrote: > In article <[EMAIL PROTECTED]>, > Roy Smith <[EMAIL PROTECTED]> wrote: > >In article <[EMAIL PROTECTED]>, > > Reinhold Birkenfeld <[EMAIL PROTECTED]> wrote: > >> > &g

Re: Why tuples use parentheses ()'s instead of something else like <>'s?

2004-12-29 Thread Roy Smith
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Aahz) wrote: > In article <[EMAIL PROTECTED]>, > Roy Smith <[EMAIL PROTECTED]> wrote: > >In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Aahz) > >wrote: > >> In article <[EMAIL PROTECTED

Re: Securing a future for anonymous functions in Python

2004-12-30 Thread Roy Smith
Ian Bicking <[EMAIL PROTECTED]> wrote: > I think this specific use case -- defining callbacks -- should be > addressed, rather than proposing a solution to something that isn't > necessary. Which is to say, no one *needs* anonymous functions; people > may need things which anonymous functions p

Re: printing anomaly

2005-03-20 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Paul Rubin wrote: > What's the deal with this? > > >>> print 3.2 > 3.2 > >>> print [3.2] > [3.2002] > >>> > > Yes, I know that 3.2 isn't an exact binary fraction. I'm wondering > why it's converted diff

Re: Submission for Python Limmerick Contest

2005-03-22 Thread Roy Smith
A tuple, a dict, and a list, And whitespace which mus'n't be missed. Imported together, And stirred with a feather, Yields a language whose name must be hissed! -- http://mail.python.org/mailman/listinfo/python-list

Re: [perl-python] limericks

2005-03-26 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Andras Malatinszky <[EMAIL PROTECTED]> wrote: > Xah Lee wrote: > > Better: > > > > there is a Python, pithy > > mighty, lissome, and tabby > > algorithms it puffs > > conundrums it snuffs > > and cherished by those savvy > > > > > > there is a camel, kooky > > u

Re: Which is easier? Translating from C++ or from Java...

2005-03-28 Thread Roy Smith
In article <[EMAIL PROTECTED]>, "cjl" <[EMAIL PROTECTED]> wrote: > Hey all: > > I'm working on a 'pure' python port of some existing software. > > Implementations of what I'm trying to accomplish are available (open > source) in C++ and in Java. > > Which would be easier for me to use as a ref

Re: [Newbie] How do I get better at Python programming?

2005-03-29 Thread Roy Smith
In article <[EMAIL PROTECTED]>, Paul Rubin wrote: > Anon <[EMAIL PROTECTED]> writes: > > I'd like to get to the next level, but I'm not sure how. Are there > > any suggestions for continuing to learn? How did you guys learn? > > I'd say look at some more general comp

Re: Which is easier? Translating from C++ or from Java...

2005-03-29 Thread Roy Smith
[EMAIL PROTECTED] wrote: > There is a difference between theory and practice. You know the difference between theory and practice? Well, in theory, there is no difference :-) -- http://mail.python.org/mailman/listinfo/python-list

Re: Grouping code by indentation - feature or ******?

2005-03-29 Thread Roy Smith
Antoon Pardon <[EMAIL PROTECTED]> wrote: > 1) The stuff doesn't has to be spread over multiple pages. One >can have 2 functions, each about three quarter of a page. >The second function will then cross a page boundary. The advice "don't write a function longer than a page" is as good advic

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