Re: C#3.0 and lambdas
Erik Wilsher wrote: > Python developement is discussed, decided and usually developed within > the members of python-dev. Have you seen any discussions about > xml-literals in python-dev lately? No. I don't need them, so I don't start a discussion. If you need them, or you want them, feel free to do so. Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: Help on regular expression match
Fredrik Lundh wrote:
> ".*" gives the longest possible match (you can think of it as searching back-
> wards from the right end). if you want to search for "everything until a
> given
> character", searching for "[^x]*x" is often a better choice than ".*x".
>
> in this case, I suggest using something like
>
> print re.findall("href=\"([^\"]+)\"", text)
>
> or, if you're going to parse HTML pages from many different sources, a
> real parser:
>
> from HTMLParser import HTMLParser
>
> class MyHTMLParser(HTMLParser):
>
> def handle_starttag(self, tag, attrs):
> if tag == "a":
> for key, value in attrs:
> if key == "href":
> print value
>
> p = MyHTMLParser()
> p.feed(text)
> p.close()
>
> see:
>
> http://docs.python.org/lib/module-HTMLParser.html
> http://docs.python.org/lib/htmlparser-example.html
> http://www.rexx.com/~dkuhlman/quixote_htmlscraping.html
>
>
Thanks for your help.
I found another solution by just simply adding a '?' after ".*" which
makes the it searching for the minimal length to match the regular
expression.
To the HTMLParser, there is another problem (take my code for example):
import urllib
import formatter
parser = htmllib.HTMLParser(formatter.NullFormatter())
parser.feed(urllib.urlopen(baseUrl).read())
parser.close()
for url in parser.anchorlist:
if url[0:7] == "http://":
print url
when the baseUrl="http://www.nba.com";, there will raise an
HTMLParseError because of a line of code "". I found that this line of code is inside
Re: Wrapping classes
Jeremy Sanders wrote:
> Is it possible to implement some sort of "lazy" creation of objects only
> when the object is used, but behaving in the same way as the object?
>
A generic approach would override __getattribute__ to let it perform the
__init__ method on not initialized objects.This is a case for using
metaclasses as even __init__ method must be overridden ad hoc to
register the arguments for the lazy initialization.
Probably you want to fine-tune the triggering (specifing which attribute
should make it happen ),as every look up would trigger.
class NotInitializedObjects(type):
def __init__(cls,*_):
realInit=cls.__init__
def __newInit__(self,*pos,**key):
def _init():
realInit(self,*pos,**key)
self._init=_init
cls.__init__=__newInit__
def __getattribute__(self,attr):
def getter(attr):
return object.__getattribute__(self,attr)
if '_init' in getter('__dict__'):
getter('_init')()
del self._init
return getter(attr)
cls.__getattribute__=__getattribute__
if __name__=='__main__':
class Class:
__metaclass__=NotInitializedObjects
def __init__(self,*pos,**key):
self.initialized=True
print 'initializing with',pos,key
a=Class('arg',key='key') # a fake initialization
try:
object.__getattribute__(a,'initialized')
except AttributeError: # should raise
print 'not initialized'
else:
raise
try:
a.initialized #every look up would do ,even a print
except AttributeError:
raise
else:
print 'initialized'
Have fun Paolino
___
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it
--
http://mail.python.org/mailman/listinfo/python-list
Python argv and special characters
Hi. Platform: Win XP Python version: 2.4.1 Running script from: cmd.exe (windows console) I am having some trouble passing arguments to a python script having special characters. In my case the argument is a filename (eg. udtræk.xml). It seems like python tries to guess the encoding in which the arguments are passed, instead of just recieving them in unicode, thus using main() instead of wmain() inside the interpreter. So I get an exception "IOError: [Errno 2] No such file or directory: 'udtr\xe6k.xml'" as a result. How can I ensure a safe passing of arguments maybe having speciel characters within. Best Regards Jakob Simon-Gaarde -- http://mail.python.org/mailman/listinfo/python-list
Re: Python argv and special characters
Jakob Simon-Gaarde: > How can I ensure a safe passing of arguments maybe having speciel > characters within. Use ctypes to call the Windows GetCommandLine function. The CommandLineToArgvW function can be used to break up the command line string into arguments. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use a timer in Python?
Hi Sybren and Wolfram,
thank you very much for the time.sleep() tip.
My program reads like this now.
import os
import time
WINDOWS_SHARE = 'C:\\Temp'
while 'transfer.lock' in os.listdir( WINDOWS_SHARE ):
print "Busy, please wait..."
time.sleep(10)
f = open(WINDOWS_SHARE + '/myfile', 'w')
f.write("test 123")
f.close()
print "Done!"
Nico
--
http://mail.python.org/mailman/listinfo/python-list
Re: Ide RAD for linux?
I use Eric3 as IDE on Linux. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use a timer in Python?
Nico Grubert <[EMAIL PROTECTED]> writes: > while 'transfer.lock' in os.listdir( WINDOWS_SHARE ): > print "Busy, please wait..." > time.sleep(10) > > f = open(WINDOWS_SHARE + '/myfile', 'w') But there's a race condition, and don't you have to make your own lock before writing myfile, so that the cron job won't clobber it or miss it? -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen and replacing the shell pipe line
by the way, you're re-inventing the wheel somewhat, check out the stdlib pipes module (http://docs.python.org/lib/module-pipes.html) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use a timer in Python?
Nico Grubert <[EMAIL PROTECTED]> wrote:
> on a Linux machine running Python 2.3.5. I want to create a file
> 'newfile' in a directory '/tmp' only if there is no file 'transfer.lock'
> in '/temp'.
> A cronjob creates a file 'transfer.lock' in '/temp' directory every 15
> minutes while the cronjob is doing something. This job takes around 30
> seconds. During these 30 seconds the 'transfer.lock' file is present in
> the '/temp' directory and I must not create 'newfile'. After the cronjob
> has been finished, the 'transfer.lock' file is deleted from '/temp' and
> I can create 'newfile'.
That all sounds very race-y to me! The cron-job and the other process
need to take the same lock, otherwise the cron-job will start 1ms
after the other process checks for transfer.lock and before it has a
chance to create newfile and there will be trouble.
Using files as locks isn't brilliant because the operations "read to
see if the lock is there" and "create the file isn't" aren't atomic.
Ie someone can get in there after you read the directory but before
you create the file.
However creating a directory is atomic, so you can take the lock by
os.mkdir("/tmp/lock"). If that succeeded you got the lock, if it
failed (threw OSError) then you didn't. If it failed then just
time.sleep(1) and try again. This kind of locking works cross
platform too. You can use it in shell too, eg "mkdir /tmp/lock ||
exit 1" in your cronjob.
You could wrap the locking up into a module of course, and I bet
someone already did.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
pymssql and bind variables
I need to write a little app that connects to an MS SQL server and for this I decided on the pymssql module. At this stage I am trying to find out if MS SQL server can handle bind variables. If anybody can give me an answer and perhaps a example it will be appreciated Thanks Albert -- http://mail.python.org/mailman/listinfo/python-list
Re: Stampare su stampante aghi
|>>>"lux" <[EMAIL PROTECTED]> 09/22/05 4:01 pm >>>
|Salve a tutti,
|sono alle prese con delle stampe su
|stampanti ad aghi...
|
|Per stampare puro testo la soluzione più gettonata
|sembra essere
|
|f = open("LPT1:")
|f.write("bla bla")
|f.close()
|
|devo dire che funziona benissimo, ma mi piacerebbe
|essere slegato falla parallela (sempre meno frequente)
|e inviare il puro testo da stampare scegliendo una delle
|stampanti installate sulla macchina senza starmi a
|preoccupare di come o dove sia configurata (locale, rete, usb, etc).
|
|Come posso fare?
Non lo so. No comprendo su questione. Parlo solomente un piu Italiano. Puoi
demandare su questione an Inglese per favore?
I don't know. I do not understand your question. My Italian is very limited.
Can you ask your question in English please?
|Grazie, Luca.
|
|--
|http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list
Re: idle
Hi Franz, >>is there no IDLE in Python2.4? > > Sure, > on Windows: > > C:\Python24\Lib\idlelib\idle.pyw > You should have a shortcuts in your StartMenu > und Python 2.4 What about with Suse 9.3 und Python 2.4? o-o Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: re.split() problem
Thanks for your reply.
>>> In Re: re.split() problem
>>> [Fredrik] = "Fredrik Lundh" wrote
Fredrik> >>> s = "foo\nbar\n\nbaz"
Fredrik> >>> re.findall("(?s).*\n\n|.+$", s)
Fredrik> ['foo\nbar\n\n', 'baz']
Fredrik> (this also lets you use finditer so you can process huge texts without
Fredrik> having to hold everything in memory)
Thanks. This sovles my problem.
> Will it be fixed in Python 2.4.2?
Fredrik> 2.4.2 is a bug fix release. "doesn't work as you intend" doesn't
really
Fredrik> count as a bug
I'm sorry for my expression. I should have written "Will those features which
were discussed
in these threads be released in Python 2.4.2 ?"
--
http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping classes
Jeremy Sanders wrote:
> Is it possible to implement some sort of "lazy" creation of objects only
> when the object is used, but behaving in the same way as the object?
Smells like a Proxy pattern...
> For instance:
>
> class Foo:
> def __init__(self, val):
> """This is really slow."""
> self.num = val
>
> # this doesn't call Foo.__init__ yet
> a = lazyclass(Foo, 6)
>
> # Foo is only initalised here
> print a.num
>
> What I really want to do is make an object which looks like a numarray,
> but only computes its contents the first time it is used.
>
Here's a Q&D, stupid simple, possibly flawed solution:
class LazyProxy(object):
def __init__(self, klass, *args, **kwargs):
self.__klass = klass
self.__args = args
self.__kwargs = kwargs
self.__subject = None
def __lazy_init(self):
if self.__subject is None:
self.__subject = self.__klass(*self.__args,**self.__kwargs)
def __getattr__(self, name):
self.__lazy_init()
return getattr(self.__subject, name)
def __setattr__(self, name, value):
# TODO : there's a better way to do this,
# but I don't remember it ruight now and
# don't have time to search...
if name in ['_LazyProxy__klass',
'_LazyProxy__args',
'_LazyProxy__kwargs',
'_LazyProxy__subject']:
self.__dict__[name] = value
else:
self.__lazy_init()
setattr(self.__subject, name, value)
if __name__ == '__main__':
class Greeter(object):
def __init__(self, name):
self.name = name
def greet(self, who):
return "hello %s, my name is %s" % (who, self.name)
lazy1 = LazyProxy(Greeter, 'toto')
print lazy1.greet('titi')
lazy2 = LazyProxy(Greeter, 'lolo')
lazy2.name = "lili"
print lazy2.greet(lazy1.name)
Every comment, fix etc welcome.
Now there are probably better ways to do this playing with decorators or
meta-classes.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
--
http://mail.python.org/mailman/listinfo/python-list
Re: idle
TK wrote: >>>is there no IDLE in Python2.4? > What about with Suse 9.3 und Python 2.4? You have to install the python-idle package. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Python argv and special characters
thanks :-) It seems a little overkill though, is it really the only/best way? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use a timer in Python?
> That all sounds very race-y to me! The cron-job and the other process
> need to take the same lock, otherwise the cron-job will start 1ms
> after the other process checks for transfer.lock and before it has a
> chance to create newfile and there will be trouble.
>
> Using files as locks isn't brilliant because the operations "read to
> see if the lock is there" and "create the file isn't" aren't atomic.
> Ie someone can get in there after you read the directory but before
> you create the file.
>
> However creating a directory is atomic, so you can take the lock by
> os.mkdir("/tmp/lock"). If that succeeded you got the lock, if it
> failed (threw OSError) then you didn't. If it failed then just
> time.sleep(1) and try again. This kind of locking works cross
> platform too. You can use it in shell too, eg "mkdir /tmp/lock ||
> exit 1" in your cronjob.
There is no cronjob anymore now. I just need to check if there is a lock
file. How would you modify my short program to avoid the situation "Ie
someone can get in there after you read the directory but before
you create the file."?
Nico
--
http://mail.python.org/mailman/listinfo/python-list
Re: Alternatives to Stackless Python?
[EMAIL PROTECTED] a écrit : >>I found LGT http://lgt.berlios.de/ but it didn't seem as if the >>NanoThreads module had the same capabilites as stackless. > > > What specific capabilities of Stackless are you looking for, that are > missing from NanoThreads? Capabilities of the different "threadlike" systems are somewhat muddy. What myself I like in stackless is : - you can put context switching instuctions anywhere in the callstack without having to explicitely chain the operation - pickle support Not sure if greenlets support pickling yet. There are no info on that point and my tests weren't succesful. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping classes
Paolino wrote:
> class NotInitializedObjects(type):
> def __init__(cls,*_):
> realInit=cls.__init__
> def __newInit__(self,*pos,**key):
> def _init():
> realInit(self,*pos,**key)
> self._init=_init
> cls.__init__=__newInit__
> def __getattribute__(self,attr):
> def getter(attr):
> return object.__getattribute__(self,attr)
> if '_init' in getter('__dict__'):
> getter('_init')()
> del self._init
> return getter(attr)
> cls.__getattribute__=__getattribute__
>
A lighter solution can be overriding __getattr__.
This will produce more object-like behaving instances even when not
initialized, aka you can call methods and access class attributes
without triggering the init (not very useful)
class NotInitializedObjects(type):
def __init__(cls,*_):
realInit=cls.__init__
def __newInit__(self,*pos,**key):
def _init():
realInit(self,*pos,**key)
self._init=_init
cls.__init__=__newInit__
def __getattr__(self,attr):
if hasattr(self,'_init'):
self._init()
del self._init
if hasattr(self,attr):
return getattr(self,attr)
raise AttributeError
cls.__getattr__=__getattr__
### Test with previous testing code
A cleaner solution is decoupling the intensive calculation attributes
from __init__ and use descriptors for them.But this is impossible if
/the/ instance value is the intensive one to be calculated.
Ciao Paolino
___
Aggiungi la toolbar di Yahoo! Search sul tuo Browser, e'gratis!
http://it.toolbar.yahoo.com
--
http://mail.python.org/mailman/listinfo/python-list
Re: C#3.0 and lambdas
Reinhold Birkenfeld wrote: >> And I think the discussion that followed proved your point perfectly >> Fredrik. Big discussion over fairly minor things, but no "big picture". >> Where are the initiatives on the "big stuff" (common documentation >> format, improved build system, improved web modules, reworking the >> standard library to mention a few) Hey, even Ruby is passing us here. > > This is Open Source. If you want an initiative, start one. you know, this "you have opinions? fuck off!" attitude isn't really helping. -- http://mail.python.org/mailman/listinfo/python-list
Re: strange import phenomenon
>One idea that seems to work is setting __name__ = '__main__' Or, del sys.modules[__name__]. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python argv and special characters
Jakob Simon-Gaarde: > thanks :-) It seems a little overkill though, is it really the > only/best way? Yes. I should have mentioned you want the wide version of the function GetCommandLineW. I wrote a patch to allow unicode in argv but later agreed that the patch should be rejected: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1231336&group_id=5470 Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping classes
Peter Hansen wrote:
> Almost anything is possible in Python, though whether the underlying
> design idea is sound is a completely different question. (Translation:
> try the following pseudo-code, but I have my suspicions about whether
> what you're doing is a good idea. :-) )
What I'd like to do precisely is to be able to evaluate an expression like
"a+2*b" (using eval) where a and b are objects which behave like numarray
arrays, but whose values aren't computed until their used.
I need to compute the values when used because the arrays could depend on
each other, and the easiest way to get the evaluation order correct is to
only evaluate them when they're used.
An alternative way is to do some string processing to replace a with
computearray("a") in the expression or something horrible like that.
Thanks
Jeremy
--
Jeremy Sanders
http://www.jeremysanders.net/
--
http://mail.python.org/mailman/listinfo/python-list
Re: words relating to networks that I should probably know
John Walton schreef: > Hello, again. I'm back with my instant messenger > project. My teacher has assigned us to write our > papers, excluding the procedure, results, and > conclusion. One of my topics is going to be networks. > Does anyone know a list of words relating to > networking/networks that I should know for this > project? Not the definitions, but just the words; I > can look up the definitions on webopedia. It would be > appreciated. Thanks! > -John Wikipedia is a good starting point, but also 'Connected: An Internet Encyclopedia' http://www.freesoft.org/CIE/ -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: Question About Logic In Python
Terry Reedy wrote: > "Steve Holden" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>Which is yet another reason why it makes absolutely no sense to apply >>arithmetic operations to Boolean values. > > > Except for counting the number of true values. This and other legitimate > uses of False/True as 0/1 (indexing, for instance) were explicitly > considered as *features* of the current design when it was entered. The > design was not merely based on backwards compatibility, but also on > actually use cases which Guido did not want to disable. There was lots of > discussion on c.l.p. > Sure. Perhaps I should have said it makes absolutely no sense "to expect the results of aritmetic operations on bools to themselves be bools". Sheesh, you have to be so careful nowadays ... :-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
minidom appendChild confusion
Hello!
Can anyone explain why the following code does not work?
(I'm using python2.4.)
Cheers, Marco
--
# the following code does _not_ work.
# intended: put child-nodes as children to another node
from xml.dom.minidom import Document
doc = Document()
node1 = doc.createElement('one')
el1 = doc.createElement('e1')
el2 = doc.createElement('e1')
node1.appendChild(el1)
node1.appendChild(el2)
assert 2 == len(node1.childNodes) # ok
doc2 = Document()
node2 = doc2.createElement('two')
for el in node1.childNodes:
node2.appendChild(el)
assert 2 == len(node2.childNodes), "node2 has an unexpected number of
children"
--
http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping classes
Jeremy Sanders wrote:
> Peter Hansen wrote:
>
>
>>Almost anything is possible in Python, though whether the underlying
>>design idea is sound is a completely different question. (Translation:
>>try the following pseudo-code, but I have my suspicions about whether
>>what you're doing is a good idea. :-) )
>
>
> What I'd like to do precisely is to be able to evaluate an expression like
> "a+2*b" (using eval) where a and b are objects which behave like numarray
> arrays, but whose values aren't computed until their used.
Maybe you can do that by passing eval your own globals dictionary -
which in its __getitem__ method will then compute the value lazy.
The heck, we're in python. Lets try:
class Foo(object):
def __init__(self):
self.a = 10
self.b = 20
#return dict.__new__(self)
def __getitem__(self, key):
print "computing %s" % key
return getattr(self, key)
l = Foo()
print l.a
print eval("10 * a + b", globals(), l)
It works - in python 2.4!! I tried subclassing dict, but my
__getitem__-method wasn't called - most probably because it's a C-type,
but I don't know for sure. Maybe someone can elaborate on that?
Regards,
Diez
--
http://mail.python.org/mailman/listinfo/python-list
Re: Perl's documentation come of age
Mike wrote: > "Steve Holden" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >>Jim Hugunin's keynote speech at this year's PyCon was accompanied by a >>projection if his interactive interpreter session, and I know I wasn't >>alone in finding this a convincing example of Microsoft's (well, Jim's, >>really) full integration of Python into the .net framework. >>Steve Holden +44 150 684 7255 +1 800 494 3119 >>Holden Web LLC www.holdenweb.com >>PyCon TX 2006 www.pycon.org > > > Which .Net integreation technology are you speaking of? > BTW, PyCon.org seems to be down (at least not reachable from here at the > moment.) > > thanks > > I spoke of IronPython, which generates CLR code. I believe pycon.org will shortly re-emerge as a redirect to a subdirectory of the python.org domain, but I'm no longer in charge, so this may not be accurate. RSN ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
Re: C#3.0 and lambdas
> "Fredrik" == Fredrik Lundh <[EMAIL PROTECTED]> writes: > Reinhold Birkenfeld wrote: >>> And I think the discussion that followed proved your point perfectly >>> Fredrik. Big discussion over fairly minor things, but no "big picture". >>> Where are the initiatives on the "big stuff" (common documentation >>> format, improved build system, improved web modules, reworking the >>> standard library to mention a few) Hey, even Ruby is passing us here. >> >> This is Open Source. If you want an initiative, start one. > you know, this "you have opinions? fuck off!" attitude isn't really > helping. I agree. I am a lurker in this list and the python-devel list and I've also noticed that increasingly big discussions happen over fairly minor things. Python's DB API is still stuck at 2.0 and we can't even agree on a single parameter style while C# is innovating and moving ahead with the "big picture" stuff. I mean who really cares what's the exact syntax for the ternary operator. Python's white space significance was a shock when I first learnt python. I have learnt to live with it because there are a lot other things to like about the language. I'll live with whatever final decision on the ternary syntax or whether "and" and "or" should a boolean or the last expression. I'd like to see the DB API move forward, and experimental new innovations like static typing (with automatic type inferencing), stackless python etc. If the experiments don't survive, fine. It's still better than quibbling over minor syntactic detail. Ganesan -- Ganesan Rajagopal (rganesan at debian.org) | GPG Key: 1024D/5D8C12EA Web: http://employees.org/~rganesan| http://rganesan.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping classes
Diez B. Roggisch wrote:
> It works - in python 2.4!! I tried subclassing dict, but my
> __getitem__-method wasn't called - most probably because it's a C-type,
> but I don't know for sure. Maybe someone can elaborate on that?
Yes - I tried that (see thread below). Unfortunately it needs Python 2.4,
and I can't rely on my users having that.
Traceback (most recent call last):
File "test.py", line 15, in ?
print eval("10 * a + b", globals(), l)
TypeError: eval() argument 3 must be dict, not Foo
If you subclass dict it doesn't call the __getitem__ method.
Jeremy
--
Jeremy Sanders
http://www.jeremysanders.net/
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to show percentage
Sen-Lung Chen wrote: > Dear All: > I have a question of show percentage. > For example ,I want to show the percentage of 1/3 = 33.33% > > I use the 1*100/3 = 33 > it is 33 not 33.33 , how to show the 33.33 % > Thanks > You should by now know enough answers. The easiest way to ensure that the result is floating point is to cast it as pct = 100.0 * v) / N This is guaranteed to work in all past and future Python versions without setting any options. Then you can format is using the % operator. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
how to pickle unpicklable objects
Hi all, I've been writing an application containing a lot of settings which can be changed by the user. I'm using wx.Config to read/write these settings (to the windows registry). This means I can only store strings, ints and floats. However, it would be very convenient if I could also store more general objects. It seems to work for wx.Colour, but not for wx.Font. It raises a "TypeError: can't pickle PySwigObject objects". Does anybody a way to get around this? Is there some other module that would allow writing general (small) objects to the registry? Some sort of serialiser or something? TIA, g -- http://mail.python.org/mailman/listinfo/python-list
Re: Anyone else getting posts back as email undeliverable bounces?
I've even tried communicating with postmaster at all relevant domains, but such messages are either bounced or ignored, so I've just filtered that domain out. regards Steve Bengt Richter wrote: > It seems lately all my posts have been coming back to me as bounced emails, > and I haven't emailed them ;-( > > I've been getting bounce messages like (excerpt): > ... > ___ > > This is the Postfix program at host deimos.liage.net. > > I'm sorry to have to inform you that your message could not be > be delivered to one or more recipients. It's attached below. > > For further assistance, please send mail to > > If you do so, please include this problem report. You can > delete your own text from the attached returned message. > > The Postfix program > > <[EMAIL PROTECTED]>: Host or domain name not found. Name service error for > name=lindensys.net type=A: Host not found > Reporting-MTA: dns; deimos.liage.net > X-Postfix-Queue-ID: DC5264161 > X-Postfix-Sender: rfc822; [EMAIL PROTECTED] > Arrival-Date: Thu, 22 Sep 2005 19:50:13 -0400 (EDT) > > Final-Recipient: rfc822; [EMAIL PROTECTED] > Action: failed > Status: 5.0.0 > Diagnostic-Code: X-Postfix; Host or domain name not found. Name service error > for name=lindensys.net type=A: Host not found > Received: by deimos.liage.net (Postfix, from userid 126) > id DC5264161; Thu, 22 Sep 2005 19:50:13 -0400 (EDT) > Received: from smtp-vbr5.xs4all.nl (smtp-vbr5.xs4all.nl [194.109.24.25]) > by deimos.liage.net (Postfix) with ESMTP id 79D8340AA > for <[EMAIL PROTECTED]>; Thu, 22 Sep 2005 19:50:13 -0400 (EDT) > Received: from bag.python.org (bag.python.org [194.109.207.14]) > by smtp-vbr5.xs4all.nl (8.13.3/8.13.3) with ESMTP id j8MNoClb072177 > for <[EMAIL PROTECTED]>; Fri, 23 Sep 2005 01:50:12 +0200 (CEST) > (envelope-from [EMAIL PROTECTED]) > Received: from bag.python.org (bag [127.0.0.1]) > by bag.python.org (Postfix) with ESMTP id 8C4871E4013 > for <[EMAIL PROTECTED]>; Fri, 23 Sep 2005 01:50:10 +0200 (CEST) > _ > ... > > > Regards, > Bengt Richter -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.pycon.org -- http://mail.python.org/mailman/listinfo/python-list
ANN: Voidspace Updates - Jalopy, logintools, textmacros, downman (etc)
Hello All, There have been various updates to the Voidspace modules : Jalopy 0.6.0 http://www.voidspace.org.uk/python/cgi.shtml#jalopy A collaborative website designer (CGI). It uses Kupu (http://kupu.oscom.org ) the WYSIWYG HTML editor. This update moves to Kupu 1.3 and the pythonutils 0.2.2 set of modules. logintools 0.6.0 http://www.voidspace.org.uk/python/cgi.shtml#logintools A CGI framework for user authentication and account management. Add user login to your CGI applications with two lines of code ! This update moves to the pythonutils 0.2.2 set of modules. logintools is now being used on another project and seeing some development work. textmacros http://www.voidspace.org.uk/python/modules.shtml#macros A textmacro system for adding features to docutils (http://docutils.sourceforge.net ). This update makes it *much* easier to use (it now behaves like the ``buildhtml.py`` script). Easily add Python source coloring, smilies, and accronyms (and much more) to reStructured Text. downman 0.4.1 http://www.voidspace.org.uk/python/cgi.shtml#downman A CGI download manager. Present files for download and statistics (basic) about download rates. This update has a security fix and uses the pythonutils 0.2.2 set of modules. Also other minor updates. It also needs the updated version of cgiutils. cgiutils 0.3.3 http://www.voidspace.org.uk/python/recipebook.shtml#utils A helpful set of constants and functions when working with CGI scripts. This update has two bugfixes. copy2cgi 1.1.1 http://www.voidspace.org.uk/python/recipebook.shtml#copy2cgi A small convenience script to copy files and directories to a target location. Useful for copying files to a server directory for testing. pycrypto 2.0.1 http://www.voidspace.org.uk/python/modules.shtml#pycrypto I've (finally) updated the prebuild windows binary of PyCrypto (Python 2.4) to the 2.0.1 version. All the best, Fuzzyman http://www.voidspace.org.uk/python/weblog/index.shtml All the Voidspace modules and applications are available under the OSI Approved Open Source BSD License - http://www.voidspace.org.uk/python/license.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping classes
Jeremy Sanders wrote:
> Diez B. Roggisch wrote:
>
>
>>It works - in python 2.4!! I tried subclassing dict, but my
>>__getitem__-method wasn't called - most probably because it's a C-type,
>>but I don't know for sure. Maybe someone can elaborate on that?
>
>
> Yes - I tried that (see thread below). Unfortunately it needs Python 2.4,
> and I can't rely on my users having that.
>
> Traceback (most recent call last):
> File "test.py", line 15, in ?
> print eval("10 * a + b", globals(), l)
> TypeError: eval() argument 3 must be dict, not Foo
>
> If you subclass dict it doesn't call the __getitem__ method.
Could it work with a UserDict subclass ?
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])"
--
http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping classes
bruno modulix wrote:
> Could it work with a UserDict subclass ?
Unfortunately not:
Traceback (most recent call last):
File "test.py", line 17, in ?
print eval("10 * a + b", globals(), l)
TypeError: eval() argument 3 must be dict, not instance
Thanks
Jeremy
--
Jeremy Sanders
http://www.jeremysanders.net/
--
http://mail.python.org/mailman/listinfo/python-list
Re: minidom appendChild confusion
Marco wrote:
> Can anyone explain why the following code does not work?
> (I'm using python2.4.)
> # the following code does _not_ work.
> # intended: put child-nodes as children to another node
>
> from xml.dom.minidom import Document
> doc = Document()
> node1 = doc.createElement('one')
> el1 = doc.createElement('e1')
> el2 = doc.createElement('e1')
> node1.appendChild(el1)
> node1.appendChild(el2)
> assert 2 == len(node1.childNodes) # ok
>
> doc2 = Document()
> node2 = doc2.createElement('two')
>
> for el in node1.childNodes:
> node2.appendChild(el)
A node added to node2's children is implicitly removed from node1's
children. So you are iterating over the node1.childNodes list while
altering it, which typically results in skipping every other item:
>>> a = list("abcde")
>>> for i in a:
... a.remove(i)
...
>>> a
['b', 'd']
You can avoid that by making a copy of node1.childNodes:
for el in list(node1.childNodes):
node2.appendChild(el)
> assert 2 == len(node2.childNodes), "node2 has an unexpected number of
> children"
Peter
--
http://mail.python.org/mailman/listinfo/python-list
Re: Finding where to store application data portably
On Thu, 22 Sep 2005 19:09:28 +0400, en.karpachov wrote: > There is an other way around: look at your home dir as if it is your > "settings" dir and don't clutter it with files other than application > config dot-files. Just make ~/files/, ~/bin/ ~/lib/ etc. for it. Do you put everything into /etc (/etc/bin, /etc/var, /etc/usr, /etc/mnt, and so forth)? If your home directory is for settings, why would you store files and binaries inside your settings directory? I understand the historical reasons for why ~/ is treated as a structureless grab-bag of everything and anything. That made sense back in the distant past when users used dumb terminals and they had perhaps half a dozen dot files. But at the point your home directory has three times as many dot files as regular files, the time has come to stop doing things just because that's the way they have always been done. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to use a timer in Python?
Nico Grubert <[EMAIL PROTECTED]> wrote:
> There is no cronjob anymore now. I just need to check if there is a lock
> file. How would you modify my short program to avoid the situation "Ie
> someone can get in there after you read the directory but before
> you create the file."?
You can't do it with files.
You can do it with directories though...
Both processes need to be using the same lock, so something like this
(all untested ;-)
import os
import time
WINDOWS_SHARE = 'C:\\Temp'
lock_file = os.path.join(WINDOWS_SHARE, "transfer.lock")
gained_lock = False
while not gained_lock:
try:
os.mkdir(lock_file)
gained_lock = True
except OSError:
print "Busy, please wait..."
time.sleep(10)
f = open(WINDOWS_SHARE + '/myfile', 'w')
f.write("test 123")
f.close()
os.rmdir(lock_file)
print "Done!"
You need to do the same thing to the program which currently creates
transfer.lock - so it waits if the transfer.lock is in existence too.
--
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
--
http://mail.python.org/mailman/listinfo/python-list
Re: minidom appendChild confusion
That's it. Thank you very much! Marco -- http://mail.python.org/mailman/listinfo/python-list
Re: What is "self"?
Ron Adam <[EMAIL PROTECTED]> wrote: > You can actually call it anything you want but "self" is sort of a > tradition. That's true, but I think needs to be said a bit more emphatically. There's no reason to call it anything other than "self" and a newcomer to the language would be well advised to not try and be creative here. Using "self" is virtually universal, and calling it anything else will just lead to confusion by other people who have to read your code. -- http://mail.python.org/mailman/listinfo/python-list
Re: C#3.0 and lambdas
On Fri, 23 Sep 2005 15:46:54 +0530, Ganesan Rajagopal <[EMAIL PROTECTED]> wrote: > I agree. I am a lurker in this list and the python-devel list and I've also > noticed that increasingly big discussions happen over fairly minor > things. Python's DB API is still stuck at 2.0 and we can't even agree on a > single parameter style while C# is innovating and moving ahead with the "big > picture" stuff. The group of committers is a diverse group of people, and not every one of them uses a relational database; that effort would be better done on the DB-SIG mailing list, because the people there presumably do all use an RDBMS. (Now, if you wanted to include SQLite in core Python, that *would* be a python-dev topic, and ISTR it's been brought up in the past.) This is also something the PSF might fund. The next time the PSF calls for grant proposals, someone could request funding to edit a new revision of the DB-API. > I'd like to see the DB API move forward, and experimental new innovations > like static typing (with automatic type inferencing), stackless python > etc. If the experiments don't survive, fine. It's still better than > quibbling over minor syntactic detail. Agreed; python-dev has gotten pretty boring with all the endless discussions over some minor point. Of course, it's much easier and lower-effort to propose a syntax or nitpick a small point issue than to tackle a big complicated issue like static typing. Similar things happen on the catalog SIG: people suggest, or even implement, an automatic package management system, But bring up the question of whether it should be called PyPI or Cheeseshop or the Catalog, and *everyone* can make a suggestion. --amk -- http://mail.python.org/mailman/listinfo/python-list
Re: Alternatives to Stackless Python?
Christophe wrote: > [EMAIL PROTECTED] a écrit : > >>> I found LGT http://lgt.berlios.de/ but it didn't seem as if the >>> NanoThreads module had the same capabilites as stackless. >> >> What specific capabilities of Stackless are you looking for, that are >> missing from NanoThreads? > > Capabilities of the different "threadlike" systems are somewhat muddy. > What myself I like in stackless is : > - you can put context switching instuctions anywhere in the callstack > without having to explicitely chain the operation > - pickle support > > Not sure if greenlets support pickling yet. There are no info on that > point and my tests weren't succesful. The greenlets play with the underlying CPU stack directly so I don't think they could ever be pickled. -- http://mail.python.org/mailman/listinfo/python-list
File processing
Hello, I'm Gopal. I'm looking for a solution to the following problem: I need to create a text file config.txt having some parameters. I'm thinking of going with this format by having "Param Name - value". Note that the value is a string/number; something like this: PROJECT_ID = "E4208506" SW_VERSION = "18d" HW_VERSION = "2" In my script, I need to parse this config file and extract the Values of the parameters. I'm very new to python as you can understand from the problem. However, I've some project dealines. So I need your help in arriving at a simple and ready-made solution. Regards, Gopal. -- http://mail.python.org/mailman/listinfo/python-list
replacments for stdio?
hi, i was wondering if anyone have written a GUI module that can function as a replacment for stdin/stdout? ie. has a file like interface, by which one could just assaign it to sys.stdout or sys.stdin and have all your prints and raw_inputs and other such things shown in a GUI window? Thanks in advance, Ido Yehieli. -- http://mail.python.org/mailman/listinfo/python-list
Re: File processing
The ConfigParser class is designed for this task, see http://docs.python.org/lib/module-ConfigParser.html -- http://mail.python.org/mailman/listinfo/python-list
Using distutils 2.4 for python 2.3
Hello, I want to distribute a package. It's compatible with Python 2.3. Is there a way to use distutils 2.4 feature package_data, while maintaining the distribution compatible with python 2.3 ? Thanks, Noam Raphael -- http://mail.python.org/mailman/listinfo/python-list
Re: Sniffing Text Files
On Fri, 23 Sep 2005 01:20:49 -0300, David Pratt wrote:
> Hi. I have files that I will be importing in at least four different
> plain text formats, one of them being tab delimited format, a couple
> being token based uses pipes (but not delimited with pipes), another
> being xml. There will likely be others as well but the data needs to be
> extracted and rewritten to a single format. The files can be fairly
> large (several MB) so I do not want to read the whole file into memory.
Why ever not? On modern machines, "several MB" counts as small files. Let
your operating system worry about memory, at least until you get to really
big (several hundred megabytes) files.
> What approach would be recommended for sniffing the files for the
> different text formats.
In no particular order:
(1) Push the problem onto the user: they specify what sort of file they
think it is. If they tell your program the file is XML when it is in fact
a CSV file, your XML importer will report back that that the input file is
a broken XML file.
(2) Look at the file extension (.xml, .csv, .txt, etc) and assume that it
is correct. If the user gives you an XML file called "data.csv", you can
hardly be blamed for treating it wrong. This behaviour is more accepted
under Windows than Linux or Macintosh.
(3) Use the Linux command "file" to determine the contents of the file.
There may be equivalents on other OSes.
(4) Write your own simple scanner that tries to determine if the file is
xml, csv, tab-delimited text, etc. A basic example:
(Will need error checking and hardening)
def sniff(filename):
"""Return one of "xml", "csv", "txt" or "tkn", or "???"
if it can't decide the file type.
"""
fp = open(filename, "r")
scores = {"xml": 0, "csv": 0, "txt": 0, "tkn": 0}
for line in fp.readlines():
if not line:
continue
if line[0] == "<":
scores["xml"] += 1
if '\t' in line:
scores["txt"] += 1
if ',' in line:
scores["csv"] += 1
if SOMETOKEN in line:
scores["csv"] += 1
# Pick the best guess:
L = [(score, name) for (name, score) in scores.items()]
L.sort()
L.reverse()
# L is now sorted from highest down to lowest by score.
best_guess = L[0]
second_best_guess = L[0]
if best_guess[0] > 10*second_best_guess[0]:
fp.close()
return best_guess[1]
fp.close()
return "???"
Note that the above code really isn't good enough for production work, but
it should give you an idea how to proceed.
Hope that helps.
--
Steven.
--
http://mail.python.org/mailman/listinfo/python-list
Re: What is "self"?
Roy Smith <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Ron Adam <[EMAIL PROTECTED]> wrote: >> You can actually call it anything you want but "self" is sort >> of a tradition. > > That's true, but I think needs to be said a bit more > emphatically. There's no reason to call it anything other than > "self" and a newcomer to the language would be well advised to > not try and be creative here. Using "self" is virtually > universal, and calling it anything else will just lead to > confusion by other people who have to read your code. I've long thought that Guido missed an opportunity by not choosing to use 'i' as the instance identifier, and making it a reserved word. For one thing, it would resonate with the personal pronoun 'I', and so carry essentially the same meaning as 'self'. It could also be understood as an initialism for 'instance'. And, because it is shorter, the number of objections to its existence *might* have been smaller than seems to be the case with 'self' as the convention. And as a side benefit, it would make it impossible to use as a loop index a language feature that would be a huge selling point among a lot of experienced programmers. -- rzed -- http://mail.python.org/mailman/listinfo/python-list
Re: Alternatives to Stackless Python?
Olivier Dormond a écrit : > Christophe wrote: > >> [EMAIL PROTECTED] a écrit : >> I found LGT http://lgt.berlios.de/ but it didn't seem as if the NanoThreads module had the same capabilites as stackless. >>> >>> >>> What specific capabilities of Stackless are you looking for, that are >>> missing from NanoThreads? >> >> >> Capabilities of the different "threadlike" systems are somewhat muddy. >> What myself I like in stackless is : >> - you can put context switching instuctions anywhere in the callstack >> without having to explicitely chain the operation >> - pickle support >> >> Not sure if greenlets support pickling yet. There are no info on that >> point and my tests weren't succesful. > > > The greenlets play with the underlying CPU stack directly so I don't > think they could ever be pickled. Then they are useless for nearly all the uses cases I need them :/ And that's why stackless is still relevant here. Or maybe pypy too but it's still a long time to go. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to pickle unpicklable objects
interesting. usually the [pickle | cpickle | marshal] modules should handle such things -- http://mail.python.org/mailman/listinfo/python-list
Re: File processing
Gopal wrote: >Hello, > >I'm Gopal. I'm looking for a solution to the following problem: > >I need to create a text file config.txt having some parameters. I'm >thinking of going with this format by having "Param Name - value". Note >that the value is a string/number; something like this: > >PROJECT_ID = "E4208506" >SW_VERSION = "18d" >HW_VERSION = "2" > >In my script, I need to parse this config file and extract the Values >of the parameters. > >I'm very new to python as you can understand from the problem. However, >I've some project dealines. So I need your help in arriving at a simple >and ready-made solution. > >Regards, >Gopal. > > > Would this (http://www.python.org/doc/current/lib/module-ConfigParser.html) do what you need? It's part of the standard library. - JMJ -- http://mail.python.org/mailman/listinfo/python-list
Re: File processing
Thanks for the reference. However, I'm not understanding how to use it. Could you please provide with an example? Like I open the file, read line and give it to parser? Please help me. -- http://mail.python.org/mailman/listinfo/python-list
Re: File processing
Gopal wrote: > Hello, > > I'm Gopal. I'm looking for a solution to the following problem: > > I need to create a text file config.txt having some parameters. I'm > thinking of going with this format by having "Param Name - value". Note > that the value is a string/number; something like this: > > PROJECT_ID = "E4208506" > SW_VERSION = "18d" > HW_VERSION = "2" > > In my script, I need to parse this config file and extract the Values > of the parameters. > > I'm very new to python as you can understand from the problem. However, > I've some project dealines. So I need your help in arriving at a simple > and ready-made solution. Luckily, you're already done! Just make sure the above file has a .py extension, say maybe "config.py", and then in code where you need to "parse" it and extract the values you can just do this: import config print 'Project Id is', config.PROJECT_ID -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: What is "self"?
Rick Wotnaz wrote: > Roy Smith <[EMAIL PROTECTED]> wrote in > news:[EMAIL PROTECTED]: > > >>Ron Adam <[EMAIL PROTECTED]> wrote: >> >>>You can actually call it anything you want but "self" is sort >>>of a tradition. >> >>That's true, but I think needs to be said a bit more >>emphatically. There's no reason to call it anything other than >>"self" and a newcomer to the language would be well advised to >>not try and be creative here. Using "self" is virtually >>universal, and calling it anything else will just lead to >>confusion by other people who have to read your code. > > > I've long thought that Guido missed an opportunity by not choosing > to use 'i' as the instance identifier, and making it a reserved > word. For one thing, it would resonate with the personal pronoun > 'I', and so carry essentially the same meaning as 'self'. It could > also be understood as an initialism for 'instance'. And, because it > is shorter, the number of objections to its existence *might* have > been smaller than seems to be the case with 'self' as the > convention. > > And as a side benefit, it would make it impossible to use as a loop > index a language feature that would be a huge selling point among a > lot of experienced programmers. And an annoyance to others. -- http://mail.python.org/mailman/listinfo/python-list
Re: Character Sequence Generation
Pedro Werneck wrote:
> On Thu, 22 Sep 2005 23:26:58 -0400
> Jeff Schwab <[EMAIL PROTECTED]> wrote:
>
>
>>What's the best way to generate a sequence of characters in Python?
>>I'm looking for something like this Perl code: 'a' .. 'z' .
>
>
> If you want arbitrary sequences, you may use something like:
>
>
>
[chr(x) for x in xrange(ord('a'), ord('z') + 1)]
>
> ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
> 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
>
>
[chr(x) for x in xrange(ord('d'), ord('p') + 1)]
>
> ['d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p']
>
>
[chr(x) for x in xrange(ord('A'), ord('Z') + 1)]
>
> ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
> 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
>
> etc...
>
Thanks, that's exactly what I want!
--
http://mail.python.org/mailman/listinfo/python-list
Re: File processing
Thank you very much. That works!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: Using distutils 2.4 for python 2.3
"Noam Raphael" <[EMAIL PROTECTED]> wrote: > Hello, > > I want to distribute a package. It's compatible with Python 2.3. > Is there a way to use distutils 2.4 feature package_data, while > maintaining the distribution compatible with python 2.3 ? > > Thanks, > Noam Raphael You could distribute the whole 2.4 distutils package in yours so that setup.py finds it before the default one. If distutils 2.4 is compatible with 2.3, that should work. George -- http://mail.python.org/mailman/listinfo/python-list
Re: File processing
Gopal wrote:
>Thanks for the reference. However, I'm not understanding how to use it.
>Could you please provide with an example? Like I open the file, read
>line and give it to parser?
>
>Please help me.
>
>
>
I had thought of recommending what Peter Hansen recommended - just
importing the text you have as a Python module. I don't know why I
recommended ConfigParser over that option. However, if you don't like
what Peter said and would still like to look at ConfigParser, here is a
very simple example. Here is the config file I created from your email:
[EMAIL PROTECTED] 8:36AM configparser % cat foo.txt
[main]
PROJECT_ID = "E4208506"
SW_VERSION = "18d"
HW_VERSION = "2"
Here is me running ConfigParser from a Python shell:
In [1]: import ConfigParser
In [2]: p = ConfigParser.ConfigParser()
In [3]: p.read("foo.txt")
Out[3]: ['foo.txt']
In [4]: p.get("main", "PROJECT_ID")
Out[4]: '"E4208506"'
Note that the value of ("main", "PROJECT_ID") is a string which contains
double quotes in it. If you take Peter's advice, you won't have that
problem; the config file will preserve your types for you.
HTH,
- JMJ
--
http://mail.python.org/mailman/listinfo/python-list
ANN: python-ldap-2.0.10
Find a new release of python-ldap: http://python-ldap.sourceforge.net/ python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAPURLs and LDAPv3 schema). Released 2.0.10 2005-09-23 Changes since 2.0.9: Lib/ * Switched back to old implementation of ldap.schema.tokenizer.split_tokens() since the new one had a bug which deletes the spaces from DESC * ldap.INSUFFICIENT_ACCESS is now ignored in ldap.ldapobject.LDAPObject.search_subschemasubentry_s() -- http://mail.python.org/mailman/listinfo/python-list
Re: Using distutils 2.4 for python 2.3
Noam Raphael wrote: > I want to distribute a package. It's compatible with Python 2.3. > Is there a way to use distutils 2.4 feature package_data, while > maintaining the distribution compatible with python 2.3 ? you can enable new metadata fields in older versions by assigning to the DistributionMetadata structure: try: from distutils.dist import DistributionMetadata DistributionMetadata.package_data = None except: pass setup( ... package_data=... ) -- http://mail.python.org/mailman/listinfo/python-list
Re: C#3.0 and lambdas
[amk] > Similar things happen on the catalog SIG: people suggest, or even implement, > an automatic package management system, But bring up the question of whether > it should be called PyPI or Cheeseshop or the Catalog, and *everyone* can make > a suggestion. This is known as the "bike shed effect": http://linuxmafia.com/~rick/lexicon.html#bikeshed -- Richie Hindle [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: C#3.0 and lambdas
"A.M. Kuchling" <[EMAIL PROTECTED]> writes: > Agreed; python-dev has gotten pretty boring with all the endless discussions > over some minor point. Of course, it's much easier and lower-effort to > propose a syntax or nitpick a small point issue than to tackle a big > complicated issue like static typing. > > Similar things happen on the catalog SIG: people suggest, or even implement, > an automatic package management system, But bring up the question of whether > it should be called PyPI or Cheeseshop or the Catalog, and *everyone* can make > a suggestion. This is a well-known phenomenon, having picked up the name "bikeshed" something like 40 years ago. Google for "bikeshed color". Or just check out the FreeBSD FAQ entry at http://www.bikeshed.com/ >. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping classes
Jeremy Sanders wrote:
> Peter Hansen wrote:
>
>
>>Almost anything is possible in Python, though whether the underlying
>>design idea is sound is a completely different question. (Translation:
>>try the following pseudo-code, but I have my suspicions about whether
>>what you're doing is a good idea. :-) )
>
>
> What I'd like to do precisely is to be able to evaluate an expression like
> "a+2*b" (using eval) where a and b are objects which behave like numarray
> arrays, but whose values aren't computed until their used.
Could you not have functions a and b each of which returns a NumArray
instance?
Your expression would then be something like a(..)+2*b(..).
Colin W.
>
> I need to compute the values when used because the arrays could depend on
> each other, and the easiest way to get the evaluation order correct is to
> only evaluate them when they're used.
>
> An alternative way is to do some string processing to replace a with
> computearray("a") in the expression or something horrible like that.
>
> Thanks
>
> Jeremy
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Question About Logic In Python
On Thursday 22 September 2005 07:09 pm, Ron Adam wrote: > Terry Hancock wrote: > > On Thursday 22 September 2005 12:26 pm, Ron Adam wrote: > True and True > > > > True > > > > Also makes sense (and this is indeed what happens). > > Only because True is the last value here. ;-) Nope, works for False, too: >>> True and False False I see what you mean, but if you were mixing types, then you probably wanted the "value preserved" behavior. If both objects are bool, the result is too (even if this is only a coincidence, it still happens to be true). So this still makes sense: >>> True and 1 1 Effectively, what you'd be asking for is to have bool coerce more strongly than ints or other types, so that results would become boolean if any boolean argument existed. But that would be a pretty major change in Python, and break lots of code. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrapping classes
Colin J. Williams wrote: > Could you not have functions a and b each of which returns a NumArray > instance? > > Your expression would then be something like a(..)+2*b(..). The user enters the expression (yes - I'm aware of the possible security issues), as it is a scientific application. I don't think they'd like to put () after each variable name. I could always munge the expression after the user enters it, of course. Jeremy -- Jeremy Sanders http://www.jeremysanders.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: how to pickle unpicklable objects
Guy Lateur schrieb:
> Hi all,
>
> I've been writing an application containing a lot of settings which can be
> changed by the user. I'm using wx.Config to read/write these settings (to
> the windows registry). This means I can only store strings, ints and floats.
>
> However, it would be very convenient if I could also store more general
> objects. It seems to work for wx.Colour, but not for wx.Font. It raises a
> "TypeError: can't pickle PySwigObject objects".
The object is wrapped by SWIG. So, python can not know anything about it
and the object can not be pickled.
As far as I see, there are two possibilities
- define __getstate__ and __setstate__ in the c/c++-source or the .i
file (used by swig). This is only possible if the source is available
- use copy_reg (http://docs.python.org/lib/module-copyreg.html) to
register a 'reduce' function (I never used that).
I use the first option in the .i-File for a wrapped c++-class like this:
%extend UMDMResult {
%insert("python") %{
def __getstate__(self):
return (self.v,self.u,self.l,self.unit,self.Z0,self.Eta0,self.t)
def __setstate__(self,tup):
self.this = _umddevice.new_UMDMResult(tup[0],tup[1],tup[2],tup[3])
self.thisown=1
(self.Z0,self.Eta0,self.t)=[i for i in tup[4:]]
%}
}
regards
Hans Georg Krauthaeuser
--
http://mail.python.org/mailman/listinfo/python-list
Re: Sniffing Text Files
Thanks Mike for your reply. I am not aware of libmagic and will look to see what it provides. As far as your first suggestion, this is what I have been looking at - probably a combination regex and readlines or similar but trying to get a better sense of best sort of approach more or less. I can't rely on file extensions in this case so believing the content will be what the file extension indicates would not be so good. Mime types can be helpful but don't always give you the full story either - so the need to sniff in the first place so I can apply the right process to the file. As it stands I am filtering mime types to the importing process to attempt to limit the possibilities. Regards, David On Friday, September 23, 2005, at 02:01 AM, Mike Meyer wrote: > David Pratt <[EMAIL PROTECTED]> writes: > >> Hi. I have files that I will be importing in at least four different >> plain text formats, one of them being tab delimited format, a couple >> being token based uses pipes (but not delimited with pipes), another >> being xml. There will likely be others as well but the data needs to >> be extracted and rewritten to a single format. The files can be fairly >> large (several MB) so I do not want to read the whole file into >> memory. What approach would be recommended for sniffing the files for >> the different text formats. I realize CSV module has a sniffer but it >> is something that is limited more or less to delimited files. I have >> a couple of ideas on what I could do but I am interested in hearing >> from others on how they might handle something like this so I can >> determine the best approach to take. Many thanks. > > With GB memory machines being common, I wouldn't think twice about > slurping a couple of meg into RAM to examine. But if that's to much, > how about simply reading in the first bytes, and checking that > for the characters you want? should be large enough to reveal > what you need, but small enogh that your'e comfortable reading it > in. I'm not sure that there aren't funny interactions between read and > readline, so do be careful with that. > > Another approach to consider is libmagic. Google turns up a number of > links to Python wrappers for it. > >-- > Mike Meyer <[EMAIL PROTECTED]> > http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, email for more > information. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Sniffing Text Files
David> I realize CSV module has a sniffer but it is something that is David> limited more or less to delimited files. Sure. How about: def sniff(fname): if open(fname).read(4) == "http://www.musi-cal.com/katrina [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: C#3.0 and lambdas
> A M Kuchling <[EMAIL PROTECTED]> writes: > The group of committers is a diverse group of people, and not every one of > them uses a relational database; that effort would be better done on the > DB-SIG mailing list, because the people there presumably do all use an > RDBMS. (Now, if you wanted to include SQLite in core Python, that *would* > be a python-dev topic, and ISTR it's been brought up in the past.) I would definitely love to see SQLite included in core python. I am a Unix systems/networking programmer myself. Just like the fact that everything looks like a database programmers to most database, I've observed that the reverse is true for non database programmers. In other words, most non RDMS normally don't think of a database even the solution screams for a database. I think SQLite does an amazing job in bridging this gap. > Agreed; python-dev has gotten pretty boring with all the endless discussions > over some minor point. Of course, it's much easier and lower-effort to > propose a syntax or nitpick a small point issue than to tackle a big > complicated issue like static typing. You have a point there :-). > Similar things happen on the catalog SIG: people suggest, or even > implement, an automatic package management system, But bring up the > question of whether it should be called PyPI or Cheeseshop or the Catalog, > and *everyone* can make a suggestion. My memory may not be perfect but I remember reading that Python 2.5's focus is libraries and no language changes. If that's correct, I can understand why core python folks are more interested in discussing language features for Python 3000 ;-). Speaking of libraries, I haven't seen many discussions on libraries in python-dev. Is there some other list with more discussions on libraries? Ganesan -- Ganesan Rajagopal (rganesan at debian.org) | GPG Key: 1024D/5D8C12EA Web: http://employees.org/~rganesan| http://rganesan.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Productivity and economics at software development
Hi folks, I'm making a little research project about programming languages e their respective IDEs. The goal is to trace each language silhouettes, where it fits better, their goods/bads and the costs of developing in this language. It's easy to find projects that doesn't worked as expected because they were develop with the wrong toolkit, or people that now dislike a given language because didn't know where the language is better used. To provide a good quality research, with results that near reality, I need the help of the community to answer my survey. This survey doesn't ask any information that identifies the person who answer the questions and is super fast to be answered. The average time to fill out the survey is 50 seconds. The survey: http://www.globalred.com.br/quest The results and the research will be released as soons as they get ready. Thank you for your cooperation! Cheers! --- Adriano Monteiro Marques http://umit.sourceforge.net http://www.globalred.com.br -- http://mail.python.org/mailman/listinfo/python-list
Re: C#3.0 and lambdas
Erik Wilsher wrote: > And I think the discussion that followed proved your point perfectly > Fredrik. Big discussion over fairly minor things, but no "big > picture". Where are the initiatives on the "big stuff" (common > documentation format, improved build system, improved web modules, > reworking the standard library to mention a few) Hey, even Ruby is > passing us here. Reinhold Birkenfeld wrote: > This is Open Source. If you want an initiative, start one. Fredrik Lundh wrote: > you know, this "you have opinions? fuck off!" attitude isn't really helping. While I should know better than replying to , ;) I have to say that I don't think "you have opinions? fuck off!" was the intent at all. I don't know many people who'd argue that we don't need: * more complete and better organized documentation * a simpler build/install system * etc. But they'll never get done if no one volunteers to work on them. Recently, I saw a volunteer on python-dev looking to help make the docs more complete, and he was redirected to the docs SIG to help out. This is good. I know that there's been a bunch of work on setuptools[1] that's supposed to be a real improvement on distutils. This is also goood. But there're only so many man-hours available to work on these projects. If you see a problem, and you want it fixed, the right thing to do is to donate some of your time to a project that needs it. This, I believe, is the essence of Reinhold Birkenfeld's comment. STeVe [1]http://peak.telecommunity.com/DevCenter/setuptools -- http://mail.python.org/mailman/listinfo/python-list
Re: Using distutils 2.4 for python 2.3
Fredrik Lundh wrote: > > you can enable new metadata fields in older versions by assigning to > the DistributionMetadata structure: > > try: > from distutils.dist import DistributionMetadata > DistributionMetadata.package_data = None > except: > pass > > setup( > ... > package_data=... > ) > > I tried this, but it made python2.4 behave like python2.3, and not install the package_data files. Did I do something wrong? -- http://mail.python.org/mailman/listinfo/python-list
Re: What is "self"?
Rick Wotnaz <[EMAIL PROTECTED]> wrote: >I've long thought that Guido missed an opportunity by not choosing >to use 'i' as the instance identifier, and making it a reserved >word. For one thing, it would resonate with the personal pronoun >'I', and so carry essentially the same meaning as 'self'. It could >also be understood as an initialism for 'instance'. And, because it >is shorter, the number of objections to its existence *might* have >been smaller than seems to be the case with 'self' as the >convention. My first serious forays into Python, where no-one else was expected to be maintaining the code, used 'I' instead of 'self' -- it's shorter, stands out better, and 'I.do_something()' reads more like English than 'self.do_something()' (unless, I suppose, you're thinking in terms of message passing). Then I started working on code which other people might need to look at, and got an editor whose Python syntax highlighting pretended that 'self' was a reserved word, and now all my old code looks odd. (But still perfectly readable -- this is Python after all.) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: Productivity and economics at software development
I get this:
Mod_python error: "PythonHandler mod_python.publisher"
Traceback (most recent call last):
File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line
299, in HandlerDispatch
result = object(req)
File "/usr/lib/python2.3/site-packages/mod_python/publisher.py", line
136, in handler
result = util.apply_fs_data(object, req.form, req=req)
File "/usr/lib/python2.3/site-packages/mod_python/util.py", line 361,
in apply_fs_data
return object(**args)
File "/var/www/html/quest/index.py", line 156, in gravar
cursor.execute(sql)
File "/usr/lib/python2.3/site-packages/pgdb.py", line 163, in execute
self.executemany(operation, (params,))
File "/usr/lib/python2.3/site-packages/pgdb.py", line 185, in
executemany
raise DatabaseError, "error '%s' in '%s'" % ( msg, sql )
DatabaseError: error 'ERROR: value too long for type character
varying(2)
' in 'INSERT INTO questionario (
linguagem, rad, preco_rad, linux,
macosx, palmos, solaris, windows,
windowsce, outras_plataformas, treinamento,
desktop, modo_texto, paginas_web, celular,
palm, outras_aplicacoes, dificuldade,
tempo, dependencia, duracao, novo_programador,
comentario, moeda)
VALUES
('false', 'false', 0.0, true,
true, false, false, true, false,
false, 0.0, true, true,
true, false, false, false,
1, 4, 2, 0.5, 1000.0,
'false', 'false')'
--
http://mail.python.org/mailman/listinfo/python-list
Re: What is "self"?
On Friday 23 September 2005 07:11 am, Rick Wotnaz wrote: > I've long thought that Guido missed an opportunity by not choosing > to use 'i' as the instance identifier, and making it a reserved > word. For one thing, it would resonate with the personal pronoun > 'I', and so carry essentially the same meaning as 'self'. It could > also be understood as an initialism for 'instance'. And, because it > is shorter, the number of objections to its existence *might* have > been smaller than seems to be the case with 'self' as the > convention. > > And as a side benefit, it would make it impossible to use as a loop > index a language feature that would be a huge selling point among a > lot of experienced programmers. How exactly is that? Anybody who uses "i" as a variable name for anything other than an innermost loop index is a sick and twisted code sadist. You'd prefer what? "count" or "kount" or "i_am_an_innermost_loop_index_counter". I mean "explicit is better than implicit", right? Maybe Fortran warped my brain, but I just don't see the benefit here. -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Productivity and economics at software development
Adriano Monteiro wrote: > Hi folks, > I'm making a little research project about programming languages e > their respective IDEs. The goal is to trace each language silhouettes, > where it fits better, their goods/bads and the costs of developing in > this language. What do you consider the IDE for Assembly code or Microcode? --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Single type for __builtins__ in Py3.0
Hallo all, As it currently stands, the type of the global __builtins__ differs depending on whether you're in the __main__ namespace (__builtins__ is a module) or not (its a dict). I was recently tripped up by this discrepancy, and googling the issue brings up half-a-dozen or so c.l.p threads where others have been bitten by this, too. I'd like to propose that in Py3.0 (if not earlier), __builtins__ will be the same type regardless of which namespace you're in. Tim Peters has said [1] that the reason __builtins__ in __main__ is a module so that "the curious don't get flooded with output when doing vars() at the prompt". Based on this, I propose that __builtins__ be a module (really, an alias for the __builtin__ module as it is now) in all namespaces. If possible, I'd like to see this go in before 3.0. The reference manual currently states [2] that __builtins__ can be either a dict or a module, so changing it to always be a module would still be in keeping with this. However, I realise that there's probably code out there that hasn't been written to deal with both types, so this would result in some minor breakage (though it would be easily fixable). If this gets a good response, I'll kick it up to python-dev. Thanks, Collin Winter [1] http://mail.python.org/pipermail/python-list/2002-May/103613.html [2] http://www.python.org/doc/2.4.1/ref/naming.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Sniffing Text Files
David Pratt <[EMAIL PROTECTED]> writes: > Thanks Mike for your reply. I am not aware of libmagic and will look > to see what it provides. and ... Skip Montanaro <[EMAIL PROTECTED]> writes: > You can also run the file(1) command and see what it says. I seem > to recall someone asking about the equivalent to file(1) implemented in > Python awhile back. libmagic is the smarts of the file command. As I said before, people have done Python wrappers for it. It uses a text database describing how to recognize a files type - see the magic(5) man page for details on that. If you use libmagic, you'll probably want to provide your own version of the databse, excerpted to include just the file types you want to recognize. You can check on whether or not this will work for you by seeing what the file command says about your sample data. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: Sniffing Text Files
Hi Skip. Thank you for your reply. This is helpful and I am glad I put this to the list. There are some really good ideas that will help me come up with something good to use. Regards, David On Friday, September 23, 2005, at 11:14 AM, [EMAIL PROTECTED] wrote: > > David> I realize CSV module has a sniffer but it is something that > is > David> limited more or less to delimited files. > > Sure. How about: > > def sniff(fname): > if open(fname).read(4) == " return "xml" > else: > # assume csv - use its sniffer to generate a dialect > return d > > Of course, as the number of file formats grows, you'll need to expand > the > logic. You can also run the file(1) command and see what it says. I > seem > to recall someone asking about the equivalent to file(1) implemented in > Python awhile back. > > -- > Skip Montanaro > Katrina Benefit Concerts: http://www.musi-cal.com/katrina > [EMAIL PROTECTED] > -- http://mail.python.org/mailman/listinfo/python-list
Re: Sniffing Text Files
Thanks Mike this is really great! Regards, David On Friday, September 23, 2005, at 11:55 AM, Mike Meyer wrote: > David Pratt <[EMAIL PROTECTED]> writes: >> Thanks Mike for your reply. I am not aware of libmagic and will look >> to see what it provides. > > and ... > > Skip Montanaro <[EMAIL PROTECTED]> writes: >> You can also run the file(1) command and see what it says. I seem >> to recall someone asking about the equivalent to file(1) implemented >> in >> Python awhile back. > > libmagic is the smarts of the file command. As I said before, people > have done Python wrappers for it. It uses a text database describing > how to recognize a files type - see the magic(5) man page for details > on that. If you use libmagic, you'll probably want to provide your own > version of the databse, excerpted to include just the file types you > want to recognize. > > You can check on whether or not this will work for you by seeing what > the file command says about your sample data. > > -- > Mike Meyer <[EMAIL PROTECTED]> > http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, email for more > information. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: time challenge
sorry about that, i got a message in my inbox that said that the post was rejected so i tried it from my email client. wont happen again. shawn -- http://mail.python.org/mailman/listinfo/python-list
NaN Vs None
In choosing a way to represent a value of "no information" for a float, would it be better to use NaN or None? None has the advantage of standard behavior across platforms, but NaN seems to propagate more easily – at least on Windows. For example, NaN+1 = NaN but None+1 raises an exception. Thanks in advance for any advice. Jon K Peck (Kim) [EMAIL PROTECTED] 312-651-3435 233 S Wacker Dr Chicago, IL 60606 -- http://mail.python.org/mailman/listinfo/python-list
Re: optimizing a program that just shuffles data, a bit like cat...
On Fri, 23 Sep 2005 01:16:46 +, Dan Stromberg wrote: > > ...but with much bigger blocksizes, and with a netcat-like ability to use > sockets. > Try using psyco and see if that helps. Also, sometimes smaller blocks are better than large blocks. Try using smaller block sizes and see if that helps. If you're worried about the time required to calculate the length of your block, try calculating it once and pass the length around. Is that doable? -- http://mail.python.org/mailman/listinfo/python-list
Config parser module
Hi all I am a newbie and I just saw a ongoing thread on Fileprocessing which talks abt config parser. I have writen many pyhton program to parse many kind of text files by using string module and regex. But after reading that config parser thread I feel stunned. Can somebody tell me some intro info how to parse huge data (most of them are input data to application softwares like nastran, abaqus etc) Recently I saw a great work by John on Nastran file parser (i am still trying to understand the program, http://jrfonseca.dyndns.org/svn/phd/python/Data/Nastran/ An example of dat may be like this, (part of) (say point id coordinateSysNo x,y,z ...) GRID 1 12478.0 0.0 256.75 1 GRID 2 12357.25 0.0 256.75 1 GRID 3 12357.25 0.0 199.0 1 (say Elementtype id property point1 point 2 point3 point4 etc) CQUAD4 7231 2156915700570156920.0 CQUAD4 7232 2156925701570256930.0 CQUAD4 7233 2156935702570356940.0 the data file is very complex if i consider all complexities) Is is possible to use config parser module insome way for this. I also have few perl parser (for some part for some particular tasks) and now changing them to python. (I feel perl regex combination is very easy to learn and very powerfull) Any information will be appreciated. -jiro -- http://mail.python.org/mailman/listinfo/python-list
Re: What is "self"?
Terry Hancock wrote: >On Friday 23 September 2005 07:11 am, Rick Wotnaz wrote: > > >>I've long thought that Guido missed an opportunity by not choosing >>to use 'i' as the instance identifier, and making it a reserved >>word. For one thing, it would resonate with the personal pronoun >>'I', and so carry essentially the same meaning as 'self'. >> Not realy. >> It could >>also be understood as an initialism for 'instance'. >> MUCH better then trying to make it refer to "i" as in "me", but still. >>And, because it >>is shorter, the number of objections to its existence *might* have >>been smaller than seems to be the case with 'self' as the >>convention. >> >> Humm... maybe. But would reap the fact that i does not have the same exact meaning of self. With the word self, it is possable to change a feature of yourSELF, but try saying you changed a feature of "yourI", some internal logic in the programmers brain is going to go off, and if the programmer is tired and trying to finish something up but has that kind of internal confusion, as suttle as it may be, he will get burnt out and have to wait intill the next day. >>And as a side benefit, it would make it impossible to use as a loop >>index a language feature that would be a huge selling point among a >>lot of experienced programmers. >> >> > > > You think thats a good thing? o.0. I agree that sometimes you need to name your loop variables well, but sometimes you only need a simple, temp loop variable. I would expect such an aprouch to be more likely to be found in intercal (http://www.catb.org/~esr/intercal/), rather then in Python. >How exactly is that? Anybody who uses "i" as a variable name for >anything other than an innermost loop index is a sick and twisted >code sadist. > > > Agreed, though to say "code sadist" is a little hard don't ya think? ;) >You'd prefer what? "count" or "kount" or >"i_am_an_innermost_loop_index_counter". >I mean "explicit is better than implicit", right? > > >Maybe Fortran warped my brain, but I just don't see the benefit here. > Me ither. I am no english professor, but isn't the word "i" usualy pointed at something you will, have, can, or can't do in english? "me" or "self" or "this" or "my" or "cls" or "inst" are refering to just the object, nothing more, nothing less (except for "my" which is like referring to "something i own") and are much more human-comprehendable. IMHO. >-- >Terry Hancock ( hancock at anansispaceworks.com ) >Anansi Spaceworks http://www.anansispaceworks.com > > > Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: What is "self"?
Terry Hancock <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > On Friday 23 September 2005 07:11 am, Rick Wotnaz wrote: >> I've long thought that Guido missed an opportunity by not >> choosing to use 'i' as the instance identifier, and making it a >> reserved word. For one thing, it would resonate with the >> personal pronoun 'I', and so carry essentially the same meaning >> as 'self'. It could also be understood as an initialism for >> 'instance'. And, because it is shorter, the number of >> objections to its existence *might* have been smaller than >> seems to be the case with 'self' as the convention. >> >> And as a side benefit, it would make it impossible to use as a >> loop index a language feature that would be a huge selling >> point among a lot of experienced programmers. > > How exactly is that? Anybody who uses "i" as a variable name > for anything other than an innermost loop index is a sick and > twisted code sadist. > > You'd prefer what? "count" or "kount" or > "i_am_an_innermost_loop_index_counter". I mean "explicit is > better than implicit", right? > > Maybe Fortran warped my brain, but I just don't see the benefit > here. -- Oh, 'ix' would be fine. Single-letter loop counters are also semi- fine if that is in fact their only use. It too-frequently happens that at some point the handy 'i' identifier is used outside the loop (for another placeholder), and its value is tromped by an intervening loop. Not terribly difficult to discover, but then what? When you're maintaining code, even a two-character index is a *lot* easier to find in source code and replace as needed. -- rzed -- http://mail.python.org/mailman/listinfo/python-list
Re: Config parser module
The Config Parser module is for extracting data from and writing to a specific format of file, generally known as a config file. As explained in the documentation, a config file is in the same format as .ini files frequently found on windows - especially used by older software. It is a very handy file format for all sorts of jobs, more so on Linux these days than Windows, probably. However, it isn't much use for your particular need as described here. [EMAIL PROTECTED] wrote: > Hi all > I am a newbie and I just saw a ongoing thread on Fileprocessing which > talks abt config parser. > I have writen many pyhton program to parse many kind of text files by > using string module and regex. But after reading that config parser > thread I feel stunned. > > Can somebody tell me some intro info how to parse huge data (most of > them are input data to application softwares like nastran, abaqus etc) > > Recently I saw a great work by John on Nastran file parser (i am still > trying to understand the program, > http://jrfonseca.dyndns.org/svn/phd/python/Data/Nastran/ > > An example of dat may be like this, (part of) > (say point id coordinateSysNo x,y,z ...) > GRID 1 12478.0 0.0 256.75 1 > GRID 2 12357.25 0.0 256.75 1 > GRID 3 12357.25 0.0 199.0 1 > (say Elementtype id property point1 point 2 point3 point4 etc) > CQUAD4 7231 2156915700570156920.0 > > CQUAD4 7232 2156925701570256930.0 > > CQUAD4 7233 2156935702570356940.0 > > the data file is very complex if i consider all complexities) > > Is is possible to use config parser module insome way for this. I also > have few perl parser (for some part for some particular tasks) and now > changing them to python. (I feel perl regex combination is very easy to > learn and very powerfull) > > Any information will be appreciated. > > -jiro -- Dale Strickland-Clark Riverhall Systems www.riverhall.co.uk We're recruiting Python programmers. See web site. -- http://mail.python.org/mailman/listinfo/python-list
Re: Single type for __builtins__ in Py3.0
Collin Winter wrote: > If possible, I'd like to see this go in before 3.0. +1 -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: optimizing a program that just shuffles data, a bit like cat...
On Fri, 23 Sep 2005 10:18:47 -0500, Oracle wrote: > On Fri, 23 Sep 2005 01:16:46 +, Dan Stromberg wrote: > >> [quoted text muted] > > Try using psyco and see if that helps. Also, sometimes smaller blocks are > better than large blocks. Try using smaller block sizes and see if that > helps. I like the psyco idea, but I'm on an AIX system with a powerpc CPU, rather than an x86 CPU. > If you're worried about the time required to calculate the length of > your block, try calculating it once and pass the length around. Is that > doable? AFAIK, that's what I've been doing... Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: NaN Vs None
[Peck, Jon] > In choosing a way to represent a value of "no information" for a > float, would it be better to use NaN or None? None has the advantage > of standard behavior across platforms, but NaN seems to propagate more > easily – at least on Windows. [...] What I do for these things is creating a Missing type which behaves like a number, that is, it has all __FUNCTION__ magic required by numbers. I then create either a single missing constant or very few such missing constants, in which case each one representing a particular way or flavor of a missing number (unknown, not applicable, uncomputable, etc.) The magic functions for Missing should know how to combine the few missing constants with numbers, and with other missing constants, for returning the "proper" one. It's easier with only one missing constant. You also need to take care of comparisons and logical operators on missing values. My usual convention is that missing values propagate within booleans and behave like False when tested. Sometimes, I also need "missing" strings. That's more difficult to implement, because of the numerous string methods and ramifications. -- François Pinard http://pinard.progiciels-bpi.ca -- http://mail.python.org/mailman/listinfo/python-list
Re: What is "self"?
On Friday 23 September 2005 10:42 am, Peter wrote: > Terry Hancock wrote: > >How exactly is that? Anybody who uses "i" as a variable name for > >anything other than an innermost loop index is a sick and twisted > >code sadist. > > > Agreed, though to say "code sadist" is a little hard don't ya think? ;) I don't know, I thought it quite poetic. ;-) > >You'd prefer what? "count" or "kount" or > >"i_am_an_innermost_loop_index_counter". > >I mean "explicit is better than implicit", right? > > > >Maybe Fortran warped my brain, but I just don't see the benefit here. > > > Me ither. > > I am no english professor, but isn't the word "i" usualy pointed at > something you will, have, can, or can't do in english? > "me" or "self" or "this" or "my" or "cls" or "inst" are refering to just > the object, nothing more, nothing less (except for "my" which is like > referring to "something i own") and are much more human-comprehendable. > IMHO. Whoa, you totally lost me there, dude. ;-) -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What is "self"?
On Friday 23 September 2005 10:41 am, Rick Wotnaz wrote: > Oh, 'ix' would be fine. Single-letter loop counters are also semi- > fine if that is in fact their only use. It too-frequently happens > that at some point the handy 'i' identifier is used outside the > loop (for another placeholder), and its value is tromped by an > intervening loop. Not terribly difficult to discover, but then > what? When you're maintaining code, even a two-character index is a > *lot* easier to find in source code and replace as needed. Sorry, but if you have to grep for it, your loop is TOO DARNED LARGE, USE A FUNCTION CALL! -- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Config parser module
ConfigParser is for parsing configuration files of the format:
[section1]
option1=
option2=
.
.
.
optionN=
[section2]
option1=
option2=
.
.
.
optionN=
Your data doesn't fit that format.
Looks to me like you should write a small class object for
each different type of record that can be found in the file
that knows how to parse that record and put the information
from that record in to class attributes for easy access.
Something like:
class gridclass:
def __init__(self, recordToParse):
elements=recordToParse.split(' ')
self.type=elements[0]
self.pointId=int(elements[1])
self.coordinateSysNo=float(elements[2])
self.x=float(elements[3])
self.y=float(elements[4])
self.z=int(elements[5])
Then read the lines, determine the line type and create a class
instance for each one.
-larry
[EMAIL PROTECTED] wrote:
> Hi all
> I am a newbie and I just saw a ongoing thread on Fileprocessing which
> talks abt config parser.
> I have writen many pyhton program to parse many kind of text files by
> using string module and regex. But after reading that config parser
> thread I feel stunned.
>
> Can somebody tell me some intro info how to parse huge data (most of
> them are input data to application softwares like nastran, abaqus etc)
>
> Recently I saw a great work by John on Nastran file parser (i am still
> trying to understand the program,
> http://jrfonseca.dyndns.org/svn/phd/python/Data/Nastran/
>
> An example of dat may be like this, (part of)
> (say point id coordinateSysNo x,y,z ...)
> GRID 1 12478.0 0.0 256.75 1
> GRID 2 12357.25 0.0 256.75 1
> GRID 3 12357.25 0.0 199.0 1
> (say Elementtype id property point1 point 2 point3 point4 etc)
> CQUAD4 7231 2156915700570156920.0
>
> CQUAD4 7232 2156925701570256930.0
>
> CQUAD4 7233 2156935702570356940.0
>
> the data file is very complex if i consider all complexities)
>
> Is is possible to use config parser module insome way for this. I also
> have few perl parser (for some part for some particular tasks) and now
> changing them to python. (I feel perl regex combination is very easy to
> learn and very powerfull)
>
> Any information will be appreciated.
>
> -jiro
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: xml2schema
""" Er, do you mean to generate a Relax NG (or possibly a DTD in fact) from some XML file?? If you do mean this then just think of that how you could generate grammar from some paragraphs of English text... Sorta non-trivial, if possible at all, isn't it? :-) """ Very well put. However, for RELAX NG there is a tool that might work for the OP: Examplotron. See: http://www-128.ibm.com/developerworks/xml/library/x-xmptron/ As I show in that article, you can use Examplotron from any XSLT processor, including one invoked through Python API. -- Uche http://copia.ogbuji.net -- http://mail.python.org/mailman/listinfo/python-list
Re: What is "self"?
Erik Max Francis wrote: > Ron Adam wrote: > >> When you call a method of an instance, Python translates it to... >> >> leader.set_name(leader, "John") > > > It actually translates it to > > Person.set_name(leader, "John") > I thought that I might have missed something there. Is there a paper on how python accesses and stores instance data and methods? I googled but couldn't find anything that addressed this particular question. >>> class a(object): ...def x(self): ... print 'x' ... >>> b = a() >>> b <__main__.a object at 0x009D1890> >>> b.x > So what exactly is a bound method object? Does it possibly translates to something like the following? def x(*args, **kwds): self = ? return __class__.self(self, *args, **kwds) Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
desktop module (was Re: Open PDF)
Dennis Lee Bieber skrev: > On Thu, 22 Sep 2005 15:16:09 +0100, Dan <[EMAIL PROTECTED]> declaimed > the following in comp.lang.python: > > > > I would like to know how to open a PDF document from a python script > > > > You mean open it and display it to the user? Under Windows you may be > > able to get away with just "executing" the file (as though it were an > > executable): > > For Windows, os.startfile() may be better... I've just uploaded a patch/suggestion/module (#1301512) to SourceForge which seeks to provide the equivalent of os.startfile for KDE and GNOME (as well as Windows) as part of a generic desktop module: http://sourceforge.net/tracker/index.php?func=detail&aid=1301512&group_id=5470&atid=305470 Rather than submit yet another PEP and argue about insignificant details whilst the webbrowser module sits comfortably in the standard library, failing to address general file-opening issues directly and doing the wrong thing under various modern desktop environments, I advocate people submitting suggestions, criticism and amendments to the uploaded attachment until we have something like os.startfile for all major desktop environments. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: C#3.0 and lambdas
Fredrik Lundh wrote: > Reinhold Birkenfeld wrote: > >>> And I think the discussion that followed proved your point perfectly >>> Fredrik. Big discussion over fairly minor things, but no "big picture". >>> Where are the initiatives on the "big stuff" (common documentation >>> format, improved build system, improved web modules, reworking the >>> standard library to mention a few) Hey, even Ruby is passing us here. >> >> This is Open Source. If you want an initiative, start one. > > you know, this "you have opinions? fuck off!" attitude isn't really helping. If I had wanted to say "you have opinions? fuck off!", I would have said "you have opinions? fuck off!". All I wanted to say is that if you want a common documentation format, and you want it badly, you should show up on python-dev and offer help. Unfortunately, there are not as many Python core developers as Perl core developers, and things move at a slower pace. That's mostly not their fault, and not anyone's fault. It's a consequence of the amount of time that is spent on Python-the-core itself. And why? Well, because it's more fun to program in Python than to program Python. Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: Small python24.dll / how to strip off asian codecs to separate package(s) ?
Robert wrote: > Or how to build one? Just download the source, and follow the instructions in PCBuild/readme.txt. Then, edit the pythoncore project to remove the files you don't want to include, and edit config.c to remove the dangling references. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
