Re: justifying text...and also...correct use of classes...

2004-12-30 Thread Craig Ringer
ize in advance if I > am, but I just can't figure it out. "%20s: %s" % (leftstring, rightstring) or "%20s: %-40s" % (leftstring, rightstring) That's Python's 'printf' style string formatting. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: what would you like to see in a 2nd edition Nutshell?

2004-12-29 Thread Craig Ringer
s sense once you already understand it. It wouldn't hurt to point C extension authors at things like the 'es' encoded string format for PyArg_ParseTuple to help them make their code better behaved with non-ascii text. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Reference behavior through C (was: Lambda going out of fashion)

2004-12-28 Thread Craig Ringer
On Wed, 2004-12-29 at 02:08, Cameron Laird wrote: > In article <[EMAIL PROTECTED]>, > Craig Ringer <[EMAIL PROTECTED]> wrote: > . > . > . > > IMO the reference behaviour of functions in the

Re: DB-API format string conventions

2004-12-28 Thread Craig Ringer
t still need to have a look for other API revision proposals. I thought it best to ask here to find out how much interest there would be in clarifying the API and adding a required format style before going ahead with actually writing a few patches and a draft PEP for comments. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: DB-API format string conventions

2004-12-28 Thread Craig Ringer
On Tue, 2004-12-28 at 18:29, Craig Ringer wrote: > Would there be any interest in releasing a DB-API 2.1 with one > parameter style made MANDATORY, and a tuple of other supported styles in > .paramstyles ? I think existing modules implemented in Python could be > retrofi

DB-API format string conventions

2004-12-28 Thread Craig Ringer
work, but still probably not a big deal. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Clearing the screen

2004-12-25 Thread Craig Ringer
r pythonrc ( ${HOME}/.pythonrc on UNIX , NFI on windows ). On a side note, it'd be easier to read your post if you'd use the shift key more often :-P -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Multiple Inheritance __slots__ problem

2004-12-25 Thread Craig Ringer
need to define slots in these classes and also need to inherit them in > Derived class. If I recall correctly, the standard advice in this situation is "don't use __slots__. If you think you need __slots__, still don't use __slots__." I've made use of __slots__ once my

Re: regular expression: perl ==> python

2004-12-23 Thread Nick Craig-Wood
mentation. This is probably what Windows people look at by default but Unix hackers like me expect everything (or at least a hint) to be in the man/pydoc pages. Just noticed in pydoc2.4 a new section MODULE DOCS http://www.python.org/doc/current/lib/module-sre.html Which is at least a hint that you are looking in the wrong place! ...however that page doesn't exist ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Lambda going out of fashion

2004-12-23 Thread Craig Ringer
Fredrik Lundh wrote: Craig Ringer wrote: It's hard to consistently support Unicode in extension modules without doing a lot of jumping through hoops. Unicode in docstrings is particularly painful. This may not be a big deal for normal extension modules, but when embedding Python it'

Re: regular expression: perl ==> python

2004-12-23 Thread Nick Craig-Wood
. xml = re.compile(r""" <([/?!]?\w+) # 1. tags |&(\#?\w+); # 2. entities |([^<>&'\"=\s]+) # 3. text strings (no special characters) |(\s+) # 4. whitespace |(.) # 5. special characters ""&quo

Re: Lambda going out of fashion

2004-12-22 Thread Craig Ringer
rivial) difference in syntax. I'd be interested in knowing if there is in fact more to it than this. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Lambda going out of fashion

2004-12-22 Thread Craig Ringer
em. Of course, all these are just my opinion in the end, but I'd still have to argue that using Python from C could be a lot nicer than it is. The API is still pretty good, but the solution of these issues would make it a fair bit nicer again, especially for people embedding Python in apps (a place were it can seriously excel as a scripting/extension/glue language). -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: PHP vs. Python

2004-12-22 Thread Craig Ringer
#x27;ll be faster or slower than PHP, I just can't guess. I think it'd certainly be well worth a try, especially if you're writing any more complex applications. That said, for 90% of users development time matters more than execution speed, and that's another matter entirely. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Killing a python thread with a signal

2004-12-22 Thread Craig Ringer
the past - it might be a good idea to search the archives. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expression: perl ==> python

2004-12-22 Thread Nick Craig-Wood
;float $1\n"; } else { print "unknown thing $line\n"; } Is there an easy way round this? AFAIK you can't assign a variable in a compound statement, so you can't use elif at all here and hence the problem? I suppose you could use a monstrosity like this, which relies on

Re: Printing

2004-12-21 Thread Craig Ringer
tdir) . I strongly recommend you read the Python tutorial if you haven't already, and have a browse over the documentation for some of the key modules like os and sys. Google and Google Groups are also often very helpful - you can use Google Groups to search comp.lang.python (this list/newsgroup). -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Printing

2004-12-20 Thread Craig Ringer
M is an option. > Or to do a DOS directory and send it directly to a file to be accessed > as needed? I'm afraid I just don't understand that. "Do" a DOS directory? If you want to list the contents of a directory, see help(os.listdir) . -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Easy "here documents" ??

2004-12-20 Thread Nick Craig-Wood
Jim Hill <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > >I prefer this > > > > ... I'll have %(amount)s %(what)s > > ... for $%(cost)s please""" % locals() > > Looks pretty slick. This might just be what I need. >

Re: A rational proposal

2004-12-20 Thread Christopher A. Craig
e are some very real performance reasons to do it in C rather than Python (i.e. I'm manipulating the internals of the numerator and denominator by hand for performance in the GCD function) -- Christopher A. Craig <[EMAIL PROTECTED]> "I affirm brethren by the boasting in you which

Re: Easy "here documents" ??

2004-12-19 Thread Nick Craig-Wood
ying around instead which is much more flexible than perl. You can even pass self.__dict__ if you are in a class method so you can access attributes. >>> class A: pass ... >>> a=A() >>> a.amount=10 >>> a.what="rutabaga" >>> a

Re: A completely silly question

2004-12-18 Thread Craig Ringer
it's probably worth just using curses, but if you have a fairly basic app that just needs to read raw characters sometimes this approach should be fine. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: expression form of one-to-many dict?

2004-12-18 Thread Nick Craig-Wood
in range(1000)])' 'map = {} for key, value in sequence: if map.has_key(key): map[key].append(value) else: map[key] = [ value ]' 1000 loops, best of 3: 1.11e+03 usec per loop Not that timing is everything of course ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expression for javadoc style comment

2004-12-18 Thread Craig Ringer
It would be good if you could post some of the things you've tried, and perhaps a little more detail about what you're trying to match. Are you trying to match the comment as a whole, eg "this is a javadoc comment", or are you trying to extract parts of it? -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Import trouble

2004-12-15 Thread Craig Ringer
On Wed, 2004-12-15 at 21:44, Craig Ringer wrote: > def import_xml: >try: >import libxml >except ImportError,err: ># handle the error >return libxml > > libxml = import_xml() Though my personal approach would actually be: try: import l

Re: Import trouble

2004-12-15 Thread Craig Ringer
e into the current namespace: > the function scope(instead of file scope as I want). Is there any solution to > my problem? Or should I solve it in another way? def import_xml: try: import libxml except ImportError,err: # handle the error return libxml libxml

Re: subprocess vs. proctools

2004-12-15 Thread Nick Craig-Wood
Keith Dart <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > This sounds rather like the new subprocess module... > > > >>>>import subprocess > >>>>rc = subprocess.call(["ls", "-l"]) > > > > total 381896

Re: Suggestion for "syntax error": ++i, --i

2004-12-15 Thread Nick Craig-Wood
7;++', '--'. > > It does already. > > $ cat plusplus.py def main(): i = 1 return ++i $ pychecker plusplus Processing plusplus... Warnings... plusplus.py:4: Operator (++) doesn't exist, statement has no effect -- Nick Craig-Wood <[EMAIL PROTECTED]>

Re: lies about OOP

2004-12-14 Thread Craig Ringer
doesn't extend as far as: instance = Constructor(*args) though if anybody knows how to do this in C++ I would be overjoyed to hear from them. Qt _does_ provide a pleasant (if somewhat limited) of the Python getattr() and setattr() calls. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Performance (pystone) of python 2.4 lower then python 2.3 ???

2004-12-14 Thread Nick Craig-Wood
dvert for AMD ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: how do I "peek" into the next line?

2004-12-13 Thread Craig Ringer
Assuming there's a good reason, such as monster lines, not to just read the next line anyway, I'd suggest read()ing the next character then seek()ing back by one character to restore the file position. def peekChar(fileobj): ch = fileobj.read(1) fileobj.seek(-1,1) r

Re: Python vs. Perl

2004-12-13 Thread Nick Craig-Wood
l(["ls", "-l"]) total 381896 -rw-r--r--1 ncw ncw 1542 Oct 12 17:55 1 [snip] -rw-r--r--1 ncw ncw 713 Nov 16 08:18 z~ >>> print rc 0 IMHO the new subprocess module is a very well thought out interface... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How can i send 8-bit data or binary data with pyserial?

2004-12-13 Thread Craig Ringer
exstring2 = "\x5b\xbd" >>> hexstring2 '[\xbd' and you can convert them all to strings. Just remember that you can work with a string as a buffer of 8-bit blocks and you'll be fine. In your specific example: >>> byte = '00100' >>> byte_chr = chr(int(byte,2)) >>> byte_chr '@' -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Read a gzip file from inside a tar file

2004-12-13 Thread Craig Ringer
hat does require the entire thing to be loaded (or anything that means you have to seek around the file), I'd say you're SOL. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: collaborative editing

2004-12-11 Thread Nick Craig-Wood
Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > Robert Kern <[EMAIL PROTECTED]> wrote: > > Personally, I loathe writing at any length inside a Web browser and > > prefer to use a real editor at all times. > > Me too! You need mozex... > >http://mozex

Re: Unicode docstrings in PyMethodDef?

2004-12-10 Thread Craig Ringer
On Wed, 2004-12-08 at 13:43, Craig Ringer wrote: > Hi folks > > I'm currently working on a fairly well internationalised app that embeds > a Python intepreter. I'd like to make the docstrings translatable, but > am running into the issue that the translation function ret

Re: collaborative editing

2004-12-10 Thread Nick Craig-Wood
Robert Kern <[EMAIL PROTECTED]> wrote: > Personally, I loathe writing at any length inside a Web browser and > prefer to use a real editor at all times. Me too! You need mozex... http://mozex.mozdev.org/ Not sure about Mac support though /OT -- Nick Craig-Wood <[

Re: converting html escape sequences to unicode characters

2004-12-10 Thread Craig Ringer
On Fri, 2004-12-10 at 16:09, Craig Ringer wrote: > On Fri, 2004-12-10 at 08:36, harrelson wrote: > > I have a list of about 2500 html escape sequences (decimal) that I need > > to convert to utf-8. Stuff like: > > I'm pretty sure this somewhat horrifying code doe

Re: converting html escape sequences to unicode characters

2004-12-10 Thread Craig Ringer
, '에', '요', '내', '면', '금', '이', '얼', '마', '지', '잠'] >>> def unescape(escapeseq): ... return ("\\u%x" % int(escapeseq[2:-1])).decode("unicode_escape") ... >>> print ' '.join([ unescape(x) for x in entities ]) 비 행 기 로 보 낼 거 에 요 내 면 금 이 얼 마 지 잠 -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible to insert variables into regular expressions?

2004-12-09 Thread Craig Ringer
You could also end up inserting ?s , *s etc, resulting in some rather frustrating bugs. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: results of division

2004-12-09 Thread Christopher A. Craig
. round(x,n) in (Python 2.4): multiplies x by 10**n adds .5 truncates divides by 10**n. Don't confuse this trick with giving us the correct result though, it's still floating point: >>> round(1.77499, 2) 1.78 -- Christopher A. Craig <[EMAIL PROTECTED]> &qu

Re: Recursive list comprehension

2004-12-08 Thread Nick Craig-Wood
doesn't catch any exceptions it shouldn't) def flatten( i ): if hasattr(i, "__iter__"): for j in i: for k in flatten(j): yield k else: yield i -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Inheritance

2004-12-08 Thread Craig Ringer
variable is still there, and unmodified, but the name search finds the copy each instance has in its dict before the class one. >>> a.__class__.name 'fred' >>> a.__class__.name = "Albert" >>> a.__class__.name 'fred' >>> a.name &#x

Re: Recursive list comprehension

2004-12-08 Thread Nick Craig-Wood
e l l o ...and this works because str supports __getitem__ according to the docs. So there is some magic going on here! Is str defined to never have an __iter__ method? I see no reason why that it couldn't one day have an __iter__ method though. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Unicode docstrings in PyMethodDef?

2004-12-07 Thread Craig Ringer
e rest of the app is translated with. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I do this? (eval() on the left hand side)

2004-12-07 Thread Craig Ringer
dict__[varname] = 'unwise' >>> obj.fred 'unwise' This, however, won't do you much good if you don't know what you'll be modifying. I know the locals() and globals() functions exist, but have always been leery of the idea of modifying their contents, an

Re: long number multiplication

2004-12-06 Thread Christopher A. Craig
bit digits. > i needed to implement this myself and was thinking of storing the digits > of an integer in a list. That's sort of what Python does except the "digits" are 15 bits, not base 10. Doing it in base 10 would be a huge pain because of the problems with base 10->b

Re: long number multiplication

2004-12-06 Thread Nick Craig-Wood
area of computer science! Its also rather big and expensive so you'll probably want to look at in the library... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Writing class factories with the Python/C API?

2004-12-05 Thread Craig Ringer
wouldn't have guessed what I was looking for would be in the exception code. Much appreciated. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Writing class factories with the Python/C API?

2004-12-05 Thread Craig Ringer
bunch of methods on the generated subclasses, so I'm hoping so... -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: [Python-Help] (fwd)

2004-12-05 Thread Craig Ringer
t;>> x [1] >>> x.append(5) >>> x [1,5] >>> sum(x) 6 >>> sum(x) / len(x) 3 As you can see, it's much easier to work with data in lists. Some of the other methods, like list.sort() and list "slices" will also be useful to you, but I'll let

Re: Galois field

2004-12-03 Thread Nick Craig-Wood
orlds If someone did wrap PARI in python it would certainly be easier to use than GP which I found very unintuitive! In fact I just found this which looks like just the job! http://www.fermigier.com/fermigier/PariPython/readme.html -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://

Re: pre-PEP generic objects

2004-12-03 Thread Nick Craig-Wood
eading to the critical > difference in this case: I think I finally understand now - thank you to you both! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-PEP generic objects

2004-12-02 Thread Nick Craig-Wood
Scott David Daniels <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > class Hash: > > def __init__(self, **kwargs): > > for key,value in kwargs.items(): > > setattr(self, key, value) > > def __getitem__(self, x): > >

Re: pre-PEP generic objects

2004-12-01 Thread Nick Craig-Wood
Steven Bethard <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > Steven Bethard <[EMAIL PROTECTED]> wrote: > > > >> I promised I'd put together a PEP for a 'generic object' data type for > >> Python 2.5 that allows one to replac

Re: Run an python method from C++

2004-11-30 Thread Craig Ringer
PyMapping_GetItemString(globals, "errorMsg") QString errorMsg = PyString_AsString(errorMsgPyStr); (I'd love to be told there's a nicer way to do this). This could easily be the wrong way to go about things, buggy, or just stupid, so be warned. It does work well here, however. I would be interested in knowing how to tell Python what encoding is used for program text passed using PyRun_String() if anybody knows. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Class methods in Python/C?

2004-11-30 Thread Craig Ringer
d to worry about older code. Thanks. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Class methods in Python/C? [ANSWER]

2004-11-30 Thread Craig Ringer
on. New in version 2.3. Sorry for the noise everybody, I could've sworn I looked over that already. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: pre-PEP generic objects

2004-11-30 Thread Nick Craig-Wood
st ram it in a hash, and write lots of functions acting on it) rather than creating a specific class for the job which is dead easy in python anyway and to which you can attach methods etc. YMMV ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Class methods in Python/C?

2004-11-30 Thread Craig Ringer
hanks to Qt the bindings are going to be both simple and quite powerful. However, I need a way to do class methods... If anybody has any tips on this, It'd be much appreciated. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

Re: Protecting Python source

2004-11-29 Thread Craig Ringer
bit more practical IMO, and may be a good place to look at digital signing. > - Your customer demands closed source because the code contains trade >secrets. My understanding is that that's never guaranteed safe, no? Or are restrictions against reverse engineering now commonly enforcable? -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list

<    4   5   6   7   8   9