Re: Need Assistance on this program.
On 13/05/2011 06:22, vijay swaminathan wrote: Hi Tim., Thanks.. This works as I had expected. are there any documentation for the subprocess.call method? I tried going through the python doc but could not narrow down. http://docs.python.org/library/subprocess.html?highlight=subprocess%20call#subprocess.call I just wanted to know how do I pass an arguement after invoking the command prompt? Well, now, that's a whole 'nother can of worms :) The more so since you're relying on a command prompt. Can I suggest you read around the Popen.communicate method: http://docs.python.org/library/subprocess.html?highlight=subprocess%20call#subprocess.Popen.communicate and some of the examples below and try something out for yourself. It can be a little bit fiddly, but you'll do better if you get something up-and-running (or up-and-failing) and then ask for advice on where you're going wrong. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
On Thu, May 12, 2011 at 11:46 PM, rusi wrote: > The boolean domain is only a 100 years old. > Unsurprisingly it is not quite 'first-class' yet: See It is nowadays. Every halfway-mainstream language I can think of has an explicit boolean datatype. Heck, as of C99, even C has one now. I conjecture the only languages still lacking one are exotic niche/fringe languages. I would be interested to see a counterexample. > http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > [Lifted from http://c2.com/cgi/wiki?EqualVsTrueFalse ] > > > "In retrospect, one might be tempted to regard the introduction of > something as simple as the boolean domain as a minor invention, but I > think that that would be a grave mistake: it is a great invention > because, being so simple, it is such a powerful simplifier. It is of > the same level as the introduction of natural numbers, which enabled > us to add 3 to 5, regardless of whether we are adding apples or > pears." > > "George Boole made a radical invention, so radical, in fact, that now, > more than a century later, the scientific community has not absorbed > it yet. (To stay with the metaphor: officially, boolean expressions > may have reached the status of first-class citizens, in practice — > because old habits and prejudices die hard— they are still the victims > of discrimination.) Let me give you a few examples." > > "In the programming language FORTRAN, as conceived a century after > Boole published his invention, boolean expressions are allowed, but > there are no boolean variables! Their introduction into programming > had to wait until the design of ALGOL 60." > > > So, M Harris problem is that python could almost be a language for the > 'masses' (whatever that might mean) were it not for warts like "l not > is empty" is shorten-able to just "l" One language's wart is another language's idiom. And I think the irrational hate towards syntactically-significant indentation is by far a much larger barrier to "mass" adoption of Python; C++ has some features that are at least (if not more) subtle/unobvious than Python's __bool__(), yet it still enjoys "mass" use. > Dijkstra's problem (paraphrased) is that python, by choosing the > FORTRAN alternative of having a non-first-class boolean type, hinders > scientific/mathematical thinking/progress. Python has *not* chosen the Fortran alternative; *it has a first-class Boolean type*, namely bool. This line of argument thus fails. The fact that other types are implicitly coercible to bools doesn't make `bool` itself any less first-class. It is also ironic that one of the projects that exploits Python's flexible typing regarding normally-Boolean operators is a scientific one (NumPy). Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
On Thu, 12 May 2011 23:20:20 +1000, Chris Angelico wrote: : Writing a program requires expertise both in programming and in the : purpose for which it's being written. Ultimately, a programmer is a : translator; without proper comprehension of the material he's : translating, he can't make a clear translation. But that's completely : different from hiring someone to do a job, and then looking at the job : afterwards; True. When you are able completely to specify the job and commission it, then it is possible to isolate the disciplines, and reduce the programmer to translator. The challenge is that that very often is not the case. The double challenge in computing is that software its development is still not as well understood as hardware or construction. We still do not have sufficient tools, experience and frameworks to project and precisely plan a software development projects. They go over time, over budget, and under specifications far more often and more seriously than projects in other disciplines. Civil and electronic engineers spend much of their time learning to project and cost solutions. Computer engineers very rarely do; they just hack it. In other trades, there tend to be clear role divisions with different roles and specialisations, complementing eachothers. We have not yet quite managed to work out what a programmer, architect, designer, engineer, et cetera are in software. We have the idea that we need them, but we have not formalised them to the point where we know what to expect from each role, and we struggle communicating between them. Therefore, a programmer is not just a translator. The language to specify precisely what is required is not good enough, and therefor the programmer also needs to be a system designer, to some extent. What extent depends much on the situation. >From my point of view, it is just harder to instruct a programmer to write a code than it is to instruct a python interpreter. : if I order a concreting job, I'll look at whether it's : properly suited to the task, but I won't expect an explanation of : exactly what went into it, and I do not expect to understand the exact : chemistry of it. Only another expert in concrete would truly : comprehend it all. Now you are thinking black and white, while reality is a gray blur. You may not care about your concrete, but someone commissioning concrete to build a skyscraper would surely want to check the spec's to quite some level of detail. The construction engineers will surely need to know a lot more about the exact composition and science behind the recipe than the manager renting the top floor, and still much less than the concrete engineer. And the main difference here, is that the civil engineers have a much better language to share information. The best programmers have is the programmming language, and we ought to make that as good as possible. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: os.popen command working differently on Windows
On Thu, 12 May 2011 15:21:41 +0100, Tim Golden wrote: > os.popen returns a file-like object from which you can read any error > messages generated. The documentation doesn't say, but if it's anything like the Unix popen() function, with mode='r' the returned file-like object will correspond to the child's stdout, but error messages will normally be written to stderr. In any case, os.popen() and similar are deprecated in favour of subprocess.Popen(). -- http://mail.python.org/mailman/listinfo/python-list
Call for Papers (CFP)
= Journal of Emerging Trends in Computing and Information Sciences Call for Research Papers (Vol. 2 No. 6) June 2011 http://cisjournal.org/ = Dear Sir/ Madam, Journal of Emerging Trends in Computing and Information Sciences (E- ISSN 2218-6301/ ISSN 2079-8407) is an international refereed research publishing journal, focused on promoting and publishing original high quality research work in both theoretical and scientific aspects of all disciplines of Computing and Information Sciences. The objectives of the journal are to promote and publish original high quality research and to provide a forum to the researchers and industry practitioners for exchanging ideas, knowledge, and experience. We welcome original research and industry experience papers. Contributions should be written for one of the following categories: Original research Literature Review / Systematic Literature Review Short Articles on ongoing research Preliminary Findings Technical Reports / Notes Results previously published in conferences and/or journals may be submitted as extended versions. For more information about Journal and Publication Charges, please visit http://www.cisjournal.org/. You are requested to circulate this message among your colleagues and college/university fellows. Sincerely Yours, Editor Journal of Emerging Trends in Computing and Information Sciences URL: http://www.cisjournal.org E-mail:edi...@cisjournal.org -- http://mail.python.org/mailman/listinfo/python-list
Parsing a graph image
Hi python lovers out there, I am searching for a library to parse data from a graph in an image file something like http://pytseries.sourceforge.net/_images/yahoo.png Any suggestions, hints, links? TIA && have a nice day! :) Basti signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
On May 13, 1:02 pm, Chris Rebert wrote: > On Thu, May 12, 2011 at 11:46 PM, rusi wrote: > > > The boolean domain is only a 100 years old. > > Unsurprisingly it is not quite 'first-class' yet: See > > It is nowadays. Every halfway-mainstream language I can think of has > an explicit boolean datatype. I guess you did not quite see my 'quite' -- which itself is a summarization of Dijkstra's "officially" vs "in practice" ? [Heres the quote] > >http://www.cs.utexas.edu/users/EWD/transcriptions/EWD10xx/EWD1070.html > > [Lifted fromhttp://c2.com/cgi/wiki?EqualVsTrueFalse] > > > > > "In retrospect, one might be tempted to regard the introduction of > > something as simple as the boolean domain as a minor invention, but I > > think that that would be a grave mistake: it is a great invention > > because, being so simple, it is such a powerful simplifier. It is of > > the same level as the introduction of natural numbers, which enabled > > us to add 3 to 5, regardless of whether we are adding apples or > > pears." > > > "George Boole made a radical invention, so radical, in fact, that now, > > more than a century later, the scientific community has not absorbed > > it yet. (To stay with the metaphor: officially, boolean expressions > > may have reached the status of first-class citizens, in practice — > > because old habits and prejudices die hard— they are still the victims > > of discrimination.) Let me give you a few examples." > > > "In the programming language FORTRAN, as conceived a century after > > Boole published his invention, boolean expressions are allowed, but > > there are no boolean variables! Their introduction into programming > > had to wait until the design of ALGOL 60." As an analogy, in Perl, a list can get coerced to its length "... when in scalar context.." or something like that. Most programmers from the static-typechecked-languages camp would balk at that laissez faire attitude. Likewise Harris is pointing out that noob python programmers may feel a bit unnerved by non-boolean types unexpectedly showing 'boolean-ness.' Maybe we are just more in noob category and we've not got the zen of python?? Dunno... -- http://mail.python.org/mailman/listinfo/python-list
Assistance in understanding the sub-Process module
Hi Gurus, I'm new to Python programming and in the process of learning the sub process module. I went through the python documentation http://docs.python.org/library/subprocess.html and I have the following queries 1. The class definition as per the documentation is: *class *subprocess.Popen(*args*, *bufsize=0*, *executable=None*, *stdin=None *, *stdout=None*, *stderr=None*, *preexec_fn=None*, *close_fds=False*, * shell=False*, *cwd=None*, *env=None*, *universal_newlines=False*, * startupinfo=None*, *creationflags=0*) *args* should be a string, or a sequence of program arguments. so I assume that args can be a string or a list with first item of the list being the program to execute. so on the python IDLE, I executed this command, >>> subprocess.Popen('cmd.exe') which opened up a command prompt. when I give this as a list, as below it throwed this error. >>> subprocess.Popen(['cmd.exe', 'dir']) Traceback (most recent call last): File "", line 1, in subprocess.Popen(['cmd.exe' 'dir']) File "C:\Python26\lib\subprocess.py", line 623, in __init__ errread, errwrite) File "C:\Python26\lib\subprocess.py", line 833, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified >>> I would assume that a list is accepted as part of the args and first being the program (cmd.exe) and the rest being the arguments... please correct me If i misunderstood. Thanks, -- Vijay Swaminathan -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursion or iteration (was Fibonacci series recursion error)
On May 12, 3:06 am, Hans Mulder wrote: > On 03/05/2011 09:52, rusi wrote: > > > [If you believe it is, then try writing a log(n) fib iteratively :D ] > > It took me a while, but this one seems to work: > > from collections import namedtuple > > Triple = namedtuple('Triple', 'hi mid lo') > Triple.__mul__ = lambda self, other: Triple( > self.hi * other.hi + self.mid * other.mid, > self.hi * other.mid + self.mid * other.lo, > self.mid * other.mid + self.lo * other.lo, > ) > > def fib(n): > f = Triple(1, 1, 0) > a = Triple(1, 0, 1) > while n: > if n & 1: > a *= f > f *= f > n >>= 1 > return a.mid > > -- HansM Bravo! Can you explain this? The tightest way I knew so far was this: The 2x2 matrix 0 1 1 1 raised to the nth power gives the nth fibonacci number. [And then use a logarithmic matrix mult] Your version is probably tighter than this. Yet one could argue that this is 'cheating' because you (and I) are still solving the power problem. What I had in mind was to use fib results like: f_(2n) = f_n^2 + f_(n+1)^2 and use these in the same way (from first principles) like we use the equation x^2n = (x*x)^n to arrive at a logarithmic power algo. -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
Bastian Ballmann wrote: > I am searching for a library to parse data from a graph in an image file > something like http://pytseries.sourceforge.net/_images/yahoo.png > Any suggestions, hints, links? I'm not sure I understand 100% what you want. If you want to extract ("parse") the data that is contained in an image file, I have no clue how to do that. However, if you want to create such images and you already have the data, that should be as easy as picking the right library for that. I did a short search of Packages available for Debian and it gave me these: python-magics++ - python support for Magics++ python-matplotlib - Python based plotting system in a style similar to Matlab python-mpmath - library for arbitrary-precision floating-point arithmetic python-plplot - Python support for PLplot, a plotting library python-qwt3d-qt3 - Python bindings of the QwtPlot3D library python-qwt3d-qt4 - Python bindings of the QwtPlot3D library python-qwt5-qt3 - Python version of the Qwt5 technical widget library python-qwt5-qt4 - Python version of the Qwt5 technical widget library python-pybiggles - Scientific plotting package for Python python-chaco - interactive plotting application toolkit python-gnuplot - A Python interface to the gnuplot plotting program python-pychart - Python library for creating high quality charts python-simpy - python-based simulation package python-scitools - Python library for scientific computing python-sympy - Computer Algebra System (CAS) in Python python-viper - minimalistic scientific plotter and run-time visualization module Good luck! Uli -- Domino Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932 -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
Hi, Am Fri, 13 May 2011 14:01:48 +0200 schrieb Ulrich Eckhardt : > I'm not sure I understand 100% what you want. If you want to extract > ("parse") the data that is contained in an image file, I have no clue > how to do that. Yes, I want to extract the data that is contained in an image file. Greets Basti signature.asc Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
Yes, I want to extract the data that is contained in an image file. Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
Yes, I want to extract the data that is contained in an image file. Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
Yes, I want to extract the data that is contained in an image file. Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
Yes, I want to extract the data that is contained in an image file. Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
Yes, I want to extract the data that is contained in an image file. Greets Basti > Yes, I want to extract the data that is contained in an image file. > Greets Maybe ask to imagemagick's or matplotlib. They should know if it is possible at all. Good luck. Laurent -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
On 13-May-2011, at 5:54 PM, Bastian Ballmann wrote: > Hi, > > Am Fri, 13 May 2011 14:01:48 +0200 > schrieb Ulrich Eckhardt : > >> I'm not sure I understand 100% what you want. If you want to extract >> ("parse") the data that is contained in an image file, I have no clue >> how to do that. > > Yes, I want to extract the data that is contained in an image file. > Greets > I guess it requires some kind of image processing , where you can move around image pixel by pixel and somehow figure out what color is present in that pixel . If there isn’t much noise in the image you should sharp contrast and would be able to differentiate between two colors ? if yes ( I don’t know matlab might provide some tools .. just guessing ) then its easy i think to pick (X,Y) as time and value ? ~saurabh verma -- http://mail.python.org/mailman/listinfo/python-list
Re: Assistance in understanding the sub-Process module
On 13/05/2011 12:03, vijay swaminathan wrote: 1. The class definition as per the documentation is: /class /subprocess.Popen(/args/, /bufsize=0/, /executable=None/, /stdin=None/, /stdout=None/, /stderr=None/, /preexec_fn=None/, /close_fds=False/, /shell=False/, /cwd=None/, /env=None/, /universal_newlines=False/, /startupinfo=None/, /creationflags=0/) /args/ should be a string, or a sequence of program arguments. so I assume that args can be a string or a list with first item of the list being the program to execute. That's more or less correct. A list is usually preferable as it leaves the heavy-lifting of getting the quotes right to the underlying library. so on the python IDLE, I executed this command, >>> subprocess.Popen('cmd.exe') which opened up a command prompt. when I give this as a list, as below it throwed this error. >>> subprocess.Popen(['cmd.exe', 'dir']) Traceback (most recent call last): File "", line 1, in subprocess.Popen(['cmd.exe' 'dir']) File "C:\Python26\lib\subprocess.py", line 623, in __init__ errread, errwrite) File "C:\Python26\lib\subprocess.py", line 833, in _execute_child startupinfo) WindowsError: [Error 2] The system cannot find the file specified Well I would actually have expected it to open a command prompt and do nothing else. If you do this in a (Windows) command prompt: cmd /? you can see that the way to run a command from with a command shell is to use: cmd /c (or /k which leaves the console running afterwards). Note that you only even need to launch cmd for internal commands which aren't executables in their own right. ie you don't need to do cmd /c notepad since notepad can run on its own. So doing cmd will just run cmd and, I think, ignore the rest of the line. You actually want: import subprocess subprocess.Popen (["cmd", "/c", "dir"]) However, that is exactly what passing shell=True to Popen does for you so... import subprocess subprocess.Popen ("dir", shell=True) # or subprocess.Popen (["dir"], shell=True) TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
I guess it requires some kind of image processing , where you can move around image pixel by pixel and somehow figure out what color is present in that pixel . If there isn’t much noise in the image you should sharp contrast and would be able to differentiate between two colors ? if yes ( I don’t know matlab >might provide some tools .. just guessing ) then its easy i think to pick (X,Y) as time and value ? You made me think that in addition to ask to imagemagick's and matplotlib, one can also as to Sage[1] In order of pythonicity : - matplotlib - sage - imagemagick's Laurent [1] www.sagemath.org PS : Sorry for having send my previous answer 5 times. I don't understand :( -- http://mail.python.org/mailman/listinfo/python-list
problem with GKT module?
I am using gtk.builder with a glade generated GUI I have a simple call back defined for a radio button widget when I use widget.name in linux I get a value of None, windows returns the widget name as I would expect. is this a bug? if not how should i find the name of the widget that has triggered a call back? (I would like all my radio buttons to go to the same callback routine if possible to make code maintenance easier) -- 101-ism: The tendency to pick apart, often in minute detail, all aspects of life using half-understood pop psychology as a tool. -- Douglas Coupland, "Generation X: Tales for an Accelerated Culture" -- You may my glories and my state dispose, But not my griefs; still am I king of those. -- William Shakespeare, "Richard II" -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
On 2011-05-13, Bastian Ballmann wrote: > Hi python lovers out there, > > I am searching for a library to parse data from a graph in an > image file something like > http://pytseries.sourceforge.net/_images/yahoo.png Any > suggestions, hints, links? You can do this with PIL http://www.pythonware.com/products/pil/>. The technique is necessary in The Python Challenge, for example. http://www.pythonchallenge.com/> -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursion or iteration (was Fibonacci series recursion error)
On Fri, May 13, 2011 at 5:11 AM, rusi wrote: > The tightest way I knew so far was this: > The 2x2 matrix > 0 1 > 1 1 > raised to the nth power gives the nth fibonacci number. [And then use > a logarithmic matrix mult] > Your version is probably tighter than this. Oh, nice! I did it this way once: V = [0 1] M = [0 1] [1 1] fib(n) = (V * M ** n)[0] Since I viewed M as operating on V, it never occurred to me that multiplying by V is actually unnecessary, but it is obvious in retrospect. I think it's just a fortuitous coincidence that it works, since V sets up the base case and M describes the recursive case. For a FIbonacci sequence starting with any other pair of numbers, V would change, but M would not, and so V would no longer happen to be identical to the top row of M. Ian -- http://mail.python.org/mailman/listinfo/python-list
My direct client Hiring and interviewing going on Live today.
Hi, My direct client Hiring and interviewing going on Live today. I am having some very good direct client openings currently. I can get the consultant interviewed within 24 business hours. Please drop me an email to get all my direct client openings. I will reply to only those emails which are delivered to yagn...@cyberthink.com. Thanks and Regards, Yagnesh -- http://mail.python.org/mailman/listinfo/python-list
My direct client Hiring and interviewing going on Live today.
Hi, My direct client Hiring and interviewing going on Live today. I am having some very good direct client openings currently. I can get the consultant interviewed within 24 business hours. Please drop me an email to get all my direct client openings. I will reply to only those emails which are delivered to yagn...@cyberthink.com. Thanks and Regards, Yagnesh -- http://mail.python.org/mailman/listinfo/python-list
Regular Expression for words (with umlauts, without numbers)
Dear experts, I'm looking for a regular expression to recognize natural language words with umlauts but without numbers. While \w with re.U does recognize words with umlauts, it also matches numbers, which I do not want. Is there a better way than an exhaustive enumeration such as [-a-zàáâãäåæ...]? I guess there should be a better way as \w appears to know about alphabetical characters... Thanks in advance Jens -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression for words (with umlauts, without numbers)
Hallo Jens, In current python re module, you have to do something like: ((?!\d|_\w)+ which uses the negative look ahead to grab all words except integers and underscore. Of course, if you turn on the unicode flag re.U or use it inline like, (?u) then this will grab your desired umlauts. I'd actually recommend, however, that if you have an extra 20 minutes, to use Regexp 2.7: http://bugs.python.org/issue2636 Its a much needed improvement over F.Lundh's re implementation (from 1999!) and its 40% faster. Moreover, you can do exactly what you are requesting like so, (?u)[[:alpha:]]+ cheers, --tim On Fri, May 13, 2011 at 9:01 AM, Jens Lechtenboerger < lech...@helios.uni-muenster.de> wrote: > Dear experts, > > I'm looking for a regular expression to recognize natural language > words with umlauts but without numbers. While \w with re.U does > recognize words with umlauts, it also matches numbers, which I do > not want. > > Is there a better way than an exhaustive enumeration such as > [-a-zàáâãäåæ...]? > > I guess there should be a better way as \w appears to know about > alphabetical characters... > > Thanks in advance > Jens > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression for words (with umlauts, without numbers)
Jens Lechtenboerger wrote: > I'm looking for a regular expression to recognize natural language > words with umlauts but without numbers. While \w with re.U does > recognize words with umlauts, it also matches numbers, which I do > not want. > > Is there a better way than an exhaustive enumeration such as > [-a-zàáâãäåæ...]? > > I guess there should be a better way as \w appears to know about > alphabetical characters... How about [^\W\d] ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression for words (with umlauts, without numbers)
On 2011-05-13, Peter Otten wrote: > Jens Lechtenboerger wrote: > >> I'm looking for a regular expression to recognize natural language >> words with umlauts but without numbers. While \w with re.U does >> recognize words with umlauts, it also matches numbers, which I do >> not want. >> >> Is there a better way than an exhaustive enumeration such as >> [-a-zàáâãäåæ...]? >> >> I guess there should be a better way as \w appears to know about >> alphabetical characters... > > How about [^\W\d] ? Brilliant. Thanks Jens -- http://mail.python.org/mailman/listinfo/python-list
Re: os.popen command working differently on Windows
On 12/05/2011 16:21, Tim Golden wrote: On 12/05/2011 15:11, Ayaskanta Swain wrote: Please help me in solving the following issue I am facing while executing my python script. Basically I am executing the OS specific move command to move a file/dir from one location to another. Why? Why not use os.rename or shutil.move which already do whatever is needed under the covers for different Operating Systems? os.popen returns a file-like object from which you can read any error messages generated. You're not doing that, and os.popen won't raise an error itself unless you, say, pass it a number rather than a string. import os output = os.popen ("dir") print output.read () # # But note: # os.popen ("Nonsen*se") # raises no exception If you want exceptions, try the subprocess module: >>> import subprocess >>> subprocess.Popen("Nonsen*se") Traceback (most recent call last): File "", line 1, in File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 672, in __init__ errread, errwrite) File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1201, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory >>> In fact, os.popen is deprecated in favour of subprocess.Popen(). HTH, -- HansM -- http://mail.python.org/mailman/listinfo/python-list
How best to convert a string "list" to a python list
I want some code to take the items in a semi-colon-delimted string "list" and places each in a python list. I came up with below. In the name of learning how to do things properly, do you experts have a better way of doing it? Thanks for any inputs! *** x = "red;blue;green;yellow" ## string of semi-colon delimited colors color_list = [] ## sc = semi-colon while x.find(";") <> -1: sc_pos = x.find(";") current_color = x[0:sc_pos] ## color w/o sc current_color_sc = x[0:sc_pos+1] ## color with sc color_list.append(current_color) ## append color to list x = x.replace(current_color_sc, "") ## remove color and sc from string print current_color print color_list print x + "\n" color_list.append(x) # append last color left in x (no sc at end of string) print color_list print "done" -- http://mail.python.org/mailman/listinfo/python-list
Re: How best to convert a string "list" to a python list
There are a series of built-in methods for string objects; including the split method which will accomplish exactly the result you are looking for. >>> x = "red;blue;green;yellow" >>> color_list = x.split(';') >>> color_list ['red', 'blue', 'green', 'yellow'] >>> Here is the link to a discussion of the build-in str methods (3.2), but this documentation exists for prior versions of Python as well. http://docs.python.org/py3k/library/stdtypes.html#str.split Good luck, Mark Niemczyk -- http://mail.python.org/mailman/listinfo/python-list
Re: How best to convert a string "list" to a python list
On Fri, May 13, 2011 at 1:15 PM, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In > the name of learning how to do things properly, do you experts have a > better way of doing it? Strings have a split method, which splits the string into a list based on a delimiter, like this: >>> x = "red;blue;green;yellow" >>> color_list = x.split(";") >>> print color_list ['red', 'blue', 'green', 'yellow'] That's how I'd do it. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: How best to convert a string "list" to a python list
On May 13, 1:25 pm, Mark Niemczyk wrote: > There are a series of built-in methods for string objects; including the > split method which will accomplish exactly the result you are looking for. > > >>> x = "red;blue;green;yellow" > >>> color_list = x.split(';') > >>> color_list > > ['red', 'blue', 'green', 'yellow'] > > > > Here is the link to a discussion of the build-in str methods (3.2), but this > documentation exists for prior versions of Python as well. > > http://docs.python.org/py3k/library/stdtypes.html#str.split > > Good luck, > > Mark Niemczyk Haha! This is why I ask, because my code is pretty laughable and elementary! I'm learning... Thanks Mark! -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression for words (with umlauts, without numbers)
On 13/05/2011 17:14, Tim Chon wrote: Hallo Jens, In current python re module, you have to do something like: ((?!\d|_\w)+ which uses the negative look ahead to grab all words except integers and underscore. Of course, if you turn on the unicode flag re.U or use it inline like, (?u) then this will grab your desired umlauts. I'd actually recommend, however, that if you have an extra 20 minutes, to use Regexp 2.7: http://bugs.python.org/issue2636 Its a much needed improvement over F.Lundh's re implementation (from 1999!) and its 40% faster. Moreover, you can do exactly what you are requesting like so, (?u)[[:alpha:]]+ The latest release is here: http://pypi.python.org/pypi/regex -- http://mail.python.org/mailman/listinfo/python-list
Re: How best to convert a string "list" to a python list
On 13/05/2011 18:15, noydb wrote: I want some code to take the items in a semi-colon-delimted string "list" and places each in a python list. I came up with below. In the name of learning how to do things properly, do you experts have a better way of doing it? Thanks for any inputs! *** x = "red;blue;green;yellow" ## string of semi-colon delimited colors color_list = [] ## sc = semi-colon while x.find(";")<> -1: sc_pos = x.find(";") current_color = x[0:sc_pos] ## color w/o sc current_color_sc = x[0:sc_pos+1] ## color with sc color_list.append(current_color) ## append color to list x = x.replace(current_color_sc, "") ## remove color and sc from string print current_color print color_list print x + "\n" color_list.append(x) # append last color left in x (no sc at end of string) print color_list print "done" >>> x = "red;blue;green;yellow" >>> x.split(";") ['red', 'blue', 'green', 'yellow'] -- http://mail.python.org/mailman/listinfo/python-list
how to install easy_install
I tried to install easy_install (This is on windows) I downloaded the executable and ran it. It claimed to have done its job. But now when I type easy_install at a cmd prompt I get easy_install is not a command... [I guess I am a perennial noob to windows, never being able to comprehend the PATH lookup logic (or lack of it)] Another related question: I gather that easy_install is being superseded by pypi or some such but I cant find the link... -- http://mail.python.org/mailman/listinfo/python-list
Re: how to install easy_install
On Fri, May 13, 2011 at 11:40 AM, rusi wrote: > I tried to install easy_install (This is on windows) > I downloaded the executable and ran it. It claimed to have done its > job. > > But now when I type easy_install at a cmd prompt I get > easy_install is not a command... > > [I guess I am a perennial noob to windows, never being able to > comprehend the PATH lookup logic (or lack of it)] > > Another related question: I gather that easy_install is being > superseded by pypi or some such but I cant find the link... easy_install is part of the setuptools or distribute package. I assume that one of these is what you installed. On Windows, the easy_install command is installed into your Python Scripts directory, which should be something like "C:\Python27\Tools\Scripts" or "C:\Python25\Scripts" depending on your Python version. You just need to find that directory and add it to your PATH. PyPI is the Python package index. It's a website at http://pypi.python.org/ -- not a replacement for setuptools or easy_install, which uses it to look up package metadata. Setuptools is supposed to be superseded by distribute, which may be what you heard. HTH, Ian -- http://mail.python.org/mailman/listinfo/python-list
Import on case insensitive filesystem
Hello, I'm developing an app which runs Python on a filesystem which is not case sensitive (Mac OS X), but is mounted as an NFS drive on a remote machine. This causes errors because of the import being case sensitive but accessing an FS which is case insensitive. Short of copying the entire directory tree over to another filesystem, is there anything I can do to flag Python to act as though it were on a case sensitive FS? The exact issue I'm seeing is this file, named crypto.py, and relying on pycrypto: from Crypto.Cipher import AES print("Made it!") That attempts to import the same file (itself) instead of finding the Crypto module since the filesystem casing is incorrect. Any tips would be greatly appreciated. Best, Mitchell -- http://mail.python.org/mailman/listinfo/python-list
Re: How best to convert a string "list" to a python list
On Fri, 13 May 2011 10:15:29 -0700, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In the > name of learning how to do things properly, do you experts have a better > way of doing it? How about the below? dan@dan:~/development$ python Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = "cyan;magenta;yellow;black" >>> xList = x.split(';') >>> xList ['cyan', 'magenta', 'yellow', 'black'] >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
On 5/13/11 7:24 AM, Bastian Ballmann wrote: Hi, Am Fri, 13 May 2011 14:01:48 +0200 schrieb Ulrich Eckhardt: I'm not sure I understand 100% what you want. If you want to extract ("parse") the data that is contained in an image file, I have no clue how to do that. Yes, I want to extract the data that is contained in an image file. There is nothing in Python that solves this problem, per se, but there are free and open source tools for this out there. E.g. http://digitizer.sourceforge.net/ -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
ru...@yahoo.com wrote: http://www.codinghorror.com/blog/2006/07/separating-programming-sheep-from-non-programming-goats.html A later paper by the same authors... (http://www.eis.mdx.ac.uk/research/PhDArea/saeed/paper3.pdf) These papers are fascinating reading, not only for philosophy sake in a great study in epistemology, but for a good clean study in good science and an appropriate measure of the scientific method in an interesting case study that 'failed'. In that regard it was a huge success! The authors recognize (in paper [2]) that while their findings disproved their hypothesis the advances they made through good science have left the door open for further study. This is good news for the field of philosophy generally, and for epistemology in particular. --- I too have noticed the general 'case' put forward in paper(1): namely, some people just don't seem to get it on the surface, and we can't figure out why. On the other hand, I have 'always' been able to teach computer science (programming in particular) to 'anyone' given enough time, attention, creativity, and caring. In fact, when I find someone who is exhibiting low aptitude potential (let's say zero '0') then I must allow even more time, more attention, much more creativity, and a lot more caring. I remember a line from "Mr. Holland's Opus," (a great movie, by the way) where Mr Holland is explaining to the coach why a certain young man has not any musical acumen --- and the coach says, "..you telling me you can't teach a willing kid to beat a drum...?... then you're a lousy teacher!" Holland ended up teaching us all a lot more than how to beat a drum, before the end of the movie The point here is that aptitude says what a person has been conditioned for at this 'point in time' to be able to do... but says nothing about what re-conditioning might do for a transformed life! If I can't teach a kid how to program a computer, I'm a lousy teacher! --- I grew up with computers. But kids today have 'magical' thinking about these machines, because they didn't grow up with them. If you started out (like I did) on the Altair 8800, or the Wang 700, programming in machine code, it became very clear rapidly why a high level language of some type might be beneficial ( and you could relate how the language constructs made the translation to machine code possible ). It was easier for me to learn programming, because I evolved with it. On the other hand, kids today are dumped into a first comp sci course in programming and plopped in-front of a Hugs interactive shell and then are expected to learn programming and be successful by trying to grasp pure functional programming in Haskell(!) in a ten to 12 week term and we wonder why so many students are failing their 'first' programming class!! Give me a break. No, give them a break. Guido van Rossum has said in one of his interviews (can't remember now which one) that BASIC is a terrible first computer language... and I agree... but, it was a lot better than Hugs! But that's not my point, my point is that Python is better still. Why? Because Python can be taught at a *very* rudimentary level ( input, control, arithmetic, logic and output ) in almost a BASIC or REXX procedural style -- top down -- so that students 'get it'. Then, in subsequent classes down the road (much later) Python can grow and expand with the student's re-conditioning for more in-depth expansion of concepts and knowledge. At the graduate level Python will still be there... challenging students to extend and expand in ways that were not even possible to discuss in the first introductory course. It seems to me that if the goal of comp sci courses at universities and colleges is 'education' that comp sci professors and instructors would get a handle on this. If you can't teach a willing kid to write a functioning computer program then you're a lousy teacher. kind regards, m harris -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursion or iteration (was Fibonacci series recursion error)
On 13/05/2011 13:11, rusi wrote: On May 12, 3:06 am, Hans Mulder wrote: On 03/05/2011 09:52, rusi wrote: [If you believe it is, then try writing a log(n) fib iteratively :D ] It took me a while, but this one seems to work: from collections import namedtuple Triple = namedtuple('Triple', 'hi mid lo') Triple.__mul__ = lambda self, other: Triple( self.hi * other.hi + self.mid * other.mid, self.hi * other.mid + self.mid * other.lo, self.mid * other.mid + self.lo * other.lo, ) def fib(n): f = Triple(1, 1, 0) a = Triple(1, 0, 1) while n: if n& 1: a *= f f *= f n>>= 1 return a.mid -- HansM Bravo! Can you explain this? The tightest way I knew so far was this: The 2x2 matrix 0 1 1 1 raised to the nth power gives the nth fibonacci number. [And then use a logarithmic matrix mult] Your version is probably tighter than this. My method is just a thinly disguised version of your method: your 2x2 matrices are symmetrical, i.e. the number in the upper right is equal to the number in the lower left. So I can save some memory and some CPU time by working with only three numbers. Yet one could argue that this is 'cheating' because you (and I) are still solving the power problem. That's true. What I had in mind was to use fib results like: f_(2n) = f_n^2 + f_(n+1)^2 and use these in the same way (from first principles) like we use the equation x^2n = (x*x)^n to arrive at a logarithmic power algo. To compute f(4n) this way, you need to compute both f(2n) and f(2n+1) first, and to compute those, you need f(n) and f(n+1) and f(n+2) I think I can construct an O(log(n)**2) algorithm this way. And it would still be 'cheating', because we'd still use some special property of the Fibonacci sequence to reduce our problem to the power problem. I think this sort of cheating can't be avoided: there is no general method to compute recurrent sequences faster than O(n); Fibonacci is just a special case. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode by default
jmfauth wrote: to worry about encodings are when you're encoding unicode characters > to byte strings, or decoding bytes to unicode characters A small but important correction/clarification: In Unicode, "unicode" does not encode a*character*. It encodes a*code point*, a number, the integer associated to the character. That is a huge code-point... pun intended. ... and there is another point that I continue to be somewhat puzzled about, and that is the issue of fonts. On of my hobbies at the moment is ancient Greek (biblical studies, Septuaginta LXX, and Greek New Testament). I have these texts on my computer in a folder in several formats... pdf, unicode 'plaintext', osis.xml, and XML. These texts may be found at http://sblgnt.com I am interested for the moment only in the 'plaintext' stream, because it is unicode. ( first, in unicode, according to all the doc there is no such thing as 'plaintext,' so keep that in mind). When I open the text stream in one of my unicode editors I can see 'most' of the characters in a rudimentary Greek font with accents; however, I also see many tiny square blocks indicating (I think) that the code points do *not* have a corresponding character in my unicode font for that Greek symbol (whatever it is supposed to be). The point, or question is, how does one go about making sure that there is a corresponding font glyph to match a specific unicode code point for display in a particular terminal (editor, browser, whatever) ? The unicode consortium is very careful to make sure that thousands of symbols have a unique code point (that's great !) but how do these thousands of symbols actually get displayed if there is no font consortium? Are there collections of 'standard' fonts for unicode that I am not aware? Is there a unix linux package that can be installed that drops at least 'one' default standard font that will be able to render all or 'most' (whatever I mean by that) code points in unicode? Is this a Python issue at all? kind regards, m harris -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode by default
On 5/13/11 2:53 PM, harrismh777 wrote: The unicode consortium is very careful to make sure that thousands of symbols have a unique code point (that's great !) but how do these thousands of symbols actually get displayed if there is no font consortium? Are there collections of 'standard' fonts for unicode that I am not aware? There are some well-known fonts that try to cover a large section of the Unicode standard. http://en.wikipedia.org/wiki/Unicode_typeface Is there a unix linux package that can be installed that drops at least 'one' default standard font that will be able to render all or 'most' (whatever I mean by that) code points in unicode? Is this a Python issue at all? Not really. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
On Fri, May 13, 2011 at 1:41 PM, harrismh777 wrote: > On the other hand, kids today are dumped into a first comp sci course in > programming and plopped in-front of a Hugs interactive shell and then are > expected to learn programming and be successful by trying to grasp pure > functional programming in Haskell(!) in a ten to 12 week term and we wonder > why so many students are failing their 'first' programming class!! Give me > a break. No, give them a break. Well, at least Haskell is probably better as an introductory language than Lisp or Scheme. But what schools actually do this? My perception is that the vast majority of schools use C++ or C# or Java, typically relegating functional programming to a single second- or third-year course. Of course it's well known that MIT used to use Scheme, but they switched to Python a couple years ago. > Guido van Rossum has said in one of his interviews (can't remember now which > one) that BASIC is a terrible first computer language... and I agree... but, > it was a lot better than Hugs! But that's not my point, my point is that > Python is better still. Why? Because Python can be taught at a *very* > rudimentary level ( input, control, arithmetic, logic and output ) in almost > a BASIC or REXX procedural style -- top down -- so that students 'get it'. > Then, in subsequent classes down the road (much later) Python can grow and > expand with the student's re-conditioning for more in-depth expansion of > concepts and knowledge. I don't think a single language is necessarily going to be best for all students. If a math major comes to you wanting to learn some programming for theorem-proving, bearing in mind that they probably aren't interested in learning more than a single language, would you try to start them out with Python, or would you just give them the functional language that they're ultimately going to want? -- http://mail.python.org/mailman/listinfo/python-list
Re: How best to convert a string "list" to a python list
On Fri, May 13, 2011 at 11:15 AM, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In > the name of learning how to do things properly, do you experts have a > better way of doing it? > > Thanks for any inputs! > > *** > x = "red;blue;green;yellow" ## string of semi-colon delimited colors > > color_list = [] > ## sc = semi-colon > > while x.find(";") <> -1: >sc_pos = x.find(";") >current_color = x[0:sc_pos] ## color w/o sc >current_color_sc = x[0:sc_pos+1] ## color with sc >color_list.append(current_color) ## append color to list >x = x.replace(current_color_sc, "") ## remove color and sc from > string >print current_color >print color_list >print x + "\n" > > color_list.append(x) # append last color left in x (no sc at end of > string) > print color_list > > print "done" > -- > http://mail.python.org/mailman/listinfo/python-list > Try the following: color_list = x.split(";") Python string objects have a variety of helpful methods. Take a look at http://docs.python.org/library/stdtypes.html#string-methods. Hope that helps. -eric -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursion or iteration (was Fibonacci series recursion error)
On May 11, 11:06 pm, Hans Mulder wrote: > On 03/05/2011 09:52, rusi wrote: > > > [If you believe it is, then try writing a log(n) fib iteratively :D ] > > It took me a while, but this one seems to work: > > from collections import namedtuple > > Triple = namedtuple('Triple', 'hi mid lo') > Triple.__mul__ = lambda self, other: Triple( > self.hi * other.hi + self.mid * other.mid, > self.hi * other.mid + self.mid * other.lo, > self.mid * other.mid + self.lo * other.lo, > ) > [...] You can even get away with pairs rather than triples: from collections import namedtuple Pair = namedtuple('Pair', 'z o') Pair.__mul__ = lambda self, other: Pair( self.z * other.z + self.o * other.o, self.z * other.o + self.o * other.z + self.o * other.o, ) def fib(n): f = Pair(0, 1) a = Pair(1, 0) while n: if n & 1: a *= f f *= f n >>= 1 return a.o I don't see this (or Hans' version) as cheating at all. This really *is* the power algorithm, just in a different number system from the usual one. For those with a bit of abstract algebra, the above algorithm is just computing x^n in the ring Z[x] / (x^2 - x - 1). A pair 'Pair(a, b)' represents the element 'a + bx' (more precisely, the image of 'a + bx' under the natural quotient map Z[x] -> Z[x] / (x^2 - x - 1)) of that ring. And this *can* be generalised to other sequences given by a linear recurrence. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing a graph image
You could convert the image to a netpbm format, like ppm, pgm or pbm. If the image has few colors, that should be quite viable. Each of these formats are easy to work with in Python. ppm is for color, pgm is for grayscale, pbm is for strictly black and white, pnm pertains to any of the 3. There are all sorts of filters for converting between these formats and many others in netpbm, and image processing. You might be able to use pnmcut (to select just the part of the image you need - I'm guessing your math will be simpler if you crop off the axes and everything outside them), ppmdist (to convert color (with a low number of colors) to grayscale) or ppmtopgm (for high color images), and pgmedge (for edge detection), etc. Then you might pnmnoraw to get an ASCII pbm instead of a binary one - ASCII netpbm files are even simpler than binary onesto work with. Here's an example of generating a ppm file in Python 2. It looks like this after conversion to png format: http://stromberg.dnsalias.org/~dstromberg/software/circle.png If you set a bunch of them next to each other (say, by tiling it as a wallpaper), it gives a slightly eerie 3D effect. It's an application of the inverse square law. I know, it's kind of the opposite of what you need, but it may still illustrate the approach: #!/usr/bin/python # writes a ppm file for a sort of sphere on stdout. import math import sys def pad(n): s = str(n) while len(s) < 4: s = s + ' ' return s size=200 colors=256 print 'P3' print size,size print colors-1 half=float(size/2) sqrt2 = math.sqrt(2) for i in range(0,size): for j in range(0,size): x = float(i - half) / half y = float(j - half) / half z = math.sqrt(x*x + y*y)/sqrt2 col = int(z * (colors-1)) #sys.stderr.write(str(x)+' '+str(y)+' '+str(col)+'\n') ch = chr(col) sys.stdout.write(pad(col)+pad(col)+pad(col)+' ') print BTW, I don't do string concatenation this much anymore, and xrange is good in 2.x. :) On Fri, May 13, 2011 at 3:19 AM, Bastian Ballmann wrote: > Hi python lovers out there, > > I am searching for a library to parse data from a graph in an image file > something like http://pytseries.sourceforge.net/_images/yahoo.png > Any suggestions, hints, links? > > TIA && have a nice day! :) > > Basti > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression for words (with umlauts, without numbers)
2011/5/13 MRAB : > The latest release is here: > > http://pypi.python.org/pypi/regex > -- Wow, set operators were added recently ... https://code.google.com/p/mrab-regex-hg/wiki/GeneralDetails ok, it might be not necassary to sove this exact problem with respect to the solutions already mentioned, but I quite like this extra possibilities, anyway, the double negation [^\W] is not needed here: (?u)[\w--\d] Thank you very much for this excellent library! vbr -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
Ian Kelly wrote: Well, at least Haskell is probably better as an introductory language than Lisp or Scheme. But what schools actually do this? http://www.cs.kent.ac.uk/teaching/resources/haskell/HugsResources.html http://research.cs.queensu.ca/home/cisc260/2010w/haskell.html These are just two schools that teach functional programming early on using Haskell... but there are many. (google around) caveat: thingks are changing all the time, for instance I notice that Margaret Lamb at Queen's University in Ontario hasn't updated her page in about a year... so things may be different there for her classes than when we were first corresponding... ... and I'm also lumping two other languages into this 'category'... namely, Scheme, and Erlang. perception is that the vast majority of schools use C++ or C# or Java, ... that may be the trend now... typically relegating functional programming to a single second- or third-year course. Of course it's well known that MIT used to use Scheme, but they switched to Python a couple years ago. Scheme seems to be very popular in education, based on the discussions, as a functional language; but, alas, I've not seen it nor played with it ( so can't comment too much, yet ). I'm glad to hear that MIT is using Python now..! I don't think a single language is necessarily going to be best for all students. no doubt... I can dream can't I ? If a math major comes to you wanting to learn some programming for theorem-proving, bearing in mind that they probably aren't interested in learning more than a single language, would you try to start them out with Python, or would you just give them the functional language that they're ultimately going to want? Well, that's just it... learning how to program is essential for all disciplines IMHO and learning just one language is not an option. Everyone needs a GPL and that's going to be Python... me hopes. And then some majors are going to require special purpose languages that meet certain requirements... and functional languages (haskell, erlang, scheme) are going to suit that need very well) by the by, don't get me wrong... I think Haskell is elegant, one of the best... but, not for students with no programming background, nor for those who just don't seem to be getting it on the first pass. kind regards, m harris -- http://mail.python.org/mailman/listinfo/python-list
Re: unicode by default
On 5/13/2011 3:53 PM, harrismh777 wrote: The unicode consortium is very careful to make sure that thousands of symbols have a unique code point (that's great !) but how do these thousands of symbols actually get displayed if there is no font consortium? Are there collections of 'standard' fonts for unicode that I am not aware? Is there a unix linux package that can be installed that drops at least 'one' default standard font that will be able to render all or 'most' (whatever I mean by that) code points in unicode? Is this a Python issue at all? Easy, practical use of unicode is still a work in progress. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
On Fri, May 13, 2011 at 6:48 PM, harrismh777 wrote: > Ian Kelly wrote: >> >> Well, at least Haskell is probably better as an introductory language >> than Lisp or Scheme. But what schools actually do this? > > http://www.cs.kent.ac.uk/teaching/resources/haskell/HugsResources.html > http://research.cs.queensu.ca/home/cisc260/2010w/haskell.html > > These are just two schools that teach functional programming early on > using Haskell... but there are many. (google around) The first link is just a collection of Haskell resources, which indicates that they use it, but not when. They also have a collection of Java resources on the department website. Perusing the handbook, I see the following modules: CO320 Introduction to Object-Oriented Programming This appears to be their introductory module. It doesn't say what language they use, but since they have Java resources on the website that's what I'm going to guess. CO530 Functional Programming This is listed as an intermediate-level course and is in the 2nd/3rd year handbook. The synopsis includes: "Introduction to a Haskell system (sessions and scripts)." So no, Kent does not appear to be teaching Haskell as an introductory course, or even in the first year. The Queen's course also appears to be a 2nd year class, based on the number. Its description includes this: "You will learn two new languages: Haskell and Prolog. These languages are a bit different from languages such as *Python* and *Java* that you have learned so far in Queen's courses" (emphasis added). Notably, this class isn't even focused on functional programming; it's an introduction to programming paradigms other than the imperative one. So far, neither of these universities support your claim that "kids today are dumped into a first comp sci course in programming and plopped in-front of a Hugs interactive shell and then are expected to learn programming and be successful by trying to grasp pure functional programming in Haskell(!) in a ten to 12 week term". -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
Ian Kelly wrote: If a math major comes to you wanting to learn some programming for theorem-proving, bearing in mind that they probably aren't interested in learning more than a single language, I would question whether theorem-proving is the *only* thing they will ever want to do with a programming language. If they really only want to learn one language, it would be better to learn the one with the widest field of applicability. I'd hazard to guess that writing a theorem prover in Python would be a more practical proposition than writing a script to automate processing his LaTeX papers in Haskell. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
harrismh777 wrote: ... and I'm also lumping two other languages into this 'category'... namely, Scheme, and Erlang. Scheme isn't really a functional language, though. You can use a subset of it in a functional way, but it doesn't have the sort of built-in support for pattern matching and case analysis that true functional languages tend to have. As families of languages go, Scheme has more in common with Python than Haskell. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
rusi wrote: Dijkstra's problem (paraphrased) is that python, by choosing the FORTRAN alternative of having a non-first-class boolean type, hinders scientific/mathematical thinking/progress. Python doesn't have the flaw that Dijkstra was talking about. Fortran's flaw wasn't so much the lack of a boolean type, but that you couldn't assign the result of a logical expression to a variable. Python has always been able to do that, even before it had a distinct boolean type. -- Greg -- http://mail.python.org/mailman/listinfo/python-list
Re: How best to convert a string "list" to a python list
On 5/13/2011 3:38 PM, noydb wrote: > I want some code to take the items in a semi-colon-delimted string > "list" and places each in a python list. I came up with below. In > the name of learning how to do things properly, No big deal that you weren't aware of the split() method for strings. Since you asked for pointers, here are some notes on your code -- which is just fine, overall! > x = "red;blue;green;yellow" ## string of semi-colon delimited colors > > color_list = [] > ## sc = semi-colon > > while x.find(";") <> -1: > sc_pos = x.find(";") > current_color = x[0:sc_pos] ## color w/o sc > current_color_sc = x[0:sc_pos+1] ## color with sc You don't really need the variable "current_color_sc", since you use it only once. For example, your invocation of replace() could look like this: x = x.replace(current_color + ";", "") But if you really want the extra variable, the following definition is clearer (and also avoids a slice operation): current_color_sc = current_color + ";" > color_list.append(current_color) ## append color to list > x = x.replace(current_color_sc, "") ## remove color and sc from string Here's another reason why you don't need the variable "current_color_sc": instead of using replace(), why not just chop off the first N characters of the string: x = x[len(current_color)+1:] (The "+1" takes care of the semicolon.) > print current_color > print color_list > print x + "\n" > > color_list.append(x) # append last color left in x (no sc at end of > string) Does that last append(), outside the loop, offend you? You can get rid of it by modifying the original string: x = "red;blue;green;yellow" x += ";" Now, the final component of the string is no longer a special case, but is terminated by ";" -- just like all the other components. HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Get IP address of WIFI interface
Hi Python Experts: There are two network interfaces on my laptop, one is 100M Ethernet interface, the other is wifi interface, both are connected and has an IP address. then the question is: how to get the ip address of the wifi interface in a python script? OS: Windows or Linux -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
Ian Kelly wrote: >> Well, at least Haskell is probably better as an introductory language >> than Lisp or Scheme. But what schools actually do this? http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/ http://www.cs.ou.edu/~rlpage/fpclassSpring97/ There are lots of these... the two above afaik are still doing this at the entry level...... supposedly, these kids are 'mostly' successful and exit interviews are great... but that doesn't fit with the observed idea that students are not doing well in comp sci classes generally... but, read below... this at the entry level?? == block quote = The first 10 to 11 weeks of the course use Haskell. Students are required to write nine programs in Haskell, three of which are team projects that combine software developed in individual projects. Different members of a team are assigned different individual projects, and the team efforts combine their solutions into a working piece of software. In the early part of the course, students use operators like map, foldr, zip, and iterate to express computations. Explicit recursion is introduced after some experience with these common patterns of computation. Examples and problems address non-numeric applications, for the most part. Both interactive and file I/O are covered, but general purpose monads are not. The last 5 to 6 weeks of the course use C, and most of the projects in that part of the course duplicate the function of earlier pieces of software that the students have written in Haskell. == /block quote = -- http://mail.python.org/mailman/listinfo/python-list
Get the IP address of WIFI interface
Hi python experts: There are two network interfaces on my laptop: one is 100M Ethernet interface, the other is wifi interface, both are connected and has an ip address. The question is: How to get the ip address of the wifi interface in a python script without parsing the output of a shell command like "ipconfig" or "ifconfig"? OS: Windows or Linux F.R -- http://mail.python.org/mailman/listinfo/python-list
How to get the IP address of the wifi interface?
Hi python experts: There are two network interfaces on my laptop, one is 100M Ethernet, the other is wifi, both are connected and have IP addresses. The question is: how to get the ip address of WIFI interface without parsing the output of a shell command like "ipconfig" or "ifconfig"? OS: Windows or Linux H.J -- http://mail.python.org/mailman/listinfo/python-list
Re: Get IP address of WIFI interface
Hi. On 14 May 2011 14:46, Far.Runner wrote: > Hi Python Experts: > There are two network interfaces on my laptop, one is > 100M Ethernet interface, the other is wifi interface, both are connected and > has an IP address. then the question is: how to get the ip address of the > wifi interface in a python script? > OS: Windows or Linux Detect the OS with os.name and branch out to specific use case. The specific functionality can be implemented 2 ways: 1/ Regular expression pattern match 2/ Substring match and splits The subprocess module will then let you run those commands. 1/ posix - (Linux in your case) will use ifconfig 2/ nt - (windows in your ase) will use ipconfig. HTH. -- Regards Ishwor Gurung Key id:0xa98db35e Key fingerprint:FBEF 0D69 6DE1 C72B A5A8 35FE 5A9B F3BB 4E5E 17B5 -- http://mail.python.org/mailman/listinfo/python-list
turn monitor off and on
Hi, I'm trying to turn off my monitor, pause and then turn it on again. I'm doing this in python 2.6 and windows xp. Here is my script so far (that doesn't work): import time import win32gui import win32con import win32api def turnOffMonitor(): SC_MONITORPOWER = 0xF170 win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, 2) def turnOnMonitor(): SC_MONITORPOWER = 0xF170 win32gui.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SYSCOMMAND, SC_MONITORPOWER, -1) if __name__ == "__main__": turnOffMonitor() time.sleep(5) turnOnMonitor() For some reason, the script doesn't turn the monitor back on. What am I doing wrong here or are there any other alternative? -- http://mail.python.org/mailman/listinfo/python-list
Re: checking if a list is empty
On Fri, May 13, 2011 at 10:47 PM, harrismh777 wrote: > http://www.inf.ed.ac.uk/teaching/courses/inf1/fp/ > > http://www.cs.ou.edu/~rlpage/fpclassSpring97/ > > > There are lots of these... the two above afaik are still doing this at the > entry level... ... supposedly, these kids are 'mostly' successful and > exit interviews are great... but that doesn't fit with the observed idea > that students are not doing well in comp sci classes generally... but, read > below... this at the entry level?? I'll grant you Edinburgh. That Oklahoma syllabus is from 1997. The 2010 syllabus for the entry-level course indicates that it is taught in Java. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python enabled gdb on Windows and relocation
On Thu, May 12, 2011 at 9:19 AM, Ruben Van Boxem wrote: > (now in plain-text as required by gdb mailing list) > > Hi, > > I am currently trying to integrate Python support into my toolchain > build (including GDB of course). It is a sysrooted > binutils+GCC+GDB+mingw-w64 toolchain. > > I currently have the basic setup working: I can link gdb with my > manually generated import lib to the python dll from the official > Windows install. If there is anything I am missing or a very easy > solution to the problems decsribed below, please just say so. I am > only suggesting what I would like to happen. > > Now on to the problems I'd like to discuss: > > 1. gdb.exe won't start without me having set PYTHONPATH manually. In a properly configured/built gdb on linux this isn't necessary, even if python is installed in some random place. I'm not sure about windows though. Did you specify --with-python when you configured gdb, and if so did you specify a value? e.g., --with-python=SOME_VALUE > I understand the need for this, but as gdb requires Python 2, and users > of my toolchain may have installed Python 3 or a 32-bit version python > they want to use from the same environment (without changing their own > PYTHONPATH), there is no way to run python-enabled gdb. > [...] Yeah. There is a proposal to add GDB_PYTHONPATH (or some such IIRC) and have gdb use that instead of PYTHONPATH if it exists, but there's been resistance to it. I think(!) what would happen is that gdb would set $PYTHONPATH to the value of $GDB_PYTHONPATH. [Inferiors started by gdb should still get the original value of PYTHONPATH though.] > 2. With PYTHONPATH set as a temporary workaround, gdb starts, but > spits out a traceback: > Traceback (most recent call last): > File "", line 35, in > File "m:\development\mingw64\share\gdb/python/gdb/__init__.py", line > 18, in > gdb.command.pretty_printers.register_pretty_printer_commands() > File > "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", > line 368, in register_pretty_printer_commands > InfoPrettyPrinter() > File > "m:\development\mingw64\share\gdb/python/gdb\command\pretty_printers.py", > line 100, in __init__ > gdb.COMMAND_DATA) > RuntimeError: Could not find command prefix info. > > This is a minor problem I think, as "python import time" "python print > time.clock()" works as expected. What is wrong? I'm not sure. The error message is complaining that the "info" command prefix doesn't exist. I don't see how that can happen as python is initialized long after the info command is created. -- http://mail.python.org/mailman/listinfo/python-list