Re: Question about idioms for clearing a list

2006-02-06 Thread Steven D'Aprano
he obviousness test. It also fails the introspection test: neither dir(list) nor help(list) make it easy to discover how to empty a list. In my opinion, the primary advantage for a clear() method would be that it is self-documenting. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Natural Language Date Processing.

2006-02-07 Thread Steven Bethard
Andrew Gwozdziewycz wrote: > I've been looking recently for date processing modules that can parse > dates in forms such as "next week" or "6 days from next sunday". This is, in fact, a fairly difficult problem in general. See the TERN_ competition that's currently held yearly on this task. Th

Re: Question about idioms for clearing a list

2006-02-07 Thread Steven Bethard
Ben Sizer wrote: >> Likewise, the del keyword is fundamental -- if you >> can't get, set, and del, then you need to go back to collections >> school. > > I have hardly used the del keyword in several years of coding in > Python. Why should it magically spring to mind in this occasion? > Similarly

Re: Question about idioms for clearing a list

2006-02-07 Thread Steven D'Aprano
th rage that dicts have a clear method too", then I'll just back away slooowly now. But if there are good, solid reasons for rejecting *this particular* (hypothetical) convenience method, then I'd like to hear about them, sans questions about my ability to program in Python. Thank you, -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

RE: module with __call__ defined is not callable?

2006-02-08 Thread Steven D'Aprano
hould not execute module.__call__()? I would have thought that by the duck typing principle, it shouldn't matter whether the object was a class, a module or an int, if it has a __call__ method it should be callable. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: super(...).__init__() vs Base.__init__(self)

2006-02-09 Thread Steven Bethard
Kent Johnson wrote: > Are there any best practice guidelines for when to use > super(Class, self).__init__() > vs > Base.__init__(self) > to call a base class __init__()? > [snip] > > 3. A third fix might be to change both Base and threading.Thread() to > call super(...).__init__(). This mig

Re: super(...).__init__() vs Base.__init__(self)

2006-02-09 Thread Steven Bethard
Jan Niklas Fingerle wrote: > Steven Bethard <[EMAIL PROTECTED]> wrote: >> Personally, I'd call the lack of the super calls in threading.Thread and >> Base bugs. > > It can't be a bug since it wasn't a bug before super was introduced and > you

Re: module with __call__ defined is not callable?

2006-02-10 Thread Steven D'Aprano
when you add a module to a class instance, it will do whatever the class __add__ method says. Frankly I can't think of anything useful adding two modules would do, but maybe that's my failure of imagination. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: anybody help me

2006-02-10 Thread Steven D'Aprano
e done wrong. You just have to pay attention. Fourth step: if you still can't determine the error, don't expect others to debug a 1000+ line script. Spend some time cutting the script back to the smallest possible version that still gives you the same error. This may even help you understan

Re: Too Many if Statements?

2006-02-10 Thread Steven D'Aprano
tements, the second by adding another array, but both came up with > the same system error at the command prompt level shown here: > > SystemError: com_backpatch: offset too large Is this a Python error or a shell error? If it is a Python error, perhaps you would like to post the entire trace

Re: Legality of using Fonts

2006-02-10 Thread Steven D'Aprano
("but Your Honour, I converted the TTF file into a bitmap"). Adding decorations and such merely means you have created a derivative work of the font, which the licence may not permit. I suggest that you use a font which comes under a clearly free to distribute licence, or you design your own. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: cmd

2006-02-10 Thread Steven D'Aprano
urce code to the module? Have you tried googling? Have you tried using Python's extensive introspection capabilities on the module? Failing that, do you have a specific question you would like to ask? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: arrays in python

2006-02-10 Thread Steven D'Aprano
silently overflow, raise an exception, or become a 201-digit integer? [snip] > The zeros function always gives me an error message. Oh, don't tell me, I love playing guessing games! Is it a SyntaxError? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: absolute removal of '\n' and the like

2006-02-10 Thread Steven D'Aprano
ine, not just newline, this is better still because you don't have to do any tests: s = line.rstrip() There is also a lstrip to strip leading whitespace, and strip() to strip both leading and trailing whitespace. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Legality of using Fonts

2006-02-11 Thread Steven D'Aprano
On Fri, 10 Feb 2006 20:24:34 -0800, Ross Ridge wrote: > Steven D'Aprano wrote: >> It is highly unlikely that any judge will be fooled by a mere change in >> format ("but Your Honour, I converted the TTF file into a bitmap"). > > If that were true, almost t

Re: Is python very slow compared to C

2006-02-11 Thread Steven D'Aprano
tension to solve that specific problem, while still having all the other advantages of Python. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is python very slow compared to C

2006-02-11 Thread Steven D'Aprano
n language is "very slow" on modern hardware in any meaningful sense. There are plenty of *specific tasks* which are too slow when written in one language or another, but that's not the same thing. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to check...

2006-02-11 Thread Steven D'Aprano
s=None): if goodchars is None: goodchars = string.printable for c in s: if c not in goodchars: return False return True -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Clearing the screen

2006-02-11 Thread Steven D'Aprano
4)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> print > chr(0x1b)+chr(0x5b)+chr(0x48)+chr(0x1b)+chr(0x5b)+chr(0x32)+chr(0x4a), Or even easier: print "\x1b[H\x1b[2J" which may or may not work, depending on the terminal you are using. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Clearing the screen

2006-02-11 Thread Steven D'Aprano
d you like us to guess? Because it works for me, both as a stand-alone script: $ cat clear.py magic = "\x1b[H\x1b[2J" def clear(): print magic if __name__ == "__main__": clear() $ python clear.py and also from inside Python as a module: >>> import clea

Re: Is python very slow compared to C

2006-02-12 Thread Steven D'Aprano
On Sun, 12 Feb 2006 03:03:20 -0800, bearophileHUGS wrote: > Steven D'Aprano>Very slow to do what, compared to what? The decay time > of the tau meson?< > > Probably every answer I can give you is wrong for you, so answering is > almost useless... We do actually agre

Re: Is python very slow compared to C

2006-02-12 Thread Steven D'Aprano
ore practical solution to the task even though a F-11 would be faster. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Tracking down memory leaks?

2006-02-12 Thread Steven D'Aprano
ction), and it will be much easier for you to write and debug when you can isolate individual pieces of the task in individual functions. Re-factoring will have another advantage: you might just find the problem on your own. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is python very slow compared to C

2006-02-12 Thread Steven D'Aprano
On Sun, 12 Feb 2006 06:20:10 -0800, bonono wrote: > > Steven D'Aprano wrote: >> But, in general, more often than not, Python is fast enough. The extra >> value of using something like Lua or Ocaml or even C is just not enough to >> make up for the disadvant

Re: Tracking down memory leaks?

2006-02-12 Thread Steven D'Aprano
# but both a and c include the same nested list True What if you want c to include a copy of the nested list? That's where you use deepcopy: py> d = copy.deepcopy(a) py> d[2] is a[2] False -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is python very slow compared to C

2006-02-12 Thread Steven D'Aprano
On Sun, 12 Feb 2006 17:44:50 +0100, PA wrote: > On Feb 12, 2006, at 16:11, Steven D'Aprano wrote: > >> availability of skilled programmers is absolutely critical for the use >> of a language. > > By that measure, we should all be using Java, no? I said nothing ab

Re: Is Forth for real?

2006-02-12 Thread Steven D'Aprano
On Sun, 12 Feb 2006 17:08:02 +, Cameron Laird wrote: > In article <[EMAIL PROTECTED]>, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > . > . > . >>on the web for each language. By comparis

Re: Downloading Large Files -- Feedback?

2006-02-12 Thread Steven D'Aprano
de you're describing? It isn't written in C, but get your hands on wget. It is probably already on your Linux distro, but if not, check it out here: http://www.gnu.org/software/wget/wget.html -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is python very slow compared to C

2006-02-12 Thread Steven D'Aprano
on: programmers may look at it and say "No classes? Prototyping? WTF is that? I don't have time to learn something so different, better stick to languages which have a smaller learning curve." -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: listing attributes

2006-02-14 Thread Steven D'Aprano
ves too much. The thing to remember is that methods are attributes too, so it is a little hard to expect Python to magically know which attributes you want to see and which you don't. Although, I don't think it is too much to expect Python to distinguish methods from non-method attributes.

Unexpected behaviour of getattr(obj, __dict__)

2006-02-14 Thread Steven D'Aprano
this? I've tried searching, but can't find anything useful. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: file names longer than MAX_PATH under Windows 2003

2006-02-14 Thread Steven D'Aprano
On Tue, 14 Feb 2006 22:43:50 +1100, Steven D'Aprano wrote: > On Tue, 14 Feb 2006 14:29:44 +0300, Sergey wrote: > >> Hello. >> >> I try to open file with pathname length 282 bytes: >> E:\files\..\something.dat >> >> On MSDN >&g

Re: file names longer than MAX_PATH under Windows 2003

2006-02-14 Thread Steven D'Aprano
files...something.dat" which doesn't exist. You should escape the backslashes: f = file("E:\\files\\...\\something.dat", "r") or use raw strings: f = file(r"E:\files\...\something.dat", "r") or just use forward slashes and let Windows deal with i

Re: Unexpected behaviour of getattr(obj, __dict__)

2006-02-14 Thread Steven D'Aprano
On Tue, 14 Feb 2006 04:11:52 -0800, Raymond Hettinger wrote: > Steven D'Aprano wrote: >> I came across this unexpected behaviour of getattr for new style classes. >> Example: >> >> >>> class Parrot(object): >> ... thing = [1,2,3] >> ... &g

Re: Unexpected behaviour of getattr(obj, __dict__)

2006-02-14 Thread Steven D'Aprano
On Tue, 14 Feb 2006 13:03:17 +0100, bruno at modulix wrote: > Steven D'Aprano wrote: >> I came across this unexpected behaviour of getattr for new style classes. >> Example: >> >> >>>>>class Parrot(object): >> >> ... thing = [1,2,

Re: processing limitation in Python

2006-02-14 Thread Steven D'Aprano
in about two seconds: >>> factor(12345678987654) [2, 3, 2057613164609L] and this in less than a second: >>> factor(12345678987654321) [3, 3, 3, 3, 37, 37, 333667, 333667] -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: processing limitation in Python

2006-02-15 Thread Steven D'Aprano
bers. A number with 1,000 factors would be enormous, and yet the memory needed for a list of 1,000 ints could be as small as 8K -- trivial on modern computers. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Which is faster? (if not b in m) or (if m.count(b) > 0)

2006-02-15 Thread Steven D'Aprano
t) C code. So even though count may do more work, it may do it faster. The only way to tell for sure is to actually time the code, not try to guess. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to write a C-style for loop?

2006-02-15 Thread Steven D'Aprano
r.__lt__, 50), (operator.__mul__, 2)) for i in loop: do_something(i) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Which is faster? (if not b in m) or (if m.count(b) > 0)

2006-02-15 Thread Steven D'Aprano
Georg Brandl wrote: > Steven D'Aprano wrote: > >>On Wed, 15 Feb 2006 08:44:10 +0100, Marc 'BlackJack' Rintsch wrote: >> >> >>>In <[EMAIL PROTECTED]>, Farel wrote: >>> >>> >>>>Which is Faster in Python and Why? &

Re: Safe Python Execution

2006-02-15 Thread Steven Bethard
Graham wrote: > The way i'm controlling functionality is with some games and exec, so > if 'code' was the text code you wanted to execute i run: > > exec code in {'__builtins__':None"} > > obviously this doesn't give you much to play with, but it does remove > file access and importing as far as

Re: Determing whether two ranges overlap

2006-02-16 Thread Steven D'Aprano
# make a local reference for speed while condition: flag = iso(t1, t2) ... code ... If your code is still too slow, you might speed it up with Psycho, or you may need to write a C extension. Either way, you won't know if the code is fast enough until you actually run it. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: web crawler in python or C?

2006-02-16 Thread Steven D'Aprano
n just a day or two ago where a function which was taking hours to complete was re-written with a better algorithm which took only seconds. And still in Python. If it is still too slow after using better algorithms, or if there are no better algorithms, then and only then re-write those bottlenecks in C for speed. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: question about scope

2006-02-16 Thread Steven D'Aprano
e x in list comprehensions are exported to the rest of the local scope, but that (mis)feature is officially going to be removed in future versions of Python. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Merging two lists of data (Pythonic way)

2006-02-17 Thread Steven D'Aprano
On Thu, 16 Feb 2006 12:30:47 -0800, SMB wrote: > I know I could do this with two for loops, but am looking for a better > solution maybe involving list comprehension. What's wrong with for loops? Why do you think they are unPythonic? -- Steven. -- http://mail.python.org/mailm

Re: Open Relay Test

2006-02-17 Thread Steven D'Aprano
am, by any chance? The spammers already know how to look for open relays. Unlike the original poster, they know how to use Google. *wink* Besides, not just spammers want to detect open relays. Many people like to block mail from open relays. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: file.read problem

2006-02-17 Thread Steven D'Aprano
> But still my question is why is the: > f = open('myfile,'r') > a = f.read(5000) > working in linux?? Why shouldn't it work in Linux? The question should be, why is it not working in Windows? (When did "my code is broken" become the excepted state of af

Re: Python 3000 deat !? Is true division ever coming ?

2006-02-17 Thread Steven D'Aprano
occasional newbie who somehow has missed out on learning about true division, but that's no reason to not implement features in the language. The cost of confusing a newbie once in a month of Sundays is far less than the benefit of introducing true division. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: pythonic way of 'b = list(a); b.append(4)"

2006-02-17 Thread Steven D'Aprano
xtra): """Return a new list consisting of extra appended to the items of L.""" return L + [extra] Now call it like this: f(functional_append(a, 4)) But in fact you can now optimize the functional_append away by just doing this: f(*a+[4]) and it will work. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Another stupid newbie question

2006-02-17 Thread Steven D'Aprano
ally will thank us. http://www.catb.org/~esr/faqs/smart-questions.html -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3000 deat !? Is true division ever coming ?

2006-02-17 Thread Steven D'Aprano
as default - because it will just PISS too many (long time python) > people OFF. ;-) Do you realise that the reason true division was introduced into Python was because many long-time Python programmers requested it? So far from annoying them, it is a feature that most Python programmers are waiting for. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class subscripting

2006-02-17 Thread Steven D'Aprano
do the same thing. try: print baz[3] except KeyError: print "No third value. Initializing it now." baz[3] = 0.0 # A third way. print baz.get(3, 0) # Prints 0 if no third value exists. # A fourth way: print baz[3] with a default value of 0, # and set the value if it doesn&#

Re: commenting out blocks of code

2006-02-17 Thread Steven D'Aprano
whether you wanted to copy selected text or paste over it according to some subtle clue in the text itself. Wouldn't that be fun? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: commenting out blocks of code

2006-02-18 Thread Steven D'Aprano
oncede that perhaps my post was a little hasty. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiplication optimization

2006-02-18 Thread Steven D'Aprano
arison than it would for the CPU to blast bits around? I have no idea whether your shortcuts are optimizations or pessimizations. I'm just asking whether you know, or if you are making assumptions. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs. Lisp -- please explain

2006-02-19 Thread Steven D'Aprano
ge. For those tasks that language speed is a limiting factor (say, writing devise drivers, operating systems, and similar), Python may not be fast enough. But they are the exception rather than the rule, and there are no shortage of ways around that: Psycho, C extensions, or even "choose another language". -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: os.mkdir simple help

2006-02-19 Thread Steven D'Aprano
but help would be much appreciated! > Thanks in advance! "input" takes the user-entered string and evaluates it as a Python expression. You want raw_input(). -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs. Lisp -- please explain

2006-02-19 Thread Steven D'Aprano
avascript or ruby or perl, >> >> >> It's not a "scripting" language, and it's not interpreted. > > Of course it is. What do you think happens to the bytecode? By that logic, all languages are interpreted. What do you think happens to the machinecode? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs. Lisp -- please explain

2006-02-19 Thread Steven D'Aprano
't mind one bit if others, less informed than them, come away with that impression. Let's be frank: "interpreted language" has negative connotations which may have been valid in the 1960s and perhaps even the 1970s, but are no longer automatically valid. Nevertheless, those connotations stick around, generally amongst the less knowledgeable. That hurts Python's commercial success, and Python's commercial success is vital for anyone who wishes to get paid to program in Python. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: number ranges (was Re: Matlab page on scipy wiki)

2006-02-20 Thread Steven D'Aprano
notation. It is too easy to make typos, what with , and . next to each other, and the typos often will not raise an exception but will simply give incorrect but puzzling behaviour. This isn't unique to the proposed syntax (e.g. under Python today it isn't obvious whethe

timeit module: am I missing something obvious?

2006-02-20 Thread Steven D'Aprano
tionality already exist? Is there a reason why it can't exist? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Quesion about the proper use of __slots__

2006-02-20 Thread Steven D'Aprano
rs for each of the two teams, which comes > out to be quite large. 750 objects is not very many, not unless they are carrying around large chunks of data. And even then, using __slots__ saves only a small amount of memory per object. Write your code the slot-less way, see how it performs, and if it is slow, change your class definition. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Processing text using python

2006-02-20 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > I think this is what you want: > > file = open(r'c:/test.txt','r') > > c = file.read(3) > while c: > print c > c = file.read(3) > > file.close(); Or: def read3(): return file.read(3) for chars in iter(read3, ''): ... do something

Re: Python vs. Lisp -- please explain

2006-02-20 Thread Steven D'Aprano
features that would have increased Python's speed at the cost of productivity, rather than deliberately choose to emphasis productivity at the expense of some speed. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs. Lisp -- please explain

2006-02-20 Thread Steven D'Aprano
(At least not yet.) But it is also absolutely true that Python is compiled. Why emphasise the interpreter, and therefore Python's similarity to bash, rather than the compiler and Python's similarity to (say) Java or Lisp? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: share function argument between subsequent calls but not between class instances!

2006-02-20 Thread Steven D'Aprano
mainder split between everything else. If anyone cares to look at my quick and dirty source code, it is attached following my signature. -- Steven. * * * """Rough and ready script to analyse the Python standard library and count function definitions that use None

Re: how to break a for loop?

2006-02-21 Thread Steven D'Aprano
oks perfectly Pythonic to me. You know, just because Python has for loops and multi-line blocks of code doesn't mean we shouldn't use them *wink* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: In need of a virtual filesystem / archive

2006-02-21 Thread Steven D'Aprano
ce Using a proper database will give you 2 and 3, but at the cost of a lot of overhead, and typically a relational database is not a single file. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs. Lisp -- please explain

2006-02-21 Thread Steven D'Aprano
Donn Cave wrote: > Quoth Steven D'Aprano <[EMAIL PROTECTED]>: > ... > | Nobody denies that Python code running with no optimization tricks is > | (currently) slower than compiled C code. That's a matter of objective > | fact. Nobody denies that Python can be

Re: number ranges

2006-02-21 Thread Steven D'Aprano
off if such people run > away to Ruby, with its (expletive deleted) a..b AND a...b syntaxes just > to ensure maximum confusion;-). Ruby uses both .. and ...? Now I'm frightened. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: getting started, .py file

2006-02-21 Thread Steven D'Aprano
y google skills are lacking or nobody has ever thought of doing import "C:\directory\module" before. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs. Lisp -- please explain

2006-02-21 Thread Steven D'Aprano
On Tue, 21 Feb 2006 09:46:27 -0800, Donn Cave wrote: > In article <[EMAIL PROTECTED]>, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > ... >> Hey Donn, here is a compiled program for the PowerPC, >> or an ARM processor, or one of IBM's Big Iron >>

Re: Python vs. Lisp -- please explain

2006-02-22 Thread Steven D'Aprano
us of Python's development. If you tell them that Python is slow because it is interpreted, they will believe that Python will always be slow. If you tell them that Python is slow because speed has not been the priority, they will believe that some day it will become the priority, and then Python will get faster. And they will be right. That is the aim of PyPy after all. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: No

2006-02-22 Thread Steven D'Aprano
the server and then emails it... > > assuming that the web server can read files on your local disk is perhaps > a bit too optimistic. Come on, Gaz is running Windows. Chances are *everyone* can read files on his local disk. *wink* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: except clause not catching IndexError

2006-02-22 Thread Steven D'Aprano
(ValueError, IndexError): ... print "Error!" ... Error! And here I was thinking that commas make tuples, not brackets. What is happening here? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: "Temporary" Variable

2006-02-22 Thread Steven D'Aprano
ax How about posting your actual code? You could try this: while 1: var = raw_input("Give me some data! ") if var == "some data": print "Success!" break else: print "No good, try again." -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Unexpected timing results

2006-02-23 Thread Steven D'Aprano
(I imagine) should be about the same as timer1. Possibly even less as it isn't timing the setup of the for loop. Any ideas what is causing the difference? I'm running Python 2.3 under Linux. Thanks, -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: formatted string like---> u'720 S'

2006-02-23 Thread Steven D'Aprano
> do I need to slice off the "u", or anything? I know it has something to > do with unicode but I don't know how to treat it. No. The u is part of the display of the string, just like the quote marks. Ordinary strings are printed with ' ' delimiters. Unicod

Re: Using repr() with escape sequences

2006-02-23 Thread Steven D'Aprano
read a file containing "d:\thedir", and print the string you have just read, the print statement uses repr() and you will see that the string is just what you expect: d:\thedir You can also check for yourself that the string is correct by looking at its length: nine characters. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Detec nonascii in a string

2006-02-23 Thread Steven D'Aprano
on: def isascii(s): for c in some_string: if c not in string.ascii_letters: return False return True -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Unexpected timing results

2006-02-23 Thread Steven D'Aprano
for _ in itr: func() t1 = timer() return t1 - t0 And the results: >>> timer.timer3() 0.64760088920593262 >>> timer.timer4() 5.2274949550628662 It looks like the time function under Linux at least is very slow. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: A C-like if statement

2006-02-23 Thread Steven D'Aprano
f calling the try..except block in every branch directly, pull it out into a function: def test(s,what): try: i = s.index(what) print "It's here: ", i except ValueError: print "No 3's here" -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: "Temporary" Variable

2006-02-23 Thread Steven D'Aprano
break >> else: >> print "No good, try again." > That works fine with strings and when "some_data" is hardcoded. I run > into trouble when "some data" is replaced with a number, unquoted. It > simply says "No good, etc" Try this, at a command line: 5 == '5' and see what you get. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: spaces at ends of filenames or directory names on Win32

2006-02-23 Thread Steven D'Aprano
g spaces? I don't see why Windows' lack is Mac users' problem. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: "Temporary" Variable

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 00:24:25 +, Jeffrey Schwab wrote: > Steven D'Aprano wrote: >> On Thu, 23 Feb 2006 12:05:59 -0800, darthbob88 wrote: >> >> My comments inserted inline. >> >> >> >>>#!/usr/bin/python >>>#simple guessing game,

Re: spaces at ends of filenames or directory names on Win32

2006-02-24 Thread Steven D'Aprano
On Thu, 23 Feb 2006 17:49:31 -0600, Larry Bates wrote: > Steven D'Aprano wrote: >> On Thu, 23 Feb 2006 14:30:22 -0600, Larry Bates wrote: >> >>> How about not naming files with leading and trailing spaces on >>> the Mac? Seems like a bad habit that need

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Thu, 23 Feb 2006 20:41:52 -0600, Terry Hancock wrote: > On Fri, 24 Feb 2006 09:14:53 +1100 > "Steven D'Aprano" <[EMAIL PROTECTED]> wrote: >> There are *reasons* why Python discourages functions with >> side-effects. Side-effects make your code hard to t

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Thu, 23 Feb 2006 16:49:09 -0800, bonono wrote: > > Steven D'Aprano wrote: >> On Thu, 23 Feb 2006 12:04:38 -0700, Bob Greschke wrote: >> >> >> try: >> >>i = a.find("3") >> >>print "It's here: ", i >&

Re: regular expresson for Unix and Dos Lineendings wanted

2006-02-24 Thread Steven D'Aprano
#x27;\n').replace('\r', '\n') elif linesep == '\r': # classic Macintosh s = s.replace('\r\n', '\r').replace('\n', '\r') elif linesep == '\r\n': # Windows s = s.replace('\r\n', '\r').replace('\n', '\r') s = s.replace('\r', '\r\n') else: # weird platforms? print "Unknown line separator, skipping." return s -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Unexpected timing results

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 10:11:18 +0100, Magnus Lycka wrote: > Steven D'Aprano wrote: >> It looks like the time function under Linux at least is very slow. > > Perhaps you should try doing the same thing in C. > Then you can see whether the problem is in the > wrapper or

Re: "Temporary" Variable

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 01:50:40 -0800, bonono wrote: > Steven D'Aprano wrote: >> Just out of curiosity, when do you think is the right time to begin >> teaching programmers good practice from bad? Before or after they've >> learnt bad habits? > > When you hav

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
ndex(substr) not only returned the index as promised, but also (say) appended substr to a list somewhere. Side-effects aren't always bad (import, for example, does all its work by side-effect). But they are generally frowned upon, and in functional languages they are verboten. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Unexpected timing results

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 10:51:09 +, Roel Schroeven wrote: [snip] > I think it looks like the problem is in the system call. Thank you Roel for going the extra mile. I appreciate the unexpected bonus. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 06:45:41 -0500, Kent Johnson wrote: > Steven D'Aprano wrote: >> Now that's a Python wart: using >>> for the prompt for interactive >> sessions. It makes it ambiguous when posting code in email or newsgroups, >> especially once the code

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 08:03:49 -0500, Roy Smith wrote: > In article <[EMAIL PROTECTED]>, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> Side-effects aren't always bad (import, for example, does all its work by >> side-effect). But they are generally f

Re: make a class instance from a string ?

2006-02-24 Thread Steven D'Aprano
you have to assume some of them will be malicious, and they will be a lot more inventive searching for security holes than you. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: "Temporary" Variable

2006-02-25 Thread Steven D'Aprano
er the motto "Nothing sucks like an Electrolux." Which is a wonderful, deliberately ironic advertising line. I love it!!! -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Optimize flag question

2006-02-25 Thread Steven D'Aprano
on is True. >> > What would be the occasion that AssertionError be the right exception > to raise then ? Surely that would be when an assert statement fails? I don't think AssertionError should be called by hand. At least, I wouldn't do so. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python a Zen language?

2006-02-25 Thread Steven D'Aprano
invest in picking up a Zen language. Hard-core hackers > might presumably lean towards the Zen languages. Regardless of whether Python is a Zen or tool language, or both, or something else, it is incredibly easy to pick up. Just remember, and this goes for *any* new language you are trying to learn, Pyth

Re: Modify the local scope inside a function

2006-02-25 Thread Steven D'Aprano
#x27;t modify locals() so it doesn't help me. No, you can't modify locals. Locals returns a copy of the local environment as a dict, but changing that dict doesn't change the local variables. There is an exception to that rule: if you run locals from the interpreter, outside of a fu

<    96   97   98   99   100   101   102   103   104   105   >