Can we pass some arguments to system(cmdline)?
Hi! I was wondering if we can pass some arguments to system(cmdline)? E.g in Perl, we can do something like: $dir=/home/cypher; system(ls $dir); which would instruct Perl to do an ls /home/cypher But in python, doing something like dir=/home/cypher system(ls dir) would cause python to execute ls dir where dir might not exist at all! Is there a way to reproduce the same thing in Python? Thanks for any insights. cheers, Didier. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can we pass some arguments to system(cmdline)?
Didier C wrote: Hi! I was wondering if we can pass some arguments to system(cmdline)? E.g in Perl, we can do something like: $dir=/home/cypher; system(ls $dir); which would instruct Perl to do an ls /home/cypher But in python, doing something like dir=/home/cypher system(ls dir) would cause python to execute ls dir where dir might not exist at all! Is there a way to reproduce the same thing in Python? Thanks for any insights. cheers, Didier. You should use something like this: dir = /home/cypher system(ls %s % dir) -- Qiangning Hong ___ / lp1 on fire \ | | \ -- One of the more obfuscated kernel messages / --- \ \ \ ___ _ ___ / \ //| / \ | | // | | | | | // | | | | | || | | | | | | {} | / | | | | ||/| | | ||==| | | | \___/ | | | | | -- http://mail.python.org/mailman/listinfo/python-list
Re: Can we pass some arguments to system(cmdline)?
On Sun, Jun 19, 2005 at 11:12:05PM -0700, Didier C wrote: Hi! I was wondering if we can pass some arguments to system(cmdline)? E.g in Perl, we can do something like: $dir=/home/cypher; system(ls $dir); which would instruct Perl to do an ls /home/cypher But in python, doing something like dir=/home/cypher system(ls dir) system(ls %(dir)s % locals()) system(ls %s % dir) system(ls %(name)s % dict(name=dir) But you should consider if you really really want to do this. What happens when in dir? What happens when dir == ; rm -Rf / Andreas -- http://mail.python.org/mailman/listinfo/python-list
Re: calling subclass constructor question
In Han Kang wrote: So each of the sub classes plots a different type of graph. The superclass defines methods that are the same for all the plots. I want to be able to pick some points and be able to generate a more plots. What I was wondering if I could define in a method in the superclass of an object the ability to make a brand new subclass (new plot). So basically, one plot makes another plot, but it'd be nice if i could put all the code in the superclass. Still not sure I understand you. How are you determining which new type of plot to create? If I'm an instance of class PlotA, and the user asks me to create create a new Plot, is it always another instance of class PlotA, or could it be an instance of another class? If the former, you can use a classmethod, e.g.: class Plot(object): @classmethod def new(cls, ...): result = cls(...) # maybe modify result some more return result If the latter, this doesn't sound like something that should be a method of an instance. It sounds more like a factory function. Why not just make it a module-global function, e.g.: def newPlot(...): # determine which kind of Plot object to create ... if ...: return PlotA(...) ... A method signature of the method you want to write would help a lot... STeVe -- http://mail.python.org/mailman/listinfo/python-list
catch argc-argv
Hello, I am writting bindings for a FEM application. In one of my function 'initModulename', called when the module is imported, I would like to get the argc and argv arguments used in the main function of Python. So, my question is: does the Python API containe fonctions like 'get_argc()' and 'get_argv()' ? Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: catch argc-argv
mg wrote: Hello, I am writting bindings for a FEM application. In one of my function 'initModulename', called when the module is imported, I would like to get the argc and argv arguments used in the main function of Python. So, my question is: does the Python API containe fonctions like 'get_argc()' and 'get_argv()' ? Thanks, Use sys.argv: http://python.org/doc/2.4.1/lib/module-sys.html HTH, Wolfram -- http://mail.python.org/mailman/listinfo/python-list
Re: Can we pass some arguments to system(cmdline)?
Didier C wrote: E.g in Perl, we can do something like: $dir=/home/cypher; system(ls $dir); Is there a way to reproduce the same thing in Python? system(ls %s % dir) But you should really be using subprocess for security (so that if dir==/home/foo; rm -rf / nothing bad will happen): import subprocess subprocess.Popen(['ls', dir]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something similar to ?: operator (C/C++) in Python?
Ron Adam wrote: You might be able to use a dictionary of tuples. call_obj = {(type_obj1,0):obj1a, (type_obj1,0):obj1b, (type_boj2,1):obj2a, (type_obj2,1):obj2b, etc... } call_obj[(type_of_obj,order)]() Regards, Ron This won't work like I was thinking it would. But to get back to your is there a ? operator question... Try this. def foo(): return foo def boo(): return boo print (foo, boo)[10]()# prints boo print (foo, boo)[10]()# prints foo Regards, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: catch argc-argv
Wolfram Kraus wrote: mg wrote: Hello, I am writting bindings for a FEM application. In one of my function 'initModulename', called when the module is imported, I would like to get the argc and argv arguments used in the main function of Python. So, my question is: does the Python API containe fonctions like 'get_argc()' and 'get_argv()' ? Thanks, Use sys.argv: http://python.org/doc/2.4.1/lib/module-sys.html HTH, Wolfram I know this module and this function. But, I search the same function in the C-API because a would like to know these variables directly in my bindings written in C++. As an example, I try to create the following fonction : PyMODINIT_FUNC initMyModule( void ) { int argc = Py_GetArgc() ; // I don't know if this function exist : I would like to know... char** argv = Py_GetArgv() ; // I don't know if this function exist : I would like to know... myfunction( argc, argv ) ; PyObject* module = Py_InitModule3( MyModule, 0, module of my FEM application ) ; } Thanks to this C function written with the C-API of Python, I will create a new Python module and import it in the Python interpreter : import MyModule -- http://mail.python.org/mailman/listinfo/python-list
Re: references/addrresses in imperative languages
In article [EMAIL PROTECTED], Xah Lee [EMAIL PROTECTED] wrote: In hindsight analysis, such language behavior forces the programer to fuse mathematical or algorithmic ideas with implementation details. A easy way to see this, is to ask yourself: how come in mathematics there's no such thing as addresses/pointers/references. There is. Each variable in predicate calculas is a reference. No matter how large the formulae, a change in a variable is, in mathematics, immediately propagated to all occurances of the variable (potentially changing the references of other variables). If the predicate calculas variables were not equivilent to references, then the use of the variable in a formula would have to be a non-propogating copy. and a change to the original value whence not be reflected in all parts of the formula and would not change what the other variables referenced. Consider for example the proof of Goedel's Incompleteness theorem, which involves constructing a formula with a free variable, and constructing the numeric encoding of that formula, and then substituting the numeric encoding in as the value of the free variable, thus ending up with a number that is talking about iteelf. The process of the proof is *definitely* one of reference to a value in the earlier stages, with the formula being evaluated at a later point -- very much like compiling a program and then feeding the compiled program as input to itelf. You cannot do it without a reference, because you need to have the entire number available as data at the time you start evaluating the mathematical formula. -- Ceci, ce n'est pas une idée. -- http://mail.python.org/mailman/listinfo/python-list
Re: login website that using PHP
pbpscript is a little python toolkit for simulating a webbrowser, specifically for doing testing. It handles all the cookies and stuff for you. You might want to have a look at it. Stephen. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can we pass some arguments to system(cmdline)?
Thanks all for the reply. I'll try out those things out. :) Cheers, Didier. Leif K-Brooks a écrit : Didier C wrote: E.g in Perl, we can do something like: $dir=/home/cypher; system(ls $dir); Is there a way to reproduce the same thing in Python? system(ls %s % dir) But you should really be using subprocess for security (so that if dir==/home/foo; rm -rf / nothing bad will happen): import subprocess subprocess.Popen(['ls', dir]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is there no instancemethod builtin?
[George Sakkis] The fact that strings don't have __iter__ is an implementation detail. I can't think of any reason other than historic and perhaps backwards compatibility for this; iterables should IMHO by definition be exactly the objects with __iter__). There would be no benefit other than satisfying that particular world view. It is a feature that all sequences are automatically iterable without having to write a custom __iter__ method. That makes life a bit easier for writers of sequence-like classes. [Michele Simionato] I think strings do not have __iter__ on purpose, exactly to distinguish them from other iterables, since sometimes it is nice to consider them atomic, but I am not sure of this. You should ask the developers. That is not correct. Since any sequence is automatically iterable (because of the presence of __getitem__), the inclusion of a separate __iter__ method is purely optional. The option to include a custom __iter__ method has been exercised only when it has offered some performance benefit. IOW, the inclusion of __iter__ for a sequence is an arbitrary implementation detail -- there is no other significance. Anyway, the right definition of iterable is (as I was told) an object X such that iter(X) does not throw an exception. Objects following the __getitem__ protocol - such as strings -are iterables even if they do not have an __iter__ method. An object is iterable if and only if it provides either __iter__ or __getitem__. Raymond -- http://mail.python.org/mailman/listinfo/python-list
Re: functions with unlimited variable arguments...
Dear Chinook Lee, Thank you very much. That seems a godsend. I'd like to also thank its author Richard Gruet. Xah [EMAIL PROTECTED] ∑ http://xahlee.org/ Chinook wrote: ... I don't get to the reference docs much. Mostly I use the quick reference guide and it's noted there in an easy to find manner. If you have not checked it out then see: http://rgruet.free.fr/#QuickRef Lee C -- http://mail.python.org/mailman/listinfo/python-list
Re: how to operate the excel by python?
On 6/17/05, Hughes, Chad O [EMAIL PROTECTED] wrote: I have posed a more complete answer to your question, however, it is quite a large and It is awaiting approval. For now, xlRight = -4152. You can find this out by opening up Excel and typing the ALT-F11 combination. From there use the ObjectBrowser. For example if you type in the word xlRight you will see that it is equal to -4152. I've had problems with these constants differing between versions before, so I don't recommend hard coding them. (This was in Word rather than Excel, AFAICR, but if Bill can do it to us once, he can do it to us twice.) Luckily, you can use the constants by name: PythonWin 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32. Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED]) - see 'Help/About PythonWin' for further copyright information. import win32com.client excel = win32com.client.gencache.EnsureDispatch(Excel.Application) win32com.client.constants.xlRight -4152 -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: catch argc-argv
mg wrote: Hello, I am writting bindings for a FEM application. In one of my function 'initModulename', called when the module is imported, I would like to get the argc and argv arguments used in the main function of Python. This is an interesting way of writing bindings. Most people would provide an interface in terms of either a library of functions or a class or two. I don't recall ever seeing a module or package that did what you say you want to do. Consider that your module should NOT be tied to command-line arguments. Abstract out what are the essential inputs to whatever a FEM application is. Then the caller of your module can parse those inputs off the command line using e.g. optparse and/or can collect them via a GUI and/or hard code them in a test module and/or read them from a test data file or database. So, my question is: does the Python API containe fonctions like 'get_argc()' and 'get_argv()' ? If you can't see them in the documentation, they aren't there. If they aren't there, that's probably for a good reason -- no demand, no use case. -- http://mail.python.org/mailman/listinfo/python-list
Re: references/addrresses in imperative languages
Xah Lee wrote: in coding Python yesterday, It seems to be giving you anxiety. Have you considered not coding on python? -- pete -- http://mail.python.org/mailman/listinfo/python-list
binary file
L.S., I have used the profile module to measure some thing as the next command: profile.run('command', 'file') But this make a binary file! How can I write the result of 'profile' in a ascii file? Others how can I read (or convert) the binary file to am ascii file? Regards, Nader -- http://mail.python.org/mailman/listinfo/python-list
Re: login website that using PHP
- Original Message - From: frost [EMAIL PROTECTED] Hi, I am trying to login a website that using PHP and javascript. This is what happend if you browse that website using IE, after you login, you can go anywhere without enter your name and password again, as long as you keep that IE open, but after you close that IE, then later on open that website in a new window, you need to login again. I guess some session is created as long as your original login window dose not close. How I can handle this in python? I want get some information from that website. But the login page is not what I want, how can I simulate regular IE browser? I mean after I login, I can get to other pages from it, but I find my programe can't go other place except the login page. Depending on your requirements, ishy_browser might help, I found it the very quick and easy to get running. It controls an IE window on your desktop and gives you access to each page's objects. You need winGuiAuto to get it to work, but that's trivial. You can either import the script as a module, or wirte your own _main_ based on the one in the script. I heard about it on this list. HTH :) -- Forwarded message -- From: [EMAIL PROTECTED] [EMAIL PROTECTED] Date: 26 May 2005 07:18:09 -0700 Subject: Re: Automatically populate and submit HTML Forms To: python-list@python.org These two blog entries might be of help to you. http://www.ishpeck.net/index.php?P=b1115239318ishpeck second half is at http://www.ishpeck.net/index.php?P=b1115225809ishpeck -- http://mail.python.org/mailman/listinfo/python-list
Re: login website that using PHP
The behaviour with the browser is what is known as a 'session cookie' -the site sets it when you login and the browser keeps it until you end the session by closing the browser. You handle the cookie using ClientCookie (Python 2.3) or cookielib (Python 2.4). You need to create a cookiejar instance and an opener that uses HTTPCookieProcessor (and your cookiejar). When you've done that - calls to your opener will fetch pages and handle the cookie *compeltely automatically*. There is an example of doing that at http://www.voidspace.org.uk/python/articles.shtml#http The authentication is via an html form. You can handle this using ClientForm - or you can look at the HTML source of the page and just have your opener (as above) send the right values to the URL. If you have problems - post the details here and people will help. It is *possible* that the javascript does 'magic' on the form submission (client side encryption is one possibility). That is very hard to automatically duplicate from Python because you would need to parse the python and mimic the page DOM to duplicate the effect. It might be easier to use PAMIE to automate the form submission in the browser. I've never tried this myself - but seen the announcements here. Best Regards, Fuzzy http://www.voidspace.org.uk/python unfortunately voidspace is temporarily down :-( -- http://mail.python.org/mailman/listinfo/python-list
Re: Can we pass some arguments to system(cmdline)?
Didier Casse [EMAIL PROTECTED] (DC) wrote: DC Thanks all for the reply. I'll try out those things out. :) But don't try the following system(ls $dir); with dir==/home/foo; rm -rf / -- Piet van Oostrum [EMAIL PROTECTED] URL: http://www.cs.uu.nl/~piet [PGP] Private email: [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Want to learn a language - is Python right?
Hi Group, I am not an experienced programmer at all. I've learned html and css well enough to hand-write simple websites. I'm now looking to move to the next step. Initially, I'd like to do 3 things: 1) Generate web pages This one's fairly obvious maybe. 2) Create a simplified translation package specific to my line of work: The principle: French vocabulary is found in spreadsheet column A, English equivalents in column B. The program selects the content of A1, bonjour, searches through the usually Word or Powerpoint document and replaces all examples by hi, then moves on to A2, etc., looping till the end, when I come back and start to work. 3) Help me learn Estonian. I wrote a couple of rules in Excel. The idea was to create a self-completion quiz where I must type the exact form of the word (Estonian is a declension language like Latin, but with 14 cases instead of 6) in the corresponding box. If I get it right, I get a Y, if I get it wrong, I get an N. If I can't remember, I type *, ** or *** to get the first to third letter If that doesn't help, I type ? and get the entire answer. The table below gives an approximate picture. The Ans. on the right should be invisible. WordCase1 Case2 Case3 CaseN Yes/No ClueAns.1 Ans.2 Ans.3 Ans.N River jõgi jõejõge jõgesidY jõgi jõe jõge jõgesid Cabbage kapsas kapsa ** kapsaid ka kapsas kapsa kapsast kapsaid Shirt ? särk särk särgi särki särke Bread leivN leibleiva leiba leibu I'm looking for ways of developing the method, making it easier to use, record right and wrong answers, and randomly re-present troublesome words. Is Python the sort of language that will let me do this sort of thing (whether *I* can actually do it is another question :) )? Best regards, Aziz -- http://mail.python.org/mailman/listinfo/python-list
Re: catch argc-argv
John Machin wrote: So, my question is: does the Python API containe fonctions like 'get_argc()' and 'get_argv()' ? If you can't see them in the documentation, they aren't there. If they aren't there, that's probably for a good reason -- no demand, no use case. Leaving aside whether or not there is a use-case for this, the reason they aren't there is that they aren't needed. As the OP was already told, to access argv, you simply import the 'sys' module and access sys.argv. There are apis both to import modules and to get an attribute of an existing Python object. So all you need is something like (untested): PyObject *sys = PyImport_ImportModule(sys); PyObject *argv = PyObject_GetAttrString(sys, argv); int argc = PyObject_Length(argv); if (argc != -1) { ... use argc, argv ... } Py_DECREF(argv); Py_DECREF(sys); -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to learn a language - is Python right?
Aziz McTang [EMAIL PROTECTED] writes: 1) Generate web pages This one's fairly obvious maybe. You might find this easier to do with PHP. Python is better in a deep way, but for web pages, that advantage only becomes real when you're doing complicated sites. Simple stuff is easier to do with PHP despite that language's flaws. 2) Create a simplified translation package specific to my line of work: This is a lot harder than it sounds and you're better off using a canned program for it. 3) Help me learn Estonian. I wrote a couple of rules in Excel. ... Is Python the sort of language that will let me do this sort of thing (whether *I* can actually do it is another question :) )? Yes, Python is a good choice for that type of program, though whether that's a good way to learn a natural language (like Estonian) is a different matter. -- http://mail.python.org/mailman/listinfo/python-list
subprocess.call(*args **kwargs) on Linux
Hi all, I am trying to use subprocess module on Linux/Python-2.4.1, but I can't dig throught. I need to call executable which needs two parameters to be ginven (the serial port and the file name). It looks like /root/dex/dex /dev/ttyS0 blabla.txt in the shell. This is easy. Subprocess function call looks: returncode = subprocess.call([/root/dex/dex,/dev/ttyS0, blabla.txt]) and it runs smoothly. The problem starts when I am trying to add 1/dev/null 2/dev/null parameters to suppres output sendings. In the Shell it looks like: /root/dex/dex /dev/ttyS0 blabla.txt 1/dev/null 2/dev/null I am not able to find the propper call syntax to do this. Any suggestions? Thanks a lot. Petr -- http://mail.python.org/mailman/listinfo/python-list
Re: OO approach to decision sequence?
Jordan Rastrick wrote: Without knowing more about your problem, I think the most obvious OO approach would be to write a seperate (simple) class for each of node_type_1, node_type_2, etc. While I agree that this is the cleanest and usually simplest approach, it does have its drawbacks. I'm currently working on a project where I'd very much like to avoid writing a whole set of classes just for the purpose of avoiding a decision chain. For a PDF library, I need basic data types that are used in a PDF document. Such are integers, floats, strings, lists, dictionaries and a few. At some point they have to be written to a file, and at first I was tempted to create types like pdfint, pdffloat, pdfstr etc. which implement the respective file encoding either in a write method or directly in __str__. However, the whole point of the library is to allow working with the document's data. Beside manipulating existing (as in read from a PDF file) mutable objects this includes creating new objects of type pdffoo. And I realized it is very bothersome to have to say x = pdfint(5) instead of x = 5 everytime I deal with integers that would end up in the document. Similar for, e.g., adding to PDF integers: x = pdfint(y+z) instead of just x = y+z. The latter can be cured by touching all methods returning any pdffoo instances. No sane person would do this, however, and it would not eliminate any pdffoo(x) type conversions in the app code anyway. So I decided that in this case it is best to go without special types and use those provided by Python, and live with an ugly decision chain or two at defined places in the library. -- Thomas -- http://mail.python.org/mailman/listinfo/python-list
dll files
How can i create dll files in Python? Is it possible? If yes, how to enclose image and font files in a dll ? Plis reply. SABIN. B'lore. -- http://mail.python.org/mailman/listinfo/python-list
Re: utf8 and ftplib
OK, I'm still not getting this unicode business. Given this document: == ?xml version=1.0 encoding=utf-8 ? document aa#224;#225;#226;#227;/a ee#232;#233;#234;#235;/e ii#236;#237;#238;#239;/i oo#242;#243;#244;#245;/o uo#249;#250;#251;#252;/u /document == (If testing, make sure you save this as utf-8 encoded.) and this Python script: == import sys from xml.dom.minidom import * from xml.dom import * import codecs import string CHARACTERS = range(128,255) def unicode2charrefs(s): Returns a unicode string with all the non-ascii characters from the given unicode string converted to character references. result = u for c in s: code = ord(c) if code in CHARACTERS: result += u# + string.zfill(str(code), 3).decode('utf-8') + u; else: result += c.encode('utf-8') return result def main(): print Parsing file... file = codecs.open(sys.argv[1], r, utf-8) document = parse(file) file.close() print done. print document.toxml(encoding=utf-8) out_str = unicode2charrefs(document.toxml(encoding=utf-8)) print Writing to ' + sys.argv[1] + ~' ... file = codecs.open(sys.argv[1] + ~, w, utf-8) file.write(out_str) file.close() print done. if __name__ == __main__: main() == Does anyone else get this output from the print document.toxml(encoding=utf-8) line: document aaà áâã/a eeèéêë/e iiìÃîï/i ooòóôõ/o uoùúûü/u /document and, similarly, this output document: == ?xml version=1.0 encoding=utf-8? document aa#195;#160;#195;#161;#195;#162;#195;#163;/a ee#195;#168;#195;#169;#195;#170;#195;#171;/e ii#195;#172;#195;#173;#195;#174;#195;#175;/i oo#195;#178;#195;#179;#195;#180;#195;#181;/o uo#195;#185;#195;#186;#195;#187;#195;#188;/u /document == i.e., does anyone else get two byte sequences beginning with capital-A-with-tilde instead of the expected characters? I'm using the Kate editor from KDE and Konsole (using bash) shell on Linux (2.6 kernel). Does that make any difference? I've just tried it on the unicode-aware xterm and the print document.toxml(encoding=utf-8) line produces the expected output but the output file is still wrong. Any ideas whats wrong? Cheers, Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedding Python - How to create a class instance
Hello Denis, I'm trying to embed Python in a C application. What I didn't find is how to create an instance once I have a class object. Class is a callable object. Just call it to create instance. ... obj = PyObject_CallObject(A, NULL); Thanks. After grepping the Python sources I've found about obj = PyInstance_New(A, NULL, NULL) which worked for me. Bye. -- Miki Tebeka [EMAIL PROTECTED] http://tebeka.bizhat.com The only difference between children and adults is the price of the toys pgptzm904CwQ4.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Extensions on Linux: import without underscore?
Terry Hancock wrote: Okay, you may want a more elegant way to do this and other people have already responded to that point, but you do at least know you can just give it a new name: import _bright bright = _bright or more idiomatically and without adding _bright to the namespace: import _bright as bright Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: utf8 and ftplib
On Mon, 20 Jun 2005 12:37:42 +0100, Richard Lewis [EMAIL PROTECTED] said: [SNIP] Just add to this: my input document was written using character references rather than literal characters (as was the sample output document). However, I've just noticed that my mail client (or maybe something else?) has converted the character references to literal characters. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.call(*args **kwargs) on Linux
McBooCzech wrote: This is easy. Subprocess function call looks: returncode = subprocess.call([/root/dex/dex,/dev/ttyS0, blabla.txt]) and it runs smoothly. The problem starts when I am trying to add 1/dev/null 2/dev/null parameters to suppres output sendings. from subprocess import call, STDOUT call([command, arg, arg], stdout=open(/dev/null, w), stderr=STDOUT) -- http://mail.python.org/mailman/listinfo/python-list
Re: binary file
Nader Emami wrote: L.S., I have used the profile module to measure some thing as the next command: profile.run('command', 'file') But this make a binary file! How can I write the result of 'profile' in a ascii file? Others how can I read (or convert) the binary file to am ascii file? Use an instance of pstats.Stats to interpret the results: from pstats import Stats s = Stats('file') s.print_stats() etc. http://docs.python.org/lib/profile-stats.html Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Extensions on Linux: import without underscore?
Swig actually was generating a bright.py file, but scons was leaving it in the source directory instead of putting it next to my SharedLibrary(). Once I moved the bright.py next to the _bright.so, it all worked with just import bright. Thanks everyone. My next trick is to try the same thing with distutils, and see how it compares with SCons. -Jim On 6/20/05, Kent Johnson [EMAIL PROTECTED] wrote: Terry Hancock wrote: Okay, you may want a more elegant way to do this and other people have already responded to that point, but you do at least know you can just give it a new name: import _bright bright = _bright or more idiomatically and without adding _bright to the namespace: import _bright as bright Kent -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: references/addrresses in imperative languages
# easy way to see this, is to ask yourself: how come in mathematics # there's no such thing as addresses/pointers/references. The whole point of Goedelisation was to add to name/value references into number theory. Thus Goedel was able to add back pointers contrary to the set hierarchy of the theory of types and reintroduce Russel's paradox. -- SM Ryan http://www.rawbw.com/~wyrmwif/ The little stoner's got a point. -- http://mail.python.org/mailman/listinfo/python-list
Re: utf8 and ftplib
Richard Lewis wrote: OK, I'm still not getting this unicode business. obviously. document aa#224;#225;#226;#227;/a ee#232;#233;#234;#235;/e ii#236;#237;#238;#239;/i oo#242;#243;#244;#245;/o uo#249;#250;#251;#252;/u /document (If testing, make sure you save this as utf-8 encoded.) why? that XML snippet doesn't include any UTF-8-encoded characters. ::: file = codecs.open(sys.argv[1], r, utf-8) document = parse(file) file.close() why do you insist on decoding the stream you pass to the XML parser, when you've already been told that you shouldn't do that? change this to: document = parse(sys.argv[1]) print document.toxml(encoding=utf-8) this converts the document to UTF-8, and prints it to stdout. if you get gibberish, your stdout wants some other encoding. if you get capital- A-with-tilde gibberish, your stdout expects ISO-8859-1. try changing this to: print document.toxml(encoding=sys.stdout.encoding) out_str = unicode2charrefs(document.toxml(encoding=utf-8)) this converts the document to UTF-8, and then translates the *encoded* data to character references as if the document had been encoded as ISO- 8859-1. this makes no sense at all, and results in an XML document full of capital-A-with-tilde gibberish. i.e., does anyone else get two byte sequences beginning with capital-A-with-tilde instead of the expected characters? since you've requested UTF-8 output, capital A with tilde is the expected result if you're directing output to an ISO-8859-1 stream. the output file is still wrong. well, you're messing it up all by yourself. getting rid of all the codecs and unicode2charrefs nonsense will fix this: document = parse(sys.argv[1]) # parser decodes ... manipulate document ... file = open(..., w) file.write(document.toxml(encoding=utf-8)) # writer encodes file.close() /F -- http://mail.python.org/mailman/listinfo/python-list
Re: binary file
Kent Johnson wrote: Nader Emami wrote: L.S., I have used the profile module to measure some thing as the next command: profile.run('command', 'file') But this make a binary file! How can I write the result of 'profile' in a ascii file? Others how can I read (or convert) the binary file to am ascii file? Use an instance of pstats.Stats to interpret the results: from pstats import Stats s = Stats('file') s.print_stats() etc. http://docs.python.org/lib/profile-stats.html Kent I got the same result as the execution of command. But I would like to write to the an external 'ascii' file! Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Using print with format to stdout generates unwanted space
Hi Paul Based on your description of what you want to do, print is probably not the correct method of controlling output format. You should use write() method of the file handle to get unadulterated output. print is working as documented . From the Python 2.3 documentation, Section 6.6 The Print statement. print evaluates each expression in turn and writes the resulting object to standard output (see below). If an object is not a string, it is first converted to a string using the rules for string conversions. The (resulting or original) string is then written. A space is written before each object is (converted and) written, unless the output system believes it is positioned at the beginning of a line. This is the case (1) when no characters have yet been written to standard output, (2) when the last character written to standard output is \n, or (3) when the last write operation on standard output was not a print statement. As you can see a space char is written and is correct as per the docs. Rgds Tim Paul Watson wrote: #!/usr/bin/env python # Using a print statement to stdout results in an # unwanted space character being generated at the # end of each print output. Same results on # DOS/Windows and AIX. # # I need precise control over the bytes that are # produced. Why is print doing this? # import sys # If this is a DOS/Windows platform, then put stdout # into binary mode so that only the UNIX compatible newline # will be generated. # try: import msvcrt, os msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) except: print 'This is not an msvcrt platform.' pass # Using print with newline suppressed generates a space at the # end of each print statement. # for i in range(3): print '%d,60,' % (i), for j in range(10): print '%d,' % (j), print '' # Using a list and doing a join does not result in the space # character being generated. # for i in range(3): alist = [] alist.append('%d,60,' % (i)) for j in range(10): alist.append('%d,' % (j)) print ''.join(alist) sys.exit(0) -- http://mail.python.org/mailman/listinfo/python-list
JEP and JPype in a single process
Hello, I have written a very simple java class file, which invokes a Python script using JEP. Code snippet:- --- Jep jep = new Jep(false); jep.runScript(C:\\temp\\testscript.py); jep.close(); Now inside this Python script I want to make Java calls using JPype. If I use startjvm() inside this Python script, a Runtime Error (exception) is thrown. Also tried attachThreadToJVM(), but doesn't work, again Runtime Error. Any clues as to how I could achieve my goal?? The interaction shown below should happen in a single process. JAVA == jep == PYTHON == jpype == JAVA Regards, skn -- http://mail.python.org/mailman/listinfo/python-list
Re: Generating .pyo from .py
Thanks a lot !! It works fine !! regards, skn Leif K-Brooks [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] skn wrote: Does the python compiler provide an option to generate a .pyo(optimized byte code file) from a .py (source file)? For generating .pyc I know that I only have to pass the source file name as an argument to py_compile.py. py_compile.py checks __debug__ to decide whether to use optimize mode, and the -O option to Python turns __debug__ off, so: python -O py_compile.py foo.py -- http://mail.python.org/mailman/listinfo/python-list
Re: global name not defined :$
Anna M. [EMAIL PROTECTED] wrote: I am trying to write a red-black tree implementation in python. I am very new to python and appologize if my question is terribly stubid. But I ran into some trouble. I have a class and in it there are functions but when I try to run the code I have I just get an error on one of the functions global name 'balancedFourNode' is not defined Now of course I realize that I am doing something wrong when defining the function but I just can't seem to find it. Any insight would be greatly appreciated. classes have methods, not functions. if x is an instance of a class and method is a method defined by that class, you should use x.method() to call the method. if you're trying to call the method from another method in the same class, use self.method(). if you type method or method(x), Python won't know where to look. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: functions with unlimeted variable arguments...
Xah Lee wrote: oops... it is in the tutorial... sorry. If you're sorry, have you now *finally* gone and worked through the rest of tutorial, making a serious attempt to learn it? This is not a rhetorical question, but where would one start to look for it in the python ref? a language is used by programers. Subroutine definition with variable/default parameters is a basic issue a programer wants to know, and different languages differs very much in how they handle this. This is what i mean that the language doc should be programing oriented, as opposed to computer-sciency or implementation oriented... You seem to be under the impression that most programmers learn a new language by looking up key phrases such as variable argument list in the index of their new language's manual as they encounter the need for a feature. In actual fact, most programmers learn by finding a tutorial or convenient beginner's lesson (hint hint), and then by browsing through other material such as a FAQ (hint hint), and then perhaps by skimming quickly through the reference material to learn what is there. This way they avoid making themselves look like complete and utter fools by appearing to learn only by looking up things in the index. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: catch argc-argv
Duncan Booth wrote: John Machin wrote: So, my question is: does the Python API containe fonctions like 'get_argc()' and 'get_argv()' ? If you can't see them in the documentation, they aren't there. If they aren't there, that's probably for a good reason -- no demand, no use case. Leaving aside whether or not there is a use-case for this, the reason they aren't there is that they aren't needed. no use-case == no need in my book As the OP was already told, to access argv, you simply import the 'sys' module and access sys.argv. Simple in Python, not in C. There are apis both to import modules and to get an attribute of an existing Python object. I know that; my point was why should you do something tedious like that when you shouldn't be interested in accessing sys.argv from a C extension anyway. So all you need is something like (untested): PyObject *sys = PyImport_ImportModule(sys); PyObject *argv = PyObject_GetAttrString(sys, argv); int argc = PyObject_Length(argv); if (argc != -1) { ... use argc, argv ... } Py_DECREF(argv); Py_DECREF(sys); -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something similar to ?: operator (C/C++) in Python?
D H wrote: Peter Hansen wrote: Bo Peng wrote: I need to pass a bunch of parameters conditionally. In C/C++, I can do func(cond1?a:b,cond2?c:d,.) Is there an easier way to do this in Python? Please read the FAQ to learn the answer and much other useful ... The answer is no. Use if statements. Actually that's just one possible answer. Whether it's _the_ answer is obviously again a matter of opinion, and as usual we differ. Doug, please stop making an idiot of yourself by offering simplistic corrections to every one of my posts. I realize you don't like me, and that's too bad, but that isn't a good reason to be rude when I try to be helpful to someone or to offer my opinion on some issue. It's downright immature. A better alternative would simply be to provide your own response to the OP, instead of appearing to be trying to correct me, and leave it to others to figure out for themselves which piece of advice they prefer. Given that I'm hardly a troll around here, and do find ways of providing useful advice from time to time, I believe I deserve the courtesy of a bit of respect. (I'd have emailed Doug about this many a time, but it doesn't appear he uses a real email address here so I'm forced to respond in a public forum. Sorry for the waste of bandwidth, and regardless of the response I won't bring it up again.) -Peter -- http://mail.python.org/mailman/listinfo/python-list
import via pathname
Okay, so in my li'l python script I'm importing a few 3rd party modules that I have installed on my comp. I need to distribute this script to several other people, but I won't have access to install the modules on their comp's. I'm thinking I'll include these modules with my script and deliver them as a bundle. When I write my script, is there a way to declare the import statements and specify a relative path to where the modules are located? I know this is wrong syntax, but I think it demonstrates what I'm trying to do: import myModule path = /modules/myModule import myModule2 path = /modules/myModule2 Something like that. Is it possible? -Thx -- http://mail.python.org/mailman/listinfo/python-list
Re: import via pathname
Am Mon, 20 Jun 2005 06:31:38 -0700 schrieb passion_to_be_free: Okay, so in my li'l python script I'm importing a few 3rd party modules that I have installed on my comp. I need to distribute this script to several other people, but I won't have access to install the modules on their comp's. I'm thinking I'll include these modules with my script and deliver them as a bundle. When I write my script, is there a way to declare the import statements and specify a relative path to where the modules are located? Hi, You can change sys.path at runtime. Example: libdir=os.path.join(os.environ[HOME], mylibs) assert(os.path.exists(libdir)) sys.path.insert(0, libdir) import mylibrary # $HOME/mylib/mylibrary.py HTH, Thomas -- Thomas Güttler, http://www.thomas-guettler.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: utf8 and ftplib
On Mon, 20 Jun 2005 14:27:17 +0200, Fredrik Lundh [EMAIL PROTECTED] said: well, you're messing it up all by yourself. getting rid of all the codecs and unicode2charrefs nonsense will fix this: Thanks for being so patient and understanding. OK, I've taken it all out. The only thinking about encoding I had to do in the actual code I'm working on was to use: file.write(document.toxml(encoding=utf-8)) instead of just file.write(document.toxml()) because otherwise I got errors on copyright symbol characters. (And similarly, I had to use file.write(unicode_string.encode(utf-8)) in another part of the actual code in order to prevent the same problem.) My code now works without generating any errors but Konqueror's KHTML and Embedded Advanced Text Viewer and IE5 on the Mac still show capital-A-with-a-tilde in all the files that have been generated/altered. Whereas my text editor and Mozilla show them correctly. The unicode2charrefs() nonsense was an attempt to make it output with character references rather than literal characters for all characters with codes greater than 128. Is there a way of doing this? (I know people will argue that character references are only preferred by humans and text editors, but if I could generate my output HTML documents with character references rather than literal characters then I wouldn't have the problem of incorrectly displayed characters on Konqueror and IE 5 for Mac. Which would be nice.) Cheers, Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: dll files
You are most likely better off creating COM objects than trying to create old .dll files. Good treatment of COM object creation is in the book titled Python Programming on Win32. Most other languages have no problem interfacing with COM objects. -Larry Sabin wrote: How can i create dll files in Python? Is it possible? If yes, how to enclose image and font files in a dll ? Plis reply. SABIN. B'lore. -- http://mail.python.org/mailman/listinfo/python-list
Re: import via pathname
If it is Windows use py2exe and Inno Installer to create an installation program that does this for you. If it is another OS, you need to put your modules into a subdirectory of site-packages and then Python will be able to see your modules. If you have a lot of modules you might consider turning them into a package. -Larry [EMAIL PROTECTED] wrote: Okay, so in my li'l python script I'm importing a few 3rd party modules that I have installed on my comp. I need to distribute this script to several other people, but I won't have access to install the modules on their comp's. I'm thinking I'll include these modules with my script and deliver them as a bundle. When I write my script, is there a way to declare the import statements and specify a relative path to where the modules are located? I know this is wrong syntax, but I think it demonstrates what I'm trying to do: import myModule path = /modules/myModule import myModule2 path = /modules/myModule2 Something like that. Is it possible? -Thx -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something similar to ?: operator (C/C++) in Python?
On Mon, 20 Jun 2005 06:36:42 GMT, Ron Adam [EMAIL PROTECTED] wrote: Ron Adam wrote: You might be able to use a dictionary of tuples. call_obj = {(type_obj1,0):obj1a, (type_obj1,0):obj1b, (type_boj2,1):obj2a, (type_obj2,1):obj2b, etc... } call_obj[(type_of_obj,order)]() Regards, Ron This won't work like I was thinking it would. But to get back to your is there a ? operator question... Try this. def foo(): return foo def boo(): return boo print (foo, boo)[10]()# prints boo print (foo, boo)[10]()# prints foo Regards, Ron Another thought: Often complicated conditional logic is a flag that we need to refactor. An accounting package I built has an official list of approved vendors, but allows users to provisionally add a new vendor, which is corrected later. The bulk of this system only understands, This document has-a vendor with a vendor factory that returns the appropriate type of vendor. All of the logic specific to the specific subclass is internal to the subclasses themselves. -- http://mail.python.org/mailman/listinfo/python-list
Re: login website that using PHP
Here are the links to ishy_browser. http://www.ishpeck.net/index.php?P=b1115239318ishpeck http://www.ishpeck.net/index.php?P=b1115225809ishpeck -- http://mail.python.org/mailman/listinfo/python-list
[no subject]
#! rnews 4339 Newsgroups: comp.lang.python Path: news.xs4all.nl!newsspool.news.xs4all.nl!transit.news.xs4all.nl!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!nntp.abs.net!attws2!ip.att.net!NetNews1!xyzzy!nntp From: Harry George [EMAIL PROTECTED] Subject: Re: Multiple instances of a python program X-Nntp-Posting-Host: cola2.ca.boeing.com Content-Type: text/plain; charset=us-ascii Message-ID: [EMAIL PROTECTED] User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.4 Lines: 83 Sender: [EMAIL PROTECTED] Organization: The Boeing Company References: [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] Mime-Version: 1.0 Date: Mon, 20 Jun 2005 14:14:24 GMT Xref: news.xs4all.nl comp.lang.python:382535 Rahul [EMAIL PROTECTED] writes: Steven D'Aprano wrote: On Thu, 16 Jun 2005 11:47:10 -0700, Rahul wrote: Hi. I am part of a group in my univ where we organize a programming contest. In this contest we have a UDP based server. The server simulates a game and each contestant is to develop a team of virtual players. Each team is composed of 75 similar bots...i.e. governed by the same logic. Thus the contestant submits a single copy of the client and we instantiate the same program 75 times at the same time. The problem is that while executables from C source files are small and we can make 75 processes but we dont know what to do with python. If you have a python script and you want that 75 copies of the script be run simultaneously how will you do it? Is there anyway to do so without running 75 copies of the python interpreter simultaneously? Have you actually tested the performance of 75 instances of Python running? Do you know that it will be too slow for your server, or are you trying to optimize before testing? I wrote a short Python script, then launched 115 instances of Python executing the script. There was no detectable slowdown of my system, which is far from a high-end PC. The details of the script aren't important. It may even be that what I tested is not even close to the load your server needs to deal with. But you may be surprised at just how easily even a low-end PC copes 75 instances of Python. Or perhaps not -- but the only way to tell is to try. Well...i havent tried (yes i hear Premature optimization is evil evil evil i say) but the point was that if we can find a solution consuming less memory than we can even increase the number from 75 to lets say 200. as for hardware we have machines with 1.7 Ghz P4 and 128 mb ram. and i cant run them right now...since i am currently not in my univ...but asked now since we are planning right now and wanted to see which languages we can support. Probably c,c++,python and lisp using clisp...and java if we can find a way to avoid running 75 jvms...this year we supported c,c++,java and actually ran 75 jvms using 3 machines and it was horrible so we are looking for better ways for the 2006 contest. And we may port our server from java to python too but it seems not many people had python installed but most had java installed. rahul As others have said, start by testing. Given 1.7 MHz and 128MB, I'm guessing your performance problems are coming from swapping. Simply getting more RAM in the box would help. A quick check on process load just for the instances themselves can be done by gradually increasing max_processes (see below) until you swap. On a box with 256MB total, 150MB free, I was getting over 150 children before swap was noticeable. By watching top I found each child was using about 3MB, of which about 2MB is shared (basically, the python library). In other words, each instance was costing 1MB. Of course, your actual apps will require more RAM than this little test program. ---main program--- max_processes=10 progname=child.py for i in xrange(max_processes): os.spawnv(os.P_NOWAIT,progname,[progname,str(i)]) ---child program--- def msg(txt): sys.stdout.write(txt) sys.stdout.flush() #get childnum from comline parameters for i in xrange(10): msg('%i ' % childnum) time.sleep(1) -- [EMAIL PROTECTED] 6-6M21 BCA CompArch Design Engineering Phone: (425) 294-4718 -- http://mail.python.org/mailman/listinfo/python-list
Re: import via pathname
[EMAIL PROTECTED] wrote: I know this is wrong syntax, but I think it demonstrates what I'm trying to do: import myModule path = /modules/myModule import myModule2 path = /modules/myModule2 Something like that. Is it possible? I would put your additional modules into a 'modules' directory with an __init__.py. For example: py os.listdir('.') ['modules'] py os.listdir('modules') ['my_module1.py', 'my_module2.py', '__init__.py'] py file('modules/__init__.py').read() '' py file('modules/my_module1.py').read() 'name = module1\n' py file('modules/my_module2.py').read() 'name = module2\n' Then, if you place your python script in the same directory as the 'modules' directory, you can simply import the additional modules from the 'modules' package: py import modules.my_module1 as module1 py module1.name 'module1' py import modules.my_module2 as module2 py module2.name 'module2' Note that the 'modules' package needs to be at the same directory level as your Python module. If you want your 'modules' directory in a different location, you may want to go the way of Thomas Güttler's suggestion and modify sys.path. But I probably wouldn't if you don't have to. STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to learn a language - is Python right?
Hi Paul, Thanks for your input. As usual, hearing some answers helps formulate the question... What I'm looking for is more to learn one good, comprehensive programming language well than several approximately on an ad hoc basis. What I also failed to mention is the desire to develop my presently limited computer skills a lot further. So although your answer to 1 suggests I'd be using a steam-roller to kill a fly, if I do need to go further (or ask other people to help and still understand what's going on: one site I may want to develop later involves a number of languages including Japanese as well as audio) I won't have to re-learn another program. Is this right? As to 2, I have yet to find a canned program that does what I want, and so far every programmer I've asked to write it has said hey that's easy then escaped, never to be heard of again. And 3: good! Actually, having learned half a dozen languages, I can vouch for it being an excellent way to acquire and consolidate vocabulary. Talking to (or, rather, understanding) the natives is another kettle of fish! Thanks again! Any new slants from yourself or others are welcome. Aziz -- http://mail.python.org/mailman/listinfo/python-list
Couple functions I need, assuming they exist?
List: First, I'm reading that aString.split() is depreciated. What's the current best practice for this? Or am I mistaking that: myWords = split(aString, aChar) is depreciated but myWords = aString.split(aChgar) is not? Second question, I've written a script that generates a LaTeX source containing randomly generated arithmetic problems of various types. The target of the problems (my daughter) would prefer that the thousands be delimited. Is there a string function that does this? Thanks Charles -- http://mail.python.org/mailman/listinfo/python-list
Re: login website that using PHP
I'll add a plug for PAMIE (another set of Python classes that drive IE) http://pamie.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Python choice of database
Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Regards, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Gadfly PySQLite ( requires SQLite library ) J Philippe C. Martin wrote: Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Regards, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Just thought of a couple more: SnakeSQL KirbyBase J John Abel wrote: Gadfly PySQLite ( requires SQLite library ) J Philippe C. Martin wrote: Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Regards, Philippe . -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Philippe C. Martin wrote: I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Why not just use native Python data structures and pickle them? -- Erik Max Francis [EMAIL PROTECTED] http://www.alcyone.com/max/ San Jose, CA, USA 37 20 N 121 53 W AIM erikmaxfrancis I used to walk around / Like nothing could happen to me -- TLC -- http://mail.python.org/mailman/listinfo/python-list
Embedded Systems Python?
Hi all, I've looked through the threads about embedded Python that are a year and a half old, and I thought that I'd ask this question now to see if anything has changed. Has anyone, or is anyone working with Python in an embedded Linux environment? Mine is NO where near as constrained as a cell phone since I've got plenty of memory to work with, I'm just running a Linux 2.4 kernel on an ARM9 platform. Are there success stories for Python on embedded Linux systems today? The embedded Java JVM's seem to all be propriatary and have quite high license fees (don't mention Kaffe, it seems pretty fragile to me.) I'm a bit of a newb when it comes to Python, is there anyone with experience compiling it on Linux platforms that can offer me pointers to try this out myself? thanks, DLC -- * Dennis Clark [EMAIL PROTECTED]www.techtoystoday.com * * Programming and Customizing the OOPic Microcontroller Mcgraw-Hill 2003 * -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
On Mon, 20 Jun 2005 15:18:58 GMT, Philippe C. Martin [EMAIL PROTECTED] said: Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K SQLite might be worth a look. There are Python bindings at: http://initd.org/tracker/pysqlite Cheers, Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: Couple functions I need, assuming they exist?
Charles Krug wrote: First, I'm reading that aString.split() is depreciated. What's the current best practice for this? Or am I mistaking that: myWords = split(aString, aChar) is depreciated but If you mean import string; string.split(aString, aChar) then yes, it's deprecated (not depreciated, by the way). myWords = aString.split(aChgar) is not? Correct, this is perfectly acceptable. Second question, I've written a script that generates a LaTeX source containing randomly generated arithmetic problems of various types. The target of the problems (my daughter) would prefer that the thousands be delimited. Is there a string function that does this? You refer to something like putting a comma between groups of three digits, as in 1,000? This is locale-specific, and there's a locale module that should have what you need. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: import via pathname
AhhI see. I played around with the sys.path function...and it looks like python automatically looks in the same directory as my script first. Then is searches to all the other pre-defined paths. So it works for me to just keep my main script in the same directory as the two modules I'm using. Thx! -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Philippe C. Martin wrote: I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. You don't say whether you want *pure* Python solutions, so I'll suggest pysqlite which wraps the SQLite embedded database in a pretty much totally transparent fashion and is highly effective, fast, compact, reliable (so far, in my experience), and clean. You also don't say whether you want a SQL database, so if you are free to try anything, you might look at ZODB or Durus (think of it as a lighter-weight ZODB). I believe Durus is pure Python, but it might have some C code for performance (like ZODB). It's not SQL, and should perhaps be thought of (as it describes itself) as an object persistence solution, rather than a database. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: JEP and JPype in a single process
On 6/20/05, skn [EMAIL PROTECTED] wrote: Hello, I have written a very simple java class file, which invokes a Python script using JEP. . . . Now inside this Python script I want to make Java calls using JPype. I am not familiar with either Jepp or JPype, but I spotted this snippet on Jepp page (http://jepp.sourceforge.net/): import jep FileInputStream = jep.findClass('java.io.FileInputStream') try: fin = FileInputStream('adsf') except jep.FileNotFoundException: print 'Invalid file' Are you sure you need to call JPype? - kv -- http://mail.python.org/mailman/listinfo/python-list
Re: Using print with format to stdout generates unwanted space
Thanks for all replies. Ok. I agree. While printf() does tightly control formatting in C, it does not in Python. Using write() can be used to output with no changes to the data. Tim Hoffman [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi Paul Based on your description of what you want to do, print is probably not the correct method of controlling output format. You should use write() method of the file handle to get unadulterated output. print is working as documented . From the Python 2.3 documentation, Section 6.6 The Print statement. print evaluates each expression in turn and writes the resulting object to standard output (see below). If an object is not a string, it is first converted to a string using the rules for string conversions. The (resulting or original) string is then written. A space is written before each object is (converted and) written, unless the output system believes it is positioned at the beginning of a line. This is the case (1) when no characters have yet been written to standard output, (2) when the last character written to standard output is \n, or (3) when the last write operation on standard output was not a print statement. As you can see a space char is written and is correct as per the docs. Rgds Tim Paul Watson wrote: #!/usr/bin/env python # Using a print statement to stdout results in an # unwanted space character being generated at the # end of each print output. Same results on # DOS/Windows and AIX. # # I need precise control over the bytes that are # produced. Why is print doing this? # import sys # If this is a DOS/Windows platform, then put stdout # into binary mode so that only the UNIX compatible newline # will be generated. # try: import msvcrt, os msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) except: print 'This is not an msvcrt platform.' pass # Using print with newline suppressed generates a space at the # end of each print statement. # for i in range(3): print '%d,60,' % (i), for j in range(10): print '%d,' % (j), print '' # Using a list and doing a join does not result in the space # character being generated. # for i in range(3): alist = [] alist.append('%d,60,' % (i)) for j in range(10): alist.append('%d,' % (j)) print ''.join(alist) sys.exit(0) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
John Abel wrote: Gadfly PySQLite ( requires SQLite library ) I want to clarify this parenthetical comment, for the record. When I first downloaded PySQLite I had already gone and installed SQLite, thinking it was a prerequisite in that sense. In fact, the PySQLite install includes a .pyd which contains a statically linked version of the complete SQLite library. No additional installation is required, making it an even simpler solution than I thought at first. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Couple functions I need, assuming they exist?
Charles Krug wrote: myWords = split(aString, aChar) is depreciated but myWords = aString.split(aChgar) is not? Yes, that's basically correct. What's deprecated are the functions in the string module. So string.split(a_str, b_str) is deprecated in favor of a_str.split(b_str) The target of the problems (my daughter) would prefer that the thousands be delimited. Is there a string function that does this? I assume you mean translating something like '100' to '1,000,000'? I don't know of an existing function that does this, but here's a relatively simple implementation: py import itertools as it py def add_commas(s): ... rev_chars = it.chain(s[::-1], it.repeat('', 2)) ... return ','.join(''.join(three_digits) ... for three_digits ... in it.izip(*[rev_chars]*3))[::-1] ... py add_commas('10') '10' py add_commas('100') '100' py add_commas('1000') '1,000' py add_commas('10') '1,000,000,000' In case you haven't seen it before, it.izip(*[itr]*N)) iterates over the 'itr' iterator in chunks of size N, discarding the last chunk if it is less than size N. To avoid losing any digits, I initially pad the sequence with two empty strings, guaranteeing that only empty strings are discarded. So basically, the function iterates over the string in reverse order, 3 characters at a time, and joins these chunks together with commas. HTH, STeVe -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Well that would be shelve I guess ... with the restrictions I mentioned. Regards, Philippe Erik Max Francis wrote: Philippe C. Martin wrote: I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Why not just use native Python data structures and pickle them? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Philippe C. Martin wrote: Well that would be shelve I guess ... with the restrictions I mentioned. I was talking about pickle, not shelve. -- Erik Max Francis [EMAIL PROTECTED] http://www.alcyone.com/max/ San Jose, CA, USA 37 20 N 121 53 W AIM erikmaxfrancis I used to walk around / Like nothing could happen to me -- TLC -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Thank you all for your answers. A pure Python would have beenmy first choice. yet I now feel I should spend some time looking at PySQLite (I like the fact it's pre-compiled for Windows). Thanks. Philippe Philippe C. Martin wrote: Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Regards, Philippe -- http://mail.python.org/mailman/listinfo/python-list
Re: Couple functions I need, assuming they exist?
Peter Hansen wrote: The target of the problems (my daughter) would prefer that the thousands be delimited. Is there a string function that does this? You refer to something like putting a comma between groups of three digits, as in 1,000? This is locale-specific, and there's a locale module that should have what you need. import locale locale.setlocale(locale.LC_ALL, '') 'English_United Kingdom.1252' print locale.format(%d, 100, True) 1,000,000 print locale.format(%.2f, 100, True) 1,000,000.00 locale.setlocale(locale.LC_ALL, 'fr') 'French_France.1252' print locale.format(%d, 100, True) 1 000 000 print locale.format(%.2f, 100, True) 1 000 000,00 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
You mean pickling a dictionnary of 5000/16K objects ? Erik Max Francis wrote: Philippe C. Martin wrote: Well that would be shelve I guess ... with the restrictions I mentioned. I was talking about pickle, not shelve. -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to learn a language - is Python right?
Aziz McTang wrote: Hi Paul, Thanks for your input. As usual, hearing some answers helps formulate the question... What I'm looking for is more to learn one good, comprehensive programming language well than several approximately on an ad hoc basis. What I also failed to mention is the desire to develop my presently limited computer skills a lot further. So although your answer to 1 suggests I'd be using a steam-roller to kill a fly, if I do need to go further (or ask other people to help and still understand what's going on: one site I may want to develop later involves a number of languages including Japanese as well as audio) I won't have to re-learn another program. Is this right? As to 2, I have yet to find a canned program that does what I want, and so far every programmer I've asked to write it has said hey that's easy then escaped, never to be heard of again. And 3: good! Actually, having learned half a dozen languages, I can vouch for it being an excellent way to acquire and consolidate vocabulary. Talking to (or, rather, understanding) the natives is another kettle of fish! Thanks again! Any new slants from yourself or others are welcome. Aziz You can use CherryPy for creating a Python-esque web application. Never buy into the fluff that says Python is not as good as PHP for web apps! PHP is still too Perl-Like (meaning old and useless)! Python is the choice of a new generation baby!!! :) JK... For your vocab program, Python is actually perfect. This could even go for apps that require some Unicode and other Internationalization snafus (like right-to-left characters and Cyrillic typesets). If you're looking for one programming language then you should consider the idea that no one language can do it all (although Python comes close in my biased opinion). Python is not for memory management, writing device drivers and the like. As far as needing something for web apps, CherryPy is great -- just learn Python first. PHP is good but it has fallen out of favor with me though there are a ton of people out there who think it is the greatest thing since sliced bread. Take a look at the Python tutorial: http://docs.python.org/tut/tut.html. Good luck, Harlin Seritt -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Philippe C. Martin wrote: You mean pickling a dictionnary of 5000/16K objects ? Yes. You said speed was not an issue; pickling only 5000 objects, each no more than 16 kB, is easily handled by any remotely modern machine (and even plenty which are not very modern). -- Erik Max Francis [EMAIL PROTECTED] http://www.alcyone.com/max/ San Jose, CA, USA 37 20 N 121 53 W AIM erikmaxfrancis I used to walk around / Like nothing could happen to me -- TLC -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Philippe C. Martin wrote: Thank you all for your answers. A pure Python would have beenmy first choice. yet I now feel I should spend some time looking at PySQLite (I like the fact it's pre-compiled for Windows). Thanks. Philippe Philippe C. Martin wrote: Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Regards, Philippe Out of the suggestions SnakeSQL and KirbyBase are pure python. Gadfly is sorta pure, in that it will work without the compiled kjbuckets lib. J -- http://mail.python.org/mailman/listinfo/python-list
Re: Couple functions I need, assuming they exist?
I assume you mean translating something like '100' to '1,000,000'? I don't know of an existing function that does this, but here's a relatively simple implementation: py import itertools as it py def add_commas(s): ... rev_chars = it.chain(s[::-1], it.repeat('', 2)) ... return ','.join(''.join(three_digits) ... for three_digits ... in it.izip(*[rev_chars]*3))[::-1] ... Or for an equivalent less cryptic (IMHO) recipe: def num2str(num): '''Return a string representation of a number with the thousands being delimited. num2str(65837) '65,837' num2str(6582942) '6,582,942' num2str(23) '23' num2str(-1934) '-1,934' ''' parts = [] div = abs(num) while True: div,mod = divmod(div,1000) parts.append(mod) if not div: if num 0: parts[-1] *= -1 return ','.join(str(part) for part in reversed(parts)) Regards, George -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
OK, I'll try that too. Regards, Philippe Erik Max Francis wrote: Philippe C. Martin wrote: You mean pickling a dictionnary of 5000/16K objects ? Yes. You said speed was not an issue; pickling only 5000 objects, each no more than 16 kB, is easily handled by any remotely modern machine (and even plenty which are not very modern). -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Philippe C. Martin [EMAIL PROTECTED] wrote: Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Possible approach might be: 1. 5000 files -- my personal favourite. 2. GDBM 3. SQLite -- William Park [EMAIL PROTECTED], Toronto, Canada ThinFlash: Linux thin-client on USB key (flash) drive http://home.eol.ca/~parkw/thinflash.html BashDiff: Full featured Bash shell http://freshmeat.net/projects/bashdiff/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
1. 5000 files -- my personal favourite. You got a point William Park wrote: Philippe C. Martin [EMAIL PROTECTED] wrote: Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Possible approach might be: 1. 5000 files -- my personal favourite. 2. GDBM 3. SQLite -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Thanks, I'm looking at KirbyBase also but wonder if it can handle bitmaps (I could always pickle it first I guess). Regards, Philippe John Abel wrote: Philippe C. Martin wrote: Thank you all for your answers. A pure Python would have beenmy first choice. yet I now feel I should spend some time looking at PySQLite (I like the fact it's pre-compiled for Windows). Thanks. Philippe Philippe C. Martin wrote: Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Regards, Philippe Out of the suggestions SnakeSQL and KirbyBase are pure python. Gadfly is sorta pure, in that it will work without the compiled kjbuckets lib. J -- http://mail.python.org/mailman/listinfo/python-list
sudoku dictionary attack
Thought I'd offer a method for solving all possible 9x9 sudoku puzzles in one go. It'll takes a bit of time to run however (and 9x9 seems to be about as big as is reasonably possible before combinatorial explosion completely scuppers this type of program)... Basic idea:- Start with a grid initialised with: 123456789 234567891 345678912 456789123 567891234 678912345 789123456 891234567 912345678 Note that all rows and columns contain all 9 digits (but that the sub-tiles aren't correct for a sudoku solution). Next write a program which permutes all 9 columns, and then for each of those permutations permutes the last 8 rows. This will, I believe, generate all possible grids with no digit repetitions in any row or column. It will generate 14,631,321,600 (9!*8!) possible sudoku candidates. Finally, check each candidate to see if any 3x3 subtile has a repeated digit in it and discard as soon as a repeat is found (sooner the better). Any that come through unscathed get written as a 82 (81 + lf) char string to an output file. I've written a short program (in Python; see below) that tries out this idea. Indications are that my HP nc6000 laptop can check around 30,000 candidates/sec and that c.0.15% of them are valid sudoku solutions. That means it would take around 6.5 days to generate the between 20-30 million possible sudoku solutions it will find. That would require around 2GB in uncompressed disk storage. Gzip does a VERY good job of compressing files containing this type of data -- so I'd expect well over 80% compression (might even fit on a CD then). Once you've generated the solution data then comes the fun of searching it efficiently which I leave as an exercise for the reader :-) Regards, sub1ime_uk (at) yahoo (dot) com == #!python # # sudoku.py - generate all valid sudoku solutions # # Usage: sudoku N S #eg: sudoku 9 3 # Whare:- #N is the grid size (ie 9 for 9x9) #S is the sub-tile size (3 for 3x3) # # (c) 2005 sub1ime_uk (at) yahoo (dot) com # import sys from gzip import GzipFile from time import time def permute(s): if len(s)==0: return if len(s)==1: yield s return for i in range(len(s)): for t in permute(s[:i]+s[i+1:]): yield s[i:i+1]+t return def populate(sz, ini): tile = [] for i in range(sz): tile.append([]) for j in range(sz): x = chr((i+j)%sz+ord(ini)) tile[i].append(x) return tile def subtilesok(t, c, r, n, s): for x in range(0, n, s): for y in range(0, n, s): d = {} for i in range(s): cn = c[x+i] for j in range(s): rn = r[y+j] d[t[cn][rn]] = 1 if len(d.keys())!=n: return 0 return 1 def displaytile(t, c, r, lf): lfstr='' print for i in r: row = [] for j in c: row.append(t[j][i]) r=''.join(row) lfstr += r print ,r print lf.write(lfstr+\n) def fact(n): if n2: return 1 return n*fact(n-1) if __name__ == '__main__': st = time() logf = GzipFile(c:\\temp\\sudoku.gz, w) N=int(sys.argv[1]) S=int(sys.argv[2]) estimate = fact(N)*fact(N-1) if N!=S*S: print Subtile size, S, not sqrt of tile size, N sys.exit(1) cols = [x for x in range(N)] rows = [x for x in range(1, N)] primarytile = populate(N, '1') count = 0 answc = 0 for colp in permute(cols): for rowp in permute(rows): count += 1 if subtilesok(primarytile, colp, [0]+rowp, N, S): answc += 1 ct = time() et=ct-st if et0.0: print Found: %d out of %d (%.2f%%) checked % (answc, count, (answc*100./count)) print Progress: %.2f%% % ((count*100./estimate)) print Elapsed time: %.2f secs, checked: %d/s, found %d/s. % (et, (count/et), (answc/et)) print Estimate time to go: %.2f hours % ((estimate-count)*et/(count*3600.)) else: print %d / %d (%5.2f%%) % (answc, count, (answc*100./count)) displaytile(primarytile, colp, [0]+rowp, logf) print print Checked, count,tiles. Found, answc,answers. logf.close() sys.exit() === -- http://mail.python.org/mailman/listinfo/python-list
Re: Want to learn a language - is Python right?
Aziz McTang [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi Paul, Thanks for your input. As usual, hearing some answers helps formulate the question... What I'm looking for is more to learn one good, comprehensive programming language well than several approximately on an ad hoc basis. What I also failed to mention is the desire to develop my presently limited computer skills a lot further. You have received some good advice. There are strong tools to support localization, but they are not inexpensive. They might be lower cost than developing your own. However, your goal to develop your programming skills is also a cost to be considered. Are you interested in developing an open source localization tool? A consideration for web applications is who will be maintaining the code. If these are all your own and no one else will ever work on them, then use any tool you like. Coding them in x86 assembly language would increase your computer knowledge, but we both know that is not the right tool for this task. -- http://mail.python.org/mailman/listinfo/python-list
Re: Couple functions I need, assuming they exist?
Charles Krug [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] The target of the problems (my daughter) would prefer that the thousands be delimited. Is there a string function that does this? Be sure to use the locale approach and avoid rolling your own. -- http://mail.python.org/mailman/listinfo/python-list
Re: sudoku dictionary attack
[EMAIL PROTECTED] wrote: Thought I'd offer a method for solving all possible 9x9 sudoku puzzles in one go. It'll takes a bit of time to run however (and 9x9 seems to be about as big as is reasonably possible before combinatorial explosion completely scuppers this type of program)... Basic idea:- Start with a grid initialised with: 123456789 234567891 345678912 456789123 567891234 678912345 789123456 891234567 912345678 Note that all rows and columns contain all 9 digits (but that the sub-tiles aren't correct for a sudoku solution). Next write a program which permutes all 9 columns, and then for each of those permutations permutes the last 8 rows. This will, I believe, generate all possible grids with no digit repetitions in any row or column. It will generate 14,631,321,600 (9!*8!) possible sudoku candidates. Finally, check each candidate to see if any 3x3 subtile has a repeated digit in it and discard as soon as a repeat is found (sooner the better). Any that come through unscathed get written as a 82 (81 + lf) char string to an output file. I'm having trouble coming up with anything that fits this grid: ..12. ..2x. . . . . . . . where x is not 3, by permuting columns, then rows. You may also have to permute the numbers. Although, even then, x=1 is still impossible. -- http://mail.python.org/mailman/listinfo/python-list
Re: login website that using PHP
On Sun, 19 Jun 2005 19:11:38 -0700, frost wrote: Hi, I am trying to login a website that using PHP and javascript. This is what happend if you browse that website using IE, after you login, you Browser remembers so called HTTP authorization header field. It sends authorization information whenever server requiress authorization by sending corresponding status code and, so called, realm specification. It is beyond the scope of this group and it is well described in HTTP standard and corresponding RFC. DG -- http://mail.python.org/mailman/listinfo/python-list
Re: login website that using PHP
frost [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I am trying to login a website that using PHP and javascript. This is what happend if you browse that website using IE, after you login, you can go anywhere without enter your name and password again, as long as you keep that IE open, but after you close that IE, then later on open that website in a new window, you need to login again. I guess some session is created as long as your original login window dose not close. How I can handle this in python? I want get some information from that website. But the login page is not what I want, how can I simulate regular IE browser? I mean after I login, I can get to other pages from it, but I find my programe can't go other place except the login page. Hope you could understand my question. Thank you very much! Check here for some other examples, specifically 'Submitting values and clicking buttons in IE' http://tinyurl.com/7n7xf -- http://mail.python.org/mailman/listinfo/python-list
Re: Couple functions I need, assuming they exist?
On 20 Jun 2005 15:51:07 GMT, Duncan Booth [EMAIL PROTECTED] wrote: Peter Hansen wrote: The target of the problems (my daughter) would prefer that the thousands be delimited. Is there a string function that does this? You refer to something like putting a comma between groups of three digits, as in 1,000? This is locale-specific, and there's a locale module that should have what you need. import locale locale.setlocale(locale.LC_ALL, '') 'English_United Kingdom.1252' print locale.format(%d, 100, True) 1,000,000 Perfect! Thanks. Sometimes hard part is figuring out which package already does the thing I need done. Charles. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python choice of database
Correct, that's not a constraint right now. Paul Rubin wrote: Philippe C. Martin [EMAIL PROTECTED] writes: 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K You don't mention whether multiple running programs need to use it concurrently. That's usually done with client/server db's but it can be done standalone. -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedded Systems Python?
I developed for my former employee a thin client whose primary purpose was AS400 connectivity. This required a fairly complex interactive gui configuration which I wrote in Python. This system could also be configed by a remote manager. Wrote that also in python using UDP sockets. The hardware was 64Mb memory and 64Mb compact flash. OS wa 2.4.20 linux from Debian I did a lot of cleanup removing unneeded modules but other than that, standard Python 2.3.4 worked great. Dennis Clark wrote: Hi all, I've looked through the threads about embedded Python that are a year and a half old, and I thought that I'd ask this question now to see if anything has changed. Has anyone, or is anyone working with Python in an embedded Linux environment? Mine is NO where near as constrained as a cell phone since I've got plenty of memory to work with, I'm just running a Linux 2.4 kernel on an ARM9 platform. Are there success stories for Python on embedded Linux systems today? The embedded Java JVM's seem to all be propriatary and have quite high license fees (don't mention Kaffe, it seems pretty fragile to me.) I'm a bit of a newb when it comes to Python, is there anyone with experience compiling it on Linux platforms that can offer me pointers to try this out myself? thanks, DLC -- http://mail.python.org/mailman/listinfo/python-list
Re: utf8 and ftplib
Richard Lewis wrote: My code now works without generating any errors but Konqueror's KHTML and Embedded Advanced Text Viewer and IE5 on the Mac still show capital-A-with-a-tilde in all the files that have been generated/altered. Whereas my text editor and Mozilla show them correctly. How are you viewing the files? You have to tell the browser that they are UTF-8. If you just double-click the file, the browser will use its default encoding. If you are server the files from a web server then you should set the Content-Type header correctly. Or you can tell the browser directly (try View / Encoding in IE). Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: utf8 and ftplib
Richard Lewis wrote: On Mon, 20 Jun 2005 14:27:17 +0200, Fredrik Lundh [EMAIL PROTECTED] said: well, you're messing it up all by yourself. getting rid of all the codecs and unicode2charrefs nonsense will fix this: Thanks for being so patient and understanding. OK, I've taken it all out. The only thinking about encoding I had to do in the actual code I'm working on was to use: file.write(document.toxml(encoding=utf-8)) instead of just file.write(document.toxml()) because otherwise I got errors on copyright symbol characters. sounds like a bug in minidom... My code now works without generating any errors but Konqueror's KHTML and Embedded Advanced Text Viewer and IE5 on the Mac still show capital-A-with-a-tilde in all the files that have been generated/altered. Whereas my text editor and Mozilla show them correctly. The unicode2charrefs() nonsense was an attempt to make it output with character references rather than literal characters for all characters with codes greater than 128. Is there a way of doing this? character references refer to code points in the Unicode code space, so you just convert the bytes you get after converting to UTF-8. however, if you're only using characters from the ISO Latin 1 set (which is a strict subset of Unicode), you could en- code to iso-8859-1 and run unicode2charrefs on the result. but someone should really fix minidom so it does the right thing. (fwiw, if you use my ElementTree kit, you can simply do tree.write(encoding=us-ascii) and the toolkit will then use charrefs for any character that's not plain ascii. you can get ElementTree from here: http://effbot.org/zone/element-index.htm ) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Back to the future - python to C++ advice wanted
Kay Schluehr wrote: I recommend studying C++ idioms carefully. http://www1.bell-labs.com/user/cope/Patterns/C++Idioms/EuroPLoP98.html Thanks for the link; very useful indeed. If Georges starts on greenfields he may have a look at Qt and it's object library which is not only concerned with widgets. http://doc.trolltech.com/3.3/ BOOST is more high brow and I guess that it compiles slow because it uses templates extensively. Template metaprogramming as a compile time language was a funny discovery. Here is some prove of it's capabilities: http://osl.iu.edu/~tveldhui/papers/2003/turing.pdf Many thanks to Kay and Bruno for suggesting Boost; I browsed through its numerous libraries and they're quite impressive ! They seem indispensable, especially for python (or other very high level language) programmers going back to C++. Some libraries that seem to be very relevant to pythoneers are: - any: brings dynamic typing in C++ - tuple; 'nuff said - iterator: out-of-the-box equivalents of itertools.{imap,ifilter,izip,count}, reversed(), and others not existing or applicable in python - tokenizer, string_algo and regex: similar functionality to str.* and re.* - bind, mem_fn, function, functional, lambda: first class callables, currying, higher order (functional) programming - assign: syntactic sugar through operator overloading for (relatively) readable container initialization: mapint,int next = map_list_of(1,2)(2,3)(3,4)(4,5)(5,6); is actually valid and equivalent to next = dict([(1,2), (2,3), (3,4), (4,5), (5,6)]) - many, many more goodies, with or without respective standard python equivalent (threads, graphs, math utils, serialization, metaprogramming, etc). - and last but not least, Boost.Python. I don't think it's just a coincidence that among all languages they chose Python to make interoperable with C++ :-) Thanks again, George -- http://mail.python.org/mailman/listinfo/python-list
Re: binary file
Nader Emami wrote: Kent Johnson wrote: Nader Emami wrote: L.S., I have used the profile module to measure some thing as the next command: profile.run('command', 'file') But this make a binary file! How can I write the result of 'profile' in a ascii file? Others how can I read (or convert) the binary file to am ascii file? Use an instance of pstats.Stats to interpret the results: from pstats import Stats s = Stats('file') s.print_stats() etc. http://docs.python.org/lib/profile-stats.html Kent I got the same result as the execution of command. But I would like to write to the an external 'ascii' file! Oh, I get it, pstats.Stats doesn't have a way to send the output to a file. That's surprising! One option would be to write a program that outputs what you want, then redirect the output in the shell. Alternatively take a look a the source for print_stats() and write your own that outputs to a file. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: login website that using PHP
Thank you all for the help. This problem bothered me for 3 days, Now I get it! You are right, it is the session cookie, after I use the cookiejar and the opener, I got it!!! I am really glad I found this place. Thank you again! -- http://mail.python.org/mailman/listinfo/python-list
RE: Python choice of database
One db that is very much worth trying is Firebird. This is an open source Interbase 6.0 (Borland product) compatible db. It is a SourceForge project. There are three versions: the super server which is a client/server db, classic server (the one that I am very familiar with) which is also a client/server db, and the embedded server which is a standalone. In order to access the database you need the open source module KInterbasdb which is also a SourceForge project. KInterbasdb is a Python DB API 2.0 database driver. Firebird has a lot of documentation. Moreover it was made based on the Interbase 6.0, which is was made open source by Borland, so all of Borland's documentation and tools apply as well. Firebird can be found at: http://firebird.sourceforge.net/ KInterbasdb can be found at: http://kinterbasdb.sourceforge.net/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Philippe C. Martin Sent: Monday, June 20, 2005 8:19 AM To: python-list@python.org Subject: Python choice of database Hi, I am looking for a stand-alone (not client/server) database solution for Python. 1) speed is not an issue 2) I wish to store less than 5000 records 3) each record should not be larger than 16K As I start with Python objects, I thought of using shelve, but looking at the restrictions (record size + potential collisions) I feel I should study my options a bit further before I get started. Regards, Philippe -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Overcoming herpetophobia (or what's up w/ Python scopes)?
On 2005-06-18 05:26:13 +0100, Dennis Lee Bieber [EMAIL PROTECTED] said: On Sat, 18 Jun 2005 03:02:13 +1000, Steven D'Aprano [EMAIL PROTECTED] declaimed the following in comp.lang.python: The language is *always* spelt without the a, and usually all in lower-case: perl. Given that, at least one well known, book relates the name to Practical Extraction () Report Language, whether that was a retrofit or not -- I'd be tempted to user PERL for the name... All lowercase most likely reflects the standard habits of Linux/Unix command naming. I'd heard it was pathologically eclectic rubbish lister, but then you can't believe everything you hear :-) John Ochiltree -- 667 - The Neighbour of the Beast -- http://mail.python.org/mailman/listinfo/python-list
Re: What is different with Python ?
Andrea Griffini wrote: Indeed when talking about if learning C can hinder or help learning C++ I remember thinking that to learn C++ *superficially* learning C first is surely pointless or can even hinder. But to learn C++ deeply (with all its quirks) I think that learning C first helps. I think you are mistakingly bringing order into the picture, when extent is more likely the case. If you want to master C++, I think that most would agree you need to understand C. But there are many who would disagree that the path to C++ must *start* at C. (In fact, many people argue that a lot of bad C++ is due to people programming C in C++.) Instead they would argue that you should start by learning C++ superficially, then learn C, and re-evaluate you C++ practices in light of the lessons learned from C. The example I'll pull out is natural languages - I understood the grammar construction of my native tounge *much* better after learning a foreign language. From people I've talked to, this is a common occurance. But there would be few people who would advocate that one should learn a foreign language before learning one's native tounge. -- http://mail.python.org/mailman/listinfo/python-list
Re: Embedded Systems Python?
Dennis Clark wrote: ... Has anyone, or is anyone working with Python in an embedded Linux environment? Mine is NO where near as constrained as a cell phone since I've got plenty of memory to work with, I'm just running a Linux 2.4 kernel on an ARM9 platform. This really shouldn't be a problem - especially given python can be made to run on mobile phones (Nokia Series 60). We've found using python on Series 60 phones to be quite useful, so if you're using a linux box, you're presumably got more memory/CPU available than there, so I doubt you'll see major problems. Regards, Michael. -- http://kamaelia.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list