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
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
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
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
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
work, but still probably not a big deal.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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'
.
xml = re.compile(r"""
<([/?!]?\w+) # 1. tags
|&(\#?\w+); # 2. entities
|([^<>&'\"=\s]+) # 3. text strings (no special characters)
|(\s+) # 4. whitespace
|(.) # 5. special characters
""&quo
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
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
#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
the past - it might be a good idea to search the archives.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
;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
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
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
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.
>
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
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
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
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
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
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
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
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
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]>
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
dvert
for AMD ;-)
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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
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
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 <[
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
, '에', '요', '내',
'면', '금', '이', '얼', '마', '지',
'잠']
>>> 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
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
. 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
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
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
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
e rest of the app is translated with.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
bunch of methods on the generated subclasses, so I'm hoping so...
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
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
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://
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
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):
> >
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
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
d to worry
about older code. Thanks.
--
Craig Ringer
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
801 - 861 of 861 matches
Mail list logo