Re: COM access sooo slow !?
I also use Python to access database on Windows. You can speed up your program by doing that: Open PythonWin, then click on the Tools menu and the item COM Makepy Utility. It will display all libraries available. Then, select Microsoft ActiveX Data Objects 2.7 Library or whatever last version of ADO you have. You just need to do it once, as it registers the objects of the library in the registry ( I think. I don't completely understand the mechanism. ) If you use another library, do the same thing with the library you use. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
jan V [EMAIL PROTECTED] wrote: +---+ .:\:\:/:/:. | PLEASE DO NOT |:.:\:\:/:/:.: | FEED THE TROLLS | :=.' - - '.=: | | '=(\ 9 9 /)=' | Thank you, | ( (_) ) | Management | /`-vvv-'\ +---+ / \ | |@@@ / /|,|\ \ | |@@@ /_// /^\ \\_\ @x@@x@| | |/ WW( ( ) )WW \/| |\| __\,,\ /,,/__ \||/ | | | jgs (__Y__) /\/\/\/\/\/\/\/\//\/\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\ Please don't use ASCII art... not everyone uses a fixed-width font for his newsreader... (your picture looks all mangled here) That's your own fault, though, innit? Richard -- http://mail.python.org/mailman/listinfo/python-list
literal accented characters in python asp page with Microsoft IIS
I try to use python as the language in an asp page with Microsoft IIS 5.0. I have these two files, req_bad.asp and req_ok.asp -- req_bad.asp - [EMAIL PROTECTED] % # il y a un problème ici Response.write('Hello') % - -- req_ok.asp - [EMAIL PROTECTED] % # il y a un probleme ici Response.write('Hello') % - When I retrieve req_bad.asp from a browser, I get the error message: HTTP/1.1 500 Server Error When I try with req_ok.asp, it works and displays 'hello'. The only difference is that in req_bad.asp, I use an accented character in the french word problème. In req_ok.asp, there is no accented character. Someone knows how to write literal accented characters in a python asp page ? It is not only for the comments, but also to write out strings with Response.write('problème') which doesn't work either. If I write probl\xe8me instead of problème, it works well. But as I already have lots of code containing literal accented characters, I would have liked to be able to use them in asp pages, without modifying them. It is only in asp pages that things don't work. If I run code containing literal accented characters as normal Python program, it works. Is the problem related to IIS and is there some configuration to change to make it work ? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get a unique id for bound methods?
Russell E. Owen wrote: I have several situations in my code where I want a unique identifier for a method of some object (I think this is called a bound method). I want this id to be both unique to that method and also stable (so I can regenerate it later if necessary). def persistent_bound_method(m): ... return m.im_self.__dict__.setdefault(m.im_func.func_name, m) ... class A: ... def x(self): ... return ... a=A() a.x is a.x False persistent_bound_method(a.x) is persistent_bound_method(a.x) True -- http://mail.python.org/mailman/listinfo/python-list
Re: loop in python
If you want a fast language, try Holden. I've just invented it. Unfortunately it gets the answer to every problem wrong unless the answer is 42, but boy it runs quickly. The code for the whole interpreter (it's written in Python) follows: print 42 great ! u can use it for ur own projects. but pls donot suggest it to anyone else. i think u can get an award for developing such a fast language in such a shorter time ;-) may be u can also be called 'Guido Holden Rossum' ;-) anyway improve it - its quite buggy now :-D Speed of execution is so insignificant for the majority of programming problems I donot agree with that. If thats the case then no one would be using C or C++ etc for instance. one important thing is that i am not comparing python with C but with similar language, Perl. well ofcourse i dont jump into conclusion, just with just a simple 'loops' snippet, that python is slower than perl. but when speed is important then ? also i hate people recommending if u need speed code it as a C extension module. ofcourse i donot expect pure python/perl program to execute at the speed of a C program. that this obsession reveals a certain inexperience. its neither obsession nor inexperience ... its just the requirement. i think less buggy code is not the main concern for all. if thats the case there are better languages (like Ada with better built in exception classes) and so used in mission critical applications. even perl is still popular even its difficult to maintain, but when one looks for speed (naturally), rather than the readability maintainability of the code, does python suit perl ? i am aware one of the main principle python isn founded is better readability but is that a feature which decreases execution speed ? then what is it ? even perl is still popular even if its difficult to maintain after a certian stage of coding. there obviously will be a bias in this list towards python but i need a honest opinion of python vs perl. (especially when it comes to webscripting) regards Steve The inventor of Holden regards, KM -- http://mail.python.org/mailman/listinfo/python-list
Network performance
Hi! I need a fast protocol to use between a client and a server, both sides written i Python. What the protocol has to accomplish is extremely simple; the client sends a number of lines (actually a RDF) and the server accepts or rejects the packet. That's all ! Now, presently I'm using Twisted and XMLRPC ( why so is a long history which I will not go into here) and that is a bit to slow for my needs. On my present setup it takes close to 200 ms to perform one transfer. But since that includes setting up and tearing down the connection I thought I'd try doing something simpler so I wrote a server and a client using socket. The client sends a number of lines (each ending with \n) and ends one set of lines with a empty line. When the client sends a line with only a . it means I'm done close the connection. Letting the client open the connection and sending a number of sets I was surprised to find that the performance was equal to what Twisted/ XMLRPC did. Around 200 ms per set, not significantly less. So what can be done to speed up things or is Python incapable of supporting fast networking (just a teaser). -- Roland #!/usr/bin/env python from SocketServer import ThreadingMixIn, TCPServer, StreamRequestHandler class UdsRequestHandler( StreamRequestHandler ): def handle(self): rdf = [] while 1: tri = self.rfile.readline().strip() if tri == .: if rdf: print rdf self.wfile.write(ACCEPT) break if tri: rdf.append(tri) else: print rdf self.wfile.write(ACCEPT) rdf = [] class UdsServer(ThreadingMixIn, TCPServer): allow_reuse_address = 1 if __name__ == __main__: serveraddr = ('', 8765) srv = UdsServer(serveraddr, UdsRequestHandler) srv.serve_forever() #!/usr/bin/env python import socket # Ending \n vital !! RDF = uds:person uds:src primula . uds:person uds:eid 4182 . uds:person uds:oid NIN:19720412-7802 . uds:person uds:add _:a . _:a uds:guise anst1 . _:a udsattr:umuEduPersonEmploymentExtent 100 . _:a udsattr:norEduOrgUnitUniqueNumber 7528 . _:a udsattr:eduPersonAffiliation staff . class UdsClient: def __init__(self, ip, port): self.ip = ip self.port = port self.s = socket.socket( socket.AF_INET, socket.SOCK_STREAM) try: self.s.connect((self.ip, self.port)) except: print Connection error return None def send( self, rdf ): self.s.send( rdf ) self.s.send( \n ) def close( self ): self.s.send( .\n ) def read( self ): r = try: r = self.s.recv(256) except: print No response return r if __name__ == __main__: uc = UdsClient(localhost, 8765) n = 10 while n: uc.send( RDF ) print Response: %s % uc.read() n -= 1 uc.close() print DONE -- http://mail.python.org/mailman/listinfo/python-list
Re: Eve from Adams' Ribs
Godwin wrote: But the funny fact is that i want this class to be dynamically generated at run time simply from a table name string. The thing you are looking for is called an object-relational mapper. try SQLObject http://sqlobject.org/ This is mainly intended to work the other way (i.e. describe the structure in Python and create tables from that), but it does support a get the structure from a legacy table mode that may be good enough (you may be in strife if your existing tables don't meet certain requirements, like having a unique integer key, or have odd column-naming schema etc). I don't think it supports Oracle (yet...) -- http://mail.python.org/mailman/listinfo/python-list
RE: Well, another try Re: while c = f.read(1)
Robert Kern wrote: James asked a question in such a way that I didn't think it would get answered. Judging from the other non-responses to his post, I was right. I showed him the way to ask questions such that they *will* get answered, and he came back, did so, and got his questions answered. FWIW, I agree with you, but then I'm another one who directs people to smart-questions. I also direct co-workers to it, and even myself on a semi-regular basis. Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list
Doubt C and Python
Dear All, I want to know the link between c and python. Some people with C background use Python instead of programming in C.why? regards Prabahar Send a rakhi to your brother, buy gifts and win attractive prizes. Log on to http://in.promos.yahoo.com/rakhi/index.html -- http://mail.python.org/mailman/listinfo/python-list
Reg python nature.
Dear All, I want to know the link between c and python. Some people with C background use Python instead of programming in C.why? regards Prabaha Send a rakhi to your brother, buy gifts and win attractive prizes. Log on to http://in.promos.yahoo.com/rakhi/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: loop in python
computers are cheap. i am expensive. give me clear and maintainable code every time. randy -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the difference between built-in func getattr() and normal call of a func of a class
Johnny wrote: Hi, I wonder what is the difference between the built-in function getattr() and the normal call of a function of a class. Here is the details: getattr( object, name[, default]) Return the value of the named attributed of object. name must be a string. If the string is the name of one of the object's attributes, the result is the value of that attribute. For example, getattr(x, 'foobar') is equivalent to x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised. Is that to say the only difference between the two is that no matter the specific function exists or not the built-in func will always return a value, but class.function will not? No, it will only return _always_ a value if you provide a default one. If not, they have the exact same semantics. What you've got here is something usually called syntactic sugaring - a specialized syntax that performs certain instructions that _could_ be done by hand - but the concise syntax is (supposedly, and certainly in this case) easier to read/write/understand. There are others - e.g. list comprehensions or a b c. Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the difference between built-in func getattr() and normal call of a func of a class
Diez B. Roggisch wrote: No, it will only return _always_ a value if you provide a default one. If not, they have the exact same semantics. What you've got here is something usually called syntactic sugaring - a specialized syntax that performs certain instructions that _could_ be done by hand - but the concise syntax is (supposedly, and certainly in this case) easier to read/write/understand. There are others - e.g. list comprehensions or a b c. Regards, Diez Cool~ Thanks for showing me the syntactic sugaring:) -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt C and Python
Some people with C background use Python instead of programming in C.why? Becuase it is much more efficient. -James -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Op 2005-08-22, Magnus Lycka schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Python doesn't guess. There are a range of values that will be treated, in a Boolean context (how perlish) as equivalent to False. Yes it does. No it doesn't! Python has no way to know what would be the most usefull Boolean interpretation of these values in a particular context. It's hardly the task of the interpreter to try to do that. Indeed ir is not, so the interpreter should not pretend it can by providing a Boolean interpretation. That it picks one out is guessing. No, it simply follows a well defined specification. See http://docs.python.org/ref/Booleans.html There is no guessing involved in that. Following a well defined specification is not contradictory to guessing. It may just mean that the guess was formalized into the specification. Lisp imterprets an empty list as false, scheme interprets it as true. So both seem usable interpretations. You might argue that *Guido* was guessing when he decided what the most useful behaviour of Python would be in this case, and there's probably some truth in that, just as there is some guesswork involved in most programming language design decisions, but that's another thing. That's not Python guessing, it's Guido using his excellent lanugage design skills. It seems most Python programmers agree that he guessed right here, as usual. I don't see a big difference. Guessing plays its roles when different people can have different expectations in cases where not all the details are known/specified. Whether that is in the language design or in program design doesn't make a big difference and I would expect that a language that discourages guessing in the software that its written in it, would follow its own rules in its design. (Perhaps you thought that Python was the name of the language designer. It's not. Python's design is led by Guido van Rossum, and the name Python comes from a (mostly) British comedy group.) You might also argue that this behaviour is counter to the Python dogma of explicit is better than implicit. Python also allows you to get a float out of an expression such as 2*3.1 without forcing an explicit cast, as in float(2)*3.1. You should note that the first Python tenet is Beautiful is better than ugly and that's probably what we have to blame here. There seems to be close to a consensus, that if users: is more beautiful than e.g. if len(users) 0: or if (len(users)==0)==False or for that matter if ((len(users)==0)==False)==True or if (((len(users)==0)==False)==True)==True etc. Well then I must say people here give beauty too high a priority. Because there seems a tendency to beautify others code when snippets are posted here. Often enough such snippets don't give enough inoformation to know whether if var is True: can be replaced by if var: or whether other beautifications are appropiate. What's true and false for Python, belongs to the few things you actually have to learn, and I can appreciate that it's annoying for a frequent schemer to remember that it's not the same in Python, but it seems that very few people argue with the way Python behaves in this respect. I care very little for what someone with experience in an other language can expect. I care about the consistence of the language and the programs written in it. I just mentioned scheme to show that [] interpreted as false is not so obvious as a lot of people seem to think. Since there are situations where using '', (), [] or 0 as false would be not appropiate I advise against using them as such, because you never know when your software that does has to cooperate with software that doesn't. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
gtkmozembed in fedora core 3
Could someone help me get gtkmozembed working under fc3? The only available rpms need gnome-python2 = 2.9 and fc3 ships with 2.6. I can't find any fc3 rpms to upgrade gnome-python2 and I can't quite figure out what I'd need to compile just to install gtkmozembed and the python bindings (I need to deploy this at work, so I'm trying to make the minimal possible change to a stock fc3 install). Upgrading to fc4 is sadly not an option :-/ martin -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the difference between built-in func getattr() and normal call of a func of a class
Johnny wrote: Hi, I wonder what is the difference between the built-in function getattr() and the normal call of a function of a class. Here is the details: getattr( object, name[, default]) Return the value of the named attributed of object. name must be a string. If the string is the name of one of the object's attributes, the result is the value of that attribute. For example, getattr(x, 'foobar') is equivalent to x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised. Is that to say the only difference between the two is that no matter the specific function exists or not the built-in func will always return a value, but class.function will not? No, getattr(object, name) will raise an AttributeError if the attribute doesn't exist; no value will be returned. When getattr(object, name, default) is called, then a value will be returned regardless of whether or not the attribute exists (but possibly something else may go wrong). In terms of practice, the getattr() form allows you to specify the attribute at run-time rather than write-time. You can do things like iterate over a list of attributes. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
check whether directory is readable
Hello, how can I check whether a directory is readable or not. Are there differences between unix and windows? Thank you for your hints, Eels -- http://mail.python.org/mailman/listinfo/python-list
RE: X-Platform method of remote execution of Windows programs
[EMAIL PROTECTED] | Well, I can do this using WMI thru VBScript for Windows-Windows | connections. What I would like is a method using python for both | Windows-Windows and Linux-Windows connections. I've looked at pyWMI | (http://tgolden.sc.sabren.com/python/wmi.html), and found it | unclear in it's dealings with remote boxes. A look at win32com netted me | a load of Access Denied errors. Well, assuming I understand the question, the wmi module won't help you if you're running on Linux, as it's just a thin wrapper around the pywin32 extensions which will only work on Windows. I remember hearing tell of a WBEM-on-Linux recently which might, I suppose, get you so far, but WMI uses the DCOM infrastructure to communicate cross-machine, so you'd have to factor that in somehow, too. That said, I'd like to know in what way the wmi is unclear about its dealing with remote boxes (if only to improve my documentation). Basically, rather than doing: import wmi c = wmi.WMI () you do: import wmi c = wmi.WMI (name_of_other_box) and then carry on as before. I admit there are issues of security and so on, especially -- I gather -- on XP, where they've actually applied some of the security contexts that the WMI documentation talks about. But that's to do with WMI itself, and not to do with Python, afaict. Tim Golden This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Revised PEP 349: Allow str() to return unicode strings
neil, i just intended to worry that returning a unicode object from ``str()`` would break assumptions about the way that 'type definers' like ``str()``, ``int()``, ``float()`` and so on work, but i quickly realized that e.g. ``int()`` does return a long where appropriate! since the principle works there one may surmise it will also work for ``str()`` in the long run. one point i don't seem to understand right now is why it says in the function definition:: if type(s) is str or type(s) is unicode: ... instead of using ``isinstance()``. Testing for ``type()`` means that instances of derived classes (that may or may not change nothing or almost nothing to the underlying class) when passed to a function that uses ``str()`` will behave in a different way! isn't it more realistic and commonplace to assume that derivatives of a class do fulfill the requirements of the underlying class? -- which may turn out to be wrong! but still... the code as it stands means i have to remember that *in this special case only* (when deriving from ``unicode``), i have to add a ``__str__()`` method myself that simply returns ``self``. then of course, one could change ``unicode.__str__()`` to return ``self``, itself, which should work. but then, why so complicated? i suggest to change said line to:: if isinstance( s, ( str, unicode ) ): ... any objections? _wolf -- http://mail.python.org/mailman/listinfo/python-list
Re: Running multiple console processes and watching their output
If you are under UNIX, try the 'screen' command. Markus -- http://mail.python.org/mailman/listinfo/python-list
Doubt Regarding link between C and Python
Dear All, I want to know the link between c and python. Some people with C background use Python instead of programming in C.why? regards Prabahar Send a rakhi to your brother, buy gifts and win attractive prizes. Log on to http://in.promos.yahoo.com/rakhi/index.html -- http://mail.python.org/mailman/listinfo/python-list
Re: loop in python
km wrote: that this obsession reveals a certain inexperience. its neither obsession nor inexperience ... its just the requirement. i think less buggy code is not the main concern for all. Argh (choking) Then you are definitely a dangerous person! If your program is fast to give a false answer, it is like driving a truck with the eyes closed in down town (I can go fast, I am not scared, I do not see the dangers). Please tell us for you are working in order for us to avoid the software / services you are providing. -- rafi Imagination is more important than knowledge. (Albert Einstein) -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Op 2005-08-22, Donn Cave schreef [EMAIL PROTECTED]: Before leaving this topic, I wanted to make a rare visit to the ruins of Google's USENET archive and pull out this giant post on the subject of True and False, when they were being considered for adoption into Python. There is some stuff to ignore, where she addresses questions that didn't go anywhere, but she goes on to write a well articulated case that makes very interesting reading, and possibly has had some effect on how people think about it around here. http://groups-beta.google.com/group/comp.lang.python/msg/2de5e1c8384c0360 Well I guess she and I disagree here. I also don't understand some of her arguments. e.g. about code like: if var == True | Aaargh! | I already see too much code like this. It's mostly written by people | who come from other languages. They define their own True and False so | they can do this. I would argue that this would be bad code even in these other languages. Heck when I was still a student and getting a course in PASCAL, people with no programming experience whatsoever would write code like that and PASCAL does have a real BOOLEAN type. So where she gets the idea that if var == True is a symptom of a language that has no real BOOLEAN type (as python now has IHO) is beyond me. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and the web
Joe T. wrote: Hello group, I'm new to Python and have a couple of beginner questions that I'm hoping someone can answer. 1. Is python something that you would recommend using for server side web programming? Definitively yes. Something like C# or Java? Far better IMHO. If so, are there any resources that you could point me to that would help me with server side python programming for dynamic html data? Most of the tutorials that I see deal with the Shell but I'd like to know more about using Python for database querying and printing database data on an html page as I would with .net's C# or Java. If your need is to build a web frontend for relational datas, have a look at Django: http://www.djangoproject.com/ Else, you have a huge choice of web programming solutions in Python, the most known being Zope, Twisted/Nevow and CherryPy (but there are many others). 2. I know there's a Jpython but what use would I get from using Python with Java? If I'm already familiar with Java programming why would I want to use Python with Java? Because Python is much more usable than Java ?-) But unless you need to work in a Java environnement, better stick to CPython. -- bruno desthuilliers ruby -e print '[EMAIL PROTECTED]'.split('@').collect{|p| p.split('.').collect{|w| w.reverse}.join('.')}.join('@') 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: Urgent: Embedding Python problems - advice sought
Thanks Michael. I will look into the areas you have suggested... Alan -- http://mail.python.org/mailman/listinfo/python-list
Re: Network performance
Roland Hedberg wrote: What the protocol has to accomplish is extremely simple; the client sends a number of lines (actually a RDF) and the server accepts or rejects the packet. That's all ! ... Now, presently I'm using ( why so is a long history which I will not go into here) and that is a bit to slow for my needs. On my present setup [Twisted and XMLRPC ]it takes close to 200 ms to perform one transfer. But since that includes setting up and tearing down the connection I thought I'd try doing something simpler so I wrote a server and a client using socket. I was surprised to find that the performance was equal to what Twisted/XMLRPC did. Around 200 ms per set, not significantly less. That should tell you two things: * Twisted/XMLRPC is as efficient as you can hand craft. (which is a good use reason for using it). * That what you're measuring is overhead - and most likely of setup. I'd measure the ping time between your two hosts. Why? TCP is not the fastest protocol in the world. If you're measuring the whole connection, you're dealing with a number of TCP messages: * Client - SYN * Server - SYN ACK * Client - ACK * Client - DATA (Assume data fits inside one message) * Server - ACK * Client - FIN * Server - FIN ACK * Server - FIN * Client - FIN ACK (Based on Fig 18.3, Steven TCP/IP Ill, Vol 2) That's 9 round trips. 200ms / 9 == 22.2 ms *IF* your ping time is close to this, then what you're really measuring is TCP setup/teardown latency, not python latency. (*IF* you're on a LAN and the latency is around that I'd suggest that you may have discovered a local network problem) If your ping time is significantly lower - eg you're running on localhost - I'd suggest you translate your code to C (and/or post your code), and repeat the same tests. So far you haven't shown that python is slow here, just that something that you're measuring causes it to be 200ms whether you use Twisted or not. (So you HAVE shown that twisted isn't slow :-) Another issue might be how you're measuring the latency - especially whether if you're including startup of python in the 200ms or not! Regards, Michael. -- [EMAIL PROTECTED], http://kamaelia.sourceforge.net/ British Broadcasting Corporation, Research and Development Kingswood Warren, Surrey KT20 6NP This message (and any attachments) may contain personal views which are not the views of the BBC unless specifically stated. -- http://mail.python.org/mailman/listinfo/python-list
What's the difference between built-in func getattr() and normal call of a func of a class
Hi, I wonder what is the difference between the built-in function getattr() and the normal call of a function of a class. Here is the details: getattr( object, name[, default]) Return the value of the named attributed of object. name must be a string. If the string is the name of one of the object's attributes, the result is the value of that attribute. For example, getattr(x, 'foobar') is equivalent to x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised. Is that to say the only difference between the two is that no matter the specific function exists or not the built-in func will always return a value, but class.function will not? -- http://mail.python.org/mailman/listinfo/python-list
Re: passing arguments from scale widget to function
Problem solved. use 'command = Calc' to call my Calc function but ignore the argument passed to it. Create a list with the following elements - a.get(), b.get() and c.get(). Every time a scale slider is moved, Calc will retrieve the current scale values and I can do with them whatever I want... Now to work out how to write the answer to a text box or similar... Thanks for your help, Matt Tony -- http://mail.python.org/mailman/listinfo/python-list
Library and real path name
I want to redistribute the library that I create. I create a project, its setup.py that when launched copy all files into the site-packages/library directory. And here it's all ok. When I call my library with: import library library.class() I want that my library know where are its real path (site-packages/library/), because it has to load a data file present into a subpackage directory (like site-package/library/data/file.dat), but if, inside the library code, I try to load the file with: f = open(./data/file.dat) python raise me an exception because it not found the file. I see that the current path are the path where I execute python. I think that I can solve this problem with something like: if sys.platform == 'win32': prefix = os.path.join(sys.prefix, Lib/site-packages/library/data/) else: prefix = os.path.join(sys.prefix, site-packages/library/data/) it work, but I think that is not a good solution (a real pythonic solution). Can someone help me? Thanks Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Network performance
23 aug 2005 kl. 10.14 skrev Michael Sparks: Roland Hedberg wrote: I was surprised to find that the performance was equal to what Twisted/XMLRPC did. Around 200 ms per set, not significantly less. That should tell you two things: * Twisted/XMLRPC is as efficient as you can hand craft. (which is a good use reason for using it). I already gathered that much :-) * That what you're measuring is overhead - and most likely of setup. Not necessarily! If the number of client - server queries/responses are large enough the effect of the setup time should be negligible. Or making testes with different numbers of queries you should be able to deduce the setup time. I'd measure the ping time between your two hosts. If your ping time is significantly lower - eg you're running on localhost - I'd suggest you translate your code to C (and/or post your code), I did the tests on localhost! And I did post the code! So, I made another test. I used a server I have already written in C and which I know quite well how fast it is. Using a python client I've written that talks to this server, it takes 0.8 s for the python client to start, connect and send 1000 queries. A C client is a bit faster but not a lot. This is more in the order of what I'd like to have. Hmm, not surprising this makes me suspect my python server implementation :-/ -- Roland -- http://mail.python.org/mailman/listinfo/python-list
Re: loop in python
Terry Reedy wrote: Benjamin Niemann [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] (snip) In that case, you are interested in IO performance. The time spent handling the loop is not significant compared to the time spent executing the 'print' statement - which is a very complex operation despite its simple usage. An implementation where a simple control flow structure has an measurable impact on the overall timing of an IO bound program would really suprising. Python suprises me often, but in different ways ;) Perhaps you could try to use sys.stdout.write() directly, avoiding the overhead of 'print'. Perhaps there are differences between the (default) output buffering settings of perl and python. According to postings some years ago, the perl folks have worked specially hard to speed I/O, even to the point of replacing or rewriting some of the C stdio library, at least for some systems. Hence, at that time, Perl was expected and known to be noticeably faster than Python on such systems. The truth is that the Perl version of the print loop program is incredibly faster than it's C counterpart (at least on my gentoo/linux box). Since the no-op loop program is faster in C (I guess that GCC 'optimizes out' the whole loop !-), it seems clear that Perl's IO do not relie on the stdlib implementation. Since then, Python I/O has been sped up to at least make better use of stdio, so the gap may be less. The Python and C versions of the print loop program have execution times that are close enough... 3. One should test computations that are relevant to the question being asked. Of course !-) -- 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: Library and real path name
Michele Petrazzo wrote: I want to redistribute the library that I create. I create a project, its setup.py that when launched copy all files into the site-packages/library directory. And here it's all ok. When I call my library with: import library library.class() I want that my library know where are its real path (site-packages/library/), because it has to load a data file present into a subpackage directory (like site-package/library/data/file.dat), http://peak.telecommunity.com/DevCenter/PkgResources -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: loop in python
Steve Holden wrote: (snip) If you want a fast language, try Holden. I've just invented it. Unfortunately it gets the answer to every problem wrong unless the answer is 42, but boy it runs quickly. The code for the whole interpreter (it's written in Python) follows: print 42 keyboard ! -- 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: Eve from Adams' Ribs
ORM: Several to choose from: http://blogs.nuxeo.com/sections/blogs/florent_guillaume/2005_08_11_object_relational http://en.wikipedia.org/wiki/Object-relational_mapping#Python http://www.python.org/pypi?:action=browseasdf=256 -- http://mail.python.org/mailman/listinfo/python-list
Re: Library and real path name
Michele Petrazzo wrote: I want to redistribute the library that I create. I create a project, its setup.py that when launched copy all files into the site-packages/library directory. And here it's all ok. When I call my library with: import library library.class() I want that my library know where are its real path (site-packages/library/) you can use the __file__ or __path__ variables to determine this. e.g. # get this module's directory import os prefix = os.path.dirname(__file__) or, inside a package __init__.py file: # get package's main directory prefix = __path__[0] /F -- http://mail.python.org/mailman/listinfo/python-list
Import Error ('mutual inclusion of modules'?)
I have the following code: A.py from B import B class R: def __str__(self): return hello world b = B() print b B.py from A import R class B: def __init__(self): self.r = R() def __str__(self): return self.r.__str__() When I try to execute A.py I get the following error: [python2.3]$ python A.py Traceback (most recent call last): File A.py, line 1, in ? from B import B File python2.3/B.py, line 1, in ? from A import R File python2.3/A.py, line 1, in ? from B import B ImportError: cannot import name B I think python does not support this kind of 'mutual inclusion'. Am I right? Thanks. Cesar. -- http://mail.python.org/mailman/listinfo/python-list
Re: Import Error ('mutual inclusion of modules'?)
[EMAIL PROTECTED] wrote: I have the following code: A.py from B import B B.py from A import R I think python does not support this kind of 'mutual inclusion'. Am I right? Thanks. Cesar. this page http://effbot.org/zone/import-confusion.htm might help you figure out what's going on here. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: loop in python
km wrote: If you want a fast language, try Holden. I've just invented it. Unfortunately it gets the answer to every problem wrong unless the answer is 42, but boy it runs quickly. The code for the whole interpreter (it's written in Python) follows: print 42 great ! u can use it for ur own projects. but pls donot suggest it to anyone else. ot If you hope to be taken seriously, please abandon the sms-talk style here. /ot anyway improve it - its quite buggy now :-D Nope, it works just as described. It's not a bug, Sir, it's a feature !-) Speed of execution is so insignificant for the majority of programming problems I donot agree with that. If thats the case then no one would be using C or C++ etc for instance. 1/ for the majority of programming problems : the majority, not all and every. 2/ Apache is coded in C, but there are cases where it can be outperformed by a specializd Python-coded HTTP server. 3/ OpenOffice is coded in C++ and it's one of the slowest app I ever saw (even Photoshop 6 on a dying P133/32mo Win98 box is more responsive) In most systems, the parts that can be performance bottlenecks are the presentation and the data persistence layers. That's the parts that are *already* coded in low-level languages and optimized as can be - if of course you use existing tools (GUI Toolkit, RDBMS etc) instead of trying to reimplement'em in Perl/Python/whatever !-) one important thing is that i am not comparing python with C but with similar language, Perl. What you are comparing is either IO times (the print loop program), where Perl beats C - which means that Perl's IO have been written at a very low level instead of relying on the stdlib's IO - or absolutely meaningless (I just don't care if no-op loops are slow since I don't write no-op loops). well ofcourse i dont jump into conclusion, Yes you did. just with just a simple 'loops' snippet, that python is slower than perl. for i in xrange(10): print this 'benchmark' is ABSOLUTELY MEANINGLESS but when speed is important then ? also i hate people recommending if u need speed code it as a C extension module. ofcourse i donot expect pure python/perl program to execute at the speed of a C program. In some cases, they can be fastest than the C version. that this obsession reveals a certain inexperience. its neither obsession nor inexperience ... its just the requirement. Which requirement ? i think less buggy code is not the main concern for all. +1 QOTW i am aware one of the main principle python isn founded is better readability but is that a feature which decreases execution speed ? Nope. It has to do with implementation (of the language), not design. there obviously will be a bias in this list towards python Oh, really ? Err, wait, what's the name of this group, exactly ? but i need a honest opinion of python vs perl. (especially when it comes to webscripting) This is another question, and has nothing to do with your benchmark, but FWIW, Google uses Python, not Perl. -- 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: loop in python
Steve Holden wrote: If you want a fast language, try Holden. I've just invented it. Unfortunately it gets the answer to every problem wrong unless the answer is 42, but boy it runs quickly. The code for the whole interpreter (it's written in Python) follows: print 42 Why are you looking for a fast language without any regard for the kind of problems you actually want (or need) to solve? isn't measuring speed by timing for-loops a 70's thing? I remember doing that back when I used Z80 BASIC machines (on a 3.58 MHz machine using floating point variables, each iteration took almost exactly 1 millisecond). I also remember that the compiler for my first custom language for that machine contained exactly one optimization: empty loops were replaced with plain assign- ments. everyone was mightly impressed. (for another view of Python's performance, see John Walker's floating point benchmarks: http://www.fourmilab.ch/fourmilog/archives/2005-08/000567.html from what I can tell, Python's the fastest interpreter in that test...) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Antoon Pardon wrote: Following a well defined specification is not contradictory to guessing. It may just mean that the guess was formalized into the specification. If you want the behaviour of Python to change, you should write a PEP. It always felt natural to me to interpret empty as false, but I could be wrong. It's strange that this flaw managed to go unnoticed for so long though... If Python is too wild for your taste, you might like OCaml. Well then I must say people here give beauty too high a priority. Because there seems a tendency to beautify others code when snippets are posted here. Often enough such snippets don't give enough inoformation to know whether if var is True: can be replaced by if var: or whether other beautifications are appropiate. You might be right about that. I didn't really notice. I think the typical comment is to replace if s != '': with if s: in contexts where s is always a string, or to replace if expr != False: with if expr: in cases where expr is an expression that returns True or False etc. In some cases, obvious bugs, such as if (a and b) == True: where the programmer should have written if (a and b): are pointed out. Many of us have a solid mathematical education, and in that world it's considered good behaviour to simplify expressions and remove redundancy. If we see things such as redundant pieces in logic expressions, functions ending in return None, returns directly after a raise, or other meaningless constructs, it suggests that someone might be doing something they don't understand, and then it's helpful to try to point that out. It's really important to understand what we do when we're programming, not just repeat mantras or wave dead chickens. If people mechanically learn I shouldn't use '!= False' in if-statements in Python, we've failed in trying to help them. If people learn what Python considers true and false, what the boolean operators return, and understands how to use these things in an effective way, we've succeeded. Another aspect of this particular idiom is that it's often better to use the exception system in Python for exceptional situations, than to use one variable to carry several different kinds of information. Concerning interfaces between different pieces of code, it's a good approach to assume as little as possible, but to be clear about what we assume. -- http://mail.python.org/mailman/listinfo/python-list
Re: Import Error ('mutual inclusion of modules'?)
Thanks, I had not found anything about it. But I had not search correctly. There is an entry in the FAQ about it: http://www.python.org/doc/faq/programming.html#how-can-i-have-modules-that-mutually-import-each-other I like the most the third way. I have also tried to move the import to the __init__ methos in B.py and it works. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Light Revisted?
Steve Holden wrote: Bryan wrote: Someone recently produced a distribution capable of running from a CD and designed to make it easy to use Python on machines where it wasn't actually installed. That might be a useful starting point too, but I can't find the right incantation to get Google to bring it up. regards Steve steve, are you thinking about moveable python? http://www.voidspace.org.uk/python/movpy/ The very one, thanks. regards Steve I have just used the NSIS + py2exe magic detailed at http://starship.python.net/crew/theller/moin.cgi/SingleFileExecutable to create a single exe tkinter + twisted app. The whole thing took about 3 days to build and deploy to testing of which about one day was figuring out how the NSIS + py2exe stuff worked. I think the nsis script needed a minor tweak to do exactly what we wanted. -- Robin Becker -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Revised PEP 349: Allow str() to return unicode strings
Thomas Heller wrote: Neil Schemenauer [EMAIL PROTECTED] writes: [Please mail followups to [EMAIL PROTECTED] The PEP has been rewritten based on a suggestion by Guido to change str() rather than adding a new built-in function. Based on my testing, I believe the idea is feasible. It would be helpful if people could test the patched Python with their own applications and report any incompatibilities. I like the fact that currently unicode(x) is guarateed to return a unicode instance, or raises a UnicodeDecodeError. Same for str(x), which is guaranteed to return a (byte) string instance or raise an error. Wouldn't also a new function make the intent clearer? So I think I'm +1 on the text() built-in, and -0 on changing str. Same here. A new API would also help make the transition easier from the current mixed data/text type (strings) to data-only (bytes) and text-only (text, renamed from unicode) in Py3.0. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Aug 23 2005) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! -- http://mail.python.org/mailman/listinfo/python-list
Re: Revised PEP 349: Allow str() to return unicode strings
Neil Schemenauer [EMAIL PROTECTED] writes: [Please mail followups to [EMAIL PROTECTED] The PEP has been rewritten based on a suggestion by Guido to change str() rather than adding a new built-in function. Based on my testing, I believe the idea is feasible. It would be helpful if people could test the patched Python with their own applications and report any incompatibilities. I like the fact that currently unicode(x) is guarateed to return a unicode instance, or raises a UnicodeDecodeError. Same for str(x), which is guaranteed to return a (byte) string instance or raise an error. Wouldn't also a new function make the intent clearer? So I think I'm +1 on the text() built-in, and -0 on changing str. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: check whether directory is readable
eels wrote: Hello, how can I check whether a directory is readable or not. Are there differences between unix and windows? As far as I know there aren't any differences, code: import os if access(/root, os.R_OK): print You are able to read the /root dir -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and the web
Terry Hancock wrote: Yes. If you're into killer apps, try out Zope. But it does have a learning curve. There are probably a dozen or so alternatives that are all smaller and quicker to learn. Very true zope is a killer app, but different from all the other well know server side languages. I myself am still in the learning stage but if you're into web development zope is the best around. But pay attention zope hosting can be expensive and hard to find. -- http://mail.python.org/mailman/listinfo/python-list
Re: check whether directory is readable
eels [EMAIL PROTECTED] wrote: how can I check whether a directory is readable or not. Are there differences between unix and windows? The Pythonic way would be to just do what you need to do (in this case, presumably, read the directory) and catch the specific exception (in this case, presumably, OSError). try: # Do whatever needs a readable directory normal_reading_stuff() except OSError, e: # Do whatever we need to when the directory is unreadable print Unable to read stuff:, e.strerror -- \ I got contacts, but I only need them when I read, so I got | `\ flip-ups. -- Steven Wright | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt C and Python
Will McGugan enlightened us with: Because I can create software many times faster. And its more fun. Same here. And because it's very easy to write unittests, for instance. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Op 2005-08-23, Magnus Lycka schreef [EMAIL PROTECTED]: Antoon Pardon wrote: Following a well defined specification is not contradictory to guessing. It may just mean that the guess was formalized into the specification. If you want the behaviour of Python to change, you should write a PEP. Such a PEP would have no chance of being accepted, since it would break to much existing code. It always felt natural to me to interpret empty as false, but I could be wrong. It's strange that this flaw managed to go unnoticed for so long though... The problem with interpreting empty as false is that empty just means no data now. But no data now can mean no data yet or it can mean no more data. The problem is not so much as having empty interpreted as false but that people don't seem to think about which false value would be more appropiate in particular circumstances. IMO reading '' from network connection is the most natural result when no data is ready and this should be treated differently from an EOF which would indicate the connection was closed. But how can you do this when somewhere else '' is used as an indication for an EOF. If Python is too wild for your taste, you might like OCaml. Well then I must say people here give beauty too high a priority. Because there seems a tendency to beautify others code when snippets are posted here. Often enough such snippets don't give enough inoformation to know whether if var is True: can be replaced by if var: or whether other beautifications are appropiate. You might be right about that. I didn't really notice. I think the typical comment is to replace if s != '': with if s: in contexts where s is always a string, And it is IMO this kind of comments that lead to '' being used as an EOF. or to replace if expr != False: with if expr: in cases where expr is an expression that returns True or False etc. In some cases, obvious bugs, such as if (a and b) == True: where the programmer should have written if (a and b): are pointed out. This is not such an obvious bug. Because python allows non boolean operands with and the two don't behave the same. How do you know which behaviour the other person wants? Many of us have a solid mathematical education, and in that world it's considered good behaviour to simplify expressions and remove redundancy. I have yet to see a mathematical work where 0, or any kind of empty sequence is treated as false. In mathematics accuracy is considered vitaly important and won't be sacrified to remove redundancy. Boolean expression are always written out fully. If we see things such as redundant pieces in logic expressions, functions ending in return None, returns directly after a raise, or other meaningless constructs, it suggests that someone might be doing something they don't understand, and then it's helpful to try to point that out. But you don't know if the logic expression are redundant. The suggestions made are usually not equivallent. It's really important to understand what we do when we're programming, not just repeat mantras or wave dead chickens. If people mechanically learn I shouldn't use '!= False' in if-statements in Python, we've failed in trying to help them. If people learn what Python considers true and false, what the boolean operators return, and understands how to use these things in an effective way, we've succeeded. Another aspect of this particular idiom is that it's often better to use the exception system in Python for exceptional situations, than to use one variable to carry several different kinds of information. In that case you wouldn't return an empty sequence if you wanted a false value in a sequence context but would throw an exception. So this would be fine by me, I just don't understand how this would support the use of empty sequences as false. I also don't see how a read from a network connection returning either: a bytestringwhen data is available, '' when no data is available Nonewhen the connection was closed As so much different kinds of information. Besides sometimes different kinds of information is not that exceptional, so why should I throw an exception in such a case? -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
py-serial + CSV
Hi I am just trying to analyze (parse) data from the serial port (I have connected GPS receiver to the ttyS0, so I can read ASCII characters in the CSV form on the serial port 1). I am doing this just to understand how Python works (yes, you can call me Python/Linux newbie :) My environment is Fedora Core 4, Python 2.4.1 CSV alone (to read CSV data from the file) and py-serial alone (to read data from the serial port) are working flawlessly. Even I was trying to google through this group and through the Internet, I am not able to read (and parse) CSV data directly from the serial port. data from my serial port (using py-serial) I am getting this way: import serial s = serial.Serial(port=0,baudrate=4800, timeout=20) s.readline() '$GPRMC,101236.331,A,5026.1018,N,01521.6653,E,0.0,328.1,230805,,*09\r\n' my next intention was to do something like this: import csv r = csv.reader(s.readline()) for currentline in r: if currentline[0] == '$GPRMC': print currentline[2] print currentline[4] but it does not work Thanks for your comments Petr Jakes -- http://mail.python.org/mailman/listinfo/python-list
Re: X-Platform method of remote execution of Windows programs
It seems as if I am doomed to use additional software on the windows box. Damn! The unclarity is in the authentication for the remote box. If I wish to start a process on a remote box with another user's credentials (other than the user I am logged in as), I am unsure as to how to accomplish this. Anything you can add to the docs concerning this would be greatly appreciated. Thanks for the response, Bob -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Antoon Pardon wrote: In that case you wouldn't return an empty sequence if you wanted a false value in a sequence context but would throw an exception. So this would be fine by me, I just don't understand how this would support the use of empty sequences as false. I also don't see how a read from a network connection returning either: a bytestringwhen data is available, '' when no data is available Nonewhen the connection was closed I do not get why returning '' when no data is available? If no data is available then nothing is returned, the function hangs. (Which is the cas for receive) -- rafi Imagination is more important than knowledge. (Albert Einstein) -- http://mail.python.org/mailman/listinfo/python-list
Re: Library and real path name
Fredrik Lundh wrote: Michele Petrazzo wrote: I want to redistribute the library that I create. I create a project, its setup.py that when launched copy all files into the site-packages/library directory. And here it's all ok. When I call my library with: import library library.class() I want that my library know where are its real path (site-packages/library/) you can use the __file__ or __path__ variables to determine this. e.g. # get this module's directory import os prefix = os.path.dirname(__file__) or, inside a package __init__.py file: # get package's main directory prefix = __path__[0] /F Thanks, it work Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt C and Python
praba kar wrote: Dear All, I want to know the link between c and python. Some people with C background use Python instead of programming in C.why? Because I can create software many times faster. And its more fun. Will McGugan -- http://www.kelpiesoft.com -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Op 2005-08-23, rafi schreef [EMAIL PROTECTED]: Antoon Pardon wrote: In that case you wouldn't return an empty sequence if you wanted a false value in a sequence context but would throw an exception. So this would be fine by me, I just don't understand how this would support the use of empty sequences as false. I also don't see how a read from a network connection returning either: a bytestringwhen data is available, '' when no data is available Nonewhen the connection was closed I do not get why returning '' when no data is available? If no data is available then nothing is returned, the function hangs. (Which is the cas for receive) Network connections can be configured to either block or return immediatly when no data is available. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: while c = f.read(1)
Antoon Pardon enlightened us with: The problem with interpreting empty as false is that empty just means no data now. But no data now can mean no data yet or it can mean no more data. The problem is not so much as having empty interpreted as false but that people don't seem to think about which false value would be more appropiate in particular circumstances. By no means can you take all possible future alterations in account. You have to make assumptions somewhere. IMO reading '' from network connection is the most natural result when no data is ready and this should be treated differently from an EOF which would indicate the connection was closed. But how can you do this when somewhere else '' is used as an indication for an EOF. That's called a protocol. If another protocol is used than the software is written for, it'll break. This has nothing to do with accepting something as False or True. And it is IMO this kind of comments that lead to '' being used as an EOF. And who cares if it is? In a blocking environment, it seems pretty okay to me. A read() call could block, waiting for more data to arrive. If there is none because the connection is down, for instance, it could return ''. Of course, raising an exception would be better in such a case, and it would also remove any ambiguity. I have yet to see a mathematical work where 0, or any kind of empty sequence is treated as false. In that case, properly define your variables to hold either booleans or numbers, and only test booleans in an if var: clause, and only test numbers in an if var != 0: clause. a bytestringwhen data is available, '' when no data is available Nonewhen the connection was closed Seems pretty nice to me. In such a case, one could do: data = network.read() if data: handleData(data) if data is None: handleClosedConnection() I don't see a problem here. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: Sanitizing untrusted code for eval()
Here's the pyparsing rendition - about 24 lines of code, and another 30 for testing. For reference, here's the JSON bnf: object { members } {} members string : value members , string : value array [ elements ] [] elements value elements , value value string number object array true false null Download pyparsing at http://pyparsing.sourceforge.net. -- Paul from pyparsing import * TRUE = Keyword(true) FALSE = Keyword(false) NULL = Keyword(null) jsonString = dblQuotedString.setParseAction( removeQuotes ) jsonNumber = Combine( Optional('-') + ( '0' | Word('123456789',nums) ) + Optional( '.' + Word(nums) ) + Optional( Word('eE',exact=1) + Word(nums+'+-',nums) ) ) jsonObject = Forward() jsonValue = Forward() jsonElements = delimitedList( jsonValue ) jsonArray = Group( Suppress('[') + jsonElements + Suppress(']') ) jsonValue ( jsonString | jsonNumber | jsonObject | jsonArray | TRUE | FALSE | NULL ) memberDef = Group( jsonString + Suppress(':') + jsonValue ) jsonMembers = delimitedList( memberDef ) jsonObject Dict( Suppress('{') + jsonMembers + Suppress('}') ) lineComment = '//' + restOfLine jsonComment = FollowedBy('/') + ( cStyleComment | lineComment ) jsonObject.ignore( jsonComment ) testdata = { glossary: { title: example glossary, GlossDiv: { title: S, GlossList: [{ ID: SGML, SortAs: SGML, GlossTerm: Standard Generalized Markup Language, Acronym: SGML, Abbrev: ISO 8879:1986, GlossDef: A meta-markup language, used to create markup languages such as DocBook., GlossSeeAlso: [GML, XML, markup] }] } } } results = jsonObject.parseString(testdata) import pprint pprint.pprint( results.asList() ) print results.glossary.title print results.glossary.GlossDiv print results.glossary.GlossDiv.GlossList.keys() Prints out (I've inserted blank lines to separate the output from the different print statements): [['glossary', ['title', 'example glossary'], ['GlossDiv', ['title', 'S'], ['GlossList', [['ID', 'SGML'], ['SortAs', 'SGML'], ['GlossTerm', 'Standard Generalized Markup Language'], ['Acronym', 'SGML'], ['Abbrev', 'ISO 8879:1986'], ['GlossDef', 'A meta-markup language, used to create markup languages such as DocBook.'], ['GlossSeeAlso', ['GML', 'XML', 'markup']]] example glossary [['title', 'S'], ['GlossList', [['ID', 'SGML'], ['SortAs', 'SGML'], ['GlossTerm', 'Standard Generalized Markup Language'], ['Acronym', 'SGML'], ['Abbrev', 'ISO 8879:1986'], ['GlossDef', 'A meta-markup language, used to create markup languages such as DocBook.'], ['GlossSeeAlso', ['GML', 'XML', 'markup'] ['GlossSeeAlso', 'GlossDef', 'Acronym', 'GlossTerm', 'SortAs', 'Abbrev', 'ID'] -- http://mail.python.org/mailman/listinfo/python-list
Re: py-serial + CSV
McBooCzech wrote: r = csv.reader(s.readline()) csv.reader expects an iterable, not a str. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to 'touch' a file?
Fredrik Lundh wrote: Peter Hansen wrote: You've quoted selectively. He also said Unix-style 'touch', from which one could quite legitimately infer nope. read his post again. Sigh. You're being tiring, Fredrik: '''I'm looking for an easy way to perform a UNIX-style touch, to update the modification time of a file without actually modifying it.''' And if your point is that I spelled UNIX in mixed case, and change the double quotation marks to single quotation marks, you really need to take a break. If your point is that this statement *clearly and unambiguously* rejects the create-if-missing feature as undesirable, then I can say only that you are simply wrong. -Peter -- http://mail.python.org/mailman/listinfo/python-list
str() representation of sequences and dicts
When calling str() on a sequence or dict object, the elements of the sequence/dict will be represented as if their __repr__ method was called. Why is this? Wouldn't it be more consistent when calling str() on sequence to use the __str__ method of the elements in the sequence? As it is now, I often find myself typing something like: print map(str, alist) instead of just print str(alist) For dicts, it's more eleborate still. Is there a better way to deal with this? Rick. -- http://mail.python.org/mailman/listinfo/python-list
Re: Revised PEP 349: Allow str() to return unicode strings
Thomas Heller [EMAIL PROTECTED] wrote: I like the fact that currently unicode(x) is guarateed to return a unicode instance, or raises a UnicodeDecodeError. Same for str(x), which is guaranteed to return a (byte) string instance or raise an error. I guess its analogous to this... int(100L) 100L Wouldn't also a new function make the intent clearer? So I think I'm +1 on the text() built-in, and -0 on changing str. Couldn't basestring() perform this function? Its kind of what basestring is for isn't it? -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt C and Python
praba kar wrote: Dear All, I want to know the link between c and python. Some people with C background use Python instead of programming in C.why? For me, the choice is typically among C++, Perl, Python, and Java. The arguments for Python relative to these languages are: 1. Python's standard library includes a lot of functionality not in the C++ standard library. 2. Python's syntax is the cleanest of these languages. 3. I don't have to compile Python, so I can test changes much more quickly that with C++ or Java. 4. System calls made from Python are more likely to be portable among the platforms I use most (WindowsXP, AIX, Linux, and MacOSX) than system calls from C++. 5. Scripting is easier in Python than in Java, particularly with regard to environment variables and process control. Of course, these are only my opinions. I am particularly not an expert on Python or Java. -- http://mail.python.org/mailman/listinfo/python-list
RE: X-Platform method of remote execution of Windows programs
[EMAIL PROTECTED] | It seems as if I am doomed to use additional software on the windows | box. Damn! 'Fraid so. If your question is: given a vanilla Windows box, can I invoke an executable on the Windows box from a Linux box? I believe the later versions of Windows run or can run Terminal Services by default, which can be invoked by the Remote Desktop protocol, but not -- I think -- any kind of Shell. Could be wrong. Of course, there are a thousand and one ways of doing this if you're prepared to have a long-running process (in Python or anything else which takes your fancy) which you can connect to with some command or other. Obvious possibilities in the Python line are: Pyro, XML-RPC, a socket server, Twisted, and so on. But you probably knew that. | The unclarity is in the authentication for the remote box. If I wish | to start a process on a remote box with another user's credentials | (other than the user I am logged in as), I am unsure as to how to | accomplish this. Anything you can add to the docs concerning | this would | be greatly appreciated. Thanks for the info. The answer is to use the slightly ungainly connect_server function. I've added an example on the cookbook page: http://timgolden.me.uk/python/wmi_cookbook.html#connect_as_a_named_user and I'd encourage you, if you haven't already, to look at the docstring documentation for the module, which is sometimes more useful than what I've got on the site. (Note to self: must do something about that). I have an oft-promised and not-yet-released version 1.0 of this module, which has a slightly tidier connection function, allowing you to call just one method (.connect, in fact) in which you can specify whatever combination of username, security context, namespace, etc. is allowed by the underlying calls. Not there yet, though. Hope that helps. TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: py-serial + CSV
So do I have to save to the file first and analyze later on? Or there is an other way how to process it (read from the serial and analyze data) on the fly? Petr Jakes -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] Revised PEP 349: Allow str() to return unicode strings
just tested the proposed implementation on a unicode-naive module basically using import sys import __builtin__ reload( sys ); sys.setdefaultencoding( 'utf-8' ) __builtin__.__dict__[ 'str' ] = new_str_function et voilà, str() calls in the module are rewritten, and print u'düsseldorf' does work as expected(*) (even on systems where i have no access to sitecustomize, like at my python-friendly isp's servers). --- * my expectation is that unicode strings do print out as utf-8, as i can't see any better solution. i suggest to make this option available e.g. via a module in the standard lib to ease transition for people in case the pep doesn't make it. it may be applied where deemed necessary and left ignored otherwise. if nobody thinks the reload hack is too awful and this solution stands testing, i guess i'll post it to the aspn cookbook. after all these countless hours of hunting down ordinal not in range, finally i'm starting to see some light in the issue. _wolf On Tue, 23 Aug 2005 12:39:03 +0200, M.-A. Lemburg [EMAIL PROTECTED] wrote: Thomas Heller wrote: Neil Schemenauer [EMAIL PROTECTED] writes: [Please mail followups to [EMAIL PROTECTED] The PEP has been rewritten based on a suggestion by Guido to change str() rather than adding a new built-in function. Based on my testing, I believe the idea is feasible. It would be helpful if people could test the patched Python with their own applications and report any incompatibilities. I like the fact that currently unicode(x) is guarateed to return a unicode instance, or raises a UnicodeDecodeError. Same for str(x), which is guaranteed to return a (byte) string instance or raise an error. Wouldn't also a new function make the intent clearer? So I think I'm +1 on the text() built-in, and -0 on changing str. Same here. A new API would also help make the transition easier from the current mixed data/text type (strings) to data-only (bytes) and text-only (text, renamed from unicode) in Py3.0. -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Xah Lee wrote: You stupid UNIX donkey! Why you wrap your email? You wasted time formatting email that you could have used to read Python documentation and critique it! How you expect to change world if you spend time formatting email??? And I no want hear you let Google groups format it! If you use stupid UNIX-using, text monkey service like Google to format your email, then you no longer worthy to be our prince!! I, Lah Xee, master of wit and expert grammarian must rise to occasion and become pre-eminent troll for common good of all mankind! Down with UNIX!! Down with Mac!! Down with Perl!! Down with Xah Lee!! You will all bow before my astonishing wisdom and knowledge!! Now, why do this so-called print statement in Python f*ck up my text by splattering it with end of line characters? Lah Xee Master Grammarian Pre-Eminent Troll Unix, RFC, and Line Truncation [Note: unix tradition requires that a return be inserted at every 70 characters in email messages or so so that each line are less than 80 characters. Unixers made this as a requirement into an RFC document.] Xah Lee, 20020511 This truncation of lines business is a hatred of mine, from email formatting to formatting of program codes. I have been fighting with the unix slew of morons about the line cut for years. The unix morons are the number one excuse expert, that whenever in an argument they'll mention some RFC “specifications”. (RFC = Really Fucking Common, invented by mostly unix folks in the 70s.) the unix morons, think that the world should truncate lines just like their incompetent operating system silently truncate lines (and it still DOES, folks! e.g. ps, tar, tcsh.) Around 1998 when i was using Outlook Express or Eudora before that, i remember i can set lines to not hard-wrap, and i did. Boy that always pissed the unix blockheads. In their diddly eyes and lousy email software, i'm breaking standards, making things hard to read, and being a stupid ass. Their brain fail to see what unix ways are not capable of. These guys are the same slew of morons who cry in pain about how the web should not commercialize (circa 1996), and email should be text only (anti-MIME, circa 1995), and lynx is the best browser (circa 1995), and GUI is for sissys and mouse is for pussies and Apple computer is for kids (circa 1987). There is no reason for a paragraph encoding to be splattered with end of line characters, nor the human labor expended. There is reason for paragraphs to be displayed not too wide, and that is readability. What the unixer could not get clear of is a distinction of concepts. Because their fantastically hacked-up operating system operate by the principle that lines should not be some 80 chars or else it will be truncated and *silently* too, thus it became _necessarily_ their _habit_ and thought that line truncation business is natural and a human duty. Unknown of these setups, the unix geeks go by their presumption that all text should be hard wrapped, as if parameters should be hard-coded. I recall, two particular unix hotshots who bugged me about the line truncations business is the Perl priest Tom Christiansen, who used to reside over comp.lang.perl.*, and another unix jockey Chris Nandor, who was a MacPerl proponent now the main maintainer. It is not a coincidence that the people who go out of their way to complain about any “format=flowed” or softwrapped or logically-formatted lines in emails are always the unixers. The unix twits will start a flame war over a petty formatting issue, because it's unix's training to bent over pettiness, not to mention they are the ones who are retarded on the issue of line truncation. As i have alluded to above, there are serious problems with the line-truncation ways of thinking. The gist is that it is a form of physical formatting as opposed to logical. (think softwrap vs hardwrap, parameter vs hard-code) Those who are familiar with the history or reason for SGML and HTML should understand the problem. Many of you familiar with drive of evolution of HTML from 1995 days to today's CSS XML should also understand the issue. We wish to encode information, and be flexible about representation, not botching info into one particular representation. The harm done by the unixers to society is of a long lasting and pervasive nature. First is the RFC, which serves as the mob's standard, which requires that every emailer should be broken like unix, so that unix can process them without problems. Fuck unix and fuck unix geeks. Secondly, it drains human labor. Right this second there are hundreds of people pressing returns or fixing jagged lines unnecessarily. Thinking and computer could have done that for us, if not for fucking stupid unix and its people. Thirdly, a generation of programs and programer's times are wasted over tools that mutilate paragraphs into pieces. (in emacs, there's fill-paragraph etc, and in BBEdit it's just called “Hard Wrap”) Fourthly, physical formatting
what's the difference between *.dll and *.pyd if both of them are extended python module?
i have written python extend module by c/c++, but i saw a module of a software(pyMOL, you can get it from http://pymol.sourceforge.net/) called _cmd.pyd instead of _cmd.dll. and it is written by c/c++ also, the author use makefile to compile it into _cmd.pyd. i have some question about it: 1. what's the difference between them? i saw the code is same as common c++ extended python module, can i use microsoft visual C++ to create a dll project for compiling it as _cmd.dll? 2. i have never written a module with extension *.pyd, how to make a *.pyd? and, i doubt, how the author debug the _cmd.pyd, only by Makefile? 3. i have a common problem about writting a extend module by c/c++, i often use msvc to write it, but i only can invoke release dll, not debug dll, even i use command like this: python_d test.py, in which case, test.py import test.dll, and invoke test.hello() api. why? anybody has nice way to debug it? thank you. any help would be appreciated. with my best regards, Wen -- http://mail.python.org/mailman/listinfo/python-list
Re: py-serial + CSV
McBooCzech wrote: So do I have to save to the file first and analyze later on? Certainly not. Or there is an other way how to process it (read from the serial and analyze data) on the fly? I've never used py-serial, so I was hoping someone else would jump in with the best way to do this (or perhaps you can find it in the documentation). One way would be to use the iter() built-in to make it into an iterable, like this: iterable = iter(s.readline, ) Note that you do not call s.readline() here; you are only supplying the bound method itself as an argument. iter() will call it later. I'm assuming that s.readline returns an empty string when there is no more input. Please replace that with whatever end sentinel it actually uses. (None?) Another way would be to use s.readlines(), which returns a list, which is iterable, but you would have to wait until the entire list were collected before beginning processing. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to 'touch' a file?
Peter Hansen wrote: Fredrik Lundh wrote: Peter Hansen wrote: You've quoted selectively. He also said Unix-style 'touch', from which one could quite legitimately infer nope. read his post again. Sigh. You're being tiring, Fredrik: You probably mean tiresome. Bots can be like that sometimes. And not only bots '''I'm looking for an easy way to perform a UNIX-style touch, to update the modification time of a file without actually modifying it.''' And if your point is that I spelled UNIX in mixed case, and change the double quotation marks to single quotation marks, you really need to take a break. If your point is that this statement *clearly and unambiguously* rejects the create-if-missing feature as undesirable, then I can say only that you are simply wrong. I rather suspect his point is that the OP's problem description specifically implies the file's prior existence. As I believe Fredrik did, I read update the modification time of a file to mean that the file already has a modification time. This would make the import of the path module you mentioned a little over the top given there's already a function in os to handle the requirement. Given that both solutions have been presented, as far as the rest of the list is concerned we are probably all three just being tiresome now. The OP can choose whichever best meets his real requirements, whether they were accurately stated or not. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: gtkmozembed in fedora core 3
Martin DeMello wrote: Could someone help me get gtkmozembed working under fc3? The only available rpms need gnome-python2 = 2.9 and fc3 ships with 2.6. I can't find any fc3 rpms to upgrade gnome-python2 and I can't quite figure out what I'd need to compile just to install gtkmozembed and the python bindings (I need to deploy this at work, so I'm trying to make the minimal possible change to a stock fc3 install). Upgrading to fc4 is sadly not an option :-/ martin If you can't find any rpm's there aren't any available. You need to compile mozilla with (I think) support for gtkmozembed but I guess that's done by default when you compile mozilla with ac_add_options --enable-default-toolkit=gtk2 in your mozconfig file. Check /usr/lib/mozilla for libgtkembedmoz.so if it's not there you'll have to rebuild your mozilla/firefox rpm , again I think, these are just some random tips .. Good luck! -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Light Revisted?
Steve M wrote: I agree with you in part and disagree in part. [snip..] Now, what I do agree with is a Python that can be run from a folder without having to be installed on the system. That could have lots of benefits, if the details with pythonpath and whatever could be sorted out. For example I haven't upgraded to 2.4 yet because I have 20 You mean like Movable Python ? *grin* (Windoze only though I'm afraid) http://www.voidspace.org.uk/python/movpy different packages (e.g. SOAPpy, ZODB, whatever) installed on WinXP, many of which required me selecting my 2.3 installation when I installed them. I have no idea what will happen to all those if I run the ActiveState installer for 2.4. I seem even to remember reading that I have to un-install 2.3 before installing 2.4. I don't want to re-install those 20 packages. Anyway I haven't had time to research it and it isn't pressing, even though I'd like to start trying decorators and generator expressions. I faced similar issues - in the end it wasn't such a pain though. http://www.voidspace.org.uk/python/articles/upgrading_python.shtml Just make a list of the modules you want to keep and fetch the Python 2.4 installers before making the switch. Gives you a nice opportunity to clean up your 'site-packages' folder. Regards, Fuzzyman http://www.voidspace.org.uk/python -- http://mail.python.org/mailman/listinfo/python-list
Re: Network performance
Roland Hedberg [EMAIL PROTECTED] wrote: [ ... ] The client sends a number of lines (each ending with \n) and ends one set of lines with a empty line. When the client sends a line with only a . it means I'm done close the connection. Letting the client open the connection and sending a number of sets I was surprised to find that the performance was equal to what Twisted/ XMLRPC did. Around 200 ms per set, not significantly less. So what can be done to speed up things or is Python incapable of supporting fast networking (just a teaser). That 200ms is a dead giveaway (if you've run into this issue before). If you've got a Linux box to hand, try sticking the server on there and see what happens. The key to what is going on is here: http://www.port80software.com/200ok/archive/2005/01/31/317.aspx The easy solutions are to either change: def send( self, rdf ): self.s.send( rdf ) self.s.send( \n ) to def send( self, rdf ): self.s.send( rdf+\n ) or to self.s.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 0) after connecting self.s . What's going on is something like this: 1. Client sends rdf 2. Server receives rdf. But it hasn't received the \n yet, so it doesn't have a response to send yet. And because of delayed ACK, it won't send the ACK without the DATA packet containing that response. 3. Meanwhile, the client tries to send \n, but because Nagle is on, it would make an underful packet, and it hasn't received the ACK from the last packet yet, so it holds on to the \n. 4. Eventually (after 200ms on Windows and, I believe, BSDs, hence OSX, but much less on Linux) the Server gives up waiting for a DATA packet and sends the ACK anyway. 5. Client gets this ACK and sends the \n. 6. At which point the Server has a complete line it can process, and sends its reponse in a DATA with the ACK to the \n piggybacked. So the solutions are either send rdf+\n as a single packet in 1, and the exchange will skip straight to 6, avoiding the 200ms delay; or disable Nagle so 3 doesn't hold and the Client sends the \n immediately instead of waiting for the ACK in 5. -- \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: Jargons of Info Tech industry
Xah Lee wrote: (circa 1996), and email should be text only (anti-MIME, circa 1995), I think e-mail should be text only. I have both my email and news readers set to display in plain text only. It prevents the marketeers and spammers from obtaining feedback that my email address is valid. A surprising amount of information can be obtained from your computer by allowing HTML and all of it's baggage when executing on your computer. Phishing comes to my mind first and it works because people click the link without looking to see where the link really takes them. reason for SGML and HTML should understand the problem. Many of you familiar with drive of evolution of HTML from 1995 days to today's CSS XML should also understand the issue. We wish to encode information, I do not want spammers to encode information in their emails. Xah Please go to jobs.org Len == Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups = East and West-Coast Server Farms - Total Privacy via Encryption = -- http://mail.python.org/mailman/listinfo/python-list
Re: what's the difference between *.dll and *.pyd if both of them are extended python module?
wen wrote: 1. what's the difference between them? i saw the code is same as common c++ extended python module, can i use microsoft visual C++ to create a dll project for compiling it as _cmd.dll? .pyd is just a naming convention. It was probably introduced to prevent name clashes with unrelated DLLs. 2. i have never written a module with extension *.pyd, how to make a *.pyd? and, i doubt, how the author debug the _cmd.pyd, only by Makefile? I think you can configure the output file name in the project properties. 3. i have a common problem about writting a extend module by c/c++, i often use msvc to write it, but i only can invoke release dll, not debug dll, even i use command like this: python_d test.py, in which case, test.py import test.dll, and invoke test.hello() api. why? anybody has nice way to debug it? thank you. Assuming your module is called _cmd: - add a function init_cmd_d to the extension module (init_cmd_d simply calls init_cmd) - import cmd_d in your Python script I must admit I haven't tried this, it is based on my understanding of how Python loads extension modules. Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: Reg python nature.
Do some reading, and stop hijacking threads http://www.python.org/doc/faq/general.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt C and Python
On 23 Aug 2005 01:22:31 -0700 James wrote: Some people with C background use Python instead of programming in C.why? Becuase it is much more efficient. It's rather because _they_ are much more efficient (that is, with Python). -- jk -- http://mail.python.org/mailman/listinfo/python-list
Re: Eve from Adams' Ribs
Godwin wrote: I think its possible with python as it is called a dynamic language. Certainly, but what's really the point with these classes? If they are completely generated from tables, they won't have different behaviour anyway, just a different chunk of attributes to fetch, save and update. It's probably as easy to just have one class, and to have a dynamic list of attributes and values that you define by passing in the table name in __init__. -- http://mail.python.org/mailman/listinfo/python-list
Re: Network performance
23 aug 2005 kl. 15.14 skrev Sion Arrowsmith: Roland Hedberg [EMAIL PROTECTED] wrote: The easy solutions are to either change: def send( self, rdf ): self.s.send( rdf ) self.s.send( \n ) to def send( self, rdf ): self.s.send( rdf+\n ) or to self.s.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 0) after connecting self.s . I had just caught this but didn't really know way yet! What's going on is something like this: Excellent description ! Thanks ever so much !! -- Roland -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
l v [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Xah Lee wrote: (circa 1996), and email should be text only (anti-MIME, circa 1995), I think e-mail should be text only. I have both my email and news readers set to display in plain text only. It prevents the marketeers and spammers from obtaining feedback that my email address is valid. A surprising amount of information can be obtained from your computer by allowing HTML and all of it's baggage when executing on your computer. Phishing comes to my mind first and it works because people click the link without looking to see where the link really takes them. A formatting-only subset of HTML would be useful for both e-mail and Usenet posts. -- http://mail.python.org/mailman/listinfo/python-list
Re: Reg python nature.
praba kar [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: Dear All, I want to know the link between c and python. Some people with C background use Python instead of programming in C.why? I will now reveal the secret that explains why some people who know how to program in C use Python instead: because they want to. The primary Python implementation is written in C, and makes use of C library functions. C applications are also written in C and make use of C library functions. So *there* is a link. Here are some possible reasons for using Python instead of C: * Some C programmers do not enjoy all aspects of C (such as managing dynamic allocation and deallocation of data structures), and prefer the higher-level abstraction of Python for routine tasks. * Sometimes extremely high performance is not an issue (probably most times), so the language choice becomes one of deciding which is more convenient. Generally, that would be Python. * Systems that must last for long periods of time will often require maintenance, and the clarity of Python code makes it easier to maintain than C equivalents in many cases. The actual code size is often smaller, and making changes requires fewer additional lines of code. This all adds up to a substantial maintenance advantage. * Many programmers use more languages than just one. Python is a good general-purpose language that is quite reasonable to choose as an alternative (or addition) to C. For those coming from a C background, learning the basics of Python syntax is quite easy. Those who have habitually used pseudocode to describe their program concepts may find it even easier to pick up Python. I hope at least one of these points addresses your question. I don't know that your subject line, referring to the nature of Python, is actually very close to the question itself, though. Programmers with a background in any other language will need to reach an understanding of Python's true nature before they can use it comfortably. The same is true when learning any other language; the language's true nature reveals itself with enough use. -- rzed -- http://mail.python.org/mailman/listinfo/python-list
yapsnmp port issues
Hello c.l.py, Does anyone else have experience with that? I'm somewhat stuck. The problem is basically the same as here: http://groups-beta.google.com/group/mailing.unix.net-snmp-users/browse_thread/thread/92fdea477a2f67ba/48924041d27b748b?tvc=2q=yapsnmp+port#48924041d27b748b that is, I can't force a Session object to connect to any other port than 161. And, you may have anticipated it, the solution given in the referenced thread doesn't work, all I get is a socket.gaierror: Name or service not known. Any thoughts on that? I also suspect that I might have messed something during compilation, because it didn't go smooth at all. That, hovewer, will probably be irrelevant, since yapsnmp is just a SWIG-generated wrapper plus some higher-level interfaces. And everything seems right in the source code... -- http://mail.python.org/mailman/listinfo/python-list
Re: Doubt C and Python
On 2005-08-23, praba kar [EMAIL PROTECTED] wrote: I want to know the link between c and python. Some people with C background use Python instead of programming in C.why? Because C is a dangerous, low-level language unsuitable for general-purposed application programming. I use C for: 1) Real-time, embedded stuff where memory is measured in KB rather than MB. 2) Device drivers where the other choice is assembly. -- Grant Edwards grante Yow! I will invent TIDY at BOWL... visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: py-serial + CSV
On 2005-08-23, McBooCzech [EMAIL PROTECTED] wrote: import serial s = serial.Serial(port=0,baudrate=4800, timeout=20) s.readline() '$GPRMC,101236.331,A,5026.1018,N,01521.6653,E,0.0,328.1,230805,,*09\r\n' my next intention was to do something like this: import csv r = csv.reader(s.readline()) for currentline in r: if currentline[0] == '$GPRMC': print currentline[2] print currentline[4] but it does not work For something that simple (the data itself doesn't contain any commas), it's probably easier to use the string's split method rahter than CSV. Try something like this: line = s.readline() words = line.split(',') -- Grant Edwards grante Yow! Now KEN and BARBIE at are PERMANENTLY ADDICTED to visi.comMIND-ALTERING DRUGS... -- http://mail.python.org/mailman/listinfo/python-list
Convert float to string ...
Hi, a simple question but i found no solution: How can i convert a float value into a string value? string_value1 = string(float_value) + ' abc' doesn't work ... Thanks Konrad -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert float to string ...
On 8/23/05, Konrad Mühler [EMAIL PROTECTED] wrote: How can i convert a float value into a string value? string_value1 = string(float_value) + ' abc' string_value1 = str(float_value) + ' abc' -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Sanitizing untrusted code for eval()
[Jim Washington] I'm still working on yet another parser for JSON (http://json.org). It's called minjson, and it's tolerant on input, strict on output, and pretty fast. The only problem is, it uses eval(). It's important to sanitize the incoming untrusted code before sending it to eval(). I think that you shouldn't need eval to parse JSON. For a discussion of the use of eval in pyjsonrpc, between me and the author, Jan-Klaas Kollhof, see the content of the following links. A discussion of the relative time *in*efficiency of eval is also included: it is much faster to use built-in functions such str and float to convert from JSON text/tokens to strings and numbers. http://mail.python.org/pipermail/python-list/2005-February/265805.html http://groups.yahoo.com/group/json-rpc/message/55 Pyjsonrpc uses the python tokeniser to split up JSON strings, which means that you cannot be strict about things like double () vs. single (') quotes, etc. JSON is so simple, I think it best to write a tokeniser and parser for it, either using a parsing library, or just coding your own. -- alan kennedy -- email alan: http://xhaus.com/contact/alan -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert float to string ...
On 2005-08-23, Konrad Mühler [EMAIL PROTECTED] wrote: Hi, a simple question but i found no solution: How can i convert a float value into a string value? string_value1 = string(float_value) + ' abc' string_value1 = str(float_value) + ' abc' Or the more versatile: string_value1 = %10.3f abc % float_value -- Grant Edwards grante Yow! I'm having a BIG at BANG THEORY!! visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert float to string ...
Konrad Mühler wrote: Hi, a simple question but i found no solution: How can i convert a float value into a string value? just use the str built-in type: f = 9.99 str(f) '9.99' -- deelan, #1 fan of adriana lima! http://www.deelan.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert float to string ...
Konrad Mühler wrote: a simple question but i found no solution: How can i convert a float value into a string value? string_value1 = string(float_value) + ' abc' str(float_value) + 'abc' repr(float_value) + abc '%fabc' % float_value '%gabc' % float_value (etc) the tutorial has more information: http://docs.python.org/tut/node9.html /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Convert float to string ...
How can i convert a float value into a string value? Try: string_value1 = str(float_value) + ' abc' or: string_value1 = repr(float_value) + ' abc' Type in an interactive python session. help(str) or: help(repr) regards Matt -- | Matt Hammond | RD Engineer, BBC Research and Development, Tadworth, Surrey, UK. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Mike Schilling [EMAIL PROTECTED] wrote: l v [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Xah Lee wrote: (circa 1996), and email should be text only (anti-MIME, circa 1995), I think e-mail should be text only. I have both my email and news readers set to display in plain text only. It prevents the marketeers and spammers from obtaining feedback that my email address is valid. A surprising amount of information can be obtained from your computer by allowing HTML and all of it's baggage when executing on your computer. Phishing comes to my mind first and it works because people click the link without looking to see where the link really takes them. A formatting-only subset of HTML would be useful for both e-mail and Usenet posts. Used to be that the formatting-only subset of HTML was called HTML. Used to be that people were wise to itinerant kooks such as the OP. Richard -- http://mail.python.org/mailman/listinfo/python-list
High Level FTP library
Hello, Is there any Python library similar to NET::FTP from Perl? ftplib seems too lowlevel. I already found a few, but would like to get one that is endorsed by the community. Thanks, Paulo -- http://mail.python.org/mailman/listinfo/python-list
Re: High Level FTP library
Paulo Pinto wrote: Hello, Is there any Python library similar to NET::FTP from Perl? ftplib seems too lowlevel. I already found a few, but would like to get one that is endorsed by the community. Thanks, Paulo libftp sucks just look at how it's written such evil code! Not that I know of, write your own based on libftp good luck! -- http://mail.python.org/mailman/listinfo/python-list
Re: literal accented characters in python asp page with Microsoft IIS
I've tried it, but I still get this message from IIS : HTTP/1.1 500 Server Error -- http://mail.python.org/mailman/listinfo/python-list
Nested Regex Conditionals
Hi All, I know that several of you will probably want to reply you should write a parser, and I may. For that matter any tips on theory in that direction would be appreciated. However, if you would indulge me in my regex question I would also be most grateful. I'm writing an edi parser and to be in compliance with the specification I need to have conditionals that are dependent on conditionals. In some regular expression implementations this is possible. The code ... #!/usr/bin/env python import re pattern = re.compile(r (?Pfirst(first)) (?(first) (?Psecond(second)) ) (?(second) (?Pthird(third)) ) , re.VERBOSE) string = 'firstsecondthird' match = re.match(pattern,string) print match.group('first','second','third') Prints ('first', 'second', None) and I haven't found any way to have a second conditional, nor any reference to it in any documentation I've found. Am I missing something, and it is possible? Or is it not possible in python? It seems like it might be a bug, as it knows there is a group (None, instead of an IndexError), but it doesn't match ... Thanks for any help :) Paul -- http://mail.python.org/mailman/listinfo/python-list
PEPM 2006: Call for Papers -- ACM SIGPLAN 2006 Workshop on Partial Evaluation and Program Manipulation
C A L L F O R P A P E R S === P E P M 2006 === ACM SIGPLAN 2006 Workshop on Partial Evaluation and Program Manipulation (Affiliated with POPL 2006) http://www.cis.ksu.edu/santos/pepm06 January 9-10, 2006 Charleston, South Carolina The PEPM Symposium/Workshop series aims to bring together researchers and practitioners working in the areas of program manipulation, partial evaluation, and program generation. PEPM focuses on techniques, supporting theory, tools, and applications of the analysis and manipulation of programs. The 2006 PEPM workshop will be based on a broad interpretation of semantics-based program manipulation. This year, a concerted effort will be made to expand the scope of PEPM significantly beyond the traditionally covered areas of partial evaluation and specialization and include practical applications of program transformations such as refactoring tools, and practical implementation techniques such as rule-based transformation systems. In addition, the scope of PEPM will be broadened to cover manipulation and transformations of program and system representations such as structural and semantic models that occur in the context of model-driven development. In order to reach out to practitioners, a separate category of tool demonstration papers will be solicited. Topics of interest for PEPM'06 include, but are not limited to: * Program and model manipulation techniques such as transformations driven by rules, patterns, or analyses, partial evaluation, specialization, slicing, symbolic execution, refactoring, aspect weaving, decompilation, and obfuscation. * Program analysis techniques that are used to drive program/model manipulation such as abstract interpretation, static analysis, binding-time analysis, dynamic analysis, constraint solving, and type systems. * Analysis and transformation for programs/models with advanced features such as objects, generics, ownership types, aspects, reflection, XML type systems, component frameworks, and middleware. * Techniques that treat programs/models as data objects including meta-programming, generative programming, model-driven program generation and transformation. * Application of the above techniques including experimental studies, engineering needed for scalability, and benchmarking in a wide variety of domains including source code manipulation, domain-specific language implementations, scientific computing, middleware frameworks and infrastructure needed for distributed and web-based applications. We especially encourage papers that break new ground including descriptions of how program/model manipulation tools can be integrated into realistic software development processes, descriptions of robust tools capable of effectively handling realistic applications, and new areas of application such as rapidly evolving systems, distributed and web-based programming including middleware manipulation, model-driven development, and on-the-fly program adaptation driven by run-time or statistical analysis. Submission Categories, Guidelines, and Proceedings: Regular Research Papers must not exceed 10 pages in ACM Proceedings style. Tool demonstration papers must not exceed 4 pages in ACM Proceedings style, and authors will be expected to present a live demonstration of the described tool at the workshop. Suggested topics, evaluation criteria, and writing guidelines for both research tool demonstration papers will be made available on the PEPM'06 Web-site. Papers should be submitted electronically via the workshop web site. We plan to publish the workshop proceedings in ACM SIGPLAN Notices (with full papers appearing in the ACM Digital Library) and selected papers will be invited for a journal special issue dedicated to PEPM'06. Important Dates: Submission: October 7, 2005 Apia, 11:59pm, Samoan time (firm deadline, no extensions) Notification..: November 18, 2005 Camera-Ready Paper: December 16, 2005. Workshop co-Chairs: John Hatcliff, Kansas State University, USA ([EMAIL PROTECTED]) Frank Tip, IBM T.J. Watson Research Center, USA ([EMAIL PROTECTED]) PEPM 2006 Program Committee: Krzysztof Czarnecki University of Waterloo Gary Daugherty Rockwell Collins Advanced Technology Center Tom Dean Queen's University Mangala Gowri Nanda IBM India John Hatcliff (co-chair) Kansas State University Nevin Heintze Agere Systems Jaakko Järvi Texas A M University Jens Krinke University of Hagen Shriram Krishnamurthi Brown University Julia Lawall University of Copenhagen (DIKU) Oege de Moor Oxford University Germán Puebla Technical University of Madrid Peter Sestoft Royal Veterinary and Agricultural University (Denmark) Gregor Snelting University of Passau Frank Tip (co-chair) IBM T.J. Watson Research Center Eelco Visser Universiteit Utrecht --
How to execute python script in Windows
People, Can someone please tell me how to execute a python script in windows? Thanks DaveDave FickbohmUse Technology to the Fullest1250 45th st suite 200Emeryville, CA, 94608510 594 4151 voice-- http://mail.python.org/mailman/listinfo/python-list
Re: pythonXX.dll size: please split CJK codecs out
Giovanni Bajo wrote: Hello, python24.dll is much bigger than python23.dll. This was discussed already on the newsgroup, see the thread starting here: http://mail.python.org/pipermail/python-list/2004-July/229096.html I don't think I fully understand the reason why additional .pyd modules were built into the .dll. OTOH, this does not help anyone, since: - Normal users don't care about the size of the pythonXX.dll, or the number of dependencies, nor if a given module is shipped as .py or .pyd. They just import modules of the standard library, ignoring where each module resides. So, putting more modules (or less modules) within pythonXX.dll makes absolutely no differences for them. - Users which freeze applications instead are *worse* served by this, because they end up with larger programs. For them, it is better to have the highest granularity wrt external modules, so that the resulting freezed application is as small as possible. snip 1.8Mb - life's too short what gain would you get from removing 1Mb from that? So it can get on a floppy? ;-). That would be more effort than is needed, IMHO, even my handy/mobile phone/cell phone can easily cope with 1.8Mb! Neil -- Neil Benn Senior Automation Engineer Cenix BioScience BioInnovations Zentrum Tatzberg 47 D-01307 Dresden Germany Tel : +49 (0)351 4173 154 e-mail : [EMAIL PROTECTED] Cenix Website : http://www.cenix-bioscience.com -- http://mail.python.org/mailman/listinfo/python-list
RE: How to execute python script in Windows
[David Fickbohm] People, Can someone please tell me how to execute a python script in windows? Thanks Dave Have a look at this: http://www.python.org/doc/faq/windows.html#how-do-i-run-a-python-program-under-windows TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list